Source code for postmd.avetime.avetime

import re
from pathlib import Path

import numpy as np
import pandas as pd

from ..system import MDFile

[docs] class AveTime(MDFile): def __init__(self, path=None, timestep:float=1.0): """process the data generated from "fix ave/time" command in LAMMPS (see https://docs.lammps.org/fix_ave_time.html). Args: path (str, optional): path to the file. Defaults to ``None``. timestep (float, optional): temperature you set in LAMMPS input file. Defaults to ``1.0`` [fs]. """ super().__init__(path=path) self.timestep = timestep
[docs] def read_file(self, header:list=None, header_line:int=2, **kwargs) -> pd.DataFrame: """read file generated from ``fix ave/time`` command. Args: header (list, optional): a list of data headers. Defaults to ``None``, means extracting headers from ``header_line``. header_line (int, optional): when ``header=None``, the content in ``line=<header_line>`` will be used as the headers. Defaults to ``2``. **kwargs: received parameters of pd.read_csv(). Returns: pd.DataFrame: DataFrame object read from the file. Notes: There are some default setting in read files: - ``comment="#"`` in the files generated by ``fix ave/time``command in LAMMPS. - ``sep="\s+"`` set the separator to ``\s+``, matching one or more whitespace characters. """ header = header if header else self._get_header(header_line) self.data = pd.read_csv(self.path, names=header, sep='\s+', comment="#", **kwargs) return self.data