def infer_compartment_adjacency(model):
def reaction_compartments(seq):<EOL><INDENT>for compound, _ in seq:<EOL><INDENT>compartment = compound.compartment<EOL>if compartment is None:<EOL><INDENT>compartment = model.default_compartment<EOL><DEDENT>if compartment is not None:<EOL><INDENT>yield compartment<EOL><DEDENT><DEDENT><DEDENT>for reaction in model.reactions:<EOL><INDENT>equation = reaction.equation<EOL>if equation is None:<EOL><INDENT>continue<EOL><DEDENT>left = reaction_compartments(equation.left)<EOL>right = reaction_compartments(equation.right)<EOL>for c1, c2 in product(left, right):<EOL><INDENT>if c1 == c2:<EOL><INDENT>continue<EOL><DEDENT>model.compartment_boundaries.add((c1, c2))<EOL>model.compartment_boundaries.add((c2, c1))<EOL><DEDENT><DEDENT>
Infer compartment adjacency for model based on reactions.