sportran.i_o.read_lammps_log.LAMMPSLogFile

class sportran.i_o.read_lammps_log.LAMMPSLogFile(data_file, run_keyword=None, select_ckeys=None, **kwargs)

Bases: object

A package that reads a LAMMPS Log file and organizes it into a dictionary according to the column headers. LAMMPS-style vector variables header are grouped together (only if group_vector = True). If the name starts with “c_” or “v_”, this is stripped away.

e.g. c_flux[0] c_flux[1] c_flux[2] –> placed in ‘flux0’ key

The output of a specific run command is identified by a string ‘run_keyword’. When this keyword is found the next output block is read (it is supposed to begin with a ‘Step’ in the first column). The reading stops when and ‘end_keyword’ is found (default: ‘Loop time’).

Lines are read SEQUENTIALLY with the method read_datalines. If a start_step is not specified the file is read from the current position. This allows one to read the file in blocks.

Example of LAMMPS Log file:

fix NVE all nve # PRODUCTION RUN run 1000 Per MPI rank memory allocation (min/avg/max) = 4.45 | 4.456 | 4.458 Mbytes … … Step Temp TotEng Press c_flux[1] c_flux[2] c_flux[3] c_stress[1] c_stress[2] 0 257.6477 -1085.7346 -1944.803 -129.20254 124.70804 -200.42864 -64.236389 -134.0399 1 247.37505 -1085.734 -1909.333 -133.77141 124.25897 -103.27461 -61.022597 -83.17237 2 238.37359 -1087.9214 -1874.56 -138.58616 115.84038 -5.7728078 -58.471318 -74.51758 … Loop time of 110.158 on 20 procs for 400000 steps with 1728 atoms

Example script:

jfile = LAMMPSLogFile(data_file, run_keyword=’PRODUCTION RUN’) jfile.read_datalines(NSTEPS=100, start_step=0, select_ckeys=[‘Step’, ‘Temp’, ‘flux’]) print(jfile.data)

# to save data into a Numpy binary file: # ‘lammps.data’ is a LAMMPS data file containing the structure, where the cell information can be retrieved jfile.save_numpy_dict(‘flux.npy’, [‘flux’], ‘lammps.data’)

__init__(data_file, run_keyword=None, select_ckeys=None, **kwargs)

LAMMPSLogFile(data_file, run_keyword, select_ckeys, **kwargs)

**kwargs:

endrun_keyword [default: ‘Loop time’] group_vectores [default: True] GUI [default: False]

Methods

__init__(data_file[, run_keyword, select_ckeys])

LAMMPSLogFile(data_file, run_keyword, select_ckeys, **kwargs)

gotostep(start_step)

Go to the start_step-th line in the time series (assumes step=1).

read_datalines([NSTEPS, start_step, ...])

Read NSTEPS steps of file, starting from start_step, and store only the selected ckeys.

save_numpy_dict(out_file[, select_ckeys, ...])

Export LAMMPSLogFile to Numpy binary format.

gotostep(start_step)
Go to the start_step-th line in the time series (assumes step=1).
start_step = -1 –> ignore, continue from current step

0 –> go to start step N –> go to N-th step

read_datalines(NSTEPS=0, start_step=- 1, select_ckeys=None, max_vector_dim=None, even_NSTEPS=True)

Read NSTEPS steps of file, starting from start_step, and store only the selected ckeys.

INPUT:

NSTEPS -> number of steps to read (default: 0 -> reads all the file) start_step = -1 -> continue from current step (default)

0 -> go to start step N -> go to N-th step

select_ckeys -> an array with the column keys you want to read (see all_ckeys for a list, default: all) max_vector_dim -> when reading vectors read only this number of components (None = read all components) even_NSTEPS -> round the number of steps to an even number (default: True)

OUTPUT:

data -> a dictionary with the selected-column steps

save_numpy_dict(out_file, select_ckeys=None, lammps_data_file=None)

Export LAMMPSLogFile to Numpy binary format.