def test_bind_and_displace3way(self):
        complexes, reactions = read_pil("""
        length a = 10
        length b = 10
        length c = 10
        length t = 5

        I = a b c
        J = b c
        C = b( c( + ) ) a*
        B = a( b c + b( c( + ) ) )
        D = a( b( c( + ) ) )
        """)
        I = complexes['I']
        J = complexes['J']
        C = complexes['C']
        B = complexes['B']
        D = complexes['D']

        # DSD-pathway "bind21"
        path1 = PepperReaction([I, C], [B], 'bind21')
        # DSD-pathway "branch3way"
        path2 = PepperReaction([B], [D, J], 'branch-3way')

        enum = Enumerator(list(complexes.values()))
        enum.enumerate()
        self.assertEqual(sorted(enum.reactions), sorted([path1, path2]))
    def test_self_displacement_01(self):
        complexes, reactions = read_pil("""
        length x = 10
        length y = 10
        B1 = x( y( x( y x + ) ) )
        B2 = x y x( y( x( + ) ) )
        B3 = x( y( x y x( + ) ) )
        B4 = x( y x y( x( + ) ) )
        """)
        B1 = complexes['B1']
        B2 = complexes['B2']
        B3 = complexes['B3']
        B4 = complexes['B4']
        path1 = PepperReaction([B1], [B4], 'branch-3way')
        path1r = PepperReaction([B4], [B1], 'branch-3way')
        path2 = PepperReaction([B4], [B2], 'branch-3way')
        path3 = PepperReaction([B2], [B3], 'branch-3way')
        path3r = PepperReaction([B3], [B2], 'branch-3way')
        path4 = PepperReaction([B3], [B1], 'branch-3way')

        enum = Enumerator([B1])
        enum.max_helix = True
        enum.enumerate()
        self.assertEqual(sorted(enum.reactions),
                         sorted([path1, path1r, path2, path3, path3r, path4]))
    def test_self_displacement_02(self):
        complexes, reactions = read_pil("""
        length x = 10
        length y = 10
        T = x( y x + ) y* x*
        T1 = x( y x + x* y* )
        T2 = x y x( + ) y* x*
        T3 = x( y( x( + ) ) )
        T4 = x y x( + x* y* )
        """)
        T = complexes['T']
        T1 = complexes['T1']
        T2 = complexes['T2']
        T3 = complexes['T3']
        T4 = complexes['T4']
        path1 = PepperReaction([T], [T1], 'branch-3way')
        path1r = PepperReaction([T1], [T], 'branch-3way')
        path2 = PepperReaction([T], [T2], 'branch-3way')
        path2r = PepperReaction([T2], [T], 'branch-3way')
        path3 = PepperReaction([T1], [T3], 'bind11')
        path4 = PepperReaction([T2], [T3], 'bind11')
        path5 = PepperReaction([T1], [T4], 'branch-3way')
        path5r = PepperReaction([T4], [T1], 'branch-3way')
        path6 = PepperReaction([T2], [T4], 'branch-3way')
        path6r = PepperReaction([T4], [T2], 'branch-3way')

        enum = Enumerator([T])
        enum.max_helix = True
        enum.enumerate()
        self.assertEqual(
            sorted(enum.reactions),
            sorted([
                path1, path1r, path2, path2r, path3, path4, path5, path5r,
                path6, path6r
            ]))
    def testLoop(self):
        complexes, _ = read_pil("C = 1 2 3() + 4")

        parts = []
        domain_length = 0
        complex = complexes['C']

        # skip the closing helical domain
        for loc in [(0, 0), (0, 1), (0, 2), None, (1, 0)]:
            if loc is None:
                parts.append(None)
                continue

            domain = complex.get_domain(loc)
            parts.append((domain, complex.get_structure(loc), loc))

            # we'll naively assume all domains have the same length for the
            # sake of this example
            domain_length = len(domain)

        # construct a loop from parts
        loop = Loop(parts)

        assert loop.bases == domain_length * 3
        assert loop.stems == 1
        assert loop.is_open
    def test_self_displacement_03(self):
        complexes, reactions = read_pil("""
        length x1 = 10
        length x2 = 10
        length y1 = 10
        length y2 = 10
        B1 = x1( x2( y1( y2( x1( x2( y1 y2 x1 x2 + ) ) ) ) ) )
        B2 = x1 x2 y1 y2 x1( x2( y1( y2( x1( x2( + ) ) ) ) ) )
        i1 = x1( x2( y1 y2 x1 x2 y1( y2( x1( x2( + ) ) ) ) ) )
        i2 = x1( x2( y1( y2( x1 x2 y1 y2 x1( x2( + ) ) ) ) ) )
        """)
        B1 = complexes['B1']
        B2 = complexes['B2']
        i1 = complexes['i1']
        i2 = complexes['i2']
        path1 = PepperReaction([B1], [i1], 'branch-3way')
        path1r = PepperReaction([i1], [B1], 'branch-3way')
        path1f = PepperReaction([i1], [B2], 'branch-3way')
        path2 = PepperReaction([B2], [i2], 'branch-3way')
        path2r = PepperReaction([i2], [B2], 'branch-3way')
        path2f = PepperReaction([i2], [B1], 'branch-3way')

        enum = Enumerator([B1])
        enum.max_helix = True
        enum.enumerate()
        self.assertEqual(
            sorted(enum.reactions),
            sorted([path1, path1r, path1f, path2, path2r, path2f]))
    def test_join_complexes_01(self):
        complexes, reactions = read_pil("""
        length a = 10
        length t = 5
        S1 = a( + a t )
        S2 = t* a*
        S3 = a( a( + t* a*( + ) ) + a( + ) )
        X = a t a*( + ) + t* a*
        XB = a t( a*( + ) + ) a*
        Y = a( a( + a t a*( + ) + t* a*( + ) ) + a( + ) )
        """)
        S1 = complexes['S1']
        S2 = complexes['S2']
        S3 = complexes['S3']
        X = complexes['X']
        Y = complexes['Y']

        c, l1, l2 = join_complexes_21(S1, (1, 1), S2, (0, 0))
        assert c is X
        assert l1 == (0, 1)
        assert l2 == (2, 0)
        n, n1, n2 = join_complexes_21(S2, (0, 0), S1, (1, 1))
        assert n is c
        assert n1 == l1
        assert n2 == l2
        c, l1, l2 = join_complexes_21(S1, (1, 1), S3, (1, 0))
        assert c is Y
        assert l1 == (1, 1)
        assert l2 == (3, 0)
        c, l1, l2 = join_complexes_21(S3, (1, 0), S1, (1, 1))
        assert c is Y
        assert l1 == (1, 1)
        assert l2 == (3, 0)
    def test_open1N_01(self):
        complexes, reactions = read_pil("""
        length a = 8
        length t = 5

        X = a( t( + ) )
        Y = a( t + t* )
        Z = a t( + ) a*
        S1 = a t 
        S2 = t* a*
        """)
        X = complexes['X']
        Y = complexes['Y']
        Z = complexes['Z']
        S1 = complexes['S1']
        S2 = complexes['S2']
        rxnYS = PepperReaction([Y], [S1, S2], 'open')
        rxnXS = PepperReaction([X], [S1, S2], 'open')
        # max helix semantics ON -> no reactions vs dissociation
        out = open1N(Y, max_helix=True, release_11=7, release_1N=7)
        assert out == []
        out = open1N(Y, max_helix=True, release_11=8, release_1N=8)
        assert out == [rxnYS]
        out = open1N(X, max_helix=True, release_11=13, release_1N=13)
        assert out == [rxnXS]

        rxnXY = PepperReaction([X], [Y], 'open')
        rxnXZ = PepperReaction([X], [Z], 'open')
        # max helix semantics OFF -> domains dissociate, but at most one at a time
        out = open1N(X, max_helix=False, release_11=7, release_1N=7)
        self.assertEqual(out, [rxnXY])
        out = open1N(X, max_helix=False, release_11=8, release_1N=8)
        self.assertEqual(out, sorted([rxnXY, rxnXZ]))
        out = open1N(X, max_helix=False, release_11=13, release_1N=13)
        self.assertEqual(out, sorted([rxnXY, rxnXZ]))
    def test_bind21_01(self):
        complexes, reactions = read_pil("""
        length a = 10
        length t = 5
        S1 = a t 
        S2 = t* a*
        X = a( t + t* )
        Y = a t( + ) a*
        Z = a( t( + ) )
        """)
        S1 = complexes['S1']
        S2 = complexes['S2']
        X = complexes['X']
        Y = complexes['Y']
        Z = complexes['Z']
        singles = sorted([S1, S2])

        rxn1 = PepperReaction([S2, S1], [X], 'bind21')
        rxn2 = PepperReaction([S1, S2], [Y], 'bind21')
        out = bind21(S1, S2, max_helix=False)
        #for o in out: print(o.kernel_string)
        self.assertEqual(out, sorted([rxn1, rxn2]))

        rxn3 = PepperReaction([S2, S1], [Z], 'bind21')
        out = bind21(S1, S2, max_helix=True)
        self.assertEqual(out, [rxn3])
    def test_join_complexes_00(self):
        complexes, reactions = read_pil("""
        length a = 10
        length t = 5
        S1 = a t 
        S2 = t* a*
        """)
        S1 = complexes['S1']
        S2 = complexes['S2']

        c, l1, l2 = join_complexes_21(S1, (0, 1), S2, (0, 0))
        assert c.kernel_string == 'a t + t* a*'
        assert l1 == (0, 1)
        assert l2 == (1, 0)
        n, n1, n2 = join_complexes_21(S2, (0, 0), S1, (0, 1))
        assert n is c
        assert n1 == l1
        assert n2 == l2
        c, l1, l2 = join_complexes_21(S1, (0, 0), S2, (0, 1))
        assert c.kernel_string == 'a t + t* a*'
        assert l1 == (0, 0)
        assert l2 == (1, 1)
        n, n1, n2 = join_complexes_21(S2, (0, 1), S1, (0, 0))
        assert n is c
        assert n1 == l1
        assert n2 == l2
    def test_bind11_02(self):
        complexes, reactions = read_pil("""
        length a = 10
        length t = 5
        S0  = a a t t* a* a*
        SG1 = a( a t t* ) a* 
        SG2 = a a( t t* a* ) 
        SG3 = a( a( t( ) ) )
        SI1 = a( a t t* a* )
        SI2 = a a( t t* ) a*
        SI3 = a a t( ) a* a*
        """)
        S0 = complexes['S0']
        SG1 = complexes['SG1']
        SG2 = complexes['SG2']
        SG3 = complexes['SG3']
        SI1 = complexes['SI1']
        SI2 = complexes['SI2']
        SI3 = complexes['SI3']

        rg1 = PepperReaction([S0], [SG1], 'bind11')
        rg2 = PepperReaction([S0], [SG2], 'bind11')
        rg3 = PepperReaction([S0], [SG3], 'bind11')
        out = bind11(S0, max_helix=True)
        #for o in out: print(o.kernel_string)
        assert sorted(out) == sorted([rg1, rg2, rg3])

        ri1 = PepperReaction([S0], [SI1], 'bind11')
        ri2 = PepperReaction([S0], [SI2], 'bind11')
        ri3 = PepperReaction([S0], [SI3], 'bind11')
        out = bind11(S0, max_helix=False)
        #for o in out: print(o.kernel_string)
        assert sorted(out) == sorted([rg1, rg2, ri1, ri2, ri3])
    def test_4way_05(self):
        # Unconventional multi-state 4way junction, no end-dissociation
        complexes, reactions = read_pil("""
        length a = 10
        length b = 10
        length c = 10
        length x = 10
        A1 = a( a*( b( + ) ) a*( x*( + ) ) b( c( + ) ) )
        A2 = a( ) b( + ) a( a*( x*( + ) ) b( c( + ) ) )
        A3 = a( a*( b( + ) a( ) x*( + ) ) b( c( + ) ) )
        A4 = a( a*( b( + ) ) ) x*( + ) a( b( c( + ) ) )
        """)
        A1 = complexes['A1']
        A2 = complexes['A2']
        A3 = complexes['A3']
        A4 = complexes['A4']

        path1 = PepperReaction([A1], [A2], 'branch-4way')
        path2 = PepperReaction([A1], [A3], 'branch-4way')
        path3 = PepperReaction([A1], [A4], 'branch-4way')
        output = branch_4way(A1, max_helix=False)
        self.assertEqual(output, sorted([path1, path2, path3]))

        path1 = PepperReaction([A1], [A2], 'branch-4way')
        path2 = PepperReaction([A1], [A3], 'branch-4way')
        path3 = PepperReaction([A1], [A4], 'branch-4way')
        output = branch_4way(A1, max_helix=True)
        self.assertEqual(output, sorted([path1, path2, path3]))
    def test_named_complexes(self):
        complexes, reactions = read_pil("""
        sequence t = GGAGCC
        sequence s = ATATAT
        sequence r = GCGCGC
        sequence d2 = GGCAAACAAG
        sequence d3 = CGGCAGAATT
        sequence a = CGCATTTGCC
        sequence b = TACCTTTTCC
        sequence c = CAAAGCCCTT

        A = t d2 s* d3
        B = d2( d3( + ) s*( a* + a*( b*( c ) ) ) ) t*
        B2 = d2( d3( + ) s* a* + a*( b*( c ) ) s ) t* @ initial 0 M
        B3 = d2( d3( + ) s*( a*( + a* b*( c ) ) ) ) t* @ initial 0 M
        B4 = d2( d3( + ) s* a*( + a* b*( c ) ) s ) t* @ initial 0 M

        C = d2 d3( + ) s* a* @initial 0 M
        D = t( d2( s*( d3 + a*( b*( c ) ) ) ) ) @i 0 M
        E = d2 d3 @i 0 M
        F = t( d2( s*( d3( + ) s* a*( + a* b*( c ) ) ) ) ) @i 0 M
        G = t d2 s* d3( + ) s* a* @i 0 M
        """)
        A = complexes['A']
        B = complexes['B']
        F = complexes['F']

        enum = Enumerator([A, B], named_complexes=[A, B, F])
        enum.max_complex_count = 1000
        enum.max_reaction_count = 5000
        enum.enumerate()
        self.assertTrue(
            F in [rms.representative for rms in enum.resting_macrostates])
def peppercorn(kernelstring, name, 
        condensed=True, 
        conc='nM', 
        max_complex_size = 10,
        release_cutoff = 13,
        k_fast=0):
    """ A wrapper for peppercorn.
    """
    #print kernelstring
    complexes, reactions = read_pil(kernelstring)
    enum = Enumerator(complexes.values(), reactions)
    enum.release_cutoff = release_cutoff
    enum.max_complex_size = max_complex_size
    enum.k_fast = k_fast
    enum.enumerate()

    #condensed = False
    if condensed:
        enumRG = PepperCondensation(enum)
        enumRG.condense()

    detailed = not condensed

    #write_kernel(enum, sys.stdout, detailed, condensed)
    with open(name + '.crn', 'w') as crn:
        write_kernel(enum, crn, detailed, condensed, molarity=conc)

    if condensed:
        return enumRG, name + '.crn'
    else :
        return enum, name + '.crn'
    def test_cooperative_binding_fail(self):
        complexes, reactions = read_pil("""
        # File generated by peppercorn-v0.5.0
        
        # Domain Specifications 
        length a = 5
        length b = 5
        length x = 10
        length y = 10
        
        # Resting-set Complexes 
        C = x( y( + b* ) ) a* 
        CR = x( y( + y b( + ) ) ) a* 
        CRF = x( y + y( b( + ) ) ) a* 
        L = a x 
        LC = a( x + x( y( + b* ) ) ) 
        LCF = a( x( + x y( + b* ) ) ) 
        LR = a( x( + y( b( + ) ) ) ) 
        R = y b 
        T = x y 
        
        # Transient Complexes 
        LCR = a( x + x( y( + y b( + ) ) ) ) 
        LCRF1 = a( x( + x y( + y b( + ) ) ) ) 
        LCRF2 = a( x + x( y + y( b( + ) ) ) ) 
        
        # Detailed Reactions 
        reaction [bind21         =      1.5e+06 /M/s ] C + L -> LC
        reaction [bind21         =      1.5e+06 /M/s ] C + R -> CR
        reaction [open           =           20 /s   ] CR -> C + R
        reaction [branch-3way    =           30 /s   ] CR -> CRF
        reaction [branch-3way    =           30 /s   ] CRF -> CR
        reaction [bind21         =      1.5e+06 /M/s ] L + CR -> LCR
        reaction [bind21         =      1.5e+06 /M/s ] L + CRF -> LCRF2
        reaction [open           =           20 /s   ] LC -> C + L
        reaction [branch-3way    =           30 /s   ] LC -> LCF
        reaction [branch-3way    =           30 /s   ] LCF -> LC
        reaction [branch-3way    =           30 /s   ] LCR -> LCRF1
        reaction [branch-3way    =           30 /s   ] LCR -> LCRF2
        reaction [branch-3way    =           30 /s   ] LCRF1 -> LCR
        reaction [branch-3way    =           30 /s   ] LCRF1 -> T + LR
        reaction [branch-3way    =           30 /s   ] LCRF2 -> LCR
        reaction [branch-3way    =           30 /s   ] LCRF2 -> T + LR
        reaction [bind21         =      1.5e+06 /M/s ] R + LC -> LCR
        reaction [bind21         =      1.5e+06 /M/s ] R + LCF -> LCRF1
        """)
        enum = Enumerator(complexes.values())
        enum.enumerate()  # or enum.dry_run()

        enumRG = PepperCondensation(enum)

        # TODO: It should raise an error here, saying that the condensed graph
        # is disconnected!

        #with self.assertRaises(c.CondensationError):
        enumRG.condense()

        self.assertEqual(enumRG.condensed_reactions, [])
    def test_max_helix_02(self):
        complexes, reactions = read_pil("""
        length d1 = 15
        length d4 = 15
        length d6 = 15
        length d7 = 15
        length h8 = 15
        length t0 = 6
        length t2 = 6
        length t3 = 6
        length t5 = 6

        # Initial Complexes
        B2 = d7 t3 d4 t5 
        helper = t3 d7 t3
        PR_FL_B2  = d1 t2( d6( + d7( t3( d4 t5 + ) ) t3* ) )  @ initial 0 M
        
        # Intermediate Complexes
        PR_FLh1B2 = d1 t2( d6( + t3( d7 t3 + d7( t3( d4 t5 + ) ) ) ) )  @ initial 0 M
        PR_FLh2B2 = d1 t2( d6( + t3 d7 t3( + d7( t3( d4 t5 + ) ) ) ) )  @ initial 0 M
        PR_FL_h1w = d1 t2( d6( + t3( d7( t3( + ) ) ) ) )  @ initial 0 M
        
        # sidestuff
        PR_FLB2B2 = d1 t2( d6( + d7 t3( d4 t5 + d7( t3( d4 t5 + ) ) ) ) )  @ initial 0 M

        # casey-semantics
        PR_FLh2B2_v2 = d1 t2( d6( + t3( d7( t3 + d7 t3( d4 t5 + ) ) ) ) )  @ initial 0 M
        PR_FLh2w =     d1 t2( d6( + t3( d7( t3 + t3* ) ) ) )  @ initial 0 M

        """)
        B2 = complexes['B2']
        helper = complexes['helper']
        PR_FL_B2 = complexes['PR_FL_B2']
        PR_FLh1B2 = complexes['PR_FLh1B2']
        PR_FLh2B2 = complexes['PR_FLh2B2']
        PR_FL_h1w = complexes['PR_FL_h1w']
        PR_FLB2B2 = complexes['PR_FLB2B2']
        PR_FLh2B2_v2 = complexes['PR_FLh2B2_v2']
        PR_FLh2w = complexes['PR_FLh2w']

        path1 = PepperReaction([PR_FL_B2, helper], [PR_FLh1B2], 'bind21')
        path1r = PepperReaction([PR_FLh1B2], [PR_FL_B2, helper], 'open')
        path2 = PepperReaction([PR_FL_B2, helper], [PR_FLh2B2], 'bind21')
        path2r = PepperReaction([PR_FLh2B2], [PR_FL_B2, helper], 'open')
        path3 = PepperReaction([PR_FLh1B2], [PR_FL_h1w, B2], 'branch-3way')
        path4 = PepperReaction([PR_FL_B2, B2], [PR_FLB2B2], 'bind21')
        path4r = PepperReaction([PR_FLB2B2], [PR_FL_B2, B2], 'open')
        path5 = PepperReaction([PR_FLh1B2], [PR_FLh2B2], 'branch-3way')
        path6 = PepperReaction([PR_FLh2B2], [PR_FLh1B2], 'branch-3way')

        enum = Enumerator([B2, helper, PR_FL_B2])
        enum.max_helix = True
        enum.enumerate()
        assert sorted(enum.reactions) == sorted(
            [path1, path1r, path2, path2r, path3, path4, path4r, path5, path6])
    def test_3way_remote(self):
        """ 
        A remote 3way branch migration reaction.
        """
        # INPUT
        complexes, reactions = read_pil("""
        length a = 10
        length b = 10
        length c = 10
        length x = 10
        length y = 10
        length z = 10
        X  = a( b x y z + x( y( z( c( + ) ) ) ) )
        I1 = a( b x( y z + x y( z( c( + ) ) ) ) )
        I2 = a( b x( y( z + x y z( c( + ) ) ) ) )
        Y  = a( b x( y( z( + x y z c( + ) ) ) ) )
        """)
        reactant = complexes['X']
        inter1 = complexes['I1']
        inter2 = complexes['I2']
        product = complexes['Y']

        # ~~~~~~~~~~~~~ #
        # OUTPUT REMOTE #
        # ~~~~~~~~~~~~~ #
        forward = PepperReaction([reactant], [product], 'branch-3way')
        backward = PepperReaction([product], [reactant], 'branch-3way')

        output = branch_3way(reactant, max_helix=True, remote=True)
        self.assertEqual(output, [forward])

        output = branch_3way(product, max_helix=True, remote=True)
        self.assertEqual(output, [backward])

        forward = PepperReaction([inter1], [product], 'branch-3way')
        backward = PepperReaction([inter1], [reactant], 'branch-3way')

        output = branch_3way(inter1, max_helix=True, remote=True)
        self.assertEqual(sorted(output), sorted([backward, forward]))

        # ~~~~~~~~~~~~~~~~~~~~ #
        # OUTPUT REJECT REMOTE #
        # ~~~~~~~~~~~~~~~~~~~~ #
        backward = PepperReaction([product], [reactant], 'branch-3way')

        output = branch_3way(reactant, max_helix=True, remote=False)
        self.assertEqual(output, [])
        output = branch_3way(product, max_helix=True, remote=False)
        self.assertEqual(output, [backward])

        forward = PepperReaction([inter1], [product], 'branch-3way')
        backward = PepperReaction([inter1], [reactant], 'branch-3way')

        output = branch_3way(inter1, max_helix=True, remote=False)
        self.assertEqual(sorted(output), sorted([forward, backward]))
 def test_4way_01(self):
     complexes, reactions = read_pil("""
     length t0 = short
     length d3 = long
     length d4 = long
     A1 = t0*( d3*( d4*( + ) ) + d3*( t0* d3*( d4*( + ) ) + ) )
     A2 = t0*( d3*( d4*( + ) d3( + ) t0* d3*( d4*( + ) ) + ) )
     """)
     A1 = complexes['A1']
     A2 = complexes['A2']
     rxn = PepperReaction([A1], [A2], 'branch-4way')
     out = branch_4way(A1, max_helix=True, remote=True)
     assert out == [rxn]
Exemple #18
0
    def test_condense_simple(self):
        complexes, reactions = read_pil("""
        # File generated by peppercorn-v0.5.0
        
        # Domain Specifications 
        length d1 = 15
        length t0 = 5
        
        # Resting-set Complexes 
        c1 = t0 d1 
        c2 = d1( + ) t0* 
        c4 = t0( d1( + ) ) 
        c5 = d1 
        
        # Transient Complexes 
        c3 = t0( d1 + d1( + ) ) 
        
        # Detailed Reactions 
        reaction [bind21         =      100 /M/s ] c1 + c2 -> c3
        reaction [open           =       50 /s   ] c3 -> c1 + c2
        reaction [branch-3way    =       50 /s   ] c3 -> c4 + c5
        """)

        # (rs1) c1                c4 (rs3)
        #         \              /
        #          <---> c3 ---->
        #         /              \
        # (rs2) c2                c5 (rs4)

        enum = Enumerator(complexes.values(), reactions)
        enum.enumerate() 
        enum.condense()
        for con in enum.condensed_reactions:
            assert con.rate_constant[0] == 50
        del enum

        # old interface ...
        c1 = PepperMacrostate([complexes['c1']])
        c2 = PepperMacrostate([complexes['c2']])
        c4 = PepperMacrostate([complexes['c4']])
        c5 = PepperMacrostate([complexes['c5']])
        cond_react = PepperReaction([c1, c2], [c4, c5], 'condensed')
        cond_react.rate_constant = 20, None

        enum = Enumerator(complexes.values(), reactions)
        enum.dry_run()
        enumRG = PepperCondensation(enum)
        enumRG.condense()
        for con in enumRG.condensed_reactions:
            assert con.rate_constant[0] == 20
 def test_3way_01(self):
     complexes, reaction = read_pil("""
     length d11 = long
     length d12 = long
     length d7 = long
     length t6 = short
     length t8 = short
     A = d11  t6( d7 t8 + d12( t6( d7 t8 + ) ) ) d11*( t8*( + d7 ) )
     B = d11( t6( d7 t8 + d12( t6( d7 t8 + ) ) ) )     t8*( + d7 ) d11
     """)
     A = complexes['A']
     B = complexes['B']
     rxn = PepperReaction([A], [B], 'branch-3way')
     out = branch_3way(A, max_helix=True)
     assert out == [rxn]
    def test_interface_01(self):
        PepperComplex.PREFIX = 'enum'
        complexes, reactions = read_pil("""
        # Domain Specifications
        length a = 8
        length b = 8
        length c = 8
        length d2 = 8
        length d3 = 8
        length t = 4

        # Resting-set Complexes
        e0 = d2( d3( + ) a* + a*( b*( c ) ) ) t* 
        e12 = d2 d3( + ) a*                     
        e13 = t( d2( d3 + a*( b*( c ) ) ) )    
        e21 = d2 d3                           
        e22 = t( d2( d3( + ) a*( + a* b*( c ) ) ) )
        e27 = t( d2( d3( + ) a* + a*( b*( c ) ) ) )
        gate = d2( d3( + ) a*( + a* b*( c ) ) ) t* 
        t23 = t d2 d3   
                                                                                                     
        # Transient Complexes    
        e5 = t( d2 d3 + d2( d3( + ) a*( + a* b*( c ) ) ) )  
        e7 = t( d2 d3 + d2( d3( + ) a* + a*( b*( c ) ) ) ) 
        e18 = t( d2( d3 + d2 d3( + ) a*( + a* b*( c ) ) ) )

        # Detailed Reactions  
        reaction [bind21         =      1.2e+06 /M/s ] e0 + t23 -> e7   
        reaction [branch-3way    =     0.122307 /s   ] e0 -> gate       
        reaction [branch-3way    =      41.6667 /s   ] e5 -> e7         
        reaction [branch-3way    =      41.6667 /s   ] e5 -> e18        
        reaction [open           =      306.345 /s   ] e5 -> t23 + gate 
        reaction [open           =      306.345 /s   ] e7 -> e0 + t23   
        reaction [branch-3way    =     0.122307 /s   ] e7 -> e5         
        reaction [branch-3way    =      41.6667 /s   ] e7 -> e12 + e13  
        reaction [branch-3way    =     0.122307 /s   ] e18 -> e5        
        reaction [branch-3way    =      41.6667 /s   ] e18 -> e12 + e13 
        reaction [branch-3way    =     0.122307 /s   ] e18 -> e22 + e21 
        reaction [branch-3way    =      41.6667 /s   ] e22 -> e27       
        reaction [branch-3way    =     0.122307 /s   ] e27 -> e22       
        reaction [branch-3way    =      41.6667 /s   ] gate -> e0       
        reaction [bind21         =      1.2e+06 /M/s ] t23 + gate -> e5 
        """)

        enum = Enumerator(complexes.values(), reactions)
        enum.release_cutoff = 7
        enum.enumerate()
        self.assertEqual(sorted(enum.reactions), sorted(reactions))
    def test_4way_reject_remote(self):
        # Standard 4way junction, no end-dissociation
        complexes, reactions = read_pil("""
        length a = 10
        length b = 10
        length c = 10
        length d = 10
        length x = 10
        length y = 10
        length z = 10
        A0 = a( x( y( z( b(  + ) ) ) ) c*( + ) x( y( z( d( + ) ) ) ) )
        A1 = a( x( y( z( b(  + ) ) ) x*( c*( + ) ) y( z( d( + ) ) ) ) )
        A2 = a( x( y( z( b(  + ) ) y*( x*( c*( + ) ) ) z( d( + ) ) ) ) )
        A3 = a( x( y( z( b(  + ) z*( y*( x*( c*( + ) ) ) ) d( + ) ) ) ) )
        """)
        A0 = complexes['A0']
        A1 = complexes['A1']
        A2 = complexes['A2']
        A3 = complexes['A3']

        path1 = PepperReaction([A1], [A3], 'branch-4way')
        path2 = PepperReaction([A1], [A0], 'branch-4way')
        output = branch_4way(A1, max_helix=True, remote=False)
        self.assertEqual(output, sorted([path1, path2]))

        path1 = PepperReaction([A2], [A0], 'branch-4way')
        path2 = PepperReaction([A2], [A3], 'branch-4way')
        output = branch_4way(A2, max_helix=True, remote=False)
        self.assertEqual(output, sorted([path1, path2]))

        path = PepperReaction([A3], [A0], 'branch-4way')
        output = branch_4way(A3, max_helix=True, remote=False)
        self.assertEqual(output, [path])

        path1 = PepperReaction([A2], [A0], 'branch-4way')
        path2 = PepperReaction([A2], [A3], 'branch-4way')
        output = branch_4way(A2, max_helix=True, remote=False)
        self.assertEqual(output, sorted([path1, path2]))

        path1 = PepperReaction([A1], [A3], 'branch-4way')
        path2 = PepperReaction([A1], [A0], 'branch-4way')
        output = branch_4way(A1, max_helix=True, remote=True)
        self.assertEqual(output, sorted([path1, path2]))

        path = PepperReaction([A3], [A0], 'branch-4way')
        output = branch_4way(A3, max_helix=True, remote=False)
        self.assertEqual(output, [path])
 def test_3way_02(self):
     complexes, reactions = read_pil("""
     length b = 7
     A = b( b*( b b*( + ) b* ) )
     B = b( b*( b( ) + b b* ) )
     C = b( b*( ) b*( + ) b* b )
     D = b( b*( b b* + b( ) ) )
     """)
     A = complexes['A']
     B = complexes['B']
     C = complexes['C']
     D = complexes['D']
     rxn1 = PepperReaction([A], [B], 'branch-3way')
     rxn2 = PepperReaction([A], [C], 'branch-3way')
     rxn3 = PepperReaction([A], [D], 'branch-3way')
     out = branch_3way(A, max_helix=False)
     assert sorted(out) == sorted([rxn1, rxn2, rxn3])
    def test_cooperative_binding(self):
        complexes, reactions = read_pil("""
        length a = 5
        length x = 10
        length y = 10
        length b = 5

        C = x( y( + b* ) ) a*
        L = a x
        R = y b
        T = x y

        LC = a( x + x( y( + b* ) ) )
         CR = x( y( + y b( + ) ) ) a*
        LCR = a( x + x( y( + y b( + ) ) ) )
        LCF = a( x( + x y( + b* ) ) )
         CRF = x( y + y( b( + ) ) ) a*

        LCRF1 = a( x( + x y( + y b( + ) ) ) )
        LCRF2 = a( x + x( y + y( b( + ) ) ) )
        LR = a( x( + y( b( + ) ) ) )
        """)

        C = complexes['C']
        L = complexes['L']
        R = complexes['R']
        T = complexes['T']
        LC = complexes['LC']
        LCF = complexes['LCF']
        CR = complexes['CR']
        CRF = complexes['CRF']
        LCRF1 = complexes['LCRF1']
        LR = complexes['LR']

        path1 = PepperReaction([L, C], [LC], 'bind21')
        path1r = PepperReaction([LC], [L, C], 'open')
        path2 = PepperReaction([LC], [LCF], 'branch-3way')
        path3 = PepperReaction([R, LCF], [LCRF1], 'bind21')
        path4 = PepperReaction([LCRF1], [LR, T], 'branch-3way')

        enum = Enumerator(list(complexes.values()))
        enum.k_fast = float('inf')
        enum.k_slow = 0
        enum.max_helix = True
        enum.enumerate()
        self.assertEqual(len(list(enum.reactions)), 22)
Exemple #24
0
    def test_read_pil_01(self):
        complexes, reactions = read_pil(
        """
        # Domains (12) 
        sequence a = NNNNNN
        sequence b = NNNNNN 
        sequence c = NNNNNN
        sequence x = NNNNNN
        sequence y = NNNNNN 
        sequence z = NNNNNN 

        # Resting complexes (8) 
        A = a x( b( y( z* c* ) ) ) @i 1e-08 M
        B = b y( c( z( x* a* ) ) ) @i 1e-08 M
        C = c z( a( x( y* b* ) ) ) @i 1e-08 M
        I = y* b* x* a* @i 1e-08 M

        IA = a( x( b( y( z* c* y* b* x* + ) ) ) ) @i 0.0 M
        IAB = y*( b*( x*( a*( + ) ) ) ) z*( c*( y*( b*( x* + ) ) ) ) x* a* z* c* y* @i 0.0 M
        IABC = y*( b*( x*( a*( + ) ) ) ) z*( c*( y*( b*( x* + ) ) ) ) x*( a*( z*( c*( y* + ) ) ) ) y* b* x* a* z* @i 0.0 M
        ABC = a( x( b( y( z*( c*( y*( b*( x* + ) ) ) ) x*( a*( z*( c*( y* + ) ) ) ) ) ) ) ) z* @i 0.0 M

        # Resting macrostates (8) 
        macrostate A = [A]
        macrostate B = [B]
        macrostate C = [C]
        macrostate I = [I]
        macrostate IA = [IA]
        macrostate IAB = [IAB]
        macrostate IABC = [IABC]
        macrostate ABC = [ABC]

        # Condensed reactions (10) 
        reaction [condensed      =  1.66666e+06 /M/s ] A + I -> IA
        reaction [condensed      =  1.66666e+06 /M/s ] IA + B -> IAB
        reaction [condensed      =  1.66646e+06 /M/s ] IAB + C -> IABC
        reaction [condensed      =    0.0261637 /s   ] IABC -> ABC + I
        """)

        # A preliminary interface to start testing prototype functions.
        #a, b, c = dom['a'], dom['b'], dom['c']
        #assert a is PepperDomain('a')
        #assert b is PepperDomain('b')
        #assert c is PepperDomain('c')
        assert PepperComplex(None, None, 'IA').kernel_string == 'a( x( b( y( z* c* y* b* x* + ) ) ) )'
    def test_simple(self):
        complexes, reactions = read_pil("""
        length a = 6
        length a1 = 2
        length a2 = 2
        length a3 = 2
        length b  = 24
        length b1 = 8
        length b2 = 8
        length b3 = 8
        length c  = 24
        length c1 = 8
        length c2 = 8
        length c3 = 8

        I = a b c
        C = b( c( + ) ) a*
        J = a( b c + b( c( + ) ) )
        D = a( b( c( + ) ) )

        cI = a1 a2 a3 b1 b2 b3 c1 c2 c3
        cC = b1( b2( b3( c1( c2( c3( + ) ) ) ) ) ) a3* a2* a1*
        cJ = a1( a2( a3( b1 b2 b3 c1 c2 c3 + b1( b2( b3( c1( c2( c3( + ) ) ) ) ) ) ) ) )
        cD = a1( a2( a3( b1( b2( b3( c1( c2( c3( + ) ) ) ) ) ) ) ) )
        """)

        enum = Enumerator(
            [complexes['I'], complexes['C'], complexes['J'], complexes['D']],
            named_complexes=list(complexes.values()))
        enum.k_fast = 0
        enum.k_slow = 0
        enum.max_helix = True
        enum.enumerate()

        enum2 = Enumerator([
            complexes['cI'], complexes['cC'], complexes['cJ'], complexes['cD']
        ],
                           named_complexes=list(complexes.values()))
        enum.k_fast = 0
        enum2.k_fast = 0
        enum2.k_slow = 0
        enum2.max_helix = True
        enum2.enumerate()

        self.assertEqual(len(list(enum2.reactions)), len(list(enum.reactions)))
 def test_4way_03(self):
     complexes, reactions = read_pil("""
     # Domain Specifications
     length d1 = 15
     length d2 = 15
     length d3 = 15
     length d4 = 15
     length d5 = 15
     length d6 = 15
     length t0 = 6
     BUG = d4*( t0* + ) t0( + ) d4*( t0*( + ) ) 
     FIX = d4*( t0* + d4( t0( + ) ) t0*( + ) )
     """)
     BUG = complexes['BUG']
     FIX = complexes['FIX']
     rxn = PepperReaction([BUG], [FIX], 'branch-4way')
     output = branch_4way(BUG, max_helix=True, remote=True)
     self.assertEqual(output, [rxn])
    def test_seesaw_leak(self):
        complexes, reactions = read_pil("""
        # Domain specifications 
        length c = 2
        length s1 = 11
        length s2 = 11
        length s3 = 11
        length s4 = 11
        length t = 3

        # Resting complexes 
        G_g2_w2_3 = c s3 c( t( c( s2( c( + c* t* ) ) ) ) )
        G_w4_2_g2 = c( s2( c( t( c( s4 c + ) ) ) ) ) t* c*

        I12_223 = c s2 c t( c( s1 c + ) ) c*( s2*( c*( t*( c*( + c s3 ) ) ) ) )
        B12_223 = c( s2( c( t( c( s1 c + ) ) ) ) ) t*( c*( + c s3 ) ) c s2 c
        I12_422 = c s2 c( t( c s1 c + c( s2( c( t( c( s4 c + ) ) ) ) ) ) )

        w1_2 = c s2 c t c s1 c
        w2_3 = c s3 c t c s2 c
        w4_2 = c s2 c t c s4 c
        """)
        G223 = complexes['G_g2_w2_3']
        G422 = complexes['G_w4_2_g2']
        w12 = complexes['w1_2']
        w23 = complexes['w2_3']
        w42 = complexes['w4_2']
        I12_223 = complexes['I12_223']
        I12_422 = complexes['I12_422']

        out = bind21(w12, G223, max_helix=True)
        self.assertEqual(len(out), 4)
        self.assertTrue(I12_223 in r.products for r in out)

        out = bind21(w12, G422, max_helix=True)
        self.assertEqual(len(out), 4)
        self.assertTrue(I12_422 in r.products for r in out)

        out = branch_3way(I12_223, max_helix=True)
        self.assertEqual(len(out), 4)
        self.assertTrue(B12_422 in r.products for r in out)

        out = branch_3way(I12_422, max_helix=True)
        assert len(out) == 4
    def test_open1N_02(self):
        # NOTE this used to be a test for breathing ...
        # Should release-cutoff of 4 mean:
        #   "max-helix-semantics up to length 4"?
        complexes, reactions = read_pil("""
        length a = 3
        length b = 1
        length c = 4
        length ab = 4

        X = a( b( c( + ) ) )
        Y = ab( c( + ) )

        S1 = a b c 
        S2 = c* b* a*
        X1 = a b( c( + ) )  a*
        X2 = a( b  c( + ) b* )
        X3 = a( b( c + c* ) )
        Y1 = ab c( + ) ab*
        Y2 = ab( c + c* )
        """)
        X = complexes['X']
        Y = complexes['Y']
        S1 = complexes['S1']
        S2 = complexes['S2']
        X1 = complexes['X1']
        X2 = complexes['X2']
        X3 = complexes['X3']
        Y1 = complexes['Y1']
        Y2 = complexes['Y2']

        rxn1 = PepperReaction([X], [X1], 'open')
        rxn2 = PepperReaction([X], [X2], 'open')
        rxn3 = PepperReaction([X], [X3], 'open')
        out = open1N(X, max_helix=False, release_11=6, release_1N=6)
        assert sorted(out) == sorted([rxn1, rxn2, rxn3])

        rxn4 = PepperReaction([X], [S1, S2], 'open')
        out = open1N(X, max_helix=True, release_11=8, release_1N=8)
        assert out == [rxn4]

        out = open1N(Y, max_helix=True, release_11=6, release_1N=6)
        assert out == []
    def testLoop_fail(self):
        complexes, _ = read_pil("C = 1 2 3() + 4")

        parts = []
        domain_length = 0
        complex = complexes['C']

        # do NOT skip the closing helical domain
        for loc in [(0, 0), (0, 1), (0, 2), (0, 3), None, (1, 0)]:
            if loc is None:
                parts.append(None)
                continue

            domain = complex.get_domain(loc)
            parts.append((domain, complex.get_structure(loc), loc))

        # construct a loop from parts
        with self.assertRaises(PeppercornUsageError):
            loop = Loop(parts)
 def test_3way_multiple_choice_02(self):
     complexes, reactions = read_pil("""
     length a = 10
     length b = 10
     length c = 10
     length x = 10
     length y = 10
     length z = 10
     N = a( x( b x y + y( z( + ) ) ) )
     P1 = a( x b x( y + y( z( + ) ) ) )
     P2 = a( x( b x y( + y z( + ) ) ) )
     """)
     N = complexes['N']
     P1 = complexes['P1']
     P2 = complexes['P2']
     forward1 = PepperReaction([N], [P1], 'branch-3way')
     forward2 = PepperReaction([N], [P2], 'branch-3way')
     output = branch_3way(N, max_helix=True, remote=True)
     self.assertEqual(sorted(output), sorted([forward1, forward2]))