|
11 | 11 | import sympy as sp |
12 | 12 |
|
13 | 13 | if TYPE_CHECKING: |
14 | | - from typing import Any |
15 | | - |
16 | 14 | SbmlID = str | sp.Symbol |
17 | 15 |
|
18 | 16 | import xml.dom.minidom |
|
23 | 21 |
|
24 | 22 | from .import_utils import ( |
25 | 23 | SBMLException, |
26 | | - _check_unsupported_functions, |
27 | | - _parse_special_functions, |
28 | 24 | amici_time_symbol, |
29 | 25 | sbml_time_symbol, |
30 | 26 | ) |
@@ -399,6 +395,7 @@ def pretty_xml(ugly_xml: str) -> str: |
399 | 395 | return pretty_xml[pretty_xml.index("\n") + 1 :] |
400 | 396 |
|
401 | 397 |
|
| 398 | +# TODO: replace by sbmlmath.SBMLMathMLPrinter |
402 | 399 | class MathMLSbmlPrinter(MathMLContentPrinter): |
403 | 400 | """Prints a SymPy expression to a MathML expression parsable by libSBML. |
404 | 401 |
|
@@ -485,57 +482,3 @@ def set_sbml_math(obj: libsbml.SBase, expr, **kwargs) -> None: |
485 | 482 | f"expression:\n{expr}\n" |
486 | 483 | f"MathML:\n{pretty_xml(mathml)}" |
487 | 484 | ) |
488 | | - |
489 | | - |
490 | | -# TODO: replace by `sbmlmath` functions |
491 | | -def mathml2sympy( |
492 | | - mathml: str, |
493 | | - *, |
494 | | - evaluate: bool = False, |
495 | | - locals: dict[str, Any] | None = None, |
496 | | - expression_type: str = "mathml2sympy", |
497 | | -) -> sp.Basic: |
498 | | - ast = libsbml.readMathMLFromString(mathml) |
499 | | - if ast is None: |
500 | | - raise ValueError( |
501 | | - f"libSBML could not parse MathML string:\n{pretty_xml(mathml)}" |
502 | | - ) |
503 | | - |
504 | | - formula = _parse_logical_operators(libsbml.formulaToL3String(ast)) |
505 | | - |
506 | | - if evaluate: |
507 | | - expr = sp.sympify(formula, locals=locals) |
508 | | - else: |
509 | | - with sp.core.parameters.evaluate(False): |
510 | | - expr = sp.sympify(formula, locals=locals) |
511 | | - |
512 | | - expr = _parse_special_functions(expr) |
513 | | - |
514 | | - if expression_type is not None: |
515 | | - _check_unsupported_functions(expr, expression_type) |
516 | | - |
517 | | - return expr |
518 | | - |
519 | | - |
520 | | -# TODO: remove after getting rid of `mathml2sympy` |
521 | | -def _parse_logical_operators( |
522 | | - math_str: str | float | None, |
523 | | -) -> str | float | None: |
524 | | - """ |
525 | | - Parses a math string in order to replace logical operators by a form |
526 | | - parsable for sympy |
527 | | -
|
528 | | - :param math_str: |
529 | | - str with mathematical expression |
530 | | - :param math_str: |
531 | | - parsed math_str |
532 | | - """ |
533 | | - if not isinstance(math_str, str): |
534 | | - return math_str |
535 | | - |
536 | | - if " xor(" in math_str or " Xor(" in math_str: |
537 | | - raise SBMLException( |
538 | | - "Xor is currently not supported as logical operation." |
539 | | - ) |
540 | | - |
541 | | - return (math_str.replace("&&", "&")).replace("||", "|") |
0 commit comments