Search in sources :

Example 21 with Species

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

the class ViewObservablesMapPanel method updateShapeSpecies.

public void updateShapeSpecies(int selectedRow) {
    GeneratedSpeciesTableRow speciesTableRow = speciesTableModel.getValueAt(selectedRow);
    String inputString = speciesTableRow.getExpression();
    // System.out.println(selectedRows[0] + ": " + inputString);
    Model tempModel = null;
    try {
        tempModel = new Model("MyTempModel");
        tempModel.addFeature("c0");
    } catch (ModelException | PropertyVetoException e1) {
        e1.printStackTrace();
    }
    if (owner != null && owner.getSimulationContext() != null) {
        List<MolecularType> mtList = owner.getSimulationContext().getModel().getRbmModelContainer().getMolecularTypeList();
        try {
            tempModel.getRbmModelContainer().setMolecularTypeList(mtList);
        } catch (PropertyVetoException e1) {
            e1.printStackTrace();
            throw new RuntimeException("Unexpected exception setting " + MolecularType.typeName + " list: " + e1.getMessage(), e1);
        }
    } else {
        System.out.println("something is wrong, we just do nothing rather than crash");
        return;
    }
    try {
        String strStructure = null;
        if (inputString.contains(RbmUtils.SiteStruct)) {
            // we are in the mode where we emulate compartments by adding the compartment name as a fake site
            Pair<List<String>, String> p = RbmUtils.extractCompartment(inputString);
            // we'll just assume there's only one, may want to throw exception if more
            strStructure = p.one.get(0);
            inputString = p.two;
        } else {
            // should be the normal @comp:expression format - if it's not it will return null
            strStructure = RbmUtils.parseCompartment(inputString, tempModel);
        }
        Structure structure;
        if (strStructure != null) {
            if (tempModel.getStructure(strStructure) == null) {
                if (owner.getSimulationContext().getModel().getStructure(strStructure).getTypeName().equals(Structure.TYPE_NAME_MEMBRANE)) {
                    tempModel.addMembrane(strStructure);
                } else {
                    tempModel.addFeature(strStructure);
                }
            }
            structure = tempModel.getStructure(strStructure);
        } else {
            structure = tempModel.getStructure(0);
        }
        SpeciesPattern sp = (SpeciesPattern) RbmUtils.parseSpeciesPattern(inputString, tempModel);
        sp.resolveBonds();
        SpeciesContext sc = new SpeciesContext(new Species("a", ""), structure, sp);
        spls = new SpeciesPatternLargeShape(20, 20, -1, sp, shapePanelSpecies, sc, issueManager);
    } catch (ParseException | PropertyVetoException | ModelException e1) {
        e1.printStackTrace();
        // error (red circle)
        spls = new SpeciesPatternLargeShape(20, 20, -1, shapePanelSpecies, true, issueManager);
        shapePanelSpecies.repaint();
    }
    int xOffset = spls.getRightEnd() + 45;
    Dimension preferredSize = new Dimension(xOffset + 90, 50);
    shapePanelSpecies.setPreferredSize(preferredSize);
    shapePanelSpecies.repaint();
}
Also used : ModelException(cbit.vcell.model.ModelException) SpeciesContext(cbit.vcell.model.SpeciesContext) Dimension(java.awt.Dimension) SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) Point(java.awt.Point) PropertyVetoException(java.beans.PropertyVetoException) MolecularType(org.vcell.model.rbm.MolecularType) Model(cbit.vcell.model.Model) ObservableTableModel(cbit.vcell.client.desktop.biomodel.ObservableTableModel) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) List(java.util.List) ArrayList(java.util.ArrayList) ParseException(org.vcell.model.bngl.ParseException) Structure(cbit.vcell.model.Structure) Species(cbit.vcell.model.Species) BNGSpecies(cbit.vcell.bionetgen.BNGSpecies)

Example 22 with Species

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

the class MathMapping_4_8 method refreshLocalNameCount.

protected void refreshLocalNameCount() {
    localNameCountHash.clear();
    ReactionStep[] reactionSteps = simContext.getModel().getReactionSteps();
    for (int j = 0; j < reactionSteps.length; j++) {
        KineticsParameter[] params = reactionSteps[j].getKinetics().getKineticsParameters();
        for (KineticsParameter kp : params) {
            String name = kp.getName();
            if (localNameCountHash.containsKey(name)) {
                localNameCountHash.put(name, localNameCountHash.get(name) + 1);
            } else {
                localNameCountHash.put(name, 1);
            }
        }
    }
    SpeciesContext[] scs = simContext.getModel().getSpeciesContexts();
    for (SpeciesContext sc : scs) {
        String name = sc.getName();
        if (localNameCountHash.containsKey(name)) {
            localNameCountHash.put(name, localNameCountHash.get(name) + 1);
        } else {
            localNameCountHash.put(name, 1);
        }
    }
    Species[] ss = simContext.getModel().getSpecies();
    for (Species s : ss) {
        String name = s.getCommonName();
        if (localNameCountHash.containsKey(name)) {
            localNameCountHash.put(name, localNameCountHash.get(name) + 1);
        } else {
            localNameCountHash.put(name, 1);
        }
    }
    ModelParameter[] mps = simContext.getModel().getModelParameters();
    for (ModelParameter mp : mps) {
        String name = mp.getName();
        if (localNameCountHash.containsKey(name)) {
            localNameCountHash.put(name, localNameCountHash.get(name) + 1);
        } else {
            localNameCountHash.put(name, 1);
        }
    }
}
Also used : ModelParameter(cbit.vcell.model.Model.ModelParameter) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) ReactionStep(cbit.vcell.model.ReactionStep) SpeciesContext(cbit.vcell.model.SpeciesContext) Species(cbit.vcell.model.Species)

Example 23 with Species

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

the class MembraneStructureAnalyzer method refreshResolvedFluxes.

/**
 * This method was created in VisualAge.
 */
void refreshResolvedFluxes() throws Exception {
    // System.out.println("MembraneStructureAnalyzer.refreshResolvedFluxes()");
    GeometryContext geoContext = mathMapping_4_8.getSimulationContext().getGeometryContext();
    StructureTopology structTopology = mathMapping_4_8.getSimulationContext().getModel().getStructureTopology();
    Vector<ResolvedFlux> resolvedFluxList = new Vector<ResolvedFlux>();
    // 
    // for each reaction, get all fluxReactions associated with this membrane
    // 
    Vector<ReactionStep> fluxList = new Vector<ReactionStep>();
    ReactionSpec[] reactionSpecs = mathMapping_4_8.getSimulationContext().getReactionContext().getReactionSpecs();
    for (int j = 0; j < reactionSpecs.length; j++) {
        if (reactionSpecs[j].isExcluded()) {
            continue;
        }
        ReactionStep rs = reactionSpecs[j].getReactionStep();
        if (rs.getStructure() == getMembrane()) {
            if (rs instanceof FluxReaction) {
                fluxList.addElement(rs);
            }
        }
    }
    // 
    for (int i = 0; i < fluxList.size(); i++) {
        FluxReaction fr = (FluxReaction) fluxList.elementAt(i);
        Species fluxCarrier = null;
        for (ReactionParticipant rp : fr.getReactionParticipants()) {
            if (rp instanceof Reactant || rp instanceof Product) {
                if (fluxCarrier == null) {
                    fluxCarrier = rp.getSpecies();
                } else {
                    if (fluxCarrier != rp.getSpecies()) {
                        throw new Exception("Flux reaction '" + fr.getName() + "' with multiple species not allowed in VCell 4.8.");
                    }
                }
            }
        }
        if (fluxCarrier == null) {
            continue;
        }
        ResolvedFlux rf = null;
        for (int j = 0; j < resolvedFluxList.size(); j++) {
            ResolvedFlux rf_tmp = (ResolvedFlux) resolvedFluxList.elementAt(j);
            if (rf_tmp.getSpecies() == fluxCarrier) {
                rf = rf_tmp;
            }
        }
        // 
        // if "inside" speciesContext is not "fixed", add flux to ResolvedFlux
        // 
        SpeciesContext insideSpeciesContext = mathMapping_4_8.getSimulationContext().getModel().getSpeciesContext(fluxCarrier, structTopology.getInsideFeature(getMembrane()));
        SpeciesContextSpec insideSpeciesContextSpec = mathMapping_4_8.getSimulationContext().getReactionContext().getSpeciesContextSpec(insideSpeciesContext);
        // if (!insideSpeciesContextSpec.isConstant()){
        if (bNoFluxIfFixed || !insideSpeciesContextSpec.isConstant()) {
            if (bNoFluxIfFixed && insideSpeciesContextSpec.isConstant()) {
                bNoFluxIfFixedExercised = true;
            }
            if (rf == null) {
                rf = new ResolvedFlux(fluxCarrier, fr.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate).getUnitDefinition());
                resolvedFluxList.addElement(rf);
            }
            FeatureMapping insideFeatureMapping = (FeatureMapping) geoContext.getStructureMapping((structTopology.getInsideFeature((Membrane) fr.getStructure())));
            Expression residualVolumeFraction = mathMapping_4_8.getResidualVolumeFraction(insideFeatureMapping).renameBoundSymbols(mathMapping_4_8.getNameScope());
            Expression insideFluxCorrection = Expression.invert(residualVolumeFraction);
            // 
            if (bResolvedFluxCorrectionBug && !residualVolumeFraction.compareEqual(new Expression(1.0))) {
                bResolvedFluxCorrectionBugExercised = true;
                System.out.println("MembraneStructureAnalyzer.refreshResolvedFluxes() ... 'ResolvedFluxCorrection' bug compatability mode");
                insideFluxCorrection = new Expression(1.0);
            }
            // 
            if (fr.getKinetics() instanceof DistributedKinetics) {
                Expression reactionRateParameter = new Expression(((DistributedKinetics) fr.getKinetics()).getReactionRateParameter(), mathMapping_4_8.getNameScope());
                if (rf.inFluxExpression.isZero()) {
                    rf.inFluxExpression = Expression.mult(reactionRateParameter, insideFluxCorrection).flatten();
                } else {
                    rf.inFluxExpression = Expression.add(rf.inFluxExpression, Expression.mult(reactionRateParameter, insideFluxCorrection).flatten());
                }
            } else if (fr.getKinetics() instanceof LumpedKinetics) {
                throw new RuntimeException("Lumped Kinetics for fluxes not yet supported");
            } else {
                throw new RuntimeException("unexpected Kinetic type in MembraneStructureAnalyzer.refreshResolvedFluxes()");
            }
        // rf.inFlux.bindExpression(mathMapping);
        }
        SpeciesContext outsideSpeciesContext = mathMapping_4_8.getSimulationContext().getModel().getSpeciesContext(fluxCarrier, structTopology.getOutsideFeature(getMembrane()));
        SpeciesContextSpec outsideSpeciesContextSpec = mathMapping_4_8.getSimulationContext().getReactionContext().getSpeciesContextSpec(outsideSpeciesContext);
        // if (!outsideSpeciesContextSpec.isConstant()){
        if (bNoFluxIfFixed || !outsideSpeciesContextSpec.isConstant()) {
            if (bNoFluxIfFixed && outsideSpeciesContextSpec.isConstant()) {
                bNoFluxIfFixedExercised = true;
            }
            if (rf == null) {
                rf = new ResolvedFlux(fluxCarrier, fr.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate).getUnitDefinition());
                resolvedFluxList.addElement(rf);
            }
            FeatureMapping outsideFeatureMapping = (FeatureMapping) geoContext.getStructureMapping(structTopology.getOutsideFeature((Membrane) fr.getStructure()));
            Expression residualVolumeFraction = mathMapping_4_8.getResidualVolumeFraction(outsideFeatureMapping).renameBoundSymbols(mathMapping_4_8.getNameScope());
            Expression outsideFluxCorrection = Expression.invert(residualVolumeFraction);
            // 
            if (bResolvedFluxCorrectionBug && !residualVolumeFraction.compareEqual(new Expression(1.0))) {
                bResolvedFluxCorrectionBugExercised = true;
                System.out.println("MembraneStructureAnalyzer.refreshResolvedFluxes() ... 'ResolvedFluxCorrection' bug compatability mode");
                outsideFluxCorrection = new Expression(1.0);
            }
            // 
            if (fr.getKinetics() instanceof DistributedKinetics) {
                Expression reactionRateParameter = new Expression(((DistributedKinetics) fr.getKinetics()).getReactionRateParameter(), mathMapping_4_8.getNameScope());
                if (rf.outFluxExpression.isZero()) {
                    rf.outFluxExpression = Expression.mult(Expression.negate(reactionRateParameter), outsideFluxCorrection).flatten();
                } else {
                    rf.outFluxExpression = Expression.add(rf.outFluxExpression, Expression.mult(Expression.negate(reactionRateParameter), outsideFluxCorrection).flatten());
                }
            } else if (fr.getKinetics() instanceof LumpedKinetics) {
                throw new RuntimeException("Lumped Kinetics not yet supported for Flux Reaction: " + fr.getName());
            } else {
                throw new RuntimeException("unexpected Kinetics type for Flux Reaction " + fr.getName());
            }
        // rf.outFlux.bindExpression(mathMapping);
        }
    }
    // 
    // for each reaction, incorporate all reactionSteps involving binding with volumetric species
    // 
    double kMoleValue = 1 / 602.0;
    for (int i = 0; i < reactionSpecs.length; i++) {
        if (reactionSpecs[i].isExcluded()) {
            continue;
        }
        ReactionStep rs = reactionSpecs[i].getReactionStep();
        if (rs.getStructure() == getMembrane()) {
            if (rs instanceof SimpleReaction) {
                SimpleReaction sr = (SimpleReaction) rs;
                ReactionParticipant[] rp_Array = sr.getReactionParticipants();
                for (int k = 0; k < rp_Array.length; k++) {
                    if (rp_Array[k] instanceof Reactant || rp_Array[k] instanceof Product) {
                        SpeciesContextSpec scs = mathMapping_4_8.getSimulationContext().getReactionContext().getSpeciesContextSpec(rp_Array[k].getSpeciesContext());
                        // if (rp_Array[k].getStructure() instanceof Feature && !scs.isConstant()){
                        if (rp_Array[k].getStructure() instanceof Feature && (bNoFluxIfFixed || !scs.isConstant())) {
                            if (bNoFluxIfFixed && scs.isConstant()) {
                                bNoFluxIfFixedExercised = true;
                            }
                            // 
                            // for each Reactant or Product binding to this membrane...
                            // 
                            // 
                            // get ResolvedFlux for this species
                            // 
                            ResolvedFlux rf = null;
                            for (int j = 0; j < resolvedFluxList.size(); j++) {
                                ResolvedFlux rf_tmp = (ResolvedFlux) resolvedFluxList.elementAt(j);
                                if (rf_tmp.getSpecies() == rp_Array[k].getSpecies()) {
                                    rf = rf_tmp;
                                }
                            }
                            if (rf == null) {
                                rf = new ResolvedFlux(rp_Array[k].getSpecies(), sr.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate).getUnitDefinition());
                                resolvedFluxList.addElement(rf);
                            }
                            Expression reactionRateExpression = getReactionRateExpression(sr, rp_Array[k]).renameBoundSymbols(mathMapping_4_8.getNameScope());
                            if (rp_Array[k].getStructure() == structTopology.getInsideFeature(getMembrane())) {
                                // 
                                // for binding on inside, add to ResolvedFlux.inFlux
                                // 
                                FeatureMapping insideFeatureMapping = (FeatureMapping) geoContext.getStructureMapping(structTopology.getInsideFeature(getMembrane()));
                                Expression residualVolumeFraction = mathMapping_4_8.getResidualVolumeFraction(insideFeatureMapping).renameBoundSymbols(mathMapping_4_8.getNameScope());
                                Expression insideFluxCorrection = Expression.div(new Expression(kMoleValue), residualVolumeFraction).flatten();
                                // 
                                if (bResolvedFluxCorrectionBug && !residualVolumeFraction.compareEqual(new Expression(1.0))) {
                                    bResolvedFluxCorrectionBugExercised = true;
                                    System.out.println("MembraneStructureAnalyzer.refreshResolvedFluxes() ... 'ResolvedFluxCorrection' bug compatability mode");
                                    insideFluxCorrection = new Expression(kMoleValue);
                                }
                                if (rf.inFluxExpression.isZero()) {
                                    rf.inFluxExpression = Expression.mult(insideFluxCorrection, reactionRateExpression);
                                } else {
                                    rf.inFluxExpression = Expression.add(rf.inFluxExpression, Expression.mult(insideFluxCorrection, reactionRateExpression));
                                }
                            // rf.inFlux.bindExpression(mathMapping);
                            } else if (rp_Array[k].getStructure() == structTopology.getOutsideFeature(getMembrane())) {
                                // 
                                // for binding on outside, add to ResolvedFlux.outFlux
                                // 
                                FeatureMapping outsideFeatureMapping = (FeatureMapping) geoContext.getStructureMapping(structTopology.getOutsideFeature(getMembrane()));
                                Expression residualVolumeFraction = mathMapping_4_8.getResidualVolumeFraction(outsideFeatureMapping).renameBoundSymbols(mathMapping_4_8.getNameScope());
                                Expression outsideFluxCorrection = Expression.div(new Expression(kMoleValue), residualVolumeFraction).flatten();
                                // 
                                if (bResolvedFluxCorrectionBug && !residualVolumeFraction.compareEqual(new Expression(1.0))) {
                                    bResolvedFluxCorrectionBugExercised = true;
                                    System.out.println("MembraneStructureAnalyzer.refreshResolvedFluxes() ... 'ResolvedFluxCorrection' bug compatability mode");
                                    outsideFluxCorrection = new Expression(kMoleValue);
                                }
                                if (rf.outFluxExpression.isZero()) {
                                    rf.outFluxExpression = Expression.mult(outsideFluxCorrection, reactionRateExpression);
                                } else {
                                    rf.outFluxExpression = Expression.add(rf.outFluxExpression, Expression.mult(outsideFluxCorrection, reactionRateExpression));
                                }
                            // rf.outFlux.bindExpression(mathMapping);
                            } else {
                                throw new Exception("SpeciesContext " + rp_Array[k].getSpeciesContext().getName() + " doesn't border membrane " + getMembrane().getName() + " but reacts there");
                            }
                        }
                    }
                }
            }
        }
    }
    // 
    if (resolvedFluxList.size() > 0) {
        resolvedFluxes = new ResolvedFlux[resolvedFluxList.size()];
        resolvedFluxList.copyInto(resolvedFluxes);
    } else {
        resolvedFluxes = null;
    }
}
Also used : LumpedKinetics(cbit.vcell.model.LumpedKinetics) Product(cbit.vcell.model.Product) FluxReaction(cbit.vcell.model.FluxReaction) SpeciesContext(cbit.vcell.model.SpeciesContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) Reactant(cbit.vcell.model.Reactant) Feature(cbit.vcell.model.Feature) FeatureMapping(cbit.vcell.mapping.FeatureMapping) Membrane(cbit.vcell.model.Membrane) GeometryContext(cbit.vcell.mapping.GeometryContext) Vector(java.util.Vector) Species(cbit.vcell.model.Species) DistributedKinetics(cbit.vcell.model.DistributedKinetics) SimpleReaction(cbit.vcell.model.SimpleReaction) StructureTopology(cbit.vcell.model.Model.StructureTopology) ReactionSpec(cbit.vcell.mapping.ReactionSpec) Expression(cbit.vcell.parser.Expression) ReactionStep(cbit.vcell.model.ReactionStep) ReactionParticipant(cbit.vcell.model.ReactionParticipant)

Example 24 with Species

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

the class XmlReader method getSpecies.

/**
 * This method creates a Specie (Compound) object from an XML Element.
 * Creation date: (3/15/2001 12:57:43 PM)
 * @return cbit.vcell.model.Species
 * @param param org.jdom.Element
 */
private Species getSpecies(Element param) throws XmlParseException {
    // get its data
    String specieName = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    String specieAnnotation = null;
    // the Annotation paramater can be optional
    // String temp = param.getAttributeValue(XMLTags.AnnotationAttrTag);
    // if (temp!=null && temp.length()!=0) {
    // specieAnnotation = unMangle(temp);
    // }
    String annotationText = param.getChildText(XMLTags.AnnotationTag, vcNamespace);
    if (annotationText != null && annotationText.length() > 0) {
        specieAnnotation = unMangle(annotationText);
    }
    // create new Specie
    Species newspecie = new Species(specieName, specieAnnotation);
    // Try to read the DBSpecie data
    Element dbspecieElement = param.getChild(XMLTags.DBSpeciesTag, vcNamespace);
    if (dbspecieElement != null && this.readKeysFlag) {
        // read the data
        try {
            newspecie.setDBSpecies(getDBSpecies(dbspecieElement));
        } catch (java.beans.PropertyVetoException e) {
            e.printStackTrace();
            throw new XmlParseException(e);
        }
    }
    return newspecie;
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) Element(org.jdom.Element) DBFormalSpecies(cbit.vcell.model.DBFormalSpecies) Species(cbit.vcell.model.Species) DBSpecies(cbit.vcell.model.DBSpecies)

Example 25 with Species

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

the class XmlReader method getModel.

/**
 * This method creates a Model object from a XML element.
 * Creation date: (3/14/2001 6:14:37 PM)
 * @return cbit.vcell.model.Model
 * @param param org.jdom.Element
 */
private Model getModel(Element param) throws XmlParseException {
    if (param == null) {
        throw new XmlParseException("Invalid 'NULL' XML 'model' element arrived!");
    }
    // Get version, if any
    Model newmodel = null;
    Version version = getVersion(param.getChild(XMLTags.VersionTag, vcNamespace));
    // if forcedModelUnitSystem has been set, ues that (could be overriding unit system for SBML export)
    if (forcedModelUnitSystem != null) {
        newmodel = new Model(version, forcedModelUnitSystem);
    } else {
        Element unitSystemNode = param.getChild(XMLTags.ModelUnitSystemTag, vcNamespace);
        if (unitSystemNode != null) {
            ModelUnitSystem modelUnitSystem = getUnitSystem(unitSystemNode);
            newmodel = new Model(version, modelUnitSystem);
        } else {
            newmodel = new Model(version);
        }
    }
    try {
        // Set attributes
        newmodel.setName(unMangle(param.getAttributeValue(XMLTags.NameAttrTag)));
        // Add annotation
        String annotationText = param.getChildText(XMLTags.AnnotationTag, vcNamespace);
        if (annotationText != null && annotationText.length() > 0) {
            newmodel.setDescription(unMangle(annotationText));
        }
        // Add global parameters
        Element globalParamsElement = param.getChild(XMLTags.ModelParametersTag, vcNamespace);
        if (globalParamsElement != null) {
            ModelParameter[] modelParams = getModelParams(globalParamsElement, newmodel);
            // add global/model param to model - done inside getModelParam by passing newModel
            newmodel.setModelParameters(modelParams);
        }
        // Add Species (Compounds)
        Iterator<Element> iterator = param.getChildren(XMLTags.SpeciesTag, vcNamespace).iterator();
        ArrayList<Species> speciesList = new ArrayList<Species>();
        while (iterator.hasNext()) {
            org.jdom.Element temp = (Element) iterator.next();
            speciesList.add(getSpecies(temp));
        }
        newmodel.setSpecies(speciesList.toArray(new Species[speciesList.size()]));
        // Add Structures
        LinkedList<Structure> newstructures = new LinkedList<Structure>();
        // (features)
        List<Element> children = param.getChildren(XMLTags.FeatureTag, vcNamespace);
        for (Element featureElement : children) {
            newstructures.add(getFeature(featureElement));
        }
        // (Membrane)
        children = param.getChildren(XMLTags.MembraneTag, vcNamespace);
        for (Element memElement : children) {
            newstructures.add(getMembrane(newmodel, memElement, newstructures));
        }
        if (newstructures.size() > 0) {
            Structure[] structarray = new Structure[newstructures.size()];
            newstructures.toArray(structarray);
            // Add all the retrieved structures
            newmodel.setStructures(structarray);
        }
        // retrieve the RbmModelContainer, if present - must be done before we retrieve species context!
        Element element = param.getChild(XMLTags.RbmModelContainerTag, vcNamespace);
        if (element != null) {
            getRbmModelContainer(element, newmodel);
        } else {
            lg.info("RbmModelContainer is missing.");
        }
        // Add SpeciesContexts
        children = param.getChildren(XMLTags.SpeciesContextTag, vcNamespace);
        SpeciesContext[] newspeccon = new SpeciesContext[children.size()];
        int scCounter = 0;
        for (Element scElement : children) {
            newspeccon[scCounter] = getSpeciesContext(scElement, newmodel);
            scCounter++;
        }
        newmodel.setSpeciesContexts(newspeccon);
        // Retrieve rateRules and add to model
        // Element rateRuleVarsElement = param.getChild(XMLTags.RateRuleVariablesTag, vcNamespace);
        // if(rateRuleVarsElement != null){
        // RateRuleVariable[] rateRuleVars = getRateRuleVariables(rateRuleVarsElement, newmodel);
        // newmodel.setRateRuleVariables(rateRuleVars);
        // }
        // Add Reaction steps (if available)
        // (Simplereaction)
        // Create a varHash with reserved symbols and global parameters, if any, to pass on to Kinetics
        // must create new hash for each reaction and flux, since each kinetics uses new variables hash
        iterator = param.getChildren(XMLTags.SimpleReactionTag, vcNamespace).iterator();
        ArrayList<ReactionStep> reactionStepList = new ArrayList<ReactionStep>();
        while (iterator.hasNext()) {
            org.jdom.Element temp = iterator.next();
            reactionStepList.add(getSimpleReaction(temp, newmodel));
        }
        // (fluxStep)
        iterator = param.getChildren(XMLTags.FluxStepTag, vcNamespace).iterator();
        while (iterator.hasNext()) {
            org.jdom.Element temp = iterator.next();
            reactionStepList.add(getFluxReaction(temp, newmodel));
        }
        newmodel.setReactionSteps(reactionStepList.toArray(new ReactionStep[reactionStepList.size()]));
        // Add Diagrams
        children = param.getChildren(XMLTags.DiagramTag, vcNamespace);
        if (children.size() > 0) {
            Diagram[] newdiagrams = new Diagram[children.size()];
            int diagramCounter = 0;
            for (Element diagramElement : children) {
                newdiagrams[diagramCounter] = getDiagram(diagramElement, newmodel);
                diagramCounter++;
            }
            reorderDiagramsInPlace_UponRead(docVCellSoftwareVersion, newdiagrams, newmodel.getStructureTopology());
            // if(docVCellSoftwareVersion != null && !docVCellSoftwareVersion.isValid() && docVCellSoftwareVersion.getMajorVersion()<=5 && docVCellSoftwareVersion.getMinorVersion() <=2){
            // //In Vcell 5.2 and previous we need to order diagrams topologically, in 5.3 and later the diagrams are displayed as they are ordered when read from document
            // final StructureTopology structureTopology = newmodel.getStructureTopology();
            // Arrays.sort(newdiagrams, new Comparator<Diagram>() {
            // @Override
            // public int compare(Diagram o1, Diagram o2) {
            // return getStructureLevel(o1.getStructure(), structureTopology) - getStructureLevel(o2.getStructure(), structureTopology);
            // }
            // });
            // }
            newmodel.setDiagrams(newdiagrams);
        }
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace();
        throw new XmlParseException(e);
    } catch (ModelException e) {
        e.printStackTrace();
    }
    // model param expresions are not bound when they are read in, since they could be functions of each other or structures/speciesContexts.
    // Hence bind the model param exprs at the end, after reading all model level quantities.
    ModelParameter[] modelParameters = newmodel.getModelParameters();
    for (int i = 0; modelParameters != null && i < modelParameters.length; i++) {
        try {
            modelParameters[i].getExpression().bindExpression(newmodel);
        } catch (ExpressionBindingException e) {
            e.printStackTrace(System.out);
            throw new RuntimeException("Error binding global parameter '" + modelParameters[i].getName() + "' to model." + e.getMessage());
        }
    }
    return newmodel;
}
Also used : Element(org.jdom.Element) ArrayList(java.util.ArrayList) SpeciesContext(cbit.vcell.model.SpeciesContext) PropertyVetoException(java.beans.PropertyVetoException) Version(org.vcell.util.document.Version) RedistributionVersion(cbit.vcell.solvers.mb.MovingBoundarySolverOptions.RedistributionVersion) SimulationVersion(org.vcell.util.document.SimulationVersion) VCellSoftwareVersion(org.vcell.util.document.VCellSoftwareVersion) Structure(cbit.vcell.model.Structure) DBFormalSpecies(cbit.vcell.model.DBFormalSpecies) Species(cbit.vcell.model.Species) DBSpecies(cbit.vcell.model.DBSpecies) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem) ModelException(cbit.vcell.model.ModelException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) LinkedList(java.util.LinkedList) Diagram(cbit.vcell.model.Diagram) ModelParameter(cbit.vcell.model.Model.ModelParameter) ReactionStep(cbit.vcell.model.ReactionStep) MathModel(cbit.vcell.mathmodel.MathModel) Model(cbit.vcell.model.Model) PathwayModel(org.vcell.pathway.PathwayModel) RelationshipModel(org.vcell.relationship.RelationshipModel) BioModel(cbit.vcell.biomodel.BioModel) Element(org.jdom.Element)

Aggregations

Species (cbit.vcell.model.Species)39 SpeciesContext (cbit.vcell.model.SpeciesContext)28 Structure (cbit.vcell.model.Structure)21 Model (cbit.vcell.model.Model)16 PropertyVetoException (java.beans.PropertyVetoException)13 KeyValue (org.vcell.util.document.KeyValue)12 Feature (cbit.vcell.model.Feature)11 ReactionStep (cbit.vcell.model.ReactionStep)11 Expression (cbit.vcell.parser.Expression)11 DBSpecies (cbit.vcell.model.DBSpecies)10 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)9 Membrane (cbit.vcell.model.Membrane)9 SimpleReaction (cbit.vcell.model.SimpleReaction)9 BioModel (cbit.vcell.biomodel.BioModel)8 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)8 ModelException (cbit.vcell.model.ModelException)8 ArrayList (java.util.ArrayList)8 FeatureMapping (cbit.vcell.mapping.FeatureMapping)7 DBFormalSpecies (cbit.vcell.model.DBFormalSpecies)7 ImageException (cbit.image.ImageException)6