Fix bug in AvgChunkReader and add docs
This commit is contained in:
11
doc/src/Python_formats.rst
Normal file
11
doc/src/Python_formats.rst
Normal file
@ -0,0 +1,11 @@
|
||||
Output Readers
|
||||
==============
|
||||
|
||||
.. py:module:: lammps.formats
|
||||
|
||||
The Python package contains the :py:mod:`lammps.formats` module, which
|
||||
provides classes to post-process some of the output files generated by LAMMPS.
|
||||
|
||||
.. automodule:: lammps.formats
|
||||
:members:
|
||||
:noindex:
|
||||
@ -13,6 +13,7 @@ together.
|
||||
Python_module
|
||||
Python_ext
|
||||
Python_call
|
||||
Python_formats
|
||||
Python_examples
|
||||
Python_error
|
||||
Python_trouble
|
||||
|
||||
@ -12,13 +12,25 @@
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
################################################################################
|
||||
# LAMMPS data formats
|
||||
# LAMMPS output formats
|
||||
# Written by Richard Berger <richard.berger@temple.edu>
|
||||
################################################################################
|
||||
|
||||
import re
|
||||
|
||||
class LogFile:
|
||||
"""Reads LAMMPS log files and extracts the thermo information
|
||||
|
||||
It supports both the default thermo output style (including custom) and multi.
|
||||
|
||||
:param filename: path to log file
|
||||
:type filename: str
|
||||
|
||||
:ivar runs: List of LAMMPS runs in log file. Each run is a dictionary with
|
||||
thermo fields as keys, storing the values over time
|
||||
:ivar errors: List of error lines in log file
|
||||
"""
|
||||
|
||||
STYLE_DEFAULT = 0
|
||||
STYLE_MULTI = 1
|
||||
|
||||
@ -73,7 +85,17 @@ class LogFile:
|
||||
else:
|
||||
current_run[k].append(float(v))
|
||||
|
||||
|
||||
class AvgChunkFile:
|
||||
"""Reads files generated by fix ave/chunk
|
||||
|
||||
:param filename: path to ave/chunk file
|
||||
:type filename: str
|
||||
|
||||
:ivar timesteps: List of timesteps stored in file
|
||||
:ivar total_count: total count over time
|
||||
:ivar chunks: List of chunks. Each chunk is a dictionary containing its ID, the coordinates, and the averaged quantities
|
||||
"""
|
||||
def __init__(self, filename):
|
||||
with open(filename, 'rt') as f:
|
||||
timestep = None
|
||||
@ -121,6 +143,7 @@ class AvgChunkFile:
|
||||
total_count = float(parts[2])
|
||||
|
||||
self.timesteps.append(timestep)
|
||||
self.total_count.append(total_count)
|
||||
|
||||
for i in range(num_chunks):
|
||||
self.chunks.append({
|
||||
|
||||
@ -73,7 +73,9 @@ class AvgChunkFiles(unittest.TestCase):
|
||||
self.assertEqual(cfile.timesteps, list(range(10000, 110000, 5000)))
|
||||
|
||||
ntimesteps = len(cfile.timesteps)
|
||||
ntotal_count = len(cfile.total_count)
|
||||
nchunks = len(cfile.chunks)
|
||||
self.assertEqual(ntimesteps, ntotal_count)
|
||||
self.assertEqual(nchunks, 20)
|
||||
|
||||
for i in range(1, nchunks+1):
|
||||
|
||||
Reference in New Issue
Block a user