fix spring and periodic boundaries


I’ve been trying to use fix spring in the couple mode to perform umbrella sampling simulations and found that when separation vector between the two fix groups crosses a periodic boundary the forces/energy from the fix are incorrect (via comparing the forces/energies output from the fix to the analytic spring force/energy).

Checking the code I found that the minimum image convention wasn’t being applied when the separation vector between the groups was calculated.

  • specifically
    dx = xcm2[0] - xcm[0] - xc;
    dy = xcm2[1] - xcm[1] - yc;
    dz = xcm2[2] - xcm[2] - zc;

When I changed this to


(I confess I have only checked the case when the xc=yc=zc=0 but I think the should be subtracted off after the minimum image correction) the output from the fix agrees with the analytic value. I can’t think of any reason why the minimum image convention wasn’t being applied here (but am prepared to be corrected) - this would also affect simulations where the separation between the groups is comparable to half the box length.


The doc page explains that the COM (of each group in this case)
in computed in coordinates unwrapped by the image flags. When
this is done I don't think it should be necessary (or even correct
in some cases) to further apply minimum image corrections. What
is the geometry of your model, where this doesn't work? Also, I think
there are cases where people want to use fix spring with springs
longer than 1/2 the box. The unwrapping method should work
in any scenario, provided the initial image flags are set appropriately.
Axel may want to comment.


Hi Steve,

Embarrassingly after putting together test input files I found that the
original version was indeed giving the correct answer - guess the problem
must be elsewhere