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 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 testOpenB(self):
        # open:  ? a( ? ) ? -> ? a ? a* ?
        complexes, _ = read_pil("""
        length a = 5
        length b = 5
        length x = 15
        length y = 15
        length z = 15

        A1 = x a( y )   z
        A2 = x a  y a* z

        A3 = x a( b( y )  )  z
        A4 = x a  b( y )  a* z
        A5 = x a( b  y b* )  z
        """)

        # No zipping possible
        rxns = open1N(complexes['A1'],
                      max_helix=False,
                      release_11=7,
                      release_1N=7)
        self.assertEqual(
            rxns,
            [PepperReaction([complexes['A1']], [complexes['A2']], 'open')])

        # Zipping possible
        rxns = open1N(complexes['A3'],
                      max_helix=False,
                      release_11=7,
                      release_1N=7)
        self.assertEqual(
            rxns,
            sorted([
                PepperReaction([complexes['A3']], [complexes['A4']], 'open'),
                PepperReaction([complexes['A3']], [complexes['A5']], 'open')
            ]))
    def testOpenA(self):
        # open:  ? a( ? ) ? -> ? a ? a* ?
        complexes, _ = read_pil("""
        length a = 5
        length b = 5
        length x = 15
        length y = 15
        length z = 15

        A1 = x( ) a( x )  x( )
        A2 = x( ) a  x a* x( )
        A3 = x a( b( y )  )  z
        A4 = x a  b  y b* a* z
        """)

        # No zipping possible
        self.assertEqual(
            open1N(complexes['A1']),
            [PepperReaction([complexes['A1']], [complexes['A2']], 'open')])

        # Zipping possible
        self.assertEqual(
            open1N(complexes['A3'], release_11=13, release_1N=13),
            [PepperReaction([complexes['A3']], [complexes['A4']], 'open')])
    def testOpenNoMaxHelix(self):
        # open:  ? a( ? ) ? -> ? a ? a* ?
        complexes, _ = read_pil("""
        length a = 5
        length b = 5

        # A1 = a( b( ) )
        A1 = a( b( ) )
        A2 = a( b b* )
        A3 = a b( ) a*
        """)

        # Zipping possible
        rxns = open1N(complexes['A1'],
                      max_helix=False,
                      release_11=10,
                      release_1N=10)
        self.assertEqual(
            rxns,
            sorted([
                PepperReaction([complexes['A1']], [complexes['A2']], 'open'),
                PepperReaction([complexes['A1']], [complexes['A3']], 'open')
            ]))