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());
}
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations