Search in sources :

Example 6 with Feature

use of cbit.vcell.model.Feature in project vcell by virtualcell.

the class XmlReader method getMembrane.

/**
 * This method returns a Membrane object from a XML element.
 * Creation date: (4/4/2001 4:17:32 PM)
 * @return cbit.vcell.model.Membrane
 * @param param org.jdom.Element
 */
private Membrane getMembrane(Model model, Element param, List<Structure> featureList) throws XmlParseException {
    String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    Membrane newmembrane = null;
    // retrieve the key if there is one
    KeyValue key = null;
    String stringkey = param.getAttributeValue(XMLTags.KeyValueAttrTag);
    if (stringkey != null && stringkey.length() > 0 && this.readKeysFlag) {
        key = new KeyValue(stringkey);
    }
    // try to create new Membrane named "name"
    try {
        newmembrane = new Membrane(key, name);
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace();
        throw new XmlParseException("An error occurred while trying to create the Membrane object " + name, e);
    }
    // set inside feature
    String infeaturename = unMangle(param.getAttributeValue(XMLTags.InsideFeatureTag));
    String outfeaturename = unMangle(param.getAttributeValue(XMLTags.OutsideFeatureTag));
    String posFeatureName = unMangle(param.getAttributeValue(XMLTags.PositiveFeatureTag));
    String negFeatureName = unMangle(param.getAttributeValue(XMLTags.NegativeFeatureTag));
    Feature infeatureref = null;
    Feature outfeatureref = null;
    Feature posFeature = null;
    Feature negFeature = null;
    for (Structure s : featureList) {
        String sname = s.getName();
        if (sname.equals(infeaturename)) {
            infeatureref = (Feature) s;
        }
        if (sname.equals(outfeaturename)) {
            outfeatureref = (Feature) s;
        }
        if (sname.equals(posFeatureName)) {
            posFeature = (Feature) s;
        }
        if (sname.equals(negFeatureName)) {
            negFeature = (Feature) s;
        }
    }
    // set inside and outside features
    if (infeatureref != null) {
        model.getStructureTopology().setInsideFeature(newmembrane, infeatureref);
    }
    if (outfeatureref != null) {
        model.getStructureTopology().setOutsideFeature(newmembrane, outfeatureref);
    }
    // set positive & negative features
    if (posFeature != null) {
        model.getElectricalTopology().setPositiveFeature(newmembrane, posFeature);
    }
    if (negFeature != null) {
        model.getElectricalTopology().setNegativeFeature(newmembrane, negFeature);
    }
    // set MemVoltName
    if (param.getAttribute(XMLTags.MemVoltNameTag) == null) {
        throw new XmlParseException("Error reading membrane Voltage Name!");
    }
    String memvoltName = unMangle(param.getAttributeValue(XMLTags.MemVoltNameTag));
    try {
        newmembrane.getMembraneVoltage().setName(memvoltName);
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace();
        throw new XmlParseException("Error setting the membrane Voltage Name", e);
    }
    return newmembrane;
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) KeyValue(org.vcell.util.document.KeyValue) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) Feature(cbit.vcell.model.Feature)

Example 7 with Feature

use of cbit.vcell.model.Feature in project vcell by virtualcell.

the class XmlReader method getFluxReaction.

/**
 * This method returns a FluxReaction object from a XML element.
 * Creation date: (3/16/2001 11:52:02 AM)
 * @return cbit.vcell.model.FluxReaction
 * @param param org.jdom.Element
 * @throws XmlParseException
 * @throws PropertyVetoException
 * @throws ModelException
 * @throws Exception
 */
private FluxReaction getFluxReaction(Element param, Model model) throws XmlParseException, PropertyVetoException {
    // retrieve the key if there is one
    KeyValue key = null;
    String keystring = param.getAttributeValue(XMLTags.KeyValueAttrTag);
    if (keystring != null && keystring.length() > 0 && this.readKeysFlag) {
        key = new KeyValue(keystring);
    }
    // resolve reference to the Membrane
    String structureName = unMangle(param.getAttributeValue(XMLTags.StructureAttrTag));
    Membrane structureref = (Membrane) model.getStructure(structureName);
    if (structureref == null) {
        throw new XmlParseException("The membrane " + structureName + " could not be resolved in the dictionnary!");
    }
    // -- Instantiate new FluxReaction --
    FluxReaction fluxreaction = null;
    String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    String reversibleAttributeValue = param.getAttributeValue(XMLTags.ReversibleAttrTag);
    boolean bReversible = true;
    if (reversibleAttributeValue != null) {
        if (Boolean.TRUE.toString().equals(reversibleAttributeValue)) {
            bReversible = true;
        } else if (Boolean.FALSE.toString().equals(reversibleAttributeValue)) {
            bReversible = false;
        } else {
            throw new RuntimeException("unexpected value " + reversibleAttributeValue + " for reversible flag for reaction " + name);
        }
    }
    try {
        fluxreaction = new FluxReaction(model, structureref, key, name, bReversible);
        fluxreaction.setModel(model);
    } catch (Exception e) {
        e.printStackTrace();
        throw new XmlParseException("An exception occurred while trying to create the FluxReaction " + name, e);
    }
    // resolve reference to the fluxCarrier
    if (param.getAttribute(XMLTags.FluxCarrierAttrTag) != null) {
        String speciesname = unMangle(param.getAttributeValue(XMLTags.FluxCarrierAttrTag));
        Species specieref = model.getSpecies(speciesname);
        if (specieref != null) {
            Feature insideFeature = model.getStructureTopology().getInsideFeature(structureref);
            try {
                if (insideFeature != null) {
                    SpeciesContext insideSpeciesContext = model.getSpeciesContext(specieref, insideFeature);
                    fluxreaction.addProduct(insideSpeciesContext, 1);
                }
                Feature outsideFeature = model.getStructureTopology().getOutsideFeature(structureref);
                if (outsideFeature != null) {
                    SpeciesContext outsideSpeciesContext = model.getSpeciesContext(specieref, outsideFeature);
                    fluxreaction.addReactant(outsideSpeciesContext, 1);
                }
            } catch (ModelException e) {
                e.printStackTrace(System.out);
                throw new XmlParseException(e.getMessage());
            }
        }
    }
    // Annotation
    // String rsAnnotation = null;
    // String annotationText = param.getChildText(XMLTags.AnnotationTag, vcNamespace);
    // if (annotationText!=null && annotationText.length()>0) {
    // rsAnnotation = unMangle(annotationText);
    // }
    // fluxreaction.setAnnotation(rsAnnotation);
    // set the fluxOption
    String fluxOptionString = null;
    fluxOptionString = param.getAttributeValue(XMLTags.FluxOptionAttrTag);
    if (fluxOptionString != null && fluxOptionString.length() > 0) {
        try {
            if (fluxOptionString.equals(XMLTags.FluxOptionElectricalOnly)) {
                fluxreaction.setPhysicsOptions(FluxReaction.PHYSICS_ELECTRICAL_ONLY);
            } else if (fluxOptionString.equals(XMLTags.FluxOptionMolecularAndElectrical)) {
                fluxreaction.setPhysicsOptions(FluxReaction.PHYSICS_MOLECULAR_AND_ELECTRICAL);
            } else if (fluxOptionString.equals(XMLTags.FluxOptionMolecularOnly)) {
                fluxreaction.setPhysicsOptions(FluxReaction.PHYSICS_MOLECULAR_ONLY);
            }
        } catch (java.beans.PropertyVetoException e) {
            e.printStackTrace(System.out);
            throw new XmlParseException("A propertyVetoException was fired when setting the fluxOption to the flux reaction " + name, e);
        }
    }
    // Add Reactants, if any
    try {
        Iterator<Element> iterator = param.getChildren(XMLTags.ReactantTag, vcNamespace).iterator();
        while (iterator.hasNext()) {
            Element temp = iterator.next();
            // Add Reactant to this SimpleReaction
            fluxreaction.addReactionParticipant(getReactant(temp, fluxreaction, model));
        }
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace();
        throw new XmlParseException("Error adding a reactant to the reaction " + name + " : " + e.getMessage());
    }
    // Add Products, if any
    try {
        Iterator<Element> iterator = param.getChildren(XMLTags.ProductTag, vcNamespace).iterator();
        while (iterator.hasNext()) {
            Element temp = iterator.next();
            // Add Product to this simplereaction
            fluxreaction.addReactionParticipant(getProduct(temp, fluxreaction, model));
        }
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace();
        throw new XmlParseException("Error adding a product to the reaction " + name + " : " + e.getMessage());
    }
    // Add Catalyst(Modifiers) (if there are)
    Iterator<Element> iterator = param.getChildren(XMLTags.CatalystTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        Element temp = iterator.next();
        fluxreaction.addReactionParticipant(getCatalyst(temp, fluxreaction, model));
    }
    // Add Kinetics
    fluxreaction.setKinetics(getKinetics(param.getChild(XMLTags.KineticsTag, vcNamespace), fluxreaction, model));
    // set the valence (for legacy support for "chargeCarrierValence" stored with reaction).
    String valenceString = null;
    try {
        valenceString = unMangle(param.getAttributeValue(XMLTags.FluxCarrierValenceAttrTag));
        if (valenceString != null && valenceString.length() > 0) {
            KineticsParameter chargeValenceParameter = fluxreaction.getKinetics().getChargeValenceParameter();
            if (chargeValenceParameter != null) {
                chargeValenceParameter.setExpression(new Expression(Integer.parseInt(unMangle(valenceString))));
            }
        }
    } catch (NumberFormatException e) {
        e.printStackTrace();
        throw new XmlParseException("A NumberFormatException was fired when setting the (integer) valence '" + valenceString + "' (integer) to the flux reaction " + name, e);
    }
    return fluxreaction;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) ModelException(cbit.vcell.model.ModelException) Element(org.jdom.Element) FluxReaction(cbit.vcell.model.FluxReaction) SpeciesContext(cbit.vcell.model.SpeciesContext) Feature(cbit.vcell.model.Feature) GeometryException(cbit.vcell.geometry.GeometryException) MathFormatException(cbit.vcell.math.MathFormatException) MappingException(cbit.vcell.mapping.MappingException) PropertyVetoException(java.beans.PropertyVetoException) ImageException(cbit.image.ImageException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ModelException(cbit.vcell.model.ModelException) DataConversionException(org.jdom.DataConversionException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException) PropertyVetoException(java.beans.PropertyVetoException) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) Expression(cbit.vcell.parser.Expression) Membrane(cbit.vcell.model.Membrane) DBFormalSpecies(cbit.vcell.model.DBFormalSpecies) Species(cbit.vcell.model.Species) DBSpecies(cbit.vcell.model.DBSpecies)

Example 8 with Feature

use of cbit.vcell.model.Feature in project vcell by virtualcell.

the class Xmlproducer method getXML.

/**
 * This method identifies if the structure as a parameter is a Feature or a Membrane, and then calls the respective getXML method.
 * Creation date: (2/22/2001 6:31:04 PM)
 * @return Element
 * @param param cbit.vcell.model.Structure
 * @param model cbit.vcell.model.Model
 */
private Element getXML(Structure structure, Model model) throws XmlParseException {
    Element structureElement = null;
    StructureTopology structTopology = model.getStructureTopology();
    if (structure instanceof Feature) {
        // This is a Feature
        structureElement = new Element(XMLTags.FeatureTag);
    } else if (structure instanceof Membrane) {
        // process a Membrane
        structureElement = new Element(XMLTags.MembraneTag);
        // add specific attributes
        Feature insideFeature = structTopology.getInsideFeature((Membrane) structure);
        if (insideFeature != null) {
            structureElement.setAttribute(XMLTags.InsideFeatureTag, mangle(insideFeature.getName()));
        }
        Feature outsideFeature = structTopology.getOutsideFeature((Membrane) structure);
        if (outsideFeature != null) {
            structureElement.setAttribute(XMLTags.OutsideFeatureTag, mangle(outsideFeature.getName()));
        }
        // positive & negative features for electrical topology
        ElectricalTopology electricalTopology = model.getElectricalTopology();
        Feature positiveFeature = electricalTopology.getPositiveFeature((Membrane) structure);
        if (positiveFeature != null) {
            structureElement.setAttribute(XMLTags.PositiveFeatureTag, mangle(positiveFeature.getName()));
        }
        Feature negativeFeature = electricalTopology.getNegativeFeature((Membrane) structure);
        if (negativeFeature != null) {
            structureElement.setAttribute(XMLTags.NegativeFeatureTag, mangle(negativeFeature.getName()));
        }
        structureElement.setAttribute(XMLTags.MemVoltNameTag, mangle(((Membrane) structure).getMembraneVoltage().getName()));
    } else {
        throw new XmlParseException("An unknown type of structure was found:" + structure.getClass().getName());
    }
    // add attributes
    structureElement.setAttribute(XMLTags.NameAttrTag, mangle(structure.getName()));
    // If the keyFlag is on, print Keys
    if (structure.getKey() != null && this.printKeysFlag) {
        structureElement.setAttribute(XMLTags.KeyValueAttrTag, structure.getKey().toString());
    }
    return structureElement;
}
Also used : StructureTopology(cbit.vcell.model.Model.StructureTopology) Element(org.jdom.Element) ElectricalTopology(cbit.vcell.model.Model.ElectricalTopology) Membrane(cbit.vcell.model.Membrane) Feature(cbit.vcell.model.Feature)

Example 9 with Feature

use of cbit.vcell.model.Feature in project vcell by virtualcell.

the class SpeciesContextSpec method initializeForSpatial.

public void initializeForSpatial() {
    if (getDiffusionParameter() != null && getDiffusionParameter().getExpression() != null && getDiffusionParameter().getExpression().isZero()) {
        Expression e = null;
        ModelUnitSystem modelUnitSystem = getSimulationContext().getModel().getUnitSystem();
        VCUnitDefinition micronsqpersecond = modelUnitSystem.getInstance("um2.s-1");
        if (speciesContext.getStructure() instanceof Feature) {
            RationalNumber rn = RationalNumber.getApproximateFraction(micronsqpersecond.convertTo(10, getDiffusionParameter().getUnitDefinition()));
            e = new Expression(rn.doubleValue());
        } else if (speciesContext.getStructure() instanceof Membrane) {
            RationalNumber rn = RationalNumber.getApproximateFraction(micronsqpersecond.convertTo(0.1, getDiffusionParameter().getUnitDefinition()));
            e = new Expression(rn.doubleValue());
        } else {
            RationalNumber rn = RationalNumber.getApproximateFraction(micronsqpersecond.convertTo(1.0, getDiffusionParameter().getUnitDefinition()));
            e = new Expression(rn.doubleValue());
        }
        try {
            getDiffusionParameter().setExpression(e);
        } catch (ExpressionBindingException e1) {
            e1.printStackTrace();
            throw new RuntimeException("Error while initializing diffusion rate, " + e1.getMessage());
        }
    }
}
Also used : VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) Membrane(cbit.vcell.model.Membrane) RationalNumber(cbit.vcell.matrix.RationalNumber) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) Feature(cbit.vcell.model.Feature) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 10 with Feature

use of cbit.vcell.model.Feature in project vcell by virtualcell.

the class SpeciesContextSpec method hasTransport.

public boolean hasTransport() {
    if (isConstant() || isWellMixed() || simulationContext == null || simulationContext.getGeometry() == null || simulationContext.getGeometry().getDimension() == 0) {
        return false;
    }
    int dimension = simulationContext.getGeometry().getDimension();
    SpeciesContext speciesContext = getSpeciesContext();
    if (speciesContext.getStructure() instanceof Membrane) {
        if (dimension > 1 && !getDiffusionParameter().getExpression().isZero()) {
            return true;
        }
    } else if (speciesContext.getStructure() instanceof Feature) {
        if (!getDiffusionParameter().getExpression().isZero()) {
            return true;
        }
        if (getVelocityXParameter().getExpression() != null && !getVelocityXParameter().getExpression().isZero()) {
            return true;
        }
        SpatialQuantity[] velX_quantities = getVelocityQuantities(QuantityComponent.X);
        if (velX_quantities.length > 0) {
            return true;
        }
        if (dimension > 1) {
            if (getVelocityYParameter().getExpression() != null && !getVelocityYParameter().getExpression().isZero()) {
                return true;
            }
            if (dimension > 2) {
                if (getVelocityZParameter().getExpression() != null && !getVelocityZParameter().getExpression().isZero()) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : Membrane(cbit.vcell.model.Membrane) SpeciesContext(cbit.vcell.model.SpeciesContext) Feature(cbit.vcell.model.Feature)

Aggregations

Feature (cbit.vcell.model.Feature)71 Membrane (cbit.vcell.model.Membrane)50 Structure (cbit.vcell.model.Structure)36 Expression (cbit.vcell.parser.Expression)29 SpeciesContext (cbit.vcell.model.SpeciesContext)25 PropertyVetoException (java.beans.PropertyVetoException)18 Model (cbit.vcell.model.Model)16 StructureTopology (cbit.vcell.model.Model.StructureTopology)16 SimpleReaction (cbit.vcell.model.SimpleReaction)15 SubVolume (cbit.vcell.geometry.SubVolume)14 MembraneMapping (cbit.vcell.mapping.MembraneMapping)14 SurfaceClass (cbit.vcell.geometry.SurfaceClass)13 FeatureMapping (cbit.vcell.mapping.FeatureMapping)13 ExpressionException (cbit.vcell.parser.ExpressionException)13 FluxReaction (cbit.vcell.model.FluxReaction)12 ReactionStep (cbit.vcell.model.ReactionStep)12 KeyValue (org.vcell.util.document.KeyValue)12 BioModel (cbit.vcell.biomodel.BioModel)11 StructureMapping (cbit.vcell.mapping.StructureMapping)11 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)11