IO¶
A module containing FILE-IO related for simlammps
Classes
read_data_file(filename[, atom_style]) |
Reads LAMMPS data file and create CUDS objects |
LammpsDataFileParser(handler) |
Class parses Lammps data file (produced by lammps command write_data) and calls a handler which processes the parsed information. |
LammpsSimpleDataHandler() |
Class to handle what is parsed by LammpsDataFileParser |
LammpsDataLineInterpreter(atom_style) |
Class interprets lines in LAMMPS data files using atom-style |
LammpsProcess([lammps_name, log_directory]) |
Class runs the lammps/liggghts program |
Implementation
-
simlammps.io.file_utility.read_data_file(filename, atom_style=None)¶ Reads LAMMPS data file and create CUDS objects
Reads LAMMPS data file and create list of Particles. The returned list of Particles will contain a Particles for each atom type (i.e. CUBA.MATERIAL_TYPE). The name of the Particles will be the atom type (e.g. a Particles with atom_type/CUBA.MATERIAL_TYPE of 1 will have the name “1”)
The attributes for each particle are based upon what atom-style the file contains (i.e. “sphere” means that particles in addition to having CUBA.VELOCITY will also have a CUBA.RADIUS and CUBA.MASS). See ‘atom_style’ for more details.
Parameters: - filename (str) – filename of lammps data file
- atom_style (AtomStyle) – type of atoms in the file. If None, then an attempt of interpreting the atom-style in the file is performed.
Returns: particles_list – list of Particles where each Particles has a name equal to their CUBA.MATERIAL_TYPE and is filled up with particles of that type.
Return type: list of Particles
-
simlammps.io.file_utility.write_data_file(filename, particles_list, atom_style=<AtomStyle.ATOMIC: 0>)¶ Writes LAMMPS data file from CUDS objects
Writes LAMMPS data file from a list of Particles.
The particles will be annotated with their Simphony-uid. For example:
10 1 17 -1.0 10.0 5.0 6.0 # particles_name:'foo' uid:'40fb302c-6e71-11e5-b35f-08606e7c2200' # noqa
Parameters: - filename (str) – filename of lammps data file
- particles_list (iterable of Particles) – particles
- atom_style (AtomStyle) – type of atoms to be written to file
-
class
simlammps.io.lammps_data_file_parser.LammpsDataFileParser(handler)¶ Bases:
objectClass parses Lammps data file (produced by lammps command write_data) and calls a handler which processes the parsed information.
A handler class is given the parsed information. This handler class can then determine what it is does with it. For, example it could just store the data in memory (see LammpsSimpleDataHandler) or write it some other data file (e.g. a CUDS-file).
- Handler classes have the following methods:
- def process_number_atom_types(self, number_types): def process_atoms(self, id, values): def process_masses(self, id, value): def process_velocities(self, id, values): def process_box_origin(self, values): def process_box_vectors(self, values): def process_atom_type(self, atom_type)
Parameters: handler – handler will handle the parsed information provided by this class -
parse(file_name)¶ Read in data file containing current state of simulation
-
class
simlammps.io.lammps_data_file_parser.SimulationBoxParser(handler)¶ Bases:
objectClasses parses lines related to simulation box
parses lines related to simulation box and then calls the related handler methods when enough information is read (i.e. all related lines in file have been read)
- The relevant lines have the form:
- 0.0000000000000000e+00 2.5687134504920127e+01 xlo xhi -2.2245711031688635e-03 2.2247935602791809e+01 ylo yhi -3.2108918131150160e-01 3.2108918131150160e-01 zlo zhi
Once all needed information is parsed, then the “handler“‘s process_box_vectors is called.
Parameters: handler – handler’s ‘process_box_vectors’ and ‘process_box_origin’ methods will be called once the required information has been parsed -
parse(line)¶
-
class
simlammps.io.lammps_simple_data_handler.LammpsSimpleDataHandler¶ Bases:
objectClass to handle what is parsed by LammpsDataFileParser
Class just stores the parsed data and provides methods to retrieve this data
-
begin()¶ Handle begin of file parsing
-
end()¶ Handle end of file parsing
-
get_atom_type()¶ Returns atom type
Returns: atom_type – Atom type. None if atom type is not known Return type: string
-
get_atoms()¶
-
get_box_origin()¶
-
get_box_vectors()¶
-
get_masses()¶
-
get_number_atom_types()¶
-
get_velocities()¶
-
process_atom_type(atom_type)¶
-
process_atoms(id, values)¶
-
process_box_origin(values)¶
-
process_box_vectors(values)¶
-
process_masses(id, value)¶
-
process_number_atom_types(number_types)¶
-
process_velocities(id, values)¶
-
-
class
simlammps.io.lammps_data_line_interpreter.LammpsDataLineInterpreter(atom_style)¶ Bases:
objectClass interprets lines in LAMMPS data files using atom-style
Lines should be interpreted differently based upon their atom style. For example, sphere atom style:
Atoms # sphere 1 1 0.5 1.0000000000000000e+00 -5.0 0.0 0.0000000000000000e+00 0 0 0 2 1 0.5 1.0000000000000000e+00 10.0 0.0 0.0000000000000000e+00 0 0 0
The “sphere” atom style is interpreted as:
atom-ID atom-type diameter mass x y z
While “atomic” atom style:
Atoms # atomic 1 3 1.00000000000000e+00 1.0000000000000e+00 1.00000000000000e+00 0 0 0 2 1 2.00000000000000e+00 2.0000000000000e+00 2.0000000000000e+00 0 0 0
is interpreted as:
atom-ID atom-type x y z
Note that the last 3 values were not discussed because in the lammps documentation, it is noted that “each line can optionally have 3 flags (nx,ny,nz) appended to it, which indicate which image of a periodic simulation box the atom is in”
Parameters: atom_style (AtomStyle) – style that lammps is using for “atoms” -
convert_atom_values(values)¶ Converts list of values to CUBA/value dictionary
Parameters: - values (iterable of numbers) – numbers read from line in atom section of LAMMPS data file
- Returns –
- -------- –
- coordinates ((float, float, float)) – x-y-z coordinates
- cuba_values (dict) – dictionary with CUBA keys/values
-
convert_velocity_values(values)¶ Converts list of velocity values to CUBA/value dictionary
Parameters: - values (iterable of numbers) – numbers read from line in velocity section of LAMMPS data file
- Returns –
- -------- –
- cuba_velocity_values (dict) – dictionary with CUBA keys/values (related to velocity)
-
static
process_value(value_info, values, index)¶ return cuba value and updated index
Parameters: - value_info (ValueInfo) – information on value info
- values (list of numbers) – values to be processed
- index (int) – starting index of values to be processed
- Returns –
- -------- –
- cuba_value (CUBA) – value in correct cuba form (e.g. type)
- index – incremented index (i.e. incremented pass this value)
-
LAMMPS Process
This module provides a way to run the lammps or liggghts process
-
class
simlammps.io.lammps_process.LammpsProcess(lammps_name='lammps', log_directory=None)¶ Bases:
objectClass runs the lammps/liggghts program
Parameters: - lammps_name (str) – name of LAMMPS executable
- log_directory (str, optional) – name of directory of log file (‘log.lammps’) for lammps. If not given, then pwd is where ‘log.lammps’ will be written.
Raises: RuntimeError– if Lammps did not run correctly