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

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

## 1.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)


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

[8]:

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

[8]:

 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.

[9]:

from cobra.test import create_test_model

[10]:

model = create_test_model("textbook")

[11]:

model.reactions.ACt2r

[11]:

 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

## 1.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.cplex_interface.Model at 0x7f04260d4b00>


### 1.3.1. Changing solver¶

[13]:

cobra_config.solver = "glpk_exact"

[14]:

new_model = create_test_model("textbook")

[15]:

new_model.solver

[15]:

<optlang.glpk_exact_interface.Model at 0x7f04260d47b8>


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