def convert_exchange_to_compounds(model):
<EOL>exchanges = set()<EOL>for reaction in model.reactions:<EOL><INDENT>equation = reaction.properties.get('<STR_LIT>')<EOL>if equation is None:<EOL><INDENT>continue<EOL><DEDENT>if len(equation.compounds) != <NUM_LIT:1>:<EOL><INDENT>if (len(equation.left) == <NUM_LIT:0>) != (len(equation.right) == <NUM_LIT:0>):<EOL><INDENT>logger.warning('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'.format(reaction.id))<EOL><DEDENT>continue<EOL><DEDENT>exchanges.add(reaction.id)<EOL><DEDENT>for reaction_id in exchanges:<EOL><INDENT>equation = model.reactions[reaction_id].equation<EOL>compound, value = equation.compounds[<NUM_LIT:0>]<EOL>if compound.compartment != model.extracellular_compartment:<EOL><INDENT>continue<EOL><DEDENT>if compound in model.exchange:<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'.format(compound))<EOL>continue<EOL><DEDENT>lower_flux, upper_flux = None, None<EOL>if reaction_id in model.limits:<EOL><INDENT>_, lower, upper = model.limits[reaction_id]<EOL>if lower is not None:<EOL><INDENT>lower_flux = lower * abs(value)<EOL><DEDENT>if upper is not None:<EOL><INDENT>upper_flux = upper * abs(value)<EOL><DEDENT><DEDENT>if lower_flux is None and equation.direction == Direction.Forward:<EOL><INDENT>lower_flux = <NUM_LIT:0><EOL><DEDENT>if upper_flux is None and equation.direction == Direction.Reverse:<EOL><INDENT>upper_flux = <NUM_LIT:0><EOL><DEDENT>if value > <NUM_LIT:0>:<EOL><INDENT>lower_flux, upper_flux = (<EOL>-upper_flux if upper_flux is not None else None,<EOL>-lower_flux if lower_flux is not None else None)<EOL><DEDENT>model.exchange[compound] = (<EOL>compound, reaction_id, lower_flux, upper_flux)<EOL>model.reactions.discard(reaction_id)<EOL>model.limits.pop(reaction_id, None)<EOL><DEDENT>
Convert exchange reactions in model to exchange compounds.

    Only exchange reactions in the extracellular compartment are converted.
    The extracelluar compartment must be defined for the model.

    Args:
        model: :class:`NativeModel`.