def list_hb(selection, selection2=None, cutoff=3.2, angle=55, mode=1, hb_list_name='hbonds'): """ USAGE list_hb selection, [selection2 (default=None)], [cutoff (default=3.2)], [angle (default=55)], [mode (default=1)], [hb_list_name (default='hbonds')] The script automatically adds a requirement that atoms in the selection (and selection2 if used) must be either of the elements N or O. If mode is set to 0 instead of the default value 1, then no angle cutoff is used, otherwise the angle cutoff is used and defaults to 55 degrees. e.g. To get a list of all H-bonds within chain A of an object list_hb 1abc & c. a &! r. hoh, cutoff=3.2, hb_list_name=abc-hbonds To get a list of H-bonds between chain B and everything else: list_hb 1tl9 & c. b, 1tl9 &! c. b """ cutoff = float(cutoff) angle = float(angle) mode = float(mode) # ensure only N and O atoms are in the selection selection = selection + " & e. n+o" if not selection2: hb = cmd.find_pairs(selection, selection, mode=mode, cutoff=cutoff, angle=angle) else: selection2 = selection2 + " & e. n+o" hb = cmd.find_pairs(selection, selection2, mode=mode, cutoff=cutoff, angle=angle) # sort the list for easier reading hb.sort(lambda x, y: (cmp(x[0][1], y[0][1]))) for pairs in hb: cmd.iterate("%s and index %s" % (pairs[0][0], pairs[0][1]), 'print "%1s/%3s`%s/%-4s " % (chain,resn,resi,name),') cmd.iterate("%s and index %s" % (pairs[1][0], pairs[1][1]), 'print "%1s/%3s`%s/%-4s " % (chain,resn,resi,name),') print "%.2f" % cmd.distance( hb_list_name, "%s and index %s" % (pairs[0][0], pairs[0][1]), "%s and index %s" % (pairs[1][0], pairs[1][1]))
def testFindPairs(self): # mode 0 cmd.fragment("gly") pairs = cmd.find_pairs("hydro", "elem O") pairs_ref = [ (('gly', 5), ('gly', 4)), (('gly', 6), ('gly', 4)), (('gly', 7), ('gly', 4)), ] self.assertEqual(sorted(pairs), pairs_ref) # mode 1 cmd.fab("GGGGG", "m2", ss=1) pairs = cmd.find_pairs("m2 & donor", "m2 & acceptor", mode=1) self.assertEqual(pairs, [(('m2', 29), ('m2', 4))])
def get_dehydrons(): cmd.delete('dehydrons') cmd.delete('DH_pairs') cmd.hide() angle = float(angle_value.get()) cutoff = float(dist_cutoff_value.get()) desolv = float(desolv_sphere.get()) min_wrappers = float(min_value.get()) selection = 'name n or name o and not resn hoh' hb = cmd.find_pairs("((byres "+selection+") and n. n)","((byres "+selection+") and n. o)",mode=1,cutoff=cutoff,angle=angle) # sort the list for easier reading hb.sort(lambda x,y:(cmp(x[0][1],y[0][1]))) print "------------------------------------------------\n----------------dehydron Results-----------------\n------------------------------------------------\n Donor | Aceptor | \nChain Residue | Chain Residue | # dehydrons" sel = [] wra = 0 for pairs in hb: cmd.iterate("%s and index %s" % (pairs[0][0], pairs[0][1]), 'stored.nitro = chain, resi, resn') # extracts the nitrogen cmd.iterate("%s and index %s" % (pairs[1][0], pairs[1][1]), 'stored.oxy = chain, resi, resn') # extracts the oxygen wrappers = cmd.select('wrap', '(((chain %s and name ca and resi %s) around %f) or ((chain %s and name ca and resi %s) around %f)) and (not ((neighbor name n*+o*) or (name n*+o*+h*)))' % (stored.nitro[0], stored.nitro[1], desolv, stored.oxy[0], stored.oxy[1], desolv)) #Identifies the putative dehydrons if wrappers < min_wrappers: wra = 1 cmd.distance('Dehydrons',"%s and index %s" % (pairs[0][0],pairs[0][1]),"%s and index %s" % (pairs[1][0],pairs[1][1])) print ' %s%7s%5d | %s%7s%5d |%7s' % (stored.nitro[0], stored.nitro[2], int(stored.nitro[1]), stored.oxy[0], stored.oxy[2], int(stored.oxy[1]), wrappers) if stored.nitro[1] not in sel: sel.append(stored.nitro[1]) if stored.oxy[1] not in sel: sel.append(stored.oxy[1]) if wra == 1: cmd.select('DH_pairs', 'resi %s' % ('+').join(sel)) cmd.show('lines', 'DH_pairs') cmd.disable('DH_pairs') cmd.hide('labels') cmd.delete('wrap') cmd.show('cartoon') cmd.show('dashes')
def dehydron(selection='all', angle_range=40, max_distance=3.5, desolv=6.5, min_wrappers=19, quiet=0): ''' DESCRIPTION dehydron calculator USAGE dehydron [ selection [, angle_range [, max_distance [, desolv [, min_wrappers ]]]]] ''' angle, max_distance = float(angle_range), float(max_distance) desolv, min_wrappers = float(desolv), int(min_wrappers) quiet = int(quiet) name = cmd.get_legal_name('DH_%s' % selection) cmd.delete(name) selection_hb = '((%s) and polymer)' % (selection) hb = cmd.find_pairs("((byres "+selection_hb+") and n. n)","((byres "+selection_hb+") and n. o)",mode=1,cutoff=max_distance,angle=angle_range) if not quiet: hb.sort(lambda x,y:(cmp(x[0][1],y[0][1]))) print "--------------------------------------------------------------------" print "--------------------------Dehydron Results--------------------------" print "--------------------------------------------------------------------" print " Donor | Aceptor |" print " Object Chain Residue | Object Chain Residue | # wrappers" cmd.select('_nonpolar', '(elem C) and not (solvent or (elem N+O) extend 1)', 0) try: cmd.select('_selection', '%s' % selection, 0) except: pass sel = [] for pairs in hb: wrappers = cmd.count_atoms('((%s and _nonpolar and _selection) within %f of byca (%s`%d %s`%d))' % ((pairs[0][0], desolv) + pairs[0] + pairs[1])) if wrappers < min_wrappers: cmd.distance(name, pairs[0], pairs[1]) if not quiet: cmd.iterate(pairs[0], 'stored.nitro = chain, resi, resn') cmd.iterate(pairs[1], 'stored.oxy = chain, resi, resn') print ' %12s%4s%6s%5d | %12s%4s%6s%5d |%7s' % (pairs[0][0], stored.nitro[0], stored.nitro[2], int(stored.nitro[1]), pairs[1][0], stored.oxy[0], stored.oxy[2], int(stored.oxy[1]), wrappers) sel.append(pairs[0]) sel.append(pairs[1]) cmd.delete('_nonpolar') cmd.delete('_selection') if len(sel) > 0: cmd.show_as('dashes', name) elif not quiet and len(hb) != 0: print ' - no dehydrons were found - ' else: print ' - no hydrogen bonds were found - '
def print_hb(selection): hb = cmd.find_pairs("((byres "+selection+") and n;n)","((byres "+selection+") and n;o)",mode=1,cutoff=3.7,angle=55) pair1_list = [] pair2_list = [] dist_list = [] for pairs in hb: cmd.iterate("%s and ID %s" % (pairs[0][0],pairs[0][1]), 'print "%s/%3s`%s/%s " % (chain,resn,resi,name),') cmd.iterate("%s and ID %s" % (pairs[1][0],pairs[1][1]), 'print "%s/%3s`%s/%s " % (chain,resn,resi,name),') print "%.2f" % cmd.dist("%s and ID %s" % (pairs[0][0],pairs[0][1]),"%s and ID %s" % (pairs[1][0],pairs[1][1]))
def list_hb(selection,selection2=None,cutoff=3.2,angle=55,mode=1,hb_list_name='hbonds'): """ USAGE list_hb selection, [selection2 (default=None)], [cutoff (default=3.2)], [angle (default=55)], [mode (default=1)], [hb_list_name (default='hbonds')] The script automatically adds a requirement that atoms in the selection (and selection2 if used) must be either of the elements N or O. If mode is set to 0 instead of the default value 1, then no angle cutoff is used, otherwise the angle cutoff is used and defaults to 55 degrees. e.g. To get a list of all H-bonds within chain A of an object list_hb 1abc & c. a &! r. hoh, cutoff=3.2, hb_list_name=abc-hbonds To get a list of H-bonds between chain B and everything else: list_hb 1tl9 & c. b, 1tl9 &! c. b """ cutoff=float(cutoff) angle=float(angle) mode=float(mode) # ensure only N and O atoms are in the selection selection = selection + " & e. n+o" if not selection2: hb = cmd.find_pairs(selection,selection,mode=mode,cutoff=cutoff,angle=angle) else: selection2 = selection2 + " & e. n+o" hb = cmd.find_pairs(selection,selection2,mode=mode,cutoff=cutoff,angle=angle) # sort the list for easier reading hb.sort(lambda x,y:(cmp(x[0][1],y[0][1]))) for pairs in hb: cmd.iterate("%s and index %s" % (pairs[0][0],pairs[0][1]), 'print "%1s/%3s`%s/%-4s " % (chain,resn,resi,name),') cmd.iterate("%s and index %s" % (pairs[1][0],pairs[1][1]), 'print "%1s/%3s`%s/%-4s " % (chain,resn,resi,name),') print "%.2f" % cmd.distance(hb_list_name,"%s and index %s" % (pairs[0][0],pairs[0][1]),"%s and index %s" % (pairs[1][0],pairs[1][1]))
def polarpairs(sel1, sel2, cutoff=4.0, angle=63.0, name='', state=1, quiet=1): ''' ARGUMENTS sel1, sel2 = string: atom selections cutoff = float: distance cutoff angle = float: h-bond angle cutoff in degrees. If angle="default", take "h_bond_max_angle" setting. If angle=0, do not detect h-bonding. name = string: If given, also create a distance object for visual representation SEE ALSO cmd.find_pairs, cmd.distance ''' cutoff = float(cutoff) quiet = int(quiet) state = int(state) if angle == 'default': angle = cmd.get('h_bond_max_angle', cmd.get_object_list(sel1)[0]) angle = float(angle) mode = 1 if angle > 0 else 0 x = cmd.find_pairs('(%s) and donors' % sel1, '(%s) and acceptors' % sel2, state, state, cutoff=cutoff, mode=mode, angle=angle) + \ cmd.find_pairs('(%s) and acceptors' % sel1, '(%s) and donors' % sel2, state, state, cutoff=cutoff, mode=mode, angle=angle) x = sorted(set(x)) if not quiet: print 'Settings: cutoff=%.1fangstrom angle=%.1fdegree' % (cutoff, angle) print 'Found %d polar contacts' % (len(x)) if len(name) > 0: for p in x: cmd.distance(name, '(%s`%s)' % p[0], '(%s`%s)' % p[1]) return x
def list_hb(selection,cutoff=3.2,angle=55,hb_list_name='hbonds'): """ USAGE list_hb selection, [cutoff (default=3.2)], [angle (default=55)], [hb_list_name] e.g. list_hb 1abc & c. a &! r. hoh, cutoff=3.2, hb_list_name=abc-hbonds """ cutoff=float(cutoff) angle=float(angle) hb = cmd.find_pairs("((byres "+selection+") and n;n)","((byres "+selection+") and n;o)",mode=1,cutoff=cutoff,angle=angle) # sort the list for easier reading hb.sort(lambda x,y:(cmp(x[0][1],y[0][1]))) for pairs in hb: for ind in [0,1]: cmd.iterate("%s and index %s" % (pairs[ind][0],pairs[ind][1]), 'print "%s/%3s`%s/%s/%s " % (chain,resn,resi,name,index),') print "%.2f" % cmd.distance(hb_list_name,"%s and index %s" % (pairs[0][0],pairs[0][1]),"%s and index %s" % (pairs[1][0],pairs[1][1]))
def pmf(key, cutoff=7.0, selection1='(name CB)', selection2='', state=1, quiet=1): ''' DESCRIPTION Potential of Mean Force ARGUMENTS key = string: aaindex key cutoff = float: distance cutoff {default: 7.0} cutoff = (float, float): distance shell selection1 = string: atom selection {default: (name CB)} selection2 = string: atom selection {default: selection1} NOTES Does also support a list of keys and a list of cutoffs to deal with multiple distance shells. EXAMPLES # distance dependent c-beta contact potentials pmf SIMK990101, 5, /2x19//A//CB pmf SIMK990102, [5, 7.5], /2x19//A//CB pmf [SIMK990101, SIMK990102, SIMK990103], [0, 5, 7.5, 10], /2x19//A//CB # interface potential sidechaincenters 2x19_scc, 2x19 pmf KESO980102, 7.0, /2x19_scc//A, /2x19_scc//B distance /2x19_scc//A, /2x19_scc//B, cutoff=7.0 ''' from pymol import cmd, stored from chempy import cpv if cmd.is_string(key): if key.lstrip().startswith('['): key = cmd.safe_alpha_list_eval(key) else: key = [key] if cmd.is_string(cutoff): cutoff = eval(cutoff) if not cmd.is_sequence(cutoff): cutoff = [cutoff] if len(cutoff) == len(key): cutoff = [0.0] + list(cutoff) if len(cutoff) != len(key) + 1: print 'Error: Number of keys and number of cutoffs inconsistent' return state = int(state) quiet = int(quiet) if len(selection2) == 0: selection2 = selection1 if not quiet and len(key) > 1: print 'Distance shells:' for i in range(len(key)): print '%s %.1f-%.1f' % (key[i], cutoff[i], cutoff[i + 1]) idmap = dict() cmd.iterate_state(state, '(%s) or (%s)' % (selection1, selection2), 'idmap[model,index] = [(resn,name),(x,y,z)]', space={'idmap': idmap}) twoN = cmd.count_atoms(selection1) + cmd.count_atoms(selection2) pairs = cmd.find_pairs(selection1, selection2, cutoff=max(cutoff), state1=state, state2=state) if len(pairs) == 0: print 'Empty pair list' return 0.0 matrix = map(get, key) for i in matrix: assert isinstance(i, MatrixRecord) i_list = range(len(key)) u_sum = 0 count = 0 for id1, id2 in pairs: a1 = idmap[id1] a2 = idmap[id2] r = cpv.distance(a1[1], a2[1]) for i in i_list: if cutoff[i] <= r and r < cutoff[i + 1]: try: aa1 = to_one_letter_code[a1[0][0]] aa2 = to_one_letter_code[a2[0][0]] u_sum += matrix[i].get(aa1, aa2) count += 1 except: print 'Failed for', a1[0], a2[0] value = float(u_sum) / twoN if not quiet: print 'PMF: %.4f (%d contacts, %d residues)' % (value, count, twoN) return value
def dehydron(selection='all', angle_range=40., max_distance=3.5, desolv=6.5, min_wrappers=19, max_wrappers=35, quiet=0): ''' DESCRIPTION dehydron calculator USAGE wrappy [ selection [, angle_range [, max_distance [, desolv [, min_wrappers [, max_wrappers ]]]]]] ''' angle, max_distance = float(angle_range), float(max_distance) desolv, min_wrappers, max_wrappers = float(desolv), int(min_wrappers), int( max_wrappers) quiet = int(quiet) DH_name = cmd.get_legal_name('DH_%s' % selection) cmd.delete(DH_name) HBA_name = cmd.get_legal_name('HBA_%s' % selection) cmd.delete(HBA_name) HBO_name = cmd.get_legal_name('HBO_%s' % selection) cmd.delete(HBO_name) selection_hb = '((%s) and polymer)' % (selection) hb = cmd.find_pairs("((byres " + selection_hb + ") and n. n)", "((byres " + selection_hb + ") and n. o)", mode=1, cutoff=max_distance, angle=angle_range) cmd.select('_nonpolar', '(elem C) and not (solvent or (elem N+O) extend 1)', 0) try: cmd.select('_selection', '%s' % selection, 0) except: pass low_sel = [] mean_sel = [] high_sel = [] total_wrappers = 0 for pairs in hb: wrappers = cmd.count_atoms( '((%s and _nonpolar and _selection) within %f of byca (%s`%d %s`%d))' % ((pairs[0][0], desolv) + pairs[0] + pairs[1])) total_wrappers = total_wrappers + wrappers cmd.iterate(pairs[0], 'stored.donor = chain, resi, resn') cmd.iterate(pairs[1], 'stored.aceptor = chain, resi, resn') if wrappers < min_wrappers: cmd.distance(DH_name, pairs[0], pairs[1]) line = (wrappers, '%12s%4s%6s%6s | %12s%4s%6s%6s |%7s below' % (pairs[0][0], stored.donor[0], stored.donor[2], stored.donor[1], pairs[1][0], stored.aceptor[0], stored.aceptor[2], stored.aceptor[1], wrappers)) low_sel.append(line) elif wrappers < max_wrappers: cmd.distance(HBA_name, pairs[0], pairs[1]) line = (wrappers, '%12s%4s%6s%6s | %12s%4s%6s%6s |%7s average' % (pairs[0][0], stored.donor[0], stored.donor[2], stored.donor[1], pairs[1][0], stored.aceptor[0], stored.aceptor[2], stored.aceptor[1], wrappers)) mean_sel.append(line) else: cmd.distance(HBO_name, pairs[0], pairs[1]) line = (wrappers, '%12s%4s%6s%6s | %12s%4s%6s%6s |%7s over' % (pairs[0][0], stored.donor[0], stored.donor[2], stored.donor[1], pairs[1][0], stored.aceptor[0], stored.aceptor[2], stored.aceptor[1], wrappers)) high_sel.append(line) cmd.delete('_nonpolar') cmd.delete('_selection') # compute the z_scores. Useful for protein structure validation. stored.ResiduesNames = [] cmd.iterate('(name ca)', 'stored.ResiduesNames.append((resn))') total_residues = float(len(stored.ResiduesNames)) z_score_wrappers = ((total_wrappers / total_residues) - 17) / 2 z_score_hb = ((len(hb) / total_residues) - 0.62) / 0.06 if len(low_sel) > 0: cmd.show_as('dashes', DH_name) cmd.color('red', DH_name) low_sel.sort() if len(mean_sel) > 0: cmd.show_as('dashes', HBA_name) cmd.color('yellow', HBA_name) mean_sel.sort() if len(high_sel) > 0: cmd.show_as('dashes', HBO_name) cmd.color('green', HBO_name) high_sel.sort() if not quiet: hb.sort() print "--------------------------------------------------------------------" print "------------------------------Results ------------------------------" print "--------------------------------------------------------------------" print " Donor | Aceptor |" print " Object Chain Residue | Object Chain Residue | # wrappers wrapping" for line in low_sel: print line[1] for line in mean_sel: print line[1] for line in high_sel: print line[1] print '\nProtein global statistics:' print '\nz-score wrappers = %6.2f\nz-score hydrogen bonds = %6.2f\n' % ( z_score_wrappers, z_score_hb) elif not quiet and len(hb) != 0: print '\n - no dehydrons were found - ' print '\nz-score hydrogen bonds = %6.2f\n' % (z_score_hb) else: print '\n - no hydrogen bonds were found - '
def dehydron(selection='all', angle_range=40., max_distance=3.5, desolv=6.5, min_wrappers=19, max_wrappers=35, quiet=0): ''' DESCRIPTION dehydron calculator USAGE wrappy [ selection [, angle_range [, max_distance [, desolv [, min_wrappers [, max_wrappers ]]]]]] ''' angle, max_distance = float(angle_range), float(max_distance) desolv, min_wrappers, max_wrappers = float(desolv), int(min_wrappers), int(max_wrappers) quiet = int(quiet) DH_name = cmd.get_legal_name('DH_%s' % selection) cmd.delete(DH_name) HBA_name = cmd.get_legal_name('HBA_%s' % selection) cmd.delete(HBA_name) HBO_name = cmd.get_legal_name('HBO_%s' % selection) cmd.delete(HBO_name) selection_hb = '((%s) and polymer)' % (selection) hb = cmd.find_pairs("((byres " + selection_hb + ") and n. n)", "((byres " + selection_hb + ") and n. o)", mode=1, cutoff=max_distance, angle=angle_range) cmd.select('_nonpolar', '(elem C) and not (solvent or (elem N+O) extend 1)', 0) try: cmd.select('_selection', '%s' % selection, 0) except: pass low_sel = [] mean_sel = [] high_sel = [] total_wrappers = 0 for pairs in hb: wrappers = cmd.count_atoms('((%s and _nonpolar and _selection) within %f of byca (%s`%d %s`%d))' % ((pairs[0][0], desolv) + pairs[0] + pairs[1])) total_wrappers = total_wrappers + wrappers cmd.iterate(pairs[0], 'stored.donor = chain, resi, resn') cmd.iterate(pairs[1], 'stored.aceptor = chain, resi, resn') if wrappers < min_wrappers: cmd.distance(DH_name, pairs[0], pairs[1]) line = (wrappers, '%12s%4s%6s%6s | %12s%4s%6s%6s |%7s below' % (pairs[0][0], stored.donor[0], stored.donor[2], stored.donor[1], pairs[1][0], stored.aceptor[0], stored.aceptor[2], stored.aceptor[1], wrappers)) low_sel.append(line) elif wrappers < max_wrappers: cmd.distance(HBA_name, pairs[0], pairs[1]) line = (wrappers, '%12s%4s%6s%6s | %12s%4s%6s%6s |%7s average' % (pairs[0][0], stored.donor[0], stored.donor[2], stored.donor[1], pairs[1][0], stored.aceptor[0], stored.aceptor[2], stored.aceptor[1], wrappers)) mean_sel.append(line) else: cmd.distance(HBO_name, pairs[0], pairs[1]) line = (wrappers, '%12s%4s%6s%6s | %12s%4s%6s%6s |%7s over' % (pairs[0][0], stored.donor[0], stored.donor[2], stored.donor[1], pairs[1][0], stored.aceptor[0], stored.aceptor[2], stored.aceptor[1], wrappers)) high_sel.append(line) cmd.delete('_nonpolar') cmd.delete('_selection') # compute the z_scores. Useful for protein structure validation. stored.ResiduesNames = [] cmd.iterate('(name ca)', 'stored.ResiduesNames.append((resn))') total_residues = float(len(stored.ResiduesNames)) z_score_wrappers = ((total_wrappers / total_residues) - 17) / 2 z_score_hb = ((len(hb) / total_residues) - 0.62) / 0.06 if len(low_sel) > 0: cmd.show_as('dashes', DH_name) cmd.color('red', DH_name) low_sel.sort() if len(mean_sel) > 0: cmd.show_as('dashes', HBA_name) cmd.color('yellow', HBA_name) mean_sel.sort() if len(high_sel) > 0: cmd.show_as('dashes', HBO_name) cmd.color('green', HBO_name) high_sel.sort() if not quiet: hb.sort() print "--------------------------------------------------------------------" print "------------------------------Results ------------------------------" print "--------------------------------------------------------------------" print " Donor | Aceptor |" print " Object Chain Residue | Object Chain Residue | # wrappers wrapping" for line in low_sel: print line[1] for line in mean_sel: print line[1] for line in high_sel: print line[1] print '\nProtein global statistics:' print '\nz-score wrappers = %6.2f\nz-score hydrogen bonds = %6.2f\n' % (z_score_wrappers, z_score_hb) elif not quiet and len(hb) != 0: print '\n - no dehydrons were found - ' print '\nz-score hydrogen bonds = %6.2f\n' % (z_score_hb) else: print '\n - no hydrogen bonds were found - '
def dehydron(selection='all', angle_range=40, max_distance=3.5, desolv=6.5, min_wrappers=19, quiet=0): ''' DESCRIPTION dehydron calculator USAGE dehydron [ selection [, angle_range [, max_distance [, desolv [, min_wrappers ]]]]] ''' angle, max_distance = float(angle_range), float(max_distance) desolv, min_wrappers = float(desolv), int(min_wrappers) quiet = int(quiet) name = cmd.get_legal_name('DH_%s' % selection) cmd.delete(name) selection_hb = '((%s) and polymer)' % (selection) hb = cmd.find_pairs("((byres " + selection_hb + ") and n. n)", "((byres " + selection_hb + ") and n. o)", mode=1, cutoff=max_distance, angle=angle_range) if not quiet: hb.sort(lambda x, y: (cmp(x[0][1], y[0][1]))) print "--------------------------------------------------------------------" print "--------------------------Dehydron Results--------------------------" print "--------------------------------------------------------------------" print " Donor | Aceptor |" print " Object Chain Residue | Object Chain Residue | # wrappers" cmd.select('_nonpolar', '(elem C) and not (solvent or (elem N+O) extend 1)', 0) try: cmd.select('_selection', '%s' % selection, 0) except: pass sel = [] total_wrappers = 0 for pairs in hb: wrappers = cmd.count_atoms( '((%s and _nonpolar and _selection) within %f of byca (%s`%d %s`%d))' % ((pairs[0][0], desolv) + pairs[0] + pairs[1])) total_wrappers = total_wrappers + wrappers if wrappers < min_wrappers: cmd.distance(name, pairs[0], pairs[1]) if not quiet: cmd.iterate(pairs[0], 'stored.nitro = chain, resi, resn') cmd.iterate(pairs[1], 'stored.oxy = chain, resi, resn') print ' %12s%4s%6s%6s | %12s%4s%6s%6s |%7s' % ( pairs[0][0], stored.nitro[0], stored.nitro[2], stored.nitro[1], pairs[1][0], stored.oxy[0], stored.oxy[2], stored.oxy[1], wrappers) sel.append(pairs[0]) sel.append(pairs[1]) cmd.delete('_nonpolar') cmd.delete('_selection') #compute the z_scores for validation porpoises. stored.ResiduesNames = [] cmd.iterate('(name ca)', 'stored.ResiduesNames.append((resn))') total_residues = float(len(stored.ResiduesNames)) z_score_wrappers = ((total_wrappers / total_residues) - 17) / 2 z_score_hb = ((len(hb) / total_residues) - 0.62) / 0.06 if len(sel) > 0: cmd.show_as('dashes', name) print '\nz-score wrappers = %6.2f\nz-score hydrogen bonds = %6.2f\n' % ( z_score_wrappers, z_score_hb) elif not quiet and len(hb) != 0: print '\n - no dehydrons were found - ' print '\nz-score hydrogen bonds = %6.2f\n' % (z_score_hb) else: print '\n - no hydrogen bonds were found - '
def peptide_rebuild(name, selection='all', cycles=1000, state=1, quiet=1): ''' DESCRIPTION Rebuild the peptide from selection. All atoms which are present in selection will be kept fixed, while atoms missing in selection are placed by sculpting. USAGE peptide_rebuild name [, selection [, cycles [, state ]]] SEE ALSO stub2ala, add_missing_atoms, peptide_rebuild_modeller ''' from chempy import fragments, feedback, models cycles, state, quiet = int(cycles), int(state), int(quiet) # suppress feedback for model merging feedback['actions'] = False # work with named selection namedsele = cmd.get_unused_name('_') cmd.select(namedsele, selection, 0) identifiers = [] cmd.iterate(namedsele + ' and polymer and guide and alt +A', 'identifiers.append([segi,chain,resi,resv,resn])', space=locals()) model = models.Indexed() for (segi,chain,resi,resv,resn) in identifiers: try: fname = resn.lower() if resn != 'MSE' else 'met' frag = fragments.get(fname) except IOError: print(' Warning: unknown residue: ' + resn) continue for a in frag.atom: a.segi = segi a.chain = chain a.resi = resi a.resi_number = resv a.resn = resn model.merge(frag) if not quiet: print(' Loading model...') cmd.load_model(model, name, 1, zoom=0) if cmd.get_setting_boolean('auto_remove_hydrogens'): cmd.remove(name + ' and hydro') cmd.protect(name + ' in ' + namedsele) cmd.sculpt_activate(name) cmd.update(name, namedsele, 1, state) cmd.delete(namedsele) if not quiet: print(' Sculpting...') cmd.set('sculpt_field_mask', 0x003, name) # bonds and angles only cmd.sculpt_iterate(name, 1, int(cycles / 4)) cmd.set('sculpt_field_mask', 0x09F, name) # local + torsions cmd.sculpt_iterate(name, 1, int(cycles / 4)) cmd.set('sculpt_field_mask', 0x0FF, name) # ... + vdw cmd.sculpt_iterate(name, 1, int(cycles / 2)) cmd.sculpt_deactivate(name) cmd.deprotect(name) cmd.unset('sculpt_field_mask', name) if not quiet: print(' Connecting peptide...') pairs = cmd.find_pairs(name + ' and name C', name + ' and name N', 1, 1, 2.0) for pair in pairs: cmd.bond(*pair) cmd.h_fix(name) if not quiet: print(' peptide_rebuild: done')
def peptide_rebuild(name, selection='all', cycles=1000, state=1, quiet=1): ''' DESCRIPTION Rebuild the peptide from selection. All atoms which are present in selection will be kept fixed, while atoms missing in selection are placed by sculpting. USAGE peptide_rebuild name [, selection [, cycles [, state ]]] SEE ALSO stub2ala, add_missing_atoms, peptide_rebuild_modeller ''' from chempy import fragments, feedback, models cycles, state, quiet = int(cycles), int(state), int(quiet) # suppress feedback for model merging feedback['actions'] = False # work with named selection namedsele = cmd.get_unused_name('_') cmd.select(namedsele, selection, 0) identifiers = [] cmd.iterate(namedsele + ' and polymer and guide and alt +A', 'identifiers.append([segi,chain,resi,resv,resn])', space=locals()) model = models.Indexed() for (segi,chain,resi,resv,resn) in identifiers: try: fname = resn.lower() if resn != 'MSE' else 'met' frag = fragments.get(fname) except IOError: print(' Warning: unknown residue:', resn) continue for a in frag.atom: a.segi = segi a.chain = chain a.resi = resi a.resi_number = resv a.resn = resn model.merge(frag) if not quiet: print(' Loading model...') cmd.load_model(model, name, 1, zoom=0) if cmd.get_setting_boolean('auto_remove_hydrogens'): cmd.remove(name + ' and hydro') cmd.protect(name + ' in ' + namedsele) cmd.sculpt_activate(name) cmd.update(name, namedsele, 1, state) cmd.delete(namedsele) if not quiet: print(' Sculpting...') cmd.set('sculpt_field_mask', 0x003, name) # bonds and angles only cmd.sculpt_iterate(name, 1, int(cycles / 4)) cmd.set('sculpt_field_mask', 0x09F, name) # local + torsions cmd.sculpt_iterate(name, 1, int(cycles / 4)) cmd.set('sculpt_field_mask', 0x0FF, name) # ... + vdw cmd.sculpt_iterate(name, 1, int(cycles / 2)) cmd.sculpt_deactivate(name) cmd.deprotect(name) cmd.unset('sculpt_field_mask', name) if not quiet: print(' Connecting peptide...') pairs = cmd.find_pairs(name + ' and name C', name + ' and name N', 1, 1, 2.0) for pair in pairs: cmd.bond(*pair) cmd.h_fix(name) if not quiet: print(' peptide_rebuild: done')
def hydro_pairs(selection, cut_off): """ Find hydrogen bonds for a given selection """ states = cmd.count_states(selection) hb = [] for i in range(1, states+1): hb.append(cmd.find_pairs("%s and (name O* and neighbor elem H) or (name N* and neighbor elem H)"%(selection), "%s and name N* or name O*"%(selection), cutoff = 3.5, mode=1, angle=40, state1=i, state2=i)) seen = {} for state in hb: for pairs in state: if pairs in seen: seen[pairs] = seen[pairs] + 1 else: seen[pairs] = 1 occurrence = seen.items() occurrence.sort(key=lambda x:x[1], reverse=True) fd = open("Hydrogen_bonds.dat", "w") fd.write("--------------------------------------------------------------------\n") fd.write("-----------------------------Results--------------------------------\n") fd.write("--------------------------------------------------------------------\n") fd.write(" Donor | Aceptor |\n") fd.write(" Object Residue Atom Index| Object Residue Atom Index| % occurrence\n") stored.donors = [] stored.aceptors = [] sub = [] occurrence_list = [] for i in range (len(occurrence)): cmd.iterate("index %s"%(occurrence[i][0][0][1]), "stored.donors.append((resn, elem))") cmd.iterate("index %s"%(occurrence[i][0][1][1]), "stored.aceptors.append((resn, elem))") if (occurrence[i][1]*100/states) >= cut_off: fd.write( "%8s%8s%6s%8s|%8s%8s%6s%8s|%5s\n" % (occurrence[i][0][0][0], stored.donors[i][0], stored.donors[i][1], occurrence[i][0][0][1], occurrence[i][0][1][0], stored.aceptors[i][0], stored.aceptors[i][1], occurrence[i][0][1][1], "%.2f"%(occurrence[i][1]*100/states))) occurrence_list.append(occurrence[i][0]) fd.close() cmd.set('suspend_updates', 'on') for state, bonds in enumerate(hb): for bond in bonds: if bond in occurrence_list: cmd.distance('HB', 'index %s' % bond[0][1], 'index %s' % bond[1][1], state=state, cutoff=3.5) cmd.hide("labels","HB") cmd.set('suspend_updates', 'off') print "Check working directory for Hydrogen bonds text file report"
def pmf(key, cutoff=7.0, selection1='(name CB)', selection2='', state=1, quiet=1): ''' DESCRIPTION Potential of Mean Force ARGUMENTS key = string: aaindex key cutoff = float: distance cutoff {default: 7.0} cutoff = (float, float): distance shell selection1 = string: atom selection {default: (name CB)} selection2 = string: atom selection {default: selection1} NOTES Does also support a list of keys and a list of cutoffs to deal with multiple distance shells. EXAMPLES # distance dependent c-beta contact potentials pmf SIMK990101, 5, /2x19//A//CB pmf SIMK990102, [5, 7.5], /2x19//A//CB pmf [SIMK990101, SIMK990102, SIMK990103], [0, 5, 7.5, 10], /2x19//A//CB # interface potential sidechaincenters 2x19_scc, 2x19 pmf KESO980102, 7.0, /2x19_scc//A, /2x19_scc//B distance /2x19_scc//A, /2x19_scc//B, cutoff=7.0 ''' from pymol import cmd, stored from chempy import cpv if cmd.is_string(key): if key.lstrip().startswith('['): key = cmd.safe_alpha_list_eval(key) else: key = [key] if cmd.is_string(cutoff): cutoff = eval(cutoff) if not cmd.is_sequence(cutoff): cutoff = [cutoff] if len(cutoff) == len(key): cutoff = [0.0] + list(cutoff) if len(cutoff) != len(key) + 1: print('Error: Number of keys and number of cutoffs inconsistent') return state = int(state) quiet = int(quiet) if len(selection2) == 0: selection2 = selection1 if not quiet and len(key) > 1: print('Distance shells:') for i in range(len(key)): print('%s %.1f-%.1f' % (key[i], cutoff[i], cutoff[i + 1])) idmap = dict() cmd.iterate_state(state, '(%s) or (%s)' % (selection1, selection2), 'idmap[model,index] = [(resn,name),(x,y,z)]', space={'idmap': idmap}) twoN = cmd.count_atoms(selection1) + cmd.count_atoms(selection2) pairs = cmd.find_pairs(selection1, selection2, cutoff=max(cutoff), state1=state, state2=state) if len(pairs) == 0: print('Empty pair list') return 0.0 matrix = list(map(get, key)) for i in matrix: assert isinstance(i, MatrixRecord) i_list = list(range(len(key))) u_sum = 0 count = 0 for id1, id2 in pairs: a1 = idmap[id1] a2 = idmap[id2] r = cpv.distance(a1[1], a2[1]) for i in i_list: if cutoff[i] <= r and r < cutoff[i + 1]: try: aa1 = to_one_letter_code[a1[0][0]] aa2 = to_one_letter_code[a2[0][0]] u_sum += matrix[i].get(aa1, aa2) count += 1 except: print('Failed for', a1[0], a2[0]) value = float(u_sum) / twoN if not quiet: print('PMF: %.4f (%d contacts, %d residues)' % (value, count, twoN)) return value
def hydro_pairs(selection, cut_off): """ Find hydrogen bonds for a given selection """ states = cmd.count_states(selection) if states: hb = [] for i in range(1, states + 1): p = cmd.find_pairs("%s and (name O* and neighbor elem H) or" "(name N* and neighbor elem H)" % selection, "%s and name N* or name O*" % selection, cutoff=3.5, mode=1, angle=40, state1=i, state2=i) hb.append(p) if any([j for i in hb for j in i]): seen = {} for state in hb: for pairs in state: if pairs in seen: seen[pairs] = seen[pairs] + 1 else: seen[pairs] = 1 occurrence = seen.items() occurrence = sorted(occurrence, key=lambda x: x[1], reverse=True) fd = open("Hydrogen_bonds.dat", "w") fd.write("--------------------------------------------------------" "------------\n") fd.write("-----------------------------Results--------------------" "------------\n") fd.write("--------------------------------------------------------" "------------\n") fd.write(" Donor |" " Aceptor |\n") fd.write(" Object Residue Atom Index|" " Object Residue Atom Index| % occurrence\n") stored.donors = [] stored.aceptors = [] sub = [] occurrence_list = [] for i in range(len(occurrence)): cmd.iterate("index %s" % (occurrence[i][0][0][1]), "stored.donors.append((resn, elem))") cmd.iterate("index %s" % (occurrence[i][0][1][1]), "stored.aceptors.append((resn, elem))") if (occurrence[i][1] * 100 / states) >= cut_off: fd.write("%8s%8s%6s%8s|%8s%8s%6s%8s|%5s\n" % (occurrence[i][0][0][0], stored.donors[i][0], stored.donors[i][1], occurrence[i][0][0][1], occurrence[i][0][1][0], stored.aceptors[i][0], stored.aceptors[i][1], occurrence[i][0][1][1], "%.2f" % (occurrence[i][1] * 100 / states))) occurrence_list.append(occurrence[i][0]) fd.close() cmd.set('suspend_updates', 'on') for state, bonds in enumerate(hb): for bond in bonds: if bond in occurrence_list: cmd.distance('HB', 'index %s' % bond[0][1], 'index %s' % bond[1][1], state=state, cutoff=3.5) cmd.hide("labels", "HB") cmd.set('suspend_updates', 'off') print( "Check working directory for hydrogen bonds text file report") else: print("No hydrogen bonds detected for this selection")