LCOV - code coverage report
Current view: top level - src - input_cp2k_almo.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:561f475) Lines: 100.0 % 246 246
Test Date: 2026-06-21 06:48:54 Functions: 100.0 % 7 7

            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 input for the ALMO SCF section
      10              : !> \author Rustam Khaliullin
      11              : ! **************************************************************************************************
      12              : MODULE input_cp2k_almo
      13              :    USE bibliography,                    ONLY: Khaliullin2007,&
      14              :                                               Khaliullin2008,&
      15              :                                               Khaliullin2013,&
      16              :                                               Scheiber2018
      17              :    USE cp_output_handling,              ONLY: cp_print_key_section_create,&
      18              :                                               low_print_level
      19              :    USE input_constants,                 ONLY: &
      20              :         almo_deloc_none, almo_deloc_scf, almo_deloc_x, almo_deloc_x_then_scf, &
      21              :         almo_deloc_xalmo_1diag, almo_deloc_xalmo_scf, almo_deloc_xalmo_x, almo_frz_crystal, &
      22              :         almo_frz_none, almo_scf_diag, almo_scf_pcg, almo_scf_skip, almo_scf_trustr, atomic_guess, &
      23              :         cg_dai_yuan, cg_fletcher, cg_fletcher_reeves, cg_hager_zhang, cg_hestenes_stiefel, &
      24              :         cg_liu_storey, cg_polak_ribiere, cg_zero, molecular_guess, op_loc_berry, op_loc_pipek, &
      25              :         optimizer_diis, optimizer_lin_eq_pcg, optimizer_pcg, optimizer_trustr, &
      26              :         spd_inversion_dense_cholesky, spd_inversion_ls_hotelling, spd_inversion_ls_taylor, &
      27              :         trustr_cauchy, trustr_dogleg, trustr_steihaug, xalmo_prec_domain, xalmo_prec_full, &
      28              :         xalmo_prec_zero, xalmo_trial_r0_out, xalmo_trial_simplex
      29              :    USE input_keyword_types,             ONLY: keyword_create,&
      30              :                                               keyword_release,&
      31              :                                               keyword_type
      32              :    USE input_section_types,             ONLY: section_add_keyword,&
      33              :                                               section_add_subsection,&
      34              :                                               section_create,&
      35              :                                               section_release,&
      36              :                                               section_type
      37              :    USE kinds,                           ONLY: dp
      38              :    USE string_utilities,                ONLY: s2a
      39              : #include "./base/base_uses.f90"
      40              : 
      41              :    IMPLICIT NONE
      42              :    PRIVATE
      43              : 
      44              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'input_cp2k_almo'
      45              : 
      46              :    INTEGER, PARAMETER, PRIVATE :: optimizer_block_diagonal_diis = 1
      47              :    INTEGER, PARAMETER, PRIVATE :: optimizer_block_diagonal_pcg = 2
      48              :    INTEGER, PARAMETER, PRIVATE :: optimizer_xalmo_pcg = 3
      49              :    INTEGER, PARAMETER, PRIVATE :: optimizer_xalmo_trustr = 4
      50              :    INTEGER, PARAMETER, PRIVATE :: optimizer_newton_pcg_solver = 5
      51              :    INTEGER, PARAMETER, PRIVATE :: optimizer_nlmo_pcg = 6
      52              :    INTEGER, PARAMETER, PRIVATE :: optimizer_block_diagonal_trustr = 7
      53              : 
      54              :    PUBLIC :: create_almo_scf_section
      55              : 
      56              : CONTAINS
      57              : 
      58              : ! **************************************************************************************************
      59              : !> \brief create the almo scf section
      60              : !> \param section ...
      61              : !> \par History
      62              : !>       2011.05 created [Rustam Z Khaliullin]
      63              : !> \author Rustam Z Khaliullin
      64              : ! **************************************************************************************************
      65        10356 :    SUBROUTINE create_almo_scf_section(section)
      66              :       TYPE(section_type), POINTER                        :: section
      67              : 
      68              :       TYPE(keyword_type), POINTER                        :: keyword
      69              :       TYPE(section_type), POINTER                        :: subsection
      70              : 
      71        10356 :       CPASSERT(.NOT. ASSOCIATED(section))
      72              :       CALL section_create(section, __LOCATION__, name="ALMO_SCF", &
      73              :                           description="Settings for a class of efficient linear scaling methods based "// &
      74              :                           "on absolutely localized orbitals"// &
      75              :                           " (ALMOs). ALMO methods are currently restricted to closed-shell molecular systems.", &
      76              :                           n_keywords=10, n_subsections=6, repeats=.FALSE., &
      77        31068 :                           citations=[Khaliullin2013, Scheiber2018])
      78              : 
      79        10356 :       NULLIFY (keyword)
      80              : 
      81              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_FILTER", &
      82              :                           description="Threshold for the matrix sparsity filter", &
      83        10356 :                           usage="EPS_FILTER 1.e-6", default_r_val=1.e-7_dp)
      84        10356 :       CALL section_add_keyword(section, keyword)
      85        10356 :       CALL keyword_release(keyword)
      86              : 
      87              :       CALL keyword_create(keyword, __LOCATION__, name="ALMO_SCF_GUESS", &
      88              :                           description="The method to generate initial ALMOs.", &
      89              :                           usage="ALMO_SCF_GUESS MOLECULAR", &
      90              :                           default_i_val=atomic_guess, &
      91              :                           enum_c_vals=s2a("MOLECULAR", "ATOMIC"), &
      92              :                           enum_desc=s2a("SCF calculations on single molecules controlled by the regular SCF "// &
      93              :                                         "keywords outside ALMO options. This kind of calculation is expensive "// &
      94              :                                         "and only recommended if ALMO SCF does not converge from the ATOMIC guess.", &
      95              :                                         "Superposition of atomic densities."), &
      96        10356 :                           enum_i_vals=[molecular_guess, atomic_guess])
      97        10356 :       CALL section_add_keyword(section, keyword)
      98        10356 :       CALL keyword_release(keyword)
      99              : 
     100              :       CALL keyword_create(keyword, __LOCATION__, name="MO_OVERLAP_INV_ALG", &
     101              :                           description="Algorithm to invert MO overlap matrix.", &
     102              :                           usage="MO_OVERLAP_INV_ALG LS_HOTELLING", &
     103              :                           default_i_val=spd_inversion_ls_hotelling, &
     104              :                           enum_c_vals=s2a("LS_HOTELLING", "LS_TAYLOR", "DENSE_CHOLESKY"), &
     105              :                           enum_desc=s2a("Linear scaling iterative Hotelling algorithm. Fast for large sparse matrices.", &
     106              :                                         "Linear scaling algorithm based on Taylor expansion of (A+B)^(-1).", &
     107              :                                         "Stable but dense Cholesky algorithm. Cubically scaling."), &
     108        10356 :                           enum_i_vals=[spd_inversion_ls_hotelling, spd_inversion_ls_taylor, spd_inversion_dense_cholesky])
     109        10356 :       CALL section_add_keyword(section, keyword)
     110        10356 :       CALL keyword_release(keyword)
     111              : 
     112              :       !CALL keyword_create(keyword, __LOCATION__, name="STOP_SCF_EARLY",&
     113              :       !     description="Stops SCF using EPS_ERROR_EARLY or MAX_ITER_EARLY", &
     114              :       !     usage="STOP_SCF_EARLY .TRUE.", default_l_val=.FALSE.,&
     115              :       !     lone_keyword_l_val=.TRUE.)
     116              :       !CALL section_add_keyword(section,keyword)
     117              :       !CALL keyword_release(keyword)
     118              : 
     119              :       CALL keyword_create(keyword, __LOCATION__, name="ALMO_EXTRAPOLATION_ORDER", &
     120              :                           description="Number of previous states used for the ASPC extrapolation of the ALMO "// &
     121              :                           "initial guess. 0 implies that the guess is given by ALMO_SCF_GUESS at each step.", &
     122        10356 :                           usage="ALMO_EXTRAPOLATION_ORDER 3", default_i_val=3)
     123        10356 :       CALL section_add_keyword(section, keyword)
     124        10356 :       CALL keyword_release(keyword)
     125              : 
     126              :       CALL keyword_create(keyword, __LOCATION__, name="XALMO_EXTRAPOLATION_ORDER", &
     127              :                           description="Number of previous states used for the ASPC extrapolation of the initial guess "// &
     128              :                           "for the delocalization correction.", &
     129        10356 :                           usage="XALMO_EXTRAPOLATION_ORDER 1", default_i_val=0)
     130        10356 :       CALL section_add_keyword(section, keyword)
     131        10356 :       CALL keyword_release(keyword)
     132              : 
     133              :       CALL keyword_create(keyword, __LOCATION__, name="ALMO_ALGORITHM", &
     134              :                           description="Specifies the algorithm to update block-diagonal ALMOs during the SCF procedure.", &
     135              :                           usage="ALMO_ALGORITHM DIAG", &
     136              :                           default_i_val=almo_scf_diag, &
     137              :                           !enum_c_vals=s2a("DIAG", "DM_SIGN","PCG"),&
     138              :                           enum_c_vals=s2a("DIAG", "PCG", "TRUST_REGION", "SKIP"), &
     139              :                           enum_desc=s2a("DIIS-accelerated diagonalization controlled by ALMO_OPTIMIZER_DIIS. "// &
     140              :                                         "Recommended for large systems containing small fragments.", &
     141              :                                         !"Update the density matrix using linear scaling routines. "//&
     142              :                                         !"Recommended if large fragments are present.",&
     143              :                                         "Energy minimization with a PCG algorithm controlled by ALMO_OPTIMIZER_PCG.", &
     144              :                                         "Trust-region optimizer is recommended if PCG has difficulty converging. "// &
     145              :                                         "It is controlled by ALMO_OPTIMIZER_TRUSTR", &
     146              :                                         "Skip optimization of block-diagonal ALMOs."), &
     147              :                           !enum_i_vals=(/almo_scf_diag,almo_scf_dm_sign,almo_scf_pcg/),&
     148        10356 :                           enum_i_vals=[almo_scf_diag, almo_scf_pcg, almo_scf_trustr, almo_scf_skip])
     149        10356 :       CALL section_add_keyword(section, keyword)
     150        10356 :       CALL keyword_release(keyword)
     151              : 
     152              :       CALL keyword_create(keyword, __LOCATION__, name="XALMO_ALGORITHM", &
     153              :                           description="Specifies the algorithm to update ALMOs on eXtended domains (XALMOs).", &
     154              :                           usage="XALMO_ALGORITHM TRUST_REGION", &
     155              :                           default_i_val=almo_scf_pcg, &
     156              :                           enum_c_vals=s2a("DIAG", "PCG", "TRUST_REGION"), &
     157              :                           enum_desc=s2a("DIIS-accelerated diagonalization.", &
     158              :                                         "PCG algorithm controlled by XALMO_OPTIMIZER_PCG.", &
     159              :                                         "Trust-region optimizer controlled by XALMO_OPTIMIZER_TRUSTR"), &
     160        10356 :                           enum_i_vals=[almo_scf_diag, almo_scf_pcg, almo_scf_trustr])
     161        10356 :       CALL section_add_keyword(section, keyword)
     162        10356 :       CALL keyword_release(keyword)
     163              : 
     164              :       CALL keyword_create(keyword, __LOCATION__, name="XALMO_TRIAL_WF", &
     165              :                           description="Determines the form of the trial XALMOs.", &
     166              :                           usage="XALMO_TRIAL_WF SIMPLE", &
     167              :                           default_i_val=xalmo_trial_r0_out, &
     168              :                           enum_c_vals=s2a("SIMPLE", "PROJECT_R0_OUT"), &
     169              :                           enum_desc=s2a("Straightforward AO-basis expansion.", &
     170              :                                         "Block-diagonal ALMOs plus the XALMO term projected onto the unoccupied "// &
     171              :                                         "ALMO-subspace."), &
     172        10356 :                           enum_i_vals=[xalmo_trial_simplex, xalmo_trial_r0_out])
     173        10356 :       CALL section_add_keyword(section, keyword)
     174        10356 :       CALL keyword_release(keyword)
     175              : 
     176              :       CALL keyword_create( &
     177              :          keyword, __LOCATION__, name="DELOCALIZE_METHOD", &
     178              :          description="Methods to reintroduce electron delocalization, which is excluded "// &
     179              :          "with the block-diagonal ALMO reference. Electron delocalization can "// &
     180              :          "be computed using either fully delocalized MOs or spatially restricted "// &
     181              :          "ALMOs (called eXtended ALMOs or XALMOs). All methods below use either a PCG or trust-region "// &
     182              :          "optimizers controlled by XALMO_OPTIMIZER_* subsections. The only exception is "// &
     183              :          "the non-iterative XALMO_1DIAG.", &
     184              :          usage="DELOCALIZE_METHOD XALMO_X", &
     185              :          default_i_val=almo_deloc_xalmo_x, &
     186              :          enum_c_vals=s2a("NONE", "XALMO_1DIAG", "XALMO_X", "XALMO_SCF", "FULL_X", "FULL_SCF", "FULL_X_THEN_SCF"), &
     187              :          enum_desc=s2a("Neglect electron delocalization", &
     188              :                        "Correction based on one diagonalization of the spatially projected Hamiltonian (XALMO)", &
     189              :                        "Single excitation correction (no Hamiltonian re-build) with spatial restrictions (XALMO)", &
     190              :                        "Self-consistent treatment of delocalization with spatial restrictions (XALMO)", &
     191              :                        "Single excitation correction (no Hamiltonian re-build) without spatial restrictions", &
     192              :                        "Self-consistent treatment of delocalization without spatial restrictions", &
     193              :                        "Single excitation correction followed by full SCF procedure, both without spatial restrictions"), &
     194              :          enum_i_vals=[almo_deloc_none, almo_deloc_xalmo_1diag, almo_deloc_xalmo_x, almo_deloc_xalmo_scf, &
     195        10356 :                       almo_deloc_x, almo_deloc_scf, almo_deloc_x_then_scf])
     196        10356 :       CALL section_add_keyword(section, keyword)
     197        10356 :       CALL keyword_release(keyword)
     198              : 
     199              :       CALL keyword_create(keyword, __LOCATION__, name="XALMO_R_CUTOFF_FACTOR", &
     200              :                           description="Controls the localization radius of XALMOs: "// &
     201              :                           !"r0 = r0_factor*(radius(at1)+radius(at2)) + r0_shift",&
     202              :                           "R_cutoff = XALMO_R_CUTOFF_FACTOR*(radius(at1)+radius(at2))", &
     203        10356 :                           usage="XALMO_R_CUTOFF_FACTOR 1.6", default_r_val=1.50_dp)
     204        10356 :       CALL section_add_keyword(section, keyword)
     205        10356 :       CALL keyword_release(keyword)
     206              : 
     207              :       CALL keyword_create(keyword, __LOCATION__, name="RETURN_ORTHOGONALIZED_MOS", &
     208              :                           description="Orthogonalize final ALMOs before they are returned "// &
     209              :                           "to Quickstep (i.e. for calculation of properties)", &
     210              :                           usage="RETURN_ORTHOGONALIZED_MOS .TRUE.", default_l_val=.TRUE., &
     211        10356 :                           lone_keyword_l_val=.TRUE.)
     212        10356 :       CALL section_add_keyword(section, keyword)
     213        10356 :       CALL keyword_release(keyword)
     214              : 
     215              :       CALL keyword_create(keyword, __LOCATION__, name="CONSTRUCT_NLMOS", &
     216              :                           description="Turns on post-SCF construction of NLMOs", &
     217        10356 :                           usage="CONSTRUCT_NLMOS .TRUE.", default_l_val=.FALSE.)
     218        10356 :       CALL section_add_keyword(section, keyword)
     219        10356 :       CALL keyword_release(keyword)
     220              : 
     221              :       !CALL keyword_create(keyword, __LOCATION__, name="DOMAIN_LAYOUT_MOS",&
     222              :       !     description="Each electron in the system is constrained to its own delocalization domain."//&
     223              :       !     " This keyword creates groups of electrons that share the same domain.",&
     224              :       !     usage="DOMAIN_LAYOUT_MOS MOLECULAR",&
     225              :       !     default_i_val=almo_domain_layout_molecular,&
     226              :       !     enum_c_vals=s2a( "ORBITAL", "ATOMIC", "MOLECULAR"),&
     227              :       !     enum_desc=s2a("Each electron can have its own delocalization domain",&
     228              :       !     "All electrons of an atom are delocalized over the same domain",&
     229              :       !     "All electrons of a molecule are delocalized over the same domain."//&
     230              :       !     " This is the only implemented option"),&
     231              :       !     enum_i_vals=(/almo_domain_layout_orbital,almo_domain_layout_atomic,almo_domain_layout_molecular/))
     232              :       !CALL section_add_keyword(section,keyword)
     233              :       !CALL keyword_release(keyword)
     234              : 
     235              :       !CALL keyword_create(keyword, __LOCATION__, name="DOMAIN_LAYOUT_AOS",&
     236              :       !     description="Atomic orbitals or groups of atomic orbitals represent domains over which electrons "//&
     237              :       !     "can be delocalized. This keyword imposes constraints on the structure of domains",&
     238              :       !     usage="DOMAIN_LAYOUT_MOS MOLECULAR",&
     239              :       !     default_i_val=almo_domain_layout_molecular,&
     240              :       !     enum_c_vals=s2a("ATOMIC", "MOLECULAR"),&
     241              :       !     enum_desc=s2a("Atomic blocks represent domains. That is, if a basis function on an atom is in"//&
     242              :       !     " domain A then all basis functions on this atom are in domain A.",&
     243              :       !     "Molecular subsets represent domains. That is, if a basis function on a molecule is"//&
     244              :       !     " in domain A then all basis functions on this molecule are in domain A. "//&
     245              :       !     "This is the only implemented option"),&
     246              :       !     enum_i_vals=(/almo_domain_layout_atomic,almo_domain_layout_molecular/))
     247              :       !CALL section_add_keyword(section,keyword)
     248              :       !CALL keyword_release(keyword)
     249              : 
     250              :       !CALL keyword_create(keyword, __LOCATION__, name="MATRIX_CLUSTERING_MOS",&
     251              :       !     description="Blocks of matrices in the MO basis set are distributed for parallel computations. "//&
     252              :       !     "This keywords specifies the type of matrix blocks.",&
     253              :       !     usage="MATRIX_CLUSTERING_MOS MOLECULAR",&
     254              :       !     default_i_val=almo_mat_distr_molecular,&
     255              :       !     enum_c_vals=s2a("ATOMIC", "MOLECULAR"),&
     256              :       !     enum_desc=s2a("Not recommended. ZZZ Maybe used for the PAO-based methods in the future",&
     257              :       !                   "All molecular orbitals of a molecule belong to the same block."),&
     258              :       !     enum_i_vals=(/almo_mat_distr_atomic,almo_mat_distr_molecular/))
     259              :       !CALL section_add_keyword(section,keyword)
     260              :       !CALL keyword_release(keyword)
     261              : 
     262              :       !CALL keyword_create(keyword, __LOCATION__, name="MATRIX_CLUSTERING_AOS",&
     263              :       !     description="Blocks of matrices in the AO basis set are distributed for parallel computations."//&
     264              :       !     " This keywords specifies the type of matrix blocks.",&
     265              :       !     usage="MATRIX_CLUSTERING_AOS MOLECULAR",&
     266              :       !     default_i_val=almo_mat_distr_molecular,&
     267              :       !     enum_c_vals=s2a("ATOMIC", "MOLECULAR"),&
     268              :       !     enum_desc=s2a("All atomic orbitals of an atom belong to the "//&
     269              :       !     "same block. Use only if there are very large molecules in the system. "//&
     270              :       !     "ZZZ Maybe used for the PAO-based methods in the future",&
     271              :       !     "All atomic orbitals of a molecule belong to the same block."),&
     272              :       !     enum_i_vals=(/almo_mat_distr_atomic,almo_mat_distr_molecular/))
     273              :       !CALL section_add_keyword(section,keyword)
     274              :       !CALL keyword_release(keyword)
     275              : 
     276              :       !CALL keyword_create(keyword, __LOCATION__, name="CONSTRAINT_TYPE",&
     277              :       !     description="Determines the type of ALMO constraints",&
     278              :       !     usage="CONSTRAINT_TYPE BLOCK_DIAGONAL",&
     279              :       !     default_i_val=almo_constraint_block_diagonal,&
     280              :       !     enum_c_vals=s2a("BLOCK_DIAGONAL", "DISTANCE", "AO_OVERLAP"),&
     281              :       !     enum_desc=s2a("MO coefficient matrix is block-diagonal",&
     282              :       !     "MO coefficients are quenched according to the distance criterion",&
     283              :       !     "MO coefficients are quenched according to the AO overlap criterion"),&
     284              :       !     enum_i_vals=(/almo_constraint_block_diagonal,almo_constraint_distance,&
     285              :       !     almo_constraint_ao_overlap/))
     286              :       !CALL section_add_keyword(section,keyword)
     287              :       !CALL keyword_release(keyword)
     288              : 
     289              :       !CALL keyword_create(keyword, __LOCATION__, name="QUENCHER_RADIUS_TYPE",&
     290              :       !     description="Determines the type of atomic radii used for imposing the ALMO constraints",&
     291              :       !     usage="QUENCHER_RADIUS_TYPE VDW",&
     292              :       !     default_i_val=do_bondparm_vdw,&
     293              :       !     enum_c_vals=s2a("COVALENT", "VDW"),&
     294              :       !     enum_desc=s2a("Covalent atomic radii",&
     295              :       !     "Van der Waals atomic radii"),&
     296              :       !     enum_i_vals=(/do_bondparm_covalent,do_bondparm_vdw/))
     297              :       !CALL section_add_keyword(section,keyword)
     298              :       !CALL keyword_release(keyword)
     299              : 
     300              :       !CALL keyword_create(keyword, __LOCATION__, name="QUENCHER_R0_FACTOR",&
     301              :       !     description="Parameter to calculate the inner soft cutoff radius: "//&
     302              :       !     !"r0 = r0_factor*(radius(at1)+radius(at2)) + r0_shift",&
     303              :       !     "r0 = r0_factor*(radius(at1)+radius(at2))",&
     304              :       !     usage="QUENCHER_R0_FACTOR 1.05", default_r_val=1.05_dp)
     305              :       !CALL section_add_keyword(section,keyword)
     306              :       !CALL keyword_release(keyword)
     307              : 
     308              :       !!CALL keyword_create(keyword, __LOCATION__, name="QUENCHER_R0_SHIFT",&
     309              :       !!     description="Parameter to calculate the inner soft cutoff radius (in Angstrom): "//&
     310              :       !!     "r0 = r0_factor*(radius(at1)+radius(at2)) + r0_shift",&
     311              :       !!     usage="QUENCHER_R0_SHIFT 0.0", default_r_val=0.0_dp)
     312              :       !!
     313              :       !!CALL section_add_keyword(section,keyword)
     314              :       !!CALL keyword_release(keyword)
     315              : 
     316              :       !CALL keyword_create(keyword, __LOCATION__, name="QUENCHER_R1_FACTOR",&
     317              :       !     description="Parameter to calculate the outer soft cutoff radius: "//&
     318              :       !     !"r1 = r1_factor*(radius(at1)+radius(at2)) + r1_shift",&
     319              :       !     "r1 = r1_factor*(radius(at1)+radius(at2))",&
     320              :       !     usage="QUENCHER_R1_FACTOR 1.55", default_r_val=1.55_dp)
     321              :       !CALL section_add_keyword(section,keyword)
     322              :       !CALL keyword_release(keyword)
     323              : 
     324              :       !!CALL keyword_create(keyword, __LOCATION__, name="QUENCHER_R1_SHIFT",&
     325              :       !!     description="Parameter to calculate the outer soft cutoff radius (in Angstrom): "//&
     326              :       !!     "r1 = r1_factor*(radius(at1)+radius(at2)) + r1_shift",&
     327              :       !!     usage="QUENCHER_R1_SHIFT 0.0", default_r_val=0.0_dp)
     328              :       !!
     329              :       !!CALL section_add_keyword(section,keyword)
     330              :       !!CALL keyword_release(keyword)
     331              : 
     332              :       !CALL keyword_create(keyword, __LOCATION__, name="QUENCHER_AO_OVERLAP_0",&
     333              :       !     description="Overlap value of the inner soft cutoff",&
     334              :       !     usage="QUENCHER_AO_OVERLAP_0 1.0E-4", default_r_val=1.0E-4_dp)
     335              :       !CALL section_add_keyword(section,keyword)
     336              :       !CALL keyword_release(keyword)
     337              : 
     338              :       !CALL keyword_create(keyword, __LOCATION__, name="QUENCHER_AO_OVERLAP_1",&
     339              :       !     description="Overlap value of the outer soft cutoff",&
     340              :       !     usage="QUENCHER_AO_OVERLAP_1 1.0E-6", default_r_val=1.0E-6_dp)
     341              :       !CALL section_add_keyword(section,keyword)
     342              :       !CALL keyword_release(keyword)
     343              : 
     344              :       !CALL keyword_create(keyword, __LOCATION__, name="ENVELOPE_AMPLITUDE",&
     345              :       !     description="Defines an upper bound on the maximum norm of the MO coefficients",&
     346              :       !     usage="ENVELOPE_AMPLITUDE 1.0", default_r_val=1.0_dp)
     347              :       !CALL section_add_keyword(section,keyword)
     348              :       !CALL keyword_release(keyword)
     349              : 
     350              :       !CALL keyword_create(keyword, __LOCATION__, name="DELOC_CAYLEY_TENSOR_TYPE",&
     351              :       !     description="Tensor properties of occupied and virtual indices",&
     352              :       !     usage="DELOC_CAYLEY_TENSOR_TYPE ORTHOGONAL",&
     353              :       !     default_i_val=tensor_orthogonal,&
     354              :       !     enum_c_vals=s2a("ORTHOGONAL", "BIORTHOGONAL"),&
     355              :       !     enum_desc=s2a("Orthogonalize both occupied and virtual orbitals",&
     356              :       !     "Contravariant virtual (MOs or AOs) and covariant occupied orbitals"),&
     357              :       !     enum_i_vals=(/tensor_orthogonal,tensor_up_down/))
     358              :       !CALL section_add_keyword(section,keyword)
     359              :       !CALL keyword_release(keyword)
     360              : 
     361              :       !CALL keyword_create(keyword, __LOCATION__, name="DELOC_CAYLEY_CONJUGATOR",&
     362              :       !     description="Various methods to compute step directions in the CG algorithm",&
     363              :       !     usage="DELOC_CAYLEY_CONJUGATOR POLAK_RIBIERE",&
     364              :       !     default_i_val=cg_hager_zhang,&
     365              :       !     enum_c_vals=s2a("ZERO", "POLAK_RIBIERE", "FLETCHER_REEVES",&
     366              :       !     "HESTENES_STIEFEL", "FLETCHER", "LIU_STOREY", "DAI_YUAN","HAGER_ZHANG"),&
     367              :       !     enum_desc=s2a("Steepest descent","Polak and Ribiere",&
     368              :       !     "Fletcher and Reeves","Hestenes and Stiefel",&
     369              :       !     "Fletcher (Conjugate descent)","Liu and Storey",&
     370              :       !     "Dai and Yuan","Hager and Zhang"),&
     371              :       !     enum_i_vals=(/cg_zero,cg_polak_ribiere,cg_fletcher_reeves,&
     372              :       !                   cg_hestenes_stiefel,cg_fletcher,cg_liu_storey,&
     373              :       !                   cg_dai_yuan,cg_hager_zhang/))
     374              :       !CALL section_add_keyword(section,keyword)
     375              :       !CALL keyword_release(keyword)
     376              : 
     377              :       !CALL keyword_create(keyword, __LOCATION__, name="DELOC_CAYLEY_MAX_ITER",&
     378              :       !     description="Maximum number of CG iterations to solve Ricatti equations",&
     379              :       !     usage="DELOC_CAYLEY_MAX_ITER 100",default_i_val=50)
     380              :       !CALL section_add_keyword(section,keyword)
     381              :       !CALL keyword_release(keyword)
     382              : 
     383              :       !CALL keyword_create(keyword, __LOCATION__, name="DELOC_CAYLEY_EPS_CONVERGENCE",&
     384              :       !     description="Convergence criterion of the CG algorithm",&
     385              :       !     usage="DELOC_CAYLEY_EPS_CONVERGENCE 1.e-6", default_r_val=1.e-7_dp)
     386              :       !CALL section_add_keyword(section,keyword)
     387              :       !CALL keyword_release(keyword)
     388              : 
     389              :       !CALL keyword_create(keyword, __LOCATION__, name="DELOC_CAYLEY_VIR_PRECOND",&
     390              :       !     description="Use preconditioner for the virtual subspace",&
     391              :       !     usage="DELOC_CAYLEY_VIR_PRECOND .TRUE.", default_l_val=.TRUE.,&
     392              :       !     lone_keyword_l_val=.TRUE.)
     393              :       !CALL section_add_keyword(section,keyword)
     394              :       !CALL keyword_release(keyword)
     395              : 
     396              :       !CALL keyword_create(keyword, __LOCATION__, name="DELOC_CAYLEY_OCC_PRECOND",&
     397              :       !     description="Use preconditioner for the occupied subspace",&
     398              :       !     usage="DELOC_CAYLEY_OCC_PRECOND .TRUE.", default_l_val=.TRUE.,&
     399              :       !     lone_keyword_l_val=.TRUE.)
     400              :       !CALL section_add_keyword(section,keyword)
     401              :       !CALL keyword_release(keyword)
     402              : 
     403              :       !CALL keyword_create(keyword, __LOCATION__, name="DELOC_TRUNCATE_VIRTUALS",&
     404              :       !     description="Truncation of the virtual subspace",&
     405              :       !     usage="DELOC_TRUNCATE_VIRTUALS MINIMAL",&
     406              :       !     default_i_val=virt_full,&
     407              :       !     enum_c_vals=s2a("FULL", "MINIMAL","OCC_SIZE", "EXACT_NUMBER_PER_DOMAIN"),&
     408              :       !     enum_desc=s2a("Keep all virtual orbitals","Retained virtuals "//&
     409              :       !     "complement occupied orbitals to form the minimal basis set",&
     410              :       !     "Number of virtuals is equal to the number of occupied orbitals",&
     411              :       !     "Specify exact number of virtuals per domain with DELOC_VIRT_PER_DOMAIN"),&
     412              :       !     enum_i_vals=(/virt_full,virt_minimal,virt_occ_size,&
     413              :       !                   virt_number/))
     414              :       !CALL section_add_keyword(section,keyword)
     415              :       !CALL keyword_release(keyword)
     416              : 
     417              :       !CALL keyword_create(keyword, __LOCATION__, name="DELOC_VIRT_PER_DOMAIN",&
     418              :       !     description="Number of virtual orbitals (per domain, atom or molecule) "//&
     419              :       !     "retained to obtain the delocalization correction",&
     420              :       !     usage="DELOC_VIRT_PER_DOMAIN",default_i_val=-1)
     421              :       !CALL section_add_keyword(section,keyword)
     422              :       !CALL keyword_release(keyword)
     423              : 
     424              :       !CALL keyword_create(keyword, __LOCATION__, name="DELOC_USE_OCC_ORBS",&
     425              :       !     description="Use occupied orbitals (as opposed to density matrix) "//&
     426              :       !     "to calculate correction for electron delocalization",&
     427              :       !     usage="DELOC_USE_OCC_ORBS .TRUE.", default_l_val=.TRUE.,&
     428              :       !     lone_keyword_l_val=.TRUE.)
     429              :       !CALL section_add_keyword(section,keyword)
     430              :       !CALL keyword_release(keyword)
     431              : 
     432              :       !CALL keyword_create(keyword, __LOCATION__, name="DELOC_CAYLEY_USE_VIRT_ORBS",&
     433              :       !     description="Use virtual orbitals (as opposed to the 1-P projector) "//&
     434              :       !     "to calculate correction for electron delocalization. Works only if "//&
     435              :       !     "DELOC_USE_OCC_ORBS is set to TRUE",&
     436              :       !     usage="DELOC_CAYLEY_USE_VIRT_ORBS .TRUE.", default_l_val=.FALSE.,&
     437              :       !     lone_keyword_l_val=.TRUE.)
     438              :       !CALL section_add_keyword(section,keyword)
     439              :       !CALL keyword_release(keyword)
     440              : 
     441              :       !CALL keyword_create(keyword, __LOCATION__, name="DELOC_CAYLEY_LINEAR",&
     442              :       !     description="Neglect the quadratic term in the Riccati equations. "//&
     443              :       !     "Equivalent to the first order correction to the occupied orbitals "//&
     444              :       !     "(second order correction to the energy)",&
     445              :       !     usage="DELOC_CAYLEY_LINEAR .FALSE.", default_l_val=.FALSE.,&
     446              :       !     lone_keyword_l_val=.TRUE.)
     447              :       !CALL section_add_keyword(section,keyword)
     448              :       !CALL keyword_release(keyword)
     449              : 
     450              :       !CALL keyword_create(keyword, __LOCATION__, name="OPT_K_OUTER_MAX_ITER",&
     451              :       !     description="Maximum number of outer loop iterations to optimize retained virtual orbitals",&
     452              :       !     usage="OPT_K_OUTER_MAX_ITER 10",default_i_val=1)
     453              :       !CALL section_add_keyword(section,keyword)
     454              :       !CALL keyword_release(keyword)
     455              : 
     456              :       !CALL keyword_create(keyword, __LOCATION__, name="OPT_K_MAX_ITER",&
     457              :       !     description="Maximum number of iterations to optimize retained virtual orbitals",&
     458              :       !     usage="OPT_K_MAX_ITER 100",default_i_val=100)
     459              :       !CALL section_add_keyword(section,keyword)
     460              :       !CALL keyword_release(keyword)
     461              : 
     462              :       !CALL keyword_create(keyword, __LOCATION__, name="OPT_K_EPS_CONVERGENCE",&
     463              :       !     description="Convergence criterion of the optimization algorithm",&
     464              :       !     usage="OPT_K_EPS_CONVERGENCE 1.e-5", default_r_val=1.e-5_dp)
     465              :       !CALL section_add_keyword(section,keyword)
     466              :       !CALL keyword_release(keyword)
     467              : 
     468              :       !CALL keyword_create(keyword, __LOCATION__, name="OPT_K_TRIAL_STEP_SIZE",&
     469              :       !     description="Size of the trial step along the gradient",&
     470              :       !     usage="OPT_K_TRIAL_STEP_SIZE 0.05", default_r_val=0.05_dp)
     471              :       !CALL section_add_keyword(section,keyword)
     472              :       !CALL keyword_release(keyword)
     473              : 
     474              :       !CALL keyword_create(keyword, __LOCATION__, name="OPT_K_TRIAL_STEP_SIZE_MULTIPLIER",&
     475              :       !     description="The trial step size is obtained by multiplying the optimal step size "//&
     476              :       !     "from the previous iteration",&
     477              :       !     usage="OPT_K_TRIAL_STEP_SIZE_multiplier 1.0", default_r_val=1.4_dp)
     478              :       !CALL section_add_keyword(section,keyword)
     479              :       !CALL keyword_release(keyword)
     480              : 
     481              :       !CALL keyword_create(keyword, __LOCATION__, name="OPT_K_CONJ_ITER_START",&
     482              :       !     description="Iteration for switching from the steepest descent algorithm "//&
     483              :       !     "to conjugate gradient",&
     484              :       !     usage="OPT_K_CONJ_ITER_START 5",default_i_val=0)
     485              :       !CALL section_add_keyword(section,keyword)
     486              :       !CALL keyword_release(keyword)
     487              : 
     488              :       !CALL keyword_create(keyword, __LOCATION__, name="OPT_K_CONJ_ITER_FREQ_RESET",&
     489              :       !     description="Reset frequency of the conjugate gradient direction",&
     490              :       !     usage="OPT_K_CONJ_ITER_FREQ_RESET 20",default_i_val=1000000)
     491              :       !CALL section_add_keyword(section,keyword)
     492              :       !CALL keyword_release(keyword)
     493              : 
     494              :       !CALL keyword_create(keyword, __LOCATION__, name="OPT_K_CONJUGATOR",&
     495              :       !     description="Various methods to compute step directions in the CG algorithm",&
     496              :       !     usage="OPT_K_CONJUGATOR POLAK_RIBIERE",&
     497              :       !     default_i_val=cg_hager_zhang,&
     498              :       !     enum_c_vals=s2a("ZERO", "POLAK_RIBIERE", "FLETCHER_REEVES",&
     499              :       !     "HESTENES_STIEFEL", "FLETCHER", "LIU_STOREY", "DAI_YUAN","HAGER_ZHANG"),&
     500              :       !     enum_desc=s2a("Steepest descent","Polak and Ribiere",&
     501              :       !     "Fletcher and Reeves","Hestenes and Stiefel",&
     502              :       !     "Fletcher (Conjugate descent)","Liu and Storey",&
     503              :       !     "Dai and Yuan","Hager and Zhang"),&
     504              :       !     enum_i_vals=(/cg_zero,cg_polak_ribiere,cg_fletcher_reeves,&
     505              :       !                   cg_hestenes_stiefel,cg_fletcher,cg_liu_storey,&
     506              :       !                   cg_dai_yuan,cg_hager_zhang/))
     507              :       !CALL section_add_keyword(section,keyword)
     508              :       !CALL keyword_release(keyword)
     509              : 
     510              :       !CALL keyword_create(keyword, __LOCATION__, name="OPT_K_PREC_ITER_START",&
     511              :       !     description="Start using the preconditioner (approximate preconditioners "//&
     512              :       !     "might not be valid on early iterations)",&
     513              :       !     usage="OPT_K_PREC_ITER_START 2",default_i_val=0)
     514              :       !CALL section_add_keyword(section,keyword)
     515              :       !CALL keyword_release(keyword)
     516              : 
     517        10356 :       NULLIFY (subsection)
     518        10356 :       CALL create_almo_fragment_section(subsection)
     519        10356 :       CALL section_add_subsection(section, subsection)
     520        10356 :       CALL section_release(subsection)
     521              : 
     522        10356 :       NULLIFY (subsection)
     523        10356 :       CALL create_optimizer_section(subsection, optimizer_block_diagonal_diis)
     524        10356 :       CALL section_add_subsection(section, subsection)
     525        10356 :       CALL section_release(subsection)
     526              : 
     527        10356 :       NULLIFY (subsection)
     528        10356 :       CALL create_optimizer_section(subsection, optimizer_block_diagonal_pcg)
     529        10356 :       CALL section_add_subsection(section, subsection)
     530        10356 :       CALL section_release(subsection)
     531              : 
     532        10356 :       NULLIFY (subsection)
     533        10356 :       CALL create_optimizer_section(subsection, optimizer_block_diagonal_trustr)
     534        10356 :       CALL section_add_subsection(section, subsection)
     535        10356 :       CALL section_release(subsection)
     536              : 
     537        10356 :       NULLIFY (subsection)
     538        10356 :       CALL create_optimizer_section(subsection, optimizer_xalmo_pcg)
     539        10356 :       CALL section_add_subsection(section, subsection)
     540        10356 :       CALL section_release(subsection)
     541              : 
     542        10356 :       NULLIFY (subsection)
     543        10356 :       CALL create_optimizer_section(subsection, optimizer_xalmo_trustr)
     544        10356 :       CALL section_add_subsection(section, subsection)
     545        10356 :       CALL section_release(subsection)
     546              : 
     547        10356 :       NULLIFY (subsection)
     548        10356 :       CALL create_optimizer_section(subsection, optimizer_nlmo_pcg)
     549        10356 :       CALL section_add_subsection(section, subsection)
     550        10356 :       CALL section_release(subsection)
     551              : 
     552        10356 :       NULLIFY (subsection)
     553        10356 :       CALL create_matrix_iterate_section(subsection)
     554        10356 :       CALL section_add_subsection(section, subsection)
     555        10356 :       CALL section_release(subsection)
     556              : 
     557        10356 :       NULLIFY (subsection)
     558        10356 :       CALL create_almo_analysis_section(subsection)
     559        10356 :       CALL section_add_subsection(section, subsection)
     560        10356 :       CALL section_release(subsection)
     561              : 
     562        10356 :    END SUBROUTINE create_almo_scf_section
     563              : 
     564              : ! **************************************************************************************************
     565              : !> \brief The optimizer section is a collection of keywords that are similar
     566              : !>        to all optimization methods (e.g. target error, number of iterations)
     567              : !> \param section ...
     568              : !> \param optimizer_id   allows to adapt the standard section for specific needs
     569              : !> \par History
     570              : !>       2012.03 created [Rustam Z Khaliullin]
     571              : !>       2014.10 fully integrated [Rustam Z Khaliullin]
     572              : !> \author Rustam Z Khaliullin
     573              : ! **************************************************************************************************
     574        72492 :    RECURSIVE SUBROUTINE create_optimizer_section(section, optimizer_id)
     575              : 
     576              :       TYPE(section_type), POINTER                        :: section
     577              :       INTEGER, INTENT(IN)                                :: optimizer_id
     578              : 
     579              :       INTEGER                                            :: optimizer_type
     580              :       TYPE(keyword_type), POINTER                        :: keyword
     581              :       TYPE(section_type), POINTER                        :: subsection
     582              : 
     583        72492 :       CPASSERT(.NOT. ASSOCIATED(section))
     584        72492 :       NULLIFY (section)
     585              : 
     586              :       ! choose the name of the section
     587        82848 :       SELECT CASE (optimizer_id)
     588              :       CASE (optimizer_block_diagonal_diis)
     589              :          CALL section_create(section, __LOCATION__, name="ALMO_OPTIMIZER_DIIS", &
     590              :                              description="Controls the iterative DIIS-accelerated optimization of block-diagonal ALMOs.", &
     591        10356 :                              n_keywords=5, n_subsections=0, repeats=.FALSE.)
     592        10356 :          optimizer_type = optimizer_diis
     593              :       CASE (optimizer_block_diagonal_pcg)
     594              :          CALL section_create(section, __LOCATION__, name="ALMO_OPTIMIZER_PCG", &
     595              :                              description="Controls the PCG optimization of block-diagonal ALMOs.", &
     596        10356 :                              n_keywords=9, n_subsections=1, repeats=.FALSE.)
     597        10356 :          optimizer_type = optimizer_pcg
     598              :       CASE (optimizer_nlmo_pcg)
     599              :          CALL section_create(section, __LOCATION__, name="NLMO_OPTIMIZER_PCG", &
     600              :                              description="Controls the PCG optimization of nonorthogonal localized MOs.", &
     601        10356 :                              n_keywords=9, n_subsections=1, repeats=.FALSE.)
     602        10356 :          optimizer_type = optimizer_pcg
     603        10356 :          NULLIFY (subsection)
     604        10356 :          CALL create_penalty_section(subsection)
     605        10356 :          CALL section_add_subsection(section, subsection)
     606        10356 :          CALL section_release(subsection)
     607              :       CASE (optimizer_xalmo_pcg)
     608              :          CALL section_create(section, __LOCATION__, name="XALMO_OPTIMIZER_PCG", &
     609              :                              description="Controls the PCG optimization of extended ALMOs.", &
     610        10356 :                              n_keywords=10, n_subsections=2, repeats=.FALSE.)
     611        10356 :          NULLIFY (subsection)
     612        10356 :          CALL create_optimizer_section(subsection, optimizer_newton_pcg_solver)
     613        10356 :          CALL section_add_subsection(section, subsection)
     614        10356 :          CALL section_release(subsection)
     615        10356 :          optimizer_type = optimizer_pcg
     616              :       CASE (optimizer_xalmo_trustr)
     617              :          CALL section_create(section, __LOCATION__, name="XALMO_OPTIMIZER_TRUSTR", &
     618              :                              description="Controls the trust-region optimization of extended ALMOs. "// &
     619              :                              "Trust radius is varied in the outer loop. Once the trust radius is "// &
     620              :                              "chosen (and fixed) the model function can be minized using various "// &
     621              :                              "approaches. Currently, an iterative conjugate-gradient approach is "// &
     622              :                              "used and controlled by the inner loop", &
     623        10356 :                              n_keywords=10, n_subsections=0, repeats=.FALSE.)
     624        10356 :          optimizer_type = optimizer_trustr
     625              :       CASE (optimizer_block_diagonal_trustr)
     626              :          CALL section_create(section, __LOCATION__, name="ALMO_OPTIMIZER_TRUSTR", &
     627              :                              description="Controls the trust-region optimization of block-diagonal ALMOs. "// &
     628              :                              "See XALMO_OPTIMIZER_TRUSTR section for brief explanations.", &
     629        10356 :                              n_keywords=10, n_subsections=0, repeats=.FALSE.)
     630        10356 :          optimizer_type = optimizer_trustr
     631              :       CASE (optimizer_newton_pcg_solver)
     632              :          CALL section_create(section, __LOCATION__, name="XALMO_NEWTON_PCG_SOLVER", &
     633              :                              description="Controls an iterative solver of the Newton-Raphson linear equation.", &
     634        10356 :                              n_keywords=4, n_subsections=0, repeats=.FALSE.)
     635        10356 :          optimizer_type = optimizer_lin_eq_pcg
     636              :       CASE DEFAULT
     637        72492 :          CPABORT("No default values allowed")
     638              :       END SELECT
     639              : 
     640        72492 :       NULLIFY (keyword)
     641              : 
     642              :       ! add common keywords
     643              :       CALL keyword_create(keyword, __LOCATION__, name="MAX_ITER", &
     644              :                           description="Maximum number of iterations", &
     645        72492 :                           usage="MAX_ITER 100", default_i_val=20)
     646        72492 :       CALL section_add_keyword(section, keyword)
     647        72492 :       CALL keyword_release(keyword)
     648              : 
     649              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_ERROR", &
     650              :                           description="Target value of the MAX norm of the error", &
     651        72492 :                           usage="EPS_ERROR 1.E-6", default_r_val=1.0E-5_dp)
     652        72492 :       CALL section_add_keyword(section, keyword)
     653        72492 :       CALL keyword_release(keyword)
     654              : 
     655              :       ! add common keywords
     656              :       CALL keyword_create(keyword, __LOCATION__, name="MAX_ITER_EARLY", &
     657              :                           description="Maximum number of iterations for truncated SCF "// &
     658              :                           "(e.g. Langevin-corrected MD). Negative values mean that this keyword is not used.", &
     659        72492 :                           usage="MAX_ITER_EARLY 5", default_i_val=-1)
     660        72492 :       CALL section_add_keyword(section, keyword)
     661        72492 :       CALL keyword_release(keyword)
     662              : 
     663              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_ERROR_EARLY", &
     664              :                           description="Target value of the MAX norm of the error for truncated SCF "// &
     665              :                           "(e.g. Langevin-corrected MD). Negative values mean that this keyword is not used.", &
     666        72492 :                           usage="EPS_ERROR_EARLY 1.E-2", default_r_val=-1.0_dp)
     667        72492 :       CALL section_add_keyword(section, keyword)
     668        72492 :       CALL keyword_release(keyword)
     669              : 
     670              :       ! add keywords specific to each type
     671        72492 :       IF (optimizer_type == optimizer_diis) THEN
     672              : 
     673              :          CALL keyword_create(keyword, __LOCATION__, name="N_DIIS", &
     674              :                              description="Number of error vectors to be used in the DIIS "// &
     675              :                              "optimization procedure", &
     676        10356 :                              usage="N_DIIS 5", default_i_val=6)
     677        10356 :          CALL section_add_keyword(section, keyword)
     678        10356 :          CALL keyword_release(keyword)
     679              : 
     680              :       END IF
     681              : 
     682              :       IF (optimizer_type == optimizer_pcg .OR. &
     683        10356 :           optimizer_type == optimizer_lin_eq_pcg .OR. &
     684              :           optimizer_type == optimizer_trustr) THEN
     685              : 
     686              :          CALL keyword_create(keyword, __LOCATION__, name="MAX_ITER_OUTER_LOOP", &
     687              :                              description="Maximum number of iterations in the outer loop. "// &
     688              :                              "Use the outer loop to update the preconditioner and reset the conjugator. "// &
     689              :                              "This can speed up convergence significantly.", &
     690        62136 :                              usage="MAX_ITER_OUTER_LOOP 10", default_i_val=0)
     691        62136 :          CALL section_add_keyword(section, keyword)
     692        62136 :          CALL keyword_release(keyword)
     693              : 
     694              :          CALL keyword_create(keyword, __LOCATION__, name="PRECONDITIONER", &
     695              :                              description="Select a preconditioner for the conjugate gradient optimization", &
     696              :                              usage="PRECONDITIONER DOMAIN", &
     697              :                              default_i_val=xalmo_prec_domain, &
     698              :                              enum_c_vals=s2a("NONE", "DEFAULT", "DOMAIN", "FULL"), &
     699              :                              enum_desc=s2a("Do not use preconditioner", &
     700              :                                            "Same as DOMAIN preconditioner", &
     701              :                                            "Invert preconditioner domain-by-domain."// &
     702              :                                            " The main component of the linear scaling algorithm", &
     703              :                                            "Solve linear equations step=-H.grad on the entire space"), &
     704              :                              enum_i_vals=[xalmo_prec_zero, xalmo_prec_domain, &
     705        62136 :                                           xalmo_prec_domain, xalmo_prec_full])
     706        62136 :          CALL section_add_keyword(section, keyword)
     707        62136 :          CALL keyword_release(keyword)
     708              : 
     709              :       END IF
     710              : 
     711        62136 :       IF (optimizer_type == optimizer_pcg) THEN
     712              : 
     713              :          CALL keyword_create(keyword, __LOCATION__, name="LIN_SEARCH_EPS_ERROR", &
     714              :                              description="Target value of the gradient norm during the linear search", &
     715        31068 :                              usage="LIN_SEARCH_EPS_ERROR 1.E-2", default_r_val=1.0E-3_dp)
     716        31068 :          CALL section_add_keyword(section, keyword)
     717        31068 :          CALL keyword_release(keyword)
     718              : 
     719              :          CALL keyword_create(keyword, __LOCATION__, name="LIN_SEARCH_STEP_SIZE_GUESS", &
     720              :                              description="The size of the first step in the linear search", &
     721        31068 :                              usage="LIN_SEARCH_STEP_SIZE_GUESS 0.1", default_r_val=1.0_dp)
     722        31068 :          CALL section_add_keyword(section, keyword)
     723        31068 :          CALL keyword_release(keyword)
     724              : 
     725              :          CALL keyword_create(keyword, __LOCATION__, name="PRECOND_FILTER_THRESHOLD", &
     726              :                              description="Select eigenvalues of the preconditioner "// &
     727              :                              "that are smaller than the threshold and project out the "// &
     728              :                              "corresponding eigenvectors from the gradient. No matter "// &
     729              :                              "how large the threshold is the maximum number of projected "// &
     730              :                              "eienvectors for a fragment equals to the number of occupied "// &
     731              :                              "orbitals of fragment's neighbors.", &
     732        31068 :                              usage="PRECOND_FILTER_THRESHOLD 0.1", default_r_val=-1.0_dp)
     733        31068 :          CALL section_add_keyword(section, keyword)
     734        31068 :          CALL keyword_release(keyword)
     735              : 
     736              :       END IF
     737              : 
     738        72492 :       IF (optimizer_type == optimizer_pcg .OR. &
     739              :           optimizer_type == optimizer_trustr) THEN
     740              : 
     741              :          CALL keyword_create(keyword, __LOCATION__, name="CONJUGATOR", &
     742              :                              description="Various methods to compute step directions in the PCG optimization", &
     743              :                              usage="CONJUGATOR POLAK_RIBIERE", &
     744              :                              default_i_val=cg_hager_zhang, &
     745              :                              enum_c_vals=s2a("ZERO", "POLAK_RIBIERE", "FLETCHER_REEVES", &
     746              :                                              "HESTENES_STIEFEL", "FLETCHER", "LIU_STOREY", "DAI_YUAN", "HAGER_ZHANG"), &
     747              :                              enum_desc=s2a("Steepest descent", "Polak and Ribiere", &
     748              :                                            "Fletcher and Reeves", "Hestenes and Stiefel", &
     749              :                                            "Fletcher (Conjugate descent)", "Liu and Storey", &
     750              :                                            "Dai and Yuan", "Hager and Zhang"), &
     751              :                              enum_i_vals=[cg_zero, cg_polak_ribiere, cg_fletcher_reeves, &
     752              :                                           cg_hestenes_stiefel, cg_fletcher, cg_liu_storey, &
     753        51780 :                                           cg_dai_yuan, cg_hager_zhang])
     754        51780 :          CALL section_add_keyword(section, keyword)
     755        51780 :          CALL keyword_release(keyword)
     756              : 
     757              :       END IF
     758              : 
     759        51780 :       IF (optimizer_type == optimizer_trustr) THEN
     760              : 
     761              :          CALL keyword_create(keyword, __LOCATION__, name="ALGORITHM", &
     762              :                              description="Selects an algorithm to solve the fixed-radius subproblem", &
     763              :                              usage="ALGORITHM CG", &
     764              :                              default_i_val=trustr_cauchy, &
     765              :                              enum_c_vals=s2a("CG", "CAUCHY", "DOGLEG"), &
     766              :                              enum_desc=s2a("Steihaug's iterative CG algorithm that does not invert model Hessian", &
     767              :                                            "Compute simple Cauchy point", &
     768              :                                            "Dogleg optimizer"), &
     769        20712 :                              enum_i_vals=[trustr_steihaug, trustr_cauchy, trustr_dogleg])
     770        20712 :          CALL section_add_keyword(section, keyword)
     771        20712 :          CALL keyword_release(keyword)
     772              : 
     773              :          CALL keyword_create(keyword, __LOCATION__, name="ETA", &
     774              :                              description="Must be between 0.0 and 0.25. Rho value below which the "// &
     775              :                              "optimization of the model function is not accepted and the "// &
     776              :                              "optimization is restarted from the same point but decreased "// &
     777              :                              "trust radius. Rho is the ratio of the actual over predicted "// &
     778              :                              "change in the objective function", &
     779        20712 :                              usage="ETA 0.1", default_r_val=0.25_dp)
     780        20712 :          CALL section_add_keyword(section, keyword)
     781        20712 :          CALL keyword_release(keyword)
     782              : 
     783              :          CALL keyword_create(keyword, __LOCATION__, name="MODEL_GRAD_NORM_RATIO", &
     784              :                              description="Stop the fixed-trust-radius (inner) loop optimization "// &
     785              :                              "once the ratio of the current norm of the model gradient over the "// &
     786              :                              "initial norm drops below this threshold", &
     787        20712 :                              usage="MODEL_GRAD_NORM_RATIO 1.E-2", default_r_val=0.01_dp)
     788        20712 :          CALL section_add_keyword(section, keyword)
     789        20712 :          CALL keyword_release(keyword)
     790              : 
     791              :          CALL keyword_create(keyword, __LOCATION__, name="INITIAL_TRUST_RADIUS", &
     792              :                              description="Initial trust radius", &
     793        20712 :                              usage="INITIAL_TRUST_RADIUS 0.1", default_r_val=0.1_dp)
     794        20712 :          CALL section_add_keyword(section, keyword)
     795        20712 :          CALL keyword_release(keyword)
     796              : 
     797              :          CALL keyword_create(keyword, __LOCATION__, name="MAX_TRUST_RADIUS", &
     798              :                              description="Maximum allowed trust radius", &
     799        20712 :                              usage="MAX_TRUST_RADIUS 1.0", default_r_val=2.0_dp)
     800        20712 :          CALL section_add_keyword(section, keyword)
     801        20712 :          CALL keyword_release(keyword)
     802              : 
     803              :       END IF
     804              : 
     805        72492 :    END SUBROUTINE create_optimizer_section
     806              : 
     807              : ! **************************************************************************************************
     808              : !> \brief The section controls iterative matrix operations like SQRT or inverse
     809              : !> \param section ...
     810              : !> \par History
     811              : !>       2017.05 created [Rustam Z Khaliullin]
     812              : !> \author Rustam Z Khaliullin
     813              : ! **************************************************************************************************
     814        10356 :    SUBROUTINE create_matrix_iterate_section(section)
     815              : 
     816              :       TYPE(section_type), POINTER                        :: section
     817              : 
     818              :       TYPE(keyword_type), POINTER                        :: keyword
     819              : 
     820        10356 :       CPASSERT(.NOT. ASSOCIATED(section))
     821        10356 :       NULLIFY (section)
     822              : 
     823              :       CALL section_create(section, __LOCATION__, name="MATRIX_ITERATE", &
     824              :                           description="Controls linear scaling iterative procedure on matrices: inversion, sqrti, etc. "// &
     825              :                           "High-order Lanczos accelerates convergence provided it can estimate the eigenspectrum correctly.", &
     826        10356 :                           n_keywords=4, n_subsections=0, repeats=.FALSE.)
     827              : 
     828        10356 :       NULLIFY (keyword)
     829              : 
     830              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_TARGET_FACTOR", &
     831              :                           description="Multiplication factor that determines acceptable error in the iterative procedure. "// &
     832              :                           "Acceptable error = EPS_TARGET_FACTOR * EPS_FILTER", &
     833        10356 :                           usage="EPS_TARGET_FACTOR 100.0", default_r_val=10.0_dp)
     834        10356 :       CALL section_add_keyword(section, keyword)
     835        10356 :       CALL keyword_release(keyword)
     836              : 
     837              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_LANCZOS", &
     838              :                           description="Threshold for Lanczos eigenvalue estimation.", &
     839        10356 :                           usage="EPS_LANCZOS 1.0E-4", default_r_val=1.0E-3_dp)
     840        10356 :       CALL section_add_keyword(section, keyword)
     841        10356 :       CALL keyword_release(keyword)
     842              : 
     843              :       CALL keyword_create(keyword, __LOCATION__, name="ORDER_LANCZOS", &
     844              :                           description="Order of the Lanczos estimator. Use 0 to turn off. Do not use 1.", &
     845        10356 :                           usage="ORDER_LANCZOS 5", default_i_val=3)
     846        10356 :       CALL section_add_keyword(section, keyword)
     847        10356 :       CALL keyword_release(keyword)
     848              : 
     849              :       CALL keyword_create(keyword, __LOCATION__, name="MAX_ITER_LANCZOS", &
     850              :                           description="Maximum number of Lanczos iterations.", &
     851        10356 :                           usage="MAX_ITER_LANCZOS 64", default_i_val=128)
     852        10356 :       CALL section_add_keyword(section, keyword)
     853        10356 :       CALL keyword_release(keyword)
     854              : 
     855        10356 :    END SUBROUTINE create_matrix_iterate_section
     856              : 
     857              : ! **************************************************************************************************
     858              : !> \brief The section controls penalty methods
     859              : !> \param section ...
     860              : !> \par History
     861              : !>       2018.01 created [Rustam Z Khaliullin]
     862              : !> \author Rustam Z Khaliullin
     863              : ! **************************************************************************************************
     864        10356 :    SUBROUTINE create_penalty_section(section)
     865              : 
     866              :       TYPE(section_type), POINTER                        :: section
     867              : 
     868              :       TYPE(keyword_type), POINTER                        :: keyword
     869              : 
     870        10356 :       CPASSERT(.NOT. ASSOCIATED(section))
     871        10356 :       NULLIFY (section)
     872              : 
     873              :       CALL section_create(section, __LOCATION__, name="PENALTY", &
     874              :                           description="Add penalty terms to the energy functional.", &
     875        10356 :                           n_keywords=3, n_subsections=0, repeats=.FALSE.)
     876              : 
     877        10356 :       NULLIFY (keyword)
     878              : 
     879              :       CALL keyword_create( &
     880              :          keyword, __LOCATION__, name="OPERATOR", &
     881              :          description="Type of opertator which defines the spread functional", &
     882              :          usage="OPERATOR PIPEK", &
     883              :          enum_c_vals=s2a("BERRY", "PIPEK"), &
     884              :          enum_i_vals=[op_loc_berry, op_loc_pipek], &
     885        10356 :          default_i_val=op_loc_berry)
     886        10356 :       CALL section_add_keyword(section, keyword)
     887        10356 :       CALL keyword_release(keyword)
     888              : 
     889              :       CALL keyword_create(keyword, __LOCATION__, name="PENALTY_STRENGTH", &
     890              :                           description="Strength of the orthogonalization penalty", &
     891        10356 :                           usage="PENALTY_STRENGTH 1.1", default_r_val=1.1_dp)
     892        10356 :       CALL section_add_keyword(section, keyword)
     893        10356 :       CALL keyword_release(keyword)
     894              : 
     895              :       CALL keyword_create(keyword, __LOCATION__, name="PENALTY_STRENGTH_DECREASE_FACTOR", &
     896              :                           description="Factor that decreases the strength of the orthogonalization penalty.", &
     897        10356 :                           usage="PENALTY_STRENGTH_DECREASE_FACTOR 1.1", default_r_val=1.1_dp)
     898        10356 :       CALL section_add_keyword(section, keyword)
     899        10356 :       CALL keyword_release(keyword)
     900              : 
     901              :       CALL keyword_create(keyword, __LOCATION__, name="DETERMINANT_TOLERANCE", &
     902              :                           description="Stop the optimization of the penalty strength if the determinant of the overlap "// &
     903              :                           "changes less than this tolerance threshold.", &
     904        10356 :                           usage="DETERMINANT_TOLERANCE 1.0E-4", default_r_val=1.0E-3_dp)
     905        10356 :       CALL section_add_keyword(section, keyword)
     906        10356 :       CALL keyword_release(keyword)
     907              : 
     908              :       CALL keyword_create(keyword, __LOCATION__, name="FINAL_DETERMINANT", &
     909              :                           description="The final determinant that obtained after optimization.", &
     910        10356 :                           usage="FINAL_DETERMINANT 0.1", default_r_val=0.1_dp)
     911        10356 :       CALL section_add_keyword(section, keyword)
     912        10356 :       CALL keyword_release(keyword)
     913              : 
     914              :       CALL keyword_create(keyword, __LOCATION__, name="COMPACTIFICATION_FILTER_START", &
     915              :                           description="Set orbital coefficients with absolute value smaller than this value to zero.", &
     916        10356 :                           usage="COMPACTIFICATION_FILTER_START 1.e-6", default_r_val=-1.0_dp)
     917        10356 :       CALL section_add_keyword(section, keyword)
     918        10356 :       CALL keyword_release(keyword)
     919              : 
     920              :       CALL keyword_create(keyword, __LOCATION__, name="VIRTUAL_NLMOS", &
     921              :                           description="Localize virtual oribtals", &
     922        10356 :                           usage="VIRTUAL_NLMOS .TRUE.", default_l_val=.FALSE.)
     923        10356 :       CALL section_add_keyword(section, keyword)
     924        10356 :       CALL keyword_release(keyword)
     925              : 
     926        10356 :    END SUBROUTINE create_penalty_section
     927              : 
     928              : ! **************************************************************************************************
     929              : !> \brief The section controls electronic structure analysis based on ALMOs
     930              : !> \param section ...
     931              : !> \par History
     932              : !>       2014.10 created [Rustam Z Khaliullin]
     933              : !> \author Rustam Z Khaliullin
     934              : ! **************************************************************************************************
     935        10356 :    SUBROUTINE create_almo_analysis_section(section)
     936              : 
     937              :       TYPE(section_type), POINTER                        :: section
     938              : 
     939              :       TYPE(keyword_type), POINTER                        :: keyword
     940              :       TYPE(section_type), POINTER                        :: subsection
     941              : 
     942        10356 :       CPASSERT(.NOT. ASSOCIATED(section))
     943        10356 :       NULLIFY (section)
     944              : 
     945              :       CALL section_create(section, __LOCATION__, name="ANALYSIS", &
     946              :                           description="Controls electronic structure analysis based on ALMOs and XALMOs.", &
     947              :                           n_keywords=2, n_subsections=1, repeats=.FALSE., &
     948        31068 :                           citations=[Khaliullin2007, Khaliullin2008])
     949              : 
     950        10356 :       NULLIFY (keyword)
     951              : 
     952              :       CALL keyword_create(keyword, __LOCATION__, name="_SECTION_PARAMETERS_", &
     953              :                           description="Activation of ALMO-based electronic structure analysis.", &
     954              :                           usage="&ANALYSIS T", &
     955              :                           default_l_val=.FALSE., &
     956        10356 :                           lone_keyword_l_val=.TRUE.)
     957        10356 :       CALL section_add_keyword(section, keyword)
     958        10356 :       CALL keyword_release(keyword)
     959              : 
     960              :       CALL keyword_create(keyword, __LOCATION__, name="FROZEN_MO_ENERGY_TERM", &
     961              :                           description="Perform calculations on single molecules to compute the frozen density term", &
     962              :                           usage="FROZEN_MO_ENERGY_TERM SUBLATTICE", default_i_val=almo_frz_none, &
     963              :                           !enum_c_vals=s2a("SKIP", "ISOLATED", "SUBLATTICE"),&
     964              :                           enum_c_vals=s2a("SKIP", "SUBLATTICE"), &
     965              :                           enum_desc=s2a("Do not compute the frozen MO energy term.", &
     966              :                                         !"Use isolated gas-phase molecules as the reference.",&
     967              :                                         "Use energies of single molecules in their positions in the crystal "// &
     968              :                                         "cell as the reference. "// &
     969              :                                         "This term does not have an interpretation if fragmetns are charged."), &
     970              :                           enum_i_vals=[almo_frz_none, &
     971              :                                        !almo_frz_isolated,&
     972        10356 :                                        almo_frz_crystal])
     973        10356 :       CALL section_add_keyword(section, keyword)
     974        10356 :       CALL keyword_release(keyword)
     975              : 
     976        10356 :       NULLIFY (subsection)
     977        10356 :       CALL create_almo_print_section(subsection)
     978        10356 :       CALL section_add_subsection(section, subsection)
     979        10356 :       CALL section_release(subsection)
     980              : 
     981        10356 :    END SUBROUTINE create_almo_analysis_section
     982              : 
     983              : ! **************************************************************************************************
     984              : !> \brief The section controls electronic structure of the different fragments
     985              : !> \param section ...
     986              : !> \par History
     987              : !>       2024.02 created [Raphael Rullan]
     988              : !> \author Raphael Rullan
     989              : ! **************************************************************************************************
     990        10356 :    SUBROUTINE create_almo_fragment_section(section)
     991              : 
     992              :       TYPE(section_type), POINTER                        :: section
     993              : 
     994              :       TYPE(keyword_type), POINTER                        :: keyword
     995              : 
     996        10356 :       CPASSERT(.NOT. ASSOCIATED(section))
     997        10356 :       NULLIFY (section)
     998              : 
     999              :       CALL section_create(section, __LOCATION__, name="FRAGMENT", &
    1000              :                           description="Specifies the caracteristics of "// &
    1001              :                           "each fragments.", &
    1002        10356 :                           n_keywords=3, n_subsections=0, repeats=.TRUE.)
    1003        10356 :       NULLIFY (keyword)
    1004              : 
    1005              :       CALL keyword_create(keyword, __LOCATION__, name="_FRAGMENT_PARAMETERS_", &
    1006              :                           description="Defines the index of the fragment.", &
    1007        10356 :                           usage="_FRAGMENT_PARAMETERS_ <INTEGER>", n_var=1, default_i_val=0)
    1008        10356 :       CALL section_add_keyword(section, keyword)
    1009        10356 :       CALL keyword_release(keyword)
    1010              : 
    1011              :       CALL keyword_create(keyword, __LOCATION__, name="CHARGE", &
    1012              :                           description="Specifies the charge of a fragment.", &
    1013        10356 :                           usage="CHARGE 1", default_i_val=0)
    1014        10356 :       CALL section_add_keyword(section, keyword)
    1015        10356 :       CALL keyword_release(keyword)
    1016              : 
    1017              :       CALL keyword_create(keyword, __LOCATION__, &
    1018              :                           name="MULTIPLICITY", &
    1019              :                           variants=["MULTIP"], &
    1020              :                           description="Specifies for each fragment the multiplicity. Two times the total spin plus one. "// &
    1021              :                           "Specify 3 for a triplet, 4 for a quartet,and so on. Default is 1 (singlet) for an "// &
    1022              :                           "even number and 2 (doublet) for an odd number of electrons.", &
    1023              :                           usage="MULTIPLICITY 3", &
    1024        20712 :                           default_i_val=1) ! this default value is just a flag to get the above
    1025        10356 :       CALL section_add_keyword(section, keyword)
    1026        10356 :       CALL keyword_release(keyword)
    1027              : 
    1028        10356 :    END SUBROUTINE create_almo_fragment_section
    1029              : 
    1030              : ! *****************************************************************************
    1031              : !> \brief Create a section with all print keys for ALMO methods
    1032              : !> \param section ...
    1033              : !> \par History
    1034              : !>       2016.05 created [Rustam Z Khaliullin]
    1035              : !> \author Rustam Z Khaliullin
    1036              : ! **************************************************************************************************
    1037        10356 :    SUBROUTINE create_almo_print_section(section)
    1038              : 
    1039              :       TYPE(section_type), POINTER                        :: section
    1040              : 
    1041              :       TYPE(section_type), POINTER                        :: print_key
    1042              : 
    1043        10356 :       CPASSERT(.NOT. ASSOCIATED(section))
    1044        10356 :       NULLIFY (section, print_key)
    1045              : 
    1046              :       CALL section_create(section, __LOCATION__, name="PRINT", &
    1047              :                           description="Controls printing of detailed ALMO decomosition analysis results", &
    1048        10356 :                           n_keywords=0, n_subsections=2, repeats=.TRUE.)
    1049              : 
    1050              :       ! create print keys within this subsection
    1051              :       CALL cp_print_key_section_create(print_key, __LOCATION__, "ALMO_EDA_CT", &
    1052              :                                        description="Controls printing of the electron transfer terms in "// &
    1053              :                                        "ALMO energy decomposition analysis. "// &
    1054              :                                        "File format: first column is the index of the electron acceptor "// &
    1055              :                                        "fragment, second -- is the index of the electron donor fragment, "// &
    1056              :                                        "third - the energy change (a.u.) associated with the electron transfer.", &
    1057              :                                        print_level=low_print_level, common_iter_levels=1, &
    1058        10356 :                                        filename="EDA")
    1059        10356 :       CALL section_add_subsection(section, print_key)
    1060        10356 :       CALL section_release(print_key)
    1061              : 
    1062              :       CALL cp_print_key_section_create(print_key, __LOCATION__, "ALMO_CTA", &
    1063              :                                        description="Controls printing of the electron transfer terms in "// &
    1064              :                                        "ALMO charge transfer analysis. "// &
    1065              :                                        "File format: first column is the index of the electron acceptor "// &
    1066              :                                        "fragment, second -- is the index of the electron donor fragment, "// &
    1067              :                                        "third - the change (a.u.) transferred between the two fragments.", &
    1068              :                                        print_level=low_print_level, common_iter_levels=1, &
    1069        10356 :                                        filename="CTA")
    1070        10356 :       CALL section_add_subsection(section, print_key)
    1071        10356 :       CALL section_release(print_key)
    1072              : 
    1073        10356 :    END SUBROUTINE create_almo_print_section
    1074              : 
    1075              : END MODULE input_cp2k_almo
        

Generated by: LCOV version 2.0-1