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 testBranch4wayA(self):
        # 4way: b( ? ) ? b ( ? ) --> b( ? b*( ? ) ? )
        complexes, _ = read_pil("""
        length b = 15
        length d1 = 15
        length d2 = 15
        length d3 = 15
        length d4 = 15
        length d5 = 15
        A1 = d1( ) b( d2( )  )  d3( ) b( d4( ) ) d5( )
        A2 = d1( ) b( d2( ) b*( d3( ) )  d4( ) ) d5( )
        """)

        forward = branch_4way(complexes['A1'])
        self.assertEqual(forward, [
            PepperReaction([complexes['A1']], [complexes['A2']], 'branch-4way')
        ])

        reverse = branch_4way(complexes['A2'])
        self.assertEqual(reverse, [
            PepperReaction([complexes['A2']], [complexes['A1']], 'branch-4way')
        ])
 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]
    def test_4way_04(self):
        # Standard 4way junction, no end-dissociation
        complexes, reactions = read_pil("""
        length a = 10
        length b = 10
        length c = 10
        length x = 10
        length y = 10
        A1 = a( b( c( + ) ) x*( + ) b( c( y( + ) ) ) )
        A2 = a( b( c( + ) b*( x*( + ) ) c( y( + ) ) ) )
        A3 = a( b( c( + c*( b*( x*( + ) ) ) y( + ) ) ) )
        """)
        A1 = complexes['A1']
        A2 = complexes['A2']
        A3 = complexes['A3']

        path = PepperReaction([A1], [A2], 'branch-4way')
        output = branch_4way(A1, max_helix=False)
        self.assertEqual(output, [path])

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

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

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

        path = PepperReaction([A3], [A1], 'branch-4way')
        output = branch_4way(A3, max_helix=True)
        self.assertEqual(output, [path])
 def test_4way_02(self):
     complexes, reactions = read_pil("""
     length a = 10
     length b = 10
     length c = 10
     length x = 10
     length y = 10
     length Y1 = 10
     length Y2 = 10
     length X1 = 10
     length X2 = 10
     B = y*( b*( a*( Y1* + ) b( c( + ) ) Y2* Y1*( + ) a ) )
     A = c* b* X2* X1*( + ) X2 b c y*( b*( a*( Y1* + ) b( c( + ) ) Y2* Y1*( + ) a ) )
     R = c* b* X2* X1*( + ) X2 b c y*( b*( a*( Y1* + ) ) c( + ) b*( Y2* Y1*( + ) a ) )
     """)
     A = complexes['A']
     R = complexes['R']
     fw = PepperReaction([A], [R], 'branch-4way')
     bw = PepperReaction([R], [A], 'branch-4way')
     out = branch_4way(A, max_helix=True, remote=True)
     assert out == [fw]
     #for o in out: print(o, o.kernel_string)
     out = branch_4way(R, max_helix=True, remote=True)
     assert out == [bw]
 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_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 dtest_branch4_way_long(self):
        # Unconventional multi-state 4way junction, no end-dissociation
        complexes, reactions = read_pil("""
        length a = 10
        length b = 10
        length c = 10
        length d = 10
        length e = 10
        length f = 10
        length g = 10
        length h = 10
        length x = 10
        length y = 10
        length z = 10
        A1 = a( x*( y*( z*( b z( y( x( c( + ) ) ) ) d z( y( x( e( + ) ) ) ) f z( y( x( g( + ) ) ) ) h ) ) ) )

        A2 = a( x*( y*( z*( b ) y( x( c( + ) ) ) z*( d z( y( x( e( + ) ) ) ) f z( y( x( g( + ) ) ) ) h ) ) ) )
        A3 = a( x*( y*( z*( b z( y( x( c( + ) ) ) ) d ) y( x( e( + ) ) ) z*( f z( y( x( g( + ) ) ) ) h ) ) ) )
        A4 = a( x*( y*( z*( b z( y( x( c( + ) ) ) ) d z( y( x( e( + ) ) ) ) f ) y( x( g( + ) ) ) z*( h ) ) ) )
        A5 = a( x*( y*( z*( b z( y( x( c( + ) ) ) ) d z( y( x( e( + ) ) ) z*( f ) y( x( g( + ) ) ) ) h ) ) ) )
        A6 = a( x*( y*( z*( b z( y( x( c( + ) ) ) z*( d ) y( x( e( + ) ) ) ) f z( y( x( g( + ) ) ) ) h ) ) ) )
        A7 = a( x*( y*( z*( b z( y( x( c( + ) ) ) z*( d z( y( x( e( + ) ) ) ) f ) y( x( g( + ) ) ) ) h ) ) ) )

        A2m = a( x*( y*( z*( b ) ) ) c( + ) x*( y*( z*( d z( y( x( e( + ) ) ) ) f z( y( x( g( + ) ) ) ) h ) ) ) )
        A3m = a( x*( y*( z*( b z( y( x( c( + ) ) ) ) d ) ) ) e( + ) x*( y*( z*( f z( y( x( g( + ) ) ) ) h ) ) ) )
        A4m = a( x*( y*( z*( b z( y( x( c( + ) ) ) ) d z( y( x( e( + ) ) ) ) f ) ) ) g( + ) x*( y*( z*( h ) ) ) )
        A5m = a( x*( y*( z*( b z( y( x( c( + ) ) ) ) d z( y( x( e( + ) x*( y*( z*( f ) ) ) g( + ) ) ) ) h ) ) ) )
        A6m = a( x*( y*( z*( b z( y( x( c( + ) x*( y*( z*( d ) ) ) e( + ) ) ) ) f z( y( x( g( + ) ) ) ) h ) ) ) )
        A7m = a( x*( y*( z*( b z( y( x( c( + ) x*( y*( z*( d z( y( x( e( + ) ) ) ) f ) ) ) g( + ) ) ) ) h ) ) ) )
        """)
        A1 = complexes['A1']
        A2 = complexes['A2']
        A3 = complexes['A3']
        A4 = complexes['A4']
        A5 = complexes['A5']
        A6 = complexes['A6']
        A7 = complexes['A7']
        A2m = complexes['A2m']
        A3m = complexes['A3m']
        A4m = complexes['A4m']
        A5m = complexes['A5m']
        A6m = complexes['A6m']
        A7m = complexes['A7m']

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

        path1 = PepperReaction([A1], [A2m], 'branch-4way')
        path2 = PepperReaction([A1], [A3m], 'branch-4way')
        path3 = PepperReaction([A1], [A4m], 'branch-4way')
        path4 = PepperReaction([A1], [A5m], 'branch-4way')
        path5 = PepperReaction([A1], [A6m], 'branch-4way')
        path6 = PepperReaction([A1], [A7m], 'branch-4way')
        output = branch_4way(A1, max_helix=True)
        self.assertEqual(sorted(output),
                         sorted([path1, path2, path3, path4, path5, path6]))