Infer compartment adjacency for model based on reactions.

def infer_compartment_adjacency(model):
    """Infer compartment adjacency for model based on reactions."""
    def reaction_compartments(seq):
        for compound, _ in seq:
            compartment = compound.compartment
            if compartment is None:
                compartment = model.default_compartment

            if compartment is not None:
                yield compartment

    for reaction in model.reactions:
        equation = reaction.equation
        if equation is None:
            continue

        left = reaction_compartments(equation.left)
        right = reaction_compartments(equation.right)
        for c1, c2 in product(left, right):
            if c1 == c2:
                continue
            model.compartment_boundaries.add((c1, c2))
            model.compartment_boundaries.add((c2, c1))