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