Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sunqm committed Aug 27, 2024
1 parent ad53183 commit c94fcba
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pyscf/grad/test/test_tduhf_grad.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_tda(self):
self.assertAlmostEqual((e1[2]-e2[2])/.002, g1[0,2], 4)

def test_tdhf(self):
td = tdscf.TDDFT(mf).run(nstates=nstates)
td = tdscf.TDDFT(mf).run(nstates=nstates, conv_tol=1e-6)
tdg = td.nuc_grad_method()
g1 = tdg.kernel(td.xy[2])
self.assertAlmostEqual(g1[0,2], -0.78969714300299776, 5)
Expand Down
2 changes: 1 addition & 1 deletion pyscf/grad/test/test_tduks_grad.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_tddft_b3lyp(self):
mf = dft.UKS(mol).set(conv_tol=1e-12)
mf.xc = '.2*HF + .8*b88, vwn'
mf.scf()
td = tdscf.TDDFT(mf).run(nstates=nstates)
td = tdscf.TDDFT(mf).run(nstates=nstates, conv_tol=1e-6)
tdg = td.nuc_grad_method()
g1 = tdg.kernel(state=3)
self.assertAlmostEqual(g1[0,2], -0.80446691153291727, 6)
Expand Down
2 changes: 1 addition & 1 deletion pyscf/pbc/tdscf/test/test_krks.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def test_tda_triplet(self):

def test_tdhf_singlet(self):
ref = [[9.25192096, 9.32080304]]
td = self.kernel('TDDFT', ref)
td = self.kernel('TDDFT', ref, conv_tol=1e-6)
a, b = td.get_ab(kshift=0)
eref = diagonalize(a, b)
self.assertAlmostEqual(abs(td.e[0][:2] - eref[:2]).max(), 0, 8)
Expand Down
7 changes: 4 additions & 3 deletions pyscf/pbc/tdscf/test/test_uks.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,12 @@ def test_tda(self):
self.assertAlmostEqual(abs(td.e[:2] - eref[:2]).max(), 0, 8)

def test_tdhf(self):
ref = [4.68534716, 4.79043398]
td = self.kernel('TDDFT', ref)
# nstates=6 is required to derive the lowest state
ref = [4.6851639, 4.7903984, 4.7903984]
td = self.kernel('TDDFT', ref[1:3])
a, b = td.get_ab()
eref = diagonalize(a, b)
self.assertAlmostEqual(abs(td.e[:2] - eref[:2]).max(), 0, 8)
self.assertAlmostEqual(abs(td.e[:2] - eref[1:3]).max(), 0, 8)


class WaterBigBoxPBE0(unittest.TestCase):
Expand Down
8 changes: 4 additions & 4 deletions pyscf/x2c/tdscf.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,9 @@ def gen_vind(self, mf=None):
mf = self._scf
return gen_tda_hop(mf)

def init_guess(self, mf, nstates=None, wfnsym=None):
def init_guess(self, mf, nstates=None, wfnsym=None, return_symmetry=False):
assert self.wfnsym is None
return ghf.TDA.init_guess(self, mf, nstates, None)
return ghf.TDA.init_guess(self, mf, nstates, None, return_symmetry)

kernel = ghf.TDA.kernel

Expand All @@ -313,9 +313,9 @@ def gen_vind(self, mf=None):
mf = self._scf
return gen_tdhf_operation(mf)

def init_guess(self, mf, nstates=None, wfnsym=None):
def init_guess(self, mf, nstates=None, wfnsym=None, return_symmetry=False):
assert self.wfnsym is None
return ghf.TDHF.init_guess(self, mf, nstates, None)
return ghf.TDHF.init_guess(self, mf, nstates, None, return_symmetry)

kernel = ghf.TDHF.kernel

Expand Down
6 changes: 3 additions & 3 deletions pyscf/x2c/test/test_tdscf.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def test_mcol_mgga_ab_ks(self):
mcol_m06l = dft.UKS(mol).set(xc='m06l', collinear='mcol')
mcol_m06l._numint.spin_samples = 6
mcol_m06l.__dict__.update(scf.chkfile.load(mf_lda.chkfile, 'scf'))
self._check_against_ab_ks(mcol_m06l.TDDFT(), -0.6984240332038076, 2.0192987108288794)
self._check_against_ab_ks(mcol_m06l.TDDFT(), -0.6984240332038076, 2.0192987108288794, 5)

def _check_against_ab_ks(self, td, refa, refb, places=6):
mf = td._scf
Expand Down Expand Up @@ -144,7 +144,7 @@ def _check_against_ab_ks(self, td, refa, refb, places=6):
def test_mcol_vs_gks(self):
with lib.temporary_env(lib.param, LIGHT_SPEED=20):
mol = gto.M(atom='C', basis='6-31g')
ref = dft.RKS(mol)
ref = dft.UKS(mol)
ref.xc = 'pbe'
ref.collinear = 'mcol'
ref._numint.spin_samples = 6
Expand All @@ -165,7 +165,7 @@ def test_mcol_vs_gks(self):
td = mf.TDA()
td.positive_eig_threshold = -10
es = td.kernel(nstates=5)[0]
self.assertAlmostEqual(abs(es - eref).max(), 0, 7)
self.assertAlmostEqual(abs(es - eref).max(), 0, 6)


if __name__ == "__main__":
Expand Down

0 comments on commit c94fcba

Please sign in to comment.