use of cbit.vcell.mapping.DummyReactionStep in project vcell by virtualcell.
the class StructureAnalyzer method refreshTotalMatrices.
/**
* This method was created in VisualAge.
*/
private void refreshTotalMatrices() throws Exception {
// System.out.println("StructureAnalyzer.refreshTotalMatrices()");
//
// update scheme matrix for full system (slow and fast)
//
ReactionSpec[] reactionSpecs = new ReactionSpec[reactionSteps.length];
for (int j = 0; j < reactionSteps.length; j++) {
reactionSpecs[j] = mathMapping_4_8.getSimulationContext().getReactionContext().getReactionSpec(reactionSteps[j]);
}
//
// initialize rate expressions for speciesContext's due to scheme matrix
//
totalSchemeMatrix = new RationalNumberMatrix(speciesContextMappings.length, reactionSteps.length);
for (int i = 0; i < speciesContextMappings.length; i++) {
SpeciesContextMapping scm = speciesContextMappings[i];
SpeciesContext sc = scm.getSpeciesContext();
//
// collect slow rate expression (fast handled by FastSystem)
//
Expression exp = new Expression(0.0);
for (int j = 0; j < reactionSteps.length; j++) {
int stoichiometry = reactionSteps[j].getStoichiometry(sc);
totalSchemeMatrix.set_elem(i, j, stoichiometry);
if (stoichiometry != 0) {
if (!(reactionSteps[j] instanceof DummyReactionStep) && !reactionSpecs[j].isFast() && !reactionSpecs[j].isExcluded()) {
ReactionParticipant[] rps1 = reactionSteps[j].getReactionParticipants();
ReactionParticipant rp0 = null;
for (ReactionParticipant rp : rps1) {
if (rp.getSpeciesContext() == sc) {
rp0 = rp;
break;
}
}
Structure structure = reactionSteps[j].getStructure();
//
if (rp0 != null) {
Expression reactRateExp = getReactionRateExpression(reactionSteps[j], rp0).renameBoundSymbols(mathMapping_4_8.getNameScope());
if ((structure instanceof Membrane) && (sc.getStructure() != structure)) {
Membrane membrane = (Membrane) structure;
MembraneMapping membraneMapping = (MembraneMapping) mathMapping_4_8.getSimulationContext().getGeometryContext().getStructureMapping(membrane);
Parameter fluxCorrectionParameter = mathMapping_4_8.getFluxCorrectionParameter(membraneMapping, (Feature) sc.getStructure());
Expression fluxCorrection = new Expression(fluxCorrectionParameter, mathMapping_4_8.getNameScope());
if (reactionSteps[j] instanceof FluxReaction) {
exp = Expression.add(exp, Expression.mult(fluxCorrection, reactRateExp));
// Expression.add(exp,new Expression(fluxCorrectionParameterSymbolName+"*"+expInfix));
} else if (reactionSteps[j] instanceof SimpleReaction) {
ModelUnitSystem unitSystem = mathMapping_4_8.getSimulationContext().getModel().getUnitSystem();
Expression unitFactor = mathMapping_4_8.getUnitFactor(unitSystem.getVolumeSubstanceUnit().divideBy(unitSystem.getMembraneSubstanceUnit()));
exp = Expression.add(exp, Expression.mult(fluxCorrection, unitFactor, reactRateExp));
// exp = Expression.add(exp,new Expression(fluxCorrectionParameterSymbolName+"*"+ReservedSymbol.KMOLE.getName()+"*"+expInfix));
} else {
throw new RuntimeException("Internal Error: expected ReactionStep " + reactionSteps[j] + " to be of type SimpleReaction or FluxReaction");
}
} else {
exp = Expression.add(exp, reactRateExp);
}
}
}
}
}
// exp.bindExpression(mathMapping);
scm.setRate(exp.flatten());
}
//
if (totalSchemeMatrix.getNumRows() > 1) {
totalNullSpaceMatrix = (RationalMatrix) totalSchemeMatrix.findNullSpace();
} else {
totalNullSpaceMatrix = null;
}
// if (totalNullSpaceMatrix==null){
// System.out.println("total system has full rank");
// }else{
// System.out.println("StructureAnalyzer.refreshTotalMatrices(), nullSpace matrix:");
// totalNullSpaceMatrix.show();
// }
}
Aggregations