Reference navigation
On this page
Focus
Animate the camera to a protein or selected region.
from proteinmotion import FocusConstructor
Focus(
camera,
region,
*,
margin=1.25,
aspect=None,
follow=True,
screen_position=(0.5, 0.5),
**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 | None | Image width divided by height. |
followkeyword only | True | Track the selection’s center after the focus completes. |
screen_positionkeyword only | (0.5, 0.5) | Normalized subject position; (0, 0) is top-left and (1, 1) bottom-right. |
**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.
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)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. |
| during()method · inherited from Animation | Set this animation duration and start delay in seconds. |
| 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.during(seconds, *, delay=0)Set this animation duration and start delay in seconds.
| Parameter | Default | Description |
|---|---|---|
seconds | Required | Positive animation duration in seconds. |
delaykeyword only | 0 | Nonnegative animation start delay in seconds. |
Inherited from animation.Animation.
Focus.targetsObjects whose state this animation changes.