def _reaction_to_dicts(reaction):
def dict_from_iter_sum(it, div):<EOL><INDENT>d = {}<EOL>for k, v in it:<EOL><INDENT>if k not in d:<EOL><INDENT>d[k] = <NUM_LIT:0><EOL><DEDENT>d[k] += int(v / div)<EOL><DEDENT>return d<EOL><DEDENT>div = reduce(gcd, (abs(v) for _, v in reaction.compounds), <NUM_LIT:0>)<EOL>if div == <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>left = dict_from_iter_sum(reaction.left, div)<EOL>right = dict_from_iter_sum(reaction.right, div)<EOL>return left, right<EOL>
Convert a reaction to reduced left, right dictionaries.

    Returns a pair of (left, right) dictionaries mapping compounds to
    normalized integer stoichiometric values. If a compound occurs multiple
    times on one side, the occurences are combined into a single entry in the
    dictionary.