Question about remap ordering and rigid-body geometry in fix rigid/npt/small

Hello,

I am studying the implementation of fix rigid/npt/small and would like to understand the reasoning behind the box-remapping order.

Source version/commit: [version or commit]

In FixRigidNHSmall::initial_integrate(), the relevant sequence is:

if (pstat_flag) remap();

set_xv();

if (pstat_flag) {
  remap();
  if (kspace_flag) force->kspace->setup();
}

My understanding is that set_xv() reconstructs the atom positions from the body center of mass, orientation, and fixed body-frame displacements. However, the second remap() appears to rescale the constituent atom positions as well as the body centers of mass. final_integrate() subsequently calls set_v(), without reconstructing the positions again.

With dilate all, does this mean that the coordinates used for the subsequent force calculation have slightly different internal distances from the stored rigid-body geometry?

If this understanding is correct, what is the reason for this ordering? Is the resulting deviation required by the integration scheme or constraint-virial calculation, or is it a finite-timestep approximation accepted by the implementation? In particular, why is the geometry not reconstructed after the second remap, using the updated center of mass?

I have looked at the NPT equations in Kamberaj, Low, and Neal, J. Chem. Phys. 122, 224114 (2005), but I could not identify a step requiring the internal displacements to be rescaled. I may be missing a detail in how those equations correspond to the LAMMPS implementation.

I also found this earlier discussion:
https://matsci.org/t/fluctuating-bond-lengths-during-rigid-npt-fix/44411

It discusses the observed bond-length fluctuations, but I would appreciate clarification of the implementation rationale or a reference explaining it.

Thank you for your time.

@Flower101010 To implement the algorithms in Kamberaj et al in the velocity Verlet framework in LAMMPS, we update the box dimension (Eq. 68), assuming an upcoupled orthogononal simulation box in a similar way to what is done in FixNH::initial_integrate():955-965. The update in the box dim matrix H is split into 2 half steps, sandwiching the atom position update.

The first remap() converts the current atom coords to relative coords (x2lamda), updates the global and local box dimensions using the barostat chain variable epsilon_dot by a half step and converts lamda back to atom coords. At this point, atoms in the group fix rigid/nhare still in the old positions in the box dims updated by a half step.

Next, set_xv() is called to set the atom coords relative to the body COM and atom velocities based on body velocities and angular momenta. The internal displacement of each constituent atom within a body is fixed and not to be rescaled.

Finally, the second remap()updates the global and local box dimensions using the barostat variable epsilon_dot by the other half step and ensures that atom coords relatively the same with the updated box dims.

The effect at the end of FixRigidNH::initial_integrate()is the same as the end of Step 1 in the Kamberaj et al paper (page 224114-16) in that the box dims are updated to a full step and atom positions are updated in the new box dims. set_v()do not update atom coordinates nor box dims.

Hope it helps.

-Trung

1 Like

Thank you. I understand that the implementation splits the box update into two half steps, with set_xv() in between.

My remaining question concerns the actual interatomic distances after the second remap(), rather than the stored body-frame displacements. I understand that set_xv() reconstructs the atom positions using the fixed internal geometry. However, with the default dilate all, the second remap() appears to rescale those reconstructed positions as well. Would this change the internal distances in the coordinates subsequently used for force evaluation?

I have attached a minimal NVT/NPT comparison using a single rigid equilateral triangle with an initial side length of 3 Å. Both inputs create the atoms directly and use pair_style zero, so no external structure or potential files are needed.

The runs used LAMMPS (30 Sep 2026), with a timestep of 0.0005 ps and one continuous run 1000 command each. Coordinates were written with 17 significant digits, and distances were calculated from the unwrapped Cartesian coordinates.

The maximum absolute deviations from the initial pair distances over the saved frames were:

Fix Maximum distance deviation (Å)
rigid/nvt/small 2.31 × 10⁻¹⁴
rigid/npt/small 2.71 × 10⁻⁵

For example, at step 1000, the distance between atoms 1 and 2 was approximately 3.000027096873131 Å in the NPT run. All three sides showed essentially the same change.

When you say that the internal displacement is fixed and should not be rescaled, does this also mean that the distances calculated from the actual atom coordinates should remain fixed after the second remap()? If the observed deviation is expected, could you clarify how it follows from the integration scheme? I may still be missing how the constituent atom coordinates are handled during that final remapping.

The attachment includes both input scripts, dump files, logs, and calculated distances.

Thank you for your help.

lammps_rigid.zip (18.2 KB)

@Flower101010 thank you for sharing the input and testing output. Your question for the relative distances between the constituent atoms in the rigid bodies may point to a potential issue with how FixRigidNH::remap() andFixRigidNHSmall::remap() are doing. I will get back to you.

@Flower101010 Could you try apply the attached changes to the LAMMPS develop branch, rebuild LAMMPS and rerun the npt test?

I think I found the issue with remap(), which should not change the internal displacements of the constituent atoms. We need to remap the body COMs in both steps, and then call set_xv()only once at the end of initial_integrate(). The first remap() should be called before body COMs are updated, just like FixNH::initial_integate()before nve_x() is called.

When I define the 3 atom pair distances to in.lammps and print them out to the log,

variable l12 equal “sqrt((x[1]-x[2])(x[1]-x[2])+(y[1]-y[2])(y[1]-y[2])+(z[1]-z[2])(z[1]-z[2]))"
variable l23 equal "sqrt((x[2]-x[3])(x[2]-x[3])+(y[2]-y[3])(y[2]-y[3])+(z[2]-z[3])(z[2]-z[3]))”
variable l31 equal “sqrt((x[3]-x[1])(x[3]-x[1])+(y[3]-y[1])(y[3]-y[1])+(z[3]-z[1])*(z[3]-z[1]))”
timestep 0.0005
thermo 100
thermo_style custom step temp press vol lx ly lz v_l12 v_l23 v_l31

I got the distances change on the same order of magnitude with the nvt run (1e-14)

   Step          Temp          Press          Volume           Lx             Ly             Lz           v_l12          v_l23          v_l31     
         0  299.99972831654111 3.068109320825529 27000 30 30 30 3 3.0000000000000018 3.0000000000000018
       100  299.91780972000032 1.4916171938104488 27007.716939638369 30.002857853539115 30.002857853539115 30.002857853539115 3.000000000000016 3.0000000000000187 3.0000000000000173
       200  299.72632147501776 1.4766538481159883 27030.319798418124 30.011225354159922 30.011225354159922 30.011225354159922 3.0000000000000222 3.0000000000000253 3.0000000000000253
       300  299.63971886284492 1.5650170709304643 27067.78069071495 30.025082981813313 30.025082981813313 30.025082981813313 3.0000000000000231 3.0000000000000253 3.0000000000000266
       400  300.27878963726647 1.8361345018791408 27120.91990922681 30.044718460421578 30.044718460421578 30.044718460421578 3.000000000000028 3.0000000000000293 3.0000000000000289
       500  301.60612676842288 1.8743118779001116 27191.54962738372 30.070777194746292 30.070777194746292 30.070777194746292 3.000000000000032 3.0000000000000324 3.0000000000000338
       600  302.64036687343435 1.7031014104618387 27280.240734515675 30.103435822450386 30.103435822450386 30.103435822450386 3.0000000000000377 3.0000000000000386 3.0000000000000395
       700  302.81035306053099 1.4355488695952765 27386.031236890889 30.142298502872258 30.142298502872258 30.142298502872258 3.0000000000000475 3.0000000000000488 3.0000000000000493
       800  301.83907689420079 1.1466441107839873 27507.191485621523 30.186684584219773 30.186684584219773 30.186684584219773 3.0000000000000546 3.0000000000000577 3.0000000000000577
       900  299.76837320204976 0.93826810324834053 27641.784856293518 30.235839231846896 30.235839231846896 30.235839231846896 3.0000000000000466 3.0000000000000484 3.0000000000000502
      1000  297.22833117480451 0.96984490278280622 27788.463646610184 30.289226218453752 30.289226218453752 30.289226218453752 3.0000000000000426 3.0000000000000431 3.0000000000000435

rigid-nh-remap.diff.txt (4.3 KB)

Thank you for the patch!

I applied the changes to the LAMMPS develop branch and rebuilt LAMMPS. I then rerun the original NPT test.

The results confirm that the patch fixed the rigid-body geometry issue in this test case:

  • Maximum change in pairwise distances: 5.60e-14 Å

  • Maximum coordinate reconstruction error: 3.55e-15 Å

  • Box length Lx: 30.0 Å → 30.289226 Å over 1000 steps

The internal distances are now preserved to within floating-point precision, even as the simulation box changes.

I’d also be happy to help with additional testing or contribute a regression test if that would be useful.

Thank you again for investigating and fixing this issue!

@ndtrung Following up on my test results above: the internal geometry is preserved, but while reviewing the patch I noticed a possible issue with the center-of-mass mapping.

In FixRigidNHSmall::remap(), the new explicit x2lamda() loop transforms the COM coordinates before the existing rfix loop calls deform(0). Since rfix includes the fix itself, FixRigidSmall::deform(0) appears to transform the same COM coordinates a second time.

Similarly, after changing the box, both the explicit lamda2x() loop and deform(1) transform the COM coordinates back. I see the same pattern in the non-small version.

For a simple orthogonal-box mapping, this would scale the separation between two COMs by (L_new/L_old)^2 instead of L_new/L_old.

Could you check whether the additional explicit COM transformation loops are needed, given the existing deform() calls? I have not yet verified this in a dedicated COM test, but I will follow up with numerical results.

@Flower101010 thanks for pointing that out. We just need to remove the new explicit x2lamda() and lamda2x()loops that transform the body COM and let the deform() functions do the job.

Could you try the attached patch to develop? I suppose this way it is cleaner than applying on top of the previous patch.

rigid-nh-remap2.diff.txt (3.8 KB)

@ndtrung Thank you for the revised patch. I found one MPI synchronization issue and have a question about the COM integration coefficient.

1. COM synchronization in the small variant

The INITIAL forward communication still occurs before the second remap(). Since FixRigidSmall::deform() updates only owned body COMs, ghost COMs are stale when set_xv() reconstructs the atoms.

I’ve attached a minimal reproducer with standalone LAMMPS inputs, logs, and coordinate dumps for four cases. It uses three particles in one rigid body, zero forces and initial velocities, and one timestep. The maximum internal-distance change is:

  • One MPI rank, NPH: 1.78e-15

  • Two ranks, body crossing the domain boundary, NPH: 1.23e-3

  • Two ranks, body within one domain, NPH: 1.78e-15

  • Two ranks, body crossing the domain boundary, NVE: 0

All NPH cases produce the same box change. The affected atoms’ position errors match a COM missing the second remap to within 2.2e-15. The pre-patch code appears to have a similar synchronization gap, although I have only tested the revised patch.

2. COM drift coefficient

With the COM drift now between the two box half steps, should scale_v retain the exp(tmp) factor? The drift displacement is subsequently scaled by the second remap(). For a fixed-rate position substep, this appears to introduce an extra half-step exponential factor. Could you check whether the coefficient is consistent with the revised splitting? I have not yet tested this second point numerically.

remap_mpi_probe.zip (12.9 KB)

I’d also be happy to turn the reproducer into a regression test or help with the remaining fixes through a pull request, if that would be useful. This would be my first contribution to LAMMPS, and I’d appreciate any guidance on how best to proceed. Thank you for working on the fixes and discussing the implementation with me.

@Flower101010 thanks for doing these helpful tests.

For (1), could you try the attached patch to develop? I have added the forward communication for the body xcm inside FixRididSmallNH::remap() to sync the body COM across the procs. I tested with 8 MPI procs with your input in npt to recover the 1e-14 differences in the internal displacements. This issue does not apply to FixRigidNH::remap() because the bodies are replicated across all the procs.

For (2), the updates to xcm made in remap()(in both places) are due to the box dims half-step updates (leaving the relative position of the COM to the box dims unchanged), whereas scale_vrepresents the actual effects of the barostat on the body COM (changing the relative position of the COM to the box dims). What you called COM drift is indeed the xcm update in initial_integrate(). I think there is no extra exp(tmp) to scale_v due to the second remap(), unless you show me that it’s the case.

To contribute a regression test, you may add an input to examples/rigid and a reference log file, similar to the existing input scripts and reference log files.

If we can resolve the issues reported here, let’s submit a pull request with the final version of the changes to develop and input deck and reference log file.

rigid-nh-remap3.diff.txt (5.5 KB)

@ndtrung Thank you for the updated patch and your work on this. I have confirmed that issue (1) is fixed.

For (2), my concern is specifically the composition of the two half-step remaps with the intervening COM drift. Let h=\Delta t, b=\texttt{epsilon\_dot}, z=bh/2, and r=e^z. Let y=x_{\rm cm}-c denote the COM position relative to the box center, and u the COM velocity after the half-kick and velocity scaling.

The intended frozen-b, frozen-u position substep,

\dot y=u+by,

has the exact map

y'=r^2y+hr\,\frac{\sinh z}{z}\,u.

Each half-step remap() maps y\to ry. Thus, with an intermediate drift y\to y+Cu, their composition is

y'=r^2y+rCu,

which requires C=h\,\sinh(z)/z.

The current scale_v instead gives C=hr\,\sinh(z)/z, up to the series truncation, so the second remap introduces an extra factor r in the velocity contribution. For this ordering, I believe scale_v should therefore be

scale_v = dtv * maclaurin_series(tmp);

without exp(tmp).

@Flower101010 thanks for the maths. I think you are correct that splitting the box volume changes with 2 remap()steps before and after the xcm update causes the issue with the second remap(). Removing exp(z) in scale_vis one option.

I have revisisted Kamberaj et al (particularly Step 1, eq (6) for xcm in page 224114-16). I initially thought that splitting the box volume changes into 2 remap()calls was necessary so to put the Kameraj et al algorithm in the velocity Verlet framework, but it turnes out not the case, because both box volume changes and xcm update are done to the full step within Step 1 already.

To be consistent with the reference, we can simply use a single remap()with the full step after xcm is already scaled with the current scale_v. The extra benefit is that we remove the computational overhead of one remap().

Could you try the attached patch to develop? A single remap() call with full time step, after xcm is already updated.

rigid-nh-remap4.diff.txt (6.3 KB)

@ndtrung Thank you for revisiting the derivation and providing the updated patch. I had also been considering combining the two half-step remaps into a single full-step remap, so I agree with this approach. The full-step remap and COM drift in remap4 now reproduce the position update in Step 1(6), page 224114-16.

I have spent days working through both the theory in Kamberaj et al. and its implementation in LAMMPS. During that comparison, I noticed three further discrepancies:

  1. Rotational barostat factor. Equation (66) uses d\,\xi_\epsilon/g_f. Since mtk_term2 already contains the sum of the controlled strain rates divided by g_f, multiplying it by pdim again introduces an extra factor. The rotational scaling should use mtk_term2 directly.

  2. Barostat half-step pairing. Equation (64), Step 1(1–2) and Step 2(7–8), requires pressure kick → thermostat scaling at the beginning of each timestep, and the reverse order at the end. In the existing code, nh_epsilon_dot() is called during setup() and once in final_integrate(), leaving the initial half-step absent on subsequent timesteps. The attached changes move that half-step into initial_integrate() and reverse the operation order for the final half-step.

  3. Epsilon bookkeeping. Equation (64), Step 1(3), advances epsilon by a full timestep. With one full-step remap(), the bookkeeping increment should therefore use dtv, matching the actual logarithmic box-length change, rather than dtq.

I have attached a cumulative diff against develop that retains your remap4 changes and addresses these three items, including the corresponding helper declarations and accelerator call sites.

rigid_diff.patch (16.6 KB)

@Flower101010 thanks for carefully walking through the implementation and for sharing the patch. These are very good catches, particularly (1) and (2) which are independent of the full-step remap() here.

I plan to create a pull request to the LAMMPS develop branch. Do you have a GitHub account?

Best,

-Trung

@ndtrung
Yes, I do have a GitHub account:

Thank you for taking the time to review the implementation and for planning to submit the fixes upstream. I really appreciate it!