def set_reaction(self, reaction_id, reaction):
<EOL>if reaction_id in self._reactions:<EOL><INDENT>for compound in self._reactions[reaction_id]:<EOL><INDENT>self._compound_reactions[compound].remove(reaction_id)<EOL><DEDENT>self._reversible.discard(reaction_id)<EOL>del self._reactions[reaction_id]<EOL><DEDENT>self._reactions[reaction_id] = OrderedDict()<EOL>for compound, _ in reaction.compounds:<EOL><INDENT>if compound not in self._reactions[reaction_id]:<EOL><INDENT>self._reactions[reaction_id][compound] = <NUM_LIT:0><EOL>self._compound_reactions[compound].add(reaction_id)<EOL><DEDENT><DEDENT>for compound, value in reaction.left:<EOL><INDENT>self._reactions[reaction_id][compound] -= value<EOL><DEDENT>for compound, value in reaction.right:<EOL><INDENT>self._reactions[reaction_id][compound] += value<EOL><DEDENT>zero_compounds = set()<EOL>for compound, value in iteritems(self._reactions[reaction_id]):<EOL><INDENT>if value == <NUM_LIT:0>:<EOL><INDENT>zero_compounds.add(compound)<EOL><DEDENT><DEDENT>for compound in zero_compounds:<EOL><INDENT>del self._reactions[reaction_id][compound]<EOL>self._compound_reactions[compound].remove(reaction_id)<EOL><DEDENT>if reaction.direction != Direction.Forward:<EOL><INDENT>self._reversible.add(reaction_id)<EOL><DEDENT>
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.