ProteinMotion
Reference navigation
On this page

CLASS · v0.9.1

Distance

Draw a distance line between two atom or residue selections.

python
from proteinmotion import Distance

Constructor

python
Distance(
    start,
    end,
    *,
    mode='3d',
    anchor='ca',
    space='model',
    color='#f2ba67',
    label_color=None,
    font_size=27,
    precision=1,
    unit='Å',
    prefix='',
    show_distance=True,
    style='dashed',
    line_width=1.7,
    radius=0.09,
    dash_count=12,
    dash_ratio=0.6,
    follow_opacity=True,
    opacity=1,
)

Parameters

ParameterDefaultDescription
startRequiredRegion for the first endpoint.
endRequiredRegion for the second endpoint.
modekeyword only'3d'"3d" draws lines within the model; "2d" draws lines over the image.
anchorkeyword only'ca'"ca" uses the Cα of a single residue when available; "centroid" averages selected coordinates.
spacekeyword only'model'"model" uses local coordinates; "world" includes display transforms.
colorkeyword only'#f2ba67'Hex color or RGB values. For tint setters, None restores the representation’s base palette.
label_colorkeyword onlyNoneDistance text color; None inherits the line color.
font_sizekeyword only27Font size in pixels at a 1080-pixel image height.
precisionkeyword only1Number of decimal places in a distance label, from 0 to 6.
unitkeyword only'Å'Displayed distance unit: "Å", "nm", or an empty suffix. The distance property uses ångströms.
prefixkeyword only''Text placed before the distance value.
show_distancekeyword onlyTrueDisplay the distance value at the line midpoint.
stylekeyword only'dashed'"dashed" or "solid".
line_widthkeyword only1.7Line width in design pixels at 1080p for overlays; ångströms for 3D highlight boxes.
radiuskeyword only0.093D line cylinder radius in ångströms.
dash_countkeyword only12Number of line segments.
dash_ratiokeyword only0.6Filled fraction of each dashed segment.
follow_opacitykeyword onlyTrueMultiply annotation opacity by its selected atom opacity.
opacitykeyword only1Opacity in [0, 1], from transparent to opaque.

Notes

Single-atom selections use that atom. A single-residue selection uses its Cα when available; larger selections use a centroid. In 3D mode, atoms can hide the line. Labels are drawn over the image. Use space="world" for endpoints on separate proteins, and preserve a shared coordinate frame for physical distances.

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 = helix_view(self)
a = p.select(residues=23, atoms="CA")
b = p.select(residues=34, atoms="CA")
for mode in ("3d", "2d"):
    ruler = Distance(
        a,
        b,
        mode=mode,
        font_size=42,
        color="#50e0d0",
        prefix="Cα · ",
    )
    title = Text(f"{mode.upper()} line", font_size=48)
    self.play(Write(ruler), Write(title), run_time=1.5)
    self.play(self.camera.animate.orbit(0.35), run_time=2)
    self.play(FadeOut(ruler), FadeOut(title), run_time=0.5)
Output Preview · 8.0 s · 60 fps
3D and 2D distance lines

Distance between Cα23 and Cα34 in PDB 1UBQ.

Methods and properties

NameDescription
distancepropertyCurrent endpoint distance in ångströms, regardless of the label unit.
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 AnnotationSet or animate text position in normalized image coordinates.
shift()method · inherited from AnnotationTranslate the object by an offset.
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
Distance.distance

Current endpoint distance in ångströms, regardless of the label unit.

python
Distance.glyph_count

Number of shaped glyphs used for writing animation.

python
Distance.text_progress

Current reveal progress for glyphs and annotation lines.

python
Distance.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
Distance.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
Distance.move_to(position)

Set or animate text position in normalized image coordinates.

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

Returns: The annotation or animation builder.

Inherited from annotations.Annotation.

python
Distance.shift(offset)

Translate the object by an offset.

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

Returns: The object or animation builder.

Inherited from annotations.Annotation.

python
Distance.snapshot()

Capture the current state for deterministic timeline evaluation.

Returns: State dictionary.

Inherited from annotations.Annotation.

python
Distance.restore(state)

Restore a state produced by snapshot().

ParameterDefaultDescription
stateRequiredState returned by snapshot().

Returns: None

Inherited from annotations.Annotation.

python
Distance.animate

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