:py:mod:`cobra.core.metabolite` =============================== .. py:module:: cobra.core.metabolite .. autoapi-nested-parse:: Define the Metabolite class. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: cobra.core.metabolite.Metabolite Attributes ~~~~~~~~~~ .. autoapisummary:: cobra.core.metabolite.element_re .. py:data:: element_re .. py:class:: Metabolite(id: Optional[str] = None, formula: Optional[str] = None, name: Optional[str] = '', charge: Optional[float] = None, compartment: Optional[str] = None) Bases: :py:obj:`cobra.core.species.Species` Class for information about metabolite in cobra.Reaction. Metabolite is a class for holding information regarding a metabolite in a cobra.Reaction object. :param id: the identifier to associate with the metabolite :type id: str :param formula: Chemical formula (e.g. H2O) :type formula: str :param name: A human readable name. :type name: str :param charge: The charge number of the metabolite :type charge: float :param compartment: Compartment of the metabolite. :type compartment: str or None .. py:property:: constraint :type: optlang.interface.Container Get the constraints associated with this metabolite from the solver. :returns: the optlang constraint for this metabolite :rtype: optlang..Containter .. py:property:: elements :type: Optional[Dict[str, Union[int, float]]] 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. :rtype: None or Dict .. py:property:: formula_weight :type: Union[int, float] 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. :rtype: float, int .. py:property:: y :type: float 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: Float representing the shadow price. :rtype: float .. py:property:: shadow_price :type: float 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: **shadow_price** :rtype: 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. :raises OptimizationError: If the solver status is anything other than 'optimal'. .. rubric:: Examples >>> from cobra.io import load_model >>> model = load_model("textbook") >>> solution = model.optimize() >>> model.metabolites.glc__D_e.shadow_price -0.09166474637510488 >>> solution.shadow_prices.glc__D_e -0.091664746375104883 .. py:method:: _set_id_with_model(value: str) -> None Set id with value. :param value: :type value: str .. py:method:: remove_from_model(destructive: bool = False) -> None Remove the association from self.model. The change is reverted upon exit when using the model as a context. :param destructive: If False then the metabolite is removed from all associated reactions. If True then all associated reactions are removed from the Model. :type destructive: bool, default False .. py:method:: summary(solution: Optional[cobra.core.Solution] = None, fva: Optional[Union[float, pandas.DataFrame]] = None) -> cobra.summary.MetaboliteSummary Create a summary of the producing and consuming fluxes. :param solution: A previous model solution to use for generating the summary. If ``None``, the summary method will generate a parsimonious flux distribution (default None). :type solution: cobra.Solution, optional :param fva: 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). :type fva: pandas.DataFrame or float, optional :rtype: cobra.summary.MetaboliteSummary .. seealso:: :obj:`Reaction.summary`, :obj:`Model.summary` .. py:method:: _repr_html_() -> str Return the metabolite as an HTML string.