ProteinMotion
Reference navigation
On this page

CLASS · v0.9.1

Focus

Animate the camera to a protein or selected region.

python
from proteinmotion import Focus

Constructor

python
Focus(camera, region, *, margin=1.25, aspect=16 / 9, follow=True, **kwargs)

Parameters

ParameterDefaultDescription
cameraRequiredCamera used to project or frame objects.
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.
**kwargsAdditional keyword options described below or in the linked constructor.

Additional keyword arguments

ParameterDefaultDescription
rate_funckeyword onlysmoothCallable that maps progress in [0, 1] to a finite value in [0, 1].

Notes

Evaluated after molecular movement in the same play() call. follow=True keeps tracking the region center after the focus finishes.

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)
helix = p.select(chain="A", residues=(23, 34))
marker = helix.highlight(
    style="box",
    color="#f2ba67",
    padding=1.5,
)
self.play(FadeIn(marker), run_time=0.6)
self.focus(helix, margin=1.6, run_time=1.5)
self.play(self.camera.animate.orbit(0.4), run_time=2)
self.play(FadeOut(marker), run_time=0.6)
self.focus(p, run_time=1.5)
Output Preview · 6.2 s · 60 fps
Camera focus

Ubiquitin residues 23–34.

Methods and properties

NameDescription
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
Focus.bind()

Capture starting values when the scene schedules the animation.

Returns: None

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

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

Objects whose state this animation changes.