2626from pyscf .lib import logger
2727from pyscf .pbc import tools
2828from pyscf .pbc .df .df_jk import _format_dms , _format_kpts_band , _format_jks
29- from pyscf .pbc .df .df_jk import _ewald_exxdiv_for_G0
3029from pyscf .pbc .lib .kpts_helper import is_zero
3130from pyscf .pbc .tools .k2gamma import kpts_to_kmesh
3231
@@ -221,6 +220,12 @@ def get_k_kpts(mydf, dm_kpts, hermi=1, kpts=np.zeros((1,3)), kpts_band=None,
221220 dms = _format_dms (dm_kpts , kpts )
222221 nset , nkpts , nao = dms .shape [:3 ]
223222
223+ kmesh = kpts_to_kmesh (cell , kpts )
224+ if nkpts != np .prod (kmesh ):
225+ logger .warning (
226+ mydf , 'Input kpts differ from the kpts attribute stored in the FFTDF '
227+ 'instance. The instance value will be ignored.' )
228+
224229 weight = 1. / nkpts * (cell .vol / ngrids )
225230
226231 kpts_band , input_band = _format_kpts_band (kpts_band , kpts ), kpts_band
@@ -268,13 +273,7 @@ def get_k_kpts(mydf, dm_kpts, hermi=1, kpts=np.zeros((1,3)), kpts_band=None,
268273 for k1 , ao1T in enumerate (ao1_kpts ):
269274 kpt1 = kpts_band [k1 ]
270275
271- # If we have an ewald exxdiv, we add the G=0 correction near the
272- # end of the function to bypass any discretization errors
273- # that arise from the FFT.
274- if exxdiv == 'ewald' :
275- coulG = tools .get_coulG (cell , kpt2 - kpt1 , False , mydf , mesh )
276- else :
277- coulG = tools .get_coulG (cell , kpt2 - kpt1 , exxdiv , mydf , mesh )
276+ coulG = tools .get_coulG (cell , kpt2 - kpt1 , exxdiv , mesh = mesh , kmesh = kmesh )
278277 if is_zero (kpt1 - kpt2 ):
279278 expmikr = np .array (1. )
280279 else :
@@ -298,14 +297,6 @@ def get_k_kpts(mydf, dm_kpts, hermi=1, kpts=np.zeros((1,3)), kpts_band=None,
298297 vk_kpts [i ,k1 ] += weight * lib .dot (vR_dm [i ], ao1T .T )
299298 t1 = logger .timer_debug1 (mydf , 'get_k_kpts: make_kpt (%d,*)' % k2 , * t1 )
300299
301- # Function _ewald_exxdiv_for_G0 to add back in the G=0 component to vk_kpts
302- # Note in the _ewald_exxdiv_for_G0 implementation, the G=0 treatments are
303- # different for 1D/2D and 3D systems. The special treatments for 1D and 2D
304- # can only be used with AFTDF/GDF/MDF method. In the FFTDF method, 1D, 2D
305- # and 3D should use the ewald probe charge correction.
306- if exxdiv == 'ewald' and cell .dimension != 0 :
307- _ewald_exxdiv_for_G0 (cell , kpts , dms , vk_kpts , kpts_band = kpts_band )
308-
309300 return _format_jks (vk_kpts , dm_kpts , input_band , kpts )
310301
311302def get_k_e1_kpts (mydf , dm_kpts , kpts = np .zeros ((1 ,3 )), kpts_band = None ,
@@ -332,6 +323,11 @@ def get_k_e1_kpts(mydf, dm_kpts, kpts=np.zeros((1,3)), kpts_band=None,
332323 nset , nkpts , nao = dms .shape [:3 ]
333324
334325 kmesh = kpts_to_kmesh (cell , kpts )
326+ if nkpts != np .prod (kmesh ):
327+ logger .warning (
328+ mydf , 'Input kpts differ from the kpts attribute stored in the FFTDF '
329+ 'instance. The instance value will be ignored.' )
330+
335331 weight = 1. / nkpts * (cell .vol / ngrids )
336332
337333 kpts_band , input_band = _format_kpts_band (kpts_band , kpts ), kpts_band
0 commit comments