Symmetry in program for ewald summation The formula for Ewald summation as given in Allen and Tildesley -
$$
U = U^{(r)} + U^{(k)} + U^{(bc)} + U^{self}
$$
where the k-space contribution of potential is given by 
$$
U^{(k)} = \frac{1}{\pi L^{3}}\sum_{\textbf{k}\ne0} \frac{4\pi^2}{k^2}\text {e}^{-\frac{k^2}{4\kappa^2}}|S(\textbf k)|^2 \qquad S(\textbf k) = \sum_{i=1}^N z_i\text{e}^{i\textbf{k}.\text{r}_i}
$$
Now in all the subroutines including the one given by Allen and Tildesley, the summation over $\vec{k}$ is done in such a way that $k_x$ has some special symmetry. Initially they choose $k_y$ and $k_z$ to be from $-n$ to $n$ where $n\in \mathbb Z_+$. But they choose  in $k_x$ to be from $0$ to $n$ and then later multiply the contribution by 2. What is the reason behind this ? If alter this, and choose $k_x$ also in the same way as $k_y$ and $k_z$ will it change the calculation ?
 A: This is a trick used to save time when doing the acctual computation by taking advantage of symmetry in the problem. 
Note that $k^2$ is an even function (invariant under ${\bf k}\to-{\bf k}$) and the norm of the fourier transform of the lattice function $|S({\bf k})|^2$ is also an even function since
$$S({\bf k}) = \sum_i q_i e^{i{\bf k}\cdot {\bf r_i}} \implies |S({\bf k})|^2 = \sum_{i,j} 2q_iq_j\cos({\bf k}\cdot({\bf r_i - r_j}))$$
and $\cos(x) = \cos(-x)$ so the whole summand is even. We can therefore replace the sum over $k_x\in[-n,n]$ in $\sum_{{\bf k}\not=0}g(k)|S({\bf k})|^2$ by a sum over $k_x>0$ by adding a factor of $2$. See the example below for how this works.
Note that we can not apply this trick to all coordinates (i.e. consider only $k_x,k_y,k_z\geq 0$ and multiply by $8$) since vectors with two negative numbers like $(-2,-3,5)$ plus the symmetry ${\bf k} \to -{\bf k}$ is not enough to cover all the gridpoints we want to sum over. This is why they only apply it to one of the coordinates $k_x$, however you can do the same for $k_y$ or $k_z$ instead of $k_x$ and get the same result.
You are also free to consider all $k_x\in[-n,n]$ (and not multiply by $2$) if you want and this will give the same result, but it will take twice the time to compute.

A simple example. Consider $n=1$ so $k_x,k_y,k_z\in\{-1,1\}$. The sum over the $(n+1)^3 = 8$ grid-points is
$$\matrix{\sum_{k_x,k_y,k_z\in\{-1,1\}} f({\bf k}) &=& f(-1,-1,-1) + f(1,1,1)\\ &+&f(-1,-1,1)  + f(1,1,-1)\\
&+&f(-1,1,-1)  + f(1,-1,1)\\
&+&f(-1,1,1)   + f(1,-1,-1)\\}$$
Since $f$ is even, $f({\bf k}) = f(-{\bf k})$, we see that the two terms on each line above is equal so
$$\matrix{\sum_{k_x,k_y,k_z\in\{-1,1\}} f({\bf k}) &=& 2f(1,1,1)\\ &+&2f(1,1,-1)\\
&+&2f(1,-1,1)\\
&+&2f(1,-1,-1)\\&=& 2 \sum_{k_z,k_y,k_z\in\{-1,1\},~~k_x > 0} f({\bf k})}$$
