sbmlmath.mathml_parser¶
SBML mathml to sympy.
Classes
|
MathML parser for sympy. |
- class sbmlmath.mathml_parser.SBMLMathMLParser(sbml_level=3, sbml_version=2, ureg=None, floats_as_rationals=True, ignore_units=False, symbol_kwargs=None, evaluate=False)[source]¶
Bases:
objectMathML parser for sympy.
Parses the SBML subset of MathML 2.0.
For details, see SBML spec section 3.4: https://raw.githubusercontent.com/combine-org/combine-specifications/main/specifications/files/sbml.level-3.version-2.core.release-2.pdf.
See also: MathML 2.0 specification.
- Parameters:
sbml_level (
int|str) – SBML level. Note that SBML level < 3 has not been thoroughly tested.ureg (
UnitRegistry) – Optionalpint.UnitRegistryto use for unit conversion.floats_as_rationals – Whether to convert floats to
sympy.Rational. Improves precision.ignore_units – Whether to ignore units. If
True, all units are ignored and all numbers are converted to plain numbers. IfFalse, all math elements with units are converted topint.Quantityobjects.symbol_kwargs – Additional keyword arguments for constructing
sympy.Symbol. For example, for passing custom assumptions such asreal=True.
- handle_ci(element)[source]¶
Handle identifiers.
See also: numerical constants in MathML.
- Return type:
- Parameters:
element (_Element)
- handle_cn(element)[source]¶
Handle numbers.
See also: numerical constants in MathML.
- Return type:
- Parameters:
element (_Element)
- parse_file(file_like)[source]¶
Parse a file-like object containing MathML.
- Parameters:
file_like – File-like object (file, filename, …) containing MathML. Expected to contain the XML prolog
<?xml [...]?>and the MathMLmathelement.- Return type:
- Returns:
The sympy representation of the MathML expression.
- parse_str(mathml)[source]¶
Parse a string containing MathML.
- Parameters:
mathml (
str) – MathML string. Expected to contain the XML prolog<?xml [...]?>and the MathMLmathelement.- Returns:
The sympy representation of the MathML expression.