Reference navigation
On this page
CLASS · v0.9.1
Focus
Animate the camera to a protein or selected region.
from proteinmotion import FocusConstructor
Focus(camera, region, *, margin=1.25, aspect=16 / 9, follow=True, **kwargs)Parameters
| Parameter | Default | Description |
|---|---|---|
camera | Required | Camera used to project or frame objects. |
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. |
**kwargs | — | Additional keyword options described below or in the linked constructor. |
Additional keyword arguments
| Parameter | Default | Description |
|---|---|---|
rate_funckeyword only | smooth | Callable 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
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
Ubiquitin residues 23–34.
Methods and properties
| Name | Description |
|---|---|
| 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. |
Focus.bind()Capture starting values when the scene schedules the animation.
Returns: None
Called by ProteinScene.play(). An animation instance can be bound once.
Focus.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.
Focus.targetsObjects whose state this animation changes.