Advertisement
Guest User

PyMOL List hydrogen Bonds

a guest
Oct 25th, 2010
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.00 KB | None | 0 0
  1. from pymol import cmd
  2. from pymol import stored
  3.  
  4. def list_hb(selection, selection2=None, cutoff=3.2,
  5.         angle=55, mode=1, hb_list_name='hbonds'):
  6.     """
  7.    USAGE
  8.    
  9.    list_hb needs a selection, not an object!
  10.    list_hb selection,
  11.    [selection2 (default=None)],
  12.    [cutoff (default=3.2)],
  13.    [angle (default=55)],
  14.    [hb_list_name]
  15.  
  16.    The script automatically adds a requirement that
  17.    atoms in the selection (and selection2 if used)
  18.    must be either of the elements N or O.
  19.  
  20.    If mode is set to 0, then no angle cutoff is used,
  21.    otherwise the angle cutoff is used and defaults to
  22.    55 degrees.
  23.  
  24.    e.g.
  25.    To get a list of all H-bonds within chain A of an object
  26.    list_hb 1abc & c. a &! r. hoh, cutoff=3.2,
  27.    hb_list_name=abc-hbonds
  28.  
  29.    To get a list of H-bonds between chain B and everything
  30.    else:
  31.    list_hb 1tl9 & c. b, 1tl9 &! c. b
  32.    """
  33.  
  34.     #hb_data = open('./pymolScripts/hb_' + selection + '.dat', 'w')
  35.     #hb_data.write('')
  36.     #hb_data.close()
  37.  
  38.     #hb_data = open('./pymolScripts/hb_' + selection + '.dat', 'w')
  39.  
  40.     cutoff=float(cutoff)
  41.     angle=float(angle)
  42.     mode=float(mode)
  43.     # ensure only N and O atoms are in the selection
  44.     selection = selection + " & e. n+o"
  45.     if not selection2:
  46.         hb = cmd.find_pairs(selection, selection, mode=mode,
  47.                 cutoff=cutoff, angle=angle)
  48.     else:
  49.         selection2 = selection2 + " & e. n+o"
  50.         hb = cmd.find_pairs(selection, selection2, mode=mode,
  51.                 cutoff=cutoff, angle=angle)
  52.  
  53.     # sort the list for easier reading
  54.     hb.sort(lambda x, y: (cmp(x[0][1], y[0][1])))
  55.  
  56.     stored.listA = []
  57.     stored.listB = []
  58.     stored.listC = []
  59.  
  60.     for pairs in hb:
  61.         cmd.iterate("%s and index %s" % (pairs[0][0], pairs[0][1]),
  62.             'print "%1s/%3s`%s/%s/%i " % (chain, resn, resi, name, ID),')
  63.         cmd.iterate("%s and index %s" % (pairs[0][0], pairs[0][1]),
  64.             'stored.listA.append( "%1s/%3s`%s/%s/%i " % (chain, resn, resi, name, ID),)')
  65.  
  66.         cmd.iterate("%s and index %s" % (pairs[1][0],pairs[1][1]),
  67.                 'print "%1s/%3s`%s/%s/%i " % (chain, resn, resi, name, ID),')
  68.         cmd.iterate("%s and index %s" % (pairs[1][0], pairs[1][1]),
  69.             'stored.listB.append( "%1s/%3s`%s/%s/%i " % (chain, resn, resi, name, ID),)')
  70.  
  71.         print "%.2f" % cmd.distance(hb_list_name, "%s and index %s" %
  72.                 (pairs[0][0], pairs[0][1]), "%s and index %s" % (pairs[1][0],
  73.                     pairs[1][1]))
  74.         stored.listC.append("%.2f" % cmd.distance(hb_list_name, "%s and index %s" %
  75.                 (pairs[0][0], pairs[0][1]), "%s and index %s" % (pairs[1][0],
  76.                     pairs[1][1])))
  77.  
  78.     for line in enumerate(stored.listA):
  79.         hb_data.write(stored.listA[line[0]]
  80.                 + '    '
  81.                 + stored.listB[line[0]]
  82.                 + '    '
  83.                 + stored.listC[line[0]]
  84.                 + '\n')
  85.  
  86.     #hb_data.close()
  87.    
  88. cmd.extend("list_hb", list_hb)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement