plotting log data in xmgrace

I also like this one, which doesn't require knowledge of how long the set
is:
   awk < log.lammps '/Step/ {flag = 1; next}; /Loop time/ {flag = 0}; \
     flag {print}' | xmgrace -nxy -

I feel embarrassed to say that I didn't know how to do -nxy and then
read from standard input before reading your message (answer: use - as
the file name); I've always used -pipe before, but that only works with
plain old x-y data.

-Karl

I said "without doing anything complicated"!. Just kidding. I never
learned awk, but I can kind of see what this is doing. Cool.

Another option which uses even less complicated maneuvers:

awk '/Step/,/Loop time/' outfile | grep -v -e 'Step' -e 'Loop' \
   > xmgrace -nxy -

This will grab everything between lines that match "Step" and lines that
match "Loop time"; the pipe through grep is only necessary because Grace
will be upset that "Step" and similar lines are not numbers. You could,
of course, remove them in awk (but I've already shown how to do that).

The above command is probably easier to remember than my previous example.

-Karl

Hi Aidan,

I have this code which I wrote a while ago (when I did not know about complex operations using grep, pipe, awk etc.) which does exactly that. It works with both line single and line multi. Please give it a shot if you wish. The basic steps are written in the pdf file. It can read multiple files in a single go and plot the multiple files’ data in parallel, (i.e., independent datasets) or in series (one after other) for a particular quantity of interest. I have written some xmgrace settings within the code which you can modify for the visualization that you feel most comfortable with.

Best regards,
Vikas

lammpsplot.cpp (26.9 KB)

lammpsplot.pdf (70 KB)

I got it down to one command, though admittedly this takes us back into
the realm of doing something complicated:
    sed -n '1,/Step/!{ /Loop time/,/Step/!p; }' outfile | xmgrace -nxy -

I adapted this from the example at:
http://sed.sourceforge.net/sedfaq4.html#s4.24

Using sed is something I would like to get better at (I usually use it
just for search-and-replace; the above example is something I wouldn't
be able to write without finding the one cited above).

I like the awk method. I have stripped it down to this:

awk /Step/,/step/ log.lammps | grep -vi step | xmgrace -nxy - (or
xmgrace -block - -bxy 1:8)

Note that if all you want is xmgrace -nxy, you do not have to strip
out the 'Loop time' and subsequent lines, but for -bxy, you do. But
the above works for both. Extra credit. If you log file contains
multiple runs, each with different thermo output, and you only want to
see, say the third run, how would you do that in awk or sed?

Karl,

I like the awk method. I have stripped it down to this:

awk /Step/,/step/ log.lammps | grep -vi step | xmgrace -nxy - (or
xmgrace -block - -bxy 1:8)

Note that if all you want is xmgrace -nxy, you do not have to strip
out the 'Loop time' and subsequent lines, but for -bxy, you do. But
the above works for both.

Extra credit: If your log file contains multiple runs, each with
different thermo output, and you only want to plot, say, the third
run, how would you do that in awk or sed?

awk '/Step/ {n+=1}; /Step/,/step/ {if (n==2) {print}}' log.lammps | \
   grep -iv step | xmgrace -nxy -

will print only the second group of data. If you want it to be easier
to set the number of the group, do this:

awk -v nmax=2 '/Step/ {n+=1}; /Step/,/step/ {if (n==nmax) {print}}' \
   log.lammps | grep -iv step | xmgrace -nxy -

Technically, you do need to strip out the "Loop time" line, but it
generates a warning, not an error, so it's not fatal. Grace is finicky
about the first line, though.

For a journey back into the realm of doing complicated things, try this
(call it "plot-thermo-data"):

#! /bin/awk -f
BEGIN {
     if ( stepnum == 0 ) stepnum = 1 # if unset, pick first set of output
     print "@xaxis label \"Time Step\""
}
/Step/ {
     num += 1
     if ( num != stepnum ) next
     n = 0
     for (i=2; i<=NF; i++) {
         print "@s" n, "legend \"" $i "\""
         n += 1
     }
}
/Step/,/step/ { if ( $0 ~ /[sS]tep/ ) next; else print }

Then this should, if you're using a version of Grace compatible with mine
(I'm using 5.1.23), plot everything and auto-label all the sets and the
x-axis for you:
   plot-thermo-data log.lammps | xmgrace -nxy -

Karl D. Hammond
University of Tennessee, Knoxville
[email protected]

"You can never know everything, and part of what you know is always
   wrong. A portion of wisdom lies in knowing that. A portion of courage
   lies in going on anyway."
"Nothing ever goes as you expect. Expect nothing, and you will not be
   surprised."

Vikas,

Thanks for sharing. This is a pretty nice program. Is this building
on your tools/ thermo_extract.c? Would you like to have it added to
the tools directory? Perhaps we should set up a tools/xmgrace folder
that people can add stuff to.

Aidan

Hi Aidan,

Thanks for the kind words. Yes, it is the second version of that program. If possible, I would like to get the older version get replaced with this one. I would let Steve decide how he wants to include it in the tools directory.

Best Regards,
Vikas

Okay. We will get rid of the old one. I am going to make an xmgrace
folder. Karl, is it okay if I include your awk mini-scripts?

Aidan

By all means! Include anything you wish---I'm glad others think it might
be useful.

Karl D. Hammond
University of Tennessee, Knoxville
[email protected]