def add_all_exchange_reactions(model, compartment, allow_duplicates=False):
all_reactions = {}<EOL>if not allow_duplicates:<EOL><INDENT>for rxnid in model.database.reactions:<EOL><INDENT>rx = model.database.get_reaction(rxnid)<EOL>all_reactions[rx] = rxnid<EOL><DEDENT><DEDENT>added = set()<EOL>added_compounds = set()<EOL>initial_compounds = set(model.compounds)<EOL>reactions = set(model.database.reactions)<EOL>for model_compound in initial_compounds:<EOL><INDENT>compound = model_compound.in_compartment(compartment)<EOL>if compound in added_compounds:<EOL><INDENT>continue<EOL><DEDENT>rxnid_ex = create_exchange_id(reactions, compound)<EOL>reaction_ex = Reaction(Direction.Both, {compound: -<NUM_LIT:1>})<EOL>if reaction_ex not in all_reactions:<EOL><INDENT>model.database.set_reaction(rxnid_ex, reaction_ex)<EOL>reactions.add(rxnid_ex)<EOL><DEDENT>else:<EOL><INDENT>rxnid_ex = all_reactions[reaction_ex]<EOL><DEDENT>if not model.has_reaction(rxnid_ex):<EOL><INDENT>added.add(rxnid_ex)<EOL><DEDENT>model.add_reaction(rxnid_ex)<EOL>added_compounds.add(compound)<EOL><DEDENT>return added<EOL>
Add all exchange reactions to database and to model.

    Args:
        model: :class:`psamm.metabolicmodel.MetabolicModel`.