(git:495eafe)
Loading...
Searching...
No Matches
input_cp2k_pwdft.F
Go to the documentation of this file.
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
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
33 USE input_val_types, ONLY: char_t, &
34 integer_t, &
35 lchar_t, &
36 logical_t, &
37 real_t
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
62CONTAINS
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 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 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 "supported by libxc and Van der Waals corrections (libvdwxc).")
89
90 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 lone_keyword_l_val=.true.)
99 CALL section_add_keyword(section, keyword)
100 CALL keyword_release(keyword)
101
102 NULLIFY (subsection)
103 CALL create_sirius_section(subsection, 'control')
104 CALL section_add_subsection(section, subsection)
105 CALL section_release(subsection)
106
107 CALL create_sirius_section(subsection, 'parameters')
108 CALL section_add_subsection(section, subsection)
109 CALL section_release(subsection)
110
111 CALL create_sirius_section(subsection, 'settings')
112 CALL section_add_subsection(section, subsection)
113 CALL section_release(subsection)
114
115 CALL create_sirius_section(subsection, 'mixer')
116 CALL section_add_subsection(section, subsection)
117 CALL section_release(subsection)
118
119 CALL create_sirius_section(subsection, 'iterative_solver')
120 CALL section_add_subsection(section, subsection)
121 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 CALL create_print_section(subsection)
151 CALL section_add_subsection(section, subsection)
152 CALL section_release(subsection)
153
154 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 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 cpassert(.NOT. ASSOCIATED(section))
169 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 repeats=.false.)
177
178 CALL fill_in_section(section, trim(adjustl(section_name)))
179 END SUBROUTINE create_sirius_section
180
181! **************************************************************************************************
182!> \brief ...
183!> \param section ...
184!> \param section_name ...
185! **************************************************************************************************
186 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 INTEGER, ALLOCATABLE, DIMENSION(:), TARGET :: enum_i_val, ivec
196 INTEGER, TARGET :: dummy_i
197 LOGICAL :: jump_dft_parameters, lvecl(1:16)
198 LOGICAL(4), ALLOCATABLE, DIMENSION(:), TARGET :: lvec
199 LOGICAL(4), TARGET :: dummy_l
200 REAL(kind=dp), ALLOCATABLE, DIMENSION(:), TARGET :: rvec
201 REAL(kind=dp), TARGET :: dummy_r
202 TYPE(keyword_type), POINTER :: keyword
203
204 ALLOCATE (ivec(1:16))
205 ALLOCATE (rvec(1:16))
206 ALLOCATE (lvec(1:16))
207 ALLOCATE (enum_i_val(1:256))
208 jump_dft_parameters = .false.
209#ifdef __LIBVDWXC
210 IF (section_name == "parameters") THEN
211 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, &
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 "FUNC_VDWDFCX"))
221 CALL section_add_keyword(section, keyword)
222 CALL keyword_release(keyword)
223 END IF
224#endif
225
226 CALL sirius_option_get_section_length(section_name, length)
227
228 DO i = 1, length
229 NULLIFY (keyword)
230 name = ''
231 description = ''
232 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 4096)
244
245 ! description and usage are ignored here
246 ! it is a minor inconvenience from the api.
247 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 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 SELECT CASE (ctype)
269 CASE (sirius_integer_type)
270 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 default_i_val=dummy_i)
278 CALL section_add_keyword(section, keyword)
279 CALL keyword_release(keyword)
280 CASE (sirius_number_type)
281 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 default_r_val=dummy_r)
289 CALL section_add_keyword(section, keyword)
290 CALL keyword_release(keyword)
291 CASE (sirius_logical_type)
292 dummy_l = .false.
293 CALL sirius_option_get(section_name, name, ctype, c_loc(dummy_l))
294 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 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 lone_keyword_l_val=.true.)
312 END IF
313 CALL section_add_keyword(section, keyword)
314 CALL keyword_release(keyword)
315 CASE (sirius_string_type)
316 IF (enum_length >= 1) THEN
317 DO j = 1, enum_length
318 possible_values(j) = ''
319 CALL sirius_option_get(section_name, name, ctype, c_loc(possible_values(j)), max_length=128, enum_idx=j)
320 enum_i_val(j) = j
321 possible_values(j) = trim(adjustl(possible_values(j)))
322 END DO
323
324 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 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 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 repeats=.false.)
350 END IF
351 CALL section_add_keyword(section, keyword)
352 CALL keyword_release(keyword)
353 CASE (sirius_integer_array_type)
354 CALL sirius_option_get(section_name, name, ctype, c_loc(ivec(1)), max_length=16)
355
356 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 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 default_i_vals=ivec(1:num_possible_values))
371 END IF
372 CALL section_add_keyword(section, keyword)
373 CALL keyword_release(keyword)
374 CASE (sirius_logical_array_type)
375 CALL sirius_option_get(section_name, name, ctype, c_loc(lvec(1)), max_length=16)
376 DO j = 1, num_possible_values
377 lvecl(j) = lvec(j)
378 END DO
379 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 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 n_var=-1)
396 END IF
397 CALL section_add_keyword(section, keyword)
398 CALL keyword_release(keyword)
399 CASE (sirius_number_array_type)
400 CALL sirius_option_get(section_name, name, ctype, c_loc(rvec(1)), max_length=16)
401
402 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 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 default_r_vals=rvec(1:num_possible_values))
419 END IF
420 CALL section_add_keyword(section, keyword)
421 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 DEALLOCATE (ivec)
432 DEALLOCATE (rvec)
433 DEALLOCATE (lvec)
434 DEALLOCATE (enum_i_val)
435 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 SUBROUTINE create_print_section(section)
443 TYPE(section_type), POINTER :: section
444
445 TYPE(section_type), POINTER :: print_key
446
447 cpassert(.NOT. ASSOCIATED(section))
448 CALL section_create(section, __location__, name="PRINT", &
449 description="Section of possible print options in PW_DFT code.", &
450 n_keywords=0, n_subsections=1, repeats=.false.)
451
452 NULLIFY (print_key)
453 CALL create_dos_section(print_key)
454 CALL section_add_subsection(section, print_key)
455 CALL section_release(print_key)
456
457 END SUBROUTINE create_print_section
458
459! **************************************************************************************************
460!> \brief ...
461!> \param print_key ...
462! **************************************************************************************************
463 SUBROUTINE create_dos_section(print_key)
464
465 TYPE(section_type), POINTER :: print_key
466
467 TYPE(keyword_type), POINTER :: keyword
468
469 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 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 lone_keyword_l_val=.true.)
480 CALL section_add_keyword(print_key, keyword)
481 CALL keyword_release(keyword)
482
483 CALL keyword_create(keyword, __location__, name="DELTA_E", &
484 description="Histogramm energy spacing.", &
485 usage="DELTA_E 0.0005", type_of_var=real_t, default_r_val=0.001_dp)
486 CALL section_add_keyword(print_key, keyword)
487 CALL keyword_release(keyword)
488
489 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
511END MODULE input_cp2k_pwdft
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer, parameter, public debug_print_level
integer, parameter, public low_print_level
integer, parameter, public medium_print_level
integer, parameter, public high_print_level
integer, parameter, public add_last_numeric
integer, parameter, public silent_print_level
subroutine, public cp_print_key_section_create(print_key_section, location, name, description, print_level, each_iter_names, each_iter_values, add_last, filename, common_iter_levels, citations, unit_str)
creates a print_key section
subroutine, public create_pwdft_section(section)
...
integer, parameter, public sirius_func_vdwdfcx
integer, parameter, public sirius_func_vdwdf2
integer, parameter, public sirius_no_vdw
integer, parameter, public sirius_func_vdwdf
represents keywords in an input
subroutine, public keyword_release(keyword)
releases the given keyword (see doc/ReferenceCounting.html)
subroutine, public keyword_create(keyword, location, name, description, usage, type_of_var, n_var, repeats, variants, default_val, default_l_val, default_r_val, default_lc_val, default_c_val, default_i_val, default_l_vals, default_r_vals, default_c_vals, default_i_vals, lone_keyword_val, lone_keyword_l_val, lone_keyword_r_val, lone_keyword_c_val, lone_keyword_i_val, lone_keyword_l_vals, lone_keyword_r_vals, lone_keyword_c_vals, lone_keyword_i_vals, enum_c_vals, enum_i_vals, enum, enum_strict, enum_desc, unit_str, citations, deprecation_notice, removed)
creates a keyword object
objects that represent the structure of input sections and the data contained in an input section
subroutine, public section_create(section, location, name, description, n_keywords, n_subsections, repeats, citations, deprecation_notice)
creates a list of keywords
subroutine, public section_add_keyword(section, keyword)
adds a keyword to the given section
subroutine, public section_add_subsection(section, subsection)
adds a subsection to the given section
recursive subroutine, public section_release(section)
releases the given keyword list (see doc/ReferenceCounting.html)
a wrapper for basic fortran types.
integer, parameter, public real_t
integer, parameter, public lchar_t
integer, parameter, public logical_t
integer, parameter, public char_t
integer, parameter, public integer_t
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Utilities for string manipulations.
represent a keyword in the input
represent a section of the input file