ProteinMotion
Reference navigation
On this page

SetTorsions

Animate backbone and side-chain torsions to new values in degrees; atoms rotate about bonds, so bond lengths and angles stay fixed.

python
from proteinmotion import SetTorsions

Constructor

python
SetTorsions(
    target,
    *,
    phi=None,
    psi=None,
    omega=None,
    chi1=None,
    chi2=None,
    chi3=None,
    chi4=None,
    chi5=None,
    conformation=None,
    anchor='center',
    secondary='auto',
    path='allowed',
    stagger=None,
    reverse=False,
    easing='smooth',
)

Parameters

ParameterDefaultDescription
targetRequiredProtein or Region whose amino acids change.
phikeyword onlyNoneφ, C(i−1)–N–Cα–C. Target angle in degrees: one value for every selected residue, one per residue, or a {residue number: angle} dictionary. None leaves it unchanged.
psikeyword onlyNoneψ, N–Cα–C–N(i+1). Target angle in degrees: one value for every selected residue, one per residue, or a {residue number: angle} dictionary. None leaves it unchanged.
omegakeyword onlyNoneω, the peptide bond Cα–C–N(i+1)–Cα(i+1). Target angle in degrees: one value for every selected residue, one per residue, or a {residue number: angle} dictionary. None leaves it unchanged.
chi1keyword onlyNoneχ1 side-chain torsion. Target angle in degrees: one value for every selected residue, one per residue, or a {residue number: angle} dictionary. None leaves it unchanged.
chi2keyword onlyNoneχ2 side-chain torsion. Target angle in degrees: one value for every selected residue, one per residue, or a {residue number: angle} dictionary. None leaves it unchanged.
chi3keyword onlyNoneχ3 side-chain torsion. Target angle in degrees: one value for every selected residue, one per residue, or a {residue number: angle} dictionary. None leaves it unchanged.
chi4keyword onlyNoneχ4 side-chain torsion. Target angle in degrees: one value for every selected residue, one per residue, or a {residue number: angle} dictionary. None leaves it unchanged.
chi5keyword onlyNoneχ5 side-chain torsion. Target angle in degrees: one value for every selected residue, one per residue, or a {residue number: angle} dictionary. None leaves it unchanged.
conformationkeyword onlyNoneSets φ and ψ together: helix, alpha, 310, pi, strand, beta, parallel, antiparallel, ppii, extended, or left.
anchorkeyword only'center'Part that stays still: "center" keeps the middle of each chain in place, "n" or "c" a terminus; a Region is held in place as a whole.
secondarykeyword only'auto'"auto" blends the cartoon toward the DSSP assignment of the final conformation; "keep" leaves it unchanged.
pathkeyword only'allowed'"allowed" turns φ and ψ the way that keeps each residue in favored and allowed Ramachandran regions; "shortest" takes the smaller turn.
staggerkeyword onlyNoneFraction of the clip, in [0, 1), used to start residues one after another from N to C.
reversekeyword onlyFalseStagger from C to N.
easingkeyword only'smooth'Easing of each torsion's change.

Notes

Torsions in rings, such as proline φ, are skipped and listed by locked. Disulfides and ligands bonded to several residues stretch. The motion illustrates a change of angles, not a folding pathway.

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
lockedproperty(residue index, torsion) pairs that could not rotate because they lie in rings.
bind()methodCapture starting values when the scene schedules the animation.
apply()methodEvaluate the animation at eased progress alpha. Called by the timeline.
during()method · inherited from AnimationSet this animation duration and start delay in seconds.
targetsproperty · inherited from AnimationObjects whose state this animation changes.
python
SetTorsions.locked

(residue index, torsion) pairs that could not rotate because they lie in rings.

python
SetTorsions.bind()

Capture starting values when the scene schedules the animation.

Returns: None

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

python
SetTorsions.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
SetTorsions.during(seconds, *, delay=0)

Set this animation duration and start delay in seconds.

ParameterDefaultDescription
secondsRequiredPositive animation duration in seconds.
delaykeyword only0Nonnegative animation start delay in seconds.

Inherited from animation.Animation.

python
SetTorsions.targets

Objects whose state this animation changes.