Color: Difference between revisions

From PyMOLWiki
Jump to navigation Jump to search
(Expanded some examples included the new B Factor coloring mini-script.)
Line 63: Line 63:
</source>
</source>


If you want to save the file with the new B Factor values for each alpha carbon,
<source lang="python">
cmd.save("protA_newBFactors.pdb", "protA")
</source>
or similar is all you need.




[[Category:Objects_and_Selections]]
[[Category:Objects_and_Selections]]
[[Category:Commands|color]]
[[Category:Commands|color]]

Revision as of 10:55, 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")

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.