Lammps writing output options

Hello everyone!
I was looking for a command or an option to continue adding information to my outputfile after a restart. I have this to write my output file:
compute layers all chunk/atom bin/1d z lower ${dz} units box
fix 2 all ave/chunk 100 40 4000 layers v_temp all file data.profile

Lammps usually remplace the last file after restart process that make me copy a lot of files and what I want is that lammps continue adding information to current file. Is someone have the solution?

I usually add commands in the submit shell script to overcome this issue. For example, after the simulation ends, you can add something like

cat data.profile >> data_old.profile

The file “data_old.profile” will contain information of all the restarts. One downside is that, the header lines will also be present in between, but that is straightforward to clean up. I am not sure if there is a cleaner way to do the same in LAMMPS.

Commands that support appending to a files generally have an option for that. So you need to check the corresponding documentation. If such a flag/keyword/setting does not exist, there is no support.

However, appending to files is generally not a good idea. Consider the fact that your simulation may have been interrupted for some reason (not unusual on HPC clusters and one of the reasons why you write out restarts). That may mean that you may have an incomplete or corrupted file, or that - after restarting - output for certain timesteps would be written multiple times. If you append to files, then you have a corrupted or incorrect file that is difficult to repair and will not read correctly. And even if there is no corruption, the size of files for long trajectories may get very large and can make manual edits or post-processing difficult.

A much better approach would be to have some variable defined containing a “run ID”, e.g. via a command line flag like -var run 1. Then you can include ${run} in your file names. If you then start the second run, you would use -var run 2 and now the overwriting of files is no longer a problem and also with a command like variable oldrun equal v_run-1 you can infer the name of the restart file from the previous run. This principle - of course - can be made more sophisticated with formatting options for variables where you can add leading zeros so the files sort properly with file globbing when you have more then 10 runs.

If you would need some combined files from all runs, you can always combine them later with commands like “cat”, possibly after editing them to remove duplicate parts. Having to split a file to which output is appended is generally much more complicated, let alone having to repair a corrupted/broken file.