how to grab some information from log file to make a new file

Use sed, awk or bash script and call it using the shell command from lammps

Arun

Use sed, awk or bash script and call it using the shell command from lammps

…or Perl, python, Tcl, ruby, matlab, or any other script / programming language.

Dear Arun and Dear Axel,
I know a little about matlab, maybe I should start with that. It seems a lot work to do for me.
Thanks very much for your help!

Dear Arun and Dear Axel,
I know a little about matlab, maybe I should start with that. It seems a lot
work to do for me.

this kind of thing is a very frequently recurring task, thus figuring
out how to do it well, is worth it.
but then again, in this particular case, it is not much of an effort,
if you have a good strategy, e.g. in this case:

open the log file
do read a line, until end of file:
   if line starts with "Step" then:
      read a line
      read a line
      print the line
   end if
end do
close the log file

quite simple, isn't it?

axel.

There is a Python script in tools/python

called logtxt.py which will extract just

the thermo data from a log file and create

a new txt file which has just the columns

of numbers.

Steve

Dear Steve,
I am sorry for that I have not used python before and I can not fix this problem when I use log2txt.py.
After putting log2txt.py and the log file in the same folder, I typed python log2txt.py log.logfilename data.txt in the terminal. But it returns the error KeyError: ‘LAMMPS_PYTHON_TOOLS’. My OS is Ubuntu 14.04 and python version is 2.7.6.
I know that I really need to learn python first and try to fix this myself. But if you can give me some help on how to fix this, it will helps a lot. Thanks very much indeed!

With My Best Regards
Liu

tools/python/README explains how to set that TOOLS variable.

Steve

Dear Steve,

Sorry for bothering you again. I have read tools/python/README and set the environment variable LAMMPS_PYTHON_TOOLS in my bash shell, which is set as export LAMMPS_PYTHON_TOOLS=/home/mgqqlwq/apps/lammps-28Jun14/tools/python/pizza:$LAMMPS_PYTHON_TOOLS.

But when I invoked log2txt.py by python log2txt.py log.lammps data.txt, another error appears and it is shown as below:

Traceback (most recent call last):

File “log2txt.py”, line 16, in

from log import log

ImportError: No module named log

It seems it cannot import log.py. I searched this error on internet and tried several methods, but I still cannot fix this. Could you please give me more help?

Thanks you very much!

Dear Steve,

Sorry for bothering you again. I have read tools/python/README and set the
environment variable LAMMPS_PYTHON_TOOLS in my bash shell, which is set as
export
LAMMPS_PYTHON_TOOLS=/home/mgqqlwq/apps/lammps-28Jun14/tools/python/pizza:$LAMMPS_PYTHON_TOOLS.

But when I invoked log2txt.py by python log2txt.py log.lammps data.txt,
another error appears and it is shown as below:

Traceback (most recent call last):

File "log2txt.py", line 16, in <module>

from log import log

ImportError: No module named log

It seems it cannot import log.py. I searched this error on internet and
tried several methods, but I still cannot fix this. Could you please give me
more help?

the README says that you have to set the variable to _one particular
directory_. it is no mentioning to treat it like $PATH.
thus try this instead:

export LAMMPS_PYTHON_TOOLS=/home/mgqqlwq/apps/lammps-28Jun14/tools/python/pizza

details matter!

axel.

p.s.: you may want to have a look at this. http://learnpythonthehardway.org/
this won't help you with this particular issue, as this is rather
specific, but get you started in better understanding what python is
doing overall.

Thanks you very much!

With My Best Regards
Liu
________________________________

[...]

Dear Axel,

Thanks very much! I am so glad that it works now.

But it seems log2txt.py only works well if the Lammps log file contains several thousand steps. The information shown in the terminal is pasted into the first attachment named log.failed.

If I cut my log file into a much shouter one, it works well. The result is shown in the second attachment named data.txt.

As you and Arun said, this actually is not a Lammps issue. And everybody here helped me a lot, really thanks everyone! Maybe I should learn Python first and try to solve the problem later.

And also thank you for the link!

With My Best Regards

Liu

log.failed (9.21 KB)

data.txt (1.1 KB)

This is a problem with log2txt.py that I have encountered before: It
can't handle LAMMPS warning messages. The following is a work around:

grep -v WARNING log.lammps > log.lammps.clean

Aidan

2015-12-03 1:37 GMT-07:00 Wenqiang Liu <[email protected]...>:

Dear Aidan,
Thank you very much!
It’s wonderful. My problem has been solved.