def add_metabolites(self, metabolites_to_add, combine=True,<EOL>reversibly=True):
old_coefficients = self.metabolites<EOL>new_metabolites = []<EOL>_id_to_metabolites = dict([(x.id, x) for x in self._metabolites])<EOL>for metabolite, coefficient in iteritems(metabolites_to_add):<EOL><INDENT>if isinstance(metabolite, Metabolite):<EOL><INDENT>if ((metabolite.model is not None) and<EOL>(metabolite.model is not self._model)):<EOL><INDENT>metabolite = metabolite.copy()<EOL><DEDENT><DEDENT>met_id = str(metabolite)<EOL>if met_id in _id_to_metabolites:<EOL><INDENT>reaction_metabolite = _id_to_metabolites[met_id]<EOL>if combine:<EOL><INDENT>self._metabolites[reaction_metabolite] += coefficient<EOL><DEDENT>else:<EOL><INDENT>self._metabolites[reaction_metabolite] = coefficient<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if self._model:<EOL><INDENT>try:<EOL><INDENT>metabolite =self._model.metabolites.get_by_id(met_id)<EOL><DEDENT>except KeyError as e:<EOL><INDENT>if isinstance(metabolite, Metabolite):<EOL><INDENT>new_metabolites.append(metabolite)<EOL><DEDENT>else:<EOL><INDENT>raise e<EOL><DEDENT><DEDENT><DEDENT>elif isinstance(metabolite, string_types):<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% self.id)<EOL><DEDENT>self._metabolites[metabolite] = coefficient<EOL>metabolite._reaction.add(self)<EOL><DEDENT><DEDENT>model = self.model<EOL>if model is not None:<EOL><INDENT>model.add_metabolites(new_metabolites)<EOL>for metabolite, coefficient in self._metabolites.items():<EOL><INDENT>model.constraints[<EOL>metabolite.id].set_linear_coefficients(<EOL>{self.forward_variable: coefficient,<EOL>self.reverse_variable: -coefficient<EOL>})<EOL><DEDENT><DEDENT>for metabolite, the_coefficient in list(self._metabolites.items()):<EOL><INDENT>if the_coefficient == <NUM_LIT:0>:<EOL><INDENT>metabolite._reaction.remove(self)<EOL>self._metabolites.pop(metabolite)<EOL><DEDENT><DEDENT>context = get_context(self)<EOL>if context and reversibly:<EOL><INDENT>if combine:<EOL><INDENT>context(partial(<EOL>self.subtract_metabolites, metabolites_to_add,<EOL>combine=True, reversibly=False))<EOL><DEDENT>else:<EOL><INDENT>mets_to_reset = {<EOL>key: old_coefficients[model.metabolites.get_by_any(key)[<NUM_LIT:0>]]<EOL>for key in iterkeys(metabolites_to_add)}<EOL>context(partial(<EOL>self.add_metabolites, mets_to_reset,<EOL>combine=False, reversibly=False))<EOL><DEDENT><DEDENT>
Add metabolites and stoichiometric coefficients to the reaction.
        If the final coefficient for a metabolite is 0 then it is removed
        from the reaction.

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

        Parameters
        ----------
        metabolites_to_add : dict
            Dictionary with metabolite objects or metabolite identifiers as
            keys and coefficients as values. If keys are strings (name of a
            metabolite) the reaction must already be part of a model and a
            metabolite with the given name must exist in the model.

        combine : bool
            Describes behavior a metabolite already exists in the reaction.
            True causes the coefficients to be added.
            False causes the coefficient to be replaced.

        reversibly : bool
            Whether to add the change to the context to make the change
            reversibly or not (primarily intended for internal use).