Coverage for gpaw/xc/gllb/nonlocalfunctionalfactory.py: 98%
61 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-14 00:18 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-14 00:18 +0000
1from gpaw.xc.gllb.nonlocalfunctional import NonLocalFunctional
4def get_nonlocal_functional(name: str,
5 stencil: int = 2,
6 metallic: bool = False,
7 width: float = None,
8 eps: float = 0.05) -> NonLocalFunctional:
9 """Function for building GLLB functionals.
11 Parameters:
13 name:
14 name of the functional
15 stencil:
16 parameter passed to :class:`~gpaw.xc.gga.GGA`
17 metallic:
18 parameter passed to :class:`~gpaw.xc.gllb.coefficients.Coefficients`
19 width:
20 parameter passed to :class:`~gpaw.xc.gllb.coefficients.Coefficients`
21 eps:
22 parameter passed to :class:`~gpaw.xc.gllb.coefficients.Coefficients`
24 Recognized names and implied parameters:
25 * GLLB (Contains screening part from B88 functional
26 and response part based on simple square root expression
27 of orbital energy differences)
28 * GLLBM (GLLB with `metallic=True`)
29 * GLLBC (GLLB with screening part from PBE + correlation from PBE)
30 * GLLBCP86 (GLLB with screening part from B88 + correlation from P86)
31 * GLLBSC (GLLB with screening part from PBEsol + correlation from PBEsol)
32 * GLLBSCM (GLLBSC with `metallic=True`)
33 * GLLBNORESP (Just GLLB screening)
34 * GLLBLDA (A test functional, which is just LDA but via
35 NonLocalFunctional framework)
36 * GLLBPBE (A test functional, which is just PBE but via
37 NonLocalFunctional framework)
38 """
39 from gpaw.xc.gllb.c_gllbscr import C_GLLBScr
40 from gpaw.xc.gllb.c_response import C_Response
41 from gpaw.xc.gllb.c_xc import C_XC
42 from gpaw.xc.gllb.coefficients import Coefficients
44 functional = NonLocalFunctional(name)
46 scr_functional = None
47 xc_functional = None
48 response = True
49 setup_name = None
51 # Set parameters based on the name
52 if name == 'GLLB':
53 scr_functional = 'GGA_X_B88'
54 elif name == 'GLLBM':
55 scr_functional = 'GGA_X_B88'
56 setup_name = 'GLLB'
57 metallic = True
58 elif name == 'GLLBSC':
59 scr_functional = 'GGA_X_PBE_SOL'
60 xc_functional = 'GGA_C_PBE_SOL'
61 setup_name = 'GLLBSC'
62 elif name == 'GLLBSCM':
63 scr_functional = 'GGA_X_PBE_SOL'
64 xc_functional = 'GGA_C_PBE_SOL'
65 setup_name = 'GLLBSC'
66 metallic = True
67 elif name == 'GLLBC':
68 scr_functional = 'GGA_X_PBE'
69 xc_functional = 'GGA_C_PBE'
70 elif name == 'GLLBCP86':
71 scr_functional = 'GGA_X_B88'
72 xc_functional = 'GGA_C_P86'
73 elif name == 'GLLBLDA':
74 xc_functional = 'LDA'
75 response = False
76 setup_name = 'LDA'
77 elif name == 'GLLBPBE':
78 xc_functional = 'PBE'
79 response = False
80 setup_name = 'PBE'
81 elif name == 'GLLBNORESP':
82 scr_functional = 'GGA_X_B88'
83 response = False
84 else:
85 raise RuntimeError('Unkown nonlocal density functional: ' + name)
87 def func_name_to_dict(name):
88 dct = {'name': name}
89 if name != 'LDA':
90 dct['stencil'] = stencil
91 return dct
93 # Construct functional
94 functional = NonLocalFunctional(name, setup_name=setup_name)
95 if scr_functional is not None:
96 scr = C_GLLBScr(1.0, functional=func_name_to_dict(scr_functional))
97 functional.add_contribution(scr)
98 if response:
99 coef = Coefficients(eps=eps, width=width)
100 resp = C_Response(1.0, coef, metallic=metallic)
101 functional.add_contribution(resp)
102 if xc_functional is not None:
103 xc = C_XC(1.0, functional=func_name_to_dict(xc_functional))
104 functional.add_contribution(xc)
105 return functional