From dc19c4aeb06ad4b1eb17eefd129c07ed1e09e413 Mon Sep 17 00:00:00 2001 From: Mayalen Etcheverry Date: Mon, 26 Feb 2024 16:16:18 +0000 Subject: [PATCH] fix to enable to vary or keep constant the reactant species specified as boundary species in the original SBML file --- sbmltoodejax/modulegeneration.py | 6 ++++-- sbmltoodejax/utils.py | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/sbmltoodejax/modulegeneration.py b/sbmltoodejax/modulegeneration.py index 83eeb17..db01eea 100644 --- a/sbmltoodejax/modulegeneration.py +++ b/sbmltoodejax/modulegeneration.py @@ -9,6 +9,7 @@ def GenerateModel(modelData, outputFilePath, ModelStepName: str='ModelStep', ModelRolloutName: str='ModelRollout', vary_constant_reactants: bool=False, + vary_boundary_reactants: bool=False, deltaT: float =0.1, atol: float=1e-6, rtol: float = 1e-12, @@ -398,8 +399,9 @@ def ParseRHS(rawRateLaw, extended_param_names=[], reaction_name=None, yvar="y", reactionCounter += 1 reaction = reactions[rxnId] for reactant in reaction.reactants: - if (reactant[1] in y_indexes) and (not species[reactant[1]].isBoundarySpecies): - stoichCoeffMat = stoichCoeffMat.at[y_indexes[reactant[1]], reactionIndex[rxnId]].add(reactant[0]) + if (reactant[1] in y_indexes): + if (not species[reactant[1]].isBoundarySpecies) or vary_boundary_reactants: + stoichCoeffMat = stoichCoeffMat.at[y_indexes[reactant[1]], reactionIndex[rxnId]].add(reactant[0]) rateArray = ['0.0'] * len(y_indexes) for rule_name, rule in rateRules.items(): diff --git a/sbmltoodejax/utils.py b/sbmltoodejax/utils.py index 3a7dc79..b523544 100644 --- a/sbmltoodejax/utils.py +++ b/sbmltoodejax/utils.py @@ -3,7 +3,9 @@ from sbmltoodejax.modulegeneration import GenerateModel from sbmltoodejax.parse import ParseSBMLFile -def generate_biomodel(model_idx, model_fp="jax_model.py", deltaT=0.1, atol=1e-6, rtol=1e-12, mxstep=5000000): +def generate_biomodel(model_idx, model_fp="jax_model.py", + vary_constant_reactants=False, vary_boundary_reactants=False, + deltaT=0.1, atol=1e-6, rtol=1e-12, mxstep=5000000): """Calls the `sbmltoodejax.modulegeneration.GenerateModel` for a SBML model hosted on the BioModel website and indexed by the provided `model_idx`. Args: @@ -19,7 +21,9 @@ def generate_biomodel(model_idx, model_fp="jax_model.py", deltaT=0.1, atol=1e-6, """ model_xml_body = get_content_for_model(model_idx) model_data = ParseSBMLFile(model_xml_body) - GenerateModel(model_data, model_fp, deltaT=deltaT, atol=atol, rtol=rtol, mxstep=mxstep) + GenerateModel(model_data, model_fp, + vary_constant_reactants=vary_constant_reactants, vary_boundary_reactants=vary_boundary_reactants, + deltaT=deltaT, atol=atol, rtol=rtol, mxstep=mxstep) return model_fp