use of cbit.vcell.parser.ExpressionBindingException in project vcell by virtualcell.
the class BioModelEditorModelPanel method duplicateReactionRule.
private ReactionRule duplicateReactionRule(ReactionRule oldRule, Structure structure) {
try {
ReactionRule newRule = ReactionRule.duplicate(oldRule, structure);
Model m = oldRule.getModel();
m.getRbmModelContainer().addReactionRule(newRule);
return newRule;
} catch (PropertyVetoException | ExpressionBindingException e) {
e.printStackTrace();
throw new RuntimeException("Problem duplicating " + ReactionRule.typeName + " " + oldRule.getDisplayName());
}
}
use of cbit.vcell.parser.ExpressionBindingException in project vcell by virtualcell.
the class XmlReader method getMathDescription.
/**
* This method returns a MathDescription from a XML element.
* Creation date: (4/26/2001 12:11:14 PM)
* @return cbit.vcell.math.MathDescription
* @param param org.jdom.Element
* @exception cbit.vcell.xml.XmlParseException The exception description.
*/
MathDescription getMathDescription(Element param, Geometry geometry) throws XmlParseException {
MathDescription mathdes = null;
Element tempelement;
// Retrieve Metadata(Version)
Version version = getVersion(param.getChild(XMLTags.VersionTag, vcNamespace));
// Retrieve attributes
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
// Create new MathDescription
if (version != null) {
mathdes = new MathDescription(version);
} else {
mathdes = new MathDescription(name);
}
try {
// this step is needed!
mathdes.setGeometry(geometry);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("a PropertyVetoException was fired when setting the Geometry to the Mathdescription in the simContext " + name, e);
}
// set attributes
try {
mathdes.setName(name);
// String annotation = param.getAttributeValue(XMLTags.AnnotationAttrTag);
// if (annotation!=null) {
// mathdes.setDescription(unMangle(annotation));
// }
// add Annotation
String annotationText = param.getChildText(XMLTags.AnnotationTag, vcNamespace);
if (annotationText != null && annotationText.length() > 0) {
mathdes.setDescription(unMangle(annotationText));
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("A PropertyVetoException was fired when setting the name " + name + ", to a new MathDescription!", e);
}
VariableHash varHash = new VariableHash();
// Retrieve Constant
Iterator<Element> iterator = param.getChildren(XMLTags.ConstantTag, vcNamespace).iterator();
while (iterator.hasNext()) {
tempelement = (Element) iterator.next();
try {
varHash.addVariable(getConstant(tempelement));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException(e);
}
}
// Retrieve FilamentRegionVariables
iterator = param.getChildren(XMLTags.FilamentRegionVariableTag, vcNamespace).iterator();
while (iterator.hasNext()) {
tempelement = (Element) iterator.next();
try {
varHash.addVariable(getFilamentRegionVariable(tempelement));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException(e);
}
}
// Retrieve FilamentVariables
iterator = param.getChildren(XMLTags.FilamentVariableTag, vcNamespace).iterator();
while (iterator.hasNext()) {
tempelement = (Element) iterator.next();
try {
varHash.addVariable(getFilamentVariable(tempelement));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException(e);
}
}
// retrieve InsideVariables
// **** This variables are for internal USE ******
// Retrieve MembraneRegionVariable
iterator = param.getChildren(XMLTags.MembraneRegionVariableTag, vcNamespace).iterator();
while (iterator.hasNext()) {
tempelement = (Element) iterator.next();
try {
varHash.addVariable(getMembraneRegionVariable(tempelement));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException(e);
}
}
// Retrieve MembraneVariable
iterator = param.getChildren(XMLTags.MembraneVariableTag, vcNamespace).iterator();
while (iterator.hasNext()) {
tempelement = (Element) iterator.next();
try {
varHash.addVariable(getMemVariable(tempelement));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException(e);
}
}
// Retrieve PointVariable
iterator = param.getChildren(XMLTags.PointVariableTag, vcNamespace).iterator();
while (iterator.hasNext()) {
tempelement = (Element) iterator.next();
try {
varHash.addVariable(getPointVariable(tempelement));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException(e);
}
}
// retrieve OutsideVariables
// **** This variables are for internal USE ******
// Retrieve Volume Region variable
iterator = param.getChildren(XMLTags.VolumeRegionVariableTag, vcNamespace).iterator();
while (iterator.hasNext()) {
tempelement = (Element) iterator.next();
try {
varHash.addVariable(getVolumeRegionVariable(tempelement));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException(e);
}
}
// Retrieve VolumeVariable
iterator = param.getChildren(XMLTags.VolumeVariableTag, vcNamespace).iterator();
while (iterator.hasNext()) {
tempelement = (Element) iterator.next();
try {
varHash.addVariable(getVolVariable(tempelement));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException(e);
}
}
// Retrieve StochVolVariable
iterator = param.getChildren(XMLTags.StochVolVariableTag, vcNamespace).iterator();
while (iterator.hasNext()) {
tempelement = (Element) iterator.next();
try {
varHash.addVariable(getStochVolVariable(tempelement));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException(e);
}
}
// Retrieve all the Functions //This needs to be processed before all the variables are read!
iterator = param.getChildren(XMLTags.FunctionTag, vcNamespace).iterator();
while (iterator.hasNext()) {
tempelement = (Element) iterator.next();
try {
varHash.addVariable(getFunction(tempelement));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException(e);
}
}
iterator = param.getChildren(XMLTags.VolumeRandomVariableTag, vcNamespace).iterator();
while (iterator.hasNext()) {
tempelement = (Element) iterator.next();
try {
varHash.addVariable(getRandomVariable(tempelement));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException(e);
}
}
iterator = param.getChildren(XMLTags.MembraneRandomVariableTag, vcNamespace).iterator();
while (iterator.hasNext()) {
tempelement = (Element) iterator.next();
try {
varHash.addVariable(getRandomVariable(tempelement));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException(e);
}
}
iterator = param.getChildren(XMLTags.VolumeParticleVariableTag, vcNamespace).iterator();
while (iterator.hasNext()) {
tempelement = (Element) iterator.next();
try {
varHash.addVariable(getVolumeParticalVariable(tempelement));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException(e);
}
}
iterator = param.getChildren(XMLTags.MembraneParticleVariableTag, vcNamespace).iterator();
while (iterator.hasNext()) {
tempelement = (Element) iterator.next();
try {
varHash.addVariable(getMembraneParticalVariable(tempelement));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException(e);
}
}
// ParticleMolecularTypeTag getParticleMolecularTypes
// has to be done before VolumeParticleSpeciesPattern and VolumeParticleObservable
iterator = param.getChildren(XMLTags.ParticleMolecularTypeTag, vcNamespace).iterator();
while (iterator.hasNext()) {
tempelement = (Element) iterator.next();
mathdes.addParticleMolecularType(getParticleMolecularType(tempelement));
}
// VolumeParticleSpeciesPatternTag
iterator = param.getChildren(XMLTags.VolumeParticleSpeciesPatternTag, vcNamespace).iterator();
while (iterator.hasNext()) {
tempelement = (Element) iterator.next();
try {
varHash.addVariable(getVolumeParticleSpeciesPattern(tempelement, mathdes));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException(e);
}
}
// VolumeParticleObservableTag getParticleObservables
iterator = param.getChildren(XMLTags.VolumeParticleObservableTag, vcNamespace).iterator();
while (iterator.hasNext()) {
tempelement = (Element) iterator.next();
try {
varHash.addVariable(getVolumeParticleObservable(tempelement, varHash));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException(e);
}
}
//
try {
mathdes.setAllVariables(varHash.getAlphabeticallyOrderedVariables());
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException("Error adding the Function variables to the MathDescription " + name, e);
} catch (ExpressionBindingException e) {
e.printStackTrace();
throw new XmlParseException("Error adding the Function variables to the MathDescription " + name, e);
}
// Retrieve CompartmentsSubdomains
iterator = param.getChildren(XMLTags.CompartmentSubDomainTag, vcNamespace).iterator();
while (iterator.hasNext()) {
tempelement = (Element) iterator.next();
try {
mathdes.addSubDomain(getCompartmentSubDomain(tempelement, mathdes));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException("Error adding a new CompartmentSubDomain to the MathDescription " + name, e);
}
}
// Retrieve MembraneSubdomains
iterator = param.getChildren(XMLTags.MembraneSubDomainTag, vcNamespace).iterator();
while (iterator.hasNext()) {
tempelement = (Element) iterator.next();
try {
mathdes.addSubDomain(getMembraneSubDomain(tempelement, mathdes));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException("Error adding a new MembraneSubDomain to the MathDescription " + name, e);
}
}
// Retrieve the FilamentSubdomain (if any)
tempelement = param.getChild(XMLTags.FilamentSubDomainTag, vcNamespace);
if (tempelement != null) {
try {
mathdes.addSubDomain(getFilamentSubDomain(tempelement, mathdes));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException("Error adding a new FilamentSubDomain to the MathDescription " + name, e);
}
}
// Retrieve the PointSubdomain (if any)
tempelement = param.getChild(XMLTags.PointSubDomainTag, vcNamespace);
if (tempelement != null) {
try {
mathdes.addSubDomain(getPointSubDomain(tempelement, mathdes));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException("Error adding a new PointSubDomain to the MathDescription " + name, e);
}
}
iterator = param.getChildren(XMLTags.EventTag, vcNamespace).iterator();
while (iterator.hasNext()) {
tempelement = (Element) iterator.next();
Event event = getEvent(mathdes, tempelement);
try {
mathdes.addEvent(event);
} catch (MathException e) {
e.printStackTrace(System.out);
throw new XmlParseException(e);
}
}
iterator = param.getChildren(XMLTags.PostProcessingBlock, vcNamespace).iterator();
while (iterator.hasNext()) {
tempelement = (Element) iterator.next();
getPostProcessingBlock(mathdes, tempelement);
}
return mathdes;
}
use of cbit.vcell.parser.ExpressionBindingException in project vcell by virtualcell.
the class XmlReader method getModel.
/**
* This method creates a Model object from a XML element.
* Creation date: (3/14/2001 6:14:37 PM)
* @return cbit.vcell.model.Model
* @param param org.jdom.Element
*/
private Model getModel(Element param) throws XmlParseException {
if (param == null) {
throw new XmlParseException("Invalid 'NULL' XML 'model' element arrived!");
}
// Get version, if any
Model newmodel = null;
Version version = getVersion(param.getChild(XMLTags.VersionTag, vcNamespace));
// if forcedModelUnitSystem has been set, ues that (could be overriding unit system for SBML export)
if (forcedModelUnitSystem != null) {
newmodel = new Model(version, forcedModelUnitSystem);
} else {
Element unitSystemNode = param.getChild(XMLTags.ModelUnitSystemTag, vcNamespace);
if (unitSystemNode != null) {
ModelUnitSystem modelUnitSystem = getUnitSystem(unitSystemNode);
newmodel = new Model(version, modelUnitSystem);
} else {
newmodel = new Model(version);
}
}
try {
// Set attributes
newmodel.setName(unMangle(param.getAttributeValue(XMLTags.NameAttrTag)));
// Add annotation
String annotationText = param.getChildText(XMLTags.AnnotationTag, vcNamespace);
if (annotationText != null && annotationText.length() > 0) {
newmodel.setDescription(unMangle(annotationText));
}
// Add global parameters
Element globalParamsElement = param.getChild(XMLTags.ModelParametersTag, vcNamespace);
if (globalParamsElement != null) {
ModelParameter[] modelParams = getModelParams(globalParamsElement, newmodel);
// add global/model param to model - done inside getModelParam by passing newModel
newmodel.setModelParameters(modelParams);
}
// Add Species (Compounds)
Iterator<Element> iterator = param.getChildren(XMLTags.SpeciesTag, vcNamespace).iterator();
ArrayList<Species> speciesList = new ArrayList<Species>();
while (iterator.hasNext()) {
org.jdom.Element temp = (Element) iterator.next();
speciesList.add(getSpecies(temp));
}
newmodel.setSpecies(speciesList.toArray(new Species[speciesList.size()]));
// Add Structures
LinkedList<Structure> newstructures = new LinkedList<Structure>();
// (features)
List<Element> children = param.getChildren(XMLTags.FeatureTag, vcNamespace);
for (Element featureElement : children) {
newstructures.add(getFeature(featureElement));
}
// (Membrane)
children = param.getChildren(XMLTags.MembraneTag, vcNamespace);
for (Element memElement : children) {
newstructures.add(getMembrane(newmodel, memElement, newstructures));
}
if (newstructures.size() > 0) {
Structure[] structarray = new Structure[newstructures.size()];
newstructures.toArray(structarray);
// Add all the retrieved structures
newmodel.setStructures(structarray);
}
// retrieve the RbmModelContainer, if present - must be done before we retrieve species context!
Element element = param.getChild(XMLTags.RbmModelContainerTag, vcNamespace);
if (element != null) {
getRbmModelContainer(element, newmodel);
} else {
lg.info("RbmModelContainer is missing.");
}
// Add SpeciesContexts
children = param.getChildren(XMLTags.SpeciesContextTag, vcNamespace);
SpeciesContext[] newspeccon = new SpeciesContext[children.size()];
int scCounter = 0;
for (Element scElement : children) {
newspeccon[scCounter] = getSpeciesContext(scElement, newmodel);
scCounter++;
}
newmodel.setSpeciesContexts(newspeccon);
// Retrieve rateRules and add to model
// Element rateRuleVarsElement = param.getChild(XMLTags.RateRuleVariablesTag, vcNamespace);
// if(rateRuleVarsElement != null){
// RateRuleVariable[] rateRuleVars = getRateRuleVariables(rateRuleVarsElement, newmodel);
// newmodel.setRateRuleVariables(rateRuleVars);
// }
// Add Reaction steps (if available)
// (Simplereaction)
// Create a varHash with reserved symbols and global parameters, if any, to pass on to Kinetics
// must create new hash for each reaction and flux, since each kinetics uses new variables hash
iterator = param.getChildren(XMLTags.SimpleReactionTag, vcNamespace).iterator();
ArrayList<ReactionStep> reactionStepList = new ArrayList<ReactionStep>();
while (iterator.hasNext()) {
org.jdom.Element temp = iterator.next();
reactionStepList.add(getSimpleReaction(temp, newmodel));
}
// (fluxStep)
iterator = param.getChildren(XMLTags.FluxStepTag, vcNamespace).iterator();
while (iterator.hasNext()) {
org.jdom.Element temp = iterator.next();
reactionStepList.add(getFluxReaction(temp, newmodel));
}
newmodel.setReactionSteps(reactionStepList.toArray(new ReactionStep[reactionStepList.size()]));
// Add Diagrams
children = param.getChildren(XMLTags.DiagramTag, vcNamespace);
if (children.size() > 0) {
Diagram[] newdiagrams = new Diagram[children.size()];
int diagramCounter = 0;
for (Element diagramElement : children) {
newdiagrams[diagramCounter] = getDiagram(diagramElement, newmodel);
diagramCounter++;
}
reorderDiagramsInPlace_UponRead(docVCellSoftwareVersion, newdiagrams, newmodel.getStructureTopology());
// if(docVCellSoftwareVersion != null && !docVCellSoftwareVersion.isValid() && docVCellSoftwareVersion.getMajorVersion()<=5 && docVCellSoftwareVersion.getMinorVersion() <=2){
// //In Vcell 5.2 and previous we need to order diagrams topologically, in 5.3 and later the diagrams are displayed as they are ordered when read from document
// final StructureTopology structureTopology = newmodel.getStructureTopology();
// Arrays.sort(newdiagrams, new Comparator<Diagram>() {
// @Override
// public int compare(Diagram o1, Diagram o2) {
// return getStructureLevel(o1.getStructure(), structureTopology) - getStructureLevel(o2.getStructure(), structureTopology);
// }
// });
// }
newmodel.setDiagrams(newdiagrams);
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException(e);
} catch (ModelException e) {
e.printStackTrace();
}
// model param expresions are not bound when they are read in, since they could be functions of each other or structures/speciesContexts.
// Hence bind the model param exprs at the end, after reading all model level quantities.
ModelParameter[] modelParameters = newmodel.getModelParameters();
for (int i = 0; modelParameters != null && i < modelParameters.length; i++) {
try {
modelParameters[i].getExpression().bindExpression(newmodel);
} catch (ExpressionBindingException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error binding global parameter '" + modelParameters[i].getName() + "' to model." + e.getMessage());
}
}
return newmodel;
}
use of cbit.vcell.parser.ExpressionBindingException in project vcell by virtualcell.
the class FunctionFileGenerator method readFunctionsFile.
/**
* This method was created in VisualAge.
* @param logFile java.io.File
*/
public static synchronized Vector<AnnotatedFunction> readFunctionsFile(File functionsFile, String simJobID) throws java.io.FileNotFoundException, java.io.IOException {
// Check if file exists
if (!functionsFile.exists()) {
throw new java.io.FileNotFoundException("functions file " + functionsFile.getPath() + " not found");
}
//
// Read characters from functionFile into character array and transfer into string buffer.
//
Vector<AnnotatedFunction> annotatedFunctionsVector = new Vector<AnnotatedFunction>();
long fnFileLength = functionsFile.length();
StringBuffer stringBuffer = new StringBuffer();
FileInputStream is = null;
try {
is = new FileInputStream(functionsFile);
InputStreamReader reader = new InputStreamReader(is);
BufferedReader br = new BufferedReader(reader);
char[] charArray = new char[10000];
while (true) {
int numRead = br.read(charArray, 0, charArray.length);
if (numRead > 0) {
stringBuffer.append(charArray, 0, numRead);
} else if (numRead == -1) {
break;
}
}
} finally {
if (is != null) {
is.close();
}
}
if (stringBuffer.length() != fnFileLength) {
System.out.println("<<<SYSOUT ALERT>>>SimulationData.readFunctionFile(), read " + stringBuffer.length() + " of " + fnFileLength + " bytes of input file");
}
String newLineDelimiters = "\n\r";
StringTokenizer lineTokenizer = new StringTokenizer(stringBuffer.toString(), newLineDelimiters);
String token1 = new String("");
int j = 0;
//
// Each token is a line representing a function name and function expression,
// separated by a semicolon
//
HashSet<String> allSymbols = new HashSet<String>();
while (lineTokenizer.hasMoreTokens()) {
token1 = lineTokenizer.nextToken();
FunctionFileGenerator.FuncFileLineInfo funcFileLineInfo = readFunctionLine(token1);
if (funcFileLineInfo != null && funcFileLineInfo.functionName != null && funcFileLineInfo.functionExpr != null && funcFileLineInfo.funcVarType != null) {
Expression functionExpr = null;
try {
functionExpr = new Expression(funcFileLineInfo.functionExpr);
functionExpr = MathFunctionDefinitions.fixFunctionSyntax(functionExpr);
} catch (cbit.vcell.parser.ExpressionException e) {
throw new RuntimeException("Error in reading expression '" + funcFileLineInfo.functionExpr + "' for function \"" + funcFileLineInfo.functionName + "\"");
}
Domain domain = Variable.getDomainFromCombinedIdentifier(funcFileLineInfo.functionName);
String funcName = Variable.getNameFromCombinedIdentifier(funcFileLineInfo.functionName);
AnnotatedFunction annotatedFunc = new AnnotatedFunction(funcName, functionExpr, domain, funcFileLineInfo.errorString, funcFileLineInfo.funcVarType, funcFileLineInfo.funcIsUserDefined ? FunctionCategory.OLDUSERDEFINED : FunctionCategory.PREDEFINED);
allSymbols.add(annotatedFunc.getName());
String[] symbols = annotatedFunc.getExpression().getSymbols();
if (symbols != null) {
allSymbols.addAll(Arrays.asList(symbols));
}
annotatedFunctionsVector.addElement(annotatedFunc);
}
j++;
}
if (simJobID != null && simJobID.trim().length() > 0) {
SimpleSymbolTable simpleSymbolTable = new SimpleSymbolTable(allSymbols.toArray(new String[0]));
// bind
for (AnnotatedFunction func : annotatedFunctionsVector) {
if (func.isOldUserDefined()) {
try {
func.bind(simpleSymbolTable);
} catch (ExpressionBindingException e) {
e.printStackTrace();
}
}
}
// rename symbol table entries
for (int i = 0; i < annotatedFunctionsVector.size(); i++) {
AnnotatedFunction func = annotatedFunctionsVector.get(i);
if (func.isOldUserDefined()) {
SimpleSymbolTableEntry ste = (SimpleSymbolTableEntry) simpleSymbolTable.getEntry(func.getName());
ste.setName(simJobID + "_" + func.getName());
}
}
// rename in the expressions
for (int i = 0; i < annotatedFunctionsVector.size(); i++) {
AnnotatedFunction func = annotatedFunctionsVector.get(i);
if (func.isOldUserDefined()) {
try {
Expression exp = func.getExpression().renameBoundSymbols(simpleSymbolTable.getNameScope());
AnnotatedFunction newfunc = new AnnotatedFunction(simJobID + "_" + func.getName(), exp, func.getDomain(), func.getName(), func.getErrorString(), func.getFunctionType(), FunctionCategory.OLDUSERDEFINED);
annotatedFunctionsVector.set(i, newfunc);
} catch (ExpressionBindingException e) {
e.printStackTrace();
}
}
}
}
return annotatedFunctionsVector;
}
use of cbit.vcell.parser.ExpressionBindingException in project vcell by virtualcell.
the class XmlReader method getRateRules.
public RateRule[] getRateRules(SimulationContext simContext, Element rateRulesElement) throws XmlParseException {
Iterator<Element> rateRulesIterator = rateRulesElement.getChildren(XMLTags.RateRuleTag, vcNamespace).iterator();
Vector<RateRule> rateRulesVector = new Vector<RateRule>();
while (rateRulesIterator.hasNext()) {
Element rrElement = (Element) rateRulesIterator.next();
RateRule newRateRule = null;
try {
String rrName = unMangle(rrElement.getAttributeValue(XMLTags.NameAttrTag));
String varname = rrElement.getAttributeValue(XMLTags.RateRuleVariableAttrTag);
SymbolTableEntry rrVar = simContext.getEntry(varname);
Expression rrExp = unMangleExpression(rrElement.getText());
newRateRule = new RateRule(rrName, rrVar, rrExp, simContext);
newRateRule.bind();
} catch (ExpressionBindingException e) {
e.printStackTrace(System.out);
throw new XmlParseException(e.getMessage());
}
if (newRateRule != null) {
rateRulesVector.add(newRateRule);
}
}
return ((RateRule[]) BeanUtils.getArray(rateRulesVector, RateRule.class));
}
Aggregations