ChimeraX docs icon

Command: color, rainbow

Depending on the type of coloring, color may apply to different sets of items:

See also: transparency, coulombic , mlp , measure convexity, surface, volume, Color Actions, Surface Color, Basic Actions, Selection Inspector, the Actions... Color menu, color schemes, color specification, palettes, limitations of transparency

Additional subcommands manage the set of named colors:

Simple Coloring

Usage: color  spec   colorname  [ what | target  string ] [ halfbond  true | false ] [ transparency  percent ]

Simple coloring applies to atomic models, including cartoon and molecular surface representations, volume data (map) displays, and 2D labels. The colorname can be:

The target option allows coloring only a subset of the possible displays of a given atom, residue, etc. The string can be any combination of the following letters, without commas or spaces:

The default is all of the above (target abcspf) except labels, which can be colored independently: 3D labels with the label command, 2D labels with the 2dlabels command. However, if only 2dlabels are specified in the command (such as by model number), labels are inferred as the target.

Alternatively, for certain types of coloring, the targets (what to act upon) can be specified with one or more of the following keywords as a comma-separated list:

These what keywords must be given in the right place in the command:

By default, bonds are shown in halfbond mode, with color and transparency settings from the flanking atoms. Setting halfbond false for a bond (or pseudobond) reveals its own color/transparency settings independent of the atoms. This option can be used to toggle halfbond mode regardless of whether the command colors any bonds. It affects only the specified bonds (not pseudobonds), except obeying the target setting when it includes p.

The transparency option sets transparency to the specified percent, where 0% is completely opaque and 100% is completely transparent. Existing transparency is not changed unless this option is used or the colorname explicitly specifies alpha (opacity); if both, the transparency option wins out. See also: transparency

Examples (Simple)

Color chain D helices sky blue, cartoons only (not atoms, etc.):
color /d & helix  sky blue  target c
– or –
color /d & helix  sky blue  cartoons
Color residues 12 and 260-275 in chains A and B, atoms/bonds only:
color /A,B:12,260-275  hot pink  target a
– or –
color /A,B:12,260-275  hot pink  atoms
Color all pseudobonds yellow:
color pbonds  yellow
Restore original model coloring to all carbon atoms:
color C  bymodel  targ a
Color map #4:
color #4  medium violet

Sequential Coloring (Rainbow)

Usage: color  sequential  atom-spec  [ level ] [ target  string ] [ palette  palette ] [ transparency  percent ]
– or –
Usage: rainbow  atom-spec  [ level ] [ target  string ] [ palette  palette ] [ transparency  percent ]

The color sequential command (synonym rainbow) applies a series of colors to atomic models at the specified level:

Sequential coloring can be restricted to certain representations with the target option. The palette option specifies what colors to use (default
). If the scope of coloring is limited by giving an atom-spec in the command, the full palette will be mapped to the specification only.

The transparency option sets transparency to the specified percent, where 0% is completely opaque and 100% is completely transparent. Existing transparency is not changed unless this option is used or the palette is defined with transparency (any of its colors have alpha < 1); if both, the transparency option wins out. See also: transparency

Examples (Sequential)

Rainbow-color residues blue → red along each biopolymer chain:
color seq res
– or –
rainbow res
– or –
rainbow
Rainbow-color each biopolymer chain from blue at residue 1 to red at residue 50, leaving the colors of other parts unchanged.
rainbow :1-50
Color the unique biopolymers in each atomic model, cartoons only, along the range cornflower blue → red → gold (chains that are the same biopolymer will be the same color):
color seq polymers  targ c  palette cornflowerblue:red:gold
– or –
rainbow polymers  targ c  palette cornflowerblue:red:gold
Color the 10-mer in PDB entry 1qmv using the 10-color version of the “paired” ColorBrewer palette:
open 1qmv; rainbow chain palette paired-10

Color Modification

Usage: color modify  spec   hue  [ + | − ]  angle  [ what | target  string ]
Usage: color modify  spec  ( saturation | lightness | whiteness | blackness | red | green | blue ) [ + | − | * ]  percent  [ what | target  string ]
Usage: color modify  spec  contrastpercent ] [ what | target  string ]

Color modification adjusts existing colors. It applies to atomic models, including cartoon and molecular surface representations. The color component to modify must be specified, with choices:

For saturation, lightness, whiteness, blackness, red, green, or blue, the percent can be added to (+), subtracted from (−), or multiplied by (*) the current value, or simply set as the current value if no operator symbol is given (or the space after the operator symbol is omitted; the space is needed to indicate a change from the current value rather than an absolute value). For hue, the angle can be added to or subtracted from the current value, or simply set as the current value.

Example image and script: Potassium Channel-Calmodulin Complex

Coloring by Attribute Value

Usage: color  byattribute  [a:][r:][m:]attribute-name   atom-spec  [ what | target  string ] [ key  true | false ] [ average  residues ]  palette-options  [ transparency  percent ] [ noValueColor  color-spec ]

Atomic models can be colored to show the values of numerical attributes. Several attributes are present automatically, but others can be defined by the user arbitrarily or created by various ChimeraX tools and commands (details...). For example, the values of a map at atom positions can be assigned as an attribute with measure mapvalues. Examples of coloring by bfactor, an attribute automatically read from mmCIF/PDB, are given below. For coloring by a user-defined attribute, see the custom preset example. For coloring by segmentation region, see segmentation. The graphical interface to color byattribute is Render by Attribute. See also size byattribute, cartoon byattribute (worm), the tutorial Coloring by Sequence Conservation and the video Coloring Aligned Proteins by Cα RMSD.

An a:, r:, or m: immediately preceding the attribute name can be used to indicate the attribute level as atom, residue, or (atomic) model, but this is only needed when the name exists at multiple levels. The color-to-value mapping is specified with palette options (default
over the full range).

Transparency (alpha < 1) can be inherent in the colors of the palette, or the separate transparency option can be used to specify it as a percent, where 0% is completely opaque and 100% is completely transparent. If both, the transparency option wins out. See also: transparency

Items without an assignment for the specified attribute will be left unchanged unless another color is specified with the noValueColor option.

When color byattribute is run interactively (in gui mode and not via a script), the key true option can be used to start Color Key and draw a color key with the corresponding colors and values.

The coloring applies to atomic models, including cartoons and molecular surfaces, but can be restricted to certain representations with the target option. If an atom attribute is used, cartoons are colored by the average value of the atoms in each residue. Atoms (and their corresponding molecular surface patches) are colored by the atomic values unless average residue is given to indicate they should be colored by the average per residue.

The command color bfactor   is shorthand for color byattribute bfactor. For example, to color chain A atoms by B-factor and cartoons by the average B-factor per residue, spreading blue-white-red coloring across value range 2-30:

color by bfactor /A range 2,30
– or –
color bfactor /A range 2,30

Regardless of whether the range of values over which to spread the coloring is specified, the full range of atomic values (or per-residue values if average residue is used) is reported in the Log.

If no range for colormapping is specified, the full range over all specified atoms is used for atom coloring and the full range of per-residue averages (over that same set of atoms) is used for cartoon coloring. Importantly, the value ranges will include solvent, ions, and ligands unless the specification excludes them, or they have been deleted beforehand. For example, to rainbow-color chain A atoms etc. by the average B-factor per residue, spreading the coloring across the full range of values from protein only:

color bfactor (/A & protein) palette rainbow ave residue

To apply attribute coloring to a surface cap (from clipping), it is necessary to first color the atoms by attribute, then use color zone to make the cap match the nearby atoms.

Coloring Surfaces by Map Value

Usage: colorsample | electrostatic | gradient )  surf-spec  [ map  map-model ] [ offset  d | start,end,increment ] [ key  true | false ] [ update  true | false ] [ palette  palette ] [ range  low,high | full ] [ transparency  percent ]

The sample, electrostatic, and gradient coloring options color surfaces by volume data (map) values. To color atoms by map values, instead use measure mapvalues followed by color byattribute. Surface coloring by map value is also implemented in the Surface Color tool. The color-to-value mapping is specified with palette options, where the palette default is red-white-blue
and the range default depends on the specific type of map coloring, explained below.

When the coloring command is run interactively (in gui mode and not via a script), the key true option can be used to start Color Key and draw a color key with the corresponding colors and values. The update option (default true) indicates whether to update the coloring automatically when the shape of the surface changes. For coloring by segmentation region, see segmentation. The coulombic command colors molecular surfaces by Coulombic electrostatic potential without requiring an input map. See also: mlp , surface cap, per-model clipping, the Protein-Ligand Binding Sites tutorial, ChimeraX videos: coloring by electrostatic potential, coloring a map by local resolution

Examples (Map)

Color surface #5 by map #1 using the average of values measured at offsets of 60, 70, 80, 90, and 100 Å from the surface:
color sample #5 map #1 offset 60,100,10
Color molecular surface of #1 by the electrostatic potential in map #2, from red at -10 (and below) to white in the middle to blue at +10 (and above):
color electrostatic #1 map #2 palette redblue  range -10,10
Same as previous except use royal blue instead of blue:
color elec #1 map #2 palette -10,red:0,white:10,royalblue

Coloring by Distance

Usage: color  radial  surf-spec  [ center  point-spec ] [ coordinateSystem  model-spec ] [ key  true | false ] [ update  true | false ]  palette-options  [ transparency  percent ]

Usage: colorcylindrical | height )  surf-spec  [ center  point-spec ] [ axis  vector-spec ] [ coordinateSystem  model-spec ] [ key  true | false ] [ update  true | false ]  palette-options  [ transparency  percent ]

Coloring by distance applies to surfaces only, both molecular and nonmolecular (such as volume isosurfaces). It is also implemented in the Surface Color tool. The color-to-distance mapping is specified with palette options (default
across the full range).

When the coloring command is run interactively (in gui mode and not via a script), the key true option can be used to start Color Key and draw a color key with the corresponding colors and values. The update option (default true) indicates whether to update the coloring automatically when the shape of the surface changes.

The coordinateSystem for interpreting center and axis coordinates can be specified by reference model number. The default coordinate system is that of the model being colored, generally the same as the scene coordinate system unless the model has been moved separately.

Coloring by Zone

Usage: color  zone  surf-spec  near  atom-spec  [ distance  cutoff ] [ sharpEdges  true | false ] [ bondPointSpacing s ] [ farColor  color-spec | keep ] [ update  true | false ]

Coloring by zone to match nearby atoms or markers applies to surfaces only. The distance cutoff is specified in physical units, typically Å (default 2.0). The corresponding Map icon uses a distance value six times the grid spacing of the map. The graphical implementation, Color Zone, includes a slider for adjusting the cutoff distance.

For coloring a molecular surface (and/or its caps where sliced by clipping) to match the underlying atoms, a cutoff of at least the diameter of the surface-calculation probe (which defaults to 2.8 Å) is recommended. When multiple specified atoms fall within the cutoff distance of a surface vertex, the vertex will be colored to match the closest one. If bondPointSpacing is specified, points spaced s Å apart along bonds will be used in addition to the atoms to define the zone. The farColor option indicates how to color vertices that are not within the cutoff distance of any of the atoms: either a specific color or keep to retain their current colors. If the farColor option is not given, the single-color setting of the surface model will be used.

The sharpEdges option (default false) subdivides surface triangles to create sharp boundaries between the different colored regions. The update option (default true) indicates whether to update the coloring automatically when the shape of the surface changes.

A map that has been colored by zone can be split accordingly with volume splitbyzone. For coloring by segmentation region, see segmentation. See also: ChimeraX video: coloring each protein in an EM map

Removing Coloring by Value or Zone

Usage: color  single  surf-model 

The color single command removes surface per-vertex colors such as from coloring by value (attribute, map, distance, coulombic, or mlp), by zone, or by the atomic patches in a molecular surface. The surface model is returned to its single-color setting.

Coloring from Image File

Usage: color  image  surf-spec  [ file  none | input-image-file [ modulate  true | false ]] [ coords  pole | south | sphere | vertexcolors ] [ writeColors  output-image-file ]

Coloring by image applies to surfaces only. In this technique, also known as texture mapping, surface vertices are associated with U,V coordinates that map to the X,Y coordinates in an image. The file option specifies an image from a file to paste onto the surface (image format indicated by the filename suffix), or none, which clears any previous image coloring (since coloring by image does not work with undo). Omitting the file option keeps using the previously specified image, if any, for texture mapping. The modulate option indicates whether the image in the file should modulate rather than replace the current surface coloring (default false, which changes the underlying surface color to white so that the resulting coloring will come from the image only).

An image is rectangular, with XY coordinates (0,0) at the lower left corner and (1,1) at the top right. The coords setting indicates how UV coordinates should be assigned to surface vertices:

If the coords option is not used, UV coordinates are not assigned (for example, to allow using Python to assign them in some other way).

Palette Options

A palette is an ordered set of colors or value,color pairs used for sequential coloring or coloring by value (map, distance, or attribute). See also: coulombic, mlp, alphafold contacts, measure convexity

palette  palette
The palette can be specified as one of the following (or as ^palette to reverse the order of the colors):
range  low,high | full
For numerical data only (not sequential coloring), what values should map to the extremes of the palette (default full, the minimum and maximum values for the items to be colored). Alternatively, low and high values separated by a comma only can be supplied. When multiple models are colored in a single command, the full range is determined separately for each model.

Defining and Listing Colors

Usage:
color name  cname  color-spec

Usage:
color deletecname | custom )

Usage:
color listall | builtin | custom ]

Usage:
color show  cname

The command color name assigns cname as the name of the specified color. It can be used to define a new color name or redefine an existing one. A built-in color name, however, cannot be redefined. Color names must begin with an alphabetical letter and may contain only lowercase letters, numbers, hyphens, underscores, and spaces. If cname has embedded spaces, it must be enclosed in quotation marks. Examples:

color name tpurple 60,0,80,50
color name tgreen rgba(0%, 80%, 40%, 0.5)

Colors can be defined automatically at ChimeraX startup by including color name commands in the Startup preferences.

The command color delete can be used to “forget” a specific user-defined color or all custom (user-defined) colors. A built-in color name cannot be deleted. User-defined color names are saved in sessions.

The command color list lists color names along with color swatches in the Log, with options:

The command “color show cname” reports in the Log the rgba (red, green, blue, opacity) definition of an existing color named cname. See also: palette list


UCSF Resource for Biocomputing, Visualization, and Informatics / May 2024