def infer_compartment_entries(model):
compartment_ids = set()<EOL>for reaction in model.reactions:<EOL><INDENT>equation = reaction.equation<EOL>if equation is None:<EOL><INDENT>continue<EOL><DEDENT>for compound, _ in equation.compounds:<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>compartment_ids.add(compartment)<EOL><DEDENT><DEDENT><DEDENT>for compartment in compartment_ids:<EOL><INDENT>if compartment in model.compartments:<EOL><INDENT>continue<EOL><DEDENT>entry = DictCompartmentEntry(dict(id=compartment))<EOL>model.compartments.add_entry(entry)<EOL><DEDENT>
Infer compartment entries for model based on reaction compounds.