def formula_balance(model):
<EOL>compound_formula = {}<EOL>for compound in model.compounds:<EOL><INDENT>if compound.formula is not None:<EOL><INDENT>try:<EOL><INDENT>f = Formula.parse(compound.formula).flattened()<EOL>compound_formula[compound.id] = f<EOL><DEDENT>except ParseError as e:<EOL><INDENT>msg = '<STR_LIT>'.format(<EOL>compound.id, e, compound.formula)<EOL>if e.indicator is not None:<EOL><INDENT>msg += '<STR_LIT>'.format(e.indicator)<EOL><DEDENT>logger.warning(msg)<EOL><DEDENT><DEDENT><DEDENT>for reaction in model.reactions:<EOL><INDENT>yield reaction, reaction_formula(reaction.equation, compound_formula)<EOL><DEDENT>
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`.