LCOV - code coverage report
Current view: top level - src - qs_scf_output.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:2c0d679) Lines: 92.9 % 563 523
Test Date: 2026-09-25 00:58:37 Functions: 100.0 % 11 11

            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              : 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 cp_blacs_env,                    ONLY: cp_blacs_env_type
      13              :    USE cp_control_types,                ONLY: dft_control_type
      14              :    USE cp_dbcsr_api,                    ONLY: dbcsr_p_type,&
      15              :                                               dbcsr_type
      16              :    USE cp_dbcsr_output,                 ONLY: cp_dbcsr_write_sparse_matrix
      17              :    USE cp_fm_struct,                    ONLY: cp_fm_struct_create,&
      18              :                                               cp_fm_struct_release,&
      19              :                                               cp_fm_struct_type
      20              :    USE cp_fm_types,                     ONLY: cp_fm_init_random,&
      21              :                                               cp_fm_type
      22              :    USE cp_log_handling,                 ONLY: cp_get_default_logger,&
      23              :                                               cp_logger_type
      24              :    USE cp_output_handling,              ONLY: cp_p_file,&
      25              :                                               cp_print_key_finished_output,&
      26              :                                               cp_print_key_should_output,&
      27              :                                               cp_print_key_unit_nr
      28              :    USE cp_units,                        ONLY: cp_unit_from_cp2k
      29              :    USE input_constants,                 ONLY: &
      30              :         becke_cutoff_element, becke_cutoff_global, cdft_alpha_constraint, cdft_beta_constraint, &
      31              :         cdft_charge_constraint, cdft_magnetization_constraint, ot_precond_full_all, &
      32              :         ot_precond_full_all_covariant, outer_scf_becke_constraint, outer_scf_hirshfeld_constraint, &
      33              :         outer_scf_optimizer_bisect, outer_scf_optimizer_broyden, outer_scf_optimizer_diis, &
      34              :         outer_scf_optimizer_newton, outer_scf_optimizer_newton_ls, outer_scf_optimizer_sd, &
      35              :         outer_scf_optimizer_secant, radius_covalent, radius_default, radius_single, radius_user, &
      36              :         radius_vdw, shape_function_density, shape_function_gaussian, smear_fermi_dirac, &
      37              :         smear_gaussian, smear_mp, smear_mv
      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: get_kpoint_info,&
      46              :                                               kpoint_type
      47              :    USE machine,                         ONLY: m_flush
      48              :    USE message_passing,                 ONLY: mp_para_env_type
      49              :    USE particle_types,                  ONLY: particle_type
      50              :    USE physcon,                         ONLY: evolt,&
      51              :                                               kcalmol
      52              :    USE preconditioner_types,            ONLY: preconditioner_type
      53              :    USE ps_implicit_types,               ONLY: MIXED_BC,&
      54              :                                               MIXED_PERIODIC_BC,&
      55              :                                               NEUMANN_BC,&
      56              :                                               PERIODIC_BC
      57              :    USE pw_env_types,                    ONLY: pw_env_type
      58              :    USE pw_poisson_types,                ONLY: pw_poisson_implicit
      59              :    USE qmmm_image_charge,               ONLY: print_image_coefficients
      60              :    USE qs_cdft_opt_types,               ONLY: cdft_opt_type_write
      61              :    USE qs_cdft_types,                   ONLY: cdft_control_type
      62              :    USE qs_charges_types,                ONLY: qs_charges_type
      63              :    USE qs_energy_types,                 ONLY: qs_energy_type
      64              :    USE qs_environment_types,            ONLY: get_qs_env,&
      65              :                                               qs_environment_type
      66              :    USE qs_kind_types,                   ONLY: qs_kind_type
      67              :    USE qs_mo_io,                        ONLY: write_mo_set_to_output_unit
      68              :    USE qs_mo_methods,                   ONLY: calculate_magnitude,&
      69              :                                               calculate_orthonormality,&
      70              :                                               calculate_subspace_eigenvalues
      71              :    USE qs_mo_occupation,                ONLY: set_mo_occupation
      72              :    USE qs_mo_types,                     ONLY: allocate_mo_set,&
      73              :                                               deallocate_mo_set,&
      74              :                                               get_mo_set,&
      75              :                                               init_mo_set,&
      76              :                                               mo_set_type
      77              :    USE qs_ot_eigensolver,               ONLY: ot_eigensolver
      78              :    USE qs_rho_types,                    ONLY: qs_rho_get,&
      79              :                                               qs_rho_type
      80              :    USE qs_sccs,                         ONLY: print_sccs_results
      81              :    USE qs_scf_types,                    ONLY: ot_method_nr,&
      82              :                                               qs_scf_env_type,&
      83              :                                               special_diag_method_nr
      84              :    USE scf_control_types,               ONLY: scf_control_type
      85              : #include "./base/base_uses.f90"
      86              : 
      87              :    IMPLICIT NONE
      88              : 
      89              :    PRIVATE
      90              : 
      91              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_scf_output'
      92              : 
      93              :    PUBLIC :: qs_scf_loop_info, &
      94              :              qs_scf_print_summary, &
      95              :              qs_scf_loop_print, &
      96              :              qs_scf_outer_loop_info, &
      97              :              qs_scf_initial_info, &
      98              :              qs_scf_write_mos, &
      99              :              qs_scf_cdft_info, &
     100              :              qs_scf_cdft_initial_info, &
     101              :              qs_scf_cdft_constraint_info, &
     102              :              qs_scf_gce_info
     103              : 
     104              : CONTAINS
     105              : 
     106              : ! **************************************************************************************************
     107              : !> \brief writes a summary of information after scf
     108              : !> \param output_unit ...
     109              : !> \param qs_env ...
     110              : ! **************************************************************************************************
     111        25487 :    SUBROUTINE qs_scf_print_summary(output_unit, qs_env)
     112              :       INTEGER, INTENT(IN)                                :: output_unit
     113              :       TYPE(qs_environment_type), POINTER                 :: qs_env
     114              : 
     115              :       INTEGER                                            :: nelectron_total
     116              :       LOGICAL                                            :: gapw, gapw_xc, qmmm
     117              :       TYPE(dft_control_type), POINTER                    :: dft_control
     118              :       TYPE(qs_charges_type), POINTER                     :: qs_charges
     119              :       TYPE(qs_energy_type), POINTER                      :: energy
     120              :       TYPE(qs_rho_type), POINTER                         :: rho
     121              :       TYPE(qs_scf_env_type), POINTER                     :: scf_env
     122              : 
     123        25487 :       NULLIFY (rho, energy, dft_control, scf_env, qs_charges)
     124              :       CALL get_qs_env(qs_env=qs_env, rho=rho, energy=energy, dft_control=dft_control, &
     125        25487 :                       scf_env=scf_env, qs_charges=qs_charges)
     126              : 
     127        25487 :       gapw = dft_control%qs_control%gapw
     128        25487 :       gapw_xc = dft_control%qs_control%gapw_xc
     129        25487 :       qmmm = qs_env%qmmm
     130        25487 :       nelectron_total = scf_env%nelectron
     131              : 
     132              :       CALL qs_scf_print_scf_summary(output_unit, rho, qs_charges, energy, nelectron_total, &
     133        25487 :                                     dft_control, qmmm, qs_env, gapw, gapw_xc)
     134              : 
     135        25487 :    END SUBROUTINE qs_scf_print_summary
     136              : 
     137              : ! **************************************************************************************************
     138              : !> \brief writes basic information at the beginning of an scf run
     139              : !> \param output_unit ...
     140              : !> \param mos ...
     141              : !> \param dft_control ...
     142              : !> \param ndep ...
     143              : ! **************************************************************************************************
     144        27069 :    SUBROUTINE qs_scf_initial_info(output_unit, mos, dft_control, ndep)
     145              :       INTEGER                                            :: output_unit
     146              :       TYPE(mo_set_type), DIMENSION(:), INTENT(IN)        :: mos
     147              :       TYPE(dft_control_type), POINTER                    :: dft_control
     148              :       INTEGER, INTENT(IN)                                :: ndep
     149              : 
     150              :       CHARACTER(LEN=*), PARAMETER :: routineN = 'qs_scf_initial_info'
     151              : 
     152              :       INTEGER                                            :: handle, homo, ispin, nao, &
     153              :                                                             nelectron_spin, nmo
     154              : 
     155        27069 :       CALL timeset(routineN, handle)
     156              : 
     157        27069 :       IF (output_unit > 0) THEN
     158        29369 :          DO ispin = 1, dft_control%nspins
     159              :             CALL get_mo_set(mo_set=mos(ispin), &
     160              :                             homo=homo, &
     161              :                             nelectron=nelectron_spin, &
     162              :                             nao=nao, &
     163        15674 :                             nmo=nmo)
     164        15674 :             IF (dft_control%nspins > 1) THEN
     165         3958 :                WRITE (UNIT=output_unit, FMT="(/,T2,A,I2)") "Spin", ispin
     166              :             END IF
     167              :             WRITE (UNIT=output_unit, FMT="(/,(T2,A,T71,I10))") &
     168        15674 :                "Number of electrons:", nelectron_spin, &
     169        15674 :                "Number of occupied orbitals:", homo, &
     170        60717 :                "Number of molecular orbitals:", nmo
     171              :          END DO
     172              :          WRITE (UNIT=output_unit, FMT="(/,(T2,A,T71,I10))") &
     173        13695 :             "Number of orbital functions:", nao, &
     174        27390 :             "Number of independent orbital functions:", nao - ndep
     175              :       END IF
     176              : 
     177        27069 :       CALL timestop(handle)
     178              : 
     179        27069 :    END SUBROUTINE qs_scf_initial_info
     180              : 
     181              : ! **************************************************************************************************
     182              : !> \brief Write the MO eigenvector, eigenvalues, and occupation numbers to the output unit
     183              : !> \param qs_env ...
     184              : !> \param scf_env ...
     185              : !> \param final_mos ...
     186              : !> \par History
     187              : !>      - Revise MO printout to enable eigenvalues with OT (05.05.2021, MK)
     188              : ! **************************************************************************************************
     189      1019328 :    SUBROUTINE qs_scf_write_mos(qs_env, scf_env, final_mos)
     190              :       TYPE(qs_environment_type), POINTER                 :: qs_env
     191              :       TYPE(qs_scf_env_type), POINTER                     :: scf_env
     192              :       LOGICAL, INTENT(IN)                                :: final_mos
     193              : 
     194              :       CHARACTER(LEN=*), PARAMETER                        :: routineN = 'qs_scf_write_mos'
     195              : 
     196              :       CHARACTER(LEN=2)                                   :: solver_method
     197              :       CHARACTER(LEN=3*default_string_length)             :: message
     198              :       CHARACTER(LEN=5)                                   :: spin
     199              :       CHARACTER(LEN=default_string_length), &
     200       254832 :          DIMENSION(:), POINTER                           :: tmpstringlist
     201              :       INTEGER                                            :: handle, homo, ikp, ikp_local, ispin, iw, &
     202              :                                                             nao, nelectron, nkp, nmo, nmo_occ, &
     203              :                                                             nspin, numo
     204              :       INTEGER, DIMENSION(2)                              :: kp_range, nmos_occ
     205       254832 :       INTEGER, DIMENSION(:), POINTER                     :: mo_index_range
     206              :       LOGICAL                                            :: do_kpoints, do_printout, print_eigvals, &
     207              :                                                             print_eigvecs, print_mo_info, &
     208              :                                                             print_occup, print_occup_stats
     209              :       REAL(KIND=dp)                                      :: flexible_electron_count, maxocc, n_el_f, &
     210              :                                                             occup_stats_occ_threshold
     211       254832 :       REAL(KIND=dp), DIMENSION(:), POINTER               :: mo_eigenvalues, umo_eigenvalues
     212              :       TYPE(admm_type), POINTER                           :: admm_env
     213              :       TYPE(cp_blacs_env_type), POINTER                   :: blacs_env
     214              :       TYPE(cp_fm_struct_type), POINTER                   :: fm_struct_tmp
     215              :       TYPE(cp_fm_type), POINTER                          :: mo_coeff, umo_coeff
     216              :       TYPE(cp_logger_type), POINTER                      :: logger
     217       254832 :       TYPE(dbcsr_p_type), DIMENSION(:), POINTER          :: ks, s
     218              :       TYPE(dbcsr_type), POINTER                          :: matrix_ks, matrix_s, mo_coeff_deriv
     219              :       TYPE(dft_control_type), POINTER                    :: dft_control
     220              :       TYPE(kpoint_type), POINTER                         :: kpoints
     221       254832 :       TYPE(mo_set_type), DIMENSION(:), POINTER           :: mos
     222              :       TYPE(mo_set_type), POINTER                         :: mo_set, umo_set
     223              :       TYPE(mp_para_env_type), POINTER                    :: para_env, para_env_inter_kp
     224       254832 :       TYPE(particle_type), DIMENSION(:), POINTER         :: particle_set
     225              :       TYPE(preconditioner_type), POINTER                 :: local_preconditioner
     226              :       TYPE(qs_environment_type), POINTER                 :: cart_overlap_qs_env
     227       254832 :       TYPE(qs_kind_type), DIMENSION(:), POINTER          :: qs_kind_set
     228              :       TYPE(scf_control_type), POINTER                    :: scf_control
     229              :       TYPE(section_vals_type), POINTER                   :: dft_section, input
     230              : 
     231       254832 :       CALL timeset(routineN, handle)
     232              : 
     233       254832 :       CPASSERT(ASSOCIATED(qs_env))
     234              : 
     235              :       ! Retrieve the required information for the requested print output
     236              :       CALL get_qs_env(qs_env, &
     237              :                       blacs_env=blacs_env, &
     238              :                       dft_control=dft_control, &
     239              :                       do_kpoints=do_kpoints, &
     240              :                       input=input, &
     241              :                       qs_kind_set=qs_kind_set, &
     242              :                       para_env=para_env, &
     243              :                       particle_set=particle_set, &
     244       254832 :                       scf_control=scf_control)
     245              : 
     246              :       ! Quick return, if no printout of MO information is requested
     247       254832 :       dft_section => section_vals_get_subs_vals(input, "DFT")
     248       254832 :       CALL section_vals_val_get(dft_section, "PRINT%MO%EIGENVALUES", l_val=print_eigvals)
     249       254832 :       CALL section_vals_val_get(dft_section, "PRINT%MO%EIGENVECTORS", l_val=print_eigvecs)
     250       254832 :       CALL section_vals_val_get(dft_section, "PRINT%MO%OCCUPATION_NUMBERS", l_val=print_occup)
     251       254832 :       CALL section_vals_val_get(dft_section, "PRINT%MO%OCCUPATION_NUMBERS_STATS", c_vals=tmpstringlist)
     252              : 
     253       254832 :       print_occup_stats = .FALSE.
     254       254832 :       occup_stats_occ_threshold = 1e-6_dp
     255       254832 :       IF (SIZE(tmpstringlist) > 0) READ (tmpstringlist(1), *) print_occup_stats
     256       254832 :       IF (SIZE(tmpstringlist) > 1) THEN
     257       254824 :          READ (tmpstringlist(2), *) occup_stats_occ_threshold
     258              :       END IF
     259              : 
     260       254832 :       logger => cp_get_default_logger()
     261       254832 :       print_mo_info = (cp_print_key_should_output(logger%iter_info, dft_section, "PRINT%MO") /= 0)
     262              : 
     263       254832 :       IF ((.NOT. print_mo_info) .OR. (.NOT. (print_eigvals .OR. print_eigvecs .OR. print_occup .OR. print_occup_stats))) THEN
     264       247256 :          CALL timestop(handle)
     265       247256 :          RETURN
     266              :       END IF
     267              : 
     268         7576 :       do_printout = .TRUE.
     269         7576 :       nspin = dft_control%nspins
     270         7576 :       nmos_occ = 0
     271              : 
     272         7576 :       IF (do_kpoints) THEN
     273           22 :          CALL get_qs_env(qs_env, kpoints=kpoints)
     274           22 :          CALL get_kpoint_info(kpoints, nkp=nkp, kp_range=kp_range, para_env_inter_kp=para_env_inter_kp)
     275           22 :          CPASSERT(ASSOCIATED(para_env_inter_kp))
     276           22 :          IF (scf_env%method == ot_method_nr) THEN
     277            0 :             solver_method = "OT"
     278              :          ELSE
     279           22 :             solver_method = "TD"
     280              :          END IF
     281          612 :          DO ikp = 1, nkp
     282         1202 :             DO ispin = 1, nspin
     283              :                ! Optional MO dummies are absent when their pointers are unassociated.
     284          590 :                NULLIFY (mo_set, cart_overlap_qs_env)
     285          590 :                nmo_occ = 0
     286          590 :                IF ((ikp >= kp_range(1)) .AND. (ikp <= kp_range(2))) THEN
     287          586 :                   ikp_local = ikp - kp_range(1) + 1
     288          586 :                   mo_set => kpoints%kp_env(ikp_local)%kpoint_env%mos(1, ispin)
     289          586 :                   IF (print_occup_stats) THEN
     290            0 :                      nmo_occ = COUNT(mo_set%occupation_numbers > occup_stats_occ_threshold)
     291              :                   END IF
     292              :                END IF
     293          590 :                IF (print_occup_stats) THEN
     294            0 :                   CALL para_env_inter_kp%max(nmo_occ)
     295            0 :                   nmos_occ(ispin) = MAX(nmos_occ(ispin), nmo_occ)
     296              :                END IF
     297              :                IF ((ikp == 1) .AND. (ikp >= kp_range(1)) .AND. &
     298          590 :                    (ikp <= kp_range(2)) .AND. (ispin == 1)) THEN
     299           21 :                   cart_overlap_qs_env => qs_env
     300              :                END IF
     301         1180 :                IF (nspin > 1) THEN
     302            0 :                   SELECT CASE (ispin)
     303              :                   CASE (1)
     304            0 :                      spin = "ALPHA"
     305              :                   CASE (2)
     306            0 :                      spin = "BETA"
     307              :                   CASE DEFAULT
     308            0 :                      CPABORT("Invalid spin")
     309              :                   END SELECT
     310              :                   CALL write_mo_set_to_output_unit(mo_set, qs_kind_set, particle_set, dft_section, 4, ikp, &
     311              :                                                    final_mos=final_mos, spin=TRIM(spin), &
     312              :                                                    solver_method=solver_method, qs_env=cart_overlap_qs_env, &
     313            0 :                                                    para_env_inter_kp=para_env_inter_kp)
     314              :                ELSE
     315              :                   CALL write_mo_set_to_output_unit(mo_set, qs_kind_set, particle_set, dft_section, 4, ikp, &
     316              :                                                    final_mos=final_mos, solver_method=solver_method, &
     317          590 :                                                    qs_env=cart_overlap_qs_env, para_env_inter_kp=para_env_inter_kp)
     318              :                END IF
     319              :             END DO
     320              :          END DO
     321              :       ELSE
     322              : 
     323         7554 :          NULLIFY (fm_struct_tmp, mo_coeff, mo_coeff_deriv, mo_eigenvalues, &
     324         7554 :                   mo_set, umo_coeff, umo_eigenvalues, umo_set)
     325              : 
     326         7554 :          CALL get_qs_env(qs_env, matrix_ks=ks, matrix_s=s, mos=mos)
     327         7554 :          CPASSERT(ASSOCIATED(ks))
     328         7554 :          CPASSERT(ASSOCIATED(s))
     329         7554 :          CPASSERT(ASSOCIATED(mos))
     330              : 
     331              :          ! Prepare MO information for printout
     332        12566 :          DO ispin = 1, nspin
     333              : 
     334              :             ! Calculate MO eigenvalues and eigenvector when OT is used
     335         7980 :             IF (scf_env%method == ot_method_nr) THEN
     336              : 
     337         3190 :                solver_method = "OT"
     338              : 
     339         3190 :                IF (final_mos) THEN
     340              : 
     341          222 :                   matrix_ks => ks(ispin)%matrix
     342          222 :                   matrix_s => s(1)%matrix
     343              : 
     344              :                   ! With ADMM, we have to modify the Kohn-Sham matrix
     345          222 :                   IF (dft_control%do_admm) THEN
     346            0 :                      CALL get_qs_env(qs_env, admm_env=admm_env)
     347            0 :                      CALL admm_correct_for_eigenvalues(ispin, admm_env, matrix_ks)
     348              :                   END IF
     349              : 
     350          222 :                   mo_set => mos(ispin)
     351              :                   CALL get_mo_set(mo_set=mo_set, &
     352              :                                   mo_coeff=mo_coeff, &
     353              :                                   eigenvalues=mo_eigenvalues, &
     354              :                                   homo=homo, &
     355              :                                   maxocc=maxocc, &
     356              :                                   nelectron=nelectron, &
     357              :                                   n_el_f=n_el_f, &
     358              :                                   nao=nao, &
     359              :                                   nmo=nmo, &
     360          222 :                                   flexible_electron_count=flexible_electron_count)
     361              : 
     362          222 :                   IF (ASSOCIATED(qs_env%mo_derivs)) THEN
     363          222 :                      mo_coeff_deriv => qs_env%mo_derivs(ispin)%matrix
     364              :                   ELSE
     365            0 :                      mo_coeff_deriv => NULL()
     366              :                   END IF
     367              : 
     368              :                   ! Update the eigenvalues of the occupied orbitals
     369              :                   CALL calculate_subspace_eigenvalues(orbitals=mo_coeff, &
     370              :                                                       ks_matrix=matrix_ks, &
     371              :                                                       evals_arg=mo_eigenvalues, &
     372          222 :                                                       co_rotate_dbcsr=mo_coeff_deriv)
     373          222 :                   CALL set_mo_occupation(mo_set=mo_set)
     374              : 
     375              :                   ! Retrieve the index of the last MO for which a printout is requested
     376          222 :                   mo_index_range => section_get_ivals(dft_section, "PRINT%MO%MO_INDEX_RANGE")
     377          222 :                   CPASSERT(ASSOCIATED(mo_index_range))
     378          222 :                   IF (mo_index_range(2) < 0) THEN
     379            0 :                      numo = nao - homo
     380              :                   ELSE
     381          222 :                      numo = MIN(mo_index_range(2) - homo, nao - homo)
     382              :                   END IF
     383              : 
     384              :                   ! Calculate the unoccupied MO set (umo_set) with OT if needed
     385          222 :                   IF (numo > 0) THEN
     386              : 
     387              :                      ! Create temporary virtual MO set for printout
     388              :                      CALL cp_fm_struct_create(fm_struct_tmp, &
     389              :                                               context=blacs_env, &
     390              :                                               para_env=para_env, &
     391              :                                               nrow_global=nao, &
     392           20 :                                               ncol_global=numo)
     393           20 :                      ALLOCATE (umo_set)
     394              :                      CALL allocate_mo_set(mo_set=umo_set, &
     395              :                                           nao=nao, &
     396              :                                           nmo=numo, &
     397              :                                           nelectron=0, &
     398              :                                           n_el_f=n_el_f, &
     399              :                                           maxocc=maxocc, &
     400           20 :                                           flexible_electron_count=flexible_electron_count)
     401              :                      CALL init_mo_set(mo_set=umo_set, &
     402              :                                       fm_struct=fm_struct_tmp, &
     403           20 :                                       name="Temporary MO set (unoccupied MOs only) for printout")
     404           20 :                      CALL cp_fm_struct_release(fm_struct_tmp)
     405              :                      CALL get_mo_set(mo_set=umo_set, &
     406              :                                      mo_coeff=umo_coeff, &
     407           20 :                                      eigenvalues=umo_eigenvalues)
     408              : 
     409              :                      ! Prepare printout of the additional unoccupied MOs when OT is being employed
     410           20 :                      CALL cp_fm_init_random(umo_coeff)
     411              : 
     412              :                      ! FULL_ALL has column-dependent occupied-state weights and cannot be reused here.
     413           20 :                      NULLIFY (local_preconditioner)
     414           20 :                      IF (ASSOCIATED(scf_env%ot_preconditioner)) THEN
     415           20 :                         local_preconditioner => scf_env%ot_preconditioner(1)%preconditioner
     416           20 :                         IF (local_preconditioner%in_use == ot_precond_full_all .OR. &
     417              :                             local_preconditioner%in_use == ot_precond_full_all_covariant) THEN
     418            0 :                            NULLIFY (local_preconditioner)
     419              :                         END IF
     420              :                      END IF
     421              : 
     422              :                      ! Calculate the MO information for the request MO index range
     423              :                      CALL ot_eigensolver(matrix_h=matrix_ks, &
     424              :                                          matrix_s=matrix_s, &
     425              :                                          matrix_c_fm=umo_coeff, &
     426              :                                          matrix_orthogonal_space_fm=mo_coeff, &
     427              :                                          eps_gradient=scf_control%eps_lumos, &
     428              :                                          preconditioner=local_preconditioner, &
     429              :                                          iter_max=scf_control%max_iter_lumos, &
     430           20 :                                          size_ortho_space=nmo)
     431              : 
     432              :                      CALL calculate_subspace_eigenvalues(orbitals=umo_coeff, &
     433              :                                                          ks_matrix=matrix_ks, &
     434           20 :                                                          evals_arg=umo_eigenvalues)
     435           20 :                      CALL set_mo_occupation(mo_set=umo_set)
     436              : 
     437              :                   END IF ! numo > 0
     438              : 
     439              :                   ! With ADMM, we have to undo the modification of the Kohn-Sham matrix
     440          222 :                   IF (dft_control%do_admm) THEN
     441            0 :                      CALL admm_uncorrect_for_eigenvalues(ispin, admm_env, matrix_ks)
     442              :                   END IF
     443              : 
     444              :                ELSE
     445              : 
     446              :                   message = "The MO information is only calculated after SCF convergence "// &
     447         2968 :                             "is achieved when the orbital transformation (OT) method is used"
     448         2968 :                   CPWARN(TRIM(message))
     449         2968 :                   do_printout = .FALSE.
     450         2968 :                   EXIT
     451              : 
     452              :                END IF ! final MOs / gamma OT
     453              : 
     454              :             ELSE
     455              : 
     456         4790 :                solver_method = "TD"
     457         4790 :                mo_set => mos(ispin)
     458         4790 :                NULLIFY (umo_set)
     459              : 
     460              :             END IF ! OT is used
     461              : 
     462              :             ! Print MO information
     463         5012 :             NULLIFY (cart_overlap_qs_env)
     464         5012 :             IF (ispin == 1) cart_overlap_qs_env => qs_env
     465         5012 :             IF (nspin > 1) THEN
     466          426 :                SELECT CASE (ispin)
     467              :                CASE (1)
     468          426 :                   spin = "ALPHA"
     469              :                CASE (2)
     470          426 :                   spin = "BETA"
     471              :                CASE DEFAULT
     472          852 :                   CPABORT("Invalid spin")
     473              :                END SELECT
     474              :                CALL write_mo_set_to_output_unit(mo_set, qs_kind_set, particle_set, dft_section, 4, 0, &
     475              :                                                 final_mos=final_mos, spin=TRIM(spin), solver_method=solver_method, &
     476          852 :                                                 umo_set=umo_set, qs_env=cart_overlap_qs_env)
     477              :             ELSE
     478              :                CALL write_mo_set_to_output_unit(mo_set, qs_kind_set, particle_set, dft_section, 4, 0, &
     479              :                                                 final_mos=final_mos, solver_method=solver_method, &
     480         4160 :                                                 umo_set=umo_set, qs_env=cart_overlap_qs_env)
     481              :             END IF
     482              : 
     483         5012 :             IF (print_occup_stats) nmos_occ(ispin) = MAX(nmos_occ(ispin), &
     484           32 :                                                          COUNT(mo_set%occupation_numbers > occup_stats_occ_threshold))
     485              : 
     486              :             ! Deallocate temporary objects needed for OT
     487         5012 :             IF (scf_env%method == ot_method_nr) THEN
     488          222 :                IF (ASSOCIATED(umo_set)) THEN
     489           20 :                   CALL deallocate_mo_set(umo_set)
     490           20 :                   DEALLOCATE (umo_set)
     491              :                END IF
     492          222 :                NULLIFY (matrix_ks)
     493          222 :                NULLIFY (matrix_s)
     494              :             END IF
     495         9598 :             NULLIFY (mo_set)
     496              : 
     497              :          END DO ! ispin
     498              :       END IF
     499              : 
     500         7576 :       IF (do_printout .AND. print_mo_info .AND. print_occup_stats) THEN
     501              :          iw = cp_print_key_unit_nr(logger, dft_section, "PRINT%MO", &
     502              :                                    ignore_should_output=print_mo_info, &
     503            8 :                                    extension=".MOLog")
     504            8 :          IF (iw > 0) THEN
     505            4 :             IF (nspin > 1) THEN
     506            4 :                WRITE (UNIT=iw, FMT="(A,I4)") " MO| Total occupied (ALPHA):", nmos_occ(1)
     507            4 :                WRITE (UNIT=iw, FMT="(A,I4)") " MO| Total occupied (BETA): ", nmos_occ(2)
     508              :             ELSE
     509            0 :                WRITE (UNIT=iw, FMT="(A,I4)") " MO| Total occupied: ", nmos_occ(1)
     510              :             END IF
     511            4 :             WRITE (UNIT=iw, FMT="(A)") ""
     512              :          END IF
     513              :          CALL cp_print_key_finished_output(iw, logger, dft_section, "PRINT%MO", &
     514            8 :                                            ignore_should_output=print_mo_info)
     515              :       END IF
     516              : 
     517         7576 :       CALL timestop(handle)
     518              : 
     519       254832 :    END SUBROUTINE qs_scf_write_mos
     520              : 
     521              : ! **************************************************************************************************
     522              : !> \brief writes basic information obtained in a scf outer loop step
     523              : !> \param output_unit ...
     524              : !> \param scf_control ...
     525              : !> \param scf_env ...
     526              : !> \param energy ...
     527              : !> \param total_steps ...
     528              : !> \param should_stop ...
     529              : !> \param outer_loop_converged ...
     530              : ! **************************************************************************************************
     531         5603 :    SUBROUTINE qs_scf_outer_loop_info(output_unit, scf_control, scf_env, &
     532              :                                      energy, total_steps, should_stop, outer_loop_converged)
     533              :       INTEGER                                            :: output_unit
     534              :       TYPE(scf_control_type), POINTER                    :: scf_control
     535              :       TYPE(qs_scf_env_type), POINTER                     :: scf_env
     536              :       TYPE(qs_energy_type), POINTER                      :: energy
     537              :       INTEGER                                            :: total_steps
     538              :       LOGICAL, INTENT(IN)                                :: should_stop, outer_loop_converged
     539              : 
     540              :       REAL(KIND=dp)                                      :: outer_loop_eps
     541              : 
     542        11206 :       outer_loop_eps = SQRT(MAXVAL(scf_env%outer_scf%gradient(:, scf_env%outer_scf%iter_count)**2))
     543         5603 :       IF (output_unit > 0) WRITE (output_unit, '(/,T3,A,I4,A,E10.2,A,F22.10)') &
     544         2922 :          "outer SCF iter = ", scf_env%outer_scf%iter_count, &
     545         5844 :          " RMS gradient = ", outer_loop_eps, " energy =", energy%total
     546              : 
     547         5603 :       IF (outer_loop_converged) THEN
     548         4595 :          IF (output_unit > 0) WRITE (output_unit, '(T3,A,I4,A,I4,A,/)') &
     549         2411 :             "outer SCF loop converged in", scf_env%outer_scf%iter_count, &
     550         4822 :             " iterations or ", total_steps, " steps"
     551              :       ELSE IF (scf_env%outer_scf%iter_count > scf_control%outer_scf%max_scf &
     552         1008 :                .OR. should_stop) THEN
     553          102 :          IF (output_unit > 0) WRITE (output_unit, '(T3,A,I4,A,I4,A,/)') &
     554           51 :             "outer SCF loop FAILED to converge after ", &
     555          102 :             scf_env%outer_scf%iter_count, " iterations or ", total_steps, " steps"
     556              :       END IF
     557              : 
     558         5603 :    END SUBROUTINE qs_scf_outer_loop_info
     559              : 
     560              : ! **************************************************************************************************
     561              : !> \brief writes basic information obtained in a scf step
     562              : !> \param scf_env ...
     563              : !> \param output_unit ...
     564              : !> \param just_energy ...
     565              : !> \param t1 ...
     566              : !> \param t2 ...
     567              : !> \param energy ...
     568              : !> \param adiis_verbose whether to print per-iteration ADIIS diagnostics
     569              : ! **************************************************************************************************
     570       235759 :    SUBROUTINE qs_scf_loop_info(scf_env, output_unit, just_energy, t1, t2, energy, adiis_verbose)
     571              : 
     572              :       TYPE(qs_scf_env_type), POINTER                     :: scf_env
     573              :       INTEGER                                            :: output_unit
     574              :       LOGICAL, INTENT(IN)                                :: just_energy
     575              :       REAL(KIND=dp)                                      :: t1, t2
     576              :       TYPE(qs_energy_type), POINTER                      :: energy
     577              :       LOGICAL, INTENT(IN)                                :: adiis_verbose
     578              : 
     579       235759 :       IF ((output_unit > 0) .AND. scf_env%print_iter_line) THEN
     580       118833 :          IF (just_energy) THEN
     581              :             WRITE (UNIT=output_unit, &
     582              :                    FMT="(T2,A,1X,A,T20,E8.2,1X,F6.1,16X,F20.10)") &
     583         8590 :                "    -", TRIM(scf_env%iter_method), scf_env%iter_param, t2 - t1, energy%total
     584              :          ELSE
     585       100222 :             IF ((ABS(scf_env%iter_delta) < 1.0E-8_dp) .OR. &
     586       110243 :                 (ABS(scf_env%iter_delta) >= 1.0E5_dp)) THEN
     587              :                WRITE (UNIT=output_unit, &
     588              :                       FMT="(T2,I5,1X,A,T20,E8.2,1X,F6.1,1X,ES14.4,1X,F20.10,1X,ES9.2)") &
     589        10021 :                   scf_env%iter_count, TRIM(scf_env%iter_method), scf_env%iter_param, &
     590        20042 :                   t2 - t1, scf_env%iter_delta, energy%total, energy%total - energy%tot_old
     591              :             ELSE
     592              :                WRITE (UNIT=output_unit, &
     593              :                       FMT="(T2,I5,1X,A,T20,E8.2,1X,F6.1,1X,F14.8,1X,F20.10,1X,ES9.2)") &
     594       100222 :                   scf_env%iter_count, TRIM(scf_env%iter_method), scf_env%iter_param, &
     595       200444 :                   t2 - t1, scf_env%iter_delta, energy%total, energy%total - energy%tot_old
     596              :             END IF
     597       110243 :             IF (adiis_verbose) THEN
     598            0 :                IF (scf_env%adiis_shift > 0.0_dp) THEN
     599              :                   WRITE (UNIT=output_unit, FMT="(T4,A,ES11.3,A,F5.2,A,I3)") &
     600            0 :                      "ADIIS shift parameter [Ha]=", scf_env%adiis_shift, &
     601            0 :                      " CDIIS weight=", scf_env%scf_subspace_buffer%diis_weight, &
     602            0 :                      " history=", scf_env%scf_subspace_buffer%nstored
     603              :                END IF
     604            0 :                IF (scf_env%raw_map_delta_valid) THEN
     605              :                   WRITE (UNIT=output_unit, FMT="(T4,A,ES11.3,A,ES11.3)") &
     606            0 :                      "ADIIS metrics: step_norm=", scf_env%step_norm, &
     607            0 :                      " raw_map_delta=", scf_env%raw_map_delta
     608              :                END IF
     609              : 
     610              :             END IF
     611              :          END IF
     612              :       END IF
     613              : 
     614       235759 :    END SUBROUTINE qs_scf_loop_info
     615              : 
     616              : ! **************************************************************************************************
     617              : !> \brief writes rather detailed summary of densities and energies
     618              : !>      after the SCF
     619              : !> \param output_unit ...
     620              : !> \param rho ...
     621              : !> \param qs_charges ...
     622              : !> \param energy ...
     623              : !> \param nelectron_total ...
     624              : !> \param dft_control ...
     625              : !> \param qmmm ...
     626              : !> \param qs_env ...
     627              : !> \param gapw ...
     628              : !> \param gapw_xc ...
     629              : !> \par History
     630              : !>      03.2006 created [Joost VandeVondele]
     631              : !>      10.2019 print dipole moment [SGh]
     632              : !>      11.2022 print SCCS results [MK]
     633              : ! **************************************************************************************************
     634        25487 :    SUBROUTINE qs_scf_print_scf_summary(output_unit, rho, qs_charges, energy, nelectron_total, &
     635              :                                        dft_control, qmmm, qs_env, gapw, gapw_xc)
     636              :       INTEGER, INTENT(IN)                                :: output_unit
     637              :       TYPE(qs_rho_type), POINTER                         :: rho
     638              :       TYPE(qs_charges_type), POINTER                     :: qs_charges
     639              :       TYPE(qs_energy_type), POINTER                      :: energy
     640              :       INTEGER, INTENT(IN)                                :: nelectron_total
     641              :       TYPE(dft_control_type), POINTER                    :: dft_control
     642              :       LOGICAL, INTENT(IN)                                :: qmmm
     643              :       TYPE(qs_environment_type), POINTER                 :: qs_env
     644              :       LOGICAL, INTENT(IN)                                :: gapw, gapw_xc
     645              : 
     646              :       CHARACTER(LEN=*), PARAMETER :: routineN = 'qs_scf_print_scf_summary'
     647              : 
     648              :       INTEGER                                            :: bc, handle, ispin, psolver
     649              :       REAL(kind=dp)                                      :: e_extrapolated, exc1_energy, exc_energy, &
     650              :                                                             implicit_ps_ehartree, tot1_h, tot1_s
     651        25487 :       REAL(KIND=dp), DIMENSION(:), POINTER               :: tot_rho_r
     652              :       TYPE(pw_env_type), POINTER                         :: pw_env
     653              :       TYPE(scf_control_type), POINTER                    :: scf_control
     654              : 
     655        25487 :       NULLIFY (tot_rho_r, pw_env)
     656        25487 :       CALL timeset(routineN, handle)
     657              : 
     658        25487 :       CALL get_qs_env(qs_env=qs_env, pw_env=pw_env, scf_control=scf_control)
     659        25487 :       psolver = pw_env%poisson_env%parameters%solver
     660              : 
     661        25487 :       IF (output_unit > 0) THEN
     662        12914 :          CALL qs_rho_get(rho, tot_rho_r=tot_rho_r)
     663        12914 :          IF (.NOT. (dft_control%qs_control%semi_empirical .OR. &
     664              :                     dft_control%qs_control%xtb .OR. &
     665              :                     dft_control%qs_control%dftb)) THEN
     666              :             WRITE (UNIT=output_unit, FMT="(/,(T3,A,T41,2F20.10))") &
     667         6641 :                "Electronic density on regular grids: ", &
     668         6641 :                accurate_sum(tot_rho_r), &
     669         6641 :                accurate_sum(tot_rho_r) + nelectron_total, &
     670         6641 :                "Core density on regular grids:", &
     671         6641 :                qs_charges%total_rho_core_rspace, &
     672              :                qs_charges%total_rho_core_rspace + &
     673              :                qs_charges%total_rho1_hard_nuc - &
     674        13282 :                REAL(nelectron_total + dft_control%charge, dp)
     675              : 
     676         6641 :             IF (dft_control%correct_surf_dip) THEN
     677              :                WRITE (UNIT=output_unit, FMT="((T3,A,/,T3,A,T41,F20.10))") &
     678            5 :                   "Total dipole moment perpendicular to ", &
     679            5 :                   "the slab [electrons-Angstroem]: ", &
     680           10 :                   qs_env%surface_dipole_moment
     681              :                WRITE (UNIT=output_unit, FMT="((T3,A,/,T3,A,T41,F20.10))") &
     682            5 :                   "Position of the dipole ", &
     683            5 :                   "correction plane [Angstroem]: ", &
     684           10 :                   qs_env%surface_dipole_ref_pos
     685              :                WRITE (UNIT=output_unit, FMT="((T3,A,/,T3,A,T41,2F20.10))") &
     686            5 :                   "Vacuum level below/above the ", &
     687            5 :                   "dipole correction plane [eV]: ", &
     688           10 :                   qs_env%vacuum_level_below, qs_env%vacuum_level_above
     689              :             END IF
     690              : 
     691         6641 :             IF (gapw) THEN
     692         1236 :                tot1_h = qs_charges%total_rho1_hard(1)
     693         1236 :                tot1_s = qs_charges%total_rho1_soft(1)
     694         1468 :                DO ispin = 2, dft_control%nspins
     695          232 :                   tot1_h = tot1_h + qs_charges%total_rho1_hard(ispin)
     696         1468 :                   tot1_s = tot1_s + qs_charges%total_rho1_soft(ispin)
     697              :                END DO
     698              :                WRITE (UNIT=output_unit, FMT="((T3,A,T41,2F20.10))") &
     699         1236 :                   "Hard and soft densities (Lebedev):", &
     700         2472 :                   tot1_h, tot1_s
     701              :                WRITE (UNIT=output_unit, FMT="(T3,A,T41,F20.10)") &
     702         1236 :                   "Total Rho_soft + Rho1_hard - Rho1_soft (r-space): ", &
     703         1236 :                   accurate_sum(tot_rho_r) + tot1_h - tot1_s, &
     704         1236 :                   "Total charge density (r-space):      ", &
     705              :                   accurate_sum(tot_rho_r) + tot1_h - tot1_s &
     706              :                   + qs_charges%total_rho_core_rspace &
     707         2472 :                   + qs_charges%total_rho1_hard_nuc
     708         1236 :                IF (qs_charges%total_rho1_hard_nuc /= 0.0_dp) THEN
     709              :                   WRITE (UNIT=output_unit, FMT="(T3,A,T41,F20.10)") &
     710            4 :                      "Total CNEO nuc. char. den. (Lebedev): ", &
     711            4 :                      qs_charges%total_rho1_hard_nuc, &
     712            4 :                      "Total CNEO soft char. den. (Lebedev): ", &
     713            4 :                      qs_charges%total_rho1_soft_nuc_lebedev, &
     714            4 :                      "Total CNEO soft char. den. (r-space): ", &
     715            4 :                      qs_charges%total_rho1_soft_nuc_rspace, &
     716            4 :                      "Total soft Rho_e+n+0 (g-space):", &
     717            8 :                      qs_charges%total_rho_gspace
     718              :                ELSE
     719              :                   WRITE (UNIT=output_unit, FMT="(T3,A,T41,F20.10)") &
     720         1232 :                      "Total Rho_soft + Rho0_soft (g-space):", &
     721         2464 :                      qs_charges%total_rho_gspace
     722              :                END IF
     723              :                ! only add total_rho1_hard_nuc for gapw as cneo requires gapw
     724              :             ELSE
     725              :                WRITE (UNIT=output_unit, FMT="(T3,A,T41,F20.10)") &
     726         5405 :                   "Total charge density on r-space grids:     ", &
     727              :                   accurate_sum(tot_rho_r) + &
     728         5405 :                   qs_charges%total_rho_core_rspace, &
     729         5405 :                   "Total charge density g-space grids:     ", &
     730        10810 :                   qs_charges%total_rho_gspace
     731              :             END IF
     732              :          END IF
     733        12914 :          IF (dft_control%qs_control%semi_empirical) THEN
     734              :             WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
     735         1917 :                "Core-core repulsion energy [eV]:               ", energy%core_overlap*evolt, &
     736         1917 :                "Core Hamiltonian energy [eV]:                  ", energy%core*evolt, &
     737         1917 :                "Two-electron integral energy [eV]:             ", energy%hartree*evolt, &
     738         1917 :                "Electronic energy [eV]:                        ", &
     739         3834 :                (energy%core + 0.5_dp*energy%hartree)*evolt
     740         1917 :             IF (energy%dispersion /= 0.0_dp) THEN
     741              :                WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
     742            8 :                   "Dispersion energy [eV]:                     ", energy%dispersion*evolt
     743              :             END IF
     744        10997 :          ELSE IF (dft_control%qs_control%dftb) THEN
     745              :             WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
     746         1187 :                "Core Hamiltonian energy:                       ", energy%core, &
     747         1187 :                "Repulsive potential energy:                    ", energy%repulsive, &
     748         1187 :                "Electronic energy:                             ", energy%hartree, &
     749         2374 :                "Dispersion energy:                             ", energy%dispersion
     750         1187 :             IF (energy%dftb3 /= 0.0_dp) THEN
     751              :                WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
     752          377 :                   "DFTB3 3rd order energy:                     ", energy%dftb3
     753              :             END IF
     754         1187 :             IF (energy%efield /= 0.0_dp) THEN
     755              :                WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
     756           16 :                   "Electric field interaction energy:          ", energy%efield
     757              :             END IF
     758         9810 :          ELSE IF (dft_control%qs_control%xtb) THEN
     759         3169 :             IF (dft_control%qs_control%xtb_control%do_tblite) THEN
     760              :                WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
     761         1309 :                   "Core Hamiltonian energy:                       ", energy%core, &
     762         1309 :                   "Repulsive potential energy:                    ", energy%repulsive, &
     763         1309 :                   "Electrostatic energy:                          ", energy%el_stat, &
     764         1309 :                   "Self-consistent dispersion energy:             ", energy%dispersion_sc, &
     765         1309 :                   "Non-self consistent dispersion energy:         ", energy%dispersion, &
     766         2618 :                   "Correction for halogen bonding:                ", energy%xtb_xb_inter
     767              :             ELSE
     768         1860 :                IF (dft_control%qs_control%xtb_control%gfn_type == 0) THEN
     769              :                   WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
     770            0 :                      "Core Hamiltonian energy:                       ", energy%core, &
     771            0 :                      "Repulsive potential energy:                    ", energy%repulsive, &
     772            0 :                      "SRB Correction energy:                         ", energy%srb, &
     773            0 :                      "Charge equilibration energy:                   ", energy%eeq, &
     774            0 :                      "Dispersion energy:                             ", energy%dispersion
     775         1860 :                ELSE IF (dft_control%qs_control%xtb_control%gfn_type == 1) THEN
     776              :                   WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
     777         1860 :                      "Core Hamiltonian energy:                       ", energy%core, &
     778         1860 :                      "Repulsive potential energy:                    ", energy%repulsive, &
     779         1860 :                      "Electronic energy:                             ", energy%hartree, &
     780         1860 :                      "DFTB3 3rd order energy:                        ", energy%dftb3, &
     781         3720 :                      "Dispersion energy:                             ", energy%dispersion
     782         1860 :                   IF (dft_control%qs_control%xtb_control%xb_interaction) THEN
     783              :                      WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
     784         1825 :                         "Correction for halogen bonding:                ", energy%xtb_xb_inter
     785              :                   END IF
     786            0 :                ELSE IF (dft_control%qs_control%xtb_control%gfn_type == 2) THEN
     787            0 :                   CPABORT("gfn_typ 2 NYA")
     788              :                ELSE
     789            0 :                   CPABORT("invalid gfn_typ")
     790              :                END IF
     791              :             END IF
     792         3169 :             IF (dft_control%qs_control%xtb_control%do_nonbonded) THEN
     793              :                WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
     794           12 :                   "Correction for nonbonded interactions:         ", energy%xtb_nonbonded
     795              :             END IF
     796         3169 :             IF (energy%efield /= 0.0_dp) THEN
     797              :                WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
     798          406 :                   "Electric field interaction energy:          ", energy%efield
     799              :             END IF
     800              :          ELSE
     801         6641 :             IF (dft_control%do_admm) THEN
     802          556 :                exc_energy = energy%exc + energy%exc_aux_fit
     803          556 :                IF (gapw .OR. gapw_xc) exc1_energy = energy%exc1 + energy%exc1_aux_fit
     804              :             ELSE
     805         6085 :                exc_energy = energy%exc
     806         6085 :                IF (gapw .OR. gapw_xc) exc1_energy = energy%exc1
     807              :             END IF
     808              : 
     809         6641 :             IF (psolver == pw_poisson_implicit) THEN
     810           60 :                implicit_ps_ehartree = pw_env%poisson_env%implicit_env%ehartree
     811           60 :                bc = pw_env%poisson_env%parameters%ps_implicit_params%boundary_condition
     812           41 :                SELECT CASE (bc)
     813              :                CASE (MIXED_PERIODIC_BC, MIXED_BC)
     814              :                   WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
     815           41 :                      "Overlap energy of the core charge distribution:", energy%core_overlap, &
     816           41 :                      "Self energy of the core charge distribution:   ", energy%core_self, &
     817           41 :                      "Core Hamiltonian energy:                       ", energy%core, &
     818           41 :                      "Hartree energy:                                ", implicit_ps_ehartree, &
     819           41 :                      "Electric enthalpy:                             ", energy%hartree, &
     820           82 :                      "Exchange-correlation energy:                   ", exc_energy
     821              :                CASE (PERIODIC_BC, NEUMANN_BC)
     822              :                   WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
     823           19 :                      "Overlap energy of the core charge distribution:", energy%core_overlap, &
     824           19 :                      "Self energy of the core charge distribution:   ", energy%core_self, &
     825           19 :                      "Core Hamiltonian energy:                       ", energy%core, &
     826           19 :                      "Hartree energy:                                ", energy%hartree, &
     827           79 :                      "Exchange-correlation energy:                   ", exc_energy
     828              :                END SELECT
     829              :             ELSE
     830              :                WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
     831         6581 :                   "Overlap energy of the core charge distribution:", energy%core_overlap, &
     832         6581 :                   "Self energy of the core charge distribution:   ", energy%core_self, &
     833         6581 :                   "Core Hamiltonian energy:                       ", energy%core, &
     834         6581 :                   "Hartree energy:                                ", energy%hartree, &
     835        13162 :                   "Exchange-correlation energy:                   ", exc_energy
     836              :             END IF
     837         6641 :             IF (energy%e_hartree /= 0.0_dp) THEN
     838              :                WRITE (UNIT=output_unit, FMT="(T3,A,/,T3,A,T56,F25.14)") &
     839           44 :                   "Coulomb Electron-Electron Interaction Energy ", &
     840           88 :                   "- Already included in the total Hartree term ", energy%e_hartree
     841              :             END IF
     842         6641 :             IF (energy%ex /= 0.0_dp) THEN
     843              :                WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
     844         1261 :                   "Hartree-Fock Exchange energy:                  ", energy%ex
     845              :             END IF
     846         6641 :             IF (energy%dispersion /= 0.0_dp) THEN
     847              :                WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
     848          227 :                   "Dispersion energy:                             ", energy%dispersion
     849              :             END IF
     850         6641 :             IF (energy%gcp /= 0.0_dp) THEN
     851              :                WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
     852            3 :                   "gCP energy:                                    ", energy%gcp
     853              :             END IF
     854         6641 :             IF (energy%efield /= 0.0_dp) THEN
     855              :                WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
     856          518 :                   "Electric field interaction energy:          ", energy%efield
     857              :             END IF
     858         6641 :             IF (gapw) THEN
     859              :                WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
     860         1236 :                   "GAPW| Exc from hard and soft atomic rho1:      ", exc1_energy, &
     861         2472 :                   "GAPW| local Eh = 1 center integrals:           ", energy%hartree_1c
     862              :             END IF
     863         6641 :             IF (gapw_xc) THEN
     864              :                WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
     865          226 :                   "GAPW_XC| Exc from hard and soft atomic rho1:      ", exc1_energy
     866              :             END IF
     867         6641 :             IF (energy%core_cneo /= 0.0_dp) THEN
     868              :                WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
     869            4 :                   "CNEO| quantum nuclear core energy: ", energy%core_cneo
     870              :             END IF
     871              :          END IF
     872        12914 :          IF (dft_control%hairy_probes .EQV. .TRUE.) THEN
     873              :             WRITE (UNIT=output_unit, FMT="((T3,A,T56,F25.14))") &
     874            2 :                "Electronic entropic energy:", energy%kTS
     875              :             WRITE (UNIT=output_unit, FMT="((T3,A,T56,F25.14))") &
     876            2 :                "Fermi energy:", energy%efermi
     877              :          END IF
     878        12914 :          IF (dft_control%smear) THEN
     879         1705 :             SELECT CASE (scf_control%smear%method)
     880              :             CASE (smear_gaussian, smear_mp, smear_mv)
     881              :                ! kTS does not have physical meaning in these smearing methods
     882              :                WRITE (UNIT=output_unit, FMT="((T3,A,T56,F25.14))") &
     883           66 :                   "Smearing free energy correction:", energy%kTS
     884              :             CASE DEFAULT
     885              :                WRITE (UNIT=output_unit, FMT="((T3,A,T56,F25.14))") &
     886         1639 :                   "Electronic entropic energy:", energy%kTS
     887              :             END SELECT
     888              :             WRITE (UNIT=output_unit, FMT="((T3,A,T56,F25.14))") &
     889         1639 :                "Fermi energy:", energy%efermi
     890              :          END IF
     891        12914 :          IF (dft_control%dft_plus_u) THEN
     892              :             WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
     893          192 :                "DFT+U energy:", energy%dft_plus_u
     894              :          END IF
     895        12914 :          IF (dft_control%do_sccs) THEN
     896            7 :             WRITE (UNIT=output_unit, FMT="(A)") ""
     897            7 :             CALL print_sccs_results(energy, dft_control%sccs_control, output_unit)
     898              :          END IF
     899        12914 :          IF (qmmm) THEN
     900              :             WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
     901         1857 :                "QM/MM Electrostatic energy:                    ", energy%qmmm_el
     902         1857 :             IF (qs_env%qmmm_env_qm%image_charge) THEN
     903              :                WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
     904           10 :                   "QM/MM image charge energy:                ", energy%image_charge
     905              :             END IF
     906              :          END IF
     907        12914 :          IF (dft_control%qs_control%mulliken_restraint) THEN
     908              :             WRITE (UNIT=output_unit, FMT="(T3,A,T56,F25.14)") &
     909            3 :                "Mulliken restraint energy: ", energy%mulliken
     910              :          END IF
     911        12914 :          IF (dft_control%qs_control%semi_empirical) THEN
     912              :             WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
     913         1917 :                "Total energy [eV]:                             ", energy%total*evolt
     914              :             WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
     915         1917 :                "Atomic reference energy [eV]:                  ", energy%core_self*evolt, &
     916         1917 :                "Heat of formation [kcal/mol]:                  ", &
     917         3834 :                (energy%total + energy%core_self)*kcalmol
     918              :          ELSE
     919              :             WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
     920        10997 :                "Total energy:                                  ", energy%total
     921        10997 :             IF (dft_control%smear) THEN
     922         3205 :                SELECT CASE (scf_control%smear%method)
     923              :                CASE (smear_fermi_dirac)
     924         1566 :                   e_extrapolated = energy%total - 0.5_dp*energy%kTS
     925              :                   WRITE (UNIT=output_unit, FMT="((T3,A,T56,F25.14))") &
     926         1566 :                      "Total energy (extrapolated to T->0):           ", e_extrapolated
     927         1566 :                   IF (scf_control%gce%do_gce) THEN
     928              :                      WRITE (UNIT=output_unit, FMT="(/,(T3,A,T56,F25.14))") &
     929            1 :                         "GCE work function [eV]: ", scf_control%gce%prev_workfunction*evolt
     930              :                      WRITE (UNIT=output_unit, FMT="((T3,A,T56,ES25.10))") &
     931            1 :                         "GCE WF-TWF [eV]: ", (scf_control%gce%prev_workfunction - &
     932            2 :                                               scf_control%gce%target_workfunction)*evolt
     933              :                      WRITE (UNIT=output_unit, FMT="((T3,A,T56,F25.14))") &
     934            1 :                         "GCE charge [e]: ", dft_control%pcc_control%charge
     935              :                      WRITE (UNIT=output_unit, FMT="((T3,A,T56,F25.14))") &
     936            1 :                         "GCE free energy: ", (dft_control%pcc_control%charge + dft_control%charge) &
     937            2 :                         *scf_control%gce%prev_workfunction*evolt
     938              :                   END IF
     939              :                CASE (smear_gaussian)
     940           62 :                   e_extrapolated = energy%total - 0.5_dp*energy%kTS
     941              :                   WRITE (UNIT=output_unit, FMT="((T3,A,T56,F25.14))") &
     942         1639 :                      "Total energy (extrapolated to sigma->0):       ", e_extrapolated
     943              :                CASE (smear_mp, smear_mv)
     944              :                   ! Sigma->0 extrapolation does not apply to MP or MV method.
     945              :                END SELECT
     946              :             END IF
     947              :          END IF
     948        12914 :          IF (qmmm) THEN
     949         1857 :             IF (qs_env%qmmm_env_qm%image_charge) THEN
     950           10 :                CALL print_image_coefficients(qs_env%image_coeff, qs_env)
     951              :             END IF
     952              :          END IF
     953        12914 :          CALL m_flush(output_unit)
     954              :       END IF
     955              : 
     956        25487 :       CALL timestop(handle)
     957              : 
     958        25487 :    END SUBROUTINE qs_scf_print_scf_summary
     959              : 
     960              : ! **************************************************************************************************
     961              : !> \brief collects the 'heavy duty' printing tasks out of the SCF loop
     962              : !> \param qs_env ...
     963              : !> \param scf_env ...
     964              : !> \param para_env ...
     965              : !> \par History
     966              : !>      03.2006 created [Joost VandeVondele]
     967              : ! **************************************************************************************************
     968       715887 :    SUBROUTINE qs_scf_loop_print(qs_env, scf_env, para_env)
     969              :       TYPE(qs_environment_type), POINTER                 :: qs_env
     970              :       TYPE(qs_scf_env_type), POINTER                     :: scf_env
     971              :       TYPE(mp_para_env_type), POINTER                    :: para_env
     972              : 
     973              :       CHARACTER(LEN=*), PARAMETER                        :: routineN = 'qs_scf_loop_print'
     974              : 
     975              :       INTEGER                                            :: after, handle, ic, ispin, iw
     976              :       LOGICAL                                            :: do_kpoints, omit_headers
     977              :       REAL(KIND=dp)                                      :: mo_mag_max, mo_mag_min, orthonormality
     978              :       TYPE(cp_logger_type), POINTER                      :: logger
     979       238629 :       TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER       :: matrix_ks, matrix_p, matrix_s
     980              :       TYPE(dft_control_type), POINTER                    :: dft_control
     981       238629 :       TYPE(mo_set_type), DIMENSION(:), POINTER           :: mos
     982              :       TYPE(qs_rho_type), POINTER                         :: rho
     983              :       TYPE(section_vals_type), POINTER                   :: dft_section, input, scf_section
     984              : 
     985       477258 :       logger => cp_get_default_logger()
     986       238629 :       CALL timeset(routineN, handle)
     987              : 
     988              :       CALL get_qs_env(qs_env=qs_env, input=input, dft_control=dft_control, &
     989       238629 :                       do_kpoints=do_kpoints)
     990              : 
     991       238629 :       dft_section => section_vals_get_subs_vals(input, "DFT")
     992       238629 :       scf_section => section_vals_get_subs_vals(dft_section, "SCF")
     993              : 
     994       238629 :       CALL section_vals_val_get(input, "DFT%PRINT%AO_MATRICES%OMIT_HEADERS", l_val=omit_headers)
     995       514931 :       DO ispin = 1, dft_control%nspins
     996              : 
     997       276302 :          IF (BTEST(cp_print_key_should_output(logger%iter_info, &
     998              :                                               dft_section, "PRINT%AO_MATRICES/DENSITY"), cp_p_file)) THEN
     999         6884 :             CALL get_qs_env(qs_env, rho=rho)
    1000         6884 :             CALL qs_rho_get(rho, rho_ao_kp=matrix_p)
    1001              :             iw = cp_print_key_unit_nr(logger, dft_section, "PRINT%AO_MATRICES/DENSITY", &
    1002         6884 :                                       extension=".Log")
    1003         6884 :             CALL section_vals_val_get(dft_section, "PRINT%AO_MATRICES%NDIGITS", i_val=after)
    1004         6884 :             after = MIN(MAX(after, 1), 16)
    1005        13768 :             DO ic = 1, SIZE(matrix_p, 2)
    1006              :                CALL cp_dbcsr_write_sparse_matrix(matrix_p(ispin, ic)%matrix, 4, after, qs_env, para_env, &
    1007        13768 :                                                  output_unit=iw, omit_headers=omit_headers)
    1008              :             END DO
    1009              :             CALL cp_print_key_finished_output(iw, logger, dft_section, &
    1010         6884 :                                               "PRINT%AO_MATRICES/DENSITY")
    1011              :          END IF
    1012              : 
    1013       276302 :          IF (BTEST(cp_print_key_should_output(logger%iter_info, &
    1014       238629 :                                               dft_section, "PRINT%AO_MATRICES/KOHN_SHAM_MATRIX"), cp_p_file)) THEN
    1015              :             iw = cp_print_key_unit_nr(logger, dft_section, "PRINT%AO_MATRICES/KOHN_SHAM_MATRIX", &
    1016         5758 :                                       extension=".Log")
    1017         5758 :             CALL section_vals_val_get(dft_section, "PRINT%AO_MATRICES%NDIGITS", i_val=after)
    1018         5758 :             after = MIN(MAX(after, 1), 16)
    1019         5758 :             CALL get_qs_env(qs_env=qs_env, matrix_ks_kp=matrix_ks)
    1020        11516 :             DO ic = 1, SIZE(matrix_ks, 2)
    1021        11516 :                IF (dft_control%qs_control%semi_empirical) THEN
    1022              :                   CALL cp_dbcsr_write_sparse_matrix(matrix_ks(ispin, ic)%matrix, 4, after, qs_env, para_env, &
    1023         5754 :                                                     scale=evolt, output_unit=iw, omit_headers=omit_headers)
    1024              :                ELSE
    1025              :                   CALL cp_dbcsr_write_sparse_matrix(matrix_ks(ispin, ic)%matrix, 4, after, qs_env, para_env, &
    1026            4 :                                                     output_unit=iw, omit_headers=omit_headers)
    1027              :                END IF
    1028              :             END DO
    1029              :             CALL cp_print_key_finished_output(iw, logger, dft_section, &
    1030         5758 :                                               "PRINT%AO_MATRICES/KOHN_SHAM_MATRIX")
    1031              :          END IF
    1032              : 
    1033              :       END DO
    1034              : 
    1035       238629 :       IF (BTEST(cp_print_key_should_output(logger%iter_info, &
    1036              :                                            scf_section, "PRINT%MO_ORTHONORMALITY"), cp_p_file)) THEN
    1037         1190 :          IF (do_kpoints) THEN
    1038              :             iw = cp_print_key_unit_nr(logger, scf_section, "PRINT%MO_ORTHONORMALITY", &
    1039           16 :                                       extension=".scfLog")
    1040           16 :             IF (iw > 0) THEN
    1041              :                WRITE (iw, '(T8,A)') &
    1042            8 :                   " K-points: Maximum deviation from MO S-orthonormality not determined"
    1043              :             END IF
    1044              :             CALL cp_print_key_finished_output(iw, logger, scf_section, &
    1045           16 :                                               "PRINT%MO_ORTHONORMALITY")
    1046              :          ELSE
    1047         1174 :             CALL get_qs_env(qs_env, mos=mos)
    1048         1174 :             IF (scf_env%method == special_diag_method_nr) THEN
    1049           58 :                CALL calculate_orthonormality(orthonormality, mos)
    1050              :             ELSE
    1051         1116 :                CALL get_qs_env(qs_env=qs_env, matrix_s_kp=matrix_s)
    1052         1116 :                CALL calculate_orthonormality(orthonormality, mos, matrix_s(1, 1)%matrix)
    1053              :             END IF
    1054              :             iw = cp_print_key_unit_nr(logger, scf_section, "PRINT%MO_ORTHONORMALITY", &
    1055         1174 :                                       extension=".scfLog")
    1056         1174 :             IF (iw > 0) THEN
    1057              :                WRITE (iw, '(T8,A,T61,E20.4)') &
    1058          587 :                   " Maximum deviation from MO S-orthonormality", orthonormality
    1059              :             END IF
    1060              :             CALL cp_print_key_finished_output(iw, logger, scf_section, &
    1061         1174 :                                               "PRINT%MO_ORTHONORMALITY")
    1062              :          END IF
    1063              :       END IF
    1064       238629 :       IF (BTEST(cp_print_key_should_output(logger%iter_info, &
    1065              :                                            scf_section, "PRINT%MO_MAGNITUDE"), cp_p_file)) THEN
    1066         1190 :          IF (do_kpoints) THEN
    1067              :             iw = cp_print_key_unit_nr(logger, scf_section, "PRINT%MO_MAGNITUDE", &
    1068           16 :                                       extension=".scfLog")
    1069           16 :             IF (iw > 0) THEN
    1070              :                WRITE (iw, '(T8,A)') &
    1071            8 :                   " K-points: Minimum/Maximum MO magnitude not determined"
    1072              :             END IF
    1073              :             CALL cp_print_key_finished_output(iw, logger, scf_section, &
    1074           16 :                                               "PRINT%MO_MAGNITUDE")
    1075              :          ELSE
    1076         1174 :             CALL get_qs_env(qs_env, mos=mos)
    1077         1174 :             CALL calculate_magnitude(mos, mo_mag_min, mo_mag_max)
    1078              :             iw = cp_print_key_unit_nr(logger, scf_section, "PRINT%MO_MAGNITUDE", &
    1079         1174 :                                       extension=".scfLog")
    1080         1174 :             IF (iw > 0) THEN
    1081              :                WRITE (iw, '(T8,A,T41,2E20.4)') &
    1082          587 :                   " Minimum/Maximum MO magnitude ", mo_mag_min, mo_mag_max
    1083              :             END IF
    1084              :             CALL cp_print_key_finished_output(iw, logger, scf_section, &
    1085         1174 :                                               "PRINT%MO_MAGNITUDE")
    1086              :          END IF
    1087              :       END IF
    1088              : 
    1089       238629 :       CALL timestop(handle)
    1090              : 
    1091       238629 :    END SUBROUTINE qs_scf_loop_print
    1092              : 
    1093              : ! **************************************************************************************************
    1094              : !> \brief writes CDFT constraint information and optionally CDFT scf loop info
    1095              : !> \param output_unit where to write the information
    1096              : !> \param scf_control settings of the SCF loop
    1097              : !> \param scf_env the env which holds convergence data
    1098              : !> \param cdft_control the env which holds information about the constraint
    1099              : !> \param energy the total energy
    1100              : !> \param total_steps the total number of performed SCF iterations
    1101              : !> \param should_stop if the calculation should stop
    1102              : !> \param outer_loop_converged logical which determines if the CDFT SCF loop converged
    1103              : !> \param cdft_loop logical which determines a CDFT SCF loop is active
    1104              : !> \par History
    1105              : !>      12.2015 created [Nico Holmberg]
    1106              : ! **************************************************************************************************
    1107          710 :    SUBROUTINE qs_scf_cdft_info(output_unit, scf_control, scf_env, cdft_control, &
    1108              :                                energy, total_steps, should_stop, outer_loop_converged, &
    1109              :                                cdft_loop)
    1110              :       INTEGER                                            :: output_unit
    1111              :       TYPE(scf_control_type), POINTER                    :: scf_control
    1112              :       TYPE(qs_scf_env_type), POINTER                     :: scf_env
    1113              :       TYPE(cdft_control_type), POINTER                   :: cdft_control
    1114              :       TYPE(qs_energy_type), POINTER                      :: energy
    1115              :       INTEGER                                            :: total_steps
    1116              :       LOGICAL, INTENT(IN)                                :: should_stop, outer_loop_converged, &
    1117              :                                                             cdft_loop
    1118              : 
    1119              :       REAL(KIND=dp)                                      :: outer_loop_eps
    1120              : 
    1121          710 :       IF (cdft_loop) THEN
    1122         1280 :          outer_loop_eps = SQRT(MAXVAL(scf_env%outer_scf%gradient(:, scf_env%outer_scf%iter_count)**2))
    1123          596 :          IF (output_unit > 0) WRITE (output_unit, '(/,T3,A,I4,A,E10.2,A,F22.10)') &
    1124          320 :             "CDFT SCF iter =  ", scf_env%outer_scf%iter_count, &
    1125          640 :             " RMS gradient = ", outer_loop_eps, " energy =", energy%total
    1126          596 :          IF (outer_loop_converged) THEN
    1127          286 :             IF (output_unit > 0) WRITE (output_unit, '(T3,A,I4,A,I4,A,/)') &
    1128          162 :                "CDFT SCF loop converged in", scf_env%outer_scf%iter_count, &
    1129          324 :                " iterations or ", total_steps, " steps"
    1130              :          END IF
    1131              :          IF ((scf_env%outer_scf%iter_count > scf_control%outer_scf%max_scf .OR. should_stop) &
    1132          596 :              .AND. .NOT. outer_loop_converged) THEN
    1133           74 :             IF (output_unit > 0) WRITE (output_unit, '(T3,A,I4,A,I4,A,/)') &
    1134           37 :                "CDFT SCF loop FAILED to converge after ", &
    1135           74 :                scf_env%outer_scf%iter_count, " iterations or ", total_steps, " steps"
    1136              :          END IF
    1137              :       END IF
    1138          710 :       CALL qs_scf_cdft_constraint_info(output_unit, cdft_control)
    1139              : 
    1140          710 :    END SUBROUTINE qs_scf_cdft_info
    1141              : 
    1142              : ! **************************************************************************************************
    1143              : !> \brief writes information about the CDFT env
    1144              : !> \param output_unit where to write the information
    1145              : !> \param cdft_control the CDFT env that stores information about the constraint calculation
    1146              : !> \par History
    1147              : !>      12.2015 created [Nico Holmberg]
    1148              : ! **************************************************************************************************
    1149          199 :    SUBROUTINE qs_scf_cdft_initial_info(output_unit, cdft_control)
    1150              :       INTEGER                                            :: output_unit
    1151              :       TYPE(cdft_control_type), POINTER                   :: cdft_control
    1152              : 
    1153          199 :       IF (output_unit > 0) THEN
    1154              :          WRITE (output_unit, '(/,A)') &
    1155          199 :             "  ---------------------------------- CDFT --------------------------------------"
    1156              :          WRITE (output_unit, '(A)') &
    1157          199 :             "  Optimizing a density constraint in an external SCF loop "
    1158          199 :          WRITE (output_unit, '(A)') "  "
    1159          217 :          SELECT CASE (cdft_control%type)
    1160              :          CASE (outer_scf_hirshfeld_constraint)
    1161           18 :             WRITE (output_unit, '(A)') "  Type of constraint:     Hirshfeld"
    1162              :          CASE (outer_scf_becke_constraint)
    1163          199 :             WRITE (output_unit, '(A)') "  Type of constraint:         Becke"
    1164              :          END SELECT
    1165          199 :          WRITE (output_unit, '(A,I8)') "  Number of constraints:   ", SIZE(cdft_control%group)
    1166          199 :          WRITE (output_unit, '(A,L8)') "  Using fragment densities:", cdft_control%fragment_density
    1167          199 :          WRITE (output_unit, '(A)') "  "
    1168          199 :          IF (cdft_control%atomic_charges) WRITE (output_unit, '(A,/)') "  Calculating atomic CDFT charges"
    1169          199 :          SELECT CASE (cdft_control%constraint_control%optimizer)
    1170              :          CASE (outer_scf_optimizer_sd)
    1171              :             WRITE (output_unit, '(A)') &
    1172            0 :                "  Minimizer               : SD                  : steepest descent"
    1173              :          CASE (outer_scf_optimizer_diis)
    1174              :             WRITE (output_unit, '(A)') &
    1175           17 :                "  Minimizer               : DIIS                : direct inversion"
    1176              :             WRITE (output_unit, '(A)') &
    1177           17 :                "                                                       in the iterative subspace"
    1178              :             WRITE (output_unit, '(A,I3,A)') &
    1179           17 :                "                                                  using ", &
    1180           34 :                cdft_control%constraint_control%diis_buffer_length, " DIIS vectors"
    1181              :          CASE (outer_scf_optimizer_bisect)
    1182              :             WRITE (output_unit, '(A)') &
    1183          121 :                "  Minimizer               : BISECT              : gradient bisection"
    1184              :             WRITE (output_unit, '(A,I3)') &
    1185          121 :                "                                                  using a trust count of", &
    1186          242 :                cdft_control%constraint_control%bisect_trust_count
    1187              :          CASE (outer_scf_optimizer_broyden, outer_scf_optimizer_newton, &
    1188              :                outer_scf_optimizer_newton_ls)
    1189              :             CALL cdft_opt_type_write(cdft_control%constraint_control%cdft_opt_control, &
    1190           60 :                                      cdft_control%constraint_control%optimizer, output_unit)
    1191              :          CASE (outer_scf_optimizer_secant)
    1192            1 :             WRITE (output_unit, '(A)') "  Minimizer               : Secant"
    1193              :          CASE DEFAULT
    1194          199 :             CPABORT("Unknown CDFT outer_scf optimizer")
    1195              :          END SELECT
    1196              :          WRITE (output_unit, '(/,A,L7)') &
    1197          199 :             "  Reusing OT preconditioner: ", cdft_control%reuse_precond
    1198          199 :          IF (cdft_control%reuse_precond) THEN
    1199              :             WRITE (output_unit, '(A,I3,A,I3,A)') &
    1200            0 :                "       using old preconditioner for up to ", &
    1201            0 :                cdft_control%max_reuse, " subsequent CDFT SCF"
    1202              :             WRITE (output_unit, '(A,I3,A,I3,A)') &
    1203            0 :                "       iterations if the relevant loop converged in less than ", &
    1204            0 :                cdft_control%precond_freq, " steps"
    1205              :          END IF
    1206          217 :          SELECT CASE (cdft_control%type)
    1207              :          CASE (outer_scf_hirshfeld_constraint)
    1208           18 :             WRITE (output_unit, '(/,A)') "  Hirshfeld constraint settings"
    1209           18 :             WRITE (output_unit, '(A)') "  "
    1210          215 :             SELECT CASE (cdft_control%hirshfeld_control%shape_function)
    1211              :             CASE (shape_function_gaussian)
    1212              :                WRITE (output_unit, '(A, A8)') &
    1213           16 :                   "  Shape function type:     ", "Gaussian"
    1214              :                WRITE (output_unit, '(A)', ADVANCE='NO') &
    1215           16 :                   "  Type of Gaussian:   "
    1216           20 :                SELECT CASE (cdft_control%hirshfeld_control%gaussian_shape)
    1217              :                CASE (radius_default)
    1218            2 :                   WRITE (output_unit, '(A13)') "Default"
    1219              :                CASE (radius_covalent)
    1220           14 :                   WRITE (output_unit, '(A13)') "Covalent"
    1221              :                CASE (radius_single)
    1222            0 :                   WRITE (output_unit, '(A13)') "Fixed radius"
    1223              :                CASE (radius_vdw)
    1224            0 :                   WRITE (output_unit, '(A13)') "Van der Waals"
    1225              :                CASE (radius_user)
    1226           16 :                   WRITE (output_unit, '(A13)') "User-defined"
    1227              : 
    1228              :                END SELECT
    1229              :             CASE (shape_function_density)
    1230              :                WRITE (output_unit, '(A, A8)') &
    1231           18 :                   "  Shape function type:     ", "Density"
    1232              :             END SELECT
    1233              :          CASE (outer_scf_becke_constraint)
    1234          181 :             WRITE (output_unit, '(/, A)') "  Becke constraint settings"
    1235          181 :             WRITE (output_unit, '(A)') "  "
    1236          293 :             SELECT CASE (cdft_control%becke_control%cutoff_type)
    1237              :             CASE (becke_cutoff_global)
    1238              :                WRITE (output_unit, '(A,F8.3,A)') &
    1239          112 :                   "  Cutoff for partitioning :", cp_unit_from_cp2k(cdft_control%becke_control%rglobal, &
    1240          224 :                                                                    "angstrom"), " angstrom"
    1241              :             CASE (becke_cutoff_element)
    1242              :                WRITE (output_unit, '(A)') &
    1243          181 :                   "  Using element specific cutoffs for partitioning"
    1244              :             END SELECT
    1245              :             WRITE (output_unit, '(A,L7)') &
    1246          181 :                "  Skipping distant gpoints: ", cdft_control%becke_control%should_skip
    1247              :             WRITE (output_unit, '(A,L7)') &
    1248          181 :                "  Precompute gradients    : ", cdft_control%becke_control%in_memory
    1249          181 :             WRITE (output_unit, '(A)') "  "
    1250          181 :             IF (cdft_control%becke_control%adjust) THEN
    1251              :                WRITE (output_unit, '(A)') &
    1252          110 :                   "  Using atomic radii to generate a heteronuclear charge partitioning"
    1253              :             END IF
    1254          181 :             WRITE (output_unit, '(A)') "  "
    1255          380 :             IF (.NOT. cdft_control%becke_control%cavity_confine) THEN
    1256              :                WRITE (output_unit, '(A)') &
    1257           23 :                   "  No confinement is active"
    1258              :             ELSE
    1259          158 :                WRITE (output_unit, '(A)') "  Confinement using a Gaussian shaped cavity is active"
    1260          159 :                SELECT CASE (cdft_control%becke_control%cavity_shape)
    1261              :                CASE (radius_single)
    1262              :                   WRITE (output_unit, '(A,F8.4, A)') &
    1263            1 :                      "  Type of Gaussian        : Fixed radius: ", &
    1264            2 :                      cp_unit_from_cp2k(cdft_control%becke_control%rcavity, "angstrom"), " angstrom"
    1265              :                CASE (radius_covalent)
    1266              :                   WRITE (output_unit, '(A)') &
    1267            1 :                      "  Type of Gaussian        : Covalent radius "
    1268              :                CASE (radius_vdw)
    1269              :                   WRITE (output_unit, '(A)') &
    1270          155 :                      "  Type of Gaussian        : vdW radius "
    1271              :                CASE (radius_user)
    1272              :                   WRITE (output_unit, '(A)') &
    1273          158 :                      "  Type of Gaussian        : User radius "
    1274              :                END SELECT
    1275              :                WRITE (output_unit, '(A,ES12.4)') &
    1276          158 :                   "  Cavity threshold        : ", cdft_control%becke_control%eps_cavity
    1277              :             END IF
    1278              :          END SELECT
    1279              :          WRITE (output_unit, '(/,A)') &
    1280          199 :             "  ---------------------------------- CDFT --------------------------------------"
    1281              :       END IF
    1282              : 
    1283          199 :    END SUBROUTINE qs_scf_cdft_initial_info
    1284              : 
    1285              : ! **************************************************************************************************
    1286              : !> \brief writes CDFT constraint information
    1287              : !> \param output_unit where to write the information
    1288              : !> \param cdft_control the env which holds information about the constraint
    1289              : !> \par History
    1290              : !>      08.2018 separated from qs_scf_cdft_info to make code callable elsewhere  [Nico Holmberg]
    1291              : ! **************************************************************************************************
    1292         4564 :    SUBROUTINE qs_scf_cdft_constraint_info(output_unit, cdft_control)
    1293              :       INTEGER                                            :: output_unit
    1294              :       TYPE(cdft_control_type), POINTER                   :: cdft_control
    1295              : 
    1296              :       INTEGER                                            :: igroup
    1297              : 
    1298         4564 :       IF (output_unit > 0) THEN
    1299         2495 :          SELECT CASE (cdft_control%type)
    1300              :          CASE (outer_scf_hirshfeld_constraint)
    1301              :             WRITE (output_unit, '(/,T3,A,T60)') &
    1302          109 :                '------------------- Hirshfeld constraint information -------------------'
    1303              :          CASE (outer_scf_becke_constraint)
    1304              :             WRITE (output_unit, '(/,T3,A,T60)') &
    1305         2277 :                '--------------------- Becke constraint information ---------------------'
    1306              :          CASE DEFAULT
    1307         2386 :             CPABORT("Unknown CDFT constraint.")
    1308              :          END SELECT
    1309         5364 :          DO igroup = 1, SIZE(cdft_control%target)
    1310         2978 :             IF (igroup > 1) WRITE (output_unit, '(T3,A)') ' '
    1311              :             WRITE (output_unit, '(T3,A,T54,(3X,I18))') &
    1312         2978 :                'Atomic group                :', igroup
    1313         4772 :             SELECT CASE (cdft_control%group(igroup)%constraint_type)
    1314              :             CASE (cdft_charge_constraint)
    1315         1794 :                IF (cdft_control%group(igroup)%is_fragment_constraint) THEN
    1316              :                   WRITE (output_unit, '(T3,A,T42,A)') &
    1317           36 :                      'Type of constraint          :', ADJUSTR('Charge density constraint (frag.)')
    1318              :                ELSE
    1319              :                   WRITE (output_unit, '(T3,A,T50,A)') &
    1320         1758 :                      'Type of constraint          :', ADJUSTR('Charge density constraint')
    1321              :                END IF
    1322              :             CASE (cdft_magnetization_constraint)
    1323            8 :                IF (cdft_control%group(igroup)%is_fragment_constraint) THEN
    1324              :                   WRITE (output_unit, '(T3,A,T35,A)') &
    1325            6 :                      'Type of constraint          :', ADJUSTR('Magnetization density constraint (frag.)')
    1326              :                ELSE
    1327              :                   WRITE (output_unit, '(T3,A,T43,A)') &
    1328            2 :                      'Type of constraint          :', ADJUSTR('Magnetization density constraint')
    1329              :                END IF
    1330              :             CASE (cdft_alpha_constraint)
    1331          588 :                IF (cdft_control%group(igroup)%is_fragment_constraint) THEN
    1332              :                   WRITE (output_unit, '(T3,A,T38,A)') &
    1333            0 :                      'Type of constraint          :', ADJUSTR('Alpha spin density constraint (frag.)')
    1334              :                ELSE
    1335              :                   WRITE (output_unit, '(T3,A,T46,A)') &
    1336          588 :                      'Type of constraint          :', ADJUSTR('Alpha spin density constraint')
    1337              :                END IF
    1338              :             CASE (cdft_beta_constraint)
    1339          588 :                IF (cdft_control%group(igroup)%is_fragment_constraint) THEN
    1340              :                   WRITE (output_unit, '(T3,A,T39,A)') &
    1341            0 :                      'Type of constraint          :', ADJUSTR('Beta spin density constraint (frag.)')
    1342              :                ELSE
    1343              :                   WRITE (output_unit, '(T3,A,T47,A)') &
    1344          588 :                      'Type of constraint          :', ADJUSTR('Beta spin density constraint')
    1345              :                END IF
    1346              :             CASE DEFAULT
    1347         2978 :                CPABORT("Unknown constraint type.")
    1348              :             END SELECT
    1349              :             WRITE (output_unit, '(T3,A,T54,(3X,F18.12))') &
    1350         2978 :                'Target value of constraint  :', cdft_control%target(igroup)
    1351              :             WRITE (output_unit, '(T3,A,T54,(3X,F18.12))') &
    1352         2978 :                'Current value of constraint :', cdft_control%value(igroup)
    1353              :             WRITE (output_unit, '(T3,A,T59,(3X,ES13.3))') &
    1354         2978 :                'Deviation from target       :', cdft_control%value(igroup) - cdft_control%target(igroup)
    1355              :             WRITE (output_unit, '(T3,A,T54,(3X,F18.12))') &
    1356         5364 :                'Strength of constraint      :', cdft_control%strength(igroup)
    1357              :          END DO
    1358              :          WRITE (output_unit, '(T3,A)') &
    1359         2386 :             '------------------------------------------------------------------------'
    1360              :       END IF
    1361              : 
    1362         4564 :    END SUBROUTINE qs_scf_cdft_constraint_info
    1363              : 
    1364              : ! **************************************************************************************************
    1365              : !> \brief Print grand canonical SCF information for the current SCF iteration.
    1366              : !> \param output_unit output unit used for SCF program run information
    1367              : !> \param qs_env QS environment
    1368              : !> \param just_energy whether this is an energy-only step
    1369              : ! **************************************************************************************************
    1370           64 :    SUBROUTINE qs_scf_gce_info(output_unit, qs_env, just_energy)
    1371              : 
    1372              :       INTEGER, INTENT(IN)                                :: output_unit
    1373              :       TYPE(qs_environment_type), POINTER                 :: qs_env
    1374              :       LOGICAL, INTENT(IN)                                :: just_energy
    1375              : 
    1376              :       REAL(KIND=dp)                                      :: charge, current_wf_ev, delta_wf_ev, &
    1377              :                                                             free_ener, target_wf_ev
    1378              :       TYPE(dft_control_type), POINTER                    :: dft_control
    1379              : 
    1380           64 :       IF (output_unit <= 0) RETURN
    1381           32 :       IF (just_energy) RETURN
    1382              : 
    1383           32 :       current_wf_ev = qs_env%scf_control%gce%prev_workfunction*evolt
    1384           32 :       target_wf_ev = qs_env%scf_control%gce%target_workfunction*evolt
    1385           32 :       delta_wf_ev = current_wf_ev - target_wf_ev
    1386              : 
    1387           32 :       CALL get_qs_env(qs_env, dft_control=dft_control)
    1388           32 :       charge = dft_control%pcc_control%charge
    1389           32 :       free_ener = (charge + dft_control%charge)*qs_env%scf_control%gce%prev_workfunction
    1390              : 
    1391              :       WRITE (UNIT=output_unit, &
    1392              :              FMT="(T8,A,T13,A,T24,A,T27,F6.1,A,T40,A,T56,A,T59,ES10.2,A)") &
    1393           32 :          "GCE", "WF", "=", current_wf_ev, " eV", &
    1394           64 :          "WF-TWF", "=", delta_wf_ev, " eV"
    1395              : 
    1396              :       WRITE (UNIT=output_unit, &
    1397              :              FMT="(T13,A,T24,A,T27,F7.3,A,T40,A,T56,A,T59,F14.10,A)") &
    1398           32 :          "Charge", "=", charge, " e", &
    1399           64 :          "GCE free energy", "=", free_ener, " a.u."
    1400              : 
    1401              :    END SUBROUTINE qs_scf_gce_info
    1402              : 
    1403              : END MODULE qs_scf_output
        

Generated by: LCOV version 2.0-1