code: def check_mass_balance(self):
          
          reaction_element_dict = defaultdict(int)
          for metabolite, coefficient in iteritems(self._metabolites):
              if metabolite.charge is not None:
                  reaction_element_dict["charge"] += \
                      coefficient * metabolite.charge
              if metabolite.elements is None:
                  raise ValueError("No elements found in metabolite %s"
                                   % metabolite.id)
              for element, amount in iteritems(metabolite.elements):
                  reaction_element_dict[element] += coefficient * amount
          # filter out 0 values
          return {k: v for k, v in iteritems(reaction_element_dict) if v != 0}
docs: Compute mass and charge balance for the reaction
  
          returns a dict of {element: amount} for unbalanced elements.
          "charge" is treated as an element in this dict
          This should be empty for balanced reactions.