From 00b9d03e750cd7b2f25c8ace482df729b87504d6 Mon Sep 17 00:00:00 2001 From: Ben Gyori Date: Sun, 25 Jun 2023 15:17:16 -0400 Subject: [PATCH] Clean formulas when processing askenet --- mira/sources/__init__.py | 5 +++++ mira/sources/askenet/petrinet.py | 4 +++- mira/sources/sbml/processor.py | 5 +---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/mira/sources/__init__.py b/mira/sources/__init__.py index 14a19ad16..96da40785 100644 --- a/mira/sources/__init__.py +++ b/mira/sources/__init__.py @@ -1 +1,6 @@ """Sources of models.""" + + +def clean_formula(f): + """Return an expression that can be parsed using sympy.""" + return f.replace('lambda', 'XXlambdaXX') diff --git a/mira/sources/askenet/petrinet.py b/mira/sources/askenet/petrinet.py index e81d40766..67e812851 100644 --- a/mira/sources/askenet/petrinet.py +++ b/mira/sources/askenet/petrinet.py @@ -15,6 +15,7 @@ import requests from mira.metamodel import * +from .. import clean_formula def model_from_url(url: str) -> TemplateModel: @@ -256,7 +257,8 @@ def transition_to_templates(transition_rate, input_concepts, output_concepts, controller_concepts, symbols): """Return a list of templates from a transition""" rate_law_expression = transition_rate.get('expression') - rate_law = sympy.parse_expr(rate_law_expression, local_dict=symbols) \ + rate_law = sympy.parse_expr(clean_formula(rate_law_expression), + local_dict=symbols) \ if rate_law_expression else None if not controller_concepts: if not input_concepts: diff --git a/mira/sources/sbml/processor.py b/mira/sources/sbml/processor.py index 88e48809e..d37f1d953 100644 --- a/mira/sources/sbml/processor.py +++ b/mira/sources/sbml/processor.py @@ -20,6 +20,7 @@ from mira.metamodel import * from mira.resources import get_resource_file +from .. import clean_formula class TqdmLoggingHandler(logging.Handler): @@ -814,7 +815,3 @@ def parse_context_grounding(grounding_str): grounding_map = _get_grounding_map() - - -def clean_formula(f): - return f.replace('lambda', 'XXlambdaXX')