def test_select_add_mols_allAtoms(self):
     """
     test selecting with stringRepr of atoms of added mols
     """
     stringSel = CompoundStringSelector()
     selString = self.mols.allAtoms.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, self.mols.allAtoms)
     self.assertEquals(selString, "stringSel:::/+/protease:::")
 def test_select_subtract_allAtoms(self):
     """
     test selecting with stringRepr of subtracted allAtoms
     """
     stringSel = CompoundStringSelector()
     diff_atoms = self.mols.allAtoms - self.mols1.allAtoms
     selString = diff_atoms.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_atoms)
     self.assertEquals(selString, "stringSel:::/+/protease:::/-/stringSel:::")
Example #3
0
 def test_select_subtract_chains(self):
     """
     test selecting with stringRepr of subtracted chains
     """
     stringSel = CompoundStringSelector()
     diff_chains = self.mols.chains - self.mols1.chains
     selString = diff_chains.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_chains)
     self.assertEquals(selString, "stringSel:/+/protease:/-/stringSel:")
 def test_select_subtract_residues(self):
     """
     test selecting with stringRepr of subtracted residues
     """
     stringSel = CompoundStringSelector()
     diff_residues = self.mols.chains.residues - self.mols1.chains.residues
     selString = diff_residues.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_residues)
     self.assertEquals(selString, "stringSel::/+/protease::/-/stringSel::")
Example #5
0
 def test_select_add_mols_atoms(self):
     """
     test selecting with stringRepr of atoms of added mols
     """
     stringSel = CompoundStringSelector()
     selString = self.mols.chains.residues.atoms.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, self.mols.chains.residues.atoms)
     #print "selString=", selString
     self.assertEquals(selString, "stringSel:::/+/protease:::")
Example #6
0
 def test_select_subtract_mols(self):
     """
     test selecting with stringRepr of subtracted mols
     """
     stringSel = CompoundStringSelector()
     diff_mols = self.mols - self.mols1
     selString = diff_mols.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_mols)
     self.assertEquals(selString, "stringSel/+/protease/-/stringSel")
 def test_select_subtract_mols(self):
     """
     test selecting with stringRepr of subtracted mols
     """
     stringSel = CompoundStringSelector()
     diff_mols = self.mols - self.mols1
     selString = diff_mols.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_mols)
     self.assertEquals(selString, "stringSel/+/protease/-/stringSel")
Example #8
0
 def test_select_xor_mols_all(self):
     """
     test selecting with stringRepr of xor mols returning all
     """
     stringSel = CompoundStringSelector()
     diff_mols = self.mols1 ^ self.mols2
     selString = diff_mols.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_mols)
     self.assertEquals(selected, self.mols)
     self.assertEquals(selString, "stringSel/^/protease")
Example #9
0
 def test_select_intersect_allAtoms(self):
     """
     test selecting with stringRepr of intersected allAtoms
     """
     stringSel = CompoundStringSelector()
     diff_atoms = self.mols1.allAtoms & self.mols2.allAtoms
     selString = diff_atoms.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_atoms)
     self.assertEquals(selected, AtomSet())
     self.assertEquals(selString, "stringSel:::/&/protease:::")
Example #10
0
 def test_select_intersect_residues_empty(self):
     """
     test selecting with stringRepr of empty intersected residues
     """
     stringSel = CompoundStringSelector()
     diff_residues = self.mols1.chains.residues & self.mols2.chains.residues
     selString = diff_residues.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_residues)
     self.assertEquals(selected, ResidueSet())
     self.assertEquals(selString, "stringSel::/&/protease::")
 def test_select_intersect_allAtoms(self):
     """
     test selecting with stringRepr of intersected allAtoms
     """
     stringSel = CompoundStringSelector()
     diff_atoms = self.mols1.allAtoms & self.mols2.allAtoms
     selString = diff_atoms.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_atoms)
     self.assertEquals(selected, AtomSet())
     self.assertEquals(selString, "stringSel:::/&/protease:::")
Example #12
0
 def test_select_union_atoms_all(self):
     """
     test selecting with stringRepr of union 2X atoms returning single copy
     """
     stringSel = CompoundStringSelector()
     diff_atoms = self.mols1.chains.residues.atoms | self.mols1.chains.residues.atoms
     selString = diff_atoms.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_atoms)
     self.assertEquals(selected, self.mols1.chains.residues.atoms)
     self.assertEquals(selString, "stringSel:::")
Example #13
0
 def test_select_union_mols_single(self):
     """
     test selecting with stringRepr of union 2X same mols returning single
     """
     stringSel = CompoundStringSelector()
     diff_mols = self.mols1 | self.mols1
     selString = diff_mols.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_mols)
     self.assertEquals(selected, self.mols1)
     self.assertEquals(selString, "stringSel")
Example #14
0
 def test_select_union_residues(self):
     """
     test selecting with stringRepr of union residues
     """
     stringSel = CompoundStringSelector()
     diff_residues = self.mols.chains.residues | self.mols1.chains.residues
     selString = diff_residues.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_residues)
     self.assertEquals(selected, self.mols.chains.residues)
     self.assertEquals(selString, "stringSel::/+/protease::/|/stringSel::")
Example #15
0
 def test_select_xor_residues_all(self):
     """
     test selecting with stringRepr of xor residues returning all
     """
     stringSel = CompoundStringSelector()
     diff_residues = self.mols1.chains.residues ^ self.mols2.chains.residues
     selString = diff_residues.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_residues)
     self.assertEquals(selected, self.mols.chains.residues)
     self.assertEquals(selString, "stringSel::/^/protease::")
Example #16
0
 def test_select_xor_allAtoms_all(self):
     """
     test selecting with stringRepr of xor allAtoms returning all
     """
     stringSel = CompoundStringSelector()
     diff_atoms = self.mols1.allAtoms ^ self.mols2.allAtoms
     selString = diff_atoms.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_atoms)
     self.assertEquals(selected, self.mols.allAtoms)
     self.assertEquals(selString, "stringSel:::/^/protease:::")
Example #17
0
 def test_select_subtract_allAtoms(self):
     """
     test selecting with stringRepr of subtracted allAtoms
     """
     stringSel = CompoundStringSelector()
     diff_atoms = self.mols.allAtoms - self.mols1.allAtoms
     selString = diff_atoms.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_atoms)
     self.assertEquals(selString,
                       "stringSel:::/+/protease:::/-/stringSel:::")
 def test_select_intersect_chains_empty(self):
     """
     test selecting with stringRepr of empty intersected chains
     """
     stringSel = CompoundStringSelector()
     diff_chains = self.mols1.chains & self.mols2.chains
     selString = diff_chains.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_chains)
     self.assertEquals(selected, ChainSet())
     self.assertEquals(selString, "stringSel:/&/protease:")
Example #19
0
 def test_select_intersect_mols_empty(self):
     """
     test selecting with stringRepr of empty intersect mols
     """
     stringSel = CompoundStringSelector()
     diff_mols = self.mols1 & self.mols2
     selString = diff_mols.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_mols)
     self.assertEquals(selString, "stringSel/&/protease")
     self.assertEquals(selected, ProteinSet())
Example #20
0
 def test_select_intersect_chains_empty(self):
     """
     test selecting with stringRepr of empty intersected chains
     """
     stringSel = CompoundStringSelector()
     diff_chains = self.mols1.chains & self.mols2.chains
     selString = diff_chains.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_chains)
     self.assertEquals(selected, ChainSet())
     self.assertEquals(selString, "stringSel:/&/protease:")
 def test_select_intersect_mols_empty(self):
     """
     test selecting with stringRepr of empty intersect mols
     """
     stringSel = CompoundStringSelector()
     diff_mols = self.mols1 & self.mols2
     selString = diff_mols.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_mols)
     self.assertEquals(selString, "stringSel/&/protease")
     self.assertEquals(selected, ProteinSet())
 def test_select_intersect_residues_empty(self):
     """
     test selecting with stringRepr of empty intersected residues
     """
     stringSel = CompoundStringSelector()
     diff_residues = self.mols1.chains.residues & self.mols2.chains.residues
     selString = diff_residues.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_residues)
     self.assertEquals(selected, ResidueSet())
     self.assertEquals(selString, "stringSel::/&/protease::")
 def test_select_union_atoms_all(self):
     """
     test selecting with stringRepr of union 2X atoms returning single copy
     """
     stringSel = CompoundStringSelector()
     diff_atoms = self.mols1.chains.residues.atoms | self.mols1.chains.residues.atoms
     selString = diff_atoms.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_atoms)
     self.assertEquals(selected, self.mols1.chains.residues.atoms)
     self.assertEquals(selString, "stringSel:::")
 def test_select_xor_atoms(self):
     """
     test selecting with stringRepr of xor atoms
     """
     stringSel = CompoundStringSelector()
     diff_atoms = self.mols.chains.residues.atoms ^ self.mols1.chains.residues.atoms
     selString = diff_atoms.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_atoms)
     self.assertEquals(selected, self.mols2.chains.residues.atoms)
     self.assertEquals(selString, "stringSel:::/+/protease:::/^/stringSel:::")
 def test_select_union_mols_single(self):
     """
     test selecting with stringRepr of union 2X same mols returning single
     """
     stringSel = CompoundStringSelector()
     diff_mols = self.mols1 | self.mols1
     selString = diff_mols.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_mols)
     self.assertEquals(selected, self.mols1)
     self.assertEquals(selString, "stringSel")
 def test_select_xor_chains(self):
     """
     test selecting with stringRepr of xor chains
     """
     stringSel = CompoundStringSelector()
     diff_chains = self.mols.chains ^ self.mols1.chains
     selString = diff_chains.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_chains)
     self.assertEquals(selected, self.mols2.chains)
     self.assertEquals(selString, "stringSel:/+/protease:/^/stringSel:")
 def test_select_xor_mols_all(self):
     """
     test selecting with stringRepr of xor mols returning all
     """
     stringSel = CompoundStringSelector()
     diff_mols = self.mols1 ^ self.mols2
     selString = diff_mols.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_mols)
     self.assertEquals(selected, self.mols)
     self.assertEquals(selString, "stringSel/^/protease")
 def test_select_xor_residues_all(self):
     """
     test selecting with stringRepr of xor residues returning all
     """
     stringSel = CompoundStringSelector()
     diff_residues = self.mols1.chains.residues ^ self.mols2.chains.residues
     selString = diff_residues.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_residues)
     self.assertEquals(selected, self.mols.chains.residues)
     self.assertEquals(selString, "stringSel::/^/protease::")
 def test_select_xor_allAtoms_all(self):
     """
     test selecting with stringRepr of xor allAtoms returning all
     """
     stringSel = CompoundStringSelector()
     diff_atoms = self.mols1.allAtoms ^ self.mols2.allAtoms
     selString = diff_atoms.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_atoms)
     self.assertEquals(selected, self.mols.allAtoms)
     self.assertEquals(selString, "stringSel:::/^/protease:::")
Example #30
0
 def test_select_subset_chains(self):
     """
     test selecting with stringRepr of subset of chains
     """
     stringSel = CompoundStringSelector()
     diff_chains = self.mols.chains.get('B')
     selString = "(stringSel:/+/protease:\\s\\B)"
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     #selected, msg = stringSel.select(self.mols, selString)
     self.assertEquals(selected, diff_chains)
     self.assertEquals(selected, self.mols.chains[-1:])
     self.assertEquals(selected.stringRepr, selString)
Example #31
0
 def test_select_xor_atoms(self):
     """
     test selecting with stringRepr of xor atoms
     """
     stringSel = CompoundStringSelector()
     diff_atoms = self.mols.chains.residues.atoms ^ self.mols1.chains.residues.atoms
     selString = diff_atoms.stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     self.assertEquals(selected, diff_atoms)
     self.assertEquals(selected, self.mols2.chains.residues.atoms)
     self.assertEquals(selString,
                       "stringSel:::/+/protease:::/^/stringSel:::")
Example #32
0
 def test_select_subset_mols(self):
     """
     test selecting with stringRepr for subset
     """
     stringSel = CompoundStringSelector()
     diff_mols = self.mols[-1:]
     selString = "(stringSel/+/protease\\s\\protease)"
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     #selected, msg = stringSel.select(self.mols, selString)
     self.assertEquals(selected, diff_mols)
     self.assertEquals(selected, self.mols[-1:])
     self.assertEquals(selected.stringRepr, selString)
 def test_select_subset_chains(self):
     """
     test selecting with stringRepr of subset of chains
     """
     stringSel = CompoundStringSelector()
     diff_chains = self.mols.chains.get('B')
     selString = "(stringSel:/+/protease:\\s\\B)"
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     #selected, msg = stringSel.select(self.mols, selString)
     self.assertEquals(selected, diff_chains)
     self.assertEquals(selected, self.mols.chains[-1:])
     self.assertEquals(selected.stringRepr, selString)
 def test_select_subset_mols(self):
     """
     test selecting with stringRepr for subset
     """
     stringSel = CompoundStringSelector()
     diff_mols = self.mols[-1:]
     selString = "(stringSel/+/protease\\s\\protease)"
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     #selected, msg = stringSel.select(self.mols, selString)
     self.assertEquals(selected, diff_mols)
     self.assertEquals(selected, self.mols[-1:])
     self.assertEquals(selected.stringRepr, selString)
Example #35
0
 def test_select_subset_allAtoms(self):
     """
     test selecting with stringRepr of subset allAtoms
     select the first atom in protease from mols.allAtoms
     """
     stringSel = CompoundStringSelector()
     diff_atoms = self.mols.allAtoms.get('0')
     selString = "(stringSel:::/+/protease:::\\s\\0)"
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     #selected, msg = stringSel.select(self.mols, selString)
     self.assertEquals(selected, diff_atoms)
     self.assertEquals(selected, self.mols.allAtoms[0:1])
     self.assertEquals(selected.stringRepr, selString)
 def test_select_set_from_string(self):
     """
      test result using key into Sets
     """
     sets = Sets()
     subset = self.mols.allAtoms[:3]
     set_name = 'first_three_atoms'
     sets.add(set_name, subset)
     selString = ':::' + set_name
     css = CompoundStringSelector()
     result, msg = css.select(self.mols, selString, sets=sets)
     self.assertEqual(result, subset)
     self.assertEquals(result.stringRepr, selString)
Example #37
0
 def test_select_subset_residues(self):
     """
     test selecting with stringRepr of subset residues
     """
     stringSel = CompoundStringSelector()
     #this is the name of the 7th residue in the first molecule
     diff_residues = self.mols.chains.residues.get("HOH617")
     selString = "(stringSel::/+/protease::\\s\\HOH617)"
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     #selected, msg = stringSel.select(self.mols, selString)
     self.assertEquals(selected, diff_residues)
     self.assertEquals(selected, self.mols.chains.residues[7:8])
     self.assertEquals(selected.stringRepr, selString)
Example #38
0
 def test_select_set_from_string(self):
     """
      test result using key into Sets
     """
     sets = Sets()
     subset = self.mols.allAtoms[:3]
     set_name = 'first_three_atoms'
     sets.add(set_name, subset)
     selString = ':::' + set_name
     css = CompoundStringSelector()
     result, msg = css.select(self.mols, selString, sets=sets)
     self.assertEqual(result, subset)
     self.assertEquals(result.stringRepr, selString)
 def test_select_subset_allAtoms(self):
     """
     test selecting with stringRepr of subset allAtoms
     select the first atom in protease from mols.allAtoms
     """
     stringSel = CompoundStringSelector()
     diff_atoms = self.mols.allAtoms.get('0')
     selString = "(stringSel:::/+/protease:::\\s\\0)"
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     #selected, msg = stringSel.select(self.mols, selString)
     self.assertEquals(selected, diff_atoms)
     self.assertEquals(selected, self.mols.allAtoms[0:1])
     self.assertEquals(selected.stringRepr,  selString)
 def test_select_subset_residues(self):
     """
     test selecting with stringRepr of subset residues
     """
     stringSel = CompoundStringSelector()
     #this is the name of the 7th residue in the first molecule
     diff_residues = self.mols.chains.residues.get("HOH617")
     selString = "(stringSel::/+/protease::\\s\\HOH617)"
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     #selected, msg = stringSel.select(self.mols, selString)
     self.assertEquals(selected, diff_residues)
     self.assertEquals(selected, self.mols.chains.residues[7:8])
     self.assertEquals(selected.stringRepr, selString)
Example #41
0
    def test_select_complicated_sidechain_atoms2(self):
        """
        test selecting w/stringRepr of complicated sidechain atoms(bug 673)

        """
        stringSel = CompoundStringSelector()
        #arg is ARG8 in chain A
        arg = self.mols2.chains.residues[7]
        sidechain = arg.atoms.get('sidechain') - arg.atoms.get('CB')
        #diff_atoms = self.mols1.allAtoms | self.mols1.allAtoms
        selString = sidechain.stringRepr
        selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
        self.assertEquals(selected, sidechain)
        self.assertEquals(selected, self.mols2.allAtoms[67:73])
        self.assertEquals(selString, selected.stringRepr)
    def test_select_complicated_sidechain_atoms2(self):
        """
        test selecting w/stringRepr of complicated sidechain atoms(bug 673)

        """
        stringSel = CompoundStringSelector()
        #arg is ARG8 in chain A
        arg = self.mols2.chains.residues[7]
        sidechain = arg.atoms.get('sidechain')-arg.atoms.get('CB')
        #diff_atoms = self.mols1.allAtoms | self.mols1.allAtoms
        selString = sidechain.stringRepr
        selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
        self.assertEquals(selected, sidechain)
        self.assertEquals(selected, self.mols2.allAtoms[67:73])
        self.assertEquals(selString, selected.stringRepr)
Example #43
0
    def test_select_get_from_get_result(self):
        """
        test selecting w/stringRepr of get from the result of a get

        """
        stringSel = CompoundStringSelector()
        m = self.mols2
        cats = m.allAtoms.get('C.?')
        cbats = cats.get('CB')
        expectedString = "((protease:::\\s\\C.?)\\s\\CB)"
        selString = cbats.stringRepr
        selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
        #selected, msg = stringSel.select(self.mols, selString)
        self.assertEquals(selected, cbats)
        self.assertEquals(selString, expectedString)
        self.assertEquals(selected.stringRepr, expectedString)
    def test_select_get_from_get_result(self):
        """
        test selecting w/stringRepr of get from the result of a get

        """
        stringSel = CompoundStringSelector()
        m = self.mols2
        cats = m.allAtoms.get('C.?')
        cbats = cats.get('CB')
        expectedString = "((protease:::\\s\\C.?)\\s\\CB)"
        selString = cbats.stringRepr
        selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
        #selected, msg = stringSel.select(self.mols, selString)
        self.assertEquals(selected, cbats)
        self.assertEquals(selString, expectedString)
        self.assertEquals(selected.stringRepr, expectedString)
    def test_select_complicated_sidechain_atoms(self):
        """
        test selecting w/stringRepr of complicated sidechain atoms(bug 672)
        ARG8 atoms excluding backbone atoms and CB atoms

        """
        stringSel = CompoundStringSelector()
        #arg is ARG8 in chain A
        arg = self.mols2.chains.residues[7]
        sidechain = arg.atoms-arg.atoms.get('backbone')-arg.atoms.get('CB')
        #diff_atoms = self.mols1.allAtoms | self.mols1.allAtoms
        selString = sidechain.stringRepr
        selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
        self.assertEquals(selected, sidechain)
        self.assertEquals(selected, self.mols2.allAtoms[67:73])
        self.assertEquals(selString, 'protease:A:ARG8:/-/(protease:A:ARG8:\\s\\backbone)/-/(protease:A:ARG8:\\s\\CB)')
        self.assertEquals(selString, selected.stringRepr)
    def expandNodes(self, nodes):
        """Takes nodes as string or TreeNode or TreeNodeSet and returns
a TreeNodeSet
If nodes is a string it can contain a series of set descriptors with operators
separated by / characters.  There is always a first set, followed by pairs of
operators and sets.  All sets ahve to describe nodes of the same level.

example:
    '1crn:::CA*/+/1crn:::O*' describes the union of all CA ans all O in 1crn
    '1crn:::CA*/+/1crn:::O*/-/1crn::TYR29:' 
"""
        if isinstance(nodes,TreeNode):
            result = nodes.setClass([nodes])
            result.setStringRepr(nodes.full_name())

        elif type(nodes)==StringType:
            stringRepr = nodes
            css = CompoundStringSelector()
            result = css.select(self.Mols, stringRepr)[0]
##            setsStrings = stringRepr.split('/')
##            getSet = self.Mols.NodesFromName
##            result = getSet(setsStrings[0])
##            for i in range(1, len(setsStrings), 2):
##                op = setsStrings[i]
##                arg = setsStrings[i+1]
##                if op=='|': # or
##                    result += getSet(arg)
##                elif op=='-': # subtract
##                    result -= getSet(arg)
##                elif op=='&': # intersection
##                    result &= getSet(arg)
##                elif op=='^': # xor
##                    result ^= getSet(arg)
##                elif op=='s': # sub select (i.e. select from previous result)
##                    result = result.get(arg)
##                else:
##                    raise ValueError, '%s bad operation in selection string'%op
##            result.setStringRepr(stringRepr)

        elif isinstance(nodes,TreeNodeSet):
            result = nodes
        else:
            raise ValueError, 'Could not expand nodes %s\n'%str(nodes)
        
        return result
Example #47
0
    def test_select_complicated_sidechain_atoms(self):
        """
        test selecting w/stringRepr of complicated sidechain atoms(bug 672)
        ARG8 atoms excluding backbone atoms and CB atoms

        """
        stringSel = CompoundStringSelector()
        #arg is ARG8 in chain A
        arg = self.mols2.chains.residues[7]
        sidechain = arg.atoms - arg.atoms.get('backbone') - arg.atoms.get('CB')
        #diff_atoms = self.mols1.allAtoms | self.mols1.allAtoms
        selString = sidechain.stringRepr
        selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
        self.assertEquals(selected, sidechain)
        self.assertEquals(selected, self.mols2.allAtoms[67:73])
        self.assertEquals(
            selString,
            'protease:A:ARG8:/-/(protease:A:ARG8:\\s\\backbone)/-/(protease:A:ARG8:\\s\\CB)'
        )
        self.assertEquals(selString, selected.stringRepr)
Example #48
0
 def test_select_complicated_sidechain_atoms3(self):
     """
     test selecting w/stringRepr of complicated sidechain atoms
     -> carbon atoms in sidechains of ARG residues in protease except CB atoms
     """
     stringSel = CompoundStringSelector()
     #arg is ARG8 in chain A
     args = self.mols2.chains.residues.get('ARG*')
     sidechains = args.atoms.get('sidechain')
     sc_carbons = sidechains.get('C*')
     #sc_carbons = sidechains.get('C.?')
     target = sc_carbons - args.atoms.get('CB')
     selString = target.stringRepr
     #check that built set has expected stringRepr
     targetStr = '(((protease::\\s\\ARG*):\\s\\sidechain)\\s\\C*)/-/((protease::\\s\\ARG*):\\s\\CB)'
     self.assertEquals(selString, targetStr)
     # try to get same atoms by selecting using built set's stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     #sanity check that 24 atoms are found
     self.assertEquals(len(selected), 24)
     #check that the same atoms are found
     self.assertEquals(selected, target)
     #check that selected set has expected stringRepr
     self.assertEquals(targetStr, selected.stringRepr)
 def test_select_complicated_sidechain_atoms3(self):
     """
     test selecting w/stringRepr of complicated sidechain atoms
     -> carbon atoms in sidechains of ARG residues in protease except CB atoms
     """
     stringSel = CompoundStringSelector()
     #arg is ARG8 in chain A
     args = self.mols2.chains.residues.get('ARG*')
     sidechains = args.atoms.get('sidechain')
     sc_carbons = sidechains.get('C*')
     #sc_carbons = sidechains.get('C.?')
     target = sc_carbons - args.atoms.get('CB')
     selString = target.stringRepr
     #check that built set has expected stringRepr
     targetStr = '(((protease::\\s\\ARG*):\\s\\sidechain)\\s\\C*)/-/((protease::\\s\\ARG*):\\s\\CB)'
     self.assertEquals(selString, targetStr)
     # try to get same atoms by selecting using built set's stringRepr
     selected, msg = stringSel.select(self.mols, selString, returnMsg=True)
     #sanity check that 24 atoms are found
     self.assertEquals(len(selected), 24)
     #check that the same atoms are found
     self.assertEquals(selected, target)
     #check that selected set has expected stringRepr
     self.assertEquals(targetStr, selected.stringRepr)
Example #50
0
class TreeViewWithCheckbuttons(TreeView, KeySelectable):
    """Tree Widget class
    A TreeWiget contains tree nodes (object of Class Node). 
    Each node can have children. Nodes that do have children can be expanded 
and collapsed using the + - icon placed before de nodes' icon. Each no has an 
icon and a name. It is possible to associate an arbitrary Python object to each 
node. The node in the tree is the graphical representation of the object.
"""
    def __init__(self, master=None, name='Tree', multi_choice=False,
                 width=800, height=200, treeWidth=140, treeHeight=100,
                 historyWidth=100, historyHeight=100, mode='Extended',
                 historyVisible=False,nohistory=False,
                 mouseBinding=None,obj2Node=True, displayValue=False,
                 offx=0, offy=0):

        TreeView. __init__(self, master=master, name=name,
                           multi_choice=multi_choice,
                           width=width, height=height,
                           treeWidth=treeWidth, treeHeight=treeHeight,
                           historyWidth=historyWidth,
                           historyHeight=historyHeight,
                           mode=mode, historyVisible=historyVisible,
                           nohistory=nohistory,
                           mouseBinding=mouseBinding, obj2Node=obj2Node,
                           displayValue=displayValue,
                           offx=offx, offy=offy, canvasHeaderCol=True)

        KeySelectable.__init__(self, self.canvas)
        # assign method that need to be overriden
        self.match = self.findFirstMatchNodeFromName
        self.selectItem = self.showNode
        self.ctrlModCallback = self.handleControlKey

        self.sets = None # used to save pmv.sets so that the selector can
                         # use it to allow selecting sets
        self.balloons = Pmw.Balloon(master, yoffset=0)
        
        self.inChain = False  # true when calling chained commands.
                              # used to prevent calling chained or chained
        
        nbcol = self.nbColumns = 15
        #nbcol += 10
        self.callbacks = [None]*nbcol
            # will be the list of call backs associated with
            # columns of checkbuttons
        self.names = [None]*nbcol
            # will be the list of names associated with
            # columns of checkbuttons
        self.colHeaderButtons = [None]*nbcol
        self.colHeaderTkVars = [None]*nbcol
        self.colOptionPanels = [None]*nbcol
        self.pmvcmd = [None]*nbcol
        self.chainWith = [None]*nbcol
        for i in range(nbcol):
            self.chainWith[i] = [None]*nbcol
        self.balloonText = ['No Help']*nbcol

        self.buttonValFunc = [None]*nbcol # function for getting the current values

        # force molecule visible when selecting, displaying or labeling
        # parts of molecules
        for i in range(1,9): # chains command 0 after command 1 through 9
            # 'Checked': call 0 when command 1 is checked
            # 'True': always check the button of the chained command
            # 'All': apply to the whole moelcular fragment
            self.chainWith[i][0] = ('Checked', 'True', 'All')

        # make display lines, S&B and CPK mutually exclusive
        for i in range(2,5):
            for j in range(2,5):
                if i==j: continue
                self.chainWith[i][j] = ('Checked','False','All')

        # make color commands (9-14) radio
        for i in range(9,15):
            for j in range(9,15):
                if i==j: continue
                self.chainWith[i][j] = ('Checked','False','All')

        self.bbmode = ['All']*nbcol
        self.colHeaderTkVars = [None]*nbcol # list of button in the header

        from mglutil.util.packageFilePath import findFilePath
        self.ICONPATH = os.path.abspath(findFilePath('Icons', 'Pmv'))
        self.ICONDIR = os.path.join(self.ICONPATH, '32x32')
        self.iconList = [None]*nbcol # save references to icon images to 
            # prevent them from being garbage collected

        # add the backbone menu option
        self.bbmodevar = Tkinter.StringVar()
        self.bbmodevar.set("Cmd setting")
        self.bbmode_menu = Pmw.OptionMenu(
            self.master, labelpos = 'w', label_text = 'Protein:',
        menubutton_textvariable = self.bbmodevar,
        items = ['Cmd setting', 'Backbone', 'Sidechain',
                         'Sidechains+CA', 'All'],
        menubutton_width = 8
    )
        cid = self.canvasHeaderCol.create_window(
            10, 15, window=self.bbmode_menu, anchor='w')
        self.proteinHelp = """This option menu allows to specify for peptidic molecular fragments
whether the command should be applied to the backbone atoms only,
the side chain atoms only, the sidechain atoms and CA atoms or the
full molecular frament."""
        self.balloons.bind(self.bbmode_menu, self.proteinHelp)

        # add a compound selector entry
        self.selectorEntry = Pmw.EntryField(
            self.master, labelpos = 'w', label_text = 'Select:  ',
            entry_width=12, validate = None, command=self.selectFromString)

        cid = self.canvasHeaderCol.create_window(
            10, 40, window=self.selectorEntry, anchor='w')
        self.selectorHelp = """This entry allows selecting enties in the Tree using a Pmv compound selector.
Only expanded nodes will be selected.  Selected nodes are outlined with a
yellow selection box.  When a button is checked for a selected node, the
command is applied to all selecte nodes.
The syntax for a compound selector is a ; separated list of expressions.
Each expression is a : separated list of selectors applying at the various
levels of the tree.
for instance:
    :::CA selects all carbon alpha atoms
    :A::CA selects all CA in chain A
    ::CYS* selects all cysteins"""
        self.balloons.bind(self.selectorEntry, self.selectorHelp)

        from MolKit.stringSelector import CompoundStringSelector
        self.selector = CompoundStringSelector()


    def handleControlKey(self, event):
        if event.keysym in ['z', 'Z']:
            self.undoSelect()

            
    def colHasButtton(self, column, klass):
        """returns True if a given column has check buttons for a given klass
"""
        if column==0:
            if klass not in [Molecule, Protein, MoleculeSet, ProteinSet]:
                return False
        return True
    
        
    def findFirstMatchNodeFromName(self, name):
        """walks the tree and find the first node whose fullname
matches name"""
        
        pat = re.compile('.*'+name.lower()+'.*')
        for root in self.roots:
            n = root._matchName(pat)
            if n:
                return n
        return None

        
    def selectFromString(self):
        value = self.selectorEntry.getvalue()
        allMols = self.roots[0].objectKey
        molFrag = self.selector.select(allMols, value, self.sets)
        self.selectNodes(molFrag[0])


    def setCallback(self, column, pmvcmd, iconName=None, balloonText=None,
                    name='command', function=None, bValFunc=None):
        """define a callback for the checkbuttons in a given column.
  pmvcmd is the Pmv command to run in the callback associated with the
         checkbuttons and used to get default values using the 'default form.
  name is a string describing the command in that column, defaults to cmd.name
  iconName is the name of the icon to be used for the button
  balloonText is the tooltip, defaults to name.
  function is an option callback to override the default callback.
           It gets called with  (node, column, pmvcmd)
"""
        assert column<1000


        def callback(node, column):
            # default call back
            
            # search for button because some commands do not have
            # buttons at all levels
            while node and not node.chkbt[column]:
                node = node.parent
            if node is None: return

            # get Pmv's command default arguments
            pmvcmd = node.tree.pmvcmd[column]
            defaultValues = pmvcmd.getLastUsedValues()

            # handle negate key to reflect state of checkbutton
            val = node.chkbtVar[column].get()
            if defaultValues.has_key('negate'):
                defaultValues['negate'] = not val

            defaultValues['callListener'] = False

            # apply the command at each level of the current selection
            for obj in node.getObjects(column):
                apply( pmvcmd, (obj,), defaultValues)

            if pmvcmd.lastUsedValues['default'].has_key('callListener'):
                del pmvcmd.lastUsedValues['default']['callListener']
            
        if function is None:
            function = callback

        self.callbacks[column] = function
        self.buttonValFunc[column] = bValFunc
        
        if name is None:
            if hasattr(function, 'name'):
                name = function.name
        self.names[column] = name
        self.pmvcmd[column] = pmvcmd
        if balloonText is None:
            balloonText = name
        self.balloonText[column] = balloonText
        if iconName:
            iconfile = os.path.join(self.ICONDIR, iconName)
            image = Image.open(iconfile)
            im = ImageTk.PhotoImage(image=image, master=self.master)
            self.iconList[column] = im

            v = Tkinter.IntVar() 
            cb = CallbackFunction(self.editColumn, column)
            button = Tkinter.Checkbutton(
                self.master, variable=v, command=cb, height=32, width=32,
                indicatoron=0, image=im)

            self.colHeaderButtons[column] = button
            self.colHeaderTkVars[column] = v

            cid = self.canvasHeaderCol.create_window(
                20 + self.offx + 175 + column*35, 32, window=button,
                width=40, height=40, anchor='center')

            self.balloons.bind(button, self.balloonText[column])
        else:
            cid = self.canvasHeaderCol.create_text(
                20 + self.offx + 175 + column*35, 5, text=name, anchor='n')


    def editColumn(self, column):
        if self.colHeaderTkVars[column].get()==0: # editor is shown
            self.colOptionPanels[column].hide()
        else:
            if self.colOptionPanels[column]:
                self.colOptionPanels[column].show()
            else:
                self.colOptionPanels[column] = CPCommandEditor(column, self)


    def initCallback(self, node, column):
        self.manageChildren(node, column)


    def manageChildren(self, node, column):
        # sets the checkbutton of all children to value of parent
        if len(node.children)==0:
            return

        val = node.chkbtVar[column].get()
        for c in node.children:
            c.chkbtVar[column].set(val)
            self.manageChildren(c, column)

 
    def chainCommands(self, node, column):
        if self.inChain is True:
            return
        self.inChain = True
        
        buttonValue = node.chkbtVar[column].get()
        chainWith = self.chainWith[column]

        for col in range(self.nbColumns):
            # find out with what argument this col's command should be called
            val = chainWith[col]
            if val is None: continue
            run, arg, prot = val

            if run=='Checked' and not buttonValue: continue
            if run=='Unchecked' and buttonValue: continue

            if arg=='Same': value = buttonValue
            elif arg=='Opposite': value= not buttonValue
            elif arg=='True': value= 1
            elif arg=='False': value= 0

            # temporarly overwrite protin mode
            bbmode = self.bbmodevar
            oldbbmode = bbmode.get()
            bbmode.set(prot)

            #print 'col', col, 'run', run, 'arg', arg, 'prot', prot
            if node.selected:
                for n in self.list_selected:
                    while n and not n.chkbt[col]:
                        n = n.parent
                    if n:
                        n.chkbtVar[col].set(value)
                if n:
                    self.callbacks[col](n, col)
                    self.manageChildren(n, col)
            else:
                n = node
                while n and not n.chkbt[col]:
                    n = n.parent
                if n:
                    n.chkbtVar[col].set(value)
                    self.callbacks[col](n, col)
                    self.manageChildren(n, col)

            # restore bbmode
            bbmode.set(oldbbmode)


    def addNodeTree(self, obj):
        """recursively add a nodes for a hierarchy of objects rooted at obj
"""
        node = self.addNode(obj.name, object=obj, parent=obj.parent,
                            hasChildren=len(obj.children),
                            nodeClass=NodeWithCheckbuttons)
        node.createTkVar(self.nbColumns)
        for child in obj.children:
            self.addNodeTree(child)
Example #51
0
 def test_constructor(self):
     """
     instantiate a StringSelector
     """
     stringSel = CompoundStringSelector()
     self.assertEquals(stringSel.__class__, CompoundStringSelector)
Example #52
0
             for residue in res:
                 all_res += res
                 if verbose: print(" added ", res.name, " to ", all_res)
         else:
             print("WARNING: no residue named " + n)
 else:
     # '1JFF_protein:A:THR179_GLU183,1JFF_protein:B:TRP21_ARG64_LEU275'
     chainStart = res_names_by_chain.index(':') + 1
     molName = res_names_by_chain[:chainStart - 1]
     #if verbose: print "molName = ", molName, " chainStart=", chainStart
     n = res_names_by_chain[chainStart:].replace("_", ",")
     #if verbose: print "after comma replaced '_', n is ", n, '\n'
     selStr = molName + ":" + n
     #if verbose: print "now selStr", selStr
     #eg: 'hsg1:A:ARG8,ILE82'
     result, msg = CompoundStringSelector().select(
         ProteinSet([rec]), selStr)
     if verbose:
         print("prepare_flexreceptor4 line 157: result=", result)
     if result.__class__ != ResidueSet:
         print(residues_to_move,
               " is not a ResidueSet instead it is a ",
               result.__class__)
     #if verbose: print selStr, " selection =", res, " msg=", msg, '\n'
     resS = ResidueSet()
     if result.__class__ == AtomSet:
         resS = result.parent.uniq()
     else:
         resS = result
     if len(resS):
         all_res += resS
     else:
Example #53
0
    l = Read(ligand_filename)[0]
    l.buildBondsByDistance()
    if verbose: print 'read ', ligand_filename
    r = Read(receptor_filename)[0]
    r.buildBondsByDistance()
    if verbose: print 'read ', receptor_filename

    all_res = ResidueSet()
    res_names = residues_to_move.split('_')
    for n in res_names:
        if n.find(':') == -1:
            res = r.chains.residues.get(lambda x: x.name == n)
            all_res += res
            if verbose: print "get: adding ", res.name, " to ", all_res
        else:
            res, msg = CompoundStringSelector().select(ProteinSet([r]), n)
            all_res += res
            if verbose: print "css: adding ", res.name, " to ", all_res
    if verbose:
        print "all_res=", all_res.full_name(
        ), 'all_res.__class__=', all_res.__class__
    #?check for duplicates
    d = {}
    for res in all_res:
        d[res] = 1
    all_res = d.keys()
    all_res = ResidueSet(all_res)

    #inactivate specified bonds
    #disallowed_Pairs "CA_CB:CB_CG:C_CA"
    all_bnds = BondSet()
Example #54
0
 msg = 'invalid vina_result filename: ' + vina_result + " not found"
 assert os.path.exists(vina_result), msg 
 ligs = Read(vina_result, "conformations")
 msg = vina_result + " contains no valid molecules"
 assert len(ligs), msg
 lig = ligs[0]
 #determine the receptor molecule to read in
 rec_file = ratom_name.split(":")[0] + ".pdbqt"
 msg = rec_file + " file not found"
 assert os.path.exists(rec_file), msg 
 recs = Read(rec_file)
 msg = rec_file + " contains no valid molecules"
 assert len(recs), msg
 rec = recs[0]
 # locate the receptor atom
 css = CompoundStringSelector()
 rec_ats = css.select(recs, ratom_name)[0]
 msg = ratom_name + " did not match exactly 1 atom in " + rec_file
 assert len(rec_ats)==1, msg
 rec_at = rec_ats[0]
 rec_at_coords = rec_at.coords
 if verbose: 
     print("found rec_at = ", rec_at.full_name(), end=' ') 
     print("with initial coords = ", rec_at.coords)
 # locate the ligand atom
 lig_ats = css.select(ligs, latom_name)[0]
 msg = latom_name + " did not match exactly 1 atom in " + ligs[0].name
 assert len(lig_ats)==1, msg
 lig_at = lig_ats[0]
 if verbose: 
     print("found lig_at =>", lig_at.full_name())
Example #55
0
    def __init__(self, master=None, name='Tree', multi_choice=False,
                 width=800, height=200, treeWidth=140, treeHeight=100,
                 historyWidth=100, historyHeight=100, mode='Extended',
                 historyVisible=False,nohistory=False,
                 mouseBinding=None,obj2Node=True, displayValue=False,
                 offx=0, offy=0):

        TreeView. __init__(self, master=master, name=name,
                           multi_choice=multi_choice,
                           width=width, height=height,
                           treeWidth=treeWidth, treeHeight=treeHeight,
                           historyWidth=historyWidth,
                           historyHeight=historyHeight,
                           mode=mode, historyVisible=historyVisible,
                           nohistory=nohistory,
                           mouseBinding=mouseBinding, obj2Node=obj2Node,
                           displayValue=displayValue,
                           offx=offx, offy=offy, canvasHeaderCol=True)

        KeySelectable.__init__(self, self.canvas)
        # assign method that need to be overriden
        self.match = self.findFirstMatchNodeFromName
        self.selectItem = self.showNode
        self.ctrlModCallback = self.handleControlKey

        self.sets = None # used to save pmv.sets so that the selector can
                         # use it to allow selecting sets
        self.balloons = Pmw.Balloon(master, yoffset=0)
        
        self.inChain = False  # true when calling chained commands.
                              # used to prevent calling chained or chained
        
        nbcol = self.nbColumns = 15
        #nbcol += 10
        self.callbacks = [None]*nbcol
            # will be the list of call backs associated with
            # columns of checkbuttons
        self.names = [None]*nbcol
            # will be the list of names associated with
            # columns of checkbuttons
        self.colHeaderButtons = [None]*nbcol
        self.colHeaderTkVars = [None]*nbcol
        self.colOptionPanels = [None]*nbcol
        self.pmvcmd = [None]*nbcol
        self.chainWith = [None]*nbcol
        for i in range(nbcol):
            self.chainWith[i] = [None]*nbcol
        self.balloonText = ['No Help']*nbcol

        self.buttonValFunc = [None]*nbcol # function for getting the current values

        # force molecule visible when selecting, displaying or labeling
        # parts of molecules
        for i in range(1,9): # chains command 0 after command 1 through 9
            # 'Checked': call 0 when command 1 is checked
            # 'True': always check the button of the chained command
            # 'All': apply to the whole moelcular fragment
            self.chainWith[i][0] = ('Checked', 'True', 'All')

        # make display lines, S&B and CPK mutually exclusive
        for i in range(2,5):
            for j in range(2,5):
                if i==j: continue
                self.chainWith[i][j] = ('Checked','False','All')

        # make color commands (9-14) radio
        for i in range(9,15):
            for j in range(9,15):
                if i==j: continue
                self.chainWith[i][j] = ('Checked','False','All')

        self.bbmode = ['All']*nbcol
        self.colHeaderTkVars = [None]*nbcol # list of button in the header

        from mglutil.util.packageFilePath import findFilePath
        self.ICONPATH = os.path.abspath(findFilePath('Icons', 'Pmv'))
        self.ICONDIR = os.path.join(self.ICONPATH, '32x32')
        self.iconList = [None]*nbcol # save references to icon images to 
            # prevent them from being garbage collected

        # add the backbone menu option
        self.bbmodevar = Tkinter.StringVar()
        self.bbmodevar.set("Cmd setting")
        self.bbmode_menu = Pmw.OptionMenu(
            self.master, labelpos = 'w', label_text = 'Protein:',
        menubutton_textvariable = self.bbmodevar,
        items = ['Cmd setting', 'Backbone', 'Sidechain',
                         'Sidechains+CA', 'All'],
        menubutton_width = 8
    )
        cid = self.canvasHeaderCol.create_window(
            10, 15, window=self.bbmode_menu, anchor='w')
        self.proteinHelp = """This option menu allows to specify for peptidic molecular fragments
whether the command should be applied to the backbone atoms only,
the side chain atoms only, the sidechain atoms and CA atoms or the
full molecular frament."""
        self.balloons.bind(self.bbmode_menu, self.proteinHelp)

        # add a compound selector entry
        self.selectorEntry = Pmw.EntryField(
            self.master, labelpos = 'w', label_text = 'Select:  ',
            entry_width=12, validate = None, command=self.selectFromString)

        cid = self.canvasHeaderCol.create_window(
            10, 40, window=self.selectorEntry, anchor='w')
        self.selectorHelp = """This entry allows selecting enties in the Tree using a Pmv compound selector.
Only expanded nodes will be selected.  Selected nodes are outlined with a
yellow selection box.  When a button is checked for a selected node, the
command is applied to all selecte nodes.
The syntax for a compound selector is a ; separated list of expressions.
Each expression is a : separated list of selectors applying at the various
levels of the tree.
for instance:
    :::CA selects all carbon alpha atoms
    :A::CA selects all CA in chain A
    ::CYS* selects all cysteins"""
        self.balloons.bind(self.selectorEntry, self.selectorHelp)

        from MolKit.stringSelector import CompoundStringSelector
        self.selector = CompoundStringSelector()