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

Untitled

By: a guest on Dec 20th, 2012  |  syntax: Python  |  size: 12.34 KB  |  views: 75  |  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, mutations based on
  11. # current 'resn'.
  12. # ------------------------------------------------------------
  13. # ************************************************************
  14.  
  15. # DESCRIPTION:
  16. # - Mutate a residue and save the fragment amino acid.
  17.  
  18. # PyMOL:
  19. # - modify>around: residues select, substrate excluded
  20. # - modify>expand: residues select, substrate included
  21.  
  22. # MODE:
  23. prod   = 'production'
  24. debug  = 'debugging'
  25. mode = prod
  26.  
  27. # PREPARATION:
  28. # - Enter 'set retain_order, 0' to protect atom ordering.
  29. # - Substrate resi set to 500
  30. # - Substrate resn and chain set to 'LIG' and A
  31.  
  32. # NOTE:
  33. # - Probably hydrogen addition to N- and C- can
  34. #   be discarded for complete enzyme chains
  35.  
  36. # Auto build-up of mutations dictionary.
  37. # First select residues to mutate, then select alpha carbons of the new selection
  38. # then store the residue number of those alpha carbons.
  39. # PyMOL> cmd.select("lig-es-default", "resi 500", enable=1)
  40. # PyMOL> cmd.select("lig-es-around", "(byres (lig-es-default around 4))", enable=1)
  41. # PyMOL> cmd.select("lig-es-around-ca", "lig-es-around and name ca", enable=1)
  42. # PyMOL> cmd.do("iterate (lig-es-around-ca)", stored.li.append(resi)")
  43.  
  44. # REQUIRES:
  45. # - PDB file to mutate
  46.  
  47. # CALLING orig_sequence:
  48. # PyMOL> cd directory/containing/vsc-set.py
  49. # PyMOL> run vsc-set.py
  50. # PyMOL> frag <state>
  51.  
  52. # PARAMETERS:
  53. # - <mutations> dictionary below
  54. obj = 'ge-onp-opt-pm6-1.0-15.pdb'
  55. sub = '500'
  56. distance = '4'
  57. state = sys.argv[1]
  58.  
  59. # OPTIONS:
  60. # - The number of conformers can be adjusted.
  61. # - The mutated side chain can be optimized locally by vdW minimization.
  62.  
  63. # ************************************************************
  64. def setup(obj):
  65.     """
  66.    Calling sequence of setup:
  67.    PyMOL> run vsc-set.py
  68.    PyMOL> setup <object_file_name.pdb>
  69.    Variables:
  70.    'mutations': {'<POSITION_ID>':['<MUTATION_1>', '<MUTATION_2>', ...]}
  71.    """
  72.     # Setup.
  73.     pwd = os.getcwd()
  74.     #cmd.do('wizard mutagenesis')
  75.     #cmd.do('refresh_wizard')
  76.     # {'<resi>':'<resn>'}
  77.     orig_sequence = set_names(obj)
  78.     # Catalytically active positions.
  79.     do_not_mutate = ['78', '172']
  80.     if mode == prod:
  81.         all_side_chains = ['ALA', 'ARG', 'ASN', 'ASP',
  82.                            'CYS', 'GLU', 'GLN', 'GLY',
  83.                            'HIS', 'ILE', 'LEU', 'LYS',
  84.                            'MET', 'PHE', 'PRO', 'SER',
  85.                            'THR', 'TRP', 'TYR', 'VAL' ]
  86.     else:
  87.         all_side_chains = ['PHE', 'ASP', 'ILE']
  88.     positions_in_selection = get_all_positions_in_selection(sub, distance)
  89.     # 1) Avoid mutation of critical positions.
  90.     # 2) All side chains are included, discarding is controlled on MOPAC side.
  91.     mutations = {}
  92.     for i in positions_in_selection:
  93.         if i[0] not in do_not_mutate:
  94.             current_resn = i[1]
  95.             mutations[i[0]] = all_side_chains
  96.     for i in mutations.keys():
  97.         print i, mutations[i]
  98.     return pwd, mutations, orig_sequence
  99. # ------------------------------------------------------------
  100.  
  101. # ************************************************************
  102. def get_all_positions_in_selection(sub, distance):
  103.     cmd.do("select lig-def, resi %s" % sub)
  104.     cmd.select("lig-around", "(byres (lig-def around %s))" % distance)
  105.     cmd.select("lig-around-ca", "lig-around and name ca")
  106.     cmd.do("stored.li = []")
  107.     cmd.do("iterate (lig-around-ca), stored.li.append((resi, resn))")
  108.     cmd.do("delete all")
  109.     if mode == prod:
  110.         return stored.li
  111.     else:
  112.         return [('71', 'PHE')]
  113. # ------------------------------------------------------------
  114.  
  115. # ************************************************************
  116. # 'state=state': The first variable is the variable used within
  117. # the scope of this function. The second variable is the one
  118. # in the global scope and defined at the top of the module.
  119. # 'state': <1|3> for ES (1) complex or TI (3).
  120. def frag(state=state, obj=obj):
  121.     pwd, mutations, orig_sequence = setup(obj)
  122.  
  123.     #get_positions_in_selection(sub, distance)
  124.    
  125.     # Run over all sites where to mutate, optionally add and retain hydrogens.
  126.     for site in mutations.keys():
  127.         variants = mutations[site]
  128.         # Run over all variants.
  129.         for variant in variants:
  130.             cmd.load(obj)
  131.             cmd.do('wizard mutagenesis')
  132.             cmd.do('refresh_wizard')
  133.             cmd.get_wizard().set_hyd("keep")
  134.             cmd.get_wizard().set_mode(variant)
  135.             #cmd.get_wizard().do_select(site + '/')
  136.            
  137.             # Get the number of available rotamers at that site.
  138.             # Introduce a condition here to check if rotamers are requested.
  139.             # <<OPTIONAL>>
  140.             nRots = getRots(site, variant)
  141.             #if nRots > 3:
  142.             #    nRots = 3
  143.             nRots=1
  144.  
  145.             cmd.rewind()
  146.             for i in range(1, nRots + 1):
  147.                 cmd.get_wizard().do_select("(" + site + "/)")
  148.                 cmd.frame(i)
  149.                 cmd.get_wizard().apply()
  150.  
  151.                 # Optimize the mutated sidechain
  152.                 #<<OPTION>>
  153.                 #print "Sculpting."
  154.                 local_sculpt(obj, variant, site)
  155.  
  156.                 # Protonation of the N.
  157.                 #cmd.do("select n%d, name n and %d/" % (int(site), int(site)))
  158.                 #cmd.edit("n%d" % int(site), None, None, None, pkresi=0, pkbond=0)
  159.                 #cmd.do("h_fill")
  160.  
  161.                 # Protonation of the C.
  162.                 #cmd.do("select c%d, name c and %d/" % (int(site), int(site)))
  163.                 #cmd.edit("c%d" % int(site), None, None, None, pkresi=0, pkbond=0)
  164.                 #cmd.do("h_fill")
  165.  
  166.                 # Definition of saveString
  167.                 #saveString  = '%s/' % pwd
  168.                 #saveString += 'frag-' + get_one(orig_sequence[site]).lower() +\
  169.                 #               site + get_one(variant).lower() + '-%s.pdb, ' % state +\
  170.                 #               '((%s/))' % site
  171.                 save_string_rot  = '%s/' % pwd
  172.                 save_string_rot += 'frag-' + get_one(orig_sequence[site]).lower() +\
  173.                                   site + get_one(variant).lower() + '-%02d-%s.pdb, ' % (i, state) +\
  174.                                   '((%s/))' % site
  175.                 #print saveString
  176.                 #cmd.do('save %s' % saveString.lower())
  177.                 cmd.do('save %s' % save_string_rot.lower())
  178.             cmd.do('delete all')
  179.             cmd.set_wizard('done')
  180. # ------------------------------------------------------------
  181.  
  182. # ************************************************************
  183. # Convenience Functions
  184. def getRots(site, variant):
  185.     cmd.get_wizard().set_mode(variant)
  186.     # Key lines
  187.     # I dont know how they work, but they make it possible.
  188.     # Jason wrote this: If you just write "site" instead of
  189.     #                   "(site)", PyMOL will delete your
  190.     #                   residue. "(site)" makes it an
  191.     #                   anonymous selection.
  192.     #print 'getRots'
  193.     cmd.get_wizard().do_select("(" + str(site) + "/)")
  194.     nRot = cmd.count_states("mutation")
  195.     return nRot
  196.  
  197. def set_names(obj):
  198.     """
  199.    Return dictionary of {resi:resn} pairs.
  200.    Loaded object is deleted in 'get_all_positions_in_selection'.
  201.    """
  202.     orig_sequence = {}
  203.     cmd.load(obj)
  204.     cmd.select("prot", "name ca")
  205.     cmd.do("stored.names = []")
  206.     cmd.do("iterate (prot), stored.names.append((resi, resn))")
  207.     for i in stored.names:
  208.         orig_sequence[i[0]] = i[1]
  209.     return orig_sequence
  210.  
  211. # Credit: Thomas Holder, MPI
  212. # CONSTRUCT: - 'res'
  213. #            - 'cpy'
  214. #            -
  215. def local_sculpt(obj, variant_three, site):
  216.     # Original version of local side chain optimization
  217.     #res = str(site)
  218.     #cmd.protect('(not %s/) or name CA+C+N+O+OXT' % (res))
  219.     #print "Activating Sculpting."
  220.     #cmd.sculpt_activate(obj[:-4])
  221.     #cmd.sculpt_iterate(obj[:-4], cycles=50)
  222.     #cmd.sculpt_deactivate(obj[:-4])
  223.     #cmd.deprotect()
  224.  
  225.     # New version of local side chain optimization.
  226.     #cmd.select("%s%s_exp" % (variant_one, site), "(byres (\"%s/\" expand 1.8))" % site)
  227.     #cmd.select("%s%s_exp_sc" % (variant_one, site), "%s%s and (not name C+CA+N+O+HA+HT)" % (variant_one, site))
  228.     #cmd.protect("not %s%s_exp_sc" % (variant_one, site))
  229.     variant_one = get_one(variant_three)
  230.     cmd.select("%s%s" % (variant_one, site), "%s/" % site)
  231.     cmd.select("bb", "name C+CA+N+O+H+HA+HT")
  232.     cmd.select("%s%s_sc" % (variant_one, site), "%s%s and not bb" % (variant_one, site))
  233.     cmd.protect("not %s%s_sc" % (variant_one, site))
  234.     cmd.sculpt_activate(obj[:-4])
  235.     cmd.sculpt_iterate(obj[:-4], cycles=3000)
  236.     cmd.sculpt_deactivate(obj[:-4])
  237.     cmd.deprotect()
  238.  
  239. def get_one(three):
  240.     trans = {
  241.        'ALA':'A',
  242.        'ARG':'R',
  243.        'ASN':'N',
  244.        'ASP':'D',
  245.        'CYS':'C',
  246.        'GLU':'E',
  247.        'GLN':'Q',
  248.        'GLY':'G',
  249.        'HIS':'H',
  250.        'ILE':'I',
  251.        'LEU':'L',
  252.        'LYS':'K',
  253.        'MET':'M',
  254.        'PHE':'F',
  255.        'PRO':'P',
  256.        'SER':'S',
  257.        'THR':'T',
  258.        'TRP':'W',
  259.        'TYR':'Y',
  260.        'VAL':'V'
  261.        }
  262.     return trans[three]
  263.  
  264. def get_mutations_depending_on(current_resn):
  265.     if current_resn == 'ALA':
  266.         return ['GLY']
  267.     if current_resn == 'ARG':
  268.         return ['ALA', 'ASN', 'ASP', 'CYS', 'GLN', 'GLU', 'GLY', 'HIS', 'ILE', 'LEU', 'LYS', 'MET', 'PHE', 'PRO', 'SER', 'THR', 'TRP', 'TYR', 'VAL']
  269.     if current_resn == 'ASP':
  270.         return ['ALA', 'ASN', 'CYS', 'GLY', 'HIS', 'ILE', 'LEU', 'PHE', 'PRO', 'SER', 'THR', 'TYR', 'VAL']
  271.     if current_resn == 'ASN':
  272.         return ['ALA', 'ASP', 'CYS', 'GLY', 'HIS', 'ILE', 'LEU', 'PHE', 'PRO', 'SER', 'THR', 'TYR', 'VAL']
  273.     if current_resn == 'CYS':
  274.         return ['ALA', 'GLY', 'PRO', 'SER', 'THR']
  275.     if current_resn == 'GLU':
  276.         return ['ALA', 'ASN', 'ASP', 'CYS', 'GLN', 'GLY', 'HIS', 'ILE', 'LEU', 'LYS', 'MET', 'PHE', 'PRO', 'SER', 'THR', 'TRP', 'TYR', 'VAL']
  277.     if current_resn == 'GLN':
  278.         return ['ALA', 'ASN', 'ASP', 'CYS', 'GLU', 'GLY', 'HIS', 'ILE', 'LEU', 'LYS', 'MET', 'PHE', 'PRO', 'SER', 'THR', 'TRP', 'TYR', 'VAL']
  279.     if current_resn == 'GLY':
  280.         return ['ALA']
  281.     if current_resn == 'HIS':
  282.         return ['ALA, ASN', 'ASP', 'CYS', 'GLY', 'PHE', 'PRO', 'SER', 'THR', 'TYR', 'VAL']
  283.     if current_resn == 'ILE':
  284.         return ['ALA', 'ASN', 'ASP', 'CYS', 'GLY', 'HIS', 'LEU', 'PHE', 'PRO', 'SER', 'THR', 'TYR', 'VAL']
  285.     if current_resn == 'LEU':
  286.         return ['ALA', 'ASN', 'ASP', 'CYS', 'GLY', 'HIS', 'ILE', 'PHE', 'PRO', 'SER', 'THR', 'TYR', 'VAL']
  287.     if current_resn == 'LYS':
  288.         return ['ALA', 'ARG', 'ASN', 'ASP', 'CYS', 'GLN', 'GLU', 'GLY', 'HIS', 'ILE', 'LEU', 'MET', 'PHE', 'PRO', 'SER', 'THR', 'TRP', 'TYR', 'VAL']
  289.     if current_resn == 'MET':
  290.         return ['ALA', 'ASN', 'ASP', 'CYS', 'GLN', 'GLU', 'GLY', 'HIS', 'ILE', 'LEU', 'MET', 'PHE', 'PRO', 'SER', 'THR', 'TYR', 'VAL']
  291.     if current_resn == 'PHE':
  292.         return ['ALA', 'ASN', 'ASP', 'CYS', 'GLN', 'GLU', 'GLY', 'HIS', 'ILE', 'LEU', 'MET', 'PHE', 'PRO', 'SER', 'THR', 'TYR', 'VAL']
  293.     if current_resn == 'PRO':
  294.         return ['ALA', 'GLY', 'SER', 'THR']
  295.     if current_resn == 'SER':
  296.         return ['ALA', 'GLY', 'CYS', 'THR']
  297.     if current_resn == 'THR':
  298.         return ['ALA', 'GLY', 'CYS', 'SER']
  299.     if current_resn == 'TRP':
  300.         return ['ALA', 'ARG', 'ASN', 'ASP', 'CYS', 'GLN', 'GLU', 'GLY', 'HIS', 'ILE', 'LEU', 'LYS', 'MET', 'PHE', 'PRO', 'SER', 'THR', 'TYR', 'VAL']
  301.     if current_resn == 'TYR':
  302.         return ['ALA', 'ASN', 'ASP', 'CYS', 'GLN', 'GLU', 'GLY', 'HIS', 'ILE', 'LEU', 'MET', 'PHE', 'PRO', 'SER', 'THR', 'VAL']
  303.     if current_resn == 'VAL':
  304.         return ['ALA', 'ASN', 'ASP', 'CYS', 'GLN', 'GLU', 'GLY', 'HIS', 'ILE', 'LEU', 'MET', 'PHE', 'PRO', 'SER', 'THR', 'TYR']
  305.  
  306. # ------------------------------------------------------------
  307.  
  308. # ************************************************************
  309. # Expose to the PyMOL shell
  310. cmd.extend('setup', setup)
  311. cmd.extend('frag', frag)
  312. cmd.extend('getRots', getRots)
  313. cmd.extend('local_sculpt', local_sculpt)
  314. # ------------------------------------------------------------
clone this paste RAW Paste Data