code: def formula_balance(model):
      
  
      # Mapping from compound id to formula
      compound_formula = {}
      for compound in model.compounds:
          if compound.formula is not None:
              try:
                  f = Formula.parse(compound.formula).flattened()
                  compound_formula[compound.id] = f
              except ParseError as e:
                  msg = 'Error parsing formula for compound {}:\n{}\n{}'.format(
                      compound.id, e, compound.formula)
                  if e.indicator is not None:
                      msg += '\n{}'.format(e.indicator)
                  logger.warning(msg)
  
      for reaction in model.reactions:
          yield reaction, reaction_formula(reaction.equation, compound_formula)
docs: Calculate formula compositions for each reaction.
  
      Call :func:`reaction_formula` for each reaction.
      Yield (reaction, result) pairs, where result has two formula compositions
      or `None`.
  
      Args:
          model: :class:`psamm.datasource.native.NativeModel`.