From 561697246048f1762c6525649b8484b288475ebc Mon Sep 17 00:00:00 2001 From: fishjojo Date: Sun, 5 Feb 2023 19:48:51 -0800 Subject: [PATCH] fix k-point symmetry adapted KS-DFT with Newton solver (issue #1462) --- pyscf/pbc/dft/numint.py | 7 +++++++ pyscf/pbc/dft/test/test_krks_ksym.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/pyscf/pbc/dft/numint.py b/pyscf/pbc/dft/numint.py index a8ca103c28..74ba8349fe 100644 --- a/pyscf/pbc/dft/numint.py +++ b/pyscf/pbc/dft/numint.py @@ -27,6 +27,7 @@ from pyscf.dft.gen_grid import NBINS, CUTOFF, ALIGNMENT_UNIT from pyscf.pbc.dft.gen_grid import make_mask, BLKSIZE from pyscf.pbc.lib.kpts_helper import member, is_zero +from pyscf.pbc.lib.kpts import KPoints def eval_ao(cell, coords, kpt=numpy.zeros(3), deriv=0, relativity=0, shls_slice=None, @@ -554,6 +555,8 @@ def nr_rks_fxc(ni, cell, grids, xc_code, dm0, dms, relativity=0, hermi=0, ''' if kpts is None: kpts = numpy.zeros((1,3)) + if isinstance(kpts, KPoints): + kpts = kpts.kpts_ibz xctype = ni._xc_type(xc_code) if xctype == 'LDA': ao_deriv = 0 @@ -843,6 +846,10 @@ def cache_xc_kernel(ni, cell, grids, xc_code, mo_coeff, mo_occ, spin=0, ''' if kpts is None: kpts = numpy.zeros((1,3)) + if isinstance(kpts, KPoints): + mo_coeff = kpts.transform_mo_coeff(mo_coeff) + mo_occ = kpts.transform_mo_occ(mo_occ) + kpts = kpts.kpts xctype = ni._xc_type(xc_code) if xctype == 'GGA': ao_deriv = 1 diff --git a/pyscf/pbc/dft/test/test_krks_ksym.py b/pyscf/pbc/dft/test/test_krks_ksym.py index caa5db1573..f55e78a43b 100644 --- a/pyscf/pbc/dft/test/test_krks_ksym.py +++ b/pyscf/pbc/dft/test/test_krks_ksym.py @@ -152,6 +152,20 @@ def test_gga_df(self): kmf.kernel() self.assertAlmostEqual(kmf.e_tot, kmf0.e_tot, 9) + def test_gga_df_newton(self): + kpts0 = He.make_kpts(nk, with_gamma_point=False) + kmf0 = krks.KRKS(He, kpts=kpts0).density_fit() + kmf0.xc = 'pbe' + kmf0 = kmf0.newton() + kmf0.kernel() + + kpts = He.make_kpts(nk, with_gamma_point=False, space_group_symmetry=True,time_reversal_symmetry=True) + kmf = pscf.KRKS(He, kpts=kpts).density_fit() + kmf.xc = 'pbe' + kmf = kmf.newton() + kmf.kernel() + self.assertAlmostEqual(kmf.e_tot, kmf0.e_tot, 9) + def test_rsh_df(self): kpts0 = He.make_kpts(nk, with_gamma_point=False) kmf0 = krks.KRKS(He, kpts=kpts0).density_fit()