Search in sources :

Example 36 with StructureMapping

use of cbit.vcell.mapping.StructureMapping 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 37 with StructureMapping

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

the class StructureAnalyzer method refreshTotalDependancies.

/**
 * This method was created by a SmartGuide.
 * @param b cbit.vcell.math.Matrix
 * @param vars java.lang.String[]
 */
static StructureAnalyzer.Dependency[] refreshTotalDependancies(RationalMatrix nullSpaceMatrix, SpeciesContextMapping[] speciesContextMappings, MathMapping_4_8 argMathMapping, boolean bFast) throws Exception {
    // System.out.println("StructureAnalyzer.refreshTotalDependancies()");
    SimulationContext argSimContext = argMathMapping.getSimulationContext();
    if (nullSpaceMatrix == null) {
        // System.out.println("the matrix has full rank, there are no dependencies");
        return new StructureAnalyzer.Dependency[0];
    }
    if (speciesContextMappings.length != nullSpaceMatrix.getNumCols()) {
        // throw new Exception("varName array not same dimension as b matrix");
        System.out.println("varName array not same dimension as b matrix");
        nullSpaceMatrix.show();
        for (int i = 0; i < speciesContextMappings.length; i++) {
            System.out.println("scm[" + i + "] is " + speciesContextMappings[i].getSpeciesContext().getName());
        }
    }
    // System.out.println("there are "+nullSpaceMatrix.rows+" dependencies");
    Vector<Dependency> dependencyList = new Vector<Dependency>();
    for (int i = 0; i < nullSpaceMatrix.getNumRows(); i++) {
        // 
        // find first variable
        // 
        Expression exp = null;
        Expression constantExp = null;
        String constantName = null;
        SpeciesContextMapping firstSCM = null;
        boolean bFirst = true;
        for (int j = 0; j < nullSpaceMatrix.getNumCols(); j++) {
            RationalNumber coeff = nullSpaceMatrix.get_elem(i, j);
            if (coeff.doubleValue() != 0.0) {
                if (bFirst) {
                    if (coeff.doubleValue() != 1.0) {
                        System.out.println("i=" + i + " j=" + j);
                        nullSpaceMatrix.show();
                        throw new Exception("expecting a coefficient of 1.0, instead coeff = " + coeff.infix());
                    }
                    firstSCM = speciesContextMappings[j];
                    // 
                    // first term of dependancy expression   ("K_CalciumCyt")
                    // 
                    SpeciesContext firstSC = firstSCM.getSpeciesContext();
                    constantName = "K_" + firstSC.getName() + "_total";
                    exp = new Expression(constantName);
                    // 
                    // first term of K expression
                    // 
                    StructureMapping firstSM = argSimContext.getGeometryContext().getStructureMapping(firstSC.getStructure());
                    SpeciesContextSpec firstSCS = argSimContext.getReactionContext().getSpeciesContextSpec(firstSC);
                    SymbolTableEntry scSTE = null;
                    if (bFast) {
                        scSTE = firstSCS.getSpeciesContext();
                    } else {
                        scSTE = firstSCS.getParameterFromRole(SpeciesContextSpec.ROLE_InitialConcentration);
                    }
                    constantExp = Expression.mult(new Expression(coeff), firstSM.getNormalizedConcentrationCorrection(argSimContext, argMathMapping), new Expression(scSTE, argMathMapping.getNameScope()));
                    bFirst = false;
                } else {
                    // 
                    // add term to dependancy expression     (" - 2*IP3Cyt ")
                    // 
                    SpeciesContextMapping scm = speciesContextMappings[j];
                    SpeciesContext sc = scm.getSpeciesContext();
                    StructureMapping sm = argSimContext.getGeometryContext().getStructureMapping(sc.getStructure());
                    SpeciesContextSpec scs = argSimContext.getReactionContext().getSpeciesContextSpec(sc);
                    exp = Expression.add(exp, Expression.negate(Expression.mult(new Expression(coeff), sm.getNormalizedConcentrationCorrection(argSimContext, argMathMapping), new Expression(sc, argMathMapping.getNameScope()))));
                    // 
                    // add term to K expression
                    // 
                    SymbolTableEntry scSTE = null;
                    if (bFast) {
                        scSTE = sc;
                    } else {
                        scSTE = scs.getParameterFromRole(SpeciesContextSpec.ROLE_InitialConcentration);
                    }
                    constantExp = Expression.add(constantExp, Expression.mult(new Expression(coeff), sm.getNormalizedConcentrationCorrection(argSimContext, argMathMapping), new Expression(scSTE, argMathMapping.getNameScope())));
                }
            }
        }
        if (firstSCM != null) {
            // 
            // store totalMass parameter (e.g. K_xyz_total = xyz_init + wzy_init)
            // 
            // MathMapping.MathMappingParameter totalMassParameter = mathMapping.addMathMappingParameter(constantName,constantExp.flatten(),MathMapping.PARAMETER_ROLE_TOTALMASS,cbit.vcell.units.VCUnitDefinition.UNIT_uM);
            // 
            // store dependency parameter (e.g. xyz = K_xyz_total - wzy)
            // 
            StructureMapping sm = argSimContext.getGeometryContext().getStructureMapping(firstSCM.getSpeciesContext().getStructure());
            exp = Expression.mult(exp, Expression.invert(sm.getNormalizedConcentrationCorrection(argSimContext, argMathMapping)));
            exp = exp.flatten();
            // exp.bindExpression(mathMapping_temp);
            // firstSCM.setDependencyExpression(exp);
            Dependency dependency = new Dependency();
            dependency.dependencyExpression = exp;
            dependency.speciesContextMapping = firstSCM;
            dependency.invariantSymbolName = constantName;
            dependency.conservedMoietyExpression = constantExp.flatten();
            dependencyList.add(dependency);
        }
    }
    return (StructureAnalyzer.Dependency[]) BeanUtils.getArray(dependencyList, StructureAnalyzer.Dependency.class);
}
Also used : SpeciesContextMapping(cbit.vcell.mapping.SpeciesContextMapping) SpeciesContext(cbit.vcell.model.SpeciesContext) SimulationContext(cbit.vcell.mapping.SimulationContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) StructureMapping(cbit.vcell.mapping.StructureMapping) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) Expression(cbit.vcell.parser.Expression) RationalNumber(cbit.vcell.matrix.RationalNumber) Vector(java.util.Vector)

Example 38 with StructureMapping

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

the class MathMapping_4_8 method getResolved.

boolean getResolved(StructureMapping structureMapping) {
    if (simContext == null || structureMapping.getStructure() == null) {
        throw new RuntimeException("failed to process getResolved()");
    }
    if (structureMapping.getGeometryClass() == null) {
        return false;
    }
    StructureTopology structureTopology = simContext.getModel().getStructureTopology();
    Structure parentStructure = structureTopology.getParentStructure(structureMapping.getStructure());
    if (parentStructure != null) {
        StructureMapping outsideSM = simContext.getGeometryContext().getStructureMapping(parentStructure);
        if (outsideSM.getGeometryClass() != null && outsideSM.getGeometryClass() == structureMapping.getGeometryClass()) {
            return false;
        }
    }
    return true;
}
Also used : StructureTopology(cbit.vcell.model.Model.StructureTopology) Structure(cbit.vcell.model.Structure) StructureMapping(cbit.vcell.mapping.StructureMapping)

Example 39 with StructureMapping

use of cbit.vcell.mapping.StructureMapping 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 40 with StructureMapping

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

the class ModelOptimizationSpec method getModelParameters.

/**
 * Insert the method's description here.
 * Creation date: (8/22/2005 10:38:04 AM)
 * @return cbit.vcell.model.Parameter[]
 */
private Parameter[] getModelParameters() {
    java.util.Vector<Parameter> modelParameterList = new java.util.Vector<Parameter>();
    Model model = getSimulationContext().getModel();
    // 
    // get Model (global) parameters
    // 
    ModelParameter[] globalParams = model.getModelParameters();
    for (int i = 0; i < globalParams.length; i++) {
        if (globalParams[i] != null && globalParams[i].getExpression() != null && globalParams[i].getExpression().isNumeric()) {
            modelParameterList.add(globalParams[i]);
        }
    }
    // 
    // get kinetic parameters that are numbers
    // 
    ReactionStep[] reactionSteps = model.getReactionSteps();
    for (int i = 0; i < reactionSteps.length; i++) {
        // 
        // make sure ReactionSteps are "enabled"
        // 
        ReactionSpec reactionSpec = getSimulationContext().getReactionContext().getReactionSpec(reactionSteps[i]);
        if (reactionSpec == null || reactionSpec.isExcluded()) {
            continue;
        }
        Kinetics.KineticsParameter[] kineticsParameters = reactionSteps[i].getKinetics().getKineticsParameters();
        for (int j = 0; j < kineticsParameters.length; j++) {
            if (kineticsParameters[j].getExpression() != null && kineticsParameters[j].getExpression().isNumeric()) {
                if (((kineticsParameters[j].getRole() == Kinetics.ROLE_CurrentDensity) || (kineticsParameters[j].getRole() == Kinetics.ROLE_LumpedCurrent)) && reactionSteps[i].getPhysicsOptions() == ReactionStep.PHYSICS_MOLECULAR_ONLY) {
                    continue;
                }
                if (((kineticsParameters[j].getRole() == Kinetics.ROLE_ReactionRate) || (kineticsParameters[j].getRole() == Kinetics.ROLE_LumpedReactionRate)) && reactionSteps[i].getPhysicsOptions() == ReactionStep.PHYSICS_ELECTRICAL_ONLY) {
                    continue;
                }
                modelParameterList.add(kineticsParameters[j]);
            }
        }
    }
    // 
    // get initial conditions that are numbers
    // 
    SpeciesContextSpec[] speciesContextSpecs = getSimulationContext().getReactionContext().getSpeciesContextSpecs();
    for (int i = 0; i < speciesContextSpecs.length; i++) {
        SpeciesContextSpec.SpeciesContextSpecParameter initParam = speciesContextSpecs[i].getInitialConditionParameter();
        if (initParam != null && initParam.getExpression() != null && initParam.getExpression().isNumeric()) {
            modelParameterList.add(initParam);
        }
    }
    // 
    // get structure parameters
    // 
    StructureMapping[] structureMappings = getSimulationContext().getGeometryContext().getStructureMappings();
    for (int i = 0; i < structureMappings.length; i++) {
        StructureMapping.StructureMappingParameter[] parameters = structureMappings[i].getParameters();
        for (int j = 0; j < parameters.length; j++) {
            if (parameters[j].getRole() == StructureMapping.ROLE_SpecificCapacitance && structureMappings[i] instanceof MembraneMapping && !((MembraneMapping) structureMappings[i]).getCalculateVoltage()) {
                continue;
            }
            if (parameters[j].getExpression() != null && parameters[j].getExpression().isNumeric()) {
                modelParameterList.add(parameters[j]);
            }
        }
    }
    Parameter[] modelParameters = (Parameter[]) BeanUtils.getArray(modelParameterList, Parameter.class);
    return modelParameters;
}
Also used : MembraneMapping(cbit.vcell.mapping.MembraneMapping) ReactionSpec(cbit.vcell.mapping.ReactionSpec) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) StructureMapping(cbit.vcell.mapping.StructureMapping) ModelParameter(cbit.vcell.model.Model.ModelParameter) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) ReactionStep(cbit.vcell.model.ReactionStep) Model(cbit.vcell.model.Model) Parameter(cbit.vcell.model.Parameter) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) ModelParameter(cbit.vcell.model.Model.ModelParameter) KineticsProxyParameter(cbit.vcell.model.Kinetics.KineticsProxyParameter) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter) Vector(java.util.Vector) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)

Aggregations

StructureMapping (cbit.vcell.mapping.StructureMapping)49 Expression (cbit.vcell.parser.Expression)25 Structure (cbit.vcell.model.Structure)22 ExpressionException (cbit.vcell.parser.ExpressionException)19 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)18 MembraneMapping (cbit.vcell.mapping.MembraneMapping)17 SimulationContext (cbit.vcell.mapping.SimulationContext)16 SpeciesContext (cbit.vcell.model.SpeciesContext)16 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)15 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)15 Model (cbit.vcell.model.Model)14 BioModel (cbit.vcell.biomodel.BioModel)13 FeatureMapping (cbit.vcell.mapping.FeatureMapping)12 ModelParameter (cbit.vcell.model.Model.ModelParameter)12 ReactionStep (cbit.vcell.model.ReactionStep)12 GeometryContext (cbit.vcell.mapping.GeometryContext)11 MappingException (cbit.vcell.mapping.MappingException)11 SpeciesContextSpecParameter (cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)11 Membrane (cbit.vcell.model.Membrane)11 Feature (cbit.vcell.model.Feature)10