def constraint_exchange_reactions(model, forsed_r_id2rev, prohibited_r_id2rev=None, cofactors=None, min_flux=0.01):
    logging.info("Constraining input reactions...")

    for r in model.getListOfReactions():
        r_id = r.getId()
        r_l, r_u = get_bounds(r)

        if forsed_r_id2rev and r_id in forsed_r_id2rev:
            rev = forsed_r_id2rev[r_id]
            if rev:
                # reverse the reaction and set positive bounds,
                # as if both bounds are negative, the glp solver produces an error
                reverse_reaction(r)
                set_bounds(r, max(min_flux, -r_u), max(min_flux, -r_l))
                forsed_r_id2rev[r_id] = not rev
            else:
                set_bounds(r, max(min_flux, r_l), max(min_flux, r_u))
            r.setReversible(False)
            continue

        if prohibited_r_id2rev and r_id in prohibited_r_id2rev:
            rev = prohibited_r_id2rev[r_id]
            if not rev:
                reverse_reaction(r)
                set_bounds(r, 0, max(0, -r_l))
                prohibited_r_id2rev[r_id] = not rev
            else:
                set_bounds(r, 0, max(0, r_u))
            r.setReversible(False)
            continue

        if not cofactors:
            continue

        rs, ps = set(get_reactants(r)), set(get_products(r))

        boundary_s_ids = {s_id for s_id in rs if model.getSpecies(s_id).getBoundaryCondition()}
        if boundary_s_ids or not rs:
            if ps - cofactors:
                reverse_reaction(r)
                set_bounds(r, 0, max(-r_l, 0))
                r.setReversible(False)
            continue
        boundary_s_ids = {s_id for s_id in ps if model.getSpecies(s_id).getBoundaryCondition()}
        if boundary_s_ids or not ps:
            if rs - cofactors:
                set_bounds(r, 0, max(r_u, 0))
                r.setReversible(False)
Esempio n. 2
0
 def r_updater(r):
     l_b, u_b = r_id2bounds[format_r_id(r.id)]
     set_bounds(r, l_b, max(u_b, 0))
     if l_b * u_b >= 0:
         r.setReversible(False)