Difference between revisions of "ColorByRMSD"

From PyMOLWiki
Jump to navigation Jump to search
(First Release)
Line 1: Line 1:
THIS PAGE IS UNDERGOING RAPID CHANGES.<br>
 
PLEASE KEEP REFRESHING YOUR BROWSER's CACHE TO DISPLAY RECENT CHANGES (SHIFT-RELOAD in Firefox).
 
 
== Introduction ==
 
== Introduction ==
An attempt to perform a coloring of two structures by RMS deviation as calculated by PyMol's internal [[Rms_Cur]] command.
+
This script allows you to color two structures by Root Mean Square Deviation (RMSD), as calculated by PyMol's internal [[Rms_Cur]] command. The pairwise, C-alpha, RMSD is calculated only between those residues which are first used by PyMol's internal [[Super]] command to superpose the two structures. The RMSD values are stored as B-factors of these residues, which are colored by a ''rainbow'' color spectrum, with blue specifying the minimum pairwise RMSD and red indicating the maximum. Residues ''NOT'' used by [[Super]] for RMSD calculation are colored ''white''.
  
 
== Code ==
 
== Code ==
This is new code, modified from the work done by Jason and myself.<br>
+
Please use this script with the option '''doPretty=T''' to gain the most benefit. Additionally, setting [[Cartoon]] representation to ''loop'', with the command: <source lang="python"> cartoon loop </script> may help ease comparisons. Do keep in mind, all original B-factors values are overwritten!
If you use the option '''doPretty=T''', the residues NOT used for alignment/superposition are now colored '''white'''.<br>
 
Please test and see if it works (somewhat) better. ''--[[User:Shiven|shiven]] 19:38, 16 July 2009 (UTC)''
 
  
 
==== Examples ====
 
==== Examples ====
 
<source lang="python">
 
<source lang="python">
 
# example #1
 
# example #1
colorByRMSD 1cbs, 1hmt, doAlign=True, doPretty=T
+
colorByRMSD 1cbs, 1hmt, doAlign=T, doPretty=T
 
# example #2
 
# example #2
colorByRMSD 1eaz, 1fao, doAlign=True, doPretty=T
+
colorByRMSD 1eaz, 1fao, doAlign=T, doPretty=T
 
</source>
 
</source>
  
Line 28: Line 24:
 
Program : ColorByRMSD
 
Program : ColorByRMSD
 
Date    : July 2009
 
Date    : July 2009
Version : 0.0.3 (very alpha!)
+
Version : 0.1.0 (first release!)
 
Mail    : firstname.lastname@umassmed.edu
 
Mail    : firstname.lastname@umassmed.edu
 
   
 
   
Line 47: Line 43:
 
     return p[0].upper() == "T"
 
     return p[0].upper() == "T"
 
   
 
   
# The main function that assigns "cur_rms" as the new b-factor
+
# The main function that assigns current RMSD as the new B-factor
 
def rmsUpdateB(objA, alnAri, objB, alnBri):
 
def rmsUpdateB(objA, alnAri, objB, alnBri):
    # don't need the *10 -- PyMOL scales things for us.
 
 
     for x in range(len(alnAri)):
 
     for x in range(len(alnAri)):
 
         s1 = objA + " and n. CA and i. " + alnAri[x]
 
         s1 = objA + " and n. CA and i. " + alnAri[x]
Line 61: Line 56:
 
def colorByRMSD(objSel1, objSel2, doAlign="True", doPretty=None):
 
def colorByRMSD(objSel1, objSel2, doAlign="True", doPretty=None):
 
     """
 
     """
     colorByRMSD -- align two structures and show the structural deviations in
+
     colorByRMSD -- align two structures and show the structural deviations
        color to more easily see variable regions.
+
                  in color to more easily see variable regions.
 
   
 
   
 
     PARAMS
 
     PARAMS
Line 73: Line 68:
 
   
 
   
 
         doAlign (boolean, either True or False)
 
         doAlign (boolean, either True or False)
             Should this script align your proteins or just leave them where they
+
             Should this script align your proteins or just leave them as is?
             are?  If doAlign=True then your original proteins are aligned. If
+
             If doAlign=True then your original proteins are aligned.
             doAlign=False, then they are not. Regardless, the b-factors are
+
             If False, then they are not. Regardless, the B-factors are changed.
            changed.
 
 
             DEFAULT: True
 
             DEFAULT: True
 
   
 
   
 
         doPretty (boolean, either True or False)
 
         doPretty (boolean, either True or False)
             If doPretty=True then a simple representation is created to high-
+
             If doPretty=True then a simple representation is created to
             light the differences.  If False, then no change is done to the
+
             highlight the differences.  If False, then no changes are made.
            structure.
+
             DEFAULT: False
             DEFAULT: None
 
 
   
 
   
 
     RETURNS
 
     RETURNS
Line 89: Line 82:
 
   
 
   
 
     SIDE-EFFECTS
 
     SIDE-EFFECTS
         Modified the b-factor columns in your original proteins.
+
         Modifies the B-factor columns in your original structures.
 
   
 
   
 
     """
 
     """
     # create backup copies; names starting with _ (underscores) are
+
     # First create backup copies; names starting with __ (underscores) are
     # hidden by PyMOL
+
     # normally hidden by PyMOL
 
     tObj1, tObj2, aln = "__tempObj1", "__tempObj2", "__aln"
 
     tObj1, tObj2, aln = "__tempObj1", "__tempObj2", "__aln"
 
   
 
   
Line 100: Line 93:
 
         cmd.create( tObj1, objSel1 )
 
         cmd.create( tObj1, objSel1 )
 
         cmd.create( tObj2, objSel2 )
 
         cmd.create( tObj2, objSel2 )
#      cmd.align( tObj1, tObj2, object=aln )
 
 
         cmd.super( tObj1, tObj2, object=aln )
 
         cmd.super( tObj1, tObj2, object=aln )
        # bug -- every other call undoes this...
 
 
         cmd.matrix_copy(tObj1, objSel1)
 
         cmd.matrix_copy(tObj1, objSel1)
 
     else:
 
     else:
Line 108: Line 99:
 
         cmd.create( tObj1, objSel1 )
 
         cmd.create( tObj1, objSel1 )
 
         cmd.create( tObj2, objSel2 )
 
         cmd.create( tObj2, objSel2 )
#      cmd.align( tObj1, tObj2, object=aln )
 
 
         cmd.super( tObj1, tObj2, object=aln )
 
         cmd.super( tObj1, tObj2, object=aln )
  
#   cmd.alter( tObj1 + " or " + tObj2, "b=-10")
+
    # Modify the B-factor columns of the original objects,
#  Now modify the B-factor columns of the original objects,
+
    # in order to identify the residues NOT used for alignment, later on
#   so as to later identify the residues NOT used for alignment
 
 
     cmd.alter( objSel1 + " or " + objSel2, "b=-10")
 
     cmd.alter( objSel1 + " or " + objSel2, "b=-10")
 
     cmd.alter( tObj1 + " or " + tObj2, "chain='A'")
 
     cmd.alter( tObj1 + " or " + tObj2, "chain='A'")
 
     cmd.alter( tObj1 + " or " + tObj2, "segi='A'")
 
     cmd.alter( tObj1 + " or " + tObj2, "segi='A'")
     # update PyMOL;
+
 
    # one of these should do the trick
+
     # Update pymol internal representations; one of these should do the trick
 
     cmd.refresh(); cmd.rebuild(); cmd.sort(tObj1); cmd.sort(tObj2)
 
     cmd.refresh(); cmd.rebuild(); cmd.sort(tObj1); cmd.sort(tObj2)
 
   
 
   
     #  Get the residue identifiers from the aln object
+
     #  Create lists for storage
 
     stored.alnAres, stored.alnBres = [], []
 
     stored.alnAres, stored.alnBres = [], []
 +
 +
    #  Get the residue identifiers from the alignment object "aln"
 
     cmd.iterate(tObj1 + " and n. CA and " + aln, "stored.alnAres.append(resi)")
 
     cmd.iterate(tObj1 + " and n. CA and " + aln, "stored.alnAres.append(resi)")
 
     cmd.iterate(tObj2 + " and n. CA and " + aln, "stored.alnBres.append(resi)")
 
     cmd.iterate(tObj2 + " and n. CA and " + aln, "stored.alnBres.append(resi)")
 
   
 
   
     #print "Length of alnAres using 'super': "+str(len(stored.alnAres))
+
     # Change the B-factors for EACH object
    #print "Length of alnBres using 'super': "+str(len(stored.alnBres))
 
 
 
    # reset the b-factors for each object
 
 
     rmsUpdateB(tObj1,stored.alnAres,tObj2,stored.alnBres)
 
     rmsUpdateB(tObj1,stored.alnAres,tObj2,stored.alnBres)
  
     # Store the NEW b-factors
+
     # Store the NEW B-factors
 
     stored.alnAnb, stored.alnBnb = [], []
 
     stored.alnAnb, stored.alnBnb = [], []
 
     cmd.iterate(tObj1 + " and n. CA and " + aln, "stored.alnAnb.append(b)" )
 
     cmd.iterate(tObj1 + " and n. CA and " + aln, "stored.alnAnb.append(b)" )
 
     cmd.iterate(tObj2 + " and n. CA and " + aln, "stored.alnBnb.append(b)" )
 
     cmd.iterate(tObj2 + " and n. CA and " + aln, "stored.alnBnb.append(b)" )
 
   
 
   
     # Get rid of all intermediate objects etc.; clean up
+
     # Get rid of all intermediate objects and clean up
 
     cmd.delete(tObj1)
 
     cmd.delete(tObj1)
 
     cmd.delete(tObj2)
 
     cmd.delete(tObj2)
 
     cmd.delete(aln)
 
     cmd.delete(aln)
 
   
 
   
     # Assign the just stored NEW b-factors to the original object
+
     # Assign the just stored NEW B-factors to the original objects
 
     for x in range(len(stored.alnAres)):
 
     for x in range(len(stored.alnAres)):
 
         cmd.alter(objSel1 + " and n. CA and i. " + str(stored.alnAres[x]), "b = " + str(stored.alnAnb[x]))
 
         cmd.alter(objSel1 + " and n. CA and i. " + str(stored.alnAres[x]), "b = " + str(stored.alnAnb[x]))
Line 156: Line 144:
 
         # Select the residues not used for alignment; they still have their B-factors as "-10"
 
         # Select the residues not used for alignment; they still have their B-factors as "-10"
 
         cmd.select("notUsedForAln", "b < 0")
 
         cmd.select("notUsedForAln", "b < 0")
        cmd.disable("notUsedForAln")
 
 
# White-wash the residues not used for alignment
 
# White-wash the residues not used for alignment
 
cmd.color("white", "notUsedForAln")
 
cmd.color("white", "notUsedForAln")
 
# Color the residues used for alignment according to their B-factors (RMSD values)
 
# Color the residues used for alignment according to their B-factors (RMSD values)
 
         cmd.spectrum("b", 'rainbow',  "((" + objSel1 + " and n. CA) or (n. CA and " + objSel2 +" )) and not notUsedForAln")
 
         cmd.spectrum("b", 'rainbow',  "((" + objSel1 + " and n. CA) or (n. CA and " + objSel2 +" )) and not notUsedForAln")
         print "\nColorByRMSD completed successfully. Objects are now colored by C-alpha RMS deviation.\n"
+
        # Delete the selection of atoms not used for alignment
 +
        # If you would like to keep this selection intact,
 +
        # just comment "cmd.delete" line and
 +
        # uncomment the "cmd.disable" line below.
 +
        cmd.delete("notUsedForAln")
 +
        # cmd.disable("notUsedForAln")
 +
 
 +
         print "\nColorByRMSD completed successfully.\nObjects are now colored by C-alpha RMS deviation.\n"
  
 
cmd.extend("colorByRMSD", colorByRMSD)
 
cmd.extend("colorByRMSD", colorByRMSD)

Revision as of 21:55, 16 July 2009

Introduction

This script allows you to color two structures by Root Mean Square Deviation (RMSD), as calculated by PyMol's internal Rms_Cur command. The pairwise, C-alpha, RMSD is calculated only between those residues which are first used by PyMol's internal Super command to superpose the two structures. The RMSD values are stored as B-factors of these residues, which are colored by a rainbow color spectrum, with blue specifying the minimum pairwise RMSD and red indicating the maximum. Residues NOT used by Super for RMSD calculation are colored white.

Code

Please use this script with the option doPretty=T to gain the most benefit. Additionally, setting Cartoon representation to loop, with the command:

 cartoon loop </script> may help ease comparisons. Do keep in mind, all original B-factors values are overwritten!

==== Examples ====
<source lang="python">
# example #1
colorByRMSD 1cbs, 1hmt, doAlign=T, doPretty=T
# example #2
colorByRMSD 1eaz, 1fao, doAlign=T, doPretty=T
"""
--- ColorByRMSD: RMSD based coloring --- 
Authors : Shivender Shandilya; Jason Vertrees
Program : ColorByRMSD
Date    : July 2009
Version : 0.1.0 (first release!)
Mail    : firstname.lastname@umassmed.edu
 
Keywords: color rms rmsd colorbyrms colorbyrmsd
----------------------------------------------------------------------
Reference:
 This email from Warren - http://www.mail-archive.com/pymol-users@lists.sourceforge.net/msg07078.html
Literature:
 DeLano, W.L. The PyMOL Molecular Graphics System (2002) DeLano Scientific, San Carlos, CA, USA. http://www.pymol.org
----------------------------------------------------------------------
"""
 
import pymol
import cmd
from pymol import stored
 
def strTrue(p):
    return p[0].upper() == "T"
 
# The main function that assigns current RMSD as the new B-factor
def rmsUpdateB(objA, alnAri, objB, alnBri):
    for x in range(len(alnAri)):
        s1 = objA + " and n. CA and i. " + alnAri[x]
        s2 = objB + " and n. CA and i. " + alnBri[x]
        rmsd = cmd.rms_cur(s1, s2, matchmaker=4)
        cmd.alter( s1, "b = " + str(rmsd))
        cmd.alter( s2, "b = " + str(rmsd))
    cmd.sort(objA); cmd.sort(objB)

 
def colorByRMSD(objSel1, objSel2, doAlign="True", doPretty=None):
    """
    colorByRMSD -- align two structures and show the structural deviations
                   in color to more easily see variable regions.
 
    PARAMS
 
        objSel1 (valid PyMOL object or selection)
            The first object to align.  
 
        objSel2 (valid PyMOL object or selection)
            The second object to align
 
        doAlign (boolean, either True or False)
            Should this script align your proteins or just leave them as is?
            If doAlign=True then your original proteins are aligned.
            If False, then they are not. Regardless, the B-factors are changed.
            DEFAULT: True
 
        doPretty (boolean, either True or False)
            If doPretty=True then a simple representation is created to
            highlight the differences.  If False, then no changes are made.
            DEFAULT: False
 
    RETURNS
        None.
 
    SIDE-EFFECTS
        Modifies the B-factor columns in your original structures.
 
    """
    # First create backup copies; names starting with __ (underscores) are
    # normally hidden by PyMOL
    tObj1, tObj2, aln = "__tempObj1", "__tempObj2", "__aln"
 
    if strTrue(doAlign):
        # perform the alignment
        cmd.create( tObj1, objSel1 )
        cmd.create( tObj2, objSel2 )
        cmd.super( tObj1, tObj2, object=aln )
        cmd.matrix_copy(tObj1, objSel1)
    else:
        # perform the alignment
        cmd.create( tObj1, objSel1 )
        cmd.create( tObj2, objSel2 )
        cmd.super( tObj1, tObj2, object=aln )

    # Modify the B-factor columns of the original objects,
    # in order to identify the residues NOT used for alignment, later on
    cmd.alter( objSel1 + " or " + objSel2, "b=-10")
    cmd.alter( tObj1 + " or " + tObj2, "chain='A'")
    cmd.alter( tObj1 + " or " + tObj2, "segi='A'")

    # Update pymol internal representations; one of these should do the trick
    cmd.refresh(); cmd.rebuild(); cmd.sort(tObj1); cmd.sort(tObj2)
 
    #  Create lists for storage
    stored.alnAres, stored.alnBres = [], []

    #  Get the residue identifiers from the alignment object "aln"
    cmd.iterate(tObj1 + " and n. CA and " + aln, "stored.alnAres.append(resi)")
    cmd.iterate(tObj2 + " and n. CA and " + aln, "stored.alnBres.append(resi)")
 
    # Change the B-factors for EACH object
    rmsUpdateB(tObj1,stored.alnAres,tObj2,stored.alnBres)

    # Store the NEW B-factors
    stored.alnAnb, stored.alnBnb = [], []
    cmd.iterate(tObj1 + " and n. CA and " + aln, "stored.alnAnb.append(b)" )
    cmd.iterate(tObj2 + " and n. CA and " + aln, "stored.alnBnb.append(b)" )
 
    # Get rid of all intermediate objects and clean up
    cmd.delete(tObj1)
    cmd.delete(tObj2)
    cmd.delete(aln)
 
    # Assign the just stored NEW B-factors to the original objects
    for x in range(len(stored.alnAres)):
        cmd.alter(objSel1 + " and n. CA and i. " + str(stored.alnAres[x]), "b = " + str(stored.alnAnb[x]))
    for x in range(len(stored.alnBres)):
        cmd.alter(objSel2 + " and n. CA and i. " + str(stored.alnBres[x]), "b = " + str(stored.alnBnb[x]))
    cmd.rebuild(); cmd.refresh(); cmd.sort(objSel1); cmd.sort(objSel2)
 
    if doPretty!=None:
        # Showcase what we did
        cmd.orient()
        cmd.hide("all")
        cmd.show_as("cartoon", objSel1 + " or " + objSel2)
        # Select the residues not used for alignment; they still have their B-factors as "-10"
        cmd.select("notUsedForAln", "b < 0")
	# White-wash the residues not used for alignment
	cmd.color("white", "notUsedForAln")
	# Color the residues used for alignment according to their B-factors (RMSD values)
        cmd.spectrum("b", 'rainbow',  "((" + objSel1 + " and n. CA) or (n. CA and " + objSel2 +" )) and not notUsedForAln")
        # Delete the selection of atoms not used for alignment
        # If you would like to keep this selection intact,
        # just comment "cmd.delete" line and
        # uncomment the "cmd.disable" line below.
        cmd.delete("notUsedForAln")
        # cmd.disable("notUsedForAln")

        print "\nColorByRMSD completed successfully.\nObjects are now colored by C-alpha RMS deviation.\n"

cmd.extend("colorByRMSD", colorByRMSD)