Search in sources :

Example 1 with DummyReactionStep

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();
// }
}
Also used : MembraneMapping(cbit.vcell.mapping.MembraneMapping) SimpleReaction(cbit.vcell.model.SimpleReaction) SpeciesContextMapping(cbit.vcell.mapping.SpeciesContextMapping) ReactionSpec(cbit.vcell.mapping.ReactionSpec) RationalNumberMatrix(cbit.vcell.matrix.RationalNumberMatrix) DummyReactionStep(cbit.vcell.mapping.DummyReactionStep) EventDummyReactionStep(cbit.vcell.mapping.EventDummyReactionStep) ParticleDummyReactionStep(cbit.vcell.mapping.ParticleDummyReactionStep) DiffusionDummyReactionStep(cbit.vcell.mapping.DiffusionDummyReactionStep) HybridDummyReactionStep(cbit.vcell.mapping.HybridDummyReactionStep) FluxReaction(cbit.vcell.model.FluxReaction) SpeciesContext(cbit.vcell.model.SpeciesContext) Expression(cbit.vcell.parser.Expression) Membrane(cbit.vcell.model.Membrane) Parameter(cbit.vcell.model.Parameter) Structure(cbit.vcell.model.Structure) ReactionParticipant(cbit.vcell.model.ReactionParticipant) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Aggregations

DiffusionDummyReactionStep (cbit.vcell.mapping.DiffusionDummyReactionStep)1 DummyReactionStep (cbit.vcell.mapping.DummyReactionStep)1 EventDummyReactionStep (cbit.vcell.mapping.EventDummyReactionStep)1 HybridDummyReactionStep (cbit.vcell.mapping.HybridDummyReactionStep)1 MembraneMapping (cbit.vcell.mapping.MembraneMapping)1 ParticleDummyReactionStep (cbit.vcell.mapping.ParticleDummyReactionStep)1 ReactionSpec (cbit.vcell.mapping.ReactionSpec)1 SpeciesContextMapping (cbit.vcell.mapping.SpeciesContextMapping)1 RationalNumberMatrix (cbit.vcell.matrix.RationalNumberMatrix)1 FluxReaction (cbit.vcell.model.FluxReaction)1 Membrane (cbit.vcell.model.Membrane)1 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)1 Parameter (cbit.vcell.model.Parameter)1 ReactionParticipant (cbit.vcell.model.ReactionParticipant)1 SimpleReaction (cbit.vcell.model.SimpleReaction)1 SpeciesContext (cbit.vcell.model.SpeciesContext)1 Structure (cbit.vcell.model.Structure)1 Expression (cbit.vcell.parser.Expression)1