[Chimera-users] how to color ribbons?

Thomas Goddard goddard at cgl.ucsf.edu
Wed Aug 20 10:51:41 PDT 2003

Hi Mario,

  I wrote some Python code you can add to your copy of Chimera to color
helices and strands in ribbon display mode.  Make a directory called
ColorSecondary and put files ChimeraExtension.py and __init__.py in it
as given below.  Then either move this directory into the chimera "share"
directory (chimera/share on Windows and Linux, and
Chimera.app/Contents/Resources/share on Mac) or use Chimera menu entry
Favorites/Preferences, Catogory tools and add the directory containing
ColorSecondary to the list of directories where Chimera looks for extensions.
If you do the latter, press the Save button on the Preferences dialog so
it remembers this new search directory the next time you run Chimera.

  Now Chimera will show an menu entry Extensions/Utilities/Color secondary
structure.  If nothing is selected it sets ribbon colors for all open
molecules, or if some residues are selected just those are colored.  This
is the standard behaviour of entries in the Actions menu.  It is a bit
tedious to use this cascaded menu entry so I added an accelerator "c2"
that does the coloring.  Accelerators are not enabled by default.  You
use Tools/Keyboard/Accelerators on to enable them.  To have them always
enabled on start-up you use Favorites/Preferences, category Tools to
indicate they should always be turned on at start-up.  A couple other
accelerators for showing a ribbon: rr = show round ribbon, ha = hide atoms.
Accelerators are described in more detail in the Chimera manual.

ColorSecondary/ChimeraExtension.py follows:

import chimera.extension

# -----------------------------------------------------------------------------
class Color_Secondary_EMO(chimera.extension.EMO):

   def name(self):
       return 'Color secondary structure'
   def description(self):
       return 'Color helices and sheets in ribbon representation'
   def categories(self):
       return ['Utilities']
   def icon(self):
   def activate(self):
       return None

# -----------------------------------------------------------------------------
def color_accel():
    'Color ribbons with helices red, sheets cyan, and the rest white'
    import ColorSecondary

import Accelerators
Accelerators.add_accelerator('c2', 'Color secondary structure', color_accel)

# -----------------------------------------------------------------------------

ColorSecondary/__init__.py follows

# -----------------------------------------------------------------------------
def color_secondary_structure():

    import chimera
    helix_color = chimera.Color_lookup('red')
    sheet_color = chimera.Color_lookup('cyan')
    turn_color = chimera.Color_lookup('white')
    default_color = chimera.Color_lookup('white')

    rlist = chosen_residues()
    for r in rlist:
        if r.isHelix:
            color = helix_color
        elif r.isSheet:
            color = sheet_color
        elif r.isTurn:
            color = turn_color
            color = default_color
        r.ribbonColor = color

# -----------------------------------------------------------------------------
# Use the same selection criteria that the Action menu uses.
def chosen_residues():

    from chimera import actions, selection
    residues = actions.instances(adjustToLevel = selection.SelSubgraph)[0]
    return residues

More information about the Chimera-users mailing list