Skip to content

Commit

Permalink
Fix line to long
Browse files Browse the repository at this point in the history
  • Loading branch information
AlberteSloth committed Nov 26, 2024
1 parent 4b6760e commit f3ecedd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
41 changes: 29 additions & 12 deletions scripts/sbml_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@
reactions_sympy = sbml.sbml_to_sympy(model_sbml)
sym_module = sbml.sympy_to_enzax(reactions_sympy)

parameters_all = [({p.getId(): p.getValue() for p in r.getKineticLaw().getListOfParameters()}) for r in model_sbml.getListOfReactions()]
parameters_all = [
({p.getId(): p.getValue() for p in r.getKineticLaw().getListOfParameters()})
for r in model_sbml.getListOfReactions()
]
parameters = {}
for i in parameters_all:
parameters.update(i)

compartments ={c.getId(): c.volume for c in model_sbml.getListOfCompartments()}
compartments = {c.getId(): c.volume for c in model_sbml.getListOfCompartments()}

species = [s.getId() for s in model_sbml.getListOfSpecies()]

balanced_species_dict = {}
unbalanced_species_dict = {}
for i in model_sbml.getListOfSpecies():
if i.boundary_condition == False:
if not i.boundary_condition:
balanced_species_dict.update({i.getId(): i.getInitialConcentration()})
else:
unbalanced_species_dict.update({i.getId(): i.getInitialConcentration()})
Expand All @@ -33,24 +36,38 @@

para = {**parameters, **compartments, **unbalanced_species_dict}

stoichmatrix = jnp.zeros((model_sbml.getNumSpecies(), model_sbml.getNumReactions()), dtype=jnp.float64)
i = 0
stoichmatrix = jnp.zeros(
(model_sbml.getNumSpecies(), model_sbml.getNumReactions()),
dtype=jnp.float64,
)
i = 0
for reaction in model_sbml.getListOfReactions():
for r in reaction.getListOfReactants():
stoichmatrix = stoichmatrix.at[species.index(r.getSpecies()), i].set(-int(r.getStoichiometry()))
stoichmatrix = stoichmatrix.at[species.index(r.getSpecies()), i].set(
-int(r.getStoichiometry())
)
for p in reaction.getListOfProducts():
stoichmatrix = stoichmatrix.at[species.index(p.getSpecies()), i].set(int(p.getStoichiometry()))
stoichmatrix = stoichmatrix.at[species.index(p.getSpecies()), i].set(
int(p.getStoichiometry())
)
i+=1

structure = KineticModelStructure(stoichmatrix, jnp.array(balanced_ix), jnp.array(unbalanced_ix))
structure = KineticModelStructure(
stoichmatrix, jnp.array(balanced_ix), jnp.array(unbalanced_ix)
)

kinmodel_sbml = KineticModelSbml(parameters=para, balanced_ids=balanced_species_dict, structure=structure, sym_module=sym_module)
kinmodel_sbml = KineticModelSbml(
parameters=para,
balanced_ids=balanced_species_dict,
structure=structure,
sym_module=sym_module
)

y0 = jnp.array([2.,4])
y0 = jnp.array([2.0, 4])
kinmodel_sbml.flux(y0)

kinmodel_sbml.dcdt(t=1, conc=y0)

guess = jnp.full((2),0.01)
guess = jnp.full((2), 0.01)
steady_state = get_kinetic_model_steady_state(kinmodel_sbml, guess)
print(steady_state)
print(steady_state)
8 changes: 6 additions & 2 deletions src/enzax/kinetic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,9 @@ def flux(
self,
conc_balanced: Float[Array, " n_balanced"],
) -> Float[Array, " n"]:
flux = jnp.array(self.sym_module(**self.parameters, **dict(zip(self.balanced_ids, conc_balanced))))
return flux
flux = jnp.array(
self.sym_module(
**self.parameters, **dict(zip(self.balanced_ids, conc_balanced))
)
)
return flux

0 comments on commit f3ecedd

Please sign in to comment.