def setUp(self): self.mols1 = Read('Data/stringSel.pdb') self.mol1 = self.mols1[0] self.mols2 = Read('Data/protease.pdb') self.mol2 = self.mols2[0] self.mols = self.mols1 + self.mols2 self.stringSel = StringSelector()
def get(self, event=None, withMsg=False): args = self.buildArgs() atArg = self.atomEntry.get() #print "atArg=", atArg, "=='' is", atArg=="" resArg = self.resEntry.get() #print "resArg=", resArg, "=='' is", resArg=="" chainArg = self.chainEntry.get() #print "chainArg=", chainArg, "=='' is", chainArg=="" molArg = self.molEntry.get() #print "molArg=", molArg, "=='' is", molArg=="" if atArg != "": args = molArg + ':' + chainArg + ':' + resArg + ':' + atArg elif resArg != "": args = molArg + ':' + chainArg + ':' + resArg elif chainArg != "": args = molArg + ':' + chainArg else: args = molArg #print "calling StringSelector.select with args=", args selitem, msgStr = StringSelector().select(self.molSet, args, sets=self.sets, caseSensitive=self.userPref) #if StringSelector starts returning msgs fix here #selitem, msgStr = StringSelector().select(self.molSet, args, self.userPref) #return selitem, msgStr #if selitem and len(selitem): # print "returning len(selitem)=", len(selitem) if withMsg: return selitem, msgStr else: return selitem
def test_select_with_empty_string(self): """ test result with empty string returns all molecules """ stringSel = StringSelector() result, msg = stringSel.select(self.molecules, "") self.assertEquals(result, self.molecules) self.assertEquals(result.stringRepr, self.molecules[0].name)
def test_select_with_bad_key_returns_EmptySet(self): """ test result with bad_key returns EmptySet """ selString = ":::'backbone'" stringSel = StringSelector() result, msg = stringSel.select(self.molecules, selString) self.assertEquals(len(result), 0)
def test_select_with_lambda_residue_expr(self): """ test result with lambda x:x.name==CA returns 9 atoms """ selString = "::lambda x:x.type=='GLN':" #sanity check stringSel = StringSelector() result, msg = stringSel.select(self.molecules, selString) self.assertEquals(len(result), 9) self.assertEquals(result.stringRepr, selString)
def test_select_with_backbone_returns_12atoms(self): """ test result with backbone returns 12 atoms """ selString = ":::backbone" #sanity check stringSel = StringSelector() result, msg = stringSel.select(self.molecules, selString) self.assertEquals(len(result), 12) self.assertEquals(result.stringRepr, selString)
def test_select_with_lambda_molecule_expr(self): """ test result with lambda x:x.name=='stringSel' returns 29 atoms """ selString = "lambda x:x.name=='stringSel':::" #sanity check stringSel = StringSelector() result, msg = stringSel.select(self.molecules, selString) self.assertEquals(len(result), 29) self.assertEquals(result.stringRepr, selString)
def test_select_with_CA_returns_3atoms(self): """ test result with CA returns 3 atoms """ selString = ":::CA" #sanity check stringSel = StringSelector() result, msg = stringSel.select(self.molecules, selString) self.assertEquals(len(result), 3) self.assertEquals(result.stringRepr, selString)
def test_select_with_compound_Residue_full_name(self): """ test result with compound Residue full_name """ subset = self.molecules.chains.residues[:2] selString = subset[0].full_name() + ';' + subset[1].full_name() stringSel = StringSelector() result, msg = stringSel.select(self.molecules, selString) self.assertEqual(result, subset) self.assertEquals(result.stringRepr, selString)
def test_select_with_simple_Residue_full_name(self): """ test result with simple Residue full_name """ subset = self.molecules.chains.residues[:2] selString = subset.full_name() stringSel = StringSelector() result, msg = stringSel.select(self.molecules, selString) self.assertEqual(result, subset) self.assertEquals(result.stringRepr, selString)
def test_select_with_simple_Atom_full_name(self): """ test result with simple Atom full_name """ subset = self.molecules.allAtoms[:2] selString = subset.full_name() stringSel = StringSelector() result, msg = stringSel.select(self.molecules, selString) self.assertEqual(result, subset) self.assertEquals(result.stringRepr, selString)
def test_select_with_backbone_returns_no_waters(self): """ test result with backbone returns no waters """ selString = ":::backbone" stringSel = StringSelector() result, msg = stringSel.select(self.molecules, selString) self.assertEquals(len(result), 12) self.assertEqual('HOH' not in result.parent.type, True) self.assertEquals(result.stringRepr, selString)
def test_select_with_hetatm_returns_5atoms(self): """ test result with hetatm returns 5 atoms """ selString = ":::hetatm" #sanity check stringSel = StringSelector() result, msg = stringSel.select(self.molecules, selString) self.assertEquals(len(result), 5) self.assertEquals(result.stringRepr, selString)
def test_select_with_lambda_chain_expr(self): """ test result with lambda x:x.id=='W' returns 5 atoms """ selString = ":lambda x:x.id=='W'::" #sanity check stringSel = StringSelector() result, msg = stringSel.select(self.molecules, selString) self.assertEquals(len(result), 5) self.assertEquals(result.stringRepr, selString)
def test_select_with_lambda_atoms_expr_with_parentheses(self): """ test result with lambda x:len(x.bonds)==1 returns 468 atoms for hsg1.pdb """ selString = ":::lambda x:len(x.bonds)==1" stringSel = StringSelector() from MolKit import Read mol = Read("Data/hsg1.pdb") mol[0].buildBondsByDistance() result, msg = stringSel.select(mol, selString) self.assertEquals(len(result), 468) self.assertEquals(result.stringRepr, selString)
def test_select_with_5_Residue_full_names(self): """ test result with 5 Residue full_names joined with ';' """ subset = self.molecules.chains.residues[:5] selString = '' for a in subset: selString += a.full_name() + ';' selString = selString[:-1] stringSel = StringSelector() result, msg = stringSel.select(self.molecules, selString) self.assertEqual(result, subset) self.assertEquals(result.stringRepr, selString)
def test_select_all_atoms_from_compound_string(self): """ test result using all the atoms' full_name() """ selString = '' subset = self.molecules.allAtoms for a in subset: selString += a.full_name() + ';' selString = selString[:-1] stringSel = StringSelector() result, msg = stringSel.select(self.molecules, selString) self.assertEqual(result, subset) self.assertEquals(result.stringRepr, selString)
def test_select_set_from_string(self): """ test result using string which is key in Sets dict """ sets = Sets() subset = self.molecules[0].allAtoms set_name = 'first' sets.add(set_name, subset) selString = ':::' + set_name stringSel = StringSelector() result, msg = stringSel.select(self.molecules, selString, sets=sets) self.assertEqual(result, subset) self.assertEquals(result.stringRepr, selString)
def setGeomAtomProp(self): if not len(self.atomSets): return from MolKit.molecule import Atom prop = 'colors' for actor in self.actors: if actor.name.find(prop) > 0: obj = actor.object if self.atomSets.has_key(obj.fullName): #setstr = self.atomSets[obj.fullName]['atomset'] g = obj.mol.geomContainer aset = g.atoms[obj.name].findType(Atom) asetstr = aset.full_name(0) #if len(asetstr) != len(setstr): # return atList = [] func = g.geomPickToAtoms.get(obj.name) if func: atList = func(obj, range(len(obj.vertexSet.vertices))) else: allAtoms = g.atoms[obj.name] if hasattr(obj, "vertexSet") and len(allAtoms) == len( obj.vertexSet): atList = allAtoms if not len(atList): return col = actor.getLastKeyFrame().getValue() oname = None if aset.colors.has_key(obj.name): oname = obj.name elif aset.colors.has_key(obj.parent.name): oname = obj.parent.name if not oname: return if len(col) == 1: for a in atList: a.colors[oname] = tuple(col[0]) else: for i, a in enumerate(atList): a.colors[oname] = tuple(col[i]) from MolKit.stringSelector import StringSelector selector = StringSelector() #nset, msg = selector.select(atList, setstr) nset, msg = selector.select(atList, asetstr)
def setUp(self): self.mols = Read('Data/stringSel.pdb') self.mol = self.mols[0] self.stringSel = StringSelector()
def test_constructor(self): """ instantiate a StringSelector """ stringSel = StringSelector() self.assertEquals(stringSel.__class__, StringSelector)
def setUp(self): self.mols = Read('Data/stringSel.pdb') self.mol = self.mols[0] self.mol.buildBondsByDistance() self.stringSel = StringSelector()