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 : Quan2026
18 : USE cp_units, ONLY: cp_unit_to_cp2k
19 : USE input_constants, ONLY: rskp_backend_fft, &
20 : rskp_backend_gemm
21 : USE input_keyword_types, ONLY: keyword_create, &
22 : keyword_release, &
23 : keyword_type
24 : USE input_section_types, ONLY: section_add_keyword, &
25 : section_create, &
26 : section_type
27 : USE input_val_types, ONLY: char_t, &
28 : enum_t, &
29 : integer_t, &
30 : real_t
31 : USE kinds, ONLY: default_path_length, &
32 : dp
33 : USE string_utilities, ONLY: newline, &
34 : s2a
35 : #include "./base/base_uses.f90"
36 :
37 : IMPLICIT NONE
38 : PRIVATE
39 :
40 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'input_cp2k_kpoints'
41 :
42 : INTEGER, PARAMETER :: use_real_wfn = 101, &
43 : use_complex_wfn = 100, &
44 : use_k290_kpoint_symmetry = 200, &
45 : use_spglib_kpoint_symmetry = 201, &
46 : use_k290_kpoint_backend = 300, &
47 : use_spglib_kpoint_backend = 301
48 :
49 : PUBLIC :: create_kpoints_section
50 : PUBLIC :: create_kpoint_set_section
51 : PUBLIC :: create_unfolding_section
52 : PUBLIC :: use_real_wfn, use_complex_wfn
53 : PUBLIC :: use_k290_kpoint_symmetry, use_spglib_kpoint_symmetry
54 : PUBLIC :: use_k290_kpoint_backend, use_spglib_kpoint_backend
55 :
56 : CONTAINS
57 :
58 : ! **************************************************************************************************
59 : !> \brief Creates the Kpoints section
60 : !> SECTION: &kpoint... &end
61 : !> SCHEME [None, Gamma, Monkhorst-Pack, MacDonald, General]
62 : !> { nx ny nz }
63 : !> { nx ny nz sx sy sz }
64 : !> KPOINT x1 y1 z1 w1
65 : !> SYMMETRY [on, off]
66 : !> WAVEFUNCTION [real, complex]
67 : !> FULL_GRID [on, off]
68 : !> RSKP_TRANSFORM [gemm, fft]
69 : !> INVERSION_SYMMETRY_ONLY [on, off]
70 : !> DEBUG_FULL_KPOINT_SYMMETRY [on, off]
71 : !> SYMMETRY_BACKEND [K290, SPGLIB]
72 : !> SYMMETRY_REDUCTION_METHOD [K290, SPGLIB]
73 : !> VERBOSE [on, off]
74 : !> EPS_SYMMETRY value
75 : !> PARALLEL_GROUP_SIZE [-1,0,n]
76 : !>
77 : !> \param section the section to create
78 : !> \author JGH
79 : ! **************************************************************************************************
80 4497 : SUBROUTINE create_kpoints_section(section)
81 : TYPE(section_type), POINTER :: section
82 :
83 : TYPE(keyword_type), POINTER :: keyword
84 :
85 4497 : CPASSERT(.NOT. ASSOCIATED(section))
86 : CALL section_create(section, __LOCATION__, name="KPOINTS", &
87 : description="Controls Brillouin-zone sampling with k-points.", &
88 4497 : n_keywords=1, n_subsections=0, repeats=.FALSE.)
89 :
90 4497 : NULLIFY (keyword)
91 : CALL keyword_create(keyword, __LOCATION__, name="SCHEME", &
92 : description="K-point generation scheme. Available options are:"//newline// &
93 : "- `NONE`"//newline// &
94 : "- `GAMMA`"//newline// &
95 : "- `MONKHORST-PACK`"//newline// &
96 : "- `MACDONALD`"//newline// &
97 : "- `GENERAL`"//newline// &
98 : newline// &
99 : "For `MONKHORST-PACK` the number of k points in all 3 dimensions has to"// &
100 : " be supplied along with the keyword. For `MACDONALD` also the list of shifts."// &
101 : " E.g. `MONKHORST-PACK 12 12 8`, `MACDONALD 4 4 4 0.25 0.25 0.25`."// &
102 : " `GENERAL` uses explicitly listed k-points. If symmetry reduction is requested,"// &
103 : " the explicit set must be equally weighted and closed under the selected operations.", &
104 : usage="SCHEME {KPMETHOD} {integer} {integer} ..", &
105 : citations=[Monkhorst1976, MacDonald1978], &
106 13491 : n_var=-1, type_of_var=char_t)
107 4497 : CALL section_add_keyword(section, keyword)
108 4497 : CALL keyword_release(keyword)
109 :
110 : CALL keyword_create(keyword, __LOCATION__, name="GAMMA_CENTERED", &
111 : description="Generate a gamma-centered variant of the "// &
112 : "Monkhorst-Pack or MacDonald mesh. This shifts the original mesh so "// &
113 : "it can include the Gamma point, and makes sense only when an "// &
114 : "even number of subdivisions is used. For MacDonald meshes, the "// &
115 : "explicit shift is applied after the gamma-centering shift.", &
116 : usage="GAMMA_CENTERED <LOGICAL>", &
117 4497 : default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
118 4497 : CALL section_add_keyword(section, keyword)
119 4497 : CALL keyword_release(keyword)
120 :
121 : CALL keyword_create(keyword, __LOCATION__, name="KPOINT", &
122 : description="Specify kpoint coordinates and weight. ", &
123 : usage="KPOINT x y z w", repeats=.TRUE., &
124 4497 : n_var=4, type_of_var=real_t)
125 4497 : CALL section_add_keyword(section, keyword)
126 4497 : CALL keyword_release(keyword)
127 :
128 : CALL keyword_create(keyword, __LOCATION__, name="UNITS", &
129 : description="Special k-points are defined either in units"// &
130 : " of reciprocal lattice vectors or in Cartesian coordinates in units of 2Pi/len."// &
131 : " B_VECTOR: in multiples of the reciprocal lattice vectors (b)."// &
132 : " CART_ANGSTROM: In units of 2*Pi/Angstrom."// &
133 : " CART_BOHR: In units of 2*Pi/Bohr.", &
134 4497 : usage="UNITS <value>", type_of_var=char_t, default_c_val="B_VECTOR")
135 4497 : CALL section_add_keyword(section, keyword)
136 4497 : CALL keyword_release(keyword)
137 :
138 : CALL keyword_create(keyword, __LOCATION__, name="SYMMETRY", &
139 : description="Use symmetry to reduce the number of kpoints.", &
140 : usage="SYMMETRY <LOGICAL>", &
141 4497 : default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
142 4497 : CALL section_add_keyword(section, keyword)
143 4497 : CALL keyword_release(keyword)
144 :
145 : CALL keyword_create(keyword, __LOCATION__, name="FULL_GRID", &
146 : description="Use the full, non-symmetry-reduced k-point grid.", &
147 : usage="FULL_GRID <LOGICAL>", &
148 4497 : default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
149 4497 : CALL section_add_keyword(section, keyword)
150 4497 : CALL keyword_release(keyword)
151 :
152 : CALL keyword_create(keyword, __LOCATION__, name="RSKP_TRANSFORM", &
153 : description="Select the backend for bulk real-space/k-point transforms, including RI-RS GW. "// &
154 : "GEMM contracts captured image panels with Bloch phases in k-point batches. "// &
155 : "FFT uses supported regular grids; forward transforms also accept subsets. "// &
156 : "Inverse FFT accepts weighted regular-grid subsets "// &
157 : "without spatial rotations. Explicit single-point and property Fourier calls "// &
158 : "are independent of this setting. Unsupported forced FFT configurations abort.", &
159 : usage="RSKP_TRANSFORM GEMM", type_of_var=enum_t, &
160 : enum_c_vals=s2a("GEMM", "FFT"), &
161 : enum_i_vals=[rskp_backend_gemm, rskp_backend_fft], &
162 : enum_desc=s2a("Use sparse phase GEMMs.", "Use regular-grid lattice FFTs."), &
163 4497 : default_i_val=rskp_backend_gemm)
164 4497 : CALL section_add_keyword(section, keyword)
165 4497 : CALL keyword_release(keyword)
166 :
167 : CALL keyword_create(keyword, __LOCATION__, name="INVERSION_SYMMETRY_ONLY", &
168 : description="Restrict k-point reduction to k-space inversion "// &
169 : "(time-reversal) symmetry.", &
170 : usage="INVERSION_SYMMETRY_ONLY <LOGICAL>", &
171 4497 : default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
172 4497 : CALL section_add_keyword(section, keyword)
173 4497 : CALL keyword_release(keyword)
174 :
175 : CALL keyword_create(keyword, __LOCATION__, name="DEBUG_FULL_KPOINT_SYMMETRY", &
176 : description="Use full atomic k-point symmetry also for DEBUG finite-difference "// &
177 : "points. This is enabled by default so analytical and finite-difference "// &
178 : "evaluations use the symmetry of their current geometry. Disable it to restrict "// &
179 : "DEBUG finite-difference energies to inversion/time-reversal symmetry.", &
180 : usage="DEBUG_FULL_KPOINT_SYMMETRY <LOGICAL>", &
181 4497 : default_l_val=.TRUE., lone_keyword_l_val=.TRUE.)
182 4497 : CALL section_add_keyword(section, keyword)
183 4497 : CALL keyword_release(keyword)
184 :
185 : CALL keyword_create(keyword, __LOCATION__, name="SYMMETRY_BACKEND", &
186 : description="Select the backend used to provide and apply atomic "// &
187 : "k-point symmetry operations. K290 is the established default. "// &
188 : "SPGLIB uses the symmetry operations returned by SPGLIB, including "// &
189 : "their fractional translations. This applies to Monkhorst-Pack, MacDonald, and "// &
190 : "closed GENERAL k-point sets. If "// &
191 : "SYMMETRY_REDUCTION_METHOD is not specified, it follows the selected backend.", &
192 : usage="SYMMETRY_BACKEND K290", type_of_var=enum_t, &
193 : enum_c_vals=s2a("K290", "SPGLIB"), &
194 : enum_i_vals=[use_k290_kpoint_backend, use_spglib_kpoint_backend], &
195 : enum_desc=s2a("Use the existing K290 k-point symmetry backend.", &
196 : "Use SPGLIB symmetry operations as k-point symmetry backend."), &
197 4497 : default_i_val=use_k290_kpoint_backend)
198 4497 : CALL section_add_keyword(section, keyword)
199 4497 : CALL keyword_release(keyword)
200 :
201 : CALL keyword_create(keyword, __LOCATION__, name="SYMMETRY_REDUCTION_METHOD", &
202 : description="Select the method used to reduce Monkhorst-Pack and MacDonald "// &
203 : "k-point meshes when atomic symmetry is enabled. K290 is the established "// &
204 : "default. SPGLIB uses the symmetry operations returned by SPGLIB for the "// &
205 : "k-point reduction. GENERAL k-point lists can be reduced when the explicit set is "// &
206 : "equally weighted and closed under the selected operations. With "// &
207 : "SYMMETRY_BACKEND K290 this can be used as a comparison mode using K290 "// &
208 : "operations for SPGLIB-generated mappings.", &
209 : usage="SYMMETRY_REDUCTION_METHOD K290", type_of_var=enum_t, &
210 : enum_c_vals=s2a("K290", "SPGLIB"), &
211 : enum_i_vals=[use_k290_kpoint_symmetry, use_spglib_kpoint_symmetry], &
212 : enum_desc=s2a("Use the existing K290 k-point symmetry reduction method.", &
213 : "Use SPGLIB symmetry operations for k-point reduction."), &
214 4497 : default_i_val=use_k290_kpoint_symmetry)
215 4497 : CALL section_add_keyword(section, keyword)
216 4497 : CALL keyword_release(keyword)
217 :
218 : CALL keyword_create(keyword, __LOCATION__, name="VERBOSE", &
219 : description="Verbose output information.", &
220 : usage="VERBOSE <LOGICAL>", &
221 4497 : default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
222 4497 : CALL section_add_keyword(section, keyword)
223 4497 : CALL keyword_release(keyword)
224 :
225 : CALL keyword_create(keyword, __LOCATION__, name="EPS_SYMMETRY", variants=["EPS_GEO"], &
226 : description="Accuracy in k-point symmetry determination."//newline// &
227 : "K290 applies this value in lattice and fractional-coordinate checks. "// &
228 : "SPGLIB uses a Cartesian distance tolerance in bohr. The same numerical "// &
229 : "value is therefore not an equivalent geometric tolerance for both backends."//newline// &
230 : "EPS_GEO is accepted as an alias.", &
231 : usage="EPS_SYMMETRY <real>", &
232 8994 : default_r_val=1.0e-6_dp)
233 4497 : CALL section_add_keyword(section, keyword)
234 4497 : CALL keyword_release(keyword)
235 :
236 : CALL keyword_create(keyword, __LOCATION__, name="PARALLEL_GROUP_SIZE", &
237 : description="Number of MPI processes to be used for a single k-point."// &
238 : " This number must divide the total number of processes."// &
239 : " The number of groups must not exceed the number of kpoints."// &
240 : " Kpoints are distributed as evenly as possible among the groups."// &
241 : " Value=-1 (smallest possible number of processes per group, satisfying the constraints)."// &
242 : " Value=0 (all processes)."// &
243 : " Value=n (exactly n processes).", &
244 : usage="PARALLEL_GROUP_SIZE <integer>", &
245 4497 : default_i_val=-1)
246 4497 : CALL section_add_keyword(section, keyword)
247 4497 : CALL keyword_release(keyword)
248 :
249 : CALL keyword_create(keyword, __LOCATION__, name="WAVEFUNCTIONS", &
250 : description="Select whether real or complex wavefunctions should be used "// &
251 : "when allowed by the k-point set. REAL wavefunctions can only represent "// &
252 : "Gamma or special k-points and symmetry operations with real Bloch phases. "// &
253 : "Use COMPLEX for general atomic k-point symmetries with nontrivial phases.", &
254 : usage="WAVEFUNCTIONS REAL", &
255 : default_i_val=use_complex_wfn, &
256 : enum_c_vals=s2a("REAL", "COMPLEX"), &
257 : enum_desc=s2a("Use real wavefunctions (if possible by kpoints specified).", &
258 : "Use complex wavefunctions (default)."), &
259 4497 : enum_i_vals=[use_real_wfn, use_complex_wfn])
260 4497 : CALL section_add_keyword(section, keyword)
261 4497 : CALL keyword_release(keyword)
262 :
263 4497 : END SUBROUTINE create_kpoints_section
264 :
265 : ! **************************************************************************************************
266 : !> \brief ...
267 : !> \param section ...
268 : !> \param section_name ...
269 : !> \author JGH
270 : ! **************************************************************************************************
271 17909 : SUBROUTINE create_kpoint_set_section(section, section_name)
272 : TYPE(section_type), POINTER :: section
273 : CHARACTER(LEN=*), OPTIONAL :: section_name
274 :
275 : CHARACTER(len=default_path_length) :: my_section_name
276 : TYPE(keyword_type), POINTER :: keyword
277 :
278 17909 : IF (PRESENT(section_name)) THEN
279 1480 : my_section_name = section_name
280 : ELSE
281 16429 : my_section_name = "KPOINT_SET"
282 : END IF
283 :
284 17909 : CPASSERT(.NOT. ASSOCIATED(section))
285 : CALL section_create(section, __LOCATION__, name=my_section_name, &
286 : description="Specifies a k-point line to be calculated.", &
287 17909 : n_keywords=0, n_subsections=0, repeats=.TRUE.)
288 : ! keywords
289 17909 : NULLIFY (keyword)
290 : CALL keyword_create(keyword, __LOCATION__, name="SPECIAL_POINT", &
291 : description="Name and coordinates of a special k-point", &
292 17909 : usage="SPECIAL_POINT GAMMA 0.0 0.0 0.0", n_var=-1, type_of_var=char_t, repeats=.TRUE.)
293 17909 : CALL section_add_keyword(section, keyword)
294 17909 : CALL keyword_release(keyword)
295 : !
296 : CALL keyword_create(keyword, __LOCATION__, name="NPOINTS", &
297 : description="Number of k-points along the line.", &
298 17909 : default_i_val=0)
299 17909 : CALL section_add_keyword(section, keyword)
300 17909 : CALL keyword_release(keyword)
301 : !
302 : CALL keyword_create(keyword, __LOCATION__, name="UNITS", &
303 : description="Special k-points are defined either in units"// &
304 : " of reciprocal lattice vectors or in Cartesian coordinates in units of 2Pi/len."// &
305 : " B_VECTOR: in multiples of the reciprocal lattice vectors (b)."// &
306 : " CART_ANGSTROM: In units of 2*Pi/Angstrom."// &
307 : " CART_BOHR: In units of 2*Pi/Bohr.", &
308 17909 : usage="UNITS <value>", type_of_var=char_t, default_c_val="B_VECTOR")
309 17909 : CALL section_add_keyword(section, keyword)
310 17909 : CALL keyword_release(keyword)
311 :
312 17909 : END SUBROUTINE create_kpoint_set_section
313 :
314 : ! **************************************************************************************************
315 : !> \brief Unfolding subsection of &BAND_STRUCTURE: projection of supercell bands onto a
316 : !> primitive-cell k-path (Quan et al., PRB 113, 085112 (2026))
317 : !> \param section ...
318 : ! **************************************************************************************************
319 1499 : SUBROUTINE create_unfolding_section(section)
320 : TYPE(section_type), POINTER :: section
321 :
322 : TYPE(keyword_type), POINTER :: keyword
323 :
324 1499 : CPASSERT(.NOT. ASSOCIATED(section))
325 : CALL section_create(section, __LOCATION__, name="UNFOLDING", &
326 : description="Unfold the supercell band structure onto a primitive"// &
327 : " cell. When this section is enabled, SPECIAL_POINTs give"// &
328 : " primitive-cell k coordinates. CP2K diagonalizes the unique folded"// &
329 : " supercell K-points and writes the total spectral weight in column 4"// &
330 : " of the band structure file (followed by per-group weights when"// &
331 : " multiple ATOMS groups are defined).", &
332 : n_keywords=0, n_subsections=0, repeats=.FALSE., &
333 2998 : citations=[Quan2026])
334 1499 : NULLIFY (keyword)
335 : CALL keyword_create(keyword, __LOCATION__, name="TRANSFORMATION_MATRIX", &
336 : description="Integer $3 \times 3$ matrix $\mathbf{M}$ relating the"// &
337 : " supercell vectors $\mathbf{A}_1, \mathbf{A}_2, \mathbf{A}_3$ in"// &
338 : " [CELL](#CP2K_INPUT.FORCE_EVAL.SUBSYS.CELL) (after"// &
339 : " MULTIPLE_UNIT_CELL, if any) to the target primitive-cell vectors"// &
340 : " $\mathbf{a}_1, \mathbf{a}_2, \mathbf{a}_3$:"// &
341 : " $[\mathbf{A}_1\ \mathbf{A}_2\ \mathbf{A}_3] ="// &
342 : " [\mathbf{a}_1\ \mathbf{a}_2\ \mathbf{a}_3]\,\mathbf{M}$, so"// &
343 : " column $j$ of $\mathbf{M}$ gives the expansion coefficients"// &
344 : " $\mathbf{A}_j = \sum_{i=1}^{3} M_{ij}\mathbf{a}_i$. Give the nine"// &
345 : " entries row by row."//newline//newline// &
346 : "Example: a hexagonal primitive cell"// &
347 : " ($\gamma = 120^\circ$) and its orthorhombic supercell"// &
348 : " $\mathbf{A}_1 = \mathbf{a}_1$,"// &
349 : " $\mathbf{A}_2 = \mathbf{a}_1 + 2\mathbf{a}_2$,"// &
350 : " $\mathbf{A}_3 = \mathbf{a}_3$ give"// &
351 : " $\mathbf{M} = \begin{bmatrix} 1 & 1 & 0 \\ 0 & 2 & 0"// &
352 : " \\ 0 & 0 & 1 \end{bmatrix}$ ($m = |\det\mathbf{M}| = 2$), entered"// &
353 : " as `1 1 0 0 2 0 0 0 1`. This column-vector convention matches"// &
354 : " VESTA and Phonopy, and is the transpose of row-vector conventions"// &
355 : " such as ASE and pymatgen. To verify $\mathbf{M}$, compare the"// &
356 : " primitive cell vectors printed in the `UNFOLD_BAND|` summary with"// &
357 : " the intended primitive cell; for a defect-free supercell the"// &
358 : " number of incomplete sets must be zero.", &
359 : usage="TRANSFORMATION_MATRIX 1 1 0 0 2 0 0 0 1", &
360 : type_of_var=integer_t, n_var=9, &
361 1499 : default_i_vals=[1, 0, 0, 0, 1, 0, 0, 0, 1])
362 1499 : CALL section_add_keyword(section, keyword)
363 1499 : CALL keyword_release(keyword)
364 : CALL keyword_create(keyword, __LOCATION__, name="ATOMS", &
365 : description="Select which supercell atoms are unfolded. Repeat the"// &
366 : " keyword to define disjoint atom groups; equivalent primitive-cell"// &
367 : " sites (see SYMM_TOL) are identified independently within each"// &
368 : " group."//newline//newline// &
369 : "- Absent: all atoms are unfolded together as a single group."//newline// &
370 : "- Given once: only the listed atoms are unfolded; unlisted atoms"// &
371 : " are excluded from the weights (e.g., a film on an incommensurate"// &
372 : " substrate)."//newline// &
373 : "- Given $G \ge 2$ times: each group is unfolded independently."// &
374 : " Column 4 holds the combined weight and columns 5 to $4+G$ hold"// &
375 : " the per-group weights (e.g., layer-resolved weights in a"// &
376 : " heterostructure). Atoms not listed in any group are excluded."// &
377 : " With $\mathbf{M} = \mathbf{I}$ this reduces to Loewdin-projected"// &
378 : " (fat) bands per group.", &
379 1499 : usage="ATOMS 1..24", n_var=-1, type_of_var=integer_t, repeats=.TRUE.)
380 1499 : CALL section_add_keyword(section, keyword)
381 1499 : CALL keyword_release(keyword)
382 : CALL keyword_create(keyword, __LOCATION__, name="SYMM_TOL", &
383 : description="Cartesian tolerance used to identify equivalent sites:"// &
384 : " sets of supercell atoms that are images of the same"// &
385 : " primitive-cell site under primitive lattice translations. Atoms"// &
386 : " are matched by element (with GHOST kinds treated as their base"// &
387 : " element), and equivalent atoms must share the same basis set. In"// &
388 : " an ideal supercell each set contains $m = |\det\mathbf{M}|$ atoms;"// &
389 : " a vacancy leaves an incomplete set with fewer members. The"// &
390 : " tolerance must be positive and smaller than half the smallest"// &
391 : " primitive-cell plane distance (checked at runtime), with a"// &
392 : " $0.5\,\mathrm{\AA}$ default suited to typical thermal"// &
393 : " displacements. Check the `UNFOLD_BAND|` summary in the output: if"// &
394 : " large relaxations split equivalent atoms into unexpected"// &
395 : " incomplete sets (leaving uncancelled folded bands), increase"// &
396 : " SYMM_TOL; if nearby inequivalent sites trigger an"// &
397 : " assignment-conflict or ambiguity abort, decrease SYMM_TOL or"// &
398 : " separate them with ATOMS.", &
399 : usage="SYMM_TOL 0.5", unit_str="angstrom", &
400 1499 : default_r_val=cp_unit_to_cp2k(0.5_dp, "angstrom"))
401 1499 : CALL section_add_keyword(section, keyword)
402 1499 : CALL keyword_release(keyword)
403 :
404 1499 : END SUBROUTINE create_unfolding_section
405 :
406 : END MODULE input_cp2k_kpoints
|