Skip to content

Commit

Permalink
Added -c option to cmd interface to print available columns in log file
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrik Andersen Sveinsson committed Dec 16, 2024
1 parent 6188c77 commit 02b2756
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lammps_logfile/cmd_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,30 @@
import matplotlib.pyplot as plt

def get_parser():
parser = argparse.ArgumentParser(description="Plot contents from lammps log files")
parser = argparse.ArgumentParser(description="Plot contents from lammps log files. Input file argument comes before keyword arguments. ")
parser.add_argument("-x", type=str, default="Time", help="Data to plot on the first axis")
parser.add_argument("-y", type=str, nargs="+", help="Data to plot on the second axis. You can supply several names to get several plot lines in the same figure.")
parser.add_argument("-a", "--running_average", type=int, default=1, help="Optionally average over this many log entries with a running average. Some thermo properties fluctuate wildly, and often we are interested in te running average of properties like temperature and pressure.")
parser.add_argument("input_file", metavar='INPUT_FILE', type=str, help="Lammps log file containing thermo output from lammps simulation.")
parser.add_argument("-o", type=str, dest='fout', default='', help='Save the figure to this file; the format must be supported by matplotlib.')
parser.add_argument("-c", "--columns", action='store_true', default=False, help='Print columns of the lammps logfile')

return parser

def run():
args = get_parser().parse_args()
log = File(args.input_file)

if args.columns:
print(f"Columns available in log file:\n{' '.join(log.get_keywords())}")
if args.y is None:
exit(0)

x = log.get(args.x)
print(x)
if args.running_average >= 2:
x = running_mean(x, args.running_average)
for y in args.y:
data = log.get(y)
print(data)
if args.running_average >= 2:
data = running_mean(data, args.running_average)

Expand Down

0 comments on commit 02b2756

Please sign in to comment.