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