65 SUBROUTINE setup_bloch_transport(qs_env, grid, do_soc, projection, max_memory_mb, energies, current, occupations, &
66 symmetry, backend, eps_symmetry, eps_operators)
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
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(:, :, :, :)
95 TYPE(
dbcsr_p_type),
POINTER :: dr(:, :), hr(:, :), sr(:, :), vr(:, :)
97 TYPE(
kpoint_type),
POINTER :: images, scf, property_points
103 CALL get_qs_env(qs_env, do_kpoints=do_kpoints, dft_control=dft_control)
104 SELECT CASE (dft_control%qs_control%method_id)
107 cpabort(
'Kubo BLOCH currently supports GPW/GAPW only.')
109 NULLIFY (qp, images, dr, vr, property_points)
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)
119 IF (do_soc) n = 2*nao
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.')
131 ALLOCATE (hs(nspin, nao, nao, ni), ss(1, nao, nao, ni), ds(3, nao, nao, ni), source=0.0_dp)
138 ALLOCATE (vs(3, nao, nao, ni), source=0.0_dp)
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))
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)
153 property_points, representative, operation)
154 nr = property_points%nkp
155 ALLOCATE (representative_k(3, nr))
156 representative_k(:, :) = property_points%xkp
159 ALLOCATE (representative_k(3, nr))
160 representative_k(:, :) = mesh
161 ALLOCATE (representative(nk), operation(nk))
162 representative(:) = [(ik, 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)
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))
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
192 CALL operators_at_k()
193 ntry = property_points%kp_sym(ir)%kpoint_sym%nwred
194 best_errors = huge(1.0_dp)
196 operation_try = operation(ik)
197 IF (trial > 0) operation_try = trial
198 IF (trial > 0 .AND. operation_try == operation(ik)) cycle
200 rotation, antiunitary, status)
201 IF (status /= 0) cycle
202 IF (maxval(abs(matmul(rotation, matmul(projection, transpose(rotation))) - projection)) &
205 eps_operators, residuals, status)
206 candidate_errors = [residuals, 0.0_dp]
207 IF (status == 0)
THEN
211 IF (antiunitary)
THEN
212 expected(:, :, axis) = expected(:, :, axis) + &
213 rotation(axis, idir)*conjg(source_current(:, :, idir))
215 expected(:, :, axis) = expected(:, :, axis) + rotation(axis, idir)*source_current(:, :, idir)
219 candidate_errors(3) = maxval(abs(cur - expected))/max(1.0_dp, maxval(abs(cur)))
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
227 errors = max(errors, best_errors)
228 IF (trial > ntry)
THEN
229 failed = max(failed, 5)
235 current(:, :, axis, channel) = current(:, :, axis, channel) + projection(axis, idir)*cur(:, :, idir)
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
250 IF (failed /= 0)
THEN
252 cpabort(
'Bloch Kubo property symmetry failed target metric/Hamiltonian/current covariance.')
254 cpabort(
'Bloch Kubo failed metric, Hermiticity or AO-connection validation.')
257 CALL para_env%sum(energies)
258 CALL para_env%sum(current)
260 IF (
ASSOCIATED(property_points))
CALL kpoint_release(property_points)
261 IF (.NOT. do_kpoints)
THEN
269 SUBROUTINE operators_at_k()
270 INTEGER :: component, direction
272 CALL rs_to_kp(hs(spin, :, :, :), a, images%index_to_cell, k)
273 CALL spin_diagonal(a, h)
276 CALL rs_to_kp(vs(component, :, :, :), v(:, :, component), images%index_to_cell, k)
280 CALL rs_to_kp(ss(1, :, :, :), a, images%index_to_cell, k)
281 CALL spin_diagonal(a, s)
283 CALL rs_to_kp(hs(spin, :, :, :), a, images%index_to_cell, k, component, cell%hmat)
284 CALL spin_diagonal(a, dh(:, :, component))
287 CALL rs_to_kp(vs(direction, :, :, :), v(:, :, direction), images%index_to_cell, k, component, cell%hmat)
289 CALL add_soc(dh(:, :, component), v)
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))
296 END SUBROUTINE operators_at_k
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.