An inconsistency of calculating potential and force between two atoms in LAMMPS

Hello LAMMPS users:

I would like to get the energy and force between two atoms so I use the compute commend group/group to get the results:

Hello LAMMPS users:

I would like to get the energy and force between two atoms so I use the
compute commend group/group to get the results:

[...]

The second column, force_in, is the energy between atom 20 and 121
calculated by the group/group commends;
The third column, Eng, is the energy between atom 20 and 121 calculated by
LJ equation.
They should be the same but it shows difference in the results.

Do I miss some items of the equation for potential energy calculation
between two atoms?

you can rest assured that the lj/cut pair style gives correct answers.
...and compute group/group has been around long enough and much used
as well.
so the logical conclusion has to be, that it is most likely your
computation is wrong. whether it is the expression for energy and
force itself, or you need to properly account for minimum image
conventions, or something else, is for you to find out.

generate a simpler input with only two atoms and no periodic
boundaries and test again. then you can also output the per-atom
forces and energies from lj/cut as well.

axel.

Hello, Axel,

As you suggested, I calculate the energy and force between two atoms in non-periodic boundary condition system with 2 atoms. Both the group/group and LJ equation show the same result.
Why are the energy and force different in the more atoms cases? Does LAMMPS use different method to calculate the energy between two atoms in different atom’s number system?

The results are:

Hello, Axel,

As you suggested, I calculate the energy and force between two atoms in
non-periodic boundary condition system with 2 atoms. Both the group/group
and LJ equation show the same result.

Why are the energy and force different in the more atoms cases?

because LAMMPS takes periodic boundaries properly under consideration
and your manual calculation does not.

take your test system and turn on periodic boundary conditions,
individually for each direction and observe.
then increase the box dimensions by 10 angstrom each and observe again.
and finally move one of your atoms by 10 angstrom and observe one more time.

Does LAMMPS use different method to calculate the energy between two atoms in different
atom's number system?

no. LAMMPS does what your input prescribes it to do. your manual
calculation doesn't do the same, as you are ignoring many basic issues
of force computations with PBC.
compare the outputs of the various test system calculations very
carefully, draw your conclusions and read up on MD simulation basics
about periodic boundary conditions, about minimum image conventions
(and codes like LAMMPS that - by design - are not affected by them),
about cutoffs, about neighbor lists and related topics.

it is very commendable that you are making tests to validate your
simulations, but it is a bit surprising that you are getting confused
by these rather basic issues.

axel.