Reference navigation
On this page
CLASS · v0.9.1
Animate
Build a fluent protein or camera animation through the .animate property.
from proteinmotion.animation import AnimateConstructor
Animate(target)Parameters
| Parameter | Default | Description |
|---|---|---|
target | Required | Object 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.
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)Ubiquitin, PDB 1UBQ.
Methods and properties
| Name | Description |
|---|---|
| shift()method | Translate the object by an offset. |
| rotate()method | Rotate around the molecular centroid. |
| scale()method | Scale around the molecular centroid. |
| set_opacity()method | Set or animate opacity in [0, 1]. |
| orbit()method | Change horizontal and vertical camera angles. |
| zoom()method | Divide camera distance by factor. Values greater than 1 zoom in. |
| set_color()method | Apply a tint across all representations. None restores the base palette. |
| focus()method | Frame a protein or region and optionally track its moving center. |
| set_focus()method | Create a FocusPull animation for this camera. |
| bind()method | Capture starting values when the scene schedules the animation. |
| apply()method | Evaluate the animation at eased progress alpha. Called by the timeline. |
| targetsproperty · inherited from Animation | Objects whose state this animation changes. |
Animate.shift(vector)Translate the object by an offset.
| Parameter | Default | Description |
|---|---|---|
vector | Required | Finite 3D translation vector in ångströms. |
Returns: The object or animation builder.
Animate.rotate(angle, axis=(0, 1, 0))Rotate around the molecular centroid.
| Parameter | Default | Description |
|---|---|---|
angle | Required | Rotation angle in radians. |
axis | (0, 1, 0) | Nonzero 3D rotation axis; it is normalized internally. |
Returns: The protein or animation builder.
Animate.scale(factor)Scale around the molecular centroid.
| Parameter | Default | Description |
|---|---|---|
factor | Required | Positive scale or zoom factor. |
Returns: The protein or animation builder.
Animate.set_opacity(opacity)Set or animate opacity in [0, 1].
| Parameter | Default | Description |
|---|---|---|
opacity | Required | Opacity in [0, 1], from transparent to opaque. |
Returns: The object or animation builder.
Animate.orbit(theta=0, phi=0)Change horizontal and vertical camera angles.
| Parameter | Default | Description |
|---|---|---|
theta | 0 | Change in horizontal camera angle, in radians. |
phi | 0 | Change in vertical camera angle, in radians. |
Returns: The camera or animation builder.
Animate.zoom(factor)Divide camera distance by factor. Values greater than 1 zoom in.
| Parameter | Default | Description |
|---|---|---|
factor | Required | Positive scale or zoom factor. |
Returns: The camera or animation builder.
Animate.set_color(color, **kwargs)Apply a tint across all representations. None restores the base palette.
| Parameter | Default | Description |
|---|---|---|
color | Required | Hex color or RGB values. For tint setters, None restores the representation’s base palette. |
**kwargs | — | Additional keyword options described below or in the linked constructor. |
Returns: The object or a Colorize animation.
Animate.focus(region, *, margin=1.25, aspect=16 / 9, follow=True)Frame a protein or region and optionally track its moving center.
| Parameter | Default | Description |
|---|---|---|
region | Required | Region selection attached to a protein. |
marginkeyword only | 1.25 | Positive framing margin; larger values leave more space around the target. |
aspectkeyword only | 16 / 9 | Image width divided by height. |
followkeyword only | True | Track the selection’s center after the focus completes. |
Returns: The camera, scene, or Focus animation.
Animate.set_focus(target, **kwargs)Create a FocusPull animation for this camera.
| Parameter | Default | Description |
|---|---|---|
target | Required | Protein, Region, or world point. |
**kwargs | — | FocusPull options, including chain, residues, atoms, fstop and follow. |
Returns: FocusPull
Animate.bind()Capture starting values when the scene schedules the animation.
Returns: None
Called by ProteinScene.play(). An animation instance can be bound once.
Animate.apply(alpha)Evaluate the animation at eased progress alpha. Called by the timeline.
| Parameter | Default | Description |
|---|---|---|
alpha | Required | Eased animation progress in [0, 1]. |
Returns: None
Inherited from animation.Animation.
Animate.targetsObjects whose state this animation changes.