Difference between revisions of "Resicolor"

From PyMOLWiki
Jump to navigation Jump to search
Line 1: Line 1:
 
Hello !
 
Hello !
  
Here is a small script to color proteins according to residue type. Call it from your .pymolrc or from within pymol: "run resicolor.py". Then, issuing "resicolor" will apply the scheme. Selections are supported: "resicolor chain A" will apply the scheme only to chain A.  
+
Here is a small plugin to color proteins according to residue type. Copy this into a file saved as resicolor.py inside your plugins startup directory, and it should add itself to the plugins menu at the next pymol startup. The script version (accessible from command line) is presented below.
 +
 
 +
<source lang="python">
 +
from Tkinter import *
 +
from pymol import cmd
 +
 
 +
def __init__(self):
 +
    # Simply add the menu entry and callback
 +
    self.menuBar.addmenuitem('Plugin', 'command',
 +
                                    'resicolor',
 +
                                    label = 'resicolor',
 +
                                    command = lambda s=self : resicolor(s))
 +
class resicolor:
 +
    def __init__(self,app):
 +
        import tkSimpleDialog
 +
        selection=tkSimpleDialog.askstring('resicolor',
 +
                                                  'Please enter a selection',
 +
                                                  parent=app.root)
 +
        if selection:
 +
            cmd.select ('calcium','resn ca or resn cal')
 +
            cmd.select ('acid','resn asp or resn glu or resn cgu')
 +
            cmd.select ('basic','resn arg or resn lys or resn his')
 +
            cmd.select ('nonpolar','resn met or resn phe or resn pro or resn trp or resn val or resn leu or resn ile or resn ala')
 +
            cmd.select ('polar','resn ser or resn thr or resn asn or resn gln or resn tyr')
 +
            cmd.select ('cys','resn cys or resn cyx')
 +
            cmd.select ('backbone','name ca or name n or name c or name o')
 +
            cmd.select ('none')   
 +
            code={'acid'    :  'red'    ,
 +
                  'basic'  :  'blue'  ,
 +
                  'nonpolar':  'orange' ,
 +
                  'polar'  :  'green'  ,
 +
                  'cys'    :  'yellow'}
 +
            cmd.do ('getchem')
 +
            cmd.select ('none')
 +
            for elem in code:
 +
                line='color '+code[elem]+','+elem+'&'+selection
 +
                print line
 +
                cmd.do (line)
 +
            word='color white,backbone &'+selection
 +
            print word
 +
            cmd.do (word)                  #Used to be in code, but looks like
 +
                                          #dictionnaries are accessed at random
 +
</source>
 +
 
 +
Here is the corresponding script file. Call it from your .pymolrc or from within pymol: "run resicolor.py". Then, issuing "resicolor" will apply the scheme. Selections are supported: "resicolor chain A" will apply the scheme only to chain A.  
 
<source lang="python">
 
<source lang="python">
 
from pymol import cmd
 
from pymol import cmd

Revision as of 14:49, 10 April 2007

Hello !

Here is a small plugin to color proteins according to residue type. Copy this into a file saved as resicolor.py inside your plugins startup directory, and it should add itself to the plugins menu at the next pymol startup. The script version (accessible from command line) is presented below.

from Tkinter import *
from pymol import cmd

def __init__(self):
    # Simply add the menu entry and callback
    self.menuBar.addmenuitem('Plugin', 'command',
                                     'resicolor',
                                     label = 'resicolor',
                                     command = lambda s=self : resicolor(s))
class resicolor:
    def __init__(self,app):
        import tkSimpleDialog
        selection=tkSimpleDialog.askstring('resicolor',
                                                  'Please enter a selection',
                                                  parent=app.root)
        if selection:
            cmd.select ('calcium','resn ca or resn cal')
            cmd.select ('acid','resn asp or resn glu or resn cgu')
            cmd.select ('basic','resn arg or resn lys or resn his')
            cmd.select ('nonpolar','resn met or resn phe or resn pro or resn trp or resn val or resn leu or resn ile or resn ala')
            cmd.select ('polar','resn ser or resn thr or resn asn or resn gln or resn tyr')
            cmd.select ('cys','resn cys or resn cyx')
            cmd.select ('backbone','name ca or name n or name c or name o')
            cmd.select ('none')     
            code={'acid'    :  'red'    ,
                  'basic'   :  'blue'   ,
                  'nonpolar':  'orange' ,
                  'polar'   :  'green'  ,
                  'cys'     :  'yellow'}
            cmd.do ('getchem')
            cmd.select ('none')
            for elem in code:
                line='color '+code[elem]+','+elem+'&'+selection
                print line
                cmd.do (line)
            word='color white,backbone &'+selection
            print word
            cmd.do (word)                  #Used to be in code, but looks like
                                           #dictionnaries are accessed at random

Here is the corresponding script file. Call it from your .pymolrc or from within pymol: "run resicolor.py". Then, issuing "resicolor" will apply the scheme. Selections are supported: "resicolor chain A" will apply the scheme only to chain A.

from pymol import cmd

def resicolor(selection='all'):
    
    '''USAGE: resicolor <selection>
    colors all or the given selection with arbitrary
    coloring scheme.
    '''
    cmd.select ('calcium','resn ca or resn cal')
    cmd.select ('acid','resn asp or resn glu or resn cgu')
    cmd.select ('basic','resn arg or resn lys or resn his')
    cmd.select ('nonpolar','resn met or resn phe or resn pro or resn trp or resn val or resn leu or resn ile or resn ala')
    cmd.select ('polar','resn ser or resn thr or resn asn or resn gln or resn tyr')
    cmd.select ('cys','resn cys or resn cyx')
    cmd.select ('backbone','name ca or name n or name c or name o')
    cmd.select ('none')

    print selection
    code={'acid'    :  'red'    ,
          'basic'   :  'blue'   ,
          'nonpolar':  'orange' ,
          'polar'   :  'green'  ,
          'cys'     :  'yellow'}
    cmd.do ('getchem')
    cmd.select ('none')
    for elem in code:
        line='color '+code[elem]+','+elem+'&'+selection
        print line
        cmd.do (line)
    word='color white,backbone &'+selection
    print word
    cmd.do (word)                  #Used to be in code, but looks like
                                   #dictionnaries are accessed at random
    cmd.hide ('everything','resn HOH')

cmd.extend ('resicolor',resicolor)