# Trajectory¶

class chemfiles::Trajectory

A Trajectory is a chemistry file on the hard drive. It is the entry point of the chemfiles library.

A Trajectory is made with a File and a Format. The File implements all the physical operations, while the Format provides a way to interpret the file.

Public Functions

Trajectory(const std::string &filename, char mode = 'r', const std::string &format = "")

Open a file, automatically gessing the file format and type from the extension.

Parameters
• filename: The file path. In w or a modes, the file is created if it does not exist yet. In r mode, an exception is thrown is the file does not exist yet.
• mode: Opening mode for the file. Default mode is r for read. Other supported modes depends on the underlying format and are w for write, and a for append. w mode discard any previously existing file.
• format: Specific format to use. Needed when there is no way to guess the format from the extension of the file, or when this guess would be wrong.

Frame read()

Read the next frame in the trajectory.

Frame read_step(const size_t step)

Read a single frame at specific step from the trajectory.

void write(const Frame &frame)

Write a single frame to the trajectory.

void set_topology(const Topology &top)

Set the Topology of all the Frame read or written to topology. This replace any topology in the file being read, or in the Frame being written.

void set_topology(const std::string &filename, const std::string &format = "")

Use the Topology of the first Frame of the following file as Topology for all the Frame read or written. This replace any topology in the file being read, or in the Frame being written. The optional parameter format can be used to specify the topology file format.

void set_cell(const UnitCell &new_cell)

Set the unit cell of all the Frame read or written to cell. This replace any cell in the file being read, or in the Frame being written.

size_t nsteps() const

Get the number of steps (the number of Frames) in this trajectory.

bool done() const

Have we read all the Frames in this file ?