use of cbit.vcell.math.Variable.Domain 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.math.Variable.Domain in project vcell by virtualcell.
the class XmlReader method getFilamentVariable.
/**
* This method returns a FilamentVariable object from a XML Element.
* Creation date: (5/16/2001 2:56:34 PM)
* @return cbit.vcell.math.FilamentVariable
* @param param org.jdom.Element
*/
private FilamentVariable getFilamentVariable(Element param) {
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
String domainStr = unMangle(param.getAttributeValue(XMLTags.DomainAttrTag));
Domain domain = null;
if (domainStr != null) {
domain = new Domain(domainStr);
}
// -- create new filVariable object
FilamentVariable filVariable = new FilamentVariable(name, domain);
transcribeComments(param, filVariable);
return filVariable;
}
use of cbit.vcell.math.Variable.Domain in project vcell by virtualcell.
the class XmlReader method getProjectionDataGenerator.
private ProjectionDataGenerator getProjectionDataGenerator(Element element) {
String name = unMangle(element.getAttributeValue(XMLTags.NameAttrTag));
String domainStr = unMangle(element.getAttributeValue(XMLTags.DomainAttrTag));
Domain domain = null;
if (domainStr != null) {
domain = new Domain(domainStr);
}
Element e = element.getChild(XMLTags.ProjectionAxis, vcNamespace);
String axis = e.getText();
// ProjectionDataGenerator.Axis axis = ProjectionDataGenerator.Axis.valueOf(s);
e = element.getChild(XMLTags.ProjectionOperation, vcNamespace);
String operation = e.getText();
// ProjectionDataGenerator.Operation operation = ProjectionDataGenerator.Operation.valueOf(s);
e = element.getChild(XMLTags.FunctionTag, vcNamespace);
String s = e.getText();
Expression exp = unMangleExpression(s);
ProjectionDataGenerator projectionDataGenerator = new ProjectionDataGenerator(name, domain, axis, operation, exp);
return projectionDataGenerator;
}
use of cbit.vcell.math.Variable.Domain in project vcell by virtualcell.
the class XmlReader method getExplicitDataGenerator.
private ExplicitDataGenerator getExplicitDataGenerator(Element element) {
String name = unMangle(element.getAttributeValue(XMLTags.NameAttrTag));
String domainStr = unMangle(element.getAttributeValue(XMLTags.DomainAttrTag));
Domain domain = null;
if (domainStr != null) {
domain = new Domain(domainStr);
}
String temp = element.getText();
Expression exp = unMangleExpression(temp);
ExplicitDataGenerator explicitDataGenerator = new ExplicitDataGenerator(name, domain, exp);
return explicitDataGenerator;
}
use of cbit.vcell.math.Variable.Domain in project vcell by virtualcell.
the class XmlReader method getFunction.
/**
* This method returns a Function variable object from a XML Element.
* Creation date: (5/16/2001 3:45:21 PM)
* @return cbit.vcell.math.Function
* @param param org.jdom.Element
* @exception cbit.vcell.xml.XmlParseException The exception description.
*/
private Function getFunction(Element param) throws XmlParseException {
// get attributes
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
/**
* ---------------------------------------------------------------
* ATTENTATION: this is a quick fix for a specific user to load his model
* with a function name as "ATP/ADP". This syntax is not allowed.
*-----------------------------------------------------------------------
*/
if (name.equals("ATP/ADP")) {
name = "ATP_ADP_renamed";
System.err.print("Applying species function name change ATP/ADP to ATP_ADP for a specific user (key=2288008)");
Thread.dumpStack();
}
String domainStr = unMangle(param.getAttributeValue(XMLTags.DomainAttrTag));
Domain domain = null;
if (domainStr != null) {
domain = new Domain(domainStr);
}
String temp = param.getText();
Expression exp = unMangleExpression(temp);
// -- create new Function --
Function function = new Function(name, exp, domain);
transcribeComments(param, function);
return function;
}
Aggregations