This is a read-only mirror of pymolwiki.org
Difference between revisions of "Color"
(Removed Set_color example and description. Changed description.) |
(remove redundancy of spectrum description) |
||
Line 17: | Line 17: | ||
Color by spectrum is in the GUI menu but did you realize that the spectrum is not limited to a simple rainbow? | Color by spectrum is in the GUI menu but did you realize that the spectrum is not limited to a simple rainbow? | ||
<source lang="python"> | <source lang="python"> | ||
− | spectrum count, | + | spectrum count, palette, object_name |
</source> | </source> | ||
− | + | ||
− | + | For available palettes and more details see: [[spectrum]] | |
===B-Factors=== | ===B-Factors=== | ||
The command to color a molecule by B-Factors (B Factors) is: | The command to color a molecule by B-Factors (B Factors) is: | ||
<source lang="python"> | <source lang="python"> | ||
− | + | spectrum b, selection=SEL | |
</source> | </source> | ||
where '''SEL''' is a valid selection, for example, "protA and n. CA", for protein A's alpha carbons. | where '''SEL''' is a valid selection, for example, "protA and n. CA", for protein A's alpha carbons. | ||
− | + | For more details see: [[spectrum]] | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
====Reassigning B-Factors and Coloring==== | ====Reassigning B-Factors and Coloring==== | ||
Line 146: | Line 119: | ||
util.color_objs("all") | util.color_objs("all") | ||
</source> | </source> | ||
+ | |||
+ | == SEE ALSO == | ||
+ | |||
+ | * [[Advanced Coloring]] | ||
+ | * [[spectrum]] | ||
[[Category:Objects_and_Selections|Color]] | [[Category:Objects_and_Selections|Color]] |
Revision as of 16:19, 2 October 2011
color sets the color of an object or an atom selection to a predefined, named color. For an overview of predifined colors, see Color Values. For a script that enumerates all the colors see, List_Colors. If you want to define your own colors, see Set_Color.
USAGE
color color-name
color color-name, object-name
color color-name, (selection)
PYMOL API
cmd.color( string color, string selection )
EXAMPLES
Color all carbons yellow
color yellow, (name C*)
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, palette, object_name
For available palettes and more details see: spectrum
B-Factors
The command to color a molecule by B-Factors (B Factors) is:
spectrum b, selection=SEL
where SEL is a valid selection, for example, "protA and n. CA", for protein A's alpha carbons.
For more details see: spectrum
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.
A script (data2bfactor.py) that loads data into the B-factor (b) or occupancy (q) columns from an external file can be found in Robert Campbell's PyMOL script repository (http://pldserver1.biochem.queensu.ca/~rlc/work/pymol/)
Expanding to Surface
See Expand_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.
Getting Atom Colors
stored.list = []
iterate all, stored.list.append(color)
print stored.list
Or, you can label each atom by it's color code:
label all, color
Color States Individually
fetch 1nmr
set all_states
# the object has 20 states, so we can set separate line colors
# for each state as follows:
for a in range(1,21): cmd.set("line_color","auto","1nmr",a)
Or, we can do it differently,
# start over,
fetch 1nmr
# break apart the object by state
split_states 1nmr
# delete the original
dele 1nmr
# and color by object (carbons only)
util.color_objs("elem c")
# (all atoms)
util.color_objs("all")