Global Configuration

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.

The configuration object

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.

Reaction bounds

The object has the following attributes which you can inspect but also change as desired.


In [3]:
cobra_config.lower_bound


Out[3]:
-1000.0

In [4]:
cobra_config.upper_bound


Out[4]:
1000.0

In [5]:
cobra_config.bounds


Out[5]:
(-1000.0, 1000.0)

Changing bounds

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]:
Reaction identifierR1
Name
Memory address 0x07f0426135fd0
Stoichiometry

-->

-->

GPR
Lower bound0.0
Upper bound20

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]:
Reaction identifierR2
Name
Memory address 0x07f04260d4438
Stoichiometry

<=>

<=>

GPR
Lower bound-10
Upper bound20

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]:
Reaction identifierACt2r
NameR 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 bound1000.0

Solver

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]:
<optlang.cplex_interface.Model at 0x7f04260d4b00>

Changing solver


In [13]:
cobra_config.solver = "glpk_exact"

In [14]:
new_model = create_test_model("textbook")

In [15]:
new_model.solver


Out[15]:
<optlang.glpk_exact_interface.Model at 0x7f04260d47b8>

Changing global configuration values is mostly useful at the beginning of a work session.