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

Generated by: LCOV version 2.0-1