Search in sources :

Example 6 with CompartmentSubVolume

use of cbit.vcell.geometry.CompartmentSubVolume 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 7 with CompartmentSubVolume

use of cbit.vcell.geometry.CompartmentSubVolume in project vcell by virtualcell.

the class XmlReader method getCompartmentSubVolume.

/**
 * This method returns a CompartmentSubVolume object from a XML representation.
 * Creation date: (5/1/2001 5:26:17 PM)
 * @return cbit.vcell.geometry.CompartmentSubVolume
 * @param param org.jdom.Element
 */
private CompartmentSubVolume getCompartmentSubVolume(Element param) throws XmlParseException {
    // retrieve the attributes
    String name = param.getAttributeValue(XMLTags.NameAttrTag);
    int handle = Integer.parseInt(param.getAttributeValue(XMLTags.HandleAttrTag));
    // process the key
    KeyValue key = null;
    String temp = param.getAttributeValue(XMLTags.KeyValueAttrTag);
    if (temp != null && temp.length() > 0 && this.readKeysFlag) {
        key = new KeyValue(temp);
    }
    // Create the CompartmentVolume
    CompartmentSubVolume newcompartment = new CompartmentSubVolume(key, handle);
    // set the name
    try {
        newcompartment.setName(name);
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace();
        throw new XmlParseException("A propertyVetoException was fired when setting the name to the compartmentSubVolume " + name, e);
    }
    return newcompartment;
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) KeyValue(org.vcell.util.document.KeyValue) CompartmentSubVolume(cbit.vcell.geometry.CompartmentSubVolume)

Aggregations

CompartmentSubVolume (cbit.vcell.geometry.CompartmentSubVolume)7 Expression (cbit.vcell.parser.Expression)5 SubVolume (cbit.vcell.geometry.SubVolume)3 PropertyVetoException (java.beans.PropertyVetoException)3 SurfaceClass (cbit.vcell.geometry.SurfaceClass)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)1 CSGObject (cbit.vcell.geometry.CSGObject)1 GeometryClass (cbit.vcell.geometry.GeometryClass)1 MembraneMapping (cbit.vcell.mapping.MembraneMapping)1 LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)1 ReactionSpec (cbit.vcell.mapping.ReactionSpec)1 StructureMappingParameter (cbit.vcell.mapping.StructureMapping.StructureMappingParameter)1 DistributedKinetics (cbit.vcell.model.DistributedKinetics)1 Feature (cbit.vcell.model.Feature)1 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)1 LumpedKinetics (cbit.vcell.model.LumpedKinetics)1 Membrane (cbit.vcell.model.Membrane)1 ModelParameter (cbit.vcell.model.Model.ModelParameter)1 Parameter (cbit.vcell.model.Parameter)1