ProteinMotion
Reference navigation
On this page

CLASS · v0.9.1

ColorByProperty

Animate property-based residue colors and optional cartoon thickness.

python
from proteinmotion import ColorByProperty

Constructor

python
ColorByProperty(
    protein,
    values,
    *,
    scale=None,
    thickness=None,
    residue_delay=0,
    reverse=False,
    easing='smooth',
)

Parameters

ParameterDefaultDescription
proteinRequiredProtein object to read or animate.
valuesRequiredNumerical input values; see the shape and missing-value rules for this object.
scalekeyword onlyNoneColorScale shared by the structure, plots, and legend. None derives limits from finite values.
thicknesskeyword onlyNoneOptional (minimum, maximum) positive cartoon cross-section scale factors. Missing values use 1.
residue_delaykeyword only0Delay in seconds between successive residue starts.
reversekeyword onlyFalseReverse residue or glyph order.
easingkeyword only'smooth'Per-residue interpolation: "smooth" or "linear".

Notes

Residue delays are in seconds. run_time must exceed total delay. The scale remains fixed during the transition.

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.

Code Full script
python
"""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)
Output Preview · 8.5 s · 60 fps
B factors across representations

1UBQ B factors control residue color and cartoon thickness.

Methods and properties

NameDescription
bind()methodCapture starting values when the scene schedules the animation.
apply()methodEvaluate the animation at eased progress alpha. Called by the timeline.
targetsproperty · inherited from AnimationObjects whose state this animation changes.
python
ColorByProperty.bind()

Capture starting values when the scene schedules the animation.

Returns: None

Called by ProteinScene.play(). An animation instance can be bound once.

python
ColorByProperty.apply(alpha)

Evaluate the animation at eased progress alpha. Called by the timeline.

ParameterDefaultDescription
alphaRequiredEased animation progress in [0, 1].

Returns: None

Inherited from animation.Animation.

python
ColorByProperty.targets

Objects whose state this animation changes.