Permalink
Browse files

disp: mods to dict_builder and some dft definitions

  • Loading branch information...
loriab committed Aug 24, 2018
1 parent b9710f0 commit 3e3d8941557bc2dbcc0794561dcff3efe9093287
@@ -223,9 +223,6 @@ def get_np_xyzw(Vpot):
## Python other helps
core.Molecule.run_dftd3 = qcdb.interface_dftd3.run_dftd3
core.Molecule.run_gcp = qcdb.interface_gcp.run_gcp
def set_options(options_dict):
"""
@@ -77,10 +77,10 @@
"""
from psi4 import core
from psi4.driver.p4util.exceptions import *
from psi4.driver.procrouting.empirical_dispersion import get_dispersion_aliases
from psi4.driver.qcdb.dashparam import dashcoeff
from psi4.driver.qcdb import intf_dftd3
import copy
import collections
from . import dict_xc_funcs
from . import dict_lda_funcs
@@ -107,10 +107,11 @@ def get_functional_aliases(functional_dict):
return aliases
# alias table for dispersion
dispersion_names = get_dispersion_aliases()
_dispersion_aliases = intf_dftd3.get_dispersion_aliases()
functionals = {}
dashcoeff_supplement = collections.defaultdict(lambda: collections.defaultdict(dict))
for functional_name in dict_functionals:
functional_aliases = get_functional_aliases(dict_functionals[functional_name])
@@ -120,27 +121,31 @@ def get_functional_aliases(functional_dict):
# if the parent functional is already dispersion corrected, skip to next
if "dispersion" in dict_functionals[functional_name]:
disp = dict_functionals[functional_name]['dispersion']
dashcoeff_supplement[disp['type']]['definitions'][functional_name] = disp['params']
# TODO still needs citation
# this is to "bless" dft_funcs dispersion definitions
continue
# else loop through dispersion types in dashparams (also considering aliases)
# and build dispersion corrected version (applies also for aliases)
for dispersion_name in dispersion_names:
dispersion_type = dispersion_names[dispersion_name]
for dispersion_functional in dashcoeff[dispersion_type]:
# and build dispersion corrected version (applies also for aliases)
for nominal_dispersion_level, resolved_dispersion_level in _dispersion_aliases.items():
for dispersion_functional in intf_dftd3.dashcoeff[resolved_dispersion_level]['definitions']:
if dispersion_functional.lower() in functional_aliases:
func = copy.deepcopy(dict_functionals[functional_name])
func["name"] = func["name"] + "-" + dispersion_type
func["name"] += "-" + resolved_dispersion_level
func["dispersion"] = dict()
# we need to pop the citation as the EmpiricalDispersion class only expects dashparams
if "citation" in dashcoeff[dispersion_type][dispersion_functional]:
func["dispersion"]["citation"] = dashcoeff[dispersion_type][dispersion_functional].pop("citation")
func["dispersion"]["type"] = dispersion_type
func["dispersion"]["params"] = dashcoeff[dispersion_type][dispersion_functional]
if "citation" in intf_dftd3.dashcoeff[resolved_dispersion_level]['definitions'][dispersion_functional]:
func["dispersion"]["citation"] = intf_dftd3.dashcoeff[resolved_dispersion_level]['definitions'][dispersion_functional].pop("citation")
func["dispersion"]["type"] = resolved_dispersion_level
func["dispersion"]["params"] = intf_dftd3.dashcoeff[resolved_dispersion_level]['definitions'][dispersion_functional]
# this ensures that M06-2X-D3, M06-2X-D3ZERO, M062X-D3 or M062X-D3ZERO
# all point to the same method (M06-2X-D3ZERO)
# all point to the same method (M06-2X-D3ZERO)
for alias in functional_aliases:
alias = alias + "-" + dispersion_name.lower()
alias += "-" + nominal_dispersion_level.lower()
functionals[alias] = func
@@ -100,7 +100,9 @@
"dispersion": {
"type": "d2",
"params": {
"s6": 0.35
"s6": 0.35,
"alpha6": 20.0,
"sr6": 1.1
},
"citation": ' S. Kozuch, J.M.L. Martin, J. Comp. Chem., 34, 2327-2344, 2013\n'
},
@@ -168,7 +170,7 @@
"b": 12.00,
"c": 0.0093,
},
"citation": " F. Yu J. Chem. Theory Comput. 10, 4400-4407, 2014\n"
"citation": " F. Yu J. Chem. Theory Comput. 10, 4400-4407, 2014\n"
},
"citation": ' S. Kozuch, J.M.L. Martin, J. Comp. Chem., 34, 2327-2344, 2013\n',
"description": ' DSD-BLYP-NL (D3BJ,FC parameters) VV10 SCS Double Hybrid XC Functional\n',
@@ -361,7 +363,9 @@
"dispersion": {
"type": "d2",
"params": {
"s6": 0.29
"s6": 0.29,
"alpha6": 20.0,
"sr6": 1.1
},
"citation": ' S. Kozuch, J.M.L. Martin, J. Comp. Chem., 34, 2327-2344, 2013\n'
},
@@ -415,7 +419,9 @@
"dispersion": {
"type": "d2",
"params": {
"s6": 0.42
"s6": 0.42,
"alpha6": 20.0,
"sr6": 1.1
},
"citation": ' S. Kozuch, J.M.L. Martin, J. Comp. Chem., 34, 2327-2344, 2013\n'
},
@@ -512,7 +518,9 @@
"dispersion": {
"type": "d2",
"params": {
"s6": 0.41
"s6": 0.41,
"alpha6": 20.0,
"sr6": 1.1
},
"citation": ' S. Kozuch, J.M.L. Martin, J. Comp. Chem., 34, 2327-2344, 2013\n'
},
@@ -542,7 +550,9 @@
"dispersion": {
"type": "d2",
"params": {
"s6": 0.28
"s6": 0.28,
"alpha6": 20.0,
"sr6": 1.1
},
"citation": ' S. Kozuch, J.M.L. Martin, J. Comp. Chem., 34, 2327-2344, 2013\n',
},
@@ -684,7 +694,9 @@ def get_pwpb95_tweaks():
"dispersion": {
"type": "d2",
"params": {
"s6": 0.32
"s6": 0.32,
"alpha6": 20.0,
"sr6": 1.1
},
"citation": ' S. Kozuch, J.M.L. Martin, J. Comp. Chem., 34, 2327-2344, 2013\n',
},
@@ -211,16 +211,28 @@
"description": ' SOGGA11 Exchange-Correlation Functional\n',
})
# dashparam.dashcoeff now defines 'b97' (<-'b97-d') as Grimme's GGA
# functional, so one could just define
# funcs.append({
# "name": "B97",
# "xc_functionals": {
# "GGA_XC_B97_D": {}
# }})
# and let the dict_builder fill out -D2, -D3(BJ), etc. Leaving the
# explicit definitions below so plain 'b97' isn't further confused.
funcs.append({
"name": "B97-D2GR",
"name": "B97-D2",
"alias": ["B97-D"],
"xc_functionals": {
"GGA_XC_B97_D": {}
},
"dispersion": {
"type": "d2gr",
"type": "d2",
"params": {
's6': 1.25,
'alpha6': 20.0
'alpha6': 20.0,
'sr6': 1.1
}
}
})
@@ -232,7 +244,7 @@
"GGA_XC_B97_D": {}
},
"dispersion": {
"type": "d3",
"type": "d3zero",
"params": {
's6': 1.0,
's8': 0.909,
@@ -37,9 +37,9 @@
funcs.append({"name": "TETER93" , "xc_functionals": {"LDA_XC_TETER93" : {}}})
funcs.append({"name": "ZLP" , "xc_functionals": {"LDA_XC_ZLP" : {}}})
funcs.append({"name": "KSDT" , "xc_functionals": {"LDA_XC_KSDT" : {}}})
funcs.append({"name": "OPBE-D" , "xc_functionals": {"GGA_XC_OPBE_D" : {}}, "dispersion": {"type": "d2gr", "params": {'s6': 1.0, 'alpha6': 20.0, 'rs6': 1.15}, "citation": ' L. Goerigk, S. Grimme, J. Chem. Theory. Comput. 6, 107-126, 2010'}})
funcs.append({"name": "OPWLYP-D" , "xc_functionals": {"GGA_XC_OPWLYP_D" : {}}, "dispersion": {"type": "d2gr", "params": {'s6': 1.0, 'alpha6': 20.0, 'rs6': 1.15}, "citation": ' L. Goerigk, S. Grimme, J. Chem. Theory. Comput. 6, 107-126, 2010'}})
funcs.append({"name": "OBLYP-D" , "xc_functionals": {"GGA_XC_OBLYP_D" : {}}, "dispersion": {"type": "d2gr", "params": {'s6': 1.0, 'alpha6': 20.0, 'rs6': 1.15}, "citation": ' L. Goerigk, S. Grimme, J. Chem. Theory. Comput. 6, 107-126, 2010'}})
funcs.append({"name": "OPBE-D" , "xc_functionals": {"GGA_XC_OPBE_D" : {}}, "dispersion": {"type": "d2", "params": {'s6': 1.0, 'alpha6': 20.0, 'sr6': 1.15}, "citation": ' L. Goerigk, S. Grimme, J. Chem. Theory. Comput. 6, 107-126, 2010'}})
funcs.append({"name": "OPWLYP-D" , "xc_functionals": {"GGA_XC_OPWLYP_D" : {}}, "dispersion": {"type": "d2", "params": {'s6': 1.0, 'alpha6': 20.0, 'sr6': 1.15}, "citation": ' L. Goerigk, S. Grimme, J. Chem. Theory. Comput. 6, 107-126, 2010'}})
funcs.append({"name": "OBLYP-D" , "xc_functionals": {"GGA_XC_OBLYP_D" : {}}, "dispersion": {"type": "d2", "params": {'s6': 1.0, 'alpha6': 20.0, 'sr6': 1.15}, "citation": ' L. Goerigk, S. Grimme, J. Chem. Theory. Comput. 6, 107-126, 2010'}})
funcs.append({"name": "HCTH407P" , "xc_functionals": {"GGA_XC_HCTH_407P" : {}}})
funcs.append({"name": "HCTHP76" , "xc_functionals": {"GGA_XC_HCTH_P76" : {}}})
funcs.append({"name": "HCTHP14" , "xc_functionals": {"GGA_XC_HCTH_P14" : {}}})
@@ -55,7 +55,7 @@
funcs.append({"name": "HCTH407" , "xc_functionals": {"GGA_XC_HCTH_407" : {}}})
funcs.append({"name": "EDF1" , "xc_functionals": {"GGA_XC_EDF1" : {}}})
funcs.append({"name": "XLYP" , "xc_functionals": {"GGA_XC_XLYP" : {}}})
funcs.append({"name": "B97-D" , "xc_functionals": {"GGA_XC_B97_D" : {}}, "dispersion": {"type": "d2", "params": {'s6': 1.25}}, "alias": ["B97-D2"]})
funcs.append({"name": "B97-D" , "xc_functionals": {"GGA_XC_B97_D" : {}}, "dispersion": {"type": "d2", "params": {'s6': 1.25, 'alpha6': 20.0, 'sr6': 1.1}}, "alias": ["B97-D2"]})
funcs.append({"name": "PBE1W" , "xc_functionals": {"GGA_XC_PBE1W" : {}}})
funcs.append({"name": "mPWLYP1W" , "xc_functionals": {"GGA_XC_MPWLYP1W" : {}}})
funcs.append({"name": "PBELYP1W" , "xc_functionals": {"GGA_XC_PBELYP1W" : {}}})
@@ -135,7 +135,7 @@
funcs.append({"name": "revTPSSh" , "xc_functionals": {"HYB_MGGA_XC_REVTPSSH" : {}}})
funcs.append({"name": "wB97M-V" , "xc_functionals": {"HYB_MGGA_XC_WB97M_V" : {}}, "alias": ["WB97MV"]})
funcs.append({"name": "ZLP" , "xc_functionals": {"MGGA_XC_ZLP" : {}}})
funcs.append({"name": "OTPSS-D" , "xc_functionals": {"MGGA_XC_OTPSS_D" : {}}, "dispersion": {"type": "d2gr", "params": {'s6': 1.0, 'alpha6': 20.0, 'rs6': 1.15}, "citation": ' L. Goerigk, S. Grimme, J. Chem. Theory. Comput. 6, 107-126, 2010'}})
funcs.append({"name": "OTPSS-D" , "xc_functionals": {"MGGA_XC_OTPSS_D" : {}}, "dispersion": {"type": "d2", "params": {'s6': 1.0, 'alpha6': 20.0, 'sr6': 1.15}, "citation": ' L. Goerigk, S. Grimme, J. Chem. Theory. Comput. 6, 107-126, 2010'}})
funcs.append({"name": "TPSSLYP1W" , "xc_functionals": {"MGGA_XC_TPSSLYP1W" : {}}})
funcs.append({"name": "B97M-V" , "xc_functionals": {"MGGA_XC_B97M_V" : {}}})
funcs.append({"name": "B5050LYP" , "xc_functionals": {"HYB_GGA_XC_B5050LYP" : {}}})
@@ -33,7 +33,6 @@
import os
from psi4 import core
from psi4.driver.qcdb import interface_dftd3 as dftd3
from psi4.driver.p4util.exceptions import *
from . import dict_builder
@@ -569,6 +569,7 @@ def scf_print_energies(self):
e2 = self.get_energies('Two-Electron')
exc = self.get_energies('XC')
ed = self.get_energies('-D')
#self.del_variable('-D Energy')
evv10 = self.get_energies('VV10')
eefp = self.get_energies('EFP')
epcm = self.get_energies('PCM Polarization')
@@ -598,11 +599,20 @@ def scf_print_energies(self):
self.set_variable('DFT XC ENERGY', exc)
self.set_variable('DFT VV10 ENERGY', evv10)
self.set_variable('DFT FUNCTIONAL TOTAL ENERGY', hf_energy + exc + evv10)
self.set_variable('DFT TOTAL ENERGY', dft_energy)
#self.set_variable(self.functional().name() + ' FUNCTIONAL TOTAL ENERGY', hf_energy + exc + evv10)
self.set_variable('DFT TOTAL ENERGY', dft_energy) # overwritten later for DH
else:
self.set_variable('HF TOTAL ENERGY', hf_energy)
if hasattr(self, "_disp_functor"):
self.set_variable('DISPERSION CORRECTION ENERGY', ed)
#if abs(ed) > 1.0e-14:
# for pv, pvv in self.variables().items():
# if abs(pvv - ed) < 1.0e-14:
# if pv.endswith('DISPERSION CORRECTION ENERGY') and pv.startswith(self.functional().name()):
# fctl_plus_disp_name = pv.split()[0]
# self.set_variable(fctl_plus_disp_name + ' TOTAL ENERGY', dft_energy) # overwritten later for DH
#else:
# self.set_variable(self.functional().name() + ' TOTAL ENERGY', dft_energy) # overwritten later for DH
self.set_variable('SCF ITERATIONS', self.iteration_)
@@ -66,3 +66,47 @@ def to_dict(self):
dicary['data'] = [self.data.real, self.data.imag]
return dicary
def print_variables(qcvars=None):
"""Form a printable representation of qcvariables.
Parameters
----------
qcvars : dict of QCAspect, optional
Group of QCAspect objects to print. If `None`, will use `qcdb.pe.active_qcvars`.
Returns
-------
str
Printable string representation of label, data, and unit in QCAspect-s.
"""
text = []
text.append('\n Variable Map:')
text.append(' ----------------------------------------------------------------------------')
if qcvars is None:
qcvars = pe.active_qcvars
if len(qcvars) == 0:
text.append(' (none)')
return '\n'.join(text)
largest_key = max(len(k) for k in qcvars) + 2 # for quotation marks
for k, qca in sorted(qcvars.items()):
if k != qca.lbl:
raise ValidationError('Huh? {} != {}'.format(k, qca.label))
if isinstance(qca.data, np.ndarray):
data = np.array_str(qca.data, max_line_width=120, precision=8, suppress_small=True)
data = '\n'.join(' ' + ln for ln in data.splitlines())
text.append(""" {:{keywidth}} => {:{width}} [{}]""".format(
'"' + k + '"', '', qca.units, keywidth=largest_key, width=20))
text.append(data)
else:
text.append(""" {:{keywidth}} => {:{width}.{prec}f} [{}]""".format(
'"' + k + '"', qca.data, qca.units, keywidth=largest_key, width=20, prec=12))
text.append('')
return '\n'.join(text)
@@ -42,7 +42,7 @@
except ImportError:
from .exceptions import *
isP4regime = False
from .p4regex import *
from .util import parse_dertype
from .molecule import Molecule
@@ -82,15 +82,9 @@ def run_gcp(self, func=None, dertype=None, verbose=False): # dashlvl=None, dash
# raise ValidationError("""-D correction level %s is not available. Choose among %s.""" % (dashlvl, dashcoeff.keys()))
if dertype is None:
dertype = -1
elif der0th.match(str(dertype)):
dertype = 0
elif der1st.match(str(dertype)):
dertype = 1
# elif der2nd.match(str(dertype)):
# raise ValidationError('Requested derivative level \'dertype\' %s not valid for run_dftd3.' % (dertype))
derint, derdriver = -1, 'gradient'
else:
raise ValidationError('Requested derivative level \'dertype\' %s not valid for run_dftd3.' % (dertype))
derint, derdriver = parse_dertype(dertype, max_derivative=1)
# if func is None:
# if dashparam is None:
@@ -213,7 +207,7 @@ def run_gcp(self, func=None, dertype=None, verbose=False): # dashlvl=None, dash
# Call gcp program
command = ['gcp', geomfile]
command.extend(['-level', func])
if dertype != 0:
if derint != 0:
command.append('-grad')
try:
#print('command', command)
@@ -237,7 +231,7 @@ def run_gcp(self, func=None, dertype=None, verbose=False): # dashlvl=None, dash
raise Dftd3Error("""Unsuccessful gCP run.""")
# Parse grad output
if dertype != 0:
if derint != 0:
derivfile = './gcp_gradient'
dfile = open(derivfile, 'r')
dashdderiv = []
@@ -256,7 +250,7 @@ def run_gcp(self, func=None, dertype=None, verbose=False): # dashlvl=None, dash
(len(dashdderiv), self.natom()))
# Prepare results for Psi4
if isP4regime and dertype != 0:
if isP4regime and derint != 0:
core.set_variable('GCP CORRECTION ENERGY', dashd)
psi_dashdderiv = core.Matrix.from_list(dashdderiv)
@@ -267,7 +261,7 @@ def run_gcp(self, func=None, dertype=None, verbose=False): # dashlvl=None, dash
text = '\n ==> GCP Output <==\n'
text += out.decode('utf-8')
if dertype != 0:
if derint != 0:
with open(derivfile, 'r') as handle:
text += handle.read().replace('D', 'E')
text += '\n'
@@ -280,7 +274,7 @@ def run_gcp(self, func=None, dertype=None, verbose=False): # dashlvl=None, dash
# os.unlink(paramfile1)
# os.unlink(paramfile2)
# os.unlink(geomfile)
# if dertype != 0:
# if derint != 0:
# os.unlink(derivfile)
# if defmoved is True:
# os.rename(defaultfile + '_hide', defaultfile)
@@ -293,11 +287,11 @@ def run_gcp(self, func=None, dertype=None, verbose=False): # dashlvl=None, dash
os.chdir(current_directory)
# return -D & d(-D)/dx
if dertype == -1:
if derint == -1:
return dashd, dashdderiv
elif dertype == 0:
elif derint == 0:
return dashd
elif dertype == 1:
elif derint == 1:
return psi_dashdderiv
try:
Oops, something went wrong.

0 comments on commit 3e3d894

Please sign in to comment.