Adding metabolites to a reaction using a dictionary

Skip to first unread message

Kristy Chang

Jun 1, 2022, 9:18:38 PM6/1/22
to cobra pie

I am stuck at this problem:
I have my reaction equation as a dictionary:
reaction= {'glu__L_c': -1.0, 'h2o_c': -1.0, 'nadp_c': -1.0, 'akg_c': 1.0, 'h_c': 1.0, 'nadph_c': 1.0, 'nh4_c': 1.0}
but when I do:
it gives a blank result and the following error:
TypeError: 'dict' object is not callable
or TypeError: Either add the reaction to a model or use Metabolite objects instead of strings as keys

How do I use metabolite objects as keys? (or rather, how do I convert my keys into objects?)

Dennis van den Berg

Jun 7, 2022, 7:05:38 AM6/7/22
to Kristy Chang, cobra pie
Hi Kristy,

To convert your keys to objects you can simple use {model.metabolites.glu__L_c:-1.0, model.metabolites.h2o_c:-1.0, etc, ect.}
Then you refer to the objects in your model, if you called it model at least. If you called it ecoli then use ecoli.metabolites.glu__L_c .
One warning: If your metabolite has a name which is illegal according to python use .get_by_id("string with name"), f.i. objects can not start with a number, so 4abz_c is not a valid name.
Then you do: model.metabolites.get_by_id('4abz_c'):-1.0 and it will work fine.

Good luck with your modeling,


You received this message because you are subscribed to the Google Groups "cobra pie" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages