コード例 #1
0
class BondSetSelectorTests(BondSetSelectorBaseTests):


    def setUp(self):
        self.mols = Read('Data/stringSel.pdb')
        for m in self.mols:
            m.buildBondsByDistance()
        self.bonds = self.mols.chains.residues.atoms.bonds[0]
        self.stringSel = BondSetSelector()
    

    def tearDown(self):
        """
        clean-up
        """
        del(self.bonds)
        del(self.mols)


    def test_select_with_empty_string(self):
        """
         test result with empty string returns all bonds
        """
        result, msg = self.stringSel.select(self.bonds, "")
        self.assertEquals(result, self.bonds)


    def test_select_end(self):
        """
         test select with '$'  returns last item
        """
        result, msg = self.stringSel.select(self.bonds, "$")
        self.assertEquals(result[-1], self.bonds[-1])


    def test_select_with_valid_index(self):
        """
         test string with valid_index returns set with 1 item 
        """
        selString = "0"
        result, msg = self.stringSel.select(self.bonds, selString)
        self.assertEquals(len(result), 1)
        self.assertEquals(result[0], self.bonds[0])


    def test_select_with_invalid_index_returns_empty_set(self):
        """
         test string with invalid_index returns empty set
        """
        selString = "400"
        result, msg = self.stringSel.select(self.bonds, selString)
        self.assertEqual(result.__class__, self.bonds.__class__)
        self.assertEqual(len(result), 0)
        self.assertEqual(msg[0], selString)


    def test_select_with_valid_range(self):
        """
         test string with valid_range returns set with 2 items
        """
        selString = "0-1"
        result, msg = self.stringSel.select(self.bonds, selString)
        self.assertEquals(len(result), 2)


    def test_select_with_invalid_range(self):
        """
         test string with invalid_range returns set with 0 items 
        """
        selString = "400-623"
        result, msg = self.stringSel.select(self.bonds, selString)
        self.assertEquals(len(result), 0)


    def test_select_with_valid_lambda_exp(self):
        """
         test string with valid_lambda_exp returns set with items
         <this regex is intended to select all bonds involving NE2>
        """
        selString = "lambda x: x.atom1.name=='NE2' or x.atom2.name=='NE2'"
        result, msg = self.stringSel.select(self.bonds, selString)
        #print "result=", result
        self.assertEquals(len(result), 1)


    def test_no_select_with_valid_regex_2(self):
        """
         bondSelector does not support regex
         test string with valid_regex returns set with 0 items
        """
        selString = "[1-2]"
        result, msg = self.stringSel.select(self.bonds, selString)
        self.assertEquals(len(result), 0)


    def test_select_valid_set(self):
        """
         test string with valid set name returns 1 set
        """
        these_sets = Sets()
        key = 'first'
        these_sets.add(key, self.bonds[1:])
        selString = key
        result, msg = self.stringSel.select(self.bonds, selString, 
                                        sets=these_sets)
        #print "result=", result
        self.assertEquals(len(result), 23)
        self.assertEquals(result, self.bonds[1:])
コード例 #2
0
 def setUp(self):
     self.mols = Read('Data/stringSel.pdb')
     for m in self.mols:
         m.buildBondsByDistance()
     self.bonds = self.mols.chains.residues.atoms.bonds[0]
     self.stringSel = BondSetSelector()
コード例 #3
0
 def test_constructor(self):
     """
     instantiate an BondSetSelector
     """
     stringSel = BondSetSelector()
     self.assertEquals(stringSel.__class__, BondSetSelector)