LCOV - code coverage report
Current view: top level - src - cp_control_utils.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:4c33f95) Lines: 1286 1451 88.6 %
Date: 2025-01-30 06:53:08 Functions: 13 13 100.0 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------------------------!
       2             : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3             : !   Copyright 2000-2025 CP2K developers group <https://cp2k.org>                                   !
       4             : !                                                                                                  !
       5             : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6             : !--------------------------------------------------------------------------------------------------!
       7             : 
       8             : ! **************************************************************************************************
       9             : !> \brief Utilities to set up the control types
      10             : ! **************************************************************************************************
      11             : MODULE cp_control_utils
      12             :    USE bibliography,                    ONLY: &
      13             :         Andreussi2012, Dewar1977, Dewar1985, Elstner1998, Fattebert2002, Grimme2017, Hu2007, &
      14             :         Krack2000, Lippert1997, Lippert1999, Porezag1995, Pracht2019, Repasky2002, Rocha2006, &
      15             :         Schenter2008, Seifert1996, Souza2002, Stengel2009, Stewart1989, Stewart2007, Thiel1992, &
      16             :         Umari2002, VanVoorhis2015, VandeVondele2005a, VandeVondele2005b, Yin2017, Zhechkov2005, &
      17             :         cite_reference
      18             :    USE cp_control_types,                ONLY: &
      19             :         admm_control_create, admm_control_type, ddapc_control_create, ddapc_restraint_type, &
      20             :         dft_control_create, dft_control_type, efield_type, expot_control_create, &
      21             :         maxwell_control_create, qs_control_type, tddfpt2_control_type, tddfpt_control_create, &
      22             :         tddfpt_control_type, xtb_control_type
      23             :    USE cp_files,                        ONLY: close_file,&
      24             :                                               open_file
      25             :    USE cp_log_handling,                 ONLY: cp_get_default_logger,&
      26             :                                               cp_logger_type
      27             :    USE cp_output_handling,              ONLY: cp_print_key_finished_output,&
      28             :                                               cp_print_key_unit_nr
      29             :    USE cp_units,                        ONLY: cp_unit_from_cp2k,&
      30             :                                               cp_unit_to_cp2k
      31             :    USE eeq_input,                       ONLY: read_eeq_param
      32             :    USE force_fields_input,              ONLY: read_gp_section
      33             :    USE input_constants,                 ONLY: &
      34             :         admm1_type, admm2_type, admmp_type, admmq_type, admms_type, constant_env, custom_env, &
      35             :         do_admm_aux_exch_func_bee, do_admm_aux_exch_func_bee_libxc, do_admm_aux_exch_func_default, &
      36             :         do_admm_aux_exch_func_default_libxc, do_admm_aux_exch_func_none, &
      37             :         do_admm_aux_exch_func_opt, do_admm_aux_exch_func_opt_libxc, do_admm_aux_exch_func_pbex, &
      38             :         do_admm_aux_exch_func_pbex_libxc, do_admm_aux_exch_func_sx_libxc, &
      39             :         do_admm_basis_projection, do_admm_blocked_projection, do_admm_blocking_purify_full, &
      40             :         do_admm_charge_constrained_projection, do_admm_exch_scaling_merlot, &
      41             :         do_admm_exch_scaling_none, do_admm_purify_cauchy, do_admm_purify_cauchy_subspace, &
      42             :         do_admm_purify_mcweeny, do_admm_purify_mo_diag, do_admm_purify_mo_no_diag, &
      43             :         do_admm_purify_none, do_admm_purify_none_dm, do_ddapc_constraint, do_ddapc_restraint, &
      44             :         do_method_am1, do_method_dftb, do_method_gapw, do_method_gapw_xc, do_method_gpw, &
      45             :         do_method_lrigpw, do_method_mndo, do_method_mndod, do_method_ofgpw, do_method_pdg, &
      46             :         do_method_pm3, do_method_pm6, do_method_pm6fm, do_method_pnnl, do_method_rigpw, &
      47             :         do_method_rm1, do_method_xtb, do_pwgrid_ns_fullspace, do_pwgrid_ns_halfspace, &
      48             :         do_pwgrid_spherical, do_s2_constraint, do_s2_restraint, do_se_is_kdso, do_se_is_kdso_d, &
      49             :         do_se_is_slater, do_se_lr_ewald, do_se_lr_ewald_gks, do_se_lr_ewald_r3, do_se_lr_none, &
      50             :         gapw_1c_large, gapw_1c_medium, gapw_1c_orb, gapw_1c_small, gapw_1c_very_large, &
      51             :         gaussian_env, no_admm_type, numerical, ramp_env, real_time_propagation, sccs_andreussi, &
      52             :         sccs_derivative_cd3, sccs_derivative_cd5, sccs_derivative_cd7, sccs_derivative_fft, &
      53             :         sccs_fattebert_gygi, sic_ad, sic_eo, sic_list_all, sic_list_unpaired, sic_mauri_spz, &
      54             :         sic_mauri_us, sic_none, slater, tddfpt_dipole_length, tddfpt_excitations, &
      55             :         tddfpt_kernel_stda, use_mom_ref_user, xtb_vdw_type_d3, xtb_vdw_type_d4, xtb_vdw_type_none
      56             :    USE input_cp2k_check,                ONLY: xc_functionals_expand
      57             :    USE input_cp2k_dft,                  ONLY: create_dft_section
      58             :    USE input_enumeration_types,         ONLY: enum_i2c,&
      59             :                                               enumeration_type
      60             :    USE input_keyword_types,             ONLY: keyword_get,&
      61             :                                               keyword_type
      62             :    USE input_section_types,             ONLY: &
      63             :         section_get_ival, section_get_keyword, section_release, section_type, section_vals_get, &
      64             :         section_vals_get_subs_vals, section_vals_type, section_vals_val_get, section_vals_val_set
      65             :    USE kinds,                           ONLY: default_path_length,&
      66             :                                               default_string_length,&
      67             :                                               dp
      68             :    USE mathconstants,                   ONLY: fourpi
      69             :    USE pair_potential_types,            ONLY: pair_potential_reallocate
      70             :    USE periodic_table,                  ONLY: get_ptable_info
      71             :    USE qs_cdft_utils,                   ONLY: read_cdft_control_section
      72             :    USE smeagol_control_types,           ONLY: read_smeagol_control
      73             :    USE string_utilities,                ONLY: uppercase
      74             :    USE util,                            ONLY: sort
      75             :    USE xc,                              ONLY: xc_uses_kinetic_energy_density,&
      76             :                                               xc_uses_norm_drho
      77             :    USE xc_input_constants,              ONLY: xc_deriv_collocate
      78             :    USE xc_write_output,                 ONLY: xc_write
      79             : #include "./base/base_uses.f90"
      80             : 
      81             :    IMPLICIT NONE
      82             : 
      83             :    PRIVATE
      84             : 
      85             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cp_control_utils'
      86             : 
      87             :    PUBLIC :: read_dft_control, &
      88             :              read_mgrid_section, &
      89             :              read_qs_section, &
      90             :              read_tddfpt_control, &
      91             :              read_tddfpt2_control, &
      92             :              write_dft_control, &
      93             :              write_qs_control, &
      94             :              write_admm_control, &
      95             :              read_ddapc_section
      96             : CONTAINS
      97             : 
      98             : ! **************************************************************************************************
      99             : !> \brief ...
     100             : !> \param dft_control ...
     101             : !> \param dft_section ...
     102             : ! **************************************************************************************************
     103      110490 :    SUBROUTINE read_dft_control(dft_control, dft_section)
     104             :       TYPE(dft_control_type), POINTER                    :: dft_control
     105             :       TYPE(section_vals_type), POINTER                   :: dft_section
     106             : 
     107             :       CHARACTER(len=default_path_length)                 :: basis_set_file_name, potential_file_name
     108             :       CHARACTER(LEN=default_string_length), &
     109        7366 :          DIMENSION(:), POINTER                           :: tmpstringlist
     110             :       INTEGER                                            :: admmtype, excitations, irep, isize, &
     111             :                                                             method_id, nrep, xc_deriv_method_id
     112             :       LOGICAL                                            :: do_hfx, do_ot, do_rpa_admm, do_rtp, &
     113             :                                                             exopt1, exopt2, exopt3, explicit, &
     114             :                                                             is_present, l_param, not_SE, &
     115             :                                                             was_present
     116             :       REAL(KIND=dp)                                      :: density_cut, gradient_cut, tau_cut
     117        7366 :       REAL(KIND=dp), DIMENSION(:), POINTER               :: pol
     118             :       TYPE(cp_logger_type), POINTER                      :: logger
     119             :       TYPE(section_vals_type), POINTER                   :: hfx_section, maxwell_section, &
     120             :                                                             sccs_section, scf_section, &
     121             :                                                             tmp_section, xc_fun_section, xc_section
     122             : 
     123        7366 :       was_present = .FALSE.
     124             : 
     125        7366 :       logger => cp_get_default_logger()
     126             : 
     127        7366 :       NULLIFY (tmp_section, xc_fun_section, xc_section)
     128        7366 :       ALLOCATE (dft_control)
     129        7366 :       CALL dft_control_create(dft_control)
     130             :       ! determine wheather this is a semiempirical or DFTB run
     131             :       ! --> (no XC section needs to be provided)
     132        7366 :       not_SE = .TRUE.
     133        7366 :       CALL section_vals_val_get(dft_section, "QS%METHOD", i_val=method_id)
     134        2160 :       SELECT CASE (method_id)
     135             :       CASE (do_method_dftb, do_method_xtb, do_method_mndo, do_method_am1, do_method_pm3, do_method_pnnl, &
     136             :             do_method_pm6, do_method_pm6fm, do_method_pdg, do_method_rm1, do_method_mndod)
     137        7366 :          not_SE = .FALSE.
     138             :       END SELECT
     139             :       ! Check for XC section and XC_FUNCTIONAL section
     140        7366 :       xc_section => section_vals_get_subs_vals(dft_section, "XC")
     141        7366 :       CALL section_vals_get(xc_section, explicit=is_present)
     142        7366 :       IF (.NOT. is_present .AND. not_SE) THEN
     143           0 :          CPABORT("XC section missing.")
     144             :       END IF
     145        7366 :       IF (is_present) THEN
     146        5222 :          CALL section_vals_val_get(xc_section, "density_cutoff", r_val=density_cut)
     147        5222 :          CALL section_vals_val_get(xc_section, "gradient_cutoff", r_val=gradient_cut)
     148        5222 :          CALL section_vals_val_get(xc_section, "tau_cutoff", r_val=tau_cut)
     149             :          ! Perform numerical stability checks and possibly correct the issues
     150        5222 :          IF (density_cut <= EPSILON(0.0_dp)*100.0_dp) &
     151             :             CALL cp_warn(__LOCATION__, &
     152             :                          "DENSITY_CUTOFF lower than 100*EPSILON, where EPSILON is the machine precision. "// &
     153           0 :                          "This may lead to numerical problems. Setting up shake_tol to 100*EPSILON! ")
     154        5222 :          density_cut = MAX(EPSILON(0.0_dp)*100.0_dp, density_cut)
     155        5222 :          IF (gradient_cut <= EPSILON(0.0_dp)*100.0_dp) &
     156             :             CALL cp_warn(__LOCATION__, &
     157             :                          "GRADIENT_CUTOFF lower than 100*EPSILON, where EPSILON is the machine precision. "// &
     158           0 :                          "This may lead to numerical problems. Setting up shake_tol to 100*EPSILON! ")
     159        5222 :          gradient_cut = MAX(EPSILON(0.0_dp)*100.0_dp, gradient_cut)
     160        5222 :          IF (tau_cut <= EPSILON(0.0_dp)*100.0_dp) &
     161             :             CALL cp_warn(__LOCATION__, &
     162             :                          "TAU_CUTOFF lower than 100*EPSILON, where EPSILON is the machine precision. "// &
     163           0 :                          "This may lead to numerical problems. Setting up shake_tol to 100*EPSILON! ")
     164        5222 :          tau_cut = MAX(EPSILON(0.0_dp)*100.0_dp, tau_cut)
     165        5222 :          CALL section_vals_val_set(xc_section, "density_cutoff", r_val=density_cut)
     166        5222 :          CALL section_vals_val_set(xc_section, "gradient_cutoff", r_val=gradient_cut)
     167        5222 :          CALL section_vals_val_set(xc_section, "tau_cutoff", r_val=tau_cut)
     168             :       END IF
     169        7366 :       xc_fun_section => section_vals_get_subs_vals(xc_section, "XC_FUNCTIONAL")
     170        7366 :       CALL section_vals_get(xc_fun_section, explicit=is_present)
     171        7366 :       IF (.NOT. is_present .AND. not_SE) THEN
     172           0 :          CPABORT("XC_FUNCTIONAL section missing.")
     173             :       END IF
     174        7366 :       scf_section => section_vals_get_subs_vals(dft_section, "SCF")
     175        7366 :       CALL section_vals_val_get(dft_section, "UKS", l_val=dft_control%uks)
     176        7366 :       CALL section_vals_val_get(dft_section, "ROKS", l_val=dft_control%roks)
     177        7366 :       IF (dft_control%uks .OR. dft_control%roks) THEN
     178        1613 :          dft_control%nspins = 2
     179             :       ELSE
     180        5753 :          dft_control%nspins = 1
     181             :       END IF
     182             : 
     183        7366 :       dft_control%lsd = (dft_control%nspins > 1)
     184        7366 :       dft_control%use_kinetic_energy_density = xc_uses_kinetic_energy_density(xc_fun_section, dft_control%lsd)
     185             : 
     186        7366 :       xc_deriv_method_id = section_get_ival(xc_section, "XC_GRID%XC_DERIV")
     187             :       dft_control%drho_by_collocation = (xc_uses_norm_drho(xc_fun_section, dft_control%lsd) &
     188        7366 :                                          .AND. (xc_deriv_method_id == xc_deriv_collocate))
     189        7366 :       IF (dft_control%drho_by_collocation) THEN
     190           0 :          CPABORT("derivatives by collocation not implemented")
     191             :       END IF
     192             : 
     193             :       ! Automatic auxiliary basis set generation
     194        7366 :       CALL section_vals_val_get(dft_section, "AUTO_BASIS", n_rep_val=nrep)
     195       14732 :       DO irep = 1, nrep
     196        7366 :          CALL section_vals_val_get(dft_section, "AUTO_BASIS", i_rep_val=irep, c_vals=tmpstringlist)
     197       14732 :          IF (SIZE(tmpstringlist) == 2) THEN
     198        7366 :             CALL uppercase(tmpstringlist(2))
     199        7366 :             SELECT CASE (tmpstringlist(2))
     200             :             CASE ("X")
     201          78 :                isize = -1
     202             :             CASE ("SMALL")
     203          78 :                isize = 0
     204             :             CASE ("MEDIUM")
     205          48 :                isize = 1
     206             :             CASE ("LARGE")
     207           0 :                isize = 2
     208             :             CASE ("HUGE")
     209           2 :                isize = 3
     210             :             CASE DEFAULT
     211        7366 :                CPWARN("Unknown basis size in AUTO_BASIS keyword:"//TRIM(tmpstringlist(1)))
     212             :             END SELECT
     213             :             !
     214        7368 :             SELECT CASE (tmpstringlist(1))
     215             :             CASE ("X")
     216             :             CASE ("RI_AUX")
     217           2 :                dft_control%auto_basis_ri_aux = isize
     218             :             CASE ("AUX_FIT")
     219           0 :                dft_control%auto_basis_aux_fit = isize
     220             :             CASE ("LRI_AUX")
     221           0 :                dft_control%auto_basis_lri_aux = isize
     222             :             CASE ("P_LRI_AUX")
     223           0 :                dft_control%auto_basis_p_lri_aux = isize
     224             :             CASE ("RI_HXC")
     225           0 :                dft_control%auto_basis_ri_hxc = isize
     226             :             CASE ("RI_XAS")
     227          48 :                dft_control%auto_basis_ri_xas = isize
     228             :             CASE ("RI_HFX")
     229          78 :                dft_control%auto_basis_ri_hfx = isize
     230             :             CASE DEFAULT
     231        7366 :                CPWARN("Unknown basis type in AUTO_BASIS keyword:"//TRIM(tmpstringlist(1)))
     232             :             END SELECT
     233             :          ELSE
     234             :             CALL cp_abort(__LOCATION__, &
     235           0 :                           "AUTO_BASIS keyword in &DFT section has a wrong number of arguments.")
     236             :          END IF
     237             :       END DO
     238             : 
     239             :       !! check if we do wavefunction fitting
     240        7366 :       tmp_section => section_vals_get_subs_vals(dft_section, "AUXILIARY_DENSITY_MATRIX_METHOD")
     241        7366 :       CALL section_vals_get(tmp_section, explicit=is_present)
     242             :       !
     243        7366 :       hfx_section => section_vals_get_subs_vals(xc_section, "HF")
     244        7366 :       CALL section_vals_get(hfx_section, explicit=do_hfx)
     245        7366 :       CALL section_vals_val_get(xc_section, "WF_CORRELATION%RI_RPA%ADMM", l_val=do_rpa_admm)
     246        7366 :       is_present = is_present .AND. (do_hfx .OR. do_rpa_admm)
     247             :       !
     248        7366 :       dft_control%do_admm = is_present
     249        7366 :       dft_control%do_admm_mo = .FALSE.
     250        7366 :       dft_control%do_admm_dm = .FALSE.
     251        7366 :       IF (is_present) THEN
     252             :          do_ot = .FALSE.
     253         442 :          CALL section_vals_val_get(scf_section, "OT%_SECTION_PARAMETERS_", l_val=do_ot)
     254         442 :          CALL admm_control_create(dft_control%admm_control)
     255             : 
     256         442 :          CALL section_vals_val_get(dft_section, "AUXILIARY_DENSITY_MATRIX_METHOD%ADMM_TYPE", i_val=admmtype)
     257         442 :          CALL section_vals_val_get(dft_section, "AUXILIARY_DENSITY_MATRIX_METHOD%ADMM_PURIFICATION_METHOD", explicit=exopt1)
     258         442 :          CALL section_vals_val_get(dft_section, "AUXILIARY_DENSITY_MATRIX_METHOD%METHOD", explicit=exopt2)
     259         442 :          CALL section_vals_val_get(dft_section, "AUXILIARY_DENSITY_MATRIX_METHOD%EXCH_SCALING_MODEL", explicit=exopt3)
     260         442 :          dft_control%admm_control%admm_type = admmtype
     261         432 :          SELECT CASE (admmtype)
     262             :          CASE (no_admm_type)
     263         432 :             CALL section_vals_val_get(dft_section, "AUXILIARY_DENSITY_MATRIX_METHOD%ADMM_PURIFICATION_METHOD", i_val=method_id)
     264         432 :             dft_control%admm_control%purification_method = method_id
     265         432 :             CALL section_vals_val_get(dft_section, "AUXILIARY_DENSITY_MATRIX_METHOD%METHOD", i_val=method_id)
     266         432 :             dft_control%admm_control%method = method_id
     267         432 :             CALL section_vals_val_get(dft_section, "AUXILIARY_DENSITY_MATRIX_METHOD%EXCH_SCALING_MODEL", i_val=method_id)
     268         432 :             dft_control%admm_control%scaling_model = method_id
     269             :          CASE (admm1_type)
     270             :             ! METHOD BASIS_PROJECTION
     271             :             ! ADMM_PURIFICATION_METHOD choose
     272             :             ! EXCH_SCALING_MODEL NONE
     273           2 :             CALL section_vals_val_get(dft_section, "AUXILIARY_DENSITY_MATRIX_METHOD%ADMM_PURIFICATION_METHOD", i_val=method_id)
     274           2 :             dft_control%admm_control%purification_method = method_id
     275           2 :             dft_control%admm_control%method = do_admm_basis_projection
     276           2 :             dft_control%admm_control%scaling_model = do_admm_exch_scaling_none
     277             :          CASE (admm2_type)
     278             :             ! METHOD BASIS_PROJECTION
     279             :             ! ADMM_PURIFICATION_METHOD NONE
     280             :             ! EXCH_SCALING_MODEL NONE
     281           2 :             dft_control%admm_control%purification_method = do_admm_purify_none
     282           2 :             dft_control%admm_control%method = do_admm_basis_projection
     283           2 :             dft_control%admm_control%scaling_model = do_admm_exch_scaling_none
     284             :          CASE (admms_type)
     285             :             ! ADMM_PURIFICATION_METHOD NONE
     286             :             ! METHOD CHARGE_CONSTRAINED_PROJECTION
     287             :             ! EXCH_SCALING_MODEL MERLOT
     288           2 :             dft_control%admm_control%purification_method = do_admm_purify_none
     289           2 :             dft_control%admm_control%method = do_admm_charge_constrained_projection
     290           2 :             dft_control%admm_control%scaling_model = do_admm_exch_scaling_merlot
     291             :          CASE (admmp_type)
     292             :             ! ADMM_PURIFICATION_METHOD NONE
     293             :             ! METHOD BASIS_PROJECTION
     294             :             ! EXCH_SCALING_MODEL MERLOT
     295           2 :             dft_control%admm_control%purification_method = do_admm_purify_none
     296           2 :             dft_control%admm_control%method = do_admm_basis_projection
     297           2 :             dft_control%admm_control%scaling_model = do_admm_exch_scaling_merlot
     298             :          CASE (admmq_type)
     299             :             ! ADMM_PURIFICATION_METHOD NONE
     300             :             ! METHOD CHARGE_CONSTRAINED_PROJECTION
     301             :             ! EXCH_SCALING_MODEL NONE
     302           2 :             dft_control%admm_control%purification_method = do_admm_purify_none
     303           2 :             dft_control%admm_control%method = do_admm_charge_constrained_projection
     304           2 :             dft_control%admm_control%scaling_model = do_admm_exch_scaling_none
     305             :          CASE DEFAULT
     306             :             CALL cp_abort(__LOCATION__, &
     307         442 :                           "ADMM_TYPE keyword in &AUXILIARY_DENSITY_MATRIX_METHOD section has a wrong value.")
     308             :          END SELECT
     309             : 
     310             :          CALL section_vals_val_get(dft_section, "AUXILIARY_DENSITY_MATRIX_METHOD%EPS_FILTER", &
     311         442 :                                    r_val=dft_control%admm_control%eps_filter)
     312             : 
     313         442 :          CALL section_vals_val_get(dft_section, "AUXILIARY_DENSITY_MATRIX_METHOD%EXCH_CORRECTION_FUNC", i_val=method_id)
     314         442 :          dft_control%admm_control%aux_exch_func = method_id
     315             : 
     316             :          ! parameters for X functional
     317         442 :          dft_control%admm_control%aux_exch_func_param = .FALSE.
     318             :          CALL section_vals_val_get(dft_section, "AUXILIARY_DENSITY_MATRIX_METHOD%OPTX_A1", explicit=explicit, &
     319         442 :                                    r_val=dft_control%admm_control%aux_x_param(1))
     320         442 :          IF (explicit) dft_control%admm_control%aux_exch_func_param = .TRUE.
     321             :          CALL section_vals_val_get(dft_section, "AUXILIARY_DENSITY_MATRIX_METHOD%OPTX_A2", explicit=explicit, &
     322         442 :                                    r_val=dft_control%admm_control%aux_x_param(2))
     323         442 :          IF (explicit) dft_control%admm_control%aux_exch_func_param = .TRUE.
     324             :          CALL section_vals_val_get(dft_section, "AUXILIARY_DENSITY_MATRIX_METHOD%OPTX_GAMMA", explicit=explicit, &
     325         442 :                                    r_val=dft_control%admm_control%aux_x_param(3))
     326         442 :          IF (explicit) dft_control%admm_control%aux_exch_func_param = .TRUE.
     327             : 
     328         442 :          CALL read_admm_block_list(dft_control%admm_control, dft_section)
     329             : 
     330             :          ! check for double assignments
     331           2 :          SELECT CASE (admmtype)
     332             :          CASE (admm2_type)
     333           2 :             IF (exopt2) CALL cp_warn(__LOCATION__, &
     334           0 :                                      "Value of ADMM_PURIFICATION_METHOD keyword will be overwritten with ADMM_TYPE selections.")
     335           2 :             IF (exopt3) CALL cp_warn(__LOCATION__, &
     336           0 :                                      "Value of EXCH_SCALING_MODEL keyword will be overwritten with ADMM_TYPE selections.")
     337             :          CASE (admm1_type, admms_type, admmp_type, admmq_type)
     338           8 :             IF (exopt1) CALL cp_warn(__LOCATION__, &
     339           0 :                                      "Value of METHOD keyword will be overwritten with ADMM_TYPE selections.")
     340           8 :             IF (exopt2) CALL cp_warn(__LOCATION__, &
     341           0 :                                      "Value of METHOD keyword will be overwritten with ADMM_TYPE selections.")
     342           8 :             IF (exopt3) CALL cp_warn(__LOCATION__, &
     343         442 :                                      "Value of EXCH_SCALING_MODEL keyword will be overwritten with ADMM_TYPE selections.")
     344             :          END SELECT
     345             : 
     346             :          !    In the case of charge-constrained projection (e.g. according to Merlot),
     347             :          !    there is no purification needed and hence, do_admm_purify_none has to be set.
     348             : 
     349             :          IF ((dft_control%admm_control%method == do_admm_blocking_purify_full .OR. &
     350             :               dft_control%admm_control%method == do_admm_blocked_projection) &
     351         442 :              .AND. dft_control%admm_control%scaling_model == do_admm_exch_scaling_merlot) THEN
     352           0 :             CPABORT("ADMM: Blocking and Merlot scaling are mutually exclusive.")
     353             :          END IF
     354             : 
     355         442 :          IF (dft_control%admm_control%method == do_admm_charge_constrained_projection .AND. &
     356             :              dft_control%admm_control%purification_method /= do_admm_purify_none) THEN
     357             :             CALL cp_abort(__LOCATION__, &
     358             :                           "ADMM: In the case of METHOD=CHARGE_CONSTRAINED_PROJECTION, "// &
     359           0 :                           "ADMM_PURIFICATION_METHOD=NONE has to be set.")
     360             :          END IF
     361             : 
     362         442 :          IF (dft_control%admm_control%purification_method == do_admm_purify_mo_diag .OR. &
     363             :              dft_control%admm_control%purification_method == do_admm_purify_mo_no_diag) THEN
     364          60 :             IF (dft_control%admm_control%method /= do_admm_basis_projection) &
     365           0 :                CPABORT("ADMM: Chosen purification requires BASIS_PROJECTION")
     366             : 
     367          60 :             IF (.NOT. do_ot) CPABORT("ADMM: MO-based purification requires OT.")
     368             :          END IF
     369             : 
     370         442 :          IF (dft_control%admm_control%purification_method == do_admm_purify_none_dm .OR. &
     371             :              dft_control%admm_control%purification_method == do_admm_purify_mcweeny) THEN
     372          14 :             dft_control%do_admm_dm = .TRUE.
     373             :          ELSE
     374         428 :             dft_control%do_admm_mo = .TRUE.
     375             :          END IF
     376             :       END IF
     377             : 
     378             :       ! Set restricted to true, if both OT and ROKS are requested
     379             :       !MK in principle dft_control%restricted could be dropped completely like the
     380             :       !MK input key by using only dft_control%roks now
     381        7366 :       CALL section_vals_val_get(scf_section, "OT%_SECTION_PARAMETERS_", l_val=l_param)
     382        7366 :       dft_control%restricted = (dft_control%roks .AND. l_param)
     383             : 
     384        7366 :       CALL section_vals_val_get(dft_section, "CHARGE", i_val=dft_control%charge)
     385        7366 :       CALL section_vals_val_get(dft_section, "MULTIPLICITY", i_val=dft_control%multiplicity)
     386        7366 :       CALL section_vals_val_get(dft_section, "RELAX_MULTIPLICITY", r_val=dft_control%relax_multiplicity)
     387        7366 :       IF (dft_control%relax_multiplicity > 0.0_dp) THEN
     388           8 :          IF (.NOT. dft_control%uks) &
     389             :             CALL cp_abort(__LOCATION__, "The option RELAX_MULTIPLICITY is only valid for "// &
     390           0 :                           "unrestricted Kohn-Sham (UKS) calculations")
     391             :       END IF
     392             : 
     393             :       ! check for the presence of the low spin roks section
     394        7366 :       tmp_section => section_vals_get_subs_vals(dft_section, "LOW_SPIN_ROKS")
     395        7366 :       CALL section_vals_get(tmp_section, explicit=dft_control%low_spin_roks)
     396             : 
     397        7366 :       dft_control%sic_method_id = sic_none
     398        7366 :       dft_control%sic_scaling_a = 1.0_dp
     399        7366 :       dft_control%sic_scaling_b = 1.0_dp
     400             : 
     401             :       ! DFT+U
     402        7366 :       dft_control%dft_plus_u = .FALSE.
     403        7366 :       CALL section_vals_val_get(dft_section, "PLUS_U_METHOD", i_val=method_id)
     404        7366 :       dft_control%plus_u_method_id = method_id
     405             : 
     406             :       ! Smearing in use
     407        7366 :       dft_control%smear = .FALSE.
     408             : 
     409             :       ! Surface dipole correction
     410        7366 :       dft_control%correct_surf_dip = .FALSE.
     411        7366 :       CALL section_vals_val_get(dft_section, "SURFACE_DIPOLE_CORRECTION", l_val=dft_control%correct_surf_dip)
     412        7366 :       CALL section_vals_val_get(dft_section, "SURF_DIP_DIR", i_val=dft_control%dir_surf_dip)
     413        7366 :       dft_control%pos_dir_surf_dip = -1.0_dp
     414        7366 :       CALL section_vals_val_get(dft_section, "SURF_DIP_POS", r_val=dft_control%pos_dir_surf_dip)
     415             :       ! another logical variable, surf_dip_correct_switch, is introduced for
     416             :       ! implementation of "SURF_DIP_SWITCH" [SGh]
     417        7366 :       dft_control%switch_surf_dip = .FALSE.
     418        7366 :       dft_control%surf_dip_correct_switch = dft_control%correct_surf_dip
     419        7366 :       CALL section_vals_val_get(dft_section, "SURF_DIP_SWITCH", l_val=dft_control%switch_surf_dip)
     420        7366 :       dft_control%correct_el_density_dip = .FALSE.
     421        7366 :       CALL section_vals_val_get(dft_section, "CORE_CORR_DIP", l_val=dft_control%correct_el_density_dip)
     422        7366 :       IF (dft_control%correct_el_density_dip) THEN
     423           4 :          IF (dft_control%correct_surf_dip) THEN
     424             :             ! Do nothing, move on
     425             :          ELSE
     426           0 :             dft_control%correct_el_density_dip = .FALSE.
     427           0 :             CPWARN("CORE_CORR_DIP keyword is activated only if SURFACE_DIPOLE_CORRECTION is TRUE")
     428             :          END IF
     429             :       END IF
     430             : 
     431             :       CALL section_vals_val_get(dft_section, "BASIS_SET_FILE_NAME", &
     432        7366 :                                 c_val=basis_set_file_name)
     433             :       CALL section_vals_val_get(dft_section, "POTENTIAL_FILE_NAME", &
     434        7366 :                                 c_val=potential_file_name)
     435             : 
     436             :       ! Read the input section
     437        7366 :       tmp_section => section_vals_get_subs_vals(dft_section, "sic")
     438             :       CALL section_vals_val_get(tmp_section, "SIC_METHOD", &
     439        7366 :                                 i_val=dft_control%sic_method_id)
     440             :       CALL section_vals_val_get(tmp_section, "ORBITAL_SET", &
     441        7366 :                                 i_val=dft_control%sic_list_id)
     442             :       CALL section_vals_val_get(tmp_section, "SIC_SCALING_A", &
     443        7366 :                                 r_val=dft_control%sic_scaling_a)
     444             :       CALL section_vals_val_get(tmp_section, "SIC_SCALING_B", &
     445        7366 :                                 r_val=dft_control%sic_scaling_b)
     446             : 
     447             :       ! Determine if this is a TDDFPT run
     448        7366 :       CALL section_vals_val_get(dft_section, "EXCITATIONS", i_val=excitations)
     449        7366 :       dft_control%do_tddfpt_calculation = (excitations == tddfpt_excitations)
     450        7366 :       IF (dft_control%do_tddfpt_calculation) THEN
     451          12 :          CALL tddfpt_control_create(dft_control%tddfpt_control)
     452             :       END IF
     453             : 
     454        7366 :       do_rtp = .FALSE.
     455        7366 :       tmp_section => section_vals_get_subs_vals(dft_section, "REAL_TIME_PROPAGATION")
     456        7366 :       CALL section_vals_get(tmp_section, explicit=is_present)
     457        7366 :       IF (is_present) THEN
     458         248 :          CALL read_rtp_section(dft_control, tmp_section)
     459         248 :          do_rtp = .TRUE.
     460             :       END IF
     461             : 
     462             :       ! Read the input section
     463        7366 :       tmp_section => section_vals_get_subs_vals(dft_section, "XAS")
     464        7366 :       CALL section_vals_get(tmp_section, explicit=dft_control%do_xas_calculation)
     465        7366 :       IF (dft_control%do_xas_calculation) THEN
     466             :          ! Override with section parameter
     467             :          CALL section_vals_val_get(tmp_section, "_SECTION_PARAMETERS_", &
     468          42 :                                    l_val=dft_control%do_xas_calculation)
     469             :       END IF
     470             : 
     471        7366 :       tmp_section => section_vals_get_subs_vals(dft_section, "XAS_TDP")
     472        7366 :       CALL section_vals_get(tmp_section, explicit=dft_control%do_xas_tdp_calculation)
     473        7366 :       IF (dft_control%do_xas_tdp_calculation) THEN
     474             :          ! Override with section parameter
     475             :          CALL section_vals_val_get(tmp_section, "_SECTION_PARAMETERS_", &
     476          50 :                                    l_val=dft_control%do_xas_tdp_calculation)
     477             :       END IF
     478             : 
     479             :       ! Read the finite field input section
     480        7366 :       dft_control%apply_efield = .FALSE.
     481        7366 :       dft_control%apply_efield_field = .FALSE. !this is for RTP
     482        7366 :       dft_control%apply_vector_potential = .FALSE. !this is for RTP
     483        7366 :       tmp_section => section_vals_get_subs_vals(dft_section, "EFIELD")
     484        7366 :       CALL section_vals_get(tmp_section, n_repetition=nrep, explicit=is_present)
     485        7366 :       IF (is_present) THEN
     486        1056 :          ALLOCATE (dft_control%efield_fields(nrep))
     487         264 :          CALL read_efield_sections(dft_control, tmp_section)
     488         264 :          IF (do_rtp) THEN
     489          24 :             IF (.NOT. dft_control%rtp_control%velocity_gauge) THEN
     490          16 :                dft_control%apply_efield_field = .TRUE.
     491             :             ELSE
     492           8 :                dft_control%apply_vector_potential = .TRUE.
     493             :                ! Use this input value of vector potential to (re)start RTP
     494          32 :                dft_control%rtp_control%vec_pot = dft_control%efield_fields(1)%efield%vec_pot_initial
     495             :             END IF
     496             :          ELSE
     497         240 :             dft_control%apply_efield = .TRUE.
     498         240 :             CPASSERT(nrep == 1)
     499             :          END IF
     500             :       END IF
     501             : 
     502             :       ! Read the finite field input section for periodic fields
     503        7366 :       tmp_section => section_vals_get_subs_vals(dft_section, "PERIODIC_EFIELD")
     504        7366 :       CALL section_vals_get(tmp_section, explicit=dft_control%apply_period_efield)
     505        7366 :       IF (dft_control%apply_period_efield) THEN
     506         504 :          ALLOCATE (dft_control%period_efield)
     507          72 :          CALL section_vals_val_get(tmp_section, "POLARISATION", r_vals=pol)
     508         504 :          dft_control%period_efield%polarisation(1:3) = pol(1:3)
     509          72 :          CALL section_vals_val_get(tmp_section, "D_FILTER", r_vals=pol)
     510         504 :          dft_control%period_efield%d_filter(1:3) = pol(1:3)
     511             :          CALL section_vals_val_get(tmp_section, "INTENSITY", &
     512          72 :                                    r_val=dft_control%period_efield%strength)
     513          72 :          dft_control%period_efield%displacement_field = .FALSE.
     514             :          CALL section_vals_val_get(tmp_section, "DISPLACEMENT_FIELD", &
     515          72 :                                    l_val=dft_control%period_efield%displacement_field)
     516             :          ! periodic fields don't work with RTP
     517          72 :          CPASSERT(.NOT. do_rtp)
     518          72 :          IF (dft_control%period_efield%displacement_field) THEN
     519          16 :             CALL cite_reference(Stengel2009)
     520             :          ELSE
     521          56 :             CALL cite_reference(Souza2002)
     522          56 :             CALL cite_reference(Umari2002)
     523             :          END IF
     524             :       END IF
     525             : 
     526             :       ! Read the external potential input section
     527        7366 :       tmp_section => section_vals_get_subs_vals(dft_section, "EXTERNAL_POTENTIAL")
     528        7366 :       CALL section_vals_get(tmp_section, explicit=dft_control%apply_external_potential)
     529        7366 :       IF (dft_control%apply_external_potential) THEN
     530          16 :          CALL expot_control_create(dft_control%expot_control)
     531             :          CALL section_vals_val_get(tmp_section, "READ_FROM_CUBE", &
     532          16 :                                    l_val=dft_control%expot_control%read_from_cube)
     533             :          CALL section_vals_val_get(tmp_section, "STATIC", &
     534          16 :                                    l_val=dft_control%expot_control%static)
     535             :          CALL section_vals_val_get(tmp_section, "SCALING_FACTOR", &
     536          16 :                                    r_val=dft_control%expot_control%scaling_factor)
     537             :          ! External potential using Maxwell equation
     538          16 :          maxwell_section => section_vals_get_subs_vals(tmp_section, "MAXWELL")
     539          16 :          CALL section_vals_get(maxwell_section, explicit=is_present)
     540          16 :          IF (is_present) THEN
     541           0 :             dft_control%expot_control%maxwell_solver = .TRUE.
     542           0 :             CALL maxwell_control_create(dft_control%maxwell_control)
     543             :             ! read the input values from Maxwell section
     544             :             CALL section_vals_val_get(maxwell_section, "TEST_REAL", &
     545           0 :                                       r_val=dft_control%maxwell_control%real_test)
     546             :             CALL section_vals_val_get(maxwell_section, "TEST_INTEGER", &
     547           0 :                                       i_val=dft_control%maxwell_control%int_test)
     548             :             CALL section_vals_val_get(maxwell_section, "TEST_LOGICAL", &
     549           0 :                                       l_val=dft_control%maxwell_control%log_test)
     550             :          ELSE
     551          16 :             dft_control%expot_control%maxwell_solver = .FALSE.
     552             :          END IF
     553             :       END IF
     554             : 
     555             :       ! Read the SCCS input section if present
     556        7366 :       sccs_section => section_vals_get_subs_vals(dft_section, "SCCS")
     557        7366 :       CALL section_vals_get(sccs_section, explicit=is_present)
     558        7366 :       IF (is_present) THEN
     559             :          ! Check section parameter if SCCS is activated
     560             :          CALL section_vals_val_get(sccs_section, "_SECTION_PARAMETERS_", &
     561          10 :                                    l_val=dft_control%do_sccs)
     562          10 :          IF (dft_control%do_sccs) THEN
     563          10 :             ALLOCATE (dft_control%sccs_control)
     564             :             CALL section_vals_val_get(sccs_section, "RELATIVE_PERMITTIVITY", &
     565          10 :                                       r_val=dft_control%sccs_control%epsilon_solvent)
     566             :             CALL section_vals_val_get(sccs_section, "ALPHA", &
     567          10 :                                       r_val=dft_control%sccs_control%alpha_solvent)
     568             :             CALL section_vals_val_get(sccs_section, "BETA", &
     569          10 :                                       r_val=dft_control%sccs_control%beta_solvent)
     570             :             CALL section_vals_val_get(sccs_section, "DELTA_RHO", &
     571          10 :                                       r_val=dft_control%sccs_control%delta_rho)
     572             :             CALL section_vals_val_get(sccs_section, "DERIVATIVE_METHOD", &
     573          10 :                                       i_val=dft_control%sccs_control%derivative_method)
     574             :             CALL section_vals_val_get(sccs_section, "METHOD", &
     575          10 :                                       i_val=dft_control%sccs_control%method_id)
     576             :             CALL section_vals_val_get(sccs_section, "EPS_SCCS", &
     577          10 :                                       r_val=dft_control%sccs_control%eps_sccs)
     578             :             CALL section_vals_val_get(sccs_section, "EPS_SCF", &
     579          10 :                                       r_val=dft_control%sccs_control%eps_scf)
     580             :             CALL section_vals_val_get(sccs_section, "GAMMA", &
     581          10 :                                       r_val=dft_control%sccs_control%gamma_solvent)
     582             :             CALL section_vals_val_get(sccs_section, "MAX_ITER", &
     583          10 :                                       i_val=dft_control%sccs_control%max_iter)
     584             :             CALL section_vals_val_get(sccs_section, "MIXING", &
     585          10 :                                       r_val=dft_control%sccs_control%mixing)
     586          18 :             SELECT CASE (dft_control%sccs_control%method_id)
     587             :             CASE (sccs_andreussi)
     588           8 :                tmp_section => section_vals_get_subs_vals(sccs_section, "ANDREUSSI")
     589             :                CALL section_vals_val_get(tmp_section, "RHO_MAX", &
     590           8 :                                          r_val=dft_control%sccs_control%rho_max)
     591             :                CALL section_vals_val_get(tmp_section, "RHO_MIN", &
     592           8 :                                          r_val=dft_control%sccs_control%rho_min)
     593           8 :                IF (dft_control%sccs_control%rho_max < dft_control%sccs_control%rho_min) THEN
     594             :                   CALL cp_abort(__LOCATION__, &
     595             :                                 "The SCCS parameter RHO_MAX is smaller than RHO_MIN. "// &
     596           0 :                                 "Please, check your input!")
     597             :                END IF
     598           8 :                CALL cite_reference(Andreussi2012)
     599             :             CASE (sccs_fattebert_gygi)
     600           2 :                tmp_section => section_vals_get_subs_vals(sccs_section, "FATTEBERT-GYGI")
     601             :                CALL section_vals_val_get(tmp_section, "BETA", &
     602           2 :                                          r_val=dft_control%sccs_control%beta)
     603           2 :                IF (dft_control%sccs_control%beta < 0.5_dp) THEN
     604             :                   CALL cp_abort(__LOCATION__, &
     605             :                                 "A value smaller than 0.5 for the SCCS parameter beta "// &
     606           0 :                                 "causes numerical problems. Please, check your input!")
     607             :                END IF
     608             :                CALL section_vals_val_get(tmp_section, "RHO_ZERO", &
     609           2 :                                          r_val=dft_control%sccs_control%rho_zero)
     610           2 :                CALL cite_reference(Fattebert2002)
     611             :             CASE DEFAULT
     612          10 :                CPABORT("Invalid SCCS model specified. Please, check your input!")
     613             :             END SELECT
     614          10 :             CALL cite_reference(Yin2017)
     615             :          END IF
     616             :       END IF
     617             : 
     618             :       ! ZMP added input sections
     619             :       ! Read the external density input section
     620        7366 :       tmp_section => section_vals_get_subs_vals(dft_section, "EXTERNAL_DENSITY")
     621        7366 :       CALL section_vals_get(tmp_section, explicit=dft_control%apply_external_density)
     622             : 
     623             :       ! Read the external vxc input section
     624        7366 :       tmp_section => section_vals_get_subs_vals(dft_section, "EXTERNAL_VXC")
     625        7366 :       CALL section_vals_get(tmp_section, explicit=dft_control%apply_external_vxc)
     626             : 
     627             :       ! SMEAGOL interface
     628        7366 :       tmp_section => section_vals_get_subs_vals(dft_section, "SMEAGOL")
     629        7366 :       CALL read_smeagol_control(dft_control%smeagol_control, tmp_section)
     630             : 
     631        7366 :    END SUBROUTINE read_dft_control
     632             : 
     633             : ! **************************************************************************************************
     634             : !> \brief ...
     635             : !> \param qs_control ...
     636             : !> \param dft_section ...
     637             : ! **************************************************************************************************
     638        7366 :    SUBROUTINE read_mgrid_section(qs_control, dft_section)
     639             : 
     640             :       TYPE(qs_control_type), INTENT(INOUT)               :: qs_control
     641             :       TYPE(section_vals_type), POINTER                   :: dft_section
     642             : 
     643             :       CHARACTER(len=*), PARAMETER :: routineN = 'read_mgrid_section'
     644             : 
     645             :       INTEGER                                            :: handle, igrid_level, ngrid_level
     646             :       LOGICAL                                            :: explicit, multigrid_set
     647             :       REAL(dp)                                           :: cutoff
     648        7366 :       REAL(dp), DIMENSION(:), POINTER                    :: cutofflist
     649             :       TYPE(section_vals_type), POINTER                   :: mgrid_section
     650             : 
     651        7366 :       CALL timeset(routineN, handle)
     652             : 
     653        7366 :       NULLIFY (mgrid_section, cutofflist)
     654        7366 :       mgrid_section => section_vals_get_subs_vals(dft_section, "MGRID")
     655             : 
     656        7366 :       CALL section_vals_val_get(mgrid_section, "NGRIDS", i_val=ngrid_level)
     657        7366 :       CALL section_vals_val_get(mgrid_section, "MULTIGRID_SET", l_val=multigrid_set)
     658        7366 :       CALL section_vals_val_get(mgrid_section, "CUTOFF", r_val=cutoff)
     659        7366 :       CALL section_vals_val_get(mgrid_section, "PROGRESSION_FACTOR", r_val=qs_control%progression_factor)
     660        7366 :       CALL section_vals_val_get(mgrid_section, "COMMENSURATE", l_val=qs_control%commensurate_mgrids)
     661        7366 :       CALL section_vals_val_get(mgrid_section, "REALSPACE", l_val=qs_control%realspace_mgrids)
     662        7366 :       CALL section_vals_val_get(mgrid_section, "REL_CUTOFF", r_val=qs_control%relative_cutoff)
     663             :       CALL section_vals_val_get(mgrid_section, "SKIP_LOAD_BALANCE_DISTRIBUTED", &
     664        7366 :                                 l_val=qs_control%skip_load_balance_distributed)
     665             : 
     666             :       ! For SE and DFTB possibly override with new defaults
     667        7366 :       IF (qs_control%semi_empirical .OR. qs_control%dftb .OR. qs_control%xtb) THEN
     668        2160 :          ngrid_level = 1
     669        2160 :          multigrid_set = .FALSE.
     670             :          ! Override default cutoff value unless user specified an explicit argument..
     671        2160 :          CALL section_vals_val_get(mgrid_section, "CUTOFF", explicit=explicit, r_val=cutoff)
     672        2160 :          IF (.NOT. explicit) cutoff = 1.0_dp
     673             :       END IF
     674             : 
     675       22098 :       ALLOCATE (qs_control%e_cutoff(ngrid_level))
     676        7366 :       qs_control%cutoff = cutoff
     677             : 
     678        7366 :       IF (multigrid_set) THEN
     679             :          ! Read the values from input
     680           4 :          IF (qs_control%commensurate_mgrids) THEN
     681           0 :             CPABORT("Do not specify cutoffs for the commensurate grids (NYI)")
     682             :          END IF
     683             : 
     684           4 :          CALL section_vals_val_get(mgrid_section, "MULTIGRID_CUTOFF", r_vals=cutofflist)
     685           4 :          IF (ASSOCIATED(cutofflist)) THEN
     686           4 :             IF (SIZE(cutofflist, 1) /= ngrid_level) THEN
     687           0 :                CPABORT("Number of multi-grids requested and number of cutoff values do not match")
     688             :             END IF
     689          20 :             DO igrid_level = 1, ngrid_level
     690          20 :                qs_control%e_cutoff(igrid_level) = cutofflist(igrid_level)
     691             :             END DO
     692             :          END IF
     693             :          ! set cutoff to smallest value in multgrid available with >= cutoff
     694          20 :          DO igrid_level = ngrid_level, 1, -1
     695          16 :             IF (qs_control%cutoff <= qs_control%e_cutoff(igrid_level)) THEN
     696           0 :                qs_control%cutoff = qs_control%e_cutoff(igrid_level)
     697           0 :                EXIT
     698             :             END IF
     699             :             ! set largest grid value to cutoff
     700          20 :             IF (igrid_level == 1) THEN
     701           4 :                qs_control%cutoff = qs_control%e_cutoff(1)
     702             :             END IF
     703             :          END DO
     704             :       ELSE
     705        7362 :          IF (qs_control%commensurate_mgrids) qs_control%progression_factor = 4.0_dp
     706        7362 :          qs_control%e_cutoff(1) = qs_control%cutoff
     707       22834 :          DO igrid_level = 2, ngrid_level
     708             :             qs_control%e_cutoff(igrid_level) = qs_control%e_cutoff(igrid_level - 1)/ &
     709       22834 :                                                qs_control%progression_factor
     710             :          END DO
     711             :       END IF
     712             :       ! check that multigrids are ordered
     713       22850 :       DO igrid_level = 2, ngrid_level
     714       22850 :          IF (qs_control%e_cutoff(igrid_level) > qs_control%e_cutoff(igrid_level - 1)) THEN
     715           0 :             CPABORT("The cutoff values for the multi-grids are not ordered from large to small")
     716       15484 :          ELSE IF (qs_control%e_cutoff(igrid_level) == qs_control%e_cutoff(igrid_level - 1)) THEN
     717           0 :             CPABORT("The same cutoff value was specified for two multi-grids")
     718             :          END IF
     719             :       END DO
     720        7366 :       CALL timestop(handle)
     721       14732 :    END SUBROUTINE read_mgrid_section
     722             : 
     723             : ! **************************************************************************************************
     724             : !> \brief ...
     725             : !> \param qs_control ...
     726             : !> \param qs_section ...
     727             : ! **************************************************************************************************
     728      117856 :    SUBROUTINE read_qs_section(qs_control, qs_section)
     729             : 
     730             :       TYPE(qs_control_type), INTENT(INOUT)               :: qs_control
     731             :       TYPE(section_vals_type), POINTER                   :: qs_section
     732             : 
     733             :       CHARACTER(len=*), PARAMETER                        :: routineN = 'read_qs_section'
     734             : 
     735             :       CHARACTER(LEN=default_string_length)               :: cval
     736             :       CHARACTER(LEN=default_string_length), &
     737        7366 :          DIMENSION(:), POINTER                           :: clist
     738             :       INTEGER                                            :: handle, itmp, j, jj, k, n_rep, n_var, &
     739             :                                                             ngauss, ngp, nrep
     740        7366 :       INTEGER, DIMENSION(:), POINTER                     :: tmplist
     741             :       LOGICAL                                            :: explicit, was_present
     742             :       REAL(dp)                                           :: tmp, tmpsqrt, value
     743        7366 :       REAL(dp), POINTER                                  :: scal(:)
     744             :       TYPE(section_vals_type), POINTER :: cdft_control_section, ddapc_restraint_section, &
     745             :          dftb_parameter, dftb_section, eeq_section, genpot_section, lri_optbas_section, &
     746             :          mull_section, nonbonded_section, s2_restraint_section, se_section, xtb_parameter, &
     747             :          xtb_section
     748             : 
     749        7366 :       CALL timeset(routineN, handle)
     750             : 
     751        7366 :       was_present = .FALSE.
     752        7366 :       NULLIFY (mull_section, ddapc_restraint_section, s2_restraint_section, &
     753        7366 :                se_section, dftb_section, xtb_section, dftb_parameter, xtb_parameter, lri_optbas_section, &
     754        7366 :                cdft_control_section, genpot_section, eeq_section)
     755             : 
     756        7366 :       mull_section => section_vals_get_subs_vals(qs_section, "MULLIKEN_RESTRAINT")
     757        7366 :       ddapc_restraint_section => section_vals_get_subs_vals(qs_section, "DDAPC_RESTRAINT")
     758        7366 :       s2_restraint_section => section_vals_get_subs_vals(qs_section, "S2_RESTRAINT")
     759        7366 :       se_section => section_vals_get_subs_vals(qs_section, "SE")
     760        7366 :       dftb_section => section_vals_get_subs_vals(qs_section, "DFTB")
     761        7366 :       xtb_section => section_vals_get_subs_vals(qs_section, "xTB")
     762        7366 :       dftb_parameter => section_vals_get_subs_vals(dftb_section, "PARAMETER")
     763        7366 :       xtb_parameter => section_vals_get_subs_vals(xtb_section, "PARAMETER")
     764        7366 :       eeq_section => section_vals_get_subs_vals(xtb_section, "EEQ")
     765        7366 :       lri_optbas_section => section_vals_get_subs_vals(qs_section, "OPTIMIZE_LRI_BASIS")
     766        7366 :       cdft_control_section => section_vals_get_subs_vals(qs_section, "CDFT")
     767        7366 :       nonbonded_section => section_vals_get_subs_vals(xtb_section, "NONBONDED")
     768        7366 :       genpot_section => section_vals_get_subs_vals(nonbonded_section, "GENPOT")
     769             : 
     770             :       ! Setup all defaults values and overwrite input parameters
     771             :       ! EPS_DEFAULT should set the target accuracy in the total energy (~per electron) or a closely related value
     772        7366 :       CALL section_vals_val_get(qs_section, "EPS_DEFAULT", r_val=value)
     773        7366 :       tmpsqrt = SQRT(value) ! a trick to work around a NAG 5.1 optimizer bug
     774             : 
     775             :       ! random choice ?
     776        7366 :       qs_control%eps_core_charge = value/100.0_dp
     777             :       ! correct if all Gaussians would have the same radius (overlap will be smaller than eps_pgf_orb**2).
     778             :       ! Can be significantly in error if not... requires fully new screening/pairlist procedures
     779        7366 :       qs_control%eps_pgf_orb = tmpsqrt
     780        7366 :       qs_control%eps_kg_orb = qs_control%eps_pgf_orb
     781             :       ! consistent since also a kind of overlap
     782        7366 :       qs_control%eps_ppnl = qs_control%eps_pgf_orb/100.0_dp
     783             :       ! accuracy is basically set by the overlap, this sets an empirical shift
     784        7366 :       qs_control%eps_ppl = 1.0E-2_dp
     785             :       !
     786        7366 :       qs_control%gapw_control%eps_cpc = value
     787             :       ! expexted error in the density
     788        7366 :       qs_control%eps_rho_gspace = value
     789        7366 :       qs_control%eps_rho_rspace = value
     790             :       ! error in the gradient, can be the sqrt of the error in the energy, ignored if map_consistent
     791        7366 :       qs_control%eps_gvg_rspace = tmpsqrt
     792             :       !
     793        7366 :       CALL section_vals_val_get(qs_section, "EPS_CORE_CHARGE", n_rep_val=n_rep)
     794        7366 :       IF (n_rep /= 0) THEN
     795           0 :          CALL section_vals_val_get(qs_section, "EPS_CORE_CHARGE", r_val=qs_control%eps_core_charge)
     796             :       END IF
     797        7366 :       CALL section_vals_val_get(qs_section, "EPS_GVG_RSPACE", n_rep_val=n_rep)
     798        7366 :       IF (n_rep /= 0) THEN
     799         132 :          CALL section_vals_val_get(qs_section, "EPS_GVG_RSPACE", r_val=qs_control%eps_gvg_rspace)
     800             :       END IF
     801        7366 :       CALL section_vals_val_get(qs_section, "EPS_PGF_ORB", n_rep_val=n_rep)
     802        7366 :       IF (n_rep /= 0) THEN
     803         620 :          CALL section_vals_val_get(qs_section, "EPS_PGF_ORB", r_val=qs_control%eps_pgf_orb)
     804             :       END IF
     805        7366 :       CALL section_vals_val_get(qs_section, "EPS_KG_ORB", n_rep_val=n_rep)
     806        7366 :       IF (n_rep /= 0) THEN
     807          62 :          CALL section_vals_val_get(qs_section, "EPS_KG_ORB", r_val=tmp)
     808          62 :          qs_control%eps_kg_orb = SQRT(tmp)
     809             :       END IF
     810        7366 :       CALL section_vals_val_get(qs_section, "EPS_PPL", n_rep_val=n_rep)
     811        7366 :       IF (n_rep /= 0) THEN
     812        7366 :          CALL section_vals_val_get(qs_section, "EPS_PPL", r_val=qs_control%eps_ppl)
     813             :       END IF
     814        7366 :       CALL section_vals_val_get(qs_section, "EPS_PPNL", n_rep_val=n_rep)
     815        7366 :       IF (n_rep /= 0) THEN
     816           0 :          CALL section_vals_val_get(qs_section, "EPS_PPNL", r_val=qs_control%eps_ppnl)
     817             :       END IF
     818        7366 :       CALL section_vals_val_get(qs_section, "EPS_RHO", n_rep_val=n_rep)
     819        7366 :       IF (n_rep /= 0) THEN
     820          30 :          CALL section_vals_val_get(qs_section, "EPS_RHO", r_val=qs_control%eps_rho_gspace)
     821          30 :          qs_control%eps_rho_rspace = qs_control%eps_rho_gspace
     822             :       END IF
     823        7366 :       CALL section_vals_val_get(qs_section, "EPS_RHO_RSPACE", n_rep_val=n_rep)
     824        7366 :       IF (n_rep /= 0) THEN
     825           2 :          CALL section_vals_val_get(qs_section, "EPS_RHO_RSPACE", r_val=qs_control%eps_rho_rspace)
     826             :       END IF
     827        7366 :       CALL section_vals_val_get(qs_section, "EPS_RHO_GSPACE", n_rep_val=n_rep)
     828        7366 :       IF (n_rep /= 0) THEN
     829           2 :          CALL section_vals_val_get(qs_section, "EPS_RHO_GSPACE", r_val=qs_control%eps_rho_gspace)
     830             :       END IF
     831        7366 :       CALL section_vals_val_get(qs_section, "EPS_FILTER_MATRIX", n_rep_val=n_rep)
     832        7366 :       IF (n_rep /= 0) THEN
     833        7366 :          CALL section_vals_val_get(qs_section, "EPS_FILTER_MATRIX", r_val=qs_control%eps_filter_matrix)
     834             :       END IF
     835        7366 :       CALL section_vals_val_get(qs_section, "EPS_CPC", n_rep_val=n_rep)
     836        7366 :       IF (n_rep /= 0) THEN
     837           0 :          CALL section_vals_val_get(qs_section, "EPS_CPC", r_val=qs_control%gapw_control%eps_cpc)
     838             :       END IF
     839             : 
     840        7366 :       CALL section_vals_val_get(qs_section, "EPSFIT", r_val=qs_control%gapw_control%eps_fit)
     841        7366 :       CALL section_vals_val_get(qs_section, "EPSISO", r_val=qs_control%gapw_control%eps_iso)
     842        7366 :       CALL section_vals_val_get(qs_section, "EPSSVD", r_val=qs_control%gapw_control%eps_svd)
     843        7366 :       CALL section_vals_val_get(qs_section, "EPSRHO0", r_val=qs_control%gapw_control%eps_Vrho0)
     844        7366 :       CALL section_vals_val_get(qs_section, "ALPHA0_HARD", r_val=qs_control%gapw_control%alpha0_hard)
     845        7366 :       qs_control%gapw_control%lrho1_eq_lrho0 = .FALSE.
     846        7366 :       qs_control%gapw_control%alpha0_hard_from_input = .FALSE.
     847        7366 :       IF (qs_control%gapw_control%alpha0_hard /= 0.0_dp) qs_control%gapw_control%alpha0_hard_from_input = .TRUE.
     848        7366 :       CALL section_vals_val_get(qs_section, "FORCE_PAW", l_val=qs_control%gapw_control%force_paw)
     849        7366 :       CALL section_vals_val_get(qs_section, "MAX_RAD_LOCAL", r_val=qs_control%gapw_control%max_rad_local)
     850             : 
     851        7366 :       CALL section_vals_val_get(qs_section, "MIN_PAIR_LIST_RADIUS", r_val=qs_control%pairlist_radius)
     852             : 
     853        7366 :       CALL section_vals_val_get(qs_section, "LS_SCF", l_val=qs_control%do_ls_scf)
     854        7366 :       CALL section_vals_val_get(qs_section, "ALMO_SCF", l_val=qs_control%do_almo_scf)
     855        7366 :       CALL section_vals_val_get(qs_section, "KG_METHOD", l_val=qs_control%do_kg)
     856             : 
     857             :       ! Logicals
     858        7366 :       CALL section_vals_val_get(qs_section, "REF_EMBED_SUBSYS", l_val=qs_control%ref_embed_subsys)
     859        7366 :       CALL section_vals_val_get(qs_section, "CLUSTER_EMBED_SUBSYS", l_val=qs_control%cluster_embed_subsys)
     860        7366 :       CALL section_vals_val_get(qs_section, "HIGH_LEVEL_EMBED_SUBSYS", l_val=qs_control%high_level_embed_subsys)
     861        7366 :       CALL section_vals_val_get(qs_section, "DFET_EMBEDDED", l_val=qs_control%dfet_embedded)
     862        7366 :       CALL section_vals_val_get(qs_section, "DMFET_EMBEDDED", l_val=qs_control%dmfet_embedded)
     863             : 
     864             :       ! Integers gapw
     865        7366 :       CALL section_vals_val_get(qs_section, "LMAXN1", i_val=qs_control%gapw_control%lmax_sphere)
     866        7366 :       CALL section_vals_val_get(qs_section, "LMAXN0", i_val=qs_control%gapw_control%lmax_rho0)
     867        7366 :       CALL section_vals_val_get(qs_section, "LADDN0", i_val=qs_control%gapw_control%ladd_rho0)
     868        7366 :       CALL section_vals_val_get(qs_section, "QUADRATURE", i_val=qs_control%gapw_control%quadrature)
     869             :       ! GAPW 1c basis
     870        7366 :       CALL section_vals_val_get(qs_section, "GAPW_1C_BASIS", i_val=qs_control%gapw_control%basis_1c)
     871        7366 :       IF (qs_control%gapw_control%basis_1c /= gapw_1c_orb) THEN
     872          18 :          qs_control%gapw_control%eps_svd = MAX(qs_control%gapw_control%eps_svd, 1.E-12_dp)
     873             :       END IF
     874             : 
     875             :       ! Integers grids
     876        7366 :       CALL section_vals_val_get(qs_section, "PW_GRID", i_val=itmp)
     877           0 :       SELECT CASE (itmp)
     878             :       CASE (do_pwgrid_spherical)
     879           0 :          qs_control%pw_grid_opt%spherical = .TRUE.
     880           0 :          qs_control%pw_grid_opt%fullspace = .FALSE.
     881             :       CASE (do_pwgrid_ns_fullspace)
     882        7366 :          qs_control%pw_grid_opt%spherical = .FALSE.
     883        7366 :          qs_control%pw_grid_opt%fullspace = .TRUE.
     884             :       CASE (do_pwgrid_ns_halfspace)
     885           0 :          qs_control%pw_grid_opt%spherical = .FALSE.
     886        7366 :          qs_control%pw_grid_opt%fullspace = .FALSE.
     887             :       END SELECT
     888             : 
     889             :       !   Method for PPL calculation
     890        7366 :       CALL section_vals_val_get(qs_section, "CORE_PPL", i_val=itmp)
     891        7366 :       qs_control%do_ppl_method = itmp
     892             : 
     893        7366 :       CALL section_vals_val_get(qs_section, "PW_GRID_LAYOUT", i_vals=tmplist)
     894       22098 :       qs_control%pw_grid_opt%distribution_layout = tmplist
     895        7366 :       CALL section_vals_val_get(qs_section, "PW_GRID_BLOCKED", i_val=qs_control%pw_grid_opt%blocked)
     896             : 
     897             :       !Integers extrapolation
     898        7366 :       CALL section_vals_val_get(qs_section, "EXTRAPOLATION", i_val=qs_control%wf_interpolation_method_nr)
     899        7366 :       CALL section_vals_val_get(qs_section, "EXTRAPOLATION_ORDER", i_val=qs_control%wf_extrapolation_order)
     900             : 
     901             :       !Method
     902        7366 :       CALL section_vals_val_get(qs_section, "METHOD", i_val=qs_control%method_id)
     903        7366 :       qs_control%gapw = .FALSE.
     904        7366 :       qs_control%gapw_xc = .FALSE.
     905        7366 :       qs_control%gpw = .FALSE.
     906        7366 :       qs_control%pao = .FALSE.
     907        7366 :       qs_control%dftb = .FALSE.
     908        7366 :       qs_control%xtb = .FALSE.
     909        7366 :       qs_control%semi_empirical = .FALSE.
     910        7366 :       qs_control%ofgpw = .FALSE.
     911        7366 :       qs_control%lrigpw = .FALSE.
     912        7366 :       qs_control%rigpw = .FALSE.
     913        8182 :       SELECT CASE (qs_control%method_id)
     914             :       CASE (do_method_gapw)
     915         816 :          CALL cite_reference(Lippert1999)
     916         816 :          CALL cite_reference(Krack2000)
     917         816 :          qs_control%gapw = .TRUE.
     918             :       CASE (do_method_gapw_xc)
     919         106 :          qs_control%gapw_xc = .TRUE.
     920             :       CASE (do_method_gpw)
     921        4244 :          CALL cite_reference(Lippert1997)
     922        4244 :          CALL cite_reference(VandeVondele2005a)
     923        4244 :          qs_control%gpw = .TRUE.
     924             :       CASE (do_method_ofgpw)
     925           0 :          qs_control%ofgpw = .TRUE.
     926             :       CASE (do_method_lrigpw)
     927          40 :          qs_control%lrigpw = .TRUE.
     928             :       CASE (do_method_rigpw)
     929           0 :          qs_control%rigpw = .TRUE.
     930             :       CASE (do_method_dftb)
     931         222 :          qs_control%dftb = .TRUE.
     932         222 :          CALL cite_reference(Porezag1995)
     933         222 :          CALL cite_reference(Seifert1996)
     934             :       CASE (do_method_xtb)
     935         940 :          qs_control%xtb = .TRUE.
     936         940 :          CALL cite_reference(Grimme2017)
     937         940 :          CALL cite_reference(Pracht2019)
     938             :       CASE (do_method_mndo)
     939          52 :          CALL cite_reference(Dewar1977)
     940          52 :          qs_control%semi_empirical = .TRUE.
     941             :       CASE (do_method_am1)
     942         112 :          CALL cite_reference(Dewar1985)
     943         112 :          qs_control%semi_empirical = .TRUE.
     944             :       CASE (do_method_pm3)
     945          46 :          CALL cite_reference(Stewart1989)
     946          46 :          qs_control%semi_empirical = .TRUE.
     947             :       CASE (do_method_pnnl)
     948          14 :          CALL cite_reference(Schenter2008)
     949          14 :          qs_control%semi_empirical = .TRUE.
     950             :       CASE (do_method_pm6)
     951         754 :          CALL cite_reference(Stewart2007)
     952         754 :          qs_control%semi_empirical = .TRUE.
     953             :       CASE (do_method_pm6fm)
     954           0 :          CALL cite_reference(VanVoorhis2015)
     955           0 :          qs_control%semi_empirical = .TRUE.
     956             :       CASE (do_method_pdg)
     957           2 :          CALL cite_reference(Repasky2002)
     958           2 :          qs_control%semi_empirical = .TRUE.
     959             :       CASE (do_method_rm1)
     960           2 :          CALL cite_reference(Rocha2006)
     961           2 :          qs_control%semi_empirical = .TRUE.
     962             :       CASE (do_method_mndod)
     963          16 :          CALL cite_reference(Dewar1977)
     964          16 :          CALL cite_reference(Thiel1992)
     965        7382 :          qs_control%semi_empirical = .TRUE.
     966             :       END SELECT
     967             : 
     968        7366 :       CALL section_vals_get(mull_section, explicit=qs_control%mulliken_restraint)
     969             : 
     970        7366 :       IF (qs_control%mulliken_restraint) THEN
     971           2 :          CALL section_vals_val_get(mull_section, "STRENGTH", r_val=qs_control%mulliken_restraint_control%strength)
     972           2 :          CALL section_vals_val_get(mull_section, "TARGET", r_val=qs_control%mulliken_restraint_control%target)
     973           2 :          CALL section_vals_val_get(mull_section, "ATOMS", n_rep_val=n_rep)
     974           2 :          jj = 0
     975           4 :          DO k = 1, n_rep
     976           2 :             CALL section_vals_val_get(mull_section, "ATOMS", i_rep_val=k, i_vals=tmplist)
     977           4 :             jj = jj + SIZE(tmplist)
     978             :          END DO
     979           2 :          qs_control%mulliken_restraint_control%natoms = jj
     980           2 :          IF (qs_control%mulliken_restraint_control%natoms < 1) &
     981           0 :             CPABORT("Need at least 1 atom to use mulliken constraints")
     982           6 :          ALLOCATE (qs_control%mulliken_restraint_control%atoms(qs_control%mulliken_restraint_control%natoms))
     983           2 :          jj = 0
     984           6 :          DO k = 1, n_rep
     985           2 :             CALL section_vals_val_get(mull_section, "ATOMS", i_rep_val=k, i_vals=tmplist)
     986           6 :             DO j = 1, SIZE(tmplist)
     987           2 :                jj = jj + 1
     988           4 :                qs_control%mulliken_restraint_control%atoms(jj) = tmplist(j)
     989             :             END DO
     990             :          END DO
     991             :       END IF
     992        7366 :       CALL section_vals_get(ddapc_restraint_section, n_repetition=nrep, explicit=qs_control%ddapc_restraint)
     993        7366 :       IF (qs_control%ddapc_restraint) THEN
     994          60 :          ALLOCATE (qs_control%ddapc_restraint_control(nrep))
     995          14 :          CALL read_ddapc_section(qs_control, qs_section=qs_section)
     996          14 :          qs_control%ddapc_restraint_is_spin = .FALSE.
     997          14 :          qs_control%ddapc_explicit_potential = .FALSE.
     998             :       END IF
     999             : 
    1000        7366 :       CALL section_vals_get(s2_restraint_section, explicit=qs_control%s2_restraint)
    1001        7366 :       IF (qs_control%s2_restraint) THEN
    1002             :          CALL section_vals_val_get(s2_restraint_section, "STRENGTH", &
    1003           0 :                                    r_val=qs_control%s2_restraint_control%strength)
    1004             :          CALL section_vals_val_get(s2_restraint_section, "TARGET", &
    1005           0 :                                    r_val=qs_control%s2_restraint_control%target)
    1006             :          CALL section_vals_val_get(s2_restraint_section, "FUNCTIONAL_FORM", &
    1007           0 :                                    i_val=qs_control%s2_restraint_control%functional_form)
    1008             :       END IF
    1009             : 
    1010        7366 :       CALL section_vals_get(cdft_control_section, explicit=qs_control%cdft)
    1011        7366 :       IF (qs_control%cdft) THEN
    1012         264 :          CALL read_cdft_control_section(qs_control, cdft_control_section)
    1013             :       END IF
    1014             : 
    1015             :       ! Semi-empirical code
    1016        7366 :       IF (qs_control%semi_empirical) THEN
    1017             :          CALL section_vals_val_get(se_section, "ORTHOGONAL_BASIS", &
    1018         998 :                                    l_val=qs_control%se_control%orthogonal_basis)
    1019             :          CALL section_vals_val_get(se_section, "DELTA", &
    1020         998 :                                    r_val=qs_control%se_control%delta)
    1021             :          CALL section_vals_val_get(se_section, "ANALYTICAL_GRADIENTS", &
    1022         998 :                                    l_val=qs_control%se_control%analytical_gradients)
    1023             :          CALL section_vals_val_get(se_section, "FORCE_KDSO-D_EXCHANGE", &
    1024         998 :                                    l_val=qs_control%se_control%force_kdsod_EX)
    1025             :          ! Integral Screening
    1026             :          CALL section_vals_val_get(se_section, "INTEGRAL_SCREENING", &
    1027         998 :                                    i_val=qs_control%se_control%integral_screening)
    1028         998 :          IF (qs_control%method_id == do_method_pnnl) THEN
    1029          14 :             IF (qs_control%se_control%integral_screening /= do_se_IS_slater) &
    1030             :                CALL cp_warn(__LOCATION__, &
    1031             :                             "PNNL semi-empirical parameterization supports only the Slater type "// &
    1032           0 :                             "integral scheme. Revert to Slater and continue the calculation.")
    1033          14 :             qs_control%se_control%integral_screening = do_se_IS_slater
    1034             :          END IF
    1035             :          ! Global Arrays variable
    1036             :          CALL section_vals_val_get(se_section, "GA%NCELLS", &
    1037         998 :                                    i_val=qs_control%se_control%ga_ncells)
    1038             :          ! Long-Range correction
    1039             :          CALL section_vals_val_get(se_section, "LR_CORRECTION%CUTOFF", &
    1040         998 :                                    r_val=qs_control%se_control%cutoff_lrc)
    1041         998 :          qs_control%se_control%taper_lrc = qs_control%se_control%cutoff_lrc
    1042             :          CALL section_vals_val_get(se_section, "LR_CORRECTION%RC_TAPER", &
    1043         998 :                                    explicit=explicit)
    1044         998 :          IF (explicit) THEN
    1045             :             CALL section_vals_val_get(se_section, "LR_CORRECTION%RC_TAPER", &
    1046           0 :                                       r_val=qs_control%se_control%taper_lrc)
    1047             :          END IF
    1048             :          CALL section_vals_val_get(se_section, "LR_CORRECTION%RC_RANGE", &
    1049         998 :                                    r_val=qs_control%se_control%range_lrc)
    1050             :          ! Coulomb
    1051             :          CALL section_vals_val_get(se_section, "COULOMB%CUTOFF", &
    1052         998 :                                    r_val=qs_control%se_control%cutoff_cou)
    1053         998 :          qs_control%se_control%taper_cou = qs_control%se_control%cutoff_cou
    1054             :          CALL section_vals_val_get(se_section, "COULOMB%RC_TAPER", &
    1055         998 :                                    explicit=explicit)
    1056         998 :          IF (explicit) THEN
    1057             :             CALL section_vals_val_get(se_section, "COULOMB%RC_TAPER", &
    1058           0 :                                       r_val=qs_control%se_control%taper_cou)
    1059             :          END IF
    1060             :          CALL section_vals_val_get(se_section, "COULOMB%RC_RANGE", &
    1061         998 :                                    r_val=qs_control%se_control%range_cou)
    1062             :          ! Exchange
    1063             :          CALL section_vals_val_get(se_section, "EXCHANGE%CUTOFF", &
    1064         998 :                                    r_val=qs_control%se_control%cutoff_exc)
    1065         998 :          qs_control%se_control%taper_exc = qs_control%se_control%cutoff_exc
    1066             :          CALL section_vals_val_get(se_section, "EXCHANGE%RC_TAPER", &
    1067         998 :                                    explicit=explicit)
    1068         998 :          IF (explicit) THEN
    1069             :             CALL section_vals_val_get(se_section, "EXCHANGE%RC_TAPER", &
    1070          38 :                                       r_val=qs_control%se_control%taper_exc)
    1071             :          END IF
    1072             :          CALL section_vals_val_get(se_section, "EXCHANGE%RC_RANGE", &
    1073         998 :                                    r_val=qs_control%se_control%range_exc)
    1074             :          ! Screening (only if the integral scheme is of dumped type)
    1075         998 :          IF (qs_control%se_control%integral_screening == do_se_IS_kdso_d) THEN
    1076             :             CALL section_vals_val_get(se_section, "SCREENING%RC_TAPER", &
    1077          14 :                                       r_val=qs_control%se_control%taper_scr)
    1078             :             CALL section_vals_val_get(se_section, "SCREENING%RC_RANGE", &
    1079          14 :                                       r_val=qs_control%se_control%range_scr)
    1080             :          END IF
    1081             :          ! Periodic Type Calculation
    1082             :          CALL section_vals_val_get(se_section, "PERIODIC", &
    1083         998 :                                    i_val=qs_control%se_control%periodic_type)
    1084        1964 :          SELECT CASE (qs_control%se_control%periodic_type)
    1085             :          CASE (do_se_lr_none)
    1086         966 :             qs_control%se_control%do_ewald = .FALSE.
    1087         966 :             qs_control%se_control%do_ewald_r3 = .FALSE.
    1088         966 :             qs_control%se_control%do_ewald_gks = .FALSE.
    1089             :          CASE (do_se_lr_ewald)
    1090          30 :             qs_control%se_control%do_ewald = .TRUE.
    1091          30 :             qs_control%se_control%do_ewald_r3 = .FALSE.
    1092          30 :             qs_control%se_control%do_ewald_gks = .FALSE.
    1093             :          CASE (do_se_lr_ewald_gks)
    1094           2 :             qs_control%se_control%do_ewald = .FALSE.
    1095           2 :             qs_control%se_control%do_ewald_r3 = .FALSE.
    1096           2 :             qs_control%se_control%do_ewald_gks = .TRUE.
    1097           2 :             IF (qs_control%method_id /= do_method_pnnl) &
    1098             :                CALL cp_abort(__LOCATION__, &
    1099             :                              "A periodic semi-empirical calculation was requested with a long-range  "// &
    1100             :                              "summation on the single integral evaluation. This scheme is supported  "// &
    1101           0 :                              "only by the PNNL parameterization.")
    1102             :          CASE (do_se_lr_ewald_r3)
    1103           0 :             qs_control%se_control%do_ewald = .TRUE.
    1104           0 :             qs_control%se_control%do_ewald_r3 = .TRUE.
    1105           0 :             qs_control%se_control%do_ewald_gks = .FALSE.
    1106           0 :             IF (qs_control%se_control%integral_screening /= do_se_IS_kdso) &
    1107             :                CALL cp_abort(__LOCATION__, &
    1108             :                              "A periodic semi-empirical calculation was requested with a long-range  "// &
    1109             :                              "summation for the slowly convergent part 1/R^3, which is not congruent "// &
    1110             :                              "with the integral screening chosen. The only integral screening supported "// &
    1111         998 :                              "by this periodic type calculation is the standard Klopman-Dewar-Sabelli-Ohno.")
    1112             :          END SELECT
    1113             : 
    1114             :          ! dispersion pair potentials
    1115             :          CALL section_vals_val_get(se_section, "DISPERSION", &
    1116         998 :                                    l_val=qs_control%se_control%dispersion)
    1117             :          CALL section_vals_val_get(se_section, "DISPERSION_RADIUS", &
    1118         998 :                                    r_val=qs_control%se_control%rcdisp)
    1119             :          CALL section_vals_val_get(se_section, "COORDINATION_CUTOFF", &
    1120         998 :                                    r_val=qs_control%se_control%epscn)
    1121         998 :          CALL section_vals_val_get(se_section, "D3_SCALING", r_vals=scal)
    1122         998 :          qs_control%se_control%sd3(1) = scal(1)
    1123         998 :          qs_control%se_control%sd3(2) = scal(2)
    1124         998 :          qs_control%se_control%sd3(3) = scal(3)
    1125             :          CALL section_vals_val_get(se_section, "DISPERSION_PARAMETER_FILE", &
    1126         998 :                                    c_val=qs_control%se_control%dispersion_parameter_file)
    1127             : 
    1128             :          ! Stop the execution for non-implemented features
    1129         998 :          IF (qs_control%se_control%periodic_type == do_se_lr_ewald_r3) THEN
    1130           0 :             CPABORT("EWALD_R3 not implemented yet!")
    1131             :          END IF
    1132             : 
    1133             :          IF (qs_control%method_id == do_method_mndo .OR. &
    1134             :              qs_control%method_id == do_method_am1 .OR. &
    1135             :              qs_control%method_id == do_method_mndod .OR. &
    1136             :              qs_control%method_id == do_method_pdg .OR. &
    1137             :              qs_control%method_id == do_method_pm3 .OR. &
    1138             :              qs_control%method_id == do_method_pm6 .OR. &
    1139             :              qs_control%method_id == do_method_pm6fm .OR. &
    1140         998 :              qs_control%method_id == do_method_pnnl .OR. &
    1141             :              qs_control%method_id == do_method_rm1) THEN
    1142         998 :             qs_control%se_control%orthogonal_basis = .TRUE.
    1143             :          END IF
    1144             :       END IF
    1145             : 
    1146             :       ! DFTB code
    1147        7366 :       IF (qs_control%dftb) THEN
    1148             :          CALL section_vals_val_get(dftb_section, "ORTHOGONAL_BASIS", &
    1149         222 :                                    l_val=qs_control%dftb_control%orthogonal_basis)
    1150             :          CALL section_vals_val_get(dftb_section, "SELF_CONSISTENT", &
    1151         222 :                                    l_val=qs_control%dftb_control%self_consistent)
    1152             :          CALL section_vals_val_get(dftb_section, "DISPERSION", &
    1153         222 :                                    l_val=qs_control%dftb_control%dispersion)
    1154             :          CALL section_vals_val_get(dftb_section, "DIAGONAL_DFTB3", &
    1155         222 :                                    l_val=qs_control%dftb_control%dftb3_diagonal)
    1156             :          CALL section_vals_val_get(dftb_section, "HB_SR_GAMMA", &
    1157         222 :                                    l_val=qs_control%dftb_control%hb_sr_damp)
    1158             :          CALL section_vals_val_get(dftb_section, "EPS_DISP", &
    1159         222 :                                    r_val=qs_control%dftb_control%eps_disp)
    1160         222 :          CALL section_vals_val_get(dftb_section, "DO_EWALD", explicit=explicit)
    1161         222 :          IF (explicit) THEN
    1162             :             CALL section_vals_val_get(dftb_section, "DO_EWALD", &
    1163         166 :                                       l_val=qs_control%dftb_control%do_ewald)
    1164             :          ELSE
    1165          56 :             qs_control%dftb_control%do_ewald = (qs_control%periodicity /= 0)
    1166             :          END IF
    1167             :          CALL section_vals_val_get(dftb_parameter, "PARAM_FILE_PATH", &
    1168         222 :                                    c_val=qs_control%dftb_control%sk_file_path)
    1169             :          CALL section_vals_val_get(dftb_parameter, "PARAM_FILE_NAME", &
    1170         222 :                                    c_val=qs_control%dftb_control%sk_file_list)
    1171             :          CALL section_vals_val_get(dftb_parameter, "HB_SR_PARAM", &
    1172         222 :                                    r_val=qs_control%dftb_control%hb_sr_para)
    1173         222 :          CALL section_vals_val_get(dftb_parameter, "SK_FILE", n_rep_val=n_var)
    1174         470 :          ALLOCATE (qs_control%dftb_control%sk_pair_list(3, n_var))
    1175         284 :          DO k = 1, n_var
    1176             :             CALL section_vals_val_get(dftb_parameter, "SK_FILE", i_rep_val=k, &
    1177          62 :                                       c_vals=clist)
    1178         470 :             qs_control%dftb_control%sk_pair_list(1:3, k) = clist(1:3)
    1179             :          END DO
    1180             :          ! Dispersion type
    1181             :          CALL section_vals_val_get(dftb_parameter, "DISPERSION_TYPE", &
    1182         222 :                                    i_val=qs_control%dftb_control%dispersion_type)
    1183             :          CALL section_vals_val_get(dftb_parameter, "UFF_FORCE_FIELD", &
    1184         222 :                                    c_val=qs_control%dftb_control%uff_force_field)
    1185             :          ! D3 Dispersion
    1186             :          CALL section_vals_val_get(dftb_parameter, "DISPERSION_RADIUS", &
    1187         222 :                                    r_val=qs_control%dftb_control%rcdisp)
    1188             :          CALL section_vals_val_get(dftb_parameter, "COORDINATION_CUTOFF", &
    1189         222 :                                    r_val=qs_control%dftb_control%epscn)
    1190             :          CALL section_vals_val_get(dftb_parameter, "D2_EXP_PRE", &
    1191         222 :                                    r_val=qs_control%dftb_control%exp_pre)
    1192             :          CALL section_vals_val_get(dftb_parameter, "D2_SCALING", &
    1193         222 :                                    r_val=qs_control%dftb_control%scaling)
    1194         222 :          CALL section_vals_val_get(dftb_parameter, "D3_SCALING", r_vals=scal)
    1195         222 :          qs_control%dftb_control%sd3(1) = scal(1)
    1196         222 :          qs_control%dftb_control%sd3(2) = scal(2)
    1197         222 :          qs_control%dftb_control%sd3(3) = scal(3)
    1198         222 :          CALL section_vals_val_get(dftb_parameter, "D3BJ_SCALING", r_vals=scal)
    1199         222 :          qs_control%dftb_control%sd3bj(1) = scal(1)
    1200         222 :          qs_control%dftb_control%sd3bj(2) = scal(2)
    1201         222 :          qs_control%dftb_control%sd3bj(3) = scal(3)
    1202         222 :          qs_control%dftb_control%sd3bj(4) = scal(4)
    1203             :          CALL section_vals_val_get(dftb_parameter, "DISPERSION_PARAMETER_FILE", &
    1204         222 :                                    c_val=qs_control%dftb_control%dispersion_parameter_file)
    1205             : 
    1206         222 :          IF (qs_control%dftb_control%dispersion) CALL cite_reference(Zhechkov2005)
    1207         222 :          IF (qs_control%dftb_control%self_consistent) CALL cite_reference(Elstner1998)
    1208         666 :          IF (qs_control%dftb_control%hb_sr_damp) CALL cite_reference(Hu2007)
    1209             :       END IF
    1210             : 
    1211             :       ! xTB code
    1212        7366 :       IF (qs_control%xtb) THEN
    1213         940 :          CALL section_vals_val_get(xtb_section, "GFN_TYPE", i_val=qs_control%xtb_control%gfn_type)
    1214         940 :          CALL section_vals_val_get(xtb_section, "DO_EWALD", explicit=explicit)
    1215         940 :          IF (explicit) THEN
    1216             :             CALL section_vals_val_get(xtb_section, "DO_EWALD", &
    1217         756 :                                       l_val=qs_control%xtb_control%do_ewald)
    1218             :          ELSE
    1219         184 :             qs_control%xtb_control%do_ewald = (qs_control%periodicity /= 0)
    1220             :          END IF
    1221             :          ! vdW
    1222         940 :          CALL section_vals_val_get(xtb_section, "VDW_POTENTIAL", explicit=explicit)
    1223         940 :          IF (explicit) THEN
    1224         660 :             CALL section_vals_val_get(xtb_section, "VDW_POTENTIAL", c_val=cval)
    1225         660 :             CALL uppercase(cval)
    1226           0 :             SELECT CASE (cval)
    1227             :             CASE ("NONE")
    1228           0 :                qs_control%xtb_control%vdw_type = xtb_vdw_type_none
    1229             :             CASE ("DFTD3")
    1230          36 :                qs_control%xtb_control%vdw_type = xtb_vdw_type_d3
    1231             :             CASE ("DFTD4")
    1232         624 :                qs_control%xtb_control%vdw_type = xtb_vdw_type_d4
    1233             :             CASE DEFAULT
    1234         660 :                CPABORT("vdW type")
    1235             :             END SELECT
    1236             :          ELSE
    1237         296 :             SELECT CASE (qs_control%xtb_control%gfn_type)
    1238             :             CASE (0)
    1239          16 :                qs_control%xtb_control%vdw_type = xtb_vdw_type_d4
    1240             :             CASE (1)
    1241         264 :                qs_control%xtb_control%vdw_type = xtb_vdw_type_d3
    1242             :             CASE (2)
    1243           0 :                qs_control%xtb_control%vdw_type = xtb_vdw_type_d4
    1244           0 :                CPABORT("gfn2-xtb tbd")
    1245             :             CASE DEFAULT
    1246         280 :                CPABORT("GFN type")
    1247             :             END SELECT
    1248             :          END IF
    1249             :          !
    1250         940 :          CALL section_vals_val_get(xtb_section, "STO_NG", i_val=ngauss)
    1251         940 :          qs_control%xtb_control%sto_ng = ngauss
    1252         940 :          CALL section_vals_val_get(xtb_section, "HYDROGEN_STO_NG", i_val=ngauss)
    1253         940 :          qs_control%xtb_control%h_sto_ng = ngauss
    1254             :          CALL section_vals_val_get(xtb_parameter, "PARAM_FILE_PATH", &
    1255         940 :                                    c_val=qs_control%xtb_control%parameter_file_path)
    1256         940 :          CALL section_vals_val_get(xtb_parameter, "PARAM_FILE_NAME", explicit=explicit)
    1257         940 :          IF (explicit) THEN
    1258             :             CALL section_vals_val_get(xtb_parameter, "PARAM_FILE_NAME", &
    1259           0 :                                       c_val=qs_control%xtb_control%parameter_file_name)
    1260             :          ELSE
    1261        1614 :             SELECT CASE (qs_control%xtb_control%gfn_type)
    1262             :             CASE (0)
    1263         674 :                qs_control%xtb_control%parameter_file_name = "xTB0_parameters"
    1264             :             CASE (1)
    1265         266 :                qs_control%xtb_control%parameter_file_name = "xTB1_parameters"
    1266             :             CASE (2)
    1267           0 :                CPABORT("gfn2-xtb tbd")
    1268             :             CASE DEFAULT
    1269         940 :                CPABORT("GFN type")
    1270             :             END SELECT
    1271             :          END IF
    1272             :          ! D3 Dispersion
    1273             :          CALL section_vals_val_get(xtb_parameter, "DISPERSION_RADIUS", &
    1274         940 :                                    r_val=qs_control%xtb_control%rcdisp)
    1275             :          CALL section_vals_val_get(xtb_parameter, "COORDINATION_CUTOFF", &
    1276         940 :                                    r_val=qs_control%xtb_control%epscn)
    1277         940 :          CALL section_vals_val_get(xtb_parameter, "D3BJ_SCALING", explicit=explicit)
    1278         940 :          IF (explicit) THEN
    1279           0 :             CALL section_vals_val_get(xtb_parameter, "D3BJ_SCALING", r_vals=scal)
    1280           0 :             qs_control%xtb_control%s6 = scal(1)
    1281           0 :             qs_control%xtb_control%s8 = scal(2)
    1282             :          ELSE
    1283        1614 :             SELECT CASE (qs_control%xtb_control%gfn_type)
    1284             :             CASE (0)
    1285         674 :                qs_control%xtb_control%s6 = 1.00_dp
    1286         674 :                qs_control%xtb_control%s8 = 2.85_dp
    1287             :             CASE (1)
    1288         266 :                qs_control%xtb_control%s6 = 1.00_dp
    1289         266 :                qs_control%xtb_control%s8 = 2.40_dp
    1290             :             CASE (2)
    1291           0 :                CPABORT("gfn2-xtb tbd")
    1292             :             CASE DEFAULT
    1293         940 :                CPABORT("GFN type")
    1294             :             END SELECT
    1295             :          END IF
    1296         940 :          CALL section_vals_val_get(xtb_parameter, "D3BJ_PARAM", explicit=explicit)
    1297         940 :          IF (explicit) THEN
    1298           0 :             CALL section_vals_val_get(xtb_parameter, "D3BJ_PARAM", r_vals=scal)
    1299           0 :             qs_control%xtb_control%a1 = scal(1)
    1300           0 :             qs_control%xtb_control%a2 = scal(2)
    1301             :          ELSE
    1302        1614 :             SELECT CASE (qs_control%xtb_control%gfn_type)
    1303             :             CASE (0)
    1304         674 :                qs_control%xtb_control%a1 = 0.80_dp
    1305         674 :                qs_control%xtb_control%a2 = 4.60_dp
    1306             :             CASE (1)
    1307         266 :                qs_control%xtb_control%a1 = 0.63_dp
    1308         266 :                qs_control%xtb_control%a2 = 5.00_dp
    1309             :             CASE (2)
    1310           0 :                CPABORT("gfn2-xtb tbd")
    1311             :             CASE DEFAULT
    1312         940 :                CPABORT("GFN type")
    1313             :             END SELECT
    1314             :          END IF
    1315             :          CALL section_vals_val_get(xtb_parameter, "DISPERSION_PARAMETER_FILE", &
    1316         940 :                                    c_val=qs_control%xtb_control%dispersion_parameter_file)
    1317             :          ! global parameters
    1318         940 :          CALL section_vals_val_get(xtb_parameter, "HUCKEL_CONSTANTS", explicit=explicit)
    1319         940 :          IF (explicit) THEN
    1320           0 :             CALL section_vals_val_get(xtb_parameter, "HUCKEL_CONSTANTS", r_vals=scal)
    1321           0 :             qs_control%xtb_control%ks = scal(1)
    1322           0 :             qs_control%xtb_control%kp = scal(2)
    1323           0 :             qs_control%xtb_control%kd = scal(3)
    1324           0 :             qs_control%xtb_control%ksp = scal(4)
    1325           0 :             qs_control%xtb_control%k2sh = scal(5)
    1326           0 :             IF (qs_control%xtb_control%gfn_type == 0) THEN
    1327             :                ! enforce ksp for gfn0
    1328           0 :                qs_control%xtb_control%ksp = 0.5_dp*(scal(1) + scal(2))
    1329             :             END IF
    1330             :          ELSE
    1331        1614 :             SELECT CASE (qs_control%xtb_control%gfn_type)
    1332             :             CASE (0)
    1333         674 :                qs_control%xtb_control%ks = 2.00_dp
    1334         674 :                qs_control%xtb_control%kp = 2.4868_dp
    1335         674 :                qs_control%xtb_control%kd = 2.27_dp
    1336         674 :                qs_control%xtb_control%ksp = 2.2434_dp
    1337         674 :                qs_control%xtb_control%k2sh = 1.1241_dp
    1338             :             CASE (1)
    1339         266 :                qs_control%xtb_control%ks = 1.85_dp
    1340         266 :                qs_control%xtb_control%kp = 2.25_dp
    1341         266 :                qs_control%xtb_control%kd = 2.00_dp
    1342         266 :                qs_control%xtb_control%ksp = 2.08_dp
    1343         266 :                qs_control%xtb_control%k2sh = 2.85_dp
    1344             :             CASE (2)
    1345           0 :                CPABORT("gfn2-xtb tbd")
    1346             :             CASE DEFAULT
    1347         940 :                CPABORT("GFN type")
    1348             :             END SELECT
    1349             :          END IF
    1350         940 :          CALL section_vals_val_get(xtb_parameter, "COULOMB_CONSTANTS", explicit=explicit)
    1351         940 :          IF (explicit) THEN
    1352           0 :             CALL section_vals_val_get(xtb_parameter, "COULOMB_CONSTANTS", r_vals=scal)
    1353           0 :             qs_control%xtb_control%kg = scal(1)
    1354           0 :             qs_control%xtb_control%kf = scal(2)
    1355             :          ELSE
    1356        1614 :             SELECT CASE (qs_control%xtb_control%gfn_type)
    1357             :             CASE (0)
    1358         674 :                qs_control%xtb_control%kg = 2.00_dp
    1359         674 :                qs_control%xtb_control%kf = 1.50_dp
    1360             :             CASE (1)
    1361         266 :                qs_control%xtb_control%kg = 2.00_dp
    1362         266 :                qs_control%xtb_control%kf = 1.50_dp
    1363             :             CASE (2)
    1364           0 :                CPABORT("gfn2-xtb tbd")
    1365             :             CASE DEFAULT
    1366         940 :                CPABORT("GFN type")
    1367             :             END SELECT
    1368             :          END IF
    1369         940 :          CALL section_vals_val_get(xtb_parameter, "CN_CONSTANTS", r_vals=scal)
    1370         940 :          qs_control%xtb_control%kcns = scal(1)
    1371         940 :          qs_control%xtb_control%kcnp = scal(2)
    1372         940 :          qs_control%xtb_control%kcnd = scal(3)
    1373             :          !
    1374         940 :          CALL section_vals_val_get(xtb_parameter, "EN_CONSTANTS", explicit=explicit)
    1375         940 :          IF (explicit) THEN
    1376           0 :             CALL section_vals_val_get(xtb_parameter, "EN_CONSTANTS", r_vals=scal)
    1377           0 :             SELECT CASE (qs_control%xtb_control%gfn_type)
    1378             :             CASE (0)
    1379           0 :                qs_control%xtb_control%ksen = scal(1)
    1380           0 :                qs_control%xtb_control%kpen = scal(2)
    1381           0 :                qs_control%xtb_control%kden = scal(3)
    1382             :             CASE (1)
    1383           0 :                qs_control%xtb_control%ken = scal(1)
    1384             :             CASE (2)
    1385           0 :                CPABORT("gfn2-xtb tbd")
    1386             :             CASE DEFAULT
    1387           0 :                CPABORT("GFN type")
    1388             :             END SELECT
    1389             :          ELSE
    1390        1614 :             SELECT CASE (qs_control%xtb_control%gfn_type)
    1391             :             CASE (0)
    1392         674 :                qs_control%xtb_control%ksen = 0.006_dp
    1393         674 :                qs_control%xtb_control%kpen = -0.001_dp
    1394         674 :                qs_control%xtb_control%kden = -0.002_dp
    1395             :             CASE (1)
    1396         266 :                qs_control%xtb_control%ken = -0.007_dp
    1397             :             CASE (2)
    1398           0 :                CPABORT("gfn2-xtb tbd")
    1399             :             CASE DEFAULT
    1400         940 :                CPABORT("GFN type")
    1401             :             END SELECT
    1402             :          END IF
    1403             :          ! ben
    1404         940 :          CALL section_vals_val_get(xtb_parameter, "BEN_CONSTANT", r_vals=scal)
    1405         940 :          qs_control%xtb_control%ben = scal(1)
    1406             :          ! enscale (hidden parameter in repulsion
    1407         940 :          CALL section_vals_val_get(xtb_parameter, "ENSCALE", explicit=explicit)
    1408         940 :          IF (explicit) THEN
    1409             :             CALL section_vals_val_get(xtb_parameter, "ENSCALE", &
    1410           0 :                                       r_val=qs_control%xtb_control%enscale)
    1411             :          ELSE
    1412        1614 :             SELECT CASE (qs_control%xtb_control%gfn_type)
    1413             :             CASE (0)
    1414         674 :                qs_control%xtb_control%enscale = -0.09_dp
    1415             :             CASE (1)
    1416         266 :                qs_control%xtb_control%enscale = 0._dp
    1417             :             CASE (2)
    1418           0 :                CPABORT("gfn2-xtb tbd")
    1419             :             CASE DEFAULT
    1420         940 :                CPABORT("GFN type")
    1421             :             END SELECT
    1422             :          END IF
    1423             :          ! XB
    1424             :          CALL section_vals_val_get(xtb_section, "USE_HALOGEN_CORRECTION", &
    1425         940 :                                    l_val=qs_control%xtb_control%xb_interaction)
    1426         940 :          CALL section_vals_val_get(xtb_parameter, "HALOGEN_BINDING", r_vals=scal)
    1427         940 :          qs_control%xtb_control%kxr = scal(1)
    1428         940 :          qs_control%xtb_control%kx2 = scal(2)
    1429             :          ! NONBONDED interactions
    1430             :          CALL section_vals_val_get(xtb_section, "DO_NONBONDED", &
    1431         940 :                                    l_val=qs_control%xtb_control%do_nonbonded)
    1432         940 :          CALL section_vals_get(nonbonded_section, explicit=explicit)
    1433         940 :          IF (explicit .AND. qs_control%xtb_control%do_nonbonded) THEN
    1434           6 :             CALL section_vals_get(genpot_section, explicit=explicit, n_repetition=ngp)
    1435           6 :             IF (explicit) THEN
    1436           6 :                CALL pair_potential_reallocate(qs_control%xtb_control%nonbonded, 1, ngp, gp=.TRUE.)
    1437           6 :                CALL read_gp_section(qs_control%xtb_control%nonbonded, genpot_section, 0)
    1438             :             END IF
    1439             :          END IF !nonbonded
    1440             :          CALL section_vals_val_get(xtb_section, "EPS_PAIRPOTENTIAL", &
    1441         940 :                                    r_val=qs_control%xtb_control%eps_pair)
    1442             :          ! SR Coulomb
    1443         940 :          CALL section_vals_val_get(xtb_parameter, "COULOMB_SR_CUT", r_vals=scal)
    1444         940 :          qs_control%xtb_control%coulomb_sr_cut = scal(1)
    1445         940 :          CALL section_vals_val_get(xtb_parameter, "COULOMB_SR_EPS", r_vals=scal)
    1446         940 :          qs_control%xtb_control%coulomb_sr_eps = scal(1)
    1447             :          ! XB_radius
    1448         940 :          CALL section_vals_val_get(xtb_parameter, "XB_RADIUS", r_val=qs_control%xtb_control%xb_radius)
    1449             :          ! Kab
    1450         940 :          CALL section_vals_val_get(xtb_parameter, "KAB_PARAM", n_rep_val=n_rep)
    1451             :          ! Coulomb
    1452        1614 :          SELECT CASE (qs_control%xtb_control%gfn_type)
    1453             :          CASE (0)
    1454         674 :             qs_control%xtb_control%coulomb_interaction = .FALSE.
    1455         674 :             qs_control%xtb_control%coulomb_lr = .FALSE.
    1456         674 :             qs_control%xtb_control%tb3_interaction = .FALSE.
    1457         674 :             qs_control%xtb_control%check_atomic_charges = .FALSE.
    1458             :             CALL section_vals_val_get(xtb_section, "VARIATIONAL_DIPOLE", &
    1459         674 :                                       l_val=qs_control%xtb_control%var_dipole)
    1460             :          CASE (1)
    1461             :             ! For debugging purposes
    1462             :             CALL section_vals_val_get(xtb_section, "COULOMB_INTERACTION", &
    1463         266 :                                       l_val=qs_control%xtb_control%coulomb_interaction)
    1464             :             CALL section_vals_val_get(xtb_section, "COULOMB_LR", &
    1465         266 :                                       l_val=qs_control%xtb_control%coulomb_lr)
    1466             :             CALL section_vals_val_get(xtb_section, "TB3_INTERACTION", &
    1467         266 :                                       l_val=qs_control%xtb_control%tb3_interaction)
    1468             :             ! Check for bad atomic charges
    1469             :             CALL section_vals_val_get(xtb_section, "CHECK_ATOMIC_CHARGES", &
    1470         266 :                                       l_val=qs_control%xtb_control%check_atomic_charges)
    1471         266 :             qs_control%xtb_control%var_dipole = .FALSE.
    1472             :          CASE (2)
    1473           0 :             CPABORT("gfn2-xtb tbd")
    1474             :          CASE DEFAULT
    1475         940 :             CPABORT("GFN type")
    1476             :          END SELECT
    1477         940 :          qs_control%xtb_control%kab_nval = n_rep
    1478         940 :          IF (n_rep > 0) THEN
    1479           6 :             ALLOCATE (qs_control%xtb_control%kab_param(3, n_rep))
    1480           6 :             ALLOCATE (qs_control%xtb_control%kab_types(2, n_rep))
    1481           6 :             ALLOCATE (qs_control%xtb_control%kab_vals(n_rep))
    1482           4 :             DO j = 1, n_rep
    1483           2 :                CALL section_vals_val_get(xtb_parameter, "KAB_PARAM", i_rep_val=j, c_vals=clist)
    1484           2 :                qs_control%xtb_control%kab_param(1, j) = clist(1)
    1485             :                CALL get_ptable_info(clist(1), &
    1486           2 :                                     ielement=qs_control%xtb_control%kab_types(1, j))
    1487           2 :                qs_control%xtb_control%kab_param(2, j) = clist(2)
    1488             :                CALL get_ptable_info(clist(2), &
    1489           2 :                                     ielement=qs_control%xtb_control%kab_types(2, j))
    1490           2 :                qs_control%xtb_control%kab_param(3, j) = clist(3)
    1491           4 :                READ (clist(3), '(F10.0)') qs_control%xtb_control%kab_vals(j)
    1492             :             END DO
    1493             :          END IF
    1494             : 
    1495         940 :          IF (qs_control%xtb_control%gfn_type == 0) THEN
    1496         674 :             CALL section_vals_val_get(xtb_parameter, "SRB_PARAMETER", r_vals=scal)
    1497         674 :             qs_control%xtb_control%ksrb = scal(1)
    1498         674 :             qs_control%xtb_control%esrb = scal(2)
    1499         674 :             qs_control%xtb_control%gscal = scal(3)
    1500         674 :             qs_control%xtb_control%c1srb = scal(4)
    1501         674 :             qs_control%xtb_control%c2srb = scal(5)
    1502         674 :             qs_control%xtb_control%shift = scal(6)
    1503             :          END IF
    1504             : 
    1505         940 :          CALL section_vals_val_get(xtb_section, "EN_SHIFT_TYPE", c_val=cval)
    1506         940 :          CALL uppercase(cval)
    1507         940 :          SELECT CASE (TRIM(cval))
    1508             :          CASE ("SELECT")
    1509           0 :             qs_control%xtb_control%enshift_type = 0
    1510             :          CASE ("MOLECULE")
    1511         940 :             qs_control%xtb_control%enshift_type = 1
    1512             :          CASE ("CRYSTAL")
    1513           0 :             qs_control%xtb_control%enshift_type = 2
    1514             :          CASE DEFAULT
    1515         940 :             CPABORT("Unknown value for EN_SHIFT_TYPE")
    1516             :          END SELECT
    1517             : 
    1518             :          ! EEQ solver params
    1519         940 :          CALL read_eeq_param(eeq_section, qs_control%xtb_control%eeq_sparam)
    1520             : 
    1521             :       END IF
    1522             : 
    1523             :       ! Optimize LRI basis set
    1524        7366 :       CALL section_vals_get(lri_optbas_section, explicit=qs_control%lri_optbas)
    1525             : 
    1526        7366 :       CALL timestop(handle)
    1527        7366 :    END SUBROUTINE read_qs_section
    1528             : 
    1529             : ! **************************************************************************************************
    1530             : !> \brief ...
    1531             : !> \param t_control ...
    1532             : !> \param dft_section ...
    1533             : ! **************************************************************************************************
    1534          12 :    SUBROUTINE read_tddfpt_control(t_control, dft_section)
    1535             :       TYPE(tddfpt_control_type)                          :: t_control
    1536             :       TYPE(section_vals_type), POINTER                   :: dft_section
    1537             : 
    1538             :       LOGICAL                                            :: kenergy_den
    1539             :       TYPE(section_vals_type), POINTER                   :: sic_section, t_section
    1540             : 
    1541          12 :       kenergy_den = .FALSE.
    1542          12 :       NULLIFY (sic_section, t_section)
    1543          12 :       t_section => section_vals_get_subs_vals(dft_section, "TDDFPT")
    1544             : 
    1545          12 :       CALL section_vals_val_get(t_section, "CONVERGENCE", r_val=t_control%tolerance)
    1546          12 :       CALL section_vals_val_get(t_section, "NEV", i_val=t_control%n_ev)
    1547          12 :       CALL section_vals_val_get(t_section, "MAX_KV", i_val=t_control%max_kv)
    1548          12 :       CALL section_vals_val_get(t_section, "RESTARTS", i_val=t_control%n_restarts)
    1549          12 :       CALL section_vals_val_get(t_section, "NREORTHO", i_val=t_control%n_reortho)
    1550          12 :       CALL section_vals_val_get(t_section, "RES_ETYPE", i_val=t_control%res_etype)
    1551          12 :       CALL section_vals_val_get(t_section, "DIAG_METHOD", i_val=t_control%diag_method)
    1552          12 :       CALL section_vals_val_get(t_section, "KERNEL", l_val=t_control%do_kernel)
    1553          12 :       CALL section_vals_val_get(t_section, "LSD_SINGLETS", l_val=t_control%lsd_singlets)
    1554          12 :       CALL section_vals_val_get(t_section, "INVERT_S", l_val=t_control%invert_S)
    1555          12 :       CALL section_vals_val_get(t_section, "PRECOND", l_val=t_control%precond)
    1556          12 :       CALL section_vals_val_get(t_section, "OE_CORR", i_val=t_control%oe_corr)
    1557             : 
    1558          12 :       t_control%use_kinetic_energy_density = .FALSE.
    1559          12 :       sic_section => section_vals_get_subs_vals(t_section, "SIC")
    1560          12 :       CALL section_vals_val_get(sic_section, "SIC_METHOD", i_val=t_control%sic_method_id)
    1561          12 :       CALL section_vals_val_get(sic_section, "ORBITAL_SET", i_val=t_control%sic_list_id)
    1562          12 :       CALL section_vals_val_get(sic_section, "SIC_SCALING_A", r_val=t_control%sic_scaling_a)
    1563          12 :       CALL section_vals_val_get(sic_section, "SIC_SCALING_B", r_val=t_control%sic_scaling_b)
    1564             : 
    1565          12 :    END SUBROUTINE read_tddfpt_control
    1566             : 
    1567             : ! **************************************************************************************************
    1568             : !> \brief Read TDDFPT-related input parameters.
    1569             : !> \param t_control  TDDFPT control parameters
    1570             : !> \param t_section  TDDFPT input section
    1571             : !> \param qs_control Quickstep control parameters
    1572             : ! **************************************************************************************************
    1573        7366 :    SUBROUTINE read_tddfpt2_control(t_control, t_section, qs_control)
    1574             :       TYPE(tddfpt2_control_type), POINTER                :: t_control
    1575             :       TYPE(section_vals_type), POINTER                   :: t_section
    1576             :       TYPE(qs_control_type), POINTER                     :: qs_control
    1577             : 
    1578             :       CHARACTER(LEN=*), PARAMETER :: routineN = 'read_tddfpt2_control'
    1579             : 
    1580             :       CHARACTER(LEN=default_string_length), &
    1581        7366 :          DIMENSION(:), POINTER                           :: tmpstringlist
    1582             :       INTEGER                                            :: handle, irep, isize, nrep
    1583        7366 :       INTEGER, ALLOCATABLE, DIMENSION(:)                 :: inds
    1584             :       LOGICAL                                            :: do_ewald, do_exchange, expl, explicit, &
    1585             :                                                             multigrid_set
    1586             :       REAL(KIND=dp)                                      :: filter, fval, hfx
    1587             :       TYPE(section_vals_type), POINTER                   :: dipole_section, mgrid_section, &
    1588             :                                                             soc_section, stda_section, xc_func, &
    1589             :                                                             xc_section
    1590             : 
    1591        7366 :       CALL timeset(routineN, handle)
    1592             : 
    1593        7366 :       CALL section_vals_val_get(t_section, "_SECTION_PARAMETERS_", l_val=t_control%enabled)
    1594             : 
    1595        7366 :       CALL section_vals_val_get(t_section, "NSTATES", i_val=t_control%nstates)
    1596        7366 :       CALL section_vals_val_get(t_section, "MAX_ITER", i_val=t_control%niters)
    1597        7366 :       CALL section_vals_val_get(t_section, "MAX_KV", i_val=t_control%nkvs)
    1598        7366 :       CALL section_vals_val_get(t_section, "NLUMO", i_val=t_control%nlumo)
    1599        7366 :       CALL section_vals_val_get(t_section, "NPROC_STATE", i_val=t_control%nprocs)
    1600        7366 :       CALL section_vals_val_get(t_section, "KERNEL", i_val=t_control%kernel)
    1601        7366 :       CALL section_vals_val_get(t_section, "OE_CORR", i_val=t_control%oe_corr)
    1602        7366 :       CALL section_vals_val_get(t_section, "EV_SHIFT", r_val=t_control%ev_shift)
    1603        7366 :       CALL section_vals_val_get(t_section, "EOS_SHIFT", r_val=t_control%eos_shift)
    1604             : 
    1605        7366 :       CALL section_vals_val_get(t_section, "CONVERGENCE", r_val=t_control%conv)
    1606        7366 :       CALL section_vals_val_get(t_section, "MIN_AMPLITUDE", r_val=t_control%min_excitation_amplitude)
    1607        7366 :       CALL section_vals_val_get(t_section, "ORTHOGONAL_EPS", r_val=t_control%orthogonal_eps)
    1608             : 
    1609        7366 :       CALL section_vals_val_get(t_section, "RESTART", l_val=t_control%is_restart)
    1610        7366 :       CALL section_vals_val_get(t_section, "RKS_TRIPLETS", l_val=t_control%rks_triplets)
    1611        7366 :       CALL section_vals_val_get(t_section, "DO_LRIGPW", l_val=t_control%do_lrigpw)
    1612        7366 :       CALL section_vals_val_get(t_section, "DO_SMEARING", l_val=t_control%do_smearing)
    1613        7366 :       CALL section_vals_val_get(t_section, "ADMM_KERNEL_CORRECTION_SYMMETRIC", l_val=t_control%admm_symm)
    1614        7366 :       CALL section_vals_val_get(t_section, "ADMM_KERNEL_XC_CORRECTION", l_val=t_control%admm_xc_correction)
    1615        7366 :       CALL section_vals_val_get(t_section, "EXCITON_DESCRIPTORS", l_val=t_control%do_exciton_descriptors)
    1616        7366 :       CALL section_vals_val_get(t_section, "DIRECTIONAL_EXCITON_DESCRIPTORS", l_val=t_control%do_directional_exciton_descriptors)
    1617             : 
    1618             :       ! read automatically generated auxiliary basis for LRI
    1619        7366 :       CALL section_vals_val_get(t_section, "AUTO_BASIS", n_rep_val=nrep)
    1620       14732 :       DO irep = 1, nrep
    1621        7366 :          CALL section_vals_val_get(t_section, "AUTO_BASIS", i_rep_val=irep, c_vals=tmpstringlist)
    1622       14732 :          IF (SIZE(tmpstringlist) == 2) THEN
    1623        7366 :             CALL uppercase(tmpstringlist(2))
    1624        7366 :             SELECT CASE (tmpstringlist(2))
    1625             :             CASE ("X")
    1626           0 :                isize = -1
    1627             :             CASE ("SMALL")
    1628           0 :                isize = 0
    1629             :             CASE ("MEDIUM")
    1630           0 :                isize = 1
    1631             :             CASE ("LARGE")
    1632           0 :                isize = 2
    1633             :             CASE ("HUGE")
    1634           0 :                isize = 3
    1635             :             CASE DEFAULT
    1636        7366 :                CPABORT("Unknown basis size in AUTO_BASIS keyword:"//TRIM(tmpstringlist(1)))
    1637             :             END SELECT
    1638             :             !
    1639        7366 :             SELECT CASE (tmpstringlist(1))
    1640             :             CASE ("X")
    1641             :             CASE ("P_LRI_AUX")
    1642           0 :                t_control%auto_basis_p_lri_aux = isize
    1643             :             CASE DEFAULT
    1644        7366 :                CPABORT("Unknown basis type in AUTO_BASIS keyword:"//TRIM(tmpstringlist(1)))
    1645             :             END SELECT
    1646             :          ELSE
    1647             :             CALL cp_abort(__LOCATION__, &
    1648           0 :                           "AUTO_BASIS keyword in &PROPERTIES &TDDFT section has a wrong number of arguments.")
    1649             :          END IF
    1650             :       END DO
    1651             : 
    1652        7366 :       IF (t_control%conv < 0) &
    1653           0 :          t_control%conv = ABS(t_control%conv)
    1654             : 
    1655             :       ! DIPOLE_MOMENTS subsection
    1656        7366 :       dipole_section => section_vals_get_subs_vals(t_section, "DIPOLE_MOMENTS")
    1657        7366 :       CALL section_vals_val_get(dipole_section, "DIPOLE_FORM", explicit=explicit)
    1658        7366 :       IF (explicit) THEN
    1659          10 :          CALL section_vals_val_get(dipole_section, "DIPOLE_FORM", i_val=t_control%dipole_form)
    1660             :       ELSE
    1661        7356 :          t_control%dipole_form = 0
    1662             :       END IF
    1663        7366 :       CALL section_vals_val_get(dipole_section, "REFERENCE", i_val=t_control%dipole_reference)
    1664        7366 :       CALL section_vals_val_get(dipole_section, "REFERENCE_POINT", explicit=explicit)
    1665        7366 :       IF (explicit) THEN
    1666           0 :          CALL section_vals_val_get(dipole_section, "REFERENCE_POINT", r_vals=t_control%dipole_ref_point)
    1667             :       ELSE
    1668        7366 :          NULLIFY (t_control%dipole_ref_point)
    1669        7366 :          IF (t_control%dipole_form == tddfpt_dipole_length .AND. t_control%dipole_reference == use_mom_ref_user) THEN
    1670           0 :             CPABORT("User-defined reference point should be given explicitly")
    1671             :          END IF
    1672             :       END IF
    1673             : 
    1674             :       !SOC subsection
    1675        7366 :       soc_section => section_vals_get_subs_vals(t_section, "SOC")
    1676        7366 :       CALL section_vals_get(soc_section, explicit=explicit)
    1677        7366 :       IF (explicit) THEN
    1678           8 :          t_control%do_soc = .TRUE.
    1679             :       END IF
    1680             : 
    1681             :       ! MGRID subsection
    1682        7366 :       mgrid_section => section_vals_get_subs_vals(t_section, "MGRID")
    1683        7366 :       CALL section_vals_get(mgrid_section, explicit=t_control%mgrid_is_explicit)
    1684             : 
    1685        7366 :       IF (t_control%mgrid_is_explicit) THEN
    1686           2 :          CALL section_vals_val_get(mgrid_section, "NGRIDS", i_val=t_control%mgrid_ngrids, explicit=explicit)
    1687           2 :          IF (.NOT. explicit) t_control%mgrid_ngrids = SIZE(qs_control%e_cutoff)
    1688             : 
    1689           2 :          CALL section_vals_val_get(mgrid_section, "CUTOFF", r_val=t_control%mgrid_cutoff, explicit=explicit)
    1690           2 :          IF (.NOT. explicit) t_control%mgrid_cutoff = qs_control%cutoff
    1691             : 
    1692             :          CALL section_vals_val_get(mgrid_section, "PROGRESSION_FACTOR", &
    1693           2 :                                    r_val=t_control%mgrid_progression_factor, explicit=explicit)
    1694           2 :          IF (explicit) THEN
    1695           0 :             IF (t_control%mgrid_progression_factor <= 1.0_dp) &
    1696             :                CALL cp_abort(__LOCATION__, &
    1697           0 :                              "Progression factor should be greater then 1.0 to ensure multi-grid ordering")
    1698             :          ELSE
    1699           2 :             t_control%mgrid_progression_factor = qs_control%progression_factor
    1700             :          END IF
    1701             : 
    1702           2 :          CALL section_vals_val_get(mgrid_section, "COMMENSURATE", l_val=t_control%mgrid_commensurate_mgrids, explicit=explicit)
    1703           2 :          IF (.NOT. explicit) t_control%mgrid_commensurate_mgrids = qs_control%commensurate_mgrids
    1704           2 :          IF (t_control%mgrid_commensurate_mgrids) THEN
    1705           0 :             IF (explicit) THEN
    1706           0 :                t_control%mgrid_progression_factor = 4.0_dp
    1707             :             ELSE
    1708           0 :                t_control%mgrid_progression_factor = qs_control%progression_factor
    1709             :             END IF
    1710             :          END IF
    1711             : 
    1712           2 :          CALL section_vals_val_get(mgrid_section, "REL_CUTOFF", r_val=t_control%mgrid_relative_cutoff, explicit=explicit)
    1713           2 :          IF (.NOT. explicit) t_control%mgrid_relative_cutoff = qs_control%relative_cutoff
    1714             : 
    1715           2 :          CALL section_vals_val_get(mgrid_section, "MULTIGRID_SET", l_val=multigrid_set, explicit=explicit)
    1716           2 :          IF (.NOT. explicit) multigrid_set = .FALSE.
    1717           2 :          IF (multigrid_set) THEN
    1718           0 :             CALL section_vals_val_get(mgrid_section, "MULTIGRID_CUTOFF", r_vals=t_control%mgrid_e_cutoff)
    1719             :          ELSE
    1720           2 :             NULLIFY (t_control%mgrid_e_cutoff)
    1721             :          END IF
    1722             : 
    1723           2 :          CALL section_vals_val_get(mgrid_section, "REALSPACE", l_val=t_control%mgrid_realspace_mgrids, explicit=explicit)
    1724           2 :          IF (.NOT. explicit) t_control%mgrid_realspace_mgrids = qs_control%realspace_mgrids
    1725             : 
    1726             :          CALL section_vals_val_get(mgrid_section, "SKIP_LOAD_BALANCE_DISTRIBUTED", &
    1727           2 :                                    l_val=t_control%mgrid_skip_load_balance, explicit=explicit)
    1728           2 :          IF (.NOT. explicit) t_control%mgrid_skip_load_balance = qs_control%skip_load_balance_distributed
    1729             : 
    1730           2 :          IF (ASSOCIATED(t_control%mgrid_e_cutoff)) THEN
    1731           0 :             IF (SIZE(t_control%mgrid_e_cutoff) /= t_control%mgrid_ngrids) &
    1732           0 :                CPABORT("Inconsistent values for number of multi-grids")
    1733             : 
    1734             :             ! sort multi-grids in descending order according to their cutoff values
    1735           0 :             t_control%mgrid_e_cutoff = -t_control%mgrid_e_cutoff
    1736           0 :             ALLOCATE (inds(t_control%mgrid_ngrids))
    1737           0 :             CALL sort(t_control%mgrid_e_cutoff, t_control%mgrid_ngrids, inds)
    1738           0 :             DEALLOCATE (inds)
    1739           0 :             t_control%mgrid_e_cutoff = -t_control%mgrid_e_cutoff
    1740             :          END IF
    1741             :       END IF
    1742             : 
    1743             :       ! expand XC subsection (if given explicitly)
    1744        7366 :       xc_section => section_vals_get_subs_vals(t_section, "XC")
    1745        7366 :       xc_func => section_vals_get_subs_vals(xc_section, "XC_FUNCTIONAL")
    1746        7366 :       CALL section_vals_get(xc_func, explicit=explicit)
    1747        7366 :       IF (explicit) &
    1748         194 :          CALL xc_functionals_expand(xc_func, xc_section)
    1749             : 
    1750             :       ! sTDA subsection
    1751        7366 :       stda_section => section_vals_get_subs_vals(t_section, "STDA")
    1752        7366 :       IF (t_control%kernel == tddfpt_kernel_stda) THEN
    1753         118 :          t_control%stda_control%hfx_fraction = 0.0_dp
    1754         118 :          t_control%stda_control%do_exchange = .TRUE.
    1755         118 :          t_control%stda_control%eps_td_filter = 1.e-10_dp
    1756         118 :          t_control%stda_control%mn_alpha = -99.0_dp
    1757         118 :          t_control%stda_control%mn_beta = -99.0_dp
    1758             :          ! set default for Ewald method (on/off) dependent on periodicity
    1759         212 :          SELECT CASE (qs_control%periodicity)
    1760             :          CASE (0)
    1761          94 :             t_control%stda_control%do_ewald = .FALSE.
    1762             :          CASE (1)
    1763           0 :             t_control%stda_control%do_ewald = .TRUE.
    1764             :          CASE (2)
    1765           0 :             t_control%stda_control%do_ewald = .TRUE.
    1766             :          CASE (3)
    1767          24 :             t_control%stda_control%do_ewald = .TRUE.
    1768             :          CASE DEFAULT
    1769         118 :             CPABORT("Illegal value for periodiciy")
    1770             :          END SELECT
    1771         118 :          CALL section_vals_get(stda_section, explicit=explicit)
    1772         118 :          IF (explicit) THEN
    1773         104 :             CALL section_vals_val_get(stda_section, "HFX_FRACTION", r_val=hfx, explicit=expl)
    1774         104 :             IF (expl) t_control%stda_control%hfx_fraction = hfx
    1775         104 :             CALL section_vals_val_get(stda_section, "EPS_TD_FILTER", r_val=filter, explicit=expl)
    1776         104 :             IF (expl) t_control%stda_control%eps_td_filter = filter
    1777         104 :             CALL section_vals_val_get(stda_section, "DO_EWALD", l_val=do_ewald, explicit=expl)
    1778         104 :             IF (expl) t_control%stda_control%do_ewald = do_ewald
    1779         104 :             CALL section_vals_val_get(stda_section, "DO_EXCHANGE", l_val=do_exchange, explicit=expl)
    1780         104 :             IF (expl) t_control%stda_control%do_exchange = do_exchange
    1781         104 :             CALL section_vals_val_get(stda_section, "MATAGA_NISHIMOTO_CEXP", r_val=fval)
    1782         104 :             t_control%stda_control%mn_alpha = fval
    1783         104 :             CALL section_vals_val_get(stda_section, "MATAGA_NISHIMOTO_XEXP", r_val=fval)
    1784         104 :             t_control%stda_control%mn_beta = fval
    1785             :          END IF
    1786         118 :          CALL section_vals_val_get(stda_section, "COULOMB_SR_CUT", r_val=fval)
    1787         118 :          t_control%stda_control%coulomb_sr_cut = fval
    1788         118 :          CALL section_vals_val_get(stda_section, "COULOMB_SR_EPS", r_val=fval)
    1789         118 :          t_control%stda_control%coulomb_sr_eps = fval
    1790             :       END IF
    1791             : 
    1792        7366 :       CALL timestop(handle)
    1793        7366 :    END SUBROUTINE read_tddfpt2_control
    1794             : 
    1795             : ! **************************************************************************************************
    1796             : !> \brief Write the DFT control parameters to the output unit.
    1797             : !> \param dft_control ...
    1798             : !> \param dft_section ...
    1799             : ! **************************************************************************************************
    1800       12564 :    SUBROUTINE write_dft_control(dft_control, dft_section)
    1801             :       TYPE(dft_control_type), POINTER                    :: dft_control
    1802             :       TYPE(section_vals_type), POINTER                   :: dft_section
    1803             : 
    1804             :       CHARACTER(len=*), PARAMETER                        :: routineN = 'write_dft_control'
    1805             : 
    1806             :       CHARACTER(LEN=20)                                  :: tmpStr
    1807             :       INTEGER                                            :: handle, output_unit
    1808             :       REAL(kind=dp)                                      :: density_cut, density_smooth_cut_range, &
    1809             :                                                             gradient_cut, tau_cut
    1810             :       TYPE(cp_logger_type), POINTER                      :: logger
    1811             :       TYPE(enumeration_type), POINTER                    :: enum
    1812             :       TYPE(keyword_type), POINTER                        :: keyword
    1813             :       TYPE(section_type), POINTER                        :: section
    1814             :       TYPE(section_vals_type), POINTER                   :: xc_section
    1815             : 
    1816        8518 :       IF (dft_control%qs_control%semi_empirical) RETURN
    1817        6362 :       IF (dft_control%qs_control%dftb) RETURN
    1818        6140 :       IF (dft_control%qs_control%xtb) THEN
    1819         936 :          CALL write_xtb_control(dft_control%qs_control%xtb_control, dft_section)
    1820         936 :          RETURN
    1821             :       END IF
    1822        5204 :       CALL timeset(routineN, handle)
    1823             : 
    1824        5204 :       NULLIFY (logger)
    1825        5204 :       logger => cp_get_default_logger()
    1826             : 
    1827             :       output_unit = cp_print_key_unit_nr(logger, dft_section, &
    1828        5204 :                                          "PRINT%DFT_CONTROL_PARAMETERS", extension=".Log")
    1829             : 
    1830        5204 :       IF (output_unit > 0) THEN
    1831             : 
    1832        1339 :          xc_section => section_vals_get_subs_vals(dft_section, "XC")
    1833             : 
    1834        1339 :          IF (dft_control%uks) THEN
    1835             :             WRITE (UNIT=output_unit, FMT="(/,T2,A,T78,A)") &
    1836         411 :                "DFT| Spin unrestricted (spin-polarized) Kohn-Sham calculation", "UKS"
    1837         928 :          ELSE IF (dft_control%roks) THEN
    1838             :             WRITE (UNIT=output_unit, FMT="(/,T2,A,T77,A)") &
    1839          15 :                "DFT| Spin restricted open Kohn-Sham calculation", "ROKS"
    1840             :          ELSE
    1841             :             WRITE (UNIT=output_unit, FMT="(/,T2,A,T78,A)") &
    1842         913 :                "DFT| Spin restricted Kohn-Sham (RKS) calculation", "RKS"
    1843             :          END IF
    1844             : 
    1845             :          WRITE (UNIT=output_unit, FMT="(T2,A,T76,I5)") &
    1846        1339 :             "DFT| Multiplicity", dft_control%multiplicity
    1847             :          WRITE (UNIT=output_unit, FMT="(T2,A,T76,I5)") &
    1848        1339 :             "DFT| Number of spin states", dft_control%nspins
    1849             : 
    1850             :          WRITE (UNIT=output_unit, FMT="(T2,A,T76,I5)") &
    1851        1339 :             "DFT| Charge", dft_control%charge
    1852             : 
    1853        1339 :          IF (dft_control%sic_method_id .NE. sic_none) CALL cite_reference(VandeVondele2005b)
    1854        2664 :          SELECT CASE (dft_control%sic_method_id)
    1855             :          CASE (sic_none)
    1856        1325 :             tmpstr = "NO"
    1857             :          CASE (sic_mauri_spz)
    1858           6 :             tmpstr = "SPZ/MAURI SIC"
    1859             :          CASE (sic_mauri_us)
    1860           3 :             tmpstr = "US/MAURI SIC"
    1861             :          CASE (sic_ad)
    1862           3 :             tmpstr = "AD SIC"
    1863             :          CASE (sic_eo)
    1864           2 :             tmpstr = "Explicit Orbital SIC"
    1865             :          CASE DEFAULT
    1866             :             ! fix throughout the cp2k for this option
    1867        1339 :             CPABORT("SIC option unknown")
    1868             :          END SELECT
    1869             : 
    1870             :          WRITE (UNIT=output_unit, FMT="(T2,A,T61,A20)") &
    1871        1339 :             "DFT| Self-interaction correction (SIC)", ADJUSTR(TRIM(tmpstr))
    1872             : 
    1873        1339 :          IF (dft_control%sic_method_id /= sic_none) THEN
    1874             :             WRITE (UNIT=output_unit, FMT="(T2,A,T66,ES15.6)") &
    1875          14 :                "DFT| SIC scaling parameter a", dft_control%sic_scaling_a, &
    1876          28 :                "DFT| SIC scaling parameter b", dft_control%sic_scaling_b
    1877             :          END IF
    1878             : 
    1879        1339 :          IF (dft_control%sic_method_id == sic_eo) THEN
    1880           2 :             IF (dft_control%sic_list_id == sic_list_all) THEN
    1881             :                WRITE (UNIT=output_unit, FMT="(T2,A,T66,A)") &
    1882           1 :                   "DFT| SIC orbitals", "ALL"
    1883             :             END IF
    1884           2 :             IF (dft_control%sic_list_id == sic_list_unpaired) THEN
    1885             :                WRITE (UNIT=output_unit, FMT="(T2,A,T66,A)") &
    1886           1 :                   "DFT| SIC orbitals", "UNPAIRED"
    1887             :             END IF
    1888             :          END IF
    1889             : 
    1890        1339 :          CALL section_vals_val_get(xc_section, "density_cutoff", r_val=density_cut)
    1891        1339 :          CALL section_vals_val_get(xc_section, "gradient_cutoff", r_val=gradient_cut)
    1892        1339 :          CALL section_vals_val_get(xc_section, "tau_cutoff", r_val=tau_cut)
    1893        1339 :          CALL section_vals_val_get(xc_section, "density_smooth_cutoff_range", r_val=density_smooth_cut_range)
    1894             : 
    1895             :          WRITE (UNIT=output_unit, FMT="(T2,A,T66,ES15.6)") &
    1896        1339 :             "DFT| Cutoffs: density ", density_cut, &
    1897        1339 :             "DFT|          gradient", gradient_cut, &
    1898        1339 :             "DFT|          tau     ", tau_cut, &
    1899        2678 :             "DFT|          cutoff_smoothing_range", density_smooth_cut_range
    1900             :          CALL section_vals_val_get(xc_section, "XC_GRID%XC_SMOOTH_RHO", &
    1901        1339 :                                    c_val=tmpStr)
    1902             :          WRITE (output_unit, '( A, T61, A )') &
    1903        1339 :             " DFT| XC density smoothing ", ADJUSTR(tmpStr)
    1904             :          CALL section_vals_val_get(xc_section, "XC_GRID%XC_DERIV", &
    1905        1339 :                                    c_val=tmpStr)
    1906             :          WRITE (output_unit, '( A, T61, A )') &
    1907        1339 :             " DFT| XC derivatives ", ADJUSTR(tmpStr)
    1908        1339 :          IF (dft_control%dft_plus_u) THEN
    1909          16 :             NULLIFY (enum, keyword, section)
    1910          16 :             CALL create_dft_section(section)
    1911          16 :             keyword => section_get_keyword(section, "PLUS_U_METHOD")
    1912          16 :             CALL keyword_get(keyword, enum=enum)
    1913             :             WRITE (UNIT=output_unit, FMT="(/,T2,A,T41,A40)") &
    1914          16 :                "DFT+U| Method", ADJUSTR(TRIM(enum_i2c(enum, dft_control%plus_u_method_id)))
    1915             :             WRITE (UNIT=output_unit, FMT="(T2,A)") &
    1916          16 :                "DFT+U| Check atomic kind information for details"
    1917          16 :             CALL section_release(section)
    1918             :          END IF
    1919             : 
    1920        1339 :          WRITE (UNIT=output_unit, FMT="(A)") ""
    1921        1339 :          CALL xc_write(output_unit, xc_section, dft_control%lsd)
    1922             : 
    1923        1339 :          IF (dft_control%apply_period_efield) THEN
    1924           4 :             WRITE (UNIT=output_unit, FMT="(A)") ""
    1925           4 :             IF (dft_control%period_efield%displacement_field) THEN
    1926             :                WRITE (UNIT=output_unit, FMT="(T2,A)") &
    1927           0 :                   "PERIODIC_EFIELD| Use displacement field formulation"
    1928             :                WRITE (UNIT=output_unit, FMT="(T2,A,T66,1X,ES14.6)") &
    1929           0 :                   "PERIODIC_EFIELD| Displacement field filter: x", &
    1930           0 :                   dft_control%period_efield%d_filter(1), &
    1931           0 :                   "PERIODIC_EFIELD|                            y", &
    1932           0 :                   dft_control%period_efield%d_filter(2), &
    1933           0 :                   "PERIODIC_EFIELD|                            z", &
    1934           0 :                   dft_control%period_efield%d_filter(3)
    1935             :             END IF
    1936             :             WRITE (UNIT=output_unit, FMT="(T2,A,T66,1X,ES14.6)") &
    1937           4 :                "PERIODIC_EFIELD| Polarisation vector:       x", &
    1938           4 :                dft_control%period_efield%polarisation(1), &
    1939           4 :                "PERIODIC_EFIELD|                            y", &
    1940           4 :                dft_control%period_efield%polarisation(2), &
    1941           4 :                "PERIODIC_EFIELD|                            z", &
    1942           4 :                dft_control%period_efield%polarisation(3), &
    1943           4 :                "PERIODIC_EFIELD| Intensity [a.u.]:", &
    1944           8 :                dft_control%period_efield%strength
    1945          16 :             IF (SQRT(DOT_PRODUCT(dft_control%period_efield%polarisation, &
    1946             :                                  dft_control%period_efield%polarisation)) < EPSILON(0.0_dp)) THEN
    1947           0 :                CPABORT("Invalid (too small) polarisation vector specified for PERIODIC_EFIELD")
    1948             :             END IF
    1949             :          END IF
    1950             : 
    1951        1339 :          IF (dft_control%do_sccs) THEN
    1952             :             WRITE (UNIT=output_unit, FMT="(/,T2,A)") &
    1953           5 :                "SCCS| Self-consistent continuum solvation model"
    1954             :             WRITE (UNIT=output_unit, FMT="(T2,A,T61,ES20.6)") &
    1955           5 :                "SCCS| Relative permittivity of the solvent (medium)", &
    1956           5 :                dft_control%sccs_control%epsilon_solvent, &
    1957           5 :                "SCCS| Absolute permittivity [a.u.]", &
    1958          10 :                dft_control%sccs_control%epsilon_solvent/fourpi
    1959           9 :             SELECT CASE (dft_control%sccs_control%method_id)
    1960             :             CASE (sccs_andreussi)
    1961             :                WRITE (UNIT=output_unit, FMT="(T2,A,/,(T2,A,T61,ES20.6))") &
    1962           4 :                   "SCCS| Dielectric function proposed by Andreussi et al.", &
    1963           4 :                   "SCCS|  rho_max", dft_control%sccs_control%rho_max, &
    1964           8 :                   "SCCS|  rho_min", dft_control%sccs_control%rho_min
    1965             :             CASE (sccs_fattebert_gygi)
    1966             :                WRITE (UNIT=output_unit, FMT="(T2,A,/,(T2,A,T61,ES20.6))") &
    1967           1 :                   "SCCS| Dielectric function proposed by Fattebert and Gygi", &
    1968           1 :                   "SCCS|  beta", dft_control%sccs_control%beta, &
    1969           2 :                   "SCCS|  rho_zero", dft_control%sccs_control%rho_zero
    1970             :             CASE DEFAULT
    1971           5 :                CPABORT("Invalid SCCS model specified. Please, check your input!")
    1972             :             END SELECT
    1973           6 :             SELECT CASE (dft_control%sccs_control%derivative_method)
    1974             :             CASE (sccs_derivative_fft)
    1975             :                WRITE (UNIT=output_unit, FMT="(T2,A,T46,A35)") &
    1976           1 :                   "SCCS| Numerical derivative calculation", &
    1977           2 :                   ADJUSTR("FFT")
    1978             :             CASE (sccs_derivative_cd3)
    1979             :                WRITE (UNIT=output_unit, FMT="(T2,A,T46,A35)") &
    1980           0 :                   "SCCS| Numerical derivative calculation", &
    1981           0 :                   ADJUSTR("3-point stencil central differences")
    1982             :             CASE (sccs_derivative_cd5)
    1983             :                WRITE (UNIT=output_unit, FMT="(T2,A,T46,A35)") &
    1984           4 :                   "SCCS| Numerical derivative calculation", &
    1985           8 :                   ADJUSTR("5-point stencil central differences")
    1986             :             CASE (sccs_derivative_cd7)
    1987             :                WRITE (UNIT=output_unit, FMT="(T2,A,T46,A35)") &
    1988           0 :                   "SCCS| Numerical derivative calculation", &
    1989           0 :                   ADJUSTR("7-point stencil central differences")
    1990             :             CASE DEFAULT
    1991             :                CALL cp_abort(__LOCATION__, &
    1992             :                              "Invalid derivative method specified for SCCS model. "// &
    1993           5 :                              "Please, check your input!")
    1994             :             END SELECT
    1995             :             WRITE (UNIT=output_unit, FMT="(T2,A,T61,ES20.6)") &
    1996           5 :                "SCCS| Repulsion parameter alpha [mN/m] = [dyn/cm]", &
    1997          10 :                cp_unit_from_cp2k(dft_control%sccs_control%alpha_solvent, "mN/m")
    1998             :             WRITE (UNIT=output_unit, FMT="(T2,A,T61,ES20.6)") &
    1999           5 :                "SCCS| Dispersion parameter beta [GPa]", &
    2000          10 :                cp_unit_from_cp2k(dft_control%sccs_control%beta_solvent, "GPa")
    2001             :             WRITE (UNIT=output_unit, FMT="(T2,A,T61,ES20.6)") &
    2002           5 :                "SCCS| Surface tension gamma [mN/m] = [dyn/cm]", &
    2003          10 :                cp_unit_from_cp2k(dft_control%sccs_control%gamma_solvent, "mN/m")
    2004             :             WRITE (UNIT=output_unit, FMT="(T2,A,T61,ES20.6)") &
    2005           5 :                "SCCS| Mixing parameter applied during the iteration cycle", &
    2006          10 :                dft_control%sccs_control%mixing
    2007             :             WRITE (UNIT=output_unit, FMT="(T2,A,T61,ES20.6)") &
    2008           5 :                "SCCS| Tolerance for the convergence of the SCCS iteration cycle", &
    2009          10 :                dft_control%sccs_control%eps_sccs
    2010             :             WRITE (UNIT=output_unit, FMT="(T2,A,T61,I20)") &
    2011           5 :                "SCCS| Maximum number of iteration steps", &
    2012          10 :                dft_control%sccs_control%max_iter
    2013             :             WRITE (UNIT=output_unit, FMT="(T2,A,T61,ES20.6)") &
    2014           5 :                "SCCS| SCF convergence threshold for starting the SCCS iteration", &
    2015          10 :                dft_control%sccs_control%eps_scf
    2016             :             WRITE (UNIT=output_unit, FMT="(T2,A,T61,ES20.6)") &
    2017           5 :                "SCCS| Numerical increment for the cavity surface calculation", &
    2018          10 :                dft_control%sccs_control%delta_rho
    2019             :          END IF
    2020             : 
    2021        1339 :          WRITE (UNIT=output_unit, FMT="(A)") ""
    2022             : 
    2023             :       END IF
    2024             : 
    2025             :       CALL cp_print_key_finished_output(output_unit, logger, dft_section, &
    2026        5204 :                                         "PRINT%DFT_CONTROL_PARAMETERS")
    2027             : 
    2028        5204 :       CALL timestop(handle)
    2029             : 
    2030             :    END SUBROUTINE write_dft_control
    2031             : 
    2032             : ! **************************************************************************************************
    2033             : !> \brief Write the ADMM control parameters to the output unit.
    2034             : !> \param admm_control ...
    2035             : !> \param dft_section ...
    2036             : ! **************************************************************************************************
    2037         442 :    SUBROUTINE write_admm_control(admm_control, dft_section)
    2038             :       TYPE(admm_control_type), POINTER                   :: admm_control
    2039             :       TYPE(section_vals_type), POINTER                   :: dft_section
    2040             : 
    2041             :       INTEGER                                            :: iounit
    2042             :       TYPE(cp_logger_type), POINTER                      :: logger
    2043             : 
    2044         442 :       NULLIFY (logger)
    2045         442 :       logger => cp_get_default_logger()
    2046             : 
    2047             :       iounit = cp_print_key_unit_nr(logger, dft_section, &
    2048         442 :                                     "PRINT%DFT_CONTROL_PARAMETERS", extension=".Log")
    2049             : 
    2050         442 :       IF (iounit > 0) THEN
    2051             : 
    2052         233 :          SELECT CASE (admm_control%admm_type)
    2053             :          CASE (no_admm_type)
    2054         114 :             WRITE (UNIT=iounit, FMT="(/,T2,A,T77,A)") "ADMM| Specific ADMM type specified", "NONE"
    2055             :          CASE (admm1_type)
    2056           1 :             WRITE (UNIT=iounit, FMT="(/,T2,A,T76,A)") "ADMM| Specific ADMM type specified", "ADMM1"
    2057             :          CASE (admm2_type)
    2058           1 :             WRITE (UNIT=iounit, FMT="(/,T2,A,T76,A)") "ADMM| Specific ADMM type specified", "ADMM2"
    2059             :          CASE (admms_type)
    2060           1 :             WRITE (UNIT=iounit, FMT="(/,T2,A,T76,A)") "ADMM| Specific ADMM type specified", "ADMMS"
    2061             :          CASE (admmp_type)
    2062           1 :             WRITE (UNIT=iounit, FMT="(/,T2,A,T76,A)") "ADMM| Specific ADMM type specified", "ADMMP"
    2063             :          CASE (admmq_type)
    2064           1 :             WRITE (UNIT=iounit, FMT="(/,T2,A,T76,A)") "ADMM| Specific ADMM type specified", "ADMMQ"
    2065             :          CASE DEFAULT
    2066         119 :             CPABORT("admm_type")
    2067             :          END SELECT
    2068             : 
    2069         189 :          SELECT CASE (admm_control%purification_method)
    2070             :          CASE (do_admm_purify_none)
    2071          70 :             WRITE (UNIT=iounit, FMT="(T2,A,T77,A)") "ADMM| Density matrix purification method", "NONE"
    2072             :          CASE (do_admm_purify_cauchy)
    2073           9 :             WRITE (UNIT=iounit, FMT="(T2,A,T75,A)") "ADMM| Density matrix purification method", "Cauchy"
    2074             :          CASE (do_admm_purify_cauchy_subspace)
    2075           5 :             WRITE (UNIT=iounit, FMT="(T2,A,T66,A)") "ADMM| Density matrix purification method", "Cauchy subspace"
    2076             :          CASE (do_admm_purify_mo_diag)
    2077          25 :             WRITE (UNIT=iounit, FMT="(T2,A,T63,A)") "ADMM| Density matrix purification method", "MO diagonalization"
    2078             :          CASE (do_admm_purify_mo_no_diag)
    2079           3 :             WRITE (UNIT=iounit, FMT="(T2,A,T71,A)") "ADMM| Density matrix purification method", "MO no diag"
    2080             :          CASE (do_admm_purify_mcweeny)
    2081           1 :             WRITE (UNIT=iounit, FMT="(T2,A,T74,A)") "ADMM| Density matrix purification method", "McWeeny"
    2082             :          CASE (do_admm_purify_none_dm)
    2083           6 :             WRITE (UNIT=iounit, FMT="(T2,A,T73,A)") "ADMM| Density matrix purification method", "NONE(DM)"
    2084             :          CASE DEFAULT
    2085         119 :             CPABORT("admm_purification_method")
    2086             :          END SELECT
    2087             : 
    2088         214 :          SELECT CASE (admm_control%method)
    2089             :          CASE (do_admm_basis_projection)
    2090          95 :             WRITE (UNIT=iounit, FMT="(T2,A)") "ADMM| Orbital projection on ADMM basis"
    2091             :          CASE (do_admm_blocking_purify_full)
    2092           3 :             WRITE (UNIT=iounit, FMT="(T2,A)") "ADMM| Blocked Fock matrix projection with full purification"
    2093             :          CASE (do_admm_blocked_projection)
    2094           6 :             WRITE (UNIT=iounit, FMT="(T2,A)") "ADMM| Blocked Fock matrix projection"
    2095             :          CASE (do_admm_charge_constrained_projection)
    2096          15 :             WRITE (UNIT=iounit, FMT="(T2,A)") "ADMM| Orbital projection with charge constrain"
    2097             :          CASE DEFAULT
    2098         119 :             CPABORT("admm method")
    2099             :          END SELECT
    2100             : 
    2101         136 :          SELECT CASE (admm_control%scaling_model)
    2102             :          CASE (do_admm_exch_scaling_none)
    2103             :          CASE (do_admm_exch_scaling_merlot)
    2104          17 :             WRITE (UNIT=iounit, FMT="(T2,A)") "ADMM| Use Merlot (2014) scaling model"
    2105             :          CASE DEFAULT
    2106         119 :             CPABORT("admm scaling_model")
    2107             :          END SELECT
    2108             : 
    2109         119 :          WRITE (UNIT=iounit, FMT="(T2,A,T61,G20.10)") "ADMM| eps_filter", admm_control%eps_filter
    2110             : 
    2111         127 :          SELECT CASE (admm_control%aux_exch_func)
    2112             :          CASE (do_admm_aux_exch_func_none)
    2113           8 :             WRITE (UNIT=iounit, FMT="(T2,A)") "ADMM| No exchange functional correction term used"
    2114             :          CASE (do_admm_aux_exch_func_default, do_admm_aux_exch_func_default_libxc)
    2115          85 :             WRITE (UNIT=iounit, FMT="(T2,A,T74,A)") "ADMM| Exchange functional in correction term", "(W)PBEX"
    2116             :          CASE (do_admm_aux_exch_func_pbex, do_admm_aux_exch_func_pbex_libxc)
    2117          17 :             WRITE (UNIT=iounit, FMT="(T2,A,T77,A)") "ADMM| Exchange functional in correction term", "PBEX"
    2118             :          CASE (do_admm_aux_exch_func_opt, do_admm_aux_exch_func_opt_libxc)
    2119           8 :             WRITE (UNIT=iounit, FMT="(T2,A,T77,A)") "ADMM| Exchange functional in correction term", "OPTX"
    2120             :          CASE (do_admm_aux_exch_func_bee, do_admm_aux_exch_func_bee_libxc)
    2121           1 :             WRITE (UNIT=iounit, FMT="(T2,A,T74,A)") "ADMM| Exchange functional in correction term", "Becke88"
    2122             :          CASE (do_admm_aux_exch_func_sx_libxc)
    2123           0 :             WRITE (UNIT=iounit, FMT="(T2,A,T74,A)") "ADMM| Exchange functional in correction term", "SlaterX"
    2124             :          CASE DEFAULT
    2125         119 :             CPABORT("admm aux_exch_func")
    2126             :          END SELECT
    2127             : 
    2128         119 :          WRITE (UNIT=iounit, FMT="(A)") ""
    2129             : 
    2130             :       END IF
    2131             : 
    2132             :       CALL cp_print_key_finished_output(iounit, logger, dft_section, &
    2133         442 :                                         "PRINT%DFT_CONTROL_PARAMETERS")
    2134         442 :    END SUBROUTINE write_admm_control
    2135             : 
    2136             : ! **************************************************************************************************
    2137             : !> \brief Write the xTB control parameters to the output unit.
    2138             : !> \param xtb_control ...
    2139             : !> \param dft_section ...
    2140             : ! **************************************************************************************************
    2141         936 :    SUBROUTINE write_xtb_control(xtb_control, dft_section)
    2142             :       TYPE(xtb_control_type), POINTER                    :: xtb_control
    2143             :       TYPE(section_vals_type), POINTER                   :: dft_section
    2144             : 
    2145             :       CHARACTER(len=*), PARAMETER                        :: routineN = 'write_xtb_control'
    2146             : 
    2147             :       INTEGER                                            :: handle, output_unit
    2148             :       TYPE(cp_logger_type), POINTER                      :: logger
    2149             : 
    2150         936 :       CALL timeset(routineN, handle)
    2151         936 :       NULLIFY (logger)
    2152         936 :       logger => cp_get_default_logger()
    2153             : 
    2154             :       output_unit = cp_print_key_unit_nr(logger, dft_section, &
    2155         936 :                                          "PRINT%DFT_CONTROL_PARAMETERS", extension=".Log")
    2156             : 
    2157         936 :       IF (output_unit > 0) THEN
    2158             : 
    2159             :          WRITE (UNIT=output_unit, FMT="(/,T2,A,T31,A50)") &
    2160          37 :             "xTB| Parameter file", ADJUSTR(TRIM(xtb_control%parameter_file_name))
    2161             :          WRITE (UNIT=output_unit, FMT="(T2,A,T71,I10)") &
    2162          37 :             "xTB| Basis expansion STO-NG", xtb_control%sto_ng
    2163             :          WRITE (UNIT=output_unit, FMT="(T2,A,T71,I10)") &
    2164          37 :             "xTB| Basis expansion STO-NG for Hydrogen", xtb_control%h_sto_ng
    2165             :          WRITE (UNIT=output_unit, FMT="(T2,A,T71,E10.4)") &
    2166          37 :             "xTB| Repulsive pair potential accuracy", xtb_control%eps_pair
    2167             :          WRITE (UNIT=output_unit, FMT="(T2,A,T71,F10.6)") &
    2168          37 :             "xTB| Repulsive enhancement factor", xtb_control%enscale
    2169             :          WRITE (UNIT=output_unit, FMT="(T2,A,T71,L10)") &
    2170          37 :             "xTB| Halogen interaction potential", xtb_control%xb_interaction
    2171             :          WRITE (UNIT=output_unit, FMT="(T2,A,T71,F10.3)") &
    2172          37 :             "xTB| Halogen interaction potential cutoff radius", xtb_control%xb_radius
    2173             :          WRITE (UNIT=output_unit, FMT="(T2,A,T71,L10)") &
    2174          37 :             "xTB| Nonbonded interactions", xtb_control%do_nonbonded
    2175          37 :          SELECT CASE (xtb_control%vdw_type)
    2176             :          CASE (xtb_vdw_type_none)
    2177           0 :             WRITE (UNIT=output_unit, FMT="(T2,A)") "xTB| No vdW potential selected"
    2178             :          CASE (xtb_vdw_type_d3)
    2179          37 :             WRITE (UNIT=output_unit, FMT="(T2,A,T72,A)") "xTB| vdW potential type:", "DFTD3(BJ)"
    2180             :             WRITE (UNIT=output_unit, FMT="(T2,A,T31,A50)") &
    2181          37 :                "xTB| D3 Dispersion: Parameter file", ADJUSTR(TRIM(xtb_control%dispersion_parameter_file))
    2182             :          CASE (xtb_vdw_type_d4)
    2183           0 :             WRITE (UNIT=output_unit, FMT="(T2,A,T76,A)") "xTB| vdW potential type:", "DFTD4"
    2184             :             WRITE (UNIT=output_unit, FMT="(T2,A,T31,A50)") &
    2185           0 :                "xTB| D4 Dispersion: Parameter file", ADJUSTR(TRIM(xtb_control%dispersion_parameter_file))
    2186             :          CASE DEFAULT
    2187          37 :             CPABORT("vdw type")
    2188             :          END SELECT
    2189             :          WRITE (UNIT=output_unit, FMT="(T2,A,T51,3F10.3)") &
    2190          37 :             "xTB| Huckel constants ks kp kd", xtb_control%ks, xtb_control%kp, xtb_control%kd
    2191             :          WRITE (UNIT=output_unit, FMT="(T2,A,T61,2F10.3)") &
    2192          37 :             "xTB| Huckel constants ksp k2sh", xtb_control%ksp, xtb_control%k2sh
    2193             :          WRITE (UNIT=output_unit, FMT="(T2,A,T71,F10.3)") &
    2194          37 :             "xTB| Mataga-Nishimoto exponent", xtb_control%kg
    2195             :          WRITE (UNIT=output_unit, FMT="(T2,A,T71,F10.3)") &
    2196          37 :             "xTB| Repulsion potential exponent", xtb_control%kf
    2197             :          WRITE (UNIT=output_unit, FMT="(T2,A,T51,3F10.3)") &
    2198          37 :             "xTB| Coordination number scaling kcn(s) kcn(p) kcn(d)", &
    2199          74 :             xtb_control%kcns, xtb_control%kcnp, xtb_control%kcnd
    2200             :          WRITE (UNIT=output_unit, FMT="(T2,A,T71,F10.3)") &
    2201          37 :             "xTB| Electronegativity scaling", xtb_control%ken
    2202             :          WRITE (UNIT=output_unit, FMT="(T2,A,T61,2F10.3)") &
    2203          37 :             "xTB| Halogen potential scaling kxr kx2", xtb_control%kxr, xtb_control%kx2
    2204          37 :          WRITE (UNIT=output_unit, FMT="(/)")
    2205             : 
    2206             :       END IF
    2207             : 
    2208             :       CALL cp_print_key_finished_output(output_unit, logger, dft_section, &
    2209         936 :                                         "PRINT%DFT_CONTROL_PARAMETERS")
    2210             : 
    2211         936 :       CALL timestop(handle)
    2212             : 
    2213         936 :    END SUBROUTINE write_xtb_control
    2214             : 
    2215             : ! **************************************************************************************************
    2216             : !> \brief Purpose: Write the QS control parameters to the output unit.
    2217             : !> \param qs_control ...
    2218             : !> \param dft_section ...
    2219             : ! **************************************************************************************************
    2220       12564 :    SUBROUTINE write_qs_control(qs_control, dft_section)
    2221             :       TYPE(qs_control_type), INTENT(IN)                  :: qs_control
    2222             :       TYPE(section_vals_type), POINTER                   :: dft_section
    2223             : 
    2224             :       CHARACTER(len=*), PARAMETER                        :: routineN = 'write_qs_control'
    2225             : 
    2226             :       CHARACTER(len=20)                                  :: method, quadrature
    2227             :       INTEGER                                            :: handle, i, igrid_level, ngrid_level, &
    2228             :                                                             output_unit
    2229             :       TYPE(cp_logger_type), POINTER                      :: logger
    2230             :       TYPE(ddapc_restraint_type), POINTER                :: ddapc_restraint_control
    2231             :       TYPE(enumeration_type), POINTER                    :: enum
    2232             :       TYPE(keyword_type), POINTER                        :: keyword
    2233             :       TYPE(section_type), POINTER                        :: qs_section
    2234             :       TYPE(section_vals_type), POINTER                   :: print_section_vals, qs_section_vals
    2235             : 
    2236        8518 :       IF (qs_control%semi_empirical) RETURN
    2237        6362 :       IF (qs_control%dftb) RETURN
    2238        6140 :       IF (qs_control%xtb) RETURN
    2239        5204 :       CALL timeset(routineN, handle)
    2240        5204 :       NULLIFY (logger, print_section_vals, qs_section, qs_section_vals)
    2241        5204 :       logger => cp_get_default_logger()
    2242        5204 :       print_section_vals => section_vals_get_subs_vals(dft_section, "PRINT")
    2243        5204 :       qs_section_vals => section_vals_get_subs_vals(dft_section, "QS")
    2244        5204 :       CALL section_vals_get(qs_section_vals, section=qs_section)
    2245             : 
    2246        5204 :       NULLIFY (enum, keyword)
    2247        5204 :       keyword => section_get_keyword(qs_section, "METHOD")
    2248        5204 :       CALL keyword_get(keyword, enum=enum)
    2249        5204 :       method = enum_i2c(enum, qs_control%method_id)
    2250             : 
    2251        5204 :       NULLIFY (enum, keyword)
    2252        5204 :       keyword => section_get_keyword(qs_section, "QUADRATURE")
    2253        5204 :       CALL keyword_get(keyword, enum=enum)
    2254        5204 :       quadrature = enum_i2c(enum, qs_control%gapw_control%quadrature)
    2255             : 
    2256             :       output_unit = cp_print_key_unit_nr(logger, print_section_vals, &
    2257        5204 :                                          "DFT_CONTROL_PARAMETERS", extension=".Log")
    2258        5204 :       IF (output_unit > 0) THEN
    2259        1339 :          ngrid_level = SIZE(qs_control%e_cutoff)
    2260             :          WRITE (UNIT=output_unit, FMT="(/,T2,A,T61,A20)") &
    2261        1339 :             "QS| Method:", ADJUSTR(method)
    2262        1339 :          IF (qs_control%pw_grid_opt%spherical) THEN
    2263             :             WRITE (UNIT=output_unit, FMT="(T2,A,T61,A)") &
    2264           0 :                "QS| Density plane wave grid type", " SPHERICAL HALFSPACE"
    2265        1339 :          ELSE IF (qs_control%pw_grid_opt%fullspace) THEN
    2266             :             WRITE (UNIT=output_unit, FMT="(T2,A,T57,A)") &
    2267        1339 :                "QS| Density plane wave grid type", " NON-SPHERICAL FULLSPACE"
    2268             :          ELSE
    2269             :             WRITE (UNIT=output_unit, FMT="(T2,A,T57,A)") &
    2270           0 :                "QS| Density plane wave grid type", " NON-SPHERICAL HALFSPACE"
    2271             :          END IF
    2272             :          WRITE (UNIT=output_unit, FMT="(T2,A,T71,I10)") &
    2273        1339 :             "QS| Number of grid levels:", SIZE(qs_control%e_cutoff)
    2274        1339 :          IF (ngrid_level == 1) THEN
    2275             :             WRITE (UNIT=output_unit, FMT="(T2,A,T71,F10.1)") &
    2276          69 :                "QS| Density cutoff [a.u.]:", qs_control%e_cutoff(1)
    2277             :          ELSE
    2278             :             WRITE (UNIT=output_unit, FMT="(T2,A,T71,F10.1)") &
    2279        1270 :                "QS| Density cutoff [a.u.]:", qs_control%cutoff
    2280        1270 :             IF (qs_control%commensurate_mgrids) &
    2281         131 :                WRITE (UNIT=output_unit, FMT="(T2,A)") "QS| Using commensurate multigrids"
    2282             :             WRITE (UNIT=output_unit, FMT="(T2,A,T71,F10.1)") &
    2283        1270 :                "QS| Multi grid cutoff [a.u.]: 1) grid level", qs_control%e_cutoff(1)
    2284             :             WRITE (UNIT=output_unit, FMT="(T2,A,I3,A,T71,F10.1)") &
    2285        3973 :                ("QS|                         ", igrid_level, ") grid level", &
    2286        5243 :                 qs_control%e_cutoff(igrid_level), &
    2287        6513 :                 igrid_level=2, SIZE(qs_control%e_cutoff))
    2288             :          END IF
    2289        1339 :          IF (qs_control%pao) THEN
    2290           0 :             WRITE (UNIT=output_unit, FMT="(T2,A)") "QS| PAO active"
    2291             :          END IF
    2292             :          WRITE (UNIT=output_unit, FMT="(T2,A,T71,F10.1)") &
    2293        1339 :             "QS| Grid level progression factor:", qs_control%progression_factor
    2294             :          WRITE (UNIT=output_unit, FMT="(T2,A,T71,F10.1)") &
    2295        1339 :             "QS| Relative density cutoff [a.u.]:", qs_control%relative_cutoff
    2296             :          WRITE (UNIT=output_unit, FMT="(T2,A,T73,ES8.1)") &
    2297        1339 :             "QS| Interaction thresholds: eps_pgf_orb:", &
    2298        1339 :             qs_control%eps_pgf_orb, &
    2299        1339 :             "QS|                         eps_filter_matrix:", &
    2300        1339 :             qs_control%eps_filter_matrix, &
    2301        1339 :             "QS|                         eps_core_charge:", &
    2302        1339 :             qs_control%eps_core_charge, &
    2303        1339 :             "QS|                         eps_rho_gspace:", &
    2304        1339 :             qs_control%eps_rho_gspace, &
    2305        1339 :             "QS|                         eps_rho_rspace:", &
    2306        1339 :             qs_control%eps_rho_rspace, &
    2307        1339 :             "QS|                         eps_gvg_rspace:", &
    2308        1339 :             qs_control%eps_gvg_rspace, &
    2309        1339 :             "QS|                         eps_ppl:", &
    2310        1339 :             qs_control%eps_ppl, &
    2311        1339 :             "QS|                         eps_ppnl:", &
    2312        2678 :             qs_control%eps_ppnl
    2313        1339 :          IF (qs_control%gapw) THEN
    2314         388 :             SELECT CASE (qs_control%gapw_control%basis_1c)
    2315             :             CASE (gapw_1c_orb)
    2316             :                WRITE (UNIT=output_unit, FMT="(T2,A)") &
    2317         191 :                   "QS| GAPW|      One center basis from orbital basis primitives"
    2318             :             CASE (gapw_1c_small)
    2319             :                WRITE (UNIT=output_unit, FMT="(T2,A)") &
    2320           2 :                   "QS| GAPW|      One center basis extended with primitives (small:s)"
    2321             :             CASE (gapw_1c_medium)
    2322             :                WRITE (UNIT=output_unit, FMT="(T2,A)") &
    2323           1 :                   "QS| GAPW|      One center basis extended with primitives (medium:sp)"
    2324             :             CASE (gapw_1c_large)
    2325             :                WRITE (UNIT=output_unit, FMT="(T2,A)") &
    2326           2 :                   "QS| GAPW|      One center basis extended with primitives (large:spd)"
    2327             :             CASE (gapw_1c_very_large)
    2328             :                WRITE (UNIT=output_unit, FMT="(T2,A)") &
    2329           1 :                   "QS| GAPW|      One center basis extended with primitives (very large:spdf)"
    2330             :             CASE DEFAULT
    2331         197 :                CPABORT("basis_1c incorrect")
    2332             :             END SELECT
    2333             :             WRITE (UNIT=output_unit, FMT="(T2,A,T73,ES8.1)") &
    2334         197 :                "QS| GAPW|                   eps_fit:", &
    2335         197 :                qs_control%gapw_control%eps_fit, &
    2336         197 :                "QS| GAPW|                   eps_iso:", &
    2337         197 :                qs_control%gapw_control%eps_iso, &
    2338         197 :                "QS| GAPW|                   eps_svd:", &
    2339         197 :                qs_control%gapw_control%eps_svd, &
    2340         197 :                "QS| GAPW|                   eps_cpc:", &
    2341         394 :                qs_control%gapw_control%eps_cpc
    2342             :             WRITE (UNIT=output_unit, FMT="(T2,A,T61,A20)") &
    2343         197 :                "QS| GAPW|   atom-r-grid: quadrature:", &
    2344         394 :                ADJUSTR(quadrature)
    2345             :             WRITE (UNIT=output_unit, FMT="(T2,A,T71,I10)") &
    2346         197 :                "QS| GAPW|      atom-s-grid:  max l :", &
    2347         197 :                qs_control%gapw_control%lmax_sphere, &
    2348         197 :                "QS| GAPW|      max_l_rho0 :", &
    2349         394 :                qs_control%gapw_control%lmax_rho0
    2350         197 :             IF (qs_control%gapw_control%non_paw_atoms) THEN
    2351             :                WRITE (UNIT=output_unit, FMT="(T2,A)") &
    2352          29 :                   "QS| GAPW|      At least one kind is NOT PAW, i.e. it has only soft AO "
    2353             :             END IF
    2354         197 :             IF (qs_control%gapw_control%nopaw_as_gpw) THEN
    2355             :                WRITE (UNIT=output_unit, FMT="(T2,A)") &
    2356          29 :                   "QS| GAPW|      The NOT PAW atoms are treated fully GPW"
    2357             :             END IF
    2358             :          END IF
    2359        1339 :          IF (qs_control%gapw_xc) THEN
    2360          50 :             SELECT CASE (qs_control%gapw_control%basis_1c)
    2361             :             CASE (gapw_1c_orb)
    2362             :                WRITE (UNIT=output_unit, FMT="(T2,A)") &
    2363          25 :                   "QS| GAPW_XC|      One center basis from orbital basis primitives"
    2364             :             CASE (gapw_1c_small)
    2365             :                WRITE (UNIT=output_unit, FMT="(T2,A)") &
    2366           0 :                   "QS| GAPW_XC|      One center basis extended with primitives (small:s)"
    2367             :             CASE (gapw_1c_medium)
    2368             :                WRITE (UNIT=output_unit, FMT="(T2,A)") &
    2369           0 :                   "QS| GAPW_XC|      One center basis extended with primitives (medium:sp)"
    2370             :             CASE (gapw_1c_large)
    2371             :                WRITE (UNIT=output_unit, FMT="(T2,A)") &
    2372           0 :                   "QS| GAPW_XC|      One center basis extended with primitives (large:spd)"
    2373             :             CASE (gapw_1c_very_large)
    2374             :                WRITE (UNIT=output_unit, FMT="(T2,A)") &
    2375           0 :                   "QS| GAPW_XC|      One center basis extended with primitives (very large:spdf)"
    2376             :             CASE DEFAULT
    2377          25 :                CPABORT("basis_1c incorrect")
    2378             :             END SELECT
    2379             :             WRITE (UNIT=output_unit, FMT="(T2,A,T73,ES8.1)") &
    2380          25 :                "QS| GAPW_XC|                eps_fit:", &
    2381          25 :                qs_control%gapw_control%eps_fit, &
    2382          25 :                "QS| GAPW_XC|                eps_iso:", &
    2383          25 :                qs_control%gapw_control%eps_iso, &
    2384          25 :                "QS| GAPW_XC|                eps_svd:", &
    2385          50 :                qs_control%gapw_control%eps_svd
    2386             :             WRITE (UNIT=output_unit, FMT="(T2,A,T55,A30)") &
    2387          25 :                "QS| GAPW_XC|atom-r-grid: quadrature:", &
    2388          50 :                enum_i2c(enum, qs_control%gapw_control%quadrature)
    2389             :             WRITE (UNIT=output_unit, FMT="(T2,A,T71,I10)") &
    2390          25 :                "QS| GAPW_XC|   atom-s-grid:  max l :", &
    2391          50 :                qs_control%gapw_control%lmax_sphere
    2392             :          END IF
    2393        1339 :          IF (qs_control%mulliken_restraint) THEN
    2394             :             WRITE (UNIT=output_unit, FMT="(T2,A,T73,ES8.1)") &
    2395           1 :                "QS| Mulliken restraint target", qs_control%mulliken_restraint_control%target
    2396             :             WRITE (UNIT=output_unit, FMT="(T2,A,T73,ES8.1)") &
    2397           1 :                "QS| Mulliken restraint strength", qs_control%mulliken_restraint_control%strength
    2398             :             WRITE (UNIT=output_unit, FMT="(T2,A,T73,I8)") &
    2399           1 :                "QS| Mulliken restraint atoms: ", qs_control%mulliken_restraint_control%natoms
    2400           2 :             WRITE (UNIT=output_unit, FMT="(5I8)") qs_control%mulliken_restraint_control%atoms
    2401             :          END IF
    2402        1339 :          IF (qs_control%ddapc_restraint) THEN
    2403          14 :             DO i = 1, SIZE(qs_control%ddapc_restraint_control)
    2404           8 :                ddapc_restraint_control => qs_control%ddapc_restraint_control(i)
    2405           8 :                IF (SIZE(qs_control%ddapc_restraint_control) .GT. 1) &
    2406             :                   WRITE (UNIT=output_unit, FMT="(T2,A,T3,I8)") &
    2407           3 :                   "QS| parameters for DDAPC restraint number", i
    2408             :                WRITE (UNIT=output_unit, FMT="(T2,A,T73,ES8.1)") &
    2409           8 :                   "QS| ddapc restraint target", ddapc_restraint_control%target
    2410             :                WRITE (UNIT=output_unit, FMT="(T2,A,T73,ES8.1)") &
    2411           8 :                   "QS| ddapc restraint strength", ddapc_restraint_control%strength
    2412             :                WRITE (UNIT=output_unit, FMT="(T2,A,T73,I8)") &
    2413           8 :                   "QS| ddapc restraint atoms: ", ddapc_restraint_control%natoms
    2414          17 :                WRITE (UNIT=output_unit, FMT="(5I8)") ddapc_restraint_control%atoms
    2415           8 :                WRITE (UNIT=output_unit, FMT="(T2,A)") "Coefficients:"
    2416          17 :                WRITE (UNIT=output_unit, FMT="(5F6.2)") ddapc_restraint_control%coeff
    2417           6 :                SELECT CASE (ddapc_restraint_control%functional_form)
    2418             :                CASE (do_ddapc_restraint)
    2419             :                   WRITE (UNIT=output_unit, FMT="(T2,A,T61,A20)") &
    2420           3 :                      "QS| ddapc restraint functional form :", "RESTRAINT"
    2421             :                CASE (do_ddapc_constraint)
    2422             :                   WRITE (UNIT=output_unit, FMT="(T2,A,T61,A20)") &
    2423           5 :                      "QS| ddapc restraint functional form :", "CONSTRAINT"
    2424             :                CASE DEFAULT
    2425           8 :                   CPABORT("Unknown ddapc restraint")
    2426             :                END SELECT
    2427             :             END DO
    2428             :          END IF
    2429        1339 :          IF (qs_control%s2_restraint) THEN
    2430             :             WRITE (UNIT=output_unit, FMT="(T2,A,T73,ES8.1)") &
    2431           0 :                "QS| s2 restraint target", qs_control%s2_restraint_control%target
    2432             :             WRITE (UNIT=output_unit, FMT="(T2,A,T73,ES8.1)") &
    2433           0 :                "QS| s2 restraint strength", qs_control%s2_restraint_control%strength
    2434           0 :             SELECT CASE (qs_control%s2_restraint_control%functional_form)
    2435             :             CASE (do_s2_restraint)
    2436             :                WRITE (UNIT=output_unit, FMT="(T2,A,T61,A20)") &
    2437           0 :                   "QS| s2 restraint functional form :", "RESTRAINT"
    2438           0 :                CPABORT("Not yet implemented")
    2439             :             CASE (do_s2_constraint)
    2440             :                WRITE (UNIT=output_unit, FMT="(T2,A,T61,A20)") &
    2441           0 :                   "QS| s2 restraint functional form :", "CONSTRAINT"
    2442             :             CASE DEFAULT
    2443           0 :                CPABORT("Unknown ddapc restraint")
    2444             :             END SELECT
    2445             :          END IF
    2446             :       END IF
    2447             :       CALL cp_print_key_finished_output(output_unit, logger, print_section_vals, &
    2448        5204 :                                         "DFT_CONTROL_PARAMETERS")
    2449             : 
    2450        5204 :       CALL timestop(handle)
    2451             : 
    2452             :    END SUBROUTINE write_qs_control
    2453             : 
    2454             : ! **************************************************************************************************
    2455             : !> \brief reads the input parameters needed for ddapc.
    2456             : !> \param qs_control ...
    2457             : !> \param qs_section ...
    2458             : !> \param ddapc_restraint_section ...
    2459             : !> \author fschiff
    2460             : !> \note
    2461             : !>      either reads DFT%QS%DDAPC_RESTRAINT or PROPERTIES%ET_coupling
    2462             : !>      if(qs_section is present the DFT part is read, if ddapc_restraint_section
    2463             : !>      is present ET_COUPLING is read. Avoid having both!!!
    2464             : ! **************************************************************************************************
    2465          14 :    SUBROUTINE read_ddapc_section(qs_control, qs_section, ddapc_restraint_section)
    2466             : 
    2467             :       TYPE(qs_control_type), INTENT(INOUT)               :: qs_control
    2468             :       TYPE(section_vals_type), OPTIONAL, POINTER         :: qs_section, ddapc_restraint_section
    2469             : 
    2470             :       INTEGER                                            :: i, j, jj, k, n_rep
    2471          14 :       INTEGER, DIMENSION(:), POINTER                     :: tmplist
    2472          14 :       REAL(KIND=dp), DIMENSION(:), POINTER               :: rtmplist
    2473             :       TYPE(ddapc_restraint_type), POINTER                :: ddapc_restraint_control
    2474             :       TYPE(section_vals_type), POINTER                   :: ddapc_section
    2475             : 
    2476          14 :       IF (PRESENT(ddapc_restraint_section)) THEN
    2477           0 :          IF (ASSOCIATED(qs_control%ddapc_restraint_control)) THEN
    2478           0 :             IF (SIZE(qs_control%ddapc_restraint_control) .GE. 2) &
    2479           0 :                CPABORT("ET_COUPLING cannot be used in combination with a normal restraint")
    2480             :          ELSE
    2481           0 :             ddapc_section => ddapc_restraint_section
    2482           0 :             ALLOCATE (qs_control%ddapc_restraint_control(1))
    2483             :          END IF
    2484             :       END IF
    2485             : 
    2486          14 :       IF (PRESENT(qs_section)) THEN
    2487          14 :          NULLIFY (ddapc_section)
    2488             :          ddapc_section => section_vals_get_subs_vals(qs_section, &
    2489          14 :                                                      "DDAPC_RESTRAINT")
    2490             :       END IF
    2491             : 
    2492          32 :       DO i = 1, SIZE(qs_control%ddapc_restraint_control)
    2493             : 
    2494          18 :          CALL ddapc_control_create(qs_control%ddapc_restraint_control(i))
    2495          18 :          ddapc_restraint_control => qs_control%ddapc_restraint_control(i)
    2496             : 
    2497             :          CALL section_vals_val_get(ddapc_section, "STRENGTH", i_rep_section=i, &
    2498          18 :                                    r_val=ddapc_restraint_control%strength)
    2499             :          CALL section_vals_val_get(ddapc_section, "TARGET", i_rep_section=i, &
    2500          18 :                                    r_val=ddapc_restraint_control%target)
    2501             :          CALL section_vals_val_get(ddapc_section, "FUNCTIONAL_FORM", i_rep_section=i, &
    2502          18 :                                    i_val=ddapc_restraint_control%functional_form)
    2503             :          CALL section_vals_val_get(ddapc_section, "ATOMS", i_rep_section=i, &
    2504          18 :                                    n_rep_val=n_rep)
    2505             :          CALL section_vals_val_get(ddapc_section, "TYPE_OF_DENSITY", i_rep_section=i, &
    2506          18 :                                    i_val=ddapc_restraint_control%density_type)
    2507             : 
    2508          18 :          jj = 0
    2509          36 :          DO k = 1, n_rep
    2510             :             CALL section_vals_val_get(ddapc_section, "ATOMS", i_rep_section=i, &
    2511          18 :                                       i_rep_val=k, i_vals=tmplist)
    2512          56 :             DO j = 1, SIZE(tmplist)
    2513          38 :                jj = jj + 1
    2514             :             END DO
    2515             :          END DO
    2516          18 :          IF (jj < 1) CPABORT("Need at least 1 atom to use ddapc constraints")
    2517          18 :          ddapc_restraint_control%natoms = jj
    2518          18 :          IF (ASSOCIATED(ddapc_restraint_control%atoms)) &
    2519           0 :             DEALLOCATE (ddapc_restraint_control%atoms)
    2520          54 :          ALLOCATE (ddapc_restraint_control%atoms(ddapc_restraint_control%natoms))
    2521          18 :          jj = 0
    2522          36 :          DO k = 1, n_rep
    2523             :             CALL section_vals_val_get(ddapc_section, "ATOMS", i_rep_section=i, &
    2524          18 :                                       i_rep_val=k, i_vals=tmplist)
    2525          56 :             DO j = 1, SIZE(tmplist)
    2526          20 :                jj = jj + 1
    2527          38 :                ddapc_restraint_control%atoms(jj) = tmplist(j)
    2528             :             END DO
    2529             :          END DO
    2530             : 
    2531          18 :          IF (ASSOCIATED(ddapc_restraint_control%coeff)) &
    2532           0 :             DEALLOCATE (ddapc_restraint_control%coeff)
    2533          54 :          ALLOCATE (ddapc_restraint_control%coeff(ddapc_restraint_control%natoms))
    2534          38 :          ddapc_restraint_control%coeff = 1.0_dp
    2535             : 
    2536             :          CALL section_vals_val_get(ddapc_section, "COEFF", i_rep_section=i, &
    2537          18 :                                    n_rep_val=n_rep)
    2538          18 :          jj = 0
    2539          20 :          DO k = 1, n_rep
    2540             :             CALL section_vals_val_get(ddapc_section, "COEFF", i_rep_section=i, &
    2541           2 :                                       i_rep_val=k, r_vals=rtmplist)
    2542          22 :             DO j = 1, SIZE(rtmplist)
    2543           2 :                jj = jj + 1
    2544           2 :                IF (jj > ddapc_restraint_control%natoms) &
    2545           0 :                   CPABORT("Need the same number of coeff as there are atoms ")
    2546           4 :                ddapc_restraint_control%coeff(jj) = rtmplist(j)
    2547             :             END DO
    2548             :          END DO
    2549          18 :          IF (jj < ddapc_restraint_control%natoms .AND. jj .NE. 0) &
    2550          50 :             CPABORT("Need no or the same number of coeff as there are atoms.")
    2551             :       END DO
    2552          14 :       k = 0
    2553          32 :       DO i = 1, SIZE(qs_control%ddapc_restraint_control)
    2554          18 :          IF (qs_control%ddapc_restraint_control(i)%functional_form == &
    2555          24 :              do_ddapc_constraint) k = k + 1
    2556             :       END DO
    2557          14 :       IF (k == 2) CALL cp_abort(__LOCATION__, &
    2558           0 :                                 "Only a single constraint possible yet, try to use restraints instead ")
    2559             : 
    2560          14 :    END SUBROUTINE read_ddapc_section
    2561             : 
    2562             : ! **************************************************************************************************
    2563             : !> \brief ...
    2564             : !> \param dft_control ...
    2565             : !> \param efield_section ...
    2566             : ! **************************************************************************************************
    2567         264 :    SUBROUTINE read_efield_sections(dft_control, efield_section)
    2568             :       TYPE(dft_control_type), POINTER                    :: dft_control
    2569             :       TYPE(section_vals_type), POINTER                   :: efield_section
    2570             : 
    2571             :       CHARACTER(len=default_path_length)                 :: file_name
    2572             :       INTEGER                                            :: i, io, j, n, unit_nr
    2573         264 :       REAL(KIND=dp), DIMENSION(:), POINTER               :: tmp_vals
    2574             :       TYPE(efield_type), POINTER                         :: efield
    2575             :       TYPE(section_vals_type), POINTER                   :: tmp_section
    2576             : 
    2577         528 :       DO i = 1, SIZE(dft_control%efield_fields)
    2578         264 :          NULLIFY (dft_control%efield_fields(i)%efield)
    2579        1320 :          ALLOCATE (dft_control%efield_fields(i)%efield)
    2580         264 :          efield => dft_control%efield_fields(i)%efield
    2581         264 :          NULLIFY (efield%envelop_i_vars, efield%envelop_r_vars)
    2582             :          CALL section_vals_val_get(efield_section, "INTENSITY", i_rep_section=i, &
    2583         264 :                                    r_val=efield%strength)
    2584             : 
    2585             :          CALL section_vals_val_get(efield_section, "POLARISATION", i_rep_section=i, &
    2586         264 :                                    r_vals=tmp_vals)
    2587         792 :          ALLOCATE (efield%polarisation(SIZE(tmp_vals)))
    2588        2112 :          efield%polarisation = tmp_vals
    2589             :          CALL section_vals_val_get(efield_section, "PHASE", i_rep_section=i, &
    2590         264 :                                    r_val=efield%phase_offset)
    2591             :          CALL section_vals_val_get(efield_section, "ENVELOP", i_rep_section=i, &
    2592         264 :                                    i_val=efield%envelop_id)
    2593             :          CALL section_vals_val_get(efield_section, "WAVELENGTH", i_rep_section=i, &
    2594         264 :                                    r_val=efield%wavelength)
    2595             :          CALL section_vals_val_get(efield_section, "VEC_POT_INITIAL", i_rep_section=i, &
    2596         264 :                                    r_vals=tmp_vals)
    2597        2112 :          efield%vec_pot_initial = tmp_vals
    2598             : 
    2599         528 :          IF (efield%envelop_id == constant_env) THEN
    2600         252 :             ALLOCATE (efield%envelop_i_vars(2))
    2601         252 :             tmp_section => section_vals_get_subs_vals(efield_section, "CONSTANT_ENV", i_rep_section=i)
    2602             :             CALL section_vals_val_get(tmp_section, "START_STEP", &
    2603         252 :                                       i_val=efield%envelop_i_vars(1))
    2604             :             CALL section_vals_val_get(tmp_section, "END_STEP", &
    2605         252 :                                       i_val=efield%envelop_i_vars(2))
    2606          12 :          ELSE IF (efield%envelop_id == gaussian_env) THEN
    2607           8 :             ALLOCATE (efield%envelop_r_vars(2))
    2608           8 :             tmp_section => section_vals_get_subs_vals(efield_section, "GAUSSIAN_ENV", i_rep_section=i)
    2609             :             CALL section_vals_val_get(tmp_section, "T0", &
    2610           8 :                                       r_val=efield%envelop_r_vars(1))
    2611             :             CALL section_vals_val_get(tmp_section, "SIGMA", &
    2612           8 :                                       r_val=efield%envelop_r_vars(2))
    2613           4 :          ELSE IF (efield%envelop_id == ramp_env) THEN
    2614           2 :             ALLOCATE (efield%envelop_i_vars(4))
    2615           2 :             tmp_section => section_vals_get_subs_vals(efield_section, "RAMP_ENV", i_rep_section=i)
    2616             :             CALL section_vals_val_get(tmp_section, "START_STEP_IN", &
    2617           2 :                                       i_val=efield%envelop_i_vars(1))
    2618             :             CALL section_vals_val_get(tmp_section, "END_STEP_IN", &
    2619           2 :                                       i_val=efield%envelop_i_vars(2))
    2620             :             CALL section_vals_val_get(tmp_section, "START_STEP_OUT", &
    2621           2 :                                       i_val=efield%envelop_i_vars(3))
    2622             :             CALL section_vals_val_get(tmp_section, "END_STEP_OUT", &
    2623           2 :                                       i_val=efield%envelop_i_vars(4))
    2624           2 :          ELSE IF (efield%envelop_id == custom_env) THEN
    2625           2 :             tmp_section => section_vals_get_subs_vals(efield_section, "CUSTOM_ENV", i_rep_section=i)
    2626           2 :             CALL section_vals_val_get(tmp_section, "EFIELD_FILE_NAME", c_val=file_name)
    2627           2 :             CALL open_file(file_name=TRIM(file_name), file_action="READ", file_status="OLD", unit_number=unit_nr)
    2628             :             !Determine the number of lines in file
    2629           2 :             n = 0
    2630          10 :             DO WHILE (.TRUE.)
    2631          12 :                READ (unit_nr, *, iostat=io)
    2632          12 :                IF (io /= 0) EXIT
    2633          10 :                n = n + 1
    2634             :             END DO
    2635           2 :             REWIND (unit_nr)
    2636           6 :             ALLOCATE (efield%envelop_r_vars(n + 1))
    2637             :             !Store the timestep of the list in the first entry of the r_vars
    2638           2 :             CALL section_vals_val_get(tmp_section, "TIMESTEP", r_val=efield%envelop_r_vars(1))
    2639             :             !Read the file
    2640          12 :             DO j = 2, n + 1
    2641          10 :                READ (unit_nr, *) efield%envelop_r_vars(j)
    2642          12 :                efield%envelop_r_vars(j) = cp_unit_to_cp2k(efield%envelop_r_vars(j), "volt/m")
    2643             :             END DO
    2644           2 :             CALL close_file(unit_nr)
    2645             :          END IF
    2646             :       END DO
    2647         264 :    END SUBROUTINE read_efield_sections
    2648             : 
    2649             : ! **************************************************************************************************
    2650             : !> \brief reads the input parameters needed real time propagation
    2651             : !> \param dft_control ...
    2652             : !> \param rtp_section ...
    2653             : !> \author fschiff
    2654             : ! **************************************************************************************************
    2655         496 :    SUBROUTINE read_rtp_section(dft_control, rtp_section)
    2656             : 
    2657             :       TYPE(dft_control_type), INTENT(INOUT)              :: dft_control
    2658             :       TYPE(section_vals_type), POINTER                   :: rtp_section
    2659             : 
    2660         248 :       INTEGER, DIMENSION(:), POINTER                     :: tmp
    2661             :       LOGICAL                                            :: is_present
    2662             :       TYPE(section_vals_type), POINTER                   :: proj_mo_section
    2663             : 
    2664        2976 :       ALLOCATE (dft_control%rtp_control)
    2665             :       CALL section_vals_val_get(rtp_section, "MAX_ITER", &
    2666         248 :                                 i_val=dft_control%rtp_control%max_iter)
    2667             :       CALL section_vals_val_get(rtp_section, "MAT_EXP", &
    2668         248 :                                 i_val=dft_control%rtp_control%mat_exp)
    2669             :       CALL section_vals_val_get(rtp_section, "ASPC_ORDER", &
    2670         248 :                                 i_val=dft_control%rtp_control%aspc_order)
    2671             :       CALL section_vals_val_get(rtp_section, "EXP_ACCURACY", &
    2672         248 :                                 r_val=dft_control%rtp_control%eps_exp)
    2673             :       CALL section_vals_val_get(rtp_section, "RTP_METHOD", &
    2674         248 :                                 i_val=dft_control%rtp_control%rtp_method)
    2675             :       CALL section_vals_val_get(rtp_section, "RTBSE_HAMILTONIAN", &
    2676         248 :                                 i_val=dft_control%rtp_control%rtbse_ham)
    2677             :       CALL section_vals_val_get(rtp_section, "PROPAGATOR", &
    2678         248 :                                 i_val=dft_control%rtp_control%propagator)
    2679             :       CALL section_vals_val_get(rtp_section, "EPS_ITER", &
    2680         248 :                                 r_val=dft_control%rtp_control%eps_ener)
    2681             :       CALL section_vals_val_get(rtp_section, "INITIAL_WFN", &
    2682         248 :                                 i_val=dft_control%rtp_control%initial_wfn)
    2683             :       CALL section_vals_val_get(rtp_section, "HFX_BALANCE_IN_CORE", &
    2684         248 :                                 l_val=dft_control%rtp_control%hfx_redistribute)
    2685             :       CALL section_vals_val_get(rtp_section, "APPLY_WFN_MIX_INIT_RESTART", &
    2686         248 :                                 l_val=dft_control%rtp_control%apply_wfn_mix_init_restart)
    2687             :       CALL section_vals_val_get(rtp_section, "APPLY_DELTA_PULSE", &
    2688         248 :                                 l_val=dft_control%rtp_control%apply_delta_pulse)
    2689             :       CALL section_vals_val_get(rtp_section, "APPLY_DELTA_PULSE_MAG", &
    2690         248 :                                 l_val=dft_control%rtp_control%apply_delta_pulse_mag)
    2691             :       CALL section_vals_val_get(rtp_section, "VELOCITY_GAUGE", &
    2692         248 :                                 l_val=dft_control%rtp_control%velocity_gauge)
    2693             :       CALL section_vals_val_get(rtp_section, "VG_COM_NL", &
    2694         248 :                                 l_val=dft_control%rtp_control%nl_gauge_transform)
    2695             :       CALL section_vals_val_get(rtp_section, "PERIODIC", &
    2696         248 :                                 l_val=dft_control%rtp_control%periodic)
    2697             :       CALL section_vals_val_get(rtp_section, "DENSITY_PROPAGATION", &
    2698         248 :                                 l_val=dft_control%rtp_control%linear_scaling)
    2699             :       CALL section_vals_val_get(rtp_section, "MCWEENY_MAX_ITER", &
    2700         248 :                                 i_val=dft_control%rtp_control%mcweeny_max_iter)
    2701             :       CALL section_vals_val_get(rtp_section, "ACCURACY_REFINEMENT", &
    2702         248 :                                 i_val=dft_control%rtp_control%acc_ref)
    2703             :       CALL section_vals_val_get(rtp_section, "MCWEENY_EPS", &
    2704         248 :                                 r_val=dft_control%rtp_control%mcweeny_eps)
    2705             :       CALL section_vals_val_get(rtp_section, "DELTA_PULSE_SCALE", &
    2706         248 :                                 r_val=dft_control%rtp_control%delta_pulse_scale)
    2707             :       CALL section_vals_val_get(rtp_section, "DELTA_PULSE_DIRECTION", &
    2708         248 :                                 i_vals=tmp)
    2709         992 :       dft_control%rtp_control%delta_pulse_direction = tmp
    2710             :       CALL section_vals_val_get(rtp_section, "SC_CHECK_START", &
    2711         248 :                                 i_val=dft_control%rtp_control%sc_check_start)
    2712         248 :       proj_mo_section => section_vals_get_subs_vals(rtp_section, "PRINT%PROJECTION_MO")
    2713         248 :       CALL section_vals_get(proj_mo_section, explicit=is_present)
    2714         248 :       IF (is_present) THEN
    2715           4 :          IF (dft_control%rtp_control%linear_scaling) &
    2716             :             CALL cp_abort(__LOCATION__, &
    2717             :                           "You have defined a time dependent projection of mos, but "// &
    2718             :                           "only the density matrix is propagated (DENSITY_PROPAGATION "// &
    2719             :                           ".TRUE.). Please either use MO-based real time DFT or do not "// &
    2720           0 :                           "define any PRINT%PROJECTION_MO section")
    2721           4 :          dft_control%rtp_control%is_proj_mo = .TRUE.
    2722             :       ELSE
    2723         244 :          dft_control%rtp_control%is_proj_mo = .FALSE.
    2724             :       END IF
    2725             : 
    2726         248 :    END SUBROUTINE read_rtp_section
    2727             : 
    2728             : ! **************************************************************************************************
    2729             : !> \brief Parses the BLOCK_LIST keywords from the ADMM section
    2730             : !> \param admm_control ...
    2731             : !> \param dft_section ...
    2732             : ! **************************************************************************************************
    2733         442 :    SUBROUTINE read_admm_block_list(admm_control, dft_section)
    2734             :       TYPE(admm_control_type), POINTER                   :: admm_control
    2735             :       TYPE(section_vals_type), POINTER                   :: dft_section
    2736             : 
    2737             :       INTEGER                                            :: irep, list_size, n_rep
    2738         442 :       INTEGER, DIMENSION(:), POINTER                     :: tmplist
    2739             : 
    2740         442 :       NULLIFY (tmplist)
    2741             : 
    2742             :       CALL section_vals_val_get(dft_section, "AUXILIARY_DENSITY_MATRIX_METHOD%BLOCK_LIST", &
    2743         442 :                                 n_rep_val=n_rep)
    2744             : 
    2745         938 :       ALLOCATE (admm_control%blocks(n_rep))
    2746             : 
    2747         478 :       DO irep = 1, n_rep
    2748             :          CALL section_vals_val_get(dft_section, "AUXILIARY_DENSITY_MATRIX_METHOD%BLOCK_LIST", &
    2749          36 :                                    i_rep_val=irep, i_vals=tmplist)
    2750          36 :          list_size = SIZE(tmplist)
    2751         108 :          ALLOCATE (admm_control%blocks(irep)%list(list_size))
    2752         650 :          admm_control%blocks(irep)%list(:) = tmplist(:)
    2753             :       END DO
    2754             : 
    2755         442 :    END SUBROUTINE read_admm_block_list
    2756             : 
    2757             : END MODULE cp_control_utils

Generated by: LCOV version 1.15