Bin1d class

The postmd.avechunk.Bin1d() class is to process the file generated from fix ave/chunk bin1d command in LAMMPS.

Examples

>>> from postmd.avechunk import Bin1d
>>> filepath = r"tests/data/ave_chunk_bin1d.dat"
>>> bin1d = Bin1d(filepath,dim="z")
You are processing the file: 'D:\Onedrive\Github\MyRepos\PostMD\tests\data\ave_chunk_bin1d.dat'
'D:\Onedrive\Github\MyRepos\PostMD\tests\data\ave_chunk_bin1d.dat' is generated by command 'fix ave/chunk'
The first line is: Chunk-averaged data for fix slab_y_free_ion and group vx
>>> bin1d.read_file()
>>> # We stored the blocks in a list
>>> print(f"The type of bin1d.blocks is {type(bin1d._blocks)}")
The type of bin1d.blocks is <class 'list'>
>>>
>>> # you can use len(bin1d) to get the number of blocks
>>> print(f"{bin1d.path} have {len(bin1d)} blocks")
D:\Onedrive\Github\MyRepos\PostMD\tests\data\ave_chunk_bin1d.dat have 10 blocks
>>>
>>> # you can use bin1d[index] to access index-th block
>>> # in each block, we store the information with dict.
>>> print("The first block is:\n", bin1d[0])
The first block is:
{'step': 1000000, 'nchunk': 800, 'total_count': 1.0, 'data':      Chunk  Coord1  Ncount  density/number   vx   vy   vz
0        1  -39.95     0.0             0.0  0.0  0.0  0.0
1        2  -39.85     0.0             0.0  0.0  0.0  0.0
2        3  -39.75     0.0             0.0  0.0  0.0  0.0
3        4  -39.65     0.0             0.0  0.0  0.0  0.0
4        5  -39.55     0.0             0.0  0.0  0.0  0.0
..     ...     ...     ...             ...  ...  ...  ...
795    796   39.55     0.0             0.0  0.0  0.0  0.0
796    797   39.65     0.0             0.0  0.0  0.0  0.0
797    798   39.75     0.0             0.0  0.0  0.0  0.0
798    799   39.85     0.0             0.0  0.0  0.0  0.0
799    800   39.95     0.0             0.0  0.0  0.0  0.0
[800 rows x 7 columns]}
>>> # you can use key to access the data in each block
>>> print("The data in the first block is:\n", bin1d[0]["data"])
The data in the first block is:
    Chunk  Coord1  Ncount  density/number   vx   vy   vz
0        1  -39.95     0.0             0.0  0.0  0.0  0.0
1        2  -39.85     0.0             0.0  0.0  0.0  0.0
2        3  -39.75     0.0             0.0  0.0  0.0  0.0
3        4  -39.65     0.0             0.0  0.0  0.0  0.0
4        5  -39.55     0.0             0.0  0.0  0.0  0.0
..     ...     ...     ...             ...  ...  ...  ...
795    796   39.55     0.0             0.0  0.0  0.0  0.0
796    797   39.65     0.0             0.0  0.0  0.0  0.0
797    798   39.75     0.0             0.0  0.0  0.0  0.0
798    799   39.85     0.0             0.0  0.0  0.0  0.0
799    800   39.95     0.0             0.0  0.0  0.0  0.0
[800 rows x 7 columns]