LammpsIO module¶
LammpsIO Created on 21 September 2018 @author: Robert Ivancic
This module was created to facilitate input and output of LAMMPS trajectory files in dump and netCDF (AMBER) format.
Notes
We plan to add a log reading functionality to this module soon.
-
class
LammpsIO.
DumpIO
[source]¶ Input and output LAMMPS trajectories in dump (lammpstrj) format.
This class inputs and outputs frames of a LAMMPS trajectory. It does this sequentially, i.e. it reads (writes) in a single frame of a dump (lammpstrj) trajectory at a time starting at frame 0. This approach has two benefits to reading in an entire trajectory at once both steming from the fact that it is more memory efficient. First (and most importantly), python has memory limits that are easily reached if the number of particles times the number of frames loaded in at one time is greater than 25,000,000. Practically, it is very easy to hit this limit when running large or long time simulations. Second, this approach is generally faster than loading in all frames at once as it requires much less time to allocate memory.
-
GetBB
()[source]¶ Gets box boundary (BB) of current frame. These are formatted as [low_x, high_x] for each dimension.
Returns: bb_t – box boundaries of current frame Return type: numpy array (dimension,2)
-
GetDataCol
(label)[source]¶ Gets data column of current frame
A data column is a way of storing values that are associated with every particle in a simulation or experiment at every timestep. Examples include: J2, D2min, p_{hop}, or softness of every particle at every timestep. This gets a data column for the current frame in the dump file.
Parameters: label (str) – name of data column label Returns: id_t – particle ids of each particle of current frame Return type: numpy array (number of particles,)
-
GetID
()[source]¶ Gets particle ids of current frame
Returns: id_t – particle ids of each particle of current frame Return type: numpy array (number of particles,)
-
GetPos
()[source]¶ Gets particle positions (coordinates) of current frame
Returns: pos_t – particle positions (coordinates) of each particle of current frame Return type: numpy array (number of particles, dimension)
-
Gett
()[source]¶ Gets timestep t of current frame.
Returns: t – timestep of the current frame. Return type: int
-
LoadNextFrame
()[source]¶ Loads next frame in the dump (lammpstrj) file.
Reads all timestep, box boundary, particle id, particle position, and data column information given in frame to file. Must use OpenI before use. Get functions may be used after this function.
-
NumDims
()[source]¶ Outputs number of dimensions of current simulation being read.
Returns: d – Number of dimensions of simulation you are reading. Return type: int
-
NumFrames
()[source]¶ Outputs number of frames of current simulation being read.
Returns: n_f – Number of frames of the simulation you are reading. Return type: int
-
NumPartsCurrentf
()[source]¶ Outputs number of particles in current frame.
Returns: n_p – Number of particles in the current frame. Return type: int Warning
If used without loading any frames, gives number of particles of first frame.
-
OpenI
(dump_file_name)[source]¶ Opens lammpstrj file for input
Opens a dump (lammpstrj) file of name dump_file_name for reading (input)
-
OpenO
(dump_file_name)[source]¶ Opens dump file for output.
Opens a dump (lammpstrj) file of name dumpe_file_name for writing (output).
-
SetBB
(bb_t)[source]¶ Sets box boundaries (BB) of current frame
Parameters: bb_t (numpy array (dimension,2)) – box boundaries of current frame
-
SetDataCol
(label, data_col_t)[source]¶ Sets particle positions of current frame
Parameters: - label (str) – name of the data column
- data_col_t (numpy array (number of particles,)) – particle positions (coordinates) of current frame in order of id_t
-
SetID
(id_t)[source]¶ Sets particle ids of current frame
Parameters: id_t (numpy array (number of particles,)) – particle ids of each particle of current frame
-
SetPos
(pos_t)[source]¶ Sets particle positions of current frame
Parameters: pos_t (numpy array (number of particles, dimensions)) – particle positions (coordinates) of current frame in order of id_t
-
SortByID
()[source]¶ Sorts particles of all arrays by their id
Sorts pos_t, id_t, and data_col_t arrays so that id_t = range(n_p)
-
WriteNextFrame
()[source]¶ Writes the next frame to the dump file.
Writes all timestep, box boundary, particle id, particle position, and data column information given in frame to file. Must use OpenO and Set functions before use.
Warning
Will run without having set particle ids. Assumes particles in order from 1,…,(number of particles).
-
-
class
LammpsIO.
NetCDFIO
[source]¶ Input and output of LAMMPS trajectories in NetCDF (AMBER).
This class inputs and outputs individual frames from an AMBER format molecular dynamics trajectory. More on AMBER can be found here: http://ambermd.org/netcdf/nctraj.xhtml. More on NetCDF can be found here: https://en.wikipedia.org/wiki/NetCDF. There are two major advantages to this output format over standard dump files. First, these files are in binary format and thus, use about 1/3 of the space of standard dump files. Second, reading standard dump files must be done sequentially. With NetCDF you may obtain data from any frame of interest f instantly by simply selecting that frame in the data array. The major disadvantage of this format is that it assumes a constant number of particles throughout a simulation or experiment. Particles are assumed to be ordered by their ids.
-
GetBB
(f)[source]¶ Gets box boundaries (BB) of frame f. These are formatted as [low_x, high_x] for each dimension.
Parameters: f (int) – frame number Returns: bb_t – box boundaries at time t Return type: numpy array (dimension,2)
-
GetDataCol
(f, label)[source]¶ Sets a data column at frame f
A data column is a way of storing values that are associated with every particle in a simulation or experiment at every timestep. Examples include: J2, D2min, p_{hop}, or softness of every particle at every timestep. This gets a data column for time t.
Parameters: - f (int) – frame number
- label (str) – data column name
Returns: data_col_t – data column values for all particles at frame f
Return type: numpy array (number of particles,)
-
GetPos
(f)[source]¶ Gets particle positions (coordinates) at frame f
Parameters: f (int) – frame number Returns: pos_t – particle positions (coordinates) at frame f Return type: numpy array (number of particles, dimension)
-
Gett
(f)[source]¶ Gets timestep t of frame f
Parameters: f (int) – frame number Returns: t Return type: int
-
NumDims
()[source]¶ Outputs number of dimensions of current simulation being read.
Returns: d – Number of dimensions of simulation you are reading. Return type: int
-
NumFrames
()[source]¶ Outputs number of frames of current simulation being read.
Returns: n_f – Number of frames of simulation you are reading. Return type: int
-
NumParts
()[source]¶ Outputs number of particles of current simulation being read.
Returns: n_p – Number of particles of simulation you are reading. Return type: int
-
OpenI
(nc_file_name)[source]¶ Opens NetCDF file for input.
Opens a NetCDF file of nc_file_name for reading (input).
Parameters: nc_file_name (str) – Name of netCDF file you wish to read from.
-
OpenO
(nc_file_name)[source]¶ Opens NetCDF file for output.
Opens a NetCDF file of nc_file_name for writing (output).
Parameters: nc_file_name (str) – Name of netCDF file you wish to write to.
-
SetBB
(f, bb_t)[source]¶ Sets box boundaries of frame f. These are formatted as [low_x, high_x] for each dimension.
Parameters: - f (int) – frame number
- bb_t (numpy array (dimension,2)) – box boundaries at time t
-
SetDataCol
(f, label, data_col_t)[source]¶ Sets a data column at frame f
A data column is a way of storing values that are associated with every particle in a simulation or experiment at every timestep. Examples include: J2, D2min, p_{hop}, or softness of every particle at every timestep. This sets a data column for time t.
Parameters: - f (int) – frame number
- label (str) – data column name
- data_col_t (numpy array (number of particles,)) – data column values for all particles at frame f
-