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 object[1](#f1) in the following way:
In [1]:
import cobra
In [2]:
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.
In [3]:
cobra_config.lower_bound
Out[3]:
In [4]:
cobra_config.upper_bound
Out[4]:
In [5]:
cobra_config.bounds
Out[5]:
If you modify the above values before creating a reaction they will be used.
In [6]:
cobra_config.bounds = -10, 20
In [7]:
cobra.Reaction("R1")
Out[7]:
Please note that by default reactions are irreversible. You can change this behavior by unsetting the lower bound argument.
In [8]:
cobra.Reaction("R2", lower_bound=None)
Out[8]:
N.B.: Most models define reaction bounds explicitly which takes precedence over the configured values.
In [9]:
from cobra.test import create_test_model
In [10]:
model = create_test_model("textbook")
In [11]:
model.reactions.ACt2r
Out[11]:
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.
In [12]:
model.solver
Out[12]:
In [13]:
cobra_config.solver = "glpk_exact"
In [14]:
new_model = create_test_model("textbook")
In [15]:
new_model.solver
Out[15]:
Changing global configuration values is mostly useful at the beginning of a work session.