ProteinMotion
Reference navigation
On this page

CLASS · v0.9.1

ProteinScene

Define a protein animation as a sequence of play() and wait() calls.

python
from proteinmotion import ProteinScene

Constructor

python
ProteinScene(*, width=1920, height=1080, fps=30, background='#0b1220', msaa=4)

Parameters

ParameterDefaultDescription
widthkeyword only1920Image width in pixels.
heightkeyword only1080Image height in pixels.
fpskeyword only30Video frames per second; must be positive.
backgroundkeyword only'#0b1220'Background color as a hex string or RGB values.
msaakeyword only4Multisample count: 1 or 4.

Notes

Subclass ProteinScene and implement construct(). Configure initial geometry, styles, and camera pose before the first play() or wait(). Concurrent animations can change separate properties.

Attributes

NameDescription
cameraCamera used by the scene.
durationTotal timeline duration in seconds.
width, heightOutput dimensions in pixels.
fpsFrames per second.

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
construct()methodOverride this method to define the scene with add(), play(), wait(), and camera setup.
add()methodAdd proteins, density objects, or annotations at the current timeline time.
play()methodRun animations together, then advance the timeline by run_time seconds.
focus()methodAnimate camera focus using the scene’s output aspect ratio.
wait()methodExtend the timeline while holding the current state.
build()methodCall construct() once and prepare the timeline.
seek()methodEvaluate the scene at a time clamped to its duration. Supports forward and backward seeks.
render_frame()methodRender one point on the timeline to an image.
render()methodExport the timeline to a video file.
preview()methodOpen an interactive preview window. Requires the preview extra.
python
ProteinScene.construct()

Override this method to define the scene with add(), play(), wait(), and camera setup.

Returns: None

python
ProteinScene.add(*proteins)

Add proteins, density objects, or annotations at the current timeline time.

ParameterDefaultDescription
*proteinsProtein or annotation objects to add or render.
python
ProteinScene.play(*animations, run_time=1.0, rate_func=None)

Run animations together, then advance the timeline by run_time seconds.

ParameterDefaultDescription
*animationsAnimation objects to run together.
run_timekeyword only1.0Clip duration in seconds; must be positive.
rate_funckeyword onlyNoneCallable that maps progress in [0, 1] to a finite value in [0, 1].

Returns: The scene.

Animations that write the same object property concurrently raise ValueError. Create a new animation object for each play() call.

python
ProteinScene.focus(target, *, run_time=1.5, margin=1.25, follow=True, rate_func=None)

Animate camera focus using the scene’s output aspect ratio.

ParameterDefaultDescription
targetRequiredObject to animate or use as a destination. The supported object type depends on the operation.
run_timekeyword only1.5Clip duration in seconds; must be positive.
marginkeyword only1.25Positive framing margin; larger values leave more space around the target.
followkeyword onlyTrueTrack the selection’s center after the focus completes.
rate_funckeyword onlyNoneCallable that maps progress in [0, 1] to a finite value in [0, 1].

Returns: The scene.

python
ProteinScene.wait(duration=1.0)

Extend the timeline while holding the current state.

ParameterDefaultDescription
duration1.0Hold duration in seconds; must be nonnegative.

Returns: The scene.

python
ProteinScene.build()

Call construct() once and prepare the timeline.

Returns: The scene.

python
ProteinScene.seek(time)

Evaluate the scene at a time clamped to its duration. Supports forward and backward seeks.

ParameterDefaultDescription
timeRequiredTimeline position in seconds.

Returns: List of visible objects.

python
ProteinScene.render_frame(time=0.0, *, output=None, renderer=None, eevee=None)

Render one point on the timeline to an image.

ParameterDefaultDescription
time0.0Timeline position in seconds.
outputkeyword onlyNoneOutput file path.
rendererkeyword onlyNone"native", "eevee", an existing renderer instance, or None for native.
eeveekeyword onlyNoneOptional EEVEEOptions instance; requires renderer="eevee".

Returns: RGBA uint8 image array.

python
ProteinScene.render(
    output,
    *,
    codec='auto',
    bitrate='20M',
    progress=True,
    renderer='native',
    eevee=None,
)

Export the timeline to a video file.

ParameterDefaultDescription
outputRequiredOutput file path.
codeckeyword only'auto'FFmpeg encoder name; auto selects hardware H.264 on macOS when available.
bitratekeyword only'20M'Target video bitrate, such as "20M".
progresskeyword onlyTruePrint frame progress and render timing.
rendererkeyword only'native'"native" (default) or "eevee".
eeveekeyword onlyNoneOptional EEVEEOptions instance; requires renderer="eevee".

Returns: Dictionary containing frames, seconds, fps, adapter, codec, and output. Here fps is render throughput.

python
ProteinScene.preview()

Open an interactive preview window. Requires the preview extra.

Returns: None