<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.pymol.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rlc</id>
	<title>PyMOL Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.pymol.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rlc"/>
	<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php/Special:Contributions/Rlc"/>
	<updated>2026-04-30T11:44:24Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.1</generator>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Scripting_FAQs&amp;diff=8757</id>
		<title>Scripting FAQs</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Scripting_FAQs&amp;diff=8757"/>
		<updated>2014-01-15T16:42:45Z</updated>

		<summary type="html">&lt;p&gt;Rlc: Fixed error in example for passing command line options to a script.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Script within a Structure==&lt;br /&gt;
Q: Is there a way to embed a script within a PDB structure?&lt;br /&gt;
&lt;br /&gt;
A: Yes, there are two ways&lt;br /&gt;
* Use the [[Read_Pdbstr]] command like,&lt;br /&gt;
 delete all&lt;br /&gt;
 cmd.read_pdbstr(&amp;quot;&amp;quot;&amp;quot;HETATM 1985  O00 MOH   132      18.797   6.477 -12.112 0.00  0.00           O\&lt;br /&gt;
 HETATM 1988  H03 MOH   132      18.437   7.229 -11.665  0.00  0.00    H\&lt;br /&gt;
 HETATM 1989  C04 MOH   132      17.737   5.662 -12.563  0.00  0.00    C\&lt;br /&gt;
 HETATM 1990  H05 MOH   132      18.129   4.785 -13.080  0.00  0.00    H\&lt;br /&gt;
 HETATM 1991  H06 MOH   132      17.096   6.211 -13.253  0.00  0.00    H\&lt;br /&gt;
 HETATM 1992  H07 MOH   132      17.130   5.322 -11.722  0.00  0.00    H&amp;quot;&amp;quot;&amp;quot;,&amp;quot;mymolecule&amp;quot;)&lt;br /&gt;
 show sticks&lt;br /&gt;
&lt;br /&gt;
Don't forget the backslashes there -- it's one long command.&lt;br /&gt;
[http://chips.csb.ki.se/pymol/msg02104.html Example]&lt;br /&gt;
&lt;br /&gt;
* Or, as Warren noted, you can do with with a &amp;quot;p1m&amp;quot; file, which is like a &amp;quot;pml&amp;quot; file, but data can be included as well.  Also note that p1m files are intended for web publishing, so embedded Python is disallowed.  In p1m files, there is an &amp;quot;embed&amp;quot; command that enables this for PDB, MOL, MOL2, SDF, and XPLOR data.  It works like this:&lt;br /&gt;
 embed tag, format&lt;br /&gt;
 ****REPLACE THIS LINE WITH YOUR DATA FILE****&lt;br /&gt;
 embed end&lt;br /&gt;
&lt;br /&gt;
 load_embedded tag&lt;br /&gt;
where tag is some identifier of your choice.&lt;br /&gt;
&lt;br /&gt;
==Scripting and Command Line Options==&lt;br /&gt;
PyMol will allow you to use command line options in a script.  That means, the following&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
pymol -qrc script.py arg1 arg2&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will work if you add a double-hyphen before the first argument in order&lt;br /&gt;
to signal Pymol to stop interpreting arguments:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
pymol -qrc script.py -- arg1 arg2&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then your script can get these arguments as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from sys import argv&lt;br /&gt;
my_argv = argv[1:]&lt;br /&gt;
print my_argv[0], my_argv[1]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripting]]&lt;/div&gt;</summary>
		<author><name>Rlc</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Split_chains&amp;diff=8943</id>
		<title>Split chains</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Split_chains&amp;diff=8943"/>
		<updated>2013-04-04T13:28:52Z</updated>

		<summary type="html">&lt;p&gt;Rlc: Added fix to check for blank chain ID.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Infobox psico&lt;br /&gt;
|module    =  psico.editing&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
'''split_chains''' is a script that creates for each chain in selection its own object.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
&lt;br /&gt;
 split_chains [ selection [, prefix ]]&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
fetch 2yko 2ykp 2ykq, async=0&lt;br /&gt;
split_chains&lt;br /&gt;
delete 2yko 2ykp 2ykq&lt;br /&gt;
alignto 2yko_A&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== The Script ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from pymol import cmd, CmdException&lt;br /&gt;
&lt;br /&gt;
def split_chains(selection='(all)', prefix=None):&lt;br /&gt;
    '''&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
&lt;br /&gt;
    Create a single object for each chain in selection&lt;br /&gt;
&lt;br /&gt;
SEE ALSO&lt;br /&gt;
&lt;br /&gt;
    split_states, http://pymolwiki.org/index.php/Split_object&lt;br /&gt;
    '''&lt;br /&gt;
    count = 0&lt;br /&gt;
    models = cmd.get_object_list('(' + selection + ')')&lt;br /&gt;
    for model in models:&lt;br /&gt;
        for chain in cmd.get_chains('(%s) and model %s' % (selection, model)):&lt;br /&gt;
            if chain == '':&lt;br /&gt;
                chain = &amp;quot;''&amp;quot;&lt;br /&gt;
            count += 1&lt;br /&gt;
            if not prefix:&lt;br /&gt;
                name = '%s_%s' % (model, chain)&lt;br /&gt;
            else:&lt;br /&gt;
                name = '%s%04d' % (prefix, count)&lt;br /&gt;
            cmd.create(name, '(%s) and model %s and chain %s' % (selection, model, chain))&lt;br /&gt;
        cmd.disable(model)&lt;br /&gt;
&lt;br /&gt;
cmd.extend('split_chains', split_chains)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[Split_States|split_states]]&lt;br /&gt;
* [[split_object]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Script_Library]]&lt;/div&gt;</summary>
		<author><name>Rlc</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Peptide_Sequence&amp;diff=7175</id>
		<title>Peptide Sequence</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Peptide_Sequence&amp;diff=7175"/>
		<updated>2009-01-21T15:16:56Z</updated>

		<summary type="html">&lt;p&gt;Rlc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Building a Peptide Sequence From Hand=&lt;br /&gt;
There are more than one method in PyMol for building a peptide sequence from hand.  First, you may simply hold down the '''alt''' ('''option''' on Mac) key and type in the one-letter code for the sequence.  Secondly, you can write a script like the following&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
for aa in &amp;quot;DCAHWLGELVWCT&amp;quot;: cmd._alt(string.lower(aa))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
which will build the amino acid sequence &amp;quot;DCAHWLGELVWCT&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==Other Sources==&lt;br /&gt;
Robert Campbell has notified us of [http://pldserver1.biochem.queensu.ca/~rlc/work/pymol his two scripts] to solve the problem.  You can apparently specify phi/psi angles, too.  Look for '''build_seq.py''' and '''build_seq_phi_psi.py'''.&lt;br /&gt;
&lt;br /&gt;
Also check out [[CreateSecondaryStructure]] , which you can build repeating units of different types of secondary structure (a-helix,b-sheets, loops,etc)  (Dan Kulp)&lt;br /&gt;
&lt;br /&gt;
In addition, [[Rotamer Toggle]] can set the sidechains to different rotamers or specific side-chain angle sets. (Dan Kulp)&lt;/div&gt;</summary>
		<author><name>Rlc</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Color_Objects&amp;diff=7561</id>
		<title>Color Objects</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Color_Objects&amp;diff=7561"/>
		<updated>2008-06-23T20:39:27Z</updated>

		<summary type="html">&lt;p&gt;Rlc: corrected web page reference for RLC's web site&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#####################################################################&lt;br /&gt;
#&lt;br /&gt;
# Colour by object&lt;br /&gt;
#&lt;br /&gt;
#####################################################################&lt;br /&gt;
&lt;br /&gt;
def color_obj(rainbow=0):&lt;br /&gt;
&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        &lt;br /&gt;
AUTHOR &lt;br /&gt;
&lt;br /&gt;
        Gareth Stockwell&lt;br /&gt;
&lt;br /&gt;
USAGE&lt;br /&gt;
&lt;br /&gt;
        color_obj(rainbow=0)&lt;br /&gt;
&lt;br /&gt;
	This function colours each object currently in the PyMOL heirarchy&lt;br /&gt;
	with a different colour.  Colours used are either the 22 named&lt;br /&gt;
	colours used by PyMOL (in which case the 23rd object, if it exists,&lt;br /&gt;
	gets the same colour as the first), or are the colours of the rainbow&lt;br /&gt;
&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	# Process arguments&lt;br /&gt;
	rainbow = int(rainbow)&lt;br /&gt;
&lt;br /&gt;
        # Get names of all PyMOL objects&lt;br /&gt;
	obj_list = cmd.get_names('models')&lt;br /&gt;
&lt;br /&gt;
	if rainbow:&lt;br /&gt;
&lt;br /&gt;
           print &amp;quot;\nColouring objects as rainbow\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	   nobj = len(obj_list)&lt;br /&gt;
&lt;br /&gt;
	   # Create colours starting at blue(240) to red(0), using intervals&lt;br /&gt;
	   # of 240/(nobj-1)&lt;br /&gt;
	   for j in range(nobj):&lt;br /&gt;
	      hsv = (240-j*240/(nobj-1), 1, 1)&lt;br /&gt;
	      # Convert to RGB&lt;br /&gt;
	      rgb = hsv_to_rgb(hsv)&lt;br /&gt;
	      # Define the new colour&lt;br /&gt;
	      cmd.set_color(&amp;quot;col&amp;quot; + str(j), rgb)&lt;br /&gt;
	      print obj_list[j], rgb&lt;br /&gt;
	      # Colour the object&lt;br /&gt;
	      cmd.color(&amp;quot;col&amp;quot; + str(j), obj_list[j])&lt;br /&gt;
&lt;br /&gt;
	else:&lt;br /&gt;
&lt;br /&gt;
	   print &amp;quot;\nColouring objects using PyMOL defined colours\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	   # List of available colours&lt;br /&gt;
	   colours = ['red', 'green', 'blue', 'yellow', 'violet', 'cyan',    \&lt;br /&gt;
           'salmon', 'lime', 'pink', 'slate', 'magenta', 'orange', 'marine', \&lt;br /&gt;
	   'olive', 'purple', 'teal', 'forest', 'firebrick', 'chocolate',    \&lt;br /&gt;
	   'wheat', 'white', 'grey' ]&lt;br /&gt;
	   ncolours = len(colours)&lt;br /&gt;
&lt;br /&gt;
	   # Loop over objects&lt;br /&gt;
	   i = 0&lt;br /&gt;
	   for obj in obj_list:&lt;br /&gt;
	      print &amp;quot;  &amp;quot;, obj, colours[i]&lt;br /&gt;
	      cmd.color(colours[i], obj)&lt;br /&gt;
	      i = i+1&lt;br /&gt;
	      if(i == ncolours):&lt;br /&gt;
	         i = 0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# HSV to RGB routine taken from Robert L. Campbell's color_b.py script&lt;br /&gt;
#   See http://pldserver1.biochem.queensu.ca/~rlc/work/pymol/&lt;br /&gt;
# Original algorithm from: http://www.cs.rit.edu/~ncs/color/t_convert.html&lt;br /&gt;
def hsv_to_rgb(hsv):&lt;br /&gt;
&lt;br /&gt;
        h = float(hsv[0])&lt;br /&gt;
        s = float(hsv[1])&lt;br /&gt;
        v = float(hsv[2])&lt;br /&gt;
&lt;br /&gt;
        if( s == 0 ) :&lt;br /&gt;
                #achromatic (grey)&lt;br /&gt;
                r = g = b = v&lt;br /&gt;
&lt;br /&gt;
        else:&lt;br /&gt;
                # sector 0 to 5&lt;br /&gt;
                h = h/60.            &lt;br /&gt;
                i = int(h)&lt;br /&gt;
                f = h - i                       # factorial part of h&lt;br /&gt;
                #print h,i,f&lt;br /&gt;
                p = v * ( 1 - s )&lt;br /&gt;
                q = v * ( 1 - s * f )&lt;br /&gt;
                t = v * ( 1 - s * ( 1 - f ) )&lt;br /&gt;
&lt;br /&gt;
                if i == 0:&lt;br /&gt;
                        (r,g,b) = (v,t,p)&lt;br /&gt;
                elif i == 1:&lt;br /&gt;
                        (r,g,b) = (q,v,p)&lt;br /&gt;
                elif i == 2:&lt;br /&gt;
                        (r,g,b) = (p,v,t)&lt;br /&gt;
                elif i == 3:&lt;br /&gt;
                        (r,g,b) = (p,q,v)&lt;br /&gt;
                elif i == 4:&lt;br /&gt;
                        (r,g,b) = (t,p,v)&lt;br /&gt;
                elif i == 5:&lt;br /&gt;
                        (r,g,b) = (v,p,q)&lt;br /&gt;
                else:&lt;br /&gt;
                        (r,g,b) = (v,v,v)&lt;br /&gt;
                        print &amp;quot;error, i not equal 1-5&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        return [r,g,b]&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
# Add color_obj to the PyMOL command list &lt;br /&gt;
cmd.extend(&amp;quot;color_obj&amp;quot;,color_obj)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Script_Library|Color Objects]]&lt;/div&gt;</summary>
		<author><name>Rlc</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Color&amp;diff=5181</id>
		<title>Color</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Color&amp;diff=5181"/>
		<updated>2008-06-23T20:38:22Z</updated>

		<summary type="html">&lt;p&gt;Rlc: /* Reassigning B-Factors and Coloring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===DESCRIPTION===&lt;br /&gt;
'''color''' changes the color of an object or an atom selection.&lt;br /&gt;
&lt;br /&gt;
===USAGE===&lt;br /&gt;
 color color-name&lt;br /&gt;
 color color-name, object-name&lt;br /&gt;
 color color-name, (selection)&lt;br /&gt;
&lt;br /&gt;
===PYMOL API===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;cmd.color( string color, string selection )&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Using RGB for Color==&lt;br /&gt;
If you prefer RGB to color any object&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
set_color newcolor, [r,g,b]&lt;br /&gt;
color newcolor&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
List of [[Color Values]]&lt;br /&gt;
&lt;br /&gt;
==EXAMPLES==&lt;br /&gt;
===Color all carbons yellow===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;color yellow, (name C*)&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===RGB Example===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
set_color khaki, [195,176,145]&lt;br /&gt;
color khaki&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Color by Spectrum Example===&lt;br /&gt;
Color by spectrum is in the GUI menu but did you realize that the spectrum is not limited to a simple rainbow?&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
spectrum count, x, object_name&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
x can can be anyone of the following:&lt;br /&gt;
blue_green, green_white_magenta, red_cyan, blue_magenta, green_white_red, red_green, blue_red, green_white_yellow, red_white_blue, blue_white_green, green_yellow, red_white_cyan, blue_white_magenta, green_yellow_red, red_white_green, blue_white_red, magenta_blue, red_white_yellow, blue_white_yellow, magenta_cyan, red_yellow, blue_yellow, magenta_green, red_yellow_green, cbmr, magenta_white_blue, rmbc, cyan_magenta, magenta_white_cyan, yellow_blue, cyan_red, magenta_white_green, yellow_cyan, cyan_white_magenta, magenta_white_yellow, yellow_cyan_white, cyan_white_red,  magenta_yellow, yellow_green, cyan_white_yellow, rainbow, yellow_magenta, cyan_yellow, rainbow2, yellow_red, gcbmry, rainbow2_rev, yellow_white_blue, green_blue, rainbow_cycle, yellow_white_green, green_magenta, rainbow_cycle_rev, yellow_white_magenta, green_red, rainbow_rev, yellow_white_red, green_white_blue, red_blue, yrmbcg &lt;br /&gt;
&lt;br /&gt;
===B-Factors===&lt;br /&gt;
The command to color a molecule by B-Factors (B Factors) is:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
cmd.spectrum(&amp;quot;b&amp;quot;, selection=&amp;quot;SEL&amp;quot;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
where '''SEL''' is a valid selection, for example, &amp;quot;protA and n. CA&amp;quot;, for protein A's alpha carbons.&lt;br /&gt;
&lt;br /&gt;
You can choose the spectrum you want with the command:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
cmd.spectrum(&amp;quot;b&amp;quot;, 'rainbow', selection=&amp;quot;SEL&amp;quot;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where '''rainbow''' is a valid selection from the list:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  blue_green            green_white_magenta   red_cyan            &lt;br /&gt;
  blue_magenta          green_white_red       red_green           &lt;br /&gt;
  blue_red              green_white_yellow    red_white_blue      &lt;br /&gt;
  blue_white_green      green_yellow          red_white_cyan      &lt;br /&gt;
  blue_white_magenta    green_yellow_red      red_white_green     &lt;br /&gt;
  blue_white_red        magenta_blue          red_white_yellow    &lt;br /&gt;
  blue_white_yellow     magenta_cyan          red_yellow          &lt;br /&gt;
  blue_yellow           magenta_green         red_yellow_green    &lt;br /&gt;
  cbmr                  magenta_white_blue    rmbc                &lt;br /&gt;
  cyan_magenta          magenta_white_cyan    yellow_blue         &lt;br /&gt;
  cyan_red              magenta_white_green   yellow_cyan         &lt;br /&gt;
  cyan_white_magenta    magenta_white_yellow  yellow_cyan_white   &lt;br /&gt;
  cyan_white_red        magenta_yellow        yellow_green        &lt;br /&gt;
  cyan_white_yellow     rainbow               yellow_magenta      &lt;br /&gt;
  cyan_yellow           rainbow2              yellow_red          &lt;br /&gt;
  gcbmry                rainbow2_rev          yellow_white_blue   &lt;br /&gt;
  green_blue            rainbow_cycle         yellow_white_green  &lt;br /&gt;
  green_magenta         rainbow_cycle_rev     yellow_white_magenta&lt;br /&gt;
  green_red             rainbow_rev           yellow_white_red    &lt;br /&gt;
  green_white_blue      red_blue              yrmbcg &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Reassigning B-Factors and Coloring====&lt;br /&gt;
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 &amp;quot;0&amp;quot;, 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.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# load the protein&lt;br /&gt;
cmd.load(&amp;quot;protA.pdb&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# open the file of new values (just 1 column of numbers, one for each alpha carbon)&lt;br /&gt;
inFile = open(&amp;quot;newBFactors&amp;quot;, 'r')&lt;br /&gt;
&lt;br /&gt;
# create the global, stored array&lt;br /&gt;
stored.newB = []&lt;br /&gt;
&lt;br /&gt;
# read the new B factors from file&lt;br /&gt;
for line in inFile.readlines(): stored.newB.append( float(line) )&lt;br /&gt;
&lt;br /&gt;
# close the input file&lt;br /&gt;
inFile.close()&lt;br /&gt;
&lt;br /&gt;
# clear out the old B Factors&lt;br /&gt;
alter protA, b=0.0&lt;br /&gt;
&lt;br /&gt;
# update the B Factors with new properties&lt;br /&gt;
alter protA and n. CA, b=stored.newB.pop(0)&lt;br /&gt;
&lt;br /&gt;
# color the protein based on the new B Factors of the alpha carbons&lt;br /&gt;
cmd.spectrum(&amp;quot;b&amp;quot;, &amp;quot;protA and n. CA&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to save the file with the new B Factor values for each alpha carbon,&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
cmd.save(&amp;quot;protA_newBFactors.pdb&amp;quot;, &amp;quot;protA&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or similar is all you need.&lt;br /&gt;
&lt;br /&gt;
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/)&lt;br /&gt;
&lt;br /&gt;
===== Expanding to Surface =====&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# Assumes alpha carbons colored from above.&lt;br /&gt;
create ca_obj, your-object-name and name ca &lt;br /&gt;
ramp_new ramp_obj, ca_obj, [0, 10], [-1, -1, 0]&lt;br /&gt;
set surface_color, ramp_obj, your-object-name&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thanks to Warren, for this one.&lt;br /&gt;
&lt;br /&gt;
[[Category:Objects_and_Selections]]&lt;br /&gt;
[[Category:Commands|color]]&lt;/div&gt;</summary>
		<author><name>Rlc</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Advanced_Coloring&amp;diff=691</id>
		<title>Advanced Coloring</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Advanced_Coloring&amp;diff=691"/>
		<updated>2008-06-23T20:33:47Z</updated>

		<summary type="html">&lt;p&gt;Rlc: modified rlc's web site location and changed some outdated text describing color_b.py&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Coloring Molecules=&lt;br /&gt;
&lt;br /&gt;
==Basic Coloring==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
PyMOL has a predefined set of colors that can be edited in the ''Settings-&amp;gt;Colors'' menu. &lt;br /&gt;
Alternatively, you can use the [[Set_Color]] command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Coloring secondary structures==&lt;br /&gt;
To assign helices, sheets and loops individual colors, do:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
color red, ss h&lt;br /&gt;
color yellow, ss s&lt;br /&gt;
color green, ss l+''&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the colour bleeds from the ends of helices and sheets into loops, do:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
set cartoon_discrete_colors, 1&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Or activate ''Cartoon -&amp;gt; Discrete Colors'' in the GUI menu.&lt;br /&gt;
&lt;br /&gt;
==Coloring by atom type==&lt;br /&gt;
The util.cba* (&amp;quot;Color By Atom&amp;quot;) 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: cbag (gray), cbac (cyan), cbas (salmon), cbap (purple), cbak (pink), cbaw (white), cbab (slate).&lt;br /&gt;
For instance:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
  util.cbay three&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will color the object ''three'' by atom type, with the carbon atoms in yellow.&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==CMYK-safe Colors==&lt;br /&gt;
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.&lt;br /&gt;
Some RGB triplets do have equivalents in CMYK space. As a result, a figure that looks great on a screen can come out with unpredictable colors when printed.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Here are some RGB values that are within the CMYK gamut (i.e. are &amp;quot;CMYK-safe&amp;quot;):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#optimized rgb values for cmyk output:&lt;br /&gt;
set_color dblue= [0.05 , 0.19 , 0.57]&lt;br /&gt;
set_color blue=  [0.02 , 0.50 , 0.72]&lt;br /&gt;
set_color mblue= [0.5  , 0.7  , 0.9 ]&lt;br /&gt;
set_color lblue= [0.86 , 1.00 , 1.00]&lt;br /&gt;
&lt;br /&gt;
set_color green= [0.00 , 0.53 , 0.22]&lt;br /&gt;
set_color lgreen=[0.50 , 0.78 , 0.50]&lt;br /&gt;
set_color yellow=[0.95 , 0.78 , 0.00]&lt;br /&gt;
set_color orange=[1.00 , 0.40 , 0.0 ]&lt;br /&gt;
&lt;br /&gt;
# these are trivial&lt;br /&gt;
set_color red=   [1.00 , 0.00 , 0.00]&lt;br /&gt;
set_color mred=  [1.00 , 0.40 , 0.40]&lt;br /&gt;
set_color lred=  [1.00 , 0.80 , 0.80]&lt;br /&gt;
set_color vlred= [1.00 , 0.90 , 0.90]&lt;br /&gt;
set_color white= [1.00 , 1.00 , 1.00]&lt;br /&gt;
set_color vlgray=[0.95 , 0.95 , 0.95]&lt;br /&gt;
set_color lgray= [0.90 , 0.90 , 0.90]&lt;br /&gt;
set_color gray=  [0.70 , 0.70 , 0.70]&lt;br /&gt;
set_color dgray= [0.50 , 0.50 , 0.50]&lt;br /&gt;
set_color vdgray=[0.30 , 0.30 , 0.30]&lt;br /&gt;
set_color black= [0.00 , 0.00 , 0.00]&lt;br /&gt;
##&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that there are default atom colors such as &amp;quot;carbon&amp;quot;, &amp;quot;nitrogen&amp;quot;, &amp;quot;oxygen&amp;quot;, &amp;quot;hydrogen&amp;quot;, &amp;quot;sulfur&amp;quot;, etc. which should also be redefined:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
set_color carbon= [0.00 , 0.53 , 0.22]&lt;br /&gt;
etc.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Coloring with 'chainbows' from a script==&lt;br /&gt;
The chainbow function can be invoked by:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
util.chainbow(&amp;quot;object-name&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Assign color by B-factor==&lt;br /&gt;
Robert Campbell has a color_b.py python script on his PyMOL web page that you can use.&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
See http://pldserver1.biochem.queensu.ca/~rlc/work/pymol to download.&lt;br /&gt;
&lt;br /&gt;
====PyMol B-factor Coloring====&lt;br /&gt;
This concept is also discussed in [[Color#Color_by_Spectrum_Example|Coloring by BFactors and Spectrum]] and has a '''great list of the colors in the spectrum'''.&lt;br /&gt;
This just shows a quick standard PyMol way to color your protein by b-factor.  It also sets the range of color for coloring:&lt;br /&gt;
 spectrum b, minimum=20, maximum=50&lt;br /&gt;
&lt;br /&gt;
Or to color on a per-object basis:&lt;br /&gt;
 load myprotein.pdb&lt;br /&gt;
 spectrum b, selection=myprotein, minimum=20, maximum=50&lt;br /&gt;
&lt;br /&gt;
= See Also =&lt;br /&gt;
[[Color]], [[Color#Color_by_Spectrum_Example|Coloring with Spectrum]]&lt;br /&gt;
&lt;br /&gt;
==Creating a Color bar==&lt;br /&gt;
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:&lt;br /&gt;
# 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.&lt;br /&gt;
# 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).&lt;br /&gt;
&lt;br /&gt;
==Coloring insides and outsides of helices differently==&lt;br /&gt;
The inside of helices can be adressed with:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
set cartoon_highlight_color, red&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Coloring all objects differently==&lt;br /&gt;
Is there a simple way to colour each object currently loaded, with a different colour?&lt;br /&gt;
There is a script color_obj.py that does the job.&lt;br /&gt;
The script is also available at&lt;br /&gt;
http://www.ebi.ac.uk/~gareth/misc&lt;br /&gt;
&lt;br /&gt;
USAGE&lt;br /&gt;
&lt;br /&gt;
        color_obj(rainbow=0)&lt;br /&gt;
&lt;br /&gt;
	This function colours each object currently in the PyMOL heirarchy&lt;br /&gt;
	with a different colour.  Colours used are either the 22 named&lt;br /&gt;
	colours used by PyMOL (in which case the 23rd object, if it exists,&lt;br /&gt;
	gets the same colour as the first), or are the colours of the rainbow&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==List the color of atoms==&lt;br /&gt;
To retrieve the color for all residues in a selection, you can iterate over it from the PyMOL command line&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
iterate all, print color&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, it looks like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import pymol&lt;br /&gt;
pymol.color_list = []&lt;br /&gt;
cmd.iterate('all', 'pymol.color_list.append(color)')&lt;br /&gt;
print pymol.color_list&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Publication_Quality|Advanced Coloring]]&lt;br /&gt;
[[Category:Coloring|Advanced Coloring]]&lt;/div&gt;</summary>
		<author><name>Rlc</name></author>
	</entry>
</feed>