I would like to understand the details of ewald summation. So, I took the calculation of madelung constant (Wikipedia) as an example. I took two method to calculate madelung constant. One is calculate it by expanding cubes method, the other is ewald summation method. A good description of ewald summation can be found here.
After the derivation, the total Coulomb interaction energy can be finally written as,
In the paper I just mentioned, we can find all the details for this formula.
While, we need potential instead of total energy to calculate Madelung constant. We should take derivative over q to calculate the potential. Notice that some term exists which include 1/2. These are used to deal with double counting. When we want to calculate potential, these 1/2 should be erased.