ProteinMotion
Reference navigation
On this page

CLASS · v0.9.1

ResidueLabels

Label several residues and adjust their positions to reduce overlap.

python
from proteinmotion import ResidueLabels

Constructor

python
ResidueLabels(region, *, offsets=None, avoid_overlap=True, **kwargs)

Parameters

ParameterDefaultDescription
regionRequiredRegion selection attached to a protein.
offsetskeyword onlyNoneMap residue numbers or (chain, number, insertion_code) keys to label offsets.
avoid_overlapkeyword onlyTrueAdjust labels in the group to reduce overlap.
**kwargsAdditional keyword options described below or in the linked constructor.

Additional keyword arguments

ParameterDefaultDescription
offsetkeyword only(24, -36)Offset (x, y) in design pixels at 1080p for residue labels; normalized image units for text shifts.
formatkeyword only'three_letter'Automatic residue name style: "three_letter" or "one_letter".
include_chainkeyword onlyTrueInclude the chain identifier in automatic residue names.
font_sizekeyword only26Font size in pixels at a 1080-pixel image height.

Notes

Options in kwargs go to ResidueLabel. Overlap adjustment applies within this group. Review label positions in the rendered scene. Residues without a Cα are skipped.

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 Scene excerpt
python
p = ubiquitin()
frame(self, p, margin=1.05)
labels = p.label_residues(
    chain="A",
    residues=[8, 44, 70],
    font_size=40,
    color="#f2ba67",
    offsets={8: (-270, -90), 44: (440, -100), 70: (380, 150)},
)
self.play(Write(labels, lag_ratio=0.08), run_time=2)
self.play(self.camera.animate.orbit(0.35), run_time=2)
self.wait(1)
Output Preview · 5.0 s · 60 fps
Amino acid labels

Ubiquitin residues 8, 44, and 70.

Methods and properties

NameDescription
glyph_countpropertyNumber of shaped glyphs used for writing animation.
text_progresspropertyCurrent reveal progress for glyphs and annotation lines.
layout()methodProject text and line geometry for the renderer at the current frame.
set_opacity()method · inherited from AnnotationSet or animate opacity in [0, 1].
move_to()method · inherited from AnnotationThis inherited method raises ValueError because residue labels follow their atoms. Set label offsets to change placement.
shift()method · inherited from AnnotationThis inherited method raises ValueError because residue labels follow their atoms. Set label offsets to change placement.
snapshot()method · inherited from AnnotationCapture the current state for deterministic timeline evaluation.
restore()method · inherited from AnnotationRestore a state produced by snapshot().
animateproperty · inherited from AnnotationCreate a builder for fluent animation calls. Pass the result to scene.play().
python
ResidueLabels.glyph_count

Number of shaped glyphs used for writing animation.

python
ResidueLabels.text_progress

Current reveal progress for glyphs and annotation lines.

python
ResidueLabels.layout(camera, width, height)

Project text and line geometry for the renderer at the current frame.

ParameterDefaultDescription
cameraRequiredCamera used to project or frame objects.
widthRequiredImage width in pixels.
heightRequiredImage height in pixels.

Returns: AnnotationLayout containing glyph placements and line paths.

Inherited from annotations.Annotation.

python
ResidueLabels.set_opacity(opacity)

Set or animate opacity in [0, 1].

ParameterDefaultDescription
opacityRequiredOpacity in [0, 1], from transparent to opaque.

Returns: The object or animation builder.

Inherited from annotations.Annotation.

python
ResidueLabels.move_to(position)

This inherited method raises ValueError because residue labels follow their atoms. Set label offsets to change placement.

ParameterDefaultDescription
positionRequiredImage coordinates (x, y), with (0, 0) at the top-left and (1, 1) at the bottom-right.

Inherited from annotations.Annotation.

python
ResidueLabels.shift(offset)

This inherited method raises ValueError because residue labels follow their atoms. Set label offsets to change placement.

ParameterDefaultDescription
offsetRequiredOffset (x, y) in design pixels at 1080p for residue labels; normalized image units for text shifts.

Inherited from annotations.Annotation.

python
ResidueLabels.snapshot()

Capture the current state for deterministic timeline evaluation.

Returns: State dictionary.

Inherited from annotations.Annotation.

python
ResidueLabels.restore(state)

Restore a state produced by snapshot().

ParameterDefaultDescription
stateRequiredState returned by snapshot().

Returns: None

Inherited from annotations.Annotation.

python
ResidueLabels.animate

Create a builder for fluent animation calls. Pass the result to scene.play().