@Override public ASTNodeValue unknownValue() throws SBMLException { throw new SBMLException( "cannot write unknown syntax tree nodes to a MathML document"); }
/** * Returns the infix formula representing this ASTNode or an empty String if there was * a problem to construct the formula. * * @return the infix formula representing this ASTNode */ public String printASTNode() { String formula = ""; try { formula = toFormula(); } catch (SBMLException e) { // log the exception e.printStackTrace(); if (isDebugEnabled) { logger.error(MessageFormat.format(resourceBundle.getString("ASTNode.toString"), e.getMessage()), e); } else { // TODO: Do not print this message if parsing the file !!! Or remove it logger.warn(MessageFormat.format(resourceBundle.getString("ASTNode.toString"), e.getMessage())); } } catch (RuntimeException e) { // added to prevent a crash when we cannot create the formula if (isDebugEnabled) { logger.error(MessageFormat.format(resourceBundle.getString("ASTNode.toString"), e.getMessage()), e); } } return formula; }
/** * This method flattens out arrays objects of a given {@link SBMLDocument}. * * @param document - the document you want to convert. * @return new Document that is not associated with the arrays package. */ public static SBMLDocument convert(SBMLDocument document) { try { SBMLDocument flattenedDoc = document.clone(); Model model = flattenedDoc.getModel(); Map<String, ASTNode> idToVector = new HashMap<String, ASTNode>(); getVectors(flattenedDoc.getModel(), idToVector); convert(flattenedDoc, model, new ArraysCompiler(), idToVector, new ArrayList<Integer>()); convertMath(flattenedDoc, model, idToVector); return flattenedDoc; } catch(SBMLException exception) { logger.error(exception.getMessage()); return null; } }
@Override public <T> ASTNode2Value<String> factorial(ASTNode2 node) { try { return function("factorial", node); } catch (SBMLException e) { e.printStackTrace(); } return null; }
/** * @param args */ public static void main(String[] args) { ASTNode formula_base = new ASTNode(Double.NaN); System.out.println(formula_base.toMathML()); try { System.out.println(formula_base.toFormula()); } catch (SBMLException e) { e.printStackTrace(); } double x = 0.0050; double y = 1.0; double z = 1.66E-4; double zz = 12548698515426596325478965230.33254; System.out.println("Test Double formatting "); // NumberFormat format = DecimalFormat.getInstance(); DecimalFormat format = new DecimalFormat(StringTools.REAL_FORMAT, new DecimalFormatSymbols(Locale.ENGLISH)); System.out.println("x = " + format.format(x)); System.out.println("y = " + format.format(y)); System.out.println("z = " + format.format(z) + " " + format.getMaximumFractionDigits()); System.out.println("zz = " + format.format(zz) + " "); }
@Override public ASTNodeValue unknownValue() throws SBMLException { throw new SBMLException( "cannot write unknown syntax tree nodes to a formula String"); }
} catch (SBMLException e) { logger.error( "There was an error creating a temporary file: " + e.getMessage()); e.printStackTrace();
/** * @param args */ public static void main(String[] args) { ASTCnRealNode formula_base = new ASTCnRealNode(Double.NaN); System.out.println(formula_base.toMathML()); try { System.out.println(formula_base.toFormula()); } catch (SBMLException e) { e.printStackTrace(); } double x = 0.0050; double y = 1.0; double z = 1.66E-4; double zz = 12548698515426596325478965230.33254; System.out.println("Test Double formatting "); // NumberFormat format = DecimalFormat.getInstance(); DecimalFormat format = new DecimalFormat(StringTools.REAL_FORMAT, new DecimalFormatSymbols(Locale.ENGLISH)); System.out.println("x = " + format.format(x)); System.out.println("y = " + format.format(y)); System.out.println("z = " + format.format(z) + " " + format.getMaximumFractionDigits()); System.out.println("zz = " + format.format(zz) + " "); } /**
@Override public <T> ASTNode2Value<String> unknownValue() throws SBMLException { throw new SBMLException( "cannot write unknown syntax tree nodes to a formula String"); }
/** * Converts a {@link ASTNode2} to a {@link ASTNode}. * * @param astNode2 {@link ASTNode2} * @return astNode {@link ASTNode} */ public static ASTNode toASTNode(ASTNode2 astNode2) { // TODO implement function without parsing. IFormulaParser parser = new FormulaParserLL3(new StringReader("")); ASTNode astNode = null; try { astNode = ASTNode.parseFormula(astNode2.toFormula(), parser); } catch (SBMLException e) { e.printStackTrace(); } catch (org.sbml.jsbml.text.parser.ParseException e) { e.printStackTrace(); } return astNode; }
@Override public ASTNodeValue compile(int integer, String units) { if ((units != null) && (units.length() > 0)) { isUnitsDefined = true; throw new SBMLException("Stopping the recursion, a units has been found and the SBML namespace is needed."); } return dummyValue; }
@Override public String toString() { if (isNode()) { try { return MathMLParser.toMathML(MathMLParser.createMathMLDocumentFor(toNode(), getLevel()), true, true, 2); } catch (IOException e) { e.printStackTrace(); } catch (SBMLException e) { e.printStackTrace(); } } String val = (value != null) ? value.toString() : super.toString(); if (isSetUnit()) { val += ' ' + UnitDefinition.printUnits(getUnits(), true); } return val; }
@Override public <T> ASTNode2Value<String> compile(int integer, String units) { if ((units != null) && (units.length() > 0)) { isUnitsDefined = true; throw new SBMLException("Stopping the recursion, a units has been found and the SBML namespace is needed."); } return dummyValue; }
@Override public String toString() { if (isNode()) { try { return MathMLParser.toMathML(MathMLParser.createMathMLDocumentFor(toNode(), getLevel()), true, true, 2); } catch (IOException e) { e.printStackTrace(); } catch (SBMLException e) { e.printStackTrace(); } } String val = (value != null) ? value.toString() : super.toString(); if (isSetUnit()) { val += ' ' + UnitDefinition.printUnits(getUnits(), true); } return val; }
@Override public <T> ASTNode2Value<String> compile(double mantissa, int exponent, String units) { if ((units != null) && (units.length() > 0)) { isUnitsDefined = true; throw new SBMLException("Stopping the recursion, a units has been found and the SBML namespace is needed."); } return dummyValue; }
@Override public <T> ASTNode2Value<String> compile(double real, String units) { if ((units != null) && (units.length() > 0)) { isUnitsDefined = true; throw new SBMLException("Stopping the recursion, a units has been found and the SBML namespace is needed."); } return dummyValue; }
@Override public ASTNodeValue compile(double mantissa, int exponent, String units) { if ((units != null) && (units.length() > 0)) { isUnitsDefined = true; throw new SBMLException("Stopping the recursion, a units has been found and the SBML namespace is needed."); } return dummyValue; }
@Override public ASTNodeValue compile(double real, String units) { if ((units != null) && (units.length() > 0)) { isUnitsDefined = true; throw new SBMLException("Stopping the recursion, a units has been found and the SBML namespace is needed."); } return dummyValue; }
/** * Sets the value of spatialDimension * @param spatialDimension */ public void setSpatialDimensions(int spatialDimension) { Integer oldSpatialDimension = spatialDimensions; if (!((spatialDimension >= 0) && (spatialDimension <= 3))) { throw new SBMLException("Not a valid spatial dimension. Must be 0, 1, 2, or 3."); } spatialDimensions = spatialDimension; firePropertyChange(SpatialConstants.spatialDimensions, oldSpatialDimension, spatialDimensions); }
@Override public String toMathML() { try { if (isSetRefId()) { return MathMLXMLStreamCompiler.toMathML(this); } throw new SBMLException(); } catch (RuntimeException e) { logger.error("Unable to create MathML"); return null; } }