use of cbit.vcell.matrix.RationalNumberMatrix 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.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++) {
ReactionStep reactionStep = reactionSteps[j];
int stoichiometry = reactionStep.getStoichiometry(sc);
totalSchemeMatrix.set_elem(i, j, stoichiometry);
if (stoichiometry != 0) {
if (!(reactionStep instanceof DummyReactionStep) && !reactionSpecs[j].isFast() && !reactionSpecs[j].isExcluded()) {
ReactionParticipant[] rps1 = reactionStep.getReactionParticipants();
ReactionParticipant rp0 = null;
for (ReactionParticipant rp : rps1) {
if (rp.getSpeciesContext() == sc) {
rp0 = rp;
break;
}
}
if (rp0 != null) {
Expression distributedReactRateExp = getCorrectedRateExpression(reactionStep, rp0, RateType.ConcentrationRate);
exp = Expression.add(exp, distributedReactRateExp);
}
}
}
}
// 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();
// }
}
use of cbit.vcell.matrix.RationalNumberMatrix in project vcell by virtualcell.
the class StructureAnalyzer method refreshFastMatrices.
/**
* This method was created in VisualAge.
*/
private void refreshFastMatrices() throws Exception {
// System.out.println("StructureAnalyzer.refreshFastMatrices()");
//
// update scheme matrix for fast system
//
fastSchemeMatrix = new RationalNumberMatrix(fastSpeciesContextMappings.length, fastReactionSteps.length);
for (int i = 0; i < fastSpeciesContextMappings.length; i++) {
for (int j = 0; j < fastReactionSteps.length; j++) {
fastSchemeMatrix.set_elem(i, j, fastReactionSteps[j].getStoichiometry(fastSpeciesContextMappings[i].getSpeciesContext()));
}
}
//
for (int i = 0; i < fastSpeciesContextMappings.length; i++) {
SpeciesContextMapping scm = fastSpeciesContextMappings[i];
SpeciesContext sc = scm.getSpeciesContext();
//
// collect fast rate expression
//
Expression exp = new Expression(0.0);
for (int j = 0; j < fastReactionSteps.length; j++) {
int stoichiometry = fastReactionSteps[j].getStoichiometry(sc);
ReactionSpec reactionSpec = mathMapping.getSimulationContext().getReactionContext().getReactionSpec(fastReactionSteps[j]);
if (stoichiometry != 0) {
if (!reactionSpec.isFast()) {
throw new Exception("expected only fast rates");
}
if (reactionSpec.isExcluded()) {
throw new Exception("expected only included rates");
}
ReactionParticipant[] rps = fastReactionSteps[j].getReactionParticipants();
ReactionParticipant rp0 = null;
for (ReactionParticipant rp : rps) {
if (rp.getSpeciesContext() == sc) {
rp0 = rp;
break;
}
}
//
if (rp0 != null) {
Expression fastRateExpression = getCorrectedRateExpression(fastReactionSteps[j], rp0, RateType.ConcentrationRate).renameBoundSymbols(mathMapping.getNameScope());
exp = Expression.add(exp, fastRateExpression);
}
}
}
// exp.bindExpression(mathMapping);
scm.setFastRate(exp.flatten());
}
// System.out.println("StructureAnalyzer.refreshFastMatrices(), scheme matrix:");
// fastSchemeMatrix.show();
//
// update null space matrix
//
fastNullSpaceMatrix = fastSchemeMatrix.findNullSpace();
// if (fastNullSpaceMatrix==null){
// System.out.println("fast system has full rank");
// }else{
// System.out.println("StructureAnalyzer.refreshFastMatrices(), nullSpace matrix:");
// fastNullSpaceMatrix.show();
// }
}
use of cbit.vcell.matrix.RationalNumberMatrix in project vcell by virtualcell.
the class StructureAnalyzer method refreshFastMatrices.
/**
* This method was created in VisualAge.
*/
private void refreshFastMatrices() throws Exception {
// System.out.println("StructureAnalyzer.refreshFastMatrices()");
//
// update scheme matrix for fast system
//
fastSchemeMatrix = new RationalNumberMatrix(fastSpeciesContextMappings.length, fastReactionSteps.length);
for (int i = 0; i < fastSpeciesContextMappings.length; i++) {
for (int j = 0; j < fastReactionSteps.length; j++) {
fastSchemeMatrix.set_elem(i, j, fastReactionSteps[j].getStoichiometry(fastSpeciesContextMappings[i].getSpeciesContext()));
}
}
//
for (int i = 0; i < fastSpeciesContextMappings.length; i++) {
SpeciesContextMapping scm = fastSpeciesContextMappings[i];
SpeciesContext sc = scm.getSpeciesContext();
//
// collect fast rate expression
//
Expression exp = new Expression(0.0);
for (int j = 0; j < fastReactionSteps.length; j++) {
int stoichiometry = fastReactionSteps[j].getStoichiometry(sc);
ReactionSpec reactionSpec = mathMapping_4_8.getSimulationContext().getReactionContext().getReactionSpec(fastReactionSteps[j]);
if (stoichiometry != 0) {
if (!reactionSpec.isFast()) {
throw new Exception("expected only fast rates");
}
if (reactionSpec.isExcluded()) {
throw new Exception("expected only included rates");
}
ReactionParticipant[] rps = fastReactionSteps[j].getReactionParticipants();
ReactionParticipant rp0 = null;
for (ReactionParticipant rp : rps) {
if (rp.getSpeciesContext() == sc) {
rp0 = rp;
break;
}
}
//
if (rp0 != null) {
Structure structure = fastReactionSteps[j].getStructure();
Expression fastRateExpression = getReactionRateExpression(fastReactionSteps[j], rp0).renameBoundSymbols(mathMapping_4_8.getNameScope());
if ((structure instanceof Membrane) && (rp0.getStructure() != structure)) {
Membrane membrane = (Membrane) structure;
MembraneMapping membraneMapping = (MembraneMapping) mathMapping_4_8.getSimulationContext().getGeometryContext().getStructureMapping(membrane);
Expression fluxCorrection = new Expression(mathMapping_4_8.getFluxCorrectionParameter(membraneMapping, (Feature) rp0.getStructure()), mathMapping_4_8.getNameScope());
exp = Expression.add(exp, Expression.mult(fluxCorrection, fastRateExpression));
} else {
exp = Expression.add(exp, new Expression(fastRateExpression));
}
}
}
}
// exp.bindExpression(mathMapping);
scm.setFastRate(exp.flatten());
}
// System.out.println("StructureAnalyzer.refreshFastMatrices(), scheme matrix:");
// fastSchemeMatrix.show();
//
// update null space matrix
//
fastNullSpaceMatrix = fastSchemeMatrix.findNullSpace();
// if (fastNullSpaceMatrix==null){
// System.out.println("fast system has full rank");
// }else{
// System.out.println("StructureAnalyzer.refreshFastMatrices(), nullSpace matrix:");
// fastNullSpaceMatrix.show();
// }
}
use of cbit.vcell.matrix.RationalNumberMatrix 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