ProteinMotion
Reference navigation
On this page

CLASS · v0.9.1

Trajectory

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

python
from proteinmotion import Trajectory

Constructor

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

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.

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
__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()methodCreate a trajectory that removes rigid translation and rotation from each frame.
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')

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.

Returns: Trajectory

python
Trajectory.from_mdanalysis(
    topology_file,
    trajectory_file,
    *,
    selection='protein',
    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'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)

Create a trajectory that removes rigid translation and rotation from each frame.

ParameterDefaultDescription
referenceNoneReference coordinates for alignment; None uses the first frame.
indiceskeyword onlyNoneAtom indices used for the rigid fit; None uses all atoms.

Returns: Trajectory