24#include <xc_version.h>
26#if (XC_MAJOR_VERSION < 5 || (XC_MAJOR_VERSION == 5 && XC_MINOR_VERSION < 1))
27 this version of
cp2k only works with libxc versions 5.1.0 and above.
28 furthermore, -i${libxc_dir}/include needs to be added to fcflags.
31 USE xc_f03_lib_m,
ONLY: xc_f03_func_end, &
33 xc_f03_functional_get_name, &
34 xc_f03_func_set_ext_params, &
35 xc_f03_func_set_dens_threshold, &
36 xc_f03_func_set_tau_threshold, &
37 xc_f03_version_string, &
39 xc_f03_reference_doi, &
40 xc_f03_functional_get_number, &
41 xc_f03_available_functional_numbers, &
42 xc_f03_available_functional_names, &
43 xc_f03_maximum_name_length, &
44 xc_f03_number_of_functionals, &
48 xc_f03_gga_exc_vxc_fxc, &
49 xc_f03_gga_exc_vxc_fxc_kxc, &
50 xc_f03_mgga_exc_vxc_fxc_kxc, &
51 xc_f03_mgga_vxc_fxc_kxc, &
55 xc_f03_gga_vxc_fxc_kxc, &
57 xc_f03_func_get_info, &
58 xc_f03_func_info_get_family, &
59 xc_f03_func_info_get_kind, &
60 xc_f03_func_info_get_name, &
61 xc_f03_func_info_get_references, &
62 xc_f03_func_info_get_flags, &
63 xc_f03_func_info_get_n_ext_params, &
64 xc_f03_func_info_get_ext_params_name, &
65 xc_f03_func_info_get_ext_params_default_value, &
66 xc_f03_func_info_get_ext_params_description, &
68 xc_f03_func_reference_get_ref, &
69 xc_f03_func_reference_get_doi, &
71 xc_f03_lda => xc_f03_lda_exc_vxc_fxc_kxc, &
74 xc_f03_lda_exc_vxc_fxc, &
79 xc_f03_mgga => xc_f03_mgga_exc_vxc_fxc, &
81 xc_f03_mgga_exc_vxc, &
84 xc_f03_mgga_vxc_fxc, &
88 xc_f03_func_reference_t, &
102 xc_exchange_correlation, &
105 xc_flags_needs_laplacian, &
109#include "../base/base_uses.f90"
115 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'xc_libxc_wrap'
117 CHARACTER(LEN=*),
PARAMETER,
PUBLIC :: libxc_version = xc_version
119 PUBLIC :: xc_f03_func_t, xc_f03_func_info_t
120 PUBLIC :: xc_f03_func_init, xc_f03_func_end, xc_f03_func_set_ext_params
121 PUBLIC :: xc_f03_functional_get_name, xc_f03_available_functional_numbers, xc_f03_maximum_name_length, &
122 xc_f03_number_of_functionals, xc_f03_available_functional_names
123 PUBLIC :: xc_f03_func_get_info, xc_f03_func_info_get_family, xc_f03_func_info_get_kind, &
124 xc_f03_func_info_get_name, xc_f03_func_info_get_ext_params_name, &
125 xc_f03_func_info_get_ext_params_description, xc_f03_func_info_get_ext_params_default_value, &
126 xc_f03_func_info_get_n_ext_params
127 PUBLIC :: xc_f03_gga_exc, xc_f03_gga_exc_vxc, xc_f03_gga_exc_vxc_fxc, xc_f03_gga_fxc, &
128 xc_f03_gga_vxc, xc_f03_gga_vxc_fxc, &
129 xc_f03_gga_exc_vxc_fxc_kxc, xc_f03_gga_vxc_fxc_kxc
130 PUBLIC :: xc_f03_mgga_exc_vxc_fxc_kxc, xc_f03_mgga_vxc_fxc_kxc
131 PUBLIC :: xc_f03_lda, &
132 xc_f03_lda_exc, xc_f03_lda_exc_vxc, xc_f03_lda_exc_vxc_fxc, &
133 xc_f03_lda_fxc, xc_f03_lda_kxc, xc_f03_lda_vxc
134 PUBLIC :: xc_f03_mgga, xc_f03_mgga_exc, xc_f03_mgga_exc_vxc, xc_f03_mgga_fxc, &
135 xc_f03_mgga_vxc, xc_f03_mgga_vxc_fxc
137 PUBLIC :: xc_family_lda, xc_family_gga, xc_family_mgga, &
138 xc_family_hyb_lda, xc_family_hyb_gga, xc_family_hyb_mgga
140 PUBLIC :: xc_unpolarized, xc_polarized
142 PUBLIC :: xc_exchange, xc_correlation, xc_exchange_correlation, xc_kinetic
145 PUBLIC :: xc_libxc_wrap_info_refs, &
146 xc_libxc_wrap_version, &
147 xc_libxc_wrap_library_reference, &
148 xc_libxc_wrap_info_needs_laplace, &
149 xc_libxc_wrap_info_no_exc, &
150 xc_libxc_wrap_set_thresholds, &
151 xc_libxc_wrap_functional_get_number, &
152 xc_libxc_wrap_is_under_development, &
153 xc_libxc_get_reference_length, &
154 xc_libxc_check_functional
164 FUNCTION xc_libxc_get_reference_length(xc_info)
RESULT(length)
166 TYPE(xc_f03_func_info_t),
INTENT(IN) :: xc_info
169 CHARACTER(LEN=*),
PARAMETER :: routineN =
'xc_libxc_get_reference_length'
170 INTEGER,
PARAMETER :: maxlen = 67
172 CHARACTER(LEN=128) :: descr_string
173 CHARACTER(LEN=1024) :: doi_string, ref_string
174 INTEGER :: i, i_ref, i_ref_old, n_params, handle
175 TYPE(xc_f03_func_reference_t) :: xc_ref
177 CALL timeset(routinen, handle)
183 DO WHILE (i_ref >= 0 .AND. i_ref /= i_ref_old)
185 xc_ref = xc_f03_func_info_get_references(xc_info, i_ref)
186 ref_string = xc_f03_func_reference_get_ref(xc_ref)
187 doi_string = xc_f03_func_reference_get_doi(xc_ref)
188 length = length + len_trim(ref_string) + len_trim(doi_string) + 11
189 IF (mod(length, maxlen) /= 0) length = length + maxlen - mod(length, maxlen)
191 n_params = xc_f03_func_info_get_n_ext_params(xc_info)
192 IF (n_params > 0)
THEN
193 length = length + maxlen
196 descr_string = xc_f03_func_info_get_ext_params_description(xc_info, i - 1)
197 length = length + len_trim(descr_string) + 3
198 IF (mod(length, maxlen) /= 0) length = length + maxlen - mod(length, maxlen)
203 length = length + 2*maxlen
205 CALL timestop(handle)
207 END FUNCTION xc_libxc_get_reference_length
218 SUBROUTINE xc_libxc_wrap_info_refs(xc_info, polarized, sc, reference)
219 TYPE(xc_f03_func_info_t),
INTENT(IN) :: xc_info
220 INTEGER,
INTENT(IN) :: polarized
221 REAL(KIND=
dp),
INTENT(IN) :: sc
222 CHARACTER(LEN=*),
INTENT(OUT) :: reference
224 CHARACTER(LEN=*),
PARAMETER :: routineN =
'xc_libxc_wrap_info_refs'
225 INTEGER,
PARAMETER :: maxlen = 67
227 CHARACTER(LEN=128) :: descr_string
228 CHARACTER(LEN=1028) :: doi_string, ref_string
230 CHARACTER(LEN=2067) :: tmp_string
231 INTEGER :: empty, first, handle, i, i_ref, i_ref_old, idx, &
233 TYPE(xc_f03_func_reference_t) :: xc_ref
235 CALL timeset(routinen, handle)
241 DO WHILE (i_ref >= 0 .AND. i_ref /= i_ref_old)
243 xc_ref = xc_f03_func_info_get_references(xc_info, i_ref)
244 ref_string = xc_f03_func_reference_get_ref(xc_ref)
245 doi_string = xc_f03_func_reference_get_doi(xc_ref)
246 WRITE (tmp_string,
'(a1,i1,a2,a,a7,a)')
'[', idx,
'] ', &
247 trim(ref_string),
', doi: ', trim(doi_string)
248 last = first + len_trim(tmp_string) - 1
249 reference(first:last) = trim(tmp_string)
251 empty = last + (maxlen - 1) - mod(last - 1, maxlen)
253 IF (empty /= last)
THEN
254 reference(first:empty) =
' '
258 n_params = xc_f03_func_info_get_n_ext_params(xc_info)
259 IF (n_params > 0)
THEN
260 reference(first:first + maxlen - 1) =
'Optional external parameters:'//repeat(
' ', maxlen - 28)
261 first = first + maxlen
264 descr_string = xc_f03_func_info_get_ext_params_description(xc_info, i - 1)
265 last = first + len_trim(descr_string) - 1 + 3
266 reference(first:last) =
' * '//trim(descr_string)
268 empty = last + (maxlen - 1) - mod(last - 1, maxlen)
271 IF (empty /= last)
THEN
272 reference(first:empty) =
' '
279 SELECT CASE (polarized)
280 CASE (xc_unpolarized)
281 WRITE (tmp_string,
"('{scale=',f5.3,', spin-unpolarized}')") sc
283 WRITE (tmp_string,
"('{scale=',f5.3,', spin-polarized}')") sc
285 cpabort(
"Unsupported value for variable 'polarized'.")
287 last = first + len_trim(tmp_string) - 1
288 reference(first:last) = trim(tmp_string)
291 reference(first:len(reference)) =
' '
293 IF (last > len(reference)) &
294 cpabort(
"Faulty reference length.")
296 CALL timestop(handle)
298 END SUBROUTINE xc_libxc_wrap_info_refs
310 SUBROUTINE xc_libxc_wrap_version(version, compiled_version)
311 CHARACTER(LEN=*),
INTENT(OUT) :: version
312 CHARACTER(LEN=*),
INTENT(OUT),
OPTIONAL :: compiled_version
314 CHARACTER(LEN=*),
PARAMETER :: routineN =
'xc_libxc_wrap_version'
318 CALL timeset(routinen, handle)
320 CALL xc_f03_version_string(version)
321 IF (
PRESENT(compiled_version)) compiled_version = trim(libxc_version)
323 CALL timestop(handle)
325 END SUBROUTINE xc_libxc_wrap_version
336 SUBROUTINE xc_libxc_wrap_library_reference(reference, doi)
337 CHARACTER(LEN=*),
INTENT(OUT) :: reference, doi
339 CHARACTER(LEN=*),
PARAMETER :: routineN =
'xc_libxc_wrap_library_reference'
343 CALL timeset(routinen, handle)
345 CALL xc_f03_reference(reference)
346 CALL xc_f03_reference_doi(doi)
348 CALL timestop(handle)
350 END SUBROUTINE xc_libxc_wrap_library_reference
367 SUBROUTINE xc_libxc_wrap_set_thresholds(xc_func, xc_info, epsilon_rho, epsilon_tau)
368 TYPE(xc_f03_func_t),
INTENT(INOUT) :: xc_func
369 TYPE(xc_f03_func_info_t),
INTENT(IN) :: xc_info
370 REAL(KIND=
dp),
INTENT(IN) :: epsilon_rho, epsilon_tau
372 CHARACTER(LEN=*),
PARAMETER :: routineN =
'xc_libxc_wrap_set_thresholds'
376 CALL timeset(routinen, handle)
378 CALL xc_f03_func_set_dens_threshold(xc_func, epsilon_rho)
380 SELECT CASE (xc_f03_func_info_get_family(xc_info))
381 CASE (xc_family_mgga, xc_family_hyb_mgga)
382 CALL xc_f03_func_set_tau_threshold(xc_func, epsilon_tau)
385 CALL timestop(handle)
387 END SUBROUTINE xc_libxc_wrap_set_thresholds
401 LOGICAL FUNCTION xc_libxc_check_functional(func_string)
RESULT(exists)
402 CHARACTER(LEN=*),
INTENT(IN) :: func_string
404 CHARACTER(LEN=*),
PARAMETER :: routineN =
'xc_libxc_check_functional'
406 INTEGER :: func_id, handle
408 CALL timeset(routinen, handle)
410 IF (func_string(1:3) ==
"XC_")
THEN
411 func_id = xc_f03_functional_get_number(func_string(4:len_trim(func_string)))
413 func_id = xc_f03_functional_get_number(func_string(1:len_trim(func_string)))
417 IF (func_id == -1) exists = .false.
419 CALL timestop(handle)
421 END FUNCTION xc_libxc_check_functional
435 INTEGER FUNCTION xc_libxc_wrap_functional_get_number(func_string)
RESULT(func_id)
436 CHARACTER(LEN=*),
INTENT(IN) :: func_string
438 CHARACTER(LEN=*),
PARAMETER :: routineN =
'xc_libxc_wrap_functional_get_number'
442 CALL timeset(routinen, handle)
444 IF (func_string(1:3) ==
"XC_")
THEN
445 func_id = xc_f03_functional_get_number(func_string(4:len_trim(func_string)))
447 func_id = xc_f03_functional_get_number(func_string(1:len_trim(func_string)))
449 IF (func_id == -1)
THEN
450 cpabort(trim(func_string)//
": wrong functional name")
453 CALL timestop(handle)
455 END FUNCTION xc_libxc_wrap_functional_get_number
464 LOGICAL FUNCTION xc_libxc_wrap_is_under_development(xc_info)
465 TYPE(xc_f03_func_info_t) :: xc_info
467 IF (iand(xc_f03_func_info_get_flags(xc_info), xc_flags_development) == xc_flags_development)
THEN
468 xc_libxc_wrap_is_under_development = .true.
470 xc_libxc_wrap_is_under_development = .false.
473 END FUNCTION xc_libxc_wrap_is_under_development
486 LOGICAL FUNCTION xc_libxc_wrap_info_needs_laplace(xc_info)
488 TYPE(xc_f03_func_info_t),
INTENT(IN) :: xc_info
490 IF (iand(xc_f03_func_info_get_flags(xc_info), xc_flags_needs_laplacian) == xc_flags_needs_laplacian)
THEN
491 xc_libxc_wrap_info_needs_laplace = .true.
493 xc_libxc_wrap_info_needs_laplace = .false.
496 END FUNCTION xc_libxc_wrap_info_needs_laplace
505 LOGICAL FUNCTION xc_libxc_wrap_info_no_exc(xc_info)
506 TYPE(xc_f03_func_info_t),
INTENT(IN) :: xc_info
508 IF (iand(xc_f03_func_info_get_flags(xc_info), xc_flags_have_exc) == xc_flags_have_exc)
THEN
509 xc_libxc_wrap_info_no_exc = .false.
511 xc_libxc_wrap_info_no_exc = .true.
514 END FUNCTION xc_libxc_wrap_info_no_exc
program cp2k
Main program of CP2K.
Defines the basic variable types.
integer, parameter, public dp
Includes all necessary routines, functions and parameters from libxc. Provides CP2K routines/function...