How to calculate sum of (Xi-Xcm)^2 for each molecule?

Dear all,

Using the following commands I can calculate the Radius of gyration for molecules and the average of all molecules consequently:

compute mol Lubricant chunk/atom molecule
compute gyration Lubricant gyration/chunk mol
variable Rg equal ave(c_gyration)

The radius of gyration calculates the average per atomic mass of (Ri-Rcm)^2. But I want to also calculate the average distance in the X direction, i,e, (Xi-Xcm)^2 for the atoms of each molecule. is there any way to do that in LAMMPS?

Please see compute chunk/spread/atom command — LAMMPS documentation

Thank you.