computing per atom pe

I want to calculate pe/atom for all atoms, every 500 steps, for example. There may be two methods:

Method I:

http://lammps.sandia.gov/threads/msg32312.html

I need to have the number of atoms to calculate “pe per atom” = pe/(# of atoms)

compute pe all pe
(???variable natom equal N_atoms ???)
variable peratom equal (c_pe / v_natom)
fix peratom all ave/time 5 99 500 v_peratom file tmp.peratom

Of course, I can do this after finishing the simulation (by knowing pe and # of atoms), but is there any method to calculate pe/(# of atoms) during simulation to avoid post-processing each time? How can I have have the variable # of atoms?

Method II:

I also tried these commands:

compute peratom all pe/atom
fix peratom all ave/atom 5 99 500 c_peratom
dump peratom all custom 500 tmp.peratom f_peratom

But this saves the average of pe/atom for each atom every 500 steps. I need only one average for all the atoms.

Can you please help regarding any of these two methods?
Thank you

I want to calculate pe/atom for all atoms, every 500 steps, for example.
There may be two methods:

Method I:

http://lammps.sandia.gov/threads/msg32312.html

I need to have the number of atoms to calculate "pe per atom" = pe/(# of
atoms)

compute pe all pe
(???variable natom equal N_atoms ???)
variable peratom equal (c_pe / v_natom)

have you tried this?

variable peratom equal (pe/atoms)

equal style variables have access to all keywords that can be used
with thermo style custom.

fix peratom all ave/time 5 99 500 v_peratom file tmp.peratom

Of course, I can do this after finishing the simulation (by knowing pe and #
of atoms), but is there any method to calculate pe/(# of atoms) during
simulation to avoid post-processing each time? How can I have have the
variable # of atoms?

Method II:

I also tried these commands:

compute peratom all pe/atom
fix peratom all ave/atom 5 99 500 c_peratom
dump peratom all custom 500 tmp.peratom f_peratom

But this saves the average of pe/atom for each atom every 500 steps. I need
only one average for all the atoms.

to get the average over atomic properties, you would use compute
reduce ave, but this is less efficient than the first method.