コード例 #1
0
def test_magic_copy():
    c = CRN()
    c.r("A + B <> 2C", [1, 1])
    c2 = copy(c)
    assert (id(c2) != id(c))
    assert (id(c2.reactions[0]) != id(c.reactions[0]))
    assert (c2.reactions[0] == c.reactions[0])
コード例 #2
0
ファイル: test_basic.py プロジェクト: jvrana/pyrxn
def test_magic_copy():
    c = CRN()
    c.r("A + B <> 2C", [1, 1])
    c2 = copy(c)
    assert(id(c2) != id(c))
    assert(id(c2.reactions[0]) != id(c.reactions[0]))
    assert(c2.reactions[0] == c.reactions[0])
コード例 #3
0
ファイル: test_basic.py プロジェクト: jvrana/pyrxn
def test_copy_reaction():
    c = CRN()
    c.r("2A + B > C", 1.0)

    reaction = c.reactions[0]
    r2 = reaction.copy(1)

    print(r2)
コード例 #4
0
def test_copy_reaction():
    c = CRN()
    c.r("2A + B > C", 1.0)

    reaction = c.reactions[0]
    r2 = reaction.copy(1)

    print(r2)
コード例 #5
0
ファイル: test_basic.py プロジェクト: jvrana/pyrxn
def test_add_reaction_shoud_maintain_state():

    c1 = CRN()
    c1.r("A + B > C", 1)
    c1['A'] = 1.0

    c1.r('B > C', 2)

    assert(c1['A'] == 1)
コード例 #6
0
ファイル: test_basic.py プロジェクト: jvrana/pyrxn
def test_bidirectional(reactants, products, direction, rates, num_rxns):
    rxn = reactants + direction + products
    c = CRN()

    if 0 in rates:
        with pytest.raises(CRNException):
            c.r(rxn, rates)
    else:
        for i in range(num_rxns):
            c.r(rxn, rates)
        assert(2*num_rxns == len(c.reactions))
コード例 #7
0
ファイル: test_basic.py プロジェクト: jvrana/pyrxn
def test_magic_add():
    c1 = CRN()
    c1.r("2A + B > C", 1.0)

    c2 = CRN()
    c1.r("3A + B <> C", [1.0, 3.0])

    c3 = c1 + c2
    assert(len(c3.reactions) == 3)

    for r in c3.reactions:
        print(r)
コード例 #8
0
ファイル: test_basic.py プロジェクト: jvrana/pyrxn
def test_run():
    c = CRN()

    c.r("P1 > m1 + P1", 0.01)
    c.r("m1 > ", 0.01)
    c.r("P1 + m2 <> PR1", [0.001, 0.001])

    c.set_state({"P1": 1})

    df = c.run(750)

    gradient(df, 'time', 1)
    gradient(df, 'time', 2)

    plot(df, 'time', c.E)
コード例 #9
0
ファイル: test_complex.py プロジェクト: jvrana/pyrxn
def test_complex():
    def nor_gate(i, j, k):
        c = CRN()

        prom = "P{}{}".format(i, j)

        txn = "{0} > {0} + {1}".format(prom, k)
        deg = "{0} > ".format(k)
        r1 = "{0} + {1} <> {0}{1}".format(prom, i)
        r2 = "{0} + {1} <> {0}{1}".format(prom, j)

        c.r(txn, 1.0, 'txn')
        c.r(deg, 0.1, 'deg')
        c.r(r1, [0.01, 0.05], 'repr')
        c.r(r2, [0.01, 0.0005], 'repr')
        c[prom] = 1
        return c

    c1 = nor_gate("r1", "r1", "r5")
    c2 = nor_gate("r2", "r2", "r6")
    c3 = nor_gate("r5", "r6", "r7")
    c4 = CRN.merge_all([c1, c2, c3])

    c4.r(" > r1", 1.0)
    c4.r("r1 > ", 0.1)

    c4.remove_duplicates()
    c4.reduce()

    df = c4.run(1000)
コード例 #10
0
def test_merge_all():
    c1 = CRN()
    c1.r("A + B <> 2C", [1, 1])
    c1['A'] = 2

    c2 = copy(c1)
    c2['A'] = 4
    c2['B'] = 1

    assert (c1['A'] == 2)
    assert (c1['B'] == 0)
    assert (c1['C'] == 0)
    c3 = CRN.merge_all([c1, c2])
    assert (c3['A'] == 4)
    assert (c3['B'] == 1)
    assert (c3['C'] == 0)
コード例 #11
0
ファイル: test_basic.py プロジェクト: jvrana/pyrxn
def test_merge_all():
    c1 = CRN()
    c1.r("A + B <> 2C", [1, 1])
    c1['A'] = 2

    c2 = copy(c1)
    c2['A'] = 4
    c2['B'] = 1

    assert(c1['A'] == 2)
    assert(c1['B'] == 0)
    assert(c1['C'] == 0)
    c3 = CRN.merge_all([c1, c2])
    assert(c3['A'] == 4)
    assert(c3['B'] == 1)
    assert(c3['C'] == 0)
コード例 #12
0
def test_merge_maintains_part():
    c = CRN()
    c.r("A + B > 2C", 1, part='part1')

    c2 = CRN()
    c2.r("AB > BC", 1, part='part2')

    c3 = CRN.merge_all([c, c2])
    for r in c3.reactions:
        print(r)
    assert c3.reactions[0].part == 'part1'
    assert c3.reactions[1].part == 'part2'

    print(c3)
コード例 #13
0
ファイル: test_basic.py プロジェクト: jvrana/pyrxn
def test_merge_with_add():
    c1 = CRN()
    c1.r("A + B <> 2C", [1, 1])
    c1['A'] = 2

    c2 = copy(c1)
    c2['A'] = 4
    c2['B'] = 1

    assert(c1['A'] == 2)
    assert(c1['B'] == 0)
    assert(c1['C'] == 0)
    print(c1.x)
    c1.merge(c2, lambda a, b: a+b)

    assert(c1['A'] == 6)
    assert(c1['B'] == 1)
    assert(c1['C'] == 0)
コード例 #14
0
ファイル: test_basic.py プロジェクト: jvrana/pyrxn
def test_merge():
    c1 = CRN()
    c1.r("A + B <> 2C", [1, 1])
    c1['A'] = 2

    c2 = copy(c1)
    c2['A'] = 4
    c2['B'] = 1

    assert(c1['A'] == 2)
    assert(c1['B'] == 0)
    assert(c1['C'] == 0)

    c1.merge(c2)

    assert(c1['A'] == 4)
    assert(c1['B'] == 1)
    assert(c1['C'] == 0)
コード例 #15
0
def test_get_part():
    c = CRN()
    c.r("A + B > 2C", 1, part='part1')

    c2 = CRN()
    c2.r("AB <> BC", [1, 1], part='part2')

    c3 = CRN.merge_all([c, c2])

    c4 = c3.get_part('part1')
    c5 = c3.get_part('part2')
    c6 = c3.get_part('part1', 'part2')

    assert len(c3.reactions) == 3
    assert len(c4.reactions) == 1
    assert len(c5.reactions) == 2
    assert len(c6.reactions) == 3
コード例 #16
0
def test_add_operator():
    """Expect to remove duplicates"""

    eqn1 = "A + B > C"
    eqn2 = "C <> A + B"

    c1 = CRN()
    c1.r(eqn1, 0.01)
    c2 = CRN()
    c2.r(eqn2, [1, 0.01])
    c3 = c1 + c2

    assert (len(c3.reactions) == 3)
    c3.remove_duplicates()
    assert (len(c3.reactions) == 2)
コード例 #17
0
def test_magic_add():
    c1 = CRN()
    c1.r("2A + B > C", 1.0)

    c2 = CRN()
    c1.r("3A + B <> C", [1.0, 3.0])

    c3 = c1 + c2
    assert (len(c3.reactions) == 3)

    for r in c3.reactions:
        print(r)
コード例 #18
0
def test_reduce():
    """Expect to remove duplicates"""

    eqn1 = "A + B > C"
    eqn2 = "C <> A + B"

    c1 = CRN()
    c1.r(eqn1, 0.01)
    c2 = CRN()
    c2.r(eqn2, [1, 0.01])
    c3 = c1 + c2

    assert (len(c3.reactions) == 3)
    c3.reduce()
    assert (len(c3.reactions) == 2)
    assert (c3.reactions[0].rate == 0.02)
コード例 #19
0
def test_N():
    c = CRN()
    c.r("A + 2B <> C", [1.0, 2.0])
    print(c.E)
    print(c.N)
    print(c.R)
    print(c.P)

    c.set_state(dict(C=55))
    print(c.x)
    print("v(x)")
    x = np.ones((3, 1)) * 5
    print(c.v(x))

    d = c.run(0.001, 20)
    print(d)
コード例 #20
0
ファイル: test_complex.py プロジェクト: jvrana/pyrxn
    def nor_gate(i, j, k):
        c = CRN()

        prom = "P{}{}".format(i, j)

        txn = "{0} > {0} + {1}".format(prom, k)
        deg = "{0} > ".format(k)
        r1 = "{0} + {1} <> {0}{1}".format(prom, i)
        r2 = "{0} + {1} <> {0}{1}".format(prom, j)

        c.r(txn, 1.0, 'txn')
        c.r(deg, 0.1, 'deg')
        c.r(r1, [0.01, 0.05], 'repr')
        c.r(r2, [0.01, 0.0005], 'repr')
        c[prom] = 1
        return c
コード例 #21
0
def test_add_reaction_shoud_maintain_state():

    c1 = CRN()
    c1.r("A + B > C", 1)
    c1['A'] = 1.0

    c1.r('B > C', 2)

    assert (c1['A'] == 1)
コード例 #22
0
def test_bidirectional(reactants, products, direction, rates, num_rxns):
    rxn = reactants + direction + products
    c = CRN()

    if 0 in rates:
        with pytest.raises(CRNException):
            c.r(rxn, rates)
    else:
        for i in range(num_rxns):
            c.r(rxn, rates)
        assert (2 * num_rxns == len(c.reactions))
コード例 #23
0
ファイル: test_basic.py プロジェクト: jvrana/pyrxn
def test_merge_maintains_part():
    c = CRN()
    c.r("A + B > 2C", 1, part='part1')

    c2 = CRN()
    c2.r("AB > BC", 1, part='part2')


    c3 = CRN.merge_all([c, c2])
    for r in c3.reactions:
        print(r)
    assert c3.reactions[0].part == 'part1'
    assert c3.reactions[1].part == 'part2'

    print(c3)
コード例 #24
0
ファイル: test_basic.py プロジェクト: jvrana/pyrxn
def test_N():
    c = CRN()
    c.r("A + 2B <> C", [1.0, 2.0])
    print(c.E)
    print(c.N)
    print(c.R)
    print(c.P)

    c.set_state(dict(C=55))
    print(c.x)
    print("v(x)")
    x = np.ones((3,1))*5
    print(c.v(x))

    d = c.run(0.001, 20)
    print(d)
コード例 #25
0
ファイル: test_basic.py プロジェクト: jvrana/pyrxn
def test_get_part():
    c = CRN()
    c.r("A + B > 2C", 1, part='part1')

    c2 = CRN()
    c2.r("AB <> BC", [1,1], part='part2')


    c3 = CRN.merge_all([c, c2])

    c4 = c3.get_part('part1')
    c5 = c3.get_part('part2')
    c6 = c3.get_part('part1', 'part2')

    assert len(c3.reactions) == 3
    assert len(c4.reactions) == 1
    assert len(c5.reactions) == 2
    assert len(c6.reactions) == 3
コード例 #26
0
ファイル: test_basic.py プロジェクト: jvrana/pyrxn
def test_add_operator():
    """Expect to remove duplicates"""

    eqn1 = "A + B > C"
    eqn2 = "C <> A + B"

    c1 = CRN()
    c1.r(eqn1, 0.01)
    c2 = CRN()
    c2.r(eqn2, [1, 0.01])
    c3 = c1 + c2

    assert(len(c3.reactions) == 3)
    c3.remove_duplicates()
    assert(len(c3.reactions) == 2)
コード例 #27
0
ファイル: test_basic.py プロジェクト: jvrana/pyrxn
def test_reduce():
    """Expect to remove duplicates"""

    eqn1 = "A + B > C"
    eqn2 = "C <> A + B"

    c1 = CRN()
    c1.r(eqn1, 0.01)
    c2 = CRN()
    c2.r(eqn2, [1, 0.01])
    c3 = c1 + c2

    assert(len(c3.reactions) == 3)
    c3.reduce()
    assert(len(c3.reactions) == 2)
    assert(c3.reactions[0].rate == 0.02)
コード例 #28
0
def test_merge():
    c1 = CRN()
    c1.r("A + B <> 2C", [1, 1])
    c1['A'] = 2

    c2 = copy(c1)
    c2['A'] = 4
    c2['B'] = 1

    assert (c1['A'] == 2)
    assert (c1['B'] == 0)
    assert (c1['C'] == 0)

    c1.merge(c2)

    assert (c1['A'] == 4)
    assert (c1['B'] == 1)
    assert (c1['C'] == 0)
コード例 #29
0
def test_merge_with_add():
    c1 = CRN()
    c1.r("A + B <> 2C", [1, 1])
    c1['A'] = 2

    c2 = copy(c1)
    c2['A'] = 4
    c2['B'] = 1

    assert (c1['A'] == 2)
    assert (c1['B'] == 0)
    assert (c1['C'] == 0)
    print(c1.x)
    c1.merge(c2, lambda a, b: a + b)

    assert (c1['A'] == 6)
    assert (c1['B'] == 1)
    assert (c1['C'] == 0)
コード例 #30
0
def test_set_operator():
    c = CRN()
    c.r("A + B <> 2C", [1, 1])
    c['A'] = 1.1

    assert (list(c.x.flatten()) == [1.1, 0, 0])
コード例 #31
0
def test_basic2():
    c = CRN()
    c.r("A + 2B > 3C", 1.0)

    assert (1 == len(c.reactions))
コード例 #32
0
def test_run():
    c = CRN()

    c.r("P1 > m1 + P1", 0.01)
    c.r("m1 > ", 0.01)
    c.r("P1 + m2 <> PR1", [0.001, 0.001])

    c.set_state({"P1": 1})

    df = c.run(750)

    gradient(df, 'time', 1)
    gradient(df, 'time', 2)

    plot(df, 'time', c.E)
コード例 #33
0
def test_basic():
    c = CRN()
    c.r("A + 2B <> C", [1.0, 2.0])

    assert (2 == len(c.reactions))
コード例 #34
0
ファイル: test_basic.py プロジェクト: jvrana/pyrxn
def test_set_operator():
    c = CRN()
    c.r("A + B <> 2C", [1, 1])
    c['A'] = 1.1

    assert(list(c.x.flatten()) == [1.1, 0, 0])
コード例 #35
0
ファイル: test_basic.py プロジェクト: jvrana/pyrxn
def test_basic2():
    c = CRN()
    c.r("A + 2B > 3C", 1.0)

    assert(1 ==len(c.reactions))
コード例 #36
-2
ファイル: test_basic.py プロジェクト: jvrana/pyrxn
def test_basic():
    c = CRN()
    c.r("A + 2B <> C", [1.0, 2.0])

    assert(2 == len(c.reactions))