LCOV - code coverage report
Current view: top level - src - qs_scf_output.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:c24029e) Lines: 94.1 % 544 512
Test Date: 2026-07-04 06:36:57 Functions: 100.0 % 11 11

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

Generated by: LCOV version 2.0-1