With cobra > 0.13.4, we introduce a global configuration object. For now, you can configure default reaction bounds and optimization solver which will be respected by newly created reactions and models.
You can get a configuration object1 in the following way:
import cobra
cobra_config = cobra.Configuration()
1The configuration object is a singleton. That means only one instance can exist and it is respected everywhere in COBRApy.
The object has the following attributes which you can inspect but also change as desired.
cobra_config.lower_bound
-1000.0
cobra_config.upper_bound
1000.0
cobra_config.bounds
(-1000.0, 1000.0)
If you modify the above values before creating a reaction they will be used.
cobra_config.bounds = -10, 20
cobra.Reaction("R1")
Reaction identifier | R1 |
Name | |
Memory address | 0x07f0426135fd0 |
Stoichiometry |
--> --> |
GPR | |
Lower bound | 0.0 |
Upper bound | 20 |
Please note that by default reactions are irreversible. You can change this behavior by unsetting the lower bound argument.
cobra.Reaction("R2", lower_bound=None)
Reaction identifier | R2 |
Name | |
Memory address | 0x07f04260d4438 |
Stoichiometry |
<=> <=> |
GPR | |
Lower bound | -10 |
Upper bound | 20 |
N.B.: Most models define reaction bounds explicitly which takes precedence over the configured values.
from cobra.test import create_test_model
model = create_test_model("textbook")
model.reactions.ACt2r
Reaction identifier | ACt2r |
Name | R acetate reversible transport via proton - symport |
Memory address | 0x07f042607c780 |
Stoichiometry |
ac_e + h_e <=> ac_c + h_c Acetate + H+ <=> Acetate + H+ |
GPR | |
Lower bound | -1000.0 |
Upper bound | 1000.0 |
You can define the default solver used by newly instantiated models. The default solver depends on your environment. In order we test for the availability of Gurobi, CPLEX, and GLPK. GLPK is assumed to always be present in the environment.
model.solver
<optlang.cplex_interface.Model at 0x7f04260d4b00>
cobra_config.solver = "glpk_exact"
new_model = create_test_model("textbook")
new_model.solver
<optlang.glpk_exact_interface.Model at 0x7f04260d47b8>
Changing global configuration values is mostly useful at the beginning of a work session.