ProteinMotion
Reference navigation
On this page

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.
lens_focus()methodSet lens focus without changing framing.
composition_offset()methodWorld offset placing the subject at a normalized top-left screen position.
focus_pointpropertyCurrent lens target in world ångströms, following the selected atoms.
cutaway_geometry()methodCenter, kept radius, window radius and outer-surface distance of the open cutaway. The outer distance is measured from the target center along the tunnel axis, to where the tunnel's centerline first reaches open space: atoms of the target's protein within 6 Å of the axis, up to the first gap longer than 8 Å. None when no cutaway is open. The fifth value is that unit axis in world coordinates: toward the eye for a cone, or the tunnel direction.
clearest_view()methodReturn (theta, phi) with the fewest atoms between the camera and ``region``. Counts atoms of ``objects`` (default: the region's protein) that project inside the region's silhouette and lie in front of it, from the current distance. Nearby views win ties through ``turn_penalty``, a fractional cost per radian of camera turn. It also decides between views with no atoms in front, so the nearest clear view wins.
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.
look_along()methodTurn the view to look down an axis, which then points toward the viewer.
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.lens_focus(target, *, fstop=5.6, follow=True)

Set lens focus without changing framing.

ParameterDefaultDescription
targetRequiredObject to animate or use as a destination. The supported object type depends on the operation.
fstopkeyword only5.6Lens f-number. Lower values produce a shallower depth of field. Must be positive.
followkeyword onlyTrueTrack the selection’s center after the focus completes.
python
Camera.composition_offset(screen_position=None, *, distance=None, aspect=None)

World offset placing the subject at a normalized top-left screen position.

ParameterDefaultDescription
screen_positionNoneNormalized subject position; (0, 0) is top-left and (1, 1) bottom-right.
distancekeyword onlyNoneDistance in ångströms.
aspectkeyword onlyNoneImage width divided by height.
python
Camera.focus_point

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

python
Camera.cutaway_geometry()

Center, kept radius, window radius and outer-surface distance of the open cutaway. The outer distance is measured from the target center along the tunnel axis, to where the tunnel's centerline first reaches open space: atoms of the target's protein within 6 Å of the axis, up to the first gap longer than 8 Å. None when no cutaway is open. The fifth value is that unit axis in world coordinates: toward the eye for a cone, or the tunnel direction.

python
Camera.clearest_view(region, *objects, samples=160, max_elevation=1.1, turn_penalty=0.15)

Return (theta, phi) with the fewest atoms between the camera and ``region``. Counts atoms of ``objects`` (default: the region's protein) that project inside the region's silhouette and lie in front of it, from the current distance. Nearby views win ties through ``turn_penalty``, a fractional cost per radian of camera turn. It also decides between views with no atoms in front, so the nearest clear view wins.

ParameterDefaultDescription
regionRequiredRegion selection attached to a protein.
*objects—Proteins whose atoms can block the view; defaults to the region's protein.
sampleskeyword only160Samples per density-slice axis; preferred over legacy resolution.
max_elevationkeyword only1.1Largest camera elevation to consider, in radians.
turn_penaltykeyword only0.15Fractional cost per radian of camera turn, which favors nearby views.
python
Camera.frame(*proteins, margin=1.25, aspect=None, screen_position=(0.5, 0.5))

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

ParameterDefaultDescription
*proteins—Protein or annotation objects to add or render.
marginkeyword only1.25Positive framing margin; larger values leave more space around the target.
aspectkeyword onlyNoneImage width divided by height.
screen_positionkeyword only(0.5, 0.5)Normalized subject position; (0, 0) is top-left and (1, 1) bottom-right.

Returns: The camera.

python
Camera.focus(
    target,
    *,
    margin=1.25,
    aspect=None,
    follow=True,
    screen_position=(0.5, 0.5),
)

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 onlyNoneImage width divided by height.
followkeyword onlyTrueTrack 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.

Returns: The camera.

python
Camera.update_tracking()

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

Returns: None

python
Camera.look_along(axis, protein=None)

Turn the view to look down an axis, which then points toward the viewer.

ParameterDefaultDescription
axisRequiredDirection in world coordinates, or in the protein's model frame when protein is given.
proteinNoneProtein whose orientation converts a model-frame axis, such as a DomainMotion axis.
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