ode2sbml.converters.mathml_utils
mathml_utils
MathML utilities: SymPy ↔ SBML-MathML conversion via sbmlmath.
formula_to_astnode(formula)
Convert a SymPy-parseable formula string to a libsbml ASTNode.
Conversion pipeline: 1. Validate the string (no np./math. prefixes) 2. sympify → SymPy expression (with Symbol locals to avoid name clashes) 3. Print to SBML MathML via sbmlmath 4. Strip sbml:units annotations and parse with libsbml.readMathMLFromString 5. Return the libsbml ASTNode
Falls back to libsbml.parseL3Formula for simple expressions if
sbmlmath conversion fails.
Source code in ode2sbml/converters/mathml_utils.py
sympy_to_astnode(expr)
Convert a SymPy expression to a libsbml ASTNode.
Source code in ode2sbml/converters/mathml_utils.py
astnode_to_sympy(node)
Convert a libsbml ASTNode to a SymPy expression.
formula_to_mathml_str(formula)
Return the SBML MathML string for a formula.
Useful for debugging and testing.