@classmethod<EOL><INDENT>def balance(cls, lhs, rhs):<DEDENT>
def missing(formula, other):<EOL><INDENT>for element, value in iteritems(formula._values):<EOL><INDENT>if element not in other._values:<EOL><INDENT>yield value*element<EOL><DEDENT>else:<EOL><INDENT>delta = value - other._values[element]<EOL>if isinstance(delta, numbers.Number) and delta > <NUM_LIT:0>:<EOL><INDENT>yield delta*element<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return (reduce(operator.or_, missing(rhs, lhs), Formula()),<EOL>reduce(operator.or_, missing(lhs, rhs), Formula()))<EOL>
Return formulas that need to be added to balance given formulas

        Given complete formulas for right side and left side of a reaction,
        calculate formulas for the missing compounds on both sides. Return
        as a left, right tuple. Formulas can be flattened before balancing
        to disregard grouping structure.