I know there have been posts about “ghost atoms in the Virial stress calculation,” but I am still not very clear when dealing with my specific simulation.

My system is periodic and I use Class 2 force filed.
I checked the pair_style lj/class2 .cpp code, but didn’t find “ghost atoms” are considered there.

My question is: for Class2 force field, does ghost atom play a role in pairwise interaction and in Virial part of the stress tensor?

What command or conditions make the ghost atoms work?

Ghost atoms are an internal feature
of LAMMPS. Users rarely need to
think about them. If you use a class2
potential and compute the virial or pressure,
you should just get the right answer.

The reason that I concern the role of ghost atom is: I didn't get the same
results for the Virial term in the "compute pressure tensor."

Using the equation in the doc page http://lammps.sandia.gov/doc/compute_pressure.html
and using the output values of atom's coordinates and force per atom, my
virial result is not the same as the Lammps virial output.

I guess the problem might be from the summation over the number of atoms N
(I didn't consider the ghost atoms in my summation).

ghost atoms don't work this way. any forces forces on ghost atoms are
communicated back to their respective local atom. however, the stress
tensor computed by LAMMPS differentiates between non-bonded
interactions (which can be tallied via F * r in the case of simple
pairwise additive potentials) and other contributions from bonded and
long range interactions, which have their own method to update the
stress tensor.

If you compute a virial by summing F dot r over all
atoms, then you do have to include ghost atoms. That’s
the only way to get the effect of periodic boundaries correct.

LAMMPS does this internally.

Again, from a user perspective (input script), you don’t
have to worry about this. But if you are writing code
yourself to add/modify LAMMPS, then of course you
have to understand more details.

Yes, In my own code for Virial stress, I calculated F dot r and sum over all the atoms in the period box (i.e. N = number of atoms in the box). I didn’t include any ghost atoms in my calculation, this could be the reason that I got different Virial stress than Lammps Virial stress output.

Just want to be clear, in Lammps Virial stress calculation, N = number of atoms in the box + ghost atoms . Is this right?