Skip to content

Commit

Permalink
FIX: metabolite thermo data was not recovered upon serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
psalvy committed Jun 4, 2020
1 parent 1e2e1e3 commit b8437c0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pytfa/io/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from ..optim.constraints import ReactionConstraint, MetaboliteConstraint, ModelConstraint
from ..optim.utils import symbol_sum

from ..thermo.metabolite import MetaboliteThermo

from optlang.util import expr_to_json, parse_expr

from copy import copy
Expand Down Expand Up @@ -215,7 +217,7 @@ def model_to_dict(model):

if is_thermo and not is_peptide: # peptides have no thermo
the_met = model.metabolites.get_by_id(the_met_id)
_add_thermo_metabolite_info(the_met, rxn_dict)
_add_thermo_metabolite_info(the_met, met_dict)
met_dict['kind'] = 'Metabolite'

# Relaxation info
Expand Down Expand Up @@ -425,6 +427,9 @@ def init_thermo_model_from_dict(new, obj):

if 'thermo' in met_dict:
new._prepare_metabolite(met)
met.thermo = MetaboliteThermo(metData=None, pH=7,ionicStr=0)
for k,v in met_dict['thermo'].items():
setattr(met.thermo,k,v)
return new

def rebuild_compositions(new, compositions_dict):
Expand Down
24 changes: 24 additions & 0 deletions pytfa/io/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,27 @@ def load_json_model(filepath):

model = model_from_dict(obj)
return model


def json_dumps_model(model):
"""
Returns a JSON dump as a string
:param model:
:return:
"""

obj = model_to_dict(model)

return json.dumps(obj,cls=MyEncoder)


def json_loads_model(s):
"""
Loads a model from a string JSON dump
:param s: JSON string
:return:
"""
obj = json.loads(s)
return model_from_dict(obj)

0 comments on commit b8437c0

Please sign in to comment.