ProteinMotion
Reference navigation
On this page

CLASS · v0.9.1

Animate

Build a fluent protein or camera animation through the .animate property.

python
from proteinmotion.animation import Animate

Constructor

python
Animate(target)

Parameters

ParameterDefaultDescription
targetRequiredObject to animate or use as a destination. The supported object type depends on the operation.

Notes

Protein operations include shift(), rotate(), scale(), and set_opacity(). Camera operations include orbit() and zoom(). set_color() returns a separate Colorize animation; focus() returns a Focus animation. Place color and transforms in separate arguments to play().

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)
self.play(FadeIn(p), run_time=1)
self.play(Rotate(p, np.pi), run_time=3)
self.play(Representation(p, "ribbon"), run_time=1)
self.play(
    p.animate.shift((5, 0, 0)),
    self.camera.animate.orbit(theta=0.6),
    run_time=2,
)
self.wait(0.5)
Output Preview · 7.5 s · 60 fps
Rotation and movement

Ubiquitin, PDB 1UBQ.

Methods and properties

NameDescription
shift()methodTranslate the object by an offset.
rotate()methodRotate around the molecular centroid.
scale()methodScale around the molecular centroid.
set_opacity()methodSet or animate opacity in [0, 1].
orbit()methodChange horizontal and vertical camera angles.
zoom()methodDivide camera distance by factor. Values greater than 1 zoom in.
set_color()methodApply a tint across all representations. None restores the base palette.
focus()methodFrame a protein or region and optionally track its moving center.
set_focus()methodCreate a FocusPull animation for this camera.
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
Animate.shift(vector)

Translate the object by an offset.

ParameterDefaultDescription
vectorRequiredFinite 3D translation vector in ångströms.

Returns: The object or animation builder.

python
Animate.rotate(angle, axis=(0, 1, 0))

Rotate around the molecular centroid.

ParameterDefaultDescription
angleRequiredRotation angle in radians.
axis(0, 1, 0)Nonzero 3D rotation axis; it is normalized internally.

Returns: The protein or animation builder.

python
Animate.scale(factor)

Scale around the molecular centroid.

ParameterDefaultDescription
factorRequiredPositive scale or zoom factor.

Returns: The protein or animation builder.

python
Animate.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.

python
Animate.orbit(theta=0, phi=0)

Change horizontal and vertical camera angles.

ParameterDefaultDescription
theta0Change in horizontal camera angle, in radians.
phi0Change in vertical camera angle, in radians.

Returns: The camera or animation builder.

python
Animate.zoom(factor)

Divide camera distance by factor. Values greater than 1 zoom in.

ParameterDefaultDescription
factorRequiredPositive scale or zoom factor.

Returns: The camera or animation builder.

python
Animate.set_color(color, **kwargs)

Apply a tint across all representations. None restores the base palette.

ParameterDefaultDescription
colorRequiredHex color or RGB values. For tint setters, None restores the representation’s base palette.
**kwargsAdditional keyword options described below or in the linked constructor.

Returns: The object or a Colorize animation.

python
Animate.focus(region, *, margin=1.25, aspect=16 / 9, follow=True)

Frame a protein or region and optionally track its moving center.

ParameterDefaultDescription
regionRequiredRegion selection attached to a protein.
marginkeyword only1.25Positive framing margin; larger values leave more space around the target.
aspectkeyword only16 / 9Image width divided by height.
followkeyword onlyTrueTrack the selection’s center after the focus completes.

Returns: The camera, scene, or Focus animation.

python
Animate.set_focus(target, **kwargs)

Create a FocusPull animation for this camera.

ParameterDefaultDescription
targetRequiredProtein, Region, or world point.
**kwargsFocusPull options, including chain, residues, atoms, fstop and follow.

Returns: FocusPull

python
Animate.bind()

Capture starting values when the scene schedules the animation.

Returns: None

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

python
Animate.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
Animate.targets

Objects whose state this animation changes.