ProteinMotion
Reference navigation
On this page

Trajectory

A random-access sequence of coordinate frames in ångströms.

python
from proteinmotion import Trajectory

Constructor

python
Trajectory(frames, *, topology=None, units='angstrom', times=None, time_unit='ps')

Parameters

ParameterDefaultDescription
framesRequiredArray or random-access sequence with shape (states, atoms, 3).
topologykeyword onlyNoneAtom identities, residues, bonds, and chains in a Topology object.
unitskeyword only'angstrom'Input coordinate units: "angstrom" or "nm". Frames are returned in ångströms.
timeskeyword onlyNoneStrictly increasing finite x coordinates, one for each value.
time_unitkeyword only'ps'Physical timestamp unit label, e.g. ps or ns. Does not rescale supplied times.

Notes

All frames must have the same atom count and order. len(trajectory) gives the frame count. Input nanometer coordinates are converted to ångströms when read.

Attributes

NameDescription
topologyOptional Topology shared by all frames.
n_atomsNumber of atoms per frame.

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
loaded = Protein.from_file(DATA / "2k39.cif", chains="A")
core = loaded.select(residues=(1, 70), atoms="CA")
aligned = loaded.trajectory.aligned(indices=core.atom_indices)
p = Protein.from_trajectory(aligned).cartoon().center()
frame(self, p)
self.play(
    PlayTrajectory(p, start=0, end=2, state_easing=smooth),
    run_time=6,
)
self.wait(0.5)
Output Preview · 6.5 s · 60 fps
NMR state playback

PDB 2K39 models 1–3. Interpolation shows structural variation.

Methods and properties

NameDescription
timespropertyPhysical timestamps, or None when the input has no physical clock.
__len__()methodReturn the number of frames with len(trajectory).
frame()methodRead a single coordinate frame.
from_npy()class methodOpen a NumPy trajectory using memory mapping.
from_mdanalysis()class methodRead MD formats lazily with MDAnalysis. Requires the md extra.
aligned()methodReturn an aligned trajectory, preserving physical timestamps.
python
Trajectory.times

Physical timestamps, or None when the input has no physical clock.

python
Trajectory.__len__()

Return the number of frames with len(trajectory).

Returns: int

python
Trajectory.frame(index)

Read a single coordinate frame.

ParameterDefaultDescription
indexRequiredZero-based frame index.

Returns: float32 array with shape (atoms, 3), in ångströms.

python
Trajectory.from_npy(path, *, topology=None, units='angstrom', times=None, time_unit='ps')

Open a NumPy trajectory using memory mapping.

ParameterDefaultDescription
pathRequiredInput or output file path, as specified by the operation.
topologykeyword onlyNoneAtom identities, residues, bonds, and chains in a Topology object.
unitskeyword only'angstrom'Input coordinate units: "angstrom" or "nm". Frames are returned in ångströms.
timeskeyword onlyNoneStrictly increasing finite x coordinates, one for each value.
time_unitkeyword only'ps'Physical timestamp unit label, e.g. ps or ns. Does not rescale supplied times.

Returns: Trajectory

python
Trajectory.from_mdanalysis(
    topology_file,
    trajectory_file,
    *,
    selection='protein or nucleic',
    stride=1,
)

Read MD formats lazily with MDAnalysis. Requires the md extra.

ParameterDefaultDescription
topology_fileRequiredTopology file accepted by MDAnalysis.
trajectory_fileRequiredCoordinate trajectory file accepted by MDAnalysis.
selectionkeyword only'protein or nucleic'MDAnalysis atom selection expression.
stridekeyword only1Read every nth frame; a positive integer.

Returns: Trajectory

Preprocess periodic boundaries before loading. Selected atoms must be grouped by residue.

python
Trajectory.aligned(reference=None, *, indices=None, selection=None)

Return an aligned trajectory, preserving physical timestamps.

ParameterDefaultDescription
referenceNoneReference coordinates for alignment; None uses the first frame.
indiceskeyword onlyNoneAtom indices used for the rigid fit; None uses all atoms.
selectionkeyword onlyNoneRegion with at least three anchor atoms matching this trajectory topology; use instead of indices.

Returns: Trajectory