use of cbit.vcell.mapping.ParameterContext.LocalParameter in project vcell by virtualcell.
the class ElectricalStimulusParameterTableModel method propertyChange.
/**
* This method gets called when a bound property is changed.
* @param evt A PropertyChangeEvent object describing the event source
* and the property that has changed.
*/
public void propertyChange(java.beans.PropertyChangeEvent evt) {
if (evt.getSource() == this && evt.getPropertyName().equals("electricalStimulus")) {
ElectricalStimulus oldValue = (ElectricalStimulus) evt.getOldValue();
if (oldValue != null) {
oldValue.removePropertyChangeListener(this);
Parameter[] oldParameters = oldValue.getParameters();
for (int i = 0; i < oldParameters.length; i++) {
oldParameters[i].removePropertyChangeListener(this);
}
}
ElectricalStimulus newValue = (ElectricalStimulus) evt.getNewValue();
if (newValue != null) {
newValue.addPropertyChangeListener(this);
Parameter[] newParameters = newValue.getParameters();
for (int i = 0; i < newParameters.length; i++) {
newParameters[i].addPropertyChangeListener(this);
}
}
refreshData();
}
if (evt.getSource() instanceof ElectricalStimulus && (evt.getPropertyName().equals("localParameters") || evt.getPropertyName().equals("proxyParameters"))) {
Parameter[] oldParameters = (Parameter[]) evt.getOldValue();
for (int i = 0; i < oldParameters.length; i++) {
oldParameters[i].removePropertyChangeListener(this);
}
Parameter[] newParameters = (Parameter[]) evt.getNewValue();
for (int i = 0; i < newParameters.length; i++) {
newParameters[i].addPropertyChangeListener(this);
}
refreshData();
}
if (evt.getSource() instanceof LocalParameter && evt.getPropertyName().equals("expression")) {
fireTableRowsUpdated(0, getRowCount() - 1);
}
}
use of cbit.vcell.mapping.ParameterContext.LocalParameter in project vcell by virtualcell.
the class ElectricalStimulusParameterTableModel method setValueAt.
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
if (columnIndex < 0 || columnIndex >= getColumnCount()) {
throw new RuntimeException("ParameterTableModel.setValueAt(), column = " + columnIndex + " out of range [" + 0 + "," + (getColumnCount() - 1) + "]");
}
Parameter parameter = getValueAt(rowIndex);
// try {
switch(columnIndex) {
case COLUMN_VALUE:
{
try {
String newExpressionString = (String) aValue;
if (parameter instanceof LocalParameter) {
LocalParameter scsParm = (LocalParameter) parameter;
getElectricalStimulus().setParameterValue(scsParm, new Expression(newExpressionString));
// fireTableRowsUpdated(rowIndex,rowIndex);
}
} catch (ExpressionException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "expression error\n" + e.getMessage());
} catch (Exception e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, e.getMessage(), e);
}
break;
}
case COLUMN_NAME:
{
try {
getElectricalStimulus().renameParameter(parameter.getName(), (String) aValue);
} catch (Exception e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, e.getMessage(), e);
}
}
}
// }catch (java.beans.PropertyVetoException e){
// e.printStackTrace(System.out);
// }
}
use of cbit.vcell.mapping.ParameterContext.LocalParameter 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.ParameterContext.LocalParameter 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_4_8.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_4_8.getSimulationContext().getGroundElectrode().getFeature();
Membrane membrane = null;
StructureTopology structTopology = mathMapping_4_8.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_4_8.getSimulationContext().getName() + "'.");
}
MembraneMapping membraneMapping = (MembraneMapping) mathMapping_4_8.getSimulationContext().getGeometryContext().getStructureMapping(membrane);
StructureMappingParameter sizeParameter = membraneMapping.getSizeParameter();
Expression area = null;
if (mathMapping_4_8.getSimulationContext().getGeometry().getDimension() == 0 && (sizeParameter.getExpression() == null || sizeParameter.getExpression().isZero())) {
area = membraneMapping.getNullSizeParameterValue();
} else {
area = new Expression(sizeParameter, mathMapping_4_8.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.ParameterContext.LocalParameter in project vcell by virtualcell.
the class ElectricalStimulus method setParameterValue.
/**
* This method was created by a SmartGuide.
* @param expressionString java.lang.String
* @exception java.lang.Exception The exception description.
*/
public void setParameterValue(LocalParameter parm, Expression exp) throws ExpressionException, PropertyVetoException {
Parameter p = parameterContext.getLocalParameterFromName(parm.getName());
if (p != parm) {
throw new RuntimeException("parameter " + parm.getName() + " not found");
}
Expression oldExpression = parm.getExpression();
boolean bBound = false;
try {
LocalParameter[] newLocalParameters = (LocalParameter[]) parameterContext.getLocalParameters().clone();
String[] symbols = exp.getSymbols();
Vector<String> symbolsToAdd = new Vector<String>();
for (int i = 0; symbols != null && i < symbols.length; i++) {
if (parameterContext.getEntry(symbols[i]) == null) {
symbolsToAdd.add(symbols[i]);
}
}
ModelUnitSystem modelUnitSystem = simulationContext.getModel().getUnitSystem();
for (int i = 0; i < symbolsToAdd.size(); i++) {
newLocalParameters = (LocalParameter[]) BeanUtils.addElement(newLocalParameters, parameterContext.new LocalParameter(symbolsToAdd.elementAt(i), new Expression(0.0), ElectricalStimulusParameterType.UserDefined, modelUnitSystem.getInstance_TBD(), ElectricalStimulusParameterType.UserDefined.databaseRoleTag));
}
parameterContext.setLocalParameters(newLocalParameters);
exp.bindExpression(parameterContext);
parm.setExpression(exp);
bBound = true;
} finally {
try {
if (!bBound) {
parm.setExpression(oldExpression);
}
parameterContext.cleanupParameters();
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
}
}
}
Aggregations