For any $\alpha>0$, a neutral unit cell with volume $V$, formal charges $q_i$ at positions $r_i$, and $N_{\rm f.u.}$ formula units satisfies $M=-\frac{r_0}{N_{\rm f.u.}}\left[\frac12\sum_{i,j}\sum_n' q_iq_j\,\operatorname{erfc}(\alpha|r_i-r_j+n|)/|r_i-r_j+n| + \frac{2\pi}{V}\sum_{k\ne0}|\sum_i q_i e^{ik\cdot r_i}|^2\,e^{-|k|^2/(4\alpha^2)}/|k|^2 - \alpha\pi^{-1/2}\sum_i q_i^2\right]$, where $n$ runs over lattice translations, $k$ over nonzero reciprocal-lattice vectors, and the prime omits the term with $i=j$ and $n=0$
[1].