Search in sources :

Example 81 with ReactionStep

use of cbit.vcell.model.ReactionStep in project vcell by virtualcell.

the class StructureAnalyzer method refreshFastSpeciesContextMappings.

/**
 * This method was created in VisualAge.
 */
private void refreshFastSpeciesContextMappings() {
    // System.out.println("StructureAnalyzer.refreshFastSpeciesContextMappings()");
    // GeometryContext geoContext = mathMapping.getSimulationContext().getGeometryContext();
    Vector<SpeciesContextMapping> scFastList = new Vector<SpeciesContextMapping>();
    // 
    if (structures == null) {
        return;
    }
    for (int i = 0; i < structures.length; i++) {
        SpeciesContext[] speciesContexts = mathMapping.getSimulationContext().getReactionContext().getModel().getSpeciesContexts(structures[i]);
        for (int j = 0; j < speciesContexts.length; j++) {
            SpeciesContext sc = speciesContexts[j];
            SpeciesContextMapping scm = mathMapping.getSpeciesContextMapping(sc);
            SpeciesContextSpec scs = mathMapping.getSimulationContext().getReactionContext().getSpeciesContextSpec(sc);
            if (scm.getDependencyExpression() == null && scs.isConstant() == false) {
                // right now all independent vars
                scFastList.addElement(scm);
            }
        }
    }
    if (scFastList.size() > 0) {
        fastSpeciesContextMappings = new SpeciesContextMapping[scFastList.size()];
        scFastList.copyInto(fastSpeciesContextMappings);
    // for (int i=0;i<fastSpeciesContextMappings.length;i++){
    // System.out.println("fastSpeciesContextMappings["+i+"] = "+fastSpeciesContextMappings[i].getSpeciesContext().getName());
    // }
    } else {
        fastSpeciesContextMappings = null;
    }
    // System.out.println("StructureAnalyzer.refreshFastSpeciesContextMapping(), fastSpeciesContextMappings.length = "+scFastList.size());
    // 
    // for each reaction, get all reactionSteps associated with these structures
    // 
    Vector<ReactionStep> rsFastList = new Vector<ReactionStep>();
    ReactionSpec[] reactionSpecs = mathMapping.getSimulationContext().getReactionContext().getReactionSpecs();
    for (int i = 0; i < reactionSpecs.length; i++) {
        ReactionStep rs = reactionSpecs[i].getReactionStep();
        if (reactionSpecs[i].isExcluded()) {
            continue;
        }
        for (int j = 0; j < structures.length; j++) {
            if (rs.getStructure() == structures[j]) {
                if (reactionSpecs[i].isFast()) {
                    rsFastList.addElement(rs);
                }
            }
        }
    }
    if (rsFastList.size() > 0) {
        fastReactionSteps = new ReactionStep[rsFastList.size()];
        rsFastList.copyInto(fastReactionSteps);
    } else {
        fastReactionSteps = null;
        fastSpeciesContextMappings = null;
    }
// System.out.println("StructureAnalyzer.refreshFastSpeciesContextMapping(), reactionSteps.length = "+scFastList.size());
}
Also used : ReactionStep(cbit.vcell.model.ReactionStep) SpeciesContext(cbit.vcell.model.SpeciesContext) Vector(java.util.Vector)

Example 82 with ReactionStep

use of cbit.vcell.model.ReactionStep in project vcell by virtualcell.

the class ElectricalCircuitGraph method getTotalMembraneCurrent.

/**
 * Insert the method's description here.
 * Creation date: (2/19/2002 12:56:13 PM)
 * @return cbit.vcell.parser.Expression
 * @param simContext cbit.vcell.mapping.SimulationContext
 * @param membrane cbit.vcell.model.Membrane
 */
private static Expression getTotalMembraneCurrent(SimulationContext simContext, Membrane membrane, AbstractMathMapping mathMapping) throws ExpressionException {
    MembraneMapping membraneMapping = (MembraneMapping) simContext.getGeometryContext().getStructureMapping(membrane);
    if (!membraneMapping.getCalculateVoltage()) {
        return new Expression(0.0);
    }
    // 
    // gather current terms
    // 
    Expression currentExp = new Expression(0.0);
    ReactionSpec[] reactionSpecs = simContext.getReactionContext().getReactionSpecs();
    StructureMappingParameter sizeParameter = membraneMapping.getSizeParameter();
    Expression area = null;
    if (simContext.getGeometry().getDimension() == 0 && (sizeParameter.getExpression() == null || sizeParameter.getExpression().isZero())) {
        System.out.println("size not set for membrane \"" + membrane.getName() + "\", refer to Structure Mapping in Application \"" + mathMapping.getSimulationContext().getName() + "\"");
        area = membraneMapping.getNullSizeParameterValue();
    } else {
        area = new Expression(sizeParameter, mathMapping.getNameScope());
    }
    for (int i = 0; i < reactionSpecs.length; i++) {
        // 
        if (reactionSpecs[i].isExcluded()) {
            continue;
        }
        if (reactionSpecs[i].getReactionStep().getKinetics() instanceof DistributedKinetics) {
            ReactionStep rs = reactionSpecs[i].getReactionStep();
            DistributedKinetics distributedKinetics = (DistributedKinetics) rs.getKinetics();
            if (rs.getStructure() == membrane) {
                if (!distributedKinetics.getCurrentDensityParameter().getExpression().isZero()) {
                    // 
                    // change sign convension from inward current to outward current (which is consistent with voltage convension)
                    // 
                    currentExp = Expression.add(currentExp, Expression.negate(Expression.mult(new Expression(distributedKinetics.getCurrentDensityParameter(), mathMapping.getNameScope()), area)));
                }
            }
        } else {
            ReactionStep rs = reactionSpecs[i].getReactionStep();
            LumpedKinetics lumpedKinetics = (LumpedKinetics) rs.getKinetics();
            if (rs.getStructure() == membrane) {
                if (!lumpedKinetics.getLumpedCurrentParameter().getExpression().isZero()) {
                    // 
                    if (!(membraneMapping.getGeometryClass() instanceof CompartmentSubVolume)) {
                        throw new RuntimeException("math generation for total currents within spatial electrophysiology not yet implemented");
                    }
                    Expression lumpedCurrentSymbolExp = new Expression(lumpedKinetics.getLumpedCurrentParameter(), mathMapping.getNameScope());
                    currentExp = Expression.add(currentExp, Expression.negate(lumpedCurrentSymbolExp));
                }
            }
        }
    }
    return currentExp.flatten();
}
Also used : DistributedKinetics(cbit.vcell.model.DistributedKinetics) MembraneMapping(cbit.vcell.mapping.MembraneMapping) CompartmentSubVolume(cbit.vcell.geometry.CompartmentSubVolume) LumpedKinetics(cbit.vcell.model.LumpedKinetics) Expression(cbit.vcell.parser.Expression) ReactionSpec(cbit.vcell.mapping.ReactionSpec) ReactionStep(cbit.vcell.model.ReactionStep) StructureMappingParameter(cbit.vcell.mapping.StructureMapping.StructureMappingParameter)

Example 83 with ReactionStep

use of cbit.vcell.model.ReactionStep in project vcell by virtualcell.

the class MathMapping_4_8 method refreshLocalNameCount.

protected void refreshLocalNameCount() {
    localNameCountHash.clear();
    ReactionStep[] reactionSteps = simContext.getModel().getReactionSteps();
    for (int j = 0; j < reactionSteps.length; j++) {
        KineticsParameter[] params = reactionSteps[j].getKinetics().getKineticsParameters();
        for (KineticsParameter kp : params) {
            String name = kp.getName();
            if (localNameCountHash.containsKey(name)) {
                localNameCountHash.put(name, localNameCountHash.get(name) + 1);
            } else {
                localNameCountHash.put(name, 1);
            }
        }
    }
    SpeciesContext[] scs = simContext.getModel().getSpeciesContexts();
    for (SpeciesContext sc : scs) {
        String name = sc.getName();
        if (localNameCountHash.containsKey(name)) {
            localNameCountHash.put(name, localNameCountHash.get(name) + 1);
        } else {
            localNameCountHash.put(name, 1);
        }
    }
    Species[] ss = simContext.getModel().getSpecies();
    for (Species s : ss) {
        String name = s.getCommonName();
        if (localNameCountHash.containsKey(name)) {
            localNameCountHash.put(name, localNameCountHash.get(name) + 1);
        } else {
            localNameCountHash.put(name, 1);
        }
    }
    ModelParameter[] mps = simContext.getModel().getModelParameters();
    for (ModelParameter mp : mps) {
        String name = mp.getName();
        if (localNameCountHash.containsKey(name)) {
            localNameCountHash.put(name, localNameCountHash.get(name) + 1);
        } else {
            localNameCountHash.put(name, 1);
        }
    }
}
Also used : ModelParameter(cbit.vcell.model.Model.ModelParameter) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) ReactionStep(cbit.vcell.model.ReactionStep) SpeciesContext(cbit.vcell.model.SpeciesContext) Species(cbit.vcell.model.Species)

Example 84 with ReactionStep

use of cbit.vcell.model.ReactionStep in project vcell by virtualcell.

the class ModelOptimizationSpec method getModelParameters.

/**
 * Insert the method's description here.
 * Creation date: (8/22/2005 10:38:04 AM)
 * @return cbit.vcell.model.Parameter[]
 */
private Parameter[] getModelParameters() {
    java.util.Vector<Parameter> modelParameterList = new java.util.Vector<Parameter>();
    Model model = getSimulationContext().getModel();
    // 
    // get Model (global) parameters
    // 
    ModelParameter[] globalParams = model.getModelParameters();
    for (int i = 0; i < globalParams.length; i++) {
        if (globalParams[i] != null && globalParams[i].getExpression() != null && globalParams[i].getExpression().isNumeric()) {
            modelParameterList.add(globalParams[i]);
        }
    }
    // 
    // get kinetic parameters that are numbers
    // 
    ReactionStep[] reactionSteps = model.getReactionSteps();
    for (int i = 0; i < reactionSteps.length; i++) {
        // 
        // make sure ReactionSteps are "enabled"
        // 
        ReactionSpec reactionSpec = getSimulationContext().getReactionContext().getReactionSpec(reactionSteps[i]);
        if (reactionSpec == null || reactionSpec.isExcluded()) {
            continue;
        }
        Kinetics.KineticsParameter[] kineticsParameters = reactionSteps[i].getKinetics().getKineticsParameters();
        for (int j = 0; j < kineticsParameters.length; j++) {
            if (kineticsParameters[j].getExpression() != null && kineticsParameters[j].getExpression().isNumeric()) {
                if (((kineticsParameters[j].getRole() == Kinetics.ROLE_CurrentDensity) || (kineticsParameters[j].getRole() == Kinetics.ROLE_LumpedCurrent)) && reactionSteps[i].getPhysicsOptions() == ReactionStep.PHYSICS_MOLECULAR_ONLY) {
                    continue;
                }
                if (((kineticsParameters[j].getRole() == Kinetics.ROLE_ReactionRate) || (kineticsParameters[j].getRole() == Kinetics.ROLE_LumpedReactionRate)) && reactionSteps[i].getPhysicsOptions() == ReactionStep.PHYSICS_ELECTRICAL_ONLY) {
                    continue;
                }
                modelParameterList.add(kineticsParameters[j]);
            }
        }
    }
    // 
    // get initial conditions that are numbers
    // 
    SpeciesContextSpec[] speciesContextSpecs = getSimulationContext().getReactionContext().getSpeciesContextSpecs();
    for (int i = 0; i < speciesContextSpecs.length; i++) {
        SpeciesContextSpec.SpeciesContextSpecParameter initParam = speciesContextSpecs[i].getInitialConditionParameter();
        if (initParam != null && initParam.getExpression() != null && initParam.getExpression().isNumeric()) {
            modelParameterList.add(initParam);
        }
    }
    // 
    // get structure parameters
    // 
    StructureMapping[] structureMappings = getSimulationContext().getGeometryContext().getStructureMappings();
    for (int i = 0; i < structureMappings.length; i++) {
        StructureMapping.StructureMappingParameter[] parameters = structureMappings[i].getParameters();
        for (int j = 0; j < parameters.length; j++) {
            if (parameters[j].getRole() == StructureMapping.ROLE_SpecificCapacitance && structureMappings[i] instanceof MembraneMapping && !((MembraneMapping) structureMappings[i]).getCalculateVoltage()) {
                continue;
            }
            if (parameters[j].getExpression() != null && parameters[j].getExpression().isNumeric()) {
                modelParameterList.add(parameters[j]);
            }
        }
    }
    Parameter[] modelParameters = (Parameter[]) BeanUtils.getArray(modelParameterList, Parameter.class);
    return modelParameters;
}
Also used : MembraneMapping(cbit.vcell.mapping.MembraneMapping) ReactionSpec(cbit.vcell.mapping.ReactionSpec) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) StructureMapping(cbit.vcell.mapping.StructureMapping) ModelParameter(cbit.vcell.model.Model.ModelParameter) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) ReactionStep(cbit.vcell.model.ReactionStep) Model(cbit.vcell.model.Model) Parameter(cbit.vcell.model.Parameter) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) ModelParameter(cbit.vcell.model.Model.ModelParameter) KineticsProxyParameter(cbit.vcell.model.Kinetics.KineticsProxyParameter) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter) Vector(java.util.Vector) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)

Example 85 with ReactionStep

use of cbit.vcell.model.ReactionStep in project vcell by virtualcell.

the class SBPAXHMMRevLawBuilder method addKinetics.

public void addKinetics(KineticContext context) {
    try {
        ReactionStep reaction = context.getReaction();
        HMM_REVKinetics kinetics = new HMM_REVKinetics((SimpleReaction) reaction);
        NameScope modelScope = reaction.getModel().getNameScope();
        ModelParameter kMichaelisFwd = context.getParameter(SBOList.MICHAELIS_CONST_FORW);
        if (kMichaelisFwd != null) {
            KineticsParameter kmfParameter = kinetics.getKmFwdParameter();
            kmfParameter.setExpression(new Expression(kMichaelisFwd, modelScope));
            kmfParameter.setUnitDefinition(kMichaelisFwd.getUnitDefinition());
        }
        ModelParameter kcatf = context.getParameter(SBOList.CATALYTIC_RATE_CONST_FORW);
        if (kcatf != null && context.getCatalysts().size() == 1) {
            KineticsParameter vmaxfParameter = kinetics.getVmaxFwdParameter();
            Catalyst catalyst = context.getCatalysts().iterator().next();
            vmaxfParameter.setExpression(Expression.mult(new Expression(kcatf, modelScope), new Expression(catalyst.getSpeciesContext(), modelScope)));
        // vmaxParameter.setUnitDefinition(vMax.getUnitDefinition());
        } else {
            ModelParameter vMaxf = context.getParameter(SBOList.MAXIMAL_VELOCITY_FORW);
            if (vMaxf != null) {
                KineticsParameter vmaxfParameter = kinetics.getVmaxFwdParameter();
                vmaxfParameter.setExpression(new Expression(vMaxf, modelScope));
                vmaxfParameter.setUnitDefinition(vMaxf.getUnitDefinition());
            }
        }
        ModelParameter kMichaelisRev = context.getParameter(SBOList.MICHAELIS_CONST_REV);
        if (kMichaelisRev != null) {
            KineticsParameter kmrParameter = kinetics.getKmRevParameter();
            kmrParameter.setExpression(new Expression(kMichaelisRev, modelScope));
            kmrParameter.setUnitDefinition(kMichaelisRev.getUnitDefinition());
        }
        ModelParameter kcatr = context.getParameter(SBOList.CATALYTIC_RATE_CONST_FORW);
        if (kcatr != null && context.getCatalysts().size() == 1) {
            KineticsParameter vmaxrParameter = kinetics.getVmaxRevParameter();
            Catalyst catalyst = context.getCatalysts().iterator().next();
            vmaxrParameter.setExpression(Expression.mult(new Expression(kcatr, modelScope), new Expression(catalyst.getSpeciesContext(), modelScope)));
        // vmaxParameter.setUnitDefinition(vMax.getUnitDefinition());
        } else {
            ModelParameter vMaxr = context.getParameter(SBOList.MAXIMAL_VELOCITY_REV);
            if (vMaxr != null) {
                KineticsParameter vmaxrParameter = kinetics.getVmaxRevParameter();
                vmaxrParameter.setExpression(new Expression(vMaxr, modelScope));
                vmaxrParameter.setUnitDefinition(vMaxr.getUnitDefinition());
            }
        }
    } catch (ExpressionException e) {
        e.printStackTrace();
    }
}
Also used : ModelParameter(cbit.vcell.model.Model.ModelParameter) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) NameScope(cbit.vcell.parser.NameScope) Expression(cbit.vcell.parser.Expression) ReactionStep(cbit.vcell.model.ReactionStep) HMM_REVKinetics(cbit.vcell.model.HMM_REVKinetics) Catalyst(cbit.vcell.model.Catalyst) ExpressionException(cbit.vcell.parser.ExpressionException)

Aggregations

ReactionStep (cbit.vcell.model.ReactionStep)111 SpeciesContext (cbit.vcell.model.SpeciesContext)55 Structure (cbit.vcell.model.Structure)37 ReactionParticipant (cbit.vcell.model.ReactionParticipant)33 Expression (cbit.vcell.parser.Expression)33 Model (cbit.vcell.model.Model)32 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)30 ArrayList (java.util.ArrayList)29 ReactionRule (cbit.vcell.model.ReactionRule)26 ModelParameter (cbit.vcell.model.Model.ModelParameter)25 Reactant (cbit.vcell.model.Reactant)25 Kinetics (cbit.vcell.model.Kinetics)24 Product (cbit.vcell.model.Product)23 PropertyVetoException (java.beans.PropertyVetoException)23 SimpleReaction (cbit.vcell.model.SimpleReaction)20 ExpressionException (cbit.vcell.parser.ExpressionException)20 Vector (java.util.Vector)19 SimulationContext (cbit.vcell.mapping.SimulationContext)18 Membrane (cbit.vcell.model.Membrane)18 BioModel (cbit.vcell.biomodel.BioModel)17