use of cbit.vcell.mapping.MembraneMapping in project vcell by virtualcell.
the class StructureMappingTableModel method isCellEditable.
/**
* Insert the method's description here.
* Creation date: (2/24/01 12:27:46 AM)
* @return boolean
* @param rowIndex int
* @param columnIndex int
*/
public boolean isCellEditable(int rowIndex, int columnIndex) {
if (getGeometryContext() == null) {
return false;
}
StructureMapping sm = getGeometryContext().getStructureMapping(rowIndex);
if (bNonSpatial) {
if (columnIndex == NONSPATIAL_COLUMN_SIZE) {
// feature size are editable
return true;
}
return false;
} else {
//
if (columnIndex == SPATIAL_COLUMN_SUBDOMAIN) {
return ((sm instanceof FeatureMapping) || (sm instanceof MembraneMapping));
}
if (columnIndex == SPATIAL_COLUMN_SIZERATIO) {
GeometryClass gc = sm.getGeometryClass();
StructureMapping[] structureMappings = getGeometryContext().getStructureMappings(gc);
boolean bDimensionless = sm.getUnitSizeParameter() != null && sm.getUnitSizeParameter().getUnitDefinition() != null && sm.getUnitSizeParameter().getUnitDefinition().isEquivalent(getGeometryContext().getModel().getUnitSystem().getInstance_DIMENSIONLESS());
return (structureMappings != null && structureMappings.length > 1) || !bDimensionless;
}
// some boundary conditions are editable
if ((columnIndex >= SPATIAL_COLUMN_X_MINUS) && (columnIndex <= SPATIAL_COLUMN_Z_PLUS)) {
if (sm.getGeometryClass() instanceof SurfaceClass) {
return false;
}
return true;
}
}
return false;
}
use of cbit.vcell.mapping.MembraneMapping in project vcell by virtualcell.
the class ElectricalMembraneMappingTableModel method setValueAt.
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
MembraneMapping membraneMapping = getValueAt(rowIndex);
switch(columnIndex) {
case COLUMN_CALCULATE_POTENTIAL:
{
boolean bCalculatePotential = ((Boolean) aValue).booleanValue();
membraneMapping.setCalculateVoltage(bCalculatePotential);
fireTableRowsUpdated(rowIndex, rowIndex);
break;
}
case COLUMN_INITIAL_POTENTIAL:
{
Expression newExpression = null;
try {
if (aValue instanceof String) {
String newExpressionString = (String) aValue;
newExpression = new Expression(newExpressionString);
}
membraneMapping.getInitialVoltageParameter().setExpression(newExpression);
fireTableRowsUpdated(rowIndex, rowIndex);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "expression error\n" + e.getMessage());
}
break;
}
case COLUMN_SPECIFIC_CAPACITANCE:
{
Expression newExpression = null;
try {
if (aValue instanceof String) {
String newExpressionString = (String) aValue;
newExpression = new Expression(newExpressionString);
} else if (aValue instanceof ScopedExpression) {
// newExpression = ((ScopedExpression)aValue).getExpression();
throw new RuntimeException("unexpected value type ScopedExpression");
}
membraneMapping.getSpecificCapacitanceParameter().setExpression(newExpression);
fireTableRowsUpdated(rowIndex, rowIndex);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "expression error\n" + e.getMessage());
}
break;
}
}
}
use of cbit.vcell.mapping.MembraneMapping in project vcell by virtualcell.
the class ElectricalMembraneMappingTableModel method setGeometryContext.
/**
* Sets the geometryContext property (cbit.vcell.mapping.GeometryContext) value.
* @param geometryContext The new value for the property.
* @see #getGeometryContext
*/
public void setGeometryContext(GeometryContext geometryContext) {
GeometryContext oldValue = fieldGeometryContext;
if (oldValue != null) {
oldValue.removePropertyChangeListener(this);
StructureMapping[] oldStructureMappings = oldValue.getStructureMappings();
for (int i = 0; i < oldStructureMappings.length; i++) {
if (oldStructureMappings[i] instanceof MembraneMapping) {
oldStructureMappings[i].removePropertyChangeListener(this);
}
}
}
fieldGeometryContext = geometryContext;
if (geometryContext != null) {
geometryContext.addPropertyChangeListener(this);
StructureMapping[] newStructureMappings = geometryContext.getStructureMappings();
for (int i = 0; i < newStructureMappings.length; i++) {
if (newStructureMappings[i] instanceof MembraneMapping) {
newStructureMappings[i].addPropertyChangeListener(this);
}
}
}
refreshData();
}
use of cbit.vcell.mapping.MembraneMapping in project vcell by virtualcell.
the class CurrentClampElectricalDevice method initializeParameters.
private void initializeParameters() throws ExpressionException {
ElectricalDevice.ElectricalDeviceParameter[] parameters = new ElectricalDevice.ElectricalDeviceParameter[3];
//
// set the transmembrane current (total current, if necessary derive it from the current density).
//
ElectricalDeviceParameter transMembraneCurrent = null;
ModelUnitSystem modelUnitSystem = mathMapping.getSimulationContext().getModel().getUnitSystem();
VCUnitDefinition currentUnit = modelUnitSystem.getCurrentUnit();
if (currentClampStimulus instanceof TotalCurrentClampStimulus) {
TotalCurrentClampStimulus stimulus = (TotalCurrentClampStimulus) currentClampStimulus;
LocalParameter currentParameter = stimulus.getCurrentParameter();
transMembraneCurrent = new ElectricalDeviceParameter(DefaultNames[ROLE_TransmembraneCurrent], new Expression(currentParameter.getExpression()), ROLE_TransmembraneCurrent, currentUnit);
} else if (currentClampStimulus instanceof CurrentDensityClampStimulus) {
CurrentDensityClampStimulus stimulus = (CurrentDensityClampStimulus) currentClampStimulus;
LocalParameter currentDensityParameter = stimulus.getCurrentDensityParameter();
//
// here we have to determine the expression for current (from current density).
//
Feature feature1 = currentClampStimulus.getElectrode().getFeature();
Feature feature2 = mathMapping.getSimulationContext().getGroundElectrode().getFeature();
Membrane membrane = null;
StructureTopology structTopology = mathMapping.getSimulationContext().getModel().getStructureTopology();
if (structTopology.getParentStructure(feature1) != null && structTopology.getOutsideFeature((Membrane) structTopology.getParentStructure(feature1)) == feature2) {
membrane = ((Membrane) structTopology.getParentStructure(feature1));
} else if (structTopology.getParentStructure(feature2) != null && structTopology.getOutsideFeature((Membrane) structTopology.getParentStructure(feature2)) == feature1) {
membrane = ((Membrane) structTopology.getParentStructure(feature2));
}
if (membrane == null) {
throw new RuntimeException("current clamp based on current density crosses multiple membranes, unable to " + "determine single membrane to convert current density into current in Application '" + mathMapping.getSimulationContext().getName() + "'.");
}
MembraneMapping membraneMapping = (MembraneMapping) mathMapping.getSimulationContext().getGeometryContext().getStructureMapping(membrane);
StructureMappingParameter sizeParameter = membraneMapping.getSizeParameter();
Expression area = null;
if (mathMapping.getSimulationContext().getGeometry().getDimension() == 0 && (sizeParameter.getExpression() == null || sizeParameter.getExpression().isZero())) {
area = membraneMapping.getNullSizeParameterValue();
} else {
area = new Expression(sizeParameter, mathMapping.getNameScope());
}
transMembraneCurrent = new ElectricalDeviceParameter(DefaultNames[ROLE_TransmembraneCurrent], Expression.mult(new Expression(currentDensityParameter.getExpression()), area), ROLE_TransmembraneCurrent, currentUnit);
} else {
throw new RuntimeException("unexpected current clamp stimulus type : " + currentClampStimulus.getClass().getName());
}
ElectricalDeviceParameter totalCurrent = new ElectricalDeviceParameter(DefaultNames[ROLE_TotalCurrent], new Expression(transMembraneCurrent, getNameScope()), ROLE_TotalCurrent, currentUnit);
ElectricalDeviceParameter voltage = new ElectricalDeviceParameter(DefaultNames[ROLE_Voltage], null, ROLE_Voltage, modelUnitSystem.getVoltageUnit());
parameters[0] = totalCurrent;
parameters[1] = transMembraneCurrent;
parameters[2] = voltage;
//
// add any user-defined parameters
//
LocalParameter[] stimulusParameters = currentClampStimulus.getLocalParameters();
for (int i = 0; stimulusParameters != null && i < stimulusParameters.length; i++) {
if (stimulusParameters[i].getRole() == ElectricalStimulus.ElectricalStimulusParameterType.UserDefined) {
ElectricalDeviceParameter newParam = new ElectricalDeviceParameter(stimulusParameters[i].getName(), new Expression(stimulusParameters[i].getExpression()), ROLE_UserDefined, stimulusParameters[i].getUnitDefinition());
parameters = (ElectricalDeviceParameter[]) BeanUtils.addElement(parameters, newParam);
}
}
setParameters(parameters);
}
use of cbit.vcell.mapping.MembraneMapping 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();
}
Aggregations