Advanced Coloring

From PyMOLWiki
Revision as of 01:31, 17 May 2010 by Sbliven (Talk | contribs) (Changed a broken external link for to point to the proper page on this wiki)

Jump to: navigation, 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* ("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 magenta
util.cbay yellow
util.cbas salmon
util.cbaw white/grey
util.cbab slate 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]

Coloring with 'chainbows' from a script

The chainbow function can be invoked by:


Assign color by B-factor

Robert Campbell has a python script on his PyMOL web page that you can use. it has a number of options including the selection, minimum and maximum values to consider and several types of colouring schemes (a selection of gradients plus the ability to set the saturation and brightness levels) and two types of binning of the colours (equal number of atoms in each colour or equal spacing of colours along the B-factor range).

See to download.

PyMol B-factor Coloring

This concept is also discussed in Coloring by BFactors and Spectrum and has a great list of the colors in the spectrum. This just shows a quick standard PyMol way to color your protein by b-factor. It also sets the range of color for coloring:

spectrum b, minimum=20, maximum=50

Or to color on a per-object basis:

load myprotein.pdb
spectrum b, selection=myprotein, minimum=20, maximum=50

See Also

Color, Coloring with 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 that does the job.



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 = []
print pymol.color_list