Trajectory class

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

A Trajectory is a chemistry file on the hard drive. It is the main entry point of Chemfiles.

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

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

The specific file format 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 the Trajectory and write any buffered content to the hard drive.

nsteps

Get the number of steps (the number of frames) in a Trajectory.

path

Get the path used to open this Trajectory.

read()

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

read_step(step)

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

set_cell(cell)

Set the UnitCell associated with a Trajectory. This UnitCell will be used when reading and writing the files, replacing any UnitCell in the frames or files.

set_topology(topology, format='')

Set the Topology associated with a Trajectory. This Topology will be used when reading and writing the files, replacing any Topology in the frames or files.

If topology is a Topology instance, it is used directly. If topology 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, the code uses this file format instead of guessing it from the file extension.

write(frame)

Write a Frame to the Trajectory.