[lammps-users] lammps fix spring/couple through periodic boundary

Dear all,
I’m trying to simulation friction by dragging a tip along some surface by applying a harmonic force to the tip in the direction of motion. I’d like to do this by using fix rigid on the tip, and then using fix spring to couple the tip to an atom (I’ll refer to this as the bob) which moves with constant velocity. My problem is as follows. When the bob moves across the periodic boundary, I find the drag force immediately change the direction. But according to the code of fix_spring.cpp, the force is calculating as fellow
dx = xcm2[0] - xcm[0] - xc;
dy = xcm2[1] - xcm[1] - yc;
dz = xcm2[2] - xcm[2] - zc;
fx = k_springdxdr/r;
fy = k_springdydr/r;
fz = k_springdzdr/r;
the xcm is the mass centre of the tip and the xcm2 is the position of the bob.

From the code of group.cpp, we find the mass centre is calculating as fellow

xbox = (image[i] & 1023) - 512;
ybox = (image[i] >> 10 & 1023) - 512;
zbox = (image[i] >> 20) - 512;
massone = mass[type[i]];
cmone[0] += (x[i][0] + xboxxprd) * massone;
cmone[1] += (x[i][1] + ybox
yprd) * massone;
cmone[2] += (x[i][2] + zbox*zprd) * massone
cm[0] /= masstotal;
cm[1] /= masstotal;
cm[2] /= masstotal;
the image note the times of atom across the periodic boundary
so it seems when the bob atom across the boundary, the calculated position will be its unwrapped position, and the dragging force will not change direction.
Is this a bug of lammps? Does someone know a method or how to change the code to make the dragging force is calculated using the unwrapped position when the bob atom across the boundary.
Yilun Liu

Paul - do you want to look at this. This is for
the fix spring couple command between 2 groups. It's unclear
to me what the behavior should be across PBC, but I think
Yulin is correct that due to the unwrapping in the COM calculation,
it should not flip sign.