Trajectory class

class chemfiles.Trajectory(path, mode='r', format='')

A Trajectory represent a physical file from which we can read Frame.

Open the file at the given path using the given mode and optional file format.

Valid modes are 'r' for read, 'w' for write and 'a' for append.

The format parameter is needed when the file format does not match the extension, or when there is not standard extension for this format. If format is an empty string, the format will be guessed from the file extension.

close()

Close this Trajectory and write any buffered content to the file.

property nsteps

Get the current number of steps in this Trajectory.

property path

Get the path used to open this Trajectory.

read()

Read the next step of this Trajectory and return the corresponding Frame.

read_step(step)

Read a specific step in this Trajectory and return the corresponding Frame.

set_cell(cell)

Set the UnitCell associated with this Trajectory to a copy of cell.

This UnitCell will be used when reading and writing the files, replacing any unit cell in the frames or files.

set_topology(topology, format='')

Set the Topology associated with this Trajectory.

The new topology will be used when reading and writing the files, replacing any topology in the frames or files.

If the topology parameter is a Topology instance, it is used directly. If the topology parameter is a string, the first Frame of the corresponding file is read, and the topology of this frame is used.

When reading from a file, if format is not the empty string, it is used as the file format instead of guessing it from the file extension.

write(frame)

Write a Frame to this Trajectory.