Skip to content

Commit

Permalink
DOCS: add script as tutorial for equilibrator integration
Browse files Browse the repository at this point in the history
  • Loading branch information
carrascomj committed Dec 19, 2019
1 parent df654e0 commit 3eb3f06
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions tutorials/tutorial_equilibrator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Tutorial for usage of equilibrator with pyTFA.
Instead of using a local thermodynamic database, pyTFA can use eQuilibrator
(https://gitlab.com/elad.noor/equilibrator-api) to build this structure and use
it to compute the thermodynamics MILP problem.
Requirements
------------
On `setup.cfg`, you can see that equilibrator-api and equilibrator-cache are
extra dependencies of the project. You can check the required versions on this
file or install them directly with pip from the project directory:
.. code:: shell
pip install .[equilibrator]
"""

import os
import pytfa
import pytfa.io

from pytfa.thermo.equilibrator import build_thermo_from_equilibrator


this_directory = os.path.dirname(os.path.realpath(__file__))

# 1. Load the cobra_model
cobra_model = pytfa.io.import_matlab_model(
this_directory + "/../models/small_ecoli.mat"
)
cobra_model.optimizer = "glpk"

# 2. Normalize annotation ids (but don't overwrite them)
for met in cobra_model.metabolites:
met.annotation["seed.compound"] = met.annotation["seed_id"]

# 3. Build the thermodb strucutre and initialize the model
# this process can take some time
thermo_data = build_thermo_from_equilibrator(cobra_model)
tmodel = pytfa.ThermoModel(thermo_data, cobra_model)
tmodel.solver = "optlang-glpk"

# 4. Now, the process follows the same steps as usual
tmodel.prepare()
tmodel.convert()

# 5. Finally, we can optimize the simulation and print some summary
solution = tmodel.optimize()
print("Some fluxes")
print(solution.fluxes.head())
print("\nOnjective solution:", str(solution.objective_value))
print("\nTotal sum of fluxes:", str(solution.fluxes.sum()))

0 comments on commit 3eb3f06

Please sign in to comment.