:py:mod:`cobra.core.solution` ============================= .. py:module:: cobra.core.solution .. autoapi-nested-parse:: Provide unified interfaces to optimization solutions. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: cobra.core.solution.Solution Functions ~~~~~~~~~ .. autoapisummary:: cobra.core.solution.get_solution .. py:class:: Solution(objective_value: float, status: str, fluxes: pandas.Series, reduced_costs: Optional[pandas.Series] = None, shadow_prices: Optional[pandas.Series] = None, **kwargs) A unified interface to a `cobra.Model` optimization solution. :param objective_value: The (optimal) value for the objective function. :type objective_value: float :param status: The solver status related to the solution. :type status: str :param fluxes: Contains the reaction fluxes (primal values of variables). :type fluxes: pandas.Series :param reduced_costs: Contains reaction reduced costs (dual values of variables) (default None). :type reduced_costs: pandas.Series :param shadow_prices: Contains metabolite shadow prices (dual values of constraints) (default None). :type shadow_prices: pandas.Series .. attribute:: objective_value The (optimal) value for the objective function. :type: float .. attribute:: status The solver status related to the solution. :type: str .. attribute:: fluxes Contains the reaction fluxes (primal values of variables). :type: pandas.Series .. attribute:: reduced_costs Contains reaction reduced costs (dual values of variables). :type: pandas.Series .. attribute:: shadow_prices Contains metabolite shadow prices (dual values of constraints). :type: pandas.Series .. rubric:: Notes Solution is meant to be constructed by `get_solution` please look at that function to fully understand the `Solution` class. .. py:attribute:: get_primal_by_id .. py:method:: __repr__() -> str Return a string representation of the solution instance. .. py:method:: _repr_html_() -> str Return a rich HTML representation of the solution. .. py:method:: __getitem__(reaction_id: str) -> float Return the flux of a reaction. :param reaction_id: A model reaction ID. :type reaction_id: str :returns: The flux of the reaction with ID `reaction_id`. :rtype: float .. py:method:: to_frame() -> pandas.DataFrame Return the fluxes and reduced costs as a pandas DataFrame. :returns: The fluxes and reduced cost. :rtype: pandas.DataFrame .. py:function:: get_solution(model: cobra.Model, reactions: Optional[Iterable[cobra.Reaction]] = None, metabolites: Optional[Iterable[cobra.Metabolite]] = None, raise_error: bool = False) -> Solution Generate a solution representation of the current solver state. :param model: The model whose reactions to retrieve values for. :type model: cobra.Model :param reactions: An iterable of `cobra.Reaction` objects. Uses `model.reactions` if None (default None). :type reactions: list, optional :param metabolites: An iterable of `cobra.Metabolite` objects. Uses `model.metabolites` if None (default None). :type metabolites: list, optional :param raise_error: If True, raise an OptimizationError if solver status is not optimal (default False). :type raise_error: bool :rtype: cobra.Solution