Search in sources :

Example 21 with Structure

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

the class BioModelEditorStructureTableModel method bioModelChange.

@Override
protected void bioModelChange(PropertyChangeEvent evt) {
    super.bioModelChange(evt);
    BioModel oldValue = (BioModel) evt.getOldValue();
    if (oldValue != null) {
        for (Structure s : oldValue.getModel().getStructures()) {
            s.removePropertyChangeListener(this);
        }
    }
    BioModel newValue = (BioModel) evt.getNewValue();
    if (newValue != null) {
        for (Structure s : newValue.getModel().getStructures()) {
            s.addPropertyChangeListener(this);
        }
    }
}
Also used : BioModel(cbit.vcell.biomodel.BioModel) Structure(cbit.vcell.model.Structure)

Example 22 with Structure

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

the class SimulationContext method gatherIssues.

public void gatherIssues(IssueContext issueContext, List<Issue> issueVector, boolean bIgnoreMathDescription) {
    // issueContext = issueContext.newChildContext(ContextType.SimContext, this);
    if (applicationType.equals(Application.RULE_BASED_STOCHASTIC)) {
        for (ReactionRuleSpec rrs : getReactionContext().getReactionRuleSpecs()) {
            if (rrs.isExcluded()) {
                continue;
            }
            ReactionRule rr = rrs.getReactionRule();
            if (rr.getReactantPatterns().size() > 2) {
                String message = "NFSim doesn't support more than 2 reactants within a reaction rule.";
                issueVector.add(new Issue(rr, issueContext, IssueCategory.Identifiers, message, Issue.Severity.WARNING));
            }
            if (rr.isReversible() && rr.getProductPatterns().size() > 2) {
                String message = "NFSim doesn't support more than 2 products within a reversible reaction rule.";
                issueVector.add(new Issue(rr, issueContext, IssueCategory.Identifiers, message, Issue.Severity.WARNING));
            }
        }
        for (ReactionSpec rrs : getReactionContext().getReactionSpecs()) {
            if (rrs.isExcluded()) {
                continue;
            }
            ReactionStep rs = rrs.getReactionStep();
            if (rs.getNumReactants() > 2) {
                String message = "NFSim doesn't support more than 2 reactants within a reaction step.";
                issueVector.add(new Issue(rs, issueContext, IssueCategory.Identifiers, message, Issue.Severity.WARNING));
            }
            if (rs.isReversible() && rs.getNumProducts() > 2) {
                String message = "NFSim doesn't support more than 2 products within a reversible reaction step.";
                issueVector.add(new Issue(rs, issueContext, IssueCategory.Identifiers, message, Issue.Severity.WARNING));
            }
        }
        // we give warning when we have plain reactions with participants with patterns;
        // making rules from these may result in inconsistent interpretation for the constant rates
        boolean isParticipantWithPattern = false;
        for (ReactionSpec rrs : getReactionContext().getReactionSpecs()) {
            if (rrs.isExcluded()) {
                continue;
            }
            ReactionStep rs = rrs.getReactionStep();
            for (Reactant r : rs.getReactants()) {
                if (r.getSpeciesContext().hasSpeciesPattern()) {
                    isParticipantWithPattern = true;
                    break;
                }
            }
            if (isParticipantWithPattern) {
                break;
            }
            for (Product p : rs.getProducts()) {
                if (p.getSpeciesContext().hasSpeciesPattern()) {
                    isParticipantWithPattern = true;
                    break;
                }
            }
            if (isParticipantWithPattern) {
                break;
            }
        }
        if (isParticipantWithPattern) {
            String message = SimulationContext.rateWarning2;
            String tooltip = SimulationContext.rateWarning;
            issueVector.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, tooltip, Issue.Severity.WARNING));
        }
        for (Structure struct : getModel().getStructures()) {
            String name = struct.getName();
            if (!name.equals(TokenMangler.fixTokenStrict(name))) {
                String msg = "'" + name + "' not legal identifier for rule-based stochastic applications, try '" + TokenMangler.fixTokenStrict(name) + "'.";
                issueVector.add(new Issue(struct, issueContext, IssueCategory.Identifiers, msg, Issue.Severity.ERROR));
            }
        }
    }
    if (fieldBioEvents != null) {
        for (BioEvent bioEvent : fieldBioEvents) {
            bioEvent.gatherIssues(issueContext, issueVector);
        }
    }
    if (spatialObjects != null) {
        for (SpatialObject spatialObject : spatialObjects) {
            spatialObject.gatherIssues(issueContext, issueVector);
        }
    }
    if (spatialProcesses != null) {
        for (SpatialProcess spatialProcess : spatialProcesses) {
            spatialProcess.gatherIssues(issueContext, issueVector);
        }
    }
    if (applicationType.equals(Application.NETWORK_DETERMINISTIC) && getModel().getRbmModelContainer().getMolecularTypeList().size() > 0) {
        // we're going to use network transformer to flatten (or we already did)
        if (isInsufficientIterations()) {
            issueVector.add(new Issue(this, issueContext, IssueCategory.RbmNetworkConstraintsBad, IssueInsufficientIterations, Issue.Severity.WARNING));
        }
        if (isInsufficientMaxMolecules()) {
            issueVector.add(new Issue(this, issueContext, IssueCategory.RbmNetworkConstraintsBad, IssueInsufficientMolecules, Issue.Severity.WARNING));
        }
    }
    getReactionContext().gatherIssues(issueContext, issueVector);
    getGeometryContext().gatherIssues(issueContext, issueVector);
    if (fieldAnalysisTasks != null) {
        for (AnalysisTask analysisTask : fieldAnalysisTasks) {
            analysisTask.gatherIssues(issueContext, issueVector);
        }
    }
    getOutputFunctionContext().gatherIssues(issueContext, issueVector);
    getMicroscopeMeasurement().gatherIssues(issueContext, issueVector);
    if (getMathDescription() != null && !bIgnoreMathDescription) {
        getMathDescription().gatherIssues(issueContext, issueVector);
    }
    if (networkConstraints == null) {
    // issueVector.add(new Issue(this, issueContext, IssueCategory.RbmNetworkConstraintsBad, "Network Constraints is null", Issue.Severity.ERROR));
    } else {
        networkConstraints.gatherIssues(issueContext, issueVector);
    }
}
Also used : Issue(org.vcell.util.Issue) ReactionRule(cbit.vcell.model.ReactionRule) Product(cbit.vcell.model.Product) Reactant(cbit.vcell.model.Reactant) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) SpatialProcess(cbit.vcell.mapping.spatial.processes.SpatialProcess) ReactionStep(cbit.vcell.model.ReactionStep) AnalysisTask(cbit.vcell.modelopt.AnalysisTask) Structure(cbit.vcell.model.Structure)

Example 23 with Structure

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

the class SpeciesContextSpec method convertParticlesToConcentration.

public Expression convertParticlesToConcentration(Expression iniParticles) throws ExpressionException, MappingException {
    Expression iniConcentrationExpr = null;
    Structure structure = getSpeciesContext().getStructure();
    double structSize = computeStructureSize();
    if (structure instanceof Membrane) {
        // iniConcentration(molecules/um2) = particles/size(um2)
        try {
            iniConcentrationExpr = new Expression((iniParticles.evaluateConstant() * 1.0) / structSize);
        } catch (ExpressionException e) {
            iniConcentrationExpr = Expression.div(iniParticles, new Expression(structSize)).flatten();
        }
    } else {
        // convert concentration(particles/volume) to number of particles
        // particles = [iniParticles(uM)/size(um3)]*KMOLE
        // @Note : 'kMole' variable here is used only as a var name, it does not represent the previously known ReservedSymbol KMOLE.
        ModelUnitSystem modelUnitSystem = getSimulationContext().getModel().getUnitSystem();
        VCUnitDefinition stochasticToVolSubstance = modelUnitSystem.getVolumeSubstanceUnit().divideBy(modelUnitSystem.getStochasticSubstanceUnit());
        double stochasticToVolSubstanceScale = stochasticToVolSubstance.getDimensionlessScale().doubleValue();
        try {
            iniConcentrationExpr = new Expression((iniParticles.evaluateConstant() * stochasticToVolSubstanceScale / structSize));
        } catch (ExpressionException e) {
            Expression numeratorExpr = Expression.mult(iniParticles, new Expression(stochasticToVolSubstanceScale));
            Expression denominatorExpr = new Expression(structSize);
            iniConcentrationExpr = Expression.div(numeratorExpr, denominatorExpr).flatten();
        }
    }
    return iniConcentrationExpr;
}
Also used : VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) ExpressionException(cbit.vcell.parser.ExpressionException) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 24 with Structure

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

the class SpeciesContextSpec method computeStructureSize.

private double computeStructureSize() throws ExpressionException, MappingException {
    Structure structure = getSpeciesContext().getStructure();
    StructureMapping sm = getSimulationContext().getGeometryContext().getStructureMapping(structure);
    double structSize = 0;
    if (getSimulationContext().getGeometry().getDimension() == 0) {
        Expression sizeParameterExpression = sm.getSizeParameter().getExpression();
        if (sizeParameterExpression == null || sizeParameterExpression.isZero()) {
            throw new RuntimeException("\nIn application '" + getSimulationContext().getName() + "', " + "size of structure '" + structure.getName() + "' is required to convert " + "concentration to number of particles.\n\nPlease go to 'Structure Mapping' tab to check the size.");
        }
        structSize = sizeParameterExpression.evaluateConstant();
    } else {
        StructureMapping structureMapping = getSimulationContext().getGeometryContext().getStructureMapping(structure);
        GeometryClass gc = structureMapping.getGeometryClass();
        if (gc == null) {
            throw new MappingException("model structure '" + structure.getName() + "' not mapped to a geometry subdomain");
        }
        try {
            GeometricRegion[] geometricRegions = getSimulationContext().getGeometry().getGeometrySurfaceDescription().getGeometricRegions(gc);
            if (geometricRegions == null) {
                throw new MappingException("Geometry is not updated.");
            }
            for (GeometricRegion gr : geometricRegions) {
                structSize += gr.getSize();
            }
        } catch (Exception ex) {
        }
    }
    return structSize;
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) Expression(cbit.vcell.parser.Expression) Structure(cbit.vcell.model.Structure) PropertyVetoException(java.beans.PropertyVetoException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ModelException(cbit.vcell.model.ModelException) ExpressionException(cbit.vcell.parser.ExpressionException) GeometricRegion(cbit.vcell.geometry.surface.GeometricRegion)

Example 25 with Structure

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

the class StochMathMapping method refreshMathDescription.

/**
 * set up a math description based on current simulationContext.
 */
@Override
protected void refreshMathDescription() throws MappingException, MatrixException, MathException, ExpressionException, ModelException {
    // use local variable instead of using getter all the time.
    SimulationContext simContext = getSimulationContext();
    GeometryClass geometryClass = simContext.getGeometry().getGeometrySpec().getSubVolumes()[0];
    Domain domain = new Domain(geometryClass);
    // local structure mapping list
    StructureMapping[] structureMappings = simContext.getGeometryContext().getStructureMappings();
    // We have to check if all the reactions are able to tranform to stochastic jump processes before generating the math.
    String stochChkMsg = simContext.getModel().isValidForStochApp();
    if (!(stochChkMsg.equals(""))) {
        throw new ModelException("Problem updating math description: " + simContext.getName() + "\n" + stochChkMsg);
    }
    simContext.checkValidity();
    // 
    if (simContext.getGeometry().getDimension() > 0) {
        throw new MappingException("nonspatial stochastic math mapping requires 0-dimensional geometry");
    }
    // 
    for (int i = 0; i < structureMappings.length; i++) {
        if (structureMappings[i] instanceof MembraneMapping) {
            if (((MembraneMapping) structureMappings[i]).getCalculateVoltage()) {
                throw new MappingException("electric potential not yet supported for particle models");
            }
        }
    }
    // 
    // fail if any events
    // 
    BioEvent[] bioEvents = simContext.getBioEvents();
    if (bioEvents != null && bioEvents.length > 0) {
        throw new MappingException("events not yet supported for particle-based models");
    }
    // 
    // verify that all structures are mapped to subvolumes and all subvolumes are mapped to a structure
    // 
    Structure[] structures = simContext.getGeometryContext().getModel().getStructures();
    for (int i = 0; i < structures.length; i++) {
        StructureMapping sm = simContext.getGeometryContext().getStructureMapping(structures[i]);
        if (sm == null || (sm instanceof FeatureMapping && ((FeatureMapping) sm).getGeometryClass() == null)) {
            throw new MappingException("model structure '" + structures[i].getName() + "' not mapped to a geometry subVolume");
        }
        if (sm != null && (sm instanceof MembraneMapping) && ((MembraneMapping) sm).getVolumeFractionParameter() != null) {
            Expression volFractExp = ((MembraneMapping) sm).getVolumeFractionParameter().getExpression();
            try {
                if (volFractExp != null) {
                    double volFract = volFractExp.evaluateConstant();
                    if (volFract >= 1.0) {
                        throw new MappingException("model structure '" + (getSimulationContext().getModel().getStructureTopology().getInsideFeature(((MembraneMapping) sm).getMembrane()).getName() + "' has volume fraction >= 1.0"));
                    }
                }
            } catch (ExpressionException e) {
                e.printStackTrace(System.out);
            }
        }
    }
    SubVolume[] subVolumes = simContext.getGeometryContext().getGeometry().getGeometrySpec().getSubVolumes();
    for (int i = 0; i < subVolumes.length; i++) {
        Structure[] mappedStructures = simContext.getGeometryContext().getStructuresFromGeometryClass(subVolumes[i]);
        if (mappedStructures == null || mappedStructures.length == 0) {
            throw new MappingException("geometry subVolume '" + subVolumes[i].getName() + "' not mapped from a model structure");
        }
    }
    // 
    // gather only those reactionSteps that are not "excluded"
    // 
    ReactionSpec[] reactionSpecs = simContext.getReactionContext().getReactionSpecs();
    Vector<ReactionStep> rsList = new Vector<ReactionStep>();
    for (int i = 0; i < reactionSpecs.length; i++) {
        if (!reactionSpecs[i].isExcluded()) {
            rsList.add(reactionSpecs[i].getReactionStep());
        }
    }
    // 
    for (ReactionStep reactionStep : rsList) {
        Kinetics.UnresolvedParameter[] unresolvedParameters = reactionStep.getKinetics().getUnresolvedParameters();
        if (unresolvedParameters != null && unresolvedParameters.length > 0) {
            StringBuffer buffer = new StringBuffer();
            for (int j = 0; j < unresolvedParameters.length; j++) {
                if (j > 0) {
                    buffer.append(", ");
                }
                buffer.append(unresolvedParameters[j].getName());
            }
            throw new MappingException("In Application '" + simContext.getName() + "', " + reactionStep.getDisplayType() + " '" + reactionStep.getName() + "' contains unresolved identifier(s): " + buffer);
        }
    }
    // 
    // create new MathDescription (based on simContext's previous MathDescription if possible)
    // 
    MathDescription oldMathDesc = simContext.getMathDescription();
    mathDesc = null;
    if (oldMathDesc != null) {
        if (oldMathDesc.getVersion() != null) {
            mathDesc = new MathDescription(oldMathDesc.getVersion());
        } else {
            mathDesc = new MathDescription(oldMathDesc.getName());
        }
    } else {
        mathDesc = new MathDescription(simContext.getName() + "_generated");
    }
    // 
    // temporarily place all variables in a hashtable (before binding) and discarding duplicates
    // 
    VariableHash varHash = new VariableHash();
    // 
    // conversion factors
    // 
    Model model = simContext.getModel();
    varHash.addVariable(new Constant(getMathSymbol(model.getKMOLE(), null), getIdentifierSubstitutions(model.getKMOLE().getExpression(), model.getKMOLE().getUnitDefinition(), null)));
    varHash.addVariable(new Constant(getMathSymbol(model.getN_PMOLE(), null), getIdentifierSubstitutions(model.getN_PMOLE().getExpression(), model.getN_PMOLE().getUnitDefinition(), null)));
    varHash.addVariable(new Constant(getMathSymbol(model.getPI_CONSTANT(), null), getIdentifierSubstitutions(model.getPI_CONSTANT().getExpression(), model.getPI_CONSTANT().getUnitDefinition(), null)));
    varHash.addVariable(new Constant(getMathSymbol(model.getFARADAY_CONSTANT(), null), getIdentifierSubstitutions(model.getFARADAY_CONSTANT().getExpression(), model.getFARADAY_CONSTANT().getUnitDefinition(), null)));
    varHash.addVariable(new Constant(getMathSymbol(model.getFARADAY_CONSTANT_NMOLE(), null), getIdentifierSubstitutions(model.getFARADAY_CONSTANT_NMOLE().getExpression(), model.getFARADAY_CONSTANT_NMOLE().getUnitDefinition(), null)));
    varHash.addVariable(new Constant(getMathSymbol(model.getGAS_CONSTANT(), null), getIdentifierSubstitutions(model.getGAS_CONSTANT().getExpression(), model.getGAS_CONSTANT().getUnitDefinition(), null)));
    varHash.addVariable(new Constant(getMathSymbol(model.getTEMPERATURE(), null), getIdentifierSubstitutions(new Expression(simContext.getTemperatureKelvin()), model.getTEMPERATURE().getUnitDefinition(), null)));
    Enumeration<SpeciesContextMapping> enum1 = getSpeciesContextMappings();
    while (enum1.hasMoreElements()) {
        SpeciesContextMapping scm = enum1.nextElement();
        if (scm.getVariable() instanceof StochVolVariable) {
            varHash.addVariable(scm.getVariable());
        }
    }
    // deals with model parameters
    ModelParameter[] modelParameters = simContext.getModel().getModelParameters();
    for (int j = 0; j < modelParameters.length; j++) {
        Expression expr = getSubstitutedExpr(modelParameters[j].getExpression(), true, false);
        expr = getIdentifierSubstitutions(expr, modelParameters[j].getUnitDefinition(), geometryClass);
        varHash.addVariable(newFunctionOrConstant(getMathSymbol(modelParameters[j], geometryClass), expr, geometryClass));
    }
    // added July 2009, ElectricalStimulusParameter electric mapping tab
    ElectricalStimulus[] elecStimulus = simContext.getElectricalStimuli();
    if (elecStimulus.length > 0) {
        throw new MappingException("Modles with electrophysiology are not supported for stochastic applications.");
    }
    for (int j = 0; j < structureMappings.length; j++) {
        if (structureMappings[j] instanceof MembraneMapping) {
            MembraneMapping memMapping = (MembraneMapping) structureMappings[j];
            Parameter initialVoltageParm = memMapping.getInitialVoltageParameter();
            try {
                Expression exp = initialVoltageParm.getExpression();
                exp.evaluateConstant();
                varHash.addVariable(newFunctionOrConstant(getMathSymbol(memMapping.getMembrane().getMembraneVoltage(), memMapping.getGeometryClass()), getIdentifierSubstitutions(memMapping.getInitialVoltageParameter().getExpression(), memMapping.getInitialVoltageParameter().getUnitDefinition(), memMapping.getGeometryClass()), memMapping.getGeometryClass()));
            } catch (ExpressionException e) {
                e.printStackTrace(System.out);
                throw new MappingException("Membrane initial voltage: " + initialVoltageParm.getName() + " cannot be evaluated as constant.");
            }
        }
    }
    // 
    for (ReactionStep rs : rsList) {
        if (rs.getKinetics() instanceof LumpedKinetics) {
            throw new RuntimeException("Lumped Kinetics not yet supported for Stochastic Math Generation");
        }
        Kinetics.KineticsParameter[] parameters = rs.getKinetics().getKineticsParameters();
        for (KineticsParameter parameter : parameters) {
            // 
            if ((parameter.getRole() == Kinetics.ROLE_CurrentDensity) && (parameter.getExpression() == null || parameter.getExpression().isZero())) {
                continue;
            }
            // 
            // don't add rate, we'll do it later when creating the jump processes
            // 
            // if (parameter.getRole() == Kinetics.ROLE_ReactionRate) {
            // continue;
            // }
            // 
            // don't add mass action reverse parameter if irreversible
            // 
            // if (!rs.isReversible() && parameters[i].getRole() == Kinetics.ROLE_KReverse){
            // continue;
            // }
            Expression expr = getSubstitutedExpr(parameter.getExpression(), true, false);
            varHash.addVariable(newFunctionOrConstant(getMathSymbol(parameter, geometryClass), getIdentifierSubstitutions(expr, parameter.getUnitDefinition(), geometryClass), geometryClass));
        }
    }
    // the parameter "Size" is already put into mathsymbolmapping in refreshSpeciesContextMapping()
    for (int i = 0; i < structureMappings.length; i++) {
        StructureMapping sm = structureMappings[i];
        StructureMapping.StructureMappingParameter parm = sm.getParameterFromRole(StructureMapping.ROLE_Size);
        if (parm.getExpression() != null) {
            try {
                double value = parm.getExpression().evaluateConstant();
                varHash.addVariable(new Constant(getMathSymbol(parm, sm.getGeometryClass()), new Expression(value)));
            } catch (ExpressionException e) {
                // varHash.addVariable(new Function(getMathSymbol0(parm,sm),getIdentifierSubstitutions(parm.getExpression(),parm.getUnitDefinition(),sm)));
                e.printStackTrace(System.out);
                throw new MappingException("Size of structure:" + sm.getNameScope().getName() + " cannot be evaluated as constant.");
            }
        }
    }
    SpeciesContextSpec[] speciesContextSpecs = getSimulationContext().getReactionContext().getSpeciesContextSpecs();
    addInitialConditions(domain, speciesContextSpecs, varHash);
    // 
    // constant species (either function or constant)
    // 
    enum1 = getSpeciesContextMappings();
    while (enum1.hasMoreElements()) {
        SpeciesContextMapping scm = (SpeciesContextMapping) enum1.nextElement();
        if (scm.getVariable() instanceof Constant) {
            varHash.addVariable(scm.getVariable());
        }
    }
    // 
    if (simContext.getGeometryContext().getGeometry() != null) {
        try {
            mathDesc.setGeometry(simContext.getGeometryContext().getGeometry());
        } catch (java.beans.PropertyVetoException e) {
            e.printStackTrace(System.out);
            throw new MappingException("failure setting geometry " + e.getMessage());
        }
    } else {
        throw new MappingException("Geometry must be defined in Application " + simContext.getName());
    }
    // 
    // create subDomains
    // 
    SubVolume subVolume = simContext.getGeometry().getGeometrySpec().getSubVolumes()[0];
    SubDomain subDomain = new CompartmentSubDomain(subVolume.getName(), 0);
    mathDesc.addSubDomain(subDomain);
    // 
    // functions: species which is not a variable, but has dependency expression
    // 
    enum1 = getSpeciesContextMappings();
    while (enum1.hasMoreElements()) {
        SpeciesContextMapping scm = (SpeciesContextMapping) enum1.nextElement();
        if (scm.getVariable() == null && scm.getDependencyExpression() != null) {
            StructureMapping sm = simContext.getGeometryContext().getStructureMapping(scm.getSpeciesContext().getStructure());
            Expression exp = scm.getDependencyExpression();
            exp.bindExpression(this);
            SpeciesCountParameter spCountParam = getSpeciesCountParameter(scm.getSpeciesContext());
            varHash.addVariable(new Function(getMathSymbol(spCountParam, sm.getGeometryClass()), getIdentifierSubstitutions(exp, spCountParam.getUnitDefinition(), sm.getGeometryClass()), domain));
        }
    }
    addJumpProcesses(varHash, geometryClass, subDomain);
    // 
    for (int i = 0; i < fieldMathMappingParameters.length; i++) {
        if (fieldMathMappingParameters[i] instanceof UnitFactorParameter) {
            varHash.addVariable(newFunctionOrConstant(getMathSymbol(fieldMathMappingParameters[i], geometryClass), getIdentifierSubstitutions(fieldMathMappingParameters[i].getExpression(), fieldMathMappingParameters[i].getUnitDefinition(), geometryClass), fieldMathMappingParameters[i].getGeometryClass()));
        }
    }
    // 
    // set Variables to MathDescription all at once with the order resolved by "VariableHash"
    // 
    mathDesc.setAllVariables(varHash.getAlphabeticallyOrderedVariables());
    // 
    // set up variable initial conditions in subDomain
    // 
    SpeciesContextSpec[] scSpecs = simContext.getReactionContext().getSpeciesContextSpecs();
    for (int i = 0; i < speciesContextSpecs.length; i++) {
        // get stochastic variable by name
        SpeciesCountParameter spCountParam = getSpeciesCountParameter(speciesContextSpecs[i].getSpeciesContext());
        StructureMapping sm = simContext.getGeometryContext().getStructureMapping(speciesContextSpecs[i].getSpeciesContext().getStructure());
        String varName = getMathSymbol(spCountParam, sm.getGeometryClass());
        StochVolVariable var = (StochVolVariable) mathDesc.getVariable(varName);
        // stochastic use initial number of particles
        SpeciesContextSpec.SpeciesContextSpecParameter initParm = scSpecs[i].getInitialCountParameter();
        // stochastic variables initial expression.
        if (initParm != null) {
            VarIniCondition varIni = null;
            if (!scSpecs[i].isConstant() && getSimulationContext().isRandomizeInitCondition()) {
                varIni = new VarIniPoissonExpectedCount(var, new Expression(getMathSymbol(initParm, sm.getGeometryClass())));
            } else {
                varIni = new VarIniCount(var, new Expression(getMathSymbol(initParm, sm.getGeometryClass())));
            }
            subDomain.addVarIniCondition(varIni);
        }
    }
    // 
    for (int i = 0; i < fieldMathMappingParameters.length; i++) {
        if (fieldMathMappingParameters[i] instanceof UnitFactorParameter) {
            Variable variable = newFunctionOrConstant(getMathSymbol(fieldMathMappingParameters[i], geometryClass), getIdentifierSubstitutions(fieldMathMappingParameters[i].getExpression(), fieldMathMappingParameters[i].getUnitDefinition(), geometryClass), fieldMathMappingParameters[i].getGeometryClass());
            if (mathDesc.getVariable(variable.getName()) == null) {
                mathDesc.addVariable(variable);
            }
        }
        if (fieldMathMappingParameters[i] instanceof ObservableCountParameter) {
            Variable variable = newFunctionOrConstant(getMathSymbol(fieldMathMappingParameters[i], geometryClass), getIdentifierSubstitutions(fieldMathMappingParameters[i].getExpression(), fieldMathMappingParameters[i].getUnitDefinition(), geometryClass), fieldMathMappingParameters[i].getGeometryClass());
            if (mathDesc.getVariable(variable.getName()) == null) {
                mathDesc.addVariable(variable);
            }
        }
    }
    if (!mathDesc.isValid()) {
        System.out.println(mathDesc.getVCML_database());
        throw new MappingException("generated an invalid mathDescription: " + mathDesc.getWarning());
    }
}
Also used : VarIniCondition(cbit.vcell.math.VarIniCondition) LumpedKinetics(cbit.vcell.model.LumpedKinetics) MathDescription(cbit.vcell.math.MathDescription) ExpressionException(cbit.vcell.parser.ExpressionException) PropertyVetoException(java.beans.PropertyVetoException) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubDomain(cbit.vcell.math.SubDomain) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) SubVolume(cbit.vcell.geometry.SubVolume) Vector(java.util.Vector) ModelException(cbit.vcell.model.ModelException) ModelParameter(cbit.vcell.model.Model.ModelParameter) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) ReactionStep(cbit.vcell.model.ReactionStep) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubDomain(cbit.vcell.math.SubDomain) Domain(cbit.vcell.math.Variable.Domain) GeometryClass(cbit.vcell.geometry.GeometryClass) StochVolVariable(cbit.vcell.math.StochVolVariable) Variable(cbit.vcell.math.Variable) VariableHash(cbit.vcell.math.VariableHash) Constant(cbit.vcell.math.Constant) VarIniPoissonExpectedCount(cbit.vcell.math.VarIniPoissonExpectedCount) Function(cbit.vcell.math.Function) Structure(cbit.vcell.model.Structure) StochVolVariable(cbit.vcell.math.StochVolVariable) VarIniCount(cbit.vcell.math.VarIniCount) Expression(cbit.vcell.parser.Expression) Model(cbit.vcell.model.Model) Parameter(cbit.vcell.model.Parameter) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) ModelParameter(cbit.vcell.model.Model.ModelParameter)

Aggregations

Structure (cbit.vcell.model.Structure)159 SpeciesContext (cbit.vcell.model.SpeciesContext)57 Membrane (cbit.vcell.model.Membrane)47 PropertyVetoException (java.beans.PropertyVetoException)42 Feature (cbit.vcell.model.Feature)36 Model (cbit.vcell.model.Model)35 ArrayList (java.util.ArrayList)35 ReactionStep (cbit.vcell.model.ReactionStep)33 Expression (cbit.vcell.parser.Expression)33 ReactionRule (cbit.vcell.model.ReactionRule)27 ExpressionException (cbit.vcell.parser.ExpressionException)27 BioModel (cbit.vcell.biomodel.BioModel)23 StructureMapping (cbit.vcell.mapping.StructureMapping)22 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)22 Species (cbit.vcell.model.Species)21 MolecularType (org.vcell.model.rbm.MolecularType)20 ReactionParticipant (cbit.vcell.model.ReactionParticipant)19 SimpleReaction (cbit.vcell.model.SimpleReaction)19 SimulationContext (cbit.vcell.mapping.SimulationContext)18 ModelException (cbit.vcell.model.ModelException)18