From a20dfb31e0bcbe234d705552103839726e670da1 Mon Sep 17 00:00:00 2001 From: Qiming Sun Date: Tue, 30 Jan 2024 12:31:45 -0800 Subject: [PATCH] Print b3lyp warning when needed (issue #2029) (#2040) * Hide b3lyp warning (issue #2029) * Backward compatibility for xcfun * typo --- pyscf/dft/libxc.py | 19 +++++++++++-------- pyscf/dft/xcfun.py | 7 ++++++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/pyscf/dft/libxc.py b/pyscf/dft/libxc.py index d584278a80..8e6d51267f 100644 --- a/pyscf/dft/libxc.py +++ b/pyscf/dft/libxc.py @@ -767,14 +767,7 @@ def _xc_key_without_underscore(xc_keys): 'TPSS0' : '.25*HF + .75*TPSS, TPSS', }) # noqa: E501 -# Issue 1480 -if not hasattr(__config__, 'B3LYP_WITH_VWN5'): - warnings.warn('Since PySCF-2.3, B3LYP (and B3P86) are changed to the VWN-RPA variant, ' - 'corresponding to the original definition by Stephens et al. (issue 1480) ' - 'and the same as the B3LYP functional in Gaussian. ' - 'To restore the VWN5 definition, you can put the setting ' - '"B3LYP_WITH_VWN5 = True" in pyscf_conf.py') -elif getattr(__config__, 'B3LYP_WITH_VWN5', False): +if getattr(__config__, 'B3LYP_WITH_VWN5', False): XC_CODES['B3P86' ] = 'B3P86V5' XC_CODES['B3LYP' ] = 'B3LYP5' XC_CODES['X3LYP' ] = 'X3LYP5' @@ -1102,6 +1095,16 @@ def parse_xc(description): elif not isinstance(description, str): #isinstance(description, (tuple,list)): return parse_xc('%s,%s' % tuple(description)) + if (description.upper() in ('B3P86', 'B3LYP', 'X3LYP') and + not getattr(parse_xc, 'b3lyp5_warned', False) and + not hasattr(__config__, 'B3LYP_WITH_VWN5')): + parse_xc.b3lyp5_warned = True + warnings.warn('Since PySCF-2.3, B3LYP (and B3P86) are changed to the VWN-RPA variant, ' + 'corresponding to the original definition by Stephens et al. (issue 1480) ' + 'and the same as the B3LYP functional in Gaussian. ' + 'To restore the VWN5 definition, you can put the setting ' + '"B3LYP_WITH_VWN5 = True" in pyscf_conf.py') + def assign_omega(omega, hyb_or_sr, lr=0): if hyb[2] == omega or omega == 0: hyb[0] += hyb_or_sr diff --git a/pyscf/dft/xcfun.py b/pyscf/dft/xcfun.py index 8fd498b338..c49c5e9ab8 100644 --- a/pyscf/dft/xcfun.py +++ b/pyscf/dft/xcfun.py @@ -252,7 +252,12 @@ 'B97XC' , 'B97_1XC' , 'B97_2XC' , 'M05XC' , 'TPSSH' , 'HFLYP'} RSH_XC = {'CAMB3LYP'} -MAX_DERIV_ORDER = ctypes.c_int.in_dll(_itrf, 'XCFUN_max_deriv_order').value + +# The compatibility with the old libxcfun_itrf.so library +try: + MAX_DERIV_ORDER = ctypes.c_int.in_dll(_itrf, 'XCFUN_max_deriv_order').value +except ValueError: + MAX_DERIV_ORDER = 3 VV10_XC = { 'B97M_V' : (6.0, 0.01),