ProteinMotion
Reference navigation
On this page

RamachandranPlot

A live φ/ψ plot: one point per residue over favored and allowed regions.

python
from proteinmotion import RamachandranPlot

Constructor

python
RamachandranPlot(
    protein,
    *,
    region=None,
    highlight=None,
    labels=True,
    color=None,
    title='Ramachandran plot',
    position=(0.64, 0.1),
    size=(0.32, 0.56),
    dot_size=5.5,
    background='general',
    region_labels=True,
    paths=True,
    highlight_color='#f5d477',
    favored_color='#2b4566',
    allowed_color='#1a2b42',
)

Parameters

ParameterDefaultDescription
proteinRequiredProtein whose residues are plotted.
regionkeyword onlyNoneRegion limiting the plotted residues; None plots every residue with both φ and ψ.
highlightkeyword onlyNoneRegion whose residues are ringed, enlarged, and labeled.
labelskeyword onlyTrueLabel highlighted residues with name and number.
colorkeyword onlyNoneOne color for every point; None uses the residue colors drawn in 3D.
titlekeyword only'Ramachandran plot'Text displayed above the plot.
positionkeyword only(0.64, 0.1)Image coordinates (x, y), with (0, 0) at the top-left and (1, 1) at the bottom-right.
sizekeyword only(0.32, 0.56)Plot (width, height) as fractions of the viewport.
dot_sizekeyword only5.5Point radius in design pixels at 1080p.
backgroundkeyword only'general'Reference regions: general, glycine, proline, preproline, or None.
region_labelskeyword onlyTrueLabel the αR, β, and αL regions.
pathskeyword onlyTrueDuring SetTorsions, draw each moving residue's path from its start.
highlight_colorkeyword only'#f5d477'Color marking the selected residues in the plot.
favored_colorkeyword only'#2b4566'Fill of regions containing 98% of reference residues.
allowed_colorkeyword only'#1a2b42'Fill of regions containing 99.8% of reference residues.

Notes

Glycine is drawn as a triangle and proline as a square. Regions come from one chain per 30% identity cluster of X-ray entries at 1.4 Å or better; scripts/build_ramachandran_reference.py rebuilds them.

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
"""Turn one ψ angle, then wind a whole peptide into an α helix.

A 12-residue alanine peptide is built as an extended β strand. ψ of Ala6 turns to
−45° with its atoms shown over the cartoon; then every residue moves to φ = −57°,
ψ = −47°, starting at the N terminus. DSSP assigns the helix from the final
coordinates, and the cartoon blends from coil to helix as the angles change.
"""

from proteinmotion import (
    FadeIn,
    Protein,
    ProteinScene,
    RamachandranPlot,
    SetTorsions,
    Text,
    Unwrite,
    Write,
)


class TorsionBasics(ProteinScene):
    def construct(self):
        peptide = Protein.build("AAAAAAAAAAAA", "strand").cartoon()
        middle = peptide.select(residues=6)
        middle.show_atoms()
        self.add(peptide)
        self.camera.frame(peptide, margin=1.0, aspect=self.width / self.height, screen_position=(0.32, 0.55))
        self.camera.phi = 0.3
        plot = RamachandranPlot(peptide, highlight=middle, position=(0.62, 0.14), size=(0.35, 0.7))
        self.add(Text("Torsion angles", font_size=48, font="semibold", position=(0.05, 0.07)))
        marker = middle.torsion_marker("psi", radius=1.6)
        self.play(FadeIn(plot), Write(marker), run_time=1.5)
        self.play(SetTorsions(middle, psi=-45, anchor="n"), run_time=2.5)
        self.play(Unwrite(marker), run_time=0.6)
        self.play(SetTorsions(peptide, conformation="helix", stagger=0.5), run_time=5)
        self.play(self.camera.animate.orbit(0.8), run_time=2.5)
Output Preview · 12.1 s · 60 fps
Torsion angles

A 12-residue alanine peptide: ψ of Ala6 turns, then every residue moves to α-helix angles.

Methods and properties

NameDescription
anglespropertyCurrent (φ, ψ) in degrees for each plotted residue.
layout()methodProject text and line geometry for the renderer at the current frame.
with_panel()method · inherited from _PlotDraw a rounded card behind the plot so molecules passing behind it stay hidden.
snapshot()method · inherited from _PlotCapture the current state for deterministic timeline evaluation.
glyph_countproperty · inherited from _PlotNumber of shaped glyphs used for writing animation.
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.
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().
text_progressproperty · inherited from AnnotationCurrent reveal progress for glyphs and annotation lines.
python
RamachandranPlot.angles

Current (φ, ψ) in degrees for each plotted residue.

python
RamachandranPlot.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 plots._Plot.

python
RamachandranPlot.with_panel(color='#0b1220', opacity=1.0, padding=18)

Draw a rounded card behind the plot so molecules passing behind it stay hidden.

ParameterDefaultDescription
color'#0b1220'Card color.
opacity1.0Card opacity in [0, 1].
padding18Margin around the plot in design pixels at 1080p.

Inherited from plots._Plot.

python
RamachandranPlot.snapshot()

Capture the current state for deterministic timeline evaluation.

Returns: State dictionary.

Inherited from plots._Plot.

python
RamachandranPlot.glyph_count

Number of shaped glyphs used for writing animation.

Inherited from annotations.Annotation.

python
RamachandranPlot.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
RamachandranPlot.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
RamachandranPlot.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
RamachandranPlot.restore(state)

Restore a state produced by snapshot().

ParameterDefaultDescription
stateRequiredState returned by snapshot().

Returns: None

Inherited from annotations.Annotation.

python
RamachandranPlot.animate

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

Inherited from annotations.Annotation.

python
RamachandranPlot.text_progress

Current reveal progress for glyphs and annotation lines.