Compute density of system

Hello all,

I want to measure the density of my system. I searched the user manual, but only I found how to calculate 1d density. Does LAMMPS compute the density of system? if yes, how can I do that?


calculate mass of all atoms using variable group mass command, divide it by the volume, and multiply with the correct prefactor to get the density in desired units.

How many times have I done that calculation? It should really be a
keyword in thermo custom. In the meantime, you can trick LAMMPS in to
giving you the system density using fix ave/spatial:

variable nbins equal 1
variable zbin equal lz/\{nbins\} fix 3 all ave/spatial 1 1 1 z lower {zbin} density/mass
variable rho0 equal f_3[1][3]
print "Initial density in first bin is \{rho0\} g/cc" run 0 print "Final density in first bin is {rho0} g/cc"

I just added the keyword density to the thermo_style command. It will
appear in the next release.