LCOV - code coverage report
Current view: top level - src - scf_control_types.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:2fce0f8) Lines: 283 293 96.6 %
Date: 2024-12-21 06:28:57 Functions: 7 10 70.0 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------------------------!
       2             : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3             : !   Copyright 2000-2024 CP2K developers group <https://cp2k.org>                                   !
       4             : !                                                                                                  !
       5             : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6             : !--------------------------------------------------------------------------------------------------!
       7             : 
       8             : ! **************************************************************************************************
       9             : !> \brief parameters that control an scf iteration
      10             : !> \note
      11             : !>       not in cp_control_types, to separate operator related parameters from
      12             : !>       method related parameters (as suggested by Matthias)
      13             : !> \par History
      14             : !>      09.2002 created [fawzi]
      15             : !> \author Fawzi Mohamed
      16             : ! **************************************************************************************************
      17             : MODULE scf_control_types
      18             : 
      19             :    USE cp_log_handling,                 ONLY: cp_get_default_logger,&
      20             :                                               cp_logger_type
      21             :    USE cp_output_handling,              ONLY: cp_print_key_finished_output,&
      22             :                                               cp_print_key_unit_nr
      23             :    USE cp_units,                        ONLY: cp_unit_from_cp2k
      24             :    USE input_constants,                 ONLY: &
      25             :         atomic_guess, diag_ot, direct_p_mix, general_roks, high_spin_roks, no_guess, no_mix, &
      26             :         ot_algo_taylor_or_diag, outer_scf_basis_center_opt, outer_scf_cdft_constraint, &
      27             :         outer_scf_ddapc_constraint, outer_scf_none, outer_scf_optimizer_bisect, &
      28             :         outer_scf_optimizer_broyden, outer_scf_optimizer_diis, outer_scf_optimizer_newton, &
      29             :         outer_scf_optimizer_newton_ls, outer_scf_optimizer_none, outer_scf_optimizer_sd, &
      30             :         outer_scf_optimizer_secant, outer_scf_s2_constraint, smear_energy_window, &
      31             :         smear_fermi_dirac, smear_list
      32             :    USE input_cp2k_scf,                  ONLY: create_scf_section
      33             :    USE input_enumeration_types,         ONLY: enum_i2c,&
      34             :                                               enumeration_type
      35             :    USE input_keyword_types,             ONLY: keyword_get,&
      36             :                                               keyword_type
      37             :    USE input_section_types,             ONLY: section_get_keyword,&
      38             :                                               section_release,&
      39             :                                               section_type,&
      40             :                                               section_vals_get,&
      41             :                                               section_vals_get_subs_vals,&
      42             :                                               section_vals_type,&
      43             :                                               section_vals_val_get
      44             :    USE kinds,                           ONLY: dp
      45             :    USE outer_scf_control_types,         ONLY: outer_scf_control_type,&
      46             :                                               outer_scf_read_parameters
      47             :    USE qs_cdft_opt_types,               ONLY: cdft_opt_type_release
      48             :    USE qs_ot_types,                     ONLY: ot_readwrite_input,&
      49             :                                               qs_ot_settings_init,&
      50             :                                               qs_ot_settings_type
      51             : #include "./base/base_uses.f90"
      52             : 
      53             :    IMPLICIT NONE
      54             : 
      55             :    PRIVATE
      56             : 
      57             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'scf_control_types'
      58             :    LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .TRUE.
      59             : 
      60             :    ! Public data types
      61             : 
      62             :    PUBLIC :: scf_control_type, &
      63             :              smear_type
      64             : 
      65             :    ! Public subroutines
      66             : 
      67             :    PUBLIC :: scf_c_create, &
      68             :              scf_c_read_parameters, &
      69             :              scf_c_release, &
      70             :              scf_c_write_parameters
      71             : 
      72             : ! **************************************************************************************************
      73             : !> \brief contains the parameters needed by a scf run
      74             : !> \param density_guess how to choose the initial density
      75             : !>        (CORE,RANDOM,RESTART,ATOMIC,FROZEN)
      76             : !> \param eps_eigval wanted error on the eigenvalues
      77             : !> \param eps_scf whanted error on the whole scf
      78             : !> \param level_shift amount of level shift
      79             : !> \param p_mix how to mix the new and old densities in non diss iterations
      80             : !> \param eps_lumos error on the lumos calculated at the end of the scf
      81             : !> \param max_iter_lumus maxumum number of iterations used to calculate
      82             : !>        the lumos at the end of the scf
      83             : !> \param max_scf max scf iterations
      84             : !> \param added_mos additional number of MOs that might be used in the SCF
      85             : !> \param step_size the optimizer step size
      86             : !> \param cdft_opt_control settings for optimizers that work only together with CDFT constraints
      87             : !> \par History
      88             : !>      09.2002 created [fawzi]
      89             : !> \author Fawzi Mohamed
      90             : ! **************************************************************************************************
      91             :    TYPE smear_type
      92             :       LOGICAL                               :: do_smear = .FALSE.
      93             :       LOGICAL                               :: common_mu = .FALSE.
      94             :       INTEGER                               :: method = -1
      95             :       REAL(KIND=dp)                         :: electronic_temperature = -1.0_dp, &
      96             :                                                fixed_mag_mom = -1.0_dp, &
      97             :                                                eps_fermi_dirac = -1.0_dp, &
      98             :                                                window_size = -1.0_dp
      99             :       REAL(KIND=dp), DIMENSION(:), POINTER  :: list => NULL()
     100             :    END TYPE smear_type
     101             : 
     102             :    TYPE diagonalization_type
     103             :       INTEGER                               :: method = -1
     104             :       REAL(KIND=dp)                         :: eps_jacobi = -1.0_dp
     105             :       REAL(KIND=dp)                         :: jacobi_threshold = -1.0_dp
     106             :       INTEGER                               :: max_iter = -1, nkrylov = -1, nblock_krylov = -1
     107             :       ! Maximum Overlap Method
     108             :       LOGICAL                               :: mom = .FALSE., mom_didguess = .FALSE.
     109             :       INTEGER                               :: mom_proj_formula = -1
     110             :       ! indices of de-occupied and newly occupied alpha / beta molecular orbitals
     111             :       INTEGER, DIMENSION(:), POINTER        :: mom_deoccA => NULL(), mom_deoccB => NULL(), &
     112             :                                                mom_occA => NULL(), mom_occB => NULL()
     113             :       ! determines on SCF which iteration MOM will be switched on;
     114             :       ! since MOs from the previous iteration should be available, it might be at least
     115             :       !  1 when wave-function has been read from restart file, or
     116             :       !  2 when the atomic guess method has been used
     117             :       INTEGER                               :: mom_start = -1
     118             :       INTEGER                               :: mom_type = -1
     119             :       REAL(KIND=dp)                         :: eps_iter = -1.0_dp
     120             :       REAL(KIND=dp)                         :: eps_adapt = -1.0_dp
     121             :       TYPE(qs_ot_settings_type)             :: ot_settings = qs_ot_settings_type()
     122             :    END TYPE diagonalization_type
     123             : 
     124             :    TYPE scf_control_type
     125             :       TYPE(outer_scf_control_type)          :: outer_scf = outer_scf_control_type()
     126             :       TYPE(smear_type), POINTER             :: smear => NULL()
     127             :       TYPE(diagonalization_type)            :: diagonalization = diagonalization_type()
     128             :       INTEGER                               :: density_guess = -1, mixing_method = -1
     129             :       REAL(KIND=dp)                         :: eps_eigval = -1.0_dp, eps_scf = -1.0_dp, eps_scf_hist = -1.0_dp, &
     130             :                                                level_shift = -1.0_dp, &
     131             :                                                eps_lumos = -1.0_dp, eps_diis = -1.0_dp
     132             :       INTEGER                               :: max_iter_lumos = -1, max_diis = -1, nmixing = -1
     133             :       INTEGER                               :: max_scf = -1, max_scf_hist = -1, &
     134             :                                                maxl = -1, nkind = -1
     135             :       LOGICAL                               :: do_diag_sub = .FALSE., &
     136             :                                                use_cholesky = .FALSE., use_ot = .FALSE., &
     137             :                                                use_diag = .FALSE., do_outer_scf_reortho = .FALSE., &
     138             :                                                ignore_convergence_failure = .FALSE.
     139             :       LOGICAL                               :: force_scf_calculation = .FALSE.
     140             :       LOGICAL                               :: non_selfconsistent = .FALSE.
     141             :       INTEGER, DIMENSION(2)                 :: added_mos = -1
     142             :       INTEGER                               :: roks_scheme = -1
     143             :       REAL(KIND=dp)                         :: roks_f = -1.0_dp
     144             :       REAL(KIND=dp), DIMENSION(0:2, 0:2, 1:2) :: roks_parameter = -1.0_dp
     145             :    END TYPE scf_control_type
     146             : 
     147             : CONTAINS
     148             : 
     149             : ! **************************************************************************************************
     150             : !> \brief allocates and initializes an scf control object with the default values
     151             : !> \param scf_control the object to initialize
     152             : !> \par History
     153             : !>      09.2002 created [fawzi]
     154             : !>      - Default ROKS parameters added (05.04.06,MK)
     155             : !> \author Fawzi Mohamed
     156             : ! **************************************************************************************************
     157        7376 :    SUBROUTINE scf_c_create(scf_control)
     158             : 
     159             :       TYPE(scf_control_type), INTENT(INOUT)              :: scf_control
     160             : 
     161             :       CHARACTER(LEN=*), PARAMETER                        :: routineN = 'scf_c_create'
     162             : 
     163             :       INTEGER                                            :: handle
     164             : 
     165        7376 :       CALL timeset(routineN, handle)
     166             : 
     167             :       ! Load the default values
     168             : 
     169        7376 :       IF (scf_control%non_selfconsistent) THEN
     170         724 :          scf_control%density_guess = no_guess
     171             :       ELSE
     172        6652 :          scf_control%density_guess = atomic_guess
     173             :       END IF
     174        7376 :       scf_control%eps_eigval = 1.0E-5_dp
     175        7376 :       scf_control%eps_scf = 1.0E-5_dp
     176        7376 :       scf_control%eps_scf_hist = 0.0_dp
     177        7376 :       scf_control%eps_lumos = 1.0E-5_dp
     178        7376 :       scf_control%max_iter_lumos = 2999
     179        7376 :       scf_control%eps_diis = 0.1_dp
     180        7376 :       scf_control%level_shift = 0.0_dp
     181        7376 :       scf_control%max_diis = 4
     182        7376 :       scf_control%max_scf = 50
     183        7376 :       scf_control%nmixing = 2
     184        7376 :       scf_control%use_cholesky = .TRUE.
     185        7376 :       scf_control%use_diag = .TRUE.
     186        7376 :       scf_control%do_diag_sub = .FALSE.
     187        7376 :       scf_control%use_ot = .FALSE.
     188        7376 :       scf_control%ignore_convergence_failure = .FALSE.
     189        7376 :       scf_control%force_scf_calculation = .FALSE.
     190        7376 :       scf_control%do_outer_scf_reortho = .TRUE.
     191             :       scf_control%max_diis = 4
     192             :       scf_control%eps_diis = 0.1_dp
     193       22128 :       scf_control%added_mos(:) = 0
     194        7376 :       scf_control%max_scf_hist = 0
     195             : 
     196             :       !Mixing
     197        7376 :       IF (scf_control%non_selfconsistent) THEN
     198         724 :          scf_control%mixing_method = no_mix
     199             :       ELSE
     200        6652 :          scf_control%mixing_method = direct_p_mix
     201             :       END IF
     202             : 
     203             :       ! Diagonalization
     204        7376 :       scf_control%diagonalization%method = 0
     205        7376 :       scf_control%diagonalization%eps_jacobi = 0.0_dp
     206        7376 :       scf_control%diagonalization%jacobi_threshold = 1.0E-7_dp
     207        7376 :       scf_control%diagonalization%max_iter = 0
     208        7376 :       scf_control%diagonalization%eps_iter = 0.0_dp
     209        7376 :       scf_control%diagonalization%eps_adapt = 0.0_dp
     210        7376 :       scf_control%diagonalization%nkrylov = 0
     211        7376 :       scf_control%diagonalization%nblock_krylov = 0
     212        7376 :       CALL qs_ot_settings_init(scf_control%diagonalization%ot_settings)
     213             : 
     214        7376 :       scf_control%diagonalization%mom = .FALSE.
     215        7376 :       scf_control%diagonalization%mom_didguess = .FALSE.
     216        7376 :       scf_control%diagonalization%mom_proj_formula = 0
     217        7376 :       NULLIFY (scf_control%diagonalization%mom_deoccA)
     218        7376 :       NULLIFY (scf_control%diagonalization%mom_deoccB)
     219        7376 :       NULLIFY (scf_control%diagonalization%mom_occA)
     220        7376 :       NULLIFY (scf_control%diagonalization%mom_occB)
     221        7376 :       scf_control%diagonalization%mom_start = 0
     222             : 
     223             :       ! ROKS
     224             : 
     225        7376 :       scf_control%roks_scheme = high_spin_roks
     226        7376 :       scf_control%roks_f = 0.5_dp
     227             : 
     228             :       ! Initialize the diagonal blocks with the default ROKS parameters
     229             :       ! 0 = v)irtual, 1 = o)pen shell, 2 = c)losed shell
     230             : 
     231        7376 :       scf_control%roks_parameter(0, 0, 1) = 1.5_dp ! avv
     232        7376 :       scf_control%roks_parameter(0, 0, 2) = -0.5_dp ! bvv
     233        7376 :       scf_control%roks_parameter(1, 1, 1) = 0.5_dp ! aoo
     234        7376 :       scf_control%roks_parameter(1, 1, 2) = 0.5_dp ! boo
     235        7376 :       scf_control%roks_parameter(2, 2, 1) = -0.5_dp ! acc
     236        7376 :       scf_control%roks_parameter(2, 2, 2) = 1.5_dp ! bcc
     237             : 
     238             :       ! Initialize off-diagonal blocks (fixed)
     239             : 
     240        7376 :       scf_control%roks_parameter(0, 1, 1) = 1.0_dp ! avo
     241        7376 :       scf_control%roks_parameter(0, 1, 2) = 0.0_dp ! bvo
     242        7376 :       scf_control%roks_parameter(0, 2, 1) = 0.5_dp ! avc
     243        7376 :       scf_control%roks_parameter(0, 2, 2) = 0.5_dp ! bvc
     244        7376 :       scf_control%roks_parameter(1, 2, 1) = 0.0_dp ! aoc
     245        7376 :       scf_control%roks_parameter(1, 2, 2) = 1.0_dp ! boc
     246             : 
     247             :       ! Symmetry enforces
     248             : 
     249        7376 :       scf_control%roks_parameter(1, 0, 1) = scf_control%roks_parameter(0, 1, 1) ! aov
     250        7376 :       scf_control%roks_parameter(1, 0, 2) = scf_control%roks_parameter(0, 1, 2) ! bov
     251        7376 :       scf_control%roks_parameter(2, 0, 1) = scf_control%roks_parameter(0, 2, 1) ! acv
     252        7376 :       scf_control%roks_parameter(2, 0, 2) = scf_control%roks_parameter(0, 2, 2) ! bcv
     253        7376 :       scf_control%roks_parameter(2, 1, 1) = scf_control%roks_parameter(1, 2, 1) ! aco
     254        7376 :       scf_control%roks_parameter(2, 1, 2) = scf_control%roks_parameter(1, 2, 2) ! bco
     255             : 
     256             :       ! Outer SCF default settings
     257             : 
     258        7376 :       scf_control%outer_scf%have_scf = .FALSE.
     259        7376 :       scf_control%outer_scf%max_scf = 0
     260        7376 :       scf_control%outer_scf%eps_scf = 0.0_dp
     261        7376 :       scf_control%outer_scf%step_size = 0.0_dp
     262        7376 :       scf_control%outer_scf%type = -1
     263        7376 :       scf_control%outer_scf%optimizer = -1
     264        7376 :       scf_control%outer_scf%diis_buffer_length = -1
     265        7376 :       NULLIFY (scf_control%outer_scf%cdft_opt_control)
     266             : 
     267             :       ! Smearing of the MO occupations
     268             : 
     269        7376 :       NULLIFY (scf_control%smear)
     270             : 
     271        7376 :       CALL timestop(handle)
     272             : 
     273        7376 :    END SUBROUTINE scf_c_create
     274             : 
     275             : ! **************************************************************************************************
     276             : !> \brief releases the given scf_control (see cp2k/doc/ReferenceCounting.html)
     277             : !> \param scf_control the object to free
     278             : !> \par History
     279             : !>      09.2002 created [fawzi]
     280             : !> \author Fawzi Mohamed
     281             : !> \note
     282             : !>      at the moment does nothing
     283             : ! **************************************************************************************************
     284        7376 :    SUBROUTINE scf_c_release(scf_control)
     285             : 
     286             :       TYPE(scf_control_type), INTENT(INOUT)              :: scf_control
     287             : 
     288        7376 :       IF (ASSOCIATED(scf_control%smear%list)) THEN
     289           2 :          DEALLOCATE (scf_control%smear%list)
     290             :       END IF
     291        7376 :       DEALLOCATE (scf_control%smear)
     292             : 
     293        7376 :       IF (ASSOCIATED(scf_control%outer_scf%cdft_opt_control)) &
     294          70 :          CALL cdft_opt_type_release(scf_control%outer_scf%cdft_opt_control)
     295             : 
     296             :       ! Maximum overlap method orbital indices lists
     297             :       ! mom_deoccA, mom_deoccB, mom_occA, mom_occB
     298             :       ! points to memory allocated by input file parser,
     299             :       ! so they do not have to be deallocated
     300             : 
     301        7376 :    END SUBROUTINE scf_c_release
     302             : 
     303             : ! **************************************************************************************************
     304             : !> \brief reads the parameters of the scf section into the given scf_control
     305             : !> \param scf_control the object that wil contain the values read
     306             : !> \param inp_section ...
     307             : !> \par History
     308             : !>      05.2001 created [Matthias]
     309             : !>      09.2002 creaded separated scf_control type [fawzi]
     310             : !> \author Matthias Krack
     311             : ! **************************************************************************************************
     312       29504 :    SUBROUTINE scf_c_read_parameters(scf_control, inp_section)
     313             : 
     314             :       TYPE(scf_control_type), INTENT(INOUT)              :: scf_control
     315             :       TYPE(section_vals_type), POINTER                   :: inp_section
     316             : 
     317             :       CHARACTER(LEN=*), PARAMETER :: routineN = 'scf_c_read_parameters'
     318             : 
     319             :       INTEGER                                            :: cholesky_flag, handle, ialgo
     320        7376 :       INTEGER, DIMENSION(:), POINTER                     :: added_mos
     321             :       LOGICAL                                            :: do_mixing
     322        7376 :       REAL(KIND=dp), DIMENSION(:), POINTER               :: roks_parameter
     323             :       TYPE(section_vals_type), POINTER                   :: mixing_section, outer_scf_section, &
     324             :                                                             scf_section, smear_section
     325             : 
     326        7376 :       CALL timeset(routineN, handle)
     327             : 
     328        7376 :       scf_section => section_vals_get_subs_vals(inp_section, "SCF")
     329             :       CALL section_vals_val_get(scf_section, "DIAGONALIZATION%_SECTION_PARAMETERS_", &
     330        7376 :                                 l_val=scf_control%use_diag)
     331        7376 :       IF (scf_control%use_diag) THEN
     332             :          CALL section_vals_val_get(scf_section, "DIAGONALIZATION%DIAG_SUB_SCF%_SECTION_PARAMETERS_", &
     333         208 :                                    l_val=scf_control%do_diag_sub)
     334             :       END IF
     335        7376 :       CALL section_vals_val_get(scf_section, "OT%_SECTION_PARAMETERS_", l_val=scf_control%use_ot)
     336        7376 :       IF (scf_control%use_diag .AND. scf_control%use_ot) THEN
     337             :          ! don't allow both options to be true
     338           0 :          CPABORT("Don't activate OT and Diagonaliztion together")
     339        7376 :       ELSEIF (.NOT. (scf_control%use_diag .OR. scf_control%use_ot)) THEN
     340             :          ! set default to diagonalization
     341        5164 :          scf_control%use_diag = .TRUE.
     342             :       END IF
     343        7376 :       CALL section_vals_val_get(scf_section, "OT%ALGORITHM", i_val=ialgo)
     344        7376 :       scf_control%do_outer_scf_reortho = ialgo .EQ. ot_algo_taylor_or_diag
     345        7376 :       CALL section_vals_val_get(scf_section, "SCF_GUESS", i_val=scf_control%density_guess)
     346        7376 :       CALL section_vals_val_get(scf_section, "EPS_DIIS", r_val=scf_control%eps_diis)
     347        7376 :       CALL section_vals_val_get(scf_section, "eps_eigval", r_val=scf_control%eps_eigval)
     348        7376 :       CALL section_vals_val_get(scf_section, "cholesky", i_val=cholesky_flag)
     349        7376 :       IF (cholesky_flag > 0) THEN
     350        7324 :          scf_control%use_cholesky = .TRUE.
     351             :       END IF
     352        7376 :       CALL section_vals_val_get(scf_section, "IGNORE_CONVERGENCE_FAILURE", l_val=scf_control%ignore_convergence_failure)
     353        7376 :       CALL section_vals_val_get(scf_section, "FORCE_SCF_CALCULATION", l_val=scf_control%force_scf_calculation)
     354        7376 :       CALL section_vals_val_get(scf_section, "eps_scf", r_val=scf_control%eps_scf)
     355        7376 :       CALL section_vals_val_get(scf_section, "level_shift", r_val=scf_control%level_shift)
     356        7376 :       CALL section_vals_val_get(scf_section, "max_diis", i_val=scf_control%max_diis)
     357        7376 :       CALL section_vals_val_get(scf_section, "max_scf", i_val=scf_control%max_scf)
     358             : 
     359             :       ! Diagonaliztion section
     360        7376 :       IF (scf_control%use_diag) THEN
     361             :          CALL section_vals_val_get(scf_section, "DIAGONALIZATION%ALGORITHM", &
     362        5372 :                                    i_val=scf_control%diagonalization%method)
     363             :          CALL section_vals_val_get(scf_section, "DIAGONALIZATION%EPS_JACOBI", &
     364        5372 :                                    r_val=scf_control%diagonalization%eps_jacobi)
     365             :          CALL section_vals_val_get(scf_section, "DIAGONALIZATION%JACOBI_THRESHOLD", &
     366        5372 :                                    r_val=scf_control%diagonalization%jacobi_threshold)
     367             :          CALL section_vals_val_get(scf_section, "DIAGONALIZATION%MAX_ITER", &
     368        5372 :                                    i_val=scf_control%diagonalization%max_iter)
     369             :          CALL section_vals_val_get(scf_section, "DIAGONALIZATION%EPS_ITER", &
     370        5372 :                                    r_val=scf_control%diagonalization%eps_iter)
     371             :          CALL section_vals_val_get(scf_section, "DIAGONALIZATION%EPS_ADAPT", &
     372        5372 :                                    r_val=scf_control%diagonalization%eps_adapt)
     373             :          CALL section_vals_val_get(scf_section, "DIAGONALIZATION%KRYLOV%NKRYLOV", &
     374        5372 :                                    i_val=scf_control%diagonalization%nkrylov)
     375             :          CALL section_vals_val_get(scf_section, "DIAGONALIZATION%KRYLOV%NBLOCK", &
     376        5372 :                                    i_val=scf_control%diagonalization%nblock_krylov)
     377        5372 :          IF (scf_control%diagonalization%method == diag_ot) THEN
     378             :             ! read OT section
     379           8 :             CALL ot_diag_read_input(scf_control%diagonalization%ot_settings, scf_section)
     380             :          END IF
     381             :          ! read maximum overlap method's parameters
     382             :          CALL section_vals_val_get(scf_section, "MOM%_SECTION_PARAMETERS_", &
     383        5372 :                                    l_val=scf_control%diagonalization%MOM)
     384        5372 :          IF (scf_control%diagonalization%mom) THEN
     385             :             CALL section_vals_val_get(scf_section, "MOM%MOM_TYPE", &
     386          20 :                                       i_val=scf_control%diagonalization%mom_type)
     387             : 
     388             :             CALL section_vals_val_get(scf_section, "MOM%START_ITER", &
     389          20 :                                       i_val=scf_control%diagonalization%mom_start)
     390             : 
     391             :             CALL section_vals_val_get(scf_section, "MOM%DEOCC_ALPHA", &
     392          20 :                                       i_vals=scf_control%diagonalization%mom_deoccA)
     393             : 
     394             :             CALL section_vals_val_get(scf_section, "MOM%DEOCC_BETA", &
     395          20 :                                       i_vals=scf_control%diagonalization%mom_deoccB)
     396             : 
     397             :             CALL section_vals_val_get(scf_section, "MOM%OCC_ALPHA", &
     398          20 :                                       i_vals=scf_control%diagonalization%mom_occA)
     399             : 
     400             :             CALL section_vals_val_get(scf_section, "MOM%OCC_BETA", &
     401          20 :                                       i_vals=scf_control%diagonalization%mom_occB)
     402             : 
     403             :             CALL section_vals_val_get(scf_section, "MOM%PROJ_FORMULA", &
     404          20 :                                       i_val=scf_control%diagonalization%mom_proj_formula)
     405             :          END IF
     406             :       END IF
     407             : 
     408             :       ! Read ROKS parameters
     409        7376 :       CALL section_vals_val_get(scf_section, "ROKS_SCHEME", i_val=scf_control%roks_scheme)
     410             : 
     411        7376 :       SELECT CASE (scf_control%roks_scheme)
     412             :       CASE (general_roks)
     413             :          ! Read parameters for the general ROKS scheme
     414           0 :          CALL section_vals_val_get(scf_section, "ROKS_F", r_val=scf_control%roks_f)
     415             :       CASE (high_spin_roks)
     416             :          ! Read high-spin ROKS parameters for the diagonal block
     417             :          ! 0 = v)irtual, 1 = o)pen shell, 2 = c)losed shell
     418        7376 :          NULLIFY (roks_parameter)
     419        7376 :          CALL section_vals_val_get(scf_section, "ROKS_PARAMETERS", r_vals=roks_parameter)
     420       14752 :          IF (ASSOCIATED(roks_parameter)) THEN
     421        7376 :             scf_control%roks_parameter(2, 2, 1) = roks_parameter(1) ! acc
     422        7376 :             scf_control%roks_parameter(2, 2, 2) = roks_parameter(2) ! bcc
     423        7376 :             scf_control%roks_parameter(1, 1, 1) = roks_parameter(3) ! aoo
     424        7376 :             scf_control%roks_parameter(1, 1, 2) = roks_parameter(4) ! boo
     425        7376 :             scf_control%roks_parameter(0, 0, 1) = roks_parameter(5) ! avv
     426        7376 :             scf_control%roks_parameter(0, 0, 2) = roks_parameter(6) ! bvv
     427             :          END IF
     428             :       END SELECT
     429             : 
     430             :       ! should be moved to printkey
     431        7376 :       CALL section_vals_val_get(scf_section, "eps_lumo", r_val=scf_control%eps_lumos)
     432        7376 :       CALL section_vals_val_get(scf_section, "max_iter_lumo", i_val=scf_control%max_iter_lumos)
     433             : 
     434             :       ! Extra MOs, e.g. for smearing
     435        7376 :       CALL section_vals_val_get(scf_section, "added_mos", i_vals=added_mos)
     436        7376 :       CPASSERT(ASSOCIATED(added_mos))
     437        7376 :       IF (SIZE(added_mos) > 0) THEN
     438        7376 :          scf_control%added_mos(1) = added_mos(1)
     439        7376 :          IF (SIZE(added_mos) > 1) THEN
     440         914 :             scf_control%added_mos(2) = added_mos(2)
     441             :          END IF
     442             :       END IF
     443             : 
     444        7376 :       CALL section_vals_val_get(scf_section, "max_scf_history", i_val=scf_control%max_scf_hist)
     445        7376 :       CALL section_vals_val_get(scf_section, "eps_scf_history", r_val=scf_control%eps_scf_hist)
     446             : 
     447        7376 :       IF (scf_control%level_shift /= 0.0_dp) scf_control%use_cholesky = .FALSE.
     448             : 
     449             :       ! Outer SCF subsection
     450        7376 :       outer_scf_section => section_vals_get_subs_vals(scf_section, "OUTER_SCF")
     451        7376 :       CALL outer_scf_read_parameters(scf_control%outer_scf, outer_scf_section)
     452             : 
     453        7376 :       smear_section => section_vals_get_subs_vals(scf_section, "SMEAR")
     454        7376 :       CALL init_smear(scf_control%smear)
     455        7376 :       CALL read_smear_section(scf_control%smear, smear_section)
     456             : 
     457             :       do_mixing = .FALSE.
     458        7376 :       mixing_section => section_vals_get_subs_vals(scf_section, "MIXING")
     459             :       CALL section_vals_val_get(mixing_section, "_SECTION_PARAMETERS_", &
     460        7376 :                                 l_val=do_mixing)
     461        7376 :       IF (do_mixing) THEN
     462             :          CALL section_vals_val_get(mixing_section, "METHOD", &
     463        7376 :                                    i_val=scf_control%mixing_method)
     464        7376 :          CALL section_vals_val_get(mixing_section, "NMIXING", i_val=scf_control%nmixing)
     465             :       END IF ! do mixing
     466             : 
     467        7376 :       CALL timestop(handle)
     468             : 
     469        7376 :    END SUBROUTINE scf_c_read_parameters
     470             : 
     471             : ! **************************************************************************************************
     472             : !> \brief ...
     473             : !> \param smear ...
     474             : ! **************************************************************************************************
     475        7376 :    SUBROUTINE init_smear(smear)
     476             :       TYPE(smear_type), POINTER                          :: smear
     477             : 
     478        7376 :       CPASSERT(.NOT. ASSOCIATED(smear))
     479        7376 :       ALLOCATE (smear)
     480             :       smear%do_smear = .FALSE.
     481        7376 :       smear%method = smear_energy_window
     482        7376 :       smear%electronic_temperature = 0.0_dp
     483        7376 :       smear%eps_fermi_dirac = 1.0E-5_dp
     484        7376 :       smear%fixed_mag_mom = -100.0_dp
     485        7376 :       smear%window_size = 0.0_dp
     486             :       NULLIFY (smear%list)
     487        7376 :    END SUBROUTINE init_smear
     488             : 
     489             : ! **************************************************************************************************
     490             : !> \brief ...
     491             : !> \param smear ...
     492             : !> \param smear_section ...
     493             : ! **************************************************************************************************
     494        7376 :    SUBROUTINE read_smear_section(smear, smear_section)
     495             :       TYPE(smear_type), POINTER                          :: smear
     496             :       TYPE(section_vals_type), POINTER                   :: smear_section
     497             : 
     498        7376 :       REAL(KIND=dp), DIMENSION(:), POINTER               :: r_vals
     499             : 
     500        7376 :       NULLIFY (r_vals)
     501             : 
     502             :       CALL section_vals_val_get(smear_section, "_SECTION_PARAMETERS_", &
     503        7376 :                                 l_val=smear%do_smear)
     504        7376 :       IF (smear%do_smear) THEN
     505             :          CALL section_vals_val_get(smear_section, "METHOD", &
     506         898 :                                    i_val=smear%method)
     507             :          CALL section_vals_val_get(smear_section, "ELECTRONIC_TEMPERATURE", &
     508         898 :                                    r_val=smear%electronic_temperature)
     509             :          CALL section_vals_val_get(smear_section, "EPS_FERMI_DIRAC", &
     510         898 :                                    r_val=smear%eps_fermi_dirac)
     511             :          CALL section_vals_val_get(smear_section, "WINDOW_SIZE", &
     512         898 :                                    r_val=smear%window_size)
     513         898 :          IF (smear%method == smear_list) THEN
     514             :             CALL section_vals_val_get(smear_section, "LIST", &
     515           2 :                                       r_vals=r_vals)
     516           2 :             CPASSERT(ASSOCIATED(r_vals))
     517           6 :             ALLOCATE (smear%list(SIZE(r_vals)))
     518          28 :             smear%list = r_vals
     519             :          END IF
     520             :          CALL section_vals_val_get(smear_section, "FIXED_MAGNETIC_MOMENT", &
     521         898 :                                    r_val=smear%fixed_mag_mom)
     522             :       END IF ! do smear
     523        7376 :    END SUBROUTINE read_smear_section
     524             : 
     525             : ! **************************************************************************************************
     526             : !> \brief writes out the scf parameters
     527             : !> \param scf_control the object you want to print
     528             : !> \param dft_section ...
     529             : !> \par History
     530             : !>      05.2001 created [Matthias]
     531             : !>      09.2002 created separated scf_control type [fawzi]
     532             : !> \author Matthias Krack
     533             : ! **************************************************************************************************
     534        6918 :    SUBROUTINE scf_c_write_parameters(scf_control, dft_section)
     535             : 
     536             :       TYPE(scf_control_type), INTENT(IN)                 :: scf_control
     537             :       TYPE(section_vals_type), POINTER                   :: dft_section
     538             : 
     539             :       CHARACTER(LEN=*), PARAMETER :: routineN = 'scf_c_write_parameters'
     540             : 
     541             :       INTEGER                                            :: handle, output_unit, roks_scheme
     542             :       LOGICAL                                            :: roks
     543             :       REAL(KIND=dp)                                      :: elec_temp
     544             :       TYPE(cp_logger_type), POINTER                      :: logger
     545             :       TYPE(enumeration_type), POINTER                    :: enum
     546             :       TYPE(keyword_type), POINTER                        :: keyword
     547             :       TYPE(section_type), POINTER                        :: section
     548             :       TYPE(section_vals_type), POINTER                   :: scf_section
     549             : 
     550        6918 :       CALL timeset(routineN, handle)
     551             : 
     552        6918 :       NULLIFY (logger)
     553        6918 :       logger => cp_get_default_logger()
     554             : 
     555        6918 :       NULLIFY (scf_section)
     556        6918 :       NULLIFY (section)
     557             : 
     558        6918 :       scf_section => section_vals_get_subs_vals(dft_section, "SCF")
     559             :       output_unit = cp_print_key_unit_nr(logger, scf_section, "PRINT%PROGRAM_RUN_INFO", &
     560        6918 :                                          extension=".scfLog")
     561             : 
     562        6918 :       IF (output_unit > 0) THEN
     563             : 
     564        3482 :          IF (scf_control%max_scf > 0) THEN
     565             : 
     566        3161 :             CALL create_scf_section(section)
     567             : 
     568        3161 :             keyword => section_get_keyword(section, "SCF_GUESS")
     569        3161 :             CALL keyword_get(keyword, enum=enum)
     570             : 
     571        3161 :             IF (.NOT. scf_control%non_selfconsistent .OR. scf_control%force_scf_calculation) THEN
     572             :                WRITE (UNIT=output_unit, &
     573             :                       FMT="(/,/,T2,A,T25,A,T51,A30,/,T25,56('-'),3(/,T25,A,T76,I5),/, "// &
     574             :                       "T25,56('-'),4(/,T25,A,T72,ES9.2),/,T25,56('-'), "// &
     575             :                       "1(/,T25,A,T71,F10.6))") &
     576        2804 :                   "SCF PARAMETERS", &
     577        2804 :                   "Density guess:     ", ADJUSTR(TRIM(enum_i2c(enum, scf_control%density_guess))), &
     578        2804 :                   "max_scf:           ", scf_control%max_scf, &
     579        2804 :                   "max_scf_history:   ", scf_control%max_scf_hist, &
     580        2804 :                   "max_diis:          ", scf_control%max_diis, &
     581        2804 :                   "eps_scf:           ", scf_control%eps_scf, &
     582        2804 :                   "eps_scf_history:   ", scf_control%eps_scf_hist, &
     583        2804 :                   "eps_diis:          ", scf_control%eps_diis, &
     584        2804 :                   "eps_eigval:        ", scf_control%eps_eigval, &
     585        5608 :                   "level_shift [a.u.]:", scf_control%level_shift
     586             :             END IF
     587             : 
     588        9483 :             IF (SUM(ABS(scf_control%added_mos)) > 0) THEN
     589             :                WRITE (UNIT=output_unit, FMT="(T25,A,T71,2I5)") &
     590         609 :                   "added MOs          ", scf_control%added_mos
     591             :             END IF
     592             : 
     593        3161 :             IF (scf_control%diagonalization%mom) THEN
     594             :                ! TODO extend the output with further parameters
     595          10 :                WRITE (UNIT=output_unit, FMT="(T25,A)") "MOM enabled"
     596             :             END IF
     597             : 
     598        3161 :             IF (scf_control%mixing_method > 0 .AND. .NOT. scf_control%use_ot .AND. &
     599             :                 .NOT. scf_control%non_selfconsistent) THEN
     600        1781 :                keyword => section_get_keyword(section, "MIXING%METHOD")
     601        1781 :                CALL keyword_get(keyword, enum=enum)
     602             :                WRITE (UNIT=output_unit, FMT="(T25,A,/,T25,A,T51,A30)") &
     603        1781 :                   REPEAT("-", 56), &
     604        3562 :                   "Mixing method:      ", ADJUSTR(TRIM(enum_i2c(enum, scf_control%mixing_method)))
     605        1781 :                IF (scf_control%mixing_method > 1) THEN
     606          98 :                   WRITE (UNIT=output_unit, FMT="(T47,A34)") "charge density mixing in g-space"
     607             :                END IF
     608             :             END IF
     609        3161 :             IF (scf_control%smear%do_smear) THEN
     610         445 :                keyword => section_get_keyword(section, "SMEAR%METHOD")
     611         445 :                CALL keyword_get(keyword, enum=enum)
     612             :                WRITE (UNIT=output_unit, FMT="(T25,A,/,T25,A,T51,A30)") &
     613         445 :                   REPEAT("-", 56), &
     614         890 :                   "Smear method:      ", ADJUSTR(TRIM(enum_i2c(enum, scf_control%smear%method)))
     615         882 :                SELECT CASE (scf_control%smear%method)
     616             :                CASE (smear_fermi_dirac)
     617             :                   elec_temp = cp_unit_from_cp2k(scf_control%smear%electronic_temperature, &
     618         437 :                                                 "K")
     619             :                   WRITE (UNIT=output_unit, FMT="(T25,A,T61,F20.1)") &
     620         437 :                      "Electronic temperature [K]:", elec_temp
     621             :                   WRITE (UNIT=output_unit, FMT="(T25,A,T71,ES10.2)") &
     622         437 :                      "Electronic temperature [a.u.]:", scf_control%smear%electronic_temperature, &
     623         874 :                      "Accuracy threshold:", scf_control%smear%eps_fermi_dirac
     624         437 :                   IF (scf_control%smear%fixed_mag_mom > 0.0_dp) WRITE (UNIT=output_unit, FMT="(T25,A,F10.5)") &
     625             :                      "Spin channel alpha and spin channel beta are smeared independently, keeping"// &
     626          90 :                      " fixed difference in number of electrons equal to ", scf_control%smear%fixed_mag_mom
     627             :                CASE (smear_energy_window)
     628             :                   WRITE (UNIT=output_unit, FMT="(T25,A,T71,F10.6)") &
     629         445 :                      "Smear window [a.u.]:       ", scf_control%smear%window_size
     630             :                END SELECT
     631             :             END IF
     632             : 
     633        3161 :             CALL section_vals_val_get(dft_section, "ROKS", l_val=roks)
     634        3161 :             IF (roks .AND. (.NOT. scf_control%use_ot)) THEN
     635             :                CALL section_vals_val_get(scf_section, "ROKS_SCHEME", &
     636          18 :                                          i_val=roks_scheme)
     637          18 :                keyword => section_get_keyword(section, "ROKS_SCHEME")
     638          18 :                CALL keyword_get(keyword, enum=enum)
     639             :                WRITE (UNIT=output_unit, FMT="(T25,A,/,T25,A,T51,A30)") &
     640          18 :                   REPEAT("-", 56), &
     641          36 :                   "ROKS scheme:", ADJUSTR(TRIM(enum_i2c(enum, roks_scheme)))
     642           0 :                SELECT CASE (roks_scheme)
     643             :                CASE (general_roks)
     644             :                   WRITE (UNIT=output_unit, FMT="(T25,A,T71,F10.6)") &
     645           0 :                      "ROKS parameter f:", scf_control%roks_f
     646             :                CASE (high_spin_roks)
     647             :                   WRITE (UNIT=output_unit, &
     648             :                          FMT="(T25,A,6(/,T25,A,T71,F10.6))") &
     649          18 :                      "ROKS parameters: a)lpha, b)eta; c)losed, o)pen, v)irtual", &
     650          18 :                      "acc", scf_control%roks_parameter(2, 2, 1), &
     651          18 :                      "bcc", scf_control%roks_parameter(2, 2, 2), &
     652          18 :                      "aoo", scf_control%roks_parameter(1, 1, 1), &
     653          18 :                      "boo", scf_control%roks_parameter(1, 1, 2), &
     654          18 :                      "avv", scf_control%roks_parameter(0, 0, 1), &
     655          36 :                      "bvv", scf_control%roks_parameter(0, 0, 2)
     656             :                END SELECT
     657             :             END IF
     658        3161 :             CALL section_release(section)
     659             : 
     660        3161 :             IF (scf_control%outer_scf%have_scf) THEN
     661         663 :                WRITE (output_unit, "(T25,56('-'),/,T25,A)") "Outer loop SCF in use "
     662        1321 :                SELECT CASE (scf_control%outer_scf%type)
     663             :                CASE (outer_scf_none)
     664         658 :                   WRITE (output_unit, '(T25,A)') "No variables optimised in outer loop"
     665             :                CASE (outer_scf_ddapc_constraint)
     666           5 :                   WRITE (output_unit, '(T25,A)') "DDAPC constraint enforced"
     667             :                CASE (outer_scf_s2_constraint)
     668           0 :                   WRITE (output_unit, '(T25,A)') "S2 constraint enforced"
     669             :                CASE (outer_scf_basis_center_opt)
     670           0 :                   WRITE (output_unit, '(T25,A)') "Floating basis function optimization enforced"
     671             :                CASE (outer_scf_cdft_constraint)
     672           0 :                   CPABORT("CDFT constraints must be defined in QS&CDFT")
     673             :                CASE DEFAULT
     674         663 :                   CPABORT("")
     675             :                END SELECT
     676         663 :                WRITE (output_unit, '(T25,A,T72,ES9.2)') "eps_scf", scf_control%outer_scf%eps_scf
     677         663 :                WRITE (output_unit, '(T25,A,T72,I9)') "max_scf", scf_control%outer_scf%max_scf
     678        1321 :                SELECT CASE (scf_control%outer_scf%optimizer)
     679             :                CASE (outer_scf_optimizer_none)
     680         658 :                   WRITE (output_unit, '(T25,A)') "No outer loop optimization"
     681             :                CASE (outer_scf_optimizer_sd)
     682           2 :                   WRITE (output_unit, '(T25,A)') "Steepest descent optimization"
     683             :                CASE (outer_scf_optimizer_bisect)
     684           1 :                   WRITE (output_unit, '(T25,A)') "Gradient bisection"
     685           1 :                   WRITE (output_unit, '(T25,A,T72,I9)') "bisect_trust_count", scf_control%outer_scf%bisect_trust_count
     686             :                CASE (outer_scf_optimizer_diis)
     687           2 :                   WRITE (output_unit, '(T25,A)') "DIIS optimization"
     688           2 :                   WRITE (output_unit, '(T25,A,T72,I9)') "DIIS buffer length", &
     689           4 :                      scf_control%outer_scf%diis_buffer_length
     690             :                CASE (outer_scf_optimizer_broyden, outer_scf_optimizer_newton, &
     691             :                      outer_scf_optimizer_newton_ls)
     692           0 :                   CPABORT("Selected optimizer only compatible with CDFT")
     693             :                CASE (outer_scf_optimizer_secant)
     694           0 :                   WRITE (output_unit, '(T25,A)') "Optimization with the secant method"
     695             :                CASE DEFAULT
     696         663 :                   CPABORT("")
     697             :                END SELECT
     698         663 :                WRITE (output_unit, '(T25,A,T72,ES9.2)') "step_size", scf_control%outer_scf%step_size
     699             :             ELSE
     700        2498 :                WRITE (output_unit, "(T25,56('-'),/,T25,A)") "No outer SCF"
     701             :             END IF
     702             : 
     703             :          END IF ! max_scf > 0
     704             : 
     705             :       END IF ! output_unit > 0
     706             : 
     707             :       CALL cp_print_key_finished_output(output_unit, logger, scf_section, &
     708        6918 :                                         "PRINT%PROGRAM_RUN_INFO")
     709             : 
     710        6918 :       CALL timestop(handle)
     711             : 
     712        6918 :    END SUBROUTINE scf_c_write_parameters
     713             : 
     714             : ! **************************************************************************************************
     715             : 
     716             : ! **************************************************************************************************
     717             : !> \brief ...
     718             : !> \param settings ...
     719             : !> \param scf_section ...
     720             : ! **************************************************************************************************
     721          16 :    SUBROUTINE ot_diag_read_input(settings, scf_section)
     722             :       TYPE(qs_ot_settings_type)                          :: settings
     723             :       TYPE(section_vals_type), POINTER                   :: scf_section
     724             : 
     725             :       CHARACTER(len=*), PARAMETER :: routineN = 'ot_diag_read_input'
     726             : 
     727             :       INTEGER                                            :: handle, output_unit
     728             :       LOGICAL                                            :: explicit
     729             :       TYPE(cp_logger_type), POINTER                      :: logger
     730             :       TYPE(section_vals_type), POINTER                   :: ot_section
     731             : 
     732           8 :       CALL timeset(routineN, handle)
     733             : 
     734           8 :       logger => cp_get_default_logger()
     735             :       output_unit = cp_print_key_unit_nr(logger, scf_section, "PRINT%PROGRAM_RUN_INFO", &
     736           8 :                                          extension=".log")
     737             : 
     738             :       ! decide default settings
     739           8 :       CALL qs_ot_settings_init(settings)
     740             : 
     741             :       ! use ot input new style
     742           8 :       ot_section => section_vals_get_subs_vals(scf_section, "DIAGONALIZATION%OT")
     743           8 :       CALL section_vals_get(ot_section, explicit=explicit)
     744             : 
     745           8 :       CALL ot_readwrite_input(settings, ot_section, output_unit)
     746             : 
     747             :       CALL cp_print_key_finished_output(output_unit, logger, scf_section, &
     748           8 :                                         "PRINT%PROGRAM_RUN_INFO")
     749             : 
     750           8 :       CALL timestop(handle)
     751             : 
     752           8 :    END SUBROUTINE ot_diag_read_input
     753             : 
     754             : ! **************************************************************************************************
     755             : 
     756           0 : END MODULE scf_control_types

Generated by: LCOV version 1.15