\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[fleqn]{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{bm}
\usepackage{indentfirst}
\usepackage{xcolor}
%\usepackage[a4paper,includeheadfoot,margin=2.54cm]{geometry}


\date{}
% Shortcuts
% ---------
\newcommand{\mw}{MetalWalls}

% Math formatting command
% -----------------------

% Vectors are in bold
\renewcommand{\vec}[1]{\bm{#1}}

% Define erf and erfc as math functions
\DeclareMathOperator\erf{erf}
\DeclareMathOperator\erfc{erfc}

\author{Abel Marin-Lafleche}
\title{Ewald summation in 2D and 3D for a set of point charges and Gaussian charges}
\begin{document}
%
  \pagenumbering{gobble}
  \maketitle
  \newpage
  \pagenumbering{arabic}
%
  \section{Electrostatics with 2D periodic boundary conditions}  
  The ions in the bulk of the system have a point charge distribution,
  %
  \begin{equation} \label{eq:rho_point}
  \rho_i(\vec{r}) \equiv q_i \delta(\vec{r}-\vec{r}_i)
  \end{equation}
  %
where $\vec{r}_i$ and   $q_i$ are the position and the integral charge of the ion $i$, respectively, and $\delta(\vec{r})$ is the Dirac delta function.

  The atoms on the electrodes are modeled with a gaussian charge distribution, 
  %
  \begin{equation} \label{eq:rho_gaussian}
  \rho_i(\vec{r}) \equiv Q_i \left(\frac{\eta^2}{\pi}\right)^{3/2} e^{-\eta^2 |\vec{r}-\vec{r}_i|^2}
  \end{equation}
  %
where $\vec{r}_i$ and $Q_i$ are the position and the integral charge of the atom $i$, respectively, and $\eta$ is a model parameter.
  
  The simulation cell is an orthombic box with dimensions $a$, $b$ and $c$ in the $\vec{x}$, $\vec{y}$ and $\vec{z}$ direction, respectively. 2D periodic boundary conditions are applied in the $xy$-plane. The position of an ion or atom $i$ in the simulation box can be expressed by $\vec{r}_i = (x_i, y_i, z_i)$, where $0 \leq x_i < a$, $0 \leq y_i < b$ and $0 \leq z_i < c$.
  
  We define $\vec{\xi}_i \equiv (x_i,y_i,0)$ the projection of $\vec{r}_i$ in the $xy$-plane. Then we can write $\vec{r}_i = \vec{\xi}_i + z_i\vec{z}$. 
  
  We define the distance between two charges $i$ and $j$ by $\vec{r}_{ij} \equiv \vec{r}_j - \vec{r}_i$.
  
    We define the lattice vector $\vec{n} \equiv (n_xa,n_yb, 0)$, where $n_x, n_y \in \mathbb{Z}$ and the reciprocal lattice vector $\vec{k} \equiv (k_x\frac{2\pi}{a},k_y\frac{2\pi}{b}, 0)$, where $k_x, k_y \in \mathbb{Z}$.
    
  \subsection{Coulomb Energy}
  
  The total energy of the system due to Coulomb interaction is given by
  %
  \begin{align} \label{eq:Uc_integral}
  U_c &= 
  % point-point interactions
  \frac{1}{2} \sum_{i=1}^{N_{\mathrm{point}}} \sum_{j=1}^{N_{\mathrm{point}}} \sideset{}{'}\sum_{\vec{n}} \frac{q_iq_j}{|\vec{r}_{ij}+\vec{n}|} \\\nonumber
  % point-electrode interactions
  &+ \sum_{e=1}^{N_\mathrm{elec}} \sum_{i=1}^{N_{\mathrm{point}}} \sum_{j=1}^{N_e} \sum_{\vec{n}} \int_{\mathbb{R}^3} dr'' \left( \frac{\eta_e^2}{\pi}\right)^{3/2} \frac{q_iQ_{j_e}}{|\vec{r}_{ij_e} + \vec{r}'' + \vec{n}|} e^{-\eta_e^2 |\vec{r}''|^2} \\\nonumber
  % electrode-electrode interactions
  &+ \frac{1}{2}   \sum_{e'=1}^{N_\mathrm{elec}} \sum_{i_{e'}=1}^{N_{e'}} \sum_{e''=1}^{N_\mathrm{elec}} \sum_{j_{e''}=1}^{N_{e''}} \sum_{\vec{n}} \int_{\mathbb{R}^3} dr' \int_{\mathbb{R}^3} dr'' \left( \frac{\eta_{e'} \eta_{e''}}{\pi}\right)^{3} \frac{Q_{i_{e'}} e^{-\eta_{e'}^2 |\vec{r}'|^2} Q_{j_{e''}} e^{-\eta_{e''}^2 |\vec{r}''|^2}}{|\vec{r}_{i_{e'}j_{e''}} + \vec{r}'' - \vec{r}' + \vec{n}|}
  \end{align}
  
  We define the intermediate quantities,
  %
  \begin{align} 
  % point-point interactions  
  U_{c_{\mathrm{pp}}} &= 
  \frac{1}{2} \sum_{i=1}^{N_{\mathrm{point}}} \sum_{j=1}^{N_{\mathrm{point}}} \sideset{}{'}\sum_{\vec{n}} \frac{q_iq_j}{|\vec{r}_{ij}+\vec{n}|} \\
  % point-electrode interactions
  U_{c_{\mathrm{pg}}} &= 
  \sum_{e=1}^{N_\mathrm{elec}} \sum_{i=1}^{N_{\mathrm{point}}} \sum_{j=1}^{N_e} \sum_{\vec{n}} \int_{\mathbb{R}^3} dr'' \left( \frac{\eta_e^2}{\pi}\right)^{3/2} \frac{q_iQ_{j_e}}{|\vec{r}_{ij_e} + \vec{r}'' + \vec{n}|} e^{-\eta_e^2 |\vec{r}''|^2} \\
  % electrode-electrode interactions
  U_{c_{\mathrm{gg}}} &= 
  \frac{1}{2}   \sum_{e'=1}^{N_\mathrm{elec}} \sum_{i_{e'}=1}^{N_{e'}} \sum_{e''=1}^{N_\mathrm{elec}} \sum_{j_{e''}=1}^{N_{e''}} \sum_{\vec{n}} \int_{\mathbb{R}^3} dr' \int_{\mathbb{R}^3} dr'' \left( \frac{\eta_{e'} \eta_{e''}}{\pi}\right)^{3} \frac{Q_{i_{e'}} e^{-\eta_{e'}^2 |\vec{r}'|^2} Q_{j_{e''}} e^{-\eta_{e''}^2 |\vec{r}''|^2}}{|\vec{r}_{i_{e'}j_{e''}} + \vec{r}'' - \vec{r}' + \vec{n}|}
  \end{align}
  
  \subsection{Point charges system}
  First we consider only a system of point-charges. The energy is given by
  %
  \begin{equation} \label{eq:Uc_pp_integral}
  U_{c_{\mathrm{pp}}} = 
  \frac{1}{2} \sum_{i,j} \sideset{}{'}\sum_{\vec{n}} \frac{q_iq_j}{|\vec{r}_{ij}+\vec{n}|}
  \end{equation}
  %
  The sum over the lattice vector $\vec{n}$ is slowly convergent. In order to speed up the numerical calculation, the sum will be split into a short-range and long-range contributions. This is achieved by representing ${|\vec{r}_{ij} + \vec{n}|}^{-1}$  as an integral over a dummy variable via the identity
  %
  \begin{equation} \label{eq:r-1_identity}
  \frac{1}{r} = \frac{1}{\sqrt{\pi}} \int_{0}^{\infty}dt\,t^{-1/2}e^{-r^2t}
  \end{equation}
  %
  Using Equation (\ref{eq:r-1_identity}) into  Equation (\ref{eq:Uc_pp_integral}) 
  yields:
  %
  \begin{equation} 
  U_{c_{\mathrm{pp}}} = 
  \frac{1}{2\sqrt{\pi}} \sum_{i,j} q_iq_j \sideset{}{'}\sum_{\vec{n}} \int_{0}^{\infty}dt\,t^{-1/2}e^{-|\vec{r}_{ij}+\vec{n}|^2t} 
  \end{equation}
  %
  The integral over the dummy variable $t$ may be split up into two parts corresponding to short-range and long-range contributions of $1/r$:
  \begin{align}
  U_{c_{\mathrm{pp}}} &= 
  \frac{1}{2\sqrt{\pi}} \sum_{i,j} q_iq_j \sideset{}{'}\sum_{\vec{n}} \int_{\alpha^2}^{\infty}dt\,t^{-1/2}e^{-|\vec{r}_{ij}+\vec{n}|^2t} \\\nonumber
  & + \frac{1}{2\sqrt{\pi}} \sum_{i,j} q_iq_j \sideset{}{'}\sum_{\vec{n}} \int_{0}^{\alpha^2}dt\,t^{-1/2}e^{-|\vec{r}_{ij}+\vec{n}|^2t} 
  \end{align}
  %
  The short-range term can be directly computed with the substitution $t=u^2|\vec{r}_{ij}+\vec{n}|^2$:
  %
  \begin{align}
  U_{c_{\mathrm{pp}}}^{\mathrm{sr}}  
  &= \frac{1}{2} \sum_{i,j} q_iq_j \sideset{}{'}\sum_{\vec{n}} \frac{1}{\sqrt{\pi}} \int_{\alpha^2}^{\infty}dt\,t^{-1/2}e^{-|\vec{r}_{ij}+\vec{n}|^2t} \\\nonumber
  &= \frac{1}{2} \sum_{i,j} q_iq_j \sideset{}{'}\sum_{\vec{n}} \frac{2}{\sqrt{\pi}}\int_{\alpha|\vec{r}_{ij}+\vec{n}|}^{\infty}du\,|\vec{r}_{ij}+\vec{n}|^{-1}e^{-u^2} \\\nonumber
  &= \frac{1}{2} \sum_{i,j} q_iq_j \sideset{}{'}\sum_{\vec{n}} \frac{\erfc \left(\alpha|\vec{r}_{ij}+\vec{n}|\right)}{|\vec{r}_{ij}+\vec{n}|}
  \end{align}
  % 
  The long-range interaction term will be treated in Fourier space. For this we will use the Poisson summation formula:
  %
  \begin{equation} \label{eq:Jacobi_transformation}
  \sum_{n=-\infty}^{\infty}e^{-(x+na)^2t} = \frac{1}{a} \left(\frac{\pi}{t}\right)^{1/2} \sum_{k=-\infty}^{\infty} 
  e^{-\frac{\pi^2k^2}{a^2t} + \mathrm{i} \frac{2\pi kx}{a}}
   \end{equation}
%
  However, in order to be able to do this, we need complete periodicity and the sum needs to include the terms with $i=j$ and $\vec{n}=\vec{0}$. These self-interaction terms will be computed separately and subtracted from the value computed with the Fourier sums. First we compute the long-range term:
  %
  \begin{align}
  U_{c_{\mathrm{pp}}}^{\mathrm{lr}}  
  &= \frac{1}{2} \sum_{i,j} q_iq_j \sum_{\vec{n}} \frac{1}{\sqrt{\pi}} \int_{0}^{\alpha^2}dt\,t^{-1/2}e^{-|\vec{r}_{ij}+\vec{n}|^2t} \\\nonumber
    &= \frac{\sqrt{\pi}}{2ab} \sum_{i,j} q_iq_j \sum_{\vec{k}} \int_{0}^{\alpha^2}dt\,  t^{-3/2}e^{-z_{ij}^2t}
    e^{-\frac{|\vec{k}|^2}{4t}  + \mathrm{i} \vec{k}\cdot\vec{\xi}_{ij}} 
  \end{align}  
  %
  The term with $\vec{k} = \vec{0}$ in the sum needs to be treated separately from the other terms. Thus we split the sum into two terms, $U_{c_{\mathrm{pp}}}^{\mathrm{lr},*}$ and $U_{c_{\mathrm{pp}}}^{\mathrm{lr},0}$ :
  \begin{align}
  U_{c_{\mathrm{pp}}}^{\mathrm{lr},*}  
       &\equiv \frac{\sqrt{\pi}}{2ab} \sum_{i,j} q_iq_j \sum_{\vec{k}\neq \vec{0}} \int_{0}^{\alpha^2}dt\,  t^{-3/2}e^{-z_{ij}^2t}
    e^{-\frac{|\vec{k}|^2}{4t}  + \mathrm{i} \vec{k}\cdot\vec{\xi}_{ij}} \\
   U_{c_{\mathrm{pp}}}^{\mathrm{lr},0}  
       &\equiv  \frac{\sqrt{\pi}}{2ab} \sum_{i,j} q_iq_j \int_{0}^{\alpha^2}dt\,  t^{-3/2}e^{-z_{ij}^2t}
  \end{align}  
  
    Again we use a Fourier transform expression to write the $e^{-{z_{ij}}^2t}$ term as an integral over a dummy variable, since
  %
  \begin{equation} \label{eq:TFgauss_1D}
  e^{-z_{ij}^2t} = \frac{1}{2\sqrt{\pi t}} \int_{-\infty}^{+\infty} du\,e^{-\frac{u^2}{4t}+\mathrm{i}uz_{ij}}
  \end{equation}
  %   
  \begin{align}
  U_{c_{\mathrm{pp}}}^{\mathrm{lr,*}}  
    &= \frac{1}{4ab} \sum_{i,j} q_iq_j \sum_{\vec{k}\neq \vec{0}} \int_{0}^{\alpha^2} dt\int_{-\infty}^{\infty} du\,  t^{-2}
    e^{-\frac{|\vec{k}|^2 + u^2}{4t}  
    + \mathrm{i} \left(\vec{k}\cdot\vec{\xi}_{ij} + uz_{ij}\right)} \\\nonumber
  &= 
    \frac{1}{4ab} \sum_{i,j} q_iq_j \sum_{\vec{k}\neq \vec{0}} \int_{-\infty}^{\infty} du\, e^{\mathrm{i} \left(\vec{k}\cdot\vec{\xi}_{ij} + uz_{ij}\right)}
    \left[ \frac{4}{|\vec{k}|^2 + u^2} e^{-\frac{|\vec{k}|^2 + u^2}{4t}} \right]_{0}^{\alpha^2} \\\nonumber
  &= 
    \frac{1}{ab} \sum_{i,j} q_iq_j \sum_{\vec{k}\neq \vec{0}} \int_{-\infty}^{\infty} du\, e^{\mathrm{i} \left(\vec{k}\cdot\vec{\xi}_{ij} + uz_{ij}\right)}
   \frac{1}{|\vec{k}|^2 + u^2} e^{-\frac{|\vec{k}|^2 + u^2}{4\alpha^2}} \\\nonumber
     &= 
    \frac{1}{ab} \sum_{i,j} q_iq_j \sum_{\vec{k}\neq \vec{0}} \int_{-\infty}^{\infty} du\, 
   \frac{\cos \left(\vec{k}\cdot\vec{\xi}_{ij} + uz_{ij}\right)}{|\vec{k}|^2 + u^2}e^{-\frac{|\vec{k}|^2 + u^2}{4\alpha^2}}
  \end{align} 
%
  In order to simplify the term $U_{c_{\mathrm{pp}}}^{\mathrm{lr},0}$, we use integration by parts and make the hypothesis that the system of point-charges is charge neutral.
  %
  \begin{align}
   U_{c_{\mathrm{pp}}}^{\mathrm{lr},0}  
       &=  \frac{\sqrt{\pi}}{2ab} \sum_{i,j} q_iq_j \int_{0}^{\alpha^2}dt\,  t^{-3/2}e^{-z_{ij}^2t}  \\\nonumber
       &=  \frac{\sqrt{\pi}}{2ab} \sum_{i,j} q_iq_j \left(\left[-2t^{-1/2}e^{-z_{ij}^2t} \right]_{0}^{\alpha^2} - 2 z_{ij}^2 \int_{0}^{\alpha^2}dt\, t^{-1/2}e^{-z_{ij}^2t}\right) \\\nonumber
       &=  -\frac{\sqrt{\pi}}{ab} \sum_{i,j} q_iq_j  \left(\frac{e^{-z_{ij}^2 \alpha^2}}{\alpha} + \sqrt{\pi} |z_{ij}| \erf(\alpha |z_{ij}|) \right)    
  \end{align}
%
  Now we need to compute the self-interaction term to be able to subtract it from the long-range contribution:
  %
    \begin{align}
  U_{c_{\mathrm{pp}}}^{\mathrm{self}}  
    &=  \frac{1}{2} \sum_{i} q_i^2 \frac{1}{\sqrt{\pi}} \int_{0}^{\alpha^2}dt\,t^{-1/2} \\ \nonumber
    &= \frac{\alpha}{\sqrt{\pi}} \sum_{i} q_i^2
    \end{align}
%
Putting it all together, we have:
%    
 \begin{align}
    U_{c_{\mathrm{pp}}} 
    &=  \frac{1}{2} \sum_{i,j} q_iq_j \sideset{}{'}\sum_{\vec{n}} \frac{\erfc \left(\alpha|\vec{r}_{ij}+\vec{n}|\right)}{|\vec{r}_{ij}+\vec{n}|} \\
    \nonumber
    &+  \frac{1}{ab} \sum_{i,j} q_iq_j \sum_{\vec{k}\neq \vec{0}} \int_{-\infty}^{\infty} du\, 
   \frac{\cos \left(\vec{k}\cdot\vec{\xi}_{ij} + uz_{ij}\right)}{|\vec{k}|^2 + u^2}e^{-\frac{|\vec{k}|^2 + u^2}{4\alpha^2}} \\
   \nonumber
   &- \frac{\sqrt{\pi}}{ab} \sum_{i,j} q_iq_j  \left(\frac{e^{-z_{ij}^2 \alpha^2}}{\alpha} + \sqrt{\pi} |z_{ij}| \erf(\alpha |z_{ij}|) \right) \\
   \nonumber
   &- \frac{\alpha}{\sqrt{\pi}} \sum_{i} q_i^2
    \end{align}
    
  \subsection{Gaussian charges system}
  Now we consider only a system of gaussian charges. The energy is given by
  %
  \begin{equation} \label{eq:Uc_gg_integral}
  U_{c_{\mathrm{gg}}} = 
    \frac{1}{2} \sum_{i,j} Q_{i}Q_{j} \sum_{\vec{n}} \int_{\mathbb{R}^3} dr' \int_{\mathbb{R}^3} dr'' \left( \frac{\eta_{i} \eta_{j}}{\pi}\right)^{3} \frac{e^{-\eta_{i}^2 |\vec{r}'|^2} e^{-\eta_{j}^2 |\vec{r}''|^2}}{|\vec{r}_{ij} + \vec{r}'' - \vec{r}' + \vec{n}|}
  \end{equation}
  %
  The sum over the lattice vector $\vec{n}$ is slowly convergent. In order to speed up the numerical calculation, the sum will be split into a short-range and long-range contributions. This is achieved by representing ${|\vec{r}_{ij} + \vec{r}'' - \vec{r}' + \vec{n}|}^{-1}$  as an integral over a dummy variable via the identity
  %
  \begin{equation} \label{eq:r-1_identity3}
  \frac{1}{r} = \frac{1}{\sqrt{\pi}} \int_{0}^{\infty}dt\,t^{-1/2}e^{-r^2t}
  \end{equation}
  %
  Using Equation (\ref{eq:r-1_identity3}) into  Equation (\ref{eq:Uc_gg_integral}) 
  yields:
  %
  \begin{equation} 
  U_{c_{\mathrm{gg}}} = 
  \frac{1}{2\sqrt{\pi}} \sum_{i,j} Q_iQ_j \sum_{\vec{n}}  \int_{\mathbb{R}^3} dr' \int_{\mathbb{R}^3} dr''\int_{0}^{\infty}dt \left( \frac{\eta_{i} \eta_{j}}{\pi}\right)^{3} e^{-\eta_{i}^2 |\vec{r}'|^2} e^{-\eta_{j}^2 |\vec{r}''|^2} t^{-1/2}e^{-|\vec{r}_{ij} + \vec{r}'' - \vec{r}' + \vec{n}|^2t} 
  \end{equation}
  %
  Additionally, we use the following identity to express the gaussian exponentials as integrals over dummy variables:
  %
  \begin{equation} \label{eq:TFGauss_3D}
  \exp(-\eta^2|\vec{r}|^2) = (2\pi)^{-3}\frac{\pi^{3/2}}{\eta^3} \int_{\mathbb{R}^3} \exp\left(-\frac{|\vec{v}|^2}{4\eta^2} + \mathrm{i} \vec{v} \cdot \vec{r} \right) d\vec{v}
  \end{equation}
  
  Using Equation (\ref{eq:TFGauss_3D}) further yields
  \begin{align}
  U_{c_{\mathrm{gg}}} &= 
  \frac{1}{2\sqrt{\pi}} \sum_{i,j} Q_iQ_j \sum_{\vec{n}}  \int_{\mathbb{R}^3} dr' \int_{\mathbb{R}^3} dr''\int_{0}^{\infty}dt\,t^{-1/2} \\ \nonumber
  &\times e^{-|\vec{r}_{ij} + \vec{r}'' - \vec{r}' + \vec{n}|^2t} \\ \nonumber
  &\times (2\pi)^{-3} \int_{\mathbb{R}^3} \exp\left(-\frac{|\vec{v}|^2}{4\eta_{i}^2} + \mathrm{i} \vec{v} \cdot \vec{r}' \right) d\vec{v} \\ \nonumber
  &\times (2\pi)^{-3} \int_{\mathbb{R}^3} \exp\left(-\frac{|\vec{w}|^2}{4\eta_{j}^2} + \mathrm{i} \vec{w} \cdot \vec{r}'' \right) d\vec{w} 
  \end{align} 
  %
  And using Poisson summation formula (Equation (\ref{eq:Jacobi_transformation})) yields:
  %
  \begin{align}
  U_{c_{\mathrm{gg}}} &= 
  \frac{1}{2\sqrt{\pi}} \sum_{i,j} Q_iQ_j \sum_{\vec{k}}  \int_{\mathbb{R}^3} dr' \int_{\mathbb{R}^3} dr''\int_{0}^{\infty}dt\,t^{-1/2} \\ \nonumber
  &\times e^{-(z_{ij} + z'' - z')^2t} \\ \nonumber
  &\times \frac{1}{ab}\frac{\pi}{t} e^{-\frac{|\vec{k}|^2}{4t}+\mathrm{i}\vec{k}\cdot (\vec{\xi}_{ij} + \vec{\xi}'' - \vec{\xi}')} \\ \nonumber
  &\times (2\pi)^{-3} \int_{\mathbb{R}^3} \exp\left(-\frac{|\vec{v}|^2}{4\eta_{i}^2} + \mathrm{i} \vec{v} \cdot \vec{r}' \right) d\vec{v} \\ \nonumber
  &\times (2\pi)^{-3} \int_{\mathbb{R}^3} \exp\left(-\frac{|\vec{w}|^2}{4\eta_{j}^2} + \mathrm{i} \vec{w} \cdot \vec{r}'' \right) d\vec{w} 
  \end{align}
  % 
  Using Equation (\ref{eq:TFgauss_1D}) on the exponential term in $z_{ij} + z'' - z'$ yields:
  %
  \begin{align}
  U_{c_{\mathrm{gg}}} &= 
  \frac{1}{2\sqrt{\pi}} \sum_{i,j} Q_iQ_j \sum_{\vec{k}}  \int_{\mathbb{R}^3} dr' \int_{\mathbb{R}^3} dr''\int_{0}^{\infty}dt\,t^{-1/2} \\ \nonumber
  &\times \frac{1}{2\sqrt{\pi t}}\int_{-\infty}^{\infty}du\, e^{-\frac{u^2}{4t}+\mathrm{i}u\left(z_{ij} + z'' - z'\right)} \\ \nonumber
  &\times \frac{1}{ab}\frac{\pi}{t} e^{-\frac{|\vec{k}|^2}{4t}+\mathrm{i}\vec{k}\cdot (\vec{\xi}_{ij} + \vec{\xi}'' - \vec{\xi}')} \\ \nonumber
  &\times (2\pi)^{-3} \int_{\mathbb{R}^3} \exp\left(-\frac{|\vec{v}|^2}{4\eta_{i}^2} + \mathrm{i} \vec{v} \cdot \vec{r}' \right) d\vec{v} \\ \nonumber
  &\times (2\pi)^{-3} \int_{\mathbb{R}^3} \exp\left(-\frac{|\vec{w}|^2}{4\eta_{j}^2} + \mathrm{i} \vec{w} \cdot \vec{r}'' \right) d\vec{w} 
  \end{align}
  %
  Grouping terms in $\vec{r}'$ and in $\vec{r}''$ together yields two integral formulas of the $\delta$-function, where we defined $\vec{\kappa} \equiv \vec{k} + u\vec{z}$
    %
  \begin{align}
  U_{c_{\mathrm{gg}}} &= 
  \frac{(2\pi)^{-6}}{4ab} \sum_{i,j} Q_i Q_j \sum_{\vec{k}}  \int_{\mathbb{R}^3} d\vec{r}  \int_{\mathbb{R}^3} d\vec{w} \int_{-\infty}^{\infty}du \int_{0}^{\infty}dt\,t^{-2} \\ \nonumber
   &\times  e^{-\frac{|\vec{\kappa}|^2}{4t} + \mathrm{i} \vec{\kappa} \cdot \vec{r}_{ij}} \\ \nonumber
   &\times \exp\left(-\frac{|\vec{v}|^2}{4\eta_{i}^2}-\frac{|\vec{w}|^2}{4\eta_{j}^2}\right) \\ \nonumber
 &\times  \int_{\mathbb{R}^3} \exp\left( + \mathrm{i}(\vec{v}-\vec{\kappa}) \cdot \vec{r}' \right)  dr' \\ \nonumber
  &\times \int_{\mathbb{R}^3} \exp\left( + \mathrm{i} (\vec{w}+\vec{\kappa}) \cdot \vec{r}'' \right) dr''
 \end{align}
%  
 Using the integral formula for Dirac $\delta$-function, 
  \begin{equation} \label{eq:TFdirac_1d}
  \frac{1}{2\pi} \int_{-\infty}^{\infty} dx \exp \left( \mathrm{i} (k-k')x \right) = \delta (k-k') 
  \end{equation}
  %
  we can simplify the expression of $U_{c_{\mathrm{gg}}}$, with $\eta_{ij} \equiv \frac{\eta_i \eta_j}{\sqrt{\eta_i^2 + \eta_j^2}}$:
      %
  \begin{align}
    U_{c_{\mathrm{gg}}} &= 
  \frac{1}{4ab} \sum_{i,j} Q_iQ_j \sum_{\vec{k}} \int_{-\infty}^{\infty}du \int_{0}^{\infty}dt\,t^{-2} \\ \nonumber
  &\times 
  \exp\left(-\frac{|\vec{\kappa}|^2}{4t} + \mathrm{i} \vec{\kappa}\cdot \vec{r}_{ij}\right)
   \exp\left(-\frac{|\vec{\kappa}|^2}{4\eta_{ij}^2}\right) \\ \nonumber
  \end{align}
  % 
  Before going forward and splitting the energy term into short-range and long-range contributions, we apply the substitution $t' = \frac{\eta_{ij}^2t}{t + \eta_{ij}^2}$:
  %
    \begin{equation}
    U_{c_{\mathrm{gg}}} = 
  \frac{1}{4ab} \sum_{i,j} Q_iQ_j \sum_{\vec{k}} \int_{-\infty}^{\infty}du \int_{0}^{\eta_{ij}^2}dt'\,t'^{-2} \exp\left(-\frac{|\vec{\kappa}|^2}{4t'} + \mathrm{i} \vec{\kappa}\cdot \vec{r}_{ij}\right)
  \end{equation}
  % 
  
  The integral over the dummy variable $t$ may be split up into two parts corresponding to short-range and long-range contributions of $1/r$:
  \begin{align}
  U_{c_{\mathrm{gg}}} &= 
   \frac{1}{4ab} \sum_{i,j} Q_iQ_j \sum_{\vec{k}} \int_{-\infty}^{\infty}du \int_{0}^{\alpha^2}dt'\,t'^{-2} \exp\left(-\frac{|\vec{\kappa}|^2}{4t'} + \mathrm{i} \vec{\kappa}\cdot \vec{r}_{ij}\right) \\
   \nonumber
   &+ \frac{1}{4ab} \sum_{i,j} Q_iQ_j \sum_{\vec{k}} \int_{-\infty}^{\infty}du \int_{\alpha^2}^{\eta_{ij}^2}dt'\,t'^{-2} \exp\left(-\frac{|\vec{\kappa}|^2}{4t'} + \mathrm{i} \vec{\kappa}\cdot \vec{r}_{ij}\right)
  \end{align}
  %
  In order to compute the short-range term we need first to revert back to real space:
  %
  \begin{align}
  U_{c_{\mathrm{gg}}}^{\mathrm{sr}}  
  &= \frac{1}{4ab} \sum_{i,j} Q_iQ_j \sum_{\vec{k}} \int_{-\infty}^{\infty}du \int_{\alpha^2}^{\eta_{ij}^2}dt'\,t'^{-2} \exp\left(-\frac{|\vec{\kappa}|^2}{4t'} + \mathrm{i} \vec{\kappa}\cdot \vec{r}_{ij}\right) \\\nonumber
  &= \frac{1}{2\sqrt{\pi}} \sum_{i,j} Q_iQ_j \sum_{\vec{n}} \int_{\alpha^2}^{\eta_{ij}^2}dt'\,t'^{-1/2} e^{-|\vec{r}_{ij} + \vec{n}|^2t} \\\nonumber
    \end{align}
 %
 The real-space terms are computed through the substitution $t=u^2|\vec{r}_{ij}+\vec{n}|^2$:
  \begin{align}
    U_{c_{\mathrm{gg}}}^{\mathrm{sr}}  &=
     \frac{1}{\sqrt{\pi}} \sum_{i,j} Q_iQ_j \sideset{}{'}\sum_{\vec{n}} \int_{\alpha|\vec{r}_{ij} + \vec{n}|}^{\eta_{ij}|\vec{r}_{ij} + \vec{n}|}du\,|\vec{r}_{ij} + \vec{n}|^{-1}e^{-u^2}
   \\\nonumber
  &= \frac{1}{2} \sum_{i,j} Q_iQ_j \sideset{}{'}\sum_{\vec{n}} |\vec{r}_{ij} + \vec{n}|^{-1} \left( \erfc(\alpha|\vec{r}_{ij} + \vec{n}|) - \erfc (\eta_{ij}|\vec{r}_{ij} + \vec{n}|)\right)
   \\\nonumber
  %%%
  \end{align}

  The long-range interaction term will be treated in Fourier space. 
  %
  \begin{align}
  U_{c_{\mathrm{gg}}}^{\mathrm{lr}} &= 
   \frac{1}{4ab} \sum_{i,j} Q_iQ_j \sum_{\vec{k}} \int_{-\infty}^{\infty}du \int_{0}^{\alpha^2}dt'\,t'^{-2} \exp\left(-\frac{|\vec{\kappa}|^2}{4t'} + \mathrm{i} \vec{\kappa}\cdot \vec{r}_{ij}\right) \\
   \nonumber
   \end{align}
   %
   This expression is identical to the one computed for a point charge system. Therefore, we use the same decomposition between the $\vec{k}=\vec{0}$ term and the other terms and get the same expression:
     %   
  \begin{align}
  U_{c_{\mathrm{gg}}}^{\mathrm{lr,*}}  
     &= 
    \frac{1}{ab} \sum_{i,j} Q_iQ_j \sum_{\vec{k}\neq \vec{0}} \int_{-\infty}^{\infty} du\, 
   \frac{\cos \left(\vec{k}\cdot\vec{\xi}_{ij} + uz_{ij}\right)}{|\vec{k}|^2 + u^2}e^{-\frac{|\vec{k}|^2 + u^2}{4\alpha^2}} \\
   \nonumber
      U_{c_{\mathrm{gg}}}^{\mathrm{lr},0}  &=
      -\frac{\sqrt{\pi}}{ab} \sum_{i,j} Q_iQ_j  \left(\frac{e^{-z_{ij}^2 \alpha^2}}{\alpha} + \sqrt{\pi} |z_{ij}| \erf(\alpha |z_{ij}|) \right)
  \end{align} 
%
 The self-interaction term can be collectively taken into account as:
   \begin{align}
    U_{c_{\mathrm{gg}}}^{\mathrm{self}}  &=
    \frac{1}{2\sqrt{\pi}} \sum_{i} Q_i^2 \int_{\alpha^2}^{\eta_{ij}^2}dt'\,t'^{-1/2} \\\nonumber
    &=  \frac{1}{\sqrt{\pi}} \sum_{i} Q_i^2 \left( \frac{\eta_{i}}{\sqrt{2}} - \alpha \right)
  \end{align}
%
Putting it all together, we have:
%    
 \begin{align}
    U_{c_{\mathrm{gg}}} 
    &=  \frac{1}{2} \sum_{i,j} Q_iQ_j \sideset{}{'}\sum_{\vec{n}} |\vec{r}_{ij} + \vec{n}|^{-1} \left( \erfc(\alpha|\vec{r}_{ij} + \vec{n}|) - \erfc (\eta_{ij}|\vec{r}_{ij} + \vec{n}|)\right) \\
    \nonumber
    &+  \frac{1}{ab} \sum_{i,j} Q_iQ_j \sum_{\vec{k}\neq \vec{0}} \int_{-\infty}^{\infty} du\, 
   \frac{\cos \left(\vec{k}\cdot\vec{\xi}_{ij} + uz_{ij}\right)}{|\vec{k}|^2 + u^2}e^{-\frac{|\vec{k}|^2 + u^2}{4\alpha^2}} \\
   \nonumber
   &- \frac{\sqrt{\pi}}{ab} \sum_{i,j} Q_iQ_j  \left(\frac{e^{-z_{ij}^2 \alpha^2}}{\alpha} + \sqrt{\pi} |z_{ij}| \erf(\alpha |z_{ij}|) \right) \\
   \nonumber
   &+ \frac{1}{\sqrt{\pi}} \sum_{i} Q_i^2 \left( \frac{\eta_{i}}{\sqrt{2}} - \alpha \right)
    \end{align}
    
\subsection{Gaussian charges and Point charges system}

In a system where gaussian charges and point charges are in interaction, the Coulomb energy can be computed in an entirely analogous manner. We make the assumption of charge neutrality in each such sub-system. The total energy of the system is the sum of the energy of the point charges subsystem, the energy of the gaussian charges subsystem and the interaction energy between the 2 subsystems. From the two previous sections we already know the first two terms of the energy. In this section, we compute the interaction energy.
\begin{align}
U_{c_{\mathrm{pg}}} &=
\sum_{i,j} \sum_{\vec{n}} \int_{\mathbb{R}^3} dr'' \left( \frac{\eta_j^2}{\pi}\right)^{3/2} \frac{q_iQ_{j}}{|\vec{r}_{ij} + \vec{r}'' + \vec{n}|} e^{-\eta_j^2 |\vec{r}''|^2} 
\end{align}
%
\begin{align}
U_{c_{\mathrm{pg}}}
    &=  \sum_{i,j} q_iQ_j \sum_{\vec{n}} |\vec{r}_{ij} + \vec{n}|^{-1} \left( \erfc(\alpha|\vec{r}_{ij} + \vec{n}|) - \erfc (\eta_{j}|\vec{r}_{ij} + \vec{n}|)\right) \\
    \nonumber
    &+  \frac{2}{ab} \sum_{i,j} q_iQ_j \sum_{\vec{k}\neq \vec{0}} \int_{-\infty}^{\infty} du\, 
   \frac{\cos \left(\vec{k}\cdot\vec{\xi}_{ij} + uz_{ij}\right)}{|\vec{k}|^2 + u^2}e^{-\frac{|\vec{k}|^2 + u^2}{4\alpha^2}} \\
   \nonumber
   &- \frac{2\sqrt{\pi}}{ab} \sum_{i,j} q_iQ_j  \left(\frac{e^{-z_{ij}^2 \alpha^2}}{\alpha} + \sqrt{\pi} |z_{ij}| \erf(\alpha |z_{ij}|) \right) 
  \end{align}

  \subsection{Evaluating the charges on the electrodes}
  
The Coulomb potential at site $i$ in electrode $e$ is $\frac{\partial U_c}{\partial Q_{ie}}$. When considering a system which is coupled to external electrodes, capable of sourcing or sinking charge to maintain a constant potential $V_e$, the equipotential constraint becomes
%
\begin{equation}
\frac{\partial U_c}{Q_{i_e}} = V_e
\end{equation}

Put another way, the charges rearrange themselves to minimize
%
\begin{equation} \label{eq:UT}
U_T = U_c -  \sum_{e=1}^{N_\mathrm{elec}} \sum_{i=1}^{N_e} V_eQ_{i_e}
\end{equation}

The second term represents the interaction between the charges on the metal and the external system holding the metal at the potentials $V_e$ . Equation (\ref{eq:UT}) is satisfied when $U_T$ is minimized with respect to the $Q_{i_e}$’s since the energy minimization implies $\frac{\partial U_T}{\partial Q_{i_e}}=0$.

The energy $U_T$ can be cast into a quadratic form:
%
\begin{equation} \label{eq:UT_quadratic}
U_T = \frac{1}{2} Q^T A Q - b^T Q + c
\end{equation} 
%
where $Q$ and $b$ are vectors of  size $N_{\mathrm{gauss}}=\sum_{e=1}{N_\mathrm{elec}} N_e$, $A$ is an $N_{\mathrm{gauss}} \times N_{\mathrm{gauss}}$ matrix and $c$ is a scalar. 
%
Introducing the notation from the previous sections, we can see that:
\begin{align}
\frac{1}{2} Q^T A Q &= U_{c_{\mathrm{gg}}} \\ 
b^T Q &= V^TQ - U_{c_{\mathrm{pg}}} \\ 
c &= U_{c_{\mathrm{pp}}}
\end{align}

$A$ is a symmetric positive-definite matrix (provided that $\eta$ is chosen large enough) and therefore there exists a single minimum vector $Q$ to Equation (\ref{eq:UT_quadratic}). The minimum energy is obtained for the vector $Q$ satisfying the relationship $AQ = b$. In order to be able to use an iterative method to find the appropriate value of $Q$ we need to be able to compute $AQ$ and $b$. This is easily obtained from the results of the previous sections:
\begin{align}
AQ_i &= 
    \sum_{j} Q_j \sideset{}{'}\sum_{\vec{n}} |\vec{r}_{ij} + \vec{n}|^{-1} \left( \erfc(\alpha|\vec{r}_{ij} + \vec{n}|) - \erfc (\eta_{ij}|\vec{r}_{ij} + \vec{n}|)\right) \\
    \nonumber
    &+  \frac{2}{ab} \sum_{j} Q_j \sum_{\vec{k}\neq \vec{0}} \int_{-\infty}^{\infty} du\, 
   \frac{\cos \left(\vec{k}\cdot\vec{\xi}_{ij} + uz_{ij}\right)}{|\vec{k}|^2 + u^2}e^{-\frac{|\vec{k}|^2 + u^2}{4\alpha^2}} \\
   \nonumber
   &- \frac{2\sqrt{\pi}}{ab} \sum_{j} Q_j  \left(\frac{e^{-z_{ij}^2 \alpha^2}}{\alpha} + \sqrt{\pi} |z_{ij}| \erf(\alpha |z_{ij}|) \right) \\
   \nonumber
   &+ \frac{2}{\sqrt{\pi}} Q_i \left( \frac{\eta_{i}}{\sqrt{2}} - \alpha \right) \\
%   
   b_i &= V_i \\ \nonumber
        &- \sum_{j} q_j \sum_{\vec{n}} |\vec{r}_{ij} + \vec{n}|^{-1} \left( \erfc(\alpha|\vec{r}_{ij} + \vec{n}|) - \erfc (\eta_{j}|\vec{r}_{ij} + \vec{n}|)\right) \\
    \nonumber
    &-  \frac{2}{ab} \sum_{j} q_j \sum_{\vec{k}\neq \vec{0}} \int_{-\infty}^{\infty} du\, 
   \frac{\cos \left(\vec{k}\cdot\vec{\xi}_{ij} + uz_{ij}\right)}{|\vec{k}|^2 + u^2}e^{-\frac{|\vec{k}|^2 + u^2}{4\alpha^2}} \\
   \nonumber
   &+ \frac{2\sqrt{\pi}}{ab} \sum_{j} q_j \left(\frac{e^{-z_{ij}^2 \alpha^2}}{\alpha} + \sqrt{\pi} |z_{ij}| \erf(\alpha |z_{ij}|) \right)
\end{align}

  \subsection{Forces on the mobile point charges}
 \begin{align}
    \vec{F}_{c_{\mathrm{pp}},i} &= - \vec{\nabla}_i U_{c_{\mathrm{pp}}} \\
    F_{c_{\mathrm{pp}},i,x} 
    &= -\sum_{j} q_iq_j \sideset{}{'}\sum_{\vec{n}} \left( \frac{2 \alpha}{\sqrt{\pi}} e^{-\alpha^2 |\vec{r}_{ij}+\vec{n}|^2} + \frac{\erfc(\alpha |\vec{r}_{ij}+\vec{n}|)}{|\vec{r}_{ij}+\vec{n}|}  \right)  \frac{x_{ij}+n_xa}{|\vec{r}_{ij}+\vec{n}|^2} \\ \nonumber
    &- \frac{2}{ab} \sum_{j} q_iq_j \sum_{\vec{k}\neq \vec{0}} \int_{-\infty}^{\infty} du\, 
   \frac{2\pi k_x}{a}\frac{\sin \left(\vec{k}\cdot\vec{\xi}_{ij} + uz_{ij}\right)}{|\vec{k}|^2 + u^2}e^{-\frac{|\vec{k}|^2 + u^2}{4\alpha^2}} \\ 
   %
    F_{c_{\mathrm{pp}},i,y} 
    &= -\sum_{j} q_iq_j \sideset{}{'}\sum_{\vec{n}} \left( \frac{2 \alpha}{\sqrt{\pi}} e^{-\alpha^2 |\vec{r}_{ij}+\vec{n}|^2} + \frac{\erfc(\alpha |\vec{r}_{ij}+\vec{n}|)}{|\vec{r}_{ij}+\vec{n}|}  \right)  \frac{y_{ij}+n_yb}{|\vec{r}_{ij}+\vec{n}|^2} \\ \nonumber
    &- \frac{2}{ab} \sum_{j} q_iq_j \sum_{\vec{k}\neq \vec{0}} \int_{-\infty}^{\infty} du\, 
   \frac{2\pi k_y}{b}\frac{\sin \left(\vec{k}\cdot\vec{\xi}_{ij} + uz_{ij}\right)}{|\vec{k}|^2 + u^2}e^{-\frac{|\vec{k}|^2 + u^2}{4\alpha^2}} \\
   %
    F_{c_{\mathrm{pp}},i,z} 
    &= -\sum_{j} q_iq_j \sideset{}{'}\sum_{\vec{n}} \left( \frac{2 \alpha}{\sqrt{\pi}} e^{-\alpha^2 |\vec{r}_{ij}+\vec{n}|^2} + \frac{\erfc(\alpha |\vec{r}_{ij}+\vec{n}|)}{|\vec{r}_{ij}+\vec{n}|}  \right)  \frac{z_{ij}}{|\vec{r}_{ij}+\vec{n}|^2} \\ \nonumber
    &- \frac{2}{ab} \sum_{j} q_iq_j \sum_{\vec{k}\neq \vec{0}} \int_{-\infty}^{\infty} du\, 
   u\frac{\sin \left(\vec{k}\cdot\vec{\xi}_{ij} + uz_{ij}\right)}{|\vec{k}|^2 + u^2}e^{-\frac{|\vec{k}|^2 + u^2}{4\alpha^2}} \\ \nonumber
 &- \frac{2\pi}{ab} \sum_{j} q_iq_j \erf(\alpha z_{ij}) 
       \end{align}  
       
 \begin{align}
    \vec{F}_{c_{\mathrm{pg}},i} &= - \vec{\nabla}_i U_{c_{\mathrm{pg}}} \\
    F_{c_{\mathrm{pg}},i,x} 
    &= -\sum_{j} q_iQ_j \sum_{\vec{n}} \left( \frac{2 \alpha}{\sqrt{\pi}} e^{-\alpha^2 |\vec{r}_{ij}+\vec{n}|^2} + \frac{\erfc(\alpha |\vec{r}_{ij}+\vec{n}|)}{|\vec{r}_{ij}+\vec{n}|}  \right)  \frac{x_{ij}+n_xa}{|\vec{r}_{ij}+\vec{n}|^2} \\ \nonumber
    &+\sum_{j} q_iQ_j \sum_{\vec{n}} \left( \frac{2 \eta_{j}}{\sqrt{\pi}} e^{-\eta_{j}^2 |\vec{r}_{ij}+\vec{n}|^2} + \frac{\erfc(\eta_{j} |\vec{r}_{ij}+\vec{n}|)}{|\vec{r}_{ij}+\vec{n}|}  \right)  \frac{x_{ij}+n_xa}{|\vec{r}_{ij}+\vec{n}|^2} \\ \nonumber
    &- \frac{2}{ab} \sum_{j} q_iQ_j \sum_{\vec{k}\neq \vec{0}} \int_{-\infty}^{\infty} du\, 
   \frac{2\pi k_x}{a}\frac{\sin \left(\vec{k}\cdot\vec{\xi}_{ij} + uz_{ij}\right)}{|\vec{k}|^2 + u^2}e^{-\frac{|\vec{k}|^2 + u^2}{4\alpha^2}} \\
   %
    F_{c_{\mathrm{pg}},i,y} 
    &= -\sum_{j} q_iQ_j \sum_{\vec{n}} \left( \frac{2 \alpha}{\sqrt{\pi}} e^{-\alpha^2 |\vec{r}_{ij}+\vec{n}|^2} + \frac{\erfc(\alpha |\vec{r}_{ij}+\vec{n}|)}{|\vec{r}_{ij}+\vec{n}|}  \right)  \frac{y_{ij}+n_yb}{|\vec{r}_{ij}+\vec{n}|^2} \\ \nonumber
    &+\sum_{j} q_iQ_j \sum_{\vec{n}} \left( \frac{2 \eta_{j}}{\sqrt{\pi}} e^{-\eta_{j}^2 |\vec{r}_{ij}+\vec{n}|^2} + \frac{\erfc(\eta_{j} |\vec{r}_{ij}+\vec{n}|)}{|\vec{r}_{ij}+\vec{n}|}  \right)  \frac{y_{ij}+n_y b}{|\vec{r}_{ij}+\vec{n}|^2} \\ \nonumber
    &- \frac{2}{ab} \sum_{j} q_iQ_j \sum_{\vec{k}\neq \vec{0}} \int_{-\infty}^{\infty} du\, 
   \frac{2\pi k_y}{b}\frac{\sin \left(\vec{k}\cdot\vec{\xi}_{ij} + uz_{ij}\right)}{|\vec{k}|^2 + u^2}e^{-\frac{|\vec{k}|^2 + u^2}{4\alpha^2}} \\
   %
    F_{c_{\mathrm{pg}},i,z} 
    &= -\sum_{j} q_iQ_j \sum_{\vec{n}} \left( \frac{2 \alpha}{\sqrt{\pi}} e^{-\alpha^2 |\vec{r}_{ij}+\vec{n}|^2} + \frac{\erfc(\alpha |\vec{r}_{ij}+\vec{n}|)}{|\vec{r}_{ij}+\vec{n}|}  \right)  \frac{z_{ij}}{|\vec{r}_{ij}+\vec{n}|^2} \\ \nonumber
    &+\sum_{j} q_iQ_j \sum_{\vec{n}} \left( \frac{2 \eta_{j}}{\sqrt{\pi}} e^{-\eta_{j}^2 |\vec{r}_{ij}+\vec{n}|^2} + \frac{\erfc(\eta_{j} |\vec{r}_{ij}+\vec{n}|)}{|\vec{r}_{ij}+\vec{n}|}  \right)  \frac{z_{ij}}{|\vec{r}_{ij}+\vec{n}|^2} \\ \nonumber
    &- \frac{2}{ab} \sum_{j} q_iQ_j \sum_{\vec{k}\neq \vec{0}} \int_{-\infty}^{\infty} du\, 
   u\frac{\sin \left(\vec{k}\cdot\vec{\xi}_{ij} + uz_{ij}\right)}{|\vec{k}|^2 + u^2}e^{-\frac{|\vec{k}|^2 + u^2}{4\alpha^2}} \\ \nonumber
 &- \frac{2\pi}{ab} \sum_{j} q_iQ_j \erf(\alpha z_{ij}) 
       \end{align}  
      
\newpage

  \section{Electrostatics with 3D periodic boundary conditions}  
  The ions in the bulk of the system have a point charge distribution,
  %
  \begin{equation} \label{eq:rho_point2}
  \rho_i(\vec{r}) \equiv q_i \delta(\vec{r}-\vec{r}_i)
  \end{equation}
  %
where $\vec{r}_i$ and   $q_i$ are the position and the integral charge of the ion $i$, respectively, and $\delta(\vec{r})$ is the Dirac delta function.

  The atoms on the electrodes are modeled with a gaussian charge distribution, 
  %
  \begin{equation} \label{eq:rho_gaussian2}
  \rho_i(\vec{r}) \equiv Q_i \left(\frac{\eta^2}{\pi}\right)^{3/2} e^{-\eta^2 |\vec{r}-\vec{r}_i|^2}
  \end{equation}
  %
where $\vec{r}_i$ and $Q_i$ are the position and the integral charge of the atom $i$, respectively, and $\eta$ is a model parameter.
  
  The simulation cell is an orthombic box with dimensions $a$, $b$ and $c$ in the $\vec{x}$, $\vec{y}$ and $\vec{z}$ direction respectively. 3D periodic boundary conditions are applied. The position of an ion or atom $i$ in the simulation box can be expressed by $\vec{r}_i = (x_i, y_i, z_i)$, where $0 \leq x_i < a$, $0 \leq y_i < b$ and $0 \leq z_i < c$.
   
  We define the distance between two charges $i$ and $j$ by $\vec{r}_{ij} \equiv \vec{r}_j - \vec{r}_i$.
  
    We define the lattice vector $\vec{n} \equiv (n_xa,n_yb, n_zc)$, where $n_x, n_y, n_z \in \mathbb{Z}$ and the reciprocal lattice vector $\vec{k} \equiv (k_x\frac{2\pi}{a},k_y\frac{2\pi}{b}, k_z\frac{2\pi}{c})$, where $k_x, k_y, k_z \in \mathbb{Z}$.
    
  \subsection{Coulomb Energy}
  
  The total energy of the system due to Coulomb interaction is given by
  %
  \begin{align} \label{eq:Uc_integral2}
  U_c &= 
  % point-point interactions
  \frac{1}{2} \sum_{i=1}^{N_{\mathrm{point}}} \sum_{j=1}^{N_{\mathrm{point}}} \sideset{}{'}\sum_{\vec{n}} \frac{q_iq_j}{|\vec{r}_{ij}+\vec{n}|} \\\nonumber
  % point-electrode interactions
  &+ \sum_{e=1}^{N_\mathrm{elec}} \sum_{i=1}^{N_{\mathrm{point}}} \sum_{j=1}^{N_e} \sum_{\vec{n}} \int_{\mathbb{R}^3} dr'' \left( \frac{\eta_e^2}{\pi}\right)^{3/2} \frac{q_iQ_{j_e}}{|\vec{r}_{ij_e} + \vec{r}'' + \vec{n}|} e^{-\eta_e^2 |\vec{r}''|^2} \\\nonumber
  % electrode-electrode interactions
  &+ \frac{1}{2}   \sum_{e'=1}^{N_\mathrm{elec}} \sum_{i_{e'}=1}^{N_{e'}} \sum_{e''=1}^{N_\mathrm{elec}} \sum_{j_{e''}=1}^{N_{e''}} \sum_{\vec{n}} \int_{\mathbb{R}^3} dr' \int_{\mathbb{R}^3} dr'' \left( \frac{\eta_{e'} \eta_{e''}}{\pi}\right)^{3} \frac{Q_{i_{e'}} e^{-\eta_{e'}^2 |\vec{r}'|^2} Q_{j_{e''}} e^{-\eta_{e''}^2 |\vec{r}''|^2}}{|\vec{r}_{i_{e'}j_{e''}} + \vec{r}'' - \vec{r}' + \vec{n}|}
  \end{align}
  
  We define the intermediate quantities,
  %
  \begin{align} 
  % point-point interactions  
  U_{c_{\mathrm{pp}}} &= 
  \frac{1}{2} \sum_{i=1}^{N_{\mathrm{point}}} \sum_{j=1}^{N_{\mathrm{point}}} \sideset{}{'}\sum_{\vec{n}} \frac{q_iq_j}{|\vec{r}_{ij}+\vec{n}|} \\
  % point-electrode interactions
  U_{c_{\mathrm{pg}}} &= 
  \sum_{e=1}^{N_\mathrm{elec}} \sum_{i=1}^{N_{\mathrm{point}}} \sum_{j=1}^{N_e} \sum_{\vec{n}} \int_{\mathbb{R}^3} dr'' \left( \frac{\eta_e^2}{\pi}\right)^{3/2} \frac{q_iQ_{j_e}}{|\vec{r}_{ij_e} + \vec{r}'' + \vec{n}|} e^{-\eta_e^2 |\vec{r}''|^2} \\
  % electrode-electrode interactions
  U_{c_{\mathrm{gg}}} &= 
  \frac{1}{2}   \sum_{e'=1}^{N_\mathrm{elec}} \sum_{i_{e'}=1}^{N_{e'}} \sum_{e''=1}^{N_\mathrm{elec}} \sum_{j_{e''}=1}^{N_{e''}} \sum_{\vec{n}} \int_{\mathbb{R}^3} dr' \int_{\mathbb{R}^3} dr'' \left( \frac{\eta_{e'} \eta_{e''}}{\pi}\right)^{3} \frac{Q_{i_{e'}} e^{-\eta_{e'}^2 |\vec{r}'|^2} Q_{j_{e''}} e^{-\eta_{e''}^2 |\vec{r}''|^2}}{|\vec{r}_{i_{e'}j_{e''}} + \vec{r}'' - \vec{r}' + \vec{n}|}
  \end{align}
  
  \subsection{Point charges system}
  First we consider only a system of point charges. The energy is given by
  %
  \begin{equation} \label{eq:Uc_pp_integral2}
  U_{c_{\mathrm{pp}}} = 
  \frac{1}{2} \sum_{i,j} \sideset{}{'}\sum_{\vec{n}} \frac{q_iq_j}{|\vec{r}_{ij}+\vec{n}|}
  \end{equation}
  %
  The sum over the lattice vector $\vec{n}$ is slowly convergent. In order to speed up the numerical calculation, the sum will be split into a short-range and long-range contributions. This is achieved by representing ${|\vec{r}_{ij} + \vec{n}|}^{-1}$  as an integral over a dummy variable via the identity
  %
  \begin{equation} \label{eq:r-1_identity2}
  \frac{1}{r} = \frac{1}{\sqrt{\pi}} \int_{0}^{\infty}dt\,t^{-1/2}e^{-r^2t}
  \end{equation}
  %
  Using Equation (\ref{eq:r-1_identity2}) into  Equation (\ref{eq:Uc_pp_integral2}) 
  yields:
  %
  \begin{equation} 
  U_{c_{\mathrm{pp}}} = 
  \frac{1}{2\sqrt{\pi}} \sum_{i,j} q_iq_j \sideset{}{'}\sum_{\vec{n}} \int_{0}^{\infty}dt\,t^{-1/2}e^{-|\vec{r}_{ij}+\vec{n}|^2t} 
  \end{equation}
  %
  The integral over the dummy variable $t$ may be split up into two parts corresponding to short-range and long-range contributions of $1/r$:
  \begin{align}
  U_{c_{\mathrm{pp}}} &= 
  \frac{1}{2\sqrt{\pi}} \sum_{i,j} q_iq_j \sideset{}{'}\sum_{\vec{n}} \int_{\alpha^2}^{\infty}dt\,t^{-1/2}e^{-|\vec{r}_{ij}+\vec{n}|^2t} \\\nonumber
  & + \frac{1}{2\sqrt{\pi}} \sum_{i,j} q_iq_j \sideset{}{'}\sum_{\vec{n}} \int_{0}^{\alpha^2}dt\,t^{-1/2}e^{-|\vec{r}_{ij}+\vec{n}|^2t} 
  \end{align}
  %
  The short-range term can be directly computed with the substitution $t=u^2|\vec{r}_{ij}+\vec{n}|^2$:
  %
  \begin{align}
  U_{c_{\mathrm{pp}}}^{\mathrm{sr}}  
  &= \frac{1}{2} \sum_{i,j} q_iq_j \sideset{}{'}\sum_{\vec{n}} \frac{1}{\sqrt{\pi}} \int_{\alpha^2}^{\infty}dt\,t^{-1/2}e^{-|\vec{r}_{ij}+\vec{n}|^2t} \\\nonumber
  &= \frac{1}{2} \sum_{i,j} q_iq_j \sideset{}{'}\sum_{\vec{n}} \frac{2}{\sqrt{\pi}}\int_{\alpha|\vec{r}_{ij}+\vec{n}|}^{\infty}du\,|\vec{r}_{ij}+\vec{n}|^{-1}e^{-u^2} \\\nonumber
  &= \frac{1}{2} \sum_{i,j} q_iq_j \sideset{}{'}\sum_{\vec{n}} \frac{\erfc \left(\alpha|\vec{r_{ij}+\vec{n}|}\right)}{|\vec{r}_{ij}+\vec{n}|}
  \end{align}
  % 
  The long-range interaction term will be treated in Fourier space. For this we will use the Poisson summation formula:
  %
  \begin{equation} \label{eq:Jacobi_transformation2}
  \sum_{n=-\infty}^{\infty}e^{-(x+na)^2t} = \frac{1}{a} \left(\frac{\pi}{t}\right)^{1/2} \sum_{k=-\infty}^{\infty} 
  e^{-\frac{\pi^2k^2}{a^2t} + \mathrm{i} \frac{2\pi kx}{a}}
   \end{equation}

  However in order to be able to do this we need complete periodicity and the sum needs to include the terms with $i=j$ and $\vec{n}=\vec{0}$.    These self-interaction terms will be computed separately and subtracted from the value computed with the Fourier sums. First we compute the long-range term:
  %
  \begin{align}
  U_{c_{\mathrm{pp}}}^{\mathrm{lr}}  
  &= \frac{1}{2} \sum_{i,j} q_iq_j \sum_{\vec{n}} \frac{1}{\sqrt{\pi}} \int_{0}^{\alpha^2}dt\,t^{-1/2}e^{-|\vec{r}_{ij}+\vec{n}|^2t} \\\nonumber
    &= \frac{\pi}{2abc} \sum_{i,j} q_iq_j \sum_{\vec{k}} \int_{0}^{\alpha^2}dt\,  t^{-2} e^{-\frac{|\vec{k}|^2}{4t}  + \mathrm{i} \vec{k}\cdot\vec{r}_{ij}}
  \end{align}  
  %
  The term with $\vec{k} = \vec{0}$ in the sum needs to be treated separately from the other terms. Thus we split the sum into two terms, $U_{c_{\mathrm{pp}}}^{\mathrm{lr},*}$ and $U_{c_{\mathrm{pp}}}^{\mathrm{lr},0}$ :
  \begin{align}
  U_{c_{\mathrm{pp}}}^{\mathrm{lr},*}  
       &\equiv \frac{\pi}{2abc} \sum_{i,j} q_iq_j \sum_{\vec{k}\neq \vec{0}} \int_{0}^{\alpha^2}dt\,  t^{-2} e^{-\frac{|\vec{k}|^2}{4t}  + \mathrm{i} \vec{k}\cdot\vec{r}_{ij}} \\
   U_{c_{\mathrm{pp}}}^{\mathrm{lr},0}  
       &\equiv  \frac{\pi}{2abc} \sum_{i,j} q_iq_j \int_{0}^{\alpha^2}dt\,  t^{-2}
  \end{align}  
  %   
  \begin{align}
  U_{c_{\mathrm{pp}}}^{\mathrm{lr},*}  
       &\equiv \frac{\pi}{2abc} \sum_{i,j} q_iq_j \sum_{\vec{k}\neq \vec{0}} \int_{0}^{\alpha^2}dt\,  t^{-2} e^{-\frac{|\vec{k}|^2}{4t}  + \mathrm{i} \vec{k}\cdot\vec{r}_{ij}} \\\nonumber  
%
  &= \frac{\pi}{2abc} \sum_{i,j} q_iq_j \sum_{\vec{k}\neq \vec{0}} e^{\mathrm{i} \vec{k}\cdot\vec{r}_{ij}} \left[ \frac{4}{|\vec{k}|^2} e^{-\frac{|\vec{k}|^2}{4t}} \right]_{0}^{\alpha^2} \\\nonumber
%
  &= \frac{2\pi}{abc} \sum_{i,j} q_iq_j \sum_{\vec{k}\neq \vec{0}} e^{\mathrm{i} \vec{k}\cdot\vec{r}_{ij}} \frac{1}{|\vec{k}|^2} e^{-\frac{|\vec{k}|^2}{4\alpha^2}}\\\nonumber
  \end{align} 

  The term $U_{c_{\mathrm{pp}}}^{\mathrm{lr},0} = 0$, when we make the hypothesis that the system of point-charges is charge neutral.

  Now we need to compute the self-interaction term to be able to subtract it from the long-range term value:
  %
    \begin{align}
  U_{c_{\mathrm{pp}}}^{\mathrm{self}}  
    &=  \frac{1}{2} \sum_{i} q_i^2 \frac{1}{\sqrt{\pi}} \int_{0}^{\alpha^2}dt\,t^{-1/2} \\ \nonumber
    &= \frac{\alpha}{\sqrt{\pi}} \sum_{i} q_i^2
    \end{align}

Putting it all together, we have:
%    
 \begin{align}
    U_{c_{\mathrm{pp}}} 
    &=  \frac{1}{2} \sum_{i,j} q_iq_j \sideset{}{'}\sum_{\vec{n}} \frac{\erfc \left(\alpha|\vec{r_{ij}+\vec{n}|}\right)}{|\vec{r}_{ij}+\vec{n}|} \\
    \nonumber
    &+ \frac{2\pi}{abc} \sum_{i,j} q_iq_j \sum_{\vec{k}\neq \vec{0}} e^{\mathrm{i} \vec{k}\cdot\vec{r}_{ij}} \frac{1}{|\vec{k}|^2} e^{-\frac{|\vec{k}|^2}{4\alpha^2}} \\
   \nonumber
   &- \frac{\alpha}{\sqrt{\pi}} \sum_{i} q_i^2
    \end{align}
    
  \subsection{Gaussian charges system}
  Now we consider only a system of gaussian charges. The energy is given by
  %
  \begin{equation} \label{eq:Uc_gg_integral2}
  U_{c_{\mathrm{gg}}} = 
    \frac{1}{2} \sum_{i,j} Q_{i}Q_{j} \sum_{\vec{n}} \int_{\mathbb{R}^3} dr' \int_{\mathbb{R}^3} dr'' \left( \frac{\eta_{i} \eta_{j}}{\pi}\right)^{3} \frac{e^{-\eta_{i}^2 |\vec{r}'|^2} e^{-\eta_{j}^2 |\vec{r}''|^2}}{|\vec{r}_{ij} + \vec{r}'' - \vec{r}' + \vec{n}|}
  \end{equation}
  %
  The sum over the lattice vector $\vec{n}$ is slowly convergent. In order to speed up the numerical calculation, the sum will be split into a short-range and long-range contributions. This is achieved by representing ${|\vec{r}_{ij} + \vec{r}'' - \vec{r}' + \vec{n}|}^{-1}$  as an integral over a dummy variable via the identity
  %
  \begin{equation} \label{eq:r-1_identity4}
  \frac{1}{r} = \frac{1}{\sqrt{\pi}} \int_{0}^{\infty}dt\,t^{-1/2}e^{-r^2t}
  \end{equation}
  %
  Using Equation (\ref{eq:r-1_identity4}) into  Equation (\ref{eq:Uc_gg_integral2}) 
  yields:
  %
  \begin{equation} 
  U_{c_{\mathrm{gg}}} = 
  \frac{1}{2\sqrt{\pi}} \sum_{i,j} Q_iQ_j \sum_{\vec{n}}  \int_{\mathbb{R}^3} dr' \int_{\mathbb{R}^3} dr''\int_{0}^{\infty}dt \left( \frac{\eta_{i} \eta_{j}}{\pi}\right)^{3} e^{-\eta_{i}^2 |\vec{r}'|^2} e^{-\eta_{j}^2 |\vec{r}''|^2} t^{-1/2}e^{-|\vec{r}_{ij} + \vec{r}'' - \vec{r}' + \vec{n}|^2t} 
  \end{equation}
  %
  Additionally, we use the following identity to express the gaussian exponentials as integrals over dummy variables.
  %
  \begin{equation} \label{eq:TFGauss_3D2}
  \exp(-\eta^2|\vec{r}|^2) = (2\pi)^{-3}\frac{\pi^{3/2}}{\eta^3} \int_{\mathbb{R}^3} \exp\left(-\frac{|\vec{v}|^2}{4\eta^2} + \mathrm{i} \vec{v} \cdot \vec{r} \right) d\vec{v}
  \end{equation}
  
  Using Equation (\ref{eq:TFGauss_3D2}) further yields
  \begin{align}
  U_{c_{\mathrm{gg}}} &= 
  \frac{1}{2\sqrt{\pi}} \sum_{i,j} Q_iQ_j \sum_{\vec{n}}  \int_{\mathbb{R}^3} dr' \int_{\mathbb{R}^3} dr''\int_{0}^{\infty}dt\,t^{-1/2} \\ \nonumber
  &\times e^{-|\vec{r}_{ij} + \vec{r}'' - \vec{r}' + \vec{n}|^2t} \\  \nonumber
  &\times (2\pi)^{-3} \int_{\mathbb{R}^3} \exp\left(-\frac{|\vec{v}|^2}{4\eta_{i}^2} + \mathrm{i} \vec{v} \cdot \vec{r}' \right) d\vec{v} \\  \nonumber
  &\times (2\pi)^{-3} \int_{\mathbb{R}^3} \exp\left(-\frac{|\vec{w}|^2}{4\eta_{j}^2} + \mathrm{i} \vec{w} \cdot \vec{r}'' \right) d\vec{w} 
  \end{align} 
  %
  And using Poisson summation formula (Equation (\ref{eq:Jacobi_transformation2})) yields:
  %
  \begin{align}
  U_{c_{\mathrm{gg}}} &= 
  \frac{1}{2\sqrt{\pi}} \sum_{i,j} Q_iQ_j \sum_{\vec{k}}  \int_{\mathbb{R}^3} dr' \int_{\mathbb{R}^3} dr''\int_{0}^{\infty}dt\,t^{-1/2} \\  \nonumber
  &\times \frac{1}{abc}\frac{\pi^{3/2}}{t^{3/2}} e^{-\frac{|\vec{k}|^2}{4t}+\mathrm{i}\vec{k}\cdot (\vec{r}_{ij} + \vec{r}'' - \vec{r}')} \\  \nonumber
  &\times (2\pi)^{-3} \int_{\mathbb{R}^3} \exp\left(-\frac{|\vec{v}|^2}{4\eta_{i}^2} + \mathrm{i} \vec{v} \cdot \vec{r}' \right) d\vec{v} \\  \nonumber
  &\times (2\pi)^{-3} \int_{\mathbb{R}^3} \exp\left(-\frac{|\vec{w}|^2}{4\eta_{j}^2} + \mathrm{i} \vec{w} \cdot \vec{r}'' \right) d\vec{w} 
  \end{align}
  % 
  Grouping terms in $\vec{r}'$ and in $\vec{r}''$ together yields two integral formulas of the $\delta$-function,
    %
  \begin{align}
  U_{c_{\mathrm{gg}}} &= 
  (2\pi)^{-6} \frac{\pi}{2abc} \sum_{i,j} Q_i Q_j \sum_{\vec{k}}  \int_{\mathbb{R}^3} d\vec{r}  \int_{\mathbb{R}^3} d\vec{w} \int_{0}^{\infty}dt\,t^{-2} \\  \nonumber
   &\times  e^{-\frac{|\vec{k}|^2}{4t} + \mathrm{i} \vec{k} \cdot \vec{r}_{ij}} \\  \nonumber
   &\times \exp\left(-\frac{|\vec{v}|^2}{4\eta_{i}^2}-\frac{|\vec{w}|^2}{4\eta_{j}^2}\right) \\  \nonumber
 &\times  \int_{\mathbb{R}^3} \exp\left( + \mathrm{i}(\vec{v}-\vec{\kappa}) \cdot \vec{r}' \right)  dr' \\  \nonumber
  &\times \int_{\mathbb{R}^3} \exp\left( + \mathrm{i} (\vec{w}+\vec{\kappa}) \cdot \vec{r}'' \right) dr''
 \end{align}
%%  
 Using the integral formula for Dirac $\delta$-function, 
  \begin{equation} \label{eq:TFdirac_1d2}
  \frac{1}{2\pi} \int_{-\infty}^{\infty} dx \exp \left( \mathrm{i} (k-k')x \right) = \delta (k-k') 
  \end{equation}
  %
  we can simplify the expression of $U_{c_{\mathrm{gg}}}$, with $\eta_{ij} \equiv \frac{\eta_i \eta_j}{\sqrt{\eta_i^2 + \eta_j^2}}$:
      %
  \begin{align}
    U_{c_{\mathrm{gg}}} &= 
  \frac{\pi}{2abc} \sum_{i,j} Q_iQ_j \sum_{\vec{k}} \int_{0}^{\infty}dt\,t^{-2} \\ \nonumber
  &\times 
  \exp\left(-\frac{|\vec{k}|^2}{4t} + \mathrm{i} \vec{k}\cdot \vec{r}_{ij}\right)
   \exp\left(-\frac{|\vec{k}|^2}{4\eta_{ij}^2}\right) 
  \end{align}
  % 
  Before going forward and splitting the Energy term into short-range and long-range contributions, we apply the substitution $t' = \frac{\eta_{ij}^2t}{t + \eta_{ij}^2}$:
  %
    \begin{equation}
    U_{c_{\mathrm{gg}}} = 
  \frac{\pi}{2abc} \sum_{i,j} Q_iQ_j \sum_{\vec{k}} \int_{0}^{\eta_{ij}^2}dt'\,t'^{-2} \exp\left(-\frac{|\vec{k}|^2}{4t'} + \mathrm{i} \vec{k}\cdot \vec{r}_{ij}\right)
  \end{equation}
  % 
  
  The integral over the dummy variable $t$ may be split up into two parts corresponding to short-range and long-range contributions of $1/r$:
  \begin{align}
  U_{c_{\mathrm{gg}}} &= 
  \frac{\pi}{2abc} \sum_{i,j} Q_iQ_j \sum_{\vec{k}} \int_{0}^{\alpha^2}dt'\,t'^{-2} \exp\left(-\frac{|\vec{k}|^2}{4t'} + \mathrm{i} \vec{k}\cdot \vec{r}_{ij}\right) \\
   \nonumber
   &+   \frac{\pi}{2abc} \sum_{i,j} Q_iQ_j \sum_{\vec{k}} \int_{-\infty}^{\infty}du \int_{\alpha^2}^{\eta_{ij}^2}dt'\,t'^{-2} \exp\left(-\frac{|\vec{k}|^2}{4t'} + \mathrm{i} \vec{k}\cdot \vec{r}_{ij}\right)
  \end{align}
  %
  In order to compute the short-range term we need first to revert back to the real space:
  %
  \begin{align}
  U_{c_{\mathrm{pp}}}^{\mathrm{sr}}  
  &=  \frac{\pi}{2abc} \sum_{i,j} Q_iQ_j \sum_{\vec{k}} \int_{\alpha^2}^{\eta_{ij}^2}dt'\,t'^{-2} \exp\left(-\frac{|\vec{k}|^2}{4t'} + \mathrm{i} \vec{k}\cdot \vec{r}_{ij}\right) \\\nonumber
  &= \frac{1}{2\sqrt{\pi}} \sum_{i,j} Q_iQ_j \sum_{\vec{n}} \int_{\alpha^2}^{\eta_{ij}^2}dt'\,t'^{-1/2} e^{-|\vec{r}_{ij} + \vec{n}|^2t} \\\nonumber
    \end{align}
 %
 The real-space terms are computed through the substitution $t=u^2|\vec{r}_{ij}+\vec{n}|^2$:
  \begin{align}
    U_{c_{\mathrm{pp}}}^{\mathrm{sr,*}}  &=
     \frac{1}{\sqrt{\pi}} \sum_{i,j} Q_iQ_j \sideset{}{'}\sum_{\vec{n}} \int_{\alpha|\vec{r}_{ij} + \vec{n}|}^{\eta_{ij}|\vec{r}_{ij} + \vec{n}|}du\,|\vec{r}_{ij} + \vec{n}|^{-1}e^{-u^2}
   \\\nonumber
  &= \frac{1}{2} \sum_{i,j} Q_iQ_j \sideset{}{'}\sum_{\vec{n}} |\vec{r}_{ij} + \vec{n}|^{-1} \left( \erfc(\alpha|\vec{r}_{ij} + \vec{n}|) - \erfc (\eta_{ij}|\vec{r}_{ij} + \vec{n}|)\right)
   \\\nonumber
  %%%
  \end{align}

  The long-range interaction term will be treated in Fourier space. 
  %
  \begin{align}
  U_{c_{\mathrm{gg}}}^{\mathrm{lr}} &= 
    \frac{\pi}{2abc} \sum_{i,j} Q_iQ_j \sum_{\vec{k}} \int_{0}^{\alpha^2}dt'\,t'^{-2} \exp\left(-\frac{|\vec{k}|^2}{4t'} + \mathrm{i} \vec{k}\cdot \vec{r}_{ij}\right) \\
   \nonumber
   \end{align}
   %
   This expression is identical to the one computed for a point charge system. Therefore, we use the same decomposition between the $\vec{k}=\vec{0}$ term and the other terms and get the same expression:
     %   
  \begin{align}
  U_{c_{\mathrm{gg}}}^{\mathrm{lr,*}}  
     &= 
\frac{2\pi}{abc} \sum_{i,j} Q_iQ_j \sum_{\vec{k}\neq \vec{0}} e^{\mathrm{i} \vec{k}\cdot\vec{r}_{ij}} \frac{1}{|\vec{k}|^2} e^{-\frac{|\vec{k}|^2}{4\alpha^2}} \\
      U_{c_{\mathrm{gg}}}^{\mathrm{lr},0}  &= 0
  \end{align} 
%
 The self-interaction terms are collectively taken into account by:
   \begin{align}
    U_{c_{\mathrm{pp}}}^{\mathrm{self}}  &=
    \frac{1}{2\sqrt{\pi}} \sum_{i} Q_i^2 \int_{\alpha^2}^{\eta_{ij}^2}dt'\,t'^{-1/2} \\\nonumber
    &=  \frac{1}{\sqrt{\pi}} \sum_{i} Q_i^2 \left( \frac{\eta_{i}}{\sqrt{2}} - \alpha \right)
  \end{align}
%
Putting it all together, we have:
%    
 \begin{align}
    U_{c_{\mathrm{gg}}} 
    &=  \frac{1}{2} \sum_{i,j} Q_iQ_j \sideset{}{'}\sum_{\vec{n}} |\vec{r}_{ij} + \vec{n}|^{-1} \left( \erfc(\alpha|\vec{r}_{ij} + \vec{n}|) - \erfc (\eta_{ij}|\vec{r}_{ij} + \vec{n}|)\right) \\
    \nonumber
    &+  \frac{2\pi}{abc} \sum_{i,j} Q_iQ_j \sum_{\vec{k}\neq \vec{0}} e^{\mathrm{i} \vec{k}\cdot\vec{r}_{ij}} \frac{1}{|\vec{k}|^2} e^{-\frac{|\vec{k}|^2}{4\alpha^2}} \\
   \nonumber
   &+ \frac{1}{\sqrt{\pi}} \sum_{i} Q_i^2 \left( \frac{\eta_{i}}{\sqrt{2}} - \alpha \right)
    \end{align}
    
\subsection{Gaussian charges and Point charges system}

In a system where Gaussian charges and Point charges are in interaction, the Coulomb energy can be computed in an entirely analogous manner. We make the assumption of charge neutrality in each such sub-system. The total energy of the system is the sum of the energy of the point charges subsystem, the energy of the gaussian charges subsystem and the interaction energy between the 2 subsystems. From the two previous sections we already know the first two terms of the energy. In this section, we compute the interaction energy.
\begin{align}
U_{c_{\mathrm{pg}}} &=
\sum_{i,j} \sum_{\vec{n}} \int_{\mathbb{R}^3} dr'' \left( \frac{\eta_j^2}{\pi}\right)^{3/2} \frac{q_iQ_{j}}{|\vec{r}_{ij} + \vec{r}'' + \vec{n}|} e^{-\eta_j^2 |\vec{r}''|^2} 
\end{align}
%
\begin{align}
U_{c_{\mathrm{pg}}}
    &=  \sum_{i,j} q_iQ_j \sum_{\vec{n}} |\vec{r}_{ij} + \vec{n}|^{-1} \left( \erfc(\alpha|\vec{r}_{ij} + \vec{n}|) - \erfc (\eta_{j}|\vec{r}_{ij} + \vec{n}|)\right) \\
    \nonumber
    &+  \frac{4\pi}{abc} \sum_{i,j} q_iQ_j \sum_{\vec{k}\neq \vec{0}} e^{\mathrm{i} \vec{k}\cdot\vec{r}_{ij}} \frac{1}{|\vec{k}|^2} e^{-\frac{|\vec{k}|^2}{4\alpha^2}} 
  \end{align}

  \section{Implementation details}
  
  \subsection{Minimum image distance criterion}
  
  All sums corresponding to the real space lattice vectors $\sum_{\vec{n}}$ are performed under the minimum image criterion with an additional cut-off distance. That is, the sum over $\vec{n}$ is removed from the final expressions of the short-range terms of energies and potentials given before. 
  %equations (\ref{eq:Yie'_shortrange_end}) and (\ref{eq:bje_shortrange_end}), 
  The coefficient $|\vec{r}_{ij}|$ must be understood as the minimum image distance between the pair of sites $i$ and $j$ and only those pairs for which  $|\vec{r}_{ij}| < r_c$ are taken into account.
  For example, the short-range contributions to the Coulomb potential used for the minimization procedure are then given by
  %
 \begin{align}
 \label{eq:Yie'_shortrange_end}
 {Y_{i_{e'}}}_{\mathrm{sr}} &= \sum_{e''=1}^{N_{\mathrm{elec}}}\sum  \limits_{\underset{0 < |\vec{r}_{i_{e'}j_{e''}}| < r_c}{j_{e''}=1}}^{N_{e''}}  \frac{Q_{j_{e''}}}{|\vec{r}_{i_{e'}j_{e''}}|} \left( \erfc ({|\vec{r}_{i_{e'}j_{e''}}|\alpha}) - \erfc({|\vec{r}_{i_{e'}j_{e''}}|\eta_{e'e''}}) \right) \\\nonumber
  &+ \frac{2Q_{i_{e'}}}{\sqrt{\pi}} \left(\frac{\eta_{e'}}{\sqrt{2}} - \alpha \right) 
  \end{align}
%   
 \begin{align}
 \label{eq:bje_shortrange_end}
 {\tilde{b_{j}^{e}}}_{\mathrm{sr}} &= \sum \limits_{\underset{|\vec{r}_{ij_{e}}| < r_c}{i=1}}^{N_{\mathrm{point}}} \frac{q_i}{|\vec{r}_{ij_{e}}|} \left( \erfc ({|\vec{r}_{ij_{e}}|\alpha}) - \erfc({|\vec{r}_{ij_{e}}|\eta_{e}}) \right) 
  \end{align}

  where $r_c$ is a user-input parameter.
  
  \subsection{Numerical integration}
  
  The integral with respect to $u$ contained in the $\vec{k}=\vec{0}$ term of the final expressions for energies, potentials and forces for the 2D periodic boundary condition system is approximated with the rectangle rule. This enables us to cast this formula in a way which is similar to the 3D periodic boundary condition case.
  %
  \begin{equation}
  \int_{-\infty}^{+\infty} du f(u) = \sum_{k_z=-k_z^{\mathrm{max}}}^{k_z^{\mathrm{max}}} \Delta_z f(k_z \Delta_z)
  \end{equation}
  
  Here $\Delta_z \equiv \delta_z \frac{2\pi}{c}$ is the step size and $\delta_z$ is a user input parameter (usually set to $1.0$). $k_z^{\mathrm{max}}$ is a cutoff parameter which is computed as a function of $\alpha$ and the tolerance on the sum convergence $\epsilon$
  
  \subsection{Truncation of reciprocal space sums}
  
  Sums on the reciprocal lattice vectors are infinite in principle. However the terms decay exponentially with the square of the norm of the $\vec{k}$ vector. Hence the sums on $\vec{k}$ are truncated to contain only term with $|\vec{k}| < r_k^{\mathrm{max}}$.
  
  Given the parameter $\alpha$ and a tolerance parameter $\epsilon$ we use the following formula to evaluate $r_k^{\mathrm{max}}$ and then $k_x^{\mathrm{max}}$, $k_y^{\mathrm{max}}$ and $k_z^{\mathrm{max}}$:
  %
  \begin{align}
  r_k^{\mathrm{max}} &= \sqrt{-\ln (\epsilon)}\frac{ 2 \alpha}{r_k^{\mathrm{min}}} \\
  k_x^{\mathrm{max}} &= \left[r_k^{\mathrm{max}} r_k^{\mathrm{min}} \frac{a}{2\pi} \right] + 1 \\
  k_y^{\mathrm{max}} &= \left[r_k^{\mathrm{max}} r_k^{\mathrm{min}} \frac{b}{2\pi} \right] + 1 \\
  k_z^{\mathrm{max}} &= \left[ \delta_{k_z}r_k^{\mathrm{max}} r_k^{\mathrm{min}} \frac{c}{2\pi} \right] + 1
\end{align}
  %
  where $[x]$ is the greatest integer smaller than $x$ and $r_k^{\mathrm{min}} = \min(\frac{2\pi}{a}, \frac{2\pi}{b}, \frac{2\pi}{c})$. Finally, $\alpha$, $\epsilon$ and $\delta_{k_z}$ are user-input parameters.
  
  \subsection{Symmetrization of the reciprocal space sums}
  
  It can be shown that the terms inside the reciprocal space sums in the final expression for the long-range contributions of energies, potentials and forces
  %(\ref{eq:Yie'_longrange_end}) and (\ref{eq:bje_longrange_end}) 
  are symmetric with respect to $\vec{k}$. Hence the computation burden can be cut in half. For example, the long-range terms of the Coulomb potential used in the minimization procedure, introducing the quantities
  %
  \begin{align}
  \vec{k}_{xyz} &\equiv \left(k_x \frac{2\pi}{a}, k_y \frac{2\pi}{b}, k_z \delta_z \frac{2\pi}{c} \right) \\
  r_k &\equiv |\vec{k}_{xyz}| = \sqrt{ \left(k_x \frac{2\pi}{a}\right)^2 + \left(k_y \frac{2\pi}{b}\right)^2 + \left( k_z \delta_z \frac{2\pi}{c} \right)^2}
  \end{align} 
    %
 can be written as 
  %
 \begin{align}
  {Y_{i_{e'}}}_{\mathrm{lr}}^{*} &= \frac{2}{ab} \sum_{k_x=0}^{k_x^{\mathrm{max}}} (2 - \delta(k_x)) \sum_{k_y=-k_y^{\mathrm{max}}}^{k_y^{\mathrm{max}}} \sum \limits_{\underset{ 0<r_k< r_k^{\mathrm{max}}}{k_z=-k_z^{\mathrm{max}}}}^{k_z^{\mathrm{max}}} \frac{1}{r_k^2}e^{-\frac{r_k^2}{4\alpha^2}}  \\\nonumber
 &\times  \left[   \cos( \vec{k}_{xyz} \cdot \vec{r_{i_{e'}}} ) \left( \sum_{e''=1}^{N_{\mathrm{elec}}}  \sum_{j_{e''}=1}^{N_{e''}} Q_{j_{e''}} \cos ( \vec{k}_{xyz} \cdot \vec{r_{j_{e''}}}) \right) \right. \\\nonumber
    &+ \left. \sin( \vec{k}_{xyz} \cdot \vec{r_{i_{e'}}} )
   \left( \sum_{e''=1}^{N_{\mathrm{elec}}} \sum_{j_{e''}=1}^{N_{e''}} Q_{j_{e''}} \sin ( \vec{k}_{xyz} \cdot \vec{r_{j_{e''}}}) \right) \right]  \\\nonumber
%   
   {\tilde{b_{j}^{e}}}_{\mathrm{lr}}^{*} &= \frac{2}{ab} \sum_{k_x=0}^{k_x^{\mathrm{max}}}(2 - \delta(k_x)) \sum_{k_y=-k_y^{\mathrm{max}}}^{k_y^{\mathrm{max}}} \sum \limits_{\underset{ 0<r_k< r_k^{\mathrm{max}}}{k_z=-k_z^{\mathrm{max}}}}^{k_z^{\mathrm{max}}}\frac{1}{r_k^2}e^{-\frac{r_k^2}{4\alpha^2}}  \\
 &\times  \left[   \cos( \vec{k}_{xyz} \cdot \vec{r_{j_{e}}} ) \left( \sum_{i=1}^{N_{\mathrm{point}}} q_i \cos ( \vec{k}_{xyz} \cdot \vec{r}_i) \right) \right.  \\\nonumber
   &+ \left. \sin( \vec{k}_{xyz} \cdot \vec{r_{j_{e}}} ) \left(\sum_{i=1}^{N_{\mathrm{point}}} q_i \sin (\vec{k}_{xyz} \cdot \vec{r}_i) \right) \right]  
  \end{align}
  %

\end{document}
