Skip to content

Commit

Permalink
Add more tests for df methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sunqm committed Aug 5, 2022
1 parent 390d551 commit fff48d2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ omit = */dmrgscf/*
*/pbc/mpicc/*
*/pbc/mpitools/*
*/gen_*_param.py
*slow*
disable_warnings = include-ignored

[report]
Expand Down
20 changes: 20 additions & 0 deletions pyscf/df/test/test_df_grad.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ def test_rhf_grad(self):
g1 = scf.RHF(mol).density_fit().run().nuc_grad_method().kernel()
self.assertAlmostEqual(abs(gref - g1).max(), 0, 5)

def test_rks_lda_grad(self):
gref = mol.RKS(xc='lda,').run().nuc_grad_method().kernel()
g1 = mol.RKS(xc='lda,').density_fit().run().nuc_grad_method().kernel()
self.assertAlmostEqual(abs(gref - g1).max(), 0, 4)

def test_rks_grad(self):
gref = mol.RKS(xc='b3lyp').run().nuc_grad_method().kernel()
g1 = mol.RKS(xc='b3lyp').density_fit().run().nuc_grad_method().kernel()
self.assertAlmostEqual(abs(gref - g1).max(), 0, 4)

def test_uhf_grad(self):
gref = mol.UHF.run().nuc_grad_method().kernel()
g1 = mol.UHF.density_fit().run().nuc_grad_method().kernel()
self.assertAlmostEqual(abs(gref - g1).max(), 0, 5)

def test_uks_lda_grad(self):
gref = mol.UKS.run(xc='lda,').nuc_grad_method().kernel()
g1 = mol.UKS.density_fit().run(xc='lda,').nuc_grad_method().kernel()
self.assertAlmostEqual(abs(gref - g1).max(), 0, 4)

def test_uks_grad(self):
gref = mol.UKS.run(xc='b3lyp').nuc_grad_method().kernel()
g1 = mol.UKS.density_fit().run(xc='b3lyp').nuc_grad_method().kernel()
Expand Down
25 changes: 17 additions & 8 deletions pyscf/df/test/test_df_hessian.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,25 @@ def tearDownModule():

class KnownValues(unittest.TestCase):
def test_rhf_hess(self):
gref = scf.RHF(mol).run().Hessian().kernel()
g1 = scf.RHF(mol).density_fit().run().Hessian().kernel()
self.assertAlmostEqual(abs(gref - g1).max(), 0, 3)
href = scf.RHF(mol).run().Hessian().kernel()
h1 = scf.RHF(mol).density_fit().run().Hessian().kernel()
self.assertAlmostEqual(abs(href - h1).max(), 0, 3)

def test_rks_hess(self):
href = mol.RKS.run(xc='b3lyp').Hessian().kernel()
h1 = mol.RKS.density_fit().run(xc='b3lyp').Hessian().kernel()
self.assertAlmostEqual(abs(href - h1).max(), 0, 3)

def test_uhf_hess(self):
href = scf.UHF(mol).run().Hessian().kernel()
h1 = scf.UHF(mol).density_fit().run().Hessian().kernel()
self.assertAlmostEqual(abs(href - h1).max(), 0, 3)

def test_uks_hess(self):
gref = mol.UKS.run(xc='b3lyp').Hessian().kernel()
g1 = mol.UKS.density_fit().run(xc='b3lyp').Hessian().kernel()
self.assertAlmostEqual(abs(gref - g1).max(), 0, 3)
#
href = mol.UKS.run(xc='b3lyp').Hessian().kernel()
h1 = mol.UKS.density_fit().run(xc='b3lyp').Hessian().kernel()
self.assertAlmostEqual(abs(href - h1).max(), 0, 3)

if __name__ == "__main__":
print("Full Tests for df.hessian")
unittest.main()

2 changes: 1 addition & 1 deletion pyscf/dft/numint2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ class NumInt2C(numint._NumIntMixin):
collinear_thrd = getattr(__config__, 'dft_numint_RnumInt_collinear_thrd', 0.99)
collinear_samples = getattr(__config__, 'dft_numint_RnumInt_collinear_samples', 200)

eval_rho = eval_rho
eval_rho = staticmethod(eval_rho)

def eval_rho2(self, mol, ao, mo_coeff, mo_occ, non0tab=None, xctype='LDA',
with_lapl=True, verbose=None):
Expand Down

0 comments on commit fff48d2

Please sign in to comment.