Difference between revisions of "Color"

From PyMOLWiki
Jump to: navigation, search
(Expanded some examples included the new B Factor coloring mini-script.)
Line 18: Line 18:
 
List of [[Color Values]]
 
List of [[Color Values]]
  
===EXAMPLES===
+
==EXAMPLES==
 +
===Color all carbons yellow===
 
<source lang="python">color yellow, (name C*)</source>
 
<source lang="python">color yellow, (name C*)</source>
  
RGB Example:
+
===RGB Example===
 
<source lang="python">
 
<source lang="python">
 
set_color khaki, [195,176,145]
 
set_color khaki, [195,176,145]
 
color khaki
 
color khaki
 
</source>
 
</source>
 +
 +
===B-Factors===
 +
The command to color your molecule by B-Factors (B Factors) is:
 +
<source lang="python">
 +
cmd.spectrum("b", selection="SEL");
 +
</source>
 +
where '''SEL''' is your selection, for example, "protA and n. CA", for protein A's alpha carbons.
 +
 +
====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.
 +
<source lang="python">
 +
# 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")
 +
</source>
 +
 +
  
 
[[Category:Objects_and_Selections]]
 
[[Category:Objects_and_Selections]]
 
[[Category:Commands|color]]
 
[[Category:Commands|color]]

Revision as of 10:53, 15 February 2007

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

B-Factors

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

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

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

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")