Skip to content

Commit fbb1a2f

Browse files
committed
bugfix dftd4
1 parent 748f735 commit fbb1a2f

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

pyscf/dispersion/dftd4.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(self, mol, xc, version='d4', ga=None, gc=None, wf=None, atm=False):
5353
nuc_types = [gto.charge(mol.atom_symbol(ia))
5454
for ia in range(mol.natm)]
5555
nuc_types = np.asarray(nuc_types, dtype=np.int32)
56-
56+
5757
self.natm = mol.natm
5858
if isinstance(mol, gto.Mole):
5959
lattice = lib.c_null_ptr()
@@ -73,27 +73,29 @@ def __init__(self, mol, xc, version='d4', ga=None, gc=None, wf=None, atm=False):
7373
lattice, periodic,
7474
)
7575
error_check(err)
76-
if version.lower()[:2] == 'd4':
76+
if version.lower() == 'd4':
7777
if ga is None and gc is None and wf is None:
7878
self._disp = libdftd4.dftd4_new_d4_model(err, self._mol)
7979
else:
8080
# Default from DFTD4 repo, https://github.com/dftd4/dftd4/blob/main/python/dftd4/interface.py#L290
8181
if ga is None: ga = 3.0
8282
if gc is None: gc = 2.0
8383
if wf is None: wf = 6.0
84-
self._disp = libdftd4.dftd4_custom_d4_model(err, self._mol,
85-
ctypes.c_double(ga),
86-
ctypes.c_double(gc),
84+
self._disp = libdftd4.dftd4_custom_d4_model(err, self._mol,
85+
ctypes.c_double(ga),
86+
ctypes.c_double(gc),
8787
ctypes.c_double(wf))
88-
elif version.lower()[:2] == 'd4s':
88+
elif version.lower() == 'd4s':
8989
if ga is None and gc is None:
9090
self._disp = libdftd4.dftd4_new_d4s_model(err, self._mol)
9191
else:
9292
if ga is None: ga = 3.0
9393
if gc is None: gc = 2.0
94-
self._disp = libdftd4.dftd4_custom_d4s_model(err, self._mol,
95-
ctypes.c_double(ga),
94+
self._disp = libdftd4.dftd4_custom_d4s_model(err, self._mol,
95+
ctypes.c_double(ga),
9696
ctypes.c_double(gc))
97+
else:
98+
raise ValueError('version must be d4 or d4s')
9799
error_check(err)
98100
self._param = libdftd4.dftd4_load_rational_damping(
99101
err,
@@ -116,10 +118,10 @@ def __del__(self):
116118
def set_param(self, s8, a1, a2, s6=1.0, s9=1.0, alp=16.0):
117119
self._param = libdftd4.dftd4_new_rational_damping(
118120
ctypes.c_double(s6),
119-
ctypes.c_double(s8),
120-
ctypes.c_double(s9),
121-
ctypes.c_double(a1),
122-
ctypes.c_double(a2),
121+
ctypes.c_double(s8),
122+
ctypes.c_double(s9),
123+
ctypes.c_double(a1),
124+
ctypes.c_double(a2),
123125
ctypes.c_double(alp))
124126
return
125127

0 commit comments

Comments
 (0)