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 : MODULE qs_scf_output
9 : USE admm_types, ONLY: admm_type
10 : USE admm_utils, ONLY: admm_correct_for_eigenvalues,&
11 : admm_uncorrect_for_eigenvalues
12 : USE atomic_kind_types, ONLY: atomic_kind_type
13 : USE cp_blacs_env, ONLY: cp_blacs_env_type
14 : USE cp_control_types, ONLY: dft_control_type
15 : USE cp_dbcsr_api, ONLY: dbcsr_p_type,&
16 : dbcsr_type
17 : USE cp_dbcsr_output, ONLY: cp_dbcsr_write_sparse_matrix
18 : USE cp_fm_struct, ONLY: cp_fm_struct_create,&
19 : cp_fm_struct_release,&
20 : cp_fm_struct_type
21 : USE cp_fm_types, ONLY: cp_fm_init_random,&
22 : cp_fm_type
23 : USE cp_log_handling, ONLY: cp_get_default_logger,&
24 : cp_logger_type
25 : USE cp_output_handling, ONLY: cp_p_file,&
26 : cp_print_key_finished_output,&
27 : cp_print_key_should_output,&
28 : cp_print_key_unit_nr
29 : USE cp_units, ONLY: cp_unit_from_cp2k
30 : USE input_constants, ONLY: &
31 : becke_cutoff_element, becke_cutoff_global, cdft_alpha_constraint, cdft_beta_constraint, &
32 : cdft_charge_constraint, cdft_magnetization_constraint, ot_precond_full_all, &
33 : outer_scf_becke_constraint, outer_scf_hirshfeld_constraint, outer_scf_optimizer_bisect, &
34 : outer_scf_optimizer_broyden, outer_scf_optimizer_diis, outer_scf_optimizer_newton, &
35 : outer_scf_optimizer_newton_ls, outer_scf_optimizer_sd, outer_scf_optimizer_secant, &
36 : radius_covalent, radius_default, radius_single, radius_user, radius_vdw, &
37 : shape_function_density, shape_function_gaussian
38 : USE input_section_types, ONLY: section_get_ivals,&
39 : section_vals_get_subs_vals,&
40 : section_vals_type,&
41 : section_vals_val_get
42 : USE kahan_sum, ONLY: accurate_sum
43 : USE kinds, ONLY: default_string_length,&
44 : dp
45 : USE kpoint_types, ONLY: kpoint_type
46 : USE machine, ONLY: m_flush
47 : USE message_passing, ONLY: mp_para_env_type
48 : USE particle_types, ONLY: particle_type
49 : USE physcon, ONLY: evolt,&
50 : kcalmol
51 : USE preconditioner_types, ONLY: preconditioner_type
52 : USE ps_implicit_types, ONLY: MIXED_BC,&
53 : MIXED_PERIODIC_BC,&
54 : NEUMANN_BC,&
55 : PERIODIC_BC
56 : USE pw_env_types, ONLY: pw_env_type
57 : USE pw_poisson_types, ONLY: pw_poisson_implicit
58 : USE qmmm_image_charge, ONLY: print_image_coefficients
59 : USE qs_cdft_opt_types, ONLY: cdft_opt_type_write
60 : USE qs_cdft_types, ONLY: cdft_control_type
61 : USE qs_charges_types, ONLY: qs_charges_type
62 : USE qs_energy_types, ONLY: qs_energy_type
63 : USE qs_environment_types, ONLY: get_qs_env,&
64 : qs_environment_type
65 : USE qs_kind_types, ONLY: qs_kind_type
66 : USE qs_mo_io, ONLY: write_mo_set_to_output_unit
67 : USE qs_mo_methods, ONLY: calculate_magnitude,&
68 : calculate_orthonormality,&
69 : calculate_subspace_eigenvalues
70 : USE qs_mo_occupation, ONLY: set_mo_occupation
71 : USE qs_mo_types, ONLY: allocate_mo_set,&
72 : deallocate_mo_set,&
73 : get_mo_set,&
74 : init_mo_set,&
75 : mo_set_type
76 : USE qs_ot_eigensolver, ONLY: ot_eigensolver
77 : USE qs_rho_types, ONLY: qs_rho_get,&
78 : qs_rho_type
79 : USE qs_sccs, ONLY: print_sccs_results
80 : USE qs_scf_types, ONLY: ot_method_nr,&
81 : qs_scf_env_type,&
82 : special_diag_method_nr
83 : USE scf_control_types, ONLY: scf_control_type
84 : #include "./base/base_uses.f90"
85 :
86 : IMPLICIT NONE
87 :
88 : PRIVATE
89 :
90 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_scf_output'
91 :
92 : PUBLIC :: qs_scf_loop_info, &
93 : qs_scf_print_summary, &
94 : qs_scf_loop_print, &
95 : qs_scf_outer_loop_info, &
96 : qs_scf_initial_info, &
97 : qs_scf_write_mos, &
98 : qs_scf_cdft_info, &
99 : qs_scf_cdft_initial_info, &
100 : qs_scf_cdft_constraint_info
101 :
102 : CONTAINS
103 :
104 : ! **************************************************************************************************
105 : !> \brief writes a summary of information after scf
106 : !> \param output_unit ...
107 : !> \param qs_env ...
108 : ! **************************************************************************************************
109 18814 : SUBROUTINE qs_scf_print_summary(output_unit, qs_env)
110 : INTEGER, INTENT(IN) :: output_unit
111 : TYPE(qs_environment_type), POINTER :: qs_env
112 :
113 : INTEGER :: nelectron_total
114 : LOGICAL :: gapw, gapw_xc, qmmm
115 : TYPE(dft_control_type), POINTER :: dft_control
116 : TYPE(qs_charges_type), POINTER :: qs_charges
117 : TYPE(qs_energy_type), POINTER :: energy
118 : TYPE(qs_rho_type), POINTER :: rho
119 : TYPE(qs_scf_env_type), POINTER :: scf_env
120 :
121 18814 : NULLIFY (rho, energy, dft_control, scf_env, qs_charges)
122 : CALL get_qs_env(qs_env=qs_env, rho=rho, energy=energy, dft_control=dft_control, &
123 18814 : scf_env=scf_env, qs_charges=qs_charges)
124 :
125 18814 : gapw = dft_control%qs_control%gapw
126 18814 : gapw_xc = dft_control%qs_control%gapw_xc
127 18814 : qmmm = qs_env%qmmm
128 18814 : nelectron_total = scf_env%nelectron
129 :
130 : CALL qs_scf_print_scf_summary(output_unit, rho, qs_charges, energy, nelectron_total, &
131 18814 : dft_control, qmmm, qs_env, gapw, gapw_xc)
132 :
133 18814 : END SUBROUTINE qs_scf_print_summary
134 :
135 : ! **************************************************************************************************
136 : !> \brief writes basic information at the beginning of an scf run
137 : !> \param output_unit ...
138 : !> \param mos ...
139 : !> \param dft_control ...
140 : ! **************************************************************************************************
141 17613 : SUBROUTINE qs_scf_initial_info(output_unit, mos, dft_control)
142 : INTEGER :: output_unit
143 : TYPE(mo_set_type), DIMENSION(:), INTENT(IN) :: mos
144 : TYPE(dft_control_type), POINTER :: dft_control
145 :
146 : INTEGER :: homo, ispin, nao, nelectron_spin, nmo
147 :
148 17613 : IF (output_unit > 0) THEN
149 19143 : DO ispin = 1, dft_control%nspins
150 : CALL get_mo_set(mo_set=mos(ispin), &
151 : homo=homo, &
152 : nelectron=nelectron_spin, &
153 : nao=nao, &
154 10155 : nmo=nmo)
155 10155 : IF (dft_control%nspins > 1) THEN
156 2334 : WRITE (UNIT=output_unit, FMT="(/,T2,A,I2)") "Spin", ispin
157 : END IF
158 : WRITE (UNIT=output_unit, FMT="(/,(T2,A,T71,I10))") &
159 10155 : "Number of electrons:", nelectron_spin, &
160 10155 : "Number of occupied orbitals:", homo, &
161 39453 : "Number of molecular orbitals:", nmo
162 : END DO
163 : WRITE (UNIT=output_unit, FMT="(/,T2,A,T71,I10)") &
164 8988 : "Number of orbital functions:", nao
165 : END IF
166 :
167 17613 : END SUBROUTINE qs_scf_initial_info
168 :
169 : ! **************************************************************************************************
170 : !> \brief Write the MO eigenvector, eigenvalues, and occupation numbers to the output unit
171 : !> \param qs_env ...
172 : !> \param scf_env ...
173 : !> \param final_mos ...
174 : !> \par History
175 : !> - Revise MO printout to enable eigenvalues with OT (05.05.2021, MK)
176 : ! **************************************************************************************************
177 651936 : SUBROUTINE qs_scf_write_mos(qs_env, scf_env, final_mos)
178 : TYPE(qs_environment_type), POINTER :: qs_env
179 : TYPE(qs_scf_env_type), POINTER :: scf_env
180 : LOGICAL, INTENT(IN) :: final_mos
181 :
182 : CHARACTER(LEN=*), PARAMETER :: routineN = 'qs_scf_write_mos'
183 :
184 : CHARACTER(LEN=2) :: solver_method
185 : CHARACTER(LEN=3*default_string_length) :: message
186 : CHARACTER(LEN=5) :: spin
187 : CHARACTER(LEN=default_string_length), &
188 162984 : DIMENSION(:), POINTER :: tmpstringlist
189 : INTEGER :: handle, homo, ikp, ispin, iw, kpoint, &
190 : nao, nelectron, nkp, nmo, nspin, numo
191 : INTEGER, DIMENSION(2) :: nmos_occ
192 162984 : INTEGER, DIMENSION(:), POINTER :: mo_index_range
193 : LOGICAL :: do_kpoints, print_eigvals, &
194 : print_eigvecs, print_mo_info, &
195 : print_occup, print_occup_stats
196 : REAL(KIND=dp) :: flexible_electron_count, maxocc, n_el_f, &
197 : occup_stats_occ_threshold
198 162984 : REAL(KIND=dp), DIMENSION(:), POINTER :: mo_eigenvalues, umo_eigenvalues
199 : TYPE(admm_type), POINTER :: admm_env
200 162984 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
201 : TYPE(cp_blacs_env_type), POINTER :: blacs_env
202 : TYPE(cp_fm_struct_type), POINTER :: fm_struct_tmp
203 : TYPE(cp_fm_type), POINTER :: mo_coeff, umo_coeff
204 : TYPE(cp_logger_type), POINTER :: logger
205 162984 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: ks, s
206 : TYPE(dbcsr_type), POINTER :: matrix_ks, matrix_s
207 : TYPE(dft_control_type), POINTER :: dft_control
208 : TYPE(kpoint_type), POINTER :: kpoints
209 162984 : TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
210 : TYPE(mo_set_type), POINTER :: mo_set, umo_set
211 : TYPE(mp_para_env_type), POINTER :: para_env
212 162984 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
213 : TYPE(preconditioner_type), POINTER :: local_preconditioner
214 162984 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
215 : TYPE(scf_control_type), POINTER :: scf_control
216 : TYPE(section_vals_type), POINTER :: dft_section, input
217 :
218 162984 : CALL timeset(routineN, handle)
219 :
220 162984 : CPASSERT(ASSOCIATED(qs_env))
221 :
222 : ! Retrieve the required information for the requested print output
223 : CALL get_qs_env(qs_env, &
224 : atomic_kind_set=atomic_kind_set, &
225 : blacs_env=blacs_env, &
226 : dft_control=dft_control, &
227 : do_kpoints=do_kpoints, &
228 : input=input, &
229 : qs_kind_set=qs_kind_set, &
230 : para_env=para_env, &
231 : particle_set=particle_set, &
232 162984 : scf_control=scf_control)
233 :
234 : ! Quick return, if no printout of MO information is requested
235 162984 : dft_section => section_vals_get_subs_vals(input, "DFT")
236 162984 : CALL section_vals_val_get(dft_section, "PRINT%MO%EIGENVALUES", l_val=print_eigvals)
237 162984 : CALL section_vals_val_get(dft_section, "PRINT%MO%EIGENVECTORS", l_val=print_eigvecs)
238 162984 : CALL section_vals_val_get(dft_section, "PRINT%MO%OCCUPATION_NUMBERS", l_val=print_occup)
239 162984 : CALL section_vals_val_get(dft_section, "PRINT%MO%OCCUPATION_NUMBERS_STATS", c_vals=tmpstringlist)
240 :
241 162984 : print_occup_stats = .FALSE.
242 162984 : occup_stats_occ_threshold = 1e-6_dp
243 162984 : IF (SIZE(tmpstringlist) > 0) THEN ! the lone_keyword_c_vals doesn't work as advertised, handle it manually
244 162984 : print_occup_stats = .TRUE.
245 162984 : IF (LEN_TRIM(tmpstringlist(1)) > 0) &
246 162984 : READ (tmpstringlist(1), *) print_occup_stats
247 : END IF
248 162984 : IF (SIZE(tmpstringlist) > 1) &
249 162984 : READ (tmpstringlist(2), *) occup_stats_occ_threshold
250 :
251 162984 : logger => cp_get_default_logger()
252 162984 : print_mo_info = (cp_print_key_should_output(logger%iter_info, dft_section, "PRINT%MO") /= 0) .OR. final_mos
253 :
254 162984 : IF ((.NOT. print_mo_info) .OR. (.NOT. (print_eigvals .OR. print_eigvecs .OR. print_occup .OR. print_occup_stats))) THEN
255 156880 : CALL timestop(handle)
256 156880 : RETURN
257 : END IF
258 :
259 6104 : NULLIFY (fm_struct_tmp)
260 6104 : NULLIFY (mo_coeff)
261 6104 : NULLIFY (mo_eigenvalues)
262 6104 : NULLIFY (mo_set)
263 6104 : NULLIFY (umo_coeff)
264 6104 : NULLIFY (umo_eigenvalues)
265 6104 : NULLIFY (umo_set)
266 :
267 6104 : nspin = dft_control%nspins
268 6104 : nmos_occ = 0
269 :
270 : ! Check, if we have k points
271 6104 : IF (do_kpoints) THEN
272 10 : CALL get_qs_env(qs_env, kpoints=kpoints)
273 10 : nkp = SIZE(kpoints%kp_env)
274 : ELSE
275 6094 : CALL get_qs_env(qs_env, matrix_ks=ks, matrix_s=s)
276 6094 : CPASSERT(ASSOCIATED(ks))
277 6094 : CPASSERT(ASSOCIATED(s))
278 : nkp = 1
279 : END IF
280 :
281 12400 : DO ikp = 1, nkp
282 :
283 6296 : IF (do_kpoints) THEN
284 202 : mos => kpoints%kp_env(ikp)%kpoint_env%mos(1, :)
285 202 : kpoint = ikp
286 : ELSE
287 6094 : CALL get_qs_env(qs_env, matrix_ks=ks, mos=mos)
288 6094 : kpoint = 0 ! Gamma point only
289 : END IF
290 6296 : CPASSERT(ASSOCIATED(mos))
291 :
292 : ! Prepare MO information for printout
293 19002 : DO ispin = 1, nspin
294 :
295 : ! Calculate MO eigenvalues and eigenvector when OT is used
296 6602 : IF (scf_env%method == ot_method_nr) THEN
297 :
298 1876 : solver_method = "OT"
299 :
300 1876 : IF (do_kpoints) THEN
301 0 : CPABORT("The OT method is not implemented for k points")
302 : END IF
303 :
304 1876 : matrix_ks => ks(ispin)%matrix
305 1876 : matrix_s => s(1)%matrix
306 :
307 : ! With ADMM, we have to modify the Kohn-Sham matrix
308 1876 : IF (dft_control%do_admm) THEN
309 0 : CALL get_qs_env(qs_env, admm_env=admm_env)
310 0 : CALL admm_correct_for_eigenvalues(ispin, admm_env, matrix_ks)
311 : END IF
312 :
313 1876 : mo_set => mos(ispin)
314 : CALL get_mo_set(mo_set=mo_set, &
315 : mo_coeff=mo_coeff, &
316 : eigenvalues=mo_eigenvalues, &
317 : homo=homo, &
318 : maxocc=maxocc, &
319 : nelectron=nelectron, &
320 : n_el_f=n_el_f, &
321 : nao=nao, &
322 : nmo=nmo, &
323 1876 : flexible_electron_count=flexible_electron_count)
324 :
325 : ! Retrieve the index of the last MO for which a printout is requested
326 1876 : mo_index_range => section_get_ivals(dft_section, "PRINT%MO%MO_INDEX_RANGE")
327 1876 : CPASSERT(ASSOCIATED(mo_index_range))
328 1876 : numo = MIN(mo_index_range(2) - homo, nao - homo)
329 :
330 1876 : IF (.NOT. final_mos) THEN
331 1654 : numo = 0
332 : message = "The MO information for unoccupied MOs is only calculated after "// &
333 : "SCF convergence is achieved when the orbital transformation (OT) "// &
334 1654 : "method is used"
335 1654 : CPWARN(TRIM(message))
336 : END IF
337 :
338 : ! Calculate the unoccupied MO set (umo_set) with OT if needed
339 1876 : IF (numo > 0) THEN
340 :
341 : ! Create temporary virtual MO set for printout
342 : CALL cp_fm_struct_create(fm_struct_tmp, &
343 : context=blacs_env, &
344 : para_env=para_env, &
345 : nrow_global=nao, &
346 20 : ncol_global=numo)
347 20 : ALLOCATE (umo_set)
348 : CALL allocate_mo_set(mo_set=umo_set, &
349 : nao=nao, &
350 : nmo=numo, &
351 : nelectron=0, &
352 : n_el_f=n_el_f, &
353 : maxocc=maxocc, &
354 20 : flexible_electron_count=flexible_electron_count)
355 : CALL init_mo_set(mo_set=umo_set, &
356 : fm_struct=fm_struct_tmp, &
357 20 : name="Temporary MO set (unoccupied MOs only)for printout")
358 20 : CALL cp_fm_struct_release(fm_struct_tmp)
359 : CALL get_mo_set(mo_set=umo_set, &
360 : mo_coeff=umo_coeff, &
361 20 : eigenvalues=umo_eigenvalues)
362 :
363 : ! Calculate the MO information for the request MO index range
364 20 : IF (final_mos) THEN
365 : ! Prepare printout of the additional unoccupied MOs when OT is being employed
366 20 : CALL cp_fm_init_random(umo_coeff)
367 : ! The FULL_ALL preconditioner makes not much sense for the unoccupied orbitals
368 20 : NULLIFY (local_preconditioner)
369 20 : IF (ASSOCIATED(scf_env%ot_preconditioner)) THEN
370 20 : local_preconditioner => scf_env%ot_preconditioner(1)%preconditioner
371 20 : IF (local_preconditioner%in_use == ot_precond_full_all) THEN
372 0 : NULLIFY (local_preconditioner)
373 : END IF
374 : END IF
375 : CALL ot_eigensolver(matrix_h=matrix_ks, &
376 : matrix_s=matrix_s, &
377 : matrix_c_fm=umo_coeff, &
378 : matrix_orthogonal_space_fm=mo_coeff, &
379 : eps_gradient=scf_control%eps_lumos, &
380 : preconditioner=local_preconditioner, &
381 : iter_max=scf_control%max_iter_lumos, &
382 20 : size_ortho_space=nmo)
383 : END IF
384 :
385 : CALL calculate_subspace_eigenvalues(orbitals=umo_coeff, &
386 : ks_matrix=matrix_ks, &
387 : evals_arg=umo_eigenvalues, &
388 20 : do_rotation=.TRUE.)
389 20 : CALL set_mo_occupation(mo_set=umo_set)
390 :
391 : ! With ADMM, we have to undo the modification of the Kohn-Sham matrix
392 20 : IF (dft_control%do_admm) THEN
393 0 : CALL admm_uncorrect_for_eigenvalues(ispin, admm_env, matrix_ks)
394 : END IF
395 :
396 : ELSE
397 :
398 : NULLIFY (umo_set)
399 :
400 : END IF ! numo > 0
401 :
402 : ELSE
403 :
404 4726 : solver_method = "TD"
405 4726 : mo_set => mos(ispin)
406 4726 : NULLIFY (umo_set)
407 :
408 : END IF ! OT is used
409 :
410 : ! Print MO information
411 6602 : IF (nspin > 1) THEN
412 306 : SELECT CASE (ispin)
413 : CASE (1)
414 306 : spin = "ALPHA"
415 : CASE (2)
416 306 : spin = "BETA"
417 : CASE DEFAULT
418 612 : CPABORT("Invalid spin")
419 : END SELECT
420 612 : IF (ASSOCIATED(umo_set)) THEN
421 : CALL write_mo_set_to_output_unit(mo_set, atomic_kind_set, qs_kind_set, particle_set, &
422 : dft_section, 4, kpoint, final_mos=final_mos, spin=TRIM(spin), &
423 12 : solver_method=solver_method, umo_set=umo_set)
424 : ELSE
425 : CALL write_mo_set_to_output_unit(mo_set, atomic_kind_set, qs_kind_set, particle_set, &
426 : dft_section, 4, kpoint, final_mos=final_mos, spin=TRIM(spin), &
427 600 : solver_method=solver_method)
428 : END IF
429 : ELSE
430 5990 : IF (ASSOCIATED(umo_set)) THEN
431 : CALL write_mo_set_to_output_unit(mo_set, atomic_kind_set, qs_kind_set, particle_set, &
432 : dft_section, 4, kpoint, final_mos=final_mos, &
433 8 : solver_method=solver_method, umo_set=umo_set)
434 : ELSE
435 : CALL write_mo_set_to_output_unit(mo_set, atomic_kind_set, qs_kind_set, particle_set, &
436 : dft_section, 4, kpoint, final_mos=final_mos, &
437 5982 : solver_method=solver_method)
438 : END IF
439 : END IF
440 :
441 52046 : nmos_occ(ispin) = MAX(nmos_occ(ispin), COUNT(mo_set%occupation_numbers > occup_stats_occ_threshold))
442 :
443 : ! Deallocate temporary objects needed for OT
444 6602 : IF (scf_env%method == ot_method_nr) THEN
445 1876 : IF (ASSOCIATED(umo_set)) THEN
446 20 : CALL deallocate_mo_set(umo_set)
447 20 : DEALLOCATE (umo_set)
448 : END IF
449 1876 : NULLIFY (matrix_ks)
450 1876 : NULLIFY (matrix_s)
451 : END IF
452 12898 : NULLIFY (mo_set)
453 :
454 : END DO ! ispin
455 :
456 : END DO ! k point loop
457 :
458 6104 : IF (print_mo_info .AND. print_occup_stats) THEN
459 : iw = cp_print_key_unit_nr(logger, dft_section, "PRINT%MO", &
460 : ignore_should_output=print_mo_info, &
461 0 : extension=".MOLog")
462 0 : IF (iw > 0) THEN
463 0 : IF (SIZE(mos) > 1) THEN
464 0 : WRITE (UNIT=iw, FMT="(A,I4)") " MO| Total occupied (ALPHA):", nmos_occ(1)
465 0 : WRITE (UNIT=iw, FMT="(A,I4)") " MO| Total occupied (BETA): ", nmos_occ(2)
466 : ELSE
467 0 : WRITE (UNIT=iw, FMT="(A,I4)") " MO| Total occupied: ", nmos_occ(1)
468 : END IF
469 0 : WRITE (UNIT=iw, FMT="(A)") ""
470 : END IF
471 : CALL cp_print_key_finished_output(iw, logger, dft_section, "PRINT%MO", &
472 0 : ignore_should_output=print_mo_info)
473 : END IF
474 :
475 6104 : CALL timestop(handle)
476 :
477 162984 : END SUBROUTINE qs_scf_write_mos
478 :
479 : ! **************************************************************************************************
480 : !> \brief writes basic information obtained in a scf outer loop step
481 : !> \param output_unit ...
482 : !> \param scf_control ...
483 : !> \param scf_env ...
484 : !> \param energy ...
485 : !> \param total_steps ...
486 : !> \param should_stop ...
487 : !> \param outer_loop_converged ...
488 : ! **************************************************************************************************
489 5102 : SUBROUTINE qs_scf_outer_loop_info(output_unit, scf_control, scf_env, &
490 : energy, total_steps, should_stop, outer_loop_converged)
491 : INTEGER :: output_unit
492 : TYPE(scf_control_type), POINTER :: scf_control
493 : TYPE(qs_scf_env_type), POINTER :: scf_env
494 : TYPE(qs_energy_type), POINTER :: energy
495 : INTEGER :: total_steps
496 : LOGICAL, INTENT(IN) :: should_stop, outer_loop_converged
497 :
498 : REAL(KIND=dp) :: outer_loop_eps
499 :
500 15306 : outer_loop_eps = SQRT(MAXVAL(scf_env%outer_scf%gradient(:, scf_env%outer_scf%iter_count)**2))
501 5102 : IF (output_unit > 0) WRITE (output_unit, '(/,T3,A,I4,A,E10.2,A,F22.10)') &
502 2668 : "outer SCF iter = ", scf_env%outer_scf%iter_count, &
503 5336 : " RMS gradient = ", outer_loop_eps, " energy =", energy%total
504 :
505 5102 : IF (outer_loop_converged) THEN
506 4071 : IF (output_unit > 0) WRITE (output_unit, '(T3,A,I4,A,I4,A,/)') &
507 2145 : "outer SCF loop converged in", scf_env%outer_scf%iter_count, &
508 4290 : " iterations or ", total_steps, " steps"
509 : ELSE IF (scf_env%outer_scf%iter_count > scf_control%outer_scf%max_scf &
510 1031 : .OR. should_stop) THEN
511 128 : IF (output_unit > 0) WRITE (output_unit, '(T3,A,I4,A,I4,A,/)') &
512 64 : "outer SCF loop FAILED to converge after ", &
513 128 : scf_env%outer_scf%iter_count, " iterations or ", total_steps, " steps"
514 : END IF
515 :
516 5102 : END SUBROUTINE qs_scf_outer_loop_info
517 :
518 : ! **************************************************************************************************
519 : !> \brief writes basic information obtained in a scf step
520 : !> \param scf_env ...
521 : !> \param output_unit ...
522 : !> \param just_energy ...
523 : !> \param t1 ...
524 : !> \param t2 ...
525 : !> \param energy ...
526 : ! **************************************************************************************************
527 148941 : SUBROUTINE qs_scf_loop_info(scf_env, output_unit, just_energy, t1, t2, energy)
528 :
529 : TYPE(qs_scf_env_type), POINTER :: scf_env
530 : INTEGER :: output_unit
531 : LOGICAL :: just_energy
532 : REAL(KIND=dp) :: t1, t2
533 : TYPE(qs_energy_type), POINTER :: energy
534 :
535 148941 : IF ((output_unit > 0) .AND. scf_env%print_iter_line) THEN
536 75702 : IF (just_energy) THEN
537 : WRITE (UNIT=output_unit, &
538 : FMT="(T2,I5,1X,A,T20,E8.2,1X,F6.1,16X,F20.10)") &
539 5203 : scf_env%iter_count, TRIM(scf_env%iter_method), scf_env%iter_param, &
540 10406 : t2 - t1, energy%total
541 : ELSE
542 68141 : IF ((ABS(scf_env%iter_delta) < 1.0E-8_dp) .OR. &
543 70499 : (ABS(scf_env%iter_delta) >= 1.0E5_dp)) THEN
544 : WRITE (UNIT=output_unit, &
545 : FMT="(T2,I5,1X,A,T20,E8.2,1X,F6.1,1X,ES14.4,1X,F20.10,1X,ES9.2)") &
546 2358 : scf_env%iter_count, TRIM(scf_env%iter_method), scf_env%iter_param, &
547 4716 : t2 - t1, scf_env%iter_delta, energy%total, energy%total - energy%tot_old
548 : ELSE
549 : WRITE (UNIT=output_unit, &
550 : FMT="(T2,I5,1X,A,T20,E8.2,1X,F6.1,1X,F14.8,1X,F20.10,1X,ES9.2)") &
551 68141 : scf_env%iter_count, TRIM(scf_env%iter_method), scf_env%iter_param, &
552 136282 : t2 - t1, scf_env%iter_delta, energy%total, energy%total - energy%tot_old
553 : END IF
554 : END IF
555 : END IF
556 :
557 148941 : END SUBROUTINE qs_scf_loop_info
558 :
559 : ! **************************************************************************************************
560 : !> \brief writes rather detailed summary of densities and energies
561 : !> after the SCF
562 : !> \param output_unit ...
563 : !> \param rho ...
564 : !> \param qs_charges ...
565 : !> \param energy ...
566 : !> \param nelectron_total ...
567 : !> \param dft_control ...
568 : !> \param qmmm ...
569 : !> \param qs_env ...
570 : !> \param gapw ...
571 : !> \param gapw_xc ...
572 : !> \par History
573 : !> 03.2006 created [Joost VandeVondele]
574 : !> 10.2019 print dipole moment [SGh]
575 : !> 11.2022 print SCCS results [MK]
576 : ! **************************************************************************************************
577 18814 : SUBROUTINE qs_scf_print_scf_summary(output_unit, rho, qs_charges, energy, nelectron_total, &
578 : dft_control, qmmm, qs_env, gapw, gapw_xc)
579 : INTEGER, INTENT(IN) :: output_unit
580 : TYPE(qs_rho_type), POINTER :: rho
581 : TYPE(qs_charges_type), POINTER :: qs_charges
582 : TYPE(qs_energy_type), POINTER :: energy
583 : INTEGER, INTENT(IN) :: nelectron_total
584 : TYPE(dft_control_type), POINTER :: dft_control
585 : LOGICAL, INTENT(IN) :: qmmm
586 : TYPE(qs_environment_type), POINTER :: qs_env
587 : LOGICAL, INTENT(IN) :: gapw, gapw_xc
588 :
589 : CHARACTER(LEN=*), PARAMETER :: routineN = 'qs_scf_print_scf_summary'
590 :
591 : INTEGER :: bc, handle, ispin, psolver
592 : REAL(kind=dp) :: exc1_energy, exc_energy, &
593 : implicit_ps_ehartree, tot1_h, tot1_s
594 18814 : REAL(KIND=dp), DIMENSION(:), POINTER :: tot_rho_r
595 : TYPE(pw_env_type), POINTER :: pw_env
596 :
597 18814 : NULLIFY (tot_rho_r, pw_env)
598 18814 : CALL timeset(routineN, handle)
599 :
600 18814 : CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
601 18814 : psolver = pw_env%poisson_env%parameters%solver
602 :
603 18814 : IF (output_unit > 0) THEN
604 9596 : CALL qs_rho_get(rho, tot_rho_r=tot_rho_r)
605 9596 : IF (.NOT. (dft_control%qs_control%semi_empirical .OR. &
606 : dft_control%qs_control%xtb .OR. &
607 : dft_control%qs_control%dftb)) THEN
608 : WRITE (UNIT=output_unit, FMT="(/,(T3,A,T41,2F20.10))") &
609 5263 : "Electronic density on regular grids: ", &
610 5263 : accurate_sum(tot_rho_r), &
611 5263 : accurate_sum(tot_rho_r) + nelectron_total, &
612 5263 : "Core density on regular grids:", &
613 5263 : qs_charges%total_rho_core_rspace, &
614 10526 : qs_charges%total_rho_core_rspace - REAL(nelectron_total + dft_control%charge, dp)
615 :
616 5263 : IF (dft_control%correct_surf_dip) THEN
617 : WRITE (UNIT=output_unit, FMT="((T3,A,/,T3,A,T41,F20.10))") &
618 5 : "Total dipole moment perpendicular to ", &
619 5 : "the slab [electrons-Angstroem]: ", &
620 10 : qs_env%surface_dipole_moment
621 : END IF
622 :
623 5263 : IF (gapw) THEN
624 757 : tot1_h = qs_charges%total_rho1_hard(1)
625 757 : tot1_s = qs_charges%total_rho1_soft(1)
626 954 : DO ispin = 2, dft_control%nspins
627 197 : tot1_h = tot1_h + qs_charges%total_rho1_hard(ispin)
628 954 : tot1_s = tot1_s + qs_charges%total_rho1_soft(ispin)
629 : END DO
630 : WRITE (UNIT=output_unit, FMT="((T3,A,T41,2F20.10))") &
631 757 : "Hard and soft densities (Lebedev):", &
632 1514 : tot1_h, tot1_s
633 : WRITE (UNIT=output_unit, FMT="(T3,A,T41,F20.10)") &
634 757 : "Total Rho_soft + Rho1_hard - Rho1_soft (r-space): ", &
635 757 : accurate_sum(tot_rho_r) + tot1_h - tot1_s, &
636 757 : "Total charge density (r-space): ", &
637 : accurate_sum(tot_rho_r) + tot1_h - tot1_s &
638 757 : + qs_charges%total_rho_core_rspace, &
639 757 : "Total Rho_soft + Rho0_soft (g-space):", &
640 1514 : qs_charges%total_rho_gspace
641 : ELSE
642 : WRITE (UNIT=output_unit, FMT="(T3,A,T41,F20.10)") &
643 4506 : "Total charge density on r-space grids: ", &
644 : accurate_sum(tot_rho_r) + &
645 4506 : qs_charges%total_rho_core_rspace, &
646 4506 : "Total charge density g-space grids: ", &
647 9012 : qs_charges%total_rho_gspace
648 : END IF
649 : END IF
650 9596 : IF (dft_control%qs_control%semi_empirical) THEN
651 : WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
652 1963 : "Core-core repulsion energy [eV]: ", energy%core_overlap*evolt, &
653 1963 : "Core Hamiltonian energy [eV]: ", energy%core*evolt, &
654 1963 : "Two-electron integral energy [eV]: ", energy%hartree*evolt, &
655 1963 : "Electronic energy [eV]: ", &
656 3926 : (energy%core + 0.5_dp*energy%hartree)*evolt
657 1963 : IF (energy%dispersion /= 0.0_dp) &
658 : WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
659 8 : "Dispersion energy [eV]: ", energy%dispersion*evolt
660 7633 : ELSEIF (dft_control%qs_control%dftb) THEN
661 : WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
662 970 : "Core Hamiltonian energy: ", energy%core, &
663 970 : "Repulsive potential energy: ", energy%repulsive, &
664 970 : "Electronic energy: ", energy%hartree, &
665 1940 : "Dispersion energy: ", energy%dispersion
666 970 : IF (energy%dftb3 /= 0.0_dp) &
667 : WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
668 136 : "DFTB3 3rd order energy: ", energy%dftb3
669 970 : IF (energy%efield /= 0.0_dp) &
670 : WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
671 16 : "Electric field interaction energy: ", energy%efield
672 6663 : ELSEIF (dft_control%qs_control%xtb) THEN
673 : WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
674 1400 : "Core Hamiltonian energy: ", energy%core, &
675 1400 : "Repulsive potential energy: ", energy%repulsive, &
676 1400 : "Electronic energy: ", energy%hartree, &
677 1400 : "DFTB3 3rd order energy: ", energy%dftb3, &
678 2800 : "Dispersion energy: ", energy%dispersion
679 1400 : IF (dft_control%qs_control%xtb_control%xb_interaction) &
680 : WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
681 1400 : "Correction for halogen bonding: ", energy%xtb_xb_inter
682 1400 : IF (dft_control%qs_control%xtb_control%do_nonbonded) &
683 : WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
684 12 : "Correction for nonbonded interactions: ", energy%xtb_nonbonded
685 1400 : IF (energy%efield /= 0.0_dp) &
686 : WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
687 309 : "Electric field interaction energy: ", energy%efield
688 : ELSE
689 5263 : IF (dft_control%do_admm) THEN
690 435 : exc_energy = energy%exc + energy%exc_aux_fit
691 435 : IF (gapw .OR. gapw_xc) exc1_energy = energy%exc1 + energy%exc1_aux_fit
692 : ELSE
693 4828 : exc_energy = energy%exc
694 4828 : IF (gapw .OR. gapw_xc) exc1_energy = energy%exc1
695 : END IF
696 :
697 5263 : IF (psolver .EQ. pw_poisson_implicit) THEN
698 61 : implicit_ps_ehartree = pw_env%poisson_env%implicit_env%ehartree
699 61 : bc = pw_env%poisson_env%parameters%ps_implicit_params%boundary_condition
700 42 : SELECT CASE (bc)
701 : CASE (MIXED_PERIODIC_BC, MIXED_BC)
702 : WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
703 42 : "Overlap energy of the core charge distribution:", energy%core_overlap, &
704 42 : "Self energy of the core charge distribution: ", energy%core_self, &
705 42 : "Core Hamiltonian energy: ", energy%core, &
706 42 : "Hartree energy: ", implicit_ps_ehartree, &
707 42 : "Electric enthalpy: ", energy%hartree, &
708 84 : "Exchange-correlation energy: ", exc_energy
709 : CASE (PERIODIC_BC, NEUMANN_BC)
710 : WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
711 19 : "Overlap energy of the core charge distribution:", energy%core_overlap, &
712 19 : "Self energy of the core charge distribution: ", energy%core_self, &
713 19 : "Core Hamiltonian energy: ", energy%core, &
714 19 : "Hartree energy: ", energy%hartree, &
715 80 : "Exchange-correlation energy: ", exc_energy
716 : END SELECT
717 : ELSE
718 : WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
719 5202 : "Overlap energy of the core charge distribution:", energy%core_overlap, &
720 5202 : "Self energy of the core charge distribution: ", energy%core_self, &
721 5202 : "Core Hamiltonian energy: ", energy%core, &
722 5202 : "Hartree energy: ", energy%hartree, &
723 10404 : "Exchange-correlation energy: ", exc_energy
724 : END IF
725 5263 : IF (energy%e_hartree /= 0.0_dp) &
726 : WRITE (UNIT=output_unit, FMT="(T3,A,/,T3,A,T56,F25.14)") &
727 44 : "Coulomb Electron-Electron Interaction Energy ", &
728 88 : "- Already included in the total Hartree term ", energy%e_hartree
729 5263 : IF (energy%ex /= 0.0_dp) &
730 : WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
731 1021 : "Hartree-Fock Exchange energy: ", energy%ex
732 5263 : IF (energy%dispersion /= 0.0_dp) &
733 : WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
734 132 : "Dispersion energy: ", energy%dispersion
735 5263 : IF (energy%gcp /= 0.0_dp) &
736 : WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
737 0 : "gCP energy: ", energy%gcp
738 5263 : IF (energy%efield /= 0.0_dp) &
739 : WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
740 353 : "Electric field interaction energy: ", energy%efield
741 5263 : IF (gapw) THEN
742 : WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
743 757 : "GAPW| Exc from hard and soft atomic rho1: ", exc1_energy, &
744 1514 : "GAPW| local Eh = 1 center integrals: ", energy%hartree_1c
745 : END IF
746 5263 : IF (gapw_xc) THEN
747 : WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
748 137 : "GAPW_XC| Exc from hard and soft atomic rho1: ", exc1_energy
749 : END IF
750 : END IF
751 9596 : IF (dft_control%smear) THEN
752 : WRITE (UNIT=output_unit, FMT="((T3,A,T56,F25.14))") &
753 236 : "Electronic entropic energy:", energy%kTS
754 : WRITE (UNIT=output_unit, FMT="((T3,A,T56,F25.14))") &
755 236 : "Fermi energy:", energy%efermi
756 : END IF
757 9596 : IF (dft_control%dft_plus_u) THEN
758 : WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
759 48 : "DFT+U energy:", energy%dft_plus_u
760 : END IF
761 9596 : IF (dft_control%do_sccs) THEN
762 6 : WRITE (UNIT=output_unit, FMT="(A)") ""
763 6 : CALL print_sccs_results(energy, dft_control%sccs_control, output_unit)
764 : END IF
765 9596 : IF (qmmm) THEN
766 : WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
767 1914 : "QM/MM Electrostatic energy: ", energy%qmmm_el
768 1914 : IF (qs_env%qmmm_env_qm%image_charge) THEN
769 : WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
770 10 : "QM/MM image charge energy: ", energy%image_charge
771 : END IF
772 : END IF
773 9596 : IF (dft_control%qs_control%mulliken_restraint) THEN
774 : WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
775 3 : "Mulliken restraint energy: ", energy%mulliken
776 : END IF
777 9596 : IF (dft_control%qs_control%semi_empirical) THEN
778 : WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
779 1963 : "Total energy [eV]: ", energy%total*evolt
780 : WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
781 1963 : "Atomic reference energy [eV]: ", energy%core_self*evolt, &
782 1963 : "Heat of formation [kcal/mol]: ", &
783 3926 : (energy%total + energy%core_self)*kcalmol
784 : ELSE
785 : WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
786 7633 : "Total energy: ", energy%total
787 : END IF
788 9596 : IF (qmmm) THEN
789 1914 : IF (qs_env%qmmm_env_qm%image_charge) THEN
790 10 : CALL print_image_coefficients(qs_env%image_coeff, qs_env)
791 : END IF
792 : END IF
793 9596 : CALL m_flush(output_unit)
794 : END IF
795 :
796 18814 : CALL timestop(handle)
797 :
798 18814 : END SUBROUTINE qs_scf_print_scf_summary
799 :
800 : ! **************************************************************************************************
801 : !> \brief collects the 'heavy duty' printing tasks out of the SCF loop
802 : !> \param qs_env ...
803 : !> \param scf_env ...
804 : !> \param para_env ...
805 : !> \par History
806 : !> 03.2006 created [Joost VandeVondele]
807 : ! **************************************************************************************************
808 448551 : SUBROUTINE qs_scf_loop_print(qs_env, scf_env, para_env)
809 : TYPE(qs_environment_type), POINTER :: qs_env
810 : TYPE(qs_scf_env_type), POINTER :: scf_env
811 : TYPE(mp_para_env_type), POINTER :: para_env
812 :
813 : CHARACTER(LEN=*), PARAMETER :: routineN = 'qs_scf_loop_print'
814 :
815 : INTEGER :: after, handle, ic, ispin, iw
816 : LOGICAL :: do_kpoints, omit_headers
817 : REAL(KIND=dp) :: mo_mag_max, mo_mag_min, orthonormality
818 : TYPE(cp_logger_type), POINTER :: logger
819 149517 : TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks, matrix_p, matrix_s
820 : TYPE(dft_control_type), POINTER :: dft_control
821 149517 : TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
822 : TYPE(qs_rho_type), POINTER :: rho
823 : TYPE(section_vals_type), POINTER :: dft_section, input, scf_section
824 :
825 299034 : logger => cp_get_default_logger()
826 149517 : CALL timeset(routineN, handle)
827 :
828 : CALL get_qs_env(qs_env=qs_env, input=input, dft_control=dft_control, &
829 149517 : do_kpoints=do_kpoints)
830 :
831 149517 : dft_section => section_vals_get_subs_vals(input, "DFT")
832 149517 : scf_section => section_vals_get_subs_vals(dft_section, "SCF")
833 :
834 149517 : CALL section_vals_val_get(input, "DFT%PRINT%AO_MATRICES%OMIT_HEADERS", l_val=omit_headers)
835 320730 : DO ispin = 1, dft_control%nspins
836 :
837 171213 : IF (BTEST(cp_print_key_should_output(logger%iter_info, &
838 : dft_section, "PRINT%AO_MATRICES/DENSITY"), cp_p_file)) THEN
839 5562 : CALL get_qs_env(qs_env, rho=rho)
840 5562 : CALL qs_rho_get(rho, rho_ao_kp=matrix_p)
841 : iw = cp_print_key_unit_nr(logger, dft_section, "PRINT%AO_MATRICES/DENSITY", &
842 5562 : extension=".Log")
843 5562 : CALL section_vals_val_get(dft_section, "PRINT%AO_MATRICES%NDIGITS", i_val=after)
844 5562 : after = MIN(MAX(after, 1), 16)
845 11124 : DO ic = 1, SIZE(matrix_p, 2)
846 : CALL cp_dbcsr_write_sparse_matrix(matrix_p(ispin, ic)%matrix, 4, after, qs_env, para_env, &
847 11124 : output_unit=iw, omit_headers=omit_headers)
848 : END DO
849 : CALL cp_print_key_finished_output(iw, logger, dft_section, &
850 5562 : "PRINT%AO_MATRICES/DENSITY")
851 : END IF
852 :
853 171213 : IF (BTEST(cp_print_key_should_output(logger%iter_info, &
854 149517 : dft_section, "PRINT%AO_MATRICES/KOHN_SHAM_MATRIX"), cp_p_file)) THEN
855 : iw = cp_print_key_unit_nr(logger, dft_section, "PRINT%AO_MATRICES/KOHN_SHAM_MATRIX", &
856 4436 : extension=".Log")
857 4436 : CALL section_vals_val_get(dft_section, "PRINT%AO_MATRICES%NDIGITS", i_val=after)
858 4436 : after = MIN(MAX(after, 1), 16)
859 4436 : CALL get_qs_env(qs_env=qs_env, matrix_ks_kp=matrix_ks)
860 8872 : DO ic = 1, SIZE(matrix_ks, 2)
861 8872 : IF (dft_control%qs_control%semi_empirical) THEN
862 : CALL cp_dbcsr_write_sparse_matrix(matrix_ks(ispin, ic)%matrix, 4, after, qs_env, para_env, &
863 4432 : scale=evolt, output_unit=iw, omit_headers=omit_headers)
864 : ELSE
865 : CALL cp_dbcsr_write_sparse_matrix(matrix_ks(ispin, ic)%matrix, 4, after, qs_env, para_env, &
866 4 : output_unit=iw, omit_headers=omit_headers)
867 : END IF
868 : END DO
869 : CALL cp_print_key_finished_output(iw, logger, dft_section, &
870 4436 : "PRINT%AO_MATRICES/KOHN_SHAM_MATRIX")
871 : END IF
872 :
873 : END DO
874 :
875 149517 : IF (BTEST(cp_print_key_should_output(logger%iter_info, &
876 : scf_section, "PRINT%MO_ORTHONORMALITY"), cp_p_file)) THEN
877 856 : IF (do_kpoints) THEN
878 : iw = cp_print_key_unit_nr(logger, scf_section, "PRINT%MO_ORTHONORMALITY", &
879 4 : extension=".scfLog")
880 4 : IF (iw > 0) THEN
881 : WRITE (iw, '(T8,A)') &
882 2 : " K-points: Maximum deviation from MO S-orthonormality not determined"
883 : END IF
884 : CALL cp_print_key_finished_output(iw, logger, scf_section, &
885 4 : "PRINT%MO_ORTHONORMALITY")
886 : ELSE
887 852 : CALL get_qs_env(qs_env, mos=mos)
888 852 : IF (scf_env%method == special_diag_method_nr) THEN
889 58 : CALL calculate_orthonormality(orthonormality, mos)
890 : ELSE
891 794 : CALL get_qs_env(qs_env=qs_env, matrix_s_kp=matrix_s)
892 794 : CALL calculate_orthonormality(orthonormality, mos, matrix_s(1, 1)%matrix)
893 : END IF
894 : iw = cp_print_key_unit_nr(logger, scf_section, "PRINT%MO_ORTHONORMALITY", &
895 852 : extension=".scfLog")
896 852 : IF (iw > 0) THEN
897 : WRITE (iw, '(T8,A,T61,E20.4)') &
898 426 : " Maximum deviation from MO S-orthonormality", orthonormality
899 : END IF
900 : CALL cp_print_key_finished_output(iw, logger, scf_section, &
901 852 : "PRINT%MO_ORTHONORMALITY")
902 : END IF
903 : END IF
904 149517 : IF (BTEST(cp_print_key_should_output(logger%iter_info, &
905 : scf_section, "PRINT%MO_MAGNITUDE"), cp_p_file)) THEN
906 856 : IF (do_kpoints) THEN
907 : iw = cp_print_key_unit_nr(logger, scf_section, "PRINT%MO_MAGNITUDE", &
908 4 : extension=".scfLog")
909 4 : IF (iw > 0) THEN
910 : WRITE (iw, '(T8,A)') &
911 2 : " K-points: Minimum/Maximum MO magnitude not determined"
912 : END IF
913 : CALL cp_print_key_finished_output(iw, logger, scf_section, &
914 4 : "PRINT%MO_MAGNITUDE")
915 : ELSE
916 852 : CALL get_qs_env(qs_env, mos=mos)
917 852 : CALL calculate_magnitude(mos, mo_mag_min, mo_mag_max)
918 : iw = cp_print_key_unit_nr(logger, scf_section, "PRINT%MO_MAGNITUDE", &
919 852 : extension=".scfLog")
920 852 : IF (iw > 0) THEN
921 : WRITE (iw, '(T8,A,T41,2E20.4)') &
922 426 : " Minimum/Maximum MO magnitude ", mo_mag_min, mo_mag_max
923 : END IF
924 : CALL cp_print_key_finished_output(iw, logger, scf_section, &
925 852 : "PRINT%MO_MAGNITUDE")
926 : END IF
927 : END IF
928 :
929 149517 : CALL timestop(handle)
930 :
931 149517 : END SUBROUTINE qs_scf_loop_print
932 :
933 : ! **************************************************************************************************
934 : !> \brief writes CDFT constraint information and optionally CDFT scf loop info
935 : !> \param output_unit where to write the information
936 : !> \param scf_control settings of the SCF loop
937 : !> \param scf_env the env which holds convergence data
938 : !> \param cdft_control the env which holds information about the constraint
939 : !> \param energy the total energy
940 : !> \param total_steps the total number of performed SCF iterations
941 : !> \param should_stop if the calculation should stop
942 : !> \param outer_loop_converged logical which determines if the CDFT SCF loop converged
943 : !> \param cdft_loop logical which determines a CDFT SCF loop is active
944 : !> \par History
945 : !> 12.2015 created [Nico Holmberg]
946 : ! **************************************************************************************************
947 626 : SUBROUTINE qs_scf_cdft_info(output_unit, scf_control, scf_env, cdft_control, &
948 : energy, total_steps, should_stop, outer_loop_converged, &
949 : cdft_loop)
950 : INTEGER :: output_unit
951 : TYPE(scf_control_type), POINTER :: scf_control
952 : TYPE(qs_scf_env_type), POINTER :: scf_env
953 : TYPE(cdft_control_type), POINTER :: cdft_control
954 : TYPE(qs_energy_type), POINTER :: energy
955 : INTEGER :: total_steps
956 : LOGICAL, INTENT(IN) :: should_stop, outer_loop_converged, &
957 : cdft_loop
958 :
959 : REAL(KIND=dp) :: outer_loop_eps
960 :
961 626 : IF (cdft_loop) THEN
962 1622 : outer_loop_eps = SQRT(MAXVAL(scf_env%outer_scf%gradient(:, scf_env%outer_scf%iter_count)**2))
963 512 : IF (output_unit > 0) WRITE (output_unit, '(/,T3,A,I4,A,E10.2,A,F22.10)') &
964 274 : "CDFT SCF iter = ", scf_env%outer_scf%iter_count, &
965 548 : " RMS gradient = ", outer_loop_eps, " energy =", energy%total
966 512 : IF (outer_loop_converged) THEN
967 270 : IF (output_unit > 0) WRITE (output_unit, '(T3,A,I4,A,I4,A,/)') &
968 153 : "CDFT SCF loop converged in", scf_env%outer_scf%iter_count, &
969 306 : " iterations or ", total_steps, " steps"
970 : END IF
971 : IF ((scf_env%outer_scf%iter_count > scf_control%outer_scf%max_scf .OR. should_stop) &
972 512 : .AND. .NOT. outer_loop_converged) THEN
973 56 : IF (output_unit > 0) WRITE (output_unit, '(T3,A,I4,A,I4,A,/)') &
974 28 : "CDFT SCF loop FAILED to converge after ", &
975 56 : scf_env%outer_scf%iter_count, " iterations or ", total_steps, " steps"
976 : END IF
977 : END IF
978 626 : CALL qs_scf_cdft_constraint_info(output_unit, cdft_control)
979 :
980 626 : END SUBROUTINE qs_scf_cdft_info
981 :
982 : ! **************************************************************************************************
983 : !> \brief writes information about the CDFT env
984 : !> \param output_unit where to write the information
985 : !> \param cdft_control the CDFT env that stores information about the constraint calculation
986 : !> \par History
987 : !> 12.2015 created [Nico Holmberg]
988 : ! **************************************************************************************************
989 181 : SUBROUTINE qs_scf_cdft_initial_info(output_unit, cdft_control)
990 : INTEGER :: output_unit
991 : TYPE(cdft_control_type), POINTER :: cdft_control
992 :
993 181 : IF (output_unit > 0) THEN
994 : WRITE (output_unit, '(/,A)') &
995 181 : " ---------------------------------- CDFT --------------------------------------"
996 : WRITE (output_unit, '(A)') &
997 181 : " Optimizing a density constraint in an external SCF loop "
998 181 : WRITE (output_unit, '(A)') " "
999 196 : SELECT CASE (cdft_control%type)
1000 : CASE (outer_scf_hirshfeld_constraint)
1001 15 : WRITE (output_unit, '(A)') " Type of constraint: Hirshfeld"
1002 : CASE (outer_scf_becke_constraint)
1003 181 : WRITE (output_unit, '(A)') " Type of constraint: Becke"
1004 : END SELECT
1005 181 : WRITE (output_unit, '(A,I8)') " Number of constraints: ", SIZE(cdft_control%group)
1006 181 : WRITE (output_unit, '(A,L8)') " Using fragment densities:", cdft_control%fragment_density
1007 181 : WRITE (output_unit, '(A)') " "
1008 181 : IF (cdft_control%atomic_charges) WRITE (output_unit, '(A,/)') " Calculating atomic CDFT charges"
1009 181 : SELECT CASE (cdft_control%constraint_control%optimizer)
1010 : CASE (outer_scf_optimizer_sd)
1011 : WRITE (output_unit, '(A)') &
1012 0 : " Minimizer : SD : steepest descent"
1013 : CASE (outer_scf_optimizer_diis)
1014 : WRITE (output_unit, '(A)') &
1015 5 : " Minimizer : DIIS : direct inversion"
1016 : WRITE (output_unit, '(A)') &
1017 5 : " in the iterative subspace"
1018 : WRITE (output_unit, '(A,I3,A)') &
1019 5 : " using ", &
1020 10 : cdft_control%constraint_control%diis_buffer_length, " DIIS vectors"
1021 : CASE (outer_scf_optimizer_bisect)
1022 : WRITE (output_unit, '(A)') &
1023 115 : " Minimizer : BISECT : gradient bisection"
1024 : WRITE (output_unit, '(A,I3)') &
1025 115 : " using a trust count of", &
1026 230 : cdft_control%constraint_control%bisect_trust_count
1027 : CASE (outer_scf_optimizer_broyden, outer_scf_optimizer_newton, &
1028 : outer_scf_optimizer_newton_ls)
1029 : CALL cdft_opt_type_write(cdft_control%constraint_control%cdft_opt_control, &
1030 60 : cdft_control%constraint_control%optimizer, output_unit)
1031 : CASE (outer_scf_optimizer_secant)
1032 1 : WRITE (output_unit, '(A)') " Minimizer : Secant"
1033 : CASE DEFAULT
1034 181 : CPABORT("")
1035 : END SELECT
1036 : WRITE (output_unit, '(/,A,L7)') &
1037 181 : " Reusing OT preconditioner: ", cdft_control%reuse_precond
1038 181 : IF (cdft_control%reuse_precond) THEN
1039 : WRITE (output_unit, '(A,I3,A,I3,A)') &
1040 0 : " using old preconditioner for up to ", &
1041 0 : cdft_control%max_reuse, " subsequent CDFT SCF"
1042 : WRITE (output_unit, '(A,I3,A,I3,A)') &
1043 0 : " iterations if the relevant loop converged in less than ", &
1044 0 : cdft_control%precond_freq, " steps"
1045 : END IF
1046 196 : SELECT CASE (cdft_control%type)
1047 : CASE (outer_scf_hirshfeld_constraint)
1048 15 : WRITE (output_unit, '(/,A)') " Hirshfeld constraint settings"
1049 15 : WRITE (output_unit, '(A)') " "
1050 15 : SELECT CASE (cdft_control%hirshfeld_control%shape_function)
1051 : CASE (shape_function_gaussian)
1052 : WRITE (output_unit, '(A, A8)') &
1053 13 : " Shape function type: ", "Gaussian"
1054 : WRITE (output_unit, '(A)', ADVANCE='NO') &
1055 13 : " Type of Gaussian: "
1056 13 : SELECT CASE (cdft_control%hirshfeld_control%gaussian_shape)
1057 : CASE (radius_default)
1058 2 : WRITE (output_unit, '(A13)') "Default"
1059 : CASE (radius_covalent)
1060 11 : WRITE (output_unit, '(A13)') "Covalent"
1061 : CASE (radius_single)
1062 0 : WRITE (output_unit, '(A13)') "Fixed radius"
1063 : CASE (radius_vdw)
1064 0 : WRITE (output_unit, '(A13)') "Van der Waals"
1065 : CASE (radius_user)
1066 0 : WRITE (output_unit, '(A13)') "User-defined"
1067 :
1068 : END SELECT
1069 : CASE (shape_function_density)
1070 : WRITE (output_unit, '(A, A8)') &
1071 2 : " Shape function type: ", "Density"
1072 : END SELECT
1073 : CASE (outer_scf_becke_constraint)
1074 166 : WRITE (output_unit, '(/, A)') " Becke constraint settings"
1075 166 : WRITE (output_unit, '(A)') " "
1076 166 : SELECT CASE (cdft_control%becke_control%cutoff_type)
1077 : CASE (becke_cutoff_global)
1078 : WRITE (output_unit, '(A,F8.3,A)') &
1079 97 : " Cutoff for partitioning :", cp_unit_from_cp2k(cdft_control%becke_control%rglobal, &
1080 194 : "angstrom"), " angstrom"
1081 : CASE (becke_cutoff_element)
1082 : WRITE (output_unit, '(A)') &
1083 69 : " Using element specific cutoffs for partitioning"
1084 : END SELECT
1085 : WRITE (output_unit, '(A,L7)') &
1086 166 : " Skipping distant gpoints: ", cdft_control%becke_control%should_skip
1087 : WRITE (output_unit, '(A,L7)') &
1088 166 : " Precompute gradients : ", cdft_control%becke_control%in_memory
1089 166 : WRITE (output_unit, '(A)') " "
1090 166 : IF (cdft_control%becke_control%adjust) &
1091 : WRITE (output_unit, '(A)') &
1092 110 : " Using atomic radii to generate a heteronuclear charge partitioning"
1093 166 : WRITE (output_unit, '(A)') " "
1094 347 : IF (.NOT. cdft_control%becke_control%cavity_confine) THEN
1095 : WRITE (output_unit, '(A)') &
1096 9 : " No confinement is active"
1097 : ELSE
1098 157 : WRITE (output_unit, '(A)') " Confinement using a Gaussian shaped cavity is active"
1099 157 : SELECT CASE (cdft_control%becke_control%cavity_shape)
1100 : CASE (radius_single)
1101 : WRITE (output_unit, '(A,F8.4, A)') &
1102 1 : " Type of Gaussian : Fixed radius: ", &
1103 2 : cp_unit_from_cp2k(cdft_control%becke_control%rcavity, "angstrom"), " angstrom"
1104 : CASE (radius_covalent)
1105 : WRITE (output_unit, '(A)') &
1106 1 : " Type of Gaussian : Covalent radius "
1107 : CASE (radius_vdw)
1108 : WRITE (output_unit, '(A)') &
1109 154 : " Type of Gaussian : vdW radius "
1110 : CASE (radius_user)
1111 : WRITE (output_unit, '(A)') &
1112 1 : " Type of Gaussian : User radius "
1113 : END SELECT
1114 : WRITE (output_unit, '(A,ES12.4)') &
1115 157 : " Cavity threshold : ", cdft_control%becke_control%eps_cavity
1116 : END IF
1117 : END SELECT
1118 : WRITE (output_unit, '(/,A)') &
1119 181 : " ---------------------------------- CDFT --------------------------------------"
1120 : END IF
1121 :
1122 181 : END SUBROUTINE qs_scf_cdft_initial_info
1123 :
1124 : ! **************************************************************************************************
1125 : !> \brief writes CDFT constraint information
1126 : !> \param output_unit where to write the information
1127 : !> \param cdft_control the env which holds information about the constraint
1128 : !> \par History
1129 : !> 08.2018 separated from qs_scf_cdft_info to make code callable elsewhere [Nico Holmberg]
1130 : ! **************************************************************************************************
1131 3660 : SUBROUTINE qs_scf_cdft_constraint_info(output_unit, cdft_control)
1132 : INTEGER :: output_unit
1133 : TYPE(cdft_control_type), POINTER :: cdft_control
1134 :
1135 : INTEGER :: igroup
1136 :
1137 3660 : IF (output_unit > 0) THEN
1138 1955 : SELECT CASE (cdft_control%type)
1139 : CASE (outer_scf_hirshfeld_constraint)
1140 : WRITE (output_unit, '(/,T3,A,T60)') &
1141 61 : '------------------- Hirshfeld constraint information -------------------'
1142 : CASE (outer_scf_becke_constraint)
1143 : WRITE (output_unit, '(/,T3,A,T60)') &
1144 1833 : '--------------------- Becke constraint information ---------------------'
1145 : CASE DEFAULT
1146 1894 : CPABORT("Unknown CDFT constraint.")
1147 : END SELECT
1148 4343 : DO igroup = 1, SIZE(cdft_control%target)
1149 2449 : IF (igroup > 1) WRITE (output_unit, '(T3,A)') ' '
1150 : WRITE (output_unit, '(T3,A,T54,(3X,I18))') &
1151 2449 : 'Atomic group :', igroup
1152 3788 : SELECT CASE (cdft_control%group(igroup)%constraint_type)
1153 : CASE (cdft_charge_constraint)
1154 1339 : IF (cdft_control%group(igroup)%is_fragment_constraint) THEN
1155 : WRITE (output_unit, '(T3,A,T42,A)') &
1156 6 : 'Type of constraint :', ADJUSTR('Charge density constraint (frag.)')
1157 : ELSE
1158 : WRITE (output_unit, '(T3,A,T50,A)') &
1159 1333 : 'Type of constraint :', ADJUSTR('Charge density constraint')
1160 : END IF
1161 : CASE (cdft_magnetization_constraint)
1162 8 : IF (cdft_control%group(igroup)%is_fragment_constraint) THEN
1163 : WRITE (output_unit, '(T3,A,T35,A)') &
1164 6 : 'Type of constraint :', ADJUSTR('Magnetization density constraint (frag.)')
1165 : ELSE
1166 : WRITE (output_unit, '(T3,A,T43,A)') &
1167 2 : 'Type of constraint :', ADJUSTR('Magnetization density constraint')
1168 : END IF
1169 : CASE (cdft_alpha_constraint)
1170 551 : IF (cdft_control%group(igroup)%is_fragment_constraint) THEN
1171 : WRITE (output_unit, '(T3,A,T38,A)') &
1172 0 : 'Type of constraint :', ADJUSTR('Alpha spin density constraint (frag.)')
1173 : ELSE
1174 : WRITE (output_unit, '(T3,A,T46,A)') &
1175 551 : 'Type of constraint :', ADJUSTR('Alpha spin density constraint')
1176 : END IF
1177 : CASE (cdft_beta_constraint)
1178 551 : IF (cdft_control%group(igroup)%is_fragment_constraint) THEN
1179 : WRITE (output_unit, '(T3,A,T39,A)') &
1180 0 : 'Type of constraint :', ADJUSTR('Beta spin density constraint (frag.)')
1181 : ELSE
1182 : WRITE (output_unit, '(T3,A,T47,A)') &
1183 551 : 'Type of constraint :', ADJUSTR('Beta spin density constraint')
1184 : END IF
1185 : CASE DEFAULT
1186 2449 : CPABORT("Unknown constraint type.")
1187 : END SELECT
1188 : WRITE (output_unit, '(T3,A,T54,(3X,F18.12))') &
1189 2449 : 'Target value of constraint :', cdft_control%target(igroup)
1190 : WRITE (output_unit, '(T3,A,T54,(3X,F18.12))') &
1191 2449 : 'Current value of constraint :', cdft_control%value(igroup)
1192 : WRITE (output_unit, '(T3,A,T59,(3X,ES13.3))') &
1193 2449 : 'Deviation from target :', cdft_control%value(igroup) - cdft_control%target(igroup)
1194 : WRITE (output_unit, '(T3,A,T54,(3X,F18.12))') &
1195 4343 : 'Strength of constraint :', cdft_control%strength(igroup)
1196 : END DO
1197 : WRITE (output_unit, '(T3,A)') &
1198 1894 : '------------------------------------------------------------------------'
1199 : END IF
1200 :
1201 3660 : END SUBROUTINE qs_scf_cdft_constraint_info
1202 :
1203 : END MODULE qs_scf_output
|