My intent is to have LAMMPS create an output file different from the format of the dump output so that it is readily readable other software like MATLAB for plotting.
Specifically, an output of only columns of time timet and associated z-positions for particles in a group of N particles zN(t). Ideally, it would look like this:
Where time(2) is the time at step 2, for example. and z2(2) is the z-position of the 2nd particle in the group at time 2.
I understand that the dump command can provide this information, but it does not fit the format we are looking for. Additionally, I understand this can be done in post-processing scripts easily, but again, that is not our intent.
I suspect that a direction would be to use compute property/atom z which would provide a per-atom vector, but we are having trouble taking that and creating variables for each z-position for each particle in the group to fix print or dump to its own column.
In my opinion you are trying to solve your problem “the hard way™”.
Here are a few ways that take IMO much less effort:
use dump style yaml and then install a yaml extension into matlab and load the yaml file directly
use dump style yaml and then read the yaml file into python and output it from python in any which way and format you like
use dump style custom and the dump class tools/python/pizza/dump.py to read and parse the file and then output it in any which way and format you like. There are a couple of examples in the tools/python folder. E.g. dump2xyz.py or dump2pdb.py which show how this could be done.
use dump style custom and a tool like awk or perl or python to just strip off the parts you don’t like or want.
Thank you for your reply and providing much more effective and efficient directions.
However, we still would like to pursue the “the hard way™” for our research as having these data as variables would provide useful for other applications.
Do you or anyone else have a workflow idea for this less-than-optimal intent?
There is nothing to gain from having the same data arranged in a different format directly. Specifically, since you are not working with large amounts of data.
I forgot a number 5. in my list:
There are MATLAB functions included in the tools/matlab folder that can read LAMMPS dump files directly. Those may need a few tweaks, since those have not been updated in a long time (last change was in 2018 to adapt to some changes in the LAMMPS dump format and before that in 2010) and I have the impression that people prefer post-processing with Python these day, particularly when using the Pandas package and Matplotlib, there is little where MATLAB has an advantage.
That said, if you absolutely want to output things in your own format, you will need to do some C++ programming and create your own dump style (it may be a class derived from DumpCustom like the yaml or the cfg dump style). This is because the per-atom data in LAMMPS is distributed across parallel processes, so when creating dump files you need to collect that data with MPI calls before you can output it. Using atom style variables does not make a difference here.
Nothing of that matters, however, when you load the data into MATLAB (or python for that matter) since you are not running in parallel so there is no more communication needed and you can access all data in any order by just using the right indexing. It is trivial to transpose the data, too.
In other words, you have to provide a much more compelling reason to make be believe that there is any value (outside of some “hack value”) in the feature that you are insisting on.
Number 6
Dump into XTC format and read into Matlab with MDToolbox
Number 7 (variant of number 4)
Dump into native atom style and then re-parse into individual atom trajectories:
for ((n=1; n<=$nmax; n++)); do grep "^$n\b" my.lammpstrj | awk '{print $3,$4,$5}' > atom_"$n".dat; done
which you can even re-fold into a single trajectory file with careful use of paste. (Note you may have to escape various special characters correctly, which is still a thousand times less work than writing new C++ code.)