module
Chem::DCD
Overview
Implementation based on Chemfiles C++ library.
Defined in:
chem/formats/dcd.crClass Method Summary
-
.each(io : IO, & : Spatial::Positions3 -> ) : Nil
Yields each trajectory frame in io.
-
.each(path : Path | String, & : Spatial::Positions3 -> ) : Nil
Yields each trajectory frame in path.
-
.read(io : IO, info : Info, index : Int) : Spatial::Positions3
Returns the trajectory frame at index from io.
-
.read(io : IO, info : Info) : Spatial::Positions3
Returns the next trajectory frame from io.
-
.read_all(io : IO) : Array(Spatial::Positions3)
Returns all trajectory frames in io.
-
.read_all(path : Path | String) : Array(Spatial::Positions3)
Returns all trajectory frames in path.
-
.read_info(io : IO) : Info
Returns the info from io.
-
.write(io : IO, frame : Spatial::Positions3, buffer : Slice(Float32) = Slice(Float32).new(frame.size)) : Nil
Writes a trajectory frame to io.
-
.write(io : IO, frames : Indexable(Spatial::Positions3), title : String | Nil = nil) : Nil
Writes trajectory frames to io.
-
.write(io : IO, frames : Enumerable(Spatial::Positions3), title : String | Nil = nil) : Nil
Writes trajectory frames to io.
-
.write(path : Path | String, frames : Indexable(Spatial::Positions3), title : String | Nil = nil) : Nil
Writes trajectory frames to path.
-
.write(path : Path | String, frames : Enumerable(Spatial::Positions3), title : String | Nil = nil) : Nil
Writes trajectory frames to path.
-
.write_info(io : IO, n_frames : Int32, n_atoms : Int32, periodic : Bool = true, title : String | Nil = nil) : Nil
Writes the DCD header to io.
Class Method Detail
Yields each trajectory frame in path.
Returns the trajectory frame at index from io.
Raises IndexError if the index is out of bounds.
NOTE io must be seekable.
Returns the next trajectory frame from io.
Use .read_all or .each for multiple.
NOTE io must be seekable.
Returns all trajectory frames in io.
NOTE io must be seekable.
Returns all trajectory frames in path.
NOTE path must be seekable.
Returns the info from io.
It must called at the beginning of the DCD content and before reading frames via .read.
NOTE io must be seekable.
Writes a trajectory frame to io.
The DCD must be initialized before writing frames, otherwise it will raise ArgumentError.
See .write_info for more details or .write(io, frames, title) for writing multiple frames.
buffer may be used to avoid allocating a new slice for each frame.
It must be pre-allocated with the correct size.
Raises ArgumentError if the frame is empty or the buffer size is different from the frame size.
NOTE It does not check the written info, so the frame size must match the number of atoms and the periodic flag must be set correctly in the header.
WARNING The unit cell must be aligned to the XY plane, otherwise the atom coordinates might be misaligned.
Writes trajectory frames to io.
This method is equivalent to calling .write_info and then .write(io, frame, buffer) for each frame.
If passed, title will be stored in the file info.
It reuses the same buffer for all frames to avoid allocating a new slice for each frame.
Writes trajectory frames to io.
This method is equivalent to calling .write_info and then .write(io, frame, buffer) for each frame.
If passed, title will be stored in the file info.
It reuses the same buffer for all frames to avoid allocating a new slice for each frame.
This is a generic implementation that works for any Enumerable, but it's less efficient than the indexable version. It writes the number of frames (initially set to 0) in the header after writing all frames so it will fail for non-seekable IO.
Writes trajectory frames to path.
This method is equivalent to calling .write_info and then .write(io, frame, buffer) for each frame.
If passed, title will be stored in the file info.
It reuses the same buffer for all frames to avoid allocating a new slice for each frame.
Writes trajectory frames to path.
This method is equivalent to calling .write_info and then .write(io, frame, buffer) for each frame.
If passed, title will be stored in the file info.
It reuses the same buffer for all frames to avoid allocating a new slice for each frame.
This is a generic implementation that works for any Enumerable, but it's less efficient than the indexable version. It writes the number of frames (initially set to 0) in the header after writing all frames so it will fail for non-seekable IO.
Writes the DCD header to io. Must be called before writing frames.
periodic indicates if the unit cell will be written for each frame. If true, all frames must have a unit cell.