Skip to content

Commit 15fe91b

Browse files
committed
Add warning msgs
1 parent 6baa694 commit 15fe91b

3 files changed

Lines changed: 33 additions & 22 deletions

File tree

pyscf/pbc/df/aft.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,17 @@ def get_nuc(mydf, kpts=None):
233233
return nuc
234234

235235

236-
def weighted_coulG(mydf, kpt=np.zeros(3), exx=False, mesh=None, omega=None):
236+
def weighted_coulG(mydf, kpt=np.zeros(3), exx=False, mesh=None, omega=None,
237+
kmesh=kmesh):
237238
'''Weighted regular Coulomb kernel'''
238239
cell = mydf.cell
239240
if mesh is None:
240241
mesh = mydf.mesh
241242
Gv, Gvbase, kws = cell.get_Gv_weights(mesh)
242-
coulG = tools.get_coulG(cell, kpt, exx, mydf, mesh, Gv, omega=omega)
243+
if kmesh is not None:
244+
mydf = None
245+
coulG = tools.get_coulG(cell, kpt, exx, mydf, mesh, Gv, omega=omega,
246+
kmesh=kmesh)
243247
coulG *= kws
244248
return coulG
245249

pyscf/pbc/df/aft_jk.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,14 @@ def get_k_kpts(mydf, dm_kpts, hermi=1, kpts=numpy.zeros((1,3)), kpts_band=None,
154154
weight = 1. / nkpts
155155

156156
aosym = 's1'
157-
bvk_kmesh = k2gamma.kpts_to_kmesh(cell, kpts)
157+
kmesh = k2gamma.kpts_to_kmesh(cell, kpts)
158+
if nkpts != np.prod(kmesh):
159+
logger.warning(
160+
mydf, 'Input kpts differ from the kpts attribute stored in the FFTDF '
161+
'instance. The instance value will be ignored.')
162+
158163
rcut = ft_ao.estimate_rcut(cell)
159-
supmol = ft_ao.ExtendedMole.from_cell(cell, bvk_kmesh, rcut.max())
164+
supmol = ft_ao.ExtendedMole.from_cell(cell, kmesh, rcut.max())
160165
supmol = supmol.strip_basis(rcut)
161166

162167
t_rev_pairs = group_by_conj_pairs(cell, kpts, return_kpts_pairs=False)
@@ -266,7 +271,7 @@ def get_k_kpts(mydf, dm_kpts, hermi=1, kpts=numpy.zeros((1,3)), kpts_band=None,
266271

267272
for group_id, (kpt, ki_idx, kj_idx, self_conj) \
268273
in enumerate(kk_adapted_iter(cell, kpts)):
269-
vkcoulG = mydf.weighted_coulG(kpt, exxdiv, mesh)
274+
vkcoulG = mydf.weighted_coulG(kpt, exxdiv, mesh, kmesh=kmesh)
270275
for p0, p1 in lib.prange(0, ngrids, Gblksize):
271276
log.debug3('update_vk [%s:%s]', p0, p1)
272277
Gpq = ft_kern(Gv[p0:p1], gxyz[p0:p1], Gvbase, kpt, out=buf)
@@ -303,6 +308,12 @@ def get_k_for_bands(mydf, dm_kpts, hermi=1, kpts=numpy.zeros((1,3)), kpts_band=N
303308
dms = _format_dms(dm_kpts, kpts)
304309
nset, nkpts, nao = dms.shape[:3]
305310

311+
kmesh = k2gamma.kpts_to_kmesh(cell, kpts)
312+
if nkpts != np.prod(kmesh):
313+
logger.warning(
314+
mydf, 'Input kpts differ from the kpts attribute stored in the FFTDF '
315+
'instance. The instance value will be ignored.')
316+
306317
swap_2e = (kpts_band is None)
307318
kpts_band, input_band = _format_kpts_band(kpts_band, kpts), kpts_band
308319
nband = len(kpts_band)
@@ -336,7 +347,7 @@ def make_kpt(kpt): # kpt = kptj - kpti
336347
#bufR = numpy.empty((blksize*nao**2))
337348
#bufI = numpy.empty((blksize*nao**2))
338349
# Use DF object to mimic KRHF/KUHF object in function get_coulG
339-
vkcoulG = mydf.weighted_coulG(kpt, exxdiv, mesh)
350+
vkcoulG = mydf.weighted_coulG(kpt, exxdiv, mesh, kmesh=kmesh)
340351
weight = 1./len(kpts)
341352
perm_sym = swap_2e and not is_zero(kpt)
342353
for Gpq, p0, p1 in mydf.ft_loop(mesh, kpt, kpts, max_memory=max_memory1,

pyscf/pbc/df/fft_jk.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from pyscf.lib import logger
2727
from pyscf.pbc import tools
2828
from 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
3029
from pyscf.pbc.lib.kpts_helper import is_zero
3130
from 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

311302
def 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

Comments
 (0)