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