Skip to content

Commit 7d71158

Browse files
committed
more tests
1 parent 611c883 commit 7d71158

5 files changed

Lines changed: 94 additions & 2 deletions

File tree

‎pyscf/dh/dh.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ def __del__(self):
150150
self.tensors.close()
151151
except Exception:
152152
pass
153+
for attr in (getattr(self, 'xc', ''), getattr(self, 'xc_n', '')):
154+
if attr and attr.startswith('__dh_'):
155+
try:
156+
from pyscf.dft.libxc import unregister_custom_functional_
157+
unregister_custom_functional_(attr)
158+
except Exception:
159+
pass
153160

154161
@timing
155162
def energy_elec_nc(self, mo_coeff=None, h1e=None, vhf=None, **_):

‎pyscf/dh/dhutil.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import os
2222
import pickle
2323
import shutil
24+
import tempfile
2425

2526
import h5py
2627
from pyscf import lib, gto
@@ -68,7 +69,7 @@ def __init__(self, chkfile_name=None, dir=None, **kwargs):
6869
if dir is None:
6970
dir = lib.param.TMPDIR
7071
if chkfile_name is None:
71-
self._chkfile = lib.NamedTemporaryFile(dir=dir)
72+
self._chkfile = tempfile.NamedTemporaryFile(dir=dir)
7273
chkfile_name = self._chkfile.name
7374
# create or open exist chkfile
7475
self.chkfile_name = chkfile_name

‎pyscf/dh/test/test_dfdh_extra.py‎

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
"""Known reference energy tests for DH functionals.
2+
"""
3+
4+
import unittest
5+
from pyscf import gto
6+
from pyscf.dh import DFDH
7+
8+
9+
class TestKnownEnergy(unittest.TestCase):
10+
11+
def test_DSD_PBEPBE_D3BJ(self):
12+
ref = -76.20415120 # QChem 5.1.1
13+
mol = gto.M(atom="O; H 1 0.94; H 1 0.94 2 104.5", basis="6-31G").build()
14+
mf = DFDH(mol, xc="DSD-PBEPBE-D3BJ").run()
15+
self.assertAlmostEqual(mf.e_tot, ref, places=4)
16+
17+
def test_DSD_PBEB95_D3BJ(self):
18+
ref = -76.22012321 # QChem 5.1.1
19+
mol = gto.M(atom="O; H 1 0.94; H 1 0.94 2 104.5", basis="6-31G").build()
20+
mf = DFDH(mol, xc="DSD-PBEB95-D3BJ").run()
21+
self.assertAlmostEqual(mf.e_tot, ref, places=4)
22+
23+
def test_wB2PLYP(self):
24+
ref = -76.223828450855 # ORCA 5.0.4
25+
mol = gto.M(atom="O; H 1 0.94; H 1 0.94 2 104.5", basis="6-31G").build()
26+
mf = DFDH(mol, xc="wB2PLYP").run()
27+
self.assertAlmostEqual(mf.e_tot, ref, places=4)
28+
29+
def test_wB2GPPLYP(self):
30+
ref = -76.216969239009 # ORCA 5.0.4
31+
mol = gto.M(atom="O; H 1 0.94; H 1 0.94 2 104.5", basis="6-31G").build()
32+
mf = DFDH(mol, xc="wB2GPPLYP").run()
33+
self.assertAlmostEqual(mf.e_tot, ref, places=4)
34+
35+
def test_wB88PP86(self):
36+
ref = -76.223203247789 # ORCA 5.0.4
37+
mol = gto.M(atom="O; H 1 0.94; H 1 0.94 2 104.5", basis="6-31G").build()
38+
mf = DFDH(mol, xc="wB88PP86").run()
39+
self.assertAlmostEqual(mf.e_tot, ref, places=4)
40+
41+
def test_wPBEPP86(self):
42+
ref = -76.261632401477 # ORCA 5.0.4
43+
mol = gto.M(atom="O; H 1 0.94; H 1 0.94 2 104.5", basis="6-31G").build()
44+
mf = DFDH(mol, xc="wPBEPP86").run()
45+
self.assertAlmostEqual(mf.e_tot, ref, places=4)
46+
47+
def test_RSX_0DH(self):
48+
ref = -76.223451307545 # ORCA 5.0.4
49+
mol = gto.M(atom="O; H 1 0.94; H 1 0.94 2 104.5", basis="6-31G").build()
50+
mf = DFDH(mol, xc="RSX-0DH").run()
51+
self.assertAlmostEqual(mf.e_tot, ref, places=4)
52+
53+
def test_RSX_QIDH(self):
54+
ref = -76.208221215310 # ORCA 5.0.4
55+
mol = gto.M(atom="O; H 1 0.94; H 1 0.94 2 104.5", basis="6-31G").build()
56+
mf = DFDH(mol, xc="RSX-QIDH").run()
57+
self.assertAlmostEqual(mf.e_tot, ref, places=4)
58+
59+
def test_PTPSS(self):
60+
ref = -76.28365901 # QChem 5.1.1
61+
mol = gto.M(atom="O; H 1 0.94; H 1 0.94 2 104.5", basis="6-31G").build()
62+
mf = DFDH(mol, xc="PTPSS").run()
63+
self.assertAlmostEqual(mf.e_tot, ref, places=4)
64+
65+
def test_PWPB95(self):
66+
ref = -76.30404653 # QChem 5.1.1
67+
mol = gto.M(atom="O; H 1 0.94; H 1 0.94 2 104.5", basis="6-31G").build()
68+
mf = DFDH(mol, xc="PWPB95").run()
69+
self.assertAlmostEqual(mf.e_tot, ref, places=4)
70+
71+
@unittest.skip('customized RSH support')
72+
def test_wB97X_2_TQZ(self):
73+
ref = -76.24074263 # QChem 5.1.1
74+
mol = gto.M(atom="O; H 1 0.94; H 1 0.94 2 104.5", basis="6-31G").build()
75+
mf = DFDH(mol, xc="wB97X-2-TQZ").run()
76+
self.assertAlmostEqual(mf.e_tot, ref, places=4)
77+
78+
@unittest.skip('customized RSH support')
79+
def test_wB97X_2_LP(self):
80+
ref = -76.28031455 # QChem 5.1.1
81+
mol = gto.M(atom="O; H 1 0.94; H 1 0.94 2 104.5", basis="6-31G").build()
82+
mf = DFDH(mol, xc="wB97X-2-LP").run()
83+
self.assertAlmostEqual(mf.e_tot, ref, places=4)

‎pyscf/dh/xccode/functionals/family_bdh.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@
250250
],
251251
"supported": false
252252
},
253+
253254
"wB97X_2_TQZ": {
254255
"code": "HYB_GGA_XC_WB97X(_alpha=1, _beta=-0.363842, _omega=0.3, _cx0=0.315503, _cx1=1.04772, _cx2=-2.33506, _cx3=3.19909, _cx4=0, _css0=0.908460, _css1=-2.80936, _css2=6.02676, _css3=-4.56981, _css4=0, _cos0=0.518198, _cos1=-0.585956, _cos2=4.27080, _cos3=-6.48897, _cos4=0), 0.529319*MP2_SS + 0.447105*MP2_OS",
255256
"ref": "10.1063/1.3244209",

‎pyscf/dh/xccode/parse.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _register_ext_params(xc_list):
5757
if not ext_params:
5858
return None
5959
base_token = xc_list.token
60-
reg_name = f"__dh_{abs(hash(base_token)):x}"
60+
reg_name = f"__dh_{abs(hash((base_token, tuple((k, v.tobytes()) for k, v in sorted(ext_params.items()))))):x}"
6161
dft.libxc.register_custom_functional_(
6262
reg_name, base_token, ext_params=ext_params)
6363
return reg_name.lower()

0 commit comments

Comments
 (0)