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

Generated by: LCOV version 2.0-1