Search in sources :

Example 1 with RationalNumberMatrix

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();
// }
}
Also used : Expression(cbit.vcell.parser.Expression) ReactionStep(cbit.vcell.model.ReactionStep) RationalNumberMatrix(cbit.vcell.matrix.RationalNumberMatrix) SpeciesContext(cbit.vcell.model.SpeciesContext) ReactionParticipant(cbit.vcell.model.ReactionParticipant)

Example 2 with RationalNumberMatrix

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();
// }
}
Also used : Expression(cbit.vcell.parser.Expression) RationalNumberMatrix(cbit.vcell.matrix.RationalNumberMatrix) SpeciesContext(cbit.vcell.model.SpeciesContext) ReactionParticipant(cbit.vcell.model.ReactionParticipant)

Example 3 with RationalNumberMatrix

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();
// }
}
Also used : MembraneMapping(cbit.vcell.mapping.MembraneMapping) SpeciesContextMapping(cbit.vcell.mapping.SpeciesContextMapping) ReactionSpec(cbit.vcell.mapping.ReactionSpec) RationalNumberMatrix(cbit.vcell.matrix.RationalNumberMatrix) SpeciesContext(cbit.vcell.model.SpeciesContext) Feature(cbit.vcell.model.Feature) Expression(cbit.vcell.parser.Expression) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) ReactionParticipant(cbit.vcell.model.ReactionParticipant)

Example 4 with RationalNumberMatrix

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();
// }
}
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

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