LCOV - code coverage report
Current view: top level - src - input_cp2k_scf.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:06f838d) Lines: 100.0 % 665 665
Test Date: 2026-06-05 07:04:50 Functions: 100.0 % 13 13

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

Generated by: LCOV version 2.0-1