Search in sources :

Example 11 with Membrane

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

the class SpeciesContextSpec method initializeForSpatial.

public void initializeForSpatial() {
    if (getDiffusionParameter() != null && getDiffusionParameter().getExpression() != null && getDiffusionParameter().getExpression().isZero()) {
        Expression e = null;
        ModelUnitSystem modelUnitSystem = getSimulationContext().getModel().getUnitSystem();
        VCUnitDefinition micronsqpersecond = modelUnitSystem.getInstance("um2.s-1");
        if (speciesContext.getStructure() instanceof Feature) {
            RationalNumber rn = RationalNumber.getApproximateFraction(micronsqpersecond.convertTo(10, getDiffusionParameter().getUnitDefinition()));
            e = new Expression(rn.doubleValue());
        } else if (speciesContext.getStructure() instanceof Membrane) {
            RationalNumber rn = RationalNumber.getApproximateFraction(micronsqpersecond.convertTo(0.1, getDiffusionParameter().getUnitDefinition()));
            e = new Expression(rn.doubleValue());
        } else {
            RationalNumber rn = RationalNumber.getApproximateFraction(micronsqpersecond.convertTo(1.0, getDiffusionParameter().getUnitDefinition()));
            e = new Expression(rn.doubleValue());
        }
        try {
            getDiffusionParameter().setExpression(e);
        } catch (ExpressionBindingException e1) {
            e1.printStackTrace();
            throw new RuntimeException("Error while initializing diffusion rate, " + e1.getMessage());
        }
    }
}
Also used : VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) Membrane(cbit.vcell.model.Membrane) RationalNumber(cbit.vcell.matrix.RationalNumber) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) Feature(cbit.vcell.model.Feature) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 12 with Membrane

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

the class SpeciesContextSpec method hasTransport.

public boolean hasTransport() {
    if (isConstant() || isWellMixed() || simulationContext == null || simulationContext.getGeometry() == null || simulationContext.getGeometry().getDimension() == 0) {
        return false;
    }
    int dimension = simulationContext.getGeometry().getDimension();
    SpeciesContext speciesContext = getSpeciesContext();
    if (speciesContext.getStructure() instanceof Membrane) {
        if (dimension > 1 && !getDiffusionParameter().getExpression().isZero()) {
            return true;
        }
    } else if (speciesContext.getStructure() instanceof Feature) {
        if (!getDiffusionParameter().getExpression().isZero()) {
            return true;
        }
        if (getVelocityXParameter().getExpression() != null && !getVelocityXParameter().getExpression().isZero()) {
            return true;
        }
        SpatialQuantity[] velX_quantities = getVelocityQuantities(QuantityComponent.X);
        if (velX_quantities.length > 0) {
            return true;
        }
        if (dimension > 1) {
            if (getVelocityYParameter().getExpression() != null && !getVelocityYParameter().getExpression().isZero()) {
                return true;
            }
            if (dimension > 2) {
                if (getVelocityZParameter().getExpression() != null && !getVelocityZParameter().getExpression().isZero()) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : Membrane(cbit.vcell.model.Membrane) SpeciesContext(cbit.vcell.model.SpeciesContext) Feature(cbit.vcell.model.Feature)

Example 13 with Membrane

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

the class SpeciesContextSpec method computeApplicableParameterList.

public List<SpeciesContextSpecParameter> computeApplicableParameterList() {
    List<SpeciesContextSpecParameter> speciesContextSpecParameterList = new ArrayList<SpeciesContextSpecParameter>();
    speciesContextSpecParameterList.add(getInitialConditionParameter());
    int dimension = simulationContext.getGeometry().getDimension();
    if (!isConstant() && !isWellMixed() && dimension > 0) {
        // diffusion
        speciesContextSpecParameterList.add(getDiffusionParameter());
    }
    if (hasTransport()) {
        SpeciesContext speciesContext = getSpeciesContext();
        if (speciesContext.getStructure() instanceof Membrane) {
            // boundary condition
            speciesContextSpecParameterList.add(getBoundaryXmParameter());
            speciesContextSpecParameterList.add(getBoundaryXpParameter());
            speciesContextSpecParameterList.add(getBoundaryYmParameter());
            speciesContextSpecParameterList.add(getBoundaryYpParameter());
            if (dimension > 2) {
                speciesContextSpecParameterList.add(getBoundaryZmParameter());
                speciesContextSpecParameterList.add(getBoundaryZpParameter());
            }
        } else if (speciesContext.getStructure() instanceof Feature) {
            // boundary condition
            speciesContextSpecParameterList.add(getBoundaryXmParameter());
            speciesContextSpecParameterList.add(getBoundaryXpParameter());
            if (dimension > 1) {
                speciesContextSpecParameterList.add(getBoundaryYmParameter());
                speciesContextSpecParameterList.add(getBoundaryYpParameter());
                if (dimension > 2) {
                    speciesContextSpecParameterList.add(getBoundaryZmParameter());
                    speciesContextSpecParameterList.add(getBoundaryZpParameter());
                }
            }
            // velocity
            speciesContextSpecParameterList.add(getVelocityXParameter());
            if (dimension > 1) {
                speciesContextSpecParameterList.add(getVelocityYParameter());
                if (dimension > 2) {
                    speciesContextSpecParameterList.add(getVelocityZParameter());
                }
            }
        }
    }
    return speciesContextSpecParameterList;
}
Also used : ArrayList(java.util.ArrayList) Membrane(cbit.vcell.model.Membrane) SpeciesContext(cbit.vcell.model.SpeciesContext) Feature(cbit.vcell.model.Feature)

Example 14 with Membrane

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

the class ElectricalCircuitGraph method getCircuitGraph.

/**
 * Insert the method's description here.
 * Creation date: (2/19/2002 11:24:04 AM)
 * @return cbit.vcell.mapping.potential.Graph
 * @param simContext cbit.vcell.mapping.SimulationContext
 */
public static Graph getCircuitGraph(SimulationContext simContext, AbstractMathMapping mathMapping) throws ExpressionException {
    Graph graph = new Graph();
    Model model = simContext.getModel();
    // 
    // add nodes to the graph (one for each Feature)
    // 
    Structure[] structures = model.getStructures();
    for (int i = 0; i < structures.length; i++) {
        if (structures[i] instanceof Feature) {
            graph.addNode(new Node(structures[i].getName(), structures[i]));
        }
    }
    // 
    // add edges for all current clamp electrodes (always have dependent voltages)
    // 
    ElectricalStimulus[] stimuli = simContext.getElectricalStimuli();
    Electrode groundElectrode = simContext.getGroundElectrode();
    for (int i = 0; i < stimuli.length; i++) {
        ElectricalStimulus stimulus = stimuli[i];
        // 
        // get electrodes
        // 
        Electrode probeElectrode = stimulus.getElectrode();
        if (probeElectrode == null) {
            throw new RuntimeException("null electrode for electrical stimulus");
        }
        if (groundElectrode == null) {
            throw new RuntimeException("null ground electrode for electrical stimulus");
        }
        // if (!membraneMapping.getResolved()){
        Node groundNode = graph.getNode(groundElectrode.getFeature().getName());
        Node probeNode = graph.getNode(probeElectrode.getFeature().getName());
        if (stimulus instanceof CurrentDensityClampStimulus) {
            CurrentDensityClampStimulus ccStimulus = (CurrentDensityClampStimulus) stimulus;
            ElectricalDevice device = new CurrentClampElectricalDevice(ccStimulus, mathMapping);
            Edge edge = new Edge(probeNode, groundNode, device);
            graph.addEdge(edge);
        } else if (stimulus instanceof TotalCurrentClampStimulus) {
            TotalCurrentClampStimulus ccStimulus = (TotalCurrentClampStimulus) stimulus;
            ElectricalDevice device = new CurrentClampElectricalDevice(ccStimulus, mathMapping);
            Edge edge = new Edge(probeNode, groundNode, device);
            graph.addEdge(edge);
        }
    // }
    }
    // 
    // add edges for all membranes
    // 
    ElectricalTopology electricalTopology = simContext.getModel().getElectricalTopology();
    for (int i = 0; i < structures.length; i++) {
        if (structures[i] instanceof Membrane) {
            Membrane membrane = (Membrane) structures[i];
            MembraneMapping membraneMapping = (MembraneMapping) simContext.getGeometryContext().getStructureMapping(membrane);
            Feature positiveFeature = electricalTopology.getPositiveFeature(membrane);
            Feature negativeFeature = electricalTopology.getNegativeFeature(membrane);
            if (positiveFeature != null && negativeFeature != null) {
                Node insideNode = graph.getNode(positiveFeature.getName());
                Node outsideNode = graph.getNode(negativeFeature.getName());
                // 
                // getTotalMembraneCurrent() already converts to "outwardCurrent" so that same convention as voltage
                // 
                Expression currentSource = getTotalMembraneCurrent(simContext, membrane, mathMapping);
                MembraneElectricalDevice device = new MembraneElectricalDevice(membraneMapping, mathMapping);
                device.getParameterFromRole(ElectricalDevice.ROLE_TransmembraneCurrent).setExpression(currentSource);
                Edge edge = new Edge(insideNode, outsideNode, device);
                graph.addEdge(edge);
            }
        }
    }
    // 
    for (int i = 0; i < stimuli.length; i++) {
        ElectricalStimulus stimulus = stimuli[i];
        // 
        // get electrodes
        // 
        Electrode probeElectrode = stimulus.getElectrode();
        if (probeElectrode == null) {
            throw new RuntimeException("null electrode for electrical stimulus");
        }
        if (groundElectrode == null) {
            throw new RuntimeException("null ground electrode for electrical stimulus");
        }
        // if (!membraneMapping.getResolved()){
        Node groundNode = graph.getNode(groundElectrode.getFeature().getName());
        Node probeNode = graph.getNode(probeElectrode.getFeature().getName());
        if (stimulus instanceof VoltageClampStimulus) {
            VoltageClampStimulus vcStimulus = (VoltageClampStimulus) stimulus;
            ElectricalDevice device = new VoltageClampElectricalDevice(vcStimulus, mathMapping);
            Edge edge = new Edge(probeNode, groundNode, device);
            graph.addEdge(edge);
        }
    // }
    }
    // System.out.println(graph);
    return graph;
}
Also used : MembraneMapping(cbit.vcell.mapping.MembraneMapping) Electrode(cbit.vcell.mapping.Electrode) Node(cbit.util.graph.Node) ElectricalTopology(cbit.vcell.model.Model.ElectricalTopology) CurrentDensityClampStimulus(cbit.vcell.mapping.CurrentDensityClampStimulus) Feature(cbit.vcell.model.Feature) TotalCurrentClampStimulus(cbit.vcell.mapping.TotalCurrentClampStimulus) ElectricalStimulus(cbit.vcell.mapping.ElectricalStimulus) Graph(cbit.util.graph.Graph) Expression(cbit.vcell.parser.Expression) VoltageClampStimulus(cbit.vcell.mapping.VoltageClampStimulus) Model(cbit.vcell.model.Model) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) Edge(cbit.util.graph.Edge)

Example 15 with Membrane

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

the class MathMapping_4_8 method getResidualVolumeFraction.

public Expression getResidualVolumeFraction(FeatureMapping featureMapping) throws ExpressionException {
    Expression exp = new Expression(1.0);
    Structure[] structures = simContext.getGeometryContext().getModel().getStructures();
    StructureTopology structTopology = simContext.getModel().getStructureTopology();
    for (int i = 0; i < structures.length; i++) {
        // 
        // for each membrane that is distributed within this feature, subtract that volume fraction
        // ????? beware, 1 - v1 - v2 ... can result in a negative number if we're not careful.
        // 
        Structure struct = structures[i];
        if (struct instanceof Membrane) {
            if ((structTopology.getOutsideFeature((Membrane) struct)) == featureMapping.getFeature()) {
                MembraneMapping mm = (MembraneMapping) simContext.getGeometryContext().getStructureMapping(struct);
                if (getResolved(mm) == false) {
                    exp = Expression.add(exp, Expression.negate(new Expression(mm.getVolumeFractionParameter(), simContext.getNameScope())));
                }
            }
        }
    }
    return exp;
}
Also used : MembraneMapping(cbit.vcell.mapping.MembraneMapping) StructureTopology(cbit.vcell.model.Model.StructureTopology) Expression(cbit.vcell.parser.Expression) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure)

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