This is a read-only mirror of pymolwiki.org

Advanced Coloring

From PyMOL Wiki
Revision as of 14:50, 3 October 2011 by Speleo3 (talk | contribs) (fix b-factor example)
Jump to navigation Jump to search

Coloring Molecules

Basic Coloring

Any molecule in PyMOL can be assigned a color using the small rightmost buttons in the object list (in the upper right part of the main GUI window. The Color command will do the same.

PyMOL has a predefined set of colors that can be edited in the Settings->Colors menu. Alternatively, you can use the Set_Color command.


Coloring secondary structures

To assign helices, sheets and loops individual colors, do:

color red, ss h
color yellow, ss s
color green, ss l+''

When the colour bleeds from the ends of helices and sheets into loops, do:

set cartoon_discrete_colors, 1

Or activate Cartoon -> Discrete Colors in the GUI menu.

Coloring by atom type

The util.cba* ("Color By Atom") commands color atoms according to type: oxygen in red, nitrogen in blue, hydrogen in white. Carbon will get a different colors, depending on the command:

command carbon color
util.cbag green
util.cbac cyan
util.cba? magenta
util.cbay yellow
util.cbas salmon
util.cbaw white/grey
util.cbab slate
util.cba? orange
util.cbao light orange
util.cbap purple
util.cbak pink

For instance:

  util.cbay three

will color the object three by atom type, with the carbon atoms in yellow.

CMYK-safe Colors

There are two distinct color spaces on computers: RGB (red-green-blue), which is for screens, and CMYK (cyan-magenta-yellow-black), which is for printing. Some RGB triplets do not have equivalents in CMYK space. As a result, a figure that looks great on a screen can come out with unpredictable colors when printed.

Most applications do a good job with RGB-to-CMYK conversions for photos, but do not do such a good job with graphics that use pure primary colors. For example, reds are generally OK, but pure blues and greens do not translate very well.

Here are some RGB values that are within the CMYK gamut (i.e. are "CMYK-safe"):

#optimized rgb values for cmyk output:
set_color dblue= [0.05 , 0.19 , 0.57]
set_color blue=  [0.02 , 0.50 , 0.72]
set_color mblue= [0.5  , 0.7  , 0.9 ]
set_color lblue= [0.86 , 1.00 , 1.00]

set_color green= [0.00 , 0.53 , 0.22]
set_color lgreen=[0.50 , 0.78 , 0.50]
set_color yellow=[0.95 , 0.78 , 0.00]
set_color orange=[1.00 , 0.40 , 0.0 ]

# these are trivial
set_color red=   [1.00 , 0.00 , 0.00]
set_color mred=  [1.00 , 0.40 , 0.40]
set_color lred=  [1.00 , 0.80 , 0.80]
set_color vlred= [1.00 , 0.90 , 0.90]
set_color white= [1.00 , 1.00 , 1.00]
set_color vlgray=[0.95 , 0.95 , 0.95]
set_color lgray= [0.90 , 0.90 , 0.90]
set_color gray=  [0.70 , 0.70 , 0.70]
set_color dgray= [0.50 , 0.50 , 0.50]
set_color vdgray=[0.30 , 0.30 , 0.30]
set_color black= [0.00 , 0.00 , 0.00]
##

Note that there are default atom colors such as "carbon", "nitrogen", "oxygen", "hydrogen", "sulfur", etc. which should also be redefined:

set_color carbon= [0.00 , 0.53 , 0.22]
etc.

Coloring with 'chainbows' from a script

The chainbow function can be invoked by:

util.chainbow("object-name")


Assign color by B-factor

B-factor coloring can be done with the spectrum command. Example:

spectrum b, blue_white_red, minimum=20, maximum=50
as cartoon
cartoon putty

See Also

Color, Spectrum

Creating a Color bar

To show a vertical/horizontal color bar indiacting the b-factor variation, use the script pseudobar.pml on the structure pseudobar.pdb, or do the following:

  1. Create a pdb-file which contains CA positions only, whereas the numbers correspond to your wanted increments of colors. Be sure that CA's are separated by a contant value, say 5 Angstroem.
  2. Load this new pseudobar-pdb file into PyMOL, make bonds between increment 1 and increment 2 [increment 2 and increment 3 and so on...], define/assign a smooth color for each increment (copy colors definition from automatically created colors made by b-factor script) and show the b-factor bar as lines (or sticks).

Also, see the newly created spectrumbar script!

Coloring insides and outsides of helices differently

The inside of helices can be adressed with:

set cartoon_highlight_color, red


Coloring all objects differently

Is there a simple way to colour each object currently loaded, with a different colour? There is a script color_obj.py that does the job.

USAGE

       color_obj(rainbow=0)

This function colours each object currently in the PyMOL heirarchy with a different colour. Colours used are either the 22 named colours used by PyMOL (in which case the 23rd object, if it exists, gets the same colour as the first), or are the colours of the rainbow

List the color of atoms

To retrieve the color for all residues in a selection, you can iterate over it from the PyMOL command line

iterate all, print color

In Python, it looks like this:

import pymol
pymol.color_list = []
cmd.iterate('all', 'pymol.color_list.append(color)')
print pymol.color_list