Writing a compute for bond states

Dear community,
Could you please help me with writing a specific compute.
The system is a set of particles with bonds. I need a compute that analyzes each bonds’ state in a simple matter:

  • bond length < Li => state 1,
  • bond length >= Li => state 2,
    where Li is a predefined constant individual for each bond type i.
    Then the compute should (1) summarize the number of bonds in each state (1 and 2), (2) summarize the number of bonds which state was changed from the previous compute, and (3) put these values to the computed variables.

Could you please recommend how to do it or what to start with?
I’ve checked several existing computes and fixes too learn about the ‘ingredients’ but still struggle to implement the thing described above.

Best regards,

Vladimir.

Have you looked at compute bond/local command — LAMMPS documentation ?
For starters, you could just use “dump local” to output the lengths and then post-process the data.

The challenge with doing this internally is that you need to have a mechanism to store the bond information and computed data from the previous step. This becomes a problem because atoms and the associated bonds may migrate between MPI ranks during neighbor list updates.

Thanks for your response, Alex!
Sure, I’ve checked compute bond/local command. Unfortunately, I really need it on the fly, and not in post-processing. The reason is the next step: I need to dump only when at least one of the bonds changes its state (really really need it to keep dump file size reasonable during long runs).
I see your point that the bond history data should migrate between MPI ranks together with the bond, even if it’s just a single integer variable per bond. Do you think writing a custom bond type with this additional information is good idea then? Or should it be done via a custom atom type not bond type? Sorry for beginner questions, I’m a bit lost at this point.

I am lost, too, since I have no clue what the science or physics is you want to implement (and I am not eager to work this out). I choose to not give advice on what I don’t understand.

As far as I see it, you have two options: a) spend more time learning about how to extend and modify LAMMPS for your purposes. Perhaps working on something simpler first or b) find a collaborator that is interested and willing to work with you on your project and already has the knowledge and experience to make the modifications.

Without knowing anything about the physics of the model, this task can be accomplished using fix bond/history which handles the writing/reading of restarts and parallel communication. An example is fix_bond_bpm_spring.cpp which stores the bond reference length. One could just modify it to store an integer state.

2 Likes

Thanks a lot! I will check fix bond/history. Haven’t known about this fix before, don’t see it in the documentation, but only in source. Will write later if I managed to solve the problem with this fix.

I believe it’s considered an “internal” fix, so it’s not documented and exposed to the user. It has two arguments:

  1. A flag that indicates whether the stored values may change with time (1 = values will evolve, 0 = values are static)
  2. The number of variables to store per bond

It then has various public methods to store/access the data. See the BPM bond styles for examples.

1 Like

jtclemm,
Thanks a lot for the recommendation!
I’m in the middle of writing my own bond type by combining bond_table (which I use in the model) and bond_bpm + bond_bpm_spring (which you recommended as a reference). I already made it to evaluate and store bond state, swap flag and number of swaps between the states. Still have to figure out how to output swap data to the atom data via pack function and how to use it as dump condition.
Will come back if more questions arise or when completed.

Thanks a lot again, you helped a lot!

PS The problem behind the coding is BPM-like system with tabulated bond potentials with multiple minima, and I need to trace & dump swaps between the states. I need the swap flag to dump only meaningful states in a long run.