use of cbit.vcell.model.Model.ElectricalTopology in project vcell by virtualcell.
the class Xmlproducer method getXML.
/**
* This method identifies if the structure as a parameter is a Feature or a Membrane, and then calls the respective getXML method.
* Creation date: (2/22/2001 6:31:04 PM)
* @return Element
* @param param cbit.vcell.model.Structure
* @param model cbit.vcell.model.Model
*/
private Element getXML(Structure structure, Model model) throws XmlParseException {
Element structureElement = null;
StructureTopology structTopology = model.getStructureTopology();
if (structure instanceof Feature) {
// This is a Feature
structureElement = new Element(XMLTags.FeatureTag);
} else if (structure instanceof Membrane) {
// process a Membrane
structureElement = new Element(XMLTags.MembraneTag);
// add specific attributes
Feature insideFeature = structTopology.getInsideFeature((Membrane) structure);
if (insideFeature != null) {
structureElement.setAttribute(XMLTags.InsideFeatureTag, mangle(insideFeature.getName()));
}
Feature outsideFeature = structTopology.getOutsideFeature((Membrane) structure);
if (outsideFeature != null) {
structureElement.setAttribute(XMLTags.OutsideFeatureTag, mangle(outsideFeature.getName()));
}
// positive & negative features for electrical topology
ElectricalTopology electricalTopology = model.getElectricalTopology();
Feature positiveFeature = electricalTopology.getPositiveFeature((Membrane) structure);
if (positiveFeature != null) {
structureElement.setAttribute(XMLTags.PositiveFeatureTag, mangle(positiveFeature.getName()));
}
Feature negativeFeature = electricalTopology.getNegativeFeature((Membrane) structure);
if (negativeFeature != null) {
structureElement.setAttribute(XMLTags.NegativeFeatureTag, mangle(negativeFeature.getName()));
}
structureElement.setAttribute(XMLTags.MemVoltNameTag, mangle(((Membrane) structure).getMembraneVoltage().getName()));
} else {
throw new XmlParseException("An unknown type of structure was found:" + structure.getClass().getName());
}
// add attributes
structureElement.setAttribute(XMLTags.NameAttrTag, mangle(structure.getName()));
// If the keyFlag is on, print Keys
if (structure.getKey() != null && this.printKeysFlag) {
structureElement.setAttribute(XMLTags.KeyValueAttrTag, structure.getKey().toString());
}
return structureElement;
}
use of cbit.vcell.model.Model.ElectricalTopology 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.Model.ElectricalTopology in project vcell by virtualcell.
the class PotentialMapping method getEdges.
/**
* Insert the method's description here.
* Creation date: (3/2/2002 11:10:22 PM)
* @return cbit.vcell.mapping.potential.Edge[]
*/
private Edge[] getEdges(Membrane membrane) {
java.util.Vector<Edge> edgeList = new java.util.Vector<Edge>();
ElectricalTopology electricalTopology = fieldSimContext.getModel().getElectricalTopology();
for (int i = 0; i < fieldEdges.length; i++) {
boolean a1 = ((Feature) fieldEdges[i].getNode1().getData()).compareEqual(electricalTopology.getPositiveFeature(membrane));
boolean a2 = ((Feature) fieldEdges[i].getNode2().getData()).compareEqual(electricalTopology.getNegativeFeature(membrane));
if (a1 && a2) {
edgeList.add(fieldEdges[i]);
}
boolean b1 = ((Feature) fieldEdges[i].getNode2().getData()).compareEqual(electricalTopology.getPositiveFeature(membrane));
boolean b2 = ((Feature) fieldEdges[i].getNode1().getData()).compareEqual(electricalTopology.getNegativeFeature(membrane));
if (b1 && b2) {
edgeList.add(fieldEdges[i]);
}
}
Edge[] edgesForMembrane = new Edge[edgeList.size()];
edgeList.copyInto(edgesForMembrane);
return edgesForMembrane;
}
use of cbit.vcell.model.Model.ElectricalTopology in project vcell by virtualcell.
the class StructurePropertiesPanel method updateInterface.
/**
* Comment
*/
private void updateInterface() {
boolean bNonNullStructure = structure != null && fieldModel != null;
nameTextField.setEditable(bNonNullStructure);
annotationTextArea.setEditable(bNonNullStructure);
boolean bMembrane = bNonNullStructure && structure instanceof Membrane;
voltageLabel.setVisible(bMembrane);
voltageTextField.setVisible(bMembrane);
electrophysiologyLabel.setVisible(bMembrane);
positiveFeatureLabel.setVisible(bMembrane);
positiveFeatureComboBox.setVisible(bMembrane);
negativeFeatureLabel.setVisible(bMembrane);
negativeFeatureComboBox.setVisible(bMembrane);
electrophysiologyExplanationLabel.setVisible(bMembrane);
if (bNonNullStructure) {
nameTextField.setText(structure.getName());
annotationTextArea.setText(fieldModel.getVcMetaData().getFreeTextAnnotation(structure));
StructureSize structureSize = structure.getStructureSize();
sizeTextField.setText(structureSize.getName() + " [" + structureSize.getUnitDefinition().getSymbolUnicode() + "]");
if (bMembrane) {
Membrane membrane = (Membrane) structure;
MembraneVoltage memVoltage = membrane.getMembraneVoltage();
voltageTextField.setText(memVoltage.getName() + " [" + memVoltage.getUnitDefinition().getSymbolUnicode() + "]");
// if membrane has +ve/-ve feature set, set the comboBox with that selection.
ElectricalTopology electricalTopology = fieldModel.getElectricalTopology();
Feature positiveFeature = electricalTopology.getPositiveFeature(membrane);
if (positiveFeature != null) {
positiveFeatureComboBox.setSelectedItem(positiveFeature.getName());
}
Feature negativeFeature = electricalTopology.getNegativeFeature(membrane);
if (negativeFeature != null) {
negativeFeatureComboBox.setSelectedItem(negativeFeature.getName());
}
this.electrophysiologyExplanationLabel.setText(getExplanationText());
}
} else {
annotationTextArea.setText(null);
nameTextField.setText(null);
sizeTextField.setText(null);
voltageTextField.setText(null);
}
}
use of cbit.vcell.model.Model.ElectricalTopology in project vcell by virtualcell.
the class NernstKinetics method updateGeneratedExpressions.
/**
* Insert the method's description here.
* Creation date: (10/19/2003 12:05:14 AM)
* @exception cbit.vcell.parser.ExpressionException The exception description.
*/
protected void updateGeneratedExpressions() throws cbit.vcell.parser.ExpressionException, java.beans.PropertyVetoException {
KineticsParameter rateParm = getKineticsParameterFromRole(ROLE_ReactionRate);
KineticsParameter currentParm = getKineticsParameterFromRole(ROLE_CurrentDensity);
KineticsParameter conductivity = getKineticsParameterFromRole(ROLE_Conductivity);
if (currentParm == null && rateParm == null) {
return;
}
Membrane membrane = (Membrane) getReactionStep().getStructure();
if (!(getReactionStep().getStructure() instanceof Membrane)) {
return;
}
ElectricalTopology electricalTopology = getReactionStep().getModel().getElectricalTopology();
Membrane.MembraneVoltage V = membrane.getMembraneVoltage();
Feature negativeFeature = electricalTopology.getNegativeFeature(membrane);
Feature positiveFeature = electricalTopology.getPositiveFeature(membrane);
if (negativeFeature == null || positiveFeature == null) {
return;
}
ReactionParticipant[] reactionParticipants = getReactionStep().getReactionParticipants();
ReactionParticipant Neg0 = null;
ReactionParticipant Pos0 = null;
for (int i = 0; i < reactionParticipants.length; i++) {
ReactionParticipant rp = reactionParticipants[i];
if ((rp instanceof Reactant || rp instanceof Product)) {
if (rp.getStructure() == negativeFeature) {
Neg0 = rp;
} else if (rp.getStructure() == positiveFeature) {
Pos0 = rp;
}
}
}
if (Neg0 != null && Pos0 != null) {
Model model = getReactionStep().getModel();
Expression carrier_z = getSymbolExpression(getKineticsParameterFromRole(ROLE_CarrierChargeValence));
Expression net_z = carrier_z;
Expression F = getSymbolExpression(model.getFARADAY_CONSTANT());
Expression R = getSymbolExpression(model.getGAS_CONSTANT());
Expression T = getSymbolExpression(model.getTEMPERATURE());
Expression Pos0_exp = getSymbolExpression(Pos0.getSpeciesContext());
Expression Neg0_exp = getSymbolExpression(Neg0.getSpeciesContext());
Expression V_exp = getSymbolExpression(V);
Expression conductivity_exp = getSymbolExpression(conductivity);
// new Expression("A0*(("+R+"*"+T+"/("+VALENCE_SYMBOL+"*"+F+"))*log(P0/R0)-"+VOLTAGE_SYMBOL+")"),
// Expression newCurrExp = new Expression(conductivity.getName()+"*(("+R.getName()+"*"+T.getName()+"/("+z+"*"+F.getName()+"))*log("+P0.getName()+"/"+R0.getName()+") - "+V.getName()+")");
// log(P/R)
Expression logterm = Expression.log(Expression.div(Neg0_exp, Pos0_exp));
// (R * T / (z * F))
Expression term1 = Expression.div(Expression.mult(R, T), Expression.mult(carrier_z, F));
// C * (term1 * logterm - V)
Expression newCurrExp = Expression.mult(conductivity_exp, Expression.add(Expression.mult(term1, logterm), Expression.negate(V_exp)));
currentParm.setExpression(newCurrExp);
// SECONDARY REACTION RATE
// update from current density
updateReactionRatesFromInwardCurrentDensity();
}
}
Aggregations