Skip to content

Commit

Permalink
FIX: Equilibrator update + reqs for building Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
psalvy committed Jun 4, 2020
1 parent b8437c0 commit 2d426b5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
2 changes: 2 additions & 0 deletions docker/requirements.txt
@@ -1,5 +1,7 @@
bokeh>=0.12.1
cobra>0.13
equilibrator-api
equilibrator-cache
ipdb
lxml
networkx
Expand Down
3 changes: 2 additions & 1 deletion pytfa/thermo/equilibrator.py
Expand Up @@ -40,7 +40,8 @@ def build_thermo_from_equilibrator(model, T=TEMPERATURE_0):
ccache = create_compound_cache_from_quilt()
logger.debug("eQuilibrator compound cache is loaded.")

cc = ComponentContribution(temperature=Q_(str(T) + "K"))
cc = ComponentContribution()
cc.temperature=Q_(str(T) + "K")

thermo_data = {"name": "eQuilibrator", "units": "kJ/mol", "cues": {}}
met_to_comps = compat.map_cobra_metabolites(ccache, model.metabolites)
Expand Down
30 changes: 19 additions & 11 deletions tests/test_equilibrator.py
Expand Up @@ -3,48 +3,56 @@
"""Tests for the equilibrator integration."""
import pytest
import sys
from pytfa.io.json import json_dumps_model, json_loads_model


t_model = None


# previous version aren't compatible for the required equlibrator_cache version
# this annotation is not necessary since this file shoud be ignored in the test
# collection phase for previous versions, but it makes it more clear.
@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires >= python3.6")
def test_load_with_equi_thermo():
def test_load_with_equi_thermo(request):
"""Build thermo data structure with equilibrator."""
t_model = request.config.cache.get('model', None)
from pytfa.thermo.equilibrator import build_thermo_from_equilibrator
from pytfa import ThermoModel
from settings import cobra_model

global t_model
cmodel = cobra_model.copy()
for met in cmodel.metabolites:
# normalize but don't overwrite
met.annotation["seed.compound"] = met.annotation["seed_id"]
thermo_data = build_thermo_from_equilibrator(cmodel)
t_model = ThermoModel(thermo_data, cmodel)
t_model.solver = "optlang-glpk"
request.config.cache.set('model', json_dumps_model(t_model))



@pytest.mark.dependency(depends=['test_load_with_equi_thermo'])
@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires >= python3.6")
def test_equilibrator_preparation():
def test_equilibrator_preparation(request):
"""Prepare using equilibrator_api."""
global t_model
t_model = json_loads_model(request.config.cache.get('model',None))
assert t_model is not None
t_model.prepare()
request.config.cache.set('model', json_dumps_model(t_model))


@pytest.mark.dependency(depends=['test_equilibrator_preparation'])
@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires >= python3.6")
def test_equilibrator_conversion():
def test_equilibrator_conversion(request):
"""Convert by the usual method in `ThermoModel`."""
global t_model
t_model = json_loads_model(request.config.cache.get('model',None))
assert t_model is not None
t_model.convert()
request.config.cache.set('model', json_dumps_model(t_model))


@pytest.mark.dependency(depends=['test_equilibrator_conversion'])
@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires >= python3.6")
def test_equilibrator_optim():
def test_equilibrator_optim(request):
"""LP optimization by the usual method in `ThermoModel`."""
global t_model
t_model = json_loads_model(request.config.cache.get('model',None))
assert t_model is not None
solution = t_model.optimize()
return sum(solution.fluxes)

0 comments on commit 2d426b5

Please sign in to comment.