Search in sources :

Example 6 with VolumeParticleSpeciesPattern

use of cbit.vcell.math.VolumeParticleSpeciesPattern in project vcell by virtualcell.

the class RulebasedMathMapping method addSpeciesPatterns.

private HashMap<SpeciesPattern, VolumeParticleSpeciesPattern> addSpeciesPatterns(Domain domain, List<ReactionRule> rrList) throws MathException {
    // Particle Molecular Types
    // 
    Model model = getSimulationContext().getModel();
    List<RbmObservable> observableList = model.getRbmModelContainer().getObservableList();
    List<MolecularType> molecularTypeList = model.getRbmModelContainer().getMolecularTypeList();
    for (MolecularType molecularType : molecularTypeList) {
        ParticleMolecularType particleMolecularType = new ParticleMolecularType(molecularType.getName());
        for (MolecularComponent molecularComponent : molecularType.getComponentList()) {
            String pmcName = molecularComponent.getName();
            String pmcId = particleMolecularType.getName() + "_" + molecularComponent.getName();
            ParticleMolecularComponent particleMolecularComponent = new ParticleMolecularComponent(pmcId, pmcName);
            for (ComponentStateDefinition componentState : molecularComponent.getComponentStateDefinitions()) {
                ParticleComponentStateDefinition pcsd = particleMolecularComponent.getComponentStateDefinition(componentState.getName());
                if (pcsd == null) {
                    particleMolecularComponent.addComponentStateDefinition(new ParticleComponentStateDefinition(componentState.getName()));
                }
            }
            particleMolecularType.addMolecularComponent(particleMolecularComponent);
        }
        if (!molecularType.isAnchorAll()) {
            List<String> anchorList = new ArrayList<>();
            for (Structure struct : molecularType.getAnchors()) {
                anchorList.add(struct.getName());
            }
            particleMolecularType.setAnchorList(anchorList);
        }
        mathDesc.addParticleMolecularType(particleMolecularType);
    }
    // 
    // Assemble list of all Species Patterns (from observables, reaction rules, and seed species).
    // 
    // linked hash set maintains insertion order
    LinkedHashMap<SpeciesPattern, Structure> speciesPatternStructureMap = new LinkedHashMap<SpeciesPattern, Structure>();
    for (RbmObservable observable : observableList) {
        for (SpeciesPattern speciesPattern : observable.getSpeciesPatternList()) {
            speciesPatternStructureMap.put(speciesPattern, observable.getStructure());
        }
    }
    for (ReactionRule reactionRule : rrList) {
        for (ReactantPattern rp : reactionRule.getReactantPatterns()) {
            speciesPatternStructureMap.put(rp.getSpeciesPattern(), rp.getStructure());
        }
        for (ProductPattern pp : reactionRule.getProductPatterns()) {
            speciesPatternStructureMap.put(pp.getSpeciesPattern(), pp.getStructure());
        }
    }
    for (SpeciesContext sc : model.getSpeciesContexts()) {
        if (!sc.hasSpeciesPattern()) {
            continue;
        }
        speciesPatternStructureMap.put(sc.getSpeciesPattern(), sc.getStructure());
    }
    // 
    // add list of unique speciesPatterns
    // 
    HashMap<String, VolumeParticleSpeciesPattern> speciesPatternVCMLMap = new HashMap<String, VolumeParticleSpeciesPattern>();
    HashMap<SpeciesPattern, VolumeParticleSpeciesPattern> speciesPatternMap = new HashMap<SpeciesPattern, VolumeParticleSpeciesPattern>();
    String speciesPatternName = "speciesPattern0";
    for (SpeciesPattern speciesPattern : speciesPatternStructureMap.keySet()) {
        VolumeParticleSpeciesPattern volumeParticleSpeciesPattern = new VolumeParticleSpeciesPattern(speciesPatternName, domain, speciesPatternStructureMap.get(speciesPattern).getName());
        for (MolecularTypePattern molecularTypePattern : speciesPattern.getMolecularTypePatterns()) {
            ParticleMolecularType particleMolecularType = mathDesc.getParticleMolecularType(molecularTypePattern.getMolecularType().getName());
            ParticleMolecularTypePattern particleMolecularTypePattern = new ParticleMolecularTypePattern(particleMolecularType);
            String participantMatchLabel = molecularTypePattern.getParticipantMatchLabel();
            if (molecularTypePattern.getParticipantMatchLabel() != null) {
                particleMolecularTypePattern.setMatchLabel(participantMatchLabel);
            }
            for (MolecularComponentPattern molecularComponentPattern : molecularTypePattern.getComponentPatternList()) {
                MolecularComponent molecularComponent = molecularComponentPattern.getMolecularComponent();
                ParticleMolecularComponent particleMolecularComponent = particleMolecularType.getMolecularComponent(molecularComponent.getName());
                ParticleMolecularComponentPattern particleMolecularComponentPattern = new ParticleMolecularComponentPattern(particleMolecularComponent);
                ComponentStatePattern componentState = molecularComponentPattern.getComponentStatePattern();
                if (componentState != null) {
                    if (componentState.isAny()) {
                        ParticleComponentStatePattern pcsp = new ParticleComponentStatePattern();
                        particleMolecularComponentPattern.setComponentStatePattern(pcsp);
                    } else {
                        String name = componentState.getComponentStateDefinition().getName();
                        ParticleComponentStateDefinition pcsd = particleMolecularComponent.getComponentStateDefinition(name);
                        // ParticleComponentStateDefinition pcsd = new ParticleComponentStateDefinition(componentState.getComponentStateDefinition().getName());
                        // particleMolecularComponent.addComponentStateDefinition(pcsd);
                        ParticleComponentStatePattern pcsp = new ParticleComponentStatePattern(pcsd);
                        particleMolecularComponentPattern.setComponentStatePattern(pcsp);
                    }
                } else {
                    ParticleComponentStatePattern pcsp = new ParticleComponentStatePattern();
                    particleMolecularComponentPattern.setComponentStatePattern(pcsp);
                }
                switch(molecularComponentPattern.getBondType()) {
                    case Specified:
                        {
                            particleMolecularComponentPattern.setBondType(ParticleBondType.Specified);
                            particleMolecularComponentPattern.setBondId(molecularComponentPattern.getBondId());
                            break;
                        }
                    case Exists:
                        {
                            particleMolecularComponentPattern.setBondType(ParticleBondType.Exists);
                            particleMolecularComponentPattern.setBondId(-1);
                            break;
                        }
                    case None:
                        {
                            particleMolecularComponentPattern.setBondType(ParticleBondType.None);
                            particleMolecularComponentPattern.setBondId(-1);
                            break;
                        }
                    case Possible:
                        {
                            particleMolecularComponentPattern.setBondType(ParticleBondType.Possible);
                            particleMolecularComponentPattern.setBondId(-1);
                            break;
                        }
                }
                particleMolecularTypePattern.addMolecularComponentPattern(particleMolecularComponentPattern);
            }
            volumeParticleSpeciesPattern.addMolecularTypePattern(particleMolecularTypePattern);
        }
        String speciesPatternVCML = volumeParticleSpeciesPattern.getVCML("tempName");
        VolumeParticleSpeciesPattern uniqueVolumeParticleSpeciesPattern = speciesPatternVCMLMap.get(speciesPatternVCML);
        if (uniqueVolumeParticleSpeciesPattern == null) {
            speciesPatternVCMLMap.put(speciesPatternVCML, volumeParticleSpeciesPattern);
            speciesPatternName = TokenMangler.getNextEnumeratedToken(speciesPatternName);
            speciesPatternMap.put(speciesPattern, volumeParticleSpeciesPattern);
        } else {
            speciesPatternMap.put(speciesPattern, uniqueVolumeParticleSpeciesPattern);
        }
    }
    return speciesPatternMap;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ParticleMolecularComponent(cbit.vcell.math.ParticleMolecularComponent) SpeciesContext(cbit.vcell.model.SpeciesContext) VolumeParticleSpeciesPattern(cbit.vcell.math.VolumeParticleSpeciesPattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition) ParticleComponentStateDefinition(cbit.vcell.math.ParticleComponentStateDefinition) LinkedHashMap(java.util.LinkedHashMap) ParticleMolecularComponent(cbit.vcell.math.ParticleMolecularComponent) MolecularComponent(org.vcell.model.rbm.MolecularComponent) ParticleComponentStateDefinition(cbit.vcell.math.ParticleComponentStateDefinition) ParticleMolecularComponentPattern(cbit.vcell.math.ParticleMolecularComponentPattern) Structure(cbit.vcell.model.Structure) ParticleMolecularType(cbit.vcell.math.ParticleMolecularType) ReactantPattern(cbit.vcell.model.ReactantPattern) ReactionRule(cbit.vcell.model.ReactionRule) ProductPattern(cbit.vcell.model.ProductPattern) ParticleMolecularComponentPattern(cbit.vcell.math.ParticleMolecularComponentPattern) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ParticleComponentStatePattern(cbit.vcell.math.ParticleComponentStatePattern) RbmObservable(cbit.vcell.model.RbmObservable) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) ParticleComponentStatePattern(cbit.vcell.math.ParticleComponentStatePattern) VolumeParticleSpeciesPattern(cbit.vcell.math.VolumeParticleSpeciesPattern) ParticleMolecularTypePattern(cbit.vcell.math.ParticleMolecularTypePattern) ParticleMolecularType(cbit.vcell.math.ParticleMolecularType) MolecularType(org.vcell.model.rbm.MolecularType) Model(cbit.vcell.model.Model) ParticleMolecularTypePattern(cbit.vcell.math.ParticleMolecularTypePattern) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern)

Example 7 with VolumeParticleSpeciesPattern

use of cbit.vcell.math.VolumeParticleSpeciesPattern in project vcell by virtualcell.

the class RulebasedMathMapping method refreshMathDescription.

/**
 * This method was created in VisualAge.
 */
@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 transform 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("rule-based particle math mapping not implemented for spatial geometry - dimension >= 1");
    }
    // 
    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 reactionRules that are not "excluded"
    // 
    ArrayList<ReactionRule> rrList = new ArrayList<ReactionRule>();
    for (ReactionRuleSpec reactionRuleSpec : simContext.getReactionContext().getReactionRuleSpecs()) {
        if (!reactionRuleSpec.isExcluded()) {
            rrList.add(reactionRuleSpec.getReactionRule());
        }
    }
    // 
    for (ReactionRule reactionRule : rrList) {
        UnresolvedParameter[] unresolvedParameters = reactionRule.getKineticLaw().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() + "', " + reactionRule.getDisplayType() + " '" + reactionRule.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 (ReactionRule reactionRule : rrList) {
        // if (reactionRule.getKineticLaw() instanceof LumpedKinetics){
        // throw new RuntimeException("Lumped Kinetics not yet supported for RuleBased Modeling");
        // }
        LocalParameter[] parameters = reactionRule.getKineticLaw().getLocalParameters();
        for (LocalParameter parameter : parameters) {
            // 
            if ((parameter.getRole() == RbmKineticLawParameterType.RuleRate)) {
                continue;
            }
            // 
            if (!reactionRule.isReversible() && parameter.getRole() == RbmKineticLawParameterType.MassActionReverseRate) {
                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);
    // 
    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);
    // 
    // define all molecules and unique species patterns (add molecules to mathDesc and speciesPatterns to varHash).
    // 
    HashMap<SpeciesPattern, VolumeParticleSpeciesPattern> speciesPatternMap = addSpeciesPatterns(domain, rrList);
    HashSet<VolumeParticleSpeciesPattern> uniqueParticleSpeciesPatterns = new HashSet<>(speciesPatternMap.values());
    for (VolumeParticleSpeciesPattern volumeParticleSpeciesPattern : uniqueParticleSpeciesPatterns) {
        varHash.addVariable(volumeParticleSpeciesPattern);
    }
    // 
    // define observables (those explicitly declared and those corresponding to seed species.
    // 
    List<ParticleObservable> observables = addObservables(geometryClass, domain, speciesPatternMap);
    for (ParticleObservable particleObservable : observables) {
        varHash.addVariable(particleObservable);
    }
    try {
        addParticleJumpProcesses(varHash, geometryClass, subDomain, speciesPatternMap);
    } catch (PropertyVetoException e1) {
        e1.printStackTrace();
        throw new MappingException(e1.getMessage(), e1);
    }
    // 
    for (int i = 0; i < fieldMathMappingParameters.length; i++) {
        if (fieldMathMappingParameters[i] instanceof UnitFactorParameter || fieldMathMappingParameters[i] instanceof ObservableConcentrationParameter) {
            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());
    // 
    for (SpeciesContext sc : model.getSpeciesContexts()) {
        if (!sc.hasSpeciesPattern()) {
            throw new MappingException("species " + sc.getName() + " has no molecular pattern");
        }
        VolumeParticleSpeciesPattern volumeParticleSpeciesPattern = speciesPatternMap.get(sc.getSpeciesPattern());
        ArrayList<ParticleInitialCondition> particleInitialConditions = new ArrayList<ParticleProperties.ParticleInitialCondition>();
        // initial conditions from scs
        SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(sc);
        Parameter initialCountParameter = scs.getInitialCountParameter();
        Expression e = getIdentifierSubstitutions(new Expression(initialCountParameter, getNameScope()), initialCountParameter.getUnitDefinition(), geometryClass);
        particleInitialConditions.add(new ParticleInitialConditionCount(e, new Expression(0.0), new Expression(0.0), new Expression(0.0)));
        ParticleProperties particleProperies = new ParticleProperties(volumeParticleSpeciesPattern, new Expression(0.0), new Expression(0.0), new Expression(0.0), new Expression(0.0), particleInitialConditions);
        subDomain.addParticleProperties(particleProperies);
    }
    // 
    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 ObservableConcentrationParameter) {
            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 : MathDescription(cbit.vcell.math.MathDescription) ArrayList(java.util.ArrayList) SpeciesContext(cbit.vcell.model.SpeciesContext) ExpressionException(cbit.vcell.parser.ExpressionException) PropertyVetoException(java.beans.PropertyVetoException) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubDomain(cbit.vcell.math.SubDomain) SubVolume(cbit.vcell.geometry.SubVolume) HashSet(java.util.HashSet) ModelException(cbit.vcell.model.ModelException) VolumeParticleSpeciesPattern(cbit.vcell.math.VolumeParticleSpeciesPattern) PropertyVetoException(java.beans.PropertyVetoException) ModelParameter(cbit.vcell.model.Model.ModelParameter) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) ParticleInitialCondition(cbit.vcell.math.ParticleProperties.ParticleInitialCondition) ParticleProperties(cbit.vcell.math.ParticleProperties) VolumeParticleObservable(cbit.vcell.math.VolumeParticleObservable) ParticleObservable(cbit.vcell.math.ParticleObservable) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubDomain(cbit.vcell.math.SubDomain) Domain(cbit.vcell.math.Variable.Domain) GeometryClass(cbit.vcell.geometry.GeometryClass) VolumeParticleVariable(cbit.vcell.math.VolumeParticleVariable) ParticleVariable(cbit.vcell.math.ParticleVariable) StochVolVariable(cbit.vcell.math.StochVolVariable) Variable(cbit.vcell.math.Variable) VariableHash(cbit.vcell.math.VariableHash) MacroscopicRateConstant(cbit.vcell.math.MacroscopicRateConstant) Constant(cbit.vcell.math.Constant) UnresolvedParameter(cbit.vcell.mapping.ParameterContext.UnresolvedParameter) VolumeParticleSpeciesPattern(cbit.vcell.math.VolumeParticleSpeciesPattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) Structure(cbit.vcell.model.Structure) StochVolVariable(cbit.vcell.math.StochVolVariable) ReactionRule(cbit.vcell.model.ReactionRule) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) Expression(cbit.vcell.parser.Expression) Model(cbit.vcell.model.Model) Parameter(cbit.vcell.model.Parameter) UnresolvedParameter(cbit.vcell.mapping.ParameterContext.UnresolvedParameter) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) ModelParameter(cbit.vcell.model.Model.ModelParameter) ParticleInitialConditionCount(cbit.vcell.math.ParticleProperties.ParticleInitialConditionCount)

Example 8 with VolumeParticleSpeciesPattern

use of cbit.vcell.math.VolumeParticleSpeciesPattern in project vcell by virtualcell.

the class RulebasedMathMapping method addObservables.

private List<ParticleObservable> addObservables(GeometryClass geometryClass, Domain domain, HashMap<SpeciesPattern, VolumeParticleSpeciesPattern> speciesPatternMap) throws MappingException, MathException {
    ArrayList<ParticleObservable> observables = new ArrayList<>();
    // 
    for (MathMappingParameter mathMappingParameter : getMathMappingParameters()) {
        if (mathMappingParameter instanceof ObservableCountParameter) {
            ObservableCountParameter observableCountParameter = (ObservableCountParameter) mathMappingParameter;
            RbmObservable rbmObservable = observableCountParameter.getObservable();
            ParticleObservable.ObservableType particleObservableType = null;
            if (rbmObservable.getType() == RbmObservable.ObservableType.Molecules) {
                particleObservableType = ParticleObservable.ObservableType.Molecules;
            } else {
                particleObservableType = ParticleObservable.ObservableType.Species;
            }
            ParticleObservable particleObservable = new VolumeParticleObservable(getMathSymbol(observableCountParameter, geometryClass), domain, particleObservableType);
            switch(rbmObservable.getSequence()) {
                case Multimolecular:
                    {
                        particleObservable.setSequence(Sequence.Multimolecular);
                        break;
                    }
                case PolymerLengthEqual:
                    {
                        particleObservable.setSequence(Sequence.PolymerLengthEqual);
                        particleObservable.setQuantity(rbmObservable.getSequenceLength());
                        break;
                    }
                case PolymerLengthGreater:
                    {
                        particleObservable.setSequence(Sequence.PolymerLengthGreater);
                        particleObservable.setQuantity(rbmObservable.getSequenceLength());
                        break;
                    }
                default:
                    {
                        throw new RuntimeException("unexpected sequence " + rbmObservable.getSequence());
                    }
            }
            for (SpeciesPattern speciesPattern : rbmObservable.getSpeciesPatternList()) {
                VolumeParticleSpeciesPattern vpsp = speciesPatternMap.get(speciesPattern);
                particleObservable.addParticleSpeciesPattern(vpsp);
            }
            observables.add(particleObservable);
        }
        if (mathMappingParameter instanceof SpeciesCountParameter) {
            SpeciesCountParameter speciesCountParameter = (SpeciesCountParameter) mathMappingParameter;
            ParticleObservable.ObservableType particleObservableType = ParticleObservable.ObservableType.Species;
            ParticleObservable particleObservable = new VolumeParticleObservable(getMathSymbol(speciesCountParameter, geometryClass), domain, particleObservableType);
            particleObservable.setSequence(Sequence.Multimolecular);
            SpeciesPattern speciesPattern = speciesCountParameter.getSpeciesContext().getSpeciesPattern();
            VolumeParticleSpeciesPattern vpsp = speciesPatternMap.get(speciesPattern);
            particleObservable.addParticleSpeciesPattern(vpsp);
            observables.add(particleObservable);
        }
    }
    return observables;
}
Also used : RbmObservable(cbit.vcell.model.RbmObservable) ArrayList(java.util.ArrayList) VolumeParticleSpeciesPattern(cbit.vcell.math.VolumeParticleSpeciesPattern) VolumeParticleObservable(cbit.vcell.math.VolumeParticleObservable) ParticleObservable(cbit.vcell.math.ParticleObservable) VolumeParticleObservable(cbit.vcell.math.VolumeParticleObservable) VolumeParticleSpeciesPattern(cbit.vcell.math.VolumeParticleSpeciesPattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Aggregations

VolumeParticleSpeciesPattern (cbit.vcell.math.VolumeParticleSpeciesPattern)8 Element (org.jdom.Element)5 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)4 ParticleMolecularTypePattern (cbit.vcell.math.ParticleMolecularTypePattern)4 ArrayList (java.util.ArrayList)4 Variable (cbit.vcell.math.Variable)3 Domain (cbit.vcell.math.Variable.Domain)3 VolumeParticleObservable (cbit.vcell.math.VolumeParticleObservable)3 VolumeParticleVariable (cbit.vcell.math.VolumeParticleVariable)3 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)3 FilamentSubDomain (cbit.vcell.math.FilamentSubDomain)2 MacroscopicRateConstant (cbit.vcell.math.MacroscopicRateConstant)2 MathDescription (cbit.vcell.math.MathDescription)2 MembraneParticleVariable (cbit.vcell.math.MembraneParticleVariable)2 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)2 ParticleComponentStateDefinition (cbit.vcell.math.ParticleComponentStateDefinition)2 ParticleComponentStatePattern (cbit.vcell.math.ParticleComponentStatePattern)2 ParticleMolecularComponent (cbit.vcell.math.ParticleMolecularComponent)2 ParticleMolecularComponentPattern (cbit.vcell.math.ParticleMolecularComponentPattern)2 ParticleMolecularType (cbit.vcell.math.ParticleMolecularType)2