Search in sources :

Example 91 with SpeciesContext

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

the class ModelUnitConverter method createBioModelWithNewUnitSystem.

public static BioModel createBioModelWithNewUnitSystem(BioModel oldBioModel, ModelUnitSystem newUnitSystem) throws ExpressionException, XmlParseException {
    // new BioModel has new unit system applied to all built-in units ... but expressions still need to be corrected (see below).
    BioModel newBioModel = XmlHelper.cloneBioModelWithNewUnitSystem(oldBioModel, newUnitSystem);
    Model newModel = newBioModel.getModel();
    Model oldModel = oldBioModel.getModel();
    for (Parameter p : newBioModel.getModel().getModelParameters()) {
        convertVarsWithUnitFactors(oldBioModel.getModel(), newBioModel.getModel(), p);
    }
    for (ReactionStep reactionStep : newBioModel.getModel().getReactionSteps()) {
        SymbolTable oldSymbolTable = oldBioModel.getModel().getReactionStep(reactionStep.getName());
        SymbolTable newSymbolTable = reactionStep;
        for (Parameter p : reactionStep.getKinetics().getUnresolvedParameters()) {
            convertVarsWithUnitFactors(oldSymbolTable, newSymbolTable, p);
        }
        for (Parameter p : reactionStep.getKinetics().getKineticsParameters()) {
            convertVarsWithUnitFactors(oldSymbolTable, newSymbolTable, p);
        }
    }
    for (ReactionRule reactionRule : newBioModel.getModel().getRbmModelContainer().getReactionRuleList()) {
        SymbolTable oldSymbolTable = oldBioModel.getModel().getRbmModelContainer().getReactionRule(reactionRule.getName()).getKineticLaw().getScopedSymbolTable();
        SymbolTable newSymbolTable = reactionRule.getKineticLaw().getScopedSymbolTable();
        for (Parameter p : reactionRule.getKineticLaw().getUnresolvedParameters()) {
            convertVarsWithUnitFactors(oldSymbolTable, newSymbolTable, p);
        }
        for (Parameter p : reactionRule.getKineticLaw().getLocalParameters()) {
            convertVarsWithUnitFactors(oldSymbolTable, newSymbolTable, p);
        }
    }
    for (SimulationContext simContext : newBioModel.getSimulationContexts()) {
        SimulationContext oldSimContext = oldBioModel.getSimulationContext(simContext.getName());
        // ArrayList<Parameter> parameterList = new ArrayList<Parameter>();
        for (StructureMapping mapping : simContext.getGeometryContext().getStructureMappings()) {
            Structure oldStructure = oldModel.getStructure(mapping.getStructure().getName());
            StructureMapping oldMapping = oldSimContext.getGeometryContext().getStructureMapping(oldStructure);
            for (Parameter p : mapping.computeApplicableParameterList()) {
                convertVarsWithUnitFactors(oldMapping, mapping, p);
            }
        }
        for (SpeciesContextSpec spec : simContext.getReactionContext().getSpeciesContextSpecs()) {
            SpeciesContext oldSpeciesContext = oldModel.getSpeciesContext(spec.getSpeciesContext().getName());
            SpeciesContextSpec oldSpec = oldSimContext.getReactionContext().getSpeciesContextSpec(oldSpeciesContext);
            for (Parameter p : spec.computeApplicableParameterList()) {
                convertVarsWithUnitFactors(oldSpec, spec, p);
            }
        }
        for (int i = 0; i < simContext.getElectricalStimuli().length; i++) {
            ElectricalStimulus newElectricalStimulus = simContext.getElectricalStimuli()[i];
            ElectricalStimulus oldElectricalStimulus = oldSimContext.getElectricalStimuli()[i];
            for (Parameter p : newElectricalStimulus.getParameters()) {
                convertVarsWithUnitFactors(oldElectricalStimulus.getNameScope().getScopedSymbolTable(), newElectricalStimulus.getNameScope().getScopedSymbolTable(), p);
            }
        }
        // convert events : trigger and delay parameters and event assignments
        for (int i = 0; simContext.getBioEvents() != null && oldSimContext.getBioEvents() != null && i < simContext.getBioEvents().length; i++) {
            BioEvent newBioEvent = simContext.getBioEvents()[i];
            BioEvent oldBioEvent = oldSimContext.getBioEvent(newBioEvent.getName());
            for (Parameter p : newBioEvent.getEventParameters()) {
                convertVarsWithUnitFactors(oldBioEvent.getNameScope().getScopedSymbolTable(), newBioEvent.getNameScope().getScopedSymbolTable(), p);
            }
            // for each event assignment expression
            for (int e = 0; e < newBioEvent.getEventAssignments().size(); e++) {
                ScopedSymbolTable newSymbolTable = newBioEvent.getNameScope().getScopedSymbolTable();
                ScopedSymbolTable oldSymbolTable = oldBioEvent.getNameScope().getScopedSymbolTable();
                EventAssignment newEventAssignment = newBioEvent.getEventAssignments().get(e);
                EventAssignment oldEventAssignment = oldBioEvent.getEventAssignments().get(e);
                VCUnitDefinition oldTargetUnit = oldEventAssignment.getTarget().getUnitDefinition();
                VCUnitDefinition newTargetUnit = newEventAssignment.getTarget().getUnitDefinition();
                Expression eventAssgnExpr = newEventAssignment.getAssignmentExpression();
                convertExprWithUnitFactors(oldSymbolTable, newSymbolTable, oldTargetUnit, newTargetUnit, eventAssgnExpr);
            }
        }
        /**
         * @TODO: If rate rule variable unit is TBD, we still need to handle the rate expression unit.
         */
        // convert rate rules
        RateRule[] rateRules = simContext.getRateRules();
        if (rateRules != null && rateRules.length > 0) {
            for (RateRule rateRule : rateRules) {
                RateRule oldRateRule = oldSimContext.getRateRule(rateRule.getName());
                ScopedSymbolTable oldSymbolTable = oldRateRule.getSimulationContext();
                ScopedSymbolTable newSymbolTable = rateRule.getSimulationContext();
                VCUnitDefinition oldTargetUnit = oldRateRule.getRateRuleVar().getUnitDefinition();
                VCUnitDefinition newTargetUnit = rateRule.getRateRuleVar().getUnitDefinition();
                Expression rateRuleExpr = rateRule.getRateRuleExpression();
                convertExprWithUnitFactors(oldSymbolTable, newSymbolTable, oldTargetUnit, newTargetUnit, rateRuleExpr);
            }
        }
    }
    // end  for - simulationContext
    return newBioModel;
}
Also used : ReactionRule(cbit.vcell.model.ReactionRule) EventAssignment(cbit.vcell.mapping.BioEvent.EventAssignment) ScopedSymbolTable(cbit.vcell.parser.ScopedSymbolTable) SymbolTable(cbit.vcell.parser.SymbolTable) SpeciesContext(cbit.vcell.model.SpeciesContext) SimulationContext(cbit.vcell.mapping.SimulationContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) StructureMapping(cbit.vcell.mapping.StructureMapping) ElectricalStimulus(cbit.vcell.mapping.ElectricalStimulus) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) ReactionStep(cbit.vcell.model.ReactionStep) Model(cbit.vcell.model.Model) Parameter(cbit.vcell.model.Parameter) RateRule(cbit.vcell.mapping.RateRule) ScopedSymbolTable(cbit.vcell.parser.ScopedSymbolTable) BioEvent(cbit.vcell.mapping.BioEvent) Structure(cbit.vcell.model.Structure)

Example 92 with SpeciesContext

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

the class SimulationContext method updateSpeciesIniCondition.

// specially created for loading from database, used in ServerDocumentManager.saveBioModel()
public void updateSpeciesIniCondition(SimulationContext simContext) throws MappingException, PropertyVetoException {
    boolean bUseConcentration = simContext.isUsingConcentration();
    this.setUsingConcentration(bUseConcentration);
    SpeciesContextSpec[] refScSpec = simContext.getReactionContext().getSpeciesContextSpecs();
    // SpeciesContextSpec[] scSpec = this.getReactionContext().getSpeciesContextSpecs();
    for (int i = 0; i < refScSpec.length; i++) {
        SpeciesContext refSc = refScSpec[i].getSpeciesContext();
        SpeciesContextSpec scSpec = this.getReactionContext().getSpeciesContextSpec(refSc);
        try {
            scSpec.getInitialConcentrationParameter().setExpression(refScSpec[i].getInitialConcentrationParameter().getExpression());
            scSpec.getInitialCountParameter().setExpression(refScSpec[i].getInitialCountParameter().getExpression());
        } catch (ExpressionBindingException e) {
            e.printStackTrace();
            throw new MappingException(e.getMessage());
        }
    }
}
Also used : SpeciesContext(cbit.vcell.model.SpeciesContext) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException)

Example 93 with SpeciesContext

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

the class SpeciesContextSpec method gatherIssues.

/**
 * Insert the method's description here.
 * Creation date: (11/1/2005 10:03:46 AM)
 * @param issueVector java.util.Vector
 */
public void gatherIssues(IssueContext issueContext, List<Issue> issueVector) {
    issueContext = issueContext.newChildContext(ContextType.SpeciesContextSpec, this);
    // 
    for (int i = 0; i < fieldParameters.length; i++) {
        RealInterval simpleBounds = parameterBounds[fieldParameters[i].getRole()];
        if (simpleBounds != null) {
            String parmName = fieldParameters[i].getNameScope().getName() + "." + fieldParameters[i].getName();
            issueVector.add(new SimpleBoundsIssue(fieldParameters[i], issueContext, simpleBounds, "parameter " + parmName + ": must be within " + simpleBounds.toString()));
        }
    }
    if (bForceContinuous && !bConstant && getSimulationContext().isStoch() && (getSimulationContext().getGeometry().getDimension() > 0)) {
        // if it's particle or constant we're good
        SpeciesContext sc = getSpeciesContext();
        ReactionContext rc = getSimulationContext().getReactionContext();
        ReactionSpec[] rsArray = rc.getReactionSpecs();
        for (ReactionSpec rs : rsArray) {
            if (!rs.isExcluded()) {
                // we only care about reactions which are not excluded
                // true if "this" is part of current reaction
                boolean iAmParticipant = false;
                // true if current reaction has at least a particle participant
                boolean haveParticle = false;
                ReactionStep step = rs.getReactionStep();
                for (ReactionParticipant p : step.getReactionParticipants()) {
                    if (p instanceof Product || p instanceof Reactant) {
                        SpeciesContextSpec candidate = rc.getSpeciesContextSpec(p.getSpeciesContext());
                        if (candidate == this) {
                            iAmParticipant = true;
                        } else if (!candidate.isForceContinuous() && !candidate.isConstant()) {
                            haveParticle = true;
                        }
                    }
                }
                if (iAmParticipant && haveParticle) {
                    String msg = "Continuous Species won't conserve mass in particle reaction " + rs.getReactionStep().getName() + ".";
                    String tip = "Mass conservation for reactions of binding between discrete and continuous species is handled approximately. <br>" + "To avoid any algorithmic approximation, which may produce undesired results, the user is advised to indicate <br>" + "the continuous species in those reactions as modifiers (i.e. 'catalysts') in the physiology.";
                    issueVector.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, tip, Issue.SEVERITY_WARNING));
                    // we issue warning as soon as we found the first reaction which satisfies criteria
                    break;
                }
            }
        }
    }
    if (!bForceContinuous && bConstant) {
        if (getSimulationContext().isStoch() && (getSimulationContext().getGeometry().getDimension() > 0)) {
            String msg = "Clamped Species must be continuous rather than particles.";
            String tip = "If choose 'clamped', must also choose 'forceContinuous'";
            issueVector.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, tip, Issue.SEVERITY_ERROR));
        }
    }
    if (bForceContinuous && !bConstant) {
        if (getSimulationContext().isStoch() && (getSimulationContext().getGeometry().getDimension() == 0)) {
            String msg = "Non-constant species is forced continuous, not supported for nonspatial stochastic applications.";
            issueVector.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, Issue.SEVERITY_ERROR));
        }
    }
}
Also used : Issue(org.vcell.util.Issue) SimpleBoundsIssue(cbit.vcell.model.SimpleBoundsIssue) SimpleBoundsIssue(cbit.vcell.model.SimpleBoundsIssue) Product(cbit.vcell.model.Product) SpeciesContext(cbit.vcell.model.SpeciesContext) RealInterval(net.sourceforge.interval.ia_math.RealInterval) Reactant(cbit.vcell.model.Reactant) ReactionStep(cbit.vcell.model.ReactionStep) ReactionParticipant(cbit.vcell.model.ReactionParticipant)

Example 94 with SpeciesContext

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

the class StructureAnalyzer method refreshFastSpeciesContextMappings.

/**
 * This method was created in VisualAge.
 */
private void refreshFastSpeciesContextMappings() {
    // System.out.println("StructureAnalyzer.refreshFastSpeciesContextMappings()");
    // GeometryContext geoContext = mathMapping.getSimulationContext().getGeometryContext();
    Vector<SpeciesContextMapping> scFastList = new Vector<SpeciesContextMapping>();
    // 
    if (structures == null) {
        return;
    }
    for (int i = 0; i < structures.length; i++) {
        SpeciesContext[] speciesContexts = mathMapping.getSimulationContext().getReactionContext().getModel().getSpeciesContexts(structures[i]);
        for (int j = 0; j < speciesContexts.length; j++) {
            SpeciesContext sc = speciesContexts[j];
            SpeciesContextMapping scm = mathMapping.getSpeciesContextMapping(sc);
            SpeciesContextSpec scs = mathMapping.getSimulationContext().getReactionContext().getSpeciesContextSpec(sc);
            if (scm.getDependencyExpression() == null && scs.isConstant() == false) {
                // right now all independent vars
                scFastList.addElement(scm);
            }
        }
    }
    if (scFastList.size() > 0) {
        fastSpeciesContextMappings = new SpeciesContextMapping[scFastList.size()];
        scFastList.copyInto(fastSpeciesContextMappings);
    // for (int i=0;i<fastSpeciesContextMappings.length;i++){
    // System.out.println("fastSpeciesContextMappings["+i+"] = "+fastSpeciesContextMappings[i].getSpeciesContext().getName());
    // }
    } else {
        fastSpeciesContextMappings = null;
    }
    // System.out.println("StructureAnalyzer.refreshFastSpeciesContextMapping(), fastSpeciesContextMappings.length = "+scFastList.size());
    // 
    // for each reaction, get all reactionSteps associated with these structures
    // 
    Vector<ReactionStep> rsFastList = new Vector<ReactionStep>();
    ReactionSpec[] reactionSpecs = mathMapping.getSimulationContext().getReactionContext().getReactionSpecs();
    for (int i = 0; i < reactionSpecs.length; i++) {
        ReactionStep rs = reactionSpecs[i].getReactionStep();
        if (reactionSpecs[i].isExcluded()) {
            continue;
        }
        for (int j = 0; j < structures.length; j++) {
            if (rs.getStructure() == structures[j]) {
                if (reactionSpecs[i].isFast()) {
                    rsFastList.addElement(rs);
                }
            }
        }
    }
    if (rsFastList.size() > 0) {
        fastReactionSteps = new ReactionStep[rsFastList.size()];
        rsFastList.copyInto(fastReactionSteps);
    } else {
        fastReactionSteps = null;
        fastSpeciesContextMappings = null;
    }
// System.out.println("StructureAnalyzer.refreshFastSpeciesContextMapping(), reactionSteps.length = "+scFastList.size());
}
Also used : ReactionStep(cbit.vcell.model.ReactionStep) SpeciesContext(cbit.vcell.model.SpeciesContext) Vector(java.util.Vector)

Example 95 with SpeciesContext

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

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