Fix ave/spatial with spherical bins

Hello everyone,

We've recently adapted fix ave/spatial to use concentric spherical shell
bins. It's proved useful for calculating things like radial temperature
profiles in spherical geometries (systems with nanoparticles, etc.).
There was a similar fix posted on the list a few years ago
(, but since that was
posted a couple of changes have been made which prevent it from
compiling. I mentioned this a little while ago, and have since had a few
questions, so I've attached the source and some documentation.

A few caveats:

- the origin of the sphere can be given by a variable, or by a compute.
For example, you can "attach" the sphere to the centre of mass of a
group using compute com. If the origin moves outside of the box, and
PBCs are active, the origin will be wrapped back into the box whenever

- if reduced units are used, and the box is not cubic, the shells are
ellipsoidal rather than spherical. The calculated bin volumes are always
in box units, and reflect this.

- every time the fix is invoked, there needs to a be a sqrt() for every
particle which is located in the sphere. This can start to get a bit
sluggish if lots of particles fall in this region, or if you apply
several different instances of this fix simultaneously.

- if scaled units are used and the box size changes, the bin volumes are
automatically adjusted. Densities are calculated at every invocation,
using the current volumes, so the density remains correct.

- no checks are made about the sanity of the choice of sphere. If r_max
is chosen to be three times the box length, that's what the fix will try
to create.

Hope this helps those who have been looking for spherical bins,


fix_ave_spatial_spherical.txt (15.2 KB)

fix_ave_spatial_spherical.cpp (36.2 KB)

fix_ave_spatial_spherical.h (6.17 KB)

fix_ave_spatial_spherical.html (16.5 KB)

Hi Niall - I’m releasing this code as part of a patch today.

I think it’s a nice optional way to do per-atom averaging.

FYI, I renamed if fix ave/spatial/sphere and make lattice units
the default (like all other LAMMPS commands).

Any interest in making a fix ave/spatial/cylinder with 1d or 2d bins,
radial and (optionally) along the cylinder axis?

There has been some interest expressed in that kind of binning
in the past.

Thanks for working on this,

Thanks for that Steve - I should be able to put together a cylindrical version this weekend.