How to write thermo_style output (or similar) to array in python?

If he would like to do this from the python side of the lammps-python interface, there are multiple ways to handle it. One is doing something similar to what is in LAMMPS' mc.py example, where extract_compute is getting the value of a thermo property every timestep, and then the simulation is advanced using a for loop and individual "run 1 pre no post no" commands. That approach may be used for a MD run, and use any desired extract_* (such as extract_variable). Another option is to use the "fix vector" command, accumulating various thermo quantities every N timesteps during a run, and then extracting them at the end of the run using extract_fix. I've had success with both approaches for different purposes.

Axel's suggestion of doing it from the LAMMPS side using python-style variables may be fruitful, too. The python functionality in LAMMPS is quite powerful, and a great feature.

cheers,

Brian Barnes
US Army Research Laboratory

In answer to John Rivas’ query and my own earlier, I have hacked together a small routine in python to pull out the thermo output from the log file, write it to a separate file, and read it into arrays/vectors

N.B. I’m new to LAMMPS and lack a strong background in python, so the attached is surely not optimal, but it appears to work and may be of benefit to anyone else facing this issue

Thank you Brian and Axel - I will read more about defining an appropriate fix and extracting that as I expect it will be much more efficient that what I currently have

postprocesslammpsthermo.py (2.19 KB)

There is a Python script in the distro that does something like this:

tools/python/log2txt.py

Also logplot which will plot columns of the log file.

They both use tools/python/pizza/log.py

which is part of Pizza.py (http://www.sandia.gov/pizza.html)

which will read LAMMPS log files and let you do various things

with the thermo data.

From Python, another option to get a more tabular file on-the-fly

is to use “fix ave/time file foo.out” which will let you

define a series of quantities (e.g. same ones as for thermo output)

and write them to a file with optional time-averaging. The format

of that file is like a table with a few header lines.

Steve