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