Fix spring/self: displacement

Hello dear all,
I am trying to fix two groups of atoms in their initial positions using fix spring self command. The two groups are two graphene sheets. I fixed them in z direction and xy plane.
The documentation says fix spring/self computes a scalar(energy) value using 0.5Kr^2. while r is the displacement from initial position. So defining a variable r = sqrt(“fix spring/self value”/0.5/k) i should be able to calculate r.
when their potential force gets equal to spring/self force, they get stabled and almost fixed. now I want to calculate the spring force which is -k*r.

I also have defined a variable (D) to compute the distance of two sheets in z direction.
regarding the fact that groups don’t move in xy plane, i expected the two variables(D & r) to be approximately equal. However they are different by almost 2-3 orders of magnitudes! Am I getting the meaning of r wrong?

here is the commands I used in input script:

group g1 id <> 1 180
group g2 id <> 181 360

compute cg1 g1 com
compute cg2 g2 com

fix 1 g1 rigid single
fix 2 g2 rigid single

fix g1 g1 spring/self 3 z

fix g11 g1 spring/self 3 xy
fix g2 g2 spring/self 3 z
fix g22 g2 spring/self 3 xy

fix 3 all nvt temp 300.0 300.0 10

variable D equal (c_cg2[3]-c_cg1[3])

variable R equal sqrt(f_g1/0.5/3)
variable F equal -3*v_R

The best way to “debug” these kind of questions
is to break down the computation into small pieces
and verify that each is doing what you think. This
includes visualizing the system, pulling values
out of dump files to check that the calculation
you are doing in your script is consistent, etc.

Steve