LCOV - code coverage report
Current view: top level - src - input_cp2k_scf.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:1155b05) Lines: 100.0 % 648 648
Test Date: 2026-03-21 06:31:29 Functions: 100.0 % 12 12

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

Generated by: LCOV version 2.0-1