The use of periodic boundaries appears to present a number of problems associated with the now infinite size of the system. For example, we have previously said that the total number of electrons, $N$, is equal to the integral of the density, $\rho(\mathbf{r})$, over all space, i.e.
$$
N=\int d\mathbf{r}\rho(\mathbf{r})
$$

Clearly, this would integrate to infinity under periodic boundary conditions. However, we can avoid such problems by adopting the following two conventions:

1.  Any integral in which the integrand is cell-periodic is taken over the extent of one unit cell only.
2.  Any integral in which the integrand is not cell periodic is taken over all space.

In the case of the Hartree energy, we have a further problem because while one of the integrals has a periodic integrand, the other does not due to the $1/\vert\mathbf{r}-\mathbf{r}'\vert$ Coulomb factor. The integral of this term over all space diverges, which would still lead to the Hartree energy being infinite. If we consider the electronic system alone, each electron is effectively interacting with an infinitely large distribution of negative charge, leading to an infinite energy. However, we also know that there is an equal amount of positive charge per unit cell due to the atomic nuclei, making the system charge neutral on average. Hence the average negative charge of the electrons is cancelled by the average positive charge of the nuclei - we only need to consider differences in the local charge density relative to the average. When using periodic boundary conditions, therefore, the correct equation for the Hartree energy is
$$
V_H=\frac{1}{2}\int d\mathbf{r}\int d\mathbf{r}'\frac{\rho(\mathbf{r})\rho(\mathbf{r}')}{\vert\mathbf{r}-\mathbf{r}'\vert}
$$
where $\langle\rho\rangle$ is the average density of the system. This term is usually not explicitly written down, but should always be taken to be present.

A similar problem arises when evaluating the external potential from the nuclear charges and when evaluating the contribution of nuclear-nuclear repulsive interaction to the total energy. Again, only differences from the average charge density need to be considered. The means by which the nuclear-nuclear repulsive interaction $V_{I-I}$ is dealt with is described in [reference](https://journals.aps.org/rmp/abstract/10.1103/RevModPhys.64.1045).