Set the reaction ID to a reaction given by a
        :class:`Reaction <psamm.reaction.Reaction>`

        If an existing reaction exists with the given reaction ID it will be
        overwritten.

def set_reaction(self, reaction_id, reaction):
        """Set the reaction ID to a reaction given by a
        :class:`Reaction <psamm.reaction.Reaction>`

        If an existing reaction exists with the given reaction ID it will be
        overwritten.
        """

        # Overwrite previous reaction if the same id is used
        if reaction_id in self._reactions:
            # Clean up compound to reaction mapping
            for compound in self._reactions[reaction_id]:
                self._compound_reactions[compound].remove(reaction_id)

            self._reversible.discard(reaction_id)
            del self._reactions[reaction_id]

        self._reactions[reaction_id] = OrderedDict()
        # Add values to global (sparse) stoichiometric matrix
        # Compounds that occur on both sides will get a stoichiometric
        # value based on the sum of the signed values on each side.
        for compound, _ in reaction.compounds:
            if compound not in self._reactions[reaction_id]:
                self._reactions[reaction_id][compound] = 0
                self._compound_reactions[compound].add(reaction_id)
        for compound, value in reaction.left:
            self._reactions[reaction_id][compound] -= value
        for compound, value in reaction.right:
            self._reactions[reaction_id][compound] += value

        # Remove reaction from compound reactions if the resulting
        # stoichiometric value turned out to be zero.
        zero_compounds = set()
        for compound, value in iteritems(self._reactions[reaction_id]):
            if value == 0:
                zero_compounds.add(compound)

        for compound in zero_compounds:
            del self._reactions[reaction_id][compound]
            self._compound_reactions[compound].remove(reaction_id)

        if reaction.direction != Direction.Forward:
            self._reversible.add(reaction_id)