use of org.sbml.jsbml.text.parser.ParseException in project vcell by virtualcell.
the class VCellModel method parseValueStringForParameter.
public ASTNode parseValueStringForParameter(Parameter parameter, String value) {
Model model = sbmlDocument.getModel();
ExplicitRule rule = model.getRuleByVariable(parameter.getId());
if (rule != null) {
try {
return ASTNode.parseFormula(value);
} catch (ParseException e) {
e.printStackTrace();
}
}
return null;
}
use of org.sbml.jsbml.text.parser.ParseException in project vcell by virtualcell.
the class SBMLExporter method getFormulaFromExpression.
/**
* getFormulaFromExpression :
* Expression infix strings are not handled gracefully by libSBML, esp when ligical or inequality operators are used.
* This method
* converts the expression into MathML using ExpressionMathMLPrinter;
* converts that into libSBMl-readable formula using libSBML utilties.
* returns the new formula string.
*/
public static ASTNode getFormulaFromExpression(Expression expression, MathType desiredType) {
// switch to libSBML for non-boolean
if (!desiredType.equals(MathType.BOOLEAN)) {
try {
return ASTNode.parseFormula(expression.infix());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new RuntimeException(e.toString());
}
}
// Convert expression into MathML string
String expMathMLStr = null;
try {
expMathMLStr = cbit.vcell.parser.ExpressionMathMLPrinter.getMathML(expression, false, desiredType);
} catch (java.io.IOException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error converting expression to MathML string :" + e.getMessage());
} catch (cbit.vcell.parser.ExpressionException e1) {
e1.printStackTrace(System.out);
throw new RuntimeException("Error converting expression to MathML string :" + e1.getMessage());
}
// Use libSBMl routines to convert MathML string to MathML document and a libSBML-readable formula string
ASTNode mathNode = ASTNode.readMathMLFromString(expMathMLStr);
return mathNode;
}
Aggregations