how to compute the sum of |Zi-Zave|

Dear Sir,

I want to compute the value of image002.pngin lammps. Zi means the each atom’s coordinate in z direction of a certain region and Zave menas the average coordinate in z direction of the same region. The value of Zave is easy to obtain. However, I cannot get access to the value of every atom’s coordinate, and cannot use it to compute |Zi-Zave|. Actually, I want to know whether there is an instruction in lammps to calculate |Zi-Zave|, or how to output the value to logfile through defining variables. And I will be very grateful if you can send me some examples about the use of variable.

Look forward to your reply and thanks in advance.


See the doc page on atom-style variables. The per-atom
formula can contain an “atom vector”, such as z, which
means the z coord of each atom, or Zi in your notation.
You can then sum the atom vector via compute reduce.