Search in sources :

Example 51 with Expression

use of cbit.vcell.parser.Expression in project vcell by virtualcell.

the class XmlReader method getMicroscopeMeasurement.

public void getMicroscopeMeasurement(Element element, SimulationContext simContext) {
    MicroscopeMeasurement microscopeMeasurement = simContext.getMicroscopeMeasurement();
    String name = element.getAttributeValue(XMLTags.NameAttrTag);
    microscopeMeasurement.setName(name);
    Element kernelElement = element.getChild(XMLTags.ConvolutionKernel, vcNamespace);
    String type = kernelElement.getAttributeValue(XMLTags.TypeAttrTag);
    ConvolutionKernel ck = null;
    if (type.equals(XMLTags.ConvolutionKernel_Type_ProjectionZKernel)) {
        ck = new ProjectionZKernel();
    } else if (type.equals(XMLTags.ConvolutionKernel_Type_GaussianConvolutionKernel)) {
        Element e = kernelElement.getChild(XMLTags.KernelGaussianSigmaXY, vcNamespace);
        String s = e.getText();
        Expression sigmaXY = unMangleExpression(s);
        e = kernelElement.getChild(XMLTags.KernelGaussianSigmaZ, vcNamespace);
        s = e.getText();
        Expression sigmaZ = unMangleExpression(s);
        ck = new GaussianConvolutionKernel(sigmaXY, sigmaZ);
    }
    microscopeMeasurement.setConvolutionKernel(ck);
    List<Element> children = element.getChildren(XMLTags.FluorescenceSpecies, vcNamespace);
    for (Element c : children) {
        String speciesName = c.getAttributeValue(XMLTags.NameAttrTag);
        SpeciesContext sc = simContext.getModel().getSpeciesContext(speciesName);
        microscopeMeasurement.addFluorescentSpecies(sc);
    }
}
Also used : ConvolutionKernel(cbit.vcell.mapping.MicroscopeMeasurement.ConvolutionKernel) GaussianConvolutionKernel(cbit.vcell.mapping.MicroscopeMeasurement.GaussianConvolutionKernel) Expression(cbit.vcell.parser.Expression) Element(org.jdom.Element) MicroscopeMeasurement(cbit.vcell.mapping.MicroscopeMeasurement) SpeciesContext(cbit.vcell.model.SpeciesContext) GaussianConvolutionKernel(cbit.vcell.mapping.MicroscopeMeasurement.GaussianConvolutionKernel) ProjectionZKernel(cbit.vcell.mapping.MicroscopeMeasurement.ProjectionZKernel)

Example 52 with Expression

use of cbit.vcell.parser.Expression in project vcell by virtualcell.

the class XmlReader method getSimulationContextParameter.

public SimulationContextParameter getSimulationContextParameter(Element paramElement, SimulationContext simContext) {
    // get its attributes : name, role and unit definition
    String appParamName = unMangle(paramElement.getAttributeValue(XMLTags.NameAttrTag));
    String role = paramElement.getAttributeValue(XMLTags.ParamRoleAttrTag);
    ModelUnitSystem modelUnitSystem = simContext.getModel().getUnitSystem();
    int appParamRole = -1;
    if (role.equals(XMLTags.ParamRoleUserDefinedTag)) {
        appParamRole = SimulationContext.ROLE_UserDefined;
    } else {
        throw new RuntimeException("unknown type of application parameter (not user-defined)");
    }
    String unitSymbol = paramElement.getAttributeValue(XMLTags.VCUnitDefinitionAttrTag);
    VCUnitDefinition appParamUnit = null;
    if (unitSymbol != null) {
        appParamUnit = modelUnitSystem.getInstance(unitSymbol);
    }
    // get parameter contents : expression; annotation, if any.
    String appParamExpStr = paramElement.getText();
    Expression appParamExp = unMangleExpression(appParamExpStr);
    // String appParamAnnotation = null;
    // String annotationText = paramElement.getChildText(XMLTags.AnnotationTag, vcNamespace);
    // if (annotationText != null && annotationText.length() > 0) {
    // appParamAnnotation = unMangle(annotationText);
    // }
    // create new global parameter
    SimulationContextParameter newAppParam = simContext.new SimulationContextParameter(appParamName, appParamExp, appParamRole, appParamUnit);
    return newAppParam;
}
Also used : VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) SimulationContextParameter(cbit.vcell.mapping.SimulationContext.SimulationContextParameter) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 53 with Expression

use of cbit.vcell.parser.Expression 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 54 with Expression

use of cbit.vcell.parser.Expression in project vcell by virtualcell.

the class XmlReader method getFastSystem.

/**
 * This method returns a FastSystemImplicit from a XML Element.
 * Creation date: (5/18/2001 2:38:56 PM)
 * @return cbit.vcell.math.FastSystemImplicit
 * @param param org.jdom.Element
 * @exception cbit.vcell.xml.XmlParseException The exception description.
 */
private FastSystem getFastSystem(Element param, MathDescription mathDesc) throws XmlParseException {
    // Create a new FastSystem
    FastSystem fastSystem = new FastSystem(mathDesc);
    // Process the FastInvariants
    Iterator<Element> iterator = param.getChildren(XMLTags.FastInvariantTag, vcNamespace).iterator();
    FastInvariant fastInvariant = null;
    while (iterator.hasNext()) {
        Element tempElement = (Element) iterator.next();
        String temp = tempElement.getText();
        try {
            Expression newExp = unMangleExpression(temp);
            fastInvariant = new FastInvariant(newExp);
            fastSystem.addFastInvariant(fastInvariant);
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException("A MathException was fired when adding the FastInvariant " + fastInvariant + ", to a FastSystem!" + " : ", e);
        }
    }
    // Process the FastRate
    iterator = param.getChildren(XMLTags.FastRateTag, vcNamespace).iterator();
    FastRate fastRate = null;
    while (iterator.hasNext()) {
        Element tempElement = (Element) iterator.next();
        String temp = tempElement.getText();
        try {
            Expression newExp = unMangleExpression(temp);
            fastRate = new FastRate(newExp);
            fastSystem.addFastRate(fastRate);
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException("A MathException was fired when adding the FastRate " + fastRate + ", to a FastSystem!", e);
        }
    }
    return fastSystem;
}
Also used : FastSystem(cbit.vcell.math.FastSystem) Expression(cbit.vcell.parser.Expression) MathException(cbit.vcell.math.MathException) Element(org.jdom.Element) FastRate(cbit.vcell.math.FastRate) FastInvariant(cbit.vcell.math.FastInvariant)

Example 55 with Expression

use of cbit.vcell.parser.Expression in project vcell by virtualcell.

the class XmlReader method getVarIniCount.

/**
 * This method return a VarIniCondition object from a XML element.
 * Creation date: (7/24/2006 5:26:05 PM)
 * @return cbit.vcell.math.VarIniCondition
 * @param param org.jdom.Element
 * @exception cbit.vcell.xml.XmlParseException The exception description.
 */
private VarIniCondition getVarIniCount(Element param, MathDescription md) throws XmlParseException, MathException, ExpressionException {
    // retrieve values
    Expression exp = unMangleExpression(param.getText());
    String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    Variable var = md.getVariable(name);
    if (var == null) {
        throw new MathFormatException("variable " + name + " not defined");
    }
    if (!(var instanceof StochVolVariable)) {
        throw new MathFormatException("variable " + name + " not a Stochastic Volume Variable");
    }
    try {
        VarIniCondition varIni = new VarIniCount(var, exp);
        return varIni;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : VarIniCondition(cbit.vcell.math.VarIniCondition) FilamentVariable(cbit.vcell.math.FilamentVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) StochVolVariable(cbit.vcell.math.StochVolVariable) RandomVariable(cbit.vcell.math.RandomVariable) VolumeRandomVariable(cbit.vcell.math.VolumeRandomVariable) VolumeParticleVariable(cbit.vcell.math.VolumeParticleVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) InsideVariable(cbit.vcell.math.InsideVariable) VolVariable(cbit.vcell.math.VolVariable) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) PointVariable(cbit.vcell.math.PointVariable) MembraneRandomVariable(cbit.vcell.math.MembraneRandomVariable) MembraneParticleVariable(cbit.vcell.math.MembraneParticleVariable) ParticleVariable(cbit.vcell.math.ParticleVariable) MemVariable(cbit.vcell.math.MemVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) Variable(cbit.vcell.math.Variable) Expression(cbit.vcell.parser.Expression) MathFormatException(cbit.vcell.math.MathFormatException) VarIniCount(cbit.vcell.math.VarIniCount) StochVolVariable(cbit.vcell.math.StochVolVariable) 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)

Aggregations

Expression (cbit.vcell.parser.Expression)549 ExpressionException (cbit.vcell.parser.ExpressionException)163 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)76 PropertyVetoException (java.beans.PropertyVetoException)73 Variable (cbit.vcell.math.Variable)69 ArrayList (java.util.ArrayList)58 Vector (java.util.Vector)56 MathException (cbit.vcell.math.MathException)55 VolVariable (cbit.vcell.math.VolVariable)53 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)51 SpeciesContext (cbit.vcell.model.SpeciesContext)50 Element (org.jdom.Element)47 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)45 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)45 Model (cbit.vcell.model.Model)43 Function (cbit.vcell.math.Function)42 Constant (cbit.vcell.math.Constant)41 ModelParameter (cbit.vcell.model.Model.ModelParameter)41 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)41 LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)38