I tested the Green's function G(r,r',k,w) against the sum-over-state expression. OK, the off-diagonal elements work perfectly. Also the case k/=0 works perfectly. I need about 100 iterations to have the Green's function converged with delta = 0.1 eV. It looks like the Green's function converges from the bottom, i.e. the more iterations we do, the larger the energy range where it matches the full calculation based on the sum-over-states.