コード例 #1
0
    def test_acr(self):
        crn = from_react_file(path.join(input_reactions, "acr/acr_1"))
        self.assertEqual(['yp'], crn.acr_species())

        crn = from_react_file(path.join(input_reactions, "acr/acr_toy"))
        self.assertEqual(['a'], crn.acr_species())

        crn = from_react_file(path.join(input_reactions, "acr/acr_complex"))
        self.assertEqual([parse_expr('A*B')], crn.acr_complexes())
        self.assertEqual(['C'], crn.acr_species(subnets = True))

        crn = from_react_file(path.join(input_reactions, "acr/neigenfind_ex1"))
        self.assertEqual(['C'], crn.acr_species(subnets = True))

        crn = from_react_file(path.join(input_reactions, "acr/neigenfind_ex2"))
        self.assertEqual(['C', 'U'], crn.acr_species(subnets = True))

        crn = from_react_strings(["A + B -> A + C", "A + B -> A + D", "C -> A", "D -> A", "A -> B"])
        self.assertEqual([], crn.acr_species())
        self.assertEqual([], crn.acr_species(subnets = True))
        self.assertEqual([], crn.acr_complexes())
        self.assertEqual([], crn.acr_complexes(subnets = True))
        self.assertEqual([], crn.acr_species(subnets = True, same_ems = True))
        self.assertTrue(sp.sympify("A*B/D") in crn.acr_complexes(subnets = True, same_ems = True))
        self.assertTrue([1, 1, -1, 0] in crn.acr_same_ems(as_vectors = True) or
                        [-1, -1, 1, 0] in crn.acr_same_ems(as_vectors = True))

        crn = from_react_strings(["A -> 2B", "B -> C", "2C -> A", "B + C -> A"])
        self.assertEqual([], crn.acr_complexes(subnets = True, same_ems = True))
コード例 #2
0
def atp_substrate_inhibitor():
    """ATP acts as substrate and inhibitor."""
    print("ATP example.")
    crn = from_react_file(
        os.path.join(input_reactions, "atp_substrate_inhibitor"))

    # Removing eatpi and eatp using conservation law
    crn.remove(qss=['eatpi', 'eatp'],
               cons_law=('e', ConsLaw('e + eatp + eatpi', 'et')))
    indatp = crn.complexes.index(parse_complex('atp'))
    fail_if_not_equal(
        sp.factor(crn.laplacian[indatp, indatp] - parse_expr(
            "(k2 * et)/((k_1 + k2) / k1 + atp + atp**2 / (k_3 / k3))")), 0)

    # Saving and reading
    crn.save_reaction_file(
        os.path.join(input_reactions, "atp_substrate_inhibitor_simplified"))
    crn = from_react_file(
        os.path.join(input_reactions, "atp_substrate_inhibitor_simplified"))

    # Removing eatpi and eatp without using conservation law
    crn = from_react_file(
        os.path.join(input_reactions, "atp_substrate_inhibitor"))
    crn.qss('eatpi')
    crn.qss('eatp')
    fail_if_not_equal(
        sp.factor(crn.laplacian[0, 0] - parse_expr("(k2 * k1)/(k_1 + k2)")), 0)
コード例 #3
0
def two_subs_two_prods_compulsory():
    """Irreversible and reversible two substrates, two products compulsory order mechanism."""
    print("Two substrates, two products compulsory mechanism.")
    # Full version, without using conservation law
    crn = from_react_file(
        os.path.join(input_reactions, "two_subs_two_prods_compul"))
    crn.qss('eab')
    crn.qss('ea')
    crn.remove_all_constants()

    # Full version
    crn = from_react_file(
        os.path.join(input_reactions, "two_subs_two_prods_compul"))
    crn.qss(cons_law=('e', ConsLaw('e + ea + eab', 'et')))
    rate = parse_expr(
        "k3*et*a*b/(k_1*(k_2+k3)/(k1*k2)+(k_2+k3)/k2*a+k3/k1*b+a*b)")
    fail_if_not_equal((crn.rates[0] - rate).factor(), 0)

    # Cornish-Bowden version, 6.3
    crn = from_react_file(
        os.path.join(input_reactions, "two_subs_two_prods_compul_ternary"))
    crn.qss(cons_law=('e', ConsLaw('e + ea + eq + eab', 'et')))

    constants = dict(Vf=parse_expr("k3*k4*et/(k3+k4)"),
                     Vr=parse_expr("k_1*k_2*et/(k_1+k_2)"),
                     kia=parse_expr("k_1/k1"),
                     kib=parse_expr("(k_1+k_2)/k2"),
                     kip=parse_expr("(k3+k4)/k_3"),
                     kiq=parse_expr("k4/k_4"),
                     Kma=parse_expr("k3*k4/k1/(k3+k4)"),
                     Kmb=parse_expr("(k_2+k3)*k4/k2/(k3+k4)"),
                     Kmp=parse_expr("k_1*(k_2+k3)/(k_1+k_2)/k_3"),
                     Kmq=parse_expr("k_1*k_2/(k_1+k_2)/k_4"))

    rateab = parse_expr(
        "Vf/(kia*Kmb)/(1+a/kia+b*Kma/(kia*Kmb)+p*Kmq/(kiq*Kmp)+q/kiq+a*b/(kia*Kmb)+Kmq*a*p/(kia*Kmp*kiq)+\
                                       Kma*b*q/(kia*Kmb*kiq)+p*q/(Kmp*kiq)+a*b*p/(kia*Kmb*kip)+b*p*q/(kib*Kmp*kiq))"
    ).subs(constants)
    ratepq = parse_expr(
        "Vr/(kiq*Kmp)/(1+a/kia+b*Kma/(kia*Kmb)+p*Kmq/(kiq*Kmp)+q/kiq+a*b/(kia*Kmb)+Kmq*a*p/(kia*Kmp*kiq)+\
                                       Kma*b*q/(kia*Kmb*kiq)+p*q/(Kmp*kiq)+a*b*p/(kia*Kmb*kip)+b*p*q/(kib*Kmp*kiq))"
    ).subs(constants)

    rateab = rateab.factor()
    ratepq = ratepq.factor()
    indab = crn.complexes.index(parse_complex('a + b'))
    indpq = crn.complexes.index(parse_complex('p + q'))
    diffab = crn.laplacian[indab, indab] - rateab
    diffab = diffab.factor()
    diffpq = crn.laplacian[indpq, indpq] - ratepq
    diffpq = diffpq.factor()
    fail_if_not_equal(diffab, 0)
    fail_if_not_equal(diffpq, 0)
コード例 #4
0
 def test_im(self):
     crn = from_react_file(path.join(input_reactions, "dsr-graph/pos_loops_main"))
     g_1_1, g_2_2, g_2_3, g_3_3, g_3_4 = sp.symbols('g_1_1 g_2_2 g_2_3 g_3_3 g_3_4')
     I = sp.Matrix([[g_1_1, 0, 0, 0], [0, g_2_2, g_2_3, 0], [0, 0, g_3_3, g_3_4]])
     self.assertEqual(I, crn.influence_matrix(state = {'x1': 2}))
     crn.dsr_graph_adj()
     crn = from_react_file(path.join(input_reactions, "dsr-graph/pos_loops_main_v2"))
     I = sp.Matrix([[g_1_1, 0, 0, 0], [0, g_2_2, g_2_3, 0], [0, 0, 0, g_3_4]])
     self.assertEqual(I, crn.influence_matrix(check = True))
     crn.dsr_graph_adj()
     a1_1, a2_2, a2_3, a3_3, a3_4 = sp.symbols('a1_1 a2_2 a2_3 a3_3 a3_4')
     I = sp.Matrix([[a1_1, 0, 0, 0], [0, a2_2, a2_3, 0], [0, 0, 0, a3_4]])
     self.assertEqual(I, crn.influence_matrix(var = "a", check = True, params = {'K': 7, 'k1': 3}))
     crn = from_react_strings(["x ->(k/(2-x))"])
     self.assertRaises(ValueError, crn.influence_matrix, check = True, state = {sp.Symbol('x'): 2})
コード例 #5
0
def two_subs_one_prod_random_irr():
    """Irreversible two substrates, one product random order mechanism.
    (random order bi-uni mechanism, http://www.ebi.ac.uk/sbo/main/SBO:0000432)."""
    print("Two substrates, one product random irreversible mechanism.")

    crn = from_react_file(
        os.path.join(input_reactions, "two_subs_one_prod_rand_irr"))

    crn.remove(rapid_eq = [('ea', 'e+a'), ('eb', 'e+b')], \
               qss = ['eab'], \
               cons_law = ('e', ConsLaw('e + ea + eb + eab', 'et')))

    constants = dict(
        Vf=parse_expr("et*k5"),
        Vr=parse_expr("et*(k_3+k_4)"),
        kia=parse_expr("k_1/k1"),
        kib=parse_expr("k_2/k2"),
        Kmb=parse_expr("k1*k_2*(k5 + k_3 + k_4)/(k1*k3*k_2 + k2*k4*k_1)"),
        Kmp=parse_expr("(k5 + k_3 + k_4)/k_5"))
    rateab = parse_expr("Vf/(kia*Kmb)/(1+a/kia+b/kib+a*b/(kia*Kmb))").subs(
        constants)

    indab = crn.complexes.index(parse_complex('a + b'))
    diff = crn.laplacian[indab, indab] - rateab
    diff = diff.factor()
    fail_if_not_equal(diff, 0)
コード例 #6
0
def two_subs_one_prod_random_rev():
    """Reversible two substrates, one product random order mechanism."""
    print("Two substrates, one product random reversible mechanism.")

    crn = from_react_file(
        os.path.join(input_reactions, "two_subs_one_prod_rand_rev"))
    crn.remove(rapid_eq = [('ea', 'e+a'), ('eb', 'e+b')], \
                         qss = ['eab'], \
                         cons_law = ('e', ConsLaw('e + ea + eb + eab', 'et')))

    constants = dict(
        Vf=parse_expr("et*k5"),
        Vr=parse_expr("et*(k_3+k_4)"),
        kia=parse_expr("k_1/k1"),
        kib=parse_expr("k_2/k2"),
        Kmb=parse_expr("k1*k_2*(k5 + k_3 + k_4)/(k1*k3*k_2 + k2*k4*k_1)"),
        Kmp=parse_expr("(k5 + k_3 + k_4)/k_5"))

    rateab = parse_expr(
        "Vf/(kia*Kmb)/(1+a/kia+b/kib+a*b/(kia*Kmb)+p/Kmp)").subs(constants)
    ratep = parse_expr("Vr/Kmp/(1+a/kia+b/kib+a*b/(kia*Kmb)+p/Kmp)").subs(
        constants)

    rateab = rateab.expand().factor().factor()
    ratep = ratep.expand().factor().factor()
    indab = crn.complexes.index(parse_complex('a + b'))
    indp = crn.complexes.index(parse_complex('p'))
    diffab = crn.laplacian[indab, indab] - rateab
    diffab = diffab.factor()
    diffp = crn.laplacian[indp, indp] - ratep
    diffp = diffp.factor()
    fail_if_not_equal(diffab, 0)
    fail_if_not_equal(diffp, 0)
コード例 #7
0
 def test_qss1(self):
     """QSS test 1 (Ingalls, section 2.2.1)."""
     crn = from_react_file(path.join(input_reactions, "basic1"))
     crn.qss('b')
     inda = crn.complexes.index(parse_complex('a'))
     self.assertEqual((crn.laplacian[inda, inda] -
                       parse_expr("k1*k2/(k2 + k_1)")).simplify(), 0)
コード例 #8
0
 def test_qss3(self):
     """QSS test 3 (Ingalls, section 2.2.1)."""
     crn = from_react_file(path.join(input_reactions, "basic3"))
     crn.qss('a')
     indb = crn.complexes.index(parse_complex('b'))
     self.assertEqual((crn.laplacian[indb, indb] -
                       parse_expr("(k0*k_1/(k0 + k1)+k2)")).simplify(), 0)
コード例 #9
0
 def test_rapid_eq3(self):
     """Rapid equilibrium with pooling test 3 (Ingalls, exercise 2.2.1)."""
     crn = from_react_file(path.join(input_reactions, "basic3"))
     crn.rapid_eq_with_pool('b', 'a', pool_name="c")
     self.assertEqual(
         sp.simplify(crn.laplacian[0, 0] -
                     parse_expr("(k0 * k_1 + k2 * k1)/(k_1 + k1)")), 0)
コード例 #10
0
def two_subs_one_prod_compulsory_rev():
    """Reversible two substrate, one product compulsory order mechanism.
    Rates compared to http://www.cogsys.cs.uni-tuebingen.de/software/SBMLsqueezer/doc/KineticLaws2.pdf."""
    print("Two substrates, one product compulsory reversible mechanism.")
    crn = from_react_file(
        os.path.join(input_reactions, "two_subs_one_prod_compul_rev"))
    crn.qss(cons_law=('e', ConsLaw('e + ea + eab', 'et')))

    constants = dict(kpluscat=parse_expr("k3"),
                     kminuscat=parse_expr("k_1*k_2/(k_1+k_2)"),
                     kia=parse_expr("k_1/k1"),
                     kip=parse_expr("k3/k_3"),
                     Kma=parse_expr("k3/k1"),
                     Kmb=parse_expr("(k_2+k3)/k2"),
                     Kmp=parse_expr("k_1*(k_2+k3)/(k_3*(k_1+k_2))"))

    rateab = parse_expr(
        "kpluscat*et/(kia*Kmb)/(1+a/kia+Kma*b/(kia*Kmb)+a*b/(Kmb*kia)+Kma*b*p/(kia*Kmb*kip)+p/Kmp)"
    ).subs(constants)
    indab = crn.complexes.index(parse_complex('a + b'))
    diffab = (rateab - crn.laplacian[indab, indab]).factor()
    ratep = parse_expr(
        "kminuscat*et/Kmp/(1+a/kia+Kma*b/(kia*Kmb)+a*b/(Kmb*kia)+Kma*b*p/(kia*Kmb*kip)+p/Kmp)"
    ).subs(constants)
    indp = crn.complexes.index(parse_complex('p'))
    diffp = (ratep - crn.laplacian[indp, indp]).factor()
    fail_if_not_equal(diffab, 0)
    fail_if_not_equal(diffp, 0)
コード例 #11
0
def two_catalytic_sites():
    """Enzyme with two catalytic sites (Ingalls, exercise 3.3.4)."""
    print("Enzyme with two catalytic sites.")
    crn = from_react_file(os.path.join(input_reactions, "two_catalytic_sites"))
    crn.qss('c', cons_law=('e', ConsLaw('e + c', 'et')))
    fail_if_not_equal(
        (crn.rates[0] -
         parse_expr('k2*et*s**2/((k_1 + k2) / k1 + s**2)')).factor(), 0)
コード例 #12
0
def competitive_inhibition():
    """Competitive inhibition (Ingalls 3.2.1)."""
    print("Competitive inhibition.")
    crn = from_react_file(
        os.path.join(input_reactions, "competitive_inhibition"))
    # Using conservation law
    crn.qss(cons_law=('E', ConsLaw('E + C + C_i', 'Et')))
    fail_if_not_equal(
        sp.factor(crn.laplacian[0, 0] - parse_expr(
            "k2*Et/(I*((k_1+k2)/k1)/(k_3/k3) + S + ((k_1+k2)/k1))")), 0)

    # Without using conservation law
    crn = from_react_file(
        os.path.join(input_reactions, "competitive_inhibition"))
    crn.qss('C_i')
    crn.qss('C')
    crn.remove_all_constants()
コード例 #13
0
def double_displ():
    """Double displacement or ping pong mechanism (Ingalls 3.7.6)."""
    print("Double displacement.")
    crn = from_react_file(os.path.join(input_reactions, "double_displacement"))
    origeqs = crn.equations()
    origspecies = crn.species
    crn.qss(cons_law=('e', ConsLaw('e + c1 + c2 + ee', 'et')))
    fail_if_not_equal(
        eqs_match(origeqs, origspecies, crn.removed_species, crn.equations(),
                  crn.species), 0)
コード例 #14
0
def non_competitive_inhibition():
    """Non-competitive inhibition (Segel, Enzyme kinetics)."""
    print("Non-competitive inhibition.")
    crn = from_react_file(
        os.path.join(input_reactions, "noncompetitive_inhibition"))
    crn.remove(rapid_eq = [('ei', 'e + i'), ('esi', 'e + s + i'), ('es', 's + e')], \
               cons_law = ('e', ConsLaw('e + ei + es + esi', 'et')))
    fail_if_not_equal(
        sp.factor(crn.laplacian[0, 0] -
                  parse_expr("et*k2/((1 + k3/k_3 * i)*(s + k_1/k1))")), 0)
コード例 #15
0
def ternary_compulsory():
    """Transfer of a radioactive atom (a_s -> p_s), in a ternary compulsory mechanism. Cornish-Bowden, 6.8."""
    print("Example of transfer of a radioactive atom.")
    # Exchange requires a_s to bind to e. Inhibited by high concentrations of a and q, as they also bind to e.
    crn = from_react_file(os.path.join(input_reactions, "ternary_compulsory"))
    with warnings.catch_warnings(record=True) as w:
        # Use 'e + ea + eab + eq' instead of proper conservation 'e + ea + ea_s + eab + ea_sb + eq')
        crn.remove(rapid_eq = [('eab', 'ea + b'), ('ea', 'e + a'), ('eq', 'e + q')], \
                             cons_law = ('e' , ConsLaw('e + ea + eab + eq', 'et')))

        crn.remove(qss=['ea_sb', 'ea_s'])
        # unlabelled species assumed constant
        for s in ['a', 'p', 'b', 'q']:
            crn.remove_constant(s)
        for ws in w:
            assert "not constant." in str(ws.message)

    # page 122
    ratea_s = parse_expr(
        'k1*k2*k3*et*b/((1+k1*a/k_1+k1*k2*a*b/(k_1*k_2)+k_4*q/k4)*(k_1*(k_2+k3)+k2*k3*b))'
    )
    ratep_s = parse_expr(
        'k_1*k_2*k_3*k_4/k4*et*q/((1+k1*a/k_1+k1*k2*a*b/(k_1*k_2)+k_4*q/k4)*(k_1*(k_2+k3)+k2*k3*b))'
    )
    ratea_s = ratea_s.expand().factor().factor()
    ratep_s = ratep_s.expand().factor().factor()
    inda_s = crn.complexes.index(parse_complex('a_s'))
    indp_s = crn.complexes.index(parse_complex('p_s'))
    diffa_s = crn.laplacian[inda_s, inda_s] - ratea_s
    diffa_s = diffa_s.factor()
    diffp_s = crn.laplacian[indp_s, indp_s] - ratep_s
    diffp_s = diffp_s.factor()
    fail_if_not_equal(diffa_s, 0)
    fail_if_not_equal(diffp_s, 0)

    # Full version
    crn = from_react_file(os.path.join(input_reactions, "ternary_compulsory"))
    #for c in ['a', 'p', 'b', 'q']: crn.remove_constant(c)
    crn.remove(rapid_eq = [('eab', 'ea + b'), ('ea', 'e + a'), ('eq', 'e + q')], \
                         qss = ['ea_sb', 'ea_s'], \
                         cons_law = ('e' , ConsLaw('e + ea + ea_s + eab + ea_sb + eq', 'et')))
コード例 #16
0
    def test_enzyme_reversible(self):
        """One-substrate enzyme reversible kinetics."""
        crn = from_react_file(path.join(input_reactions, "enzyme_reversible"))

        crn.qss(cons_law=('E', ConsLaw('E + C', 'Et')))
        forward = parse_expr("Vf*S/Ks/(1 + S/Ks + P/Kp)").subs(parse_expr("Vf"), parse_expr("Et*k2"))\
                                                         .subs(parse_expr("Ks"), parse_expr("(k_1+k2)/k1"))\
                                                         .subs(parse_expr("Kp"), parse_expr("(k_1+k2)/k_2")).simplify()
        backward = parse_expr("Vr*P/Kp/(1 + S/Ks + P/Kp)").subs(parse_expr("Vr"), parse_expr("Et*k_1"))\
                                                          .subs(parse_expr("Ks"), parse_expr("(k_1+k2)/k1"))\
                                                          .subs(parse_expr("Kp"), parse_expr("(k_1+k2)/k_2")).simplify()
        self.assertEqual(set(crn.rates), set([forward, backward]))
コード例 #17
0
def adair_two_sites():
    """Adair equation for a protein that binds ligand at two identical sites (Ingalls 3.3.1)."""
    print("Adair equation.")
    crn = from_react_file(os.path.join(input_reactions, "adair_two_sites"))
    for p in ['PX2', 'PX1']:
        crn.qss(p)
    saturation = parse_expr('(PX1 + 2 * PX2)/2/(P + PX1 + PX2)')
    for s, expr in crn.removed_species:
        saturation = saturation.subs(s, expr).factor()
    Y = parse_expr("(X/K1 + X**2/(K1*K2))/(1 + 2*X/K1 + X**2/(K1*K2))").subs(parse_expr("K1"), parse_expr("k_1/k1")). \
                            subs(parse_expr("K2"), parse_expr("k_2/k2"))
    fail_if_not_equal(sp.factor(saturation - Y), 0)
コード例 #18
0
def three_subs_one_prod_compulsory_irr_0():
    """Irreversible three substrate, one product compulsory order mechanism."""
    print(
        "Three substrate, one product, compusory irreversible mechanism, v2.")
    crn = from_react_file(
        os.path.join(input_reactions, "three_subs_one_prod_compul_irr"))
    origeqs = crn.equations()
    origspecies = crn.species
    crn.qss(cons_law=('e', ConsLaw('e + ea + eab + eabc', 'et')))
    fail_if_not_equal(
        eqs_match(origeqs, origspecies, crn.removed_species, crn.equations(),
                  crn.species), 0)
コード例 #19
0
def passive_transport():
    """Passive transport (Ingalls, section 3.4.2) """
    print("Passive transport.")
    crn = from_react_file(
        os.path.join(input_reactions, "passive_transport_simpl"))
    crn.qss(cons_law=('T', ConsLaw('T + TS', 'Ttot')))
    forward = parse_expr("a1*S1/K1/(1 + S1/K1 + S2/K2)").subs("a1", parse_expr("k2*Ttot"))\
                                                     .subs("K1", parse_expr("(k_1+k2)/k1"))\
                                                     .subs("K2", parse_expr("(k_1+k2)/k_2")).factor()
    backward = parse_expr("a2*S2/K2/(1 + S1/K1 + S2/K2)").subs("a2", parse_expr("k_1*Ttot"))\
                                                      .subs("K1", parse_expr("(k_1+k2)/k1"))\
                                                      .subs("K2", parse_expr("(k_1+k2)/k_2")).factor()
    fail_if_not_equal(set(crn.rates), set([forward, backward]))

    # Rapid equilibrium on transport step
    crn = from_react_file(os.path.join(input_reactions, "passive_transport"))
    crn.rapid_eq_with_pool('TS1', 'TS2', pool_name="TS")

    # Assuming only qqs
    crn = from_react_file(os.path.join(input_reactions, "passive_transport"))
    crn.qss(cons_law=('T', ConsLaw('T + TS1 + TS2', 'Ttot')))
コード例 #20
0
def three_subs_one_prod_compulsory_irr():
    """Cornish-Bowden, example section 6.9, irreversible version."""
    print("Three substrate, one product, compusory irreversible mechanism.")
    crn = from_react_file(os.path.join(input_reactions, "three_subs_mech_irr"))
    origeqs = crn.equations()
    origspecies = crn.species
    fail_if_not_equal(crn.is_constant('e + e1 + ea + er + eab + eqr'), True)
    crn.qss(cons_law=('e', ConsLaw('e + e1 + ea + er + eab + eqr', 'et')))
    fail_if_not_equal(
        eqs_match(origeqs, origspecies, crn.removed_species, crn.equations(),
                  crn.species), 0)
    fail_if_not_equal(set(get_monoms(crn.rates[0].as_numer_denom()[1], ["a", "b", "c"])), \
                     set(map(parse_expr, ["c", "a*b", "a*c", "b*c", "a*b*c"])))
コード例 #21
0
def allosteric_activation():
    """Allosteric activation (Ingalls 3.7.8)."""
    print("Allosteric activation.")
    crn = from_react_file(
        os.path.join(input_reactions, "allosteric_activation"))
    crn.qss(cons_law = ('E', ConsLaw('E + ER + ERS', 'Etot')), \
            remove_const = True, merge_reacts = True)
    #crn.remove_all_constants()
    inds = crn.complexes.index(parse_complex('S'))
    fail_if_not_equal(
        sp.factor(crn.laplacian[inds, inds] - parse_expr(
            "R*k3*Etot/(R * (k_2 + k3)/k2 + k_1*(k_2 + k3)/(k1*k2) + S*R)")),
        0)
コード例 #22
0
def two_subs_one_prod_compulsory_irr():
    """Irreversible two substrate, one product compulsory order mechanism.
    Rates compared to http://www.cogsys.cs.uni-tuebingen.de/software/SBMLsqueezer/doc/KineticLaws2.pdf."""
    print("Two substrates, one product compulsory irreversible mechanism.")
    # Irreversible
    crn = from_react_file(
        os.path.join(input_reactions, "two_subs_one_prod_compul_irr"))
    crn.qss(cons_law=('e', ConsLaw('e + ea + eab', 'et')))
    rateab = parse_expr("k3*et/(kia*Kmb)/(1+a/kia+Kma*b/(kia*Kmb)+a*b/(Kmb*kia))").subs("kia", parse_expr("k_1/k1")) \
                                                                                  .subs("Kma", parse_expr("k3/k1")) \
                                                                                  .subs("Kmb", parse_expr("(k_2+k3)/k2"))
    indab = crn.complexes.index(parse_complex('a + b'))
    fail_if_not_equal((rateab - crn.laplacian[indab, indab]).factor(), 0)
コード例 #23
0
def enzyme_reversible():
    """One-substrate enzyme reversible kinetics."""
    print("One-substrate reversible enzyme kinetics.")
    crn = from_react_file(os.path.join(input_reactions, "enzyme_reversible"))

    crn.qss(cons_law=('E', ConsLaw('E + C', 'Et')))
    forward = parse_expr("Vf*S/Ks/(1 + S/Ks + P/Kp)").subs("Vf", parse_expr("Et*k2"))\
                                                  .subs("Ks", parse_expr("(k_1+k2)/k1"))\
                                                  .subs("Kp", parse_expr("(k_1+k2)/k_2")).factor()
    backward = parse_expr("Vr*P/Kp/(1 + S/Ks + P/Kp)").subs("Vr", parse_expr("Et*k_1"))\
                                                   .subs("Ks", parse_expr("(k_1+k2)/k1"))\
                                                   .subs("Kp", parse_expr("(k_1+k2)/k_2")).factor()
    fail_if_not_equal(set(crn.rates), set([forward, backward]))
コード例 #24
0
def three_subs_one_prod_full():
    """Three substrates, one product, with rapid eq. and qss."""
    print(
        "Three substrate, one product, compusory irreversible mechanism, v3.")
    crn = from_react_file(
        os.path.join(input_reactions, "three_subs_one_prod_full"))
    origeqs = crn.equations()
    origspecies = crn.species
    fail_if_not_equal(
        crn.is_constant('e + ea + eb + ec + eab + eac + ebc + eabc'), True)
    crn.remove(rapid_eq = [('ea', 'e + a'), ('eb', 'e + b'), ('ec', 'e + c'), \
                          ('eab', 'e + a + b'), ('eac', 'e + a + c'), ('ebc', 'e + b +c')], \
               qss = ['eabc'], \
               cons_law = ('e' , ConsLaw('e + ea + eb + ec + eab + eac + ebc + eabc', 'et')))
    fail_if_not_equal(set(get_monoms(crn.rates[0].as_numer_denom()[1], ["a", "b", "c"])), \
                     set(map(parse_expr, ["1", "a", "b", "c", "a*b", "a*c", "b*c", "a*b*c"])))
コード例 #25
0
 def test_merge(self):
     crn = from_react_file(path.join(input_folder, "test_merge"))
     origspecies = crn.species
     origeqs = crn.equations()
     for r in crn.reactions:
         print(r)
     crn.merge_reactions()
     print
     for r in crn.reactions:
         print(r)
     eqs = crn.equations()
     couples = [(tuple(sorted(r.reactant.items())),
                 tuple(sorted(r.product.items()))) for r in crn.reactions]
     self.assertEqual(len(couples), len(set(couples)))
     self.assertEqual(
         eqs_match(origeqs, origspecies, crn.removed_species,
                   crn.equations(), crn.species), 0)
コード例 #26
0
def pfloops_examples(debug=False):
    folder = "data/reactions/dsr-graph/"
    filenames = [
        "pos_loops_main", "pos_loops_main_v2", "ubiquitination",
        "phosphorylation", "signalling_cascades", "apoptosis"
    ]

    for i in range(len(filenames)):
        crn = from_react_file(os.path.join(folder, filenames[i]))
        print(filenames[i])
        for r in crn.reactions:
            print(r)
        pfls = pos_fb_loops_multistat(crn, debug)
        if len(pfls) > 0:
            print("Positive feedback loops found:")
            for pfl in pfls:
                print(pfl)
        print("")
コード例 #27
0
 def test_multi_product(self):
     """Test for the case of intermediate produced
     with multiple stoichiometries."""
     crn = from_react_file(path.join(input_reactions, "multi_product"))
     origspecies = crn.species
     origeqs = crn.equations()
     self.assertEqual(
         eqs_match(origeqs, origspecies, crn.removed_species,
                   crn.equations(), crn.species), 0)
     crn._qss_generalised('y', no_rates=True)
     reacts = parse_reactions([
         "r0_3r1: a + 2d ->(k_r0_3r1) 3b + c",
         "r0_3r4: a ->(k_r0_3r4) 3a + 6b + c + d",
         "r2_r1: d + e + f ->(k_r2_r1) b",
         "r2_r4: e + f ->(k_r2_r4) a + 2b",
         "r3_2r1: 2d + 2e ->(k_r3_2r1) 2b + h",
         "r3_2r4: 2e ->(k_r3_2r4) 2a + 4b + h"
     ])
     self.assertTrue(
         all(r in reacts for r in crn.reactions)
         and all(r in crn.reactions for r in reacts))
コード例 #28
0
def two_subs_two_prods_subs_enzyme():
    """Substituted-enzyme (ping-pong) mechanism. From Cornish-Bowden, section 6.1."""
    print("Substituted enzyme mechanism.")
    crn = from_react_file(
        os.path.join(input_reactions, "two_subs_two_prods_subs_enzyme"))
    crn.qss(cons_law=('e', ConsLaw('e + e1 + ea + e1b', 'et')))

    constants = dict(Vf=parse_expr("k2*k4*et/(k2+k4)"),
                     Vr=parse_expr("k_1*k_3*et/(k_1+k_3)"),
                     kia=parse_expr("k_1/k1"),
                     kib=parse_expr("k_3/k3"),
                     kip=parse_expr("k2/k_2"),
                     kiq=parse_expr("k4/k_4"),
                     Kma=parse_expr("(k_1+k2)*k4/k1/(k2+k4)"),
                     Kmb=parse_expr("k2/k3*(k_3+k4)/(k2+k4)"),
                     Kmp=parse_expr("k_3/k_2*(k_1+k2)/(k_1+k_3)"),
                     Kmq=parse_expr("k_1/k_4*(k_3+k4)/(k_1+k_3)"))

    rateab = parse_expr(
        "Vf/(kia*Kmb)/(a/kia+b*Kma/(kia*Kmb)+p/kip+q*Kmp/(kip*Kmq)+a*b/(kia*Kmb)+a*p/(kia*kip)+\
                                       Kma*b*q/(kia*Kmb*kiq)+p*q/(Kmq*kip))"
    ).subs(constants)

    ratepq = parse_expr(
        "Vr/(kip*Kmq)/(a/kia+b*Kma/(kia*Kmb)+p/kip+q*Kmp/(kip*Kmq)+a*b/(kia*Kmb)+a*p/(kia*kip)+\
                                       Kma*b*q/(kia*Kmb*kiq)+p*q/(Kmq*kip))"
    ).subs(constants)

    rateab = rateab.expand().factor().factor()
    ratepq = ratepq.expand().factor().factor()
    indab = crn.complexes.index(parse_complex('a + b'))
    indpq = crn.complexes.index(parse_complex('p + q'))
    diffab = crn.laplacian[indab, indab] - rateab
    diffab = diffab.factor()
    diffpq = crn.laplacian[indpq, indpq] - ratepq
    diffpq = diffpq.factor()
    fail_if_not_equal(diffab, 0)
    fail_if_not_equal(diffpq, 0)
コード例 #29
0
    def test_examples(self):
        """Examples."""
        folder = path.join(input_reactions, "examples/")
        files = [
            f for f in listdir(folder) if path.isfile(path.join(folder, f))
        ]
        solFolder = path.join(input_reactions, "examples/sols")
        notVerified = []

        for reactionFile in files:
            print("######################################")
            print("Example: {}".format(reactionFile))
            crn = from_react_file(path.join(folder, reactionFile))
            origspecies = crn.species
            origeqs = crn.equations()
            crn.qss('i')

            # Check that equations are as expected
            self.assertEqual(
                eqs_match(origeqs, origspecies, crn.removed_species,
                          crn.equations(), crn.species), 0)

            # Check that reactions are as in solution file
            reactions = map(lambda x: x.split(': ')[1],
                            map(str, crn.reactions))
            solFile = path.join(solFolder, reactionFile + "_sol")
            if path.isfile(solFile):
                with open(solFile) as f:
                    reacts = map(lambda x: x.split(': ')[1],
                                 f.read().splitlines())
                self.assertEqual(set(reactions), set(reacts))
            else:
                notVerified.append(reactionFile)

        if len(notVerified) > 0:
            print("Solutions not checked: {}".format(notVerified))
コード例 #30
0
 def test_dynEq(self):
     crn1 = from_react_file(path.join(input_reactions, "dynEq/net1"))
     crn2 = from_react_file(path.join(input_reactions, "dynEq/net2"))
     assert crn1.is_dyn_eq(crn2)
     assert crn2.is_dyn_eq(crn1)