def add_all_transport_reactions(model, boundaries, 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>boundary_pairs = set()<EOL>for source, dest in boundaries:<EOL><INDENT>if source != dest:<EOL><INDENT>boundary_pairs.add(tuple(sorted((source, dest))))<EOL><DEDENT><DEDENT>added = set()<EOL>added_pairs = set()<EOL>initial_compounds = set(model.compounds)<EOL>reactions = set(model.database.reactions)<EOL>for compound in initial_compounds:<EOL><INDENT>for c1, c2 in boundary_pairs:<EOL><INDENT>compound1 = compound.in_compartment(c1)<EOL>compound2 = compound.in_compartment(c2)<EOL>pair = compound1, compound2<EOL>if pair in added_pairs:<EOL><INDENT>continue<EOL><DEDENT>rxnid_tp = create_transport_id(reactions, compound1, compound2)<EOL>reaction_tp = Reaction(Direction.Both, {<EOL>compound1: -<NUM_LIT:1>,<EOL>compound2: <NUM_LIT:1><EOL>})<EOL>if reaction_tp not in all_reactions:<EOL><INDENT>model.database.set_reaction(rxnid_tp, reaction_tp)<EOL>reactions.add(rxnid_tp)<EOL><DEDENT>else:<EOL><INDENT>rxnid_tp = all_reactions[reaction_tp]<EOL><DEDENT>if not model.has_reaction(rxnid_tp):<EOL><INDENT>added.add(rxnid_tp)<EOL><DEDENT>model.add_reaction(rxnid_tp)<EOL>added_pairs.add(pair)<EOL><DEDENT><DEDENT>return added<EOL>
Add all transport reactions to database and to model.

    Add transport reactions for all boundaries. Boundaries are defined
    by pairs (2-tuples) of compartment IDs. Transport reactions are
    added for all compounds in the model, not just for compounds in the
    two boundary compartments.

    Args:
        model: :class:`psamm.metabolicmodel.MetabolicModel`.
        boundaries: Set of compartment boundary pairs.

    Returns:
        Set of IDs of reactions that were added.