Search in sources :

Example 6 with MembraneMapping

use of cbit.vcell.mapping.MembraneMapping 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 7 with MembraneMapping

use of cbit.vcell.mapping.MembraneMapping 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)

Example 8 with MembraneMapping

use of cbit.vcell.mapping.MembraneMapping in project vcell by virtualcell.

the class MathMapping_4_8 method refreshKFluxParameters.

/**
 * Insert the method's description here.
 * Creation date: (6/13/2004 8:10:34 AM)
 */
private void refreshKFluxParameters() throws ExpressionException {
    MathMapping_4_8.MathMappingParameter[] newMathMappingParameters = (MathMappingParameter[]) fieldMathMappingParameters.clone();
    // 
    for (int i = 0; i < newMathMappingParameters.length; i++) {
        if (newMathMappingParameters[i].getRole() == PARAMETER_ROLE_KFLUX) {
            newMathMappingParameters = (MathMappingParameter[]) BeanUtils.removeElement(newMathMappingParameters, newMathMappingParameters[i]);
        }
    }
    // 
    // Add new KFlux Parameters
    // 
    StructureMapping[] structureMappings = simContext.getGeometryContext().getStructureMappings();
    StructureTopology structTopology = simContext.getModel().getStructureTopology();
    VCUnitDefinition lengthInverseUnit = simContext.getModel().getX().getUnitDefinition().getInverse();
    for (int i = 0; i < structureMappings.length; i++) {
        if (structureMappings[i] instanceof MembraneMapping && !getResolved(structureMappings[i])) {
            MembraneMapping membraneMapping = (MembraneMapping) structureMappings[i];
            // 
            // add "inside" flux correction
            // 
            Expression insideCorrectionExp = getInsideFluxCorrectionExpression(membraneMapping);
            insideCorrectionExp.bindExpression(this);
            Membrane memMappingMembrane = membraneMapping.getMembrane();
            Feature insideFeature = structTopology.getInsideFeature(memMappingMembrane);
            String membraneNameWithScope = membraneMapping.getNameScope().getName();
            String insideName = "KFlux_" + membraneNameWithScope + "_" + insideFeature.getNameScope().getName();
            KFluxParameter insideKFluxParameter = new KFluxParameter(insideName, insideCorrectionExp, lengthInverseUnit, membraneMapping, insideFeature);
            newMathMappingParameters = (MathMappingParameter[]) BeanUtils.addElement(newMathMappingParameters, insideKFluxParameter);
            // 
            // add "outside" flux correction
            // 
            Expression outsideCorrectionExp = getOutsideFluxCorrectionExpression(simContext, membraneMapping);
            outsideCorrectionExp.bindExpression(this);
            Feature outsideFeature = structTopology.getOutsideFeature(memMappingMembrane);
            String outsideName = "KFlux_" + membraneNameWithScope + "_" + outsideFeature.getNameScope().getName();
            KFluxParameter outsideKFluxParameter = new KFluxParameter(outsideName, outsideCorrectionExp, lengthInverseUnit, membraneMapping, outsideFeature);
            newMathMappingParameters = (MathMappingParameter[]) BeanUtils.addElement(newMathMappingParameters, outsideKFluxParameter);
        }
    }
    try {
        setMathMapppingParameters(newMathMappingParameters);
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace(System.out);
        throw new RuntimeException(e.getMessage());
    }
}
Also used : MembraneMapping(cbit.vcell.mapping.MembraneMapping) StructureTopology(cbit.vcell.model.Model.StructureTopology) StructureMapping(cbit.vcell.mapping.StructureMapping) Feature(cbit.vcell.model.Feature) PropertyVetoException(java.beans.PropertyVetoException) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) Membrane(cbit.vcell.model.Membrane)

Example 9 with MembraneMapping

use of cbit.vcell.mapping.MembraneMapping in project vcell by virtualcell.

the class MathMapping_4_8 method getStructures.

public Structure[] getStructures(SubVolume subVolume) {
    ArrayList<Structure> list = new ArrayList<Structure>();
    StructureMapping[] structureMappings = simContext.getGeometryContext().getStructureMappings();
    // 
    for (int i = 0; i < structureMappings.length; i++) {
        StructureMapping sm = structureMappings[i];
        if (sm instanceof FeatureMapping && ((FeatureMapping) sm).getGeometryClass() == subVolume) {
            list.add(sm.getStructure());
        }
    }
    // 
    for (int i = 0; i < structureMappings.length; i++) {
        StructureMapping sm = structureMappings[i];
        if (sm instanceof MembraneMapping) {
            Membrane membrane = ((MembraneMapping) sm).getMembrane();
            if (list.contains(simContext.getModel().getStructureTopology().getInsideFeature(membrane))) {
                list.add(membrane);
            }
        }
    }
    if (list.size() > 0) {
        return list.toArray(new Structure[list.size()]);
    } else {
        return null;
    }
}
Also used : MembraneMapping(cbit.vcell.mapping.MembraneMapping) FeatureMapping(cbit.vcell.mapping.FeatureMapping) ArrayList(java.util.ArrayList) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) StructureMapping(cbit.vcell.mapping.StructureMapping)

Example 10 with MembraneMapping

use of cbit.vcell.mapping.MembraneMapping in project vcell by virtualcell.

the class MathMapping_4_8 method getMathSymbol0.

/**
 * Substitutes appropriate variables for speciesContext bindings
 *
 * @return cbit.vcell.parser.Expression
 * @param origExp cbit.vcell.parser.Expression
 * @param structureMapping cbit.vcell.mapping.StructureMapping
 */
private String getMathSymbol0(SymbolTableEntry ste, StructureMapping structureMapping) throws MappingException {
    String steName = ste.getName();
    if (ste instanceof Kinetics.KineticsParameter) {
        Integer count = localNameCountHash.get(steName);
        if (count == null) {
            throw new MappingException("KineticsParameter " + steName + " not found in local name count");
        }
        if (count > 1 || steName.equals("J")) {
            return steName + "_" + ste.getNameScope().getName();
        // return getNameScope().getSymbolName(ste);
        } else {
            return steName;
        }
    }
    if (ste instanceof MathMapping_4_8.ProbabilityParameter) {
        // be careful here, to see if we need mangle the reaction name
        MathMapping_4_8.ProbabilityParameter probParm = (MathMapping_4_8.ProbabilityParameter) ste;
        return probParm.getName();
    }
    if (ste instanceof MathMapping_4_8.SpeciesConcentrationParameter) {
        MathMapping_4_8.SpeciesConcentrationParameter concParm = (MathMapping_4_8.SpeciesConcentrationParameter) ste;
        return concParm.getSpeciesContextSpec().getSpeciesContext().getName() + MATH_FUNC_SUFFIX_SPECIES_CONCENTRATION;
    }
    if (ste instanceof MathMapping_4_8.SpeciesCountParameter) {
        MathMapping_4_8.SpeciesCountParameter countParm = (MathMapping_4_8.SpeciesCountParameter) ste;
        return countParm.getSpeciesContextSpec().getSpeciesContext().getName() + MATH_VAR_SUFFIX_SPECIES_COUNT;
    }
    if (ste instanceof MathMapping_4_8.EventAssignmentInitParameter) {
        MathMapping_4_8.EventAssignmentInitParameter eventInitParm = (MathMapping_4_8.EventAssignmentInitParameter) ste;
        return eventInitParm.getName() + MATH_FUNC_SUFFIX_EVENTASSIGN_INIT;
    }
    if (ste instanceof Model.ReservedSymbol) {
        return steName;
    }
    if (ste instanceof Membrane.MembraneVoltage) {
        return steName;
    }
    if (ste instanceof Structure.StructureSize) {
        Structure structure = ((Structure.StructureSize) ste).getStructure();
        StructureMapping.StructureMappingParameter sizeParameter = simContext.getGeometryContext().getStructureMapping(structure).getSizeParameter();
        return getMathSymbol(sizeParameter, structureMapping);
    }
    if (ste instanceof ProxyParameter) {
        ProxyParameter pp = (ProxyParameter) ste;
        return getMathSymbol0(pp.getTarget(), structureMapping);
    }
    // 
    Model model = simContext.getModel();
    if (ste instanceof ModelParameter) {
        ModelParameter mp = (ModelParameter) ste;
        if (simContext.getGeometry().getDimension() == 0) {
            return mp.getName();
        } else {
            if (mp.getExpression().getSymbols() == null) {
                return mp.getName();
            }
            // check if global param variant name exists in globalVarsHash. If so, return it, else, throw exception.
            Hashtable<String, Expression> smVariantsHash = globalParamVariantsHash.get(mp);
            String variantName = mp.getName() + "_" + TokenMangler.fixTokenStrict(structureMapping.getStructure().getName());
            if (smVariantsHash.get(variantName) != null) {
                return variantName;
            } else {
                // global param variant doesn't exist in the hash, so get the substituted expression for global param and
                // gather all symbols (speciesContexts) that do not match with arg 'structureMapping' to display a proper error message.
                Expression expr = null;
                try {
                    expr = substituteGlobalParameters(mp.getExpression());
                } catch (ExpressionException e) {
                    e.printStackTrace(System.out);
                    throw new RuntimeException("Could not substitute expression for global parameter '" + mp.getName() + "' with expression '" + "'" + e.getMessage());
                }
                // find symbols (typically speciesContexts) in 'exp' that do not match with the arg 'structureMapping'
                String[] symbols = expr.getSymbols();
                String msg = "";
                if (symbols != null) {
                    Vector<String> spContextNamesVector = new Vector<String>();
                    for (int j = 0; j < symbols.length; j++) {
                        SpeciesContext sc = model.getSpeciesContext(symbols[j]);
                        if (sc != null) {
                            if (!sc.getStructure().compareEqual(structureMapping.getStructure())) {
                                spContextNamesVector.addElement(sc.getName());
                            }
                        }
                    }
                    for (int i = 0; (spContextNamesVector != null && i < spContextNamesVector.size()); i++) {
                        if (i == 0) {
                            msg += "'" + spContextNamesVector.elementAt(i) + ", ";
                        } else if (i == spContextNamesVector.size() - 1) {
                            msg += spContextNamesVector.elementAt(i) + "'";
                        } else {
                            msg += spContextNamesVector.elementAt(i) + ", ";
                        }
                    }
                }
                throw new RuntimeException("Global parameter '" + mp.getName() + "' is not defined in compartment '" + structureMapping.getStructure().getName() + "', but was referenced in that compartment." + "\n\nExpression '" + mp.getExpression().infix() + "' for global parameter '" + mp.getName() + "' expands to '" + expr.infix() + "' " + "and contains species " + msg + " that is/are not in adjacent compartments.");
            }
        // return (mp.getName()+"_"+TokenMangler.fixTokenStrict(structureMapping.getStructure().getName()));
        }
    }
    if (ste instanceof SpeciesContextSpec.SpeciesContextSpecParameter) {
        SpeciesContextSpec.SpeciesContextSpecParameter scsParm = (SpeciesContextSpec.SpeciesContextSpecParameter) ste;
        if (scsParm.getRole() == SpeciesContextSpec.ROLE_InitialConcentration) {
            return ((SpeciesContextSpec) (scsParm.getNameScope().getScopedSymbolTable())).getSpeciesContext().getName() + MATH_FUNC_SUFFIX_SPECIES_INIT_CONCENTRATION;
        }
        if (scsParm.getRole() == SpeciesContextSpec.ROLE_InitialCount) {
            return ((SpeciesContextSpec) (scsParm.getNameScope().getScopedSymbolTable())).getSpeciesContext().getName() + MATH_FUNC_SUFFIX_SPECIES_INIT_COUNT;
        }
        if (scsParm.getRole() == SpeciesContextSpec.ROLE_DiffusionRate) {
            return ((SpeciesContextSpec) (scsParm.getNameScope().getScopedSymbolTable())).getSpeciesContext().getName() + "_diffusionRate";
        }
        if (scsParm.getRole() == SpeciesContextSpec.ROLE_BoundaryValueXm) {
            return ((SpeciesContextSpec) (scsParm.getNameScope().getScopedSymbolTable())).getSpeciesContext().getName() + "_boundaryXm";
        }
        if (scsParm.getRole() == SpeciesContextSpec.ROLE_BoundaryValueXp) {
            return ((SpeciesContextSpec) (scsParm.getNameScope().getScopedSymbolTable())).getSpeciesContext().getName() + "_boundaryXp";
        }
        if (scsParm.getRole() == SpeciesContextSpec.ROLE_BoundaryValueYm) {
            return ((SpeciesContextSpec) (scsParm.getNameScope().getScopedSymbolTable())).getSpeciesContext().getName() + "_boundaryYm";
        }
        if (scsParm.getRole() == SpeciesContextSpec.ROLE_BoundaryValueYp) {
            return ((SpeciesContextSpec) (scsParm.getNameScope().getScopedSymbolTable())).getSpeciesContext().getName() + "_boundaryYp";
        }
        if (scsParm.getRole() == SpeciesContextSpec.ROLE_BoundaryValueZm) {
            return ((SpeciesContextSpec) (scsParm.getNameScope().getScopedSymbolTable())).getSpeciesContext().getName() + "_boundaryZm";
        }
        if (scsParm.getRole() == SpeciesContextSpec.ROLE_BoundaryValueZp) {
            return ((SpeciesContextSpec) (scsParm.getNameScope().getScopedSymbolTable())).getSpeciesContext().getName() + "_boundaryZp";
        }
        if (scsParm.getRole() == SpeciesContextSpec.ROLE_VelocityX) {
            return ((SpeciesContextSpec) (scsParm.getNameScope().getScopedSymbolTable())).getSpeciesContext().getName() + "_velocityX";
        }
        if (scsParm.getRole() == SpeciesContextSpec.ROLE_VelocityY) {
            return ((SpeciesContextSpec) (scsParm.getNameScope().getScopedSymbolTable())).getSpeciesContext().getName() + "_velocityY";
        }
        if (scsParm.getRole() == SpeciesContextSpec.ROLE_VelocityZ) {
            return ((SpeciesContextSpec) (scsParm.getNameScope().getScopedSymbolTable())).getSpeciesContext().getName() + "_velocityZ";
        }
    }
    if (ste instanceof ElectricalDevice.ElectricalDeviceParameter) {
        ElectricalDevice.ElectricalDeviceParameter edParm = (ElectricalDevice.ElectricalDeviceParameter) ste;
        ElectricalDevice electricalDevice = (ElectricalDevice) edParm.getNameScope().getScopedSymbolTable();
        if (electricalDevice instanceof MembraneElectricalDevice) {
            String nameWithScope = ((MembraneElectricalDevice) electricalDevice).getMembraneMapping().getMembrane().getNameScope().getName();
            if (edParm.getRole() == ElectricalDevice.ROLE_TotalCurrent) {
                return "I_" + nameWithScope;
            }
            if (edParm.getRole() == ElectricalDevice.ROLE_TransmembraneCurrent) {
                return "F_" + nameWithScope;
            }
        // }else if (electricalDevice instanceof CurrentClampElectricalDevice) {
        // if (edParm.getRole()==ElectricalDevice.ROLE_TotalCurrentDensity){
        // return "I_"+((CurrentClampElectricalDevice)electricalDevice).getCurrentClampStimulus().getNameScope().getName();
        // }
        // if (edParm.getRole()==ElectricalDevice.ROLE_TransmembraneCurrentDensity){
        // return "F_"+((CurrentClampElectricalDevice)electricalDevice).getCurrentClampStimulus().getNameScope().getName();
        // }
        // }else if (electricalDevice instanceof VoltageClampElectricalDevice) {
        // if (edParm.getRole()==ElectricalDevice.ROLE_TotalCurrentDensity){
        // return "I_"+((VoltageClampElectricalDevice)electricalDevice).getVoltageClampStimulus().getNameScope().getName();
        // }
        // if (edParm.getRole()==ElectricalDevice.ROLE_TransmembraneCurrentDensity){
        // return "F_"+((VoltageClampElectricalDevice)electricalDevice).getVoltageClampStimulus().getNameScope().getName();
        // }
        }
    }
    if (ste instanceof LocalParameter && ((LocalParameter) ste).getNameScope() instanceof ElectricalStimulus.ElectricalStimulusNameScope) {
        LocalParameter esParm = (LocalParameter) ste;
        String nameWithScope = esParm.getNameScope().getName();
        if (esParm.getRole() == ElectricalStimulusParameterType.TotalCurrent) {
            return "I_" + nameWithScope;
        } else if (esParm.getRole() == ElectricalStimulusParameterType.Voltage) {
            return "V_" + nameWithScope;
        }
    }
    StructureTopology structTopology = model.getStructureTopology();
    if (ste instanceof StructureMapping.StructureMappingParameter) {
        StructureMapping.StructureMappingParameter smParm = (StructureMapping.StructureMappingParameter) ste;
        Structure structure = ((StructureMapping) (smParm.getNameScope().getScopedSymbolTable())).getStructure();
        int role = smParm.getRole();
        if (role == StructureMapping.ROLE_VolumeFraction) {
            return "VolFract_" + (structTopology.getInsideFeature((Membrane) structure)).getNameScope().getName();
        } else {
            String nameWithScope = structure.getNameScope().getName();
            if (role == StructureMapping.ROLE_SurfaceToVolumeRatio) {
                return "SurfToVol_" + nameWithScope;
            } else if (role == StructureMapping.ROLE_InitialVoltage) {
                return smParm.getName();
            } else if (role == StructureMapping.ROLE_SpecificCapacitance) {
                return "C_" + nameWithScope;
            } else if (role == StructureMapping.ROLE_AreaPerUnitArea) {
                return "AreaPerUnitArea_" + nameWithScope;
            } else if (role == StructureMapping.ROLE_AreaPerUnitVolume) {
                return "AreaPerUnitVolume_" + nameWithScope;
            } else if (role == StructureMapping.ROLE_VolumePerUnitArea) {
                return "VolumePerUnitArea_" + nameWithScope;
            } else if (role == StructureMapping.ROLE_VolumePerUnitVolume) {
                return "VolumePerUnitVolume_" + nameWithScope;
            } else if (role == StructureMapping.ROLE_Size) {
                if (simContext.getGeometry().getDimension() == 0) {
                    // if geometry is compartmental, make sure compartment sizes are set if referenced in model.
                    if (smParm.getExpression() == null || smParm.getExpression().isZero()) {
                        throw new MappingException("\nIn non-spatial application '" + getSimulationContext().getName() + "', " + "size of structure '" + structure.getName() + "' must be assigned a " + "positive value if referenced in the model.\n\nPlease go to 'Structure Mapping' tab to check the size.");
                    }
                }
                return "Size_" + nameWithScope;
            }
        }
    }
    // 
    if (ste instanceof SpeciesContext) {
        SpeciesContext sc = (SpeciesContext) ste;
        SpeciesContextMapping scm = getSpeciesContextMapping(sc);
        // 
        if (structureMapping instanceof FeatureMapping) {
            // 
            if (scm.getVariable() != null && !scm.getVariable().getName().equals(steName)) {
                return scm.getVariable().getName();
            }
        // 
        // for reactions within a spatially resolved membrane, may need "_INSIDE" or "_OUTSIDE" for jump condition
        // 
        // if the membrane is distributed, then always use the plain variable.
        // 
        } else if (structureMapping instanceof MembraneMapping) {
            Membrane membrane = ((MembraneMapping) structureMapping).getMembrane();
            // 
            if (sc.getStructure() instanceof Membrane || getResolved(structureMapping) == false) {
                if (scm.getVariable() != null && !(scm.getVariable().getName().equals(steName))) {
                    return scm.getVariable().getName();
                }
            // 
            // if the speciesContext is outside the membrane
            // 
            } else {
                SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(sc);
                if (sc.getStructure() == structTopology.getInsideFeature(membrane) || sc.getStructure() == structTopology.getOutsideFeature(membrane)) {
                    if (getResolved(structureMapping) && !scs.isConstant()) {
                        if (!scs.isDiffusing()) {
                            throw new MappingException("Enable diffusion in Application '" + simContext.getName() + "'. This must be done for any species (e.g '" + sc.getName() + "') in flux reactions.\n\n" + "To save or run simulations, set the diffusion rate to a non-zero " + "value in Initial Conditions or disable those reactions in Specifications->Reactions.");
                        }
                        return scm.getVariable().getName() + (sc.getStructure() == structTopology.getInsideFeature(membrane) ? "_INSIDE" : "_OUTSIDE");
                    } else {
                        return scm.getSpeciesContext().getName();
                    }
                } else {
                    throw new MappingException(sc.getName() + " shouldn't be involved with structure " + structureMapping.getStructure().getName());
                }
            }
        }
    }
    return getNameScope().getSymbolName(ste);
}
Also used : MembraneMapping(cbit.vcell.mapping.MembraneMapping) SpeciesContextMapping(cbit.vcell.mapping.SpeciesContextMapping) SpeciesContext(cbit.vcell.model.SpeciesContext) StructureMappingParameter(cbit.vcell.mapping.StructureMapping.StructureMappingParameter) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) StructureMapping(cbit.vcell.mapping.StructureMapping) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) FeatureMapping(cbit.vcell.mapping.FeatureMapping) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) Vector(java.util.Vector) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter) StructureTopology(cbit.vcell.model.Model.StructureTopology) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) ModelParameter(cbit.vcell.model.Model.ModelParameter) ElectricalStimulus(cbit.vcell.mapping.ElectricalStimulus) ProxyParameter(cbit.vcell.model.ProxyParameter) SpeciesContextSpecProxyParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecProxyParameter) StructureMappingParameter(cbit.vcell.mapping.StructureMapping.StructureMappingParameter) Expression(cbit.vcell.parser.Expression) Model(cbit.vcell.model.Model)

Aggregations

MembraneMapping (cbit.vcell.mapping.MembraneMapping)32 Expression (cbit.vcell.parser.Expression)24 Membrane (cbit.vcell.model.Membrane)20 FeatureMapping (cbit.vcell.mapping.FeatureMapping)17 StructureMapping (cbit.vcell.mapping.StructureMapping)17 Feature (cbit.vcell.model.Feature)14 Structure (cbit.vcell.model.Structure)13 ExpressionException (cbit.vcell.parser.ExpressionException)11 SubVolume (cbit.vcell.geometry.SubVolume)10 Model (cbit.vcell.model.Model)9 StructureTopology (cbit.vcell.model.Model.StructureTopology)9 SpeciesContext (cbit.vcell.model.SpeciesContext)9 SurfaceClass (cbit.vcell.geometry.SurfaceClass)8 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)8 ReactionSpec (cbit.vcell.mapping.ReactionSpec)7 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)7 StructureMappingParameter (cbit.vcell.mapping.StructureMapping.StructureMappingParameter)7 PropertyVetoException (java.beans.PropertyVetoException)6 ImageException (cbit.image.ImageException)5 GeometryClass (cbit.vcell.geometry.GeometryClass)5