Skip to content

Commit

Permalink
Add warning messages
Browse files Browse the repository at this point in the history
  • Loading branch information
sunqm committed Mar 23, 2024
1 parent aedaecc commit 7f383ac
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
17 changes: 12 additions & 5 deletions pyscf/dft/dft_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'''

from functools import lru_cache
import warnings

# supported dispersion corrections
DISP_VERSIONS = ['d3bj', 'd3zero', 'd3bjm', 'd3zerom', 'd3op', 'd4']
Expand Down Expand Up @@ -63,18 +64,24 @@ def parse_dft(dft_method):
for d in DISP_VERSIONS:
if method_lower.endswith(d):
disp = d
with_3body = False
xc = method_lower.replace(f'-{d}','')
if method_lower.endswith(d+'2b'):
elif method_lower.endswith(d+'2b'):
disp = d
with_3body = False
xc = method_lower.replace(f'-{d}2b', '')
if method_lower.endswith(d+'atm'):
elif method_lower.endswith(d+'atm'):
disp = d
with_3body = True
xc = method_lower.replace(f'-{d}atm', '')

if disp is not None:
if xc in ('b97m', 'wb97m', 'wb97x'):
return xc+'-v', False, (xc, disp, False)
if xc in ('b97m', 'wb97m'):
warnings.warn(
f'{dft_method} is not a well-defined functional. '
'The XC part is changed to {xc}-v')
return xc+'-v', False, (xc, disp, with_3body)
else:
return xc, None, (xc, disp, False)
return xc, None, (xc, disp, with_3body)

return xc, None, (xc, None, False)
2 changes: 1 addition & 1 deletion pyscf/dft/libxc.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ def is_gga(xc_code):
@lru_cache(100)
def is_nlc(xc_code):
enable_nlc = dft_parser.parse_dft(xc_code)[1]
if not (enable_nlc is None and enable_nlc):
if enable_nlc is False:
return False
# identify nlc by xc_code itself if enable_nlc is None
if isinstance(xc_code, str):
Expand Down
9 changes: 8 additions & 1 deletion pyscf/dft/test/test_h2o.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,4 +608,11 @@ def test_init(self):

if __name__ == "__main__":
print("Full Tests for H2O")
unittest.main()
#unittest.main()
if 1:
setUpModule()
method = dft.RKS(h2o)
dm = method.get_init_guess()
method.xc = 'wB97M_V'
vxc = method.get_veff(h2o, dm)
print(lib.fp(vxc), 22.767792068559917, 8)
4 changes: 2 additions & 2 deletions pyscf/dft/test/test_libxc.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def test_m06(self):
def test_dft_parser(self):
from pyscf.dft.dft_parser import parse_dft
self.assertEqual(parse_dft('wb97m-d3bj'), ('wb97m-v', False, ('wb97m', 'd3bj', False)))
self.assertEqual(dft.libxc.parse_xc('wb97m-d3bj')[1][0][0] == 531)
self.assertEqual(dft.libxc.parse_xc('wb97m-d3bj')[1][0][0], 531)
self.assertTrue(not dft.libxc.is_nlc('wb97m-d3bj'))

self.assertEqual(parse_dft('wb97-d3zerom'), ('wb97', None, ('wb97', 'd3zerom', False)))
Expand All @@ -353,7 +353,7 @@ def test_dft_parser(self):
self.assertEqual(parse_dft('wb97m-d3bjatm'), ('wb97m-v', False, ('wb97m', 'd3bj', True)))
self.assertTrue(not dft.libxc.is_nlc('wb97m-d3bjatm'))

self.assertEqual(parse_dft('wb97x-d3zero2b'), ('wb97x-v', False, ('wb97x', 'd3zero', False)))
self.assertEqual(parse_dft('wb97x-d3zero2b'), ('wb97x', None, ('wb97x', 'd3zero', False)))
self.assertTrue(not dft.libxc.is_nlc('wb97x-d3zero2b'))

if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion pyscf/dft/xcfun.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def is_gga(xc_code):

def is_nlc(xc_code):
enable_nlc = dft_parser.parse_dft(xc_code)[1]
if not (enable_nlc is None and enable_nlc):
if enable_nlc is False:
return False
fn_facs = parse_xc(xc_code)[1]
return any(xid >= 5000 for xid, c in fn_facs)
Expand Down

0 comments on commit 7f383ac

Please sign in to comment.