def add_loopless(model, zero_cutoff=None):
zero_cutoff = normalize_cutoff(model, zero_cutoff)<EOL>internal = [i for i, r in enumerate(model.reactions) if not r.boundary]<EOL>s_int = create_stoichiometric_matrix(model)[:, numpy.array(internal)]<EOL>n_int = nullspace(s_int).T<EOL>max_bound = max(max(abs(b) for b in r.bounds) for r in model.reactions)<EOL>prob = model.problem<EOL>to_add = []<EOL>for i in internal:<EOL><INDENT>rxn = model.reactions[i]<EOL>indicator = prob.Variable("<STR_LIT>" + rxn.id, type="<STR_LIT>")<EOL>on_off_constraint = prob.Constraint(<EOL>rxn.flux_expression - max_bound * indicator,<EOL>lb=-max_bound, ub=<NUM_LIT:0>, name="<STR_LIT>" + rxn.id)<EOL>delta_g = prob.Variable("<STR_LIT>" + rxn.id)<EOL>delta_g_range = prob.Constraint(<EOL>delta_g + (max_bound + <NUM_LIT:1>) * indicator,<EOL>lb=<NUM_LIT:1>, ub=max_bound, name="<STR_LIT>" + rxn.id)<EOL>to_add.extend([indicator, on_off_constraint, delta_g, delta_g_range])<EOL><DEDENT>model.add_cons_vars(to_add)<EOL>for i, row in enumerate(n_int):<EOL><INDENT>name = "<STR_LIT>" + str(i)<EOL>nullspace_constraint = prob.Constraint(Zero, lb=<NUM_LIT:0>, ub=<NUM_LIT:0>, name=name)<EOL>model.add_cons_vars([nullspace_constraint])<EOL>coefs = {model.variables[<EOL>"<STR_LIT>" + model.reactions[ridx].id]: row[i]<EOL>for i, ridx in enumerate(internal) if<EOL>abs(row[i]) > zero_cutoff}<EOL>model.constraints[name].set_linear_coefficients(coefs)<EOL><DEDENT>
Modify a model so all feasible flux distributions are loopless.

    In most cases you probably want to use the much faster `loopless_solution`.
    May be used in cases where you want to add complex constraints and
    objecives (for instance quadratic objectives) to the model afterwards
    or use an approximation of Gibbs free energy directions in you model.
    Adds variables and constraints to a model which will disallow flux
    distributions with loops. The used formulation is described in [1]_.
    This function *will* modify your model.

    Parameters
    ----------
    model : cobra.Model
        The model to which to add the constraints.
    zero_cutoff : positive float, optional
        Cutoff used for null space. Coefficients with an absolute value smaller
        than `zero_cutoff` are considered to be zero (default model.tolerance).

    Returns
    -------
    Nothing

    References
    ----------
    .. [1] Elimination of thermodynamically infeasible loops in steady-state
       metabolic models. Schellenberger J, Lewis NE, Palsson BO. Biophys J.
       2011 Feb 2;100(3):544-53. doi: 10.1016/j.bpj.2010.12.3707. Erratum
       in: Biophys J. 2011 Mar 2;100(5):1381.