Invoke second pair_style every N timesteps

Hi all,
Is there a way to have two pair_styles defined where the first runs the dynamics (ie. at every timestep) and the second gets invoked at every N steps? In my case, the second pair_style will be estimating the confidence of the first, but because it’s much costlier I only want to run at every 5-10 steps, for example. I know that the other option is to save the dump and do rerun but I have a limited disk space and I’m trying to run long MDs.

This is a non-trivial operation.
You cannot use two pair styles this way at the same time from within the same input. So to orchestrate this, you would have to either do your simulation as a loop where you run the 5-10 steps, then redefine the pair style, execute a run 0 command, and then switch back to the original style, or you would use the library interface (e.g. via the LAMMPS python module) to create two LAMMPS instances and - again - alternate between running for a few steps, then transfer the coordinates to the second instance, execute a run 0, and then continue from the first. The difference between the two variants is that the second would be more efficient, since you can continue the main simulation with run 10 pre no post no, while in the first case you must use the run 10 pre yes post no since you switched the pair style and thus need to recompute the forces. Also, with the two LAMMPS instances all kinds of analysis and trajectory collection will be easier, since you don’t insert any extra calculations with different settings.

A third option would be to write a custom pair style similar to pair style hybrid/overlay, that will maintain sub-styles as you need it, but then only use the results from the first for propagation and the second for special analysis.

1 Like

As an example for something similar to the third option, you can look at the (new) fix pair command and pair style pace/extrapolation (not yet released, but available in the develop tree of the git repository, pair_style pace command — LAMMPS documentation).

I though this would be possible using respa, and assigning the different pair_styles to different rRESPA levels. Or may be I am misunderstanding this part of the doc:

Another option for using pair potentials with rRESPA is with the hybrid keyword, which requires the use of the pair_style hybrid or hybrid/overlay command. In this scenario, different sub-styles of the hybrid pair style are evaluated at different rRESPA levels. This can be useful, for example, to set different timesteps for hybrid coarse-grained/all-atom models. The hybrid keyword requires as many level assignments as there are hybrid sub-styles, which assigns each sub-style to a rRESPA level, following their order of definition in the pair_style command. Since the hybrid keyword operates on pair style computations, it is mutually exclusive with either the pair or the inner/middle/outer keywords.

This would be for different pairs of atom types, i.e. for different assignments of sub-styles in pair style hybrid. In r-RESPA some interactions are computed less frequently and their forces stored and then added to the forces of interactions computed more frequently to produce the total force. This is very different from invoking a different pair style on the same atoms in order to validate (and possibly correct) the fast computation with the results from the slow computation (which is how I understood the OP).

1 Like

I see, interesting. Indeed I initially misunderstood what OP wants to do.

For the sake of completeness. The hybrid r-RESPA option was conceived for mixing all-atom and coarse-grain force field calculations Only the interactions involving the all-atom parts need to be evaluated (and time integrated) on the “inner” time step. Coarse grain interactions are typically much softer and the particles heavier (since they combine multiple atoms in one site) so they can be time integrated at a much larger time step. Since for such mixed systems, the computation of the coarse-grain only interactions is the dominant part, this hybrid approach can result in a significant speedup.

1 Like