LCOV - code coverage report
Current view: top level - src - input_cp2k_scf.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:6d276e9) Lines: 100.0 % 707 707
Test Date: 2026-09-10 07:29:18 Functions: 100.0 % 14 14

            Line data    Source code
       1              : !--------------------------------------------------------------------------------------------------!
       2              : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3              : !   Copyright 2000-2026 CP2K developers group <https://cp2k.org>                                   !
       4              : !                                                                                                  !
       5              : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6              : !--------------------------------------------------------------------------------------------------!
       7              : 
       8              : ! **************************************************************************************************
       9              : !> \brief function that build the scf section of the input
      10              : !> \par History
      11              : !>      10.2005 moved out of input_cp2k [fawzi]
      12              : !>      07.2024 moved out of input_cp2k_dft [JGH]
      13              : !> \author fawzi
      14              : ! **************************************************************************************************
      15              : MODULE input_cp2k_scf
      16              :    USE bibliography,                    ONLY: &
      17              :         Becke1988b, Blaha2010, Chai2024a, Holmberg2017, Holmberg2018, Hu2010, &
      18              :         KresseFurthmueller1996, Schiffmann2015, Stewart1982, VandeVondele2003, VandeVondele2005a, &
      19              :         Weber2008
      20              :    USE cp_output_handling,              ONLY: add_last_numeric,&
      21              :                                               cp_print_key_section_create,&
      22              :                                               high_print_level,&
      23              :                                               low_print_level
      24              :    USE cp_units,                        ONLY: cp_unit_to_cp2k
      25              :    USE input_constants,                 ONLY: &
      26              :         atomic_guess, becke_cutoff_element, becke_cutoff_global, broyden_type_1, &
      27              :         broyden_type_1_explicit, broyden_type_1_explicit_ls, broyden_type_1_ls, broyden_type_2, &
      28              :         broyden_type_2_explicit, broyden_type_2_explicit_ls, broyden_type_2_ls, &
      29              :         cdft_alpha_constraint, cdft_beta_constraint, cdft_charge_constraint, &
      30              :         cdft_magnetization_constraint, cholesky_dbcsr, cholesky_inverse, cholesky_off, &
      31              :         cholesky_reduce, cholesky_restore, core_guess, diag_block_davidson, diag_block_krylov, &
      32              :         diag_filter_matrix, diag_ot, diag_standard, diag_update_method_adiis, &
      33              :         diag_update_method_mixing, eht_guess, external_density_guess, gaussian, general_roks, &
      34              :         high_spin_roks, history_guess, jacobian_fd1, jacobian_fd1_backward, jacobian_fd1_central, &
      35              :         jacobian_fd2, jacobian_fd2_backward, ls_2pnt, ls_3pnt, ls_adapt, ls_gold, ls_none, &
      36              :         mopac_guess, no_guess, numerical, ot_algo_irac, ot_algo_taylor_or_diag, ot_chol_irac, &
      37              :         ot_low_rank_base_lattice_fft, ot_low_rank_base_overlap, ot_lwdn_irac, ot_mini_broyden, &
      38              :         ot_mini_cg, ot_mini_diis, ot_mini_lbfgs, ot_mini_sd, ot_poly_irac, &
      39              :         ot_precond_fermi_low_rank, ot_precond_full_all, ot_precond_full_kinetic, &
      40              :         ot_precond_full_single, ot_precond_full_single_inverse, ot_precond_none, &
      41              :         ot_precond_s_inverse, ot_precond_solver_chebyshev, ot_precond_solver_default, &
      42              :         ot_precond_solver_direct, ot_precond_solver_inv_chol, ot_precond_solver_update, &
      43              :         outer_scf_basis_center_opt, outer_scf_becke_constraint, outer_scf_cdft_constraint, &
      44              :         outer_scf_ddapc_constraint, outer_scf_hirshfeld_constraint, outer_scf_none, &
      45              :         outer_scf_optimizer_bisect, outer_scf_optimizer_broyden, outer_scf_optimizer_diis, &
      46              :         outer_scf_optimizer_newton, outer_scf_optimizer_newton_ls, outer_scf_optimizer_none, &
      47              :         outer_scf_optimizer_sd, outer_scf_optimizer_secant, outer_scf_s2_constraint, &
      48              :         radius_covalent, radius_default, radius_single, radius_user, radius_vdw, random_guess, &
      49              :         restart_guess, shape_function_density, shape_function_gaussian, smear_energy_window, &
      50              :         smear_fermi_dirac, smear_gaussian, smear_list, smear_mp, smear_mv, sparse_guess
      51              :    USE input_keyword_types,             ONLY: keyword_create,&
      52              :                                               keyword_release,&
      53              :                                               keyword_type
      54              :    USE input_section_types,             ONLY: section_add_keyword,&
      55              :                                               section_add_subsection,&
      56              :                                               section_create,&
      57              :                                               section_release,&
      58              :                                               section_type
      59              :    USE input_val_types,                 ONLY: char_t,&
      60              :                                               integer_t,&
      61              :                                               real_t
      62              :    USE kinds,                           ONLY: dp
      63              :    USE qs_density_mixing_types,         ONLY: create_mixing_section
      64              :    USE qs_fb_input,                     ONLY: create_filtermatrix_section
      65              :    USE qs_mom_types,                    ONLY: create_mom_section
      66              :    USE string_utilities,                ONLY: newline,&
      67              :                                               s2a
      68              : #include "./base/base_uses.f90"
      69              : 
      70              :    IMPLICIT NONE
      71              :    PRIVATE
      72              : 
      73              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'input_cp2k_scf'
      74              : 
      75              :    PUBLIC :: create_scf_section, create_cdft_control_section
      76              : 
      77              : CONTAINS
      78              : 
      79              : ! **************************************************************************************************
      80              : !> \brief creates the structure of the section with the DFT SCF parameters
      81              : !> \param section will contain the SCF section
      82              : !> \author fawzi
      83              : ! **************************************************************************************************
      84        25775 :    SUBROUTINE create_scf_section(section)
      85              :       TYPE(section_type), POINTER                        :: section
      86              : 
      87              :       TYPE(keyword_type), POINTER                        :: keyword
      88              :       TYPE(section_type), POINTER                        :: print_key, subsection
      89              : 
      90        25775 :       NULLIFY (print_key)
      91              : 
      92        25775 :       CPASSERT(.NOT. ASSOCIATED(section))
      93              :       CALL section_create(section, __LOCATION__, name="scf", &
      94              :                           description="Parameters needed to perform an SCF run.", &
      95        25775 :                           n_keywords=21, n_subsections=8, repeats=.FALSE.)
      96              : 
      97        25775 :       NULLIFY (subsection)
      98              : 
      99        25775 :       CALL create_ot_section(subsection)
     100        25775 :       CALL section_add_subsection(section, subsection)
     101        25775 :       CALL section_release(subsection)
     102              : 
     103        25775 :       CALL create_diagonalization_section(subsection)
     104        25775 :       CALL section_add_subsection(section, subsection)
     105        25775 :       CALL section_release(subsection)
     106              : 
     107        25775 :       CALL create_outer_scf_section(subsection)
     108        25775 :       CALL section_add_subsection(section, subsection)
     109        25775 :       CALL section_release(subsection)
     110              : 
     111        25775 :       CALL create_smear_section(subsection)
     112        25775 :       CALL section_add_subsection(section, subsection)
     113        25775 :       CALL section_release(subsection)
     114              : 
     115        25775 :       CALL create_mixing_section(subsection)
     116        25775 :       CALL section_add_subsection(section, subsection)
     117        25775 :       CALL section_release(subsection)
     118              : 
     119        25775 :       CALL create_adiis_section(subsection)
     120        25775 :       CALL section_add_subsection(section, subsection)
     121        25775 :       CALL section_release(subsection)
     122              : 
     123        25775 :       CALL create_mom_section(subsection)
     124        25775 :       CALL section_add_subsection(section, subsection)
     125        25775 :       CALL section_release(subsection)
     126              : 
     127        25775 :       CALL create_gce_section(subsection)
     128        25775 :       CALL section_add_subsection(section, subsection)
     129        25775 :       CALL section_release(subsection)
     130              : 
     131        25775 :       NULLIFY (keyword)
     132              : 
     133              :       CALL keyword_create(keyword, __LOCATION__, name="MAX_ITER_LUMO", &
     134              :                           variants=["MAX_ITER_LUMOS"], &
     135              :                           description="Maximum number of iterations for the calculation of the LUMO energies "// &
     136              :                           "with the OT eigensolver.", &
     137        51550 :                           usage="MAX_ITER_LUMO 100", default_i_val=299)
     138        25775 :       CALL section_add_keyword(section, keyword)
     139        25775 :       CALL keyword_release(keyword)
     140              : 
     141              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_LUMO", &
     142              :                           variants=["EPS_LUMOS"], &
     143              :                           description="Target accuracy for the calculation of the LUMO energies with the OT eigensolver.", &
     144        51550 :                           usage="EPS_LUMO 1.0E-6", default_r_val=1.0E-5_dp)
     145        25775 :       CALL section_add_keyword(section, keyword)
     146        25775 :       CALL keyword_release(keyword)
     147              : 
     148              :       CALL keyword_create(keyword, __LOCATION__, name="MAX_SCF", &
     149              :                           description="Maximum number of inner SCF iterations for one electronic optimization.", &
     150        25775 :                           usage="MAX_SCF 200", default_i_val=50)
     151        25775 :       CALL section_add_keyword(section, keyword)
     152        25775 :       CALL keyword_release(keyword)
     153              : 
     154              :       CALL keyword_create(keyword, __LOCATION__, name="MAX_SCF_HISTORY", variants=["MAX_SCF_HIST"], &
     155              :                           description="Maximum number of SCF iterations after the history pipeline is filled", &
     156        51550 :                           usage="MAX_SCF_HISTORY 1", default_i_val=0, lone_keyword_i_val=1)
     157        25775 :       CALL section_add_keyword(section, keyword)
     158        25775 :       CALL keyword_release(keyword)
     159              : 
     160              :       CALL keyword_create(keyword, __LOCATION__, name="MAX_DIIS", &
     161              :                           variants=["MAX_DIIS_BUFFER_SIZE"], &
     162              :                           description="Maximum number of conventional DIIS subspace vectors to be used", &
     163        51550 :                           usage="MAX_DIIS 3", default_i_val=4)
     164        25775 :       CALL section_add_keyword(section, keyword)
     165        25775 :       CALL keyword_release(keyword)
     166              : 
     167              :       CALL keyword_create(keyword, __LOCATION__, name="LEVEL_SHIFT", &
     168              :                           variants=["LSHIFT"], &
     169              :                           description="Use level shifting to improve convergence", &
     170              :                           unit_str="au_e", &
     171              :                           usage="LEVEL_SHIFT 0.1", &
     172        51550 :                           default_r_val=0.0_dp)
     173        25775 :       CALL section_add_keyword(section, keyword)
     174        25775 :       CALL keyword_release(keyword)
     175              : 
     176              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_SCF", &
     177              :                           description="Target convergence threshold for the inner SCF cycle.", &
     178        25775 :                           usage="EPS_SCF 1.e-6", default_r_val=1.e-5_dp)
     179        25775 :       CALL section_add_keyword(section, keyword)
     180        25775 :       CALL keyword_release(keyword)
     181              : 
     182              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_SCF_HISTORY", variants=["EPS_SCF_HIST"], &
     183              :                           description="Target accuracy for the SCF convergence after the history pipeline is filled.", &
     184        51550 :                           usage="EPS_SCF_HISTORY 1.e-5", default_r_val=0.0_dp, lone_keyword_r_val=1.0e-5_dp)
     185        25775 :       CALL section_add_keyword(section, keyword)
     186        25775 :       CALL keyword_release(keyword)
     187              : 
     188              :       CALL keyword_create(keyword, __LOCATION__, name="CHOLESKY", &
     189              :                           description="If the cholesky method should be used for computing "// &
     190              :                           "the inverse of S, and in this case calling which Lapack routines", &
     191              :                           usage="CHOLESKY REDUCE", default_i_val=cholesky_restore, &
     192              :                           enum_c_vals=s2a("OFF", "REDUCE", "RESTORE", "INVERSE", "INVERSE_DBCSR"), &
     193              :                           enum_desc=s2a("The cholesky algorithm is not used", "Reduce is called", &
     194              :                                         "Reduce is replaced by two restore", &
     195              :                                         "Restore uses operator multiply by inverse of the triangular matrix", &
     196              :                                         "Like inverse, but matrix stored as dbcsr, sparce matrix algebra used when possible"), &
     197        25775 :                           enum_i_vals=[cholesky_off, cholesky_reduce, cholesky_restore, cholesky_inverse, cholesky_dbcsr])
     198        25775 :       CALL section_add_keyword(section, keyword)
     199        25775 :       CALL keyword_release(keyword)
     200              : 
     201              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_EIGVAL", &
     202              :                           description="Throw away linear combinations of basis functions with a small eigenvalue in S", &
     203        25775 :                           usage="EPS_EIGVAL 1.0", default_r_val=1.0e-5_dp)
     204        25775 :       CALL section_add_keyword(section, keyword)
     205        25775 :       CALL keyword_release(keyword)
     206              : 
     207              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_DIIS", &
     208              :                           description="Threshold on the convergence to start using DIAG/DIIS or OT/DIIS."// &
     209              :                           " Default for OT/DIIS is never to switch.", &
     210        25775 :                           usage="EPS_DIIS 5.0e-2", default_r_val=0.1_dp)
     211        25775 :       CALL section_add_keyword(section, keyword)
     212        25775 :       CALL keyword_release(keyword)
     213              : 
     214              :       CALL keyword_create( &
     215              :          keyword, __LOCATION__, name="SCF_GUESS", &
     216              :          description="Selects how the initial wavefunction or density matrix is generated.", &
     217              :          usage="SCF_GUESS RESTART", default_i_val=atomic_guess, &
     218              :          enum_c_vals=s2a("ATOMIC", "RESTART", "RANDOM", "CORE", &
     219              :                          "HISTORY_RESTART", "MOPAC", "EHT", "SPARSE", "EXTERNAL_DENSITY", "NONE"), &
     220              :          enum_desc=s2a("Generate an atomic density using the atomic code and internal default values", &
     221              :                        "Use the RESTART file as an initial guess (and ATOMIC if not present).", &
     222              :                        "Use random wavefunction coefficients.", &
     223              :                        "Diagonalize the core hamiltonian for an initial guess.", &
     224              :                        "Extrapolated from previous RESTART files.", &
     225              :                        "Use same guess as MOPAC for semi-empirical methods or a simple diagonal density matrix for other methods", &
     226              :                        "Use the EHT (gfn0-xTB) code to generate an initial wavefunction.", &
     227              :                        "Generate a sparse wavefunction using the atomic code (for OT based methods)", &
     228              :                        "Read a scalar electron density from a cube file for the first SCF Hamiltonian", &
     229              :                        "Skip initial guess (only for non-self consistent methods)."), &
     230              :          enum_i_vals=[atomic_guess, restart_guess, random_guess, core_guess, &
     231        25775 :                       history_guess, mopac_guess, eht_guess, sparse_guess, external_density_guess, no_guess])
     232        25775 :       CALL section_add_keyword(section, keyword)
     233        25775 :       CALL keyword_release(keyword)
     234              : 
     235              :       CALL keyword_create(keyword, __LOCATION__, name="EXTERNAL_DENSITY_FILE_NAME", &
     236              :                           description="Cube file containing the electron density used when SCF_GUESS is "// &
     237              :                           "EXTERNAL_DENSITY. The density is consumed once to build the first KS Hamiltonian; "// &
     238              :                           "all subsequent densities are generated by the regular SCF solver. The cube grid "// &
     239              :                           "has to coincide with the finest CP2K real-space grid.", &
     240              :                           usage="EXTERNAL_DENSITY_FILE_NAME <FILENAME>", &
     241        25775 :                           type_of_var=char_t, default_c_val="", n_var=1)
     242        25775 :       CALL section_add_keyword(section, keyword)
     243        25775 :       CALL keyword_release(keyword)
     244              : 
     245              :       CALL keyword_create(keyword, __LOCATION__, name="NROW_BLOCK", &
     246              :                           description="sets the number of rows in a scalapack block", &
     247        25775 :                           usage="NROW_BLOCK 31", default_i_val=32)
     248        25775 :       CALL section_add_keyword(section, keyword)
     249        25775 :       CALL keyword_release(keyword)
     250              : 
     251              :       CALL keyword_create(keyword, __LOCATION__, name="NCOL_BLOCK", &
     252              :                           description="Sets the number of columns in a scalapack block", &
     253        25775 :                           usage="NCOL_BLOCK 31", default_i_val=32)
     254        25775 :       CALL section_add_keyword(section, keyword)
     255        25775 :       CALL keyword_release(keyword)
     256              : 
     257              :       CALL keyword_create(keyword, __LOCATION__, name="ADDED_MOS", &
     258              :                           description="Number of additional molecular orbitals added for each spin channel. "// &
     259              :                           "This is commonly needed for smearing, excited-state, or post-Hartree-Fock calculations. "// &
     260              :                           "Use -1 to add all available orbitals. For k-point smearing, use AUTO "// &
     261              :                           "to select and adapt the virtual-space buffer.", &
     262        25775 :                           usage="ADDED_MOS {integer|AUTO}", default_c_val="0", n_var=-1)
     263        25775 :       CALL section_add_keyword(section, keyword)
     264        25775 :       CALL keyword_release(keyword)
     265              : 
     266              :       CALL keyword_create(keyword, __LOCATION__, &
     267              :                           name="ROKS_SCHEME", &
     268              :                           description="Selects the ROKS scheme when ROKS is applied.", &
     269              :                           usage="ROKS_SCHEME HIGH-SPIN", &
     270              :                           repeats=.FALSE., &
     271              :                           n_var=1, &
     272              :                           enum_c_vals=s2a("GENERAL", "HIGH-SPIN"), &
     273              :                           enum_i_vals=[general_roks, high_spin_roks], &
     274        25775 :                           default_i_val=high_spin_roks)
     275        25775 :       CALL section_add_keyword(section, keyword)
     276        25775 :       CALL keyword_release(keyword)
     277              : 
     278              :       CALL keyword_create(keyword, __LOCATION__, &
     279              :                           name="ROKS_F", &
     280              :                           variants=["F_ROKS"], &
     281              :                           description="Allows to define the parameter f for the "// &
     282              :                           "general ROKS scheme.", &
     283              :                           usage="ROKS_F 1/2", &
     284              :                           repeats=.FALSE., &
     285              :                           n_var=1, &
     286              :                           type_of_var=real_t, &
     287        51550 :                           default_r_val=0.5_dp)
     288        25775 :       CALL section_add_keyword(section, keyword)
     289        25775 :       CALL keyword_release(keyword)
     290              : 
     291              :       CALL keyword_create(keyword, __LOCATION__, &
     292              :                           name="ROKS_PARAMETERS", &
     293              :                           variants=["ROKS_PARAMETER"], &
     294              :                           description="Allows to define all parameters for the high-spin "// &
     295              :                           "ROKS scheme explicitly. "// &
     296              :                           "The full set of 6 parameters has to be specified "// &
     297              :                           "in the order acc, bcc, aoo, boo, avv, bvv", &
     298              :                           usage="ROKS_PARAMETERS 1/2 1/2 1/2 1/2 1/2 1/2", &
     299              :                           repeats=.FALSE., &
     300              :                           n_var=6, &
     301              :                           type_of_var=real_t, &
     302        51550 :                           default_r_vals=[-0.5_dp, 1.5_dp, 0.5_dp, 0.5_dp, 1.5_dp, -0.5_dp])
     303        25775 :       CALL section_add_keyword(section, keyword)
     304        25775 :       CALL keyword_release(keyword)
     305              : 
     306              :       CALL keyword_create(keyword, __LOCATION__, name="IGNORE_CONVERGENCE_FAILURE", &
     307              :                           description="If true, only a warning is issued if an SCF "// &
     308              :                           "iteration has not converged. By default, a run is aborted "// &
     309              :                           "if the required convergence criteria have not been achieved.", &
     310              :                           usage="IGNORE_CONVERGENCE_FAILURE logical_value", &
     311              :                           default_l_val=.FALSE., &
     312        25775 :                           lone_keyword_l_val=.TRUE.)
     313        25775 :       CALL section_add_keyword(section, keyword)
     314        25775 :       CALL keyword_release(keyword)
     315              : 
     316              :       CALL keyword_create(keyword, __LOCATION__, name="FORCE_SCF_CALCULATION", &
     317              :                           description="Request a SCF type solution even for nonSCF methods. ", &
     318              :                           usage="FORCE_SCF_CALCULATION logical_value", &
     319              :                           default_l_val=.FALSE., &
     320        25775 :                           lone_keyword_l_val=.TRUE.)
     321        25775 :       CALL section_add_keyword(section, keyword)
     322        25775 :       CALL keyword_release(keyword)
     323              : 
     324              :       CALL section_create(subsection, __LOCATION__, name="PRINT", &
     325        25775 :                           description="Printing of information during the SCF.", repeats=.FALSE.)
     326              : 
     327              :       CALL cp_print_key_section_create(print_key, __LOCATION__, "RESTART", &
     328              :                                        description="Controls the dumping of the MO restart file during SCF. "// &
     329              :                                        "By default keeps a short history of three restarts. "// &
     330              :                                        "See also RESTART_HISTORY", &
     331              :                                        print_level=low_print_level, common_iter_levels=3, &
     332              :                                        each_iter_names=s2a("QS_SCF"), each_iter_values=[20], &
     333        25775 :                                        add_last=add_last_numeric, filename="RESTART")
     334              :       CALL keyword_create(keyword, __LOCATION__, name="BACKUP_COPIES", &
     335              :                           description="Specifies the maximum number of backup copies.", &
     336              :                           usage="BACKUP_COPIES {int}", &
     337        25775 :                           default_i_val=1)
     338        25775 :       CALL section_add_keyword(print_key, keyword)
     339        25775 :       CALL keyword_release(keyword)
     340        25775 :       CALL section_add_subsection(subsection, print_key)
     341        25775 :       CALL section_release(print_key)
     342              : 
     343              :       CALL cp_print_key_section_create( &
     344              :          print_key, __LOCATION__, "RESTART_HISTORY", &
     345              :          description="Dumps unique MO restart files during the run keeping all of them.", &
     346              :          print_level=low_print_level, common_iter_levels=0, &
     347              :          each_iter_names=s2a("__ROOT__", "MD", "GEO_OPT", "ROT_OPT", "NEB", "METADYNAMICS", "QS_SCF"), &
     348              :          each_iter_values=[500, 500, 500, 500, 500, 500, 500], &
     349        25775 :          filename="RESTART")
     350              :       CALL keyword_create(keyword, __LOCATION__, name="BACKUP_COPIES", &
     351              :                           description="Specifies the maximum number of backup copies.", &
     352              :                           usage="BACKUP_COPIES {int}", &
     353        25775 :                           default_i_val=1)
     354        25775 :       CALL section_add_keyword(print_key, keyword)
     355        25775 :       CALL keyword_release(keyword)
     356        25775 :       CALL section_add_subsection(subsection, print_key)
     357        25775 :       CALL section_release(print_key)
     358              : 
     359              :       CALL cp_print_key_section_create(print_key, __LOCATION__, "iteration_info", &
     360              :                                        description="Controls the printing of basic iteration information during the SCF.", &
     361        25775 :                                        print_level=low_print_level, add_last=add_last_numeric, filename="__STD_OUT__")
     362              :       CALL keyword_create(keyword, __LOCATION__, name="time_cumul", &
     363              :                           description="If the printkey is activated switches the printing of timings"// &
     364              :                           " to cumulative (over the SCF).", &
     365        25775 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     366        25775 :       CALL section_add_keyword(print_key, keyword)
     367        25775 :       CALL keyword_release(keyword)
     368        25775 :       CALL section_add_subsection(subsection, print_key)
     369        25775 :       CALL section_release(print_key)
     370              : 
     371              :       CALL cp_print_key_section_create(print_key, __LOCATION__, "program_run_info", &
     372              :                                        description="Controls the printing of basic information during the SCF.", &
     373        25775 :                                        print_level=low_print_level, add_last=add_last_numeric, filename="__STD_OUT__")
     374        25775 :       CALL section_add_subsection(subsection, print_key)
     375        25775 :       CALL section_release(print_key)
     376              : 
     377              :       CALL cp_print_key_section_create(print_key, __LOCATION__, "MO_ORTHONORMALITY", &
     378              :                                        description="Controls the printing relative to the orthonormality of MOs (CT S C).", &
     379        25775 :                                        print_level=high_print_level, add_last=add_last_numeric, filename="__STD_OUT__")
     380        25775 :       CALL section_add_subsection(subsection, print_key)
     381        25775 :       CALL section_release(print_key)
     382              : 
     383              :       CALL cp_print_key_section_create(print_key, __LOCATION__, "MO_MAGNITUDE", &
     384              :                                        description="Prints the min/max eigenvalues of the overlap of the MOs without S (CT C).", &
     385        25775 :                                        print_level=high_print_level, add_last=add_last_numeric, filename="__STD_OUT__")
     386        25775 :       CALL section_add_subsection(subsection, print_key)
     387        25775 :       CALL section_release(print_key)
     388              : 
     389              :       CALL cp_print_key_section_create(print_key, __LOCATION__, "detailed_energy", &
     390              :                                        description="Controls the printing of detailed energy information.", &
     391        25775 :                                        print_level=high_print_level, add_last=add_last_numeric, filename="__STD_OUT__")
     392        25775 :       CALL section_add_subsection(subsection, print_key)
     393        25775 :       CALL section_release(print_key)
     394              : 
     395              :       CALL cp_print_key_section_create(print_key, __LOCATION__, "diis_info", &
     396              :                                        description="Controls the printing of DIIS information.", &
     397        25775 :                                        print_level=high_print_level, add_last=add_last_numeric, filename="__STD_OUT__")
     398        25775 :       CALL section_add_subsection(subsection, print_key)
     399        25775 :       CALL section_release(print_key)
     400              : 
     401              :       CALL cp_print_key_section_create(print_key, __LOCATION__, "total_densities", &
     402              :                                        description="Controls the printing of total densities.", &
     403        25775 :                                        print_level=high_print_level, add_last=add_last_numeric, filename="__STD_OUT__")
     404        25775 :       CALL section_add_subsection(subsection, print_key)
     405        25775 :       CALL section_release(print_key)
     406              : 
     407              :       CALL cp_print_key_section_create(print_key, __LOCATION__, "Lanczos", &
     408              :                                        description="Controls the printing of information on Lanczos refinement iterations.", &
     409        25775 :                                        print_level=high_print_level, add_last=add_last_numeric, filename="__STD_OUT__")
     410        25775 :       CALL section_add_subsection(subsection, print_key)
     411        25775 :       CALL section_release(print_key)
     412              : 
     413              :       CALL cp_print_key_section_create( &
     414              :          print_key, __LOCATION__, "DIAG_SUB_SCF", &
     415              :          description="Controls the printing of information on subspace diagonalization internal loop. ", &
     416        25775 :          print_level=high_print_level, add_last=add_last_numeric, filename="__STD_OUT__")
     417        25775 :       CALL section_add_subsection(subsection, print_key)
     418        25775 :       CALL section_release(print_key)
     419              : 
     420              :       CALL cp_print_key_section_create(print_key, __LOCATION__, "Davidson", &
     421              :                                        description="Controls the printing of information on Davidson iterations.", &
     422        25775 :                                        print_level=high_print_level, add_last=add_last_numeric, filename="__STD_OUT__")
     423        25775 :       CALL section_add_subsection(subsection, print_key)
     424        25775 :       CALL section_release(print_key)
     425              : 
     426              :       CALL cp_print_key_section_create(print_key, __LOCATION__, "FILTER_MATRIX", &
     427              :                                        description="Controls the printing of information on Filter Matrix method.", &
     428        25775 :                                        print_level=high_print_level, add_last=add_last_numeric, filename="__STD_OUT__")
     429        25775 :       CALL section_add_subsection(subsection, print_key)
     430        25775 :       CALL section_release(print_key)
     431              : 
     432              :       CALL keyword_create(keyword, __LOCATION__, name="DM_RESTART_WRITE", &
     433              :                           description="Write the density matrix into a binary file at the end of the SCF.", &
     434        25775 :                           usage="DM_RESTART_WRITE", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     435        25775 :       CALL section_add_keyword(subsection, keyword)
     436        25775 :       CALL keyword_release(keyword)
     437              : 
     438        25775 :       CALL section_add_subsection(section, subsection)
     439        25775 :       CALL section_release(subsection)
     440              : 
     441        25775 :    END SUBROUTINE create_scf_section
     442              : 
     443              : ! **************************************************************************************************
     444              : !> \brief creates the structure of the section with SCF parameters
     445              : !>      controlling an other loop
     446              : !> \param section will contain the SCF section
     447              : !> \author Joost VandeVondele [2006.03]
     448              : ! **************************************************************************************************
     449        36672 :    SUBROUTINE create_outer_scf_section(section)
     450              :       TYPE(section_type), POINTER                        :: section
     451              : 
     452              :       TYPE(keyword_type), POINTER                        :: keyword
     453              :       TYPE(section_type), POINTER                        :: subsection
     454              : 
     455        36672 :       CPASSERT(.NOT. ASSOCIATED(section))
     456              :       CALL section_create(section, __LOCATION__, name="OUTER_SCF", &
     457              :                           description="Controls an outer SCF loop, often used to stabilize difficult OT convergence, "// &
     458              :                           "constraints, or other variables wrapped around the inner SCF cycle.", &
     459        36672 :                           n_keywords=13, n_subsections=1, repeats=.FALSE.)
     460              : 
     461        36672 :       NULLIFY (keyword)
     462              : 
     463              :       CALL keyword_create(keyword, __LOCATION__, name="_SECTION_PARAMETERS_", &
     464              :                           description="Activates the outer SCF loop.", &
     465        36672 :                           usage="&OUTER_SCF ON", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     466        36672 :       CALL section_add_keyword(section, keyword)
     467        36672 :       CALL keyword_release(keyword)
     468              : 
     469              :       ! add CDFT_OPT section
     470        36672 :       NULLIFY (subsection)
     471        36672 :       CALL create_cdft_opt_section(subsection)
     472        36672 :       CALL section_add_subsection(section, subsection)
     473        36672 :       CALL section_release(subsection)
     474              : 
     475              :       CALL keyword_create(keyword, __LOCATION__, name="TYPE", &
     476              :                           description="Specifies which kind of outer SCF should be employed", &
     477              :                           usage="TYPE DDAPC_CONSTRAINT ", &
     478              :                           default_i_val=outer_scf_none, &
     479              :                           enum_c_vals=s2a("DDAPC_CONSTRAINT", "S2_CONSTRAINT", &
     480              :                                           "BASIS_CENTER_OPT", "CDFT_CONSTRAINT", "NONE"), &
     481              :                           enum_desc=s2a("Enforce a constraint on the DDAPC, requires the corresponding section", &
     482              :                                         "Enforce a constraint on the S2, requires the corresponding section", &
     483              :                                         "Optimize positions of basis functions, if atom types FLOATING_BASIS_CENTER "// &
     484              :                                         "are defined", &
     485              :                                         "Enforce a constraint on a generic CDFT weight population. "// &
     486              :                                         "Requires the corresponding section QS&CDFT"// &
     487              :                                         " which determines the type of weight used.", &
     488              :                                         "Do nothing in the outer loop, useful for resetting the inner loop,"), &
     489              :                           enum_i_vals=[outer_scf_ddapc_constraint, outer_scf_s2_constraint, &
     490        36672 :                                        outer_scf_basis_center_opt, outer_scf_cdft_constraint, outer_scf_none])
     491        36672 :       CALL section_add_keyword(section, keyword)
     492        36672 :       CALL keyword_release(keyword)
     493              : 
     494              :       CALL keyword_create(keyword, __LOCATION__, name="OPTIMIZER", &
     495              :                           description="Method used to bring the outer loop to a stationary point", &
     496              :                           usage="OPTIMIZER SD", &
     497              :                           default_i_val=outer_scf_optimizer_none, &
     498              :                           enum_c_vals=s2a("SD", "DIIS", "NONE", "BISECT", "BROYDEN", "NEWTON", "SECANT", "NEWTON_LS"), &
     499              :                           enum_desc=s2a("Takes steps in the direction of the gradient, multiplied by step_size", &
     500              :                                         "Uses a Direct Inversion in the Iterative Subspace method", &
     501              :                                         "Do nothing, useful only with the none type", &
     502              :                                         "Bisection of the gradient, useful for difficult one dimensional cases", &
     503              :                                         "Broyden's method. Variant defined in BROYDEN_TYPE.", &
     504              :                                         "Newton's method. Only compatible with CDFT constraints.", &
     505              :                                         "Secant method. Only for one dimensional cases. See Broyden for "// &
     506              :                                         "multidimensional cases.", &
     507              :                                         "Newton's method with backtracking line search to find the optimal step size. "// &
     508              :                                         "Only compatible with CDFT constraints. Starts from the regular Newton solution "// &
     509              :                                         "and successively reduces the step size until the L2 norm of the CDFT gradient "// &
     510              :                                         "decreases or MAX_LS steps is reached. Potentially very expensive because "// &
     511              :                                         "each iteration performs a full SCF calculation."), &
     512              :                           enum_i_vals=[outer_scf_optimizer_sd, outer_scf_optimizer_diis, outer_scf_optimizer_none, &
     513              :                                        outer_scf_optimizer_bisect, outer_scf_optimizer_broyden, &
     514              :                                        outer_scf_optimizer_newton, outer_scf_optimizer_secant, &
     515        36672 :                                        outer_scf_optimizer_newton_ls])
     516        36672 :       CALL section_add_keyword(section, keyword)
     517        36672 :       CALL keyword_release(keyword)
     518              : 
     519              :       CALL keyword_create(keyword, __LOCATION__, name="BISECT_TRUST_COUNT", &
     520              :                           description="Maximum number of times the same point will be used in bisection,"// &
     521              :                           " a small number guards against the effect of wrongly converged states.", &
     522        36672 :                           usage="BISECT_TRUST_COUNT 5", default_i_val=10)
     523        36672 :       CALL section_add_keyword(section, keyword)
     524        36672 :       CALL keyword_release(keyword)
     525              : 
     526              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_SCF", &
     527              :                           description="The target gradient of the outer SCF variables. "// &
     528              :                           "Notice that the EPS_SCF of the inner loop also determines "// &
     529              :                           "the value that can be reached in the outer loop, "// &
     530              :                           "typically EPS_SCF of the outer loop must be smaller "// &
     531              :                           "than or equal to EPS_SCF of the inner loop.", &
     532        36672 :                           usage="EPS_SCF 1.0E-6 ", default_r_val=1.0E-5_dp)
     533        36672 :       CALL section_add_keyword(section, keyword)
     534        36672 :       CALL keyword_release(keyword)
     535              : 
     536              :       CALL keyword_create(keyword, __LOCATION__, name="DIIS_BUFFER_LENGTH", &
     537              :                           description="Maximum number of DIIS vectors used ", &
     538        36672 :                           usage="DIIS_BUFFER_LENGTH 5", default_i_val=3)
     539        36672 :       CALL section_add_keyword(section, keyword)
     540        36672 :       CALL keyword_release(keyword)
     541              : 
     542              :       CALL keyword_create(keyword, __LOCATION__, name="EXTRAPOLATION_ORDER", &
     543              :                           description="Number of past states used in the extrapolation of the variables during e.g. MD", &
     544        36672 :                           usage="EXTRAPOLATION_ORDER 5", default_i_val=3)
     545        36672 :       CALL section_add_keyword(section, keyword)
     546        36672 :       CALL keyword_release(keyword)
     547              : 
     548              :       CALL keyword_create(keyword, __LOCATION__, name="MAX_SCF", &
     549              :                           description="Maximum number of outer SCF loops.", &
     550        36672 :                           usage="MAX_SCF 20", default_i_val=50)
     551        36672 :       CALL section_add_keyword(section, keyword)
     552        36672 :       CALL keyword_release(keyword)
     553              : 
     554              :       CALL keyword_create(keyword, __LOCATION__, name="STEP_SIZE", &
     555              :                           description="The initial step_size used in the optimizer (currently steepest descent). "// &
     556              :                           "Note that in cases where a sadle point is sought for (constrained DFT),"// &
     557              :                           " this can be negative. For Newton and Broyden optimizers, use a value less/higher than "// &
     558              :                           "the default 1.0 (in absolute value, the sign is not significant) to active an under/overrelaxed "// &
     559              :                           "optimizer.", &
     560        36672 :                           usage="STEP_SIZE -1.0", default_r_val=0.5_dp)
     561        36672 :       CALL section_add_keyword(section, keyword)
     562        36672 :       CALL keyword_release(keyword)
     563              : 
     564        36672 :    END SUBROUTINE create_outer_scf_section
     565              : 
     566              : ! **************************************************************************************************
     567              : !> \brief makes the orbital transformation section
     568              : !> \param section ...
     569              : !> \param diagonalization ...
     570              : !> \par History
     571              : !>      11.2004 created [Joost VandeVondele]
     572              : ! **************************************************************************************************
     573        51550 :    SUBROUTINE create_ot_section(section, diagonalization)
     574              :       TYPE(section_type), POINTER                        :: section
     575              :       LOGICAL, INTENT(IN), OPTIONAL                      :: diagonalization
     576              : 
     577              :       LOGICAL                                            :: is_diagonalization
     578              :       TYPE(keyword_type), POINTER                        :: keyword
     579              : 
     580        51550 :       CPASSERT(.NOT. ASSOCIATED(section))
     581        51550 :       is_diagonalization = .FALSE.
     582        51550 :       IF (PRESENT(diagonalization)) is_diagonalization = diagonalization
     583        25775 :       IF (is_diagonalization) THEN
     584              :          CALL section_create(section, __LOCATION__, name="OT", &
     585              :                              description="Configures OT as the iterative eigensolver selected by "// &
     586              :                              "SCF%DIAGONALIZATION%ALGORITHM OT. The solver minimizes the trace of the "// &
     587              :                              "requested orbital subspace for a fixed Kohn-Sham matrix. Orbital energies, "// &
     588              :                              "occupations, smearing, density construction, and density mixing are handled "// &
     589              :                              "afterwards by the parent DIAGONALIZATION SCF path.", &
     590              :                              n_keywords=28, n_subsections=0, repeats=.FALSE., &
     591        77325 :                              citations=[VandeVondele2003, Weber2008])
     592              :       ELSE
     593              :          CALL section_create(section, __LOCATION__, name="OT", &
     594              :                              description="Sets the various options for the orbital transformation (OT) method. "// &
     595              :                              "Default settings already provide an efficient, yet robust method. "// &
     596              :                              "Most systems benefit from using the FULL_ALL preconditioner "// &
     597              :                              "combined with a small value (0.001) of ENERGY_GAP. "// &
     598              :                              "Well-behaved systems might benefit from using a DIIS minimizer. "//newline//newline// &
     599              :                              "**Advantages:** "// &
     600              :                              "It's fast, because no expensive diagonalisation is performed. "// &
     601              :                              "If preconditioned correctly, method guaranteed to find minimum. "//newline//newline// &
     602              :                              "**Disadvantages:** "// &
     603              :                              "Sensitive to preconditioning. A good preconditioner can be expensive. "// &
     604              :                              "Metallic systems require a sufficiently large virtual orbital space and "// &
     605              :                              "the coupled ROTATION and ENERGIES variables.", &
     606              :                              n_keywords=28, n_subsections=0, repeats=.FALSE., &
     607        77325 :                              citations=[VandeVondele2003, Weber2008])
     608              :       END IF
     609              : 
     610        51550 :       NULLIFY (keyword)
     611              : 
     612              :       CALL keyword_create(keyword, __LOCATION__, name="_SECTION_PARAMETERS_", &
     613              :                           description="controls the activation of the ot method", &
     614              :                           usage="&OT T", &
     615              :                           default_l_val=.FALSE., &
     616        51550 :                           lone_keyword_l_val=.TRUE.)
     617        51550 :       CALL section_add_keyword(section, keyword)
     618        51550 :       CALL keyword_release(keyword)
     619              : 
     620              :       CALL keyword_create(keyword, __LOCATION__, name="ALGORITHM", &
     621              :                           description="Algorithm to be used for OT", &
     622              :                           usage="ALGORITHM STRICT", &
     623              :                           default_i_val=ot_algo_taylor_or_diag, &
     624              :                           enum_c_vals=s2a("STRICT", "IRAC"), &
     625              :                           enum_desc=s2a("Strict orthogonality: Taylor or diagonalization based algorithm.", &
     626              :                                         "Orbital Transformation based Iterative Refinement "// &
     627              :                                         "of the Approximative Congruence transformation (OT/IR)."), &
     628              :                           enum_i_vals=[ot_algo_taylor_or_diag, ot_algo_irac], &
     629       206200 :                           citations=[VandeVondele2003, VandeVondele2005a, Weber2008])
     630        51550 :       CALL section_add_keyword(section, keyword)
     631        51550 :       CALL keyword_release(keyword)
     632              : 
     633              :       CALL keyword_create(keyword, __LOCATION__, name="IRAC_DEGREE", &
     634              :                           description="The refinement polynomial degree (2, 3 or 4).", &
     635              :                           usage="IRAC_DEGREE 4", &
     636        51550 :                           default_i_val=4)
     637        51550 :       CALL section_add_keyword(section, keyword)
     638        51550 :       CALL keyword_release(keyword)
     639              : 
     640              :       CALL keyword_create(keyword, __LOCATION__, name="MAX_IRAC", &
     641              :                           description="Maximum allowed refinement iteration.", &
     642              :                           usage="MAX_IRAC 5", &
     643        51550 :                           default_i_val=50)
     644        51550 :       CALL section_add_keyword(section, keyword)
     645        51550 :       CALL keyword_release(keyword)
     646              : 
     647              :       CALL keyword_create(keyword, __LOCATION__, name="ORTHO_IRAC", &
     648              :                           description="The orthogonality method.", &
     649              :                           usage="ORTHO_IRAC POLY", &
     650              :                           default_i_val=ot_chol_irac, &
     651              :                           enum_c_vals=s2a("CHOL", "POLY", "LWDN"), &
     652              :                           enum_desc=s2a("Cholesky.", "Polynomial.", "Loewdin."), &
     653        51550 :                           enum_i_vals=[ot_chol_irac, ot_poly_irac, ot_lwdn_irac])
     654        51550 :       CALL section_add_keyword(section, keyword)
     655        51550 :       CALL keyword_release(keyword)
     656              : 
     657              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_IRAC_FILTER_MATRIX", &
     658              :                           description="Sets the threshold for filtering the matrices.", &
     659              :                           usage="EPS_IRAC_FILTER_MATRIX 1.0E-5", &
     660        51550 :                           default_r_val=0.0_dp)
     661        51550 :       CALL section_add_keyword(section, keyword)
     662        51550 :       CALL keyword_release(keyword)
     663              : 
     664              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_IRAC", &
     665              :                           description="Targeted accuracy during the refinement iteration.", &
     666              :                           usage="EPS_IRAC 1.0E-5", &
     667        51550 :                           default_r_val=1.0E-10_dp)
     668        51550 :       CALL section_add_keyword(section, keyword)
     669        51550 :       CALL keyword_release(keyword)
     670              : 
     671              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_IRAC_QUICK_EXIT", &
     672              :                           description="Only one extra refinement iteration is "// &
     673              :                           "done when the norm is below this value.", &
     674              :                           usage="EPS_IRAC_QUICK_EXIT 1.0E-2", &
     675        51550 :                           default_r_val=1.0E-5_dp)
     676        51550 :       CALL section_add_keyword(section, keyword)
     677        51550 :       CALL keyword_release(keyword)
     678              : 
     679              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_IRAC_SWITCH", &
     680              :                           description="The algorithm switches to the polynomial "// &
     681              :                           "refinement when the norm is below this value.", &
     682              :                           usage="EPS_IRAC_SWITCH 1.0E-3", &
     683        51550 :                           default_r_val=1.0E-2_dp)
     684        51550 :       CALL section_add_keyword(section, keyword)
     685        51550 :       CALL keyword_release(keyword)
     686              : 
     687              :       CALL keyword_create(keyword, __LOCATION__, name="ON_THE_FLY_LOC", &
     688              :                           description="On the fly localization of the molecular orbitals. "// &
     689              :                           "Can only be used with OT/IRAC.", &
     690              :                           usage="ON_THE_FLY_LOC T", &
     691        51550 :                           default_l_val=.FALSE.)
     692        51550 :       CALL section_add_keyword(section, keyword)
     693        51550 :       CALL keyword_release(keyword)
     694              : 
     695              :       CALL keyword_create( &
     696              :          keyword, __LOCATION__, name="MINIMIZER", &
     697              :          description="Minimizer to be used with the OT method", &
     698              :          usage="MINIMIZER DIIS", &
     699              :          default_i_val=ot_mini_cg, &
     700              :          enum_c_vals=s2a("SD", "CG", "DIIS", "BROYDEN", "LBFGS"), &
     701              :          enum_desc=s2a("Steepest descent: not recommended", "Conjugate Gradients: most reliable, use for difficult systems."// &
     702              :                        " The total energy should decrease at every OT CG step if the line search is appropriate.", &
     703              :                        "Direct inversion in the iterative subspace: less reliable than CG, but sometimes about 50% faster", &
     704              :                        "Broyden mixing approximating the inverse Hessian", &
     705              :                        "Limited-memory BFGS in the fixed OT product chart. The selected OT preconditioner is used"// &
     706              :                        " as the initial inverse Hessian. The secant history is reset after a tenfold increase in"// &
     707              :                        " the raw fixed-chart gradient norm. With OUTER_SCF, an explicit EPS_DIIS can switch later"// &
     708              :                        " outer iterations to OT/DIIS. Available with ALGORITHM STRICT or IRAC."), &
     709        51550 :          enum_i_vals=[ot_mini_sd, ot_mini_cg, ot_mini_diis, ot_mini_broyden, ot_mini_lbfgs])
     710        51550 :       CALL section_add_keyword(section, keyword)
     711        51550 :       CALL keyword_release(keyword)
     712              : 
     713              :       CALL keyword_create(keyword, __LOCATION__, name="SAFE_DIIS", &
     714              :                           variants=["SAFER_DIIS"], &
     715              :                           description="Reject DIIS steps if they point away from the"// &
     716              :                           " minimum, do SD in that case.", &
     717       103100 :                           usage="SAFE_DIIS ON", default_l_val=.TRUE.)
     718        51550 :       CALL section_add_keyword(section, keyword)
     719        51550 :       CALL keyword_release(keyword)
     720              : 
     721              :       CALL keyword_create(keyword, __LOCATION__, name="MAX_SCF_DIIS", &
     722              :                           description="Maximum DIIS SCF inner loop cycles. This can be used to extend"// &
     723              :                           " SCF cycles after a switch to DIIS (see eps_diis).", &
     724              :                           usage="MAX_SCF_DIIS 20", &
     725        51550 :                           default_i_val=0)
     726        51550 :       CALL section_add_keyword(section, keyword)
     727        51550 :       CALL keyword_release(keyword)
     728              : 
     729              :       CALL keyword_create(keyword, __LOCATION__, name="N_HISTORY_VEC", &
     730              :                           variants=s2a("NDIIS", "N_DIIS", "N_BROYDEN", "N_LBFGS"), &
     731              :                           description="Number of history vectors to be used with DIIS, BROYDEN, or LBFGS", &
     732              :                           usage="N_HISTORY_VEC 7", &
     733        51550 :                           default_i_val=7)
     734        51550 :       CALL section_add_keyword(section, keyword)
     735        51550 :       CALL keyword_release(keyword)
     736              : 
     737              :       CALL keyword_create( &
     738              :          keyword, __LOCATION__, name="LBFGS_CURVATURE_TOL", &
     739              :          description="Minimum dimensionless relative curvature accepted for an LBFGS secant pair."// &
     740              :          " Values are restricted to the interval [0,1).", &
     741              :          usage="LBFGS_CURVATURE_TOL 1.0E-4", &
     742        51550 :          default_r_val=1.0E-4_dp)
     743        51550 :       CALL section_add_keyword(section, keyword)
     744        51550 :       CALL keyword_release(keyword)
     745              : 
     746              :       CALL keyword_create( &
     747              :          keyword, __LOCATION__, name="LBFGS_DAMPING", &
     748              :          description="Regularize weak or negative LBFGS curvature by the smallest shift of the"// &
     749              :          " gradient difference along the step that satisfies LBFGS_CURVATURE_TOL."// &
     750              :          " If disabled, such secant pairs are skipped.", &
     751              :          usage="LBFGS_DAMPING ON", &
     752              :          default_l_val=.TRUE., &
     753        51550 :          lone_keyword_l_val=.TRUE.)
     754        51550 :       CALL section_add_keyword(section, keyword)
     755        51550 :       CALL keyword_release(keyword)
     756              : 
     757              :       CALL keyword_create(keyword, __LOCATION__, name="BROYDEN_BETA", &
     758              :                           description="Underrelaxation for the broyden mixer", &
     759              :                           usage="BROYDEN_BETA 0.9", &
     760        51550 :                           default_r_val=0.9_dp)
     761        51550 :       CALL section_add_keyword(section, keyword)
     762        51550 :       CALL keyword_release(keyword)
     763              : 
     764              :       CALL keyword_create(keyword, __LOCATION__, name="BROYDEN_GAMMA", &
     765              :                           description="Backtracking parameter", &
     766              :                           usage="BROYDEN_GAMMA 0.5", &
     767        51550 :                           default_r_val=0.5_dp)
     768        51550 :       CALL section_add_keyword(section, keyword)
     769        51550 :       CALL keyword_release(keyword)
     770              : 
     771              :       CALL keyword_create(keyword, __LOCATION__, name="BROYDEN_SIGMA", &
     772              :                           description="Curvature of energy functional.", &
     773              :                           usage="BROYDEN_SIGMA 0.25", &
     774        51550 :                           default_r_val=0.25_dp)
     775        51550 :       CALL section_add_keyword(section, keyword)
     776        51550 :       CALL keyword_release(keyword)
     777              : 
     778              :       CALL keyword_create(keyword, __LOCATION__, name="BROYDEN_ETA", &
     779              :                           description="Dampening of estimated energy curvature.", &
     780              :                           usage="BROYDEN_ETA 0.7", &
     781        51550 :                           default_r_val=0.7_dp)
     782        51550 :       CALL section_add_keyword(section, keyword)
     783        51550 :       CALL keyword_release(keyword)
     784              : 
     785              :       CALL keyword_create(keyword, __LOCATION__, name="BROYDEN_OMEGA", &
     786              :                           description="Growth limit of curvature.", &
     787              :                           usage="BROYDEN_OMEGA 1.1", &
     788        51550 :                           default_r_val=1.1_dp)
     789        51550 :       CALL section_add_keyword(section, keyword)
     790        51550 :       CALL keyword_release(keyword)
     791              : 
     792              :       CALL keyword_create(keyword, __LOCATION__, name="BROYDEN_SIGMA_DECREASE", &
     793              :                           description="Reduction of curvature on bad approximation.", &
     794              :                           usage="BROYDEN_SIGMA_DECREASE 0.7", &
     795        51550 :                           default_r_val=0.7_dp)
     796        51550 :       CALL section_add_keyword(section, keyword)
     797        51550 :       CALL keyword_release(keyword)
     798              : 
     799              :       CALL keyword_create(keyword, __LOCATION__, name="BROYDEN_SIGMA_MIN", &
     800              :                           description="Minimum adaptive curvature.", &
     801              :                           usage="BROYDEN_SIGMA_MIN 0.05", &
     802        51550 :                           default_r_val=0.05_dp)
     803        51550 :       CALL section_add_keyword(section, keyword)
     804        51550 :       CALL keyword_release(keyword)
     805              : 
     806              :       CALL keyword_create(keyword, __LOCATION__, name="BROYDEN_FORGET_HISTORY", &
     807              :                           description="Forget history on bad approximation", &
     808              :                           usage="BROYDEN_FORGET_HISTORY OFF", default_l_val=.FALSE., &
     809        51550 :                           lone_keyword_l_val=.TRUE.)
     810        51550 :       CALL section_add_keyword(section, keyword)
     811        51550 :       CALL keyword_release(keyword)
     812              : 
     813              :       CALL keyword_create(keyword, __LOCATION__, name="BROYDEN_ADAPTIVE_SIGMA", &
     814              :                           description="Enable adaptive curvature estimation", &
     815              :                           usage="BROYDEN_ADAPTIVE_SIGMA ON", default_l_val=.TRUE., &
     816        51550 :                           lone_keyword_l_val=.TRUE.)
     817        51550 :       CALL section_add_keyword(section, keyword)
     818        51550 :       CALL keyword_release(keyword)
     819              : 
     820              :       CALL keyword_create(keyword, __LOCATION__, name="BROYDEN_ENABLE_FLIP", &
     821              :                           description="Ensure positive definite update", &
     822              :                           usage="BROYDEN_ENABLE_FLIP ON", default_l_val=.TRUE., &
     823        51550 :                           lone_keyword_l_val=.TRUE.)
     824        51550 :       CALL section_add_keyword(section, keyword)
     825        51550 :       CALL keyword_release(keyword)
     826              : 
     827              :       CALL keyword_create(keyword, __LOCATION__, name="LINESEARCH", &
     828              :                           variants=["LINE_SEARCH"], &
     829              :                           description="1D line search algorithm to be used with the OT minimizer,"// &
     830              :                           " in increasing order of robustness and cost. MINIMIZER CG combined with"// &
     831              :                           " LINESEARCH GOLD should always find an electronic minimum."// &
     832              :                           " Whereas the 2PNT minimizer is almost always OK, 3PNT might be needed for systems"// &
     833              :                           " in which successive OT CG steps do not decrease the total energy.", &
     834              :                           usage="LINESEARCH GOLD", &
     835              :                           default_i_val=ls_2pnt, &
     836              :                           enum_c_vals=s2a("ADAPT", "NONE", "2PNT", "3PNT", "GOLD"), &
     837              :                           enum_desc=s2a("extrapolates usually based on 3 points, "// &
     838              :                                         "uses additional points on demand, very robust.", &
     839              :                                         "always take steps of fixed length", &
     840              :                                         "extrapolate based on 2 points", &
     841              :                                         "extrapolate based on 3 points", &
     842              :                                         "perform 1D golden section search of the minimum (very expensive)"), &
     843       103100 :                           enum_i_vals=[ls_adapt, ls_none, ls_2pnt, ls_3pnt, ls_gold])
     844        51550 :       CALL section_add_keyword(section, keyword)
     845        51550 :       CALL keyword_release(keyword)
     846              : 
     847              :       CALL keyword_create( &
     848              :          keyword, __LOCATION__, name="STEPSIZE", &
     849              :          description="Initial stepsize used for the line search, sometimes this parameter can be reduced to stabilize DIIS"// &
     850              :          " or to improve the CG behavior in the first few steps."// &
     851              :          " The optimal value depends on the quality of the preconditioner."// &
     852              :          " A negative values leaves the choice to CP2K depending on the preconditioner.", &
     853              :          usage="STEPSIZE 0.4", &
     854        51550 :          default_r_val=-1.0_dp)
     855        51550 :       CALL section_add_keyword(section, keyword)
     856        51550 :       CALL keyword_release(keyword)
     857              : 
     858              :       CALL keyword_create(keyword, __LOCATION__, name="GOLD_TARGET", &
     859              :                           description="Target relative uncertainty in the location of the minimum for LINESEARCH GOLD", &
     860              :                           usage="GOLD_TARGET 0.1", &
     861        51550 :                           default_r_val=0.01_dp)
     862        51550 :       CALL section_add_keyword(section, keyword)
     863        51550 :       CALL keyword_release(keyword)
     864              : 
     865              :       CALL keyword_create( &
     866              :          keyword, __LOCATION__, name="PRECONDITIONER", &
     867              :          description="Type of preconditioner to be used with all minimization schemes. "// &
     868              :          "They differ in effectiveness, cost of construction, cost of application. "// &
     869              :          "Properly preconditioned minimization can be orders of magnitude faster than doing nothing.", &
     870              :          usage="PRECONDITIONER FULL_ALL", &
     871              :          default_i_val=ot_precond_full_kinetic, &
     872              :          enum_c_vals=s2a("FULL_ALL", "FERMI_LOW_RANK", "FULL_SINGLE_INVERSE", "FULL_SINGLE", &
     873              :                          "FULL_KINETIC", "FULL_S_INVERSE", "NONE"), &
     874              :          enum_desc=s2a("Most effective state selective preconditioner based on diagonalization, "// &
     875              :                        "requires the ENERGY_GAP parameter to be an underestimate of the HOMO-LUMO gap. "// &
     876              :                        "This preconditioner is recommended for almost all systems, except very large systems where "// &
     877              :                        "make_preconditioner would dominate the total computational cost.", &
     878              :                        "Experimental rotationally covariant bounded spectral preconditioner. It applies an "// &
     879              :                        "overlap-inverse base plus at most 48 complementary-state corrections relative to a "// &
     880              :                        "common occupied reference level. Construction currently retains a full diagonalization. "// &
     881              :                        "Application can be cheaper when the complementary space is larger than the retained rank.", &
     882              :                        "Based on H-eS cholesky inversion, similar to FULL_SINGLE in preconditioning efficiency "// &
     883              :                        "but cheaper to construct, "// &
     884              :                        "might be somewhat less robust. Recommended for large systems.", &
     885              :                        "Based on H-eS diagonalisation, not as good as FULL_ALL, but somewhat cheaper to apply. ", &
     886              :                        "Cholesky inversion of S and T, fast construction, robust, and relatively good, "// &
     887              :                        "use for very large systems.", &
     888              :                        "Cholesky inversion of S, not as good as FULL_KINETIC, yet equally expensive.", &
     889              :                        "skip preconditioning"), &
     890              :          enum_i_vals=[ot_precond_full_all, ot_precond_fermi_low_rank, ot_precond_full_single_inverse, &
     891              :                       ot_precond_full_single, ot_precond_full_kinetic, ot_precond_s_inverse, ot_precond_none], &
     892       206200 :          citations=[VandeVondele2003, Weber2008, Schiffmann2015])
     893        51550 :       CALL section_add_keyword(section, keyword)
     894        51550 :       CALL keyword_release(keyword)
     895              : 
     896              :       CALL keyword_create( &
     897              :          keyword, __LOCATION__, name="FERMI_LOW_RANK_BASE", &
     898              :          description="Base operator used only with PRECONDITIONER FERMI_LOW_RANK. OVERLAP_INVERSE "// &
     899              :          "applies the exact dense inverse overlap. LATTICE_FFT projects the overlap onto translations "// &
     900              :          "of an explicitly replicated SUBSYS multiple unit cell, inverts its small reciprocal-space "// &
     901              :          "blocks, and applies the approximate inverse with lattice FFTs. The experimental FFT path is "// &
     902              :          "restricted to real Gamma-point OT calculations and is never selected automatically.", &
     903              :          usage="FERMI_LOW_RANK_BASE LATTICE_FFT", &
     904              :          default_i_val=ot_low_rank_base_overlap, &
     905              :          enum_c_vals=s2a("OVERLAP_INVERSE", "LATTICE_FFT"), &
     906              :          enum_desc=s2a("Exact dense inverse-overlap base", &
     907              :                        "Approximate block-circulant inverse applied by lattice FFT"), &
     908        51550 :          enum_i_vals=[ot_low_rank_base_overlap, ot_low_rank_base_lattice_fft])
     909        51550 :       CALL section_add_keyword(section, keyword)
     910        51550 :       CALL keyword_release(keyword)
     911              : 
     912              :       CALL keyword_create(keyword, __LOCATION__, name="CHOLESKY", &
     913              :                           description="If FULL_ALL the cholesky decomposition of the S matrix is used. "// &
     914              :                           "Options on the algorithm to be used.", &
     915              :                           usage="CHOLESKY REDUCE", default_i_val=cholesky_reduce, &
     916              :                           enum_c_vals=s2a("OFF", "REDUCE", "RESTORE", "INVERSE", "INVERSE_DBCSR"), &
     917              :                           enum_desc=s2a("The cholesky algorithm is not used", "Reduce is called", &
     918              :                                         "Reduce is replaced by two restore", &
     919              :                                         "Restore uses operator multiply by inverse of the triangular matrix", &
     920              :                                         "Like inverse, but matrix stored as dbcsr, sparce matrix algebra used when possible"), &
     921        51550 :                           enum_i_vals=[cholesky_off, cholesky_reduce, cholesky_restore, cholesky_inverse, cholesky_dbcsr])
     922        51550 :       CALL section_add_keyword(section, keyword)
     923        51550 :       CALL keyword_release(keyword)
     924              : 
     925              :       CALL keyword_create( &
     926              :          keyword, __LOCATION__, name="PRECOND_SOLVER", &
     927              :          description="How the preconditioner is applied to the residual.", &
     928              :          usage="PRECOND_SOLVER DIRECT", &
     929              :          default_i_val=ot_precond_solver_default, &
     930              :          enum_c_vals=s2a("DEFAULT", "DIRECT", "INVERSE_CHOLESKY", "INVERSE_UPDATE", "CHEBYSHEV"), &
     931              :          enum_desc=s2a("the default", "Cholesky decomposition followed by triangular solve "// &
     932              :                        "(works for FULL_KINETIC/SINGLE_INVERSE/S_INVERSE)", &
     933              :                        "Cholesky decomposition followed by explicit inversion "// &
     934              :                        "(works for FULL_KINETIC/SINGLE_INVERSE/S_INVERSE)", &
     935              :                        "Performs a Hotelling update of the inverse if a previous preconditioner is present. "// &
     936              :                        "Mainly useful for GPU accelerated systems (works for FULL_KINETIC/SINGLE_INVERSE/S_INVERSE)", &
     937              :                        "Applies a bounded Chebyshev approximation to the inverse using matrix products only "// &
     938              :                        "(currently requires FULL_KINETIC)."), &
     939              :          enum_i_vals=[ot_precond_solver_default, &
     940              :                       ot_precond_solver_direct, &
     941              :                       ot_precond_solver_inv_chol, &
     942              :                       ot_precond_solver_update, &
     943        51550 :                       ot_precond_solver_chebyshev])
     944        51550 :       CALL section_add_keyword(section, keyword)
     945        51550 :       CALL keyword_release(keyword)
     946              : 
     947              :       CALL keyword_create( &
     948              :          keyword, __LOCATION__, name="CHEBYSHEV_DEGREE", &
     949              :          description="Polynomial degree of the positive Chebyshev semi-iterative inverse used by "// &
     950              :          "PRECOND_SOLVER CHEBYSHEV.", &
     951              :          usage="CHEBYSHEV_DEGREE 8", &
     952        51550 :          default_i_val=8)
     953        51550 :       CALL section_add_keyword(section, keyword)
     954        51550 :       CALL keyword_release(keyword)
     955              : 
     956              :       CALL keyword_create( &
     957              :          keyword, __LOCATION__, name="ENERGY_GAP", &
     958              :          description="Should be an estimate for the energy gap [a.u.] (HOMO-LUMO) and is used in preconditioning, "// &
     959              :          "especially effective with the FULL_ALL preconditioner, in which case it should be an underestimate "// &
     960              :          "of the gap (can be a small number, e.g. 0.002)."// &
     961              :          " FULL_SINGLE_INVERSE takes it as lower bound (values below 0.05 can cause stability issues)."// &
     962              :          " In general, higher values will tame the preconditioner in case of poor initial guesses."// &
     963              :          " A negative value will leave the choice to CP2K depending on type of preconditioner.", &
     964              :          usage="ENERGY_GAP 0.001", &
     965        51550 :          default_r_val=-1.0_dp)
     966        51550 :       CALL section_add_keyword(section, keyword)
     967        51550 :       CALL keyword_release(keyword)
     968              : 
     969              :       CALL keyword_create( &
     970              :          keyword, __LOCATION__, name="EPS_TAYLOR", &
     971              :          variants=["EPSTAYLOR"], &
     972              :          description="Target accuracy of the taylor expansion for the matrix functions, should normally be kept as is.", &
     973              :          usage="EPS_TAYLOR 1.0E-15", &
     974       103100 :          default_r_val=1.0E-16_dp)
     975        51550 :       CALL section_add_keyword(section, keyword)
     976        51550 :       CALL keyword_release(keyword)
     977              : 
     978              :       CALL keyword_create( &
     979              :          keyword, __LOCATION__, name="MAX_TAYLOR", &
     980              :          description="Maximum order of the Taylor expansion before diagonalisation is preferred, for large parallel runs"// &
     981              :          " a slightly higher order could sometimes result in a small speedup.", &
     982              :          usage="MAX_TAYLOR 5", &
     983        51550 :          default_i_val=4)
     984        51550 :       CALL section_add_keyword(section, keyword)
     985        51550 :       CALL keyword_release(keyword)
     986              : 
     987              :       CALL keyword_create(keyword, __LOCATION__, name="ROTATION", &
     988              :                           description="Introduce additional variables so that rotations of the occupied"// &
     989              :                           " subspace are allowed as well, only needed for cases where the energy is not invariant under"// &
     990              :                           " a rotation of the occupied subspace such as non-singlet restricted calculations"// &
     991              :                           " or fractional occupations. This variable is not used by DIAGONALIZATION%OT, "// &
     992              :                           "which canonicalizes the converged eigenspace explicitly.", &
     993              :                           usage="ROTATION", lone_keyword_l_val=.TRUE., &
     994        51550 :                           default_l_val=.FALSE.)
     995        51550 :       CALL section_add_keyword(section, keyword)
     996        51550 :       CALL keyword_release(keyword)
     997              : 
     998              :       CALL keyword_create(keyword, __LOCATION__, name="ENERGIES", &
     999              :                           description="Optimize auxiliary orbital energies for Mermin smearing in direct SCF%OT "// &
    1000              :                           "(requires ROTATION and smearing to be active). DIAGONALIZATION%OT obtains "// &
    1001              :                           "orbital energies by canonicalizing its converged eigenspace instead.", &
    1002              :                           usage="ENERGIES", lone_keyword_l_val=.TRUE., &
    1003        51550 :                           default_l_val=.FALSE.)
    1004        51550 :       CALL section_add_keyword(section, keyword)
    1005        51550 :       CALL keyword_release(keyword)
    1006              : 
    1007              :       CALL keyword_create(keyword, __LOCATION__, name="OCCUPATION_PRECONDITIONER", &
    1008              :                           description="Augment the direct SCF%OT orbital metric with coupled fixed-N "// &
    1009              :                           "occupation response. This augments the independently selected orbital "// &
    1010              :                           "preconditioner. It is not used by DIAGONALIZATION%OT, where occupations are "// &
    1011              :                           "assigned after the eigensolver has converged.", &
    1012              :                           usage="OCCUPATION_PRECONDITIONER", lone_keyword_l_val=.TRUE., &
    1013        51550 :                           default_l_val=.FALSE.)
    1014        51550 :       CALL section_add_keyword(section, keyword)
    1015        51550 :       CALL keyword_release(keyword)
    1016              : 
    1017              :       CALL keyword_create(keyword, __LOCATION__, name="NONDIAG_ENERGY", &
    1018              :                           description="Add a non-diagonal auxiliary-energy penalty in direct SCF%OT. "// &
    1019              :                           "It is not used by DIAGONALIZATION%OT.", &
    1020              :                           usage="NONDIAG_ENERGY", lone_keyword_l_val=.TRUE., &
    1021        51550 :                           default_l_val=.FALSE.)
    1022        51550 :       CALL section_add_keyword(section, keyword)
    1023        51550 :       CALL keyword_release(keyword)
    1024              : 
    1025              :       CALL keyword_create(keyword, __LOCATION__, name="NONDIAG_ENERGY_STRENGTH", &
    1026              :                           description="The prefactor for the non-diagonal energy penalty (FD smearing)", &
    1027        51550 :                           usage="NONDIAG_ENERGY_STRENGTH", default_r_val=1.0_dp)
    1028        51550 :       CALL section_add_keyword(section, keyword)
    1029        51550 :       CALL keyword_release(keyword)
    1030              : 
    1031        51550 :    END SUBROUTINE create_ot_section
    1032              : 
    1033              : ! **************************************************************************************************
    1034              : !> \brief creates the ADIIS section
    1035              : !> \param section ...
    1036              : ! **************************************************************************************************
    1037        25775 :    SUBROUTINE create_adiis_section(section)
    1038              :       TYPE(section_type), POINTER                        :: section
    1039              : 
    1040              :       TYPE(keyword_type), POINTER                        :: keyword
    1041              : 
    1042        25775 :       CPASSERT(.NOT. ASSOCIATED(section))
    1043              :       CALL section_create(section, __LOCATION__, name="ADIIS", &
    1044              :                           description="Parameters for the ADIIS SCF update method.", &
    1045        25775 :                           n_keywords=3, n_subsections=0, repeats=.FALSE.)
    1046              : 
    1047        25775 :       NULLIFY (keyword)
    1048              :       CALL keyword_create(keyword, __LOCATION__, name="MAX_HISTORY", &
    1049              :                           description="Maximum number of paired density/Fock states retained by ADIIS. "// &
    1050              :                           "Histories up to 12 use exact active-face enumeration; larger histories use "// &
    1051              :                           "deterministic pairwise simplex minimization.", &
    1052        25775 :                           usage="MAX_HISTORY 7", default_i_val=16)
    1053        25775 :       CALL section_add_keyword(section, keyword)
    1054        25775 :       CALL keyword_release(keyword)
    1055              : 
    1056              :       CALL keyword_create(keyword, __LOCATION__, name="ODA", &
    1057              :                           description="Enable safeguarded optimal damping of raw Roothaan steps used to initialize "// &
    1058              :                           "or globalize ADIIS. "// &
    1059              :                           "ODA supports STANDARD diagonalization, including k-point calculations. "// &
    1060              :                           "It is disabled with a warning when HF%ACE is active. "// &
    1061              :                           "Smearing remains unsupported for ADIIS and ODA.", &
    1062        25775 :                           usage="ODA T", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
    1063        25775 :       CALL section_add_keyword(section, keyword)
    1064        25775 :       CALL keyword_release(keyword)
    1065              : 
    1066              :       CALL keyword_create(keyword, __LOCATION__, name="VERBOSE", &
    1067              :                           description="Print per-iteration ADIIS and ODA diagnostic metrics.", &
    1068        25775 :                           usage="VERBOSE", lone_keyword_l_val=.TRUE., default_l_val=.FALSE.)
    1069        25775 :       CALL section_add_keyword(section, keyword)
    1070        25775 :       CALL keyword_release(keyword)
    1071              : 
    1072        25775 :    END SUBROUTINE create_adiis_section
    1073              : 
    1074              : ! **************************************************************************************************
    1075              : !> \brief creates the diagonalization section
    1076              : !> \param section ...
    1077              : !> \par History
    1078              : !>      10.2008 created [JGH]
    1079              : ! **************************************************************************************************
    1080        25775 :    SUBROUTINE create_diagonalization_section(section)
    1081              :       TYPE(section_type), POINTER                        :: section
    1082              : 
    1083              :       TYPE(keyword_type), POINTER                        :: keyword
    1084              :       TYPE(section_type), POINTER                        :: subsection
    1085              : 
    1086        25775 :       CPASSERT(.NOT. ASSOCIATED(section))
    1087              :       CALL section_create(section, __LOCATION__, name="DIAGONALIZATION", &
    1088              :                           description="Set up type and parameters for Kohn-Sham matrix diagonalization.", &
    1089        25775 :                           n_keywords=0, n_subsections=1, repeats=.FALSE.)
    1090              : 
    1091        25775 :       NULLIFY (keyword)
    1092              : 
    1093              :       CALL keyword_create(keyword, __LOCATION__, name="_SECTION_PARAMETERS_", &
    1094              :                           description="controls the activation of the diagonalization method", &
    1095              :                           usage="&DIAGONALIZATION T", &
    1096              :                           default_l_val=.FALSE., &
    1097        25775 :                           lone_keyword_l_val=.TRUE.)
    1098        25775 :       CALL section_add_keyword(section, keyword)
    1099        25775 :       CALL keyword_release(keyword)
    1100              : 
    1101              :       CALL keyword_create(keyword, __LOCATION__, name="UPDATE_METHOD", &
    1102              :                           description="Selects the SCF update method used with diagonalization. MIXING uses "// &
    1103              :                           "the existing density-mixing and DIIS workflow; ADIIS uses augmented-DIIS "// &
    1104              :                           "Fock-space interpolation and accepts the diagonalized density directly.", &
    1105              :                           usage="UPDATE_METHOD ADIIS", default_i_val=diag_update_method_mixing, &
    1106              :                           enum_c_vals=s2a("MIXING", "ADIIS"), &
    1107              :                           enum_desc=s2a("Use the existing density-mixing SCF workflow", &
    1108              :                                         "Use augmented-DIIS Fock-space interpolation"), &
    1109              :                           enum_i_vals=[diag_update_method_mixing, diag_update_method_adiis], &
    1110        51550 :                           citations=[Hu2010])
    1111        25775 :       CALL section_add_keyword(section, keyword)
    1112        25775 :       CALL keyword_release(keyword)
    1113              : 
    1114              :       CALL keyword_create(keyword, __LOCATION__, name="ALGORITHM", &
    1115              :                           description="Algorithm to be used for diagonalization", &
    1116              :                           usage="ALGORITHM STANDARD", &
    1117              :                           default_i_val=diag_standard, &
    1118              :                           enum_c_vals=s2a("STANDARD", "OT", "LANCZOS", "DAVIDSON", "FILTER_MATRIX"), &
    1119              :                           enum_desc=s2a("AO-basis Kohn-Sham diagonalization using LAPACK-compatible methods"// &
    1120              :                                         " or a late-SCF Jacobi sweep.", &
    1121              :                                         "Iterative diagonalization using OT method", &
    1122              :                                         "Block Krylov-space approach to self-consistent diagonalisation", &
    1123              :                                         "Preconditioned blocked Davidson", &
    1124              :                                         "Filter matrix diagonalization"), &
    1125              :                           enum_i_vals=[diag_standard, diag_ot, diag_block_krylov, diag_block_davidson, &
    1126        25775 :                                        diag_filter_matrix])
    1127        25775 :       CALL section_add_keyword(section, keyword)
    1128        25775 :       CALL keyword_release(keyword)
    1129              : 
    1130              :       CALL keyword_create(keyword, __LOCATION__, name="JACOBI_THRESHOLD", &
    1131              :                           description="Controls the accuracy of the pseudo-diagonalization method using Jacobi rotations", &
    1132              :                           usage="JACOBI_THRESHOLD 1.0E-6", &
    1133              :                           default_r_val=1.0E-7_dp, &
    1134        51550 :                           citations=[Stewart1982])
    1135        25775 :       CALL section_add_keyword(section, keyword)
    1136        25775 :       CALL keyword_release(keyword)
    1137              : 
    1138              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_JACOBI", &
    1139              :                           description="Below this threshold value for the SCF convergence the pseudo-diagonalization "// &
    1140              :                           "method using Jacobi rotations is activated. This method is much faster than a "// &
    1141              :                           "real diagonalization and it is even speeding up while achieving full convergence. "// &
    1142              :                           "However, it needs a pre-converged wavefunction obtained by at least one real "// &
    1143              :                           "diagonalization which is further optimized while keeping the original eigenvalue "// &
    1144              :                           "spectrum. The MO eigenvalues are NOT updated. The method might be useful to speed "// &
    1145              :                           "up calculations for large systems e.g. using a semi-empirical method.", &
    1146              :                           usage="EPS_JACOBI 1.0E-5", &
    1147              :                           default_r_val=0.0_dp, &
    1148        51550 :                           citations=[Stewart1982])
    1149        25775 :       CALL section_add_keyword(section, keyword)
    1150        25775 :       CALL keyword_release(keyword)
    1151              : 
    1152              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_ADAPT", &
    1153              :                           description="Tolerance of the iterative diagonalization relative to the current SCF convergence. "// &
    1154              :                           "A positive value makes the inner tolerance the looser of EPS_ITER and this factor "// &
    1155              :                           "times the SCF error: loose while the density is far from self-consistency, "// &
    1156              :                           "tightening as the SCF converges. The value 0 disables the tracking.", &
    1157              :                           usage="EPS_ADAPT 0.01", &
    1158        25775 :                           default_r_val=0._dp)
    1159        25775 :       CALL section_add_keyword(section, keyword)
    1160        25775 :       CALL keyword_release(keyword)
    1161              : 
    1162              :       CALL keyword_create(keyword, __LOCATION__, name="MAX_ITER", &
    1163              :                           description="Maximum number of iterations in iterative diagonalization", &
    1164              :                           usage="MAX_ITER 20", &
    1165        25775 :                           default_i_val=2)
    1166        25775 :       CALL section_add_keyword(section, keyword)
    1167        25775 :       CALL keyword_release(keyword)
    1168              : 
    1169              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_ITER", &
    1170              :                           description="Required accuracy in iterative diagonalization", &
    1171              :                           usage="EPS_ITER 1.e-8", &
    1172        25775 :                           default_r_val=1.e-8_dp)
    1173        25775 :       CALL section_add_keyword(section, keyword)
    1174        25775 :       CALL keyword_release(keyword)
    1175              : 
    1176        25775 :       NULLIFY (subsection)
    1177        25775 :       CALL create_ot_section(subsection, diagonalization=.TRUE.)
    1178        25775 :       CALL section_add_subsection(section, subsection)
    1179        25775 :       CALL section_release(subsection)
    1180              : 
    1181        25775 :       NULLIFY (subsection)
    1182        25775 :       CALL create_krylov_section(subsection)
    1183        25775 :       CALL section_add_subsection(section, subsection)
    1184        25775 :       CALL section_release(subsection)
    1185              : 
    1186        25775 :       NULLIFY (subsection)
    1187        25775 :       CALL create_diag_subspace_section(subsection)
    1188        25775 :       CALL section_add_subsection(section, subsection)
    1189        25775 :       CALL section_release(subsection)
    1190              : 
    1191        25775 :       NULLIFY (subsection)
    1192        25775 :       CALL create_davidson_section(subsection)
    1193        25775 :       CALL section_add_subsection(section, subsection)
    1194        25775 :       CALL section_release(subsection)
    1195              : 
    1196        25775 :       NULLIFY (subsection)
    1197        25775 :       CALL create_filtermatrix_section(subsection)
    1198        25775 :       CALL section_add_subsection(section, subsection)
    1199        25775 :       CALL section_release(subsection)
    1200              : 
    1201        25775 :    END SUBROUTINE create_diagonalization_section
    1202              : 
    1203              : ! **************************************************************************************************
    1204              : !> \brief ...
    1205              : !> \param section ...
    1206              : ! **************************************************************************************************
    1207        25775 :    SUBROUTINE create_davidson_section(section)
    1208              :       TYPE(section_type), POINTER                        :: section
    1209              : 
    1210              :       TYPE(keyword_type), POINTER                        :: keyword
    1211              : 
    1212        25775 :       CPASSERT(.NOT. ASSOCIATED(section))
    1213              :       CALL section_create(section, __LOCATION__, name="DAVIDSON", &
    1214              :                           description="Settings of the blocked Davidson iterative diagonalization. "// &
    1215              :                           "Also available at symmetry-reduced complex k points.", &
    1216              :                           n_keywords=2, n_subsections=0, repeats=.FALSE., &
    1217        77325 :                           citations=[Blaha2010, KresseFurthmueller1996])
    1218              : 
    1219        25775 :       NULLIFY (keyword)
    1220              : 
    1221              :       CALL keyword_create( &
    1222              :          keyword, __LOCATION__, name="PRECONDITIONER", &
    1223              :          description="Type of preconditioner to be used with all minimization schemes. "// &
    1224              :          "With k points, all preconditioners except NONE use the complex "// &
    1225              :          "k-point preconditioners.", &
    1226              :          usage="PRECONDITIONER FULL_ALL", &
    1227              :          default_i_val=ot_precond_full_all, &
    1228              :          enum_c_vals=s2a("FULL_ALL", "FULL_SINGLE_INVERSE", "FULL_KINETIC", "FULL_S_INVERSE", "NONE"), &
    1229              :          enum_desc=s2a("Most effective state selective preconditioner based on diagonalization ", &
    1230              :                        "Based on H-eS cholesky inversion, similar to FULL_SINGLE in preconditioning efficiency "// &
    1231              :                        "but cheaper to construct, might be somewhat less robust. Recommended for large systems.", &
    1232              :                        "Preconditioner based on the kinetic energy matrix", &
    1233              :                        "Preconditioner based on the overlap matrix", &
    1234              :                        "skip preconditioning"), &
    1235              :          enum_i_vals=[ot_precond_full_all, ot_precond_full_single_inverse, ot_precond_full_kinetic, &
    1236              :                       ot_precond_s_inverse, ot_precond_none], &
    1237        51550 :          citations=[VandeVondele2003])
    1238        25775 :       CALL section_add_keyword(section, keyword)
    1239        25775 :       CALL keyword_release(keyword)
    1240              : 
    1241              :       CALL keyword_create(keyword, __LOCATION__, name="PRECOND_SOLVER", &
    1242              :                           description="How the preconditioner is applied to the residual.", &
    1243              :                           usage="PRECOND_SOLVER DIRECT", &
    1244              :                           default_i_val=ot_precond_solver_default, &
    1245              :                           enum_c_vals=s2a("DEFAULT", "DIRECT", "INVERSE_CHOLESKY"), &
    1246              :                           enum_desc=s2a("the default", "Cholesky decomposition followed by triangular solve "// &
    1247              :                                         "(works for FULL_KINETIC/SINGLE_INVERSE/S_INVERSE)", &
    1248              :                                         "Cholesky decomposition followed by explicit inversion "// &
    1249              :                                         "(works for FULL_KINETIC/SINGLE_INVERSE/S_INVERSE)"), &
    1250              :                           enum_i_vals=[ot_precond_solver_default, &
    1251              :                                        ot_precond_solver_direct, &
    1252        25775 :                                        ot_precond_solver_inv_chol])
    1253        25775 :       CALL section_add_keyword(section, keyword)
    1254        25775 :       CALL keyword_release(keyword)
    1255              : 
    1256              :       CALL keyword_create( &
    1257              :          keyword, __LOCATION__, name="ENERGY_GAP", &
    1258              :          description="Should be an estimate for the energy gap [a.u.] (HOMO-LUMO) and is used in preconditioning, "// &
    1259              :          "especially effective with the FULL_ALL preconditioner, in which case it should be an underestimate "// &
    1260              :          "of the gap (0.001 doing normally fine). For the other preconditioners, making this value larger (0.2)"// &
    1261              :          " will tame the preconditioner in case of poor initial guesses.", &
    1262              :          usage="ENERGY_GAP 0.001", &
    1263        25775 :          default_r_val=0.2_dp)
    1264        25775 :       CALL section_add_keyword(section, keyword)
    1265        25775 :       CALL keyword_release(keyword)
    1266              : 
    1267              :       CALL keyword_create(keyword, __LOCATION__, name="NEW_PREC_EACH", &
    1268              :                           description="Number of SCF iterations after which a new Preconditioner is computed", &
    1269        25775 :                           usage="NEW_PREC_EACH 10", default_i_val=20)
    1270        25775 :       CALL section_add_keyword(section, keyword)
    1271        25775 :       CALL keyword_release(keyword)
    1272              : 
    1273              :       CALL keyword_create(keyword, __LOCATION__, name="FIRST_PREC", &
    1274              :                           description="First SCF iteration at which a Preconditioner is employed. "// &
    1275              :                           "With k points the first build waits until after the cold start, whatever lower value is set. "// &
    1276              :                           "The preconditioner makers read the MO coefficients, and only the cold start fills them.", &
    1277        25775 :                           usage="FIRST_PREC 1", default_i_val=1)
    1278        25775 :       CALL section_add_keyword(section, keyword)
    1279        25775 :       CALL keyword_release(keyword)
    1280              : 
    1281              :       CALL keyword_create(keyword, __LOCATION__, name="CONV_MOS_PERCENT", &
    1282              :                           description="Minimal percent of MOS that have to converge within the Davidson loop"// &
    1283              :                           " before the SCF iteration is completed and a new Hamiltonian is computed", &
    1284        25775 :                           usage="CONV_MOS_PERCENT 0.8", default_r_val=0.5_dp)
    1285        25775 :       CALL section_add_keyword(section, keyword)
    1286        25775 :       CALL keyword_release(keyword)
    1287              : 
    1288              :       CALL keyword_create(keyword, __LOCATION__, name="NOISE_SCALE", &
    1289              :                           description="Divisor that maps the SCF mixing error onto the adaptive Davidson tolerance. "// &
    1290              :                           "The inner tolerance tracks EPS_ADAPT times the mixing error divided by this value. "// &
    1291              :                           "The value approximates how much the per-column residuals amplify the density mixing error. "// &
    1292              :                           "A measured amplification on a smeared slab is 20. Increase the value for looser tracking. "// &
    1293              :                           "Only used with EPS_ADAPT.", &
    1294        25775 :                           usage="NOISE_SCALE 100", default_r_val=100.0_dp)
    1295        25775 :       CALL section_add_keyword(section, keyword)
    1296        25775 :       CALL keyword_release(keyword)
    1297              : 
    1298              :       CALL keyword_create(keyword, __LOCATION__, name="SPARSE_MOS", &
    1299              :                        description="Use MOS as sparse matrix and avoid as much as possible multiplications with full matrices. "// &
    1300              :                           "Not used with k points.", &
    1301              :                           usage="SPARSE_MOS", default_l_val=.TRUE., &
    1302        25775 :                           lone_keyword_l_val=.TRUE.)
    1303        25775 :       CALL section_add_keyword(section, keyword)
    1304        25775 :       CALL keyword_release(keyword)
    1305              : 
    1306        25775 :    END SUBROUTINE create_davidson_section
    1307              : 
    1308              : ! **************************************************************************************************
    1309              : !> \brief ...
    1310              : !> \param section ...
    1311              : ! **************************************************************************************************
    1312        25775 :    SUBROUTINE create_krylov_section(section)
    1313              :       TYPE(section_type), POINTER                        :: section
    1314              : 
    1315              :       TYPE(keyword_type), POINTER                        :: keyword
    1316              : 
    1317        25775 :       CPASSERT(.NOT. ASSOCIATED(section))
    1318              :       CALL section_create(section, __LOCATION__, name="KRYLOV", &
    1319              :                           description=" ", &
    1320        25775 :                           n_keywords=2, n_subsections=0, repeats=.FALSE.)
    1321              : 
    1322        25775 :       NULLIFY (keyword)
    1323              : 
    1324              :       CALL keyword_create(keyword, __LOCATION__, name="NKRYLOV", &
    1325              :                           description="Dimension of the Krylov space used for the Lanczos refinement", &
    1326              :                           usage="NKRYLOV 20", &
    1327        25775 :                           default_i_val=4)
    1328        25775 :       CALL section_add_keyword(section, keyword)
    1329        25775 :       CALL keyword_release(keyword)
    1330              : 
    1331              :       CALL keyword_create(keyword, __LOCATION__, name="NBLOCK", &
    1332              :                           description="Size of the block of vectors refined simultaneously by the Lanczos procedure", &
    1333              :                           usage="NBLOCK 1", &
    1334        25775 :                           default_i_val=32)
    1335        25775 :       CALL section_add_keyword(section, keyword)
    1336        25775 :       CALL keyword_release(keyword)
    1337              : 
    1338              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_KRYLOV", &
    1339              :                           description="Convergence criterion for the MOs", &
    1340              :                           usage="EPS_KRYLOV 0.00001", &
    1341        25775 :                           default_r_val=0.0000001_dp)
    1342        25775 :       CALL section_add_keyword(section, keyword)
    1343        25775 :       CALL keyword_release(keyword)
    1344              : 
    1345              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_STD_DIAG", &
    1346              :                           description="Level of convergence to be reached before starting the Lanczos procedure."// &
    1347              :                           " Above this threshold a standard diagonalization method is used."// &
    1348              :                           " If negative Lanczos is started at the first iteration", &
    1349              :                           usage="EPS_STD_DIAG 0.001", &
    1350        25775 :                           default_r_val=-1.0_dp)
    1351        25775 :       CALL section_add_keyword(section, keyword)
    1352        25775 :       CALL keyword_release(keyword)
    1353              : 
    1354              :       CALL keyword_create(keyword, __LOCATION__, name="CHECK_MOS_CONV", &
    1355              :                           description="This requires to check the convergence of MOS also when standard "// &
    1356              :                           "diagonalization steps are performed, if the block krylov approach is active.", &
    1357              :                           usage="CHECK_MOS_CONV T", &
    1358              :                           default_l_val=.FALSE., &
    1359        25775 :                           lone_keyword_l_val=.TRUE.)
    1360        25775 :       CALL section_add_keyword(section, keyword)
    1361        25775 :       CALL keyword_release(keyword)
    1362              : 
    1363        25775 :    END SUBROUTINE create_krylov_section
    1364              : 
    1365              : ! **************************************************************************************************
    1366              : !> \brief ...
    1367              : !> \param section ...
    1368              : ! **************************************************************************************************
    1369        25775 :    SUBROUTINE create_diag_subspace_section(section)
    1370              :       TYPE(section_type), POINTER                        :: section
    1371              : 
    1372              :       TYPE(keyword_type), POINTER                        :: keyword
    1373              :       TYPE(section_type), POINTER                        :: subsection
    1374              : 
    1375        25775 :       CPASSERT(.NOT. ASSOCIATED(section))
    1376              :       CALL section_create(section, __LOCATION__, name="DIAG_SUB_SCF", &
    1377              :                           description="Activation of self-consistenf subspace refinement by diagonalization "// &
    1378              :                           "of H by adjusting the occupation but keeping the MOS unchanged.", &
    1379        25775 :                           n_keywords=2, n_subsections=1, repeats=.FALSE.)
    1380              : 
    1381        25775 :       NULLIFY (keyword, subsection)
    1382              : 
    1383              :       CALL keyword_create(keyword, __LOCATION__, name="_SECTION_PARAMETERS_", &
    1384              :                           description="controls the activation of inner SCF loop to refine occupations in MOS subspace", &
    1385              :                           usage="&DIAG_SUB_SCF T", &
    1386              :                           default_l_val=.FALSE., &
    1387        25775 :                           lone_keyword_l_val=.TRUE.)
    1388        25775 :       CALL section_add_keyword(section, keyword)
    1389        25775 :       CALL keyword_release(keyword)
    1390              : 
    1391              :       CALL keyword_create(keyword, __LOCATION__, name="MAX_ITER", &
    1392              :                           description="Maximum number of iterations for the SCF inner loop", &
    1393              :                           usage="MAX_ITER 20", &
    1394        25775 :                           default_i_val=2)
    1395        25775 :       CALL section_add_keyword(section, keyword)
    1396        25775 :       CALL keyword_release(keyword)
    1397              : 
    1398              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_ENE", &
    1399              :                           description="Required energy accuracy for convergence of subspace diagonalization", &
    1400              :                           usage="EPS_ENE 1.e-8", &
    1401        25775 :                           default_r_val=1.e-4_dp)
    1402        25775 :       CALL section_add_keyword(section, keyword)
    1403        25775 :       CALL keyword_release(keyword)
    1404              : 
    1405              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_ADAPT_SCF", &
    1406              :                           description="Required density matrix accuracy as compared to current SCF convergence", &
    1407              :                           usage="EPS_ADAPT_SCF 1.e-1", &
    1408        25775 :                           default_r_val=1._dp)
    1409        25775 :       CALL section_add_keyword(section, keyword)
    1410        25775 :       CALL keyword_release(keyword)
    1411              : 
    1412              :       CALL keyword_create( &
    1413              :          keyword, __LOCATION__, name="EPS_SKIP_SUB_DIAG", &
    1414              :          description="Level of convergence to be reached before starting the internal loop of subspace rotations."// &
    1415              :          " Above this threshold only the outer diagonalization method is used."// &
    1416              :          " If negative the subspace rotation is started at the first iteration", &
    1417              :          usage="EPS_SKIP_SUB_DIAG 0.001", &
    1418        25775 :          default_r_val=-1.0_dp)
    1419        25775 :       CALL section_add_keyword(section, keyword)
    1420        25775 :       CALL keyword_release(keyword)
    1421              : 
    1422        25775 :       CALL create_mixing_section(subsection)
    1423        25775 :       CALL section_add_subsection(section, subsection)
    1424        25775 :       CALL section_release(subsection)
    1425        25775 :    END SUBROUTINE create_diag_subspace_section
    1426              : 
    1427              : ! **************************************************************************************************
    1428              : !> \brief      Create CP2K input section for the smearing of occupation numbers
    1429              : !> \param section ...
    1430              : !> \date       27.08.2008
    1431              : !> \author     Matthias Krack (MK)
    1432              : !> \version    1.0
    1433              : ! **************************************************************************************************
    1434        25775 :    SUBROUTINE create_smear_section(section)
    1435              : 
    1436              :       TYPE(section_type), POINTER                        :: section
    1437              : 
    1438              :       TYPE(keyword_type), POINTER                        :: keyword
    1439              : 
    1440        25775 :       CPASSERT(.NOT. ASSOCIATED(section))
    1441              : 
    1442              :       CALL section_create(section, __LOCATION__, &
    1443              :                           name="SMEAR", &
    1444              :                           description="Controls smearing of MO occupation numbers for systems with small or zero gaps.", &
    1445              :                           n_keywords=6, &
    1446              :                           n_subsections=0, &
    1447        25775 :                           repeats=.FALSE.)
    1448              : 
    1449        25775 :       NULLIFY (keyword)
    1450              : 
    1451              :       CALL keyword_create(keyword, __LOCATION__, &
    1452              :                           name="_SECTION_PARAMETERS_", &
    1453              :                           description="Controls the activation of smearing", &
    1454              :                           usage="&SMEAR ON", &
    1455              :                           default_l_val=.FALSE., &
    1456        25775 :                           lone_keyword_l_val=.TRUE.)
    1457        25775 :       CALL section_add_keyword(section, keyword)
    1458        25775 :       CALL keyword_release(keyword)
    1459              : 
    1460              :       CALL keyword_create(keyword, __LOCATION__, &
    1461              :                           name="METHOD", &
    1462              :                           description="Selects the smearing method to apply.", &
    1463              :                           usage="METHOD Fermi_Dirac", &
    1464              :                           default_i_val=smear_gaussian, &
    1465              :                           enum_c_vals=s2a("FERMI_DIRAC", "ENERGY_WINDOW", "LIST", "GAUSSIAN", &
    1466              :                                           "METHFESSEL_PAXTON", "MARZARI_VANDERBILT"), &
    1467              :                           enum_i_vals=[smear_fermi_dirac, smear_energy_window, smear_list, &
    1468              :                                        smear_gaussian, smear_mp, smear_mv], &
    1469              :                           enum_desc=s2a("Fermi-Dirac distribution defined by the keyword ELECTRONIC_TEMPERATURE. "// &
    1470              :                                         "Use this method if the temperature equivalence is important for you, "// &
    1471              :                                         "e.g. if you want to compute some properties based on the occupations. "// &
    1472              :                                         "If you use this method without interest in electronic temperature, "// &
    1473              :                                         "it's suggested to use extrapolated result from finite ELECTRONIC_TEMPERATURE "// &
    1474              :                                         "to ELECTRONIC_TEMPERATURE = 0. Note the forces and stress are consistent "// &
    1475              :                                         "with the free energy and not with the extrapolated energy.", &
    1476              :                                         "Energy window defined by the keyword WINDOW_SIZE.", &
    1477              :                                         "Use a fixed list of occupations.", &
    1478              :                                         "Gaussian broadening with width SIGMA; should work well in most cases. "// &
    1479              :                                         "With this method you have to use extrapolated results from finite "// &
    1480              :                                         "SIGMA results to SIGMA = 0, but usually this value would not be quite "// &
    1481              :                                         "accurate without systematically reducing SIGMA. Note the forces and stress "// &
    1482              :                                         "are consistent with the free energy and not with the extrapolated energy.", &
    1483              :                                         "First-order Methfessel-Paxton distribution with width SIGMA. Don't "// &
    1484              :                                         "use it for semiconductors and insulators because the partial "// &
    1485              :                                         "occupancies can be unphysical and thus lead to wrong results.", &
    1486        25775 :                                         "Marzari-Vanderbilt cold smearing with width SIGMA."))
    1487        25775 :       CALL section_add_keyword(section, keyword)
    1488        25775 :       CALL keyword_release(keyword)
    1489              : 
    1490              :       CALL keyword_create(keyword, __LOCATION__, &
    1491              :                           name="LIST", &
    1492              :                           description="A list of fractional occupations to use. Must match the number of states "// &
    1493              :                           "and sum up to the correct number of electrons", &
    1494              :                           repeats=.FALSE., &
    1495              :                           n_var=-1, &
    1496              :                           type_of_var=real_t, &
    1497        25775 :                           usage="LIST 2.0 0.6666 0.6666 0.66666 0.0 0.0")
    1498        25775 :       CALL section_add_keyword(section, keyword)
    1499        25775 :       CALL keyword_release(keyword)
    1500              : 
    1501              :       CALL keyword_create(keyword, __LOCATION__, &
    1502              :                           name="ELECTRONIC_TEMPERATURE", &
    1503              :                           variants=s2a("ELEC_TEMP", "TELEC"), &
    1504              :                           description="Electronic temperature used for Fermi-Dirac smearing.", &
    1505              :                           repeats=.FALSE., &
    1506              :                           n_var=1, &
    1507              :                           type_of_var=real_t, &
    1508              :                           default_r_val=cp_unit_to_cp2k(value=300.0_dp, unit_str="K"), &
    1509              :                           unit_str="K", &
    1510        25775 :                           usage="ELECTRONIC_TEMPERATURE [K] 300")
    1511        25775 :       CALL section_add_keyword(section, keyword)
    1512        25775 :       CALL keyword_release(keyword)
    1513              : 
    1514              :       CALL keyword_create(keyword, __LOCATION__, &
    1515              :                           name="EPS_FERMI_DIRAC", &
    1516              :                           description="Accuracy checks on occupation numbers use this as a tolerance", &
    1517              :                           repeats=.FALSE., &
    1518              :                           n_var=1, &
    1519              :                           type_of_var=real_t, &
    1520              :                           default_r_val=1.0E-10_dp, &
    1521        25775 :                           usage="EPS_FERMI_DIRAC 1.0E-6")
    1522        25775 :       CALL section_add_keyword(section, keyword)
    1523        25775 :       CALL keyword_release(keyword)
    1524              : 
    1525              :       CALL keyword_create(keyword, __LOCATION__, &
    1526              :                           name="SIGMA", &
    1527              :                           description="Smearing width sigma (in energy units) in the case of "// &
    1528              :                           "Gaussian, Methfessel-Paxton or Marzari-Vanderbilt smearing.", &
    1529              :                           repeats=.FALSE., &
    1530              :                           n_var=1, &
    1531              :                           type_of_var=real_t, &
    1532              :                           default_r_val=0.002_dp, &
    1533              :                           unit_str="au_e", &
    1534        25775 :                           usage="SIGMA [eV] 0.2")
    1535        25775 :       CALL section_add_keyword(section, keyword)
    1536        25775 :       CALL keyword_release(keyword)
    1537              : 
    1538              :       CALL keyword_create(keyword, __LOCATION__, &
    1539              :                           name="WINDOW_SIZE", &
    1540              :                           description="Size of the energy window centred at the Fermi level", &
    1541              :                           repeats=.FALSE., &
    1542              :                           n_var=1, &
    1543              :                           type_of_var=real_t, &
    1544              :                           default_r_val=0.0_dp, &
    1545              :                           unit_str="au_e", &
    1546        25775 :                           usage="WINDOW_SIZE [eV] 0.3")
    1547        25775 :       CALL section_add_keyword(section, keyword)
    1548        25775 :       CALL keyword_release(keyword)
    1549              : 
    1550              :       CALL keyword_create(keyword, __LOCATION__, name="FIXED_MAGNETIC_MOMENT", &
    1551              :                           description="Imposed difference between the numbers of electrons of spin up "// &
    1552              :                           "and spin down: m = n(up) - n(down). A negative value (default) allows "// &
    1553              :                           "for a change of the magnetic moment. -1 specifically keeps an integer "// &
    1554              :                           "number of spin up and spin down electrons.", &
    1555              :                           repeats=.FALSE., &
    1556              :                           n_var=1, &
    1557              :                           type_of_var=real_t, &
    1558              :                           default_r_val=-100.0_dp, &
    1559        25775 :                           usage="FIXED_MAGNETIC_MOMENT 1.5")
    1560        25775 :       CALL section_add_keyword(section, keyword)
    1561        25775 :       CALL keyword_release(keyword)
    1562              : 
    1563        25775 :    END SUBROUTINE create_smear_section
    1564              : 
    1565              : ! **************************************************************************************************
    1566              : !> \brief Creates the input section for defining CDFT constraints.
    1567              : !> \param section the section to create
    1568              : ! **************************************************************************************************
    1569        10897 :    SUBROUTINE create_cdft_control_section(section)
    1570              :       TYPE(section_type), POINTER                        :: section
    1571              : 
    1572              :       TYPE(keyword_type), POINTER                        :: keyword
    1573              :       TYPE(section_type), POINTER                        :: group_section, print_key, subsection
    1574              : 
    1575        10897 :       NULLIFY (keyword, subsection, group_section, print_key)
    1576              : 
    1577        10897 :       CPASSERT(.NOT. ASSOCIATED(section))
    1578              :       CALL section_create(section, __LOCATION__, name="CDFT", &
    1579              :                           description="Parameters needed to set up a constrained DFT calculation."// &
    1580              :                           " Each repetition of the ATOM_GROUP section defines a new constraint."// &
    1581              :                           " The constraint(s) is (are) converged in a separate external SCF loop with settings"// &
    1582              :                           " read from the OUTER_SCF section. Supported constraints: Becke and Gaussian"// &
    1583              :                           " Hirshfeld (partial).", n_keywords=8, n_subsections=2, &
    1584        32691 :                           repeats=.FALSE., citations=[Holmberg2017, Holmberg2018])
    1585              : 
    1586        10897 :       NULLIFY (subsection, keyword)
    1587        10897 :       CALL create_outer_scf_section(subsection)
    1588        10897 :       CALL section_add_subsection(section, subsection)
    1589        10897 :       CALL section_release(subsection)
    1590              : 
    1591        10897 :       CALL create_becke_constraint_section(subsection)
    1592        10897 :       CALL section_add_subsection(section, subsection)
    1593        10897 :       CALL section_release(subsection)
    1594              : 
    1595        10897 :       CALL create_hirshfeld_constraint_section(subsection)
    1596        10897 :       CALL section_add_subsection(section, subsection)
    1597        10897 :       CALL section_release(subsection)
    1598              : 
    1599              :       CALL keyword_create(keyword, __LOCATION__, name="TYPE_OF_CONSTRAINT", &
    1600              :                           description="Specifies the type of constraint used.", &
    1601              :                           usage="TYPE_OF_CONSTRAINT (NONE|HIRSHFELD|BECKE)", &
    1602              :                           enum_c_vals=s2a("NONE", "HIRSHFELD", "BECKE"), &
    1603              :                           enum_i_vals=[outer_scf_none, outer_scf_hirshfeld_constraint, &
    1604              :                                        outer_scf_becke_constraint], &
    1605              :                           enum_desc=s2a("No constraint (disables section).", &
    1606              :                                         "Gaussian Hirshfeld constraint. Partial implementation: no forces. "// &
    1607              :                                         "Requires corresponding section. Not as extensively tested.", &
    1608              :                                         "Becke constraint. Requires corresponding section."), &
    1609              :                           citations=[Becke1988b], &
    1610        21794 :                           default_i_val=outer_scf_none)
    1611        10897 :       CALL section_add_keyword(section, keyword)
    1612        10897 :       CALL keyword_release(keyword)
    1613              : 
    1614              :       CALL keyword_create(keyword, __LOCATION__, name="STRENGTH", &
    1615              :                           description="Constraint force constants (Lagrange multipliers). "// &
    1616              :                           "Give one value per constraint group.", &
    1617              :                           type_of_var=real_t, n_var=-1, &
    1618        10897 :                           default_r_val=0.0_dp)
    1619        10897 :       CALL section_add_keyword(section, keyword)
    1620        10897 :       CALL keyword_release(keyword)
    1621              : 
    1622              :       CALL keyword_create(keyword, __LOCATION__, name="TARGET", &
    1623              :                           description="Constraint target values. Give one value per constraint group. "// &
    1624              :                           "The target value is the desired number of valence electrons, spin moment, or the number of "// &
    1625              :                           "alpha or beta electrons on the atoms that define the constraint, suitably multiplied by "// &
    1626              :                           "atomic coefficients in case a relative constraint between two sets of atoms is employed. "// &
    1627              :                           "Note that core charges are not subtracted from the target value.", &
    1628              :                           usage="TARGET {real}", repeats=.FALSE., &
    1629              :                           type_of_var=real_t, n_var=-1, &
    1630        10897 :                           default_r_val=0.0_dp)
    1631        10897 :       CALL section_add_keyword(section, keyword)
    1632        10897 :       CALL keyword_release(keyword)
    1633              : 
    1634              :       CALL keyword_create(keyword, __LOCATION__, name="ATOMIC_CHARGES", &
    1635              :                           description="Calculate atomic CDFT charges with selected weight function"// &
    1636              :                           " (Z = Z_core - Z_CDFT). With fragment based constraints, charges are"// &
    1637              :                           " relative to the fragment reference state i.e. Z = Z_CDFT -"// &
    1638              :                           " Z_frag_reference. Note: if the number of atoms is greater than the"// &
    1639              :                           " default pw_pool max cache, calculation of atomic CDFT charges"// &
    1640              :                           " will prompt harmless warnings during deallocation of atomic grids.", &
    1641              :                           usage="ATOMIC_CHARGES", &
    1642        10897 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
    1643        10897 :       CALL section_add_keyword(section, keyword)
    1644        10897 :       CALL keyword_release(keyword)
    1645              : 
    1646              :       CALL keyword_create(keyword, __LOCATION__, name="FRAGMENT_A_FILE_NAME", variants=["FRAGMENT_A_FILE"], &
    1647              :                           description="Name of the reference total electron density cube file for fragment A."// &
    1648              :                           " May include a path. The reference electron density needs to be outputted"// &
    1649              :                           " on the same grid as the full system (same cutoff and cell, output stride 1)."// &
    1650              :                           " For GAPW, generate the cube with E_DENSITY_CUBE% DENSITY_INCLUDE TOTAL_DENSITY;"// &
    1651              :                           " a regular GAPW electron-density cube contains only the soft density and is rejected.", &
    1652              :                           usage="FRAGMENT_A_FILE_NAME <FILENAME>", &
    1653        21794 :                           default_lc_val="fragment_a.cube")
    1654        10897 :       CALL section_add_keyword(section, keyword)
    1655        10897 :       CALL keyword_release(keyword)
    1656              : 
    1657              :       CALL keyword_create(keyword, __LOCATION__, name="FRAGMENT_B_FILE_NAME", variants=["FRAGMENT_B_FILE"], &
    1658              :                           description="Name of the reference total electron density cube file for fragment B."// &
    1659              :                           " May include a path. The reference electron density needs to be outputted"// &
    1660              :                           " on the same grid as the full system (same cutoff and cell, output stride 1)."// &
    1661              :                           " For GAPW, generate the cube with E_DENSITY_CUBE% DENSITY_INCLUDE TOTAL_DENSITY;"// &
    1662              :                           " a regular GAPW electron-density cube contains only the soft density and is rejected.", &
    1663              :                           usage="FRAGMENT_B_FILE_NAME <FILENAME>", &
    1664        21794 :                           default_lc_val="fragment_b.cube")
    1665        10897 :       CALL section_add_keyword(section, keyword)
    1666        10897 :       CALL keyword_release(keyword)
    1667              : 
    1668              :       CALL keyword_create(keyword, __LOCATION__, name="FRAGMENT_A_SPIN_FILE", &
    1669              :                           variants=["FRAGMENT_A_SPIN_FILE_NAME"], &
    1670              :                           description="Name of the reference spin density cube file for fragment A."// &
    1671              :                           " May include a path. The reference spin density needs to be outputted"// &
    1672              :                           " on the same grid as the full system (same cutoff and cell, output stride 1)."// &
    1673              :                           " For GAPW, use the TOTAL_SPIN_DENSITY cube generated together with"// &
    1674              :                           " E_DENSITY_CUBE% DENSITY_INCLUDE TOTAL_DENSITY.", &
    1675              :                           usage="FRAGMENT_A_SPIN_FILE <FILENAME>", &
    1676        21794 :                           default_lc_val="fragment_a_spin.cube")
    1677        10897 :       CALL section_add_keyword(section, keyword)
    1678        10897 :       CALL keyword_release(keyword)
    1679              : 
    1680              :       CALL keyword_create(keyword, __LOCATION__, name="FRAGMENT_B_SPIN_FILE", &
    1681              :                           variants=["FRAGMENT_B_SPIN_FILE_NAME"], &
    1682              :                           description="Name of the reference spin density cube file for fragment B."// &
    1683              :                           " May include a path. The reference spin density needs to be outputted"// &
    1684              :                           " on the same grid as the full system (same cutoff and cell, output stride 1)."// &
    1685              :                           " For GAPW, use the TOTAL_SPIN_DENSITY cube generated together with"// &
    1686              :                           " E_DENSITY_CUBE% DENSITY_INCLUDE TOTAL_DENSITY.", &
    1687              :                           usage="FRAGMENT_B_SPIN_FILE <FILENAME>", &
    1688        21794 :                           default_lc_val="fragment_b_spin.cube")
    1689        10897 :       CALL section_add_keyword(section, keyword)
    1690        10897 :       CALL keyword_release(keyword)
    1691              : 
    1692              :       CALL keyword_create(keyword, __LOCATION__, name="FLIP_FRAGMENT_A", &
    1693              :                           description="Logical which determines if the reference spin difference density "// &
    1694              :                           "(rho_alpha-rho_beta) for fragment A should be flipped. With default (off) "// &
    1695              :                           "value, the fragment is constrained to have more alpha than beta electrons "// &
    1696              :                           "if the isolated fragment has unpaired electrons. Useful in conjunction with "// &
    1697              :                           "FLIP_FRAGMENT_B.", &
    1698              :                           usage="FLIP_FRAGMENT_A", &
    1699        10897 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
    1700        10897 :       CALL section_add_keyword(section, keyword)
    1701        10897 :       CALL keyword_release(keyword)
    1702              : 
    1703              :       CALL keyword_create(keyword, __LOCATION__, name="FLIP_FRAGMENT_B", &
    1704              :                           description="Logical which determines if the reference spin difference density "// &
    1705              :                           "(rho_alpha-rho_beta) for fragment B should be flipped. With default (off) "// &
    1706              :                           "value, the fragment is constrained to have more alpha than beta electrons "// &
    1707              :                           "if the isolated fragment has unpaired electrons. Useful in conjunction with "// &
    1708              :                           "FLIP_FRAGMENT_A.", &
    1709              :                           usage="FLIP_FRAGMENT_B", &
    1710        10897 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
    1711        10897 :       CALL section_add_keyword(section, keyword)
    1712        10897 :       CALL keyword_release(keyword)
    1713              : 
    1714              :       CALL cp_print_key_section_create(print_key, __LOCATION__, "PROGRAM_RUN_INFO", &
    1715              :                                        description="Controls the printing of basic info about the method.", &
    1716        10897 :                                        print_level=low_print_level, add_last=add_last_numeric, filename="__STD_OUT__")
    1717              : 
    1718              :       CALL section_create(subsection, __LOCATION__, name="WEIGHT_FUNCTION", &
    1719              :                           description="Controls the printing of cube files with "// &
    1720              :                           "the CDFT weight function(s). Intended for single-point testing. "// &
    1721              :                           "In multistep simulations, generated cube files are overwritten each step.", &
    1722        10897 :                           n_keywords=1, n_subsections=0, repeats=.FALSE.)
    1723              : 
    1724              :       CALL keyword_create(keyword, __LOCATION__, name="STRIDE", &
    1725              :                           description="The stride (X,Y,Z) used to write the cube file "// &
    1726              :                           "(larger values result in smaller cube files). You can provide 3 numbers (for X,Y,Z) or"// &
    1727              :                           " 1 number valid for all components.", &
    1728        10897 :                           usage="STRIDE 2 2 2", n_var=-1, default_i_vals=[2, 2, 2], type_of_var=integer_t)
    1729        10897 :       CALL section_add_keyword(subsection, keyword)
    1730        10897 :       CALL keyword_release(keyword)
    1731              : 
    1732        10897 :       CALL section_add_subsection(print_key, subsection)
    1733        10897 :       CALL section_release(subsection)
    1734              : 
    1735        10897 :       CALL section_add_subsection(section, print_key)
    1736        10897 :       CALL section_release(print_key)
    1737              : 
    1738              :       CALL section_create(group_section, __LOCATION__, name="ATOM_GROUP", &
    1739              :                           description="Define a group of atoms for use in a CDFT constraint. Each repetition of "// &
    1740              :                           "this section creates a new constraint.", &
    1741        10897 :                           n_keywords=4, n_subsections=0, repeats=.TRUE.)
    1742              : 
    1743              :       CALL keyword_create(keyword, __LOCATION__, name="ATOMS", &
    1744              :                           description="Specifies the list of atoms that are included in the constraint group.", &
    1745              :                           usage="ATOMS {integer} {integer} .. {integer}", &
    1746        10897 :                           n_var=-1, type_of_var=integer_t)
    1747        10897 :       CALL section_add_keyword(group_section, keyword)
    1748        10897 :       CALL keyword_release(keyword)
    1749              : 
    1750              :       CALL keyword_create(keyword, __LOCATION__, name="COEFF", &
    1751              :                           description="Defines coefficients for the atoms in the list of atoms. Accepts values +/-1.0.", &
    1752              :                           usage="COEFF 1.0 -1.0", repeats=.TRUE., &
    1753        10897 :                           type_of_var=real_t, n_var=-1)
    1754        10897 :       CALL section_add_keyword(group_section, keyword)
    1755        10897 :       CALL keyword_release(keyword)
    1756              : 
    1757              :       CALL keyword_create(keyword, __LOCATION__, name="CONSTRAINT_TYPE ", &
    1758              :                           description="Determines what type of constraint to apply. ", &
    1759              :                           usage="CONSTRAINT_TYPE (CHARGE|MAGNETIZATION|ALPHA|BETA)", &
    1760              :                           enum_c_vals=s2a("CHARGE", "MAGNETIZATION", "ALPHA", "BETA"), &
    1761              :                           enum_i_vals=[cdft_charge_constraint, cdft_magnetization_constraint, &
    1762              :                                        cdft_alpha_constraint, cdft_beta_constraint], &
    1763              :                           enum_desc=s2a("Total charge density constraint (rho_alpha + rho_beta).", &
    1764              :                                         "Magnetization density constraint (rho_alpha - rho_beta).", &
    1765              :                                         "Alpha spin density constraint.", &
    1766              :                                         "Beta spin density constraint."), &
    1767        10897 :                           default_i_val=cdft_charge_constraint)
    1768        10897 :       CALL section_add_keyword(group_section, keyword)
    1769        10897 :       CALL keyword_release(keyword)
    1770              : 
    1771              :       CALL keyword_create(keyword, __LOCATION__, name="FRAGMENT_CONSTRAINT", &
    1772              :                           description="Use a fragment based constraint. "// &
    1773              :                           "Takes as input the electron densities of two isolated fragments in the "// &
    1774              :                           "same geometry that they have in the full system. "// &
    1775              :                           "The isolated fragment densities are read from cube files defined in FRAGMENT_{A,B}_FILE. "// &
    1776              :                           "For magnetization density constraints, additional files containing the spin difference "// &
    1777              :                           "densities must be defined with the keywords FRAGMENT_{A,B}_SPIN_FILE. "// &
    1778              :                           "With this keyword active, the target value of the constraint is calculated from the "// &
    1779              :                           "the superposition of the isolated fragment densities. Supports only static calculations.", &
    1780              :                           usage="FRAGMENT_CONSTRAINT", &
    1781        10897 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
    1782        10897 :       CALL section_add_keyword(group_section, keyword)
    1783        10897 :       CALL keyword_release(keyword)
    1784              : 
    1785        10897 :       CALL section_add_subsection(section, group_section)
    1786        10897 :       CALL section_release(group_section)
    1787              : 
    1788              :       CALL section_create(group_section, __LOCATION__, name="DUMMY_ATOMS", &
    1789              :                           description="Define an extra group of atoms for which only atomic CDFT charges "// &
    1790              :                           "should be computed. The section cannot contain any constraint "// &
    1791              :                           "atoms that were included in section ATOM_GROUP.", &
    1792        10897 :                           n_keywords=1, n_subsections=0, repeats=.TRUE.)
    1793              : 
    1794              :       CALL keyword_create(keyword, __LOCATION__, name="ATOMS", &
    1795              :                           description="Specifies the list of atoms that are included in the DUMMY_ATOMS group.", &
    1796              :                           usage="ATOMS {integer} {integer} .. {integer}", &
    1797        10897 :                           n_var=-1, type_of_var=integer_t)
    1798        10897 :       CALL section_add_keyword(group_section, keyword)
    1799        10897 :       CALL keyword_release(keyword)
    1800              : 
    1801        10897 :       CALL section_add_subsection(section, group_section)
    1802        10897 :       CALL section_release(group_section)
    1803              : 
    1804              :       CALL keyword_create(keyword, __LOCATION__, name="REUSE_PRECOND", &
    1805              :                           description="Reuse a previously built OT preconditioner between subsequent CDFT SCF iterations "// &
    1806              :                           "if the inner OT SCF loop converged in PRECOND_FREQ steps or less. Intended mainly for MD "// &
    1807              :                           "simulations with the FULL_ALL preconditioner to speed up the final iterations of the CDFT SCF loop.", &
    1808              :                           usage="REUSE_PRECOND yes", repeats=.FALSE., n_var=1, &
    1809        10897 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
    1810        10897 :       CALL section_add_keyword(section, keyword)
    1811        10897 :       CALL keyword_release(keyword)
    1812              : 
    1813              :       CALL keyword_create(keyword, __LOCATION__, name="PRECOND_FREQ", &
    1814              :                           description="See REUSE_PRECOND.", &
    1815        10897 :                           usage="PRECOND_FREQ {int}", default_i_val=0)
    1816        10897 :       CALL section_add_keyword(section, keyword)
    1817        10897 :       CALL keyword_release(keyword)
    1818              : 
    1819              :       CALL keyword_create(keyword, __LOCATION__, name="MAX_REUSE", &
    1820              :                           description="Determines how many times a previously built preconditioner can be reused.", &
    1821        10897 :                           usage="MAX_REUSE {int}", default_i_val=0)
    1822        10897 :       CALL section_add_keyword(section, keyword)
    1823        10897 :       CALL keyword_release(keyword)
    1824              : 
    1825              :       CALL keyword_create(keyword, __LOCATION__, name="PURGE_HISTORY", &
    1826              :                           description="Purge wavefunction and constraint history to improve SCF convergence during MD."// &
    1827              :                           " Counts how often the convergence of the first CDFT SCF iteration takes 2 or more outer SCF"// &
    1828              :                           " iterations and purges the history if the counter exceeds PURGE_FREQ, and PURGE_OFFSET"// &
    1829              :                           " MD steps have passed since the last purge."// &
    1830              :                           " The counter is zeroed after each purge.", &
    1831              :                           usage="PURGE_HISTORY yes", repeats=.FALSE., n_var=1, &
    1832        10897 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
    1833        10897 :       CALL section_add_keyword(section, keyword)
    1834        10897 :       CALL keyword_release(keyword)
    1835              : 
    1836              :       CALL keyword_create(keyword, __LOCATION__, name="PURGE_FREQ", &
    1837              :                           description="See PURGE_HISTORY.", &
    1838        10897 :                           usage="PURGE_FREQ {int} ", default_i_val=1)
    1839        10897 :       CALL section_add_keyword(section, keyword)
    1840        10897 :       CALL keyword_release(keyword)
    1841              : 
    1842              :       CALL keyword_create(keyword, __LOCATION__, name="PURGE_OFFSET", &
    1843              :                           description="See PURGE_HISTORY.", &
    1844        10897 :                           usage="PURGE_OFFSET {int} ", default_i_val=1)
    1845        10897 :       CALL section_add_keyword(section, keyword)
    1846        10897 :       CALL keyword_release(keyword)
    1847              : 
    1848              :       CALL keyword_create(keyword, __LOCATION__, name="COUNTER", &
    1849              :                           description="A counter to track the total number of energy evaluations. Needed by"// &
    1850              :                           " some optimizers to print information. Useful mainly for restarts.", &
    1851        10897 :                           usage="COUNTER {int} ", default_i_val=0)
    1852        10897 :       CALL section_add_keyword(section, keyword)
    1853        10897 :       CALL keyword_release(keyword)
    1854              : 
    1855              :       CALL keyword_create(keyword, __LOCATION__, name="IN_MEMORY", &
    1856              :                           description="Precompute gradients due to constraint during"// &
    1857              :                           " initial formation of constraint and store them in memory. Does"// &
    1858              :                           " nothing if forces are not calculated.", &
    1859              :                           usage="IN_MEMORY", &
    1860        10897 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
    1861        10897 :       CALL section_add_keyword(section, keyword)
    1862        10897 :       CALL keyword_release(keyword)
    1863              : 
    1864        10897 :    END SUBROUTINE create_cdft_control_section
    1865              : 
    1866              : ! **************************************************************************************************
    1867              : !> \brief Creates the input section for defining Gaussian Hirshfeld CDFT constraints.
    1868              : !> \param section the section to create
    1869              : ! **************************************************************************************************
    1870        10897 :    SUBROUTINE create_hirshfeld_constraint_section(section)
    1871              :       TYPE(section_type), POINTER                        :: section
    1872              : 
    1873              :       TYPE(keyword_type), POINTER                        :: keyword
    1874              : 
    1875        10897 :       NULLIFY (keyword)
    1876              : 
    1877        10897 :       CPASSERT(.NOT. ASSOCIATED(section))
    1878              :       CALL section_create(section, __LOCATION__, name="HIRSHFELD_CONSTRAINT", &
    1879              :                           description="Parameters for CDFT with a Gaussian Hirshfeld constraint.", &
    1880        10897 :                           n_keywords=11, n_subsections=0, repeats=.FALSE.)
    1881              : 
    1882              :       CALL keyword_create(keyword, __LOCATION__, name="SHAPE_FUNCTION", &
    1883              :                           description="Type of shape function used for Hirshfeld partitioning.", &
    1884              :                           usage="SHAPE_FUNCTION {Gaussian,Density}", repeats=.FALSE., n_var=1, &
    1885              :                           default_i_val=shape_function_gaussian, &
    1886              :                           enum_c_vals=s2a("GAUSSIAN", "DENSITY"), &
    1887              :                           enum_desc=s2a("One Gaussian per atom with radius determined by the keyword GAUSSIAN_SHAPE.", &
    1888              :                                         "Atomic density expanded in terms of multiple Gaussians."), &
    1889        10897 :                           enum_i_vals=[shape_function_gaussian, shape_function_density])
    1890        10897 :       CALL section_add_keyword(section, keyword)
    1891        10897 :       CALL keyword_release(keyword)
    1892              : 
    1893              :       CALL keyword_create(keyword, __LOCATION__, name="GAUSSIAN_SHAPE", &
    1894              :                           description="Specifies the type of Gaussian used for SHAPE_FUNCTION GAUSSIAN.", &
    1895              :                           usage="GAUSSIAN_SHAPE (SINGLE|VDW|COVALENT|USER)", &
    1896              :                           enum_c_vals=s2a("DEFAULT", "SINGLE", "VDW", "COVALENT", "USER"), &
    1897              :                           enum_i_vals=[radius_default, radius_single, radius_vdw, radius_covalent, radius_user], &
    1898              :                           enum_desc=s2a("Use covalent radii (in angstrom) to construct Gaussians, but fixed"// &
    1899              :                                         " 1.0_dp radius for elements with a radius larger than this value.", &
    1900              :                                         "Single Gaussian for all atom types with radius given by GAUSSIAN_RADIUS.", &
    1901              :                                         "Use van der Waals radii to construct Gaussians.", &
    1902              :                                         "Use covalent radii to construct Gaussians.", &
    1903              :                                         "Use user defined radii (keyword ATOMIC_RADII) to construct Gaussians."), &
    1904        10897 :                           default_i_val=radius_default)
    1905        10897 :       CALL section_add_keyword(section, keyword)
    1906        10897 :       CALL keyword_release(keyword)
    1907              : 
    1908              :       CALL keyword_create(keyword, __LOCATION__, name="GAUSSIAN_RADIUS", &
    1909              :                           description="Radius parameter controlling the creation of Gaussians.", &
    1910              :                           usage="GAUSSIAN_RADIUS <REAL>", &
    1911              :                           unit_str="angstrom", &
    1912              :                           default_r_val=cp_unit_to_cp2k(3.0_dp, "angstrom"), &
    1913        10897 :                           type_of_var=real_t, n_var=1)
    1914        10897 :       CALL section_add_keyword(section, keyword)
    1915        10897 :       CALL keyword_release(keyword)
    1916              : 
    1917              :       CALL keyword_create(keyword, __LOCATION__, name="ATOMIC_RADII", &
    1918              :                           description="Defines custom radii to setup the spherical Gaussians. "// &
    1919              :                           "Give one value per element in the same order as they "// &
    1920              :                           "appear in the input coordinates.", &
    1921              :                           usage="ATOMIC_RADII {real} {real} {real}", repeats=.FALSE., &
    1922              :                           unit_str="angstrom", &
    1923        10897 :                           type_of_var=real_t, n_var=-1)
    1924        10897 :       CALL section_add_keyword(section, keyword)
    1925        10897 :       CALL keyword_release(keyword)
    1926              : 
    1927              :       CALL keyword_create(keyword, __LOCATION__, name="USE_BOHR", &
    1928              :                           description="Convert the Gaussian radius from angstrom to bohr. This results in a larger "// &
    1929              :                           "Gaussian than without unit conversion.", &
    1930              :                           usage="USE_BOHR .TRUE.", &
    1931        10897 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
    1932        10897 :       CALL section_add_keyword(section, keyword)
    1933        10897 :       CALL keyword_release(keyword)
    1934              : 
    1935              :       CALL keyword_create(keyword, __LOCATION__, name="PRINT_DENSITY", &
    1936              :                           description="Logical to control printing of Hirshfeld densities to .cube file.", &
    1937              :                           usage="PRINT_DENSITY TRUE", &
    1938        10897 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
    1939        10897 :       CALL section_add_keyword(section, keyword)
    1940        10897 :       CALL keyword_release(keyword)
    1941              : 
    1942              :       CALL keyword_create(keyword, __LOCATION__, name="ATOMS_MEMORY", &
    1943              :                           description="Number of atomic gradients to store in memory.", &
    1944              :                           usage="ATOMS_MEMORY", &
    1945              :                           n_var=1, type_of_var=integer_t, &
    1946        10897 :                           default_i_val=80)
    1947        10897 :       CALL section_add_keyword(section, keyword)
    1948        10897 :       CALL keyword_release(keyword)
    1949              : 
    1950              :       CALL keyword_create(keyword, __LOCATION__, name="USE_ATOMIC_CUTOFF", &
    1951              :                           description="Logical to control use of ATOMIC_CUTOFF.", &
    1952              :                           usage="USE_ATOMIC_CUTOFF TRUE", &
    1953        10897 :                           default_l_val=.TRUE., lone_keyword_l_val=.TRUE.)
    1954        10897 :       CALL section_add_keyword(section, keyword)
    1955        10897 :       CALL keyword_release(keyword)
    1956              : 
    1957              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_CUTOFF", &
    1958              :                           description="Numerical cutoff for calculation of weight function.", &
    1959        10897 :                           usage="EPS_CUTOFF {real} ", default_r_val=1.0e-12_dp)
    1960        10897 :       CALL section_add_keyword(section, keyword)
    1961        10897 :       CALL keyword_release(keyword)
    1962              : 
    1963              :       CALL keyword_create(keyword, __LOCATION__, name="ATOMIC_CUTOFF", &
    1964              :                           description="Numerical cutoff for calculation of Hirshfeld densities.", &
    1965        10897 :                           usage="ATOMIC_CUTOFF {real} ", default_r_val=1.0e-12_dp)
    1966        10897 :       CALL section_add_keyword(section, keyword)
    1967        10897 :       CALL keyword_release(keyword)
    1968              : 
    1969        10897 :    END SUBROUTINE create_hirshfeld_constraint_section
    1970              : 
    1971              : ! **************************************************************************************************
    1972              : !> \brief Create input section to define CDFT constraint settings specific to Becke weight function.
    1973              : !> \param section the section to create
    1974              : ! **************************************************************************************************
    1975        10897 :    SUBROUTINE create_becke_constraint_section(section)
    1976              :       TYPE(section_type), POINTER                        :: section
    1977              : 
    1978              :       TYPE(keyword_type), POINTER                        :: keyword
    1979              : 
    1980        10897 :       NULLIFY (keyword)
    1981        10897 :       CPASSERT(.NOT. ASSOCIATED(section))
    1982              :       CALL section_create(section, __LOCATION__, name="BECKE_CONSTRAINT", &
    1983              :                           description="Define settings influencing the construction of the Becke weight function.", &
    1984        21794 :                           n_keywords=13, repeats=.FALSE., citations=[Becke1988b])
    1985              : 
    1986              :       CALL keyword_create(keyword, __LOCATION__, name="ADJUST_SIZE", &
    1987              :                           description="Adjust Becke cell boundaries with atomic"// &
    1988              :                           " radii to generate a heteronuclear cutoff profile. These"// &
    1989              :                           " radii are defined with the keyword ATOMIC_RADII.", &
    1990              :                           usage="ADJUST_SIZE", &
    1991        10897 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
    1992        10897 :       CALL section_add_keyword(section, keyword)
    1993        10897 :       CALL keyword_release(keyword)
    1994              : 
    1995              :       CALL keyword_create(keyword, __LOCATION__, name="ATOMIC_RADII", &
    1996              :                           description="Defines atomic radii to generate a heteronuclear cutoff profile."// &
    1997              :                           " Give one value per element in the same order as they"// &
    1998              :                           " appear in the input coordinates.", &
    1999              :                           usage="ATOMIC_RADII {real} {real} {real}", repeats=.FALSE., &
    2000              :                           unit_str="angstrom", &
    2001        10897 :                           type_of_var=real_t, n_var=-1)
    2002        10897 :       CALL section_add_keyword(section, keyword)
    2003        10897 :       CALL keyword_release(keyword)
    2004              : 
    2005              :       CALL keyword_create(keyword, __LOCATION__, name="SHOULD_SKIP", &
    2006              :                           description="If grid point is farther than GLOBAL_CUTOFF from all constraint atoms, "// &
    2007              :                           "move directly to next grid point, thus saving computational resources.", &
    2008              :                           usage="SHOULD_SKIP", &
    2009        10897 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
    2010        10897 :       CALL section_add_keyword(section, keyword)
    2011        10897 :       CALL keyword_release(keyword)
    2012              : 
    2013              :       CALL keyword_create(keyword, __LOCATION__, name="CAVITY_CONFINE", &
    2014              :                           description="Activates Gaussian cavity confinement. The constraint is evaluated only inside "// &
    2015              :                           "the cavity. The cavity is formed by summing spherical Gaussians centered on the constraint atoms.", &
    2016              :                           usage="CAVITY_CONFINE", &
    2017        10897 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
    2018        10897 :       CALL section_add_keyword(section, keyword)
    2019        10897 :       CALL keyword_release(keyword)
    2020              : 
    2021              :       CALL keyword_create(keyword, __LOCATION__, name="CAVITY_SHAPE", &
    2022              :                           description="Specifies the type of Gaussian cavity used.", &
    2023              :                           usage="CAVITY_SHAPE (SINGLE|VDW|COVALENT|USER)", &
    2024              :                           enum_c_vals=s2a("DEFAULT", "SINGLE", "VDW", "COVALENT", "USER"), &
    2025              :                           enum_i_vals=[radius_default, radius_single, radius_vdw, radius_covalent, radius_user], &
    2026              :                           enum_desc=s2a("Use covalent radii (in angstrom) to construct Gaussians, but fixed"// &
    2027              :                                         " 1.0_dp radius for elements with a radius larger than this value.", &
    2028              :                                         "Single Gaussian for all atom types with radius given by CAVITY_RADIUS.", &
    2029              :                                         "Use van der Waals radii to construct Gaussians.", &
    2030              :                                         "Use covalent radii to construct Gaussians.", &
    2031              :                                         "Use user defined radii (keyword ATOMIC_RADII) to construct Gaussians."), &
    2032        10897 :                           default_i_val=radius_default)
    2033        10897 :       CALL section_add_keyword(section, keyword)
    2034        10897 :       CALL keyword_release(keyword)
    2035              : 
    2036              :       CALL keyword_create(keyword, __LOCATION__, name="CAVITY_USE_BOHR", &
    2037              :                           description="Convert the cavity radius from angstrom to bohr. This results in a larger"// &
    2038              :                           " confinement cavity than without unit conversion.", &
    2039              :                           usage="CAVITY_USE_BOHR TRUE", &
    2040        10897 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
    2041        10897 :       CALL section_add_keyword(section, keyword)
    2042        10897 :       CALL keyword_release(keyword)
    2043              : 
    2044              :       CALL keyword_create(keyword, __LOCATION__, name="CAVITY_PRINT", &
    2045              :                           description="Print cavity in Gaussian cube file format. Currently, printing options"// &
    2046              :                           " are hardcoded.", &
    2047              :                           usage="CAVITY_PRINT", &
    2048        10897 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
    2049        10897 :       CALL section_add_keyword(section, keyword)
    2050        10897 :       CALL keyword_release(keyword)
    2051              : 
    2052              :       CALL keyword_create(keyword, __LOCATION__, name="CAVITY_RADIUS", &
    2053              :                           description="Radius parameter controlling the creation of Gaussian cavity confinement.", &
    2054              :                           usage="CAVITY_RADIUS <REAL>", &
    2055              :                           unit_str="angstrom", &
    2056              :                           default_r_val=cp_unit_to_cp2k(3.0_dp, "angstrom"), &
    2057        10897 :                           type_of_var=real_t, n_var=1)
    2058        10897 :       CALL section_add_keyword(section, keyword)
    2059        10897 :       CALL keyword_release(keyword)
    2060              : 
    2061              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_CAVITY", &
    2062              :                           description="Density threshold for cavity creation. Grid points where the Gaussian"// &
    2063              :                           " density falls below the threshold are ignored.", &
    2064        10897 :                           usage="EPS_CAVITY {real} ", default_r_val=1.0e-6_dp)
    2065        10897 :       CALL section_add_keyword(section, keyword)
    2066        10897 :       CALL keyword_release(keyword)
    2067              : 
    2068              :       CALL keyword_create(keyword, __LOCATION__, name="CUTOFF_TYPE", &
    2069              :                           description="Specifies the type of cutoff used when building the Becke weight function.", &
    2070              :                           usage="CUTOFF_TYPE (GLOBAL|ELEMENT)", &
    2071              :                           enum_c_vals=s2a("GLOBAL", "ELEMENT"), &
    2072              :                           enum_i_vals=[becke_cutoff_global, becke_cutoff_element], &
    2073              :                           enum_desc=s2a("Use a single value for all elements. Read from GLOBAL_CUTOFF.", &
    2074              :                                         "Use a different value for all elements. Values read from ELEMENT_CUTOFF."), &
    2075        10897 :                           default_i_val=becke_cutoff_global)
    2076        10897 :       CALL section_add_keyword(section, keyword)
    2077        10897 :       CALL keyword_release(keyword)
    2078              : 
    2079              :       CALL keyword_create(keyword, __LOCATION__, name="GLOBAL_CUTOFF", &
    2080              :                           description="Parameter used to select which atoms contribute to the"// &
    2081              :                           " weight function at each real space grid point.", &
    2082              :                           usage="GLOBAL_CUTOFF <REAL>", &
    2083              :                           unit_str="angstrom", &
    2084              :                           default_r_val=cp_unit_to_cp2k(3.1750632515_dp, "angstrom"), &
    2085        10897 :                           type_of_var=real_t, n_var=1)
    2086        10897 :       CALL section_add_keyword(section, keyword)
    2087        10897 :       CALL keyword_release(keyword)
    2088              : 
    2089              :       CALL keyword_create(keyword, __LOCATION__, name="ELEMENT_CUTOFF", &
    2090              :                           description="Defines element specific cutoffs to decide which atoms contribute to the"// &
    2091              :                           " weight function at each real space grid point. Give one value per element in the same"// &
    2092              :                           " order as they appear in the coordinates.", &
    2093              :                           usage="ELEMENT_CUTOFF {real} {real} {real}", repeats=.FALSE., &
    2094              :                           unit_str="angstrom", &
    2095        10897 :                           type_of_var=real_t, n_var=-1)
    2096        10897 :       CALL section_add_keyword(section, keyword)
    2097        10897 :       CALL keyword_release(keyword)
    2098              : 
    2099              :       CALL keyword_create(keyword, __LOCATION__, name="IN_MEMORY", &
    2100              :                           description="Precompute gradients due to Becke constraint during"// &
    2101              :                           " initial formation of constraint and store them in memory. Useful"// &
    2102              :                           " in combination with confinement, memory intensive otherwise. Does"// &
    2103              :                           " nothing if forces are not calculated.", &
    2104              :                           usage="IN_MEMORY", &
    2105        10897 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
    2106        10897 :       CALL section_add_keyword(section, keyword)
    2107        10897 :       CALL keyword_release(keyword)
    2108              : 
    2109        10897 :    END SUBROUTINE create_becke_constraint_section
    2110              : 
    2111              : ! **************************************************************************************************
    2112              : !> \brief creates the input section for parameters related to CDFT specific optimizers
    2113              : !> \param section the section to be created
    2114              : !> \par History
    2115              : !>      03.2018 separated from create_outer_scf_section [Nico Holmberg]
    2116              : !> \author Nico Holmberg
    2117              : ! **************************************************************************************************
    2118        36672 :    SUBROUTINE create_cdft_opt_section(section)
    2119              :       TYPE(section_type), POINTER                        :: section
    2120              : 
    2121              :       TYPE(keyword_type), POINTER                        :: keyword
    2122              : 
    2123        36672 :       CPASSERT(.NOT. ASSOCIATED(section))
    2124              :       CALL section_create(section, __LOCATION__, name="CDFT_OPT", &
    2125              :                           description="Parameters controlling optimization methods that are compatible "// &
    2126              :                           "only with CDFT based constraints (i.e. CDFT SCF is active). Specifically, "// &
    2127              :                           "the control parameters for the Broyden and Newton optimizers are defined in this "// &
    2128              :                           "section.", &
    2129        36672 :                           n_keywords=10, n_subsections=0, repeats=.FALSE.)
    2130              : 
    2131        36672 :       NULLIFY (keyword)
    2132              : 
    2133              :       CALL keyword_create(keyword, __LOCATION__, name="BROYDEN_TYPE", &
    2134              :                           description="Specifies the Broyden optimizer variant to use.", &
    2135              :                           usage="BROYDEN_TYPE BT1", &
    2136              :                           default_i_val=broyden_type_1, &
    2137              :                           enum_c_vals=s2a("BT1", "BT1_EXPLICIT", "BT2", "BT2_EXPLICIT", &
    2138              :                                           "BT1_LS", "BT1_EXPLICIT_LS", "BT2_LS", "BT2_EXPLICIT_LS"), &
    2139              :                           enum_desc=s2a("Broyden's first method, also known as the good method. The initial Jacobian"// &
    2140              :                                         " is built from MD history if available. Otherwise switches to SD for one"// &
    2141              :                                         " SCF iteration until a Jacobian can be built from the SCF history.", &
    2142              :                                         "Same as BT1, but computes the explicit Jacobian with finite differences. "// &
    2143              :                                         "Requires a CDFT SCF procedure to be active.", &
    2144              :                                         "Same as BT1, but uses Broyden's second method, also known as the bad method.", &
    2145              :                                         "Same as BT1_EXPLICIT, but using Broyden's second method.", &
    2146              :                                         "Same as BT1, but uses backtracking line search for optimizing the step size "// &
    2147              :                                         "(see optimizer NEWTON_LS).", &
    2148              :                                         "Same as BT1_EXPLICIT, but uses backtracking line search for optimizing the step size.", &
    2149              :                                         "Same as BT2, but uses backtracking line search for optimizing the step size.", &
    2150              :                                         "Same as BT2_EXPLICIT, but uses backtracking line search for optimizing the step size."), &
    2151              :                           enum_i_vals=[broyden_type_1, broyden_type_1_explicit, broyden_type_2, &
    2152              :                                        broyden_type_2_explicit, broyden_type_1_ls, broyden_type_1_explicit_ls, &
    2153        36672 :                                        broyden_type_2_ls, broyden_type_2_explicit_ls])
    2154        36672 :       CALL section_add_keyword(section, keyword)
    2155        36672 :       CALL keyword_release(keyword)
    2156              : 
    2157              :       CALL keyword_create(keyword, __LOCATION__, name="JACOBIAN_TYPE", &
    2158              :                           description="Finite difference method used to calculate the inverse Jacobian "// &
    2159              :                           "needed by some optimizers. Compatible only with CDFT constraints.", &
    2160              :                           usage="JACOBIAN_TYPE FD1", &
    2161              :                           default_i_val=jacobian_fd1, &
    2162              :                           enum_c_vals=s2a("FD1", "FD1_BACKWARD", "FD2", "FD2_BACKWARD", "FD1_CENTRAL"), &
    2163              :                           enum_desc=s2a("First order forward difference (one extra energy evaluation per constraint).", &
    2164              :                                         "First order backward difference (one extra energy evaluation per constraint).", &
    2165              :                                         "Second order forward difference (two extra energy evaluations per constraint).", &
    2166              :                                         "Second order backward difference (two extra energy evaluations per constraint).", &
    2167              :                                         "First order central difference (two extra energy evaluations per constraint)."), &
    2168              :                           enum_i_vals=[jacobian_fd1, jacobian_fd1_backward, jacobian_fd2, &
    2169        36672 :                                        jacobian_fd2_backward, jacobian_fd1_central])
    2170        36672 :       CALL section_add_keyword(section, keyword)
    2171        36672 :       CALL keyword_release(keyword)
    2172              : 
    2173              :       CALL keyword_create(keyword, __LOCATION__, name="JACOBIAN_STEP", &
    2174              :                           description="Step size to use in the calculation of the inverse Jacobian with finite differences. "// &
    2175              :                           "Expects one value for all constraints, or one value per constraint.", &
    2176        36672 :                           usage="JACOBIAN_STEP 5.0E-3 ", n_var=-1, default_r_val=5.0E-3_dp)
    2177        36672 :       CALL section_add_keyword(section, keyword)
    2178        36672 :       CALL keyword_release(keyword)
    2179              : 
    2180              :       CALL keyword_create(keyword, __LOCATION__, name="JACOBIAN_FREQ", &
    2181              :                           description="Defines parameters that control how often the explicit Jacobian is built,"// &
    2182              :                           " which is needed by some optimizers. Expects two values. The first value"// &
    2183              :                           " determines how many consecutive CDFT SCF iterations should skip a rebuild,"// &
    2184              :                           " whereas the latter how many MD steps. The values can be zero (meaning never"// &
    2185              :                           " rebuild) or positive. Both values cannot be zero.", &
    2186              :                           usage="JACOBIAN_FREQ 1 1", n_var=2, &
    2187        36672 :                           default_i_vals=[1, 1], type_of_var=integer_t)
    2188        36672 :       CALL section_add_keyword(section, keyword)
    2189        36672 :       CALL keyword_release(keyword)
    2190              : 
    2191              :       CALL keyword_create(keyword, __LOCATION__, name="JACOBIAN_RESTART", &
    2192              :                           description="Restart the inverse Jacobian using the vector defined with keyword JACOBIAN_VECTOR.", &
    2193              :                           usage="JACOBIAN_RESTART TRUE", &
    2194        36672 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
    2195        36672 :       CALL section_add_keyword(section, keyword)
    2196        36672 :       CALL keyword_release(keyword)
    2197              : 
    2198              :       CALL keyword_create(keyword, __LOCATION__, name="JACOBIAN_VECTOR", &
    2199              :                           description="Defines the inverse Jacobian matrix. Useful for restarting calculations. "// &
    2200              :                           "Expects n^2 values where n is the total number of constraints. "// &
    2201              :                           "The matrix should be given in row major order.", &
    2202        36672 :                           usage="JACOBIAN_VECTOR 1.0 0.0", n_var=-1, type_of_var=real_t)
    2203        36672 :       CALL section_add_keyword(section, keyword)
    2204        36672 :       CALL keyword_release(keyword)
    2205              : 
    2206              :       CALL keyword_create(keyword, __LOCATION__, name="MAX_LS", &
    2207              :                           description="The maximum number of backtracking line search steps to perform.", &
    2208        36672 :                           usage="MAX_LS 5", default_i_val=5)
    2209        36672 :       CALL section_add_keyword(section, keyword)
    2210        36672 :       CALL keyword_release(keyword)
    2211              : 
    2212              :       CALL keyword_create(keyword, __LOCATION__, name="FACTOR_LS", &
    2213              :                           description="Control parameter for backtracking line search. The step size is reduced by "// &
    2214              :                           "this factor on every line search iteration. Value must be between 0 and 1 (exclusive).", &
    2215        36672 :                           usage="FACTOR_LS 0.5", default_r_val=0.5_dp)
    2216        36672 :       CALL section_add_keyword(section, keyword)
    2217        36672 :       CALL keyword_release(keyword)
    2218              : 
    2219              :       CALL keyword_create(keyword, __LOCATION__, name="CONTINUE_LS", &
    2220              :                           description="Continue backtracking line search until MAX_LS steps are reached or the "// &
    2221              :                           "norm of the CDFT gradient no longer decreases. Default (false) behavior exits the "// &
    2222              :                           "line search procedure on the first step that the gradient decreases.", &
    2223              :                           usage="CONTINUE_LS TRUE", &
    2224        36672 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
    2225        36672 :       CALL section_add_keyword(section, keyword)
    2226        36672 :       CALL keyword_release(keyword)
    2227              : 
    2228        36672 :    END SUBROUTINE create_cdft_opt_section
    2229              : 
    2230              : ! **************************************************************************************************
    2231              : !> \brief      Create CP2K input section for the grand canonical SCF
    2232              : !> \param section ...
    2233              : !> \date
    2234              : !> \author     Ziwei Chai
    2235              : !> \version    1.0
    2236              : ! **************************************************************************************************
    2237        25775 :    SUBROUTINE create_gce_section(section)
    2238              : 
    2239              :       TYPE(section_type), POINTER                        :: section
    2240              : 
    2241              :       TYPE(keyword_type), POINTER                        :: keyword
    2242              : 
    2243        25775 :       CPASSERT(.NOT. ASSOCIATED(section))
    2244              : 
    2245              :       CALL section_create(section, __LOCATION__, &
    2246              :                           name="GCE", &
    2247              :                           description="Enables grand canonical SCF calculations for "// &
    2248              :                           "slab models with a target work function specified by the "// &
    2249              :                           "user. The current implementation is intended for three "// &
    2250              :                           "dimensional periodic calculations and should be used "// &
    2251              :                           "together with the planar counter charge model. The planar "// &
    2252              :                           "counter charge screens the net charge of the DFT slab, so "// &
    2253              :                           "that the work function can be obtained from the planar "// &
    2254              :                           "averaged Hartree potential in the implicit solvent region "// &
    2255              :                           "or vacuum region. During the SCF iterations, the work "// &
    2256              :                           "function is mixed toward the target value. "// &
    2257              :                           "The reported GCE charges during SCF iterations are the "// &
    2258              :                           "current net charge of the DFT system excluding the planar "// &
    2259              :                           "counter charge. A positive value means electron deficiency. "// &
    2260              :                           "The input CHARGE value in the DFT section defines the "// &
    2261              :                           "reference charge state. The quantity N_e^(abs,alpha) is "// &
    2262              :                           "evaluated as the input CHARGE value minus the reported GCE "// &
    2263              :                           "charge. The reported GCE free energy is the sum of the DFT "// &
    2264              :                           "total energy and the product of the target work function "// &
    2265              :                           "and N_e^(abs,alpha).", &
    2266              :                           citations=[Chai2024a], &
    2267              :                           n_keywords=3, &
    2268              :                           n_subsections=0, &
    2269        51550 :                           repeats=.FALSE.)
    2270              : 
    2271        25775 :       NULLIFY (keyword)
    2272              : 
    2273              :       CALL keyword_create(keyword, __LOCATION__, &
    2274              :                           name="_SECTION_PARAMETERS_", &
    2275              :                           description="Controls the activation of grand canonical SCF", &
    2276              :                           usage="&GCE ON", &
    2277              :                           default_l_val=.FALSE., &
    2278        25775 :                           lone_keyword_l_val=.TRUE.)
    2279        25775 :       CALL section_add_keyword(section, keyword)
    2280        25775 :       CALL keyword_release(keyword)
    2281              : 
    2282              :       CALL keyword_create(keyword, __LOCATION__, &
    2283              :                           name="TARGET_WORKFUNCTION", &
    2284              :                           description="The user input target work function of the symmetric slab model", &
    2285              :                           repeats=.FALSE., &
    2286              :                           n_var=1, &
    2287              :                           type_of_var=real_t, &
    2288              :                           default_r_val=0.16_dp, &
    2289              :                           unit_str="au_e", &
    2290        25775 :                           usage="TARGET_WORKFUNCTION [eV] 0.16")
    2291        25775 :       CALL section_add_keyword(section, keyword)
    2292        25775 :       CALL keyword_release(keyword)
    2293              : 
    2294              :       CALL keyword_create(keyword, __LOCATION__, &
    2295              :                           name="MIXING_COEF", &
    2296              :                           description="The proportion of the target work function mixed with the "// &
    2297              :                           "work function of the previous SCF iteration", &
    2298              :                           repeats=.FALSE., &
    2299              :                           n_var=1, &
    2300              :                           type_of_var=real_t, &
    2301              :                           default_r_val=0.3_dp, &
    2302        25775 :                           usage="MIXING_COEF 0.3")
    2303        25775 :       CALL section_add_keyword(section, keyword)
    2304        25775 :       CALL keyword_release(keyword)
    2305              : 
    2306        25775 :    END SUBROUTINE create_gce_section
    2307              : 
    2308              : END MODULE input_cp2k_scf
        

Generated by: LCOV version 2.0-1