LCOV - code coverage report
Current view: top level - src - input_cp2k_ec.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:039bc03) Lines: 100.0 % 229 229
Test Date: 2026-03-13 07:10:03 Functions: 100.0 % 3 3

            Line data    Source code
       1              : !--------------------------------------------------------------------------------------------------!
       2              : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3              : !   Copyright 2000-2026 CP2K developers group <https://cp2k.org>                                   !
       4              : !                                                                                                  !
       5              : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6              : !--------------------------------------------------------------------------------------------------!
       7              : 
       8              : ! **************************************************************************************************
       9              : !> \brief function that build the dft section of the input
      10              : !> \par History
      11              : !>      10.2005 moved out of input_cp2k [fawzi]
      12              : !> \author fawzi
      13              : ! **************************************************************************************************
      14              : MODULE input_cp2k_ec
      15              :    USE bibliography,                    ONLY: Niklasson2003,&
      16              :                                               VandeVondele2012,&
      17              :                                               brehm2018
      18              :    USE cp_output_handling,              ONLY: cp_print_key_section_create,&
      19              :                                               debug_print_level,&
      20              :                                               high_print_level
      21              :    USE cp_units,                        ONLY: cp_unit_to_cp2k
      22              :    USE input_constants,                 ONLY: &
      23              :         bqb_opt_exhaustive, bqb_opt_normal, bqb_opt_off, bqb_opt_patient, bqb_opt_quick, &
      24              :         ec_diagonalization, ec_functional_dc, ec_functional_ext, ec_functional_harris, &
      25              :         ec_ls_solver, ec_matrix_sign, ec_matrix_tc2, ec_matrix_trs4, ec_mo_solver, ec_ot_atomic, &
      26              :         ec_ot_diag, ec_ot_gs, kg_cholesky, ls_cluster_atomic, ls_cluster_molecular, &
      27              :         ls_s_inversion_hotelling, ls_s_inversion_sign_sqrt, ls_s_preconditioner_atomic, &
      28              :         ls_s_preconditioner_molecular, ls_s_preconditioner_none, ls_s_sqrt_ns, ls_s_sqrt_proot, &
      29              :         ls_scf_sign_ns, ls_scf_sign_proot, ot_precond_full_all, ot_precond_full_kinetic, &
      30              :         ot_precond_full_single, ot_precond_full_single_inverse, ot_precond_none, &
      31              :         ot_precond_s_inverse, precond_mlp
      32              :    USE input_cp2k_mm,                   ONLY: create_dipoles_section
      33              :    USE input_cp2k_voronoi,              ONLY: create_print_voronoi_section
      34              :    USE input_cp2k_xc,                   ONLY: create_xc_section
      35              :    USE input_keyword_types,             ONLY: keyword_create,&
      36              :                                               keyword_release,&
      37              :                                               keyword_type
      38              :    USE input_section_types,             ONLY: section_add_keyword,&
      39              :                                               section_add_subsection,&
      40              :                                               section_create,&
      41              :                                               section_release,&
      42              :                                               section_type
      43              :    USE input_val_types,                 ONLY: char_t,&
      44              :                                               integer_t,&
      45              :                                               real_t
      46              :    USE kinds,                           ONLY: dp
      47              :    USE string_utilities,                ONLY: s2a
      48              : #include "./base/base_uses.f90"
      49              : 
      50              :    IMPLICIT NONE
      51              :    PRIVATE
      52              : 
      53              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'input_cp2k_ec'
      54              : 
      55              :    PUBLIC :: create_ec_section
      56              : 
      57              : CONTAINS
      58              : 
      59              : ! **************************************************************************************************
      60              : !> \brief creates the ENERGY CORRECTION section
      61              : !> \param section ...
      62              : !> \author JGH
      63              : ! **************************************************************************************************
      64         9552 :    SUBROUTINE create_ec_section(section)
      65              :       TYPE(section_type), POINTER                        :: section
      66              : 
      67              :       TYPE(keyword_type), POINTER                        :: keyword
      68              :       TYPE(section_type), POINTER                        :: subsection
      69              : 
      70         9552 :       CPASSERT(.NOT. ASSOCIATED(section))
      71              : 
      72         9552 :       NULLIFY (keyword)
      73              :       CALL section_create(section, __LOCATION__, name="ENERGY_CORRECTION", &
      74              :                           description="Sets the various options for the Energy Correction", &
      75         9552 :                           n_keywords=0, n_subsections=2, repeats=.FALSE.)
      76              : 
      77              :       CALL keyword_create(keyword, __LOCATION__, name="_SECTION_PARAMETERS_", &
      78              :                           description="Controls the activation of the energy_correction", &
      79              :                           usage="&ENERGY_CORRECTION T", &
      80              :                           default_l_val=.FALSE., &
      81         9552 :                           lone_keyword_l_val=.TRUE.)
      82         9552 :       CALL section_add_keyword(section, keyword)
      83         9552 :       CALL keyword_release(keyword)
      84              : 
      85              :       ! add a special XC section
      86         9552 :       NULLIFY (subsection)
      87         9552 :       CALL create_xc_section(subsection)
      88         9552 :       CALL section_add_subsection(section, subsection)
      89         9552 :       CALL section_release(subsection)
      90              : 
      91              :       ! add a section for solver keywords
      92         9552 :       NULLIFY (subsection)
      93         9552 :       CALL create_ec_solver_section(subsection)
      94         9552 :       CALL section_add_subsection(section, subsection)
      95         9552 :       CALL section_release(subsection)
      96              : 
      97              :       ! add a print section for properties
      98         9552 :       NULLIFY (subsection)
      99         9552 :       CALL create_ec_print_section(subsection)
     100         9552 :       CALL section_add_subsection(section, subsection)
     101         9552 :       CALL section_release(subsection)
     102              : 
     103              :       CALL keyword_create(keyword, __LOCATION__, name="ENERGY_FUNCTIONAL", &
     104              :                           description="Functional used in energy correction", &
     105              :                           usage="ENERGY_FUNCTIONAL HARRIS", &
     106              :                           default_i_val=ec_functional_harris, &
     107              :                           enum_c_vals=s2a("HARRIS", "DCDFT", "EXTERNAL"), &
     108              :                           enum_desc=s2a("Harris functional", &
     109              :                                         "Density-corrected DFT", &
     110              :                                         "External calculated energy"), &
     111         9552 :                           enum_i_vals=[ec_functional_harris, ec_functional_dc, ec_functional_ext])
     112         9552 :       CALL section_add_keyword(section, keyword)
     113         9552 :       CALL keyword_release(keyword)
     114              : 
     115              :       CALL keyword_create(keyword, __LOCATION__, name="HARRIS_BASIS", &
     116              :                           description="Specifies the type of basis to be used for the KG energy correction. "// &
     117              :                           "Options are: (1) the default orbital basis (ORBITAL); "// &
     118              :                           "(2) the primitive functions of the default orbital basis (PRIMITIVE); "// &
     119              :                           "(3) the basis set labeled in Kind section (HARRIS)", &
     120              :                           usage="HARRIS_BASIS ORBITAL", &
     121         9552 :                           type_of_var=char_t, default_c_val="ORBITAL", n_var=-1)
     122         9552 :       CALL section_add_keyword(section, keyword)
     123         9552 :       CALL keyword_release(keyword)
     124              : 
     125              :       CALL keyword_create(keyword, __LOCATION__, name="DEBUG_FORCES", &
     126              :                           description="Additional output to debug energy correction forces.", &
     127         9552 :                           usage="DEBUG_FORCES T", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     128         9552 :       CALL section_add_keyword(section, keyword)
     129         9552 :       CALL keyword_release(keyword)
     130              :       CALL keyword_create(keyword, __LOCATION__, name="DEBUG_STRESS", &
     131              :                           description="Additional output to debug energy correction forces.", &
     132         9552 :                           usage="DEBUG_STRESS T", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     133         9552 :       CALL section_add_keyword(section, keyword)
     134         9552 :       CALL keyword_release(keyword)
     135              :       CALL keyword_create(keyword, __LOCATION__, name="DEBUG_EXTERNAL_METHOD", &
     136              :                           description="Uses an internal pseudo-energy to test EXTERNAL energy method.", &
     137         9552 :                           usage="DEBUG_EXTERNAL_METHOD T", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     138         9552 :       CALL section_add_keyword(section, keyword)
     139         9552 :       CALL keyword_release(keyword)
     140              : 
     141              :       CALL keyword_create(keyword, __LOCATION__, name="SKIP_EC", &
     142              :                           description="Skip EC calculation if ground-state calculation has not converged.", &
     143         9552 :                           usage="SKIP_EC T", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     144         9552 :       CALL section_add_keyword(section, keyword)
     145         9552 :       CALL keyword_release(keyword)
     146              : 
     147              :       CALL keyword_create(keyword, __LOCATION__, name="MAO", &
     148              :                           description="Use modified atomic orbitals (MAO) to solve Harris equation", &
     149         9552 :                           usage="MAO T", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     150         9552 :       CALL section_add_keyword(section, keyword)
     151         9552 :       CALL keyword_release(keyword)
     152              : 
     153              :       CALL keyword_create(keyword, __LOCATION__, name="MAO_MAX_ITER", &
     154              :                           description="Maximum iterations in MAO optimization. ", &
     155         9552 :                           usage="MAO_MAX_ITER 100 ", default_i_val=0)
     156         9552 :       CALL section_add_keyword(section, keyword)
     157         9552 :       CALL keyword_release(keyword)
     158              : 
     159              :       CALL keyword_create(keyword, __LOCATION__, name="MAO_EPS_GRAD", &
     160              :                           description="Threshold used for MAO iterations. ", &
     161         9552 :                           usage="MAO_EPS_GRAD 1.0E-4 ", default_r_val=1.0E-5_dp)
     162         9552 :       CALL section_add_keyword(section, keyword)
     163         9552 :       CALL keyword_release(keyword)
     164              : 
     165              :       CALL keyword_create(keyword, __LOCATION__, name="MAO_EPS1", &
     166              :                           description="Occupation threshold used to determine number of MAOs."// &
     167              :                           " KIND section MAO keyword sets the minimum.", &
     168         9552 :                           usage="MAO_EPS1 0.001 ", default_r_val=1000.0_dp)
     169         9552 :       CALL section_add_keyword(section, keyword)
     170         9552 :       CALL keyword_release(keyword)
     171              : 
     172              :       CALL keyword_create(keyword, __LOCATION__, name="MAO_IOLEVEL", &
     173              :                           description="Verbosity of MAO output: (0) no output ... (3) fully verbose", &
     174         9552 :                           usage="MAO_IOLEVEL 0 ", default_i_val=1)
     175         9552 :       CALL section_add_keyword(section, keyword)
     176         9552 :       CALL keyword_release(keyword)
     177              : 
     178              :       CALL keyword_create(keyword, __LOCATION__, &
     179              :                           name="ELECTRONIC_TEMPERATURE", &
     180              :                           variants=s2a("ELEC_TEMP", "FD_TEMP"), &
     181              :                           description="Electronic temperature for Harris functional with "// &
     182              :                           "Fermi-Dirac smearing.", &
     183              :                           repeats=.FALSE., &
     184              :                           n_var=1, &
     185              :                           type_of_var=real_t, &
     186              :                           default_r_val=cp_unit_to_cp2k(value=0.0_dp, unit_str="K"), &
     187              :                           unit_str="K", &
     188         9552 :                           usage="ELECTRONIC_TEMPERATURE [K] 300")
     189         9552 :       CALL section_add_keyword(section, keyword)
     190         9552 :       CALL keyword_release(keyword)
     191              : 
     192              :       CALL keyword_create(keyword, __LOCATION__, name="ALGORITHM", &
     193              :                           description="Algorithm used to solve KS equation", &
     194              :                           usage="ALGORITHM DIAGONALIZATION", &
     195              :                           default_i_val=ec_diagonalization, &
     196              :                           enum_c_vals=s2a("DIAGONALIZATION", "MATRIX_SIGN", &
     197              :                                           "TRS4", "TC2", "OT_DIAG"), &
     198              :                           enum_desc=s2a("Diagonalization of KS matrix.", &
     199              :                                         "Matrix Sign algorithm", &
     200              :                                         "Trace resetting trs4 algorithm", &
     201              :                                         "Trace resetting tc2 algorithm", &
     202              :                                         "OT diagonalization"), &
     203              :                           enum_i_vals=[ec_diagonalization, ec_matrix_sign, &
     204         9552 :                                        ec_matrix_trs4, ec_matrix_tc2, ec_ot_diag])
     205         9552 :       CALL section_add_keyword(section, keyword)
     206         9552 :       CALL keyword_release(keyword)
     207              : 
     208              :       CALL keyword_create(keyword, __LOCATION__, name="FACTORIZATION", &
     209              :                           description="Algorithm used to calculate factorization of overlap matrix", &
     210              :                           usage="FACTORIZATION CHOLESKY", &
     211              :                           default_i_val=kg_cholesky, &
     212              :                           enum_c_vals=s2a("CHOLESKY"), &
     213              :                           enum_desc=s2a("Cholesky factorization of overlap matrix"), &
     214         9552 :                           enum_i_vals=[kg_cholesky])
     215         9552 :       CALL section_add_keyword(section, keyword)
     216         9552 :       CALL keyword_release(keyword)
     217              : 
     218              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_DEFAULT", &
     219              :                           description="Threshold used for accuracy estimates within energy correction. ", &
     220         9552 :                           usage="EPS_DEFAULT 1.0E-7 ", default_r_val=1.0E-7_dp)
     221         9552 :       CALL section_add_keyword(section, keyword)
     222         9552 :       CALL keyword_release(keyword)
     223              : 
     224              :       ! Keywords for LS solver of Harris functional
     225              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_FILTER", &
     226              :                           description="Threshold used for filtering matrix operations.", &
     227         9552 :                           usage="EPS_FILTER 1.0E-12", default_r_val=1.0E-12_dp)
     228         9552 :       CALL section_add_keyword(section, keyword)
     229         9552 :       CALL keyword_release(keyword)
     230              : 
     231              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_LANCZOS", &
     232              :                           description="Threshold used for lanczos estimates.", &
     233         9552 :                           usage="EPS_LANCZOS 1.0E-4", default_r_val=1.0E-3_dp)
     234         9552 :       CALL section_add_keyword(section, keyword)
     235         9552 :       CALL keyword_release(keyword)
     236              : 
     237              :       CALL keyword_create(keyword, __LOCATION__, name="MAX_ITER_LANCZOS", &
     238              :                           description="Maximum number of lanczos iterations.", &
     239         9552 :                           usage="MAX_ITER_LANCZOS ", default_i_val=128)
     240         9552 :       CALL section_add_keyword(section, keyword)
     241         9552 :       CALL keyword_release(keyword)
     242              : 
     243              :       CALL keyword_create(keyword, __LOCATION__, name="MU", &
     244              :                           description="Value (or initial guess) for the chemical potential,"// &
     245              :                           " i.e. some suitable energy between HOMO and LUMO energy.", &
     246         9552 :                           usage="MU 0.0", default_r_val=-0.1_dp)
     247         9552 :       CALL section_add_keyword(section, keyword)
     248         9552 :       CALL keyword_release(keyword)
     249              : 
     250              :       CALL keyword_create(keyword, __LOCATION__, name="FIXED_MU", &
     251              :                           description="Should the calculation be performed at fixed chemical potential,"// &
     252              :                           " or should it be found fixing the number of electrons", &
     253         9552 :                           usage="FIXED_MU .TRUE.", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     254         9552 :       CALL section_add_keyword(section, keyword)
     255         9552 :       CALL keyword_release(keyword)
     256              : 
     257              :       CALL keyword_create(keyword, __LOCATION__, name="S_PRECONDITIONER", &
     258              :                           description="Preconditions S with some appropriate form.", &
     259              :                           usage="S_PRECONDITIONER MOLECULAR", &
     260              :                           default_i_val=ls_s_preconditioner_atomic, &
     261              :                           enum_c_vals=s2a("NONE", "ATOMIC", "MOLECULAR"), &
     262              :                           enum_desc=s2a("No preconditioner", &
     263              :                                         "Using atomic blocks", &
     264              :                                         "Using molecular sub-blocks. Recommended if molecules are defined and not too large."), &
     265         9552 :                           enum_i_vals=[ls_s_preconditioner_none, ls_s_preconditioner_atomic, ls_s_preconditioner_molecular])
     266         9552 :       CALL section_add_keyword(section, keyword)
     267         9552 :       CALL keyword_release(keyword)
     268              : 
     269              :       CALL keyword_create(keyword, __LOCATION__, name="S_SQRT_METHOD", &
     270              :                           description="Method for the caclulation of the sqrt of S.", &
     271              :                           usage="S_SQRT_METHOD NEWTONSCHULZ", &
     272              :                           default_i_val=ls_s_sqrt_ns, &
     273              :                           enum_c_vals=s2a("NEWTONSCHULZ", "PROOT"), &
     274              :                           enum_desc=s2a("Using a Newton-Schulz-like iteration", &
     275              :                                         "Using the p-th root method."), &
     276         9552 :                           enum_i_vals=[ls_s_sqrt_ns, ls_s_sqrt_proot])
     277         9552 :       CALL section_add_keyword(section, keyword)
     278         9552 :       CALL keyword_release(keyword)
     279              : 
     280              :       CALL keyword_create(keyword, __LOCATION__, name="S_SQRT_ORDER", &
     281              :                           variants=s2a("SIGN_SQRT_ORDER"), &
     282              :                           description="Order of the iteration method for the calculation of the sqrt of S.", &
     283         9552 :                           usage="S_SQRT_ORDER 3", default_i_val=3)
     284         9552 :       CALL section_add_keyword(section, keyword)
     285         9552 :       CALL keyword_release(keyword)
     286              : 
     287              :       CALL keyword_create(keyword, __LOCATION__, name="SIGN_METHOD", &
     288              :                           description="Method used for the computation of the sign matrix.", &
     289              :                           usage="SIGN_METHOD NEWTONSCHULZ", &
     290              :                           default_i_val=ls_scf_sign_ns, &
     291              :                           citations=[VandeVondele2012, Niklasson2003], &
     292              :                           enum_c_vals=s2a("NEWTONSCHULZ", "PROOT"), &
     293              :                           enum_desc=s2a("Newton-Schulz iteration.", &
     294              :                                         "p-th order root iteration"), &
     295        28656 :                           enum_i_vals=[ls_scf_sign_ns, ls_scf_sign_proot])
     296         9552 :       CALL section_add_keyword(section, keyword)
     297         9552 :       CALL keyword_release(keyword)
     298              : 
     299              :       CALL keyword_create(keyword, __LOCATION__, name="SIGN_ORDER", &
     300              :                           description="Order of the method used for the computation of the sign matrix.", &
     301              :                           usage="SIGN_ORDER 2", &
     302         9552 :                           default_i_val=2)
     303         9552 :       CALL section_add_keyword(section, keyword)
     304         9552 :       CALL keyword_release(keyword)
     305              : 
     306              :       CALL keyword_create(keyword, __LOCATION__, name="DYNAMIC_THRESHOLD", &
     307              :                           description="Should the threshold for the purification be chosen dynamically", &
     308         9552 :                           usage="DYNAMIC_THRESHOLD .TRUE.", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     309         9552 :       CALL section_add_keyword(section, keyword)
     310         9552 :       CALL keyword_release(keyword)
     311              : 
     312              :       CALL keyword_create(keyword, __LOCATION__, name="NON_MONOTONIC", &
     313              :                           description="Should the purification be performed non-monotonically. Relevant for TC2 only.", &
     314         9552 :                           usage="NON_MONOTONIC .TRUE.", default_l_val=.TRUE., lone_keyword_l_val=.TRUE.)
     315         9552 :       CALL section_add_keyword(section, keyword)
     316         9552 :       CALL keyword_release(keyword)
     317              : 
     318              :       CALL keyword_create( &
     319              :          keyword, __LOCATION__, name="MATRIX_CLUSTER_TYPE", &
     320              :          description="Specify how atomic blocks should be clustered in the used matrices, in order to improve flop rate, "// &
     321              :          "and possibly speedup the matrix multiply. Note that the atomic s_preconditioner can not be used. "// &
     322              :          "Furthermore, since screening is on matrix blocks, "// &
     323              :          "slightly more accurate results can be expected with molecular.", &
     324              :          usage="MATRIX_CLUSTER_TYPE MOLECULAR", &
     325              :          default_i_val=ls_cluster_atomic, &
     326              :          enum_c_vals=s2a("ATOMIC", "MOLECULAR"), &
     327              :          enum_desc=s2a("Using atomic blocks", &
     328              :                        "Using molecular blocks."), &
     329         9552 :          enum_i_vals=[ls_cluster_atomic, ls_cluster_molecular])
     330         9552 :       CALL section_add_keyword(section, keyword)
     331         9552 :       CALL keyword_release(keyword)
     332              : 
     333              :       CALL keyword_create(keyword, __LOCATION__, name="S_INVERSION", &
     334              :                           description="Method used to compute the inverse of S.", &
     335              :                           usage="S_INVERSION MOLECULAR", &
     336              :                           default_i_val=ls_s_inversion_sign_sqrt, &
     337              :                           enum_c_vals=s2a("SIGN_SQRT", "HOTELLING"), &
     338              :                           enum_desc=s2a("Using the inverse sqrt as obtained from sign function iterations.", &
     339              :                                         "Using the Hotellign iteration."), &
     340         9552 :                           enum_i_vals=[ls_s_inversion_sign_sqrt, ls_s_inversion_hotelling])
     341         9552 :       CALL section_add_keyword(section, keyword)
     342         9552 :       CALL keyword_release(keyword)
     343              : 
     344              :       CALL keyword_create(keyword, __LOCATION__, name="REPORT_ALL_SPARSITIES", &
     345              :                           description="Run the sparsity report at the end of the SCF", &
     346         9552 :                           usage="REPORT_ALL_SPARSITIES", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     347         9552 :       CALL section_add_keyword(section, keyword)
     348         9552 :       CALL keyword_release(keyword)
     349              : 
     350              :       CALL keyword_create(keyword, __LOCATION__, name="CHECK_S_INV", &
     351              :                           description="Perform an accuracy check on the inverse/sqrt of the s matrix.", &
     352         9552 :                           usage="CHECK_S_INV", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     353         9552 :       CALL section_add_keyword(section, keyword)
     354         9552 :       CALL keyword_release(keyword)
     355              : 
     356              :       CALL keyword_create(keyword, __LOCATION__, name="OT_INITIAL_GUESS", &
     357              :                           description="Initial guess of density matrix used for OT Diagonalization", &
     358              :                           usage="OT_INITIAL_GUESS ATOMIC", &
     359              :                           default_i_val=ec_ot_atomic, &
     360              :                           enum_c_vals=s2a("ATOMIC", "GROUND_STATE"), &
     361              :                           enum_desc=s2a("Generate an atomic density using the atomic code", &
     362              :                                         "Using the ground-state density."), &
     363         9552 :                           enum_i_vals=[ec_ot_atomic, ec_ot_gs])
     364         9552 :       CALL section_add_keyword(section, keyword)
     365         9552 :       CALL keyword_release(keyword)
     366              : 
     367              :       CALL keyword_create( &
     368              :          keyword, __LOCATION__, &
     369              :          name="ADMM", &
     370              :          description="Decide whether to perform ADMM in the exact exchange calc. for DC-DFT. "// &
     371              :          "The ADMM XC correction is governed by the AUXILIARY_DENSITY_MATRIX_METHOD section in &DFT. "// &
     372              :          "In most cases, the Hartree-Fock exchange is not too expensive and there is no need for ADMM, "// &
     373              :          "ADMM can however provide significant speedup and memory savings in case of diffuse basis sets. ", &
     374              :          usage="ADMM", &
     375              :          default_l_val=.FALSE., &
     376         9552 :          lone_keyword_l_val=.TRUE.)
     377         9552 :       CALL section_add_keyword(section, keyword)
     378         9552 :       CALL keyword_release(keyword)
     379              : 
     380              :       CALL keyword_create(keyword, __LOCATION__, name="EXTERNAL_RESPONSE_FILENAME", &
     381              :                           description="Name of the file that contains response information.", &
     382              :                           usage="EXTERNAL_RESPONSE_FILENAME <FILENAME>", &
     383         9552 :                           default_c_val="TREXIO")
     384         9552 :       CALL section_add_keyword(section, keyword)
     385         9552 :       CALL keyword_release(keyword)
     386              : 
     387              :       CALL keyword_create(keyword, __LOCATION__, name="EXTERNAL_RESPONSE_ERROR_FILENAME", &
     388              :                           description="Name of the file that contains response error information.", &
     389              :                           usage="EXTERNAL_RESPONSE_ERROR_FILENAME <FILENAME>", &
     390         9552 :                           default_c_val="TREXIO")
     391         9552 :       CALL section_add_keyword(section, keyword)
     392         9552 :       CALL keyword_release(keyword)
     393              : 
     394              :       CALL keyword_create(keyword, __LOCATION__, name="EXTERNAL_RESULT_FILENAME", &
     395              :                           description="Name of the file that contains results from external response calculation.", &
     396              :                           usage="EXTERNAL_RESULT_FILENAME <FILENAME>", &
     397         9552 :                           default_c_val="CP2K_EXRESP.result")
     398         9552 :       CALL section_add_keyword(section, keyword)
     399         9552 :       CALL keyword_release(keyword)
     400              : 
     401              :       CALL keyword_create( &
     402              :          keyword, __LOCATION__, &
     403              :          name="ERROR_ESTIMATION", &
     404              :          description="Perform an error estimation for the response forces/stress. "// &
     405              :          "Requires error estimates for the RHS of the response equation from input. ", &
     406              :          usage="ERROR_ESTIMATION", &
     407              :          default_l_val=.FALSE., &
     408         9552 :          lone_keyword_l_val=.TRUE.)
     409         9552 :       CALL section_add_keyword(section, keyword)
     410         9552 :       CALL keyword_release(keyword)
     411              : 
     412              :       CALL keyword_create(keyword, __LOCATION__, name="ERROR_ESTIMATION_METHOD", &
     413              :                           description="Method used for error estimation: F(ull); D(ifferenc); E(xtrapolate).", &
     414              :                           usage="ERROR_ESTIMATION_METHOD E", &
     415         9552 :                           default_c_val="E")
     416         9552 :       CALL section_add_keyword(section, keyword)
     417         9552 :       CALL keyword_release(keyword)
     418              : 
     419              :       CALL keyword_create(keyword, __LOCATION__, name="ERROR_CUTOFF", &
     420              :                           description="Cutoff value for error estimation.", &
     421              :                           usage="ERROR_CUTOFF 1.E-6", &
     422         9552 :                           default_r_val=1.E-5_dp)
     423         9552 :       CALL section_add_keyword(section, keyword)
     424         9552 :       CALL keyword_release(keyword)
     425              : 
     426              :       CALL keyword_create(keyword, __LOCATION__, name="ERROR_SUBSPACE_SIZE", &
     427              :                           description="MAX. size of subspace for response vector extrapolation.", &
     428              :                           usage="ERROR_SUBSPACE_SIZE 100", &
     429         9552 :                           default_i_val=250)
     430         9552 :       CALL section_add_keyword(section, keyword)
     431         9552 :       CALL keyword_release(keyword)
     432              : 
     433         9552 :    END SUBROUTINE create_ec_section
     434              : 
     435              : ! **************************************************************************************************
     436              : !> \brief creates the linear scaling solver section
     437              : !> \param section ...
     438              : !> \author Joost VandeVondele [2010-10], JGH [2019-12]
     439              : ! **************************************************************************************************
     440         9552 :    SUBROUTINE create_ec_solver_section(section)
     441              :       TYPE(section_type), POINTER                        :: section
     442              : 
     443              :       TYPE(keyword_type), POINTER                        :: keyword
     444              : 
     445         9552 :       CPASSERT(.NOT. ASSOCIATED(section))
     446              :       CALL section_create(section, __LOCATION__, name="RESPONSE_SOLVER", &
     447              :                           description="Specifies the parameters of the linear scaling solver routines", &
     448              :                           n_keywords=24, n_subsections=3, repeats=.FALSE., &
     449        19104 :                           citations=[VandeVondele2012])
     450              : 
     451         9552 :       NULLIFY (keyword)
     452              : 
     453              :       CALL keyword_create(keyword, __LOCATION__, name="EPS", &
     454              :                           description="Target accuracy for the convergence of the conjugate gradient.", &
     455         9552 :                           usage="EPS 1.e-10", default_r_val=1.e-12_dp)
     456         9552 :       CALL section_add_keyword(section, keyword)
     457         9552 :       CALL keyword_release(keyword)
     458              : 
     459              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_FILTER", &
     460              :                           description="Threshold used for filtering matrix operations.", &
     461         9552 :                           usage="EPS_FILTER 1.0E-10", default_r_val=1.0E-10_dp)
     462         9552 :       CALL section_add_keyword(section, keyword)
     463         9552 :       CALL keyword_release(keyword)
     464              : 
     465              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_LANCZOS", &
     466              :                           description="Threshold used for lanczos estimates.", &
     467         9552 :                           usage="EPS_LANCZOS 1.0E-4", default_r_val=1.0E-3_dp)
     468         9552 :       CALL section_add_keyword(section, keyword)
     469         9552 :       CALL keyword_release(keyword)
     470              : 
     471              :       CALL keyword_create(keyword, __LOCATION__, name="MAX_ITER", &
     472              :                           description="Maximum number of conjugate gradient iteration "// &
     473              :                           "to be performed for one optimization.", &
     474         9552 :                           usage="MAX_ITER 200", default_i_val=50)
     475         9552 :       CALL section_add_keyword(section, keyword)
     476         9552 :       CALL keyword_release(keyword)
     477              : 
     478              :       CALL keyword_create(keyword, __LOCATION__, name="MAX_ITER_LANCZOS", &
     479              :                           description="Maximum number of lanczos iterations.", &
     480         9552 :                           usage="MAX_ITER_LANCZOS 128", default_i_val=128)
     481         9552 :       CALL section_add_keyword(section, keyword)
     482         9552 :       CALL keyword_release(keyword)
     483              : 
     484              :       CALL keyword_create(keyword, __LOCATION__, name="METHOD", &
     485              :                           description="Algorithm used to solve response equation. "// &
     486              :                           "Both solver are conjugate gradient based, but use either a vector (MO-coefficient) "// &
     487              :                           "or density matrix formalism in the orthonormal AO-basis to obtain response density", &
     488              :                           usage="METHOD SOLVER", &
     489              :                           default_i_val=ec_ls_solver, &
     490              :                           enum_c_vals=s2a("MO_SOLVER", "AO_ORTHO"), &
     491              :                           enum_desc=s2a("Solver based on MO (vector) formalism", &
     492              :                                         "Solver based on density matrix formalism"), &
     493         9552 :                           enum_i_vals=[ec_mo_solver, ec_ls_solver])
     494         9552 :       CALL section_add_keyword(section, keyword)
     495         9552 :       CALL keyword_release(keyword)
     496              : 
     497              :       CALL keyword_create( &
     498              :          keyword, __LOCATION__, name="PRECONDITIONER", &
     499              :          description="Type of preconditioner to be used with MO conjugate gradient solver. "// &
     500              :          "They differ in effectiveness, cost of construction, cost of application. "// &
     501              :          "Properly preconditioned minimization can be orders of magnitude faster than doing nothing. "// &
     502              :          "Only multi-level conjugate gradient preconditioner (MULTI_LEVEL) available for AO response solver (AO_ORTHO). ", &
     503              :          usage="PRECONDITIONER FULL_ALL", &
     504              :          default_i_val=precond_mlp, &
     505              :          enum_c_vals=s2a("FULL_ALL", "FULL_SINGLE_INVERSE", "FULL_SINGLE", "FULL_KINETIC", "FULL_S_INVERSE", &
     506              :                          "MULTI_LEVEL", "NONE"), &
     507              :          enum_desc=s2a("Most effective state selective preconditioner based on diagonalization, "// &
     508              :                        "requires the ENERGY_GAP parameter to be an underestimate of the HOMO-LUMO gap. "// &
     509              :                        "This preconditioner is recommended for almost all systems, except very large systems where "// &
     510              :                        "make_preconditioner would dominate the total computational cost.", &
     511              :                        "Based on H-eS cholesky inversion, similar to FULL_SINGLE in preconditioning efficiency "// &
     512              :                        "but cheaper to construct, "// &
     513              :                        "might be somewhat less robust. Recommended for large systems.", &
     514              :                        "Based on H-eS diagonalisation, not as good as FULL_ALL, but somewhat cheaper to apply. ", &
     515              :                        "Cholesky inversion of S and T, fast construction, robust, and relatively good, "// &
     516              :                        "use for very large systems.", &
     517              :                        "Cholesky inversion of S, not as good as FULL_KINETIC, yet equally expensive.", &
     518              :                        "Based on same CG as AO-solver itself, but uses cheaper linear transformation", &
     519              :                        "skip preconditioning"), &
     520              :          enum_i_vals=[ot_precond_full_all, ot_precond_full_single_inverse, ot_precond_full_single, &
     521         9552 :                       ot_precond_full_kinetic, ot_precond_s_inverse, precond_mlp, ot_precond_none])
     522         9552 :       CALL section_add_keyword(section, keyword)
     523         9552 :       CALL keyword_release(keyword)
     524              : 
     525              :       CALL keyword_create(keyword, __LOCATION__, name="S_PRECONDITIONER", &
     526              :                           description="Preconditions S with some appropriate form.", &
     527              :                           usage="S_PRECONDITIONER MOLECULAR", &
     528              :                           default_i_val=ls_s_preconditioner_atomic, &
     529              :                           enum_c_vals=s2a("NONE", "ATOMIC", "MOLECULAR"), &
     530              :                           enum_desc=s2a("No preconditioner", &
     531              :                                         "Using atomic blocks", &
     532              :                                         "Using molecular sub-blocks. Recommended if molecules are defined and not too large."), &
     533         9552 :                           enum_i_vals=[ls_s_preconditioner_none, ls_s_preconditioner_atomic, ls_s_preconditioner_molecular])
     534         9552 :       CALL section_add_keyword(section, keyword)
     535         9552 :       CALL keyword_release(keyword)
     536              : 
     537              :       CALL keyword_create(keyword, __LOCATION__, name="S_SQRT_METHOD", &
     538              :                           description="Method for the caclulation of the sqrt of S.", &
     539              :                           usage="S_SQRT_METHOD NEWTONSCHULZ", &
     540              :                           default_i_val=ls_s_sqrt_ns, &
     541              :                           enum_c_vals=s2a("NEWTONSCHULZ", "PROOT"), &
     542              :                           enum_desc=s2a("Using a Newton-Schulz-like iteration", &
     543              :                                         "Using the p-th root method."), &
     544         9552 :                           enum_i_vals=[ls_s_sqrt_ns, ls_s_sqrt_proot])
     545         9552 :       CALL section_add_keyword(section, keyword)
     546         9552 :       CALL keyword_release(keyword)
     547              : 
     548              :       CALL keyword_create(keyword, __LOCATION__, name="S_SQRT_ORDER", &
     549              :                           variants=s2a("SIGN_SQRT_ORDER"), &
     550              :                           description="Order of the iteration method for the calculation of the sqrt of S.", &
     551         9552 :                           usage="S_SQRT_ORDER 3", default_i_val=3)
     552         9552 :       CALL section_add_keyword(section, keyword)
     553         9552 :       CALL keyword_release(keyword)
     554              : 
     555              :       CALL keyword_create( &
     556              :          keyword, __LOCATION__, name="MATRIX_CLUSTER_TYPE", &
     557              :          description="Specify how atomic blocks should be clustered in the used matrices, in order to improve flop rate, "// &
     558              :          "and possibly speedup the matrix multiply. Note that the atomic s_preconditioner can not be used. "// &
     559              :          "Furthermore, since screening is on matrix blocks, "// &
     560              :          "slightly more accurate results can be expected with molecular.", &
     561              :          usage="MATRIX_CLUSTER_TYPE MOLECULAR", &
     562              :          default_i_val=ls_cluster_atomic, &
     563              :          enum_c_vals=s2a("ATOMIC", "MOLECULAR"), &
     564              :          enum_desc=s2a("Using atomic blocks", &
     565              :                        "Using molecular blocks."), &
     566         9552 :          enum_i_vals=[ls_cluster_atomic, ls_cluster_molecular])
     567         9552 :       CALL section_add_keyword(section, keyword)
     568         9552 :       CALL keyword_release(keyword)
     569              : 
     570              :       CALL keyword_create(keyword, __LOCATION__, name="S_INVERSION", &
     571              :                           description="Method used to compute the inverse of S.", &
     572              :                           usage="S_INVERSION MOLECULAR", &
     573              :                           default_i_val=ls_s_inversion_sign_sqrt, &
     574              :                           enum_c_vals=s2a("SIGN_SQRT", "HOTELLING"), &
     575              :                           enum_desc=s2a("Using the inverse sqrt as obtained from sign function iterations.", &
     576              :                                         "Using the Hotellign iteration."), &
     577         9552 :                           enum_i_vals=[ls_s_inversion_sign_sqrt, ls_s_inversion_hotelling])
     578         9552 :       CALL section_add_keyword(section, keyword)
     579         9552 :       CALL keyword_release(keyword)
     580              : 
     581              :       CALL keyword_create(keyword, __LOCATION__, name="RESTART", &
     582              :                           description="Restart the response calculation if the restart file exists", &
     583              :                           usage="RESTART", &
     584         9552 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     585         9552 :       CALL section_add_keyword(section, keyword)
     586         9552 :       CALL keyword_release(keyword)
     587              : 
     588              :       CALL keyword_create(keyword, __LOCATION__, name="RESTART_EVERY", &
     589              :                           description="Restart the conjugate gradient after the specified number of iterations.", &
     590         9552 :                           usage="RESTART_EVERY 50", default_i_val=50)
     591         9552 :       CALL section_add_keyword(section, keyword)
     592         9552 :       CALL keyword_release(keyword)
     593              : 
     594         9552 :    END SUBROUTINE create_ec_solver_section
     595              : 
     596              : ! **************************************************************************************************
     597              : !> \brief Create the print dft section
     598              : !> \param section the section to create
     599              : !> \author fbelle - from create_print_dft_section
     600              : ! **************************************************************************************************
     601         9552 :    SUBROUTINE create_ec_print_section(section)
     602              :       TYPE(section_type), POINTER                        :: section
     603              : 
     604              :       TYPE(keyword_type), POINTER                        :: keyword
     605              :       TYPE(section_type), POINTER                        :: print_key
     606              : 
     607         9552 :       CPASSERT(.NOT. ASSOCIATED(section))
     608              :       CALL section_create(section, __LOCATION__, name="PRINT", &
     609              :                           description="Section of possible print options in EC code.", &
     610         9552 :                           n_keywords=0, n_subsections=1, repeats=.FALSE.)
     611              : 
     612         9552 :       NULLIFY (print_key, keyword)
     613              : 
     614              :       ! Output of BQB volumetric files
     615              :       CALL cp_print_key_section_create(print_key, __LOCATION__, name="E_DENSITY_BQB", &
     616              :                                        description="Controls the output of the electron density to the losslessly"// &
     617              :                                        " compressed BQB file format, see [Brehm2018]"// &
     618              :                                        " (via LibBQB see <https://brehm-research.de/bqb>)."// &
     619              :                                        " Currently does not work with changing cell vector (NpT ensemble).", &
     620              :                                        print_level=debug_print_level + 1, filename="", &
     621        19104 :                                        citations=[Brehm2018])
     622              : 
     623              :       CALL keyword_create(keyword, __LOCATION__, name="SKIP_FIRST", &
     624              :                           description="Skips the first step of a MD run (avoids duplicate step if restarted).", &
     625         9552 :                           usage="SKIP_FIRST T", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     626         9552 :       CALL section_add_keyword(print_key, keyword)
     627         9552 :       CALL keyword_release(keyword)
     628              : 
     629              :       CALL keyword_create(keyword, __LOCATION__, name="STORE_STEP_NUMBER", &
     630              :                           description="Stores the step number and simulation time in the comment line of each BQB"// &
     631              :                           " frame. Switch it off for binary compatibility with original CP2k CUBE files.", &
     632         9552 :                           usage="STORE_STEP_NUMBER F", default_l_val=.TRUE., lone_keyword_l_val=.TRUE.)
     633         9552 :       CALL section_add_keyword(print_key, keyword)
     634         9552 :       CALL keyword_release(keyword)
     635              : 
     636              :       CALL keyword_create(keyword, __LOCATION__, name="CHECK", &
     637              :                           description="Performs an on-the-fly decompression of each compressed BQB frame to check"// &
     638              :                           " whether the volumetric data exactly matches, and aborts the run if not so.", &
     639         9552 :                           usage="CHECK T", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     640         9552 :       CALL section_add_keyword(print_key, keyword)
     641         9552 :       CALL keyword_release(keyword)
     642              : 
     643              :       CALL keyword_create(keyword, __LOCATION__, name="OVERWRITE", &
     644              :                           description="Specify this keyword to overwrite the output BQB file if"// &
     645              :                           " it already exists. By default, the data is appended to an existing file.", &
     646         9552 :                           usage="OVERWRITE T", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     647         9552 :       CALL section_add_keyword(print_key, keyword)
     648         9552 :       CALL keyword_release(keyword)
     649              : 
     650              :       CALL keyword_create(keyword, __LOCATION__, name="HISTORY", &
     651              :                           description="Controls how many previous steps are taken into account for extrapolation in"// &
     652              :                           " compression. Use a value of 1 to compress the frames independently.", &
     653         9552 :                           usage="HISTORY 10", n_var=1, default_i_val=10, type_of_var=integer_t)
     654         9552 :       CALL section_add_keyword(print_key, keyword)
     655         9552 :       CALL keyword_release(keyword)
     656              : 
     657              :       CALL keyword_create(keyword, __LOCATION__, name="PARAMETER_KEY", &
     658              :                           description="Allows to supply previously optimized compression parameters via a"// &
     659              :                           " parameter key (alphanumeric character sequence starting with 'at')."// &
     660              :                           " Just leave away the 'at' sign here, because CP2k will otherwise"// &
     661              :                           " assume it is a variable name in the input", &
     662         9552 :                           usage="PARAMETER_KEY <KEY>", n_var=1, default_c_val="", type_of_var=char_t)
     663         9552 :       CALL section_add_keyword(print_key, keyword)
     664         9552 :       CALL keyword_release(keyword)
     665              : 
     666              :       CALL keyword_create(keyword, __LOCATION__, name="OPTIMIZE", &
     667              :                           description="Controls the time spent to optimize the parameters for compression efficiency.", &
     668              :                           usage="OPTIMIZE {OFF,QUICK,NORMAL,PATIENT,EXHAUSTIVE}", repeats=.FALSE., n_var=1, &
     669              :                           default_i_val=bqb_opt_quick, &
     670              :                           enum_c_vals=s2a("OFF", "QUICK", "NORMAL", "PATIENT", "EXHAUSTIVE"), &
     671              :                           enum_desc=s2a("No optimization (use defaults)", "Quick optimization", &
     672              :                                         "Standard optimization", "Precise optimization", "Exhaustive optimization"), &
     673         9552 :                           enum_i_vals=[bqb_opt_off, bqb_opt_quick, bqb_opt_normal, bqb_opt_patient, bqb_opt_exhaustive])
     674         9552 :       CALL section_add_keyword(print_key, keyword)
     675         9552 :       CALL keyword_release(keyword)
     676              : 
     677         9552 :       CALL section_add_subsection(section, print_key)
     678         9552 :       CALL section_release(print_key)
     679              : 
     680              :       ! Voronoi Integration via LibVori
     681         9552 :       NULLIFY (print_key)
     682         9552 :       CALL create_print_voronoi_section(print_key)
     683         9552 :       CALL section_add_subsection(section, print_key)
     684         9552 :       CALL section_release(print_key)
     685              : 
     686              :       !Printing of Moments
     687         9552 :       CALL create_dipoles_section(print_key, "MOMENTS", high_print_level)
     688              :       CALL keyword_create( &
     689              :          keyword, __LOCATION__, &
     690              :          name="MAX_MOMENT", &
     691              :          description="Maximum moment to be calculated. Values higher than 1 not implemented under periodic boundaries.", &
     692              :          usage="MAX_MOMENT {integer}", &
     693              :          repeats=.FALSE., &
     694              :          n_var=1, &
     695              :          type_of_var=integer_t, &
     696         9552 :          default_i_val=1)
     697         9552 :       CALL section_add_keyword(print_key, keyword)
     698         9552 :       CALL keyword_release(keyword)
     699              :       CALL keyword_create(keyword, __LOCATION__, &
     700              :                           name="MAGNETIC", &
     701              :                           description="Calculate also magnetic moments, only implemented without periodic boundaries", &
     702              :                           usage="MAGNETIC yes", &
     703              :                           repeats=.FALSE., &
     704              :                           n_var=1, &
     705              :                           default_l_val=.FALSE., &
     706         9552 :                           lone_keyword_l_val=.TRUE.)
     707         9552 :       CALL section_add_keyword(print_key, keyword)
     708         9552 :       CALL keyword_release(keyword)
     709         9552 :       CALL section_add_subsection(section, print_key)
     710         9552 :       CALL section_release(print_key)
     711              : 
     712         9552 :    END SUBROUTINE create_ec_print_section
     713              : 
     714              : END MODULE input_cp2k_ec
        

Generated by: LCOV version 2.0-1