(git:6344619)
Loading...
Searching...
No Matches
qs_kubo_bloch.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 Full-mesh scalar/spinor Bloch currents from CP2K image operators and analytic AO moments.
10!> \author Thomas D. Kuehne, tkuehne@cp2k.org
11! **************************************************************************************************
13 USE cell_types, ONLY: cell_type
15 USE cp_dbcsr_api, ONLY: dbcsr_get_info,&
21 USE kinds, ONLY: dp,&
22 int_8
26 USE kpoint_types, ONLY: kpoint_create,&
29 USE kubo_bloch, ONLY: bloch_current,&
37 USE qs_mo_types, ONLY: mo_set_type
42#include "./base/base_uses.f90"
43
44 IMPLICIT NONE
45 PRIVATE
46 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_kubo_bloch'
47 PUBLIC :: setup_bloch_transport
48CONTAINS
49! **************************************************************************************************
50!> \brief Build a full Gamma-centered property mesh, independent of SCF reduction.
51!> \param qs_env Converged GPW/GAPW environment
52!> \param grid Full property mesh; nonperiodic directions must be one
53!> \param do_soc Add complete GTH SOC after a restricted SCF
54!> \param projection Cartesian projection onto periodic transport directions
55!> \param max_memory_mb Safety bound on replicated array memory per rank, in MiB
56!> \param energies Complete spectrum, flattened (spin,k) channels
57!> \param current Anti-Hermitian -i*velocity per channel
58!> \param occupations Maximum occupations including normalized k weights
59!> \param symmetry Reconstruct symmetry-equivalent property eigenframes
60!> \param backend Geometric symmetry backend
61!> \param eps_symmetry Geometric tolerance
62!> \param eps_operators Target frame and current validation tolerance
63!> \note This dense reference stores image operators on every rank; eigensystems are distributed by k.
64! **************************************************************************************************
65 SUBROUTINE setup_bloch_transport(qs_env, grid, do_soc, projection, max_memory_mb, energies, current, occupations, &
66 symmetry, backend, eps_symmetry, eps_operators)
67 TYPE(qs_environment_type), POINTER :: qs_env
68 INTEGER, INTENT(IN) :: grid(3)
69 LOGICAL, INTENT(IN) :: do_soc
70 REAL(dp), INTENT(IN) :: projection(3, 3)
71 INTEGER, INTENT(IN) :: max_memory_mb
72 REAL(dp), ALLOCATABLE, INTENT(OUT) :: energies(:, :)
73 COMPLEX(dp), ALLOCATABLE, INTENT(OUT) :: current(:, :, :, :)
74 REAL(dp), ALLOCATABLE, INTENT(OUT) :: occupations(:)
75 LOGICAL, INTENT(IN) :: symmetry
76 INTEGER, INTENT(IN) :: backend
77 REAL(dp), INTENT(IN) :: eps_symmetry, eps_operators
78
79 COMPLEX(dp), ALLOCATABLE :: a(:, :), cur(:, :, :), d(:, :, :), &
80 dh(:, :, :), dsk(:, :, :), h(:, :), &
81 s(:, :), v(:, :, :), source(:, :), TARGET(:, :), &
82 source_current(:, :, :), expected(:, :, :)
83 INTEGER :: axis, channel, failed, idir, ik, n, nao, &
84 ni, nk, nspin, spin, status, ir, nr, iw, &
85 trial, ntry, operation_try, alternatives
86 INTEGER, ALLOCATABLE :: representative(:), operation(:)
87 INTEGER(int_8) :: bytes
88 LOGICAL :: do_kpoints, antiunitary
89 REAL(dp) :: k(3), rotation(3, 3), residuals(2), errors(3), &
90 candidate_errors(3), best_errors(3)
91 REAL(dp), ALLOCATABLE :: mesh(:, :), representative_k(:, :), source_energies(:)
92 REAL(dp), ALLOCATABLE :: ds(:, :, :, :), hs(:, :, :, :), &
93 ss(:, :, :, :), vs(:, :, :, :)
94 TYPE(cell_type), POINTER :: cell
95 TYPE(dbcsr_p_type), POINTER :: dr(:, :), hr(:, :), sr(:, :), vr(:, :)
96 TYPE(dft_control_type), POINTER :: dft_control
97 TYPE(kpoint_type), POINTER :: images, scf, property_points
98 TYPE(mo_set_type), POINTER :: mos(:)
99 TYPE(mp_para_env_type), POINTER :: para_env
100 TYPE(neighbor_list_set_p_type), POINTER :: all_pairs(:)
101 TYPE(qs_environment_type), POINTER :: qp
102
103 CALL get_qs_env(qs_env, do_kpoints=do_kpoints, dft_control=dft_control)
104 SELECT CASE (dft_control%qs_control%method_id)
106 CASE DEFAULT
107 cpabort('Kubo BLOCH currently supports GPW/GAPW only.')
108 END SELECT
109 NULLIFY (qp, images, dr, vr, property_points)
110 IF (do_kpoints) THEN
111 qp => qs_env
112 ELSE
113 CALL create_kp_from_gamma(qs_env, qp)
114 END IF
115 CALL get_qs_env(qp, cell=cell, para_env=para_env, matrix_ks_kp=hr, matrix_s_kp=sr, &
116 sab_all=all_pairs, kpoints=scf, mos=mos)
117 CALL dbcsr_get_info(sr(1, 1)%matrix, nfullrows_total=nao)
118 n = nao
119 IF (do_soc) n = 2*nao
120 nspin = SIZE(hr, 1)
121 nk = product(grid)
122 CALL kpoint_create(images)
123 CALL kpoint_init_cell_index(images, all_pairs, para_env, ni)
124 bytes = 8_int_8*nao*nao*ni*(nspin + 4 + merge(3, 0, do_soc)) + &
125 16_int_8*n*n*(3_int_8*nspin*nk + 48_int_8)
126 IF (max_memory_mb < 1 .OR. bytes > int(max_memory_mb, int_8)*1024*1024) THEN
127 cpabort('Kubo BLOCH arrays exceed MAX_MEMORY_MB per MPI rank.')
128 END IF
129 ALLOCATE (dr(3, ni))
131 ALLOCATE (hs(nspin, nao, nao, ni), ss(1, nao, nao, ni), ds(3, nao, nao, ni), source=0.0_dp)
132 CALL replicate_rs_matrices(hr, scf, hs, images%cell_to_index)
133 CALL replicate_rs_matrices(sr, scf, ss, images%cell_to_index)
134 CALL replicate_rs_matrices(dr, images, ds, images%cell_to_index)
136 IF (do_soc) THEN
137 CALL finite_ao_soc(qp, vr)
138 ALLOCATE (vs(3, nao, nao, ni), source=0.0_dp)
139 CALL replicate_rs_matrices(vr, scf, vs, images%cell_to_index)
141 END IF
142 ALLOCATE (energies(n, nspin*nk), current(n, n, 3, nspin*nk), occupations(nspin*nk))
143 ALLOCATE (h(n, n), s(n, n), dh(n, n, 3), dsk(n, n, 3), d(n, n, 3), cur(n, n, 3), &
144 a(nao, nao), v(nao, nao, 3))
145 ALLOCATE (mesh(3, nk), source(n, n), target(n, n), source_energies(n), &
146 source_current(n, n, 3), expected(n, n, 3))
147 DO ik = 1, nk
148 mesh(:, ik) = real([mod(ik - 1, grid(1)), mod((ik - 1)/grid(1), grid(2)), &
149 (ik - 1)/(grid(1)*grid(2))], dp)/real(grid, dp)
150 END DO
151 IF (symmetry) THEN
152 CALL property_symmetry_plan(qp, mesh, grid, projection, backend, eps_symmetry, &
153 property_points, representative, operation)
154 nr = property_points%nkp
155 ALLOCATE (representative_k(3, nr))
156 representative_k(:, :) = property_points%xkp
157 ELSE
158 nr = nk
159 ALLOCATE (representative_k(3, nr))
160 representative_k(:, :) = mesh
161 ALLOCATE (representative(nk), operation(nk))
162 representative(:) = [(ik, ik=1, nk)]
163 operation = 0
164 END IF
165 energies = 0.0_dp
166 current = 0.0_dp
167 failed = 0
168 errors = 0.0_dp
169 alternatives = 0
170 DO spin = 1, nspin
171 DO ik = 1, nk
172 channel = ik + (spin - 1)*nk
173 occupations(channel) = mos(spin)%maxocc/real(nk, dp)
174 IF (do_soc) occupations(channel) = 1.0_dp/real(nk, dp)
175 END DO
176 DO ir = 1, nr
177 IF (mod(ir - 1, para_env%num_pe) /= para_env%mepos) cycle
178 k = representative_k(:, ir)
179 CALL operators_at_k()
180 CALL bloch_current(h, s, dh, dsk, d, source_energies, source_current, status, source)
181 IF (status /= 0) THEN
182 failed = max(failed, abs(status))
183 cycle
184 END IF
185 DO ik = 1, nk
186 IF (representative(ik) /= ir) cycle
187 channel = ik + (spin - 1)*nk
188 energies(:, channel) = source_energies
189 cur(:, :, :) = source_current
190 IF (operation(ik) /= 0) THEN
191 k = mesh(:, ik)
192 CALL operators_at_k()
193 ntry = property_points%kp_sym(ir)%kpoint_sym%nwred
194 best_errors = huge(1.0_dp)
195 DO trial = 0, ntry
196 operation_try = operation(ik)
197 IF (trial > 0) operation_try = trial
198 IF (trial > 0 .AND. operation_try == operation(ik)) cycle
199 CALL property_symmetry_frame(property_points, ir, operation_try, k, source, do_soc, TARGET, &
200 rotation, antiunitary, status)
201 IF (status /= 0) cycle
202 IF (maxval(abs(matmul(rotation, matmul(projection, transpose(rotation))) - projection)) &
203 > 1.e-9_dp) cycle
204 CALL bloch_current_from_frame(h, s, dh, dsk, d, source_energies, TARGET, cur, &
205 eps_operators, residuals, status)
206 candidate_errors = [residuals, 0.0_dp]
207 IF (status == 0) THEN
208 expected = 0.0_dp
209 DO axis = 1, 3
210 DO idir = 1, 3
211 IF (antiunitary) THEN
212 expected(:, :, axis) = expected(:, :, axis) + &
213 rotation(axis, idir)*conjg(source_current(:, :, idir))
214 ELSE
215 expected(:, :, axis) = expected(:, :, axis) + rotation(axis, idir)*source_current(:, :, idir)
216 END IF
217 END DO
218 END DO
219 candidate_errors(3) = maxval(abs(cur - expected))/max(1.0_dp, maxval(abs(cur)))
220 END IF
221 IF (maxval(candidate_errors) < maxval(best_errors)) best_errors = candidate_errors
222 IF (status /= 0 .OR. maxval(candidate_errors) > eps_operators) cycle
223 best_errors = candidate_errors
224 IF (trial > 0) alternatives = alternatives + 1
225 EXIT
226 END DO
227 errors = max(errors, best_errors)
228 IF (trial > ntry) THEN
229 failed = max(failed, 5)
230 cycle
231 END IF
232 END IF
233 DO axis = 1, 3
234 DO idir = 1, 3
235 current(:, :, axis, channel) = current(:, :, axis, channel) + projection(axis, idir)*cur(:, :, idir)
236 END DO
237 END DO
238 END DO
239 END DO
240 END DO
241 CALL para_env%max(failed)
242 CALL para_env%max(errors)
243 CALL para_env%sum(alternatives)
245 IF (symmetry .AND. iw > 0) THEN
246 WRITE (iw, '(T2,A,I0,A,I0)') 'KUBO_TRANSPORT| Property symmetry representatives: ', nr, ' / ', nk
247 WRITE (iw, '(T2,A,3ES14.5)') 'KUBO_TRANSPORT| Symmetry errors S/H/current: ', errors
248 WRITE (iw, '(T2,A,I0)') 'KUBO_TRANSPORT| Alternative validated orbit operations: ', alternatives
249 END IF
250 IF (failed /= 0) THEN
251 IF (symmetry) THEN
252 cpabort('Bloch Kubo property symmetry failed target metric/Hamiltonian/current covariance.')
253 ELSE
254 cpabort('Bloch Kubo failed metric, Hermiticity or AO-connection validation.')
255 END IF
256 END IF
257 CALL para_env%sum(energies)
258 CALL para_env%sum(current)
259 CALL kpoint_release(images)
260 IF (ASSOCIATED(property_points)) CALL kpoint_release(property_points)
261 IF (.NOT. do_kpoints) THEN
262 CALL qs_env_release(qp)
263 DEALLOCATE (qp)
264 END IF
265 CONTAINS
266! **************************************************************************************************
267!> \brief Fourier-transform the frozen image operators at the current (k,spin).
268! **************************************************************************************************
269 SUBROUTINE operators_at_k()
270 INTEGER :: component, direction
271
272 CALL rs_to_kp(hs(spin, :, :, :), a, images%index_to_cell, k)
273 CALL spin_diagonal(a, h)
274 IF (do_soc) THEN
275 DO component = 1, 3
276 CALL rs_to_kp(vs(component, :, :, :), v(:, :, component), images%index_to_cell, k)
277 END DO
278 CALL add_soc(h, v)
279 END IF
280 CALL rs_to_kp(ss(1, :, :, :), a, images%index_to_cell, k)
281 CALL spin_diagonal(a, s)
282 DO component = 1, 3
283 CALL rs_to_kp(hs(spin, :, :, :), a, images%index_to_cell, k, component, cell%hmat)
284 CALL spin_diagonal(a, dh(:, :, component))
285 IF (do_soc) THEN
286 DO direction = 1, 3
287 CALL rs_to_kp(vs(direction, :, :, :), v(:, :, direction), images%index_to_cell, k, component, cell%hmat)
288 END DO
289 CALL add_soc(dh(:, :, component), v)
290 END IF
291 CALL rs_to_kp(ss(1, :, :, :), a, images%index_to_cell, k, component, cell%hmat)
292 CALL spin_diagonal(a, dsk(:, :, component))
293 CALL rs_to_kp(ds(component, :, :, :), a, images%index_to_cell, k)
294 CALL spin_diagonal(a, d(:, :, component))
295 END DO
296 END SUBROUTINE operators_at_k
297 END SUBROUTINE setup_bloch_transport
298! **************************************************************************************************
299!> \brief Duplicate a scalar operator in the physical spin basis.
300!> \param a Scalar operator
301!> \param out Scalar or doubled spinor operator
302! **************************************************************************************************
303 SUBROUTINE spin_diagonal(a, out)
304 COMPLEX(dp), INTENT(IN) :: a(:, :)
305 COMPLEX(dp), INTENT(OUT) :: out(:, :)
306
307 INTEGER :: n
308
309 n = SIZE(a, 1)
310 out = 0.0_dp
311 out(:n, :n) = a
312 IF (SIZE(out, 1) == 2*n) out(n + 1:, n + 1:) = a
313 END SUBROUTINE spin_diagonal
314! **************************************************************************************************
315!> \brief Add i*sigma times the real-spherical-harmonic SOC components, including their derivatives.
316!> \param h Spinor Hamiltonian or derivative
317!> \param v Fourier-transformed real antisymmetric SOC components (without the factor i)
318! **************************************************************************************************
319 SUBROUTINE add_soc(h, v)
320 COMPLEX(dp), INTENT(INOUT) :: h(:, :)
321 COMPLEX(dp), INTENT(IN) :: v(:, :, :)
322
323 COMPLEX(dp), PARAMETER :: iu = (0.0_dp, 1.0_dp)
324
325 INTEGER :: n
326
327 n = SIZE(v, 1)
328 h(:n, :n) = h(:n, :n) + iu*v(:, :, 3)
329 h(n + 1:, n + 1:) = h(n + 1:, n + 1:) - iu*v(:, :, 3)
330 h(:n, n + 1:) = h(:n, n + 1:) + iu*v(:, :, 1) - v(:, :, 2)
331 h(n + 1:, :n) = h(n + 1:, :n) + iu*v(:, :, 1) + v(:, :, 2)
332 END SUBROUTINE add_soc
333END MODULE qs_kubo_bloch
Handles all functions related to the CELL.
Definition cell_types.F:15
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)
...
DBCSR operations in CP2K.
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...
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
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public int_8
Definition kinds.F:54
integer, parameter, public dp
Definition kinds.F:34
Implements simple k-space/R-space transformations and Gamma-point MIC reconstruction.
subroutine, public rs_to_kp(rs_real, ks_complex, index_to_cell, xkp, deriv_direction, hmat)
Integrate RS matrices (stored as Fortran array) into a kpoint matrix at given kp.
subroutine, public replicate_rs_matrices(rs_dbcsr_in, kpoint_in, rs_array_out, cell_to_index_out)
Convert dbcsr matrices representing operators in real-space image cells to arrays.
Routines needed for kpoint calculation.
subroutine, public kpoint_init_cell_index(kpoint, sab_nl, para_env, nimages)
Generates the mapping of cell indices and linear RS index CELL (0,0,0) is always mapped to index 1.
Types and basic routines needed for a kpoint calculation.
subroutine, public kpoint_release(kpoint)
Release a kpoint environment, deallocate all data.
subroutine, public kpoint_create(kpoint)
Create a kpoint environment.
Metric-aware Bloch velocities without eigenvector derivatives or band-gap divisions.
Definition kubo_bloch.F:12
subroutine, public bloch_current(h, s, dh, ds, d, energies, current, status, coefficients)
Evaluate v_nm = C^H(dH - E_n*dS)C + i*(E_n-E_m)*C^H*D*C.
Definition kubo_bloch.F:36
subroutine, public bloch_current_from_frame(h, s, dh, ds, d, energies, c, current, tolerance, residuals, status)
Evaluate the current in a validated reconstructed eigenframe, without rediagonalization.
Definition kubo_bloch.F:76
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.
subroutine, public qs_env_release(qs_env)
releases the given qs_env (see doc/ReferenceCounting.html)
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.
Initialize a qs_env for kpoint calculations starting from a gamma point qs_env.
Definition qs_gamma2kp.F:14
subroutine, public create_kp_from_gamma(qs_env, qs_env_kp, with_xc_terms)
...
Definition qs_gamma2kp.F:66
Full-mesh scalar/spinor Bloch currents from CP2K image operators and analytic AO moments.
subroutine, public setup_bloch_transport(qs_env, grid, do_soc, projection, max_memory_mb, energies, current, occupations, symmetry, backend, eps_symmetry, eps_operators)
Build a full Gamma-centered property mesh, independent of SCF reduction.
Definition and initialisation of the mo data type.
Definition qs_mo_types.F:22
Calculates the moment integrals <a|r^m|b> and <a|r x d/dr|b>.
Definition qs_moments.F:14
subroutine, public build_local_moment_matrix_rs_img(qs_env, moments_rs_img, rcc)
Calculate local moment matrix for a periodic system for all image cells.
Define the neighbor list data types and the corresponding functionality.
Cell-gauge scalar/spinor reconstruction on independent complete property meshes.
subroutine, public property_symmetry_frame(points, representative, operation, k, source, soc, target, rotation, antiunitary, status)
Reconstruct a target eigenframe with atomic image phases and physical SU(2)/Theta action.
subroutine, public property_symmetry_plan(qs_env, k, grid, projection, backend, tolerance, points, representative, operation)
Construct a geometric orbit plan; each reconstructed frame still needs H/S validation.
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
Contains information about kpoints.
stores all the informations relevant to an mpi environment