ProteinMotion
Reference navigation
On this page

CLASS · v0.9.1

Camera

A perspective camera with orbit, zoom, framing, depth cueing, and EEVEE lens focus.

python
from proteinmotion.camera import Camera

Constructor

python
Camera()

Notes

Each scene creates its own camera at scene.camera. Use frame() for initial setup and Focus or scene.focus() for animated camera movement.

Attributes

NameDescription
targetLook-at point in world coordinates.
distanceDistance from the camera to its target, initially 70 Å.
theta, phiHorizontal and vertical angles in radians.
fovVertical field of view in radians; initially 38 degrees.
depth_cueDistance fog strength; 0 disables it.
radiusFraming radius used to choose clipping planes.
dofWhether EEVEE depth of field is enabled; initially False.
fstopLens f-number, initially 5.6. Lower values produce more blur.

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
set_focus()methodSet lens focus without moving or zooming the camera.
focus_pointpropertyCurrent lens target in world ångströms, following the selected atoms.
frame()methodFrame the supplied proteins or regions immediately and stop previous tracking.
focus()methodFrame a protein or region immediately and optionally track its center.
update_tracking()methodUpdate the camera target from the tracked region while keeping zoom fixed.
orbit()methodChange horizontal and vertical camera angles.
zoom()methodDivide camera distance by factor. Values greater than 1 zoom in.
eyepropertyCurrent camera position in world coordinates.
matrix()methodCompute the view-projection matrix for the given image aspect ratio.
animatepropertyCreate a builder for orbit, zoom, and focus animations.
snapshot()methodCapture the current state for deterministic timeline evaluation.
restore()methodRestore a state produced by snapshot().
python
Camera.set_focus(
    target,
    *,
    chain=None,
    residues=None,
    atoms=None,
    fstop=5.6,
    follow=True,
)

Set lens focus without moving or zooming the camera.

ParameterDefaultDescription
targetRequiredProtein, Region, world point, or None to disable DOF.
chainkeyword onlyNoneAuthor chain ID or a collection of IDs; None selects all chains.
residueskeyword onlyNoneAuthor residue number, inclusive (first, last) tuple, or list of individual numbers.
atomskeyword onlyNoneAtom name or list of names, such as "CA"; None selects all atom names.
fstopkeyword only5.6Lens f-number. Lower values produce a shallower depth of field. Must be positive.
followkeyword onlyTrueTrack the mean selected position through motion; False fixes the initial world point.

Returns: The camera.

Selectors apply to a Protein target. Ranges use inclusive PDB author numbers. atoms="CA" focuses on the Cα centroid. A region defines one focus plane, rather than making all selected atoms equally sharp.

python
Camera.focus_point

Current lens target in world ångströms, following the selected atoms.

python
Camera.frame(*proteins, margin=1.25, aspect=16 / 9)

Frame the supplied proteins or regions immediately and stop previous tracking.

ParameterDefaultDescription
*proteinsProtein or annotation objects to add or render.
marginkeyword only1.25Positive framing margin; larger values leave more space around the target.
aspectkeyword only16 / 9Image width divided by height.

Returns: The camera.

python
Camera.focus(target, *, margin=1.25, aspect=16 / 9, follow=True)

Frame a protein or region immediately and optionally track its center.

ParameterDefaultDescription
targetRequiredObject to animate or use as a destination. The supported object type depends on the operation.
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.

Returns: The camera.

python
Camera.update_tracking()

Update the camera target from the tracked region while keeping zoom fixed.

Returns: None

python
Camera.orbit(theta=0.0, phi=0.0)

Change horizontal and vertical camera angles.

ParameterDefaultDescription
theta0.0Change in horizontal camera angle, in radians.
phi0.0Change in vertical camera angle, in radians.

Returns: The camera or animation builder.

python
Camera.zoom(factor)

Divide camera distance by factor. Values greater than 1 zoom in.

ParameterDefaultDescription
factorRequiredPositive scale or zoom factor.

Returns: The camera or animation builder.

python
Camera.eye

Current camera position in world coordinates.

python
Camera.matrix(aspect)

Compute the view-projection matrix for the given image aspect ratio.

ParameterDefaultDescription
aspectRequiredImage width divided by height.

Returns: 4 × 4 array.

python
Camera.animate

Create a builder for orbit, zoom, and focus animations.

Returns: Animate

python
Camera.snapshot()

Capture the current state for deterministic timeline evaluation.

Returns: State dictionary.

python
Camera.restore(state)

Restore a state produced by snapshot().

ParameterDefaultDescription
stateRequiredState returned by snapshot().

Returns: None