Now I have wave functions $\psi_a$ and $\psi_b$ of two states in Gaussian CUBE format. I'd like to evaluate the transition dipole moment integral $\pmb\mu$ between these two states. As my simulation cell is cubic periodic with length of $L$, I will need the Berry phase formula to calculate $\pmb\mu$: $$\pmb\mu= \rm{IMAG}\; \rm{LOG}\; \langle \psi_a|\exp(\it i\frac{2\pi}{\it L}\pmb r)|\psi_b\rangle\; $$ My implementation is as follows: $n$ is the number of grid points of CUBE file in each direction. $b$ is the step length. So the lattice constant $L$ is $nb$. $\pmb r$ is the coordinate. psi_a and psi_b are the volumetric data which are changed to 1D arrays. $dd=\exp(i2\pi \pmb r/L)$.
However, the above implementation didn't give me correct numbers as I expected. So please can anyone help me point out the problems of the implementation?