Line data Source code
1 : !--------------------------------------------------------------------------------------------------!
2 : ! CP2K: A general program to perform molecular dynamics simulations !
3 : ! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4 : ! !
5 : ! SPDX-License-Identifier: GPL-2.0-or-later !
6 : !--------------------------------------------------------------------------------------------------!
7 :
8 : ! **************************************************************************************************
9 : MODULE xc_derivatives
10 :
11 : USE input_section_types, ONLY: section_vals_get_subs_vals2,&
12 : section_vals_type,&
13 : section_vals_val_get
14 : USE kinds, ONLY: default_string_length,&
15 : dp
16 : USE string_utilities, ONLY: uppercase
17 : USE xc_b97, ONLY: b97_lda_eval,&
18 : b97_lda_info,&
19 : b97_lsd_eval,&
20 : b97_lsd_info
21 : USE xc_cs1, ONLY: cs1_lda_eval,&
22 : cs1_lda_info,&
23 : cs1_lsd_eval,&
24 : cs1_lsd_info
25 : USE xc_derivative_set_types, ONLY: xc_derivative_set_type
26 : USE xc_exchange_gga, ONLY: xgga_eval,&
27 : xgga_info
28 : USE xc_gauxc_functional, ONLY: skala_info
29 : USE xc_hcth, ONLY: hcth_lda_eval,&
30 : hcth_lda_info
31 : USE xc_ke_gga, ONLY: ke_gga_info,&
32 : ke_gga_lda_eval,&
33 : ke_gga_lsd_eval
34 : USE xc_libxc, ONLY: libxc_lda_eval,&
35 : libxc_lda_info,&
36 : libxc_lsd_eval,&
37 : libxc_lsd_info
38 : USE xc_lyp, ONLY: lyp_lda_eval,&
39 : lyp_lda_info,&
40 : lyp_lsd_eval,&
41 : lyp_lsd_info
42 : USE xc_lyp_adiabatic, ONLY: lyp_adiabatic_lda_eval,&
43 : lyp_adiabatic_lda_info,&
44 : lyp_adiabatic_lsd_eval,&
45 : lyp_adiabatic_lsd_info
46 : USE xc_optx, ONLY: optx_lda_eval,&
47 : optx_lda_info,&
48 : optx_lsd_eval,&
49 : optx_lsd_info
50 : USE xc_pade, ONLY: pade_info,&
51 : pade_init,&
52 : pade_lda_pw_eval,&
53 : pade_lsd_pw_eval
54 : USE xc_pbe, ONLY: pbe_lda_eval,&
55 : pbe_lda_info,&
56 : pbe_lsd_eval,&
57 : pbe_lsd_info
58 : USE xc_perdew86, ONLY: p86_lda_eval,&
59 : p86_lda_info
60 : USE xc_perdew_wang, ONLY: perdew_wang_info,&
61 : perdew_wang_lda_eval,&
62 : perdew_wang_lsd_eval
63 : USE xc_perdew_zunger, ONLY: pz_info,&
64 : pz_lda_eval,&
65 : pz_lsd_eval
66 : USE xc_rho_cflags_types, ONLY: xc_rho_cflags_setall,&
67 : xc_rho_cflags_type
68 : USE xc_rho_set_types, ONLY: xc_rho_set_get,&
69 : xc_rho_set_type
70 : USE xc_tfw, ONLY: tfw_lda_eval,&
71 : tfw_lda_info,&
72 : tfw_lsd_eval,&
73 : tfw_lsd_info
74 : USE xc_thomas_fermi, ONLY: thomas_fermi_info,&
75 : thomas_fermi_lda_eval,&
76 : thomas_fermi_lsd_eval
77 : USE xc_tpss, ONLY: tpss_lda_eval,&
78 : tpss_lda_info
79 : USE xc_vwn, ONLY: vwn_lda_eval,&
80 : vwn_lda_info,&
81 : vwn_lsd_eval,&
82 : vwn_lsd_info
83 : USE xc_xalpha, ONLY: xalpha_info,&
84 : xalpha_lda_eval,&
85 : xalpha_lsd_eval
86 : USE xc_xbecke88, ONLY: xb88_lda_eval,&
87 : xb88_lda_info,&
88 : xb88_lsd_eval,&
89 : xb88_lsd_info
90 : USE xc_xbecke88_long_range, ONLY: xb88_lr_lda_eval,&
91 : xb88_lr_lda_info,&
92 : xb88_lr_lsd_eval,&
93 : xb88_lr_lsd_info
94 : USE xc_xbecke88_lr_adiabatic, ONLY: xb88_lr_adiabatic_lda_eval,&
95 : xb88_lr_adiabatic_lda_info,&
96 : xb88_lr_adiabatic_lsd_eval,&
97 : xb88_lr_adiabatic_lsd_info
98 : USE xc_xbecke_roussel, ONLY: xbecke_roussel_lda_eval,&
99 : xbecke_roussel_lda_info,&
100 : xbecke_roussel_lsd_eval,&
101 : xbecke_roussel_lsd_info
102 : USE xc_xbeef, ONLY: xbeef_lda_eval,&
103 : xbeef_lda_info,&
104 : xbeef_lsd_eval,&
105 : xbeef_lsd_info
106 : USE xc_xbr_pbe_lda_hole_t_c_lr, ONLY: xbr_pbe_lda_hole_tc_lr_lda_eval,&
107 : xbr_pbe_lda_hole_tc_lr_lda_info,&
108 : xbr_pbe_lda_hole_tc_lr_lsd_eval,&
109 : xbr_pbe_lda_hole_tc_lr_lsd_info
110 : USE xc_xlda_hole_t_c_lr, ONLY: xlda_hole_t_c_lr_lda_eval,&
111 : xlda_hole_t_c_lr_lda_info,&
112 : xlda_hole_t_c_lr_lsd_eval,&
113 : xlda_hole_t_c_lr_lsd_info
114 : USE xc_xpbe_hole_t_c_lr, ONLY: xpbe_hole_t_c_lr_lda_eval,&
115 : xpbe_hole_t_c_lr_lda_info,&
116 : xpbe_hole_t_c_lr_lsd_eval,&
117 : xpbe_hole_t_c_lr_lsd_info
118 : USE xc_xwpbe, ONLY: xwpbe_lda_eval,&
119 : xwpbe_lda_info,&
120 : xwpbe_lsd_eval,&
121 : xwpbe_lsd_info
122 : #include "../base/base_uses.f90"
123 :
124 : IMPLICIT NONE
125 :
126 : PRIVATE
127 :
128 : LOGICAL, PARAMETER :: debug_this_module = .FALSE.
129 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'xc_derivatives'
130 :
131 : PUBLIC :: xc_functional_get_info, xc_functionals_eval, xc_functionals_get_needs
132 :
133 : CONTAINS
134 :
135 : ! **************************************************************************************************
136 : !> \brief get the information about the given functional
137 : !> \param functional the functional you want info about
138 : !> \param lsd if you are using lsd or lda
139 : !> \param reference the reference to the acticle where the functional is
140 : !> explained
141 : !> \param shortform the short definition of the functional
142 : !> \param needs the flags corresponding to the inputs needed by this
143 : !> functional are set to true (the flags not needed aren't touched)
144 : !> \param max_deriv the maximal derivative available
145 : !> \param print_warn whether to print warnings (mainly relevant for libxc)
146 : !> \author fawzi
147 : ! **************************************************************************************************
148 283140 : SUBROUTINE xc_functional_get_info(functional, lsd, reference, shortform, &
149 : needs, max_deriv, print_warn)
150 : TYPE(section_vals_type), POINTER :: functional
151 : LOGICAL, INTENT(in) :: lsd
152 : CHARACTER(LEN=*), INTENT(OUT), OPTIONAL :: reference, shortform
153 : TYPE(xc_rho_cflags_type), INTENT(inout), OPTIONAL :: needs
154 : INTEGER, INTENT(out), OPTIONAL :: max_deriv
155 : LOGICAL, INTENT(IN), OPTIONAL :: print_warn
156 :
157 : INTEGER :: i_param
158 : REAL(kind=dp) :: r_param
159 :
160 283140 : CPASSERT(ASSOCIATED(functional))
161 283807 : SELECT CASE (functional%section%name)
162 : CASE ("BECKE97")
163 667 : IF (lsd) THEN
164 : CALL b97_lsd_info(reference=reference, shortform=shortform, &
165 0 : needs=needs, max_deriv=max_deriv, b97_params=functional)
166 : ELSE
167 : CALL b97_lda_info(reference=reference, shortform=shortform, &
168 1993 : needs=needs, max_deriv=max_deriv, b97_params=functional)
169 : END IF
170 : CASE ("BECKE88_LR_ADIABATIC")
171 186 : IF (lsd) THEN
172 : CALL xb88_lr_adiabatic_lsd_info(reference=reference, shortform=shortform, &
173 325 : needs=needs, max_deriv=max_deriv)
174 : ELSE
175 : CALL xb88_lr_adiabatic_lda_info(reference=reference, shortform=shortform, &
176 229 : needs=needs, max_deriv=max_deriv)
177 : END IF
178 : CASE ("LYP_ADIABATIC")
179 186 : IF (lsd) THEN
180 : CALL lyp_adiabatic_lsd_info(reference=reference, shortform=shortform, &
181 325 : needs=needs, max_deriv=max_deriv)
182 : ELSE
183 : CALL lyp_adiabatic_lda_info(reference=reference, shortform=shortform, &
184 229 : needs=needs, max_deriv=max_deriv)
185 : END IF
186 : CASE ("BEEF")
187 23 : IF (lsd) THEN
188 : CALL xbeef_lsd_info(reference=reference, shortform=shortform, &
189 0 : needs=needs, max_deriv=max_deriv)
190 : ELSE
191 : CALL xbeef_lda_info(reference=reference, shortform=shortform, &
192 67 : needs=needs, max_deriv=max_deriv)
193 : END IF
194 : CASE ("BECKE88")
195 13752 : IF (lsd) THEN
196 : CALL xb88_lsd_info(reference=reference, shortform=shortform, &
197 8808 : needs=needs, max_deriv=max_deriv)
198 : ELSE
199 : CALL xb88_lda_info(reference=reference, shortform=shortform, &
200 32134 : needs=needs, max_deriv=max_deriv)
201 : END IF
202 : CASE ("BECKE88_LR")
203 1387 : IF (lsd) THEN
204 : CALL xb88_lr_lsd_info(reference=reference, shortform=shortform, &
205 169 : needs=needs, max_deriv=max_deriv)
206 : ELSE
207 : CALL xb88_lr_lda_info(reference=reference, shortform=shortform, &
208 3974 : needs=needs, max_deriv=max_deriv)
209 : END IF
210 : CASE ("LYP")
211 11363 : IF (lsd) THEN
212 : CALL lyp_lsd_info(reference=reference, shortform=shortform, &
213 8605 : needs=needs, max_deriv=max_deriv)
214 : ELSE
215 : CALL lyp_lda_info(reference=reference, shortform=shortform, &
216 25188 : needs=needs, max_deriv=max_deriv)
217 : END IF
218 : CASE ("PADE")
219 263703 : CALL pade_info(reference, shortform, lsd=lsd, needs=needs)
220 : CASE ("HCTH")
221 589 : CALL section_vals_val_get(functional, "PARAMETER_SET", i_val=i_param)
222 589 : CPASSERT(.NOT. lsd)
223 1763 : CALL hcth_lda_info(i_param, reference, shortform, needs, max_deriv)
224 : CASE ("OPTX")
225 916 : IF (lsd) THEN
226 1441 : CALL optx_lsd_info(reference, shortform, needs, max_deriv)
227 : ELSE
228 1299 : CALL optx_lda_info(reference, shortform, needs, max_deriv)
229 : END IF
230 : CASE ("CS1")
231 33 : IF (lsd) THEN
232 0 : CALL cs1_lsd_info(reference, shortform, needs, max_deriv)
233 : ELSE
234 97 : CALL cs1_lda_info(reference, shortform, needs=needs, max_deriv=max_deriv)
235 : END IF
236 : CASE ("XGGA")
237 28 : CALL section_vals_val_get(functional, "FUNCTIONAL", i_val=i_param)
238 76 : CALL xgga_info(i_param, lsd, reference, shortform, needs, max_deriv)
239 : CASE ("KE_GGA")
240 2176 : CALL section_vals_val_get(functional, "FUNCTIONAL", i_val=i_param)
241 6528 : CALL ke_gga_info(i_param, lsd, reference, shortform, needs, max_deriv)
242 : CASE ("P86C")
243 215 : IF (lsd) THEN
244 0 : CPABORT("BP functional not implemented with LSD")
245 : END IF
246 631 : CALL p86_lda_info(reference, shortform, needs, max_deriv)
247 : CASE ("PW92")
248 343 : CALL section_vals_val_get(functional, "PARAMETRIZATION", i_val=i_param)
249 343 : CALL section_vals_val_get(functional, "SCALE", r_val=r_param)
250 : CALL perdew_wang_info(i_param, lsd, reference, shortform, needs, max_deriv, &
251 1003 : r_param)
252 : CASE ("PZ81")
253 41 : CALL section_vals_val_get(functional, "PARAMETRIZATION", i_val=i_param)
254 121 : CALL pz_info(i_param, lsd, reference, shortform, needs, max_deriv)
255 : CASE ("TFW")
256 0 : IF (lsd) THEN
257 0 : CALL tfw_lsd_info(reference, shortform, needs, max_deriv)
258 : ELSE
259 0 : CALL tfw_lda_info(reference, shortform, needs, max_deriv)
260 : END IF
261 : CASE ("TF")
262 672 : CALL thomas_fermi_info(lsd, reference, shortform, needs, max_deriv)
263 : CASE ("VWN")
264 966 : IF (lsd) THEN
265 56 : CALL vwn_lsd_info(reference, shortform, needs, max_deriv)
266 : ELSE
267 2792 : CALL vwn_lda_info(reference, shortform, needs, max_deriv)
268 : END IF
269 : CASE ("XALPHA")
270 2760 : CALL section_vals_val_get(functional, "XA", r_val=r_param)
271 : CALL xalpha_info(lsd, reference, shortform, needs, max_deriv, &
272 8202 : xa_parameter=r_param)
273 : CASE ("TPSS")
274 1956 : IF (lsd) THEN
275 0 : CPABORT("TPSS functional not implemented with LSD. Use the LIBXC version instead.")
276 : ELSE
277 5820 : CALL tpss_lda_info(functional, reference, shortform, needs, max_deriv)
278 : END IF
279 : CASE ("PBE")
280 132730 : IF (lsd) THEN
281 67135 : CALL pbe_lsd_info(functional, reference, shortform, needs, max_deriv)
282 : ELSE
283 328925 : CALL pbe_lda_info(functional, reference, shortform, needs, max_deriv)
284 : END IF
285 : CASE ("GAUXC")
286 400 : IF (gauxc_model_none_selected(functional)) THEN
287 : CALL gauxc_model_none_xc_info(functional, lsd, reference, shortform, &
288 112 : needs, max_deriv, print_warn)
289 : ELSE
290 1072 : CALL skala_info(functional, lsd, reference, shortform, needs, max_deriv)
291 : ! Note: SKALA functional routes through apply_gauxc in qs_ks_methods.F
292 : ! when USE_GAUXC = .TRUE. (requires dft_control%use_gauxc to be set)
293 : END IF
294 : CASE ("XWPBE")
295 3943 : IF (lsd) THEN
296 3086 : CALL xwpbe_lsd_info(reference, shortform, needs, max_deriv)
297 : ELSE
298 8721 : CALL xwpbe_lda_info(reference, shortform, needs, max_deriv)
299 : END IF
300 : CASE ("BECKE_ROUSSEL")
301 191 : IF (lsd) THEN
302 272 : CALL xbecke_roussel_lsd_info(reference, shortform, needs, max_deriv)
303 : ELSE
304 291 : CALL xbecke_roussel_lda_info(reference, shortform, needs, max_deriv)
305 : END IF
306 : CASE ("LDA_HOLE_T_C_LR")
307 90 : IF (lsd) THEN
308 187 : CALL xlda_hole_t_c_lr_lsd_info(reference, shortform, needs, max_deriv)
309 : ELSE
310 79 : CALL xlda_hole_t_c_lr_lda_info(reference, shortform, needs, max_deriv)
311 : END IF
312 : CASE ("PBE_HOLE_T_C_LR")
313 3554 : IF (lsd) THEN
314 3104 : CALL xpbe_hole_t_c_lr_lsd_info(reference, shortform, needs, max_deriv)
315 : ELSE
316 7550 : CALL xpbe_hole_t_c_lr_lda_info(reference, shortform, needs, max_deriv)
317 : END IF
318 : CASE ("GV09")
319 268 : IF (lsd) THEN
320 187 : CALL xbr_pbe_lda_hole_tc_lr_lsd_info(reference, shortform, needs, max_deriv)
321 : ELSE
322 613 : CALL xbr_pbe_lda_hole_tc_lr_lda_info(reference, shortform, needs, max_deriv)
323 : END IF
324 : CASE default
325 : ! If the functional has not been implemented internally, it's from LibXC
326 283140 : IF (lsd) THEN
327 7312 : CALL libxc_lsd_info(functional, reference, shortform, needs, max_deriv, print_warn)
328 : ELSE
329 40102 : CALL libxc_lda_info(functional, reference, shortform, needs, max_deriv, print_warn)
330 : END IF
331 : END SELECT
332 283140 : END SUBROUTINE xc_functional_get_info
333 :
334 : ! **************************************************************************************************
335 : !> \brief evaluate a functional (and its derivatives)
336 : !> \param functional a section that describes the functional to be added
337 : !> \param lsd if a local spin desnity is performed
338 : !> \param rho_set a rho set where all the arguments needed by this functional
339 : !> should be valid (which argument are needed can be found with
340 : !> xc_functional_get_info)
341 : !> \param deriv_set place where to store the functional derivatives (they are
342 : !> added to the derivatives)
343 : !> \param deriv_order degree of the derivative that should be evaluated,
344 : !> if positive all the derivatives up to the given degree are evaluated,
345 : !> if negative only the given degree is requested (but to simplify
346 : !> the code all the derivatives might be calculated, you should ignore
347 : !> them when adding derivatives of various functionals they might contain
348 : !> the derivative of just one functional)
349 : !> \par History
350 : !> 11.2003 created [fawzi]
351 : !> \author fawzi
352 : ! **************************************************************************************************
353 930651 : SUBROUTINE xc_functional_eval(functional, lsd, rho_set, deriv_set, deriv_order)
354 :
355 : TYPE(section_vals_type), POINTER :: functional
356 : LOGICAL, INTENT(in) :: lsd
357 : TYPE(xc_rho_set_type), INTENT(IN) :: rho_set
358 : TYPE(xc_derivative_set_type), INTENT(IN) :: deriv_set
359 : INTEGER, INTENT(IN) :: deriv_order
360 :
361 : CHARACTER(len=*), PARAMETER :: abort_message_skala = &
362 : "GauXC functionals are evaluated only through the QS GauXC path. "// &
363 : "Higher XC derivatives for response and kernel properties are not implemented.", &
364 : routineN = 'xc_functional_eval'
365 :
366 : INTEGER :: handle, i_param
367 : LOGICAL :: fun_active
368 : REAL(KIND=dp) :: density_cut, gradient_cut, r_param
369 :
370 310217 : CALL timeset(routineN, handle)
371 :
372 : CALL xc_rho_set_get(rho_set, rho_cutoff=density_cut, &
373 310217 : drho_cutoff=gradient_cut)
374 : CALL section_vals_val_get(functional, "_SECTION_PARAMETERS_", &
375 310217 : l_val=fun_active)
376 310217 : IF (.NOT. fun_active) THEN
377 28 : CALL timestop(handle)
378 28 : RETURN
379 : END IF
380 :
381 310832 : SELECT CASE (functional%section%name)
382 : CASE ("BECKE97")
383 643 : IF (lsd) THEN
384 0 : CALL b97_lsd_eval(rho_set, deriv_set, deriv_order, functional)
385 : ELSE
386 643 : CALL b97_lda_eval(rho_set, deriv_set, deriv_order, functional)
387 : END IF
388 : CASE ("BECKE88_LR_ADIABATIC")
389 176 : IF (lsd) THEN
390 104 : CALL xb88_lr_adiabatic_lsd_eval(rho_set, deriv_set, deriv_order, functional)
391 : ELSE
392 72 : CALL xb88_lr_adiabatic_lda_eval(rho_set, deriv_set, deriv_order, functional)
393 : END IF
394 : CASE ("LYP_ADIABATIC")
395 176 : IF (lsd) THEN
396 104 : CALL lyp_adiabatic_lsd_eval(rho_set, deriv_set, deriv_order, functional)
397 : ELSE
398 72 : CALL lyp_adiabatic_lda_eval(rho_set, deriv_set, deriv_order, functional)
399 : END IF
400 : CASE ("BECKE88")
401 13065 : IF (lsd) THEN
402 3198 : CALL xb88_lsd_eval(rho_set, deriv_set, deriv_order, functional)
403 : ELSE
404 9867 : CALL xb88_lda_eval(rho_set, deriv_set, deriv_order, functional)
405 : END IF
406 : CASE ("BEEF")
407 18 : IF (lsd) THEN
408 0 : CALL xbeef_lsd_eval(rho_set, deriv_set, deriv_order, functional)
409 : ELSE
410 18 : CALL xbeef_lda_eval(rho_set, deriv_set, deriv_order, functional)
411 : END IF
412 : CASE ("BECKE88_LR")
413 1250 : IF (lsd) THEN
414 52 : CALL xb88_lr_lsd_eval(rho_set, deriv_set, deriv_order, functional)
415 : ELSE
416 1198 : CALL xb88_lr_lda_eval(rho_set, deriv_set, deriv_order, functional)
417 : END IF
418 : CASE ("LYP")
419 11557 : IF (lsd) THEN
420 3144 : CALL lyp_lsd_eval(rho_set, deriv_set, deriv_order, functional)
421 : ELSE
422 8413 : CALL lyp_lda_eval(rho_set, deriv_set, deriv_order, functional)
423 : END IF
424 : CASE ("PADE")
425 93486 : CALL pade_init(density_cut)
426 93486 : IF (lsd) THEN
427 14149 : CALL pade_lsd_pw_eval(deriv_set, rho_set, deriv_order)
428 : ELSE
429 79337 : CALL pade_lda_pw_eval(deriv_set, rho_set, deriv_order)
430 : END IF
431 : CASE ("HCTH")
432 565 : CPASSERT(.NOT. lsd)
433 565 : CALL section_vals_val_get(functional, "PARAMETER_SET", i_val=i_param)
434 565 : CALL hcth_lda_eval(i_param, rho_set, deriv_set, deriv_order)
435 : CASE ("OPTX")
436 1040 : IF (lsd) THEN
437 476 : CALL optx_lsd_eval(rho_set, deriv_set, deriv_order, functional)
438 : ELSE
439 564 : CALL optx_lda_eval(rho_set, deriv_set, deriv_order, functional)
440 : END IF
441 : CASE ("CS1")
442 32 : IF (lsd) THEN
443 0 : CALL cs1_lsd_eval(rho_set, deriv_set, deriv_order)
444 : ELSE
445 32 : CALL cs1_lda_eval(rho_set, deriv_set, deriv_order)
446 : END IF
447 : CASE ("XGGA")
448 8 : CALL section_vals_val_get(functional, "FUNCTIONAL", i_val=i_param)
449 8 : CALL xgga_eval(i_param, lsd, rho_set, deriv_set, deriv_order)
450 : CASE ("KE_GGA")
451 1876 : CALL section_vals_val_get(functional, "FUNCTIONAL", i_val=i_param)
452 1876 : IF (lsd) THEN
453 0 : CALL ke_gga_lsd_eval(i_param, rho_set, deriv_set, deriv_order)
454 : ELSE
455 1876 : CALL ke_gga_lda_eval(i_param, rho_set, deriv_set, deriv_order)
456 : END IF
457 : CASE ("P86C")
458 180 : CPASSERT(.NOT. lsd)
459 180 : CALL p86_lda_eval(rho_set, deriv_set, deriv_order, functional)
460 : CASE ("PW92")
461 236 : CALL section_vals_val_get(functional, "PARAMETRIZATION", i_val=i_param)
462 236 : CALL section_vals_val_get(functional, "SCALE", r_val=r_param)
463 236 : IF (lsd) THEN
464 : CALL perdew_wang_lsd_eval(i_param, rho_set, deriv_set, deriv_order, &
465 20 : r_param)
466 : ELSE
467 : CALL perdew_wang_lda_eval(i_param, rho_set, deriv_set, deriv_order, &
468 216 : r_param)
469 : END IF
470 : CASE ("PZ81")
471 54 : CALL section_vals_val_get(functional, "PARAMETRIZATION", i_val=i_param)
472 54 : IF (lsd) THEN
473 12 : CALL pz_lsd_eval(i_param, rho_set, deriv_set, deriv_order, functional)
474 : ELSE
475 42 : CALL pz_lda_eval(i_param, rho_set, deriv_set, deriv_order, functional)
476 : END IF
477 : CASE ("TFW")
478 0 : IF (lsd) THEN
479 0 : CALL tfw_lsd_eval(rho_set, deriv_set, deriv_order)
480 : ELSE
481 0 : CALL tfw_lda_eval(rho_set, deriv_set, deriv_order)
482 : END IF
483 : CASE ("TF")
484 216 : IF (lsd) THEN
485 0 : CALL thomas_fermi_lsd_eval(rho_set, deriv_set, deriv_order)
486 : ELSE
487 216 : CALL thomas_fermi_lda_eval(rho_set, deriv_set, deriv_order)
488 : END IF
489 : CASE ("VWN")
490 1163 : IF (lsd) THEN
491 32 : CALL vwn_lsd_eval(rho_set, deriv_set, deriv_order, functional)
492 : ELSE
493 1131 : CALL vwn_lda_eval(rho_set, deriv_set, deriv_order, functional)
494 : END IF
495 : CASE ("XALPHA")
496 2799 : CALL section_vals_val_get(functional, "XA", r_val=r_param)
497 2799 : IF (lsd) THEN
498 : CALL xalpha_lsd_eval(rho_set, deriv_set, deriv_order, &
499 166 : xa_parameter=r_param, xa_params=functional)
500 : ELSE
501 : CALL xalpha_lda_eval(rho_set, deriv_set, deriv_order, &
502 2633 : xa_parameter=r_param, xa_params=functional)
503 : END IF
504 : CASE ("TPSS")
505 2708 : IF (lsd) THEN
506 0 : CPABORT("TPSS functional not implemented with LSD. Use the LIBXC version instead.")
507 : ELSE
508 2708 : CALL tpss_lda_eval(rho_set, deriv_set, deriv_order, functional)
509 : END IF
510 : CASE ("PBE")
511 148479 : IF (lsd) THEN
512 23065 : CALL pbe_lsd_eval(rho_set, deriv_set, deriv_order, functional)
513 : ELSE
514 125414 : CALL pbe_lda_eval(rho_set, deriv_set, deriv_order, functional)
515 : END IF
516 : CASE ("GAUXC")
517 0 : IF (gauxc_model_none_selected(functional)) THEN
518 0 : CALL gauxc_model_none_xc_eval(functional, lsd, rho_set, deriv_set, deriv_order)
519 : ELSE
520 0 : CPABORT(abort_message_skala)
521 : END IF
522 : CASE ("XWPBE")
523 5004 : IF (lsd) THEN
524 1190 : CALL xwpbe_lsd_eval(rho_set, deriv_set, deriv_order, functional)
525 : ELSE
526 3814 : CALL xwpbe_lda_eval(rho_set, deriv_set, deriv_order, functional)
527 : END IF
528 : CASE ("BECKE_ROUSSEL")
529 166 : IF (lsd) THEN
530 82 : CALL xbecke_roussel_lsd_eval(rho_set, deriv_set, deriv_order, functional)
531 : ELSE
532 84 : CALL xbecke_roussel_lda_eval(rho_set, deriv_set, deriv_order, functional)
533 : END IF
534 : CASE ("LDA_HOLE_T_C_LR")
535 80 : IF (lsd) THEN
536 58 : CALL xlda_hole_t_c_lr_lsd_eval(rho_set, deriv_set, deriv_order, functional)
537 : ELSE
538 22 : CALL xlda_hole_t_c_lr_lda_eval(rho_set, deriv_set, deriv_order, functional)
539 : END IF
540 : CASE ("PBE_HOLE_T_C_LR")
541 4262 : IF (lsd) THEN
542 1178 : CALL xpbe_hole_t_c_lr_lsd_eval(rho_set, deriv_set, deriv_order, functional)
543 : ELSE
544 3084 : CALL xpbe_hole_t_c_lr_lda_eval(rho_set, deriv_set, deriv_order, functional)
545 : END IF
546 : CASE ("GV09")
547 258 : IF (lsd) THEN
548 : CALL xbr_pbe_lda_hole_tc_lr_lsd_eval(rho_set, deriv_set, deriv_order, &
549 58 : functional)
550 : ELSE
551 : CALL xbr_pbe_lda_hole_tc_lr_lda_eval(rho_set, deriv_set, deriv_order, &
552 200 : functional)
553 : END IF
554 : CASE default
555 : ! If functional not natively supported, ask LibXC
556 310754 : IF (lsd) THEN
557 2750 : CALL libxc_lsd_eval(rho_set, deriv_set, deriv_order, functional)
558 : ELSE
559 17942 : CALL libxc_lda_eval(rho_set, deriv_set, deriv_order, functional)
560 : END IF
561 : END SELECT
562 :
563 310189 : CALL timestop(handle)
564 : END SUBROUTINE xc_functional_eval
565 :
566 : ! **************************************************************************************************
567 : !> \brief true for GAUXC sections that wrap a conventional LibXC functional
568 : !> \param functional the GAUXC section
569 : !> \return whether MODEL NONE is active
570 : ! **************************************************************************************************
571 400 : FUNCTION gauxc_model_none_selected(functional)
572 : TYPE(section_vals_type), POINTER :: functional
573 : LOGICAL :: gauxc_model_none_selected
574 :
575 : CHARACTER(LEN=default_string_length) :: model_key, model_name, xc_fun_name, &
576 : xc_key
577 :
578 400 : CALL section_vals_val_get(functional, "MODEL", c_val=model_name)
579 400 : CALL section_vals_val_get(functional, "FUNCTIONAL", c_val=xc_fun_name)
580 400 : model_key = ADJUSTL(model_name)
581 400 : xc_key = ADJUSTL(xc_fun_name)
582 400 : CALL uppercase(model_key)
583 400 : CALL uppercase(xc_key)
584 : gauxc_model_none_selected = (TRIM(model_key) == "" .OR. TRIM(model_key) == "NONE" .OR. &
585 400 : TRIM(model_key) == TRIM(xc_key))
586 400 : END FUNCTION gauxc_model_none_selected
587 :
588 : ! **************************************************************************************************
589 : !> \brief map GAUXC MODEL NONE shorthand names to LibXC exchange/correlation components
590 : !> \param functional the GAUXC section
591 : !> \param xc_fun_name the GAUXC FUNCTIONAL value
592 : !> \param libxc_names LibXC section names to evaluate and add
593 : !> \param nfunc number of LibXC components
594 : ! **************************************************************************************************
595 80 : SUBROUTINE gauxc_model_none_libxc_names(functional, xc_fun_name, libxc_names, nfunc)
596 : TYPE(section_vals_type), POINTER :: functional
597 : CHARACTER(LEN=*), INTENT(OUT) :: xc_fun_name
598 : CHARACTER(LEN=*), DIMENSION(:), INTENT(OUT) :: libxc_names
599 : INTEGER, INTENT(OUT) :: nfunc
600 :
601 : CHARACTER(LEN=default_string_length) :: xc_key
602 :
603 40 : CALL section_vals_val_get(functional, "FUNCTIONAL", c_val=xc_fun_name)
604 40 : xc_key = ADJUSTL(xc_fun_name)
605 40 : CALL uppercase(xc_key)
606 120 : libxc_names(:) = ""
607 40 : SELECT CASE (TRIM(xc_key))
608 : CASE ("LDA", "PADE")
609 0 : nfunc = 2
610 0 : libxc_names(1) = "LDA_X"
611 0 : libxc_names(2) = "LDA_C_PW"
612 : CASE ("VWN")
613 0 : nfunc = 2
614 0 : libxc_names(1) = "LDA_X"
615 0 : libxc_names(2) = "LDA_C_VWN"
616 : CASE ("PBE")
617 40 : nfunc = 2
618 40 : libxc_names(1) = "GGA_X_PBE"
619 40 : libxc_names(2) = "GGA_C_PBE"
620 : CASE ("BLYP")
621 0 : nfunc = 2
622 0 : libxc_names(1) = "GGA_X_B88"
623 0 : libxc_names(2) = "GGA_C_LYP"
624 : CASE ("BP")
625 0 : nfunc = 2
626 0 : libxc_names(1) = "GGA_X_B88"
627 0 : libxc_names(2) = "GGA_C_P86"
628 : CASE ("TPSS")
629 0 : nfunc = 2
630 0 : libxc_names(1) = "MGGA_X_TPSS"
631 0 : libxc_names(2) = "MGGA_C_TPSS"
632 : CASE ("R2SCAN")
633 0 : nfunc = 2
634 0 : libxc_names(1) = "MGGA_X_R2SCAN"
635 0 : libxc_names(2) = "MGGA_C_R2SCAN"
636 : CASE DEFAULT
637 0 : nfunc = 1
638 40 : libxc_names(1) = TRIM(xc_key)
639 : END SELECT
640 40 : END SUBROUTINE gauxc_model_none_libxc_names
641 :
642 : ! **************************************************************************************************
643 : !> \brief needs information for GAUXC MODEL NONE one-center GAPW corrections
644 : !> \param functional the GAUXC section
645 : !> \param lsd whether spin-polarized derivatives are needed
646 : !> \param reference reference string for the wrapped functional
647 : !> \param shortform short name for printout
648 : !> \param needs density ingredients needed by the wrapped functional
649 : !> \param max_deriv maximum implemented derivative order
650 : !> \param print_warn whether LibXC should print development warnings
651 : ! **************************************************************************************************
652 40 : SUBROUTINE gauxc_model_none_xc_info(functional, lsd, reference, shortform, &
653 : needs, max_deriv, print_warn)
654 : TYPE(section_vals_type), POINTER :: functional
655 : LOGICAL, INTENT(in) :: lsd
656 : CHARACTER(LEN=*), INTENT(OUT), OPTIONAL :: reference, shortform
657 : TYPE(xc_rho_cflags_type), INTENT(inout), OPTIONAL :: needs
658 : INTEGER, INTENT(out), OPTIONAL :: max_deriv
659 : LOGICAL, INTENT(IN), OPTIONAL :: print_warn
660 :
661 : CHARACTER(LEN=default_string_length) :: libxc_names(2), xc_fun_name
662 : INTEGER :: ifunc, max_deriv_i, max_deriv_min, nfunc
663 :
664 40 : CALL gauxc_model_none_libxc_names(functional, xc_fun_name, libxc_names, nfunc)
665 40 : max_deriv_min = HUGE(max_deriv_min)
666 120 : DO ifunc = 1, nfunc
667 80 : IF (lsd) THEN
668 : CALL libxc_lsd_info(functional, needs=needs, max_deriv=max_deriv_i, &
669 : print_warn=print_warn, &
670 8 : func_name_override=TRIM(libxc_names(ifunc)))
671 : ELSE
672 : CALL libxc_lda_info(functional, needs=needs, max_deriv=max_deriv_i, &
673 : print_warn=print_warn, &
674 72 : func_name_override=TRIM(libxc_names(ifunc)))
675 : END IF
676 120 : max_deriv_min = MIN(max_deriv_min, max_deriv_i)
677 : END DO
678 40 : IF (PRESENT(max_deriv)) max_deriv = max_deriv_min
679 40 : IF (PRESENT(reference)) THEN
680 4 : reference = "Functional computed by GauXC (underlying: "//TRIM(xc_fun_name)//")"
681 : END IF
682 40 : IF (PRESENT(shortform)) shortform = "GAUXC ("//TRIM(xc_fun_name)//")"
683 40 : END SUBROUTINE gauxc_model_none_xc_info
684 :
685 : ! **************************************************************************************************
686 : !> \brief one-center GAPW correction evaluation for GAUXC MODEL NONE
687 : !> \param functional the GAUXC section
688 : !> \param lsd whether spin-polarized derivatives are evaluated
689 : !> \param rho_set density ingredients
690 : !> \param deriv_set derivative accumulator
691 : !> \param deriv_order derivative order to evaluate
692 : ! **************************************************************************************************
693 0 : SUBROUTINE gauxc_model_none_xc_eval(functional, lsd, rho_set, deriv_set, deriv_order)
694 : TYPE(section_vals_type), POINTER :: functional
695 : LOGICAL, INTENT(in) :: lsd
696 : TYPE(xc_rho_set_type), INTENT(IN) :: rho_set
697 : TYPE(xc_derivative_set_type), INTENT(IN) :: deriv_set
698 : INTEGER, INTENT(IN) :: deriv_order
699 :
700 : CHARACTER(LEN=default_string_length) :: libxc_names(2), xc_fun_name
701 : INTEGER :: ifunc, nfunc
702 :
703 0 : CALL gauxc_model_none_libxc_names(functional, xc_fun_name, libxc_names, nfunc)
704 0 : DO ifunc = 1, nfunc
705 0 : IF (lsd) THEN
706 : CALL libxc_lsd_eval(rho_set, deriv_set, deriv_order, functional, &
707 0 : func_name_override=TRIM(libxc_names(ifunc)))
708 : ELSE
709 : CALL libxc_lda_eval(rho_set, deriv_set, deriv_order, functional, &
710 0 : func_name_override=TRIM(libxc_names(ifunc)))
711 : END IF
712 : END DO
713 0 : END SUBROUTINE gauxc_model_none_xc_eval
714 :
715 : ! **************************************************************************************************
716 : !> \brief ...
717 : !> \param functionals a section containing the functional combination to be
718 : !> applied
719 : !> \param lsd if a local spin desnity is performed
720 : !> \param rho_set a rho set where all the arguments needed by this functional
721 : !> should be valid (which argument are needed can be found with
722 : !> xc_functional_get_info)
723 : !> \param deriv_set place where to store the functional derivatives (they are
724 : !> added to the derivatives)
725 : !> \param deriv_order degree of the derivative that should be evaluated,
726 : !> if positive all the derivatives up to the given degree are evaluated,
727 : !> if negative only the given degree is requested (but to simplify
728 : !> the code all the derivatives might be calculated, you should ignore
729 : !> them when adding derivatives of various functionals they might contain
730 : !> the derivative of just one functional)
731 : !> \author fawzi
732 : ! **************************************************************************************************
733 278162 : SUBROUTINE xc_functionals_eval(functionals, lsd, rho_set, deriv_set, &
734 : deriv_order)
735 : TYPE(section_vals_type), POINTER :: functionals
736 : LOGICAL, INTENT(in) :: lsd
737 : TYPE(xc_rho_set_type), INTENT(IN) :: rho_set
738 : TYPE(xc_derivative_set_type), INTENT(IN) :: deriv_set
739 : INTEGER, INTENT(in) :: deriv_order
740 :
741 : INTEGER :: ifun
742 : TYPE(section_vals_type), POINTER :: xc_fun
743 :
744 278162 : CPASSERT(ASSOCIATED(functionals))
745 278162 : ifun = 0
746 310217 : DO
747 588379 : ifun = ifun + 1
748 588379 : xc_fun => section_vals_get_subs_vals2(functionals, i_section=ifun)
749 588379 : IF (.NOT. ASSOCIATED(xc_fun)) EXIT
750 : CALL xc_functional_eval(xc_fun, &
751 : lsd=lsd, &
752 : rho_set=rho_set, &
753 : deriv_set=deriv_set, &
754 310217 : deriv_order=deriv_order)
755 : END DO
756 278162 : END SUBROUTINE xc_functionals_eval
757 :
758 : ! **************************************************************************************************
759 : !> \brief ...
760 : !> \param functionals a section containing the functional combination to be
761 : !> applied
762 : !> \param lsd if a local spin desnity is performed
763 : !> \param calc_potential set, if potential calculation will be carried out later.
764 : !> helps to save memory and flops. defaults to false.
765 : !> \return ...
766 : !> \author fawzi
767 : ! **************************************************************************************************
768 263892 : FUNCTION xc_functionals_get_needs(functionals, lsd, calc_potential) &
769 : RESULT(needs)
770 : TYPE(section_vals_type), POINTER :: functionals
771 : LOGICAL, INTENT(in) :: lsd
772 : LOGICAL, INTENT(in), OPTIONAL :: calc_potential
773 : TYPE(xc_rho_cflags_type) :: needs
774 :
775 : INTEGER :: ifun
776 : LOGICAL :: my_calc_potential
777 : TYPE(section_vals_type), POINTER :: xc_fun
778 :
779 263892 : my_calc_potential = .FALSE.
780 263892 : IF (PRESENT(calc_potential)) my_calc_potential = calc_potential
781 :
782 263892 : CPASSERT(ASSOCIATED(functionals))
783 263892 : CALL xc_rho_cflags_setall(needs, .FALSE.)
784 :
785 263892 : ifun = 0
786 280929 : DO
787 544821 : ifun = ifun + 1
788 544821 : xc_fun => section_vals_get_subs_vals2(functionals, i_section=ifun)
789 544821 : IF (.NOT. ASSOCIATED(xc_fun)) EXIT
790 280929 : CALL xc_functional_get_info(xc_fun, lsd=lsd, needs=needs)
791 : END DO
792 :
793 263892 : IF (my_calc_potential) THEN
794 211507 : IF (lsd) THEN
795 35343 : needs%rho_spin = .TRUE.
796 69884 : needs%tau_spin = needs%tau_spin .OR. needs%tau
797 : ELSE
798 176164 : needs%rho = .TRUE.
799 : END IF
800 211507 : IF (needs%norm_drho .OR. needs%norm_drho_spin) THEN
801 124047 : IF (lsd) THEN
802 21978 : needs%drho_spin = .TRUE.
803 : ELSE
804 102069 : needs%drho = .TRUE.
805 : END IF
806 : END IF
807 : END IF
808 263892 : END FUNCTION xc_functionals_get_needs
809 :
810 : END MODULE xc_derivatives
|