Search in sources :

Example 21 with Membrane

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

the class DiffEquMathMapping method computeBoundaryConditionSource.

// determine membrane inside and outside subvolume
public static Pair<SubVolume, SubVolume> computeBoundaryConditionSource(Model model, SimulationContext simContext, SurfaceClass surfaceClass) {
    SubVolume outerSubVolume = null;
    SubVolume innerSubVolume = null;
    Structure[] mappedStructures = simContext.getGeometryContext().getStructuresFromGeometryClass(surfaceClass);
    // inside and outside correspond to structure hierarchy when present
    for (Structure s : mappedStructures) {
        if (s instanceof Membrane) {
            Membrane m = (Membrane) s;
            Feature infeature = model.getStructureTopology().getInsideFeature(m);
            if (infeature != null) {
                FeatureMapping insm = (FeatureMapping) simContext.getGeometryContext().getStructureMapping(infeature);
                if (insm.getGeometryClass() instanceof SubVolume) {
                    innerSubVolume = (SubVolume) insm.getGeometryClass();
                }
            }
            Feature outfeature = model.getStructureTopology().getOutsideFeature(m);
            if (outfeature != null) {
                FeatureMapping outsm = (FeatureMapping) simContext.getGeometryContext().getStructureMapping(outfeature);
                if (outsm.getGeometryClass() instanceof SubVolume) {
                    outerSubVolume = (SubVolume) outsm.getGeometryClass();
                }
            }
        }
    }
    // make the choice deterministic
    if (innerSubVolume == null || outerSubVolume == null || innerSubVolume == outerSubVolume) {
        Set<SubVolume> sv = surfaceClass.getAdjacentSubvolumes();
        Iterator<SubVolume> iterator = sv.iterator();
        innerSubVolume = iterator.next();
        outerSubVolume = iterator.next();
        if (innerSubVolume.getName().compareTo(outerSubVolume.getName()) > 0) {
            SubVolume temp = innerSubVolume;
            innerSubVolume = outerSubVolume;
            outerSubVolume = temp;
        }
    }
    Pair<SubVolume, SubVolume> ret = new Pair<>(innerSubVolume, outerSubVolume);
    return ret;
}
Also used : SubVolume(cbit.vcell.geometry.SubVolume) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) Feature(cbit.vcell.model.Feature) Pair(org.vcell.util.Pair)

Example 22 with Membrane

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

the class DiffEquMathMapping method refreshVariables.

/**
 * This method was created in VisualAge.
 */
private void refreshVariables() throws MappingException {
    // System.out.println("MathMapping.refreshVariables()");
    // 
    // non-constant dependent variables require a function
    // 
    Enumeration<SpeciesContextMapping> enum1 = getSpeciesContextMappings();
    while (enum1.hasMoreElements()) {
        SpeciesContextMapping scm = enum1.nextElement();
        SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
        if (scm.getDependencyExpression() != null && !scs.isConstant()) {
            // scm.setVariable(new Function(scm.getSpeciesContext().getName(),scm.getDependencyExpression()));
            scm.setVariable(null);
        }
        if (getSimulationContext().hasEventAssignment(scs.getSpeciesContext())) {
            scm.setDependencyExpression(null);
        }
    }
    // 
    // non-constant independent variables require either a membrane or volume variable
    // 
    enum1 = getSpeciesContextMappings();
    while (enum1.hasMoreElements()) {
        SpeciesContextMapping scm = (SpeciesContextMapping) enum1.nextElement();
        SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
        if (scm.getDependencyExpression() == null && (!scs.isConstant() || getSimulationContext().hasEventAssignment(scs.getSpeciesContext()))) {
            StructureMapping sm = simContext.getGeometryContext().getStructureMapping(scm.getSpeciesContext().getStructure());
            Structure struct = scm.getSpeciesContext().getStructure();
            Domain domain = null;
            if (sm.getGeometryClass() != null) {
                domain = new Domain(sm.getGeometryClass());
            }
            if (struct instanceof Feature || struct instanceof Membrane) {
                if (sm.getGeometryClass() instanceof SurfaceClass) {
                    if (scs.isWellMixed()) {
                        scm.setVariable(new MembraneRegionVariable(scm.getSpeciesContext().getName(), domain));
                    } else if (getSimulationContext().isStoch() && getSimulationContext().getGeometry().getDimension() > 0 && !scs.isForceContinuous()) {
                        scm.setVariable(new MemVariable(scm.getSpeciesContext().getName() + "_conc", domain));
                    } else {
                        scm.setVariable(new MemVariable(scm.getSpeciesContext().getName(), domain));
                    }
                } else {
                    if (scs.isWellMixed()) {
                        scm.setVariable(new VolumeRegionVariable(scm.getSpeciesContext().getName(), domain));
                    } else if (getSimulationContext().isStoch() && getSimulationContext().getGeometry().getDimension() > 0 && !scs.isForceContinuous()) {
                        scm.setVariable(new VolVariable(scm.getSpeciesContext().getName() + "_conc", domain));
                    } else {
                        scm.setVariable(new VolVariable(scm.getSpeciesContext().getName(), domain));
                    }
                }
            } else {
                throw new MappingException("class " + scm.getSpeciesContext().getStructure().getClass() + " not supported");
            }
            mathSymbolMapping.put(scm.getSpeciesContext(), scm.getVariable().getName());
        }
    }
}
Also used : MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) SurfaceClass(cbit.vcell.geometry.SurfaceClass) VolVariable(cbit.vcell.math.VolVariable) Feature(cbit.vcell.model.Feature) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) MemVariable(cbit.vcell.math.MemVariable) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubDomain(cbit.vcell.math.SubDomain) PointSubDomain(cbit.vcell.math.PointSubDomain) Domain(cbit.vcell.math.Variable.Domain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain)

Example 23 with Membrane

use of cbit.vcell.model.Membrane 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 24 with Membrane

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

the class StructureAnalyzer method getReactionRateExpression.

public Expression getReactionRateExpression(ReactionStep reactionStep, ReactionParticipant reactionParticipant) throws Exception {
    if (reactionParticipant instanceof Catalyst) {
        throw new Exception("Catalyst " + reactionParticipant + " doesn't have a rate for this reaction");
    // return new Expression(0.0);
    }
    double stoich = reactionStep.getStoichiometry(reactionParticipant.getSpeciesContext());
    if (stoich == 0.0) {
        return new Expression(0.0);
    }
    if (reactionStep.getKinetics() instanceof DistributedKinetics) {
        DistributedKinetics distributedKinetics = (DistributedKinetics) reactionStep.getKinetics();
        if (stoich != 1) {
            Expression exp = Expression.mult(new Expression(stoich), new Expression(distributedKinetics.getReactionRateParameter(), mathMapping_4_8.getNameScope()));
            return exp;
        } else {
            Expression exp = new Expression(distributedKinetics.getReactionRateParameter(), mathMapping_4_8.getNameScope());
            return exp;
        }
    } else if (reactionStep.getKinetics() instanceof LumpedKinetics) {
        Structure.StructureSize structureSize = reactionStep.getStructure().getStructureSize();
        // 
        // need to put this into concentration/time with respect to structure for reaction.
        // 
        LumpedKinetics lumpedKinetics = (LumpedKinetics) reactionStep.getKinetics();
        Expression factor = null;
        ModelUnitSystem unitSystem = mathMapping_4_8.getSimulationContext().getModel().getUnitSystem();
        if (reactionStep.getStructure() instanceof Feature || ((reactionStep.getStructure() instanceof Membrane) && reactionStep instanceof FluxReaction)) {
            VCUnitDefinition lumpedToVolumeSubstance = unitSystem.getVolumeSubstanceUnit().divideBy(unitSystem.getLumpedReactionSubstanceUnit());
            factor = Expression.div(new Expression(lumpedToVolumeSubstance.getDimensionlessScale()), new Expression(structureSize, mathMapping_4_8.getNameScope()));
        } else if (reactionStep.getStructure() instanceof Membrane && reactionStep instanceof SimpleReaction) {
            VCUnitDefinition lumpedToVolumeSubstance = unitSystem.getMembraneSubstanceUnit().divideBy(unitSystem.getLumpedReactionSubstanceUnit());
            factor = Expression.div(new Expression(lumpedToVolumeSubstance.getDimensionlessScale()), new Expression(structureSize, mathMapping_4_8.getNameScope()));
        } else {
            throw new RuntimeException("failed to create reaction rate expression for reaction " + reactionStep.getName() + ", with kinetic type of " + reactionStep.getKinetics().getClass().getName());
        }
        if (stoich != 1) {
            Expression exp = Expression.mult(new Expression(stoich), Expression.mult(new Expression(lumpedKinetics.getLumpedReactionRateParameter(), mathMapping_4_8.getNameScope()), factor));
            return exp;
        } else {
            Expression exp = Expression.mult(new Expression(lumpedKinetics.getLumpedReactionRateParameter(), mathMapping_4_8.getNameScope()), factor);
            return exp;
        }
    } else {
        throw new RuntimeException("unexpected kinetic type " + reactionStep.getKinetics().getClass().getName());
    }
}
Also used : DistributedKinetics(cbit.vcell.model.DistributedKinetics) SimpleReaction(cbit.vcell.model.SimpleReaction) LumpedKinetics(cbit.vcell.model.LumpedKinetics) FluxReaction(cbit.vcell.model.FluxReaction) Feature(cbit.vcell.model.Feature) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) Membrane(cbit.vcell.model.Membrane) Catalyst(cbit.vcell.model.Catalyst) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 25 with Membrane

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

the class VolumeStructureAnalyzer method refreshStructures.

/**
 * Build list of structures that are mapped to this volume subdomain
 */
protected void refreshStructures() {
    // 
    // get all structures that are mapped to this subvolume (subdomain)
    // 
    Structure[] structs = mathMapping_4_8.getStructures(subVolume);
    Vector<Structure> structList = new Vector<Structure>();
    if (structs != null) {
        for (int i = 0; i < structs.length; i++) {
            // 
            if (structs[i] instanceof Membrane) {
                Membrane membrane = (Membrane) structs[i];
                MembraneMapping membraneMapping = (MembraneMapping) mathMapping_4_8.getSimulationContext().getGeometryContext().getStructureMapping(membrane);
                if (mathMapping_4_8.getResolved(membraneMapping)) {
                    continue;
                }
            }
            // 
            // add all others to the structure list
            // 
            structList.addElement(structs[i]);
        }
    }
    // 
    if (structList.size() > 0) {
        structures = new Structure[structList.size()];
        structList.copyInto(structures);
    } else {
        structures = null;
    }
}
Also used : MembraneMapping(cbit.vcell.mapping.MembraneMapping) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) Vector(java.util.Vector)

Aggregations

Membrane (cbit.vcell.model.Membrane)77 Feature (cbit.vcell.model.Feature)50 Structure (cbit.vcell.model.Structure)47 Expression (cbit.vcell.parser.Expression)31 SpeciesContext (cbit.vcell.model.SpeciesContext)25 MembraneMapping (cbit.vcell.mapping.MembraneMapping)20 StructureTopology (cbit.vcell.model.Model.StructureTopology)19 ExpressionException (cbit.vcell.parser.ExpressionException)18 PropertyVetoException (java.beans.PropertyVetoException)17 FluxReaction (cbit.vcell.model.FluxReaction)16 Model (cbit.vcell.model.Model)16 ReactionStep (cbit.vcell.model.ReactionStep)16 SimpleReaction (cbit.vcell.model.SimpleReaction)16 ArrayList (java.util.ArrayList)14 StructureMapping (cbit.vcell.mapping.StructureMapping)12 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)12 ReactionParticipant (cbit.vcell.model.ReactionParticipant)12 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)12 SubVolume (cbit.vcell.geometry.SubVolume)11 SurfaceClass (cbit.vcell.geometry.SurfaceClass)11