LCOV - code coverage report
Current view: top level - src - input_cp2k_kpoints.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:358cae4) Lines: 100.0 % 64 64
Test Date: 2026-05-18 07:17:23 Functions: 100.0 % 2 2

            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 kpoints section of the input
      10              : !> \par History
      11              : !>      init [07.2014]
      12              : !> \author JGH
      13              : ! **************************************************************************************************
      14              : MODULE input_cp2k_kpoints
      15              :    USE bibliography,                    ONLY: MacDonald1978,&
      16              :                                               Monkhorst1976
      17              :    USE input_keyword_types,             ONLY: keyword_create,&
      18              :                                               keyword_release,&
      19              :                                               keyword_type
      20              :    USE input_section_types,             ONLY: section_add_keyword,&
      21              :                                               section_create,&
      22              :                                               section_type
      23              :    USE input_val_types,                 ONLY: char_t,&
      24              :                                               enum_t,&
      25              :                                               real_t
      26              :    USE kinds,                           ONLY: default_path_length,&
      27              :                                               dp
      28              :    USE string_utilities,                ONLY: newline,&
      29              :                                               s2a
      30              : #include "./base/base_uses.f90"
      31              : 
      32              :    IMPLICIT NONE
      33              :    PRIVATE
      34              : 
      35              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'input_cp2k_kpoints'
      36              : 
      37              :    INTEGER, PARAMETER                      :: use_real_wfn = 101, &
      38              :                                               use_complex_wfn = 100, &
      39              :                                               use_k290_kpoint_symmetry = 200, &
      40              :                                               use_spglib_kpoint_symmetry = 201, &
      41              :                                               use_k290_kpoint_backend = 300, &
      42              :                                               use_spglib_kpoint_backend = 301
      43              : 
      44              :    PUBLIC :: create_kpoints_section
      45              :    PUBLIC :: create_kpoint_set_section
      46              :    PUBLIC :: use_real_wfn, use_complex_wfn
      47              :    PUBLIC :: use_k290_kpoint_symmetry, use_spglib_kpoint_symmetry
      48              :    PUBLIC :: use_k290_kpoint_backend, use_spglib_kpoint_backend
      49              : 
      50              : CONTAINS
      51              : 
      52              : ! **************************************************************************************************
      53              : !> \brief Creates the Kpoints section
      54              : !>  SECTION: &kpoint... &end
      55              : !>      SCHEME [None, Gamma, Monkhorst-Pack, MacDonald, General]
      56              : !>        { nx ny nz }
      57              : !>        { nx ny nz  sx sy sz }
      58              : !>      KPOINT           x1 y1 z1 w1
      59              : !>      SYMMETRY         [on, off]
      60              : !>      WAVEFUNCTION     [real, complex]
      61              : !>      FULL_GRID        [on, off]
      62              : !>      INVERSION_SYMMETRY_ONLY [on, off]
      63              : !>      DEBUG_FULL_KPOINT_SYMMETRY [on, off]
      64              : !>      SYMMETRY_BACKEND [K290, SPGLIB]
      65              : !>      SYMMETRY_REDUCTION_METHOD [K290, SPGLIB]
      66              : !>      VERBOSE          [on, off]
      67              : !>      EPS_SYMMETRY     value
      68              : !>      PARALLEL_GROUP_SIZE   [-1,0,n]
      69              : !>
      70              : !> \param section the section to create
      71              : !> \author JGH
      72              : ! **************************************************************************************************
      73        30282 :    SUBROUTINE create_kpoints_section(section)
      74              :       TYPE(section_type), POINTER                        :: section
      75              : 
      76              :       TYPE(keyword_type), POINTER                        :: keyword
      77              : 
      78        30282 :       CPASSERT(.NOT. ASSOCIATED(section))
      79              :       CALL section_create(section, __LOCATION__, name="KPOINTS", &
      80              :                           description="Controls Brillouin-zone sampling with k-points.", &
      81        30282 :                           n_keywords=1, n_subsections=0, repeats=.FALSE.)
      82              : 
      83        30282 :       NULLIFY (keyword)
      84              :       CALL keyword_create(keyword, __LOCATION__, name="SCHEME", &
      85              :                           description="K-point generation scheme. Available options are:"//newline// &
      86              :                           "- `NONE`"//newline// &
      87              :                           "- `GAMMA`"//newline// &
      88              :                           "- `MONKHORST-PACK`"//newline// &
      89              :                           "- `MACDONALD`"//newline// &
      90              :                           "- `GENERAL`"//newline// &
      91              :                           newline// &
      92              :                           "For `MONKHORST-PACK` the number of k points in all 3 dimensions has to"// &
      93              :                           " be supplied along with the keyword. For `MACDONALD` also the list of shifts."// &
      94              :                           " E.g. `MONKHORST-PACK 12 12 8`, `MACDONALD 4 4 4 0.25 0.25 0.25`."// &
      95              :                           " `GENERAL` uses explicitly listed k-points. If symmetry reduction is requested,"// &
      96              :                           " the explicit set must be equally weighted and closed under the selected operations.", &
      97              :                           usage="SCHEME {KPMETHOD} {integer} {integer} ..", &
      98              :                           citations=[Monkhorst1976, MacDonald1978], &
      99        90846 :                           n_var=-1, type_of_var=char_t)
     100        30282 :       CALL section_add_keyword(section, keyword)
     101        30282 :       CALL keyword_release(keyword)
     102              : 
     103              :       CALL keyword_create(keyword, __LOCATION__, name="GAMMA_CENTERED", &
     104              :                           description="Generate a gamma-centered variant of the "// &
     105              :                           "Monkhorst-Pack or MacDonald mesh. This shifts the original mesh so "// &
     106              :                           "it can include the Gamma point, and makes sense only when an "// &
     107              :                           "even number of subdivisions is used. For MacDonald meshes, the "// &
     108              :                           "explicit shift is applied after the gamma-centering shift.", &
     109              :                           usage="GAMMA_CENTERED <LOGICAL>", &
     110        30282 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     111        30282 :       CALL section_add_keyword(section, keyword)
     112        30282 :       CALL keyword_release(keyword)
     113              : 
     114              :       CALL keyword_create(keyword, __LOCATION__, name="KPOINT", &
     115              :                           description="Specify kpoint coordinates and weight. ", &
     116              :                           usage="KPOINT x  y  z  w", repeats=.TRUE., &
     117        30282 :                           n_var=4, type_of_var=real_t)
     118        30282 :       CALL section_add_keyword(section, keyword)
     119        30282 :       CALL keyword_release(keyword)
     120              : 
     121              :       CALL keyword_create(keyword, __LOCATION__, name="UNITS", &
     122              :                           description="Special k-points are defined either in units"// &
     123              :                           " of reciprocal lattice vectors or in Cartesian coordinates in units of 2Pi/len."// &
     124              :                           " B_VECTOR: in multiples of the reciprocal lattice vectors (b)."// &
     125              :                           " CART_ANGSTROM: In units of 2*Pi/Angstrom."// &
     126              :                           " CART_BOHR: In units of 2*Pi/Bohr.", &
     127        30282 :                           usage="UNITS <value>", type_of_var=char_t, default_c_val="B_VECTOR")
     128        30282 :       CALL section_add_keyword(section, keyword)
     129        30282 :       CALL keyword_release(keyword)
     130              : 
     131              :       CALL keyword_create(keyword, __LOCATION__, name="SYMMETRY", &
     132              :                           description="Use symmetry to reduce the number of kpoints.", &
     133              :                           usage="SYMMETRY <LOGICAL>", &
     134        30282 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     135        30282 :       CALL section_add_keyword(section, keyword)
     136        30282 :       CALL keyword_release(keyword)
     137              : 
     138              :       CALL keyword_create(keyword, __LOCATION__, name="FULL_GRID", &
     139              :                           description="Use the full, non-symmetry-reduced k-point grid.", &
     140              :                           usage="FULL_GRID <LOGICAL>", &
     141        30282 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     142        30282 :       CALL section_add_keyword(section, keyword)
     143        30282 :       CALL keyword_release(keyword)
     144              : 
     145              :       CALL keyword_create(keyword, __LOCATION__, name="INVERSION_SYMMETRY_ONLY", &
     146              :                           description="Restrict k-point reduction to k-space inversion "// &
     147              :                           "(time-reversal) symmetry.", &
     148              :                           usage="INVERSION_SYMMETRY_ONLY <LOGICAL>", &
     149        30282 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     150        30282 :       CALL section_add_keyword(section, keyword)
     151        30282 :       CALL keyword_release(keyword)
     152              : 
     153              :       CALL keyword_create(keyword, __LOCATION__, name="DEBUG_FULL_KPOINT_SYMMETRY", &
     154              :                           description="Use full atomic k-point symmetry also for DEBUG finite-difference "// &
     155              :                           "points. This is an expert option: the default keeps finite-difference energies "// &
     156              :                           "on inversion/time-reversal symmetry to avoid comparing slightly different "// &
     157              :                           "irreducible k-point sets.", &
     158              :                           usage="DEBUG_FULL_KPOINT_SYMMETRY <LOGICAL>", &
     159        30282 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     160        30282 :       CALL section_add_keyword(section, keyword)
     161        30282 :       CALL keyword_release(keyword)
     162              : 
     163              :       CALL keyword_create(keyword, __LOCATION__, name="SYMMETRY_BACKEND", &
     164              :                           description="Select the backend used to provide and apply atomic "// &
     165              :                           "k-point symmetry operations. K290 is the established default. "// &
     166              :                           "SPGLIB uses the symmetry operations returned by SPGLIB, including "// &
     167              :                           "their fractional translations. This applies to Monkhorst-Pack, MacDonald, and "// &
     168              :                           "closed GENERAL k-point sets. If "// &
     169              :                           "SYMMETRY_REDUCTION_METHOD is not specified, it follows the selected backend.", &
     170              :                           usage="SYMMETRY_BACKEND K290", type_of_var=enum_t, &
     171              :                           enum_c_vals=s2a("K290", "SPGLIB"), &
     172              :                           enum_i_vals=[use_k290_kpoint_backend, use_spglib_kpoint_backend], &
     173              :                           enum_desc=s2a("Use the existing K290 k-point symmetry backend.", &
     174              :                                         "Use SPGLIB symmetry operations as k-point symmetry backend."), &
     175        30282 :                           default_i_val=use_k290_kpoint_backend)
     176        30282 :       CALL section_add_keyword(section, keyword)
     177        30282 :       CALL keyword_release(keyword)
     178              : 
     179              :       CALL keyword_create(keyword, __LOCATION__, name="SYMMETRY_REDUCTION_METHOD", &
     180              :                           description="Select the method used to reduce Monkhorst-Pack and MacDonald "// &
     181              :                           "k-point meshes when atomic symmetry is enabled. K290 is the established "// &
     182              :                           "default. SPGLIB uses the symmetry operations returned by SPGLIB for the "// &
     183              :                           "k-point reduction. GENERAL k-point lists can be reduced when the explicit set is "// &
     184              :                           "equally weighted and closed under the selected operations. With "// &
     185              :                           "SYMMETRY_BACKEND K290 this can be used as a comparison mode using K290 "// &
     186              :                           "operations for SPGLIB-generated mappings.", &
     187              :                           usage="SYMMETRY_REDUCTION_METHOD K290", type_of_var=enum_t, &
     188              :                           enum_c_vals=s2a("K290", "SPGLIB"), &
     189              :                           enum_i_vals=[use_k290_kpoint_symmetry, use_spglib_kpoint_symmetry], &
     190              :                           enum_desc=s2a("Use the existing K290 k-point symmetry reduction method.", &
     191              :                                         "Use SPGLIB symmetry operations for k-point reduction."), &
     192        30282 :                           default_i_val=use_k290_kpoint_symmetry)
     193        30282 :       CALL section_add_keyword(section, keyword)
     194        30282 :       CALL keyword_release(keyword)
     195              : 
     196              :       CALL keyword_create(keyword, __LOCATION__, name="VERBOSE", &
     197              :                           description="Verbose output information.", &
     198              :                           usage="VERBOSE <LOGICAL>", &
     199        30282 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     200        30282 :       CALL section_add_keyword(section, keyword)
     201        30282 :       CALL keyword_release(keyword)
     202              : 
     203              :       CALL keyword_create(keyword, __LOCATION__, name="EPS_SYMMETRY", variants=["EPS_GEO"], &
     204              :                           description="Accuracy in k-point symmetry determination."//newline// &
     205              :                           "EPS_GEO is accepted as an alias.", &
     206              :                           usage="EPS_SYMMETRY <real>", &
     207        60564 :                           default_r_val=1.0e-6_dp)
     208        30282 :       CALL section_add_keyword(section, keyword)
     209        30282 :       CALL keyword_release(keyword)
     210              : 
     211              :       CALL keyword_create(keyword, __LOCATION__, name="PARALLEL_GROUP_SIZE", &
     212              :                           description="Number of MPI processes to be used for a single k-point."// &
     213              :                           " This number must divide the total number of processes."// &
     214              :                           " The number of groups must divide the total number of kpoints."// &
     215              :                           " Value=-1 (smallest possible number of processes per group, satisfying the constraints)."// &
     216              :                           " Value=0 (all processes)."// &
     217              :                           " Value=n (exactly n processes).", &
     218              :                           usage="PARALLEL_GROUP_SIZE <integer>", &
     219        30282 :                           default_i_val=-1)
     220        30282 :       CALL section_add_keyword(section, keyword)
     221        30282 :       CALL keyword_release(keyword)
     222              : 
     223              :       CALL keyword_create(keyword, __LOCATION__, name="WAVEFUNCTIONS", &
     224              :                           description="Select whether real or complex wavefunctions should be used "// &
     225              :                           "when allowed by the k-point set. REAL wavefunctions can only represent "// &
     226              :                           "Gamma or special k-points and symmetry operations with real Bloch phases. "// &
     227              :                           "Use COMPLEX for general atomic k-point symmetries with nontrivial phases.", &
     228              :                           usage="WAVEFUNCTIONS REAL", &
     229              :                           default_i_val=use_complex_wfn, &
     230              :                           enum_c_vals=s2a("REAL", "COMPLEX"), &
     231              :                           enum_desc=s2a("Use real wavefunctions (if possible by kpoints specified).", &
     232              :                                         "Use complex wavefunctions (default)."), &
     233        30282 :                           enum_i_vals=[use_real_wfn, use_complex_wfn])
     234        30282 :       CALL section_add_keyword(section, keyword)
     235        30282 :       CALL keyword_release(keyword)
     236              : 
     237        30282 :    END SUBROUTINE create_kpoints_section
     238              : 
     239              : ! **************************************************************************************************
     240              : !> \brief ...
     241              : !> \param section ...
     242              : !> \param section_name ...
     243              : !> \author JGH
     244              : ! **************************************************************************************************
     245       121048 :    SUBROUTINE create_kpoint_set_section(section, section_name)
     246              :       TYPE(section_type), POINTER                        :: section
     247              :       CHARACTER(LEN=*), OPTIONAL                         :: section_name
     248              : 
     249              :       CHARACTER(len=default_path_length)                 :: my_section_name
     250              :       TYPE(keyword_type), POINTER                        :: keyword
     251              : 
     252       121048 :       IF (PRESENT(section_name)) THEN
     253        10078 :          my_section_name = section_name
     254              :       ELSE
     255       110970 :          my_section_name = "KPOINT_SET"
     256              :       END IF
     257              : 
     258       121048 :       CPASSERT(.NOT. ASSOCIATED(section))
     259              :       CALL section_create(section, __LOCATION__, name=my_section_name, &
     260              :                           description="Specifies a k-point line to be calculated.", &
     261       121048 :                           n_keywords=0, n_subsections=0, repeats=.TRUE.)
     262              :       ! keywords
     263       121048 :       NULLIFY (keyword)
     264              :       CALL keyword_create(keyword, __LOCATION__, name="SPECIAL_POINT", &
     265              :                           description="Name and coordinates of a special k-point", &
     266       121048 :                           usage="SPECIAL_POINT GAMMA 0.0 0.0 0.0", n_var=-1, type_of_var=char_t, repeats=.TRUE.)
     267       121048 :       CALL section_add_keyword(section, keyword)
     268       121048 :       CALL keyword_release(keyword)
     269              :       !
     270              :       CALL keyword_create(keyword, __LOCATION__, name="NPOINTS", &
     271              :                           description="Number of k-points along the line.", &
     272       121048 :                           default_i_val=0)
     273       121048 :       CALL section_add_keyword(section, keyword)
     274       121048 :       CALL keyword_release(keyword)
     275              :       !
     276              :       CALL keyword_create(keyword, __LOCATION__, name="UNITS", &
     277              :                           description="Special k-points are defined either in units"// &
     278              :                           " of reciprocal lattice vectors or in Cartesian coordinates in units of 2Pi/len."// &
     279              :                           " B_VECTOR: in multiples of the reciprocal lattice vectors (b)."// &
     280              :                           " CART_ANGSTROM: In units of 2*Pi/Angstrom."// &
     281              :                           " CART_BOHR: In units of 2*Pi/Bohr.", &
     282       121048 :                           usage="UNITS <value>", type_of_var=char_t, default_c_val="B_VECTOR")
     283       121048 :       CALL section_add_keyword(section, keyword)
     284       121048 :       CALL keyword_release(keyword)
     285              : 
     286       121048 :    END SUBROUTINE create_kpoint_set_section
     287              : 
     288              : END MODULE input_cp2k_kpoints
        

Generated by: LCOV version 2.0-1