Search in sources :

Example 6 with SpeciesContextMapping

use of cbit.vcell.mapping.SpeciesContextMapping in project vcell by virtualcell.

the class StructureAnalyzer method substituteIntoFastSystem.

/**
 * This method was created in VisualAge.
 */
private void substituteIntoFastSystem() throws Exception {
    // 
    for (int j = 0; j < speciesContextMappings.length; j++) {
        if (speciesContextMappings[j].getDependencyExpression() != null) {
            Expression dependentVar = new Expression(speciesContextMappings[j].getSpeciesContext(), mathMapping_4_8.getNameScope());
            Expression dependentExp = new Expression(speciesContextMappings[j].getDependencyExpression());
            // System.out.println("trying to substitute '"+dependentExp.toString()+"' for variable '"+dependentVar.toString()+"'");
            for (int i = 0; i < fastSpeciesContextMappings.length; i++) {
                SpeciesContextMapping scm = fastSpeciesContextMappings[i];
                if (scm.getFastInvariant() != null) {
                    scm.getFastInvariant().substituteInPlace(dependentVar, dependentExp);
                    scm.setFastInvariant(scm.getFastInvariant().flatten());
                } else {
                    scm.getFastRate().substituteInPlace(dependentVar, dependentExp);
                    scm.setFastRate(scm.getFastRate().flatten());
                }
            }
        }
    }
// for (int i=0;i<fastSpeciesContextMappings.length;i++){
// SpeciesContextMapping scm = fastSpeciesContextMappings[i];
// if (scm.fastInvariant!=null){
// System.out.println("fastInvariant for "+scm.getSpeciesContext().getName()+" = "+scm.fastInvariant.toString());
// }else{
// System.out.println("fastRate for "+scm.getSpeciesContext().getName()+" = "+scm.fastRate.toString());
// }
// }
}
Also used : Expression(cbit.vcell.parser.Expression) SpeciesContextMapping(cbit.vcell.mapping.SpeciesContextMapping)

Example 7 with SpeciesContextMapping

use of cbit.vcell.mapping.SpeciesContextMapping in project vcell by virtualcell.

the class StructureAnalyzer method refreshFastSystem.

/**
 * Find which species are fast-independent, use their rates as the "fastRate"s.
 * null space rows correspond to "fastInvariant".
 */
private void refreshFastSystem() throws Exception {
    // 
    for (int v = 0; v < fastSpeciesContextMappings.length; v++) {
        fastSpeciesContextMappings[v].setFastInvariant(null);
    }
    if (fastNullSpaceMatrix == null) {
        // System.out.println("the fast matrix has full rank, there are no fast invariants");
        return;
    }
    if (fastSpeciesContextMappings.length != fastNullSpaceMatrix.getNumCols()) {
        throw new Exception("varName array not same dimension as b matrix");
    }
    StructureAnalyzer.Dependency[] dependencies = refreshTotalDependancies(fastNullSpaceMatrix, fastSpeciesContextMappings, mathMapping_4_8, true);
    for (int i = 0; i < dependencies.length; i++) {
        // String constantName = dependencies[i].invariantSymbolName;
        Expression constantExp = dependencies[i].conservedMoietyExpression;
        SpeciesContextMapping firstSCM = dependencies[i].speciesContextMapping;
        // Expression exp = dependencies[i].dependencyExpression;
        // 
        // store fastInvariant (e.g. (K_fast_total= xyz + wzy)
        // 
        constantExp.bindExpression(mathMapping_4_8);
        firstSCM.setFastInvariant(constantExp.flatten());
    }
}
Also used : Expression(cbit.vcell.parser.Expression) SpeciesContextMapping(cbit.vcell.mapping.SpeciesContextMapping)

Example 8 with SpeciesContextMapping

use of cbit.vcell.mapping.SpeciesContextMapping in project vcell by virtualcell.

the class MathMapping_4_8 method getResolvedVolVariable.

/**
 * Find the defined variable (VolVariable) for the resolved compartments.
 * This method is used to assure only one variable is created.
 * @return cbit.vcell.math.VolVariable
 * @param species cbit.vcell.model.Species
 */
private VolVariable getResolvedVolVariable(Species species) {
    Enumeration<SpeciesContextMapping> enum1 = getSpeciesContextMappings();
    while (enum1.hasMoreElements()) {
        SpeciesContextMapping scm = enum1.nextElement();
        if (scm.getSpeciesContext().getSpecies() == species) {
            Variable var = scm.getVariable();
            if (var instanceof VolVariable) {
                Structure structure = scm.getSpeciesContext().getStructure();
                StructureMapping sm = simContext.getGeometryContext().getStructureMapping(structure);
                if (structure instanceof Feature && getResolved(sm)) {
                    return (VolVariable) var;
                }
            }
        }
    }
    return new VolVariable(TokenMangler.fixTokenStrict(species.getCommonName()), nullDomain);
}
Also used : MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) VolVariable(cbit.vcell.math.VolVariable) MemVariable(cbit.vcell.math.MemVariable) Variable(cbit.vcell.math.Variable) SpeciesContextMapping(cbit.vcell.mapping.SpeciesContextMapping) VolVariable(cbit.vcell.math.VolVariable) Structure(cbit.vcell.model.Structure) StructureMapping(cbit.vcell.mapping.StructureMapping) Feature(cbit.vcell.model.Feature)

Example 9 with SpeciesContextMapping

use of cbit.vcell.mapping.SpeciesContextMapping in project vcell by virtualcell.

the class MathMapping_4_8 method refreshVariables.

/**
 * This method was created in VisualAge.
 */
private void refreshVariables() throws MappingException {
    // System.out.println("MathMapping.refreshVariables()");
    // 
    // non-constant dependent variables require a function
    // 
    Enumeration<SpeciesContextMapping> enum1 = getSpeciesContextMappings();
    while (enum1.hasMoreElements()) {
        SpeciesContextMapping scm = enum1.nextElement();
        SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
        if (scm.getDependencyExpression() != null && !scs.isConstant()) {
            // scm.setVariable(new Function(scm.getSpeciesContext().getName(),scm.getDependencyExpression()));
            scm.setVariable(null);
        }
    }
    enum1 = getSpeciesContextMappings();
    while (enum1.hasMoreElements()) {
        SpeciesContextMapping scm = enum1.nextElement();
        SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
        if (getSimulationContext().hasEventAssignment(scs.getSpeciesContext())) {
            scm.setDependencyExpression(null);
        }
    }
    // 
    // non-constant independent variables require either a membrane or volume variable
    // 
    enum1 = getSpeciesContextMappings();
    while (enum1.hasMoreElements()) {
        SpeciesContextMapping scm = (SpeciesContextMapping) enum1.nextElement();
        SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
        if (scm.getDependencyExpression() == null && (!scs.isConstant() || getSimulationContext().hasEventAssignment(scs.getSpeciesContext()))) {
            StructureMapping sm = simContext.getGeometryContext().getStructureMapping(scm.getSpeciesContext().getStructure());
            Structure struct = scm.getSpeciesContext().getStructure();
            if (struct instanceof Feature) {
                if (getResolved(sm)) {
                    scm.setVariable(getResolvedVolVariable(scm.getSpeciesContext().getSpecies()));
                } else {
                    scm.setVariable(new VolVariable(scm.getSpeciesContext().getName(), nullDomain));
                }
            } else if (struct instanceof Membrane) {
                if (getResolved(sm)) {
                    scm.setVariable(new MemVariable(scm.getSpeciesContext().getName(), nullDomain));
                } else {
                    scm.setVariable(new VolVariable(scm.getSpeciesContext().getName(), nullDomain));
                }
            } else {
                throw new MappingException("class " + scm.getSpeciesContext().getStructure().getClass() + " not supported");
            }
            mathSymbolMapping.put(scm.getSpeciesContext(), scm.getVariable().getName());
        }
    }
}
Also used : MemVariable(cbit.vcell.math.MemVariable) SpeciesContextMapping(cbit.vcell.mapping.SpeciesContextMapping) VolVariable(cbit.vcell.math.VolVariable) Membrane(cbit.vcell.model.Membrane) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) Structure(cbit.vcell.model.Structure) StructureMapping(cbit.vcell.mapping.StructureMapping) Feature(cbit.vcell.model.Feature) MappingException(cbit.vcell.mapping.MappingException)

Example 10 with SpeciesContextMapping

use of cbit.vcell.mapping.SpeciesContextMapping in project vcell by virtualcell.

the class MathMapping_4_8 method refreshSpeciesContextMappings.

/**
 * This method was created in VisualAge.
 */
private void refreshSpeciesContextMappings() throws ExpressionException, MappingException, MathException {
    // 
    // create a SpeciesContextMapping for each speciesContextSpec.
    // 
    // set initialExpression from SpeciesContextSpec.
    // set diffusing
    // set variable (only if "Constant" or "Function", else leave it as null)
    // 
    speciesContextMappingList.removeAllElements();
    SpeciesContextSpec[] speciesContextSpecs = simContext.getReactionContext().getSpeciesContextSpecs();
    for (int i = 0; i < speciesContextSpecs.length; i++) {
        SpeciesContextSpec scs = speciesContextSpecs[i];
        SpeciesContextMapping scm = new SpeciesContextMapping(scs.getSpeciesContext());
        scm.setPDERequired(simContext.isPDERequired(scs.getSpeciesContext()));
        scm.setHasEventAssignment(simContext.hasEventAssignment(scs.getSpeciesContext()));
        scm.setHasHybridReaction(false);
        for (ReactionSpec reactionSpec : getSimulationContext().getReactionContext().getReactionSpecs()) {
            if (!reactionSpec.isExcluded() && reactionSpec.hasHybrid(getSimulationContext(), scs.getSpeciesContext())) {
                scm.setHasHybridReaction(true);
            }
        }
        // scm.setAdvecting(isAdvectionRequired(scs.getSpeciesContext()));
        if (scs.isConstant()) {
            Expression initCond = scs.getInitialConditionParameter() == null ? null : scs.getInitialConditionParameter().getExpression();
            scm.setDependencyExpression(initCond);
        // //
        // // determine if a Function is necessary
        // //
        // boolean bNeedFunction = false;
        // if (initCond.getSymbols()!=null){
        // bNeedFunction = true;
        // }
        // if (bNeedFunction){
        // scm.setVariable(new Function(scm.getSpeciesContext().getName(),initCond));
        // }else{
        // scm.setVariable(new Constant(scm.getSpeciesContext().getName(),initCond));
        // }
        }
        // 
        // test if participant in fast reaction step, request elimination if possible
        // 
        scm.setFastParticipant(false);
        ReactionSpec[] reactionSpecs = simContext.getReactionContext().getReactionSpecs();
        for (int j = 0; j < reactionSpecs.length; j++) {
            ReactionSpec reactionSpec = reactionSpecs[j];
            if (reactionSpec.isExcluded()) {
                continue;
            }
            ReactionStep rs = reactionSpec.getReactionStep();
            if (rs instanceof SimpleReaction && rs.countNumReactionParticipants(scs.getSpeciesContext()) > 0) {
                if (reactionSpec.isFast()) {
                    scm.setFastParticipant(true);
                }
            }
        }
        speciesContextMappingList.addElement(scm);
    }
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) SpeciesContextMapping(cbit.vcell.mapping.SpeciesContextMapping) Expression(cbit.vcell.parser.Expression) ReactionSpec(cbit.vcell.mapping.ReactionSpec) ReactionStep(cbit.vcell.model.ReactionStep) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec)

Aggregations

SpeciesContextMapping (cbit.vcell.mapping.SpeciesContextMapping)16 Expression (cbit.vcell.parser.Expression)13 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)10 ReactionSpec (cbit.vcell.mapping.ReactionSpec)8 SpeciesContext (cbit.vcell.model.SpeciesContext)8 StructureMapping (cbit.vcell.mapping.StructureMapping)7 Structure (cbit.vcell.model.Structure)7 ReactionStep (cbit.vcell.model.ReactionStep)6 Vector (java.util.Vector)6 MappingException (cbit.vcell.mapping.MappingException)5 MembraneMapping (cbit.vcell.mapping.MembraneMapping)5 Feature (cbit.vcell.model.Feature)5 Membrane (cbit.vcell.model.Membrane)5 Model (cbit.vcell.model.Model)4 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)4 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)4 DiffusionDummyReactionStep (cbit.vcell.mapping.DiffusionDummyReactionStep)3 DummyReactionStep (cbit.vcell.mapping.DummyReactionStep)3 EventDummyReactionStep (cbit.vcell.mapping.EventDummyReactionStep)3 FeatureMapping (cbit.vcell.mapping.FeatureMapping)3