Data File classes¶
SimpleDataFile¶
Class to handle simple data files, aka cvs files.
-
class
pylam.SimpleDataFile(filename, header_prefix='#', delimiter=None)[source]¶ Bases:
pylam.base.IndexedFileClass for a simple (csv) data file with an optional header line.
Parameters: - filename (str) – file name
- header_prefix (str) – prefix of header line (default:
#) - delimiter (str) – string used to separate values (default: any whitespace)
Returns: simple data file object
Return type: -
getRows(startRowIndex, endRowIndex)[source]¶ Returns a part of the file as a numpy array.
Parameters: - startRowIndex (int) – index of first data row
- endRowIndex (int) – index of last data row (included!)
Returns: data
Return type: numpy.ndarray
-
getRow(rowIndex)[source]¶ Returns the data in row with index (0,1,..) as a numpy array.
Parameters: rowIndex (int) – index of data row in file Returns: data Return type: numpy.ndarray
-
getCol(idx)[source]¶ Returns a whole column as a np.ndarray.
Parameters: idx (int) – column index Returns: column data Return type: np.ndarray
-
data¶ Returns: the whole data Return type: numpy.ndarray
-
header¶ Returns: the header line as list Return type: list
-
properHeader¶ Returns: tests if a proper header is defined Return type: bool
-
info()[source]¶ Prints debug info to screen, e.g.:
file name : example_data_files/simple.dat data header : ['Chunk', 'Coord1', 'Ncount', 'v_temp'] number of lines : 491
-
columnName2Index(name)[source]¶ Returns the column index for a given name as defined in the header. Therefore
pylam.SimpleDataFile.properHeadermust be True.Parameters: name (str) – column name Returns: column index Return type: int
FixBlockFile¶
-
class
pylam.FixBlockFile(filename)[source]¶ Bases:
pylam.base.BlockFileClass for LAMMPS fix data files.
Parameters: filename (str) – file name Returns: fix block data file object Return type: FixBlockFile -
blockClass¶ Block class which is attached, here:
pylam.DataBlockalias of
FixBlock
-
aveBlocks(bids)[source]¶ Average over blocks.
Parameters: bids (list) – list of block ids to use for average Returns: numpy array containing the ‘average block’ Return type: numpy.ndarray
-
info()[source]¶ Prints debug info to screen, e.g.:
file name : example_data_files/chunk1D.dat title : Chunk-averaged data for fix TPROFILE and group all data type : Chunk-averaged block header : ['Timestep', 'Number-of-chunks', 'Total-count'] data header : ['Chunk', 'Coord1', 'Ncount', 'v_temp'] block size : 121 number of lines : 491 number of blocks : 4 multi : True
-
columnName2Index(name)[source]¶ The index of the column with a given name.
Parameters: name (str) – name of the column (property) Returns: index of the column Return type: int
-
blocks2cols(colname, fix=[])[source]¶ Extracts a selected column (property) from a each block and combines them.
For example, if
chunk1D.datlooks like:# Chunk-averaged data for fix TPROFILE and group all # Timestep Number-of-chunks Total-count # Chunk Coord1 Ncount v_temp 500000 121 2000 1 0.0881802 12.1949 0.842912 2 0.264541 12.09 0.842986 3 0.440901 12.0788 0.840996 ... 1000000 121 2000 1 0.0881802 11.6526 0.841493 2 0.264541 11.7525 0.840792 3 0.440901 11.7087 0.842102 ... ...
with
>>> import pylam >>> FBF = pylam.FixBlockFile('chunk1D.dat') >>> newTable = FBF.blocks2cols('v_temp', fix=['Chunk','Coord1']) >>> newTable.write('new.dat')
new.datwill look like:# Chunk Coord1 v_temp_0 v_temp_1 v_temp_2 v_temp_3 +1.00000000e+00 +8.81802000e-02 +8.42912000e-01 +8.41493000e-01 +8.40999000e-01 +8.43067000e-01 +2.00000000e+00 +2.64541000e-01 +8.42986000e-01 +8.40792000e-01 +8.45285000e-01 +8.40694000e-01 +3.00000000e+00 +4.40901000e-01 +8.40996000e-01 +8.42102000e-01 +8.40272000e-01 +8.44249000e-01 +4.00000000e+00 +6.17262000e-01 +8.37955000e-01 +8.37166000e-01 +8.39804000e-01 +8.38266000e-01
Parameters: - colname – selected column to collect
- fix – common column (like, e.g. ‘Bin’)
Returns: Table object
Return type:
-
LogFile¶
This class provides a access to the log file (log.lammps). The thermodynamic info block(s) are made accessable as ThermoBlock objects.
-
class
pylam.LogFile(filename)[source]¶ Bases:
pylam.base.BlockFileClass for LAMMPS log files.
Parameters: filename (str) – log file name Returns: log file object Return type: LogFile -
blockClass¶ Block class which is attached, here:
pylam.ThermoBlockalias of
ThermoBlock
-
info(re=False)[source]¶ Prints debug info to screen, e.g.:
file name: example_data_files/log.lammps units: real N atoms 1372 N runs: 3 total run time: 3682.2074 sec total steps: 5010000
Parameters: re (bool) – recursive info for pylam.ThermoBlock
-