Permalink
Browse files

disp: allow dispersion in user-defined dict fctls

  • Loading branch information...
loriab committed Oct 3, 2018
1 parent 349efcc commit 60da95c7682710dea5c19d352297f9a3d1e5fda5
@@ -186,6 +186,13 @@ def compute_energy(self, molecule):
float
Dispersion energy [Eh].
Notes
-----
DISPERSION CORRECTION ENERGY
Disp always set. Overridden in SCF finalization, but that only changes for "-3C" methods.
self.fctldash + DISPERSION CORRECTION ENERGY
Set if `fctldash` nonempty.
"""
if self.engine == 'dftd3':
jobrec = intf_dftd3.run_dftd3_from_arrays(
@@ -208,8 +215,11 @@ def compute_energy(self, molecule):
return dashd_part
else:
return self.disp.compute_energy(molecule)
# TODO need to set 'DISPERSION CORRECTION ENERGY' and self.fctldash + 'DISPERSION CORRECTION ENERGY' psivars for libdisp?
ene = self.disp.compute_energy(molecule)
core.set_variable('DISPERSION CORRECTION ENERGY', ene)
if self.fctldash:
core.set_variable('{} DISPERSION CORRECTION ENERGY'.format(self.fctldash), ene)
return ene
def compute_gradient(self, molecule):
"""Compute dispersion gradient based on engine, dispersion level, and parameters in `self`.
@@ -1015,7 +1015,15 @@ def scf_wavefunction_factory(name, ref_wfn, reference, **kwargs):
raise ValidationError("SCF: Unknown reference (%s) when building the Wavefunction." % reference)
if disp_type:
wfn._disp_functor = empirical_dispersion.EmpiricalDispersion(
if isinstance(name, dict):
wfn._disp_functor = empirical_dispersion.EmpiricalDispersion(
name_hint='',
level_hint=disp_type["type"],
citation=disp_type["citation"],
param_tweaks=disp_type["params"],
engine=kwargs.get('engine', None))
else:
wfn._disp_functor = empirical_dispersion.EmpiricalDispersion(
name_hint=superfunc.name(),
level_hint=disp_type["type"],
citation=disp_type["citation"],
@@ -318,10 +318,12 @@ def dftd3_harvest(jobrec, dftd3rec):
# OLD WAY
calcinfo = []
calcinfo.append(QCAspect('DISPERSION CORRECTION ENERGY', 'Eh', ene, ''))
calcinfo.append(QCAspect('{} DISPERSION CORRECTION ENERGY'.format(qcvkey), 'Eh', ene, ''))
if qcvkey:
calcinfo.append(QCAspect('{} DISPERSION CORRECTION ENERGY'.format(qcvkey), 'Eh', ene, ''))
if jobrec['driver'] == 'gradient':
calcinfo.append(QCAspect('DISPERSION CORRECTION GRADIENT', 'Eh/a0', fullgrad, ''))
calcinfo.append(QCAspect('{} DISPERSION CORRECTION GRADIENT'.format(qcvkey), 'Eh/a0', fullgrad, ''))
if qcvkey:
calcinfo.append(QCAspect('{} DISPERSION CORRECTION GRADIENT'.format(qcvkey), 'Eh/a0', fullgrad, ''))
calcinfo = {info.lbl: info for info in calcinfo}
text += print_variables(calcinfo)
@@ -39,3 +39,54 @@ compare_values(test_dict["PBE"], ret, 5, "RKS 0 1 PBE Energy, dft_f
ret = energy("scf", dft_functional=pbe)
compare_values(test_dict["PBE"], ret, 5, "RKS 0 1 PBE Energy, dft_functional=dict()") #TEST
test_dict_dash = {
'E': {'075': -3.958e-05,
'100': -5.278e-05,
'200': -0.00010556
},
'G': {'075':
[[ 0.00000000e+00, 0.00000000e+00, 1.54317695e-06],
[ 0.00000000e+00, 1.21681806e-04, -7.71588475e-07],
[ 0.00000000e+00, -1.21681806e-04, -7.71588475e-07]],
'100':
[[ 0.00000000e+00, 0.00000000e+00, 2.05756927e-06],
[ 0.00000000e+00, 1.62242408e-04, -1.02878463e-06],
[ 0.00000000e+00, -1.62242408e-04, -1.02878463e-06]],
'200':
[[ 0.00000000e+00, 0.00000000e+00, 4.11513853e-06],
[ 0.00000000e+00, 3.24484816e-04, -2.05756927e-06],
[ 0.00000000e+00, -3.24484816e-04, -2.05756927e-06]]
}
}
pbed2 = {
"name": "PBED2-TEST",
"x_functionals": { "GGA_X_PBE": {} },
"c_functionals": { "GGA_C_PBE": {} },
"dispersion": {
"type": "d2",
"params": {"s6": 0.75,
"alpha6": 20.0,
"sr6": 1.1
}
}
}
ret = energy('scf', dft_functional=pbed2)
compare_values(test_dict['PBE'] + test_dict_dash['E']['075'], ret, 5, 'PBE-D2 Energy, dft_functional=dict(s6=native)')
compare_values(test_dict_dash['E']['075'], get_variable('PBE-D2 dispersion correction energy'), 5, 'PBE-D2 Energy, dft_functional=dict(s6=native)')
clean()
import numpy as np
pbed2['dispersion']['params']['s6'] = 1.0
ret = energy('scf', dft_functional=pbed2)
compare_values(test_dict['PBE'] + test_dict_dash['E']['100'], ret, 5, 'PBE-D2 Energy, dft_functional=dict(s6=1.0)')
compare_values(test_dict_dash['E']['100'], get_variable('tpss-d2 dispersion correction energy'), 5, 'PBE-D2 Energy, dft_functional=dict(s6=1.0)')
clean()
set dft_dispersion_parameters [1.0]
pbed2['dispersion']['params']['s6'] = 2.0
ret = energy('scf', dft_functional=pbed2)
compare_values(test_dict['PBE'] + test_dict_dash['E']['200'], ret, 5, 'user option s6 irrelevant to dft_functional')
clean()

0 comments on commit 60da95c

Please sign in to comment.