Search in sources :

Example 16 with SpeciesContext

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

the class RbmUtils method toBnglString.

public static String toBnglString(Parameter parameter, boolean bFunction) {
    if (!bFunction) {
        // parameter
        String str = parameter.getName() + " ";
        if (parameter.getExpression() != null) {
            str += parameter.getExpression().infixBng();
        } else {
            str = "# " + str + "(expression undefined)";
        }
        return str;
    } else {
        // function
        String str = parameter.getName() + "()\t=\t";
        if (parameter.getExpression() != null) {
            String[] symbols = parameter.getExpression().getSymbols();
            for (String s : symbols) {
                SymbolTableEntry ste = parameter.getExpression().getSymbolBinding(s);
                if (ste instanceof SpeciesContext) {
                    System.out.println("SpeciesContext '" + s + "' found in expression of function, not exporting");
                    str = "# " + str;
                    break;
                }
            }
            str += parameter.getExpression().infixBng();
        } else {
            str = "# " + str + "(expression undefined)";
        }
        return str;
    }
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) SpeciesContext(cbit.vcell.model.SpeciesContext)

Example 17 with SpeciesContext

use of cbit.vcell.model.SpeciesContext 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 18 with SpeciesContext

use of cbit.vcell.model.SpeciesContext 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 19 with SpeciesContext

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

the class XmlReader method getReactant.

/**
 * This method returns a Reactant object from a XML representation.
 * Creation date: (5/4/2001 2:22:56 PM)
 * @return cbit.vcell.model.Reactant
 * @param param org.jdom.Element
 * @exception cbit.vcell.xml.XmlParseException The exception description.
 */
private Reactant getReactant(Element param, ReactionStep reaction, Model model) throws XmlParseException {
    // retrieve the key if there is one
    String keystring = param.getAttributeValue(XMLTags.KeyValueAttrTag);
    KeyValue key = null;
    if (keystring != null && keystring.length() > 0 && this.readKeysFlag) {
        key = new KeyValue(keystring);
    }
    String speccontref = unMangle(param.getAttributeValue(XMLTags.SpeciesContextRefAttrTag));
    SpeciesContext speccont = model.getSpeciesContext(speccontref);
    if (speccont == null) {
        throw new XmlParseException("The reference to the SpecieContext " + speccontref + " for a SimpleReaction could not be resolved!");
    }
    // Retrieve Stoichiometry
    int stoch = 1;
    org.jdom.Attribute tempArg = param.getAttribute(XMLTags.StoichiometryAttrTag);
    if (tempArg != null) {
        String tempValue = tempArg.getValue();
        if (tempValue.length() > 0)
            stoch = Integer.parseInt(tempValue);
    // param.getAttributeValue(XMLTags.StoichiometryAttrTag));
    }
    // return new Reactant(newkey, reaction, speccont, stoch);
    return new Reactant(key, reaction, speccont, stoch);
}
Also used : KeyValue(org.vcell.util.document.KeyValue) Attribute(org.jdom.Attribute) SpeciesContext(cbit.vcell.model.SpeciesContext) Reactant(cbit.vcell.model.Reactant)

Example 20 with SpeciesContext

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

the class XmlReader method getCatalyst.

/**
 * This method returns a Catalyst object from a XML representation.
 * Creation date: (5/4/2001 2:22:56 PM)
 * @return cbit.vcell.model.Product
 * @param param org.jdom.Element
 * @exception cbit.vcell.xml.XmlParseException The exception description.
 */
private Catalyst getCatalyst(Element param, ReactionStep reaction, Model model) throws XmlParseException {
    // 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);
    }
    String speccontref = unMangle(param.getAttributeValue(XMLTags.SpeciesContextRefAttrTag));
    SpeciesContext speccont = model.getSpeciesContext(speccontref);
    if (speccont == null) {
        throw new XmlParseException("The reference to the SpecieContext " + speccontref + " for a Catalyst could not be resolved!");
    }
    return new Catalyst(key, reaction, speccont);
}
Also used : KeyValue(org.vcell.util.document.KeyValue) SpeciesContext(cbit.vcell.model.SpeciesContext) Catalyst(cbit.vcell.model.Catalyst)

Aggregations

SpeciesContext (cbit.vcell.model.SpeciesContext)153 Structure (cbit.vcell.model.Structure)57 Expression (cbit.vcell.parser.Expression)49 ReactionStep (cbit.vcell.model.ReactionStep)48 Model (cbit.vcell.model.Model)44 ArrayList (java.util.ArrayList)37 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)32 ModelParameter (cbit.vcell.model.Model.ModelParameter)32 PropertyVetoException (java.beans.PropertyVetoException)32 ReactionParticipant (cbit.vcell.model.ReactionParticipant)30 BioModel (cbit.vcell.biomodel.BioModel)28 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)28 Species (cbit.vcell.model.Species)28 ReactionRule (cbit.vcell.model.ReactionRule)27 Feature (cbit.vcell.model.Feature)25 Membrane (cbit.vcell.model.Membrane)25 ExpressionException (cbit.vcell.parser.ExpressionException)25 SimpleReaction (cbit.vcell.model.SimpleReaction)22 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)22 Reactant (cbit.vcell.model.Reactant)20