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_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::")
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_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_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:::")
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_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_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_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_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_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:::")
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)
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_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)
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_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 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)
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()
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()
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:
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())
def test_constructor(self): """ instantiate a StringSelector """ stringSel = CompoundStringSelector() self.assertEquals(stringSel.__class__, CompoundStringSelector)