LCOV - code coverage report
Current view: top level - src - input_cp2k_almo.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:936074a) Lines: 100.0 % 227 227
Test Date: 2025-12-04 06:27:48 Functions: 100.0 % 6 6

            Line data    Source code
       1              : !--------------------------------------------------------------------------------------------------!
       2              : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3              : !   Copyright 2000-2025 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         9300 :    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         9300 :       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        27900 :                           citations=[Khaliullin2013, Scheiber2018])
      78              : 
      79         9300 :       NULLIFY (keyword)
      80              : 
      81              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_FILTER", &
      82              :                           description="Threshold for the matrix sparsity filter", &
      83         9300 :                           usage="EPS_FILTER 1.e-6", default_r_val=1.e-7_dp)
      84         9300 :       CALL section_add_keyword(section, keyword)
      85         9300 :       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         9300 :                           enum_i_vals=[molecular_guess, atomic_guess])
      97         9300 :       CALL section_add_keyword(section, keyword)
      98         9300 :       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         9300 :                           enum_i_vals=[spd_inversion_ls_hotelling, spd_inversion_ls_taylor, spd_inversion_dense_cholesky])
     109         9300 :       CALL section_add_keyword(section, keyword)
     110         9300 :       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         9300 :                           usage="ALMO_EXTRAPOLATION_ORDER 3", default_i_val=3)
     123         9300 :       CALL section_add_keyword(section, keyword)
     124         9300 :       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         9300 :                           usage="XALMO_EXTRAPOLATION_ORDER 1", default_i_val=0)
     130         9300 :       CALL section_add_keyword(section, keyword)
     131         9300 :       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         9300 :                           enum_i_vals=[almo_scf_diag, almo_scf_pcg, almo_scf_trustr, almo_scf_skip])
     149         9300 :       CALL section_add_keyword(section, keyword)
     150         9300 :       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         9300 :                           enum_i_vals=[almo_scf_diag, almo_scf_pcg, almo_scf_trustr])
     161         9300 :       CALL section_add_keyword(section, keyword)
     162         9300 :       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         9300 :                           enum_i_vals=[xalmo_trial_simplex, xalmo_trial_r0_out])
     173         9300 :       CALL section_add_keyword(section, keyword)
     174         9300 :       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         9300 :                       almo_deloc_x, almo_deloc_scf, almo_deloc_x_then_scf])
     196         9300 :       CALL section_add_keyword(section, keyword)
     197         9300 :       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         9300 :                           usage="XALMO_R_CUTOFF_FACTOR 1.6", default_r_val=1.50_dp)
     204         9300 :       CALL section_add_keyword(section, keyword)
     205         9300 :       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         9300 :                           lone_keyword_l_val=.TRUE.)
     212         9300 :       CALL section_add_keyword(section, keyword)
     213         9300 :       CALL keyword_release(keyword)
     214              : 
     215              :       CALL keyword_create(keyword, __LOCATION__, name="CONSTRUCT_NLMOS", &
     216              :                           description="Turns on post-SCF construction of NLMOs", &
     217         9300 :                           usage="CONSTRUCT_NLMOS .TRUE.", default_l_val=.FALSE.)
     218         9300 :       CALL section_add_keyword(section, keyword)
     219         9300 :       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              :       !CALL keyword_create(keyword, __LOCATION__, name="OPT_K_PREC_ITER_FREQ_UPDATE",&
     518              :       !     description="Frequency for updating the preconditioner",&
     519              :       !     usage="OPT_K_PREC_ITER_FREQ_UPDATE 10",default_i_val=1)
     520              :       !CALL section_add_keyword(section,keyword)
     521              :       !CALL keyword_release(keyword)
     522              : 
     523         9300 :       NULLIFY (subsection)
     524         9300 :       CALL create_optimizer_section(subsection, optimizer_block_diagonal_diis)
     525         9300 :       CALL section_add_subsection(section, subsection)
     526         9300 :       CALL section_release(subsection)
     527              : 
     528         9300 :       NULLIFY (subsection)
     529         9300 :       CALL create_optimizer_section(subsection, optimizer_block_diagonal_pcg)
     530         9300 :       CALL section_add_subsection(section, subsection)
     531         9300 :       CALL section_release(subsection)
     532              : 
     533         9300 :       NULLIFY (subsection)
     534         9300 :       CALL create_optimizer_section(subsection, optimizer_block_diagonal_trustr)
     535         9300 :       CALL section_add_subsection(section, subsection)
     536         9300 :       CALL section_release(subsection)
     537              : 
     538         9300 :       NULLIFY (subsection)
     539         9300 :       CALL create_optimizer_section(subsection, optimizer_xalmo_pcg)
     540         9300 :       CALL section_add_subsection(section, subsection)
     541         9300 :       CALL section_release(subsection)
     542              : 
     543         9300 :       NULLIFY (subsection)
     544         9300 :       CALL create_optimizer_section(subsection, optimizer_xalmo_trustr)
     545         9300 :       CALL section_add_subsection(section, subsection)
     546         9300 :       CALL section_release(subsection)
     547              : 
     548         9300 :       NULLIFY (subsection)
     549         9300 :       CALL create_optimizer_section(subsection, optimizer_nlmo_pcg)
     550         9300 :       CALL section_add_subsection(section, subsection)
     551         9300 :       CALL section_release(subsection)
     552              : 
     553         9300 :       NULLIFY (subsection)
     554         9300 :       CALL create_matrix_iterate_section(subsection)
     555         9300 :       CALL section_add_subsection(section, subsection)
     556         9300 :       CALL section_release(subsection)
     557              : 
     558         9300 :       NULLIFY (subsection)
     559         9300 :       CALL create_almo_analysis_section(subsection)
     560         9300 :       CALL section_add_subsection(section, subsection)
     561         9300 :       CALL section_release(subsection)
     562              : 
     563         9300 :    END SUBROUTINE create_almo_scf_section
     564              : 
     565              : ! **************************************************************************************************
     566              : !> \brief The optimizer section is a collection of keywords that are similar
     567              : !>        to all optimization methods (e.g. target error, number of iterations)
     568              : !> \param section ...
     569              : !> \param optimizer_id   allows to adapt the standard section for specific needs
     570              : !> \par History
     571              : !>       2012.03 created [Rustam Z Khaliullin]
     572              : !>       2014.10 fully integrated [Rustam Z Khaliullin]
     573              : !> \author Rustam Z Khaliullin
     574              : ! **************************************************************************************************
     575        65100 :    RECURSIVE SUBROUTINE create_optimizer_section(section, optimizer_id)
     576              : 
     577              :       TYPE(section_type), POINTER                        :: section
     578              :       INTEGER, INTENT(IN)                                :: optimizer_id
     579              : 
     580              :       INTEGER                                            :: optimizer_type
     581              :       TYPE(keyword_type), POINTER                        :: keyword
     582              :       TYPE(section_type), POINTER                        :: subsection
     583              : 
     584        65100 :       CPASSERT(.NOT. ASSOCIATED(section))
     585        65100 :       NULLIFY (section)
     586              : 
     587              :       ! choose the name of the section
     588        74400 :       SELECT CASE (optimizer_id)
     589              :       CASE (optimizer_block_diagonal_diis)
     590              :          CALL section_create(section, __LOCATION__, name="ALMO_OPTIMIZER_DIIS", &
     591              :                              description="Controls the iterative DIIS-accelerated optimization of block-diagonal ALMOs.", &
     592         9300 :                              n_keywords=5, n_subsections=0, repeats=.FALSE.)
     593         9300 :          optimizer_type = optimizer_diis
     594              :       CASE (optimizer_block_diagonal_pcg)
     595              :          CALL section_create(section, __LOCATION__, name="ALMO_OPTIMIZER_PCG", &
     596              :                              description="Controls the PCG optimization of block-diagonal ALMOs.", &
     597         9300 :                              n_keywords=9, n_subsections=1, repeats=.FALSE.)
     598         9300 :          optimizer_type = optimizer_pcg
     599              :       CASE (optimizer_nlmo_pcg)
     600              :          CALL section_create(section, __LOCATION__, name="NLMO_OPTIMIZER_PCG", &
     601              :                              description="Controls the PCG optimization of nonorthogonal localized MOs.", &
     602         9300 :                              n_keywords=9, n_subsections=1, repeats=.FALSE.)
     603         9300 :          optimizer_type = optimizer_pcg
     604         9300 :          NULLIFY (subsection)
     605         9300 :          CALL create_penalty_section(subsection)
     606         9300 :          CALL section_add_subsection(section, subsection)
     607         9300 :          CALL section_release(subsection)
     608              :       CASE (optimizer_xalmo_pcg)
     609              :          CALL section_create(section, __LOCATION__, name="XALMO_OPTIMIZER_PCG", &
     610              :                              description="Controls the PCG optimization of extended ALMOs.", &
     611         9300 :                              n_keywords=10, n_subsections=2, repeats=.FALSE.)
     612         9300 :          NULLIFY (subsection)
     613         9300 :          CALL create_optimizer_section(subsection, optimizer_newton_pcg_solver)
     614         9300 :          CALL section_add_subsection(section, subsection)
     615         9300 :          CALL section_release(subsection)
     616         9300 :          optimizer_type = optimizer_pcg
     617              :       CASE (optimizer_xalmo_trustr)
     618              :          CALL section_create(section, __LOCATION__, name="XALMO_OPTIMIZER_TRUSTR", &
     619              :                              description="Controls the trust-region optimization of extended ALMOs. "// &
     620              :                              "Trust radius is varied in the outer loop. Once the trust radius is "// &
     621              :                              "chosen (and fixed) the model function can be minized using various "// &
     622              :                              "approaches. Currently, an iterative conjugate-gradient approach is "// &
     623              :                              "used and controlled by the inner loop", &
     624         9300 :                              n_keywords=10, n_subsections=0, repeats=.FALSE.)
     625         9300 :          optimizer_type = optimizer_trustr
     626              :       CASE (optimizer_block_diagonal_trustr)
     627              :          CALL section_create(section, __LOCATION__, name="ALMO_OPTIMIZER_TRUSTR", &
     628              :                              description="Controls the trust-region optimization of block-diagonal ALMOs. "// &
     629              :                              "See XALMO_OPTIMIZER_TRUSTR section for brief explanations.", &
     630         9300 :                              n_keywords=10, n_subsections=0, repeats=.FALSE.)
     631         9300 :          optimizer_type = optimizer_trustr
     632              :       CASE (optimizer_newton_pcg_solver)
     633              :          CALL section_create(section, __LOCATION__, name="XALMO_NEWTON_PCG_SOLVER", &
     634              :                              description="Controls an iterative solver of the Newton-Raphson linear equation.", &
     635         9300 :                              n_keywords=4, n_subsections=0, repeats=.FALSE.)
     636         9300 :          optimizer_type = optimizer_lin_eq_pcg
     637              :       CASE DEFAULT
     638        65100 :          CPABORT("No default values allowed")
     639              :       END SELECT
     640              : 
     641        65100 :       NULLIFY (keyword)
     642              : 
     643              :       ! add common keywords
     644              :       CALL keyword_create(keyword, __LOCATION__, name="MAX_ITER", &
     645              :                           description="Maximum number of iterations", &
     646        65100 :                           usage="MAX_ITER 100", default_i_val=20)
     647        65100 :       CALL section_add_keyword(section, keyword)
     648        65100 :       CALL keyword_release(keyword)
     649              : 
     650              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_ERROR", &
     651              :                           description="Target value of the MAX norm of the error", &
     652        65100 :                           usage="EPS_ERROR 1.E-6", default_r_val=1.0E-5_dp)
     653        65100 :       CALL section_add_keyword(section, keyword)
     654        65100 :       CALL keyword_release(keyword)
     655              : 
     656              :       ! add common keywords
     657              :       CALL keyword_create(keyword, __LOCATION__, name="MAX_ITER_EARLY", &
     658              :                           description="Maximum number of iterations for truncated SCF "// &
     659              :                           "(e.g. Langevin-corrected MD). Negative values mean that this keyword is not used.", &
     660        65100 :                           usage="MAX_ITER_EARLY 5", default_i_val=-1)
     661        65100 :       CALL section_add_keyword(section, keyword)
     662        65100 :       CALL keyword_release(keyword)
     663              : 
     664              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_ERROR_EARLY", &
     665              :                           description="Target value of the MAX norm of the error for truncated SCF "// &
     666              :                           "(e.g. Langevin-corrected MD). Negative values mean that this keyword is not used.", &
     667        65100 :                           usage="EPS_ERROR_EARLY 1.E-2", default_r_val=-1.0_dp)
     668        65100 :       CALL section_add_keyword(section, keyword)
     669        65100 :       CALL keyword_release(keyword)
     670              : 
     671              :       ! add keywords specific to each type
     672        65100 :       IF (optimizer_type == optimizer_diis) THEN
     673              : 
     674              :          CALL keyword_create(keyword, __LOCATION__, name="N_DIIS", &
     675              :                              description="Number of error vectors to be used in the DIIS "// &
     676              :                              "optimization procedure", &
     677         9300 :                              usage="N_DIIS 5", default_i_val=6)
     678         9300 :          CALL section_add_keyword(section, keyword)
     679         9300 :          CALL keyword_release(keyword)
     680              : 
     681              :       END IF
     682              : 
     683              :       IF (optimizer_type == optimizer_pcg .OR. &
     684        65100 :           optimizer_type == optimizer_lin_eq_pcg .OR. &
     685              :           optimizer_type == optimizer_trustr) THEN
     686              : 
     687              :          CALL keyword_create(keyword, __LOCATION__, name="MAX_ITER_OUTER_LOOP", &
     688              :                              description="Maximum number of iterations in the outer loop. "// &
     689              :                              "Use the outer loop to update the preconditioner and reset the conjugator. "// &
     690              :                              "This can speed up convergence significantly.", &
     691        55800 :                              usage="MAX_ITER_OUTER_LOOP 10", default_i_val=0)
     692        55800 :          CALL section_add_keyword(section, keyword)
     693        55800 :          CALL keyword_release(keyword)
     694              : 
     695              :          CALL keyword_create(keyword, __LOCATION__, name="PRECONDITIONER", &
     696              :                              description="Select a preconditioner for the conjugate gradient optimization", &
     697              :                              usage="PRECONDITIONER DOMAIN", &
     698              :                              default_i_val=xalmo_prec_domain, &
     699              :                              enum_c_vals=s2a("NONE", "DEFAULT", "DOMAIN", "FULL"), &
     700              :                              enum_desc=s2a("Do not use preconditioner", &
     701              :                                            "Same as DOMAIN preconditioner", &
     702              :                                            "Invert preconditioner domain-by-domain."// &
     703              :                                            " The main component of the linear scaling algorithm", &
     704              :                                            "Solve linear equations step=-H.grad on the entire space"), &
     705              :                              enum_i_vals=[xalmo_prec_zero, xalmo_prec_domain, &
     706        55800 :                                           xalmo_prec_domain, xalmo_prec_full])
     707        55800 :          CALL section_add_keyword(section, keyword)
     708        55800 :          CALL keyword_release(keyword)
     709              : 
     710              :       END IF
     711              : 
     712        55800 :       IF (optimizer_type == optimizer_pcg) THEN
     713              : 
     714              :          CALL keyword_create(keyword, __LOCATION__, name="LIN_SEARCH_EPS_ERROR", &
     715              :                              description="Target value of the gradient norm during the linear search", &
     716        27900 :                              usage="LIN_SEARCH_EPS_ERROR 1.E-2", default_r_val=1.0E-3_dp)
     717        27900 :          CALL section_add_keyword(section, keyword)
     718        27900 :          CALL keyword_release(keyword)
     719              : 
     720              :          CALL keyword_create(keyword, __LOCATION__, name="LIN_SEARCH_STEP_SIZE_GUESS", &
     721              :                              description="The size of the first step in the linear search", &
     722        27900 :                              usage="LIN_SEARCH_STEP_SIZE_GUESS 0.1", default_r_val=1.0_dp)
     723        27900 :          CALL section_add_keyword(section, keyword)
     724        27900 :          CALL keyword_release(keyword)
     725              : 
     726              :          CALL keyword_create(keyword, __LOCATION__, name="PRECOND_FILTER_THRESHOLD", &
     727              :                              description="Select eigenvalues of the preconditioner "// &
     728              :                              "that are smaller than the threshold and project out the "// &
     729              :                              "corresponding eigenvectors from the gradient. No matter "// &
     730              :                              "how large the threshold is the maximum number of projected "// &
     731              :                              "eienvectors for a fragment equals to the number of occupied "// &
     732              :                              "orbitals of fragment's neighbors.", &
     733        27900 :                              usage="PRECOND_FILTER_THRESHOLD 0.1", default_r_val=-1.0_dp)
     734        27900 :          CALL section_add_keyword(section, keyword)
     735        27900 :          CALL keyword_release(keyword)
     736              : 
     737              :       END IF
     738              : 
     739        65100 :       IF (optimizer_type == optimizer_pcg .OR. &
     740              :           optimizer_type == optimizer_trustr) THEN
     741              : 
     742              :          CALL keyword_create(keyword, __LOCATION__, name="CONJUGATOR", &
     743              :                              description="Various methods to compute step directions in the PCG optimization", &
     744              :                              usage="CONJUGATOR POLAK_RIBIERE", &
     745              :                              default_i_val=cg_hager_zhang, &
     746              :                              enum_c_vals=s2a("ZERO", "POLAK_RIBIERE", "FLETCHER_REEVES", &
     747              :                                              "HESTENES_STIEFEL", "FLETCHER", "LIU_STOREY", "DAI_YUAN", "HAGER_ZHANG"), &
     748              :                              enum_desc=s2a("Steepest descent", "Polak and Ribiere", &
     749              :                                            "Fletcher and Reeves", "Hestenes and Stiefel", &
     750              :                                            "Fletcher (Conjugate descent)", "Liu and Storey", &
     751              :                                            "Dai and Yuan", "Hager and Zhang"), &
     752              :                              enum_i_vals=[cg_zero, cg_polak_ribiere, cg_fletcher_reeves, &
     753              :                                           cg_hestenes_stiefel, cg_fletcher, cg_liu_storey, &
     754        46500 :                                           cg_dai_yuan, cg_hager_zhang])
     755        46500 :          CALL section_add_keyword(section, keyword)
     756        46500 :          CALL keyword_release(keyword)
     757              : 
     758              :       END IF
     759              : 
     760        46500 :       IF (optimizer_type == optimizer_trustr) THEN
     761              : 
     762              :          CALL keyword_create(keyword, __LOCATION__, name="ALGORITHM", &
     763              :                              description="Selects an algorithm to solve the fixed-radius subproblem", &
     764              :                              usage="ALGORITHM CG", &
     765              :                              default_i_val=trustr_cauchy, &
     766              :                              enum_c_vals=s2a("CG", "CAUCHY", "DOGLEG"), &
     767              :                              enum_desc=s2a("Steihaug's iterative CG algorithm that does not invert model Hessian", &
     768              :                                            "Compute simple Cauchy point", &
     769              :                                            "Dogleg optimizer"), &
     770        18600 :                              enum_i_vals=[trustr_steihaug, trustr_cauchy, trustr_dogleg])
     771        18600 :          CALL section_add_keyword(section, keyword)
     772        18600 :          CALL keyword_release(keyword)
     773              : 
     774              :          CALL keyword_create(keyword, __LOCATION__, name="ETA", &
     775              :                              description="Must be between 0.0 and 0.25. Rho value below which the "// &
     776              :                              "optimization of the model function is not accepted and the "// &
     777              :                              "optimization is restarted from the same point but decreased "// &
     778              :                              "trust radius. Rho is the ratio of the actual over predicted "// &
     779              :                              "change in the objective function", &
     780        18600 :                              usage="ETA 0.1", default_r_val=0.25_dp)
     781        18600 :          CALL section_add_keyword(section, keyword)
     782        18600 :          CALL keyword_release(keyword)
     783              : 
     784              :          CALL keyword_create(keyword, __LOCATION__, name="MODEL_GRAD_NORM_RATIO", &
     785              :                              description="Stop the fixed-trust-radius (inner) loop optimization "// &
     786              :                              "once the ratio of the current norm of the model gradient over the "// &
     787              :                              "initial norm drops below this threshold", &
     788        18600 :                              usage="MODEL_GRAD_NORM_RATIO 1.E-2", default_r_val=0.01_dp)
     789        18600 :          CALL section_add_keyword(section, keyword)
     790        18600 :          CALL keyword_release(keyword)
     791              : 
     792              :          CALL keyword_create(keyword, __LOCATION__, name="INITIAL_TRUST_RADIUS", &
     793              :                              description="Initial trust radius", &
     794        18600 :                              usage="INITIAL_TRUST_RADIUS 0.1", default_r_val=0.1_dp)
     795        18600 :          CALL section_add_keyword(section, keyword)
     796        18600 :          CALL keyword_release(keyword)
     797              : 
     798              :          CALL keyword_create(keyword, __LOCATION__, name="MAX_TRUST_RADIUS", &
     799              :                              description="Maximum allowed trust radius", &
     800        18600 :                              usage="MAX_TRUST_RADIUS 1.0", default_r_val=2.0_dp)
     801        18600 :          CALL section_add_keyword(section, keyword)
     802        18600 :          CALL keyword_release(keyword)
     803              : 
     804              :       END IF
     805              : 
     806        65100 :    END SUBROUTINE create_optimizer_section
     807              : 
     808              : ! **************************************************************************************************
     809              : !> \brief The section controls iterative matrix operations like SQRT or inverse
     810              : !> \param section ...
     811              : !> \par History
     812              : !>       2017.05 created [Rustam Z Khaliullin]
     813              : !> \author Rustam Z Khaliullin
     814              : ! **************************************************************************************************
     815         9300 :    SUBROUTINE create_matrix_iterate_section(section)
     816              : 
     817              :       TYPE(section_type), POINTER                        :: section
     818              : 
     819              :       TYPE(keyword_type), POINTER                        :: keyword
     820              : 
     821         9300 :       CPASSERT(.NOT. ASSOCIATED(section))
     822         9300 :       NULLIFY (section)
     823              : 
     824              :       CALL section_create(section, __LOCATION__, name="MATRIX_ITERATE", &
     825              :                           description="Controls linear scaling iterative procedure on matrices: inversion, sqrti, etc. "// &
     826              :                           "High-order Lanczos accelerates convergence provided it can estimate the eigenspectrum correctly.", &
     827         9300 :                           n_keywords=4, n_subsections=0, repeats=.FALSE.)
     828              : 
     829         9300 :       NULLIFY (keyword)
     830              : 
     831              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_TARGET_FACTOR", &
     832              :                           description="Multiplication factor that determines acceptable error in the iterative procedure. "// &
     833              :                           "Acceptable error = EPS_TARGET_FACTOR * EPS_FILTER", &
     834         9300 :                           usage="EPS_TARGET_FACTOR 100.0", default_r_val=10.0_dp)
     835         9300 :       CALL section_add_keyword(section, keyword)
     836         9300 :       CALL keyword_release(keyword)
     837              : 
     838              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_LANCZOS", &
     839              :                           description="Threshold for Lanczos eigenvalue estimation.", &
     840         9300 :                           usage="EPS_LANCZOS 1.0E-4", default_r_val=1.0E-3_dp)
     841         9300 :       CALL section_add_keyword(section, keyword)
     842         9300 :       CALL keyword_release(keyword)
     843              : 
     844              :       CALL keyword_create(keyword, __LOCATION__, name="ORDER_LANCZOS", &
     845              :                           description="Order of the Lanczos estimator. Use 0 to turn off. Do not use 1.", &
     846         9300 :                           usage="ORDER_LANCZOS 5", default_i_val=3)
     847         9300 :       CALL section_add_keyword(section, keyword)
     848         9300 :       CALL keyword_release(keyword)
     849              : 
     850              :       CALL keyword_create(keyword, __LOCATION__, name="MAX_ITER_LANCZOS", &
     851              :                           description="Maximum number of Lanczos iterations.", &
     852         9300 :                           usage="MAX_ITER_LANCZOS 64", default_i_val=128)
     853         9300 :       CALL section_add_keyword(section, keyword)
     854         9300 :       CALL keyword_release(keyword)
     855              : 
     856         9300 :    END SUBROUTINE create_matrix_iterate_section
     857              : 
     858              : ! **************************************************************************************************
     859              : !> \brief The section controls penalty methods
     860              : !> \param section ...
     861              : !> \par History
     862              : !>       2018.01 created [Rustam Z Khaliullin]
     863              : !> \author Rustam Z Khaliullin
     864              : ! **************************************************************************************************
     865         9300 :    SUBROUTINE create_penalty_section(section)
     866              : 
     867              :       TYPE(section_type), POINTER                        :: section
     868              : 
     869              :       TYPE(keyword_type), POINTER                        :: keyword
     870              : 
     871         9300 :       CPASSERT(.NOT. ASSOCIATED(section))
     872         9300 :       NULLIFY (section)
     873              : 
     874              :       CALL section_create(section, __LOCATION__, name="PENALTY", &
     875              :                           description="Add penalty terms to the energy functional.", &
     876         9300 :                           n_keywords=3, n_subsections=0, repeats=.FALSE.)
     877              : 
     878         9300 :       NULLIFY (keyword)
     879              : 
     880              :       CALL keyword_create( &
     881              :          keyword, __LOCATION__, name="OPERATOR", &
     882              :          description="Type of opertator which defines the spread functional", &
     883              :          usage="OPERATOR PIPEK", &
     884              :          enum_c_vals=s2a("BERRY", "PIPEK"), &
     885              :          enum_i_vals=[op_loc_berry, op_loc_pipek], &
     886         9300 :          default_i_val=op_loc_berry)
     887         9300 :       CALL section_add_keyword(section, keyword)
     888         9300 :       CALL keyword_release(keyword)
     889              : 
     890              :       CALL keyword_create(keyword, __LOCATION__, name="PENALTY_STRENGTH", &
     891              :                           description="Strength of the orthogonalization penalty", &
     892         9300 :                           usage="PENALTY_STRENGTH 1.1", default_r_val=1.1_dp)
     893         9300 :       CALL section_add_keyword(section, keyword)
     894         9300 :       CALL keyword_release(keyword)
     895              : 
     896              :       CALL keyword_create(keyword, __LOCATION__, name="PENALTY_STRENGTH_DECREASE_FACTOR", &
     897              :                           description="Factor that decreases the strength of the orthogonalization penalty.", &
     898         9300 :                           usage="PENALTY_STRENGTH_DECREASE_FACTOR 1.1", default_r_val=1.1_dp)
     899         9300 :       CALL section_add_keyword(section, keyword)
     900         9300 :       CALL keyword_release(keyword)
     901              : 
     902              :       CALL keyword_create(keyword, __LOCATION__, name="DETERMINANT_TOLERANCE", &
     903              :                           description="Stop the optimization of the penalty strength if the determinant of the overlap "// &
     904              :                           "changes less than this tolerance threshold.", &
     905         9300 :                           usage="DETERMINANT_TOLERANCE 1.0E-4", default_r_val=1.0E-3_dp)
     906         9300 :       CALL section_add_keyword(section, keyword)
     907         9300 :       CALL keyword_release(keyword)
     908              : 
     909              :       CALL keyword_create(keyword, __LOCATION__, name="FINAL_DETERMINANT", &
     910              :                           description="The final determinant that obtained after optimization.", &
     911         9300 :                           usage="FINAL_DETERMINANT 0.1", default_r_val=0.1_dp)
     912         9300 :       CALL section_add_keyword(section, keyword)
     913         9300 :       CALL keyword_release(keyword)
     914              : 
     915              :       CALL keyword_create(keyword, __LOCATION__, name="COMPACTIFICATION_FILTER_START", &
     916              :                           description="Set orbital coefficients with absolute value smaller than this value to zero.", &
     917         9300 :                           usage="COMPACTIFICATION_FILTER_START 1.e-6", default_r_val=-1.0_dp)
     918         9300 :       CALL section_add_keyword(section, keyword)
     919         9300 :       CALL keyword_release(keyword)
     920              : 
     921              :       CALL keyword_create(keyword, __LOCATION__, name="VIRTUAL_NLMOS", &
     922              :                           description="Localize virtual oribtals", &
     923         9300 :                           usage="VIRTUAL_NLMOS .TRUE.", default_l_val=.FALSE.)
     924         9300 :       CALL section_add_keyword(section, keyword)
     925         9300 :       CALL keyword_release(keyword)
     926              : 
     927         9300 :    END SUBROUTINE create_penalty_section
     928              : 
     929              : ! **************************************************************************************************
     930              : !> \brief The section controls electronic structure analysis based on ALMOs
     931              : !> \param section ...
     932              : !> \par History
     933              : !>       2014.10 created [Rustam Z Khaliullin]
     934              : !> \author Rustam Z Khaliullin
     935              : ! **************************************************************************************************
     936         9300 :    SUBROUTINE create_almo_analysis_section(section)
     937              : 
     938              :       TYPE(section_type), POINTER                        :: section
     939              : 
     940              :       TYPE(keyword_type), POINTER                        :: keyword
     941              :       TYPE(section_type), POINTER                        :: subsection
     942              : 
     943         9300 :       CPASSERT(.NOT. ASSOCIATED(section))
     944         9300 :       NULLIFY (section)
     945              : 
     946              :       CALL section_create(section, __LOCATION__, name="ANALYSIS", &
     947              :                           description="Controls electronic structure analysis based on ALMOs and XALMOs.", &
     948              :                           n_keywords=2, n_subsections=1, repeats=.FALSE., &
     949        27900 :                           citations=[Khaliullin2007, Khaliullin2008])
     950              : 
     951         9300 :       NULLIFY (keyword)
     952              : 
     953              :       CALL keyword_create(keyword, __LOCATION__, name="_SECTION_PARAMETERS_", &
     954              :                           description="Activation of ALMO-based electronic structure analysis.", &
     955              :                           usage="&ANALYSIS T", &
     956              :                           default_l_val=.FALSE., &
     957         9300 :                           lone_keyword_l_val=.TRUE.)
     958         9300 :       CALL section_add_keyword(section, keyword)
     959         9300 :       CALL keyword_release(keyword)
     960              : 
     961              :       CALL keyword_create(keyword, __LOCATION__, name="FROZEN_MO_ENERGY_TERM", &
     962              :                           description="Perform calculations on single molecules to compute the frozen density term", &
     963              :                           usage="FROZEN_MO_ENERGY_TERM SUBLATTICE", default_i_val=almo_frz_none, &
     964              :                           !enum_c_vals=s2a("SKIP", "ISOLATED", "SUBLATTICE"),&
     965              :                           enum_c_vals=s2a("SKIP", "SUBLATTICE"), &
     966              :                           enum_desc=s2a("Do not compute the frozen MO energy term.", &
     967              :                                         !"Use isolated gas-phase molecules as the reference.",&
     968              :                                         "Use energies of single molecules in their positions in the crystal "// &
     969              :                                         "cell as the reference. "// &
     970              :                                         "This term does not have an interpretation if fragmetns are charged."), &
     971              :                           enum_i_vals=[almo_frz_none, &
     972              :                                        !almo_frz_isolated,&
     973         9300 :                                        almo_frz_crystal])
     974         9300 :       CALL section_add_keyword(section, keyword)
     975         9300 :       CALL keyword_release(keyword)
     976              : 
     977         9300 :       NULLIFY (subsection)
     978         9300 :       CALL create_almo_print_section(subsection)
     979         9300 :       CALL section_add_subsection(section, subsection)
     980         9300 :       CALL section_release(subsection)
     981              : 
     982         9300 :    END SUBROUTINE create_almo_analysis_section
     983              : 
     984              : ! *****************************************************************************
     985              : !> \brief Create a section with all print keys for ALMO methods
     986              : !> \param section ...
     987              : !> \par History
     988              : !>       2016.05 created [Rustam Z Khaliullin]
     989              : !> \author Rustam Z Khaliullin
     990              : ! **************************************************************************************************
     991         9300 :    SUBROUTINE create_almo_print_section(section)
     992              : 
     993              :       TYPE(section_type), POINTER                        :: section
     994              : 
     995              :       TYPE(section_type), POINTER                        :: print_key
     996              : 
     997         9300 :       CPASSERT(.NOT. ASSOCIATED(section))
     998         9300 :       NULLIFY (section, print_key)
     999              : 
    1000              :       CALL section_create(section, __LOCATION__, name="PRINT", &
    1001              :                           description="Controls printing of detailed ALMO decomosition analysis results", &
    1002         9300 :                           n_keywords=0, n_subsections=2, repeats=.TRUE.)
    1003              : 
    1004              :       ! create print keys within this subsection
    1005              :       CALL cp_print_key_section_create(print_key, __LOCATION__, "ALMO_EDA_CT", &
    1006              :                                        description="Controls printing of the electron transfer terms in "// &
    1007              :                                        "ALMO energy decomposition analysis. "// &
    1008              :                                        "File format: first column is the index of the electron acceptor "// &
    1009              :                                        "fragment, second -- is the index of the electron donor fragment, "// &
    1010              :                                        "third - the energy change (a.u.) associated with the electron transfer.", &
    1011              :                                        print_level=low_print_level, common_iter_levels=1, &
    1012         9300 :                                        filename="EDA")
    1013         9300 :       CALL section_add_subsection(section, print_key)
    1014         9300 :       CALL section_release(print_key)
    1015              : 
    1016              :       CALL cp_print_key_section_create(print_key, __LOCATION__, "ALMO_CTA", &
    1017              :                                        description="Controls printing of the electron transfer terms in "// &
    1018              :                                        "ALMO charge transfer analysis. "// &
    1019              :                                        "File format: first column is the index of the electron acceptor "// &
    1020              :                                        "fragment, second -- is the index of the electron donor fragment, "// &
    1021              :                                        "third - the change (a.u.) transferred between the two fragments.", &
    1022              :                                        print_level=low_print_level, common_iter_levels=1, &
    1023         9300 :                                        filename="CTA")
    1024         9300 :       CALL section_add_subsection(section, print_key)
    1025         9300 :       CALL section_release(print_key)
    1026              : 
    1027         9300 :    END SUBROUTINE create_almo_print_section
    1028              : 
    1029              : END MODULE input_cp2k_almo
        

Generated by: LCOV version 2.0-1