Color

From PyMOLWiki
Revision as of 10:53, 20 May 2008 by Domsicj (talk | contribs) (reversed order of "ramp_obj" and "your-objec-name" for the "set surface_color" option.)
Jump to navigation Jump to search

DESCRIPTION

color changes the color of an object or an atom selection.

USAGE

color color-name
color color-name, object-name
color color-name, (selection)

PYMOL API

cmd.color( string color, string selection )

Using RGB for Color

If you prefer RGB to color any object

set_color newcolor, [r,g,b]
color newcolor

List of Color Values

EXAMPLES

Color all carbons yellow

color yellow, (name C*)

RGB Example

set_color khaki, [195,176,145]
color khaki

Color by Spectrum Example

Color by spectrum is in the GUI menu but did you realize that the spectrum is not limited to a simple rainbow?

spectrum count, x, object_name

x can can be anyone of the following: blue_green, green_white_magenta, red_cyan, blue_magenta, green_white_red, red_green, blue_red, green_white_yellow, red_white_blue, blue_white_green, green_yellow, red_white_cyan, blue_white_magenta, green_yellow_red, red_white_green, blue_white_red, magenta_blue, red_white_yellow, blue_white_yellow, magenta_cyan, red_yellow, blue_yellow, magenta_green, red_yellow_green, cbmr, magenta_white_blue, rmbc, cyan_magenta, magenta_white_cyan, yellow_blue, cyan_red, magenta_white_green, yellow_cyan, cyan_white_magenta, magenta_white_yellow, yellow_cyan_white, cyan_white_red, magenta_yellow, yellow_green, cyan_white_yellow, rainbow, yellow_magenta, cyan_yellow, rainbow2, yellow_red, gcbmry, rainbow2_rev, yellow_white_blue, green_blue, rainbow_cycle, yellow_white_green, green_magenta, rainbow_cycle_rev, yellow_white_magenta, green_red, rainbow_rev, yellow_white_red, green_white_blue, red_blue, yrmbcg

B-Factors

The command to color a molecule by B-Factors (B Factors) is:

cmd.spectrum("b", selection="SEL");

where SEL is a valid selection, for example, "protA and n. CA", for protein A's alpha carbons.

You can choose the spectrum you want with the command:

cmd.spectrum("b", 'rainbow', selection="SEL");

where rainbow is a valid selection from the list:

  blue_green            green_white_magenta   red_cyan            
  blue_magenta          green_white_red       red_green           
  blue_red              green_white_yellow    red_white_blue      
  blue_white_green      green_yellow          red_white_cyan      
  blue_white_magenta    green_yellow_red      red_white_green     
  blue_white_red        magenta_blue          red_white_yellow    
  blue_white_yellow     magenta_cyan          red_yellow          
  blue_yellow           magenta_green         red_yellow_green    
  cbmr                  magenta_white_blue    rmbc                
  cyan_magenta          magenta_white_cyan    yellow_blue         
  cyan_red              magenta_white_green   yellow_cyan         
  cyan_white_magenta    magenta_white_yellow  yellow_cyan_white   
  cyan_white_red        magenta_yellow        yellow_green        
  cyan_white_yellow     rainbow               yellow_magenta      
  cyan_yellow           rainbow2              yellow_red          
  gcbmry                rainbow2_rev          yellow_white_blue   
  green_blue            rainbow_cycle         yellow_white_green  
  green_magenta         rainbow_cycle_rev     yellow_white_magenta
  green_red             rainbow_rev           yellow_white_red    
  green_white_blue      red_blue              yrmbcg 

Reassigning B-Factors and Coloring

It is commonplace to replace the B-Factor column of a protein with some other biochemical property at that residue, observed from some calculation or experiment. PyMOL can easily reassign the B-Factors and color them, too. The following example will load a protein, set ALL it's B Factors to "0", read in a list of properties for each alpha carbon in the proteins, assign those new values as the B-Factor values and color by the new values. This example is possible because commands PyMOL does not recognize are passed to the Python interpreter --- a very powerful tool.

# load the protein
cmd.load("protA.pdb")

# open the file of new values (just 1 column of numbers, one for each alpha carbon)
inFile = open("newBFactors", 'r')

# create the global, stored array
stored.newB = []

# read the new B factors from file
for line in inFile.readlines(): stored.newB.append( float(line) )

# close the input file
inFile.close()

# clear out the old B Factors
alter protA, b=0.0

# update the B Factors with new properties
alter protA and n. CA, b=stored.newB.pop(0)

# color the protein based on the new B Factors of the alpha carbons
cmd.spectrum("b", "protA and n. CA")

If you want to save the file with the new B Factor values for each alpha carbon,

cmd.save("protA_newBFactors.pdb", "protA")

or similar is all you need.


Expanding to Surface

If you have run the above code and would like the colors to be shown in the Surface representation, too, then you need to do the following:

# Assumes alpha carbons colored from above.
create ca_obj, your-object-name and name ca 
ramp_new ramp_obj, ca_obj, [0, 10], [-1, -1, 0]
set surface_color, ramp_obj, your-object-name

Thanks to Warren, for this one.