Issues with fix npt and fix recenter

I’ve been having an infrequently recurring issue when applying fix npt and fix recenter simultaneously, leading to a non numeric pressure error. The system I am simulating is a gold slab (with a drude oscillator dummy electron) in contact with water, an example of how I’m applying thermo/barostatting and the recentering is as follows:

fix integrate_water water npt temp 300.0 300.0 $(100.0*dt) iso 1.0 1.0 $(250*dt) dilate all
fix integrate gold nvt temp 300.0 300.0 $(100.0*dt)
fix drift gold_cores recenter INIT INIT INIT

In this case I encounter a non numeric pressure error after ~25-100fs, and the error seems to be very configuration dependent, and only seems to happen on larger systems (Where the water region is larger, rather than the gold slab being larger). I’ve tried different barostatting/thermostatting setups (including barostatting the entire system, barostatting the gold and only thermostatting the water, playing around with different barostat params etc.) but the only configuration I’ve found where the issue consistently doesn’t arise is when applying the fix recenter to the entire system, or applying fix recenter entirely under the nvt ensemble. This issue also doesn’t arise when applying fix momentum.

For my purposes, applying fix momentum or fix recenter to the entire system works perfectly fine, so I’m less looking for debugging help but was more wondering if this was an issue others had encountered, and/or if there was something I am missing?

It seems to me that you are misunderstanding what fix recenter does.
It allows you to change the frame of reference for the atoms in the fix group.
This means, the dynamics in the laboratory frame remain unchanged, but the atoms in the fix group are repositioned. This is useful, for example, if you want to study a moving object in a flowing matrix.
This is rarely what you want since it can hide an unphysical center of mass drift.

Another problem is when you apply the recentering only to a subset of atoms. This will introduce a relative motion between the atoms in the group and the atoms outside the group that is artificial.
That you get a non-numeric pressure would be due to atoms getting too close because of this unphysical enforce relative motion. As you stated, this does not happen when you use group all (but just using shift all as additional argument to the fix command should do the trick as well).

Fix momentum is different because it manipulates velocities instead of positions, so it will remove the unwanted net velocity but not make any changes to positions.

If your system is drifting in an undesired way, the first step is not to apply something like fix recenter (or fix momentum) but rather try to figure out what is inducing the drift. As you noted, this can be very system specific. Often, simulation settings like time step or details of the model and its symmetry or asymmetry can have an impact. Features like a barostat, especially when applied to an inhomogeneous system, can enhance that drift. Similarly, it is often introduced when there are regions with high potential energy (i.e. at the beginning of equilbration). This kind of drift can be removed statically with the velocity command and often this would be sufficient, as further buildup during production is minor (if all other settings are proper).

If the drift persist, you have to make a choice of how to deal with it. Using fix momentum can be a way, but so would be applying fix spring or fix spring/self. Fix recenter is usually not a good choice because the drift will persist but is just hidden.