[lammps-users] Virial calculation

Fellow LAMMPS users,

   Is there a way by which I can output the virial from LAMMPS simulation for
each timestep? I am interested in knowing the quantity: SUM(fij.rij) for i<j for
each timestep, where fij is the vector force acting on i due to j and rij is the
distance vector from j to i and '.' represents the dot product between two vectors.

   Since I could not find a direct way to output virial, I thought of
calculating it from the pressure output in log file. For the case of a system of
particles interacting via LJ pair potential, I looked in the pair_lj_cut.cpp, in
the functions PairLJCut::compute(it eflag, int vflag) and
PairLJCut::compute_outer(it eflag, int vflag) the following code is used to
calculate virial:

Look in compute_pressure.cpp where all the virial terms
are summed (pair, bond, long-range etc). Then the kinetic
term is added in to get the pressure. You could print
out the virial there.

In the pair routines, the code you mention is b/c
the virial can be computed 2 ways, as Fij Rij or as Fi Ri. The
latter is cheaper, and works when you have ghost atoms
to account for periodic BC, so that's what LAMMPS does when
it can.