def test_CondenseGraphCRN_03(self):
        complexes = self.complexes
        reactions = self.reactions
        cplx = self.cplx
        rxn = self.rxn
        rs = self.rs

        rxn('X -> T1', k=0.1)
        rxn('T1 -> T2')
        rxn('T2 -> T1')
        rxn('T1 -> A')
        rxn('T1 -> B')
        rxn('T2 -> T3')
        rxn('T3 -> D')
        rxn('T3 -> C')

        enum = Enumerator(complexes.values(), list(reactions))
        enum.k_fast = 0.5
        enum.dry_run()

        enumRG = PepperCondensation(enum)
        enumRG.condense()

        self.assertEqual(sorted(enumRG.resting_sets),
                         sorted([rs('X'),
                                 rs('A'),
                                 rs('B'),
                                 rs('C'),
                                 rs('D')]))

        self.assertEqual(enumRG.get_fates(cplx('X')), SetOfFates([[rs('X')]]))

        self.assertEqual(
            enumRG.get_fates(cplx('T1')),
            SetOfFates([[rs('A')], [rs('B')], [rs('C')], [rs('D')]]))
    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_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)
    def test_cooperative_binding(self):
        # cooperative binding with k-fast 25
        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
        """)
        L = complexes['L']
        C = complexes['C']
        R = complexes['R']
        T = complexes['T']
        LR = complexes['LR']
        LC = complexes['LC']
        CR = complexes['CR']
        CRF = complexes['CRF']
        LCF = complexes['LCF']
        LCR = complexes['LCR']
        LCRF1 = complexes['LCRF1']
        LCRF2 = complexes['LCRF2']

        # always resting sets
        rs1 = PepperMacrostate([L], memorycheck=False)
        rs2 = PepperMacrostate([C], memorycheck=False)
        rs3 = PepperMacrostate([R], memorycheck=False)
        rs4 = PepperMacrostate([T], memorycheck=False)
        rs5 = PepperMacrostate([LR], memorycheck=False)

        rs6 = PepperMacrostate([CR, CRF], memorycheck=False)
        rs7 = PepperMacrostate([LC, LCF], memorycheck=False)

        cplx_to_fate = {  # maps Complex to its SetOfFates
            L: SetOfFates([[rs1]]),
            C: SetOfFates([[rs2]]),
            R: SetOfFates([[rs3]]),
            T: SetOfFates([[rs4]]),
            LR: SetOfFates([[rs5]]),
            CR: SetOfFates([[rs6]]),
            CRF: SetOfFates([[rs6]]),
            LC: SetOfFates([[rs7]]),
            LCF: SetOfFates([[rs7]]),
            #NOTE: only rs4 and rs5 bec. the other unimolecular reactions are now slow!!
            LCR: SetOfFates([[rs4, rs5]]),
            LCRF1: SetOfFates([[rs4, rs5]]),
            LCRF2: SetOfFates([[rs4, rs5]])
        }

        cr1 = PepperReaction([rs1, rs2], [rs7],
                             'condensed',
                             rate=1.5e6,
                             memorycheck=False)
        cr2 = PepperReaction([rs2, rs3], [rs6],
                             'condensed',
                             rate=1.5e6,
                             memorycheck=False)

        # not sure how these rates were computed...
        cr1r = PepperReaction([rs7], [rs1, rs2],
                              'condensed',
                              rate=10.0,
                              memorycheck=False)
        cr2r = PepperReaction([rs6], [rs2, rs3],
                              'condensed',
                              rate=10.0,
                              memorycheck=False)
        cr3 = PepperReaction([rs1, rs6], [rs5, rs4],
                             'condensed',
                             rate=3e6 / 2,
                             memorycheck=False)
        cr4 = PepperReaction([rs3, rs7], [rs5, rs4],
                             'condensed',
                             rate=3e6 / 2,
                             memorycheck=False)

        enum = Enumerator(complexes.values(), reactions)

        enum.k_fast = 25

        #enum.enumerate() # or enum.dry_run()
        enum.dry_run()  # or enum.dry_run()

        enumRG = PepperCondensation(enum)
        enumRG.condense()

        # Works...
        self.assertEqual(enum.k_fast, enumRG.k_fast)
        self.assertEqual(sorted([rs1, rs2, rs3, rs4, rs5, rs6, rs7]),
                         sorted(enumRG.resting_sets))

        self.assertDictEqual(cplx_to_fate, enumRG.cplx_to_fate)
        self.assertEqual(sorted([cr1, cr1r, cr2, cr2r, cr3, cr4]),
                         sorted(enumRG.condensed_reactions))

        for (r1, r2) in zip(sorted([cr1, cr1r, cr2, cr2r, cr3, cr4]),
                            sorted(enumRG.condensed_reactions)):
            self.assertEqual(r1, r2)
            self.assertAlmostEqual(r1.rate, r2.rate)
    def test_zhang_cooperative_binding(self):
        complexes, reactions = read_pil("""
        # Figure 1 of David Yu Zhang, "Cooperative hybridization of oligonucleotides", JACS, 2012

        # File generated by peppercorn-v0.5.0

        # Domain Specifications 
        length d1 = 8
        length d2 = 18
        length d3 = 18
        length d4 = 8

        # Resting-set Complexes 
        C1 = d2( d3( + d4* ) ) d1* 
        L1 = d1( d2 + d2( d3( + d4* ) ) ) 
        L2 = d1( d2( + d2 d3( + d4* ) ) ) 
        Out = d2 d3 
        R1 = d2( d3( + d3 d4( + ) ) ) d1* 
        R2 = d2( d3 + d3( d4( + ) ) ) d1* 
        T1 = d1 d2 
        T2 = d3 d4 
        Waste = d1( d2( + d3( d4( + ) ) ) ) 

        # Transient Complexes 
        L1R1 = d1( d2 + d2( d3( + d3 d4( + ) ) ) ) 
        L1R2 = d1( d2 + d2( d3 + d3( d4( + ) ) ) ) 
        L2R1 = d1( d2( + d2 d3( + d3 d4( + ) ) ) ) 

        # Detailed Reactions 
        reaction [bind21         =      2.4e+06 /M/s ] C1 + T2 -> R1
        reaction [bind21         =      2.4e+06 /M/s ] L1 + T2 -> L1R1
        reaction [branch-3way    =      18.5185 /s   ] L1 -> L2
        reaction [branch-3way    =      18.5185 /s   ] L1R1 -> L1R2
        reaction [branch-3way    =      18.5185 /s   ] L1R1 -> L2R1
        reaction [branch-3way    =      18.5185 /s   ] L1R2 -> L1R1
        reaction [branch-3way    =      18.5185 /s   ] L1R2 -> Waste + Out
        reaction [bind21         =      2.4e+06 /M/s ] L2 + T2 -> L2R1
        reaction [branch-3way    =      18.5185 /s   ] L2 -> L1
        reaction [branch-3way    =      18.5185 /s   ] L2R1 -> L1R1
        reaction [branch-3way    =      18.5185 /s   ] L2R1 -> Waste + Out
        reaction [branch-3way    =      18.5185 /s   ] R1 -> R2
        reaction [branch-3way    =      18.5185 /s   ] R2 -> R1
        reaction [bind21         =      2.4e+06 /M/s ] T1 + C1 -> L1
        reaction [bind21         =      2.4e+06 /M/s ] T1 + R1 -> L1R1
        reaction [bind21         =      2.4e+06 /M/s ] T1 + R2 -> L1R2
        """)

        enum = Enumerator(complexes.values(), reactions)
        enum.k_fast = 0.01
        enum.release_cutoff = 10
        #enum.enumerate() # or enum.dry_run()
        enum.dry_run()

        enumRG = PepperCondensation(enum)
        enumRG.condense()
        """
        macrostate rC1 = [C1]
        macrostate rL2 = [L2, L1]
        macrostate rOut = [Out]
        macrostate rR1 = [R1, R2]
        macrostate rT1 = [T1]
        macrostate rT2 = [T2]
        macrostate rWaste = [Waste]

        reaction [condensed      =      2.4e+06 /M/s ] rT1 + rC1 -> rL2
        reaction [condensed      =      2.4e+06 /M/s ] rL2 + rT2 -> rWaste + rOut
        reaction [condensed      =      2.4e+06 /M/s ] rC1 + rT2 -> rR1
        reaction [condensed      =      2.4e+06 /M/s ] rT1 + rR1 -> rWaste + rOut
        reaction [condensed      =   0.00316623 /s   ] rL2 -> rT1 + rC1
        reaction [condensed      =   0.00316623 /s   ] rR1 -> rC1 + rT2
        """

        L1 = complexes['L1']
        L2 = complexes['L2']
        rL2 = PepperMacrostate([L2, L1], memorycheck=False)
        Out = complexes['Out']
        rOut = PepperMacrostate([Out], memorycheck=False)
        Waste = complexes['Waste']
        rWaste = PepperMacrostate([Waste], memorycheck=False)
        T2 = complexes['T2']
        rT2 = PepperMacrostate([T2], memorycheck=False)

        # calculated by hand...
        cr1 = PepperReaction([rL2, rT2], [rWaste, rOut],
                             'condensed',
                             rate=2.4e6,
                             memorycheck=False)

        found = False
        for r in enumRG.condensed_reactions:
            if r == cr1:
                found = True
                self.assertAlmostEqual(r.rate, cr1.rate)

        self.assertTrue(found)
Пример #6
0
    def test_zhang_cooperative_binding(self):
        complexes, reactions = read_pil("""
        # Figure 1 of David Yu Zhang, "Cooperative hybridization of oligonucleotides", JACS, 2012

        # File generated by peppercorn-v0.5.0

        # Domain Specifications 
        length d1 = 8
        length d2 = 18
        length d3 = 18
        length d4 = 8

        # Resting-set Complexes 
        C1 = d2( d3( + d4* ) ) d1* 
        L1 = d1( d2 + d2( d3( + d4* ) ) ) 
        L2 = d1( d2( + d2 d3( + d4* ) ) ) 
        Out = d2 d3 
        R1 = d2( d3( + d3 d4( + ) ) ) d1* 
        R2 = d2( d3 + d3( d4( + ) ) ) d1* 
        T1 = d1 d2 
        T2 = d3 d4 
        Waste = d1( d2( + d3( d4( + ) ) ) ) 

        # Transient Complexes 
        L1R1 = d1( d2 + d2( d3( + d3 d4( + ) ) ) ) 
        L1R2 = d1( d2 + d2( d3 + d3( d4( + ) ) ) ) 
        L2R1 = d1( d2( + d2 d3( + d3 d4( + ) ) ) ) 

        # Detailed Reactions 
        reaction [bind21         =      2.4e+06 /M/s ] C1 + T2 -> R1
        reaction [bind21         =      2.4e+06 /M/s ] L1 + T2 -> L1R1
        reaction [branch-3way    =      18.5185 /s   ] L1 -> L2
        reaction [branch-3way    =      18.5185 /s   ] L1R1 -> L1R2
        reaction [branch-3way    =      18.5185 /s   ] L1R1 -> L2R1
        reaction [branch-3way    =      18.5185 /s   ] L1R2 -> L1R1
        reaction [branch-3way    =      18.5185 /s   ] L1R2 -> Waste + Out
        reaction [bind21         =      2.4e+06 /M/s ] L2 + T2 -> L2R1
        reaction [branch-3way    =      18.5185 /s   ] L2 -> L1
        reaction [branch-3way    =      18.5185 /s   ] L2R1 -> L1R1
        reaction [branch-3way    =      18.5185 /s   ] L2R1 -> Waste + Out
        reaction [branch-3way    =      18.5185 /s   ] R1 -> R2
        reaction [branch-3way    =      18.5185 /s   ] R2 -> R1
        reaction [bind21         =      2.4e+06 /M/s ] T1 + C1 -> L1
        reaction [bind21         =      2.4e+06 /M/s ] T1 + R1 -> L1R1
        reaction [bind21         =      2.4e+06 /M/s ] T1 + R2 -> L1R2
        """)

        enum = Enumerator(complexes.values(), reactions)
        enum.k_fast = 0.01 
        enum.release_cutoff = 10
        enum.enumerate() # or enum.dry_run()

        enumRG = PepperCondensation(enum)
        enumRG.condense()
        
        """
        macrostate rC1 = [C1]
        macrostate rL2 = [L2, L1]
        macrostate rOut = [Out]
        macrostate rR1 = [R1, R2]
        macrostate rT1 = [T1]
        macrostate rT2 = [T2]
        macrostate rWaste = [Waste]

        reaction [condensed      =      2.4e+06 /M/s ] rT1 + rC1 -> rL2
        reaction [condensed      =      2.4e+06 /M/s ] rL2 + rT2 -> rWaste + rOut
        reaction [condensed      =      2.4e+06 /M/s ] rC1 + rT2 -> rR1
        reaction [condensed      =      2.4e+06 /M/s ] rT1 + rR1 -> rWaste + rOut
        reaction [condensed      =   0.00316623 /s   ] rL2 -> rT1 + rC1
        reaction [condensed      =   0.00316623 /s   ] rR1 -> rC1 + rT2
        """
        
        try:
            L1 = complexes['L1']
            L2 = complexes['L2']
            L = PepperMacrostate([L1, L2])
        except SingletonError as err:
            L = err.existing
        O = PepperMacrostate([complexes['Out']])
        W = PepperMacrostate([complexes['Waste']])
        T = PepperMacrostate([complexes['T2']])

        # calculated by hand...
        cr1 = PepperReaction([L, T], [W, O], 'condensed')
        assert cr1 in enumRG.condensed_reactions
        assert cr1.rate_constant == (2.4e6, '/M/s')
    def test_max_helix_01(self):
        complexes, reactions = read_pil("""
        length a = 15
        length x = 15
        length x1 = 15
        length x2 = 15
        length y = 15
        length y1 = 15
        length y2 = 15
        length z = 15
        length z1 = 15
        length z2 = 15

        # should be one reaction, is one
        A1 = x( y z + y( z( + ) ) )
        A1_2 = x( y( z( + ) ) )
        YZ = y z

        # should be one reactions, is one
        B1 = x1( x2( y1 y2 z1 z2 + y1( y2( z1( z2( + ) ) ) ) ) ) 
        B1_2 = x1( x2( y1( y2( z1( z2( + ) ) ) ) ) ) 
        YZ2 = y1 y2 z1 z2

        # should be two reactions, is two
        A2   = x( y z + y( + z( + ) ) )
        A2_1 = x( y( z + z( + ) ) )
        #A2_2 = x( y( z( + ) ) ) # = A1_2
        Y1 = y
        Z1 = z

        # should be two reactions, is two
        B2 = x1( x2( y1 y2 z1 z2 + y1( y2( + z1( z2( + ) ) ) ) ) ) 
        B2_1 = x1( x2( y1( y2( z1 z2 + z1( z2( + ) ) ) ) ) ) 
        Y2 = y1 y2
        Z2 = z1 z2

        # should be two reactions, is two
        C = x( y z + y( + a( + ) z( + ) ) )
        C1 = x( y( z + a( + ) z( + ) ) )
        r1 = a( + ) z

        """)

        A1 = complexes['A1']
        A1_2 = complexes['A1_2']
        YZ = complexes['YZ']

        A2 = complexes['A2']
        A2_1 = complexes['A2_1']
        #A2_2 = complexes['A2_2']
        Y1 = complexes['Y1']
        Z1 = complexes['Z1']

        enum = Enumerator([A1, A2])
        enum.k_fast = 0
        enum.k_slow = 0
        enum.max_helix = True
        enum.enumerate()

        path1 = PepperReaction([A1], sorted([A1_2, YZ]), 'branch-3way')
        path2 = PepperReaction([A2], sorted([A2_1, Y1]), 'branch-3way')
        path3 = PepperReaction([A2_1], sorted([A1_2, Z1]), 'branch-3way')
        self.assertEqual(sorted(enum.reactions), sorted([path1, path2, path3]))

        B1 = complexes['B1']
        B1_2 = complexes['B1_2']
        YZ2 = complexes['YZ2']

        B2 = complexes['B2']
        B2_1 = complexes['B2_1']
        Y2 = complexes['Y2']
        Z2 = complexes['Z2']

        enum = Enumerator([B1, B2])
        enum.k_fast = 0
        enum.k_slow = 0
        enum.max_helix = True
        enum.enumerate()

        path1 = PepperReaction([B1], sorted([B1_2, YZ2]), 'branch-3way')
        path2 = PepperReaction([B2], sorted([B2_1, Y2]), 'branch-3way')
        path3 = PepperReaction([B2_1], sorted([B1_2, Z2]), 'branch-3way')
        self.assertEqual(sorted(enum.reactions), sorted([path1, path2, path3]))

        C = complexes['C']
        enum = Enumerator([C])
        enum.k_fast = 0
        enum.k_slow = 0
        enum.max_helix = True
        enum.enumerate()
        self.assertEqual(len(list(enum.reactions)), 2)