Reference navigation
On this page
ColorScale
A fixed linear scale mapping scalar values to RGB colors.
from proteinmotion import ColorScaleConstructor
ColorScale(
vmin,
vmax,
*,
colors=('#355f9e', '#56c5bd', '#f5d477'),
missing='#87909c',
boundaries=None,
)Parameters
| Parameter | Default | Description |
|---|---|---|
vmin | Required | Finite lower limit of the fixed color scale. |
vmax | Required | Finite upper limit, greater than vmin. |
colorskeyword only | ('#355f9e', '#56c5bd', '#f5d477') | Two or more RGB colors, interpolated between equally spaced stops. |
missingkeyword only | '#87909c' | Color for missing values (NaN). |
boundarieskeyword only | None | Increasing values that split the scale into bands, one fewer than colors; None interpolates. |
Notes
Values outside the limits use endpoint colors. NaN uses the missing color. Intermediate colors interpolate between equally spaced stops.
Example and output
This excerpt runs inside a scene’s construct() method. The full example file includes imports, structure loading, and camera setup. Run it from a repository checkout.
"""Map 1UBQ Cα B factors to residue color and cartoon thickness."""
from pathlib import Path
from proteinmotion import (
ColorByProperty,
ColorLegend,
ColorScale,
Protein,
ProteinScene,
Representation,
ResidueValues,
Rotate,
Text,
)
DATA = Path(__file__).parent / "data"
class NumericalProperties(ProteinScene):
def construct(self):
protein = Protein.from_file(DATA / "1ubq.cif").center()
values = ResidueValues.b_factors(protein)
scale = ColorScale(0, 40)
self.add(protein)
self.camera.frame(protein, margin=1.08)
self.add(Text("Residue properties", position=(0.06, 0.07), font_size=42))
self.add(Text("Ubiquitin · Cα B factors", position=(0.06, 0.13), font_size=25))
self.add(ColorLegend(scale, title="B factor", unit="Ų", position=(0.06, 0.8)))
self.play(
ColorByProperty(protein, values, scale=scale, thickness=(0.6, 1.8), residue_delay=0.012),
Rotate(protein, 0.25),
run_time=2.5,
)
self.wait(0.5)
self.play(Representation(protein, "ball_and_stick"), run_time=1.5)
self.play(Rotate(protein, 0.3), run_time=1)
self.play(Representation(protein, "surface"), run_time=1.5)
self.play(Rotate(protein, 0.25), run_time=1.5)1UBQ B factors control residue color and cartoon thickness.
Methods and properties
| Name | Description |
|---|---|
| hydropathy()class method | Hydrophilic blue, neutral near-white, hydrophobic orange; symmetric about 0. |
| conservation()class method | ConSurf's palette from variable (turquoise) through white to conserved (maroon). |
| plddt()class method | AlphaFold's four confidence bands, split at pLDDT 50, 70 and 90. |
| pae()class method | Predicted aligned error in Å: confident dark green to uncertain near-white. |
| distance()class method | Current endpoint distance in ångströms, regardless of the label unit. |
| difference()class method | A signed change in Å: closer in blue, unchanged near-white, farther in red. |
| from_values()class method | Choose limits from finite values; expand a constant range by ±0.5. |
| normalize()method | Clip values to [0, 1], keeping NaN for missing data. |
| map()method | Map values to an RGB array shaped (*values.shape, 3). |
ColorScale.hydropathy(scale='kyte-doolittle')Hydrophilic blue, neutral near-white, hydrophobic orange; symmetric about 0.
| Parameter | Default | Description |
|---|---|---|
scale | 'kyte-doolittle' | "kyte-doolittle" or "eisenberg". |
ColorScale.conservation(vmin=0.0, vmax=1.0)ConSurf's palette from variable (turquoise) through white to conserved (maroon).
| Parameter | Default | Description |
|---|---|---|
vmin | 0.0 | Score drawn turquoise (variable). |
vmax | 1.0 | Score drawn maroon (conserved). |
ColorScale.plddt()AlphaFold's four confidence bands, split at pLDDT 50, 70 and 90.
ColorScale.pae(max_error=31.75)Predicted aligned error in Å: confident dark green to uncertain near-white.
| Parameter | Default | Description |
|---|---|---|
max_error | 31.75 | Error in ångströms drawn near white. |
ColorScale.distance(max_distance=40.0)Current endpoint distance in ångströms, regardless of the label unit.
| Parameter | Default | Description |
|---|---|---|
max_distance | 40.0 | Distance in ångströms drawn darkest. |
ColorScale.difference(limit=10.0)A signed change in Å: closer in blue, unchanged near-white, farther in red.
| Parameter | Default | Description |
|---|---|---|
limit | 10.0 | Change in ångströms at either end of the symmetric scale. |
ColorScale.from_values(values, **kwargs)Choose limits from finite values; expand a constant range by ±0.5.
| Parameter | Default | Description |
|---|---|---|
values | Required | Numerical input values; see the shape and missing-value rules for this object. |
**kwargs | — | Additional keyword options described below or in the linked constructor. |
ColorScale.normalize(values)Clip values to [0, 1], keeping NaN for missing data.
| Parameter | Default | Description |
|---|---|---|
values | Required | Numerical input values; see the shape and missing-value rules for this object. |
ColorScale.map(values)Map values to an RGB array shaped (*values.shape, 3).
| Parameter | Default | Description |
|---|---|---|
values | Required | Numerical input values; see the shape and missing-value rules for this object. |