(git:24d69ee)
Loading...
Searching...
No Matches
scf_control_types.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 parameters that control an scf iteration
10!> \note
11!> not in cp_control_types, to separate operator related parameters from
12!> method related parameters (as suggested by Matthias)
13!> \par History
14!> 09.2002 created [fawzi]
15!> \author Fawzi Mohamed
16! **************************************************************************************************
18
25 USE input_constants, ONLY: &
46 USE kinds, ONLY: default_string_length,&
47 dp
55#include "./base/base_uses.f90"
56
57 IMPLICIT NONE
58
59 PRIVATE
60
61 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'scf_control_types'
62 LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .true.
63
64 ! Public data types
65
66 PUBLIC :: scf_control_type, &
67 smear_type, &
69
70 ! Public subroutines
71
72 PUBLIC :: scf_c_create, &
76
77! **************************************************************************************************
78!> \brief contains the parameters needed by a scf run
79!> \param density_guess how to choose the initial density
80!> (CORE,RANDOM,RESTART,ATOMIC,FROZEN)
81!> \param eps_eigval wanted error on the eigenvalues
82!> \param eps_scf whanted error on the whole scf
83!> \param level_shift amount of level shift
84!> \param p_mix how to mix the new and old densities in non diss iterations
85!> \param eps_lumos error on the lumos calculated at the end of the scf
86!> \param max_iter_lumus maxumum number of iterations used to calculate
87!> the lumos at the end of the scf
88!> \param max_scf max scf iterations
89!> \param added_mos additional number of MOs that might be used in the SCF
90!> \param step_size the optimizer step size
91!> \param cdft_opt_control settings for optimizers that work only together with CDFT constraints
92!> \par History
93!> 09.2002 created [fawzi]
94!> \author Fawzi Mohamed
95! **************************************************************************************************
97 LOGICAL :: do_smear = .false.
98 LOGICAL :: common_mu = .false.
99 INTEGER :: method = -1
100 REAL(kind=dp) :: electronic_temperature = -1.0_dp, &
101 fixed_mag_mom = -1.0_dp, &
102 eps_fermi_dirac = -1.0_dp, &
103 window_size = -1.0_dp, &
104 smearing_width = -1.0_dp
105 REAL(kind=dp), DIMENSION(:), POINTER :: list => null()
106 END TYPE smear_type
107
108 TYPE diagonalization_type
109 INTEGER :: method = -1, update_method = -1, max_history = -1
110 REAL(kind=dp) :: eps_jacobi = -1.0_dp
111 REAL(kind=dp) :: jacobi_threshold = -1.0_dp
112 INTEGER :: max_iter = -1, nkrylov = -1, nblock_krylov = -1
113 LOGICAL :: adiis_verbose = .false., do_oda = .false.
114 ! Maximum Overlap Method
115 LOGICAL :: mom = .false., mom_didguess = .false.
116 INTEGER :: mom_proj_formula = -1
117 ! indices of de-occupied and newly occupied alpha / beta molecular orbitals
118 INTEGER, DIMENSION(:), POINTER :: mom_deocca => null(), mom_deoccb => null(), &
119 mom_occa => null(), mom_occb => null()
120 ! determines on SCF which iteration MOM will be switched on;
121 ! since MOs from the previous iteration should be available, it might be at least
122 ! 1 when wave-function has been read from restart file, or
123 ! 2 when the atomic guess method has been used
124 INTEGER :: mom_start = -1
125 INTEGER :: mom_type = -1
126 REAL(kind=dp) :: eps_iter = -1.0_dp
127 REAL(kind=dp) :: eps_adapt = -1.0_dp
128 TYPE(qs_ot_settings_type) :: ot_settings = qs_ot_settings_type()
129 END TYPE diagonalization_type
130
133 TYPE(smear_type), POINTER :: smear => null()
134 TYPE(diagonalization_type) :: diagonalization = diagonalization_type()
135 TYPE(gce_type), POINTER :: gce => null()
136 INTEGER :: density_guess = -1, mixing_method = -1
137 REAL(kind=dp) :: eps_eigval = -1.0_dp, eps_scf = -1.0_dp, eps_scf_hist = -1.0_dp, &
138 level_shift = -1.0_dp, &
139 eps_lumos = -1.0_dp, eps_diis = -1.0_dp
140 INTEGER :: max_iter_lumos = -1, max_diis = -1, nmixing = -1
141 INTEGER :: max_scf = -1, max_scf_hist = -1, &
142 maxl = -1, nkind = -1
143 LOGICAL :: do_diag_sub = .false., &
144 use_cholesky = .false., use_ot = .false., &
145 use_diag = .false., do_outer_scf_reortho = .false., &
146 ignore_convergence_failure = .false.
147 LOGICAL :: force_scf_calculation = .false.
148 LOGICAL :: non_selfconsistent = .false.
149 INTEGER, DIMENSION(2) :: added_mos = -1
150 LOGICAL, DIMENSION(2) :: added_mos_auto = .false.
151 INTEGER :: roks_scheme = -1
152 REAL(kind=dp) :: roks_f = -1.0_dp
153 REAL(kind=dp), DIMENSION(0:2, 0:2, 1:2) :: roks_parameter = -1.0_dp
154 END TYPE scf_control_type
155
157 LOGICAL :: do_gce = .false.
158 REAL(kind=dp) :: target_workfunction = 0.16_dp, &
159 ref_esp = 0.0_dp, &
160 mixing_coef = 0.3_dp, &
161 prev_workfunction = -1001.0_dp, &
162 nelec = 0.0_dp
163 END TYPE gce_type
164
165CONTAINS
166
167! **************************************************************************************************
168!> \brief allocates and initializes an scf control object with the default values
169!> \param scf_control the object to initialize
170!> \par History
171!> 09.2002 created [fawzi]
172!> - Default ROKS parameters added (05.04.06,MK)
173!> \author Fawzi Mohamed
174! **************************************************************************************************
175 SUBROUTINE scf_c_create(scf_control)
176
177 TYPE(scf_control_type), INTENT(INOUT) :: scf_control
178
179 CHARACTER(LEN=*), PARAMETER :: routinen = 'scf_c_create'
180
181 INTEGER :: handle
182
183 CALL timeset(routinen, handle)
184
185 ! Load the default values
186
187 IF (scf_control%non_selfconsistent) THEN
188 scf_control%density_guess = no_guess
189 ELSE
190 scf_control%density_guess = atomic_guess
191 END IF
192 scf_control%eps_eigval = 1.0e-5_dp
193 scf_control%eps_scf = 1.0e-5_dp
194 scf_control%eps_scf_hist = 0.0_dp
195 scf_control%eps_lumos = 1.0e-5_dp
196 scf_control%max_iter_lumos = 2999
197 scf_control%eps_diis = 0.1_dp
198 scf_control%level_shift = 0.0_dp
199 scf_control%max_diis = 4
200 scf_control%max_scf = 50
201 scf_control%nmixing = 2
202 scf_control%use_cholesky = .true.
203 scf_control%use_diag = .true.
204 scf_control%do_diag_sub = .false.
205 scf_control%use_ot = .false.
206 scf_control%ignore_convergence_failure = .false.
207 scf_control%force_scf_calculation = .false.
208 scf_control%do_outer_scf_reortho = .true.
209 scf_control%max_diis = 4
210 scf_control%eps_diis = 0.1_dp
211 scf_control%added_mos(:) = 0
212 scf_control%added_mos_auto(:) = .false.
213 scf_control%max_scf_hist = 0
214
215 !Mixing
216 IF (scf_control%non_selfconsistent) THEN
217 scf_control%mixing_method = no_mix
218 ELSE
219 scf_control%mixing_method = direct_p_mix
220 END IF
221
222 ! Diagonalization
223 scf_control%diagonalization%method = 0
224 scf_control%diagonalization%update_method = diag_update_method_mixing
225 scf_control%diagonalization%max_history = 16
226 scf_control%diagonalization%do_oda = .false.
227 scf_control%diagonalization%adiis_verbose = .false.
228 scf_control%diagonalization%eps_jacobi = 0.0_dp
229 scf_control%diagonalization%jacobi_threshold = 1.0e-7_dp
230 scf_control%diagonalization%max_iter = 0
231 scf_control%diagonalization%eps_iter = 0.0_dp
232 scf_control%diagonalization%eps_adapt = 0.0_dp
233 scf_control%diagonalization%nkrylov = 0
234 scf_control%diagonalization%nblock_krylov = 0
235 CALL qs_ot_settings_init(scf_control%diagonalization%ot_settings)
236
237 scf_control%diagonalization%mom = .false.
238 scf_control%diagonalization%mom_didguess = .false.
239 scf_control%diagonalization%mom_proj_formula = 0
240 NULLIFY (scf_control%diagonalization%mom_deoccA)
241 NULLIFY (scf_control%diagonalization%mom_deoccB)
242 NULLIFY (scf_control%diagonalization%mom_occA)
243 NULLIFY (scf_control%diagonalization%mom_occB)
244 scf_control%diagonalization%mom_start = 0
245
246 ! ROKS
247
248 scf_control%roks_scheme = high_spin_roks
249 scf_control%roks_f = 0.5_dp
250
251 ! Initialize the diagonal blocks with the default ROKS parameters
252 ! 0 = v)irtual, 1 = o)pen shell, 2 = c)losed shell
253
254 scf_control%roks_parameter(0, 0, 1) = 1.5_dp ! avv
255 scf_control%roks_parameter(0, 0, 2) = -0.5_dp ! bvv
256 scf_control%roks_parameter(1, 1, 1) = 0.5_dp ! aoo
257 scf_control%roks_parameter(1, 1, 2) = 0.5_dp ! boo
258 scf_control%roks_parameter(2, 2, 1) = -0.5_dp ! acc
259 scf_control%roks_parameter(2, 2, 2) = 1.5_dp ! bcc
260
261 ! Initialize off-diagonal blocks (fixed)
262
263 scf_control%roks_parameter(0, 1, 1) = 1.0_dp ! avo
264 scf_control%roks_parameter(0, 1, 2) = 0.0_dp ! bvo
265 scf_control%roks_parameter(0, 2, 1) = 0.5_dp ! avc
266 scf_control%roks_parameter(0, 2, 2) = 0.5_dp ! bvc
267 scf_control%roks_parameter(1, 2, 1) = 0.0_dp ! aoc
268 scf_control%roks_parameter(1, 2, 2) = 1.0_dp ! boc
269
270 ! Symmetry enforces
271
272 scf_control%roks_parameter(1, 0, 1) = scf_control%roks_parameter(0, 1, 1) ! aov
273 scf_control%roks_parameter(1, 0, 2) = scf_control%roks_parameter(0, 1, 2) ! bov
274 scf_control%roks_parameter(2, 0, 1) = scf_control%roks_parameter(0, 2, 1) ! acv
275 scf_control%roks_parameter(2, 0, 2) = scf_control%roks_parameter(0, 2, 2) ! bcv
276 scf_control%roks_parameter(2, 1, 1) = scf_control%roks_parameter(1, 2, 1) ! aco
277 scf_control%roks_parameter(2, 1, 2) = scf_control%roks_parameter(1, 2, 2) ! bco
278
279 ! Outer SCF default settings
280
281 scf_control%outer_scf%have_scf = .false.
282 scf_control%outer_scf%max_scf = 0
283 scf_control%outer_scf%eps_scf = 0.0_dp
284 scf_control%outer_scf%step_size = 0.0_dp
285 scf_control%outer_scf%type = -1
286 scf_control%outer_scf%optimizer = -1
287 scf_control%outer_scf%diis_buffer_length = -1
288 NULLIFY (scf_control%outer_scf%cdft_opt_control)
289
290 ! Smearing of the MO occupations
291
292 NULLIFY (scf_control%smear)
293
294 CALL timestop(handle)
295
296 END SUBROUTINE scf_c_create
297
298! **************************************************************************************************
299!> \brief releases the given scf_control (see cp2k/doc/ReferenceCounting.html)
300!> \param scf_control the object to free
301!> \par History
302!> 09.2002 created [fawzi]
303!> \author Fawzi Mohamed
304!> \note
305!> at the moment does nothing
306! **************************************************************************************************
307 SUBROUTINE scf_c_release(scf_control)
308
309 TYPE(scf_control_type), INTENT(INOUT) :: scf_control
310
311 IF (ASSOCIATED(scf_control%smear%list)) THEN
312 DEALLOCATE (scf_control%smear%list)
313 END IF
314 DEALLOCATE (scf_control%smear)
315
316 IF (ASSOCIATED(scf_control%outer_scf%cdft_opt_control)) THEN
317 CALL cdft_opt_type_release(scf_control%outer_scf%cdft_opt_control)
318 END IF
319
320 IF (ASSOCIATED(scf_control%gce)) THEN
321 DEALLOCATE (scf_control%gce)
322 END IF
323
324 ! Maximum overlap method orbital indices lists
325 ! mom_deoccA, mom_deoccB, mom_occA, mom_occB
326 ! points to memory allocated by input file parser,
327 ! so they do not have to be deallocated
328
329 END SUBROUTINE scf_c_release
330
331! **************************************************************************************************
332!> \brief reads the parameters of the scf section into the given scf_control
333!> \param scf_control the object that wil contain the values read
334!> \param inp_section ...
335!> \par History
336!> 05.2001 created [Matthias]
337!> 09.2002 creaded separated scf_control type [fawzi]
338!> \author Matthias Krack
339! **************************************************************************************************
340 SUBROUTINE scf_c_read_parameters(scf_control, inp_section)
341
342 TYPE(scf_control_type), INTENT(INOUT) :: scf_control
343 TYPE(section_vals_type), POINTER :: inp_section
344
345 CHARACTER(LEN=*), PARAMETER :: routinen = 'scf_c_read_parameters'
346
347 CHARACTER(LEN=default_string_length) :: added_mos_string, error_message
348 CHARACTER(LEN=default_string_length), &
349 DIMENSION(:), POINTER :: added_mos
350 INTEGER :: added_mos_value, cholesky_flag, handle, &
351 i, ialgo
352 LOGICAL :: do_mixing, explicit
353 REAL(kind=dp), DIMENSION(:), POINTER :: roks_parameter
354 TYPE(section_vals_type), POINTER :: adiis_section, gce_section, &
355 mixing_section, outer_scf_section, &
356 scf_section, smear_section
357
358 CALL timeset(routinen, handle)
359
360 scf_section => section_vals_get_subs_vals(inp_section, "SCF")
361 CALL section_vals_val_get(scf_section, "DIAGONALIZATION%_SECTION_PARAMETERS_", &
362 l_val=scf_control%use_diag)
363 IF (scf_control%use_diag) THEN
364 CALL section_vals_val_get(scf_section, "DIAGONALIZATION%DIAG_SUB_SCF%_SECTION_PARAMETERS_", &
365 l_val=scf_control%do_diag_sub)
366 END IF
367 CALL section_vals_val_get(scf_section, "OT%_SECTION_PARAMETERS_", l_val=scf_control%use_ot)
368 IF (scf_control%use_diag .AND. scf_control%use_ot) THEN
369 ! don't allow both options to be true
370 cpabort("Don't activate OT and Diagonaliztion together")
371 ELSE IF (.NOT. (scf_control%use_diag .OR. scf_control%use_ot)) THEN
372 ! set default to diagonalization
373 scf_control%use_diag = .true.
374 END IF
375 CALL section_vals_val_get(scf_section, "OT%ALGORITHM", i_val=ialgo)
376 scf_control%do_outer_scf_reortho = ialgo == ot_algo_taylor_or_diag
377 CALL section_vals_val_get(scf_section, "SCF_GUESS", i_val=scf_control%density_guess)
378 CALL section_vals_val_get(scf_section, "eps_eigval", r_val=scf_control%eps_eigval)
379 CALL section_vals_val_get(scf_section, "cholesky", i_val=cholesky_flag)
380 IF (scf_control%use_ot) THEN
381 ! eps_diis default is 0 for OT
382 scf_control%eps_diis = 0.0_dp
383 CALL section_vals_val_get(scf_section, "EPS_DIIS", explicit=explicit)
384 IF (explicit) THEN
385 CALL section_vals_val_get(scf_section, "EPS_DIIS", r_val=scf_control%eps_diis)
386 END IF
387 ELSE
388 CALL section_vals_val_get(scf_section, "EPS_DIIS", r_val=scf_control%eps_diis)
389 END IF
390 IF (cholesky_flag > 0) THEN
391 scf_control%use_cholesky = .true.
392 END IF
393 CALL section_vals_val_get(scf_section, "IGNORE_CONVERGENCE_FAILURE", l_val=scf_control%ignore_convergence_failure)
394 CALL section_vals_val_get(scf_section, "FORCE_SCF_CALCULATION", l_val=scf_control%force_scf_calculation)
395 CALL section_vals_val_get(scf_section, "eps_scf", r_val=scf_control%eps_scf)
396 CALL section_vals_val_get(scf_section, "level_shift", r_val=scf_control%level_shift)
397 CALL section_vals_val_get(scf_section, "max_diis", i_val=scf_control%max_diis)
398 CALL section_vals_val_get(scf_section, "max_scf", i_val=scf_control%max_scf)
399
400 ! Diagonaliztion section
401 IF (scf_control%use_diag) THEN
402 CALL section_vals_val_get(scf_section, "DIAGONALIZATION%ALGORITHM", &
403 i_val=scf_control%diagonalization%method)
404 CALL section_vals_val_get(scf_section, "DIAGONALIZATION%UPDATE_METHOD", &
405 i_val=scf_control%diagonalization%update_method)
406 CALL section_vals_val_get(scf_section, "DIAGONALIZATION%EPS_JACOBI", &
407 r_val=scf_control%diagonalization%eps_jacobi)
408 CALL section_vals_val_get(scf_section, "DIAGONALIZATION%JACOBI_THRESHOLD", &
409 r_val=scf_control%diagonalization%jacobi_threshold)
410 CALL section_vals_val_get(scf_section, "DIAGONALIZATION%MAX_ITER", &
411 i_val=scf_control%diagonalization%max_iter)
412 CALL section_vals_val_get(scf_section, "DIAGONALIZATION%EPS_ITER", &
413 r_val=scf_control%diagonalization%eps_iter)
414 CALL section_vals_val_get(scf_section, "DIAGONALIZATION%EPS_ADAPT", &
415 r_val=scf_control%diagonalization%eps_adapt)
416 CALL section_vals_val_get(scf_section, "DIAGONALIZATION%KRYLOV%NKRYLOV", &
417 i_val=scf_control%diagonalization%nkrylov)
418 CALL section_vals_val_get(scf_section, "DIAGONALIZATION%KRYLOV%NBLOCK", &
419 i_val=scf_control%diagonalization%nblock_krylov)
420 IF (scf_control%diagonalization%method == diag_ot) THEN
421 ! read OT section
422 CALL ot_diag_read_input(scf_control%diagonalization%ot_settings, scf_section)
423 END IF
424 ! read maximum overlap method's parameters
425 CALL section_vals_val_get(scf_section, "MOM%_SECTION_PARAMETERS_", &
426 l_val=scf_control%diagonalization%MOM)
427 IF (scf_control%diagonalization%mom) THEN
428 CALL section_vals_val_get(scf_section, "MOM%MOM_TYPE", &
429 i_val=scf_control%diagonalization%mom_type)
430
431 CALL section_vals_val_get(scf_section, "MOM%START_ITER", &
432 i_val=scf_control%diagonalization%mom_start)
433
434 CALL section_vals_val_get(scf_section, "MOM%DEOCC_ALPHA", &
435 i_vals=scf_control%diagonalization%mom_deoccA)
436
437 CALL section_vals_val_get(scf_section, "MOM%DEOCC_BETA", &
438 i_vals=scf_control%diagonalization%mom_deoccB)
439
440 CALL section_vals_val_get(scf_section, "MOM%OCC_ALPHA", &
441 i_vals=scf_control%diagonalization%mom_occA)
442
443 CALL section_vals_val_get(scf_section, "MOM%OCC_BETA", &
444 i_vals=scf_control%diagonalization%mom_occB)
445
446 CALL section_vals_val_get(scf_section, "MOM%PROJ_FORMULA", &
447 i_val=scf_control%diagonalization%mom_proj_formula)
448 END IF
449 END IF
450 ! Read ADIIS section
451 adiis_section => section_vals_get_subs_vals(scf_section, "ADIIS")
452 CALL section_vals_val_get(adiis_section, "MAX_HISTORY", &
453 i_val=scf_control%diagonalization%max_history)
454 CALL section_vals_val_get(adiis_section, "ODA", &
455 l_val=scf_control%diagonalization%do_oda)
456 CALL section_vals_val_get(adiis_section, "VERBOSE", &
457 l_val=scf_control%diagonalization%adiis_verbose)
458 ! Read ROKS parameters
459 CALL section_vals_val_get(scf_section, "ROKS_SCHEME", i_val=scf_control%roks_scheme)
460
461 SELECT CASE (scf_control%roks_scheme)
462 CASE (general_roks)
463 ! Read parameters for the general ROKS scheme
464 CALL section_vals_val_get(scf_section, "ROKS_F", r_val=scf_control%roks_f)
465 CASE (high_spin_roks)
466 ! Read high-spin ROKS parameters for the diagonal block
467 ! 0 = v)irtual, 1 = o)pen shell, 2 = c)losed shell
468 NULLIFY (roks_parameter)
469 CALL section_vals_val_get(scf_section, "ROKS_PARAMETERS", r_vals=roks_parameter)
470 IF (ASSOCIATED(roks_parameter)) THEN
471 scf_control%roks_parameter(2, 2, 1) = roks_parameter(1) ! acc
472 scf_control%roks_parameter(2, 2, 2) = roks_parameter(2) ! bcc
473 scf_control%roks_parameter(1, 1, 1) = roks_parameter(3) ! aoo
474 scf_control%roks_parameter(1, 1, 2) = roks_parameter(4) ! boo
475 scf_control%roks_parameter(0, 0, 1) = roks_parameter(5) ! avv
476 scf_control%roks_parameter(0, 0, 2) = roks_parameter(6) ! bvv
477 END IF
478 END SELECT
479
480 ! should be moved to printkey
481 CALL section_vals_val_get(scf_section, "eps_lumo", r_val=scf_control%eps_lumos)
482 CALL section_vals_val_get(scf_section, "max_iter_lumo", i_val=scf_control%max_iter_lumos)
483
484 ! Extra MOs, e.g. for smearing
485 CALL section_vals_val_get(scf_section, "added_mos", c_vals=added_mos)
486 cpassert(ASSOCIATED(added_mos))
487 IF (SIZE(added_mos) > 0) THEN
488 scf_control%added_mos_auto(:) = .false.
489 DO i = 1, min(SIZE(added_mos), SIZE(scf_control%added_mos))
490 added_mos_string = adjustl(added_mos(i))
491 CALL uppercase(added_mos_string)
492 IF (trim(added_mos_string) == "AUTO") THEN
493 scf_control%added_mos(i) = 0
494 scf_control%added_mos_auto(i) = .true.
495 ELSE
496 CALL read_integer_object(trim(added_mos(i)), added_mos_value, error_message)
497 IF (len_trim(error_message) > 0) THEN
498 CALL cp_abort(__location__, &
499 "Invalid ADDED_MOS value '"//trim(added_mos(i))// &
500 "'. Use an integer or AUTO.")
501 END IF
502 scf_control%added_mos(i) = added_mos_value
503 END IF
504 END DO
505 IF (SIZE(added_mos) == 1 .AND. scf_control%added_mos_auto(1)) THEN
506 scf_control%added_mos_auto(2) = .true.
507 END IF
508 END IF
509
510 CALL section_vals_val_get(scf_section, "max_scf_history", i_val=scf_control%max_scf_hist)
511 CALL section_vals_val_get(scf_section, "eps_scf_history", r_val=scf_control%eps_scf_hist)
512
513 IF (scf_control%level_shift /= 0.0_dp) scf_control%use_cholesky = .false.
514
515 ! Outer SCF subsection
516 outer_scf_section => section_vals_get_subs_vals(scf_section, "OUTER_SCF")
517 CALL outer_scf_read_parameters(scf_control%outer_scf, outer_scf_section)
518
519 smear_section => section_vals_get_subs_vals(scf_section, "SMEAR")
520 CALL init_smear(scf_control%smear)
521 CALL read_smear_section(scf_control%smear, smear_section)
522
523 do_mixing = .false.
524 mixing_section => section_vals_get_subs_vals(scf_section, "MIXING")
525 CALL section_vals_val_get(mixing_section, "_SECTION_PARAMETERS_", &
526 l_val=do_mixing)
527 IF (do_mixing) THEN
528 CALL section_vals_val_get(mixing_section, "METHOD", &
529 i_val=scf_control%mixing_method)
530 CALL section_vals_val_get(mixing_section, "NMIXING", i_val=scf_control%nmixing)
531 END IF ! do mixing
532
533 gce_section => section_vals_get_subs_vals(scf_section, "GCE")
534 CALL init_gce(scf_control%gce)
535 CALL read_gce_section(scf_control%gce, gce_section)
536
537 CALL timestop(handle)
538
539 END SUBROUTINE scf_c_read_parameters
540
541! **************************************************************************************************
542!> \brief ...
543!> \param smear ...
544! **************************************************************************************************
545 SUBROUTINE init_smear(smear)
546 TYPE(smear_type), POINTER :: smear
547
548 cpassert(.NOT. ASSOCIATED(smear))
549 ALLOCATE (smear)
550 smear%do_smear = .false.
551 smear%method = smear_energy_window
552 smear%electronic_temperature = 0.0_dp
553 smear%eps_fermi_dirac = 1.0e-5_dp
554 smear%fixed_mag_mom = -100.0_dp
555 smear%window_size = 0.0_dp
556 smear%smearing_width = 0.0_dp
557 NULLIFY (smear%list)
558 END SUBROUTINE init_smear
559
560! **************************************************************************************************
561!> \brief ...
562!> \param smear ...
563!> \param smear_section ...
564! **************************************************************************************************
565 SUBROUTINE read_smear_section(smear, smear_section)
566 TYPE(smear_type), POINTER :: smear
567 TYPE(section_vals_type), POINTER :: smear_section
568
569 REAL(kind=dp), DIMENSION(:), POINTER :: r_vals
570
571 NULLIFY (r_vals)
572
573 CALL section_vals_val_get(smear_section, "_SECTION_PARAMETERS_", &
574 l_val=smear%do_smear)
575 IF (smear%do_smear) THEN
576 CALL section_vals_val_get(smear_section, "METHOD", &
577 i_val=smear%method)
578 CALL section_vals_val_get(smear_section, "ELECTRONIC_TEMPERATURE", &
579 r_val=smear%electronic_temperature)
580 CALL section_vals_val_get(smear_section, "EPS_FERMI_DIRAC", &
581 r_val=smear%eps_fermi_dirac)
582 CALL section_vals_val_get(smear_section, "WINDOW_SIZE", &
583 r_val=smear%window_size)
584 IF (smear%method == smear_gaussian .OR. &
585 smear%method == smear_mp .OR. &
586 smear%method == smear_mv) THEN
587 CALL section_vals_val_get(smear_section, "SIGMA", &
588 r_val=smear%smearing_width)
589 END IF
590 IF (smear%method == smear_list) THEN
591 CALL section_vals_val_get(smear_section, "LIST", &
592 r_vals=r_vals)
593 cpassert(ASSOCIATED(r_vals))
594 ALLOCATE (smear%list(SIZE(r_vals)))
595 smear%list = r_vals
596 END IF
597 CALL section_vals_val_get(smear_section, "FIXED_MAGNETIC_MOMENT", &
598 r_val=smear%fixed_mag_mom)
599 END IF ! do smear
600 END SUBROUTINE read_smear_section
601
602! **************************************************************************************************
603!> \brief ...
604!> \param gce ...
605! **************************************************************************************************
606 SUBROUTINE init_gce(gce)
607 TYPE(gce_type), POINTER :: gce
608
609 cpassert(.NOT. ASSOCIATED(gce))
610 ALLOCATE (gce)
611 gce%do_gce = .false.
612 gce%target_workfunction = 0.16_dp
613 gce%prev_workfunction = -1001.0_dp
614 gce%ref_esp = 0.0_dp
615 gce%mixing_coef = 0.3_dp
616 END SUBROUTINE init_gce
617
618! **************************************************************************************************
619!> \brief ...
620!> \param gce ...
621!> \param gce_section ...
622! **************************************************************************************************
623 SUBROUTINE read_gce_section(gce, gce_section)
624 TYPE(gce_type), POINTER :: gce
625 TYPE(section_vals_type), POINTER :: gce_section
626
627 CALL section_vals_val_get(gce_section, "_SECTION_PARAMETERS_", &
628 l_val=gce%do_gce)
629 IF (gce%do_gce) THEN
630 CALL section_vals_val_get(gce_section, "TARGET_WORKFUNCTION", &
631 r_val=gce%target_workfunction)
632 CALL section_vals_val_get(gce_section, "MIXING_COEF", &
633 r_val=gce%mixing_coef)
634 END IF ! do gce
635 END SUBROUTINE read_gce_section
636
637! **************************************************************************************************
638!> \brief writes out the scf parameters
639!> \param scf_control the object you want to print
640!> \param dft_section ...
641!> \par History
642!> 05.2001 created [Matthias]
643!> 09.2002 created separated scf_control type [fawzi]
644!> \author Matthias Krack
645! **************************************************************************************************
646 SUBROUTINE scf_c_write_parameters(scf_control, dft_section)
647
648 TYPE(scf_control_type), INTENT(IN) :: scf_control
649 TYPE(section_vals_type), POINTER :: dft_section
650
651 CHARACTER(LEN=*), PARAMETER :: routinen = 'scf_c_write_parameters'
652
653 INTEGER :: handle, output_unit, roks_scheme
654 LOGICAL :: roks
655 REAL(kind=dp) :: elec_temp
656 TYPE(cp_logger_type), POINTER :: logger
657 TYPE(enumeration_type), POINTER :: enum
658 TYPE(keyword_type), POINTER :: keyword
659 TYPE(section_type), POINTER :: section
660 TYPE(section_vals_type), POINTER :: scf_section
661
662 CALL timeset(routinen, handle)
663
664 NULLIFY (logger)
665 logger => cp_get_default_logger()
666
667 NULLIFY (scf_section)
668 NULLIFY (section)
669
670 scf_section => section_vals_get_subs_vals(dft_section, "SCF")
671 output_unit = cp_print_key_unit_nr(logger, scf_section, "PRINT%PROGRAM_RUN_INFO", &
672 extension=".scfLog")
673
674 IF (output_unit > 0) THEN
675
676 IF (scf_control%max_scf > 0) THEN
677
678 CALL create_scf_section(section)
679
680 keyword => section_get_keyword(section, "SCF_GUESS")
681 CALL keyword_get(keyword, enum=enum)
682
683 IF (.NOT. scf_control%non_selfconsistent .OR. scf_control%force_scf_calculation) THEN
684 WRITE (unit=output_unit, &
685 fmt="(/,/,T2,A,T25,A,T51,A30,/,T25,56('-'),3(/,T25,A,T76,I5),/, "// &
686 "T25,56('-'),4(/,T25,A,T72,ES9.2),/,T25,56('-'), "// &
687 "1(/,T25,A,T71,F10.6))") &
688 "SCF PARAMETERS", &
689 "Density guess: ", adjustr(trim(enum_i2c(enum, scf_control%density_guess))), &
690 "max_scf: ", scf_control%max_scf, &
691 "max_scf_history: ", scf_control%max_scf_hist, &
692 "max_diis: ", scf_control%max_diis, &
693 "eps_scf: ", scf_control%eps_scf, &
694 "eps_scf_history: ", scf_control%eps_scf_hist, &
695 "eps_diis: ", scf_control%eps_diis, &
696 "eps_eigval: ", scf_control%eps_eigval, &
697 "level_shift [a.u.]:", scf_control%level_shift
698
699 IF (scf_control%use_diag) THEN
700 keyword => section_get_keyword(section, "DIAGONALIZATION%UPDATE_METHOD")
701 CALL keyword_get(keyword, enum=enum)
702 WRITE (unit=output_unit, fmt="(T25,A,T51,A30)") &
703 "SCF update method: ", &
704 adjustr(trim(enum_i2c(enum, scf_control%diagonalization%update_method)))
705 IF (scf_control%diagonalization%update_method == diag_update_method_adiis) THEN
706 WRITE (unit=output_unit, fmt="(T25,A,T71,I10)") &
707 "ADIIS max history: ", scf_control%diagonalization%max_history
708 WRITE (unit=output_unit, fmt="(T25,A,T71,L10)") &
709 "ADIIS optimal damping: ", scf_control%diagonalization%do_oda
710 END IF
711 END IF
712 END IF
713
714 IF (any(scf_control%added_mos_auto)) THEN
715 WRITE (unit=output_unit, fmt="(T25,A,T71,2I5)") &
716 "added MOs (auto) ", scf_control%added_mos
717 ELSE IF (sum(abs(scf_control%added_mos)) > 0) THEN
718 WRITE (unit=output_unit, fmt="(T25,A,T71,2I5)") &
719 "added MOs ", scf_control%added_mos
720 END IF
721
722 IF (scf_control%diagonalization%mom) THEN
723 ! TODO extend the output with further parameters
724 WRITE (unit=output_unit, fmt="(T25,A)") "MOM enabled"
725 END IF
726
727 IF (scf_control%mixing_method > 0 .AND. .NOT. scf_control%use_ot .AND. &
728 .NOT. scf_control%non_selfconsistent) THEN
729 keyword => section_get_keyword(section, "MIXING%METHOD")
730 CALL keyword_get(keyword, enum=enum)
731 WRITE (unit=output_unit, fmt="(T25,A,/,T25,A,T51,A30)") &
732 repeat("-", 56), &
733 "Mixing method: ", adjustr(trim(enum_i2c(enum, scf_control%mixing_method)))
734 IF (scf_control%mixing_method > 1) THEN
735 WRITE (unit=output_unit, fmt="(T47,A34)") "charge density mixing in g-space"
736 END IF
737 END IF
738 IF (scf_control%smear%do_smear) THEN
739 keyword => section_get_keyword(section, "SMEAR%METHOD")
740 CALL keyword_get(keyword, enum=enum)
741 WRITE (unit=output_unit, fmt="(T25,A,/,T25,A,T51,A30)") &
742 repeat("-", 56), &
743 "Smear method: ", adjustr(trim(enum_i2c(enum, scf_control%smear%method)))
744 SELECT CASE (scf_control%smear%method)
745 CASE (smear_fermi_dirac)
746 elec_temp = cp_unit_from_cp2k(scf_control%smear%electronic_temperature, &
747 "K")
748 WRITE (unit=output_unit, fmt="(T25,A,T61,F20.1)") &
749 "Electronic temperature [K]:", elec_temp
750 WRITE (unit=output_unit, fmt="(T25,A,T71,ES10.2)") &
751 "Electronic temperature [a.u.]:", scf_control%smear%electronic_temperature, &
752 "Accuracy threshold:", scf_control%smear%eps_fermi_dirac
753 IF (scf_control%smear%fixed_mag_mom > 0.0_dp) WRITE (unit=output_unit, fmt="(T25,A,T61,F20.1)") &
754 "Fixed magnetic moment set to:", scf_control%smear%fixed_mag_mom
756 WRITE (unit=output_unit, fmt="(T25,A,T71,ES10.2)") &
757 "Smearing width (sigma) [a.u.]:", scf_control%smear%smearing_width, &
758 "Accuracy threshold:", scf_control%smear%eps_fermi_dirac
759 IF (scf_control%smear%fixed_mag_mom > 0.0_dp) THEN
760 WRITE (unit=output_unit, fmt="(T25,A,T61,F20.1)") &
761 "Fixed magnetic moment set to:", scf_control%smear%fixed_mag_mom
762 END IF
764 WRITE (unit=output_unit, fmt="(T25,A,T71,F10.6)") &
765 "Smear window [a.u.]: ", scf_control%smear%window_size
766 END SELECT
767 END IF
768
769 IF (scf_control%gce%do_gce) THEN
770 WRITE (unit=output_unit, fmt="(T25,A,/,T25,A,T61,F20.1)") &
771 repeat("-", 56), &
772 "Target workfunction [eV]:", scf_control%gce%target_workfunction
773 WRITE (unit=output_unit, fmt="(T25,A,T61,F20.1)") "Mixing coefficient:", scf_control%gce%mixing_coef
774 WRITE (unit=output_unit, fmt="(T25,A)") "Grand canonical SCF is activated."
775 END IF
776
777 CALL section_vals_val_get(dft_section, "ROKS", l_val=roks)
778 IF (roks .AND. (.NOT. scf_control%use_ot)) THEN
779 CALL section_vals_val_get(scf_section, "ROKS_SCHEME", &
780 i_val=roks_scheme)
781 keyword => section_get_keyword(section, "ROKS_SCHEME")
782 CALL keyword_get(keyword, enum=enum)
783 WRITE (unit=output_unit, fmt="(T25,A,/,T25,A,T51,A30)") &
784 repeat("-", 56), &
785 "ROKS scheme:", adjustr(trim(enum_i2c(enum, roks_scheme)))
786 SELECT CASE (roks_scheme)
787 CASE (general_roks)
788 WRITE (unit=output_unit, fmt="(T25,A,T71,F10.6)") &
789 "ROKS parameter f:", scf_control%roks_f
790 CASE (high_spin_roks)
791 WRITE (unit=output_unit, &
792 fmt="(T25,A,6(/,T25,A,T71,F10.6))") &
793 "ROKS parameters: a)lpha, b)eta; c)losed, o)pen, v)irtual", &
794 "acc", scf_control%roks_parameter(2, 2, 1), &
795 "bcc", scf_control%roks_parameter(2, 2, 2), &
796 "aoo", scf_control%roks_parameter(1, 1, 1), &
797 "boo", scf_control%roks_parameter(1, 1, 2), &
798 "avv", scf_control%roks_parameter(0, 0, 1), &
799 "bvv", scf_control%roks_parameter(0, 0, 2)
800 END SELECT
801 END IF
802 CALL section_release(section)
803
804 IF (scf_control%outer_scf%have_scf) THEN
805 WRITE (output_unit, "(T25,56('-'),/,T25,A)") "Outer loop SCF in use "
806 SELECT CASE (scf_control%outer_scf%type)
807 CASE (outer_scf_none)
808 WRITE (output_unit, '(T25,A)') "No variables optimised in outer loop"
810 WRITE (output_unit, '(T25,A)') "DDAPC constraint enforced"
812 WRITE (output_unit, '(T25,A)') "S2 constraint enforced"
814 WRITE (output_unit, '(T25,A)') "Floating basis function optimization enforced"
816 cpabort("CDFT constraints must be defined in QS&CDFT")
817 CASE DEFAULT
818 cpabort("Unknown outer SCF type")
819 END SELECT
820 WRITE (output_unit, '(T25,A,T72,ES9.2)') "eps_scf", scf_control%outer_scf%eps_scf
821 WRITE (output_unit, '(T25,A,T72,I9)') "max_scf", scf_control%outer_scf%max_scf
822 SELECT CASE (scf_control%outer_scf%optimizer)
824 WRITE (output_unit, '(T25,A)') "No outer loop optimization"
826 WRITE (output_unit, '(T25,A)') "Steepest descent optimization"
828 WRITE (output_unit, '(T25,A)') "Gradient bisection"
829 WRITE (output_unit, '(T25,A,T72,I9)') "bisect_trust_count", scf_control%outer_scf%bisect_trust_count
831 WRITE (output_unit, '(T25,A)') "DIIS optimization"
832 WRITE (output_unit, '(T25,A,T72,I9)') "DIIS buffer length", &
833 scf_control%outer_scf%diis_buffer_length
836 cpabort("Selected optimizer only compatible with CDFT")
838 WRITE (output_unit, '(T25,A)') "Optimization with the secant method"
839 CASE DEFAULT
840 cpabort("Unknown outer SCF optimizer")
841 END SELECT
842 WRITE (output_unit, '(T25,A,T72,ES9.2)') "step_size", scf_control%outer_scf%step_size
843 ELSE
844 WRITE (output_unit, "(T25,56('-'),/,T25,A)") "No outer SCF"
845 END IF
846
847 END IF ! max_scf > 0
848
849 END IF ! output_unit > 0
850
851 CALL cp_print_key_finished_output(output_unit, logger, scf_section, &
852 "PRINT%PROGRAM_RUN_INFO")
853
854 CALL timestop(handle)
855
856 END SUBROUTINE scf_c_write_parameters
857
858! **************************************************************************************************
859
860! **************************************************************************************************
861!> \brief ...
862!> \param settings ...
863!> \param scf_section ...
864! **************************************************************************************************
865 SUBROUTINE ot_diag_read_input(settings, scf_section)
866 TYPE(qs_ot_settings_type) :: settings
867 TYPE(section_vals_type), POINTER :: scf_section
868
869 CHARACTER(len=*), PARAMETER :: routinen = 'ot_diag_read_input'
870
871 INTEGER :: handle, output_unit
872 LOGICAL :: explicit
873 TYPE(cp_logger_type), POINTER :: logger
874 TYPE(section_vals_type), POINTER :: ot_section
875
876 CALL timeset(routinen, handle)
877
878 logger => cp_get_default_logger()
879 output_unit = cp_print_key_unit_nr(logger, scf_section, "PRINT%PROGRAM_RUN_INFO", &
880 extension=".log")
881
882 ! decide default settings
883 CALL qs_ot_settings_init(settings)
884
885 ! use ot input new style
886 ot_section => section_vals_get_subs_vals(scf_section, "DIAGONALIZATION%OT")
887 CALL section_vals_get(ot_section, explicit=explicit)
888
889 CALL ot_readwrite_input(settings, ot_section, output_unit, eigensolver=.true.)
890
891 CALL cp_print_key_finished_output(output_unit, logger, scf_section, &
892 "PRINT%PROGRAM_RUN_INFO")
893
894 CALL timestop(handle)
895
896 END SUBROUTINE ot_diag_read_input
897
898! **************************************************************************************************
899
900END MODULE scf_control_types
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
Utility routines to read data from files. Kept as close as possible to the old parser because.
elemental subroutine, public read_integer_object(string, object, error_message)
Returns an integer number read from a string including products of integer numbers like iz1*iz2*iz3.
unit conversion facility
Definition cp_units.F:30
real(kind=dp) function, public cp_unit_from_cp2k(value, unit_str, defaults, power)
converts from the internal cp2k units to the given unit
Definition cp_units.F:1251
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public smear_fermi_dirac
integer, parameter, public outer_scf_optimizer_sd
integer, parameter, public outer_scf_optimizer_bisect
integer, parameter, public outer_scf_optimizer_secant
integer, parameter, public smear_energy_window
integer, parameter, public outer_scf_cdft_constraint
integer, parameter, public no_guess
integer, parameter, public outer_scf_optimizer_broyden
integer, parameter, public atomic_guess
integer, parameter, public outer_scf_basis_center_opt
integer, parameter, public direct_p_mix
integer, parameter, public outer_scf_s2_constraint
integer, parameter, public ot_algo_taylor_or_diag
integer, parameter, public smear_list
integer, parameter, public no_mix
integer, parameter, public high_spin_roks
integer, parameter, public diag_update_method_mixing
integer, parameter, public diag_ot
integer, parameter, public outer_scf_ddapc_constraint
integer, parameter, public smear_gaussian
integer, parameter, public smear_mv
integer, parameter, public diag_update_method_adiis
integer, parameter, public outer_scf_optimizer_newton_ls
integer, parameter, public outer_scf_optimizer_none
integer, parameter, public outer_scf_optimizer_newton
integer, parameter, public general_roks
integer, parameter, public outer_scf_none
integer, parameter, public smear_mp
integer, parameter, public outer_scf_optimizer_diis
function that build the scf section of the input
subroutine, public create_scf_section(section)
creates the structure of the section with the DFT SCF parameters
represents an enumeration, i.e. a mapping between integers and strings
character(len=default_string_length) function, public enum_i2c(enum, i)
maps an integer to a string
represents keywords in an input
subroutine, public keyword_get(keyword, names, usage, description, type_of_var, n_var, default_value, lone_keyword_value, repeats, enum, citations)
...
objects that represent the structure of input sections and the data contained in an input section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
recursive subroutine, public section_release(section)
releases the given keyword list (see doc/ReferenceCounting.html)
recursive type(keyword_type) function, pointer, public section_get_keyword(section, keyword_name)
returns the requested keyword
subroutine, public section_vals_get(section_vals, ref_count, n_repetition, n_subs_vals_rep, section, explicit)
returns various attributes about the section_vals
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
An array-based list which grows on demand. When the internal array is full, a new array of twice the ...
Definition list.F:24
parameters that control the outer loop of an SCF iteration
subroutine, public outer_scf_read_parameters(outer_scf, outer_scf_section)
reads the parameters of the outer_scf section into the given outer_scf
Control parameters for optimizers that work with CDFT constraints.
subroutine, public cdft_opt_type_release(cdft_opt_control)
releases the CDFT optimizer control object
orbital transformations
Definition qs_ot_types.F:15
subroutine, public qs_ot_settings_init(settings)
sets default values for the settings type
subroutine, public ot_readwrite_input(settings, ot_section, output_unit, complex_kpoints, eigensolver)
...
parameters that control an scf iteration
subroutine, public scf_c_read_parameters(scf_control, inp_section)
reads the parameters of the scf section into the given scf_control
subroutine, public scf_c_release(scf_control)
releases the given scf_control (see cp2k/doc/ReferenceCounting.html)
subroutine, public scf_c_write_parameters(scf_control, dft_section)
writes out the scf parameters
subroutine, public scf_c_create(scf_control)
allocates and initializes an scf control object with the default values
Utilities for string manipulations.
elemental subroutine, public uppercase(string)
Convert all lower case characters in a string to upper case.
type of a logger, at the moment it contains just a print level starting at which level it should be l...
represent a keyword in the input
represent a section of the input file
contains the parameters needed by a scf run
notice, this variable needs to be copyable, needed for spins as e.g. in qs_ot_scf
Definition qs_ot_types.F:77
contains the parameters needed by a scf run