LAMMPS can't read in bond information between atoms

Hi LAMMPS users,
I am trying to rerun my simulation from a specific snapshot using the read_dump command. I use read_data first just to set up my simulation box, then read_dump for the xyz coordinares (from the traj.dump file). I then need a second read_dump command to read information about pairs of bonded atoms, but I believe this fails because lammps is not set up to accept that dump file format.

Is there a way to accept a dump file that is formatted for bond pairs?
Is there another command I can use to read in this information for a rerun?

Here are the lines in the input file:

read_data npt_system.data
read_dump traj.dump 300000 x y z
read_dump bonds.dump 300000 c_3[2] c_3[3] c_3[1]

Here is the error message:
ERROR: Read_dump must use at least either ‘id’ or ‘type’ field (src/read_dump.cpp:1173)

Here are the dumpfile formats:

traj.dump:
ITEM: ATOMS id mol type x y z ix iy iz
1 1 4 -17.5268 2.91378 5.92206 3 -3 -5
2 1 3 -17.1123 3.82072 5.96327 3 -3 -5

bonds.dump:
ITEM: ENTRIES index c_3[2] c_3[3] c_4 c_3[1]
1 9050 9051 1.01085 1
2 9052 9053 0.929943 1

*Note c_3[2] is atom1, c3[3] is atom2, c_4 is the bond length, and c_3[1] is the bond type. These are just the way I named the computes during the simulation.

Let me know! I assume the error is that the documentation only specifies position/velocity fields, not atom1 atom2 bond-pairing fields, since these were created by my computes. But there MUST be some way to read in this information…

Documentation page is here.

What would you like LAMMPS to do with this information?

In most MD simulations the bond topology (which atoms are bonded and with which bond types) does not often (if ever) change; bond distances are usually output information rather than input – that is, it is very easy to read in a configuration and work out how long each bond is, but it is difficult to read in a list of bond lengths and work out a configuration that satisfies them.

Thus LAMMPS does not have functionalities as far as I know to read in this information, apart from the usual read_data function (and it is already very flexible as an MD package). There are ways, using shell tools, to extract the bond topology from your dump format and reformat it into an acceptable data file section of Bonds.

The error message is self-explanatory: LAMMPS doesn’t know what “c_3[2]”, “c_3[3]”, and “c_3[1]” means.
Besides, the bond information should already be included in the file you read with read_data. It has a “Bonds” section for defining which atoms are bound to which and what bond type those bonds have, and the bond distance follows automatically from the atom positions, that are also stored in the data file and then updated with read_dump traj.dump.

How should LAMMPS know that? Please keep in mind that LAMMPS is a simple computer program and not a mind-reading AI. As a computer program, it requires to be given exact information according to its documentation.

It makes NO SENSE to read this back from this specific file. The information is already present.

Hi, I think what @srtee described regarding the data file is most likely the answer you need. If your bond topology hasn’t changed and you are just reading a dump file to update atom coordinates, then you don’t need to worry about reloading bond info and you should be all set.

However, if your bond topology has changed, unfortunately I do not believe there is currently a way to load in updated bond info. Your best bet might be to:

  1. load the dump file without bonds
  2. have lammps output a new datafile
  3. process your bonds.dump file to append a new list of bonds (w/ bonded atom IDs and bond type) at the bottom of your new data file (e.g. with python)
  4. load the new datafile with the new coordinates and new bonds.

Unless you are referring to an equilibrium length (only relevant for a few bond styles like the BPM package or harmonic/restrain), there is no need to worry about the bond distances from your bonds.dump file.

Thanks for the response Axel. I understand that Lammps doesn’t understand the names I gave to the compute property/local outputs, but my question is about whether there is another way to read bond information (or a better format to dump it).

Read_data doesn’t work in this case because, as I said, I am looking for bond information from a different snapshot (bond info changes with fix bond/react). Given your lack of suggestions, it seems that Lammps is not equipped to read bond information in any format other than read_data.

In the future, I suppose my best option is to write_data periodically by running every N steps, although I wish there was an option that didn’t require me to fill my directory with hundreds of files.

Thank you for the helpful suggestions. My bond topology does change, so rewriting my .dump files into .data files is a feasible solution (although of course it is tedious). I will likely run new simulations.

Certainly the ability to read in bond topologies may come in helpful in the future, given LAMMPS’s ability to perform bond-reactive simulations.

In the meantime, note that since LAMMPS takes pure text files as input, you should be able to script out an appropriate conversion procedure. With the above format for bonds.dump:

...
ITEM: ENTRIES index c_3[2] c_3[3] c_4 c_3[1]
1 9050 9051 1.01085 1
2 9052 9053 0.929943 1

and assuming you want to recast the very last dump of the file into valid LAMMPS information, overwriting an existing LAMMPS data file, here’s how you could do it on most UNIX systems as a series of commands:

OLDDATA='npt_system.data'
BONDDUMP='bonds.dump'
NEWDATA='npt_system_newbonds.data'
endline=$(grep -n -m 1 '^Bonds' $OLDDATA | cut -f1 -d: )
sed -n "1,${endline}p" $OLDDATA > $NEWDATA
echo "\n" >> $NEWDATA
dumpline=$(grep -n -m 1 '^ITEM' $BONDDUMP | cut -f1 -d: )
sed -n "${dumpline}"',$p' $BONDDUMP | awk '{print $1, $5, $2, $3}' >> $NEWDATA

Have fun!

Excellent thank you, this gives me a lot of progress towards file rewriting.

Yes and no. There are read_data and read_restart.

Please note that what you are trying to do (using rerun with a trajectory that uses fix bond/react) is highly unusual and most of what is programmed in LAMMPS is contributed by people that have a particular need. Thus, the more unusual your application is, the less likely is there are particular way to handle this. That said, using data or restart files are the canonical way in LAMMPS to restore a state of the system with geometry, per-atom properties and topology information being present. While there is currently no clean way to record data files during a simulation, there is the restart command which can generate a sequence of restart files during the course of your simulation and those can be written out at the same frequency that you are tracking your bond information. Restart files can be converted to data files from the LAMMPS command line and then you have what you want and with a well supported mechanism. Of course, the specific problem is, that you likely didn’t record restart files.

Please note that rewriting the data file this way will only work for cases where your system has only bonds. If you also have angles and/or dihedrals, the resulting computations from rerun will still be bogus.

Thus, writing out restart files during the simulation and then using read_restart (or read_data after converting them) is the only clean way to continue a simulation with changing bond topology. What you are asking for is rather questionable in its use, so it is quite understandable that in light of the existing mechanisms, that nobody has cared to implement what you are specifically looking for.