# A question about density calculation with regard to periodic boundary conditions

Hello,
I just thought about one question with regard to the density calculation of `gmx energy`. I have checked myself I think the way Gromacs calculate the density is to use the total mass of the system to divide the total volume. But I guess if periodic boundary conditions are applied, the mass of the atoms on the boundaries maybe should be counted partially. For example, if the atom is at the surface of the boundary, 1/2 of its mass should be counted. I am not sure whether I am thinking this correctly. If it is true, how much difference would be caused by this factor?
Any help would be much appreciated!

There is no need to divide masses. An atom that is at a boundary also has a corresponding void on the other “side” of the box, so the total mass occupies the specified volume.

Hello,
Thank you very much for the reply!
I have thought about this for a while. The way I think of the simulation box under the periodic boundary condition is similar to the unit cell of the lattice of a material. I have a sense that I might be wrong. But I am still unable to distinguish the difference between the two cases. Could you please help me to explain it a little bit more? Thanks very much in advance!

In a periodic system, everything is inside the box. Even an atom or group that appears to stick “out” of the central image is “in” with respect to the other side. So any apparent void is actually occupied. So there is a total volume that is occupied by a total mass, yielding the density.

Thank you very very much for all your detailed explanations! That helps me a lot.