use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.
the class XmlReader method getAction.
/**
* This method returns a Action object from a XML element.
* Creation date: (7/24/2006 5:56:36 PM)
* @return cbit.vcell.math.Action
* @param param org.jdom.Element
* @exception cbit.vcell.xml.XmlParseException The exception description.
*/
private Action getAction(Element param, MathDescription md) throws XmlParseException, MathException, ExpressionException {
// retrieve values
String operation = unMangle(param.getAttributeValue(XMLTags.OperationAttrTag));
String operand = param.getText();
Expression exp = null;
if (operand != null && operand.length() != 0) {
exp = unMangleExpression(operand);
}
String name = unMangle(param.getAttributeValue(XMLTags.VarNameAttrTag));
Variable var = md.getVariable(name);
if (var == null) {
throw new MathFormatException("variable " + name + " not defined");
}
if (!(var instanceof StochVolVariable) && !(var instanceof ParticleVariable)) {
throw new MathFormatException("variable " + name + " not a Stochastic Volume Variable");
}
try {
Action action = new Action(var, operation, exp);
return action;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of cbit.vcell.parser.ExpressionException 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.parser.ExpressionException in project vcell by virtualcell.
the class XmlReader method getAnalyticSubVolume.
/**
* This method returns an AnalyticSubVolume object from a XML representation.
* Creation date: (5/1/2001 5:26:17 PM)
* @return cbit.vcell.geometry.AnalyticSubVolume
* @param param org.jdom.Element
*/
private AnalyticSubVolume getAnalyticSubVolume(Element param) throws XmlParseException {
// retrieve the attributes
String name = param.getAttributeValue(XMLTags.NameAttrTag);
int handle = Integer.parseInt(param.getAttributeValue(XMLTags.HandleAttrTag));
// process the key
KeyValue key = null;
String temp = param.getAttributeValue(XMLTags.KeyValueAttrTag);
if (temp != null && temp.length() > 0 && this.readKeysFlag) {
key = new KeyValue(temp);
}
// Retrieve the expression
temp = param.getChildText(XMLTags.AnalyticExpressionTag, vcNamespace);
if (temp == null) {
throw new XmlParseException("A Problem occured while retrieving the analytic expression of the AnalyticSubvolume " + name);
}
Expression newexpression = unMangleExpression(temp);
// Create the AnalyticCompartment
AnalyticSubVolume newsubvolume = null;
try {
newsubvolume = new AnalyticSubVolume(key, name, newexpression, handle);
} catch (ExpressionException e) {
e.printStackTrace();
throw new XmlParseException("An ExpressionException occured when creating the new AnalyticSubvolume " + name, e);
}
return newsubvolume;
}
use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.
the class LocalOptimizationService method solve.
/**
* solve method comment.
*/
public OptimizationResultSet solve(OptimizationSpec optSpec, OptimizationSolverSpec optSolverSpec, OptSolverCallbacks optSolverCallbacks) {
OptimizationSolver optSolver = null;
if (optSolverSpec.getSolverType().equals(OptimizationSolverSpec.SOLVERTYPE_POWELL)) {
optSolver = new PowellOptimizationSolver();
// }else if (optSolverSpec.getSolverType().equals(OptimizationSolverSpec.SOLVERTYPE_CONJUGATE_GRADIENT)){
// optSolver = new ConjugateGradientOptimizationSolver();
} else {
throw new RuntimeException("unsupported solver type '" + optSolverSpec.getSolverType() + "'");
}
OptimizationResultSet optResultSet = null;
try {
optResultSet = optSolver.solve(optSpec, optSolverSpec, optSolverCallbacks);
} catch (IOException e) {
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
} catch (OptimizationException e) {
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
}
return optResultSet;
}
use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.
the class XmlReader method getGeometry.
/**
* This method returns a Geometry object from a XML representation.
* Creation date: (4/26/2001 12:12:18 PM)
* @return cbit.vcell.geometry.Geometry
* @param param org.jdom.Element
* @exception cbit.vcell.xml.XmlParseException The exception description.
*/
public Geometry getGeometry(Element param) throws XmlParseException {
// Get the Extent object
Extent newextent = getExtent(param.getChild(XMLTags.ExtentTag, vcNamespace));
// Get VCimage information
VCImage newimage = null;
if (param.getChild(XMLTags.ImageTag, vcNamespace) != null) {
try {
newimage = getVCImage(param.getChild(XMLTags.ImageTag, vcNamespace), newextent);
} catch (Throwable e) {
e.printStackTrace();
throw new XmlParseException(e);
}
}
// Get attributes
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
int newdimension = Integer.parseInt(param.getAttributeValue(XMLTags.DimensionAttrTag));
// Get Version
Version version = getVersion(param.getChild(XMLTags.VersionTag, vcNamespace));
// Try to construct the geometry upon four different cases
Geometry newgeometry = null;
if (version != null && newimage != null) {
newgeometry = new Geometry(version, newimage);
} else if (version != null) {
newgeometry = new Geometry(version, newdimension);
} else if (newimage != null) {
newgeometry = new Geometry(name, newimage);
} else {
newgeometry = new Geometry(name, newdimension);
}
// set attributes
try {
if (!newgeometry.getName().equalsIgnoreCase(name)) {
newgeometry.setName(name);
}
// String annotation = param.getAttributeValue(XMLTags.AnnotationAttrTag);
// if (annotation!=null) {
// newgeometry.setDescription( unMangle(annotation) );
// }
// Add annotation
String annotation = param.getChildText(XMLTags.AnnotationTag, vcNamespace);
if (annotation != null && annotation.length() > 0) {
newgeometry.setDescription(unMangle(annotation));
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("A PropertyVetoException occurred when setting the name " + name + " to a Geometry object!", e);
}
// Add the Extent
try {
newgeometry.getGeometrySpec().setExtent(newextent);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("A PropertyVetoException occurred while trying to set the Extent for the Geometry " + name, e);
}
// Add the Origin
newgeometry.getGeometrySpec().setOrigin(getOrigin(param.getChild(XMLTags.OriginTag, vcNamespace)));
// Add the SubVolumes
List<Element> children = param.getChildren(XMLTags.SubVolumeTag, vcNamespace);
SubVolume[] newsubvolumes = new SubVolume[children.size()];
int subvolumeCounter = 0;
for (Element child : children) {
newsubvolumes[subvolumeCounter] = getSubVolume(child);
subvolumeCounter++;
}
try {
newgeometry.getGeometrySpec().setSubVolumes(newsubvolumes);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("A PropertyVetoException was generated when ading the subvolumes to the Geometry " + name, e);
}
if (newgeometry.getDimension() > 0) {
// Add SurfaceClasses
List<Element> surfaceClassChildren = param.getChildren(XMLTags.SurfaceClassTag, vcNamespace);
SurfaceClass[] newSurfaceClassArr = new SurfaceClass[surfaceClassChildren.size()];
int surfClassCounter = 0;
for (Element surfClassChild : surfaceClassChildren) {
newSurfaceClassArr[surfClassCounter] = getSurfaceClass(surfClassChild, newgeometry);
surfClassCounter++;
}
try {
newgeometry.getGeometrySurfaceDescription().setSurfaceClasses(newSurfaceClassArr);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("A PropertyVetoException was generated when ading the subvolumes to the Geometry " + name, e);
}
}
// read Filaments (if any)
Iterator<Element> iterator = param.getChildren(XMLTags.FilamentTag, vcNamespace).iterator();
while (iterator.hasNext()) {
Element tempElement = iterator.next();
String filname = unMangle(tempElement.getAttributeValue(XMLTags.NameAttrTag));
Iterator<Element> curveiterator = tempElement.getChildren().iterator();
while (curveiterator.hasNext()) {
ControlPointCurve curve = getControlPointCurve(curveiterator.next());
newgeometry.getGeometrySpec().getFilamentGroup().addCurve(filname, curve);
}
}
// read Surface description (if any)
Element sd = param.getChild(XMLTags.SurfaceDescriptionTag, vcNamespace);
if (sd != null) {
GeometrySurfaceDescription dummy = getGeometrySurfaceDescription(sd, newgeometry);
}
try {
newgeometry.precomputeAll(new GeometryThumbnailImageFactoryAWT(), false, false);
} catch (GeometryException e) {
e.printStackTrace(System.out);
} catch (ImageException e) {
e.printStackTrace(System.out);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
}
return newgeometry;
}
Aggregations