Search in sources :

Example 76 with SymbolTableEntry

use of cbit.vcell.parser.SymbolTableEntry 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 77 with SymbolTableEntry

use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.

the class MathDescription method getEntry.

/**
 * This method was created by a SmartGuide.
 * @return cbit.vcell.parser.SymbolTableEntry
 * @param id java.lang.String
 * @param qualifier java.lang.String
 * @exception java.lang.Exception The exception description.
 */
public SymbolTableEntry getEntry(String id) {
    SymbolTableEntry entry = null;
    entry = ReservedMathSymbolEntries.getEntry(id, false);
    if (entry != null) {
        if (entry instanceof SymbolTableFunctionEntry) {
            if (entry.equals(MathFunctionDefinitions.Function_regionArea_current) || entry.equals(MathFunctionDefinitions.Function_regionArea_indexed) || entry.equals(MathFunctionDefinitions.Function_regionVolume_current) || entry.equals(MathFunctionDefinitions.Function_regionVolume_indexed)) {
                bRegionSizeFunctionsUsed = true;
            }
        }
        return entry;
    }
    entry = getVariable(id);
    if (entry != null) {
        return entry;
    }
    return null;
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) SymbolTableFunctionEntry(cbit.vcell.parser.SymbolTableFunctionEntry)

Example 78 with SymbolTableEntry

use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.

the class MathSymbolMapping method reconcileVarNames.

/**
 * Insert the method's description here.
 * Creation date: (5/3/2006 4:03:51 PM)
 * @param mathDesc cbit.vcell.math.MathDescription
 */
public void reconcileVarNames(MathDescription mathDesc) {
    // 
    // clear secondary hashmaps in case called multiple times.
    // 
    biologicalToMathHash.clear();
    mathToBiologicalHash.clear();
    java.util.Set<SymbolTableEntry> keyset = biologicalToMathSymbolNameHash.keySet();
    java.util.Iterator<SymbolTableEntry> keysetIter = keyset.iterator();
    while (keysetIter.hasNext()) {
        SymbolTableEntry biologicalSymbol = keysetIter.next();
        String mathVarName = (String) biologicalToMathSymbolNameHash.get(biologicalSymbol);
        Variable var = mathDesc.getVariable(mathVarName);
        if (var != null) {
            biologicalToMathHash.put(biologicalSymbol, var);
            SymbolTableEntry[] previousBiologicalSymbolArr = (SymbolTableEntry[]) mathToBiologicalHash.put(var, new SymbolTableEntry[] { biologicalSymbol });
            if (previousBiologicalSymbolArr != null) {
                SymbolTableEntry[] steArr = (SymbolTableEntry[]) BeanUtils.addElement(previousBiologicalSymbolArr, biologicalSymbol);
                mathToBiologicalHash.put(var, steArr);
            }
        }
    }
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) InsideVariable(cbit.vcell.math.InsideVariable) Variable(cbit.vcell.math.Variable) OutsideVariable(cbit.vcell.math.OutsideVariable)

Example 79 with SymbolTableEntry

use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.

the class ParameterContext method getEntry.

/**
 * getEntry method comment.
 */
public SymbolTableEntry getEntry(String identifierString) {
    SymbolTableEntry localSTE = getLocalEntry(identifierString);
    if (localSTE != null && !(localSTE instanceof UnresolvedParameter)) {
        return localSTE;
    }
    // may be null.
    UnresolvedParameter unresolvedParameter = (UnresolvedParameter) localSTE;
    SymbolTableEntry externalSTE = getNameScope().getExternalEntry(identifierString, this);
    if (externalSTE instanceof SymbolTableFunctionEntry) {
        return externalSTE;
    }
    // 
    if (externalSTE != null) {
        if (unresolvedParameter != null) {
            removeUnresolvedParameters(this);
        }
        return addProxyParameter(externalSTE);
    } else if (unresolvedParameter != null) {
        return unresolvedParameter;
    }
    return null;
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) SymbolTableFunctionEntry(cbit.vcell.parser.SymbolTableFunctionEntry)

Example 80 with SymbolTableEntry

use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.

the class ParameterContext method getLocalEntry.

/**
 * Insert the method's description here.
 * Creation date: (12/8/2003 11:46:37 AM)
 * @return SymbolTableEntry
 * @param identifier java.lang.String
 */
public SymbolTableEntry getLocalEntry(java.lang.String identifier) {
    SymbolTableEntry ste = getLocalParameterFromName(identifier);
    if (ste != null) {
        return ste;
    }
    ste = getProxyParameter(identifier);
    if (ste != null) {
        return ste;
    }
    return null;
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry)

Aggregations

SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)115 Expression (cbit.vcell.parser.Expression)50 ExpressionException (cbit.vcell.parser.ExpressionException)20 Vector (java.util.Vector)20 ArrayList (java.util.ArrayList)19 SpeciesContext (cbit.vcell.model.SpeciesContext)18 ModelParameter (cbit.vcell.model.Model.ModelParameter)14 PropertyVetoException (java.beans.PropertyVetoException)14 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)13 Model (cbit.vcell.model.Model)12 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)11 HashMap (java.util.HashMap)11 SimulationContext (cbit.vcell.mapping.SimulationContext)10 Variable (cbit.vcell.math.Variable)10 LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)9 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)9 Parameter (cbit.vcell.model.Parameter)9 SingleXPlot2D (cbit.plot.SingleXPlot2D)8 MathException (cbit.vcell.math.MathException)8 ReservedVariable (cbit.vcell.math.ReservedVariable)8