LCOV - code coverage report
Current view: top level - src - input_cp2k_scf.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:cccd2f3) Lines: 100.0 % 648 648
Test Date: 2026-05-06 07:07:47 Functions: 100.0 % 12 12

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

Generated by: LCOV version 2.0-1