LCOV - code coverage report
Current view: top level - src - input_cp2k_harris.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:744416f) Lines: 100.0 % 50 50
Test Date: 2026-09-20 02:09:09 Functions: 100.0 % 1 1

            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 Harris input section
      10              : ! **************************************************************************************************
      11              : MODULE input_cp2k_harris
      12              :    USE input_constants,                 ONLY: hden_atomic,&
      13              :                                               hden_cube,&
      14              :                                               hden_cube_fit,&
      15              :                                               hfit_least_squares,&
      16              :                                               hfit_relative_entropy,&
      17              :                                               hfun_harris,&
      18              :                                               horb_default
      19              :    USE input_keyword_types,             ONLY: keyword_create,&
      20              :                                               keyword_release,&
      21              :                                               keyword_type
      22              :    USE input_section_types,             ONLY: section_add_keyword,&
      23              :                                               section_create,&
      24              :                                               section_type
      25              :    USE input_val_types,                 ONLY: char_t
      26              :    USE kinds,                           ONLY: dp
      27              :    USE physcon,                         ONLY: kelvin
      28              :    USE string_utilities,                ONLY: s2a
      29              : #include "./base/base_uses.f90"
      30              : 
      31              :    IMPLICIT NONE
      32              :    PRIVATE
      33              : 
      34              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'input_cp2k_harris'
      35              : 
      36              :    PUBLIC :: create_harris_section
      37              : 
      38              : CONTAINS
      39              : 
      40              : ! **************************************************************************************************
      41              : !> \brief creates the HARRIS_METHOD section
      42              : !> \param section ...
      43              : !> \author JGH
      44              : ! **************************************************************************************************
      45         1399 :    SUBROUTINE create_harris_section(section)
      46              :       TYPE(section_type), POINTER                        :: section
      47              : 
      48              :       TYPE(keyword_type), POINTER                        :: keyword
      49              : 
      50         1399 :       CPASSERT(.NOT. ASSOCIATED(section))
      51              : 
      52         1399 :       NULLIFY (keyword)
      53              :       CALL section_create(section, __LOCATION__, name="HARRIS_METHOD", &
      54              :                           description="Sets the various options for the Harris method", &
      55         1399 :                           n_keywords=15, n_subsections=0, repeats=.FALSE.)
      56              : 
      57              :       CALL keyword_create(keyword, __LOCATION__, name="_SECTION_PARAMETERS_", &
      58              :                           description="Controls the activation of the Harris method", &
      59              :                           usage="&HARRIS_METHOD T", &
      60              :                           default_l_val=.FALSE., &
      61         1399 :                           lone_keyword_l_val=.TRUE.)
      62         1399 :       CALL section_add_keyword(section, keyword)
      63         1399 :       CALL keyword_release(keyword)
      64              : 
      65              :       CALL keyword_create(keyword, __LOCATION__, name="ENERGY_FUNCTIONAL", &
      66              :                           description="Functional used in energy correction", &
      67              :                           usage="ENERGY_FUNCTIONAL HARRIS", &
      68              :                           default_i_val=hfun_harris, &
      69              :                           enum_c_vals=s2a("HARRIS"), &
      70              :                           enum_desc=s2a("Harris functional"), &
      71         1399 :                           enum_i_vals=[hfun_harris])
      72         1399 :       CALL section_add_keyword(section, keyword)
      73         1399 :       CALL keyword_release(keyword)
      74              : 
      75              :       CALL keyword_create(keyword, __LOCATION__, name="DENSITY_SOURCE", &
      76              :                           description="Method to create the input density", &
      77              :                           usage="DENSITY_SOURCE ATOMIC", &
      78              :                           default_i_val=hden_atomic, &
      79              :                           enum_c_vals=s2a("ATOMIC", "CUBE", "CUBE_FIT"), &
      80              :                           enum_desc=s2a("Atomic densities", &
      81              :                                         "Electron density read directly from a Gaussian cube file", &
      82              :                                         "Cube density fitted by a constrained AO density matrix. "// &
      83              :                                         "This dense reference method currently requires GPW, a "// &
      84              :                                         "spin-restricted calculation, and the Gamma point"), &
      85         1399 :                           enum_i_vals=[hden_atomic, hden_cube, hden_cube_fit])
      86         1399 :       CALL section_add_keyword(section, keyword)
      87         1399 :       CALL keyword_release(keyword)
      88              : 
      89              :       CALL keyword_create(keyword, __LOCATION__, name="FILE_DENSITY", &
      90              :                           description="Filename of the electron density in Gaussian cube format. "// &
      91              :                           "Used when DENSITY_SOURCE is CUBE or CUBE_FIT. The cube grid has to coincide with "// &
      92              :                           "the finest CP2K real-space grid.", &
      93              :                           usage="FILE_DENSITY <FILENAME>", &
      94         1399 :                           type_of_var=char_t, default_c_val="", n_var=1)
      95         1399 :       CALL section_add_keyword(section, keyword)
      96         1399 :       CALL keyword_release(keyword)
      97              : 
      98              :       CALL keyword_create(keyword, __LOCATION__, name="FIT_METHOD", &
      99              :                           description="Objective used to reconstruct an AO density matrix for CUBE_FIT. "// &
     100              :                           "RELATIVE_ENTROPY uses the frozen H[n_cube] Fermi matrix as a physical prior. "// &
     101              :                           "The current implementation is a dense cubic reference method.", &
     102              :                           usage="FIT_METHOD LEAST_SQUARES", &
     103              :                           default_i_val=hfit_least_squares, &
     104              :                           enum_c_vals=s2a("LEAST_SQUARES", "RELATIVE_ENTROPY"), &
     105              :                           enum_desc=s2a("Constrained least-squares density fit", &
     106              :                                         "Fermionic relative-entropy/Mermin reconstruction with H[n_cube] prior"), &
     107         1399 :                           enum_i_vals=[hfit_least_squares, hfit_relative_entropy])
     108         1399 :       CALL section_add_keyword(section, keyword)
     109         1399 :       CALL keyword_release(keyword)
     110              : 
     111              :       CALL keyword_create(keyword, __LOCATION__, name="FIT_MAX_ITER", &
     112              :                           description="Maximum number of projected-gradient iterations for CUBE_FIT.", &
     113         1399 :                           usage="FIT_MAX_ITER 50", default_i_val=50)
     114         1399 :       CALL section_add_keyword(section, keyword)
     115         1399 :       CALL keyword_release(keyword)
     116              : 
     117              :       CALL keyword_create(keyword, __LOCATION__, name="FIT_EPS", &
     118              :                           description="Target RMS error of the fitted density for CUBE_FIT.", &
     119         1399 :                           usage="FIT_EPS 1.0E-3", default_r_val=1.0E-3_dp)
     120         1399 :       CALL section_add_keyword(section, keyword)
     121         1399 :       CALL keyword_release(keyword)
     122              : 
     123              :       CALL keyword_create(keyword, __LOCATION__, name="FIT_STEP_SIZE", &
     124              :                           description="Initial spectral projected-gradient step size for CUBE_FIT.", &
     125         1399 :                           usage="FIT_STEP_SIZE 1.0", default_r_val=1.0_dp)
     126         1399 :       CALL section_add_keyword(section, keyword)
     127         1399 :       CALL keyword_release(keyword)
     128              : 
     129              :       CALL keyword_create(keyword, __LOCATION__, name="FIT_MAX_BACKTRACK", &
     130              :                           description="Maximum number of line-search reductions in each CUBE_FIT iteration.", &
     131         1399 :                           usage="FIT_MAX_BACKTRACK 20", default_i_val=20)
     132         1399 :       CALL section_add_keyword(section, keyword)
     133         1399 :       CALL keyword_release(keyword)
     134              : 
     135              :       CALL keyword_create(keyword, __LOCATION__, name="FIT_TEMPERATURE", &
     136              :                           description="Electronic temperature of the Fermi-matrix prior used by "// &
     137              :                           "FIT_METHOD RELATIVE_ENTROPY.", &
     138              :                           usage="FIT_TEMPERATURE [K] 300", &
     139         1399 :                           default_r_val=300.0_dp/kelvin, unit_str="K")
     140         1399 :       CALL section_add_keyword(section, keyword)
     141         1399 :       CALL keyword_release(keyword)
     142              : 
     143              :       CALL keyword_create(keyword, __LOCATION__, name="FIT_RELATIVE_ENTROPY_WEIGHT", &
     144              :                           description="Weight multiplying the dimensionless fermionic relative entropy "// &
     145              :                           "in the regularized CUBE_FIT objective.", &
     146         1399 :                           usage="FIT_RELATIVE_ENTROPY_WEIGHT 1.0E-3", default_r_val=1.0E-3_dp)
     147         1399 :       CALL section_add_keyword(section, keyword)
     148         1399 :       CALL keyword_release(keyword)
     149              : 
     150              :       CALL keyword_create(keyword, __LOCATION__, name="DIRECT_DENSITY_MATRIX_ENERGY", &
     151              :                           description="Evaluate the fitted AO density matrix directly, without a NONSCF "// &
     152              :                           "eigensolver. Requires DENSITY_SOURCE CUBE_FIT. CP2K reports both the "// &
     153              :                           "consistent trial-density-matrix energy and a Harris-like energy based on "// &
     154              :                           "the original cube density.", &
     155              :                           usage="DIRECT_DENSITY_MATRIX_ENERGY T", default_l_val=.FALSE., &
     156         1399 :                           lone_keyword_l_val=.TRUE.)
     157         1399 :       CALL section_add_keyword(section, keyword)
     158         1399 :       CALL keyword_release(keyword)
     159              : 
     160              :       CALL keyword_create(keyword, __LOCATION__, name="ORBITAL_BASIS", &
     161              :                           description="Specifies the type of basis to be used for the energy functional. ", &
     162              :                           default_i_val=horb_default, &
     163              :                           enum_c_vals=s2a("ATOMIC_KIND_BASIS"), &
     164              :                           enum_desc=s2a("Atomic kind orbital basis"), &
     165         1399 :                           enum_i_vals=[horb_default])
     166         1399 :       CALL section_add_keyword(section, keyword)
     167         1399 :       CALL keyword_release(keyword)
     168              : 
     169              :       CALL keyword_create(keyword, __LOCATION__, name="DEBUG_FORCES", &
     170              :                           description="Additional output to debug Harris method forces.", &
     171         1399 :                           usage="DEBUG_FORCES T", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     172         1399 :       CALL section_add_keyword(section, keyword)
     173         1399 :       CALL keyword_release(keyword)
     174              :       CALL keyword_create(keyword, __LOCATION__, name="DEBUG_STRESS", &
     175              :                           description="Additional output to debug Harris method stress.", &
     176         1399 :                           usage="DEBUG_STRESS T", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     177         1399 :       CALL section_add_keyword(section, keyword)
     178         1399 :       CALL keyword_release(keyword)
     179              : 
     180         1399 :    END SUBROUTINE create_harris_section
     181              : 
     182              : END MODULE input_cp2k_harris
        

Generated by: LCOV version 2.0-1