Developer’s Guide¶
Trajectory reader implementation¶
To implement a trajectory reader, first keep in mind that a garnett trajectory is simply a sequence of frames. This means that a trajectory reader needs to generate individual instances of frames.
To implement a new reader:
- Provide a minimal sample for your format.
- Create a new module in garnett with the name yourformatreader.py.
- Specialize a frame class for your format called YourFormatFrame.
- Implement the read() method for your frame, it should return an instance of
garnett.trajectory._RawFrameData
.class YourFormatFrame(trajectory.Frame): def read(): """Read the frame data from the stream. :returns: :class:`.trajectory._RawFrameData` """
- Define a class YourFormatReader, where the constructor may take optional arguments for your reader.
- The YourFormatReader class needs to implement a read() method.
class YourFormatReader(object): def read(stream): """Read the trajectory from stream. .. code:: # pseudo-example frames = list(self.scan(stream)) return trajectory.Trajectory(frames) :stream: A file-like object. :returns: :class:`.trajectory.Trajectory` """
- Add your reader class to the __all__ directive in the garnett/reader.py module.
- Provide a unit test for your reader, that reads a sample and generates a trajectory object accordingly.
For an example, please see the GSDHOOMDFileReader
implementation.