public static void main(String[] args) { if (args.length < 1) { System.out.println("Usage: evaluateCustomMath formula [model containing values]"); System.exit(1); } String formula = args[0]; String filename = args.length == 2 ? args[1] : null; ASTNode math = libsbml.parseFormula(formula); if (math == null) { System.out.println("Invalid formula, aborting."); System.exit(1); } SBMLDocument doc = null; if (filename != null) { doc = libsbml.readSBML(filename); if (doc.getNumErrors(libsbml.LIBSBML_SEV_ERROR) > 0) { System.out.println("The models contains errors, please correct them before continuing."); doc.printErrors(); System.exit(1); } // the following maps a list of ids to their corresponding model values // this makes it possible to evaluate expressions involving SIds. SBMLTransforms.mapComponentValues(doc.getModel()); } else { // create dummy document doc = new SBMLDocument(3, 1); } double result = SBMLTransforms.evaluateASTNode(math, doc.getModel()); System.out.println(String.format("%s = %s", formula, result)); }