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 : ! > \brief Creates the PW section of the input
10 : ! > \par History
11 : ! > 07.2018 created
12 : ! > \author JHU
13 : ! **************************************************************************************************
14 :
15 : MODULE input_cp2k_pwdft
16 : #if defined(__SIRIUS)
17 : USE ISO_C_BINDING, ONLY: C_LOC
18 : USE SIRIUS, ONLY: &
19 : sirius_option_get, &
20 : sirius_option_get_section_length, sirius_option_get_info, &
21 : SIRIUS_INTEGER_TYPE, SIRIUS_NUMBER_TYPE, SIRIUS_STRING_TYPE, SIRIUS_OBJECT_TYPE, &
22 : SIRIUS_LOGICAL_TYPE, SIRIUS_ARRAY_TYPE, SIRIUS_INTEGER_ARRAY_TYPE, SIRIUS_LOGICAL_ARRAY_TYPE, &
23 : SIRIUS_NUMBER_ARRAY_TYPE, SIRIUS_STRING_ARRAY_TYPE, string_f2c
24 : #endif
25 : USE input_keyword_types, ONLY: keyword_create, &
26 : keyword_release, &
27 : keyword_type
28 : USE input_section_types, ONLY: section_add_keyword, &
29 : section_add_subsection, &
30 : section_create, &
31 : section_release, &
32 : section_type
33 : USE input_val_types, ONLY: char_t, &
34 : integer_t, &
35 : lchar_t, &
36 : logical_t, &
37 : real_t
38 : USE cp_output_handling, ONLY: add_last_numeric, &
39 : cp_print_key_section_create, &
40 : debug_print_level, &
41 : high_print_level, &
42 : low_print_level, &
43 : medium_print_level, &
44 : silent_print_level
45 : USE kinds, ONLY: dp
46 : USE string_utilities, ONLY: s2a
47 : #include "./base/base_uses.f90"
48 :
49 : IMPLICIT NONE
50 : PRIVATE
51 :
52 : LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .TRUE.
53 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'input_cp2k_pwdft'
54 :
55 : PUBLIC :: create_pwdft_section
56 :
57 : INTEGER, PARAMETER, PUBLIC :: SIRIUS_NO_VDW = -1
58 : INTEGER, PARAMETER, PUBLIC :: SIRIUS_FUNC_VDWDF = 1
59 : INTEGER, PARAMETER, PUBLIC :: SIRIUS_FUNC_VDWDF2 = 2
60 : INTEGER, PARAMETER, PUBLIC :: SIRIUS_FUNC_VDWDFCX = 3
61 :
62 : CONTAINS
63 :
64 : #if defined(__SIRIUS)
65 : ! **************************************************************************************************
66 : !> \brief Create the input section for PW calculations using SIRIUS
67 : !> \param section the section to create
68 : !> \par History
69 : !> 07.2018 created
70 : !> \author JHU
71 : ! **************************************************************************************************
72 9823 : SUBROUTINE create_pwdft_section(section)
73 : TYPE(section_type), POINTER :: section
74 :
75 : TYPE(keyword_type), POINTER :: keyword
76 : TYPE(section_type), POINTER :: subsection
77 :
78 : ! ------------------------------------------------------------------------
79 :
80 9823 : CPASSERT(.NOT. ASSOCIATED(section))
81 : CALL section_create(section, __LOCATION__, name="PW_DFT", &
82 : description="DFT calculation using plane waves basis can be set in this section. "// &
83 : "The backend called SIRIUS, computes the basic properties of the system, "// &
84 : "such as ground state, forces and stresses tensors which can be used by "// &
85 : "cp2k afterwards. The engine has all these features build-in, support of "// &
86 : "pseudo-potentials and full-potentials, spin-orbit coupling, collinear and "// &
87 : "non collinear magnetism, Hubbard correction, all exchange functionals "// &
88 9823 : "supported by libxc and Van der Waals corrections (libvdwxc).")
89 :
90 9823 : NULLIFY (keyword)
91 : CALL keyword_create(keyword, __LOCATION__, &
92 : name='ignore_convergence_failure', &
93 : description="when set to true, calculation will continue irrespectively "// &
94 : "of the convergence status of SIRIUS", &
95 : type_of_var=logical_t, &
96 : repeats=.FALSE., &
97 : default_l_val=.FALSE., &
98 9823 : lone_keyword_l_val=.TRUE.)
99 9823 : CALL section_add_keyword(section, keyword)
100 9823 : CALL keyword_release(keyword)
101 :
102 9823 : NULLIFY (subsection)
103 9823 : CALL create_sirius_section(subsection, 'control')
104 9823 : CALL section_add_subsection(section, subsection)
105 9823 : CALL section_release(subsection)
106 :
107 9823 : CALL create_sirius_section(subsection, 'parameters')
108 9823 : CALL section_add_subsection(section, subsection)
109 9823 : CALL section_release(subsection)
110 :
111 9823 : CALL create_sirius_section(subsection, 'settings')
112 9823 : CALL section_add_subsection(section, subsection)
113 9823 : CALL section_release(subsection)
114 :
115 9823 : CALL create_sirius_section(subsection, 'mixer')
116 9823 : CALL section_add_subsection(section, subsection)
117 9823 : CALL section_release(subsection)
118 :
119 9823 : CALL create_sirius_section(subsection, 'iterative_solver')
120 9823 : CALL section_add_subsection(section, subsection)
121 9823 : CALL section_release(subsection)
122 :
123 : !
124 : ! uncomment these lines when nlcg is officialy supported in cp2k
125 : !
126 : #if defined(__SIRIUS_NLCG)
127 : CALL create_sirius_section(subsection, 'nlcg')
128 : CALL section_add_subsection(section, subsection)
129 : CALL section_release(subsection)
130 : #endif
131 :
132 : #if defined(__SIRIUS_VCSQNM)
133 : CALL create_sirius_section(subsection, 'vcsqnm')
134 : CALL section_add_subsection(section, subsection)
135 : CALL section_release(subsection)
136 : #endif
137 :
138 : #if defined(__SIRIUS_DFTD3)
139 : CALL create_sirius_section(subsection, "dftd3")
140 : CALL section_add_subsection(section, subsection)
141 : CALL section_release(subsection)
142 : #endif
143 :
144 : #if defined(__SIRIUS_DFTD4)
145 : CALL create_sirius_section(subsection, "dftd4")
146 : CALL section_add_subsection(section, subsection)
147 : CALL section_release(subsection)
148 : #endif
149 :
150 9823 : CALL create_print_section(subsection)
151 9823 : CALL section_add_subsection(section, subsection)
152 9823 : CALL section_release(subsection)
153 :
154 9823 : END SUBROUTINE create_pwdft_section
155 :
156 : ! **************************************************************************************************
157 : !> \brief input section for PWDFT control
158 : !> \param section will contain the CONTROL section
159 : !> \param section_name ...
160 : !> \author JHU
161 : ! **************************************************************************************************
162 49115 : SUBROUTINE create_sirius_section(section, section_name)
163 : TYPE(section_type), POINTER :: section
164 : CHARACTER(len=*), INTENT(in) :: section_name
165 :
166 : INTEGER :: length
167 :
168 0 : CPASSERT(.NOT. ASSOCIATED(section))
169 49115 : CALL sirius_option_get_section_length(TRIM(ADJUSTL(section_name)), length)
170 :
171 : CALL section_create(section, __LOCATION__, &
172 : name=TRIM(ADJUSTL(section_name)), &
173 : description=TRIM(section_name)//" section", &
174 : n_subsections=0, &
175 : n_keywords=length, &
176 49115 : repeats=.FALSE.)
177 :
178 49115 : CALL fill_in_section(section, TRIM(ADJUSTL(section_name)))
179 49115 : END SUBROUTINE create_sirius_section
180 :
181 : ! **************************************************************************************************
182 : !> \brief ...
183 : !> \param section ...
184 : !> \param section_name ...
185 : ! **************************************************************************************************
186 49115 : SUBROUTINE fill_in_section(section, section_name)
187 : TYPE(section_type), POINTER :: section
188 : CHARACTER(len=*), INTENT(in) :: section_name
189 :
190 : CHARACTER(len=128) :: name
191 : CHARACTER(len=128), TARGET :: possible_values(1:256)
192 : CHARACTER(len=4096) :: description, usage
193 : INTEGER :: ctype, enum_length, i, j, length, &
194 : num_possible_values
195 49115 : INTEGER, ALLOCATABLE, DIMENSION(:), TARGET :: enum_i_val, ivec
196 : INTEGER, TARGET :: dummy_i
197 : LOGICAL :: jump_dft_parameters, lvecl(1:16)
198 49115 : LOGICAL(4), ALLOCATABLE, DIMENSION(:), TARGET :: lvec
199 : LOGICAL(4), TARGET :: dummy_l
200 49115 : REAL(kind=dp), ALLOCATABLE, DIMENSION(:), TARGET :: rvec
201 : REAL(kind=dp), TARGET :: dummy_r
202 : TYPE(keyword_type), POINTER :: keyword
203 :
204 49115 : ALLOCATE (ivec(1:16))
205 49115 : ALLOCATE (rvec(1:16))
206 49115 : ALLOCATE (lvec(1:16))
207 49115 : ALLOCATE (enum_i_val(1:256))
208 49115 : jump_dft_parameters = .FALSE.
209 : #ifdef __LIBVDWXC
210 49115 : IF (section_name == "parameters") THEN
211 9823 : NULLIFY (keyword)
212 : CALL keyword_create(keyword, __LOCATION__, name="VDW_FUNCTIONAL", &
213 : description="Select the Van der Walls functionals corrections type", &
214 : default_i_val=SIRIUS_NO_VDW, &
215 : enum_i_vals=[SIRIUS_NO_VDW, SIRIUS_FUNC_VDWDF, SIRIUS_FUNC_VDWDF2, SIRIUS_FUNC_VDWDFCX], &
216 : enum_c_vals=s2a("NONE", "FUNC_VDWDF", "FUNC_VDWDF2", "FUNC_VDWDFCX"), &
217 : enum_desc=s2a("No VdW correction", &
218 : "FUNC_VDWDF", &
219 : "FUNC_VDWDF2", &
220 9823 : "FUNC_VDWDFCX"))
221 9823 : CALL section_add_keyword(section, keyword)
222 9823 : CALL keyword_release(keyword)
223 : END IF
224 : #endif
225 :
226 49115 : CALL sirius_option_get_section_length(section_name, length)
227 :
228 1090353 : DO i = 1, length
229 1041238 : NULLIFY (keyword)
230 1041238 : name = ''
231 1041238 : description = ''
232 1041238 : usage = ''
233 : CALL sirius_option_get_info(section_name, &
234 : i, &
235 : name, &
236 : 128, &
237 : ctype, &
238 : num_possible_values, &
239 : enum_length, &
240 : description, &
241 : 4096, &
242 : usage, &
243 1041238 : 4096)
244 :
245 : ! description and usage are ignored here
246 : ! it is a minor inconvenience from the api.
247 1041238 : name = TRIM(ADJUSTL(name))
248 :
249 : #if defined(__SIRIUS_DFTD3)
250 : IF ((section_name == 'dftd3') .AND. (name == 'parameters')) THEN
251 : CYCLE
252 : END IF
253 : #endif
254 : #if defined(__SIRIUS_DFTD4)
255 : ! need to implement the object case within a section
256 : IF ((section_name == 'dftd4') .AND. (name == 'parameters')) THEN
257 : CYCLE
258 : END IF
259 : #endif
260 :
261 : ! I exclude these three keywords because one of them is for debugging
262 : ! purpose the other are replaced by a dedicated call in cp2k
263 : !
264 : ! Moreover xc_functionals would need a special treatment.
265 :
266 2131591 : IF ((name /= 'xc_functionals') .AND. (name /= 'memory_usage') .AND. (name /= 'vk')) THEN
267 : ! we need to null char since SIRIUS interface is basically C
268 255398 : SELECT CASE (ctype)
269 : CASE (SIRIUS_INTEGER_TYPE)
270 255398 : CALL sirius_option_get(section_name, name, ctype, C_LOC(dummy_i))
271 : CALL keyword_create(keyword, __LOCATION__, &
272 : name=TRIM(name), &
273 : description=TRIM(ADJUSTL(description)), &
274 : ! usage=TRIM(ADJUSTL(usage)), &
275 : type_of_var=integer_t, &
276 : repeats=.FALSE., &
277 255398 : default_i_val=dummy_i)
278 255398 : CALL section_add_keyword(section, keyword)
279 255398 : CALL keyword_release(keyword)
280 : CASE (SIRIUS_NUMBER_TYPE)
281 294690 : CALL sirius_option_get(section_name, name, ctype, C_LOC(dummy_r))
282 : CALL keyword_create(keyword, __LOCATION__, &
283 : name=name, &
284 : description=TRIM(ADJUSTL(description)), &
285 : ! usage=TRIM(ADJUSTL(usage)), &
286 : type_of_var=real_t, &
287 : repeats=.FALSE., &
288 294690 : default_r_val=dummy_r)
289 294690 : CALL section_add_keyword(section, keyword)
290 294690 : CALL keyword_release(keyword)
291 : CASE (SIRIUS_LOGICAL_TYPE)
292 255398 : dummy_l = .FALSE.
293 255398 : CALL sirius_option_get(section_name, name, ctype, C_LOC(dummy_l))
294 255398 : IF (dummy_l) THEN
295 : CALL keyword_create(keyword, __LOCATION__, &
296 : name=name, &
297 : description=TRIM(ADJUSTL(description)), &
298 : ! usage=TRIM(ADJUSTL(usage)), &
299 : type_of_var=logical_t, &
300 : repeats=.FALSE., &
301 : default_l_val=.TRUE., &
302 78584 : lone_keyword_l_val=.TRUE.)
303 : ELSE
304 : CALL keyword_create(keyword, __LOCATION__, &
305 : name=name, &
306 : description=TRIM(ADJUSTL(description)), &
307 : ! usage=TRIM(ADJUSTL(usage)), &
308 : type_of_var=logical_t, &
309 : repeats=.FALSE., &
310 : default_l_val=.FALSE., &
311 176814 : lone_keyword_l_val=.TRUE.)
312 : END IF
313 255398 : CALL section_add_keyword(section, keyword)
314 255398 : CALL keyword_release(keyword)
315 : CASE (SIRIUS_STRING_TYPE)
316 157168 : IF (enum_length >= 1) THEN
317 648318 : DO j = 1, enum_length
318 510796 : possible_values(j) = ''
319 510796 : CALL sirius_option_get(section_name, name, ctype, C_LOC(possible_values(j)), max_length=128, enum_idx=j)
320 510796 : enum_i_val(j) = j
321 648318 : possible_values(j) = TRIM(ADJUSTL(possible_values(j)))
322 : END DO
323 :
324 137522 : IF (enum_length > 1) THEN
325 : CALL keyword_create(keyword, __LOCATION__, &
326 : name=name, &
327 : description=TRIM(ADJUSTL(description)), &
328 : ! usage=TRIM(ADJUSTL(usage)), &
329 : repeats=.FALSE., &
330 : enum_i_vals=enum_i_val(1:enum_length), &
331 : enum_c_vals=possible_values(1:enum_length), &
332 137522 : default_i_val=1)
333 : ELSE
334 : CALL keyword_create(keyword, __LOCATION__, &
335 : name=name, &
336 : description=TRIM(ADJUSTL(description)), &
337 : ! usage=TRIM(ADJUSTL(usage)), &
338 : type_of_var=char_t, &
339 : default_c_val=possible_values(1), &
340 0 : repeats=.FALSE.)
341 : END IF
342 : ELSE
343 : CALL keyword_create(keyword, __LOCATION__, &
344 : name=name, &
345 : description=TRIM(ADJUSTL(description)), &
346 : ! usage=TRIM(ADJUSTL(usage)), &
347 : type_of_var=char_t, &
348 : default_c_val='', &
349 19646 : repeats=.FALSE.)
350 : END IF
351 157168 : CALL section_add_keyword(section, keyword)
352 157168 : CALL keyword_release(keyword)
353 : CASE (SIRIUS_INTEGER_ARRAY_TYPE)
354 39292 : CALL sirius_option_get(section_name, name, ctype, C_LOC(ivec(1)), max_length=16)
355 :
356 39292 : IF (num_possible_values == 0) THEN
357 : CALL keyword_create(keyword, __LOCATION__, &
358 : name=name, &
359 : description=TRIM(ADJUSTL(description)), &
360 : type_of_var=integer_t, &
361 : n_var=-1, &
362 0 : repeats=.FALSE.)
363 : ELSE
364 : CALL keyword_create(keyword, __LOCATION__, &
365 : name=name, &
366 : description=TRIM(ADJUSTL(description)), &
367 : type_of_var=integer_t, &
368 : repeats=.FALSE., &
369 : n_var=num_possible_values, &
370 39292 : default_i_vals=ivec(1:num_possible_values))
371 : END IF
372 39292 : CALL section_add_keyword(section, keyword)
373 39292 : CALL keyword_release(keyword)
374 : CASE (SIRIUS_LOGICAL_ARRAY_TYPE)
375 0 : CALL sirius_option_get(section_name, name, ctype, C_LOC(lvec(1)), max_length=16)
376 0 : DO j = 1, num_possible_values
377 0 : lvecl(j) = lvec(j)
378 : END DO
379 0 : IF (num_possible_values > 0) THEN
380 : CALL keyword_create(keyword, __LOCATION__, &
381 : name=name, &
382 : description=TRIM(ADJUSTL(description)), &
383 : !usage=TRIM(ADJUSTL(usage)), &
384 : type_of_var=logical_t, &
385 : repeats=.FALSE., &
386 : n_var=num_possible_values, &
387 0 : default_l_vals=lvecl(1:num_possible_values))
388 : ELSE
389 : CALL keyword_create(keyword, __LOCATION__, &
390 : name=name, &
391 : description=TRIM(ADJUSTL(description)), &
392 : !usage=TRIM(ADJUSTL(usage)), &
393 : type_of_var=logical_t, &
394 : repeats=.FALSE., &
395 0 : n_var=-1)
396 : END IF
397 0 : CALL section_add_keyword(section, keyword)
398 0 : CALL keyword_release(keyword)
399 : CASE (SIRIUS_NUMBER_ARRAY_TYPE)
400 19646 : CALL sirius_option_get(section_name, name, ctype, C_LOC(rvec(1)), max_length=16)
401 :
402 19646 : IF (num_possible_values == 0) THEN
403 : CALL keyword_create(keyword, __LOCATION__, &
404 : name=name, &
405 : description=TRIM(ADJUSTL(description)), &
406 : ! usage=TRIM(ADJUSTL(usage)), &
407 : type_of_var=real_t, &
408 : repeats=.FALSE., &
409 9823 : n_var=-1)
410 : ELSE
411 : CALL keyword_create(keyword, __LOCATION__, &
412 : name=name, &
413 : description=TRIM(ADJUSTL(description)), &
414 : ! usage=TRIM(ADJUSTL(usage)), &
415 : type_of_var=real_t, &
416 : repeats=.FALSE., &
417 : n_var=num_possible_values, &
418 9823 : default_r_vals=rvec(1:num_possible_values))
419 : END IF
420 19646 : CALL section_add_keyword(section, keyword)
421 1041238 : CALL keyword_release(keyword)
422 : !CASE (SIRIUS_OBJECT_TYPE)
423 : ! create a subsection for the dftd3/dftd4 parameters
424 : !CALL create_sirius_section(sub_section, sub_section_name)
425 : !CALL section_add_subsection(section, sub_section)
426 : !CALL section_release(sub_section)
427 : CASE default
428 : END SELECT
429 : END IF
430 : END DO
431 49115 : DEALLOCATE (ivec)
432 49115 : DEALLOCATE (rvec)
433 49115 : DEALLOCATE (lvec)
434 49115 : DEALLOCATE (enum_i_val)
435 49115 : END SUBROUTINE fill_in_section
436 :
437 : ! **************************************************************************************************
438 : !> \brief Create the print section for sirius
439 : !> \param section the section to create
440 : !> \author jgh
441 : ! **************************************************************************************************
442 9823 : SUBROUTINE create_print_section(section)
443 : TYPE(section_type), POINTER :: section
444 :
445 : TYPE(section_type), POINTER :: print_key
446 :
447 9823 : CPASSERT(.NOT. ASSOCIATED(section))
448 : CALL section_create(section, __LOCATION__, name="PRINT", &
449 : description="Section of possible print options in PW_DFT code.", &
450 9823 : n_keywords=0, n_subsections=1, repeats=.FALSE.)
451 :
452 9823 : NULLIFY (print_key)
453 9823 : CALL create_dos_section(print_key)
454 9823 : CALL section_add_subsection(section, print_key)
455 9823 : CALL section_release(print_key)
456 :
457 9823 : END SUBROUTINE create_print_section
458 :
459 : ! **************************************************************************************************
460 : !> \brief ...
461 : !> \param print_key ...
462 : ! **************************************************************************************************
463 9823 : SUBROUTINE create_dos_section(print_key)
464 :
465 : TYPE(section_type), POINTER :: print_key
466 :
467 : TYPE(keyword_type), POINTER :: keyword
468 :
469 9823 : NULLIFY (keyword)
470 :
471 : CALL cp_print_key_section_create(print_key, __LOCATION__, "DOS", &
472 : description="Print Density of States (DOS) (only available states from SCF)", &
473 9823 : print_level=debug_print_level, common_iter_levels=1, filename="")
474 :
475 : CALL keyword_create(keyword, __LOCATION__, name="APPEND", &
476 : description="Append the DOS obtained at different iterations to the output file. "// &
477 : "By default the file is overwritten", &
478 : usage="APPEND", default_l_val=.FALSE., &
479 9823 : lone_keyword_l_val=.TRUE.)
480 9823 : CALL section_add_keyword(print_key, keyword)
481 9823 : CALL keyword_release(keyword)
482 :
483 : CALL keyword_create(keyword, __LOCATION__, name="DELTA_E", &
484 : description="Histogramm energy spacing.", &
485 9823 : usage="DELTA_E 0.0005", type_of_var=real_t, default_r_val=0.001_dp)
486 9823 : CALL section_add_keyword(print_key, keyword)
487 9823 : CALL keyword_release(keyword)
488 :
489 9823 : END SUBROUTINE create_dos_section
490 :
491 : #else
492 : ! **************************************************************************************************
493 : !> \brief ...
494 : !> \param section ...
495 : ! **************************************************************************************************
496 : SUBROUTINE create_pwdft_section(section)
497 : TYPE(section_type), POINTER :: section
498 :
499 : CPASSERT(.NOT. ASSOCIATED(section))
500 :
501 : CALL section_create(section, __LOCATION__, name="PW_DFT", &
502 : description="This section contains all information to run an "// &
503 : "SIRIUS PW calculation.", &
504 : n_subsections=0, &
505 : repeats=.FALSE.)
506 :
507 : END SUBROUTINE create_pwdft_section
508 :
509 : #endif
510 :
511 : END MODULE input_cp2k_pwdft
|