diff --git a/pytfa/io/dict.py b/pytfa/io/dict.py index 0ca760f..ffd2cb6 100644 --- a/pytfa/io/dict.py +++ b/pytfa/io/dict.py @@ -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 @@ -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 @@ -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): diff --git a/pytfa/io/json.py b/pytfa/io/json.py index 253a640..d863ba6 100644 --- a/pytfa/io/json.py +++ b/pytfa/io/json.py @@ -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) \ No newline at end of file