(git:08825b9)
Loading...
Searching...
No Matches
qs_spectral_localizer.F
Go to the documentation of this file.
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 Post-SCF finite-system spectral localizers and analytic AO position export.
10!> \author Thomas D. Kuehne, tkuehne@cp2k.org
11! **************************************************************************************************
13 USE bibliography, ONLY: dixon2023,&
14 doll2025,&
17 USE cell_types, ONLY: cell_type,&
24 USE cp_dbcsr_api, ONLY: dbcsr_create,&
34 USE cp_output_handling, ONLY: cp_p_file,&
38 USE ieee_arithmetic, ONLY: ieee_is_finite
44 USE kinds, ONLY: dp
45 USE mathconstants, ONLY: twopi
65#include "./base/base_uses.f90"
66
67 IMPLICIT NONE
68 PRIVATE
69 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_spectral_localizer'
70 PUBLIC :: qs_scf_post_localizer
71
72CONTAINS
73
74! **************************************************************************************************
75!> \brief Export finite AO positions and optionally evaluate localizers after SCF.
76!> \param qs_env Converged Quickstep environment
77! **************************************************************************************************
78 SUBROUTINE qs_scf_post_localizer(qs_env)
79 TYPE(qs_environment_type), POINTER :: qs_env
80
81 CHARACTER(len=*), PARAMETER :: routinen = 'qs_scf_post_localizer'
82 CHARACTER(len=1), PARAMETER :: axes(3) = ['X', 'Y', 'Z']
83 INTEGER, PARAMETER :: plane_periodicity(3) = [use_perd_xy, use_perd_xz, use_perd_yz]
84
85 COMPLEX(KIND=dp), ALLOCATABLE :: local_dense(:, :), metric_dense(:, :)
86 INTEGER :: after, axis, directions(3), flatten_handle, formulation, handle, ie, ik, &
87 invariant, ip, iw, max_ao, n, nao, ndim, nposition, output_unit, plane, poisson_periodic, &
88 spin_channel, status, topology
89 INTEGER, POINTER :: grid(:)
90 LOGICAL :: active, aii, do_kpoints, do_soc, explicit_scale, flatten, omit_headers, &
91 periodic_localizer, print_position, print_soc, time_reversal, torus
92 REAL(dp) :: build_energy, electronic_gap(2), eps_electronic_gap, eps_flattening, &
93 flatten_residuals(4), flatten_scale, local_point(3), physical_ratio
94 REAL(kind=dp) :: eps_gap, eps_metric, gap, &
95 matrix_tolerance, metric_ratio
96 REAL(kind=dp), POINTER :: energies(:), kappas(:), point(:)
97 TYPE(cell_type), POINTER :: cell
98 TYPE(cp_logger_type), POINTER :: logger
99 TYPE(dbcsr_p_type), POINTER :: cosines(:), image_matrices(:, :), &
100 matrix_ks(:), matrix_s(:), &
101 positions(:), soc_matrices(:, :)
102 TYPE(dft_control_type), POINTER :: dft_control
103 TYPE(localizer_matrix_type) :: localizer, metric, physical_h(1), &
104 physical_metric
105 TYPE(localizer_matrix_type), POINTER :: flat_hamiltonian
106 TYPE(mp_para_env_type), POINTER :: para_env
107 TYPE(neighbor_list_set_p_type), POINTER :: sab_orb(:)
108 TYPE(section_vals_type), POINTER :: input, section
109
110 CALL timeset(routinen, handle)
111 NULLIFY (input, section, cell, dft_control, para_env, sab_orb, matrix_ks, matrix_s, &
112 positions, soc_matrices, energies, kappas, point, cosines, flat_hamiltonian)
113 CALL get_qs_env(qs_env, input=input)
114 section => section_vals_get_subs_vals(input, 'PROPERTIES%SPECTRAL_LOCALIZER')
115 CALL section_vals_val_get(section, '_SECTION_PARAMETERS_', l_val=active)
116 logger => cp_get_default_logger()
117 output_unit = cp_logger_get_default_io_unit(logger)
118 print_position = btest(cp_print_key_should_output(logger%iter_info, input, &
119 'DFT%PRINT%AO_MATRICES/POSITION'), cp_p_file)
120 print_soc = btest(cp_print_key_should_output(logger%iter_info, input, &
121 'DFT%PRINT%AO_MATRICES/SOC'), cp_p_file)
122 IF (.NOT. active .AND. .NOT. print_position .AND. .NOT. print_soc) THEN
123 CALL timestop(handle)
124 RETURN
125 END IF
126 CALL get_qs_env(qs_env, cell=cell, do_kpoints=do_kpoints, dft_control=dft_control, &
127 matrix_s_kp=image_matrices, para_env=para_env, sab_orb=sab_orb)
128 matrix_s => image_matrices(:, 1)
129 CALL section_vals_val_get(section, 'FORMULATION', i_val=formulation)
130 periodic_localizer = active .AND. formulation == 1
131 IF ((print_position .OR. print_soc) .AND. (any(cell%perd /= 0) .OR. do_kpoints)) THEN
132 cpabort('AO_MATRICES POSITION/SOC requires finite systems without KPOINTS.')
133 END IF
134 IF (do_kpoints .AND. .NOT. periodic_localizer) THEN
135 cpabort('Explicit KPOINTS require FORMULATION PERIODIC for localizers.')
136 END IF
137 IF (.NOT. periodic_localizer .AND. any(cell%perd /= 0)) THEN
138 cpabort('AO position/localizer requires PERIODIC NONE without KPOINTS.')
139 END IF
140 CALL section_vals_val_get(section, 'DIMENSION', i_val=ndim)
141 IF (ndim /= 2 .AND. ndim /= 3) cpabort('SPECTRAL_LOCALIZER DIMENSION must be 2 or 3.')
142 CALL section_vals_val_get(section, 'PLANE', i_val=plane, explicit=explicit_scale)
143 IF (active .AND. ndim == 3 .AND. explicit_scale) THEN
144 cpabort('PLANE is only valid for DIMENSION 2.')
145 END IF
146 CALL section_vals_val_get(section, 'MP_GRID', i_vals=grid, explicit=explicit_scale)
147 IF (any(grid < 1)) cpabort('SPECTRAL_LOCALIZER MP_GRID must be positive.')
148 IF (.NOT. periodic_localizer .AND. explicit_scale) THEN
149 cpabort('SPECTRAL_LOCALIZER MP_GRID requires FORMULATION PERIODIC.')
150 END IF
151 IF (any(grid /= 1 .AND. cell%perd == 0)) THEN
152 cpabort('Localizer MP_GRID must be one in nonperiodic directions.')
153 END IF
154 torus = periodic_localizer .AND. (do_kpoints .OR. any(grid /= 1))
155 directions = [1, 2, 3]
156 IF (ndim == 2) THEN
157 SELECT CASE (plane)
158 CASE (1)
159 directions(:2) = [1, 2]
160 CASE (2)
161 directions(:2) = [1, 3]
162 CASE (3)
163 directions(:2) = [2, 3]
164 END SELECT
165 END IF
166 CALL section_vals_val_get(input, 'DFT%POISSON%PERIODIC', i_val=poisson_periodic)
167 IF (periodic_localizer) THEN
168 IF (ndim == 3) THEN
169 IF (any(cell%perd == 0) .OR. poisson_periodic /= use_perd_xyz) THEN
170 cpabort('PERIODIC DIMENSION 3 requires CELL and POISSON PERIODIC XYZ.')
171 END IF
172 ELSE
173 IF (count(cell%perd /= 0) /= 2 .OR. any(cell%perd(directions(:2)) == 0)) THEN
174 cpabort('PERIODIC localizer requires two periodic CELL axes matching PLANE.')
175 END IF
176 IF (poisson_periodic /= plane_periodicity(plane)) THEN
177 cpabort('PERIODIC localizer requires matching CELL and POISSON periodicity.')
178 END IF
179 END IF
180 CALL section_vals_val_get(section, 'KAPPA', explicit=explicit_scale)
181 IF (explicit_scale) cpabort('Use ETA, not KAPPA, for FORMULATION PERIODIC.')
182 ELSE IF (active .AND. poisson_periodic /= use_perd_none) THEN
183 cpabort('SPECTRAL_LOCALIZER requires POISSON PERIODIC NONE.')
184 END IF
185 IF (active .AND. .NOT. periodic_localizer) THEN
186 CALL section_vals_val_get(section, 'ETA', explicit=explicit_scale)
187 IF (explicit_scale) cpabort('Use KAPPA, not ETA, for FORMULATION FINITE.')
188 END IF
189 SELECT CASE (dft_control%qs_control%method_id)
191 CASE DEFAULT
192 cpabort('AO position/localizer currently supports GPW and GAPW only.')
193 END SELECT
194 IF (active) THEN
195 IF (.NOT. qs_env%scf_convergence_available .OR. .NOT. qs_env%scf_converged) THEN
196 cpabort('SPECTRAL_LOCALIZER requires a converged SCF calculation.')
197 END IF
199 IF (periodic_localizer) CALL cite_reference(doll2025)
200 CALL dbcsr_get_info(matrix_s(1)%matrix, nfullrows_total=nao)
201 CALL section_vals_val_get(section, 'MAX_AO', i_val=max_ao)
202 IF (max_ao < 1 .OR. nao > max_ao) THEN
203 cpabort('SPECTRAL_LOCALIZER exceeds the MAX_AO limit.')
204 END IF
205 DO axis = 1, 3
206 IF (grid(axis) > max_ao/nao) THEN
207 cpabort('SPECTRAL_LOCALIZER torus exceeds the MAX_AO limit.')
208 END IF
209 nao = nao*grid(axis)
210 END DO
211 END IF
212
213 IF (periodic_localizer .AND. .NOT. torus) THEN
214 CALL periodic_ao_moments(qs_env, directions(:ndim), cosines, positions)
215 ELSE IF (.NOT. periodic_localizer .AND. (active .OR. print_position)) THEN
216 CALL finite_ao_positions(qs_env, positions)
217 END IF
218 IF (print_position) THEN
219 CALL section_vals_val_get(input, 'DFT%PRINT%AO_MATRICES%NDIGITS', i_val=after)
220 CALL section_vals_val_get(input, 'DFT%PRINT%AO_MATRICES%OMIT_HEADERS', l_val=omit_headers)
221 after = min(max(after, 1), 16)
222 DO axis = 1, 3
223 iw = cp_print_key_unit_nr(logger, input, 'DFT%PRINT%AO_MATRICES/POSITION', &
224 extension='.Log', middle_name=axes(axis))
225 IF (iw > 0 .AND. .NOT. omit_headers) THEN
226 WRITE (iw, '(A)') 'AO POSITION '//axes(axis)//' [bohr]; coordinate origin; covariant AO matrix'
227 END IF
228 CALL cp_dbcsr_write_sparse_matrix(positions(axis)%matrix, 4, after, qs_env, para_env, &
229 output_unit=iw, omit_headers=omit_headers)
230 CALL cp_print_key_finished_output(iw, logger, input, 'DFT%PRINT%AO_MATRICES/POSITION')
231 END DO
232 END IF
233 IF (print_soc) THEN
234 CALL finite_ao_soc(qs_env, soc_matrices)
235 CALL section_vals_val_get(input, 'DFT%PRINT%AO_MATRICES%NDIGITS', i_val=after)
236 CALL section_vals_val_get(input, 'DFT%PRINT%AO_MATRICES%OMIT_HEADERS', l_val=omit_headers)
237 after = min(max(after, 1), 16)
238 DO axis = 1, 3
239 iw = cp_print_key_unit_nr(logger, input, 'DFT%PRINT%AO_MATRICES/SOC', &
240 extension='.Log', middle_name='SOC_'//axes(axis))
241 IF (iw > 0 .AND. .NOT. omit_headers) THEN
242 WRITE (iw, '(A)') 'AO SOC '//axes(axis)//' [hartree]; real antisymmetric component; multiply by i'
243 END IF
244 CALL cp_dbcsr_write_sparse_matrix(soc_matrices(axis, 1)%matrix, 4, after, qs_env, para_env, &
245 output_unit=iw, omit_headers=omit_headers)
246 CALL cp_print_key_finished_output(iw, logger, input, 'DFT%PRINT%AO_MATRICES/SOC')
247 END DO
248 END IF
249 IF (.NOT. active) THEN
250 IF (ASSOCIATED(positions)) CALL dbcsr_deallocate_matrix_set(positions)
251 IF (ASSOCIATED(soc_matrices)) CALL dbcsr_deallocate_matrix_set(soc_matrices)
252 CALL timestop(handle)
253 RETURN
254 END IF
255
256 CALL section_vals_val_get(section, 'INVARIANT', i_val=topology)
257 aii = topology == 1
258 IF (ndim == 3 .AND. .NOT. aii) cpabort('DIMENSION 3 requires INVARIANT Z2.')
259 IF (aii .AND. ndim == 2) CALL cite_reference(wong2026)
260 IF (ndim == 3) CALL cite_reference(loring2015)
261 CALL section_vals_val_get(section, 'SOC', l_val=do_soc)
262 CALL section_vals_val_get(section, 'TIME_REVERSAL', l_val=time_reversal)
263 CALL section_vals_val_get(section, 'SPIN_CHANNEL', i_val=spin_channel)
264 IF (aii .AND. (.NOT. do_soc .OR. .NOT. time_reversal)) THEN
265 cpabort('SPECTRAL_LOCALIZER INVARIANT Z2 requires SOC T and TIME_REVERSAL T.')
266 END IF
267 CALL get_qs_env(qs_env, matrix_ks_kp=image_matrices)
268 matrix_ks => image_matrices(:, 1)
269 IF (spin_channel < 1 .OR. spin_channel > SIZE(matrix_ks)) THEN
270 cpabort('SPECTRAL_LOCALIZER SPIN_CHANNEL is unavailable.')
271 END IF
272 IF (do_soc .AND. (SIZE(matrix_ks) /= 1 .OR. spin_channel /= 1)) THEN
273 cpabort('SPECTRAL_LOCALIZER SOC requires a restricted SCF and SPIN_CHANNEL 1.')
274 END IF
275 CALL section_vals_val_get(section, 'ENERGY', r_vals=energies)
276 IF (periodic_localizer) THEN
277 CALL section_vals_val_get(section, 'ETA', r_vals=kappas)
278 ELSE
279 CALL section_vals_val_get(section, 'KAPPA', r_vals=kappas)
280 END IF
281 IF (.NOT. all(ieee_is_finite(energies)) .OR. .NOT. all(ieee_is_finite(kappas))) THEN
282 cpabort('SPECTRAL_LOCALIZER requires finite ENERGY and KAPPA/ETA.')
283 END IF
284 IF (any(kappas <= 0.0_dp)) THEN
285 cpabort('SPECTRAL_LOCALIZER requires positive KAPPA/ETA.')
286 END IF
287 CALL section_vals_val_get(section, 'EPS_GAP', r_val=eps_gap)
288 CALL section_vals_val_get(section, 'EPS_METRIC', r_val=eps_metric)
289 CALL section_vals_val_get(section, 'MATRIX_TOLERANCE', r_val=matrix_tolerance)
290 IF (.NOT. all(ieee_is_finite([eps_gap, eps_metric, matrix_tolerance]))) THEN
291 cpabort('SPECTRAL_LOCALIZER requires finite numerical tolerances.')
292 END IF
293 IF (eps_gap < 0.0_dp .OR. eps_metric <= 0.0_dp .OR. eps_metric >= 1.0_dp .OR. &
294 matrix_tolerance <= 0.0_dp .OR. matrix_tolerance >= 1.0_dp) THEN
295 cpabort('SPECTRAL_LOCALIZER: invalid EPS_GAP, EPS_METRIC or MATRIX_TOLERANCE.')
296 END IF
297 CALL section_vals_val_get(section, 'SPECTRAL_FLATTENING', l_val=flatten)
298 CALL section_vals_val_get(section, 'FLATTENING_SCALE', r_val=flatten_scale)
299 CALL section_vals_val_get(section, 'EPS_FLATTENING', r_val=eps_flattening)
300 CALL section_vals_val_get(section, 'EPS_ELECTRONIC_GAP', r_val=eps_electronic_gap)
301 IF (flatten) THEN
302 IF (.NOT. all(ieee_is_finite([flatten_scale, eps_flattening, eps_electronic_gap]))) THEN
303 cpabort('SPECTRAL_FLATTENING requires finite scales and tolerances.')
304 END IF
305 IF (flatten_scale <= 0.0_dp .OR. eps_flattening <= 0.0_dp .OR. eps_flattening >= 1.0_dp .OR. &
306 eps_electronic_gap < 0.0_dp) THEN
307 cpabort('SPECTRAL_FLATTENING: invalid scale or tolerance.')
308 END IF
309 END IF
310 CALL section_vals_val_get(section, 'POSITION', n_rep_val=nposition)
311 n = nao
312 IF (do_soc) n = 2*nao
313 IF (torus) THEN
314 NULLIFY (matrix_ks, matrix_s)
315 CALL localizer_torus_operators(qs_env, grid, directions(:ndim), do_soc, matrix_ks, matrix_s, &
316 cosines, positions, soc_matrices)
317 ELSE IF (do_soc) THEN
318 IF (.NOT. ASSOCIATED(soc_matrices)) CALL finite_ao_soc(qs_env, soc_matrices)
319 END IF
320 IF (output_unit > 0) THEN
321 IF (periodic_localizer) THEN
322 WRITE (output_unit, '(/,T2,A)') 'SPECTRAL_LOCALIZER| Periodic Born-von-Karman DBCSR localizer'
323 WRITE (output_unit, '(T2,A,3I6)') 'SPECTRAL_LOCALIZER| Full analysis mesh: ', grid
324 WRITE (output_unit, '(T2,A)') 'SPECTRAL_LOCALIZER| Analytic cos(G.r)/sin(G.r); no finite-coordinate substitution.'
325 WRITE (output_unit, '(T2,A)') 'SPECTRAL_LOCALIZER| Finite AO torus diagnostic; converge basis, supercell and ETA.'
326 ELSE
327 WRITE (output_unit, '(/,T2,A)') 'SPECTRAL_LOCALIZER| Finite-system DBCSR localizer'
328 END IF
329 IF (ndim == 3) THEN
330 WRITE (output_unit, '(T2,A)') 'SPECTRAL_LOCALIZER| LAPACK real LU/QR sign; independent generalized chiral gap.'
331 ELSE
332 WRITE (output_unit, '(T2,A)') 'SPECTRAL_LOCALIZER| LAPACK LDL inertia with eigenvalue validation.'
333 END IF
334 WRITE (output_unit, '(T2,A,I0)') 'SPECTRAL_LOCALIZER| Localizer dimension: ', merge(4*n, 2*n, ndim == 3)
335 IF (ndim == 3) THEN
336 WRITE (output_unit, '(T2,A)') 'SPECTRAL_LOCALIZER| Three-dimensional AII; chiral determinant sign.'
337 ELSE
338 WRITE (output_unit, '(T2,A,2A)') 'SPECTRAL_LOCALIZER| Oriented plane: ', axes(directions(:2))
339 END IF
340 IF (.NOT. periodic_localizer) THEN
341 WRITE (output_unit, '(T2,A)') 'SPECTRAL_LOCALIZER| Check basis, volume and KAPPA convergence.'
342 END IF
343 IF (.NOT. do_soc) WRITE (output_unit, '(T2,A)') &
344 'SPECTRAL_LOCALIZER| Real scalar Hamiltonian: no nonzero class A Chern index is expected.'
345 END IF
346 IF (flatten) THEN
347 ALLOCATE (flat_hamiltonian)
348 IF (do_soc) THEN
349 CALL localizer_ao_operators(matrix_ks(spin_channel)%matrix, matrix_s(1)%matrix, positions(:0), &
350 physical_h, physical_metric, soc_matrices)
351 ELSE
352 CALL localizer_ao_operators(matrix_ks(spin_channel)%matrix, matrix_s(1)%matrix, positions(:0), &
353 physical_h, physical_metric)
354 END IF
355 IF (output_unit > 0) THEN
356 WRITE (output_unit, '(T2,A,ES23.14)') 'SPECTRAL_LOCALIZER| Flattening scale [hartree]: ', flatten_scale
357 WRITE (output_unit, '(T2,A)') 'SPECTRAL_LOCALIZER| Gaps and indices refer to the flattened Hamiltonian.'
358 IF (periodic_localizer) THEN
359 WRITE (output_unit, '(T2,A)') 'SPECTRAL_LOCALIZER| Flattening in complete primitive Bloch blocks.'
360 WRITE (output_unit, '(T2,A)') &
361 'SPECTRAL_LOCALIZER| Residuals: translation, metric orthonormality, eigenproblem, Hermiticity.'
362 END IF
363 END IF
364 END IF
365 DO ie = 1, SIZE(energies)
366 build_energy = energies(ie)
367 IF (flatten) THEN
368 CALL timeset('localizer_spectral_flattening', flatten_handle)
369 IF (periodic_localizer) THEN
370 CALL localizer_flatten_bloch(physical_h(1), physical_metric, grid, merge(2, 1, do_soc), &
371 energies(ie), flatten_scale, eps_flattening, eps_metric, eps_electronic_gap, &
372 para_env, flat_hamiltonian, electronic_gap(1), physical_ratio, &
373 flatten_residuals, status)
374 electronic_gap(2) = electronic_gap(1)
375 ELSE
376 CALL localizer_flatten_checked(physical_h(1), physical_metric, energies(ie), flatten_scale, eps_flattening, &
377 eps_metric, eps_electronic_gap, para_env, flat_hamiltonian, &
378 electronic_gap, physical_ratio, flatten_residuals, status)
379 END IF
380 CALL timestop(flatten_handle)
381 IF (output_unit > 0) THEN
382 WRITE (output_unit, '(T2,A,ES23.14)') 'SPECTRAL_LOCALIZER| Flattening query [hartree]: ', energies(ie)
383 WRITE (output_unit, '(T2,A,2ES23.14)') &
384 'SPECTRAL_LOCALIZER| Original electronic gap bracket [hartree]: ', electronic_gap
385 WRITE (output_unit, '(T2,A,ES23.14)') 'SPECTRAL_LOCALIZER| Original metric ratio bound: ', physical_ratio
386 WRITE (output_unit, '(T2,A,4ES14.5)') 'SPECTRAL_LOCALIZER| Flattening residuals: ', flatten_residuals
387 END IF
388 SELECT CASE (status)
389 CASE (0)
390 CASE (1)
391 cpabort('SPECTRAL_FLATTENING: electronic gap unresolved; no index.')
392 CASE (-2)
393 cpabort('SPECTRAL_FLATTENING: invalid original AO metric.')
394 CASE (-6)
395 cpabort('SPECTRAL_FLATTENING: sign iteration or structure failed.')
396 CASE (-7)
397 cpabort('SPECTRAL_FLATTENING: broken torus translations.')
398 CASE DEFAULT
399 cpabort('SPECTRAL_FLATTENING: input or gap factorization failed.')
400 END SELECT
401 build_energy = 0.0_dp
402 END IF
403 DO ip = 1, nposition
404 CALL section_vals_val_get(section, 'POSITION', i_rep_val=ip, r_vals=point)
405 IF (.NOT. all(ieee_is_finite(point))) THEN
406 cpabort('SPECTRAL_LOCALIZER requires finite POSITION.')
407 END IF
408 local_point(:ndim) = point(directions(:ndim))
409 IF (periodic_localizer) THEN
410 DO axis = 1, ndim
411 local_point(axis) = twopi*dot_product(cell%h_inv(directions(axis), :), point)/ &
412 REAL(grid(directions(axis)), dp)
413 END DO
414 END IF
415 DO ik = 1, SIZE(kappas)
416 IF (ndim == 3) THEN
417 CALL localizer_dbcsr_3d_build(matrix_ks(spin_channel)%matrix, matrix_s(1)%matrix, positions, &
418 local_point, build_energy, kappas(ik), localizer, metric, soc_matrices, &
419 shifted_hamiltonian=flat_hamiltonian, periodic_cosines=cosines)
420 ELSE IF (do_soc) THEN
421 CALL localizer_dbcsr_build(matrix_ks(spin_channel)%matrix, matrix_s(1)%matrix, &
422 positions(directions(1))%matrix, positions(directions(2))%matrix, &
423 local_point(:2), build_energy, kappas(ik), localizer, metric, soc_matrices, cosines, &
424 shifted_hamiltonian=flat_hamiltonian)
425 ELSE
426 CALL localizer_dbcsr_build(matrix_ks(spin_channel)%matrix, matrix_s(1)%matrix, &
427 positions(directions(1))%matrix, positions(directions(2))%matrix, &
428 local_point(:2), build_energy, kappas(ik), localizer, metric, &
429 periodic_cosines=cosines, shifted_hamiltonian=flat_hamiltonian)
430 END IF
431 CALL localizer_dbcsr_dense(localizer, para_env, local_dense)
432 CALL localizer_dbcsr_dense(metric, para_env, metric_dense)
433 IF (para_env%is_source()) THEN
434 IF (ndim == 3) THEN
435 CALL localizer_3d_matrix_evaluate(local_dense, metric_dense(:n, :n), &
436 matrix_tolerance, eps_metric, eps_gap, invariant, gap, &
437 metric_ratio, status)
438 ELSE
439 CALL localizer_matrix_evaluate(local_dense, metric_dense(:n, :n), aii, &
440 matrix_tolerance, eps_metric, eps_gap, invariant, gap, metric_ratio, status)
441 END IF
442 IF (status < 0 .AND. output_unit > 0 .AND. ndim == 2) THEN
443 WRITE (output_unit, '(T2,A,I0,2ES14.5)') &
444 'SPECTRAL_LOCALIZER| Failure status and L/B Hermiticity residuals: ', status, &
445 maxval(abs(local_dense - conjg(transpose(local_dense)))), &
446 maxval(abs(metric_dense - conjg(transpose(metric_dense))))
447 END IF
448 END IF
449 DEALLOCATE (local_dense, metric_dense)
450 CALL localizer_dbcsr_release(localizer)
451 CALL localizer_dbcsr_release(metric)
452 CALL para_env%bcast(status, para_env%source)
453 IF (status < 0 .OR. status > 1) THEN
454 SELECT CASE (status)
455 CASE (-2)
456 cpabort('SPECTRAL_LOCALIZER: invalid AO metric; check basis/EPS_METRIC.')
457 CASE (-3)
458 cpabort('SPECTRAL_LOCALIZER: broken physical TR/AII structure.')
459 CASE DEFAULT
460 cpabort('SPECTRAL_LOCALIZER: invalid data or factorization failure.')
461 END SELECT
462 END IF
463 CALL para_env%bcast(invariant, para_env%source)
464 CALL para_env%bcast(gap, para_env%source)
465 CALL para_env%bcast(metric_ratio, para_env%source)
466 IF (output_unit > 0) THEN
467 WRITE (output_unit, '(T2,A,3ES23.14)') 'SPECTRAL_LOCALIZER| Position [bohr]: ', point
468 WRITE (output_unit, '(T2,A,ES23.14)') 'SPECTRAL_LOCALIZER| Energy [hartree]: ', energies(ie)
469 IF (periodic_localizer) THEN
470 WRITE (output_unit, '(T2,A,ES23.14)') 'SPECTRAL_LOCALIZER| Eta [hartree]: ', kappas(ik)
471 ELSE
472 WRITE (output_unit, '(T2,A,ES23.14)') 'SPECTRAL_LOCALIZER| Kappa [hartree/bohr]: ', kappas(ik)
473 END IF
474 WRITE (output_unit, '(T2,A,ES23.14)') 'SPECTRAL_LOCALIZER| Metric ratio: ', metric_ratio
475 WRITE (output_unit, '(T2,A,ES23.14)') 'SPECTRAL_LOCALIZER| Gap [hartree]: ', gap
476 IF (status == 1) THEN
477 WRITE (output_unit, '(T2,A)') 'SPECTRAL_LOCALIZER| UNRESOLVED: gap or factorization below accuracy; no index.'
478 ELSE IF (aii) THEN
479 WRITE (output_unit, '(T2,A,I0)') 'SPECTRAL_LOCALIZER| Z2 index: ', invariant
480 ELSE
481 WRITE (output_unit, '(T2,A,I0)') 'SPECTRAL_LOCALIZER| Chern index: ', invariant
482 END IF
483 END IF
484 END DO
485 END DO
486 IF (flatten) CALL localizer_dbcsr_release(flat_hamiltonian)
487 END DO
488 IF (flatten) THEN
489 CALL localizer_dbcsr_release(physical_h(1))
490 CALL localizer_dbcsr_release(physical_metric)
491 DEALLOCATE (flat_hamiltonian)
492 END IF
493 CALL dbcsr_deallocate_matrix_set(positions)
494 IF (ASSOCIATED(cosines)) CALL dbcsr_deallocate_matrix_set(cosines)
495 IF (ASSOCIATED(soc_matrices)) CALL dbcsr_deallocate_matrix_set(soc_matrices)
496 IF (torus) THEN
497 CALL dbcsr_deallocate_matrix_set(matrix_ks)
498 CALL dbcsr_deallocate_matrix_set(matrix_s)
499 END IF
500 CALL timestop(handle)
501 END SUBROUTINE qs_scf_post_localizer
502
503! **************************************************************************************************
504!> \brief Analytic torus coordinates in the reciprocal frame of a Gamma supercell.
505!> \param qs_env Quickstep environment
506!> \param directions Two or three periodic lattice directions
507!> \param cosines Newly allocated cosine matrices, indexed by oriented direction
508!> \param sines Newly allocated sine matrices, indexed by lattice direction
509! **************************************************************************************************
510 SUBROUTINE periodic_ao_moments(qs_env, directions, cosines, sines)
511 TYPE(qs_environment_type), POINTER :: qs_env
512 INTEGER, INTENT(IN) :: directions(:)
513 TYPE(dbcsr_p_type), POINTER :: cosines(:), sines(:)
514
515 INTEGER :: j
516 TYPE(cell_type), POINTER :: cell
517 TYPE(dbcsr_p_type), POINTER :: matrix_s(:)
518 TYPE(neighbor_list_set_p_type), POINTER :: sab_orb(:)
519
520 CALL get_qs_env(qs_env, cell=cell, matrix_s=matrix_s, sab_orb=sab_orb)
521 ALLOCATE (cosines(SIZE(directions)), sines(3))
522 DO j = 1, 3
523 ALLOCATE (sines(j)%matrix)
524 CALL dbcsr_create(sines(j)%matrix, template=matrix_s(1)%matrix, name='TORUS SIN')
525 CALL cp_dbcsr_alloc_block_from_nbl(sines(j)%matrix, sab_orb)
526 CALL dbcsr_set(sines(j)%matrix, 0.0_dp)
527 END DO
528 DO j = 1, SIZE(directions)
529 ALLOCATE (cosines(j)%matrix)
530 CALL dbcsr_create(cosines(j)%matrix, template=matrix_s(1)%matrix, name='TORUS COS')
531 CALL cp_dbcsr_alloc_block_from_nbl(cosines(j)%matrix, sab_orb)
532 CALL dbcsr_set(cosines(j)%matrix, 0.0_dp)
533 CALL build_berry_moment_matrix(qs_env, cosines(j)%matrix, sines(directions(j))%matrix, &
534 twopi*cell%h_inv(directions(j), :))
535 END DO
536 END SUBROUTINE periodic_ao_moments
537
538END MODULE qs_spectral_localizer
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public wong2026
integer, save, public dixon2023
integer, save, public doll2025
integer, save, public loring2015
Handles all functions related to the CELL.
Definition cell_types.F:15
integer, parameter, public use_perd_xyz
Definition cell_types.F:42
integer, parameter, public use_perd_xz
Definition cell_types.F:42
integer, parameter, public use_perd_yz
Definition cell_types.F:42
integer, parameter, public use_perd_none
Definition cell_types.F:42
integer, parameter, public use_perd_xy
Definition cell_types.F:42
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
subroutine, public dbcsr_set(matrix, alpha)
...
DBCSR operations in CP2K.
DBCSR output in CP2K.
subroutine, public cp_dbcsr_write_sparse_matrix(sparse_matrix, before, after, qs_env, para_env, first_row, last_row, first_col, last_col, scale, output_unit, omit_headers, cartesian_basis)
...
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
integer, parameter, public cp_p_file
integer function, public cp_print_key_should_output(iteration_info, basis_section, print_key_path, used_print_key, first_time)
returns what should be done with the given property if btest(res,cp_p_store) then the property should...
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_method_gpw
integer, parameter, public do_method_gapw
objects that represent the structure of input sections and the data contained in an input section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Definition of mathematical constants and functions.
real(kind=dp), parameter, public twopi
Interface to the message passing library MPI.
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
Shared finite-system AO position and SOC operators for post-SCF analyses.
subroutine, public finite_ao_soc(qs_env, soc_matrices)
Validate and construct post-SCF GTH SOC components shared by finite AO analyses.
subroutine, public finite_ao_positions(qs_env, positions)
Analytic covariant first moments in the coordinate frame of SUBSYS/COORD.
Full Born-von-Karman AO operators at a frozen SCF potential.
subroutine, public localizer_torus_operators(qs_env, grid, directions, do_soc, h, s, cosines, sines, soc)
Lift scalar image operators and ordered Berry integrals to a full real-cell torus.
Calculates the moment integrals <a|r^m|b> and <a|r x d/dr|b>.
Definition qs_moments.F:14
subroutine, public build_berry_moment_matrix(qs_env, cosmat, sinmat, kvec, sab_orb_external, basis_type)
...
Define the neighbor list data types and the corresponding functionality.
Post-SCF finite-system spectral localizers and analytic AO position export.
subroutine, public qs_scf_post_localizer(qs_env)
Export finite AO positions and optionally evaluate localizers after SCF.
provides a uniform framework to add references to CP2K cite and output these
subroutine, public cite_reference(key)
marks a given reference as cited.
Exact spectral flattening of a translation-invariant AO torus in primitive Bloch blocks.
subroutine, public localizer_flatten_bloch(h, s, grid, nspin, energy, scale, tolerance, metric_tolerance, gap_tolerance, para_env, flattened, gap, metric_ratio, residuals, status)
Flatten all Bloch bands, then return to the original distributed real-cell/spin AO basis.
Distributed block-sparse finite localizers, retaining the covariant AO metric.
subroutine, public localizer_ao_operators(h, s, positions, operators, metric, soc)
Shared AO Hamiltonian, Hermitian scalar observables and optional GTH physical-spin SOC.
subroutine, public localizer_dbcsr_dense(matrix, para_env, dense)
Collect the size-limited dense oracle; sparse solvers must not call this routine.
subroutine, public localizer_dbcsr_release(matrix)
Release both real components of a complex sparse operator.
subroutine, public localizer_dbcsr_build(h, s, x, y, point, energy, kappa, localizer, metric, soc, periodic_cosines, shifted_hamiltonian)
Assemble L and B=diag(S,S), including optional physical spin and SOC, without dense AOs.
subroutine, public localizer_dbcsr_3d_build(h, s, positions, point, energy, kappa, block, metric, soc, shifted_hamiltonian, periodic_cosines)
Build the 3D AII chiral block in DBCSR; not a Hermitian 2D localizer.
Metric-covariant spectral flattening with existing distributed matrix iterations.
subroutine, public localizer_flatten_checked(h, s, energy, scale, tolerance, metric_tolerance, gap_tolerance, para_env, flattened, gap, metric_ratio, residuals, status)
Establish a positive AO metric and electronic gap before iterating the matrix sign.
Dense reference spectral localizers in a nonorthogonal finite basis.
subroutine, public localizer_matrix_evaluate(localizer, s, aii, matrix_tol, metric_tol, gap_tol, invariant, gap, metric_ratio, status)
Dense reference evaluation of an assembled localizer with metric diag(S,S).
subroutine, public localizer_3d_matrix_evaluate(block, s, matrix_tol, metric_tol, gap_tol, invariant, gap, metric_ratio, status)
Metric gap and real determinant sign of a three-dimensional AII chiral block.
Control for reading in different topologies and coordinates.
Definition topology.F:13
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
type of a logger, at the moment it contains just a print level starting at which level it should be l...
stores all the informations relevant to an mpi environment