def infer_compartment_entries(model):
    """Infer compartment entries for model based on reaction compounds."""
    compartment_ids = set()
    for reaction in model.reactions:
        equation = reaction.equation
        if equation is None:
            continue

        for compound, _ in equation.compounds:
            compartment = compound.compartment
            if compartment is None:
                compartment = model.default_compartment

            if compartment is not None:
                compartment_ids.add(compartment)

    for compartment in compartment_ids:
        if compartment in model.compartments:
            continue

        entry = DictCompartmentEntry(dict(id=compartment))
        model.compartments.add_entry(entry)
def infer_compartment_entries ( model ) : compartment_ids = set ( ) for reaction in model . reactions : equation = reaction . equation if equation is None : continue for compound , _ in equation . compounds : compartment = compound . compartment if compartment is None : compartment = model . default_compartment if compartment is not None : compartment_ids . add ( compartment ) for compartment in compartment_ids : if compartment in model . compartments : continue entry = DictCompartmentEntry ( dict ( id = compartment ) ) model . compartments . add_entry ( entry )
Infer compartment entries for model based on reaction compounds.