use of cbit.vcell.mapping.SpeciesContextMapping 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);
}
Aggregations