Reference navigation
On this page
CLASS · v0.9.1
Trajectory
A random-access sequence of coordinate frames in ångströms.
from proteinmotion import TrajectoryConstructor
Trajectory(frames, *, topology=None, units='angstrom')Parameters
| Parameter | Default | Description |
|---|---|---|
frames | Required | Array or random-access sequence with shape (states, atoms, 3). |
topologykeyword only | None | Atom 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
| Name | Description |
|---|---|
topology | Optional Topology shared by all frames. |
n_atoms | Number 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.
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)PDB 2K39 models 1–3. Interpolation shows structural variation.
Methods and properties
| Name | Description |
|---|---|
| __len__()method | Return the number of frames with len(trajectory). |
| frame()method | Read a single coordinate frame. |
| from_npy()class method | Open a NumPy trajectory using memory mapping. |
| from_mdanalysis()class method | Read MD formats lazily with MDAnalysis. Requires the md extra. |
| aligned()method | Create a trajectory that removes rigid translation and rotation from each frame. |
Trajectory.__len__()Return the number of frames with len(trajectory).
Returns: int
Trajectory.frame(index)Read a single coordinate frame.
| Parameter | Default | Description |
|---|---|---|
index | Required | Zero-based frame index. |
Returns: float32 array with shape (atoms, 3), in ångströms.
Trajectory.from_npy(path, *, topology=None, units='angstrom')Open a NumPy trajectory using memory mapping.
| Parameter | Default | Description |
|---|---|---|
path | Required | Input or output file path, as specified by the operation. |
topologykeyword only | None | Atom 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
Trajectory.from_mdanalysis(
topology_file,
trajectory_file,
*,
selection='protein',
stride=1,
)Read MD formats lazily with MDAnalysis. Requires the md extra.
| Parameter | Default | Description |
|---|---|---|
topology_file | Required | Topology file accepted by MDAnalysis. |
trajectory_file | Required | Coordinate trajectory file accepted by MDAnalysis. |
selectionkeyword only | 'protein' | MDAnalysis atom selection expression. |
stridekeyword only | 1 | Read every nth frame; a positive integer. |
Returns: Trajectory
Preprocess periodic boundaries before loading. Selected atoms must be grouped by residue.
Trajectory.aligned(reference=None, *, indices=None)Create a trajectory that removes rigid translation and rotation from each frame.
| Parameter | Default | Description |
|---|---|---|
reference | None | Reference coordinates for alignment; None uses the first frame. |
indiceskeyword only | None | Atom indices used for the rigid fit; None uses all atoms. |
Returns: Trajectory