# 17.1.1.1.1.6. cobra.core.metabolite¶

Define the Metabolite class.

## 17.1.1.1.1.6.1. Module Contents¶

### 17.1.1.1.1.6.1.1. Classes¶

 Metabolite Class for information about metabolite in cobra.Reaction.
cobra.core.metabolite.element_re[source]
class cobra.core.metabolite.Metabolite(id: Optional[str] = None, formula: Optional[str] = None, name: Optional[str] = '', charge: Optional[float] = None, compartment: Optional[str] = None)[source]

Class for information about metabolite in cobra.Reaction.

Metabolite is a class for holding information regarding a metabolite in a cobra.Reaction object.

Parameters
• id (str) – the identifier to associate with the metabolite

• formula (str) – Chemical formula (e.g. H2O)

• name (str) – A human readable name.

• charge (float) – The charge number of the metabolite

• compartment (str or None) – Compartment of the metabolite.

_set_id_with_model(self, value: str) → None[source]

Set id with value.

Parameters

value (str) –

property constraint(self) → 'Container'[source]

Get the constraints associated with this metabolite from the solver.

Returns

the optlang constraint for this metabolite

Return type

optlang.<interface>.Containter

property elements(self) → Optional[Dict[str, Union[int, float]]][source]

Get dicitonary of elements and counts.

Dictionary of elements as keys and their count in the metabolite as integer. When set, the formula property is updated accordingly.

Returns

composition – A dictionary of elements and counts, where count is int unless it is needed to be a float. Returns None in case of error.

Return type

None or Dict

property formula_weight(self) → Union[int, float][source]

Calculate the formula weight.

Returns

Weight of formula, based on the weight and count of elements. Can be int if the formula weight is a whole number, but unlikely.

Return type
property y(self) → float[source]

Return the shadow price for the metabolite in the most recent solution.

Shadow prices are computed from the dual values of the bounds in the solution. .. deprecated :: Use metabolite.shadow_price instead.

Returns

Return type

float

property shadow_price(self) → float[source]

Return the shadow price for the metabolite in the most recent solution.

Shadow price is the dual value of the corresponding constraint in the model.

Returns

Return type

float

Warning

• Accessing shadow prices through a Solution object is the safer, preferred, and only guaranteed to be correct way. You can see how to do so easily in the examples.

• Shadow price is retrieved from the currently defined self._model.solver. The solver status is checked but there are no guarantees that the current solver state is the one you are looking for.

• If you modify the underlying model after an optimization, you will retrieve the old optimization values.

Raises
• RuntimeError – If the underlying model was never optimized beforehand or the metabolite is not part of a model.

• OptimizationError – If the solver status is anything other than ‘optimal’.

Examples

>>> from cobra.io import load_model
>>> solution = model.optimize()
-0.09166474637510488
-0.091664746375104883

remove_from_model(self, destructive: bool = False) → None[source]

Remove the association from self.model.

The change is reverted upon exit when using the model as a context.

Parameters

destructive (bool, default False) – If False then the metabolite is removed from all associated reactions. If True then all associated reactions are removed from the Model.

summary(self, solution: Optional['Solution'] = None, fva: Optional[Union[float, 'DataFrame']] = None) → 'MetaboliteSummary'[source]

Create a summary of the producing and consuming fluxes.

Parameters
• solution (cobra.Solution, optional) – A previous model solution to use for generating the summary. If None, the summary method will generate a parsimonious flux distribution (default None).

• fva (pandas.DataFrame or float, optional) – Whether or not to include flux variability analysis in the output. If given, fva should either be a previous FVA solution matching the model or a float between 0 and 1 representing the fraction of the optimum objective to be searched (default None).

Returns

Return type

cobra.summary.MetaboliteSummary

Reaction.summary(), Model.summary()
_repr_html_(self) → str[source]