# 2. 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.

## 2.1. The configuration object¶

You can get a configuration object1 in the following way:

[1]:

import cobra

[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.

## 2.2. Reaction bounds¶

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

[3]:

cobra_config.lower_bound

[3]:

-1000.0

[4]:

cobra_config.upper_bound

[4]:

1000.0

[5]:

cobra_config.bounds

[5]:

(-1000.0, 1000.0)


### 2.2.1. Changing bounds¶

If you modify the above values before creating a reaction they will be used.

[6]:

cobra_config.bounds = -10, 20

[7]:

cobra.Reaction("R1")

[7]:

 Reaction identifier R1 Name Memory address 0x7f8642e5bba8 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.

[8]:

cobra.Reaction("R2", lower_bound=None)

[8]:

 Reaction identifier R2 Name Memory address 0x7f8642e5bda0 Stoichiometry <=> <=> GPR Lower bound -10 Upper bound 20

N.B.: Most models define reaction bounds explicitly which takes precedence over the configured values.

[9]:

from cobra.io import load_model

[10]:

model = load_model("textbook")

Scaling...
A: min|aij| =  1.000e+00  max|aij| =  1.000e+00  ratio =  1.000e+00
Problem data seem to be well scaled

[11]:

model.reactions.ACt2r

[11]:

 Reaction identifier ACt2r Name R acetate reversible transport via proton - symport Memory address 0x7f8642f174e0 Stoichiometry ac_e + h_e <=> ac_c + h_c Acetate + H+ <=> Acetate + H+ GPR Lower bound -1000.0 Upper bound 1000.0

## 2.3. 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.

[12]:

model.solver

[12]:

<optlang.glpk_interface.Model at 0x7f8642e740f0>


### 2.3.1. Changing solver¶

[13]:

cobra_config.solver = "glpk_exact"

[14]:

new_model = load_model("textbook")

[15]:

new_model.solver

[15]:

<optlang.glpk_exact_interface.Model at 0x7f8643112a90>


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