Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

variation of side chains pymol

By: a guest on Oct 3rd, 2012  |  syntax: Python  |  size: 8.28 KB  |  views: 87  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. from pymol import cmd
  2. import os
  3. import sys
  4. from pymol import stored
  5. from os.path import splitext
  6.  
  7. # ************************************************************
  8. # ------------------------------------------------------------
  9. # VSC: Variant Side Chains of BCX
  10. # Modifies selection around substrate.
  11. # ------------------------------------------------------------
  12. # ************************************************************
  13.  
  14. # DESCRIPTION:
  15. # - Mutate a residue and save the fragment amino acid.
  16.  
  17. # PyMOL:
  18. # - modify>around: residues select, substrate excluded
  19. # - modify>expand: residues select, substrate included
  20.  
  21. # Auto build-up of mutations dictionary.
  22. # First select residues to mutate, then select alpha carbons of the new selection
  23. # then store the residue number of those alpha carbons.
  24. # PyMOL> cmd.select("lig-es-default", "resi 500", enable=1)
  25. # PyMOL> cmd.select("lig-es-around", "(byres (lig-es-default around 4))", enable=1)
  26. # PyMOL> cmd.select("lig-es-around-ca", "lig-es-around and name ca", enable=1)
  27. # PyMOL> cmd.do("iterate (lig-es-around-ca)", stored.li.append(resi)")
  28.  
  29. # REQUIRES:
  30. # - PDB file to mutate
  31.  
  32. # CALLING orig_sequence:
  33. # PyMOL> run vsc.py
  34. # PyMOL> frag <state>
  35.  
  36. # PARAMETERS:
  37. # - <mutations> dictionary below
  38. obj = 'es-onp-opt-pm6-5.0-09.pdb'
  39. sub = '500'
  40. distance = '4'
  41. state = sys.argv[1]
  42.  
  43. # OPTIONS:
  44. # - The number of conformers can be adjusted.
  45. # - The mutated side chain can be optimized locally by vdW minimization.
  46.  
  47. # ************************************************************
  48. def setup(obj):
  49.  
  50.     # Various set up
  51.     pwd = os.getcwd()
  52.     #print "os.getcwd()", os.getcwd()
  53.     cmd.do('wizard mutagenesis')
  54.     cmd.do('refresh_wizard')
  55.  
  56.     # Save residue names and numbers.
  57.     orig_sequence = setNames(obj)
  58.     #print orig_sequence
  59.  
  60.     # Keeping track of the mutations
  61.     # Example: '42':  ['GLY', 'ASN', 'VAL', 'ALA']
  62.     # Important: Trailing commata.
  63.     all_side_chains = ['ALA', 'ARG', 'ASN', 'ASP',
  64.                        'CYS', 'GLU', 'GLN', 'GLY',
  65.                        'HIS', 'ILE', 'LEU', 'LYS',
  66.                        'MET', 'PHE', 'PRO', 'SER',
  67.                        'THR', 'TRP', 'TYR', 'VAL'
  68.                        ]
  69.     do_not_mutate = ['78', '172']
  70.     positions_in_selection = get_positions_in_selection(sub, distance)
  71.     mutations = {}
  72.     for i in positions_in_selection:
  73.         if i[0] not in do_not_mutate:
  74.             # Prevent mutating from WT to WT.
  75.             mutations[i[0]] = []
  76.             for mut in all_side_chains:
  77.                 if i[1] != mut:
  78.                     mutations[i[0]].append(mut)
  79.     for i in mutations.keys():
  80.         print i, mutations[i]
  81.     return pwd, mutations, orig_sequence
  82. # ------------------------------------------------------------
  83.  
  84. # ************************************************************
  85. def get_positions_in_selection(sub, distance):
  86.     cmd.do("select lig-def, resi %s" % sub)
  87.     cmd.select("lig-around", "(byres (lig-def around %s))" % distance)
  88.     cmd.select("lig-around-ca", "lig-around and name ca")
  89.     cmd.do("stored.li = []")
  90.     cmd.do("iterate (lig-around-ca), stored.li.append((resi, resn))")
  91.     positions_in_selection = stored.li
  92.     cmd.do("delete all")
  93.     return positions_in_selection
  94. # ------------------------------------------------------------
  95.  
  96. # ************************************************************
  97. # 'state=state': The first variable is the variable used within
  98. # the scope of this function. The second variable is the one
  99. # in the global scoped and defined at the top of the module.
  100. def frag(state=state, obj=obj):
  101.  
  102.     pwd, mutations, orig_sequence = setup(obj)
  103.     get_positions_in_selection(sub, distance)
  104.    
  105.     # Add and retain hydrogens
  106.     cmd.get_wizard().set_hyd("keep")
  107.  
  108.     # Run over all sites where to mutate
  109.     for site in mutations.keys():
  110.  
  111.         variants = mutations[site]
  112.  
  113.         # Run over all variants.
  114.         for variant in variants:
  115.  
  116.             cmd.load(obj)
  117.  
  118.             cmd.do('wizard mutagenesis')
  119.             cmd.do('refresh_wizard')
  120.             cmd.get_wizard().set_mode(variant)
  121.             cmd.get_wizard().do_select(site + '/')
  122.            
  123.             # Get the number of available rotamers at that site
  124.             # Introduce a condition here to check if
  125.             # rotamers are requested.
  126.             # <<OPTION>>
  127.             nRots = getRots(site, variant)
  128.             #if nRots > 3:
  129.             #    nRots = 3
  130.             nRots=1
  131.  
  132.             cmd.rewind()
  133.             for i in range(1, nRots + 1):
  134.                
  135.                 cmd.get_wizard().do_select("(" + site + "/)")
  136.                 cmd.frame(i)
  137.                 cmd.get_wizard().apply()
  138.  
  139.                 # Optimize the mutated sidechain
  140.                 #<<OPTION>>
  141.                 #print "Sculpting."
  142.                 localSculpt(obj, site)
  143.  
  144.                 # Protonation of the N.
  145.                 cmd.do("select n%d, name n and %d/" % (int(site), int(site)))
  146.                 cmd.edit("n%d" % int(site), None, None, None, pkresi=0, pkbond=0)
  147.                 cmd.do("h_fill")
  148.  
  149.                 # Protonation of the C.
  150.                 cmd.do("select c%d, name c and %d/" % (int(site), int(site)))
  151.                 cmd.edit("c%d" % int(site), None, None, None, pkresi=0, pkbond=0)
  152.                 cmd.do("h_fill")
  153.  
  154.                 # Definition of saveString
  155.                 #saveString  = '%s/' % pwd
  156.                 #saveString += 'frag-' + getOne(orig_sequence[site]).lower() +\
  157.                 #               site + getOne(variant).lower() + '-%s.pdb, ' % state +\
  158.                 #               '((%s/))' % site
  159.                 saveStringRot  = '%s/' % pwd
  160.                 saveStringRot += 'frag-' + getOne(orig_sequence[site]).lower() +\
  161.                                   site + getOne(variant).lower() + '-%02d-%s.pdb, ' % (i, state) +\
  162.                                   '((%s/))' % site
  163.                 #print saveString
  164.                 #cmd.do('save %s' % saveString.lower())
  165.                 cmd.do('save %s' % saveStringRot.lower())
  166.             cmd.do('delete all')
  167.             cmd.set_wizard('done')
  168. # ------------------------------------------------------------
  169.  
  170.  
  171. # ************************************************************
  172. # Convenience Functions
  173. def getRots(site, variant):
  174.     cmd.get_wizard().set_mode(variant)
  175.    
  176.     # Key lines
  177.     # I dont know how they work, but they make it possible.
  178.     # Jason wrote this: If you just write "site" instead of
  179.     #                   "(site)", PyMOL will delete your
  180.     #                   residue. "(site)" makes it an
  181.     #                   anonymous selection.
  182.     #print 'getRots'
  183.     cmd.get_wizard().do_select("(" + str(site) + "/)")
  184.     nRot = cmd.count_states("mutation")
  185.     return nRot
  186.  
  187. def setNames(obj):
  188.     orig_sequence = {}
  189.     cmd.load(obj)
  190.     cmd.select("prot", "name ca")
  191.     cmd.do("stored.names = []")
  192.     cmd.do("iterate (prot), stored.names.append((resi, resn))")
  193.     for i in stored.names:
  194.         orig_sequence[i[0]] = i[1]
  195.     # Now in 'get_all_positions_in_selection'
  196.     #cmd.do('delete all')
  197.     #print stored.names
  198.     return orig_sequence
  199.  
  200. # Credit: Thomas Holder, MPI
  201. # CONSTRUCT: - 'res'
  202. #            - 'cpy'
  203. #            -
  204. def localSculpt(obj, site):
  205.     res = str(site)
  206.     cmd.protect('(not %s/) or name CA+C+N+O+OXT' % (res))
  207.     print "Activating Sculpting."
  208.     cmd.sculpt_activate(obj[:-4])
  209.     cmd.sculpt_iterate(obj[:-4], cycles=5000)
  210.     cmd.sculpt_deactivate(obj[:-4])
  211.     cmd.deprotect()
  212.  
  213. def getOne(three):
  214.     trans = {
  215.        'ALA':'A',
  216.        'ARG':'R',
  217.        'ASN':'N',
  218.        'ASP':'D',
  219.        'CYS':'C',
  220.        'GLU':'E',
  221.        'GLN':'Q',
  222.        'GLY':'G',
  223.        'HIS':'H',
  224.        'ILE':'I',
  225.        'LEU':'L',
  226.        'LYS':'K',
  227.        'MET':'M',
  228.        'PHE':'F',
  229.        'PRO':'P',
  230.        'SER':'S',
  231.        'THR':'T',
  232.        'TRP':'W',
  233.        'TYR':'Y',
  234.        'VAL':'V'
  235.        }
  236.     return trans[three]
  237. # ------------------------------------------------------------
  238.  
  239. # ************************************************************
  240. # Expose to the PyMOL shell
  241. cmd.extend('setup', setup)
  242. cmd.extend('frag', frag)
  243. cmd.extend('getRots', getRots)
  244. cmd.extend('localSculpt', localSculpt)
  245. # ------------------------------------------------------------