LCOV - code coverage report
Current view: top level - src - input_cp2k_tb.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:71c3ab0) Lines: 100.0 % 476 476
Test Date: 2026-07-25 06:35:44 Functions: 100.0 % 14 14

            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_tb
      15              :    USE bibliography,                    ONLY: Elstner1998,&
      16              :                                               Grimme2017,&
      17              :                                               Hu2007,&
      18              :                                               Katbashev2025,&
      19              :                                               Porezag1995,&
      20              :                                               Seifert1996,&
      21              :                                               Zhechkov2005
      22              :    USE cp_units,                        ONLY: cp_unit_to_cp2k
      23              :    USE eeq_input,                       ONLY: create_eeq_control_section
      24              :    USE input_constants,                 ONLY: &
      25              :         dispersion_d2, dispersion_d3, dispersion_d3bj, dispersion_uff, gfn1xtb, gfn2xtb, &
      26              :         gfn_tblite, ipea1xtb, slater, tblite_cli_born_kernel_auto, tblite_cli_born_kernel_p16, &
      27              :         tblite_cli_born_kernel_still, tblite_cli_solution_state_bar1mol, &
      28              :         tblite_cli_solution_state_gsolv, tblite_cli_solution_state_reference, &
      29              :         tblite_cli_solvation_alpb, tblite_cli_solvation_cpcm, tblite_cli_solvation_gb, &
      30              :         tblite_cli_solvation_gbe, tblite_cli_solvation_gbsa, tblite_guess_ceh, tblite_guess_eeq, &
      31              :         tblite_guess_sad, tblite_mixer_damping_default, tblite_mixer_iterations_default, &
      32              :         tblite_mixer_max_weight_default, tblite_mixer_memory_inherit, &
      33              :         tblite_mixer_min_weight_default, tblite_mixer_omega0_default, &
      34              :         tblite_mixer_weight_factor_default, tblite_scc_mixer_auto, tblite_scc_mixer_cp2k, &
      35              :         tblite_scc_mixer_none, tblite_scc_mixer_tblite, tblite_solver_gvd, tblite_solver_gvr
      36              :    USE input_cp2k_mm,                   ONLY: create_GENPOT_section
      37              :    USE input_keyword_types,             ONLY: keyword_create,&
      38              :                                               keyword_release,&
      39              :                                               keyword_type
      40              :    USE input_section_types,             ONLY: section_add_keyword,&
      41              :                                               section_add_subsection,&
      42              :                                               section_create,&
      43              :                                               section_release,&
      44              :                                               section_type
      45              :    USE input_val_types,                 ONLY: char_t,&
      46              :                                               real_t
      47              :    USE kinds,                           ONLY: dp
      48              :    USE string_utilities,                ONLY: s2a
      49              : #include "./base/base_uses.f90"
      50              : 
      51              :    IMPLICIT NONE
      52              :    PRIVATE
      53              : 
      54              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'input_cp2k_tb'
      55              : 
      56              :    PUBLIC :: create_dftb_control_section, create_xtb_control_section
      57              : 
      58              : CONTAINS
      59              : 
      60              : ! **************************************************************************************************
      61              : !> \brief ...
      62              : !> \param section ...
      63              : ! **************************************************************************************************
      64        10502 :    SUBROUTINE create_dftb_control_section(section)
      65              :       TYPE(section_type), POINTER                        :: section
      66              : 
      67              :       TYPE(keyword_type), POINTER                        :: keyword
      68              :       TYPE(section_type), POINTER                        :: subsection
      69              : 
      70        10502 :       CPASSERT(.NOT. ASSOCIATED(section))
      71              :       CALL section_create(section, __LOCATION__, name="DFTB", &
      72              :                           description="Parameters needed to set up the DFTB methods", &
      73              :                           n_keywords=1, n_subsections=1, repeats=.FALSE., &
      74        52510 :                           citations=[Porezag1995, Seifert1996, Elstner1998, Zhechkov2005])
      75              : 
      76        10502 :       NULLIFY (subsection)
      77        10502 :       CALL create_dftb_parameter_section(subsection)
      78        10502 :       CALL section_add_subsection(section, subsection)
      79        10502 :       CALL section_release(subsection)
      80              : 
      81        10502 :       NULLIFY (subsection)
      82        10502 :       CALL create_tblite_mixer_section(subsection)
      83        10502 :       CALL section_add_subsection(section, subsection)
      84        10502 :       CALL section_release(subsection)
      85              : 
      86        10502 :       NULLIFY (keyword)
      87              :       CALL keyword_create(keyword, __LOCATION__, name="self_consistent", &
      88              :                           description="Use self-consistent method", &
      89              :                           citations=[Elstner1998], &
      90        21004 :                           usage="SELF_CONSISTENT", default_l_val=.TRUE.)
      91        10502 :       CALL section_add_keyword(section, keyword)
      92        10502 :       CALL keyword_release(keyword)
      93              : 
      94              :       CALL keyword_create(keyword, __LOCATION__, name="orthogonal_basis", &
      95              :                           description="Assume orthogonal basis set", &
      96        10502 :                           usage="ORTHOGONAL_BASIS", default_l_val=.FALSE.)
      97        10502 :       CALL section_add_keyword(section, keyword)
      98        10502 :       CALL keyword_release(keyword)
      99              : 
     100              :       CALL keyword_create(keyword, __LOCATION__, name="do_ewald", &
     101              :                           description="Deprecated debug override for the DFTB Ewald treatment. "// &
     102              :                           "By default the setting is inferred from SUBSYS/CELL/PERIODIC. "// &
     103              :                           "If set to TRUE, the DFT/POISSON section must use a periodic Poisson solver.", &
     104              :                           usage="DO_EWALD", default_l_val=.FALSE., lone_keyword_l_val=.TRUE., &
     105              :                           deprecation_notice="Use SUBSYS/CELL/PERIODIC to select periodicity. "// &
     106        10502 :                           "DO_EWALD is retained only as a debug override for the DFTB Ewald path.")
     107        10502 :       CALL section_add_keyword(section, keyword)
     108        10502 :       CALL keyword_release(keyword)
     109              : 
     110              :       CALL keyword_create(keyword, __LOCATION__, name="dispersion", &
     111              :                           description="Use dispersion correction", &
     112              :                           citations=[Zhechkov2005], lone_keyword_l_val=.TRUE., &
     113        21004 :                           usage="DISPERSION", default_l_val=.FALSE.)
     114        10502 :       CALL section_add_keyword(section, keyword)
     115        10502 :       CALL keyword_release(keyword)
     116              : 
     117              :       CALL keyword_create(keyword, __LOCATION__, name="DIAGONAL_DFTB3", &
     118              :                           description="Use a diagonal version of the 3rd order energy correction (DFTB3) ", &
     119              :                           lone_keyword_l_val=.TRUE., &
     120        10502 :                           usage="DIAGONAL_DFTB3", default_l_val=.FALSE.)
     121        10502 :       CALL section_add_keyword(section, keyword)
     122        10502 :       CALL keyword_release(keyword)
     123              : 
     124              :       CALL keyword_create(keyword, __LOCATION__, name="HB_SR_GAMMA", &
     125              :                           description="Uses a modified version for the GAMMA within the SCC-DFTB scheme, "// &
     126              :                           "specifically tuned for hydrogen bonds.", &
     127              :                           citations=[Hu2007], lone_keyword_l_val=.TRUE., &
     128        21004 :                           usage="HB_SR_GAMMA", default_l_val=.FALSE.)
     129        10502 :       CALL section_add_keyword(section, keyword)
     130        10502 :       CALL keyword_release(keyword)
     131              : 
     132              :       CALL keyword_create(keyword, __LOCATION__, name="eps_disp", &
     133              :                           description="Define accuracy of dispersion interaction", &
     134        10502 :                           usage="EPS_DISP", default_r_val=0.0001_dp)
     135        10502 :       CALL section_add_keyword(section, keyword)
     136        10502 :       CALL keyword_release(keyword)
     137              : 
     138              :       CALL add_tb_scc_mixer_keywords(section, "CP2K-internal DFTB", &
     139        10502 :                                      "AUTO keeps the existing CP2K density/SCF mixing path for DFTB.")
     140              : 
     141        10502 :    END SUBROUTINE create_dftb_control_section
     142              : 
     143              : ! **************************************************************************************************
     144              : !> \brief ...
     145              : !> \param section ...
     146              : ! **************************************************************************************************
     147        10502 :    SUBROUTINE create_xtb_control_section(section)
     148              :       TYPE(section_type), POINTER                        :: section
     149              : 
     150              :       TYPE(keyword_type), POINTER                        :: keyword
     151              :       TYPE(section_type), POINTER                        :: subsection
     152              : 
     153        10502 :       CPASSERT(.NOT. ASSOCIATED(section))
     154              :       CALL section_create(section, __LOCATION__, name="xTB", &
     155              :                           description="Parameters needed to set up the xTB methods", &
     156              :                           n_keywords=1, n_subsections=1, repeats=.FALSE., &
     157        21004 :                           citations=[GRIMME2017])
     158              : 
     159        10502 :       NULLIFY (subsection)
     160        10502 :       CALL create_xtb_parameter_section(subsection)
     161        10502 :       CALL section_add_subsection(section, subsection)
     162        10502 :       CALL section_release(subsection)
     163              : 
     164        10502 :       CALL create_xtb_nonbonded_section(subsection)
     165        10502 :       CALL section_add_subsection(section, subsection)
     166        10502 :       CALL section_release(subsection)
     167              : 
     168        10502 :       CALL create_eeq_control_section(subsection)
     169        10502 :       CALL section_add_subsection(section, subsection)
     170        10502 :       CALL section_release(subsection)
     171              : 
     172        10502 :       CALL create_tblite_mixer_section(subsection)
     173        10502 :       CALL section_add_subsection(section, subsection)
     174        10502 :       CALL section_release(subsection)
     175              : 
     176        10502 :       CALL create_xtb_tblite_section(subsection)
     177        10502 :       CALL section_add_subsection(section, subsection)
     178        10502 :       CALL section_release(subsection)
     179              : 
     180        10502 :       NULLIFY (keyword)
     181              :       CALL keyword_create(keyword, __LOCATION__, name="GFN_TYPE", &
     182              :                           description="Selects the xTB backend. GFN_TYPE 1 uses the CP2K-internal GFN1-xTB "// &
     183              :                           "implementation. GFN_TYPE 0 uses the CP2K-internal GFN0-xTB implementation, which "// &
     184              :                           "has no SCC variables to mix, so XTB/SCC_MIXER AUTO is treated as NONE. "// &
     185              :                           "GFN_TYPE TBLITE uses the tblite backend and requires an XTB/TBLITE "// &
     186              :                           "section, where the actual tblite method is selected.", &
     187              :                           usage="GFN_TYPE (0|1|TBLITE)", &
     188              :                           enum_c_vals=s2a("0", "1", "TBLITE"), &
     189              :                           enum_i_vals=[0, gfn1xtb, gfn_tblite], &
     190              :                           enum_desc=s2a("Use the CP2K-internal GFN0-xTB implementation.", &
     191              :                                         "Use the CP2K-internal GFN1-xTB implementation.", &
     192              :                                         "Use the CP2K/tblite backend; requires XTB/TBLITE."), &
     193        10502 :                           default_i_val=gfn1xtb)
     194        10502 :       CALL section_add_keyword(section, keyword)
     195        10502 :       CALL keyword_release(keyword)
     196              : 
     197              :       CALL add_tb_scc_mixer_keywords(section, "xTB", &
     198              :                                      "AUTO is treated as NONE for CP2K-internal GFN0-xTB, keeps the CP2K "// &
     199              :                                      "charge mixer for CP2K-internal GFN1-xTB, and uses "// &
     200        10502 :                                      "tblite's native SCC mixer for XTB/GFN_TYPE TBLITE.")
     201              : 
     202              :       CALL keyword_create(keyword, __LOCATION__, name="DO_EWALD", &
     203              :                           description="Deprecated debug override for the xTB Ewald treatment. "// &
     204              :                           "By default the setting is inferred from SUBSYS/CELL/PERIODIC. "// &
     205              :                           "If set to TRUE for CP2K-internal xTB, the DFT/POISSON section must use a periodic "// &
     206              :                           "Poisson solver. For CP2K/tblite, the periodic long-range treatment is performed "// &
     207              :                           "inside tblite.", &
     208              :                           usage="DO_EWALD", default_l_val=.FALSE., lone_keyword_l_val=.TRUE., &
     209              :                           deprecation_notice="Use SUBSYS/CELL/PERIODIC to select periodicity. "// &
     210        10502 :                           "DO_EWALD is retained only as a debug override for the CP2K-internal xTB Ewald path.")
     211        10502 :       CALL section_add_keyword(section, keyword)
     212        10502 :       CALL keyword_release(keyword)
     213              : 
     214              :       CALL keyword_create(keyword, __LOCATION__, name="STO_NG", &
     215              :                           description="Provides the order of the Slater orbital expansion in GTOs.", &
     216        10502 :                           usage="STO_NG 3", default_i_val=6)
     217        10502 :       CALL section_add_keyword(section, keyword)
     218        10502 :       CALL keyword_release(keyword)
     219              : 
     220              :       CALL keyword_create(keyword, __LOCATION__, name="HYDROGEN_STO_NG", &
     221              :                           description="Number of GTOs for Hydrogen basis expansion.", &
     222        10502 :                           usage="HYDROGEN_STO_NG 3", default_i_val=4)
     223        10502 :       CALL section_add_keyword(section, keyword)
     224        10502 :       CALL keyword_release(keyword)
     225              : 
     226              :       CALL keyword_create(keyword, __LOCATION__, name="USE_HALOGEN_CORRECTION", &
     227              :                           description="Use XB interaction term", &
     228        10502 :                           usage="USE_HALOGEN_CORRECTION T", default_l_val=.TRUE., lone_keyword_l_val=.TRUE.)
     229        10502 :       CALL section_add_keyword(section, keyword)
     230        10502 :       CALL keyword_release(keyword)
     231              : 
     232              :       CALL keyword_create(keyword, __LOCATION__, name="DO_NONBONDED", &
     233              :                           description="Controls the computation of real-space "// &
     234              :                           "(short-range) nonbonded interactions as correction to xTB.", &
     235        10502 :                           usage="DO_NONBONDED T", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     236        10502 :       CALL section_add_keyword(section, keyword)
     237        10502 :       CALL keyword_release(keyword)
     238              : 
     239              :       CALL keyword_create(keyword, __LOCATION__, name="VDW_POTENTIAL", &
     240              :                           description="vdW potential to be used: NONE, DFTD3, DFTD4. "// &
     241              :                           "Defaults: DFTD3(gfn1), DFTD4(gfn0, gfn2).", &
     242        10502 :                           usage="VDW_POTENTIAL type", default_c_val="")
     243        10502 :       CALL section_add_keyword(section, keyword)
     244        10502 :       CALL keyword_release(keyword)
     245              : 
     246              :       CALL keyword_create(keyword, __LOCATION__, name="SPIN_POLARISATION", &
     247              :                           description="Use the spin polarisation Hamiltonian for gfn1/2", &
     248        10502 :                           usage="SPIN_POLARISATION T", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     249        10502 :       CALL section_add_keyword(section, keyword)
     250        10502 :       CALL keyword_release(keyword)
     251              : 
     252              :       CALL keyword_create(keyword, __LOCATION__, name="COULOMB_INTERACTION", &
     253              :                           description="Use Coulomb interaction terms (electrostatics + TB3); for debug only", &
     254        10502 :                           usage="COULOMB_INTERACTION T", default_l_val=.TRUE., lone_keyword_l_val=.TRUE.)
     255        10502 :       CALL section_add_keyword(section, keyword)
     256        10502 :       CALL keyword_release(keyword)
     257              : 
     258              :       CALL keyword_create(keyword, __LOCATION__, name="COULOMB_LR", &
     259              :                           description="Use Coulomb LR (1/r) interaction terms; for debug only", &
     260        10502 :                           usage="COULOMB_LR T", default_l_val=.TRUE., lone_keyword_l_val=.TRUE.)
     261        10502 :       CALL section_add_keyword(section, keyword)
     262        10502 :       CALL keyword_release(keyword)
     263              : 
     264              :       CALL keyword_create(keyword, __LOCATION__, name="TB3_INTERACTION", &
     265              :                           description="Use TB3 interaction terms; for debug only", &
     266        10502 :                           usage="TB3_INTERACTION T", default_l_val=.TRUE., lone_keyword_l_val=.TRUE.)
     267        10502 :       CALL section_add_keyword(section, keyword)
     268        10502 :       CALL keyword_release(keyword)
     269              : 
     270              :       CALL keyword_create(keyword, __LOCATION__, name="CHECK_ATOMIC_CHARGES", &
     271              :                           description="Stop calculation if atomic charges are outside chemical range.", &
     272        10502 :                           usage="CHECK_ATOMIC_CHARGES T", default_l_val=.TRUE., lone_keyword_l_val=.TRUE.)
     273        10502 :       CALL section_add_keyword(section, keyword)
     274        10502 :       CALL keyword_release(keyword)
     275              : 
     276              :       CALL keyword_create(keyword, __LOCATION__, name="VARIATIONAL_DIPOLE", &
     277              :                           description="gfn0-xTB use dipole definition from energy derivative.", &
     278        10502 :                           usage="VARIATIONAL_DIPOLE T", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     279        10502 :       CALL section_add_keyword(section, keyword)
     280        10502 :       CALL keyword_release(keyword)
     281              : 
     282              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_PAIRPOTENTIAL", &
     283              :                           description="Accuracy for the repulsive pair potential.", &
     284        10502 :                           usage="EPS_PAIRPOTENTIAL 1.0E-8", default_r_val=1.0e-10_dp)
     285        10502 :       CALL section_add_keyword(section, keyword)
     286        10502 :       CALL keyword_release(keyword)
     287              : 
     288              :       CALL keyword_create(keyword, __LOCATION__, name="EN_SHIFT_TYPE", &
     289              :                           description="Shift function for electronegativity in EEQ method. "// &
     290              :                           "[Select/Molecule/Crystal] Default Select from periodicity.", &
     291              :                           usage="EN_SHIFT_TYPE [Select/Molecule/Crystal]", &
     292        10502 :                           n_var=1, type_of_var=char_t, default_c_val="Molecule")
     293        10502 :       CALL section_add_keyword(section, keyword)
     294        10502 :       CALL keyword_release(keyword)
     295              : 
     296        10502 :    END SUBROUTINE create_xtb_control_section
     297              : 
     298              : ! **************************************************************************************************
     299              : !> \brief ...
     300              : !> \param section ...
     301              : ! **************************************************************************************************
     302        10502 :    SUBROUTINE create_dftb_parameter_section(section)
     303              : 
     304              :       TYPE(section_type), POINTER                        :: section
     305              : 
     306              :       TYPE(keyword_type), POINTER                        :: keyword
     307              : 
     308        10502 :       CPASSERT(.NOT. ASSOCIATED(section))
     309              : 
     310              :       CALL section_create(section, __LOCATION__, name="PARAMETER", &
     311              :                           description="Information on where to find DFTB parameters", &
     312        10502 :                           n_keywords=1, n_subsections=0, repeats=.FALSE.)
     313              : 
     314        10502 :       NULLIFY (keyword)
     315              :       CALL keyword_create(keyword, __LOCATION__, name="SK_FILE", &
     316              :                           description="Define parameter file for atom pair", &
     317              :                           usage="SK_FILE a1 a2 filename", &
     318        10502 :                           n_var=3, type_of_var=char_t, repeats=.TRUE.)
     319        10502 :       CALL section_add_keyword(section, keyword)
     320        10502 :       CALL keyword_release(keyword)
     321              : 
     322              :       CALL keyword_create(keyword, __LOCATION__, name="PARAM_FILE_PATH", &
     323              :                           description="Specify the directory with the DFTB parameter files. "// &
     324              :                           "Used in combination with the filenames specified in the file "// &
     325              :                           "given in PARAM_FILE_NAME.", usage="PARAM_FILE_PATH pathname", &
     326        10502 :                           n_var=1, type_of_var=char_t, default_c_val="./")
     327        10502 :       CALL section_add_keyword(section, keyword)
     328        10502 :       CALL keyword_release(keyword)
     329              : 
     330              :       CALL keyword_create(keyword, __LOCATION__, name="PARAM_FILE_NAME", &
     331              :                           description="Specify file that contains the names of "// &
     332              :                           "Slater-Koster tables: A plain text file, each line has the "// &
     333              :                           'format "ATOM1 ATOM2 filename.spl".', &
     334              :                           usage="PARAM_FILE_NAME filename", &
     335        10502 :                           n_var=1, type_of_var=char_t, default_c_val="")
     336        10502 :       CALL section_add_keyword(section, keyword)
     337        10502 :       CALL keyword_release(keyword)
     338              : 
     339              :       CALL keyword_create(keyword, __LOCATION__, name="DISPERSION_TYPE", &
     340              :                           description="Use dispersion correction of the specified type."// &
     341              :                           " Dispersion correction has to be switched on in the DFTB section.", &
     342              :                           usage="DISPERSION_TYPE (UFF|D3|D3(BJ)|D2)", &
     343              :                           enum_c_vals=s2a("UFF", "D3", "D3(BJ)", "D2"), &
     344              :                           enum_i_vals=[dispersion_uff, dispersion_d3, dispersion_d3bj, dispersion_d2], &
     345              :                           enum_desc=s2a("Uses the UFF force field for a pair potential dispersion correction.", &
     346              :                                         "Uses the Grimme D3 method (simplified) for a pair potential dispersion correction.", &
     347              :                                         "Uses the Grimme D3 method (simplified) with Becke-Johnson attenuation.", &
     348              :                                         "Uses the Grimme D2 method for pair potential dispersion correction."), &
     349        10502 :                           default_i_val=dispersion_uff)
     350        10502 :       CALL section_add_keyword(section, keyword)
     351        10502 :       CALL keyword_release(keyword)
     352              : 
     353              :       CALL keyword_create(keyword, __LOCATION__, name="UFF_FORCE_FIELD", &
     354              :                           description="Name of file with UFF parameters that will be used "// &
     355              :                           "for the dispersion correction. Needs to be specified when "// &
     356              :                           "DISPERSION==.TRUE., otherwise cp2k crashes with a Segmentation "// &
     357              :                           "Fault.", usage="UFF_FORCE_FIELD filename", &
     358        10502 :                           n_var=1, type_of_var=char_t, default_c_val="")
     359        10502 :       CALL section_add_keyword(section, keyword)
     360        10502 :       CALL keyword_release(keyword)
     361              : 
     362              :       CALL keyword_create(keyword, __LOCATION__, name="DISPERSION_PARAMETER_FILE", &
     363              :                           description="Specify file that contains the atomic dispersion "// &
     364              :                           "parameters for the D3 method", &
     365              :                           usage="DISPERSION_PARAMETER_FILE filename", &
     366        10502 :                           n_var=1, type_of_var=char_t, default_c_val="")
     367        10502 :       CALL section_add_keyword(section, keyword)
     368        10502 :       CALL keyword_release(keyword)
     369              : 
     370              :       CALL keyword_create(keyword, __LOCATION__, name="DISPERSION_RADIUS", &
     371              :                           description="Define radius of dispersion interaction", &
     372        10502 :                           usage="DISPERSION_RADIUS", default_r_val=15._dp)
     373        10502 :       CALL section_add_keyword(section, keyword)
     374        10502 :       CALL keyword_release(keyword)
     375              : 
     376              :       CALL keyword_create(keyword, __LOCATION__, name="COORDINATION_CUTOFF", &
     377              :                           description="Define cutoff for coordination number calculation", &
     378        10502 :                           usage="COORDINATION_CUTOFF", default_r_val=1.e-6_dp)
     379        10502 :       CALL section_add_keyword(section, keyword)
     380        10502 :       CALL keyword_release(keyword)
     381              : 
     382              :       CALL keyword_create(keyword, __LOCATION__, name="D3_SCALING", &
     383              :                           description="Scaling parameters (s6,sr6,s8) for the D3 dispersion method,", &
     384        10502 :                           usage="D3_SCALING 1.0 1.0 1.0", n_var=3, default_r_vals=[0.0_dp, 0.0_dp, 0.0_dp])
     385        10502 :       CALL section_add_keyword(section, keyword)
     386        10502 :       CALL keyword_release(keyword)
     387              : 
     388              :       CALL keyword_create(keyword, __LOCATION__, name="D3BJ_SCALING", &
     389              :                           description="Scaling parameters (s6,a1,s8,a2) for the D3(BJ) dispersion method,", &
     390              :                           usage="D3BJ_SCALING 1.0 1.0 1.0 1.0", n_var=4, &
     391        10502 :                           default_r_vals=[0.0_dp, 0.0_dp, 0.0_dp, 0.0_dp])
     392        10502 :       CALL section_add_keyword(section, keyword)
     393        10502 :       CALL keyword_release(keyword)
     394              : 
     395              :       CALL keyword_create(keyword, __LOCATION__, name="D2_SCALING", &
     396              :                           description="Scaling parameter for the D2 dispersion method,", &
     397        10502 :                           usage="D2_SCALING 1.0", default_r_val=1.0_dp)
     398        10502 :       CALL section_add_keyword(section, keyword)
     399        10502 :       CALL keyword_release(keyword)
     400              : 
     401              :       CALL keyword_create(keyword, __LOCATION__, name="D2_EXP_PRE", &
     402              :                           description="Exp prefactor for damping for the D2 dispersion method,", &
     403        10502 :                           usage="D2_EXP_PRE 2.0", default_r_val=2.0_dp)
     404        10502 :       CALL section_add_keyword(section, keyword)
     405        10502 :       CALL keyword_release(keyword)
     406              : 
     407              :       CALL keyword_create(keyword, __LOCATION__, name="HB_SR_PARAM", &
     408              :                           description="Uses a modified version for the GAMMA within the SCC-DFTB scheme, "// &
     409              :                           "specifically tuned for hydrogen bonds. Specify the exponent used in the exponential.", &
     410        10502 :                           usage="HB_SR_PARAM {real}", default_r_val=4.0_dp)
     411        10502 :       CALL section_add_keyword(section, keyword)
     412        10502 :       CALL keyword_release(keyword)
     413              : 
     414        10502 :    END SUBROUTINE create_dftb_parameter_section
     415              : 
     416              : ! **************************************************************************************************
     417              : !> \brief ...
     418              : !> \param section ...
     419              : ! **************************************************************************************************
     420        10502 :    SUBROUTINE create_xtb_parameter_section(section)
     421              : 
     422              :       TYPE(section_type), POINTER                        :: section
     423              : 
     424              :       TYPE(keyword_type), POINTER                        :: keyword
     425              : 
     426        10502 :       CPASSERT(.NOT. ASSOCIATED(section))
     427              : 
     428              :       CALL section_create(section, __LOCATION__, name="PARAMETER", &
     429              :                           description="Information on and where to find xTB parameters", &
     430        10502 :                           n_keywords=1, n_subsections=0, repeats=.FALSE.)
     431              : 
     432        10502 :       NULLIFY (keyword)
     433              :       CALL keyword_create(keyword, __LOCATION__, name="PARAM_FILE_PATH", &
     434              :                           description="Specify the directory with the xTB parameter file. ", &
     435              :                           usage="PARAM_FILE_PATH pathname", &
     436        10502 :                           n_var=1, type_of_var=char_t, default_c_val="")
     437        10502 :       CALL section_add_keyword(section, keyword)
     438        10502 :       CALL keyword_release(keyword)
     439              : 
     440              :       CALL keyword_create(keyword, __LOCATION__, name="PARAM_FILE_NAME", &
     441              :                           description="Specify file that contains all xTB default parameters. ", &
     442              :                           usage="PARAM_FILE_NAME filename", &
     443        10502 :                           n_var=1, type_of_var=char_t, default_c_val="xTB_parameters")
     444        10502 :       CALL section_add_keyword(section, keyword)
     445        10502 :       CALL keyword_release(keyword)
     446              : 
     447              :       CALL keyword_create(keyword, __LOCATION__, name="SPINPOL_PARAM_FILE_NAME", &
     448              :                           description="Specify file that contains parameters for "// &
     449              :                           "xTB spin polarisation Hamiltonian", &
     450              :                           usage="SPINPOL_PARAM_FILE_NAME filename", &
     451        10502 :                           n_var=1, type_of_var=char_t, default_c_val="xTB_sp_param_060")
     452        10502 :       CALL section_add_keyword(section, keyword)
     453        10502 :       CALL keyword_release(keyword)
     454              : 
     455              :       CALL keyword_create(keyword, __LOCATION__, name="DISPERSION_PARAMETER_FILE", &
     456              :                           description="Specify file that contains the atomic dispersion "// &
     457              :                           "parameters for the D3 method", &
     458              :                           usage="DISPERSION_PARAMETER_FILE filename", &
     459        10502 :                           n_var=1, type_of_var=char_t, default_c_val="dftd3.dat")
     460        10502 :       CALL section_add_keyword(section, keyword)
     461        10502 :       CALL keyword_release(keyword)
     462              : 
     463              :       CALL keyword_create(keyword, __LOCATION__, name="DISPERSION_RADIUS", &
     464              :                           description="Define radius of dispersion interaction", &
     465        10502 :                           usage="DISPERSION_RADIUS", default_r_val=15._dp)
     466        10502 :       CALL section_add_keyword(section, keyword)
     467        10502 :       CALL keyword_release(keyword)
     468              : 
     469              :       CALL keyword_create(keyword, __LOCATION__, name="COORDINATION_CUTOFF", &
     470              :                           description="Define cutoff for coordination number calculation", &
     471        10502 :                           usage="COORDINATION_CUTOFF", default_r_val=1.e-6_dp)
     472        10502 :       CALL section_add_keyword(section, keyword)
     473        10502 :       CALL keyword_release(keyword)
     474              : 
     475              :       CALL keyword_create(keyword, __LOCATION__, name="D3BJ_SCALING", &
     476              :                           description="Scaling parameters (s6,s8) for the D3 dispersion method.", &
     477        10502 :                           usage="D3BJ_SCALING 1.0 2.4", n_var=2, default_r_vals=[1.0_dp, 2.4_dp])
     478        10502 :       CALL section_add_keyword(section, keyword)
     479        10502 :       CALL keyword_release(keyword)
     480              : 
     481              :       CALL keyword_create(keyword, __LOCATION__, name="D3BJ_PARAM", &
     482              :                           description="Becke-Johnson parameters (a1, a2 for the D3 dispersion method.", &
     483        10502 :                           usage="D3BJ_PARAM 0.63 5.0", n_var=2, default_r_vals=[0.63_dp, 5.0_dp])
     484        10502 :       CALL section_add_keyword(section, keyword)
     485        10502 :       CALL keyword_release(keyword)
     486              : 
     487              :       CALL keyword_create(keyword, __LOCATION__, name="HUCKEL_CONSTANTS", &
     488              :                           description="Huckel parameters (s, p, d, sp, 2sH).", &
     489              :                           usage="HUCKEL_CONSTANTS 1.85 2.25 2.00 2.08 2.85", n_var=5, &
     490        10502 :                           default_r_vals=[1.85_dp, 2.25_dp, 2.00_dp, 2.08_dp, 2.85_dp])
     491        10502 :       CALL section_add_keyword(section, keyword)
     492        10502 :       CALL keyword_release(keyword)
     493              : 
     494              :       CALL keyword_create(keyword, __LOCATION__, name="COULOMB_CONSTANTS", &
     495              :                           description="Scaling parameters for Coulomb interactions (electrons, nuclei).", &
     496              :                           usage="COULOMB_CONSTANTS 2.00 1.50", n_var=2, &
     497        10502 :                           default_r_vals=[2.00_dp, 1.50_dp])
     498        10502 :       CALL section_add_keyword(section, keyword)
     499        10502 :       CALL keyword_release(keyword)
     500              : 
     501              :       CALL keyword_create(keyword, __LOCATION__, name="CN_CONSTANTS", &
     502              :                           description="Scaling parameters for Coordination number correction term.", &
     503              :                           usage="CN_CONSTANTS 0.006 -0.003 -0.005", n_var=3, &
     504        10502 :                           default_r_vals=[0.006_dp, -0.003_dp, -0.005_dp])
     505        10502 :       CALL section_add_keyword(section, keyword)
     506        10502 :       CALL keyword_release(keyword)
     507              : 
     508              :       CALL keyword_create(keyword, __LOCATION__, name="EN_CONSTANTS", &
     509              :                           description="Scaling parameters for electronegativity correction term.", &
     510              :                           usage="EN_CONSTANTS -0.007 0.000 0.000", n_var=3, &
     511        10502 :                           default_r_vals=[-0.007_dp, 0.000_dp, 0.000_dp])
     512        10502 :       CALL section_add_keyword(section, keyword)
     513        10502 :       CALL keyword_release(keyword)
     514              : 
     515              :       CALL keyword_create(keyword, __LOCATION__, name="BEN_CONSTANT", &
     516              :                           description="Scaling parameter for electronegativity correction term.", &
     517              :                           usage="BEN_CONSTANT 4.0", n_var=1, &
     518        10502 :                           default_r_val=4.0_dp)
     519        10502 :       CALL section_add_keyword(section, keyword)
     520        10502 :       CALL keyword_release(keyword)
     521              : 
     522              :       CALL keyword_create(keyword, __LOCATION__, name="ENSCALE", &
     523              :                           description="Scaling parameter repulsive energy (dEN in exponential).", &
     524              :                           usage="ENSCALE 0.01", n_var=1, &
     525        10502 :                           default_r_val=0.0_dp)
     526        10502 :       CALL section_add_keyword(section, keyword)
     527        10502 :       CALL keyword_release(keyword)
     528              : 
     529              :       CALL keyword_create(keyword, __LOCATION__, name="HALOGEN_BINDING", &
     530              :                           description="Scaling parameters for electronegativity correction term.", &
     531        10502 :                           usage="HALOGEN_BINDING 1.30 0.44", n_var=2, default_r_vals=[1.30_dp, 0.44_dp])
     532        10502 :       CALL section_add_keyword(section, keyword)
     533        10502 :       CALL keyword_release(keyword)
     534              : 
     535              :       CALL keyword_create(keyword, __LOCATION__, name="KAB_PARAM", &
     536              :                           description="Specifies the specific Kab value for types A and B.", &
     537              :                           usage="KAB_PARAM kind1 kind2 value ", repeats=.TRUE., &
     538        10502 :                           n_var=-1, type_of_var=char_t)
     539        10502 :       CALL section_add_keyword(section, keyword)
     540        10502 :       CALL keyword_release(keyword)
     541              : 
     542              :       CALL keyword_create(keyword, __LOCATION__, name="SPIN_POL_PARAM", &
     543              :                           description="Specifies the spin polarisation parameters for kind A.", &
     544              :                           usage="SPIN_POL_PARAM atomtype Wss Wsp Wpp Wsd Wpd Wdd", repeats=.TRUE., &
     545        10502 :                           n_var=-1, type_of_var=char_t)
     546        10502 :       CALL section_add_keyword(section, keyword)
     547        10502 :       CALL keyword_release(keyword)
     548              : 
     549              :       CALL keyword_create(keyword, __LOCATION__, name="XB_RADIUS", &
     550              :                           description="Specifies the radius [Bohr] of the XB pair interaction in xTB.", &
     551              :                           usage="XB_RADIUS 20.0 ", repeats=.FALSE., &
     552        10502 :                           n_var=1, default_r_val=20.0_dp)
     553        10502 :       CALL section_add_keyword(section, keyword)
     554        10502 :       CALL keyword_release(keyword)
     555              : 
     556              :       CALL keyword_create(keyword, __LOCATION__, name="COULOMB_SR_CUT", &
     557              :                           description="Maximum range of short range part of Coulomb interaction.", &
     558              :                           usage="COULOMB_SR_CUT 20.0 ", repeats=.FALSE., &
     559        10502 :                           n_var=1, default_r_val=20.0_dp)
     560        10502 :       CALL section_add_keyword(section, keyword)
     561        10502 :       CALL keyword_release(keyword)
     562              : 
     563              :       CALL keyword_create(keyword, __LOCATION__, name="COULOMB_SR_EPS", &
     564              :                           description="Cutoff for short range part of Coulomb interaction.", &
     565              :                           usage="COULOMB_SR_EPS 1.E-3 ", repeats=.FALSE., &
     566        10502 :                           n_var=1, default_r_val=1.0E-03_dp)
     567        10502 :       CALL section_add_keyword(section, keyword)
     568        10502 :       CALL keyword_release(keyword)
     569              : 
     570              :       CALL keyword_create(keyword, __LOCATION__, name="SRB_PARAMETER", &
     571              :                           description="SRB parameters (ksrb, esrb, gscal, c1, c2, shift).", &
     572              :                           usage="SRB_PARAMETER -0.0129 3.48 0.51 -1.71 2.11 0.0537", n_var=6, &
     573              :                           default_r_vals=[-0.0129_dp, 3.4847_dp, 0.5097_dp, &
     574        10502 :                                           -1.70549806_dp, 2.10878369_dp, 0.0537_dp])
     575        10502 :       CALL section_add_keyword(section, keyword)
     576        10502 :       CALL keyword_release(keyword)
     577              : 
     578        10502 :    END SUBROUTINE create_xtb_parameter_section
     579              : ! **************************************************************************************************
     580              : !> \brief ...
     581              : !> \param section ...
     582              : ! **************************************************************************************************
     583        10502 :    SUBROUTINE create_xtb_nonbonded_section(section)
     584              :       TYPE(section_type), POINTER                        :: section
     585              : 
     586              :       TYPE(keyword_type), POINTER                        :: keyword
     587              :       TYPE(section_type), POINTER                        :: subsection
     588              : 
     589        10502 :       CPASSERT(.NOT. ASSOCIATED(section))
     590              :       CALL section_create(section, __LOCATION__, name="NONBONDED", &
     591              :                           description="This section specifies the input parameters for NON-BONDED interactions.", &
     592        10502 :                           n_keywords=1, n_subsections=0, repeats=.FALSE.)
     593        10502 :       NULLIFY (subsection)
     594              : 
     595        10502 :       CALL create_GENPOT_section(subsection)
     596        10502 :       CALL section_add_subsection(section, subsection)
     597        10502 :       CALL section_release(subsection)
     598              : 
     599        10502 :       NULLIFY (keyword)
     600              :       CALL keyword_create(keyword, __LOCATION__, name="DX", &
     601              :                           description="Parameter used for computing the derivative with the Ridders' method.", &
     602        10502 :                           usage="DX <REAL>", default_r_val=0.1_dp, unit_str="bohr")
     603        10502 :       CALL section_add_keyword(section, keyword)
     604        10502 :       CALL keyword_release(keyword)
     605              : 
     606              :       CALL keyword_create(keyword, __LOCATION__, name="ERROR_LIMIT", &
     607              :                           description="Checks that the error in computing the derivative is not larger than "// &
     608              :                           "the value set; in case error is larger a warning message is printed.", &
     609        10502 :                           usage="ERROR_LIMIT <REAL>", default_r_val=1.0E-12_dp)
     610        10502 :       CALL section_add_keyword(section, keyword)
     611        10502 :       CALL keyword_release(keyword)
     612              : 
     613        10502 :    END SUBROUTINE create_xtb_nonbonded_section
     614              : ! **************************************************************************************************
     615              : !> \brief Creates the &TBLITE section
     616              : !> \param section the section to create
     617              : !> \author JVP
     618              : ! **************************************************************************************************
     619        10502 :    SUBROUTINE create_xtb_tblite_section(section)
     620              :       TYPE(section_type), POINTER                        :: section
     621              : 
     622              :       TYPE(keyword_type), POINTER                        :: keyword
     623              :       TYPE(section_type), POINTER                        :: subsection
     624              : 
     625        10502 :       CPASSERT(.NOT. ASSOCIATED(section))
     626              :       CALL section_create(section, __LOCATION__, name="TBLITE", &
     627              :                           description="Section used to specify options for an xTB computation using tblite. "// &
     628              :                           "This section is required when XTB/GFN_TYPE is set to TBLITE. "// &
     629              :                           "Periodicity follows SUBSYS/CELL/PERIODIC; the deprecated XTB/DO_EWALD keyword "// &
     630              :                           "is read consistently with CP2K-internal xTB for diagnostics/debugging. "// &
     631              :                           "Initial densities and restarts are controlled by the regular CP2K SCF settings, "// &
     632              :                           "for example DFT/SCF/SCF_GUESS, not by a separate tblite guess in this section. "// &
     633              :                           "Spin-polarized CP2K/tblite calculations are selected with the regular DFT/UKS keyword "// &
     634              :                           "or its LSD/SPIN_POLARIZED aliases; DFT/MULTIPLICITY sets the number of unpaired "// &
     635              :                           "electrons. UKS uses tblite's spin-polarized Hamiltonian; AUTO selects the native tblite "// &
     636              :                           "SCC mixer for XTB/GFN_TYPE TBLITE, while SCC_MIXER CP2K mixes both total-charge and "// &
     637              :                           "magnetization SCC variables through CP2K's TB charge-mixing infrastructure. Native "// &
     638              :                           "tblite SCC convergence follows ACCURACY; SCC_MIXER CP2K follows the regular CP2K "// &
     639              :                           "SCF convergence settings such as DFT/SCF/EPS_SCF. With QS/LS_SCF, CP2K disables the "// &
     640              :                           "separate SCC-variable mixer and lets LS_SCF optimize the density matrix directly. "// &
     641              :                           "The same direct SCC-variable update is available for Gamma-point OT calculations, "// &
     642              :                           "where smearing and ADDED_MOS are not supported.", &
     643        21004 :                           n_keywords=1, n_subsections=1, repeats=.FALSE., citations=[Katbashev2025])
     644              : 
     645        10502 :       NULLIFY (keyword)
     646              :       CALL keyword_create(keyword, __LOCATION__, name="_SECTION_PARAMETERS_", &
     647              :                           description="Marks the tblite options section as present. The actual switch to the tblite "// &
     648              :                           "backend is XTB/GFN_TYPE TBLITE; this section then collects the numerical model, SCC "// &
     649              :                           "mixing, and optional native-reference settings used by that backend.", &
     650        10502 :                           lone_keyword_l_val=.TRUE., default_l_val=.FALSE.)
     651        10502 :       CALL section_add_keyword(section, keyword)
     652        10502 :       CALL keyword_release(keyword)
     653              : 
     654        10502 :       NULLIFY (keyword)
     655              :       CALL keyword_create(keyword, __LOCATION__, name="METHOD", &
     656              :                           description="Selects the xTB Hamiltonian model used by tblite. Without PARAM this chooses "// &
     657              :                           "one of tblite's built-in parametrizations, including the basis, reference occupations, "// &
     658              :                           "repulsion, dispersion, electrostatic, and coordination-number dependent terms. When PARAM "// &
     659              :                           "is given, METHOD remains the declared model family that the custom parametrization is "// &
     660              :                           "expected to implement and that CP2K uses for method-dependent setup and diagnostics.", &
     661              :                           usage="METHOD (GFN1|GFN2|IPEA1)", &
     662              :                           enum_c_vals=s2a("GFN1", "GFN2", "IPEA1"), &
     663              :                           enum_i_vals=[gfn1xtb, gfn2xtb, ipea1xtb], &
     664              :                           enum_desc=s2a("Uses the GFN1-XTB method by Grimme.", &
     665              :                                         "Uses the GFN2-XTB method by Grimme.", &
     666              :                                         "Uses the IPEA1 method by Grimme."), &
     667        10502 :                           default_i_val=gfn2xtb)
     668        10502 :       CALL section_add_keyword(section, keyword)
     669        10502 :       CALL keyword_release(keyword)
     670              : 
     671              :       CALL keyword_create(keyword, __LOCATION__, name="PARAM", &
     672              :                           description="Custom tblite parametrization file. The file is read by tblite and used to "// &
     673              :                           "construct the xTB calculator instead of the built-in parameter table for METHOD. It may "// &
     674              :                           "therefore change model constants such as Hamiltonian, repulsion, dispersion, electrostatic, "// &
     675              :                           "and coordination-number response parameters. It does not change the CP2K charge, spin, "// &
     676              :                           "cell, k-point, or SCF setup. The parametrization must be compatible with the selected "// &
     677              :                           "METHOD; CP2K does not reinterpret or validate the physical content of the file.", &
     678        10502 :                           usage="PARAM filename", n_var=1, type_of_var=char_t, default_c_val="")
     679        10502 :       CALL section_add_keyword(section, keyword)
     680        10502 :       CALL keyword_release(keyword)
     681              : 
     682        10502 :       NULLIFY (keyword)
     683              :       CALL keyword_create(keyword, __LOCATION__, name="ACCURACY", &
     684              :                           description="Numerical accuracy factor for the CP2K/tblite backend. This scales tblite's "// &
     685              :                           "internal accuracy-dependent thresholds. With the native tblite SCC mixer, this is the "// &
     686              :                           "user-visible convergence control and corresponds to native tblite's --acc setting. With "// &
     687              :                           "SCC_MIXER CP2K, SCF convergence instead follows DFT/SCF/EPS_SCF; ACCURACY still controls "// &
     688              :                           "the tblite numerical setup, such as the distance cutoff used to build the xTB basis and "// &
     689              :                           "neighbor data. "// &
     690              :                           "The default matches native tblite. Smaller values make the calculation tighter and usually "// &
     691              :                           "more expensive; larger values loosen the numerical setup and can affect energies, forces, "// &
     692              :                           "and stress. Native REFERENCE_CLI diagnostics inherit this value so the production and "// &
     693              :                           "external reference calculations use the same accuracy setting.", &
     694        10502 :                           usage="ACCURACY 1.0", default_r_val=1.0_dp)
     695        10502 :       CALL section_add_keyword(section, keyword)
     696        10502 :       CALL keyword_release(keyword)
     697              : 
     698        10502 :       NULLIFY (keyword)
     699              :       CALL keyword_create(keyword, __LOCATION__, name="REFERENCE_CLI", &
     700              :                           description="Enable an optional diagnostic comparison against an external native tblite "// &
     701              :                           "command line calculation. CP2K writes the current geometry, charge, spin, method, optional "// &
     702              :                           "PARAM file, electronic temperature, and requested reference settings to temporary files, "// &
     703              :                           "runs the external program, and compares the resulting energy, gradient, and optionally "// &
     704              :                           "virial with the CP2K/tblite values. This check is meant for debugging backend consistency, "// &
     705              :                           "not for production sampling. The native tblite CLI exposes only an electronic temperature "// &
     706              :                           "for the occupation broadening; if CP2K uses another smearing method, the reference run "// &
     707              :                           "prints a warning and uses Fermi-Dirac smearing with the CP2K electronic temperature. "// &
     708              :                           "If true, the XTB/TBLITE/REFERENCE_CLI section must be present. "// &
     709              :                           "The check is also enabled whenever that section is present. It is skipped for CP2K "// &
     710              :                           "multi-k-point calculations, because the native tblite CLI does not reproduce CP2K KPOINTS "// &
     711              :                           "sampling.", &
     712        10502 :                           usage="REFERENCE_CLI", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     713        10502 :       CALL section_add_keyword(section, keyword)
     714        10502 :       CALL keyword_release(keyword)
     715              : 
     716        10502 :       NULLIFY (subsection)
     717        10502 :       CALL create_xtb_reference_cli_section(subsection)
     718        10502 :       CALL section_add_subsection(section, subsection)
     719        10502 :       CALL section_release(subsection)
     720              : 
     721        10502 :    END SUBROUTINE create_xtb_tblite_section
     722              : 
     723              : ! **************************************************************************************************
     724              : !> \brief Creates the common &TBLITE_MIXER section for TB SCC-variable mixing.
     725              : !> \param section section to create
     726              : ! **************************************************************************************************
     727        21004 :    SUBROUTINE create_tblite_mixer_section(section)
     728              :       TYPE(section_type), POINTER                        :: section
     729              : 
     730              :       TYPE(keyword_type), POINTER                        :: keyword
     731              : 
     732        21004 :       CPASSERT(.NOT. ASSOCIATED(section))
     733              :       CALL section_create(section, __LOCATION__, name="TBLITE_MIXER", &
     734              :                           description="Controls tblite's modified Broyden SCC-variable mixer when SCC_MIXER is set "// &
     735              :                           "to TBLITE, either explicitly or through AUTO where AUTO selects tblite. The mixer "// &
     736              :                           "variables are the self-consistent "// &
     737              :                           "xTB/DFTB populations and, for methods that require them, atomic multipoles. ITERATIONS "// &
     738              :                           "limits the number of tblite SCC-mixer updates, while MEMORY controls how many previous "// &
     739              :                           "Broyden update vectors are retained. These are independent quantities when MEMORY is set "// &
     740              :                           "explicitly; otherwise MEMORY follows ITERATIONS, matching the tblite library default. "// &
     741              :                           "DAMPING controls the size of the retained population/multipole update. OMEGA0, "// &
     742              :                           "MIN_WEIGHT, MAX_WEIGHT, and WEIGHT_FACTOR expose tblite's modified-Broyden weighting "// &
     743              :                           "constants. ITERATIONS is the tblite-side SCC-mixer update limit and defaults to the "// &
     744              :                           "native tblite value of 250. When SCC_MIXER is explicitly set to TBLITE, CP2K also "// &
     745              :                           "sets the regular DFT/SCF/MAX_SCF limit to ITERATIONS so that the tblite SCC cycle is "// &
     746              :                           "not truncated by CP2K's default SCF limit. With SCC_MIXER AUTO or CP2K, DFT/SCF/MAX_SCF "// &
     747              :                           "keeps its normal CP2K meaning. This section configures the tblite SCC mixer, not the "// &
     748              :                           "regular CP2K charge mixer. With SCC_MIXER CP2K, the CP2K-side SCC-variable mixer is "// &
     749              :                           "controlled by DFT/SCF/MIXING. With QS/LS_SCF, this section is ignored and CP2K resets "// &
     750              :                           "SCC_MIXER to NONE internally, because LS_SCF performs the density-matrix optimization "// &
     751              :                           "instead of a separate SCC-variable mixing step. Native tblite "// &
     752              :                           "REFERENCE_CLI diagnostics inherit this section. ITERATIONS and SOLVER are representable "// &
     753              :                           "by tblite run directly; CP2K reports inherited MEMORY, DAMPING, or Broyden-weight settings "// &
     754              :                           "that native tblite CLI cannot reproduce.", &
     755        21004 :                           n_keywords=1, repeats=.FALSE.)
     756              : 
     757        21004 :       NULLIFY (keyword)
     758              :       CALL keyword_create(keyword, __LOCATION__, name="ITERATIONS", &
     759              :                           description="Maximum number of tblite SCC-mixer updates. This is the tblite-side SCC "// &
     760              :                           "iteration limit, matching native tblite's --iterations setting for reference CLI "// &
     761              :                           "diagnostics. For explicit SCC_MIXER TBLITE runs, CP2K synchronizes DFT/SCF/MAX_SCF to "// &
     762              :                           "this value. For SCC_MIXER AUTO or CP2K, DFT/SCF/MAX_SCF remains the normal CP2K "// &
     763              :                           "SCF-loop iteration limit. ITERATIONS is independent of MEMORY, which controls the "// &
     764              :                           "Broyden history length.", &
     765        21004 :                           usage="ITERATIONS 250", default_i_val=tblite_mixer_iterations_default)
     766        21004 :       CALL section_add_keyword(section, keyword)
     767        21004 :       CALL keyword_release(keyword)
     768              : 
     769              :       CALL keyword_create(keyword, __LOCATION__, name="MEMORY", &
     770              :                           description="Number of previous modified-Broyden update vectors kept by the tblite SCC "// &
     771              :                           "mixer. This is a history length, not an iteration limit. Larger values retain more "// &
     772              :                           "history and use more memory; smaller values reduce the history and can be more robust for "// &
     773              :                           "difficult SCC cycles. A value of zero means library default: inherit ITERATIONS, as native "// &
     774              :                           "tblite does when it constructs the Broyden mixer from calc%max_iter.", &
     775        21004 :                           usage="MEMORY 250", default_i_val=tblite_mixer_memory_inherit)
     776        21004 :       CALL section_add_keyword(section, keyword)
     777        21004 :       CALL keyword_release(keyword)
     778              : 
     779              :       CALL keyword_create(keyword, __LOCATION__, name="SOLVER", &
     780              :                           description="Electronic eigensolver selected for native tblite SCC calculations where "// &
     781              :                           "tblite owns the electronic solve, and forwarded to native REFERENCE_CLI diagnostics as "// &
     782              :                           "tblite run --solver. GVD is tblite's default LAPACK divide-and-conquer generalized "// &
     783              :                           "symmetric eigensolver. GVR selects LAPACK's relatively robust generalized symmetric "// &
     784              :                           "eigensolver. Production CP2K/tblite calculations still use CP2K's electronic "// &
     785              :                           "diagonalization machinery.", &
     786              :                           usage="SOLVER (GVD|GVR)", &
     787              :                           enum_c_vals=s2a("GVD", "GVR"), &
     788              :                           enum_i_vals=[tblite_solver_gvd, tblite_solver_gvr], &
     789              :                           enum_desc=s2a("Use LAPACK's divide-and-conquer generalized symmetric eigensolver.", &
     790              :                                         "Use LAPACK's relatively robust generalized symmetric eigensolver."), &
     791        21004 :                           default_i_val=tblite_solver_gvd)
     792        21004 :       CALL section_add_keyword(section, keyword)
     793        21004 :       CALL keyword_release(keyword)
     794              : 
     795              :       CALL keyword_create(keyword, __LOCATION__, name="DAMPING", &
     796              :                           description="Damping parameter for the tblite modified Broyden SCC mixer. It controls the "// &
     797              :                           "size of the population/multipole update retained by the native tblite mixer between SCC "// &
     798              :                           "iterations. Smaller values damp oscillatory SCC cycles more strongly but may slow "// &
     799              :                           "convergence; larger values can accelerate well-behaved cases but may destabilize difficult "// &
     800              :                           "ones. For CP2K-internal GFN1-xTB UKS k-point calculations with explicit SCC_MIXER TBLITE, "// &
     801              :                           "CP2K uses a conservative damping of 0.25 unless DAMPING is set explicitly.", &
     802        21004 :                           usage="DAMPING 0.4", default_r_val=tblite_mixer_damping_default)
     803        21004 :       CALL section_add_keyword(section, keyword)
     804        21004 :       CALL keyword_release(keyword)
     805              : 
     806              :       CALL keyword_create(keyword, __LOCATION__, name="OMEGA0", &
     807              :                           description="Regularization weight added to the diagonal of tblite's modified-Broyden "// &
     808              :                           "linear system. The default matches the hard-coded value in native tblite and damps nearly "// &
     809              :                           "singular history updates without changing the first simple-damping step.", &
     810        21004 :                           usage="OMEGA0 0.01", default_r_val=tblite_mixer_omega0_default)
     811        21004 :       CALL section_add_keyword(section, keyword)
     812        21004 :       CALL keyword_release(keyword)
     813              : 
     814              :       CALL keyword_create(keyword, __LOCATION__, name="MIN_WEIGHT", &
     815              :                           description="Lower bound for the dynamic Broyden history weight derived from the current "// &
     816              :                           "SCC residual. The default matches native tblite and prevents tiny weights from removing "// &
     817              :                           "history vectors from the update.", &
     818        21004 :                           usage="MIN_WEIGHT 1.0", default_r_val=tblite_mixer_min_weight_default)
     819        21004 :       CALL section_add_keyword(section, keyword)
     820        21004 :       CALL keyword_release(keyword)
     821              : 
     822              :       CALL keyword_create(keyword, __LOCATION__, name="MAX_WEIGHT", &
     823              :                           description="Upper bound for the dynamic Broyden history weight derived from the current "// &
     824              :                           "SCC residual. The default matches native tblite and caps the influence of very small "// &
     825              :                           "residual norms.", &
     826        21004 :                           usage="MAX_WEIGHT 100000.0", default_r_val=tblite_mixer_max_weight_default)
     827        21004 :       CALL section_add_keyword(section, keyword)
     828        21004 :       CALL keyword_release(keyword)
     829              : 
     830              :       CALL keyword_create(keyword, __LOCATION__, name="WEIGHT_FACTOR", &
     831              :                           description="Residual-to-weight scaling factor used by tblite's modified Broyden mixer. "// &
     832              :                           "For a residual norm above WEIGHT_FACTOR/MAX_WEIGHT, the dynamic weight is approximately "// &
     833              :                           "WEIGHT_FACTOR divided by that residual norm; otherwise MAX_WEIGHT is used before applying "// &
     834              :                           "MIN_WEIGHT. The default matches native tblite.", &
     835        21004 :                           usage="WEIGHT_FACTOR 0.01", default_r_val=tblite_mixer_weight_factor_default)
     836        21004 :       CALL section_add_keyword(section, keyword)
     837        21004 :       CALL keyword_release(keyword)
     838              : 
     839        21004 :    END SUBROUTINE create_tblite_mixer_section
     840              : 
     841              : ! **************************************************************************************************
     842              : !> \brief Adds common SCC-mixer keywords for TB methods.
     843              : !> \param section section receiving the keywords
     844              : !> \param TARGET method/path description for the manual text
     845              : !> \param auto_desc AUTO behavior for this section
     846              : ! **************************************************************************************************
     847        21004 :    SUBROUTINE add_tb_scc_mixer_keywords(section, TARGET, auto_desc)
     848              :       TYPE(section_type), POINTER                        :: section
     849              :       CHARACTER(LEN=*), INTENT(IN)                       :: target, auto_desc
     850              : 
     851              :       TYPE(keyword_type), POINTER                        :: keyword
     852              : 
     853        21004 :       NULLIFY (keyword)
     854              :       CALL keyword_create(keyword, __LOCATION__, name="SCC_MIXER", &
     855              :                           description="Selects the SCC variable mixer for "//TARGET//" calculations. "// &
     856              :                           auto_desc//" The SCC variables are the model populations and, where required by the "// &
     857              :                           "selected method, atomic multipoles that feed the self-consistent xTB potential. TBLITE "// &
     858              :                           "uses tblite's modified Broyden mixer for those variables inside the CP2K SCF cycle. CP2K "// &
     859              :                           "maps the variables onto CP2K's charge-mixing infrastructure. When TBLITE is active, the "// &
     860              :                           "native SCC convergence follows XTB/TBLITE/ACCURACY and the tblite-side SCC update limit "// &
     861              :                           "follows TBLITE_MIXER/ITERATIONS. If SCC_MIXER is explicitly set to TBLITE, CP2K also "// &
     862              :                           "sets DFT/SCF/MAX_SCF to TBLITE_MIXER/ITERATIONS. With SCC_MIXER AUTO or CP2K, MAX_SCF "// &
     863              :                           "keeps its normal CP2K meaning. With QS/LS_SCF, explicit SCC_MIXER settings are reset to "// &
     864              :                           "NONE internally and CP2K emits a warning; LS_SCF controls the density-matrix optimization. "// &
     865              :                           "When CP2K is active, convergence follows the normal CP2K SCF "// &
     866              :                           "controls, in particular DFT/SCF/EPS_SCF and DFT/SCF/MIXING. For GFN2/tblite, the CP2K "// &
     867              :                           "mixer acts on the full SCC-variable set: shell charges plus atomic dipole and quadrupole "// &
     868              :                           "variables. CP2K-internal GFN0-xTB has no SCC variables to mix, so AUTO and NONE are "// &
     869              :                           "equivalent there and explicit CP2K or TBLITE mixer choices are reset to NONE. For "// &
     870              :                           "CP2K-internal GFN1 and DFTB/DFTB3, the SCC variables are only charge or shell-charge like. The "// &
     871              :                           "initial SCC variables are seeded from CP2K's current density, so DFT/SCF/SCF_GUESS and "// &
     872              :                           "DFT/WFN_RESTART_FILE_NAME define the starting point. NONE performs direct updates without "// &
     873              :                           "mixing and is intended for debugging, since it can be unstable.", &
     874              :                           usage="SCC_MIXER (AUTO|TBLITE|CP2K|NONE)", &
     875              :                           enum_c_vals=s2a("AUTO", "TBLITE", "CP2K", "NONE"), &
     876              :                           enum_i_vals=[tblite_scc_mixer_auto, tblite_scc_mixer_tblite, &
     877              :                                        tblite_scc_mixer_cp2k, tblite_scc_mixer_none], &
     878              :                           enum_desc=s2a("Default method-dependent choice.", &
     879              :                                         "Use the tblite modified Broyden SCC mixer.", &
     880              :                                         "Use CP2K charge mixing for SCC variables.", &
     881              :                                         "Do not mix SCC variables; for debugging."), &
     882        21004 :                           default_i_val=tblite_scc_mixer_auto)
     883        21004 :       CALL section_add_keyword(section, keyword)
     884        21004 :       CALL keyword_release(keyword)
     885              : 
     886        21004 :    END SUBROUTINE add_tb_scc_mixer_keywords
     887              : 
     888              : ! **************************************************************************************************
     889              : !> \brief Creates the &REFERENCE_CLI section used to compare against native tblite.
     890              : !> \param section the section to create
     891              : ! **************************************************************************************************
     892        10502 :    SUBROUTINE create_xtb_reference_cli_section(section)
     893              :       TYPE(section_type), POINTER                        :: section
     894              : 
     895              :       TYPE(keyword_type), POINTER                        :: keyword
     896              :       TYPE(section_type), POINTER                        :: subsection
     897              : 
     898        10502 :       CPASSERT(.NOT. ASSOCIATED(section))
     899              :       CALL section_create(section, __LOCATION__, name="REFERENCE_CLI", &
     900              :                           description="Run the native tblite command line interface as a reference "// &
     901              :                           "for CP2K/tblite energies, nuclear gradients, and optionally virials. "// &
     902              :                           "The section is a lone section: if it is present, the reference check is enabled. By default "// &
     903              :                           "the native CLI calculation inherits the CP2K/tblite method, PARAM file, ACCURACY, charge, "// &
     904              :                           "spin state, spin-polarized Hamiltonian setting, electronic temperature, "// &
     905              :                           "TBLITE_MIXER/ITERATIONS, and TBLITE_MIXER/SOLVER from the surrounding input. CP2K forwards "// &
     906              :                           "DFT/UKS, including its LSD and SPIN_POLARIZED aliases, as native tblite "// &
     907              :                           "--spin-polarized; DFT/MULTIPLICITY is forwarded separately as --spin. "// &
     908              :                           "REFERENCE_CLI/EFIELD can add a homogeneous electric field to the "// &
     909              :                           "external native tblite command only. REFERENCE_CLI/IMPLICIT_SOLVATION can add native "// &
     910              :                           "tblite implicit-solvent settings to the external reference command only. "// &
     911              :                           "Native tblite run does not expose independent options for mixer MEMORY, DAMPING, OMEGA0, "// &
     912              :                           "MIN_WEIGHT, MAX_WEIGHT, or WEIGHT_FACTOR; CP2K warns if these inherited production settings "// &
     913              :                           "cannot be reproduced and aborts when STOP_ON_ERROR is enabled. "// &
     914              :                           "Native CLI verbosity follows GLOBAL/PRINT_LEVEL: SILENT is forwarded as --silent, and "// &
     915              :                           "HIGH or DEBUG are forwarded as --verbose. "// &
     916              :                           "It remains a diagnostic one-shot calculation from temporary input files and is independent "// &
     917              :                           "of CP2K's SCF history, diagonalization, and k-point machinery. If RESTART "// &
     918              :                           "is set, the named native tblite restart file is passed to the external command. Non-Fermi "// &
     919              :                           "CP2K smearing methods cannot be represented by native tblite and are replaced by a "// &
     920              :                           "Fermi-Dirac electronic temperature in the reference command with an explicit warning.", &
     921        10502 :                           n_keywords=1, n_subsections=0, repeats=.FALSE.)
     922              : 
     923        10502 :       NULLIFY (keyword)
     924              :       CALL keyword_create(keyword, __LOCATION__, name="_SECTION_PARAMETERS_", &
     925              :                           description="Activates the native tblite CLI reference check when the section is present. "// &
     926              :                           "The check compares CP2K/tblite against a freshly executed external tblite calculation.", &
     927        10502 :                           lone_keyword_l_val=.TRUE., default_l_val=.FALSE.)
     928        10502 :       CALL section_add_keyword(section, keyword)
     929        10502 :       CALL keyword_release(keyword)
     930              : 
     931              :       CALL keyword_create(keyword, __LOCATION__, name="PROGRAM_NAME", &
     932              :                           description="Executable name or path for the native tblite command line program used for "// &
     933              :                           "the reference calculation. This allows testing the CP2K/tblite implementation against a "// &
     934              :                           "specific tblite build without changing the CP2K executable.", &
     935        10502 :                           usage="PROGRAM_NAME tblite", n_var=1, type_of_var=char_t, default_c_val="tblite")
     936        10502 :       CALL section_add_keyword(section, keyword)
     937        10502 :       CALL keyword_release(keyword)
     938              : 
     939              :       CALL keyword_create(keyword, __LOCATION__, name="GUESS", &
     940              :                           description="Initial population guess used only for the native tblite reference command. "// &
     941              :                           "SAD uses the superposition of atomic densities, matching the default of tblite run. EEQ "// &
     942              :                           "uses electronegativity equilibration charges, while CEH uses the charge-equilibration "// &
     943              :                           "Hamiltonian guess. This keyword does not affect the production CP2K/tblite calculation; "// &
     944              :                           "there, initial densities and restarts remain controlled by CP2K's SCF machinery.", &
     945              :                           usage="GUESS (SAD|EEQ|CEH)", &
     946              :                           enum_c_vals=s2a("SAD", "EEQ", "CEH"), &
     947              :                           enum_i_vals=[tblite_guess_sad, tblite_guess_eeq, tblite_guess_ceh], &
     948              :                           enum_desc=s2a("Use the superposition of atomic densities guess.", &
     949              :                                         "Use the electronegativity equilibration guess.", &
     950              :                                         "Use the charge-equilibration Hamiltonian guess."), &
     951        10502 :                           default_i_val=tblite_guess_sad)
     952        10502 :       CALL section_add_keyword(section, keyword)
     953        10502 :       CALL keyword_release(keyword)
     954              : 
     955              :       CALL keyword_create(keyword, __LOCATION__, name="WORK_DIRECTORY", &
     956              :                           description="Directory used for the temporary native tblite CLI input and output files. "// &
     957              :                           "The CP2K/tblite result is not taken from this directory; the files are only used to run and "// &
     958              :                           "inspect the independent reference calculation.", &
     959        10502 :                           usage="WORK_DIRECTORY .", n_var=1, type_of_var=char_t, default_c_val=".")
     960        10502 :       CALL section_add_keyword(section, keyword)
     961        10502 :       CALL keyword_release(keyword)
     962              : 
     963              :       CALL keyword_create(keyword, __LOCATION__, name="PREFIX", &
     964              :                           description="Prefix for the temporary native tblite CLI input and output files. Changing "// &
     965              :                           "the prefix is useful when several reference checks are run in the same directory or when "// &
     966              :                           "KEEP_FILES is used to inspect the generated geometry, gradient, JSON, or log files.", &
     967              :                           usage="PREFIX tblite-reference", n_var=1, type_of_var=char_t, &
     968        10502 :                           default_c_val="tblite-reference")
     969        10502 :       CALL section_add_keyword(section, keyword)
     970        10502 :       CALL keyword_release(keyword)
     971              : 
     972              :       CALL keyword_create(keyword, __LOCATION__, name="INPUT_FORMAT", &
     973              :                           description="Input format hint passed to native tblite run as --input. The default is GEN, "// &
     974              :                           "matching the temporary DFTB+ GEN geometry written by CP2K for the reference calculation. "// &
     975              :                           "Only change this together with a compatible externally inspected or modified input file "// &
     976              :                           "workflow; the normal CP2K-generated reference geometry is GEN.", &
     977        10502 :                           usage="INPUT_FORMAT gen", n_var=1, type_of_var=char_t, default_c_val="gen")
     978        10502 :       CALL section_add_keyword(section, keyword)
     979        10502 :       CALL keyword_release(keyword)
     980              : 
     981              :       CALL keyword_create(keyword, __LOCATION__, name="RESTART", &
     982              :                           description="Native tblite restart file passed to the external reference command. When this "// &
     983              :                           "keyword is absent, CP2K passes --no-restart so each diagnostic reference is a clean one-shot "// &
     984              :                           "run from the generated geometry and selected CLI options. When a filename is given, CP2K "// &
     985              :                           "passes --restart with that file. This affects only the external native tblite run; it does "// &
     986              :                           "not read or write CP2K wavefunction or density restart data and is therefore independent of "// &
     987              :                           "DFT/SCF/SCF_GUESS RESTART.", &
     988        10502 :                           usage="RESTART filename", n_var=1, type_of_var=char_t, default_c_val="")
     989        10502 :       CALL section_add_keyword(section, keyword)
     990        10502 :       CALL keyword_release(keyword)
     991              : 
     992              :       CALL keyword_create(keyword, __LOCATION__, name="POST_PROCESSING", &
     993              :                           description="Additional native tblite post-SCF analysis passed as tblite run "// &
     994              :                           "--post-processing. The value can be a built-in post-processing module name or a TOML file. "// &
     995              :                           "Native tblite already enables Mayer-Wiberg bond-order analysis internally by default. "// &
     996              :                           "The additional built-in module names currently exposed by tblite include molmom for "// &
     997              :                           "molecular moments and xtbml for xTB-ML descriptors. If the value names a TOML file, tblite "// &
     998              :                           "reads its [post-processing] configuration and can select the post-processing modules more "// &
     999              :                           "finely. This keyword affects only the external REFERENCE_CLI diagnostic run; CP2K does not "// &
    1000              :                           "parse the generated post-processing data for the energy/force/virial comparison.", &
    1001        10502 :                           usage="POST_PROCESSING molmom", n_var=1, type_of_var=char_t, default_c_val="")
    1002        10502 :       CALL section_add_keyword(section, keyword)
    1003        10502 :       CALL keyword_release(keyword)
    1004              : 
    1005              :       CALL keyword_create(keyword, __LOCATION__, name="POST_PROCESSING_OUTPUT", &
    1006              :                           description="Filename passed to native tblite as --post-processing-output. Native tblite "// &
    1007              :                           "documents this as the NPZ output file for post-processing data, with tblite-data.npz as its "// &
    1008              :                           "CLI default. In the locally checked tblite 0.5.0 source this option appears in the help text "// &
    1009              :                           "but is not wired in the command-line parser, so CP2K emits it only when explicitly requested "// &
    1010              :                           "and prints a warning before running the reference command. Use this keyword only with tblite "// &
    1011              :                           "CLI builds that actually accept the option. Unless KEEP_FILES is enabled, CP2K removes this "// &
    1012              :                           "explicit output file after the reference check.", &
    1013              :                           usage="POST_PROCESSING_OUTPUT tblite-data.npz", n_var=1, type_of_var=char_t, &
    1014        10502 :                           default_c_val="", lone_keyword_c_val="tblite-data.npz")
    1015        10502 :       CALL section_add_keyword(section, keyword)
    1016        10502 :       CALL keyword_release(keyword)
    1017              : 
    1018              :       CALL keyword_create(keyword, __LOCATION__, name="GRAD", &
    1019              :                           description="Filename passed to native tblite as --grad for the tagged ASCII gradient output. "// &
    1020              :                           "The native file contains the total energy, energy contributions, analytical molecular "// &
    1021              :                           "gradient, and virial. CP2K reads this file for the REFERENCE_CLI energy, force, and virial "// &
    1022              :                           "checks. If the keyword is omitted, CP2K writes a temporary PREFIX.grad file in "// &
    1023              :                           "WORK_DIRECTORY. If the keyword is present without a filename, CP2K uses tblite's CLI default "// &
    1024              :                           "name tblite.txt. Unless KEEP_FILES is enabled, CP2K removes the selected file after the "// &
    1025              :                           "reference check.", &
    1026              :                           usage="GRAD tblite.txt", n_var=1, type_of_var=char_t, default_c_val="", &
    1027        10502 :                           lone_keyword_c_val="tblite.txt")
    1028        10502 :       CALL section_add_keyword(section, keyword)
    1029        10502 :       CALL keyword_release(keyword)
    1030              : 
    1031              :       CALL keyword_create(keyword, __LOCATION__, name="JSON", &
    1032              :                           description="Filename passed to native tblite as --json for JSON result output. Without "// &
    1033              :                           "--grad the native JSON usually contains the energy and energy contributions; because CP2K's "// &
    1034              :                           "REFERENCE_CLI path also requests --grad, native tblite can additionally include derivative "// &
    1035              :                           "data such as gradient and virial when supported by the CLI version. CP2K currently reads the "// &
    1036              :                           "tagged GRAD file for comparisons and keeps the JSON file as an inspectable native artifact. "// &
    1037              :                           "If the keyword is omitted, CP2K writes a temporary PREFIX.json file in WORK_DIRECTORY. If the "// &
    1038              :                           "keyword is present without a filename, CP2K uses tblite's CLI default name tblite.json. "// &
    1039              :                           "Unless KEEP_FILES is enabled, CP2K removes the selected file after the reference check.", &
    1040              :                           usage="JSON tblite.json", n_var=1, type_of_var=char_t, default_c_val="", &
    1041        10502 :                           lone_keyword_c_val="tblite.json")
    1042        10502 :       CALL section_add_keyword(section, keyword)
    1043        10502 :       CALL keyword_release(keyword)
    1044              : 
    1045              :       CALL keyword_create(keyword, __LOCATION__, name="ELECTRONIC_TEMPERATURE_GUESS", &
    1046              :                           description="Electronic temperature used only for the native tblite reference command's "// &
    1047              :                           "initial CEH population guess. CP2K forwards positive values as tblite run "// &
    1048              :                           "--etemp-guess. The value does not affect CP2K/tblite production calculations and is "// &
    1049              :                           "independent of DFT/SCF/SMEAR/ELECTRONIC_TEMPERATURE, which controls the final electronic "// &
    1050              :                           "occupation temperature passed as --etemp. A value of zero leaves the native tblite default "// &
    1051              :                           "for the guess temperature untouched. Positive values are valid only together with GUESS CEH; "// &
    1052              :                           "CP2K aborts for SAD or EEQ because native tblite uses this option for the CEH guess.", &
    1053              :                           usage="ELECTRONIC_TEMPERATURE_GUESS [K] 4000", &
    1054        10502 :                           default_r_val=cp_unit_to_cp2k(value=0.0_dp, unit_str="K"), unit_str="K")
    1055        10502 :       CALL section_add_keyword(section, keyword)
    1056        10502 :       CALL keyword_release(keyword)
    1057              : 
    1058              :       CALL keyword_create(keyword, __LOCATION__, name="EFIELD", &
    1059              :                           description="Homogeneous electric field passed only to the native tblite reference command "// &
    1060              :                           "as tblite run --efield. The three components are given in V/Angstrom, matching the native "// &
    1061              :                           "tblite CLI convention. This keyword does not affect the production CP2K/tblite "// &
    1062              :                           "calculation because that path currently does not construct tblite's external electric "// &
    1063              :                           "field container. If enabled together with energy, force, or virial checks, the comparison "// &
    1064              :                           "therefore intentionally diagnoses the native field response rather than matching a CP2K "// &
    1065              :                           "production field calculation.", &
    1066              :                           usage="EFIELD 0.0 0.0 0.0", repeats=.FALSE., n_var=3, type_of_var=real_t, &
    1067        10502 :                           default_r_vals=[0.0_dp, 0.0_dp, 0.0_dp])
    1068        10502 :       CALL section_add_keyword(section, keyword)
    1069        10502 :       CALL keyword_release(keyword)
    1070              : 
    1071              :       CALL keyword_create(keyword, __LOCATION__, name="KEEP_FILES", &
    1072              :                           description="Keep the temporary native tblite CLI input and output files after the "// &
    1073              :                           "comparison. This is mainly a debugging aid for inspecting the generated GEN geometry, the "// &
    1074              :                           "native tblite gradient/virial file, the JSON output, and the CLI log.", &
    1075        10502 :                           usage="KEEP_FILES T", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
    1076        10502 :       CALL section_add_keyword(section, keyword)
    1077        10502 :       CALL keyword_release(keyword)
    1078              : 
    1079              :       CALL keyword_create(keyword, __LOCATION__, name="ERROR_LIMIT", &
    1080              :                           description="Tolerance for reporting reference CLI deviations. The value is applied to the "// &
    1081              :                           "absolute CP2K-minus-native differences printed by the enabled energy, force, and virial "// &
    1082              :                           "checks. Exceeding this limit produces a diagnostic warning, or an abort when STOP_ON_ERROR "// &
    1083              :                           "is enabled.", &
    1084        10502 :                           usage="ERROR_LIMIT 1.0E-8", default_r_val=1.0E-8_dp)
    1085        10502 :       CALL section_add_keyword(section, keyword)
    1086        10502 :       CALL keyword_release(keyword)
    1087              : 
    1088              :       CALL keyword_create(keyword, __LOCATION__, name="STOP_ON_ERROR", &
    1089              :                           description="Abort the CP2K run if any enabled reference CLI comparison exceeds "// &
    1090              :                           "ERROR_LIMIT. When disabled, CP2K prints the deviation but continues, which is useful for "// &
    1091              :                           "exploratory diagnostics and regression-test probes.", &
    1092        10502 :                           usage="STOP_ON_ERROR T", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
    1093        10502 :       CALL section_add_keyword(section, keyword)
    1094        10502 :       CALL keyword_release(keyword)
    1095              : 
    1096              :       CALL keyword_create(keyword, __LOCATION__, name="CHECK_ENERGY", &
    1097              :                           description="Compare the CP2K/tblite total xTB energy with the energy obtained from the "// &
    1098              :                           "native tblite reference run. This checks the Hamiltonian setup, SCC solution, static "// &
    1099              :                           "repulsion/dispersion terms, charge and spin state, electronic temperature, and optional "// &
    1100              :                           "PARAM file consistency for the one-shot reference geometry.", &
    1101        10502 :                           usage="CHECK_ENERGY T", default_l_val=.TRUE., lone_keyword_l_val=.TRUE.)
    1102        10502 :       CALL section_add_keyword(section, keyword)
    1103        10502 :       CALL keyword_release(keyword)
    1104              : 
    1105              :       CALL keyword_create(keyword, __LOCATION__, name="CHECK_FORCES", &
    1106              :                           description="Compare CP2K/tblite nuclear gradients with the gradients written by the "// &
    1107              :                           "native tblite reference run. This is a sensitive check of derivative terms, including "// &
    1108              :                           "repulsion, dispersion, electrostatic response, and coordination-number response. The "// &
    1109              :                           "comparison uses the same geometry and model setup as the energy reference.", &
    1110        10502 :                           usage="CHECK_FORCES T", default_l_val=.TRUE., lone_keyword_l_val=.TRUE.)
    1111        10502 :       CALL section_add_keyword(section, keyword)
    1112        10502 :       CALL keyword_release(keyword)
    1113              : 
    1114              :       CALL keyword_create(keyword, __LOCATION__, name="CHECK_VIRIAL", &
    1115              :                           description="Compare CP2K/tblite virial with the virial written by the native tblite "// &
    1116              :                           "reference run. This is a diagnostic for cell derivatives and stress-related terms. It is "// &
    1117              :                           "disabled by default because virial conventions, finite periodicity, and the absence of "// &
    1118              :                           "native CLI k-point sampling make this comparison more restrictive than the energy and "// &
    1119              :                           "force checks.", &
    1120        10502 :                           usage="CHECK_VIRIAL T", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
    1121        10502 :       CALL section_add_keyword(section, keyword)
    1122        10502 :       CALL keyword_release(keyword)
    1123              : 
    1124        10502 :       NULLIFY (subsection)
    1125        10502 :       CALL create_xtb_reference_cli_guess_section(subsection)
    1126        10502 :       CALL section_add_subsection(section, subsection)
    1127        10502 :       CALL section_release(subsection)
    1128              : 
    1129        10502 :       NULLIFY (subsection)
    1130        10502 :       CALL create_xtb_reference_cli_param_section(subsection)
    1131        10502 :       CALL section_add_subsection(section, subsection)
    1132        10502 :       CALL section_release(subsection)
    1133              : 
    1134        10502 :       NULLIFY (subsection)
    1135        10502 :       CALL create_xtb_reference_cli_fit_section(subsection)
    1136        10502 :       CALL section_add_subsection(section, subsection)
    1137        10502 :       CALL section_release(subsection)
    1138              : 
    1139        10502 :       NULLIFY (subsection)
    1140        10502 :       CALL create_xtb_reference_cli_tagdiff_section(subsection)
    1141        10502 :       CALL section_add_subsection(section, subsection)
    1142        10502 :       CALL section_release(subsection)
    1143              : 
    1144        10502 :       NULLIFY (subsection)
    1145        10502 :       CALL create_xtb_reference_cli_solvation_section(subsection)
    1146        10502 :       CALL section_add_subsection(section, subsection)
    1147        10502 :       CALL section_release(subsection)
    1148              : 
    1149        10502 :    END SUBROUTINE create_xtb_reference_cli_section
    1150              : 
    1151              : ! **************************************************************************************************
    1152              : !> \brief Creates the &REFERENCE_CLI%GUESS_CLI section for native tblite guess.
    1153              : !> \param section section to create
    1154              : ! **************************************************************************************************
    1155        10502 :    SUBROUTINE create_xtb_reference_cli_guess_section(section)
    1156              :       TYPE(section_type), POINTER                        :: section
    1157              : 
    1158              :       TYPE(keyword_type), POINTER                        :: keyword
    1159              : 
    1160        10502 :       CPASSERT(.NOT. ASSOCIATED(section))
    1161              :       CALL section_create(section, __LOCATION__, name="GUESS_CLI", &
    1162              :                           description="Run the native tblite guess subcommand as an auxiliary REFERENCE_CLI "// &
    1163              :                           "diagnostic. The command executes tblite guess on the generated GEN geometry by default and "// &
    1164              :                           "prints the initializing charges and dipole moments. CP2K forwards the surrounding charge "// &
    1165              :                           "and multiplicity as native --charge and --spin. GLOBAL/PRINT_LEVEL controls native "// &
    1166              :                           "--silent or --verbose exactly as for the main REFERENCE_CLI run command. This section is "// &
    1167              :                           "diagnostic only; CP2K does not use the generated guess data to seed the production "// &
    1168              :                           "calculation.", &
    1169        10502 :                           n_keywords=1, n_subsections=0, repeats=.FALSE.)
    1170              : 
    1171        10502 :       NULLIFY (keyword)
    1172              :       CALL keyword_create(keyword, __LOCATION__, name="_SECTION_PARAMETERS_", &
    1173              :                           description="Activates the native tblite guess auxiliary command when the section is "// &
    1174        10502 :                           "present.", lone_keyword_l_val=.TRUE., default_l_val=.FALSE.)
    1175        10502 :       CALL section_add_keyword(section, keyword)
    1176        10502 :       CALL keyword_release(keyword)
    1177              : 
    1178              :       CALL keyword_create(keyword, __LOCATION__, name="METHOD", &
    1179              :                           description="Initial-population method passed to native tblite guess as --method. SAD uses "// &
    1180              :                           "superposed atomic densities, EEQ uses electronegativity equilibration, and CEH uses the "// &
    1181              :                           "charge-extended Huckel guess. The default matches native tblite guess.", &
    1182              :                           usage="METHOD (SAD|EEQ|CEH)", &
    1183              :                           enum_c_vals=s2a("SAD", "EEQ", "CEH"), &
    1184              :                           enum_i_vals=[tblite_guess_sad, tblite_guess_eeq, tblite_guess_ceh], &
    1185              :                           enum_desc=s2a("Use the superposition of atomic densities guess.", &
    1186              :                                         "Use the electronegativity equilibration guess.", &
    1187              :                                         "Use the charge-extended Huckel guess."), &
    1188        10502 :                           default_i_val=tblite_guess_ceh)
    1189        10502 :       CALL section_add_keyword(section, keyword)
    1190        10502 :       CALL keyword_release(keyword)
    1191              : 
    1192              :       CALL keyword_create(keyword, __LOCATION__, name="ELECTRONIC_TEMPERATURE_GUESS", &
    1193              :                           description="Electronic temperature for native tblite guess --etemp-guess. This option is "// &
    1194              :                           "used by the CEH guess in native tblite. A value of zero leaves tblite's own default "// &
    1195              :                           "untouched.", usage="ELECTRONIC_TEMPERATURE_GUESS [K] 4000", &
    1196        10502 :                           default_r_val=cp_unit_to_cp2k(value=0.0_dp, unit_str="K"), unit_str="K")
    1197        10502 :       CALL section_add_keyword(section, keyword)
    1198        10502 :       CALL keyword_release(keyword)
    1199              : 
    1200              :       CALL keyword_create(keyword, __LOCATION__, name="SOLVER", &
    1201              :                           description="Electronic solver passed to native tblite guess as --solver. GVD is the "// &
    1202              :                           "default generalized eigenvalue decomposition solver; GVR selects the alternative solver "// &
    1203              :                           "exposed by tblite.", usage="SOLVER (GVD|GVR)", &
    1204              :                           enum_c_vals=s2a("GVD", "GVR"), enum_i_vals=[tblite_solver_gvd, tblite_solver_gvr], &
    1205              :                           enum_desc=s2a("Use the GVD electronic solver.", "Use the GVR electronic solver."), &
    1206        10502 :                           default_i_val=tblite_solver_gvd)
    1207        10502 :       CALL section_add_keyword(section, keyword)
    1208        10502 :       CALL keyword_release(keyword)
    1209              : 
    1210              :       CALL keyword_create(keyword, __LOCATION__, name="EFIELD", &
    1211              :                           description="Homogeneous electric field passed to native tblite guess as --efield. The "// &
    1212              :                           "three components are given in V/Angstrom, matching native tblite.", &
    1213              :                           usage="EFIELD 0.0 0.0 0.0", repeats=.FALSE., n_var=3, type_of_var=real_t, &
    1214        10502 :                           default_r_vals=[0.0_dp, 0.0_dp, 0.0_dp])
    1215        10502 :       CALL section_add_keyword(section, keyword)
    1216        10502 :       CALL keyword_release(keyword)
    1217              : 
    1218              :       CALL keyword_create(keyword, __LOCATION__, name="GRAD", &
    1219              :                           description="Request native tblite guess --grad, evaluating the analytic gradient of the "// &
    1220        10502 :                           "guessed charges.", usage="GRAD T", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
    1221        10502 :       CALL section_add_keyword(section, keyword)
    1222        10502 :       CALL keyword_release(keyword)
    1223              : 
    1224              :       CALL keyword_create(keyword, __LOCATION__, name="JSON", &
    1225              :                           description="Filename passed to native tblite guess as --json. If the keyword is present "// &
    1226              :                           "without a filename, CP2K uses tblite's CLI default name tblite.json. If omitted, CP2K does "// &
    1227              :                           "not request JSON output for the auxiliary guess command.", &
    1228              :                           usage="JSON tblite.json", n_var=1, type_of_var=char_t, default_c_val="", &
    1229        10502 :                           lone_keyword_c_val="tblite.json")
    1230        10502 :       CALL section_add_keyword(section, keyword)
    1231        10502 :       CALL keyword_release(keyword)
    1232              : 
    1233              :       CALL keyword_create(keyword, __LOCATION__, name="INPUT_FORMAT", &
    1234              :                           description="Input format hint passed to native tblite guess as --input. The default is GEN, "// &
    1235              :                           "matching the temporary DFTB+ GEN geometry written by CP2K for the enclosing reference "// &
    1236              :                           "calculation.", &
    1237        10502 :                           usage="INPUT_FORMAT gen", n_var=1, type_of_var=char_t, default_c_val="gen")
    1238        10502 :       CALL section_add_keyword(section, keyword)
    1239        10502 :       CALL keyword_release(keyword)
    1240              : 
    1241              :       CALL keyword_create(keyword, __LOCATION__, name="INPUT_FILE", &
    1242              :                           description="Positional input structure for native tblite guess. The file format must match "// &
    1243              :                           "GUESS_CLI/INPUT_FORMAT. If omitted, CP2K uses the temporary GEN geometry written for the "// &
    1244              :                           "enclosing REFERENCE_CLI calculation.", &
    1245        10502 :                           usage="INPUT_FILE structure.gen", n_var=1, type_of_var=char_t, default_c_val="")
    1246        10502 :       CALL section_add_keyword(section, keyword)
    1247        10502 :       CALL keyword_release(keyword)
    1248              : 
    1249        10502 :    END SUBROUTINE create_xtb_reference_cli_guess_section
    1250              : 
    1251              : ! **************************************************************************************************
    1252              : !> \brief Creates the &REFERENCE_CLI%PARAM_CLI section for native tblite param.
    1253              : !> \param section section to create
    1254              : ! **************************************************************************************************
    1255        10502 :    SUBROUTINE create_xtb_reference_cli_param_section(section)
    1256              :       TYPE(section_type), POINTER                        :: section
    1257              : 
    1258              :       TYPE(keyword_type), POINTER                        :: keyword
    1259              : 
    1260        10502 :       CPASSERT(.NOT. ASSOCIATED(section))
    1261              :       CALL section_create(section, __LOCATION__, name="PARAM_CLI", &
    1262              :                           description="Run the native tblite param subcommand as an auxiliary REFERENCE_CLI "// &
    1263              :                           "diagnostic. The command inspects, imports, exports, or converts tblite parameter data. "// &
    1264              :                           "If no INPUT_FILE is supplied, CP2K selects the surrounding XTB/TBLITE/METHOD as native "// &
    1265              :                           "--method. If METHOD is specified here, it overrides only this auxiliary command.", &
    1266        10502 :                           n_keywords=1, n_subsections=0, repeats=.FALSE.)
    1267              : 
    1268        10502 :       NULLIFY (keyword)
    1269              :       CALL keyword_create(keyword, __LOCATION__, name="_SECTION_PARAMETERS_", &
    1270              :                           description="Activates the native tblite param auxiliary command when the section is "// &
    1271        10502 :                           "present.", lone_keyword_l_val=.TRUE., default_l_val=.FALSE.)
    1272        10502 :       CALL section_add_keyword(section, keyword)
    1273        10502 :       CALL keyword_release(keyword)
    1274              : 
    1275              :       CALL keyword_create(keyword, __LOCATION__, name="METHOD", &
    1276              :                           description="Base parametrization passed to native tblite param as --method. If omitted, "// &
    1277              :                           "CP2K uses the surrounding XTB/TBLITE/METHOD.", &
    1278              :                           usage="METHOD (GFN1|GFN2|IPEA1)", &
    1279              :                           enum_c_vals=s2a("GFN1", "GFN2", "IPEA1"), &
    1280              :                           enum_i_vals=[gfn1xtb, gfn2xtb, ipea1xtb], &
    1281              :                           enum_desc=s2a("Use the GFN1-xTB base parametrization.", &
    1282              :                                         "Use the GFN2-xTB base parametrization.", &
    1283              :                                         "Use the IPEA1 base parametrization."), &
    1284        10502 :                           default_i_val=gfn2xtb)
    1285        10502 :       CALL section_add_keyword(section, keyword)
    1286        10502 :       CALL keyword_release(keyword)
    1287              : 
    1288              :       CALL keyword_create(keyword, __LOCATION__, name="OUTPUT", &
    1289              :                           description="Output parameter file passed to native tblite param as --output. If omitted, "// &
    1290              :                           "native tblite writes to its default stream or file for the selected operation.", &
    1291        10502 :                           usage="OUTPUT parameters.toml", n_var=1, type_of_var=char_t, default_c_val="")
    1292        10502 :       CALL section_add_keyword(section, keyword)
    1293        10502 :       CALL keyword_release(keyword)
    1294              : 
    1295              :       CALL keyword_create(keyword, __LOCATION__, name="INPUT_FILE", &
    1296              :                           description="Optional positional input parameter file for native tblite param. If omitted, "// &
    1297              :                           "the command operates on the selected built-in METHOD.", &
    1298        10502 :                           usage="INPUT_FILE parameters.toml", n_var=1, type_of_var=char_t, default_c_val="")
    1299        10502 :       CALL section_add_keyword(section, keyword)
    1300        10502 :       CALL keyword_release(keyword)
    1301              : 
    1302        10502 :    END SUBROUTINE create_xtb_reference_cli_param_section
    1303              : 
    1304              : ! **************************************************************************************************
    1305              : !> \brief Creates the &REFERENCE_CLI%FIT_CLI section for native tblite fit.
    1306              : !> \param section section to create
    1307              : ! **************************************************************************************************
    1308        10502 :    SUBROUTINE create_xtb_reference_cli_fit_section(section)
    1309              :       TYPE(section_type), POINTER                        :: section
    1310              : 
    1311              :       TYPE(keyword_type), POINTER                        :: keyword
    1312              : 
    1313        10502 :       CPASSERT(.NOT. ASSOCIATED(section))
    1314              :       CALL section_create(section, __LOCATION__, name="FIT_CLI", &
    1315              :                           description="Run the native tblite fit subcommand as an auxiliary REFERENCE_CLI diagnostic. "// &
    1316              :                           "The command optimizes or dry-runs tblite parameters from a starting PARAM_FILE and a fit "// &
    1317              :                           "settings INPUT_FILE. Because native fitting can be expensive and writes its own outputs, "// &
    1318              :                           "the section is inactive unless explicitly present.", &
    1319        10502 :                           n_keywords=1, n_subsections=0, repeats=.FALSE.)
    1320              : 
    1321        10502 :       NULLIFY (keyword)
    1322              :       CALL keyword_create(keyword, __LOCATION__, name="_SECTION_PARAMETERS_", &
    1323              :                           description="Activates the native tblite fit auxiliary command when the section is present.", &
    1324        10502 :                           lone_keyword_l_val=.TRUE., default_l_val=.FALSE.)
    1325        10502 :       CALL section_add_keyword(section, keyword)
    1326        10502 :       CALL keyword_release(keyword)
    1327              : 
    1328              :       CALL keyword_create(keyword, __LOCATION__, name="PARAM_FILE", &
    1329              :                           description="Starting parameter file passed as the first positional argument to native "// &
    1330        10502 :                           "tblite fit.", usage="PARAM_FILE start.toml", n_var=1, type_of_var=char_t, default_c_val="")
    1331        10502 :       CALL section_add_keyword(section, keyword)
    1332        10502 :       CALL keyword_release(keyword)
    1333              : 
    1334              :       CALL keyword_create(keyword, __LOCATION__, name="INPUT_FILE", &
    1335              :                           description="Fit-settings input file passed as the second positional argument to native "// &
    1336        10502 :                           "tblite fit.", usage="INPUT_FILE fit.toml", n_var=1, type_of_var=char_t, default_c_val="")
    1337        10502 :       CALL section_add_keyword(section, keyword)
    1338        10502 :       CALL keyword_release(keyword)
    1339              : 
    1340              :       CALL keyword_create(keyword, __LOCATION__, name="DRY_RUN", &
    1341              :                           description="Pass native tblite fit --dry-run. This expands and checks the fit setup "// &
    1342              :                           "without starting the optimization.", usage="DRY_RUN T", default_l_val=.FALSE., &
    1343        10502 :                           lone_keyword_l_val=.TRUE.)
    1344        10502 :       CALL section_add_keyword(section, keyword)
    1345        10502 :       CALL keyword_release(keyword)
    1346              : 
    1347              :       CALL keyword_create(keyword, __LOCATION__, name="COPY", &
    1348              :                           description="Filename passed to native tblite fit as --copy. Native tblite writes the full "// &
    1349              :                           "representation of the fit input to this file, with defaults filled in and masks expanded.", &
    1350        10502 :                           usage="COPY expanded-fit.toml", n_var=1, type_of_var=char_t, default_c_val="")
    1351        10502 :       CALL section_add_keyword(section, keyword)
    1352        10502 :       CALL keyword_release(keyword)
    1353              : 
    1354        10502 :    END SUBROUTINE create_xtb_reference_cli_fit_section
    1355              : 
    1356              : ! **************************************************************************************************
    1357              : !> \brief Creates the &REFERENCE_CLI%TAGDIFF_CLI section for native tblite tagdiff.
    1358              : !> \param section section to create
    1359              : ! **************************************************************************************************
    1360        10502 :    SUBROUTINE create_xtb_reference_cli_tagdiff_section(section)
    1361              :       TYPE(section_type), POINTER                        :: section
    1362              : 
    1363              :       TYPE(keyword_type), POINTER                        :: keyword
    1364              : 
    1365        10502 :       CPASSERT(.NOT. ASSOCIATED(section))
    1366              :       CALL section_create(section, __LOCATION__, name="TAGDIFF_CLI", &
    1367              :                           description="Run the native tblite tagdiff auxiliary command. It compares an ACTUAL tagged "// &
    1368              :                           "data file against a REFERENCE tagged data file and reports differences using the keys from "// &
    1369        10502 :                           "the reference file.", n_keywords=1, n_subsections=0, repeats=.FALSE.)
    1370              : 
    1371        10502 :       NULLIFY (keyword)
    1372              :       CALL keyword_create(keyword, __LOCATION__, name="_SECTION_PARAMETERS_", &
    1373              :                           description="Activates the native tblite tagdiff auxiliary command when the section is "// &
    1374        10502 :                           "present.", lone_keyword_l_val=.TRUE., default_l_val=.FALSE.)
    1375        10502 :       CALL section_add_keyword(section, keyword)
    1376        10502 :       CALL keyword_release(keyword)
    1377              : 
    1378              :       CALL keyword_create(keyword, __LOCATION__, name="ACTUAL", &
    1379              :                           description="Actual tagged data file passed as the first positional argument to native "// &
    1380        10502 :                           "tblite tagdiff.", usage="ACTUAL actual.tag", n_var=1, type_of_var=char_t, default_c_val="")
    1381        10502 :       CALL section_add_keyword(section, keyword)
    1382        10502 :       CALL keyword_release(keyword)
    1383              : 
    1384              :       CALL keyword_create(keyword, __LOCATION__, name="REFERENCE", &
    1385              :                           description="Reference tagged data file passed as the second positional argument to native "// &
    1386              :                           "tblite tagdiff. Native tblite uses only keys present in this reference file.", &
    1387        10502 :                           usage="REFERENCE reference.tag", n_var=1, type_of_var=char_t, default_c_val="")
    1388        10502 :       CALL section_add_keyword(section, keyword)
    1389        10502 :       CALL keyword_release(keyword)
    1390              : 
    1391              :       CALL keyword_create(keyword, __LOCATION__, name="FIT", &
    1392              :                           description="Pass native tblite tagdiff --fit, producing output suitable for tblite fit.", &
    1393        10502 :                           usage="FIT T", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
    1394        10502 :       CALL section_add_keyword(section, keyword)
    1395        10502 :       CALL keyword_release(keyword)
    1396              : 
    1397        10502 :    END SUBROUTINE create_xtb_reference_cli_tagdiff_section
    1398              : 
    1399              : ! **************************************************************************************************
    1400              : !> \brief Creates the &REFERENCE_CLI%IMPLICIT_SOLVATION section for native tblite.
    1401              : !> \param section section to create
    1402              : ! **************************************************************************************************
    1403        10502 :    SUBROUTINE create_xtb_reference_cli_solvation_section(section)
    1404              :       TYPE(section_type), POINTER                        :: section
    1405              : 
    1406              :       TYPE(keyword_type), POINTER                        :: keyword
    1407              : 
    1408        10502 :       CPASSERT(.NOT. ASSOCIATED(section))
    1409              :       CALL section_create(section, __LOCATION__, name="IMPLICIT_SOLVATION", &
    1410              :                           description="Native tblite implicit-solvation settings for the external REFERENCE_CLI "// &
    1411              :                           "diagnostic command. This section does not affect the production CP2K/tblite calculation. "// &
    1412              :                           "The section is active when present; no additional enable keyword is needed. "// &
    1413              :                           "CP2K aborts for fully three-dimensional periodic cells and prints a warning for one- or "// &
    1414              :                           "two-dimensional periodic cells because native tblite's implicit-solvent models are mainly "// &
    1415              :                           "molecular continuum-solvation diagnostics. "// &
    1416              :                           "MODEL selects the native tblite run solvation switch: ALPB maps to --alpb, GBSA to --gbsa, "// &
    1417              :                           "GBE to --gbe, GB to --gb, and CPCM to --cpcm. SOLVENT is the argument passed to that switch. "// &
    1418              :                           "For ALPB and GBSA it must be a named solvent with tblite parameters; for GBE, GB, and CPCM "// &
    1419              :                           "it can be either a named solvent or a dielectric constant written as a token such as 78.36. "// &
    1420              :                           "BORN_KERNEL maps to --born-kernel and applies only to ALPB, GBSA, GBE, and GB; AUTO leaves "// &
    1421              :                           "the native tblite model-dependent default untouched. SOLUTION_STATE maps to --solv-state "// &
    1422              :                           "and is only supported for the parametrized named solvent ALPB/GBSA models; GSOLV leaves "// &
    1423              :                           "the native tblite default untouched.", &
    1424        10502 :                           n_keywords=4, repeats=.FALSE.)
    1425              : 
    1426        10502 :       NULLIFY (keyword)
    1427              :       CALL keyword_create(keyword, __LOCATION__, name="MODEL", &
    1428              :                           description="Implicit-solvation model passed to native tblite run. ALPB selects the "// &
    1429              :                           "parametrized analytical linearized Poisson-Boltzmann model with CDS and solution-state "// &
    1430              :                           "shift support. GBSA selects the parametrized generalized Born surface-area model with CDS "// &
    1431              :                           "and solution-state shift support. GBE selects finite-epsilon generalized Born/ALPB "// &
    1432              :                           "electrostatics without the named-solvent CDS and shift terms. GB selects generalized Born "// &
    1433              :                           "electrostatics without the named-solvent CDS and shift terms. CPCM selects tblite's "// &
    1434              :                           "conductor-like polarizable continuum model.", &
    1435              :                           usage="MODEL (ALPB|GBSA|GBE|GB|CPCM)", &
    1436              :                           enum_c_vals=s2a("ALPB", "GBSA", "GBE", "GB", "CPCM"), &
    1437              :                           enum_i_vals=[tblite_cli_solvation_alpb, tblite_cli_solvation_gbsa, &
    1438              :                                        tblite_cli_solvation_gbe, tblite_cli_solvation_gb, &
    1439              :                                        tblite_cli_solvation_cpcm], &
    1440              :                           enum_desc=s2a("Use native tblite --alpb.", &
    1441              :                                         "Use native tblite --gbsa.", &
    1442              :                                         "Use native tblite --gbe.", &
    1443              :                                         "Use native tblite --gb.", &
    1444              :                                         "Use native tblite --cpcm."), &
    1445        10502 :                           default_i_val=tblite_cli_solvation_alpb)
    1446        10502 :       CALL section_add_keyword(section, keyword)
    1447        10502 :       CALL keyword_release(keyword)
    1448              : 
    1449              :       CALL keyword_create(keyword, __LOCATION__, name="SOLVENT", &
    1450              :                           description="Solvent argument passed to the selected native tblite solvation switch. "// &
    1451              :                           "For MODEL ALPB and MODEL GBSA this must be a named solvent supported by tblite's "// &
    1452              :                           "parametrized solvation data, for example water, acetone, methanol, thf, or toluene. "// &
    1453              :                           "For MODEL GBE, MODEL GB, and MODEL CPCM this can also be a dielectric constant, for "// &
    1454              :                           "example 78.36. Native tblite normalizes names by ignoring case, spaces, commas, and "// &
    1455              :                           "hyphens before lookup.", &
    1456        10502 :                           usage="SOLVENT water", n_var=1, type_of_var=char_t, default_c_val="")
    1457        10502 :       CALL section_add_keyword(section, keyword)
    1458        10502 :       CALL keyword_release(keyword)
    1459              : 
    1460              :       CALL keyword_create(keyword, __LOCATION__, name="BORN_KERNEL", &
    1461              :                           description="Born interaction kernel passed to native tblite as --born-kernel. AUTO leaves "// &
    1462              :                           "the native default untouched: tblite uses p16 for ALPB/GBE and still for GB/GBSA. P16 "// &
    1463              :                           "selects the Lange p16 kernel, while STILL selects the classical Still kernel. This keyword "// &
    1464              :                           "is not valid with MODEL CPCM because CPCM does not use the Born-kernel machinery.", &
    1465              :                           usage="BORN_KERNEL (AUTO|P16|STILL)", &
    1466              :                           enum_c_vals=s2a("AUTO", "P16", "STILL"), &
    1467              :                           enum_i_vals=[tblite_cli_born_kernel_auto, tblite_cli_born_kernel_p16, &
    1468              :                                        tblite_cli_born_kernel_still], &
    1469              :                           enum_desc=s2a("Use tblite's model-dependent default kernel.", &
    1470              :                                         "Use the Lange p16 Born kernel.", &
    1471              :                                         "Use the classical Still Born kernel."), &
    1472        10502 :                           default_i_val=tblite_cli_born_kernel_auto)
    1473        10502 :       CALL section_add_keyword(section, keyword)
    1474        10502 :       CALL keyword_release(keyword)
    1475              : 
    1476              :       CALL keyword_create(keyword, __LOCATION__, name="SOLUTION_STATE", &
    1477              :                           description="Solution-state convention passed to native tblite as --solv-state. GSOLV is "// &
    1478              :                           "the default solvation free-energy convention. BAR1MOL applies the 1 bar ideal-gas to "// &
    1479              :                           "1 mol/L liquid-solution shift. REFERENCE requests tblite's reference-state convention. "// &
    1480              :                           "Native tblite supports non-default solution-state shifts only for named parametrized "// &
    1481              :                           "ALPB/GBSA solvents, not for GBE, GB, or CPCM.", &
    1482              :                           usage="SOLUTION_STATE (GSOLV|BAR1MOL|REFERENCE)", &
    1483              :                           enum_c_vals=s2a("GSOLV", "BAR1MOL", "REFERENCE"), &
    1484              :                           enum_i_vals=[tblite_cli_solution_state_gsolv, tblite_cli_solution_state_bar1mol, &
    1485              :                                        tblite_cli_solution_state_reference], &
    1486              :                           enum_desc=s2a("Use tblite's default solvation free-energy convention.", &
    1487              :                                         "Apply the 1 bar ideal-gas to 1 mol/L solution shift.", &
    1488              :                                         "Use tblite's reference-state convention."), &
    1489        10502 :                           default_i_val=tblite_cli_solution_state_gsolv)
    1490        10502 :       CALL section_add_keyword(section, keyword)
    1491        10502 :       CALL keyword_release(keyword)
    1492              : 
    1493        10502 :    END SUBROUTINE create_xtb_reference_cli_solvation_section
    1494              : 
    1495              : END MODULE input_cp2k_tb
        

Generated by: LCOV version 2.0-1