use of cbit.vcell.mapping.Electrode in project vcell by virtualcell.
the class XmlReader method getElectricalStimulus.
/**
* This method process Electrical Stimulus, also called Clamps.
* Creation date: (6/6/2002 4:46:18 PM)
* @return cbit.vcell.mapping.ElectricalStimulus
* @param param org.jdom.Element
*/
private ElectricalStimulus getElectricalStimulus(Element param, SimulationContext currentSimulationContext) throws XmlParseException {
ElectricalStimulus clampStimulus = null;
// get name
// String name = unMangle( param.getAttributeValue(XMLTags.NameAttrTag) );
// get Electrode
Electrode electrode = getElectrode(param.getChild(XMLTags.ElectrodeTag, vcNamespace), currentSimulationContext);
if (param.getAttributeValue(XMLTags.TypeAttrTag).equalsIgnoreCase(XMLTags.VoltageClampTag)) {
// is a voltage clamp
clampStimulus = new VoltageClampStimulus(electrode, "voltClampElectrode", new Expression(0.0), currentSimulationContext);
} else if (param.getAttributeValue(XMLTags.TypeAttrTag).equalsIgnoreCase(XMLTags.CurrentDensityClampTag) || param.getAttributeValue(XMLTags.TypeAttrTag).equalsIgnoreCase(XMLTags.CurrentDensityClampTag_oldName)) {
// is a current density clamp
clampStimulus = new CurrentDensityClampStimulus(electrode, "currDensityClampElectrode", new Expression(0.0), currentSimulationContext);
} else if (param.getAttributeValue(XMLTags.TypeAttrTag).equalsIgnoreCase(XMLTags.TotalCurrentClampTag)) {
// is a "total" current clamp
clampStimulus = new TotalCurrentClampStimulus(electrode, "totalCurrClampElectrode", new Expression(0.0), currentSimulationContext);
}
try {
// transaction begin flag ... yeah, this is a hack
clampStimulus.reading(true);
// Read all of the parameters
List<Element> list = param.getChildren(XMLTags.ParameterTag, vcNamespace);
// add constants that may be used in the electrical stimulus.
VariableHash varHash = new VariableHash();
Model model = currentSimulationContext.getModel();
addResevedSymbols(varHash, model);
//
for (Element xmlParam : list) {
String paramName = unMangle(xmlParam.getAttributeValue(XMLTags.NameAttrTag));
String role = xmlParam.getAttributeValue(XMLTags.ParamRoleAttrTag);
String paramExpStr = xmlParam.getText();
Expression paramExp = unMangleExpression(paramExpStr);
try {
if (varHash.getVariable(paramName) == null) {
Domain domain = null;
varHash.addVariable(new Function(paramName, paramExp, domain));
} else {
if (model.getReservedSymbolByName(paramName) != null) {
varHash.removeVariable(paramName);
Domain domain = null;
varHash.addVariable(new Function(paramName, paramExp, domain));
}
}
} catch (MathException e) {
e.printStackTrace(System.out);
throw new XmlParseException("error reordering parameters according to dependencies:", e);
}
LocalParameter tempParam = null;
if (!role.equals(XMLTags.ParamRoleUserDefinedTag)) {
if (role.equals(XMLTags.ParamRoleTotalCurrentTag)) {
if (clampStimulus instanceof TotalCurrentClampStimulus) {
tempParam = ((TotalCurrentClampStimulus) clampStimulus).getCurrentParameter();
} else {
varHash.removeVariable(paramName);
continue;
}
} else if (role.equals(XMLTags.ParamRoleTotalCurrentDensityTag) || role.equals(XMLTags.ParamRoleTotalCurrentDensityOldNameTag)) {
if (clampStimulus instanceof CurrentDensityClampStimulus) {
tempParam = ((CurrentDensityClampStimulus) clampStimulus).getCurrentDensityParameter();
} else {
varHash.removeVariable(paramName);
continue;
}
} else if (role.equals(XMLTags.ParamRolePotentialDifferenceTag)) {
if (clampStimulus instanceof VoltageClampStimulus) {
tempParam = ((VoltageClampStimulus) clampStimulus).getVoltageParameter();
} else {
varHash.removeVariable(paramName);
continue;
}
}
} else {
continue;
}
if (tempParam == null) {
throw new XmlParseException("parameter with role '" + role + "' not found in electricalstimulus");
}
//
if (!tempParam.getName().equals(paramName)) {
LocalParameter multNameParam = clampStimulus.getLocalParameter(paramName);
int n = 0;
while (multNameParam != null) {
String tempName = paramName + "_" + n++;
clampStimulus.renameParameter(paramName, tempName);
multNameParam = clampStimulus.getLocalParameter(tempName);
}
clampStimulus.renameParameter(tempParam.getName(), paramName);
}
}
//
// create unresolved parameters for all unresolved symbols
//
String unresolvedSymbol = varHash.getFirstUnresolvedSymbol();
while (unresolvedSymbol != null) {
try {
Domain domain = null;
// will turn into an UnresolvedParameter.
varHash.addVariable(new Function(unresolvedSymbol, new Expression(0.0), domain));
} catch (MathException e) {
e.printStackTrace(System.out);
throw new XmlParseException(e.getMessage());
}
clampStimulus.addUnresolvedParameter(unresolvedSymbol);
unresolvedSymbol = varHash.getFirstUnresolvedSymbol();
}
Variable[] sortedVariables = varHash.getTopologicallyReorderedVariables();
ModelUnitSystem modelUnitSystem = model.getUnitSystem();
for (int i = sortedVariables.length - 1; i >= 0; i--) {
if (sortedVariables[i] instanceof Function) {
Function paramFunction = (Function) sortedVariables[i];
Element xmlParam = null;
for (int j = 0; j < list.size(); j++) {
Element tempParam = (Element) list.get(j);
if (paramFunction.getName().equals(unMangle(tempParam.getAttributeValue(XMLTags.NameAttrTag)))) {
xmlParam = tempParam;
break;
}
}
if (xmlParam == null) {
// must have been an unresolved parameter
continue;
}
String symbol = xmlParam.getAttributeValue(XMLTags.VCUnitDefinitionAttrTag);
VCUnitDefinition unit = null;
if (symbol != null) {
unit = modelUnitSystem.getInstance(symbol);
}
LocalParameter tempParam = clampStimulus.getLocalParameter(paramFunction.getName());
if (tempParam == null) {
clampStimulus.addUserDefinedParameter(paramFunction.getName(), paramFunction.getExpression(), unit);
} else {
if (tempParam.getExpression() != null) {
// if the expression is null, it should remain null.
clampStimulus.setParameterValue(tempParam, paramFunction.getExpression());
}
tempParam.setUnitDefinition(unit);
}
}
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace(System.out);
throw new XmlParseException("Exception while setting parameters for simContext : " + currentSimulationContext.getName(), e);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new XmlParseException("Exception while settings parameters for simContext : " + currentSimulationContext.getName(), e);
} finally {
clampStimulus.reading(false);
}
return clampStimulus;
}
use of cbit.vcell.mapping.Electrode in project vcell by virtualcell.
the class XmlReader method getSimulationContext.
/**
* This method returns a SimulationContext from a XML representation.
* Creation date: (4/2/2001 3:19:01 PM)
* @return cbit.vcell.mapping.SimulationContext
* @param param org.jdom.Element
*/
private SimulationContext getSimulationContext(Element param, BioModel biomodel) throws XmlParseException {
// get the attributes
// name
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
boolean bStoch = false;
boolean bRuleBased = false;
boolean bUseConcentration = true;
boolean bRandomizeInitCondition = false;
boolean bInsufficientIterations = false;
boolean bInsufficientMaxMolecules = false;
// default is true for now
boolean bMassConservationModelReduction = true;
NetworkConstraints nc = null;
Element ncElement = param.getChild(XMLTags.RbmNetworkConstraintsTag, vcNamespace);
if (ncElement != null) {
// one network constraint element
nc = getAppNetworkConstraints(ncElement, biomodel.getModel());
} else {
if (legacyNetworkConstraints != null) {
nc = legacyNetworkConstraints;
}
}
if ((param.getAttributeValue(XMLTags.StochAttrTag) != null) && (param.getAttributeValue(XMLTags.StochAttrTag).equals("true"))) {
bStoch = true;
}
if (bStoch) {
// stochastic and using concentration vs amount
if ((param.getAttributeValue(XMLTags.ConcentrationAttrTag) != null) && (param.getAttributeValue(XMLTags.ConcentrationAttrTag).equals("false"))) {
bUseConcentration = false;
}
// stochastic and randomizing initial conditions or not (for non-spatial)
if ((param.getAttributeValue(XMLTags.RandomizeInitConditionTag) != null) && (param.getAttributeValue(XMLTags.RandomizeInitConditionTag).equals("true"))) {
bRandomizeInitCondition = true;
}
}
if ((param.getAttributeValue(XMLTags.MassConservationModelReductionTag) != null) && (param.getAttributeValue(XMLTags.MassConservationModelReductionTag).equals("false"))) {
bMassConservationModelReduction = false;
}
if ((param.getAttributeValue(XMLTags.InsufficientIterationsTag) != null) && (param.getAttributeValue(XMLTags.InsufficientIterationsTag).equals("true"))) {
bInsufficientIterations = true;
}
if ((param.getAttributeValue(XMLTags.InsufficientMaxMoleculesTag) != null) && (param.getAttributeValue(XMLTags.InsufficientMaxMoleculesTag).equals("true"))) {
bInsufficientMaxMolecules = true;
}
if ((param.getAttributeValue(XMLTags.RuleBasedAttrTag) != null) && (param.getAttributeValue(XMLTags.RuleBasedAttrTag).equals("true"))) {
bRuleBased = true;
if ((param.getAttributeValue(XMLTags.ConcentrationAttrTag) != null) && (param.getAttributeValue(XMLTags.ConcentrationAttrTag).equals("false"))) {
bUseConcentration = false;
}
if ((param.getAttributeValue(XMLTags.RandomizeInitConditionTag) != null) && (param.getAttributeValue(XMLTags.RandomizeInitConditionTag).equals("true"))) {
// we propagate the flag but we don't use it for now
bRandomizeInitCondition = true;
}
}
// Retrieve Geometry
Geometry newgeometry = null;
try {
newgeometry = getGeometry(param.getChild(XMLTags.GeometryTag, vcNamespace));
} catch (Throwable e) {
e.printStackTrace();
String stackTrace = null;
try {
java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
java.io.PrintStream ps = new java.io.PrintStream(bos);
e.printStackTrace(ps);
ps.flush();
bos.flush();
stackTrace = new String(bos.toByteArray());
ps.close();
bos.close();
} catch (Exception e2) {
// do Nothing
}
throw new XmlParseException("A Problem occurred while retrieving the geometry for the simulationContext " + name, e);
}
// Retrieve MathDescription(if there is no MathDescription skip it)
MathDescription newmathdesc = null;
Element xmlMathDescription = param.getChild(XMLTags.MathDescriptionTag, vcNamespace);
if (xmlMathDescription != null) {
newmathdesc = getMathDescription(xmlMathDescription, newgeometry);
if (biomodel.getVersion() != null && biomodel.getVersion().getVersionKey() != null) {
Long lpcBMKey = Long.valueOf(biomodel.getVersion().getVersionKey().toString());
// MathDescription.originalHasLowPrecisionConstants.remove(lpcBMKey);
try {
Enumeration<Constant> myenum = newmathdesc.getConstants();
while (myenum.hasMoreElements()) {
Constant nextElement = myenum.nextElement();
String name2 = nextElement.getName();
ReservedSymbol reservedSymbolByName = biomodel.getModel().getReservedSymbolByName(name2);
if (reservedSymbolByName != null && nextElement.getExpression() != null && reservedSymbolByName.getExpression() != null) {
// System.out.println(name2);
boolean equals = nextElement.getExpression().infix().equals(reservedSymbolByName.getExpression().infix());
// System.out.println("--"+" "+nextElement.getExpression().infix() +" "+reservedSymbolByName.getExpression().infix()+" "+equals);
if (!equals) {
TreeSet<String> treeSet = MathDescription.originalHasLowPrecisionConstants.get(lpcBMKey);
if (treeSet == null) {
treeSet = new TreeSet<>();
MathDescription.originalHasLowPrecisionConstants.put(lpcBMKey, treeSet);
}
treeSet.add(newmathdesc.getVersion().getVersionKey().toString());
break;
}
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
// Retrieve Version (Metada)
Version version = getVersion(param.getChild(XMLTags.VersionTag, vcNamespace));
// ------ Create SimContext ------
SimulationContext newsimcontext = null;
try {
newsimcontext = new SimulationContext(biomodel.getModel(), newgeometry, newmathdesc, version, bStoch, bRuleBased);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace(System.out);
throw new XmlParseException("A propertyveto exception was generated when creating the new SimulationContext " + name, e);
}
// set attributes
try {
newsimcontext.setName(name);
// Add annotation
String annotation = param.getChildText(XMLTags.AnnotationTag, vcNamespace);
if (annotation != null) /* && annotation.length()>0*/
{
newsimcontext.setDescription(unMangle(annotation));
}
// set if using concentration
newsimcontext.setUsingConcentration(bUseConcentration);
// set mass conservation model reduction flag
newsimcontext.setUsingMassConservationModelReduction(bMassConservationModelReduction);
// set if randomizing init condition or not (for stochastic applications
if (bStoch) {
newsimcontext.setRandomizeInitConditions(bRandomizeInitCondition);
}
if (bInsufficientIterations) {
newsimcontext.setInsufficientIterations(bInsufficientIterations);
}
if (bInsufficientMaxMolecules) {
newsimcontext.setInsufficientMaxMolecules(bInsufficientMaxMolecules);
}
if (nc != null) {
newsimcontext.setNetworkConstraints(nc);
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace(System.out);
throw new XmlParseException("Exception", e);
}
String tempchar = param.getAttributeValue(XMLTags.CharacteristicSizeTag);
if (tempchar != null) {
try {
newsimcontext.setCharacteristicSize(Double.valueOf(tempchar));
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace(System.out);
throw new XmlParseException("A PropertyVetoException was fired when setting the CharacteristicSize " + tempchar, e);
}
}
// Retrieve DataContext
Element dataContextElement = param.getChild(XMLTags.DataContextTag, vcNamespace);
if (dataContextElement != null) {
DataContext dataContext = newsimcontext.getDataContext();
ArrayList<DataSymbol> dataSymbols = getDataSymbols(dataContextElement, dataContext, newsimcontext.getModel().getUnitSystem());
for (int i = 0; i < dataSymbols.size(); i++) {
dataContext.addDataSymbol(dataSymbols.get(i));
}
}
// Retrieve spatialObjects and add to simContext
Element spatialObjectsElement = param.getChild(XMLTags.SpatialObjectsTag, vcNamespace);
if (spatialObjectsElement != null) {
SpatialObject[] spatialObjects = getSpatialObjects(newsimcontext, spatialObjectsElement);
try {
newsimcontext.setSpatialObjects(spatialObjects);
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error adding spatialObjects to simulationContext", e);
}
}
// Retrieve application parameters and add to simContext
Element appParamsElement = param.getChild(XMLTags.ApplicationParametersTag, vcNamespace);
if (appParamsElement != null) {
SimulationContextParameter[] appParameters = getSimulationContextParams(appParamsElement, newsimcontext);
try {
newsimcontext.setSimulationContextParameters(appParameters);
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error adding application parameters to simulationContext", e);
}
}
//
// -Process the GeometryContext-
//
Element tempelement = param.getChild(XMLTags.GeometryContextTag, vcNamespace);
LinkedList<StructureMapping> maplist = new LinkedList<StructureMapping>();
// Retrieve FeatureMappings
Iterator<Element> iterator = tempelement.getChildren(XMLTags.FeatureMappingTag, vcNamespace).iterator();
while (iterator.hasNext()) {
maplist.add(getFeatureMapping((Element) (iterator.next()), newsimcontext));
}
// Retrieve MembraneMappings
iterator = tempelement.getChildren(XMLTags.MembraneMappingTag, vcNamespace).iterator();
while (iterator.hasNext()) {
maplist.add(getMembraneMapping((Element) (iterator.next()), newsimcontext));
}
// Add these mappings to the internal geometryContext of this simcontext
StructureMapping[] structarray = new StructureMapping[maplist.size()];
maplist.toArray(structarray);
try {
newsimcontext.getGeometryContext().setStructureMappings(structarray);
newsimcontext.getGeometryContext().refreshStructureMappings();
newsimcontext.refreshSpatialObjects();
} catch (MappingException e) {
e.printStackTrace();
throw new XmlParseException("A MappingException was fired when trying to set the StructureMappings array to the Geometrycontext of the SimContext " + name, e);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace(System.out);
throw new XmlParseException("A PopertyVetoException was fired when trying to set the StructureMappings array to the Geometrycontext of the SimContext " + name, e);
}
//
// -Process the ReactionContext-
//
tempelement = param.getChild(XMLTags.ReactionContextTag, vcNamespace);
// Retrieve ReactionSpecs
List<Element> children = tempelement.getChildren(XMLTags.ReactionSpecTag, vcNamespace);
if (children.size() != 0) {
if (children.size() != biomodel.getModel().getReactionSteps().length) {
throw new XmlParseException("The number of reactions is not consistent.\n" + "Model reactions=" + biomodel.getModel().getReactionSteps().length + ", Reaction specs=" + children.size());
}
// *NOTE: Importing a model from other languages does not generates reaction specs.
// A more robust code will read the reactions in the source file and replace the ones created by the default by the VirtualCell framework.
ReactionSpec[] reactionSpecs = new ReactionSpec[children.size()];
int rSpecCounter = 0;
for (Element rsElement : children) {
reactionSpecs[rSpecCounter] = getReactionSpec(rsElement, newsimcontext);
rSpecCounter++;
}
try {
newsimcontext.getReactionContext().setReactionSpecs(reactionSpecs);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace(System.out);
throw new XmlParseException("A PropertyVetoException occurred while setting the ReactionSpecs to the SimContext " + name, e);
}
}
// Retrieve ReactionRuleSpecs
Element reactionRuleSpecsElement = tempelement.getChild(XMLTags.ReactionRuleSpecsTag, vcNamespace);
if (reactionRuleSpecsElement != null) {
ReactionRuleSpec[] reactionRuleSpecs = getReactionRuleSpecs(newsimcontext, reactionRuleSpecsElement);
try {
newsimcontext.getReactionContext().setReactionRuleSpecs(reactionRuleSpecs);
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
throw new XmlParseException("A PropertyVetoException occurred while setting the ReactionRuleSpecs to the SimContext " + name, e);
}
}
children = tempelement.getChildren(XMLTags.SpeciesContextSpecTag, vcNamespace);
getSpeciesContextSpecs(children, newsimcontext.getReactionContext(), biomodel.getModel());
// Retrieve output functions
Element outputFunctionsElement = param.getChild(XMLTags.OutputFunctionsTag, vcNamespace);
if (outputFunctionsElement != null) {
ArrayList<AnnotatedFunction> outputFunctions = getOutputFunctions(outputFunctionsElement);
try {
// construct OutputFnContext from mathDesc in newSimContext and add output functions that were read in from XML.
OutputFunctionContext outputFnContext = newsimcontext.getOutputFunctionContext();
for (AnnotatedFunction outputFunction : outputFunctions) {
outputFnContext.addOutputFunction(outputFunction);
}
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
throw new XmlParseException(e);
}
}
// Retrieve Electrical context
org.jdom.Element electElem = param.getChild(XMLTags.ElectricalContextTag, vcNamespace);
// this information is optional!
if (electElem != null) {
if (electElem.getChild(XMLTags.ClampTag, vcNamespace) != null) {
// read clamp
ElectricalStimulus[] electArray = new ElectricalStimulus[1];
electArray[0] = getElectricalStimulus(electElem.getChild(XMLTags.ClampTag, vcNamespace), newsimcontext);
try {
newsimcontext.setElectricalStimuli(electArray);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace(System.out);
throw new XmlParseException(e);
}
}
// read ground electrode
if (electElem.getChild(XMLTags.ElectrodeTag, vcNamespace) != null) {
Electrode groundElectrode = getElectrode(electElem.getChild(XMLTags.ElectrodeTag, vcNamespace), newsimcontext);
try {
newsimcontext.setGroundElectrode(groundElectrode);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace(System.out);
throw new XmlParseException(e);
}
}
}
// Retrieve (bio)events and add to simContext
tempelement = param.getChild(XMLTags.BioEventsTag, vcNamespace);
if (tempelement != null) {
BioEvent[] bioEvents = getBioEvents(newsimcontext, tempelement);
try {
newsimcontext.setBioEvents(bioEvents);
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error adding events to simulationContext", e);
}
}
// Retrieve spatialProcesses and add to simContext
tempelement = param.getChild(XMLTags.SpatialProcessesTag, vcNamespace);
if (tempelement != null) {
SpatialProcess[] spatialProcesses = getSpatialProcesses(newsimcontext, tempelement);
try {
newsimcontext.setSpatialProcesses(spatialProcesses);
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error adding spatialProcesses to simulationContext", e);
}
}
// Retrieve rate rules and add to simContext
tempelement = param.getChild(XMLTags.RateRulesTag, vcNamespace);
if (tempelement != null) {
RateRule[] rateRules = getRateRules(newsimcontext, tempelement);
try {
newsimcontext.setRateRules(rateRules);
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error adding rate rules to simulationContext", e);
}
}
tempelement = param.getChild(XMLTags.AssignmentRulesTag, vcNamespace);
if (tempelement != null) {
AssignmentRule[] assignmentRules = getAssignmentRules(newsimcontext, tempelement);
try {
newsimcontext.setAssignmentRules(assignmentRules);
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error adding assignment rules to simulationContext", e);
}
}
org.jdom.Element analysisTaskListElement = param.getChild(XMLTags.AnalysisTaskListTag, vcNamespace);
if (analysisTaskListElement != null) {
children = analysisTaskListElement.getChildren(XMLTags.ParameterEstimationTaskTag, vcNamespace);
if (children.size() != 0) {
Vector<ParameterEstimationTask> analysisTaskList = new Vector<ParameterEstimationTask>();
for (Element parameterEstimationTaskElement : children) {
try {
ParameterEstimationTask parameterEstimationTask = ParameterEstimationTaskXMLPersistence.getParameterEstimationTask(parameterEstimationTaskElement, newsimcontext);
analysisTaskList.add(parameterEstimationTask);
} catch (Exception e) {
e.printStackTrace(System.out);
throw new XmlParseException("An Exception occurred when parsing AnalysisTasks of SimContext " + name, e);
}
}
try {
AnalysisTask[] analysisTasks = (AnalysisTask[]) BeanUtils.getArray(analysisTaskList, AnalysisTask.class);
newsimcontext.setAnalysisTasks(analysisTasks);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace(System.out);
throw new XmlParseException("A PropertyVetoException occurred when setting the AnalysisTasks of the SimContext " + name, e);
}
}
}
// Microscope Measurement
org.jdom.Element element = param.getChild(XMLTags.MicroscopeMeasurement, vcNamespace);
if (element != null) {
getMicroscopeMeasurement(element, newsimcontext);
}
for (GeometryClass gc : newsimcontext.getGeometry().getGeometryClasses()) {
try {
StructureSizeSolver.updateUnitStructureSizes(newsimcontext, gc);
} catch (Exception e) {
e.printStackTrace();
}
}
newsimcontext.getGeometryContext().enforceHierarchicalBoundaryConditions(newsimcontext.getModel().getStructureTopology());
return newsimcontext;
}
use of cbit.vcell.mapping.Electrode in project vcell by virtualcell.
the class SimulationContextDbDriver method insertStimuliSQL.
/**
* This method was created in VisualAge.
*/
private void insertStimuliSQL(InsertHashtable hash, Connection con, KeyValue simContextKey, SimulationContext simContext) throws SQLException, DataAccessException {
StimulusTable stimulusTable = StimulusTable.table;
ElectricalStimulus[] stimuli = simContext.getElectricalStimuli();
//
for (int i = 0; i < stimuli.length; i++) {
ElectricalStimulus stimulus = stimuli[i];
KeyValue newStimuliKey = keyFactory.getNewKey(con);
//
String sql = "INSERT INTO " + stimulusTable.getTableName() + " " + stimulusTable.getSQLColumnList() + " VALUES " + stimulusTable.getSQLValueList(hash, newStimuliKey, simContextKey, stimulus);
// System.out.println(sql);
updateCleanSQL(con, sql);
}
//
// store ground electrode
//
Electrode groundElectrode = simContext.getGroundElectrode();
if (groundElectrode != null) {
KeyValue newStimuliKey = keyFactory.getNewKey(con);
//
String sql = "INSERT INTO " + stimulusTable.getTableName() + " " + stimulusTable.getSQLColumnList() + " VALUES " + stimulusTable.getSQLValueList(hash, newStimuliKey, simContextKey, groundElectrode);
// System.out.println(sql);
updateCleanSQL(con, sql);
}
}
use of cbit.vcell.mapping.Electrode in project vcell by virtualcell.
the class ElectricalStimulusPanel method newStimulus.
/**
* Comment
*/
private void newStimulus() {
try {
SimulationContext simContext = getSimulationContext();
if (simContext == null) {
return;
}
//
// When the voltage and current clamp radio buttons is deselected within the same simulation context (application),
// display a warning saying that the present clamp settings will be lost (not applicable when the 'no clamp'
// radiobutton is deselected.
//
ElectricalStimulus currElectricalStimulus = null;
if (simContext.getElectricalStimuli() != null && simContext.getElectricalStimuli().length > 0) {
currElectricalStimulus = simContext.getElectricalStimuli()[0];
}
//
// ignore selection if already selected
// warn upon deselect if about to loose edits
//
Clamp selectedClamp = (Clamp) clampComboBox.getSelectedItem();
if (currElectricalStimulus instanceof VoltageClampStimulus) {
if (selectedClamp == Clamp.Voltage_Clamp) {
return;
}
String response = PopupGenerator.showWarningDialog(this, "warning: the present voltage clamp settings will be lost", new String[] { UserMessage.OPTION_CONTINUE, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_CONTINUE);
if (response == null || response.equals(UserMessage.OPTION_CANCEL)) {
// revert back to Voltage Clamp
clampComboBox.setSelectedItem(Clamp.Voltage_Clamp);
return;
}
}
if (currElectricalStimulus instanceof TotalCurrentClampStimulus) {
if (selectedClamp == Clamp.Total_Current_Clamp) {
return;
}
String response = PopupGenerator.showWarningDialog(this, "warning: the present current clamp settings will be lost", new String[] { UserMessage.OPTION_CONTINUE, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_CONTINUE);
if (response == null || response.equals(UserMessage.OPTION_CANCEL)) {
// revert back to Current Clamp
clampComboBox.setSelectedItem(Clamp.Total_Current_Clamp);
return;
}
}
if (currElectricalStimulus instanceof CurrentDensityClampStimulus) {
if (selectedClamp == Clamp.Current_Density_Clamp) {
return;
}
String response = PopupGenerator.showWarningDialog(this, "warning: the present current clamp settings will be lost", new String[] { UserMessage.OPTION_CONTINUE, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_CONTINUE);
if (response == null || response.equals(UserMessage.OPTION_CANCEL)) {
// revert back to Current Clamp
clampComboBox.setSelectedItem(Clamp.Current_Density_Clamp);
return;
}
}
if (currElectricalStimulus == null && selectedClamp == Clamp.No_Clamp) {
return;
}
StructureTopology structTopology = getSimulationContext().getModel().getStructureTopology();
Structure[] structures = getSimulationContext().getModel().getStructures();
ArrayList<Feature> features = new ArrayList<Feature>();
for (Structure structure : structures) {
if (structure instanceof Feature) {
features.add((Feature) structure);
}
}
if (features.size() < 2) {
PopupGenerator.showErrorDialog(this, "error: electrodes must be placed in distinct volumetric structures, found " + features.size() + " volumetric structures in model");
return;
}
Feature groundFeature = features.get(0);
Feature clampedFeature = features.get(1);
//
if (selectedClamp == Clamp.Total_Current_Clamp) {
if (simContext.getElectricalStimuli().length == 0 || !(simContext.getElectricalStimuli()[0] instanceof TotalCurrentClampStimulus)) {
Electrode probeElectrode = new Electrode(clampedFeature, new Coordinate(0, 0, 0));
TotalCurrentClampStimulus ccStimulus = new TotalCurrentClampStimulus(probeElectrode, "ccElectrode", new Expression(0.0), simContext);
System.out.println(" Geo's dim = " + simContext.getGeometry().getDimension());
simContext.setElectricalStimuli(new ElectricalStimulus[] { ccStimulus });
simContext.setGroundElectrode(new Electrode(groundFeature, new Coordinate(0, 0, 0)));
}
}
//
if (selectedClamp == Clamp.Current_Density_Clamp) {
if (simContext.getElectricalStimuli().length == 0 || !(simContext.getElectricalStimuli()[0] instanceof CurrentDensityClampStimulus)) {
Electrode probeElectrode = new Electrode(clampedFeature, new Coordinate(0, 0, 0));
CurrentDensityClampStimulus ccStimulus = new CurrentDensityClampStimulus(probeElectrode, "ccElectrode", new Expression(0.0), simContext);
System.out.println(" Geo's dim = " + simContext.getGeometry().getDimension());
simContext.setElectricalStimuli(new ElectricalStimulus[] { ccStimulus });
simContext.setGroundElectrode(new Electrode(groundFeature, new Coordinate(0, 0, 0)));
}
}
//
if (selectedClamp == Clamp.No_Clamp) {
if (simContext.getElectricalStimuli().length > 0) {
simContext.setElectricalStimuli(new ElectricalStimulus[0]);
}
}
//
if (selectedClamp == Clamp.Voltage_Clamp) {
if (simContext.getElectricalStimuli().length == 0 || !(simContext.getElectricalStimuli()[0] instanceof VoltageClampStimulus)) {
Electrode probeElectrode = new Electrode(clampedFeature, new Coordinate(0, 0, 0));
VoltageClampStimulus vcStimulus = new VoltageClampStimulus(probeElectrode, "vcElectrode", new Expression(0.0), simContext);
System.out.println(" Geo's dim = " + simContext.getGeometry().getDimension());
simContext.setElectricalStimuli(new ElectricalStimulus[] { vcStimulus });
simContext.setGroundElectrode(new Electrode(groundFeature, new Coordinate(0, 0, 0)));
}
}
} catch (java.beans.PropertyVetoException e) {
PopupGenerator.showErrorDialog(this, "Error setting electrical stimulus: " + e.getMessage());
}
}
use of cbit.vcell.mapping.Electrode in project vcell by virtualcell.
the class XmlReader method getElectrode.
/**
* This method returns an Electrode object from a XML representation.
* Creation date: (6/6/2002 4:22:55 PM)
* @return cbit.vcell.mapping.Electrode
*/
private Electrode getElectrode(org.jdom.Element elem, SimulationContext currentSimulationContext) {
// retrieve feature
String featureName = unMangle(elem.getAttributeValue(XMLTags.FeatureAttrTag));
Feature feature = (Feature) currentSimulationContext.getModel().getStructure(featureName);
// retrieve position
Coordinate position = getCoordinate(elem.getChild(XMLTags.CoordinateTag, vcNamespace));
Electrode newElect = new Electrode(feature, position);
return newElect;
}
Aggregations