# 17.1.1.5.1.3. cobra.medium.minimal_medium¶

Provide functions and helpers to obtain minimal growth media.

## 17.1.1.5.1.3.1. Module Contents¶

### 17.1.1.5.1.3.1.1. Functions¶

 add_linear_obj(model: Model) → None Add a linear version of a minimal medium to the model solver. add_mip_obj(model: Model) → None Add a mixed-integer version of a minimal medium to the model. _as_medium(exchanges: Iterable[‘Reaction’], tolerance: float = 1e-06, exports: bool = False) → pd.Series Convert a solution to medium. minimal_medium(model: Model, min_objective_value: float = 0.1, exports: bool = False, minimize_components: Union[bool, int] = False, open_exchanges: bool = False) → Union[pd.Series, pd.DataFrame, None] Find the minimal growth medium for the model.
cobra.medium.minimal_medium.logger[source]
cobra.medium.minimal_medium.add_linear_obj(model: Model) → None[source]

Add a linear version of a minimal medium to the model solver.

Changes the optimization objective to finding the growth medium requiring the smallest total import flux:

..math:: minimize sum_{r_i in import_reactions} |r_i|

Parameters

model (cobra.Model) – The cobra model to modify.

cobra.medium.minimal_medium.add_mip_obj(model: Model) → None[source]

Add a mixed-integer version of a minimal medium to the model.

Changes the optimization objective to finding the medium with the least components:

minimize size(R) where R part of import_reactions

Parameters

model (cobra.model) – The model to modify.

cobra.medium.minimal_medium._as_medium(exchanges: Iterable['Reaction'], tolerance: float = 1e-06, exports: bool = False) → pd.Series[source]

Convert a solution to medium.

Parameters
• exchanges (list of cobra.reaction) – The exchange reactions to consider.

• tolerance (float > 0, optional) – The absolute tolerance for fluxes. Fluxes with an absolute value smaller than this number will be ignored (default 1e-6).

• exports (bool, optional) – Whether to return export fluxes as well (default False).

Returns

The “medium”, meaning all active import fluxes in the solution.

Return type

pandas.Series

cobra.medium.minimal_medium.minimal_medium(model: Model, min_objective_value: float = 0.1, exports: bool = False, minimize_components: Union[bool, int] = False, open_exchanges: bool = False) → Union[pd.Series, pd.DataFrame, None][source]

Find the minimal growth medium for the model.

Finds the minimal growth medium for the model which allows for model as well as individual growth. Here, a minimal medium can either be the medium requiring the smallest total import flux or the medium requiring the least components (ergo ingredients), which will be much slower due to being a mixed integer problem (MIP).

Parameters
• model (cobra.model) – The model to modify.

• min_objective_value (float > 0 or array-like object, optional) – The minimum growth rate (objective) that has to be achieved (default 0.1).

• exports (bool, optional) – Whether to include export fluxes in the returned medium. Defaults to False which will only return import fluxes (default False).

• minimize_components (bool or int > 0, optional) – Whether to minimize the number of components instead of the total import flux. Might be more intuitive if set to True, but may also be slow to calculate for large communities. If set to a number n will return up to n alternative solutions all with the same number of components (default False).

• open_exchanges (bool or number, optional) – Whether to ignore currently set bounds and make all exchange reactions in the model possible. If set to a number, all exchange reactions will be opened with (-number, number) as bounds (default False).

Returns

A pandas.Series giving the import flux for each required import reaction and (optionally) the associated export fluxes. All exchange fluxes are oriented into the import reaction e.g. positive fluxes denote imports and negative fluxes exports. If minimize_components is a number larger than 1, may return a pandas.DataFrame where each column is a minimal medium. Returns None, if the minimization is infeasible (for instance if min_growth > maximum growth rate).

Return type

pandas.Series, pandas.DataFrame or None

Notes

Due to numerical issues, the minimize_components option will usually only minimize the number of “large” import fluxes. Specifically, the detection limit is given by integrality_tolerance * max_bound where max_bound is the largest bound on an import reaction. Thus, if you are interested in small import fluxes as well you may have to adjust the solver tolerance at first with model.tolerance = 1e-7 for instance. However, this will be very slow for large models especially with GLPK.