ColorByRMSD: Difference between revisions

From PyMOLWiki
Jump to navigation Jump to search
Line 12: Line 12:
Program : ColByRMS
Program : ColByRMS
Date    : July 2009
Date    : July 2009
Version : 0.0.1 (very very alpha!)
Version : 0.0.2 (very very alpha!)
Mail    : firstname.lastname@umassmed.edu
Mail    : firstname.lastname@umassmed.edu
 
Keywords: color rms rmsd colorbyrms colorbyrmsd
Keywords: color rms rmsd colorbyrms colorbyrmsd
----------------------------------------------------------------------
----------------------------------------------------------------------
Line 23: Line 23:
----------------------------------------------------------------------
----------------------------------------------------------------------
"""
"""
 
import pymol
import pymol
import cmd
import cmd
 
# Code for a special case first
# Code for a special case first
cmd.load("D:/PyMOL-1.2r1/data/tut/1hpv.pdb", "1hpv")
cmd.load("D:/PyMOL-1.2r1/data/tut/1hpv.pdb", "1hpv")
 
cmd.create("chA", "1hpv and polymer and chain A")
cmd.create("chA", "1hpv and polymer and chain A")
cmd.create("chB", "1hpv and polymer and chain B")
cmd.create("chB", "1hpv and polymer and chain B")
 
# We need the alignment object, but PyMol refuses to give us that unless
# We need the alignment object, but PyMol refuses to give us that unless
# we (needlessly) specify all the other values in the cmd.align() function
# we (needlessly) specify all the other values in the cmd.align() function
# all the 0's are needlessly forced to be specified...
# all the 0's are needlessly forced to be specified...
# PyMol is not smart enough to use the defaults
# PyMol is not smart enough to use the defaults
# cmd.align("chA and name CA", "chB and name CA",0,0,0,0,0,object="aln")
cmd.align("chA and name CA", "chB and name CA",0,0,0,0,0,object="aln")
# So, lets use "super" instead
# So, lets use "super" instead
cmd.super("chA", "chB",object="aln")
#cmd.super("chA", "chB",object="aln")
 
# Utter the magic word
# Utter the magic word
cmd.refresh()
cmd.refresh()
 
# Arrays to store all residue identifiers in "aln"
# Arrays to store all residue identifiers in "aln"
stored.alnAres = []
stored.alnAres = []
stored.alnBres = []
stored.alnBres = []
 
# Now interrogate "aln" to get residue numbers for each object
# Now interrogate "aln" to get residue numbers for each object
cmd.iterate("chA and aln","stored.alnAres.append(resi)")
cmd.iterate("chA and aln","stored.alnAres.append(resi)")
cmd.iterate("chB and aln","stored.alnBres.append(resi)")
cmd.iterate("chB and aln","stored.alnBres.append(resi)")


# The main function that assigns "cur_rms"*10 as the new b-factor
print "Length of alnAres: "+str(len(stored.alnAres))
print "Length of alnBres: "+str(len(stored.alnBres))
# The main function that assigns "cur_rms" as the new b-factor
def colbyRMS(objA, alnAri, objB, alnBri):
def colbyRMS(objA, alnAri, objB, alnBri):
     cmd.alter(str(objA), "chain='Z'")
     cmd.alter(str(objA), "chain='Z'")
Line 58: Line 61:
     cmd.rebuild()
     cmd.rebuild()
     for x in range(len(alnAri)):
     for x in range(len(alnAri)):
         rmsd = cmd.rms_cur(str(objA)+" and i. "+str(alnAri[x]), str(objB)+" and i. "+str(alnBri[x]))
         rmsd = cmd.rms_cur(str(objA)+" and i. "+str(alnAri[x]), str(objB)+" and i. "+str(alnBri[x]), matchmaker=4)
         cmd.alter(str(objA)+" and resi "+str(alnAri[x]), "b = "+str(rmsd*10))
         cmd.alter(str(objA)+" and resi "+str(alnAri[x]), "b = "+str(rmsd))
         cmd.alter(str(objB)+" and resi "+str(alnBri[x]), "b = "+str(rmsd*10))
         cmd.alter(str(objB)+" and resi "+str(alnBri[x]), "b = "+str(rmsd))
 
cmd.extend("colbyRMS", colbyRMS)
cmd.extend("colbyRMS", colbyRMS)
 
# Run the just defined function
# Run the just defined function
if len(stored.alnAres) > len(stored.alnBres):
if len(stored.alnAres) > len(stored.alnBres):
Line 69: Line 72:
else:
else:
     colbyRMS("chB",stored.alnBres,"chA",stored.alnAres)
     colbyRMS("chB",stored.alnBres,"chA",stored.alnAres)
 
# Arrays to store the NEW b-factors
# Arrays to store the NEW b-factors
stored.alnAnb = []
stored.alnAnb = []
stored.alnBnb = []
stored.alnBnb = []
 
# Store the NEW b-factors
# Store the NEW b-factors
cmd.iterate("chA and aln","stored.alnAnb.append(b)")
cmd.iterate("chA and aln","stored.alnAnb.append(b)")
cmd.iterate("chB and aln","stored.alnBnb.append(b)")
cmd.iterate("chB and aln","stored.alnBnb.append(b)")
 
# Assign the just stored NEW b-factors to the original object
# Assign the just stored NEW b-factors to the original object
for x in range(len(stored.alnAres)):
for x in range(len(stored.alnAres)):
Line 83: Line 86:
for x in range(len(stored.alnBres)):
for x in range(len(stored.alnBres)):
     cmd.alter("1hpv and chain B and resi "+str(stored.alnBres[x]), "b = "+str(stored.alnBnb[x]))
     cmd.alter("1hpv and chain B and resi "+str(stored.alnBres[x]), "b = "+str(stored.alnBnb[x]))
 
# Get rid of all intermediate objects etc.
# Get rid of all intermediate objects etc.
cmd.delete("chA")
cmd.delete("chA")
cmd.delete("chB")
cmd.delete("chB")
cmd.delete("aln")
cmd.delete("aln")
 
# Showcase what you did
# Showcase what you did
cmd.orient()
cmd.orient()
Line 96: Line 99:
print "\n"
print "\n"
print "Colored by 'overall' RMSD...\n"
print "Colored by 'overall' RMSD...\n"
cmd.spectrum("b", "rainbow", "1hpv")
cmd.spectrum("b", "rainbow", "1hpv and polymer")
</source>
</source>

Revision as of 22:54, 14 July 2009

Introduction

An attempt to perform a coloring of two structures by RMS deviation as calculated by PyMol's internal Rms_Cur command.

Code

WARNING: This is still a work in progress, and is almost useless right now! It is just a proof of principle at this stage and mainly an attempt at using the "alignment" object to iterate over the aligned objects. However, if you make any improvements, please do edit this page to reflect the same.

"""
--- ColorByRMSD: RMSD based coloring --- 
Author  : Shivender Shandilya
Program : ColByRMS
Date    : July 2009
Version : 0.0.2 (very very alpha!)
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
 
# Code for a special case first
cmd.load("D:/PyMOL-1.2r1/data/tut/1hpv.pdb", "1hpv")
 
cmd.create("chA", "1hpv and polymer and chain A")
cmd.create("chB", "1hpv and polymer and chain B")
 
# We need the alignment object, but PyMol refuses to give us that unless
# we (needlessly) specify all the other values in the cmd.align() function
# all the 0's are needlessly forced to be specified...
# PyMol is not smart enough to use the defaults
cmd.align("chA and name CA", "chB and name CA",0,0,0,0,0,object="aln")
# So, lets use "super" instead
#cmd.super("chA", "chB",object="aln")
 
# Utter the magic word
cmd.refresh()
 
# Arrays to store all residue identifiers in "aln"
stored.alnAres = []
stored.alnBres = []
 
# Now interrogate "aln" to get residue numbers for each object
cmd.iterate("chA and aln","stored.alnAres.append(resi)")
cmd.iterate("chB and aln","stored.alnBres.append(resi)")

print "Length of alnAres: "+str(len(stored.alnAres))
print "Length of alnBres: "+str(len(stored.alnBres))
 
# The main function that assigns "cur_rms" as the new b-factor
def colbyRMS(objA, alnAri, objB, alnBri):
    cmd.alter(str(objA), "chain='Z'")
    cmd.alter(str(objB), "chain='Z'")
    cmd.rebuild()
    for x in range(len(alnAri)):
        rmsd = cmd.rms_cur(str(objA)+" and i. "+str(alnAri[x]), str(objB)+" and i. "+str(alnBri[x]), matchmaker=4)
        cmd.alter(str(objA)+" and resi "+str(alnAri[x]), "b = "+str(rmsd))
        cmd.alter(str(objB)+" and resi "+str(alnBri[x]), "b = "+str(rmsd))
 
cmd.extend("colbyRMS", colbyRMS)
 
# Run the just defined function
if len(stored.alnAres) > len(stored.alnBres):
    colbyRMS("chA",stored.alnAres,"chB",stored.alnBres)
else:
    colbyRMS("chB",stored.alnBres,"chA",stored.alnAres)
 
# Arrays to store the NEW b-factors
stored.alnAnb = []
stored.alnBnb = []
 
# Store the NEW b-factors
cmd.iterate("chA and aln","stored.alnAnb.append(b)")
cmd.iterate("chB and aln","stored.alnBnb.append(b)")
 
# Assign the just stored NEW b-factors to the original object
for x in range(len(stored.alnAres)):
    cmd.alter("1hpv and chain A and resi "+str(stored.alnAres[x]), "b = "+str(stored.alnAnb[x]))
for x in range(len(stored.alnBres)):
    cmd.alter("1hpv and chain B and resi "+str(stored.alnBres[x]), "b = "+str(stored.alnBnb[x]))
 
# Get rid of all intermediate objects etc.
cmd.delete("chA")
cmd.delete("chB")
cmd.delete("aln")
 
# Showcase what you did
cmd.orient()
cmd.hide("all")
cmd.show("cartoon", "1hpv")
cmd.cartoon("loop")
print "\n"
print "Colored by 'overall' RMSD...\n"
cmd.spectrum("b", "rainbow", "1hpv and polymer")