Skip to content

Commit d57f1d6

Browse files
fishjojosunqm
authored andcommitted
fix pbc df with KPoints input
1 parent fdd4e48 commit d57f1d6

File tree

6 files changed

+25
-7
lines changed

6 files changed

+25
-7
lines changed

pyscf/pbc/df/df.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
from pyscf.pbc.df import df_ao2mo
5454
from pyscf.pbc.df.aft import estimate_eta, _check_kpts
5555
from pyscf.pbc.df.df_jk import zdotCN
56+
from pyscf.pbc.lib.kpts import KPoints
5657
from pyscf.pbc.lib.kpts_helper import (is_zero, gamma_point, member, unique,
5758
KPT_DIFF_TOL)
5859
from pyscf.pbc.df.gdf_builder import libpbc, _CCGDFBuilder, _CCNucBuilder
@@ -146,6 +147,8 @@ def __init__(self, cell, kpts=numpy.zeros((1,3))):
146147
self.verbose = cell.verbose
147148
self.max_memory = cell.max_memory
148149

150+
if isinstance(kpts, KPoints):
151+
kpts = kpts.kpts
149152
self.kpts = kpts # default is gamma point
150153
self.kpts_band = None
151154
self._auxbasis = None

pyscf/pbc/df/df_jk.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from pyscf import lib
2929
from pyscf.lib import logger, zdotNN, zdotCN, zdotNC
3030
from pyscf.pbc import tools
31-
from pyscf.pbc.lib.kpts import KPoints
3231
from pyscf.pbc.lib.kpts_helper import is_zero, gamma_point, member, get_kconserv_ria
3332
from pyscf import __config__
3433

@@ -53,8 +52,6 @@ def density_fit(mf, auxbasis=None, mesh=None, with_df=None):
5352
else:
5453
kpts = numpy.reshape(mf.kpt, (1,3))
5554

56-
if isinstance(kpts, KPoints):
57-
kpts = kpts.kpts
5855
with_df = df.DF(mf.cell, kpts)
5956
with_df.max_memory = mf.max_memory
6057
with_df.stdout = mf.stdout

pyscf/pbc/df/fft.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from pyscf.pbc.df import fft_jk
3131
from pyscf.pbc.df import aft
3232
from pyscf.pbc.df.aft import _check_kpts
33+
from pyscf.pbc.lib.kpts import KPoints
3334
from pyscf.pbc.lib.kpts_helper import is_zero
3435
from pyscf import __config__
3536

@@ -168,6 +169,8 @@ def __init__(self, cell, kpts=numpy.zeros((1,3))):
168169
self.verbose = cell.verbose
169170
self.max_memory = cell.max_memory
170171

172+
if isinstance(kpts, KPoints):
173+
kpts = kpts.kpts
171174
self.kpts = kpts
172175

173176
self.grids = gen_grid.UniformGrids(cell)

pyscf/pbc/df/mdf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from pyscf.pbc.df.gdf_builder import _CCGDFBuilder
3939
from pyscf.pbc.df.rsdf_builder import _RSGDFBuilder
4040
from pyscf.pbc.df.incore import libpbc, make_auxcell
41+
from pyscf.pbc.lib.kpts import KPoints
4142
from pyscf.pbc.lib.kpts_helper import is_zero, member, unique
4243
from pyscf.pbc.df import mdf_jk
4344
from pyscf.pbc.df import mdf_ao2mo
@@ -55,6 +56,8 @@ def __init__(self, cell, kpts=np.zeros((1,3))):
5556
self.verbose = cell.verbose
5657
self.max_memory = cell.max_memory
5758

59+
if isinstance(kpts, KPoints):
60+
kpts = kpts.kpts
5861
self.kpts = kpts # default is gamma point
5962
self.kpts_band = None
6063
self._auxbasis = None

pyscf/pbc/df/mdf_jk.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from pyscf.lib import logger
2727
from pyscf.pbc.df import df_jk
2828
from pyscf.pbc.df import aft_jk
29-
from pyscf.pbc.lib.kpts import KPoints
3029

3130
#
3231
# Divide the Coulomb potential to two parts. Computing short range part in
@@ -52,8 +51,6 @@ def density_fit(mf, auxbasis=None, mesh=None, with_df=None):
5251
else:
5352
kpts = numpy.reshape(mf.kpt, (1,3))
5453

55-
if isinstance(kpts, KPoints):
56-
kpts = kpts.kpts
5754
with_df = mdf.MDF(mf.cell, kpts)
5855
with_df.max_memory = mf.max_memory
5956
with_df.stdout = mf.stdout

pyscf/pbc/df/test/test_df.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from pyscf import ao2mo, gto
2121
from pyscf.pbc import gto as pgto
2222
from pyscf.pbc import scf as pscf
23-
from pyscf.pbc.df import df, aug_etb, FFTDF
23+
from pyscf.pbc.df import df, aug_etb, FFTDF, mdf
2424
from pyscf.pbc.df import gdf_builder
2525
#from mpi4pyscf.pbc.df import df
2626
pyscf.pbc.DEBUG = False
@@ -250,6 +250,21 @@ def test_cell_with_cart(self):
250250
eri1 = df.GDF(cell).set(auxbasis=aug_etb(cell)).get_eri()
251251
self.assertAlmostEqual(abs(eri1-eri0).max(), 0, 2)
252252

253+
def test_kpoints_input(sef):
254+
cell.space_group_symmetry = True
255+
cell.build()
256+
kpts = cell.make_kpts([2,2,2],
257+
space_group_symmetry=True,
258+
time_reversal_symmetry=True)
259+
260+
mydf = df.GDF(cell, kpts=kpts)
261+
assert mydf.kpts.shape == (8,3)
262+
263+
mydf = FFTDF(cell, kpts=kpts)
264+
assert mydf.kpts.shape == (8,3)
265+
266+
mydf = mdf.MDF(cell, kpts=kpts)
267+
assert mydf.kpts.shape == (8,3)
253268

254269
if __name__ == '__main__':
255270
print("Full Tests for df")

0 commit comments

Comments
 (0)