32 dbcsr_type_no_symmetry, dbcsr_type_symmetric
113#include "./base/base_uses.f90"
118 CHARACTER(LEN=12),
PARAMETER :: window_keywords(4) = &
119 [character(len=12) ::
'DIS_WIN_MIN',
'DIS_WIN_MAX',
'DIS_FROZ_MIN',
'DIS_FROZ_MAX']
120 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_wannier90'
121 INTEGER,
PARAMETER,
PRIVATE :: w90_kpoints_mp_grid = 0, &
122 w90_kpoints_scf = 1, w90_kpoints_nnkp = 2, w90_kpoints_wilson = 3, &
125 TYPE berry_matrix_type
126 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: sinmat => null(), cosmat => null()
127 END TYPE berry_matrix_type
146 CHARACTER(len=*),
PARAMETER :: routinen =
'wannier90_interface'
148 INTEGER :: first_spin, handle, i, ichern, ispin, &
149 iw, iz2, last_spin, max_refinement, &
150 old_chern, old_z2, refinement, &
152 LOGICAL :: converged, explicit, require_chern, &
154 REAL(kind=
dp) :: error, movement, tolerance
155 REAL(kind=
dp),
ALLOCATABLE :: centres(:, :), previous(:, :)
161 CALL timeset(routinen, handle)
163 subsection_name=
"DFT%PRINT%WANNIER90")
170 WRITE (iw,
'(/,T2,A)') &
171 '!-----------------------------------------------------------------------------!'
172 WRITE (iw,
'(T32,A)')
"Interface to Wannier90"
173 WRITE (iw,
'(T2,A)') &
174 '!-----------------------------------------------------------------------------!'
177 CALL get_qs_env(qs_env, dft_control=dft_control)
179 last_spin = dft_control%nspins
180 IF (last_spin /= 1 .AND. last_spin /= 2) cpabort(
'Wannier90 requires collinear spin channels.')
182 IF (selection /= 0)
THEN
183 IF (selection > last_spin) cpabort(
'The requested Wannier90 spin channel is not present.')
184 first_spin = selection
185 last_spin = selection
187 DO ispin = first_spin, last_spin
193 IF (tolerance <= 0.0_dp) cpabort(
"WILSON_TOL must be positive.")
194 IF (source == w90_kpoints_wilson)
THEN
195 IF (max_refinement < 1 .OR. max_refinement > 10)
THEN
196 cpabort(
"WILSON_MAX_REFINEMENT must be between 1 and 10.")
201 DO refinement = 0, max_refinement
202 CALL wannier90_files(qs_env, w_input, iw, ispin, refinement, centres, iz2, ichern)
203 IF (refinement > 0)
THEN
205 DO i = 1,
SIZE(previous, 2)
206 error = max(error,
wcc_distance(previous(:, i), centres(:, 2*i - 1)))
209 DO i = 2,
SIZE(centres, 2)
210 movement = max(movement,
wcc_distance(centres(:, i - 1), centres(:, i)))
212 IF (iw > 0)
WRITE (iw,
'(T2,A,I0,A,ES12.4,A,ES12.4)') &
213 "TOPOLOGY| Refinement ", refinement,
": WCC change ", error,
", transverse step ", movement
214 converged = error < tolerance .AND. movement < 0.1_dp .AND. iz2 == old_z2
215 IF (require_z2) converged = converged .AND. iz2 >= 0 .AND.
surface_resolved(centres)
216 IF (require_chern) converged = converged .AND. ichern /= huge(0) .AND. ichern == old_chern
219 CALL move_alloc(centres, previous)
223 IF (.NOT. converged)
THEN
224 cpabort(
"Wilson surface unconverged; increase WILSON_MAX_REFINEMENT or mesh.")
227 WRITE (iw,
'(T2,A)')
"TOPOLOGY| Wilson surface sampling converged."
228 IF (iz2 >= 0)
WRITE (iw,
'(T2,A,I0)')
"TOPOLOGY| Converged Z2 invariant: ", iz2
229 IF (require_chern)
WRITE (iw,
'(T2,A,I0)')
"TOPOLOGY| Converged first Chern number: ", ichern
232 CALL wannier90_files(qs_env, w_input, iw, ispin, 0, centres, iz2, ichern)
234 IF (
ALLOCATED(previous))
DEALLOCATE (previous)
238 WRITE (iw,
'(/,T2,A)') &
239 '!--------------------------------End of Wannier90-----------------------------!'
242 CALL timestop(handle)
252 SUBROUTINE wannier90_copy_cfm_general(source, destination, para_env)
259 IF (
ASSOCIATED(source))
THEN
265 END SUBROUTINE wannier90_copy_cfm_general
278 SUBROUTINE wannier90_files(qs_env, input, iw, ispin, refinement, wcc_out, z2_value, chern_value)
281 INTEGER,
INTENT(IN) :: iw, ispin, refinement
282 REAL(kind=
dp),
ALLOCATABLE,
INTENT(OUT) :: wcc_out(:, :)
283 INTEGER,
INTENT(OUT) :: z2_value, chern_value
285 INTEGER,
PARAMETER :: num_nnmax = 12
287 CHARACTER(len=2) :: asym
288 CHARACTER(len=20),
ALLOCATABLE,
DIMENSION(:) :: atom_symbols
289 CHARACTER(len=default_path_length) :: nnkp_file
290 CHARACTER(len=default_string_length) :: filename, input_kp_scheme, reuse_reason, &
292 CHARACTER(LEN=timestamp_length) :: timestamp
293 COMPLEX(KIND=dp) :: zmmn
294 COMPLEX(KIND=dp),
ALLOCATABLE :: ao_projections(:, :, :), export_coeff(:, :), &
295 export_scalar(:, :), hybrid_projections(:, :, :), initial_amn(:, :, :), &
296 link_matrix(:, :), parity_metric(:, :), parity_phase(:), reference_mo(:, :, :), &
297 scalar_overlap(:, :), soc_h(:, :), soc_u(:, :), soc_xyz(:, :, :), spinor_coeff(:, :, :), &
298 wilson_product(:, :, :)
299 INTEGER :: aligned_degenerate_blocks, aligned_degenerate_max_size, axis, base_mesh(2), &
300 counts(2), first_point, i, i_rep, ib, ib1, ib2, ibs, ik, ik2, ikk, ikpgr, iloop, &
301 initial_projections, ipoint, iunit, ix, iy, iz, jpar, k, kept_index, kpoints_source, &
302 loop_direction(3), n_rep, nadd, nao, nberry_images, nbs, nelectron, nexcl, nkp, nloop, &
303 nmo, nntot, npoint, nscalar, num_atoms, num_bands, num_bands_tot, num_kpts, num_wann, &
304 projection_candidates, spin_channel, state_components, state_unit, status, strong, &
305 tqc_dimension, trim_id, weak(3), z4
306 INTEGER,
ALLOCATABLE :: ebr_coefficients(:, :), hybrid_groups(:, :), loop_index(:), &
307 parity_map(:), parity_odd(:), projection_pivots(:)
308 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: band_indices, exclude_bands
309 INTEGER,
ALLOCATABLE,
DIMENSION(:, :) :: nblist, nnlist
310 INTEGER,
ALLOCATABLE,
DIMENSION(:, :, :) :: nncell
311 INTEGER,
DIMENSION(2) :: kp_range
312 INTEGER,
DIMENSION(3) :: input_nkp_grid, mp_grid
313 INTEGER,
DIMENSION(:),
POINTER :: invals
314 INTEGER,
DIMENSION(:, :, :),
POINTER :: berry_cell_index, cell_to_index
315 LOGICAL :: diis_step, do_chern, do_kpoints, do_parity, do_soc, do_tqc, do_wilson, do_z2, &
316 export_ao, export_hybrids, export_state, full_mesh_diagonalized, input_full_grid, &
317 input_gamma_centered, input_kpoint_symmetry, lowest_bands, mp_grid_explicit, &
318 mp_grid_valid, my_kpgrp, mygrp, nonnegative_atomic, ordered_berry, require_global_gap, &
319 reuse_scf_mos, reused_scf_mos, signed_atomic, time_reversal, use_bloch_phases, &
320 validate_reuse_ok, validate_reuse_scf_mos, window_set(4)
321 LOGICAL,
ALLOCATABLE,
DIMENSION(:) :: allowed_band, keep_band
322 REAL(kind=
dp) :: aligned_degenerate_min_svalue, berry_phase, chern_winding, cmmn, &
323 conduction_min, direct_gap, energy_window(4), gap_tol, gauge_arg, gauge_imag, gauge_real, &
324 gauge_tmp, ksign, link_sv, loop_origin(3), pair_gap, parity_checks(4), &
325 parity_energy_error, parity_energy_tolerance, parity_error, parity_gap, parity_origin(3), &
326 parity_tolerance, projection_min_svalue, reuse_candidate_deviation, &
327 reuse_candidate_metric_deviation, reuse_candidate_min_svalue, reuse_candidate_residual, &
328 rmmn, transverse(3), valence_max, validation_eigenvalue_deviation, validation_min_svalue
329 REAL(kind=
dp) :: validation_subspace_deviation, wkp_ref
330 REAL(kind=
dp),
ALLOCATABLE :: loop_sv(:), parity_energies(:), &
331 projection_eigenvalues(:, :), &
332 scalar_values(:), spinor_values(:, :)
333 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigval
334 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: atoms_cart, b_latt, kpt_latt, &
335 reference_eigenvalues
336 REAL(kind=
dp),
DIMENSION(3) :: bvec, input_kp_shift, phase_center
337 REAL(kind=
dp),
DIMENSION(3, 3) :: h_inv, real_lattice, recip_lattice
338 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues, wkp, wkp_source
339 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: xkp, xkp_source
340 REAL(kind=
dp),
POINTER :: rvals(:)
341 TYPE(berry_matrix_type),
DIMENSION(:),
POINTER :: berry_matrix
344 TYPE(
cp_cfm_type) :: fmk1_cfm, fmk2_cfm, mmn_cfm, omat_cfm, &
350 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks, matrix_s, soc_matrices
351 TYPE(
dbcsr_type),
POINTER :: cmatrix, cmatrix_full, loop_imag, &
352 loop_real, rmatrix, rmatrix_full
355 TYPE(
kpoint_type),
POINTER :: berry_kpoint, kpoint, qs_kpoint
359 POINTER :: overlap_nl, sab_nl
369 CALL get_qs_env(qs_env, dft_control=dft_control)
370 IF (dft_control%nspins == 2)
THEN
371 IF (len_trim(seed_name) + 5 > len(seed_name))
THEN
372 cpabort(
'Wannier90 seed is too long for the spin suffix.')
374 IF (ispin == 1) seed_name = trim(seed_name)//
'_up'
375 IF (ispin == 2) seed_name = trim(seed_name)//
'_down'
376 IF (iw > 0)
WRITE (iw,
'(T2,A,I0,2A)')
'WANNIER90| Spin channel ', ispin,
' file prefix ', trim(seed_name)
380 ordered_berry = kpoints_source >= w90_kpoints_nnkp
392 parity_origin = rvals
395 do_parity = do_parity .OR. do_tqc .OR. kpoints_source == w90_kpoints_trim
396 IF (do_parity .AND. .NOT. ordered_berry)
THEN
397 cpabort(
"PARITY requires explicit NNKP, WILSON or TRIM points.")
399 IF (tqc_dimension < 2 .OR. tqc_dimension > 3) cpabort(
"TQC_DIMENSION must be 2 or 3.")
400 IF (parity_tolerance <= 0.0_dp .OR. parity_energy_tolerance <= 0.0_dp)
THEN
401 cpabort(
"Invalid parity tolerance.")
403 IF (export_state .AND. .NOT. ordered_berry)
THEN
404 cpabort(
"STATE_EXPORT requires explicit NNKP, WILSON or TRIM points.")
408 IF (do_tqc .AND. (.NOT. do_soc .OR. .NOT. time_reversal))
THEN
409 cpabort(
"INVERSION_TQC requires SOC T and TIME_REVERSAL T.")
412 IF (gap_tol <= 0.0_dp) cpabort(
"WILSON_GAP_TOL must be positive.")
414 chern_value = huge(0)
415 do_wilson = do_wilson .OR. kpoints_source == w90_kpoints_wilson
416 IF (do_wilson .AND. kpoints_source == w90_kpoints_trim)
THEN
417 cpabort(
"TRIM points are not Wilson loops; use KPOINTS_SOURCE WILSON.")
419 IF (do_wilson)
CALL cite_reference(
gresch2017)
421 IF ((do_wilson .OR. do_soc) .AND. kpoints_source < w90_kpoints_nnkp)
THEN
422 cpabort(
"Native Wilson/SOC requires KPOINTS_SOURCE NNKP or WILSON.")
424 IF (do_z2 .AND. (kpoints_source /= w90_kpoints_wilson .OR. .NOT. do_soc .OR. .NOT. time_reversal))
THEN
425 cpabort(
"Z2 requires KPOINTS_SOURCE WILSON, SOC T, and TIME_REVERSAL T.")
427 IF (do_chern .AND. (kpoints_source /= w90_kpoints_wilson .OR. do_z2))
THEN
428 cpabort(
"CHERN requires a full WILSON surface and cannot be combined with Z2.")
430 IF (require_global_gap .AND. .NOT. do_wilson)
THEN
431 cpabort(
"REQUIRE_GLOBAL_GAP requires Wilson analysis.")
433 CALL get_qs_env(qs_env, dft_control=dft_control)
434 IF (spin_channel < 1 .OR. spin_channel > dft_control%nspins)
THEN
435 cpabort(
"WANNIER90%SPIN_CHANNEL is not available in this calculation.")
437 IF (do_soc .AND. dft_control%nspins /= 1)
THEN
438 cpabort(
"WANNIER90 SOC currently requires a restricted SCF.")
441 IF (n_rep > 1 .AND. n_rep /= dft_control%nspins)
THEN
442 cpabort(
'Specify WANNIER_FUNCTIONS once, or once per spin channel.')
445 IF (n_rep > 1) i_rep = ispin
453 export_ao = projection_candidates == 1 .OR. projection_candidates == 3
454 export_hybrids = projection_candidates == 2 .OR. projection_candidates == 3
455 IF (initial_projections == -1 .AND. use_bloch_phases) initial_projections = 0
456 energy_window = [-huge(0.0_dp)/100, huge(0.0_dp)/100, -huge(0.0_dp)/100, huge(0.0_dp)/100]
459 IF (window_set(i))
CALL section_vals_val_get(input, trim(window_keywords(i)), r_val=energy_window(i))
461 IF (ordered_berry .AND. (initial_projections > 0 .OR. projection_candidates > 0 .OR. any(window_set)))
THEN
462 cpabort(
"AO projections and energy windows require KPOINTS_SOURCE MP_GRID or SCF.")
464 IF (window_set(3) .AND. .NOT. window_set(4)) cpabort(
"DIS_FROZ_MIN requires DIS_FROZ_MAX.")
465 IF (energy_window(1) > energy_window(2) .OR. energy_window(3) > energy_window(4))
THEN
466 cpabort(
"Invalid Wannier90 energy window.")
468 reuse_scf_mos = reuse_scf_mos .AND. kpoints_source == w90_kpoints_scf
469 validate_reuse_scf_mos = validate_reuse_scf_mos .AND. reuse_scf_mos
470 mp_grid(1:3) = invals(1:3)
476 nexcl = nexcl +
SIZE(invals)
479 ALLOCATE (exclude_bands(nexcl))
483 exclude_bands(nexcl + 1:nexcl +
SIZE(invals)) = invals(:)
484 nexcl = nexcl +
SIZE(invals)
490 CALL get_cell(cell, h=real_lattice, h_inv=h_inv)
492 CALL get_qs_env(qs_env, particle_set=particle_set)
494 phase_center = 0.0_dp
495 DO i = 1,
SIZE(particle_set)
496 phase_center(1:3) = phase_center(1:3) + matmul(h_inv, particle_set(i)%r)
498 phase_center(1:3) = phase_center(1:3)/real(
SIZE(particle_set), kind=
dp)
499 phase_center(1:3) = phase_center(1:3) - floor(phase_center(1:3))
500 recip_lattice(1:3, 1:3) = h_inv(1:3, 1:3)
501 real_lattice(1:3, 1:3) =
angstrom*real_lattice(1:3, 1:3)
502 recip_lattice(1:3, 1:3) = (
twopi/
angstrom)*transpose(recip_lattice(1:3, 1:3))
503 NULLIFY (kpoint, qs_kpoint, xkp, wkp, xkp_source, wkp_source)
504 CALL get_qs_env(qs_env, do_kpoints=do_kpoints, kpoints=qs_kpoint)
505 input_kpoint_symmetry = .false.
506 input_full_grid = .false.
508 IF (do_kpoints .AND.
ASSOCIATED(qs_kpoint))
THEN
509 CALL get_kpoint_info(qs_kpoint, kp_scheme=input_kp_scheme, nkp_grid=input_nkp_grid, &
510 kp_shift=input_kp_shift, symmetry=input_kpoint_symmetry, &
511 full_grid=input_full_grid, gamma_centered=input_gamma_centered, &
512 nkp=nkp, xkp=xkp, wkp=wkp)
516 SELECT CASE (kpoints_source)
517 CASE (w90_kpoints_nnkp, w90_kpoints_wilson, w90_kpoints_trim)
518 IF (kpoints_source == w90_kpoints_nnkp)
THEN
520 ELSE IF (kpoints_source == w90_kpoints_trim)
THEN
521 num_kpts = 2**tqc_dimension
522 ALLOCATE (kpt_latt(3, num_kpts), nnlist(num_kpts, 1), nncell(3, num_kpts, 1))
526 DO axis = 1, tqc_dimension
527 IF (btest(i - 1, axis - 1)) kpt_latt(axis, i) = 0.5_dp
534 IF (base_mesh(1) < 2 .OR. base_mesh(2) < 2)
THEN
535 cpabort(
"WILSON_MESH entries must be at least two.")
537 npoint = base_mesh(1)*2**refinement
538 nloop = (base_mesh(2) - 1)*2**refinement + 1
540 loop_direction = invals
541 IF (all(loop_direction == 0)) cpabort(
"WILSON_DIRECTION must be nonzero.")
546 bvec = [loop_direction(2)*transverse(3) - loop_direction(3)*transverse(2), &
547 loop_direction(3)*transverse(1) - loop_direction(1)*transverse(3), &
548 loop_direction(1)*transverse(2) - loop_direction(2)*transverse(1)]
549 IF (sum(bvec**2) < 1.e-20_dp)
THEN
550 cpabort(
"Wilson loop and transverse vectors must be linearly independent.")
552 IF (do_chern .AND. maxval(abs(transverse - nint(transverse))) > 1.e-10_dp)
THEN
553 cpabort(
"CHERN requires integer WILSON_TRANSVERSE: a closed full surface, not a half-plane.")
556 IF (maxval(abs(2*loop_origin - nint(2*loop_origin))) > 1.e-10_dp .OR. &
557 maxval(abs(2*transverse - nint(2*transverse))) > 1.e-10_dp)
THEN
558 cpabort(
"Z2 surface boundaries must pass through time-reversal-invariant momenta.")
561 IF (sum(abs(loop_direction)) /= 1 .OR. &
562 abs(sum(abs(transverse)) - 0.5_dp) > 1.e-10_dp .OR. &
563 abs(dot_product(real(loop_direction,
dp), transverse)) > 1.e-10_dp)
THEN
564 cpabort(
"Native Z2 requires distinct coordinate axes with windings one and one half.")
567 num_kpts = npoint*nloop
568 ALLOCATE (kpt_latt(3, num_kpts), nnlist(num_kpts, 1), nncell(3, num_kpts, 1))
571 first_point = (iloop - 1)*npoint + 1
572 DO ipoint = 1, npoint
573 i = first_point + ipoint - 1
574 kpt_latt(:, i) = loop_origin + real(iloop - 1,
dp)/real(nloop - 1,
dp)*transverse + &
575 REAL(ipoint - 1,
dp)/
REAL(npoint,
dp)*loop_direction
578 nnlist(i, 1) = first_point
579 nncell(:, i, 1) = loop_direction
582 num_kpts =
SIZE(kpt_latt, 2)
583 nntot =
SIZE(nnlist, 2)
584 kpoint%kp_scheme =
"GENERAL"
585 kpoint%symmetry = .false.
586 kpoint%verbose = .false.
587 kpoint%full_grid = .true.
588 kpoint%eps_geo = 1.0e-6_dp
589 kpoint%use_real_wfn = .false.
590 kpoint%parallel_group_size = para_env%num_pe
591 kpoint%nkp = num_kpts
592 ALLOCATE (kpoint%xkp(3, num_kpts), kpoint%wkp(num_kpts))
593 kpoint%xkp = kpt_latt
595 kpoint%wkp = 1.0_dp/real(num_kpts, kind=
dp)
596 IF (iw > 0)
WRITE (iw,
'(T2,A,I0,A,I0)') &
597 "WANNIER90| Explicit points: ", num_kpts,
", neighbours per point: ", nntot
598 CASE (w90_kpoints_mp_grid)
599 num_kpts = mp_grid(1)*mp_grid(2)*mp_grid(3)
600 ALLOCATE (kpt_latt(3, num_kpts))
601 kpoint%kp_scheme =
"MONKHORST-PACK"
602 kpoint%symmetry = .false.
603 kpoint%nkp_grid(1:3) = mp_grid(1:3)
604 kpoint%verbose = .false.
605 kpoint%full_grid = .true.
606 kpoint%eps_geo = 1.0e-6_dp
607 kpoint%use_real_wfn = .false.
608 kpoint%parallel_group_size = para_env%num_pe
610 DO ix = 0, mp_grid(1) - 1
611 DO iy = 0, mp_grid(2) - 1
612 DO iz = 0, mp_grid(3) - 1
614 kpt_latt(1, i) = real(ix, kind=
dp)/real(mp_grid(1), kind=
dp)
615 kpt_latt(2, i) = real(iy, kind=
dp)/real(mp_grid(2), kind=
dp)
616 kpt_latt(3, i) = real(iz, kind=
dp)/real(mp_grid(3), kind=
dp)
620 kpoint%nkp = num_kpts
621 ALLOCATE (kpoint%xkp(3, num_kpts), kpoint%wkp(num_kpts))
622 kpoint%wkp(:) = 1._dp/real(num_kpts, kind=
dp)
624 kpoint%xkp(:, :) = kpt_latt(:, :)
626 CASE (w90_kpoints_scf)
627 IF (.NOT. do_kpoints .OR. .NOT.
ASSOCIATED(qs_kpoint))
THEN
628 cpabort(
"WANNIER90%KPOINTS_SOURCE SCF requires an active DFT%KPOINTS section.")
630 SELECT CASE (trim(input_kp_scheme))
634 ALLOCATE (kpt_latt(3, num_kpts))
635 kpt_latt(1:3, 1) = 0.0_dp
636 kpoint%kp_scheme =
"GAMMA"
637 kpoint%symmetry = .false.
638 kpoint%verbose = .false.
639 kpoint%full_grid = .true.
640 kpoint%eps_geo = 1.0e-6_dp
641 kpoint%use_real_wfn = .false.
642 kpoint%parallel_group_size = para_env%num_pe
643 kpoint%nkp = num_kpts
644 ALLOCATE (kpoint%xkp(3, num_kpts), kpoint%wkp(num_kpts))
645 kpoint%xkp(1:3, 1) = 0.0_dp
646 kpoint%wkp(1) = 1.0_dp
648 CASE (
"MONKHORST-PACK",
"MACDONALD")
649 mp_grid(1:3) = input_nkp_grid(1:3)
650 kpoint%kp_scheme = input_kp_scheme
651 kpoint%symmetry = .false.
652 kpoint%nkp_grid(1:3) = input_nkp_grid(1:3)
653 kpoint%kp_shift(1:3) = input_kp_shift(1:3)
654 kpoint%gamma_centered = input_gamma_centered
655 kpoint%verbose = .false.
656 kpoint%full_grid = .true.
657 kpoint%eps_geo = 1.0e-6_dp
658 kpoint%use_real_wfn = .false.
659 kpoint%parallel_group_size = para_env%num_pe
661 num_kpts = kpoint%nkp
662 ALLOCATE (kpt_latt(3, num_kpts))
663 kpt_latt(1:3, 1:num_kpts) = kpoint%xkp(1:3, 1:num_kpts)
664 IF (input_kpoint_symmetry .AND. .NOT. input_full_grid .AND. iw > 0)
THEN
665 WRITE (iw,
'(T2,A)') &
666 "WANNIER90| SCF k-points are symmetry-reduced; regenerating the full SCF mesh."
667 IF (reuse_scf_mos)
THEN
668 WRITE (iw,
'(T2,A)') &
669 "WANNIER90| CP2K will try to reconstruct the full-mesh MOs from the SCF orbitals."
671 WRITE (iw,
'(T2,A)') &
672 "WANNIER90| The full exported mesh is diagonalized for the Wannier90 files."
677 IF (
ASSOCIATED(qs_kpoint%xkp_input))
THEN
678 xkp_source => qs_kpoint%xkp_input
679 wkp_source => qs_kpoint%wkp_input
684 IF (.NOT.
ASSOCIATED(xkp_source) .OR. .NOT.
ASSOCIATED(wkp_source))
THEN
685 cpabort(
"Could not access the SCF GENERAL k-point set for the Wannier90 export.")
687 num_kpts =
SIZE(wkp_source)
688 ALLOCATE (kpt_latt(3, num_kpts))
689 kpt_latt(1:3, 1:num_kpts) = xkp_source(1:3, 1:num_kpts)
690 IF (mp_grid_explicit)
THEN
691 IF (mp_grid(1)*mp_grid(2)*mp_grid(3) /= num_kpts)
THEN
692 cpabort(
"WANNIER90%MP_GRID must contain exactly as many points as the SCF GENERAL mesh.")
695 CALL infer_wannier_mp_grid(kpt_latt, mp_grid, mp_grid_valid)
696 IF (.NOT. mp_grid_valid)
THEN
697 cpabort(
"Could not infer WANNIER90%MP_GRID from the SCF GENERAL mesh.")
700 wkp_ref = 1.0_dp/real(num_kpts, kind=
dp)
702 IF (abs(wkp_source(i) - wkp_ref) > 1.0e-10_dp)
THEN
703 cpabort(
"WANNIER90%KPOINTS_SOURCE SCF requires equally weighted GENERAL k-points.")
706 kpoint%kp_scheme =
"GENERAL"
707 kpoint%symmetry = .false.
708 kpoint%nkp_grid(1:3) = mp_grid(1:3)
709 kpoint%verbose = .false.
710 kpoint%full_grid = .true.
711 kpoint%eps_geo = 1.0e-6_dp
712 kpoint%use_real_wfn = .false.
713 kpoint%parallel_group_size = para_env%num_pe
714 kpoint%nkp = num_kpts
715 ALLOCATE (kpoint%xkp(3, num_kpts), kpoint%wkp(num_kpts))
716 kpoint%xkp(1:3, 1:num_kpts) = xkp_source(1:3, 1:num_kpts)
717 kpoint%wkp(1:num_kpts) = wkp_ref
718 IF (input_kpoint_symmetry .AND. .NOT. input_full_grid .AND. iw > 0)
THEN
719 WRITE (iw,
'(T2,A)') &
720 "WANNIER90| SCF k-points are symmetry-reduced; using the full input GENERAL mesh."
721 IF (reuse_scf_mos)
THEN
722 WRITE (iw,
'(T2,A)') &
723 "WANNIER90| CP2K will try to reconstruct the full-mesh MOs from the SCF orbitals."
725 WRITE (iw,
'(T2,A)') &
726 "WANNIER90| The full exported mesh is diagonalized for the Wannier90 files."
731 cpabort(
"WANNIER90%KPOINTS_SOURCE SCF does not support this DFT%KPOINTS scheme.")
734 cpabort(
"Unknown WANNIER90%KPOINTS_SOURCE setting.")
738 CALL get_mo_set(mo_set=mos(ispin), nao=nao, nmo=num_bands_tot, nelectron=nelectron)
739 num_bands_tot = min(nao, num_bands_tot + nadd)
740 nscalar = num_bands_tot
741 IF (do_soc) num_bands_tot = 2*nscalar
742 ALLOCATE (keep_band(num_bands_tot))
745 ib = exclude_bands(i)
746 IF (ib < 1 .OR. ib > num_bands_tot) cpabort(
"WANNIER90%EXCLUDE_BANDS: index out of range.")
747 IF (ordered_berry .AND. .NOT. keep_band(ib))
THEN
748 cpabort(
"WANNIER90%EXCLUDE_BANDS: duplicate band index.")
750 keep_band(ib) = .false.
752 num_bands = count(keep_band)
753 IF (num_bands < 1 .OR. num_wann > num_bands)
THEN
754 cpabort(
"WANNIER90 EXCLUDE_BANDS leaves too few bands for WANNIER_FUNCTIONS.")
756 ALLOCATE (band_indices(num_bands))
757 band_indices(:) = pack([(i, i=1, num_bands_tot)], keep_band)
758 lowest_bands = num_bands < num_bands_tot .AND. all(band_indices == [(i, i=1, num_bands)])
759 IF (require_global_gap .AND. .NOT. lowest_bands)
THEN
760 cpabort(
"REQUIRE_GLOBAL_GAP needs a lowest-band prefix and an excluded band above it.")
763 IF (num_bands /= nelectron)
THEN
764 cpabort(
"Z2 requires one occupied spinor per electron; adjust EXCLUDE_BANDS.")
766 IF (num_bands == num_bands_tot .OR. mod(num_bands, 2) /= 0)
THEN
767 cpabort(
"Z2 needs an even occupied spinor subspace and at least one excluded conduction band.")
769 IF (any(band_indices /= [(i, i=1, num_bands)]))
THEN
770 cpabort(
"Z2 requires the lowest occupied spinor bands.")
774 IF (nntot /= 1) cpabort(
"WILSON_LOOP requires exactly one directed neighbour per point.")
775 ALLOCATE (loop_index(num_kpts))
778 DO WHILE (i <= num_kpts)
782 loop_index(i) = nloop
783 IF (nnlist(i, 1) == first_point)
EXIT
784 IF (nnlist(i, 1) /= i + 1 .OR. i == num_kpts)
THEN
785 cpabort(
"WILSON_LOOP requires contiguous ordered closed loops.")
791 ALLOCATE (wilson_product(num_bands, num_bands, nloop), loop_sv(nloop))
792 wilson_product = cmplx(0.0_dp, 0.0_dp,
dp)
794 wilson_product(i, i, :) = cmplx(1.0_dp, 0.0_dp,
dp)
797 ALLOCATE (wcc_out(num_bands, nloop))
799 ALLOCATE (wcc_out(0, 0))
801 ALLOCATE (link_matrix(num_bands, num_bands))
802 IF (initial_projections == 0 .AND. num_wann /= num_bands .AND. .NOT. ordered_berry)
THEN
803 cpabort(
"IDENTITY projections require WANNIER_FUNCTIONS to match the number of bands.")
805 IF (initial_projections >= 0 .AND. .NOT. ordered_berry .AND. num_wann < 1)
THEN
806 cpabort(
"Initial projections require a positive WANNIER_FUNCTIONS count.")
808 IF (any(window_set) .AND. num_wann == num_bands)
THEN
809 cpabort(
"Energy windows require more bands than Wannier functions.")
811 IF (any(window_set) .AND. num_wann < 1)
THEN
812 cpabort(
"Energy windows require a positive WANNIER_FUNCTIONS count.")
814 ALLOCATE (allowed_band(num_bands))
815 IF (any(window_set))
ALLOCATE (projection_eigenvalues(num_bands, num_kpts))
816 num_atoms =
SIZE(particle_set)
817 ALLOCATE (atoms_cart(3, num_atoms))
818 ALLOCATE (atom_symbols(num_atoms))
820 atoms_cart(1:3, i) = particle_set(i)%r(1:3)
822 atom_symbols(i) = asym
824 IF (kpoints_source < w90_kpoints_nnkp)
THEN
825 ALLOCATE (nnlist(num_kpts, num_nnmax), nncell(3, num_kpts, num_nnmax))
830 CALL wannier_setup(mp_grid, num_kpts, real_lattice, recip_lattice, &
831 kpt_latt, nntot, nnlist, nncell, iw)
833 CALL para_env%sum(nntot)
834 CALL para_env%sum(nnlist)
835 CALL para_env%sum(nncell)
838 IF (para_env%is_source() .AND. kpoints_source < w90_kpoints_nnkp)
THEN
840 WRITE (filename,
'(A,A)') trim(seed_name),
".win"
841 CALL open_file(filename, unit_number=iunit, file_status=
"REPLACE", file_action=
"WRITE")
844 WRITE (iunit,
"(A)")
"! Wannier90 input file generated by CP2K "
845 WRITE (iunit,
"(A,/)")
"! Creation date "//timestamp
847 WRITE (iunit,
"(A,I5)")
"num_wann = ", num_wann
848 IF (num_bands /= num_wann .OR. use_bloch_phases)
THEN
849 WRITE (iunit,
"(A,I5)")
"num_bands = ", num_bands
852 IF (window_set(i))
WRITE (iunit,
'(2A,ES24.16)') trim(window_keywords(i)),
' = ', energy_window(i)*
evolt
854 WRITE (iunit,
"(/,A,/)")
"length_unit = bohr"
855 WRITE (iunit,
"(/,A,/)")
"! System"
856 WRITE (iunit,
"(/,A)")
"begin unit_cell_cart"
857 WRITE (iunit,
"(A)")
"bohr"
859 WRITE (iunit,
"(3ES24.16)") cell%hmat(1:3, i)
861 WRITE (iunit,
"(A,/)")
"end unit_cell_cart"
862 WRITE (iunit,
"(/,A)")
"begin atoms_cart"
863 WRITE (iunit,
"(A)")
"bohr"
865 WRITE (iunit,
"(A,3F15.10)") atom_symbols(i), atoms_cart(1:3, i)
867 WRITE (iunit,
"(A,/)")
"end atoms_cart"
868 WRITE (iunit,
"(/,A,/)")
"! Kpoints"
869 WRITE (iunit,
"(/,A,3I6/)")
"mp_grid = ", mp_grid(1:3)
870 WRITE (iunit,
"(A)")
"begin kpoints"
872 WRITE (iunit,
"(3ES24.16)") kpt_latt(1:3, i)
874 WRITE (iunit,
"(A)")
"end kpoints"
882 IF (kpoints_source == w90_kpoints_mp_grid .AND. input_kpoint_symmetry .AND. iw > 0)
THEN
883 WRITE (iw,
'(T2,A)') &
884 "WANNIER90| Atomic k-point symmetry from the SCF calculation is not reused."
885 WRITE (iw,
'(T2,A)') &
886 "WANNIER90| A full Monkhorst-Pack grid is generated for the Wannier90 interface."
896 WRITE (unit=iw, fmt=
"(/,T2,A)")
"Start K-Point Calculation ..."
900 CALL get_qs_env(qs_env=qs_env_kp, para_env=para_env, blacs_env=blacs_env, mos=mos)
905 CALL get_qs_env(qs_env=qs_env_kp, sab_orb=sab_nl, dft_control=dft_control)
908 CALL get_qs_env(qs_env=qs_env_kp, matrix_ks_kp=matrix_ks, matrix_s_kp=matrix_s, &
909 scf_env=scf_env, scf_control=scf_control)
910 full_mesh_diagonalized = .false.
911 reused_scf_mos = .false.
913 aligned_degenerate_blocks = 0
914 aligned_degenerate_max_size = 0
915 aligned_degenerate_min_svalue = 0.0_dp
916 IF (reuse_scf_mos)
THEN
918 CALL do_general_diag_kp(matrix_ks, matrix_s, qs_kpoint, scf_env, scf_control, .false., &
920 IF (validate_reuse_scf_mos)
THEN
922 WRITE (iw,
'(T2,A)') &
923 "WANNIER90| Validating SCF MO reuse against a full-mesh diagonalization reference."
925 CALL do_general_diag_kp(matrix_ks, matrix_s, kpoint, scf_env, scf_control, .false., diis_step)
926 full_mesh_diagonalized = .true.
927 CALL save_wannier90_mo_snapshot(kpoint, ispin, para_env, reference_mo, reference_eigenvalues)
928 CALL diagnose_wannier90_scf_reuse_candidates(kpoint, qs_kpoint, matrix_s, matrix_ks, &
929 cell_to_index, sab_nl, para_env, iw, ispin, &
930 reuse_candidate_deviation, &
931 reuse_candidate_min_svalue, &
932 reuse_candidate_metric_deviation, &
933 reuse_candidate_residual)
934 IF (iw > 0 .AND. reuse_candidate_deviation < 1.0e100_dp)
THEN
935 WRITE (iw,
'(T2,A,ES10.3,A,ES10.3,A,ES10.3,A,ES10.3)') &
936 "WANNIER90| Best atom/AO candidate subspace deviation ", &
937 reuse_candidate_deviation,
", minimum singular value ", &
938 reuse_candidate_min_svalue,
", max metric deviation ", &
939 reuse_candidate_metric_deviation,
", max residual ", reuse_candidate_residual
943 sab_nl, para_env, reused_scf_mos, reuse_reason, &
944 aligned_degenerate_blocks, aligned_degenerate_max_size, &
945 aligned_degenerate_min_svalue, spin_channel=ispin)
946 IF (validate_reuse_scf_mos)
THEN
947 IF (reused_scf_mos)
THEN
948 CALL validate_wannier90_reused_mos(kpoint, matrix_s, cell_to_index, sab_nl, &
949 para_env, ispin, reference_mo, &
950 reference_eigenvalues, validate_reuse_ok, &
951 validation_subspace_deviation, validation_min_svalue, &
952 validation_eigenvalue_deviation)
954 WRITE (iw,
'(T2,A,ES10.3,A,ES10.3,A,ES10.3)') &
955 "WANNIER90| Reused MO validation: subspace deviation ", &
956 validation_subspace_deviation,
", minimum singular value ", &
957 validation_min_svalue,
", eigenvalue deviation ", &
958 validation_eigenvalue_deviation
960 IF (.NOT. validate_reuse_ok)
THEN
961 reused_scf_mos = .false.
962 WRITE (reuse_reason,
"(A,ES10.3,A,ES10.3)") &
963 "validation failed: dS=", &
964 validation_subspace_deviation,
", dE=", validation_eigenvalue_deviation
967 IF (.NOT. reused_scf_mos)
THEN
968 CALL restore_wannier90_mo_snapshot(kpoint, ispin, reference_mo, &
969 reference_eigenvalues)
973 IF (reused_scf_mos)
THEN
974 WRITE (iw,
'(T2,A)') &
975 "WANNIER90| Reused SCF MO coefficients for the Wannier90 full k-point mesh."
976 IF (use_bloch_phases)
THEN
977 IF (initial_projections == 0)
WRITE (iw,
'(T2,A)') &
978 "WANNIER90| Wrote identity projections for Bloch-phase complete band subspaces."
979 WRITE (iw,
'(T2,A,3F10.6)') &
980 "WANNIER90| Applied Bloch phase gauge to reused overlaps around fractional center", &
983 IF (aligned_degenerate_blocks > 0)
THEN
984 WRITE (iw,
'(T2,A,I0,A,I0,A,ES10.3)') &
985 "WANNIER90| Ritz-stabilized ", aligned_degenerate_blocks, &
986 " degenerate SCF MO subspace(s) with S(k),H(k); largest block has ", &
987 aligned_degenerate_max_size,
" band(s), min metric eigenvalue ", &
988 aligned_degenerate_min_svalue
991 WRITE (iw,
'(T2,A,A)') &
992 "WANNIER90| Could not reuse SCF MOs: ", trim(reuse_reason)
993 WRITE (iw,
'(T2,A)') &
994 "WANNIER90| Falling back to full-mesh diagonalization for the Wannier90 files."
998 IF (.NOT. reused_scf_mos .AND. .NOT. full_mesh_diagonalized)
THEN
999 CALL do_general_diag_kp(matrix_ks, matrix_s, kpoint, scf_env, scf_control, .false., diis_step)
1001 IF (
ALLOCATED(reference_mo))
DEALLOCATE (reference_mo)
1002 IF (
ALLOCATED(reference_eigenvalues))
DEALLOCATE (reference_eigenvalues)
1005 WRITE (iw,
'(T69,A)')
"... Finished"
1012 ALLOCATE (nblist(num_kpts, nntot))
1013 ALLOCATE (b_latt(3, num_kpts*nntot))
1018 bvec(1:3) = kpt_latt(1:3, nnlist(ik, i)) - kpt_latt(1:3, ik) + nncell(1:3, ik, i)
1021 IF (sum(abs(bvec(1:3) - b_latt(1:3, k))) < 1.e-6_dp)
THEN
1025 IF (sum(abs(bvec(1:3) + b_latt(1:3, k))) < 1.e-6_dp)
THEN
1036 b_latt(1:3, nbs) = bvec(1:3)
1042 overlap_nl => sab_nl
1043 NULLIFY (berry_kpoint)
1044 IF (ordered_berry)
THEN
1045 CALL get_qs_env(qs_env_kp, sab_all=overlap_nl)
1050 IF (.NOT.
ASSOCIATED(overlap_nl)) cpabort(
"Explicit overlaps require k-point neighbour lists.")
1051 ALLOCATE (berry_matrix(nbs))
1053 NULLIFY (berry_matrix(i)%cosmat)
1054 NULLIFY (berry_matrix(i)%sinmat)
1055 bvec(1:3) = -
twopi*matmul(transpose(cell%h_inv(1:3, 1:3)), b_latt(1:3, i))
1057 berry_matrix(i)%sinmat, bvec, ordered=ordered_berry, ordered_kpoints=berry_kpoint)
1060 kp => kpoint%kp_env(1)%kpoint_env
1062 IF (ordered_berry .AND. nmo /= nscalar)
THEN
1063 cpabort(
"WANNIER90: unexpected orbital count in export.")
1065 NULLIFY (matrix_struct_ao, matrix_struct_work)
1068 para_env=para_env, &
1075 para_env=para_env, &
1081 NULLIFY (matrix_struct_mmn)
1084 para_env=para_env, &
1088 ALLOCATE (rmatrix_full, cmatrix_full)
1089 CALL dbcsr_create(rmatrix_full, template=matrix_s(1, 1)%matrix, &
1090 matrix_type=dbcsr_type_no_symmetry)
1091 CALL dbcsr_create(cmatrix_full, template=matrix_s(1, 1)%matrix, &
1092 matrix_type=dbcsr_type_no_symmetry)
1093 IF (ordered_berry)
THEN
1094 ALLOCATE (loop_real, loop_imag)
1095 CALL dbcsr_create(loop_real, template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_no_symmetry)
1096 CALL dbcsr_create(loop_imag, template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_no_symmetry)
1107 NULLIFY (cmo_coeff_source)
1108 IF (do_soc .OR. do_parity)
THEN
1110 ALLOCATE (rmatrix, cmatrix)
1111 CALL dbcsr_create(rmatrix, template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
1112 CALL dbcsr_create(cmatrix, template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_antisymmetric)
1118 cpassert(all(kpoint%kp_range == [1, num_kpts]))
1119 NULLIFY (soc_matrices)
1121 ALLOCATE (soc_xyz(nmo, nmo, 3), soc_h(2*nmo, 2*nmo), soc_u(2*nmo, 2*nmo))
1122 ALLOCATE (scalar_values(2*nmo), spinor_values(2*nmo, num_kpts))
1123 ALLOCATE (spinor_coeff(2*nmo, num_bands, num_kpts), scalar_overlap(nmo, nmo))
1125 kp => kpoint%kp_env(ik)%kpoint_env
1127 CALL get_mo_set(kp%mos(1), eigenvalues=eigenvalues)
1128 scalar_values(1:nmo) = eigenvalues(1:nmo)
1129 scalar_values(nmo + 1:) = eigenvalues(1:nmo)
1133 CALL rskp_transform(cmatrix, rmatrix, rsmat=soc_matrices, ispin=axis, &
1134 xkp=kpoint%xkp(:, ik), cell_to_index=cell_to_index, sab_nl=sab_nl)
1141 CALL parallel_gemm(
"N",
"N", nao, nmo, nao, cmplx(1.0_dp, 0.0_dp,
dp), &
1142 omat_cfm, fmk1_cfm, cmplx(0.0_dp, 0.0_dp,
dp), tmp_cfm)
1143 CALL parallel_gemm(
"C",
"N", nmo, nmo, nao, cmplx(1.0_dp, 0.0_dp,
dp), &
1144 fmk1_cfm, tmp_cfm, cmplx(0.0_dp, 0.0_dp,
dp), mmn_cfm)
1147 soc_h(1:nmo, 1:nmo) = soc_xyz(:, :, 3)
1148 soc_h(nmo + 1:, nmo + 1:) = -soc_xyz(:, :, 3)
1150 soc_h(1:nmo, nmo + 1:) = soc_xyz(:, :, 1) + cmplx(0.0_dp, 1.0_dp,
dp)*soc_xyz(:, :, 2)
1151 soc_h(nmo + 1:, 1:nmo) = soc_xyz(:, :, 1) - cmplx(0.0_dp, 1.0_dp,
dp)*soc_xyz(:, :, 2)
1153 soc_h(ib, ib) = soc_h(ib, ib) + scalar_values(ib)
1155 IF (maxval(abs(soc_h - conjg(transpose(soc_h)))) > 1.e-8_dp)
THEN
1156 IF (iw > 0)
WRITE (iw,
'(T2,A,I0,A,ES18.10)') &
1157 "TOPOLOGY| SOC Hermiticity error at point ", ik,
": ", &
1158 maxval(abs(soc_h - conjg(transpose(soc_h))))
1159 cpabort(
"WANNIER90 SOC: non-Hermitian second-variational Hamiltonian.")
1162 spinor_coeff(:, :, ik) = soc_u(:, band_indices)
1165 DEALLOCATE (soc_xyz, soc_h, soc_u, scalar_values)
1166 IF (iw > 0)
WRITE (iw,
'(T2,A,I0)')
"TOPOLOGY| Scalar bands in SOC second variation: ", nmo
1169 kp => kpoint%kp_env(1)%kpoint_env
1171 cpassert(nmo >= nscalar)
1172 ALLOCATE (eigval(merge(2*nmo, nmo, do_soc)))
1173 direct_gap = huge(1.0_dp)
1174 valence_max = -huge(1.0_dp)
1175 conduction_min = huge(1.0_dp)
1177 IF (para_env%is_source())
THEN
1178 WRITE (filename,
'(A,A)') trim(seed_name),
".eig"
1179 CALL open_file(filename, unit_number=iunit, file_status=
"REPLACE", file_action=
"WRITE")
1185 my_kpgrp = (ik >= kp_range(1) .AND. ik <= kp_range(2))
1187 eigval(:) = spinor_values(:, ik)
1188 ELSE IF (my_kpgrp)
THEN
1189 ikpgr = ik - kp_range(1) + 1
1190 kp => kpoint%kp_env(ikpgr)%kpoint_env
1191 CALL get_mo_set(kp%mos(ispin), eigenvalues=eigenvalues)
1192 eigval(1:nmo) = eigenvalues(1:nmo)
1194 eigval(1:nmo) = 0.0_dp
1196 IF (.NOT. do_soc)
CALL kpoint%para_env_inter_kp%sum(eigval)
1197 IF (.NOT. ordered_berry .AND. nexcl > 0)
THEN
1198 DO ib = 1, num_bands_tot - 1
1199 IF (keep_band(ib) .EQV. keep_band(ib + 1)) cycle
1201 kept_index = merge(ib, ib + 1, keep_band(ib))
1202 IF (eigval(kept_index) < energy_window(1) .OR. eigval(kept_index) > energy_window(2)) cycle
1203 IF (abs(eigval(ib + 1) - eigval(ib)) < 1.0e-8_dp)
THEN
1204 cpabort(
"WANNIER90 EXCLUDE_BANDS must retain or remove complete degenerate subspaces.")
1209 IF (lowest_bands)
THEN
1210 valence_max = max(valence_max, eigval(num_bands))
1211 conduction_min = min(conduction_min, eigval(num_bands + 1))
1213 DO ib = 1, num_bands_tot - 1
1214 IF (any(band_indices == ib) .NEQV. any(band_indices == ib + 1))
THEN
1215 pair_gap = eigval(ib + 1) - eigval(ib)
1216 direct_gap = min(direct_gap, pair_gap)
1220 eigval(:) = eigval*
evolt
1221 IF (any(window_set))
THEN
1222 projection_eigenvalues(:, ik) = eigval(band_indices)
1224 window_set, allowed_band)
1228 DO ib = 1, num_bands
1229 WRITE (iunit,
"(2I8,F24.14)") ib, ik, eigval(band_indices(ib))
1236 IF (initial_projections > 0 .OR. projection_candidates > 0)
THEN
1237 CALL build_wannier90_ao_projections(kpoint, matrix_s, sab_nl, para_env, ispin, band_indices, &
1238 reused_scf_mos .AND. use_bloch_phases, phase_center, ao_projections)
1240 CALL write_wannier90_amn(ao_projections, para_env, trim(seed_name)//
"_ao_candidates.amn")
1242 IF (initial_projections == 2 .OR. export_hybrids)
THEN
1243 CALL build_wannier90_hybrid_groups(qs_env, hybrid_groups)
1245 DEALLOCATE (hybrid_groups)
1246 IF (export_hybrids)
THEN
1247 CALL write_wannier90_amn(hybrid_projections, para_env, trim(seed_name)//
"_hybrid_candidates.amn")
1248 IF (iw > 0)
WRITE (iw,
'(T2,A,I0)') &
1249 "WANNIER90| Exported hybrid projection candidates ",
SIZE(hybrid_projections, 2)
1251 IF (initial_projections == 2)
THEN
1252 CALL move_alloc(hybrid_projections, ao_projections)
1253 IF (iw > 0)
WRITE (iw,
'(T2,A)')
"WANNIER90| Selecting from the full radial s/p hybrid candidate bank."
1255 DEALLOCATE (hybrid_projections)
1259 IF (.NOT. ordered_berry .AND. initial_projections >= 0)
THEN
1260 ALLOCATE (initial_amn(num_bands, num_wann, num_kpts))
1261 IF (initial_projections == 0)
THEN
1262 initial_amn(:, :, :) = cmplx(0.0_dp, 0.0_dp, kind=
dp)
1264 initial_amn(i, i, :) = cmplx(1.0_dp, 0.0_dp, kind=
dp)
1267 IF (para_env%is_source() .AND. any(window_set))
THEN
1270 window_set, allowed_band)
1271 DO ib = 1, num_bands
1272 IF (.NOT. allowed_band(ib)) ao_projections(ib, :, ik) = cmplx(0.0_dp, 0.0_dp,
dp)
1276 ALLOCATE (projection_pivots(num_wann))
1278 projection_min_svalue)
1280 WRITE (iw,
'(T2,A,ES12.4)')
"WANNIER90| Minimum projection singular value ", projection_min_svalue
1281 WRITE (iw,
'(T2,A,*(I6))')
"WANNIER90| Selected projection candidates ", projection_pivots
1283 IF (projection_min_svalue < 1.0e-10_dp)
THEN
1284 cpabort(
"No full-rank Wannier90 AO trial set was found on the entire k-point mesh.")
1286 DEALLOCATE (projection_pivots)
1288 CALL write_wannier90_amn(initial_amn, para_env, trim(seed_name)//
".amn")
1289 DEALLOCATE (initial_amn)
1291 IF (
ALLOCATED(ao_projections))
DEALLOCATE (ao_projections)
1292 IF (para_env%is_source())
THEN
1293 WRITE (filename,
'(A,A)') trim(seed_name),
".mmn"
1294 CALL open_file(filename, unit_number=iunit, file_status=
"REPLACE", file_action=
"WRITE")
1296 WRITE (iunit,
"(A)")
"! Wannier90 file generated by CP2K "//timestamp
1297 WRITE (iunit,
"(3I8)") num_bands, num_kpts, nntot
1304 my_kpgrp = (ik >= kpoint%kp_range(1) .AND. ik <= kpoint%kp_range(2))
1306 ikk = ik - kpoint%kp_range(1) + 1
1307 kp => kpoint%kp_env(ikk)%kpoint_env
1308 cmo_coeff_source => kp%mos(ispin)%cmo_coeff
1310 NULLIFY (cmo_coeff_source, kp)
1312 CALL wannier90_copy_cfm_general(cmo_coeff_source, fmk1_cfm, para_env)
1317 mygrp = (ik2 >= kpoint%kp_range(1) .AND. ik2 <= kpoint%kp_range(2))
1319 ikk = ik2 - kpoint%kp_range(1) + 1
1320 kp => kpoint%kp_env(ikk)%kpoint_env
1321 cmo_coeff_source => kp%mos(ispin)%cmo_coeff
1323 NULLIFY (cmo_coeff_source, kp)
1325 CALL wannier90_copy_cfm_general(cmo_coeff_source, fmk2_cfm, para_env)
1329 ksign = sign(1.0_dp, real(ibs, kind=
dp))
1331 IF (ordered_berry)
THEN
1338 CALL rskp_transform(rmatrix_full, cmatrix_full, berry_matrix(ibs)%cosmat, 1, &
1339 kpoint%xkp(:, ik2), berry_cell_index, overlap_nl)
1340 CALL rskp_transform(loop_real, loop_imag, berry_matrix(ibs)%sinmat, 1, &
1341 kpoint%xkp(:, ik2), berry_cell_index, overlap_nl, rs_sign=ksign)
1342 CALL dbcsr_add(rmatrix_full, loop_imag, 1.0_dp, -1.0_dp)
1343 CALL dbcsr_add(cmatrix_full, loop_real, 1.0_dp, 1.0_dp)
1345 CALL transform_wannier90_overlap(berry_matrix(ibs)%cosmat, berry_matrix(ibs)%sinmat, &
1346 ksign, kpoint%xkp(:, ik), kpoint%xkp(:, ik2), &
1347 cell_to_index, sab_nl, rmatrix_full, cmatrix_full)
1354 CALL parallel_gemm(
"N",
"N", nao, nmo, nao, cmplx(1.0_dp, 0.0_dp, kind=
dp), &
1355 omat_cfm, fmk2_cfm, cmplx(0.0_dp, 0.0_dp, kind=
dp), tmp_cfm)
1356 CALL parallel_gemm(
"C",
"N", nmo, nmo, nao, cmplx(1.0_dp, 0.0_dp, kind=
dp), &
1357 fmk1_cfm, tmp_cfm, cmplx(0.0_dp, 0.0_dp, kind=
dp), mmn_cfm)
1360 link_matrix(:, :) = matmul(conjg(transpose(spinor_coeff(1:nmo, :, ik))), &
1361 matmul(scalar_overlap, spinor_coeff(1:nmo, :, ik2))) + &
1362 matmul(conjg(transpose(spinor_coeff(nmo + 1:, :, ik))), &
1363 matmul(scalar_overlap, spinor_coeff(nmo + 1:, :, ik2)))
1367 IF (reused_scf_mos .AND. use_bloch_phases)
THEN
1369 gauge_arg =
twopi*dot_product(kpoint%xkp(1:3, ik2) - kpoint%xkp(1:3, ik), &
1371 gauge_real = cos(gauge_arg)
1372 gauge_imag = sin(gauge_arg)
1378 WRITE (iunit,
"(2I8,3I5)") ik, ik2, nncell(1:3, ik, i)
1380 DO ib2 = 1, num_bands
1381 DO ib1 = 1, num_bands
1383 rmmn = real(link_matrix(ib1, ib2),
dp)
1384 cmmn = aimag(link_matrix(ib1, ib2))
1387 rmmn = real(zmmn, kind=
dp)
1390 gauge_tmp = gauge_real*rmmn - gauge_imag*cmmn
1391 cmmn = gauge_imag*rmmn + gauge_real*cmmn
1393 link_matrix(ib1, ib2) = cmplx(rmmn, cmmn,
dp)
1395 WRITE (iunit,
"(2E30.14)") rmmn, cmmn
1400 iloop = loop_index(ik)
1401 CALL wilson_step(wilson_product(:, :, iloop), link_matrix, link_sv, status, 1.e-10_dp)
1402 IF (status /= 0)
THEN
1403 cpabort(
"Wilson link singular or SVD failed; refine sampling and check subspace.")
1405 loop_sv(iloop) = min(loop_sv(iloop), link_sv)
1411 IF (export_state .OR. do_parity)
THEN
1412 state_components = 1
1413 IF (do_soc) state_components = 2
1414 ALLOCATE (export_scalar(nao, nscalar), export_coeff(nao*state_components, num_bands))
1416 IF (export_state)
CALL topology_state_begin(qs_env_kp, trim(seed_name)//
".topology", nao, num_bands, num_kpts, &
1417 state_components, num_bands_tot, spin_channel, band_indices, state_unit)
1419 cpassert(all(kpoint%kp_range == [1, num_kpts]))
1420 ALLOCATE (parity_metric(nao, nao), parity_phase(nao), parity_map(nao), &
1421 parity_odd(2**tqc_dimension), ebr_coefficients(2, 2**tqc_dimension), &
1422 parity_energies(num_bands_tot))
1425 IF (num_bands /= nelectron .OR. mod(num_bands, 2) /= 0 .OR. &
1426 any(band_indices /= [(i, i=1, num_bands)]))
THEN
1427 cpabort(
"INVERSION_TQC requires the full occupied spinor band prefix.")
1432 kp => kpoint%kp_env(ik)%kpoint_env
1436 export_coeff(:nao, :) = matmul(export_scalar, spinor_coeff(:nscalar, :, ik))
1437 export_coeff(nao + 1:, :) = matmul(export_scalar, spinor_coeff(nscalar + 1:, :, ik))
1439 IF (do_parity) parity_energies(:) = spinor_values(:, ik)
1441 export_coeff(:, :) = export_scalar(:, band_indices)
1442 CALL get_mo_set(kp%mos(spin_channel), eigenvalues=eigenvalues)
1443 CALL topology_state_point(state_unit, ik, kpt_latt(:, ik), eigenvalues(:nscalar), export_coeff)
1444 IF (do_parity) parity_energies(:) = eigenvalues(:nscalar)
1446 IF (.NOT. do_parity) cycle
1447 parity_gap = huge(1.0_dp)
1448 DO jpar = 1, num_bands_tot
1449 IF (any(band_indices == jpar)) cycle
1450 parity_gap = min(parity_gap, minval(abs(parity_energies(band_indices) - parity_energies(jpar))))
1452 IF (num_bands == num_bands_tot .OR. parity_gap <= gap_tol)
THEN
1453 cpabort(
"PARITY requires an isolated selected subspace and computed excluded bands.")
1455 IF (maxval(abs(2*kpt_latt(:, ik) - nint(2*kpt_latt(:, ik)))) > 1.e-8_dp) cycle
1457 parity_phase, parity_tolerance, status)
1458 IF (status /= 0)
THEN
1459 cpabort(
"PARITY: inversion does not preserve geometry and atomic kinds.")
1463 CALL rskp_transform(rmatrix, cmatrix, rsmat=matrix_s, ispin=1, xkp=kpoint%xkp(:, ik), &
1464 cell_to_index=cell_to_index, sab_nl=sab_nl)
1472 parity_energies(band_indices), do_soc .AND. time_reversal, parity_tolerance, &
1473 parity_energy_tolerance, counts, parity_error, parity_energy_error, status, parity_checks)
1475 WRITE (iw,
'(T2,A,3F10.5,A,2I8,A,3ES14.5)')
'TQC| TRIM ', kpt_latt(:, ik), &
1476 ' even/odd states ', counts,
' residuals/gap ', parity_error, parity_energy_error, parity_gap
1477 WRITE (iw,
'(T2,A,4ES14.5)')
'TQC| Metric/normalization/inversion/TR residuals: ', parity_checks
1479 IF (status /= 0)
THEN
1480 cpabort(
"PARITY: metric, subspace or symmetry representation check failed.")
1482 IF (tqc_dimension == 2 .AND.
modulo(nint(2*kpt_latt(3, ik)), 2) /= 0) cycle
1484 DO axis = 1, tqc_dimension
1485 trim_id = trim_id + 2**(axis - 1)*
modulo(nint(2*kpt_latt(axis, ik)), 2)
1487 IF (parity_odd(trim_id) >= 0 .AND. parity_odd(trim_id) /= counts(2))
THEN
1488 cpabort(
"PARITY: repeated equivalent TRIM have inconsistent multiplicities.")
1490 parity_odd(trim_id) = counts(2)
1492 IF (state_unit > 0)
CALL close_file(state_unit)
1494 IF (all(parity_odd < 0))
THEN
1495 cpabort(
"PARITY requires a TRIM in the requested dimension.")
1499 IF (any(parity_odd < 0))
THEN
1500 cpabort(
"INVERSION_TQC requires all four (2D) or eight (3D) TRIM.")
1502 IF (any(mod(parity_odd, 2) /= 0))
THEN
1503 cpabort(
"INVERSION_TQC requires whole odd-parity Kramers pairs.")
1505 parity_odd(:) = parity_odd/2
1507 IF (status /= 0) cpabort(
"Invalid inversion indicator data.")
1509 ebr_coefficients, status)
1510 IF (status /= 0) cpabort(
"Invalid inversion EBR data.")
1512 WRITE (iw,
'(T2,A,I0)')
'TQC| Inversion-subgroup dimension: ', tqc_dimension
1513 WRITE (iw,
'(T2,A,I0)')
'TQC| Fu-Kane parity index: ', strong
1514 IF (tqc_dimension == 3)
THEN
1515 WRITE (iw,
'(T2,A,3I3)')
'TQC| Weak parity indices: ', weak
1516 WRITE (iw,
'(T2,A,I0)')
'TQC| Inversion Z4 (sum odd pairs mod 4): ', z4
1518 WRITE (iw,
'(T2,A,L1)')
'TQC| Signed atomic signature: ', signed_atomic
1519 WRITE (iw,
'(T2,A,L1)')
'TQC| Nonnegative atomic signature: ', nonnegative_atomic
1520 IF (nonnegative_atomic)
THEN
1521 DO i = 1,
SIZE(parity_odd)
1522 WRITE (iw,
'(T2,A,I0,A,2I8)')
'TQC| Center bit index ', i - 1, &
1523 ' even/odd EBR pairs ', ebr_coefficients(:, i)
1525 WRITE (iw,
'(T2,A)')
'TQC| Atomic-compatible symmetry signature; not a proof of trivial topology.'
1526 ELSE IF (signed_atomic)
THEN
1527 WRITE (iw,
'(T2,A)')
'TQC| Nonnegative EBR obstruction; '// &
1528 'exclude hidden stable topology before calling it fragile.'
1530 WRITE (iw,
'(T2,A)')
'TQC| Stable inversion-symmetry indicator obstruction.'
1532 WRITE (iw,
'(T2,A)')
'TQC| TRIM checks do not establish a bulk gap; verify band isolation over the BZ.'
1533 WRITE (iw,
'(T2,A)')
'TQC| Converge the scalar-state basis used for second-variational SOC.'
1541 DEALLOCATE (berry_matrix)
1554 IF (do_soc .OR. do_parity)
THEN
1558 IF (ordered_berry)
THEN
1568 IF (iw > 0 .AND. num_bands < num_bands_tot)
WRITE (iw,
'(T2,A,ES18.10)') &
1569 "TOPOLOGY| Minimum sampled subspace gap [eV]: ", direct_gap*
evolt
1570 IF (direct_gap < gap_tol) cpabort(
"Wilson subspace is not isolated on the sampled points.")
1571 IF (lowest_bands)
THEN
1573 WRITE (iw,
'(T2,A,ES18.10)') &
1574 "TOPOLOGY| Maximum selected-band energy [eV]: ", valence_max*
evolt
1575 WRITE (iw,
'(T2,A,ES18.10)') &
1576 "TOPOLOGY| Minimum excluded-band energy [eV]: ", conduction_min*
evolt
1577 WRITE (iw,
'(T2,A,ES18.10)') &
1578 "TOPOLOGY| Sampled indirect gap [eV]: ", (conduction_min - valence_max)*
evolt
1579 IF (conduction_min - valence_max <= gap_tol)
WRITE (iw,
'(T2,A)') &
1580 "TOPOLOGY| Isolated band subspace, but no resolved common spectral gap on these samples."
1582 IF (require_global_gap .AND. conduction_min - valence_max <= gap_tol)
THEN
1583 cpabort(
"No positive sampled indirect gap above the selected bands.")
1587 CALL wilson_spectrum(wilson_product(:, :, iloop), wcc_out(:, iloop), berry_phase, status)
1588 IF (status /= 0) cpabort(
"Wilson eigenvalue calculation failed.")
1589 IF (iw > 0)
WRITE (iw,
'(T2,A,I0,A,F18.12,A,ES12.4)') &
1590 "TOPOLOGY| Loop ", iloop,
" Berry phase [rad]: ", berry_phase,
" min singular value: ", loop_sv(iloop)
1592 IF (para_env%is_source())
THEN
1593 CALL open_file(trim(seed_name)//
".wilson", unit_number=iunit, file_status=
"UNKNOWN", file_action=
"WRITE")
1594 WRITE (iunit,
'(A)')
"# loop, minimum link singular value, sorted WCC (arg(lambda)/(2*pi))"
1596 WRITE (iunit,
'(I8,*(1X,ES24.16))') iloop, loop_sv(iloop), wcc_out(:, iloop)
1601 CALL z2_from_wcc(wcc_out, z2_value, status, 1.e-5_dp)
1602 IF (status /= 0 .AND. iw > 0)
WRITE (iw,
'(T2,A,I0)') &
1603 "TOPOLOGY| Kramers/crossing check requests refinement, status: ", status
1604 IF (iw > 0)
WRITE (iw,
'(T2,A,I0)')
"TOPOLOGY| Z2 candidate (before sampling convergence): ", z2_value
1607 CALL chern_from_wcc(wcc_out, chern_value, chern_winding, status, 1.e-5_dp)
1608 IF (status /= 0)
THEN
1609 chern_value = huge(0)
1610 IF (iw > 0)
WRITE (iw,
'(T2,A,I0)') &
1611 "TOPOLOGY| Chern closure/winding check requests refinement, status: ", status
1612 ELSE IF (iw > 0)
THEN
1613 WRITE (iw,
'(T2,A,I0,A,F18.12)') &
1614 "TOPOLOGY| First Chern candidate: ", chern_value,
", winding: ", chern_winding
1620 DEALLOCATE (kpt_latt, atoms_cart, atom_symbols, eigval)
1621 DEALLOCATE (nnlist, nncell)
1622 DEALLOCATE (nblist, b_latt)
1623 IF (para_env%is_source())
THEN
1625 CALL open_file(trim(seed_name)//
'_band_indices.dat', unit_number=iunit, &
1626 file_status=
'REPLACE', file_action=
'WRITE')
1627 WRITE (iunit,
'(A)')
'# Exported band, original MO index (before EXCLUDE_BANDS)'
1628 DO ib = 1, num_bands
1629 WRITE (iunit,
'(2I10)') ib, band_indices(ib)
1633 IF (nexcl > 0)
DEALLOCATE (exclude_bands)
1634 DEALLOCATE (band_indices, keep_band, allowed_band)
1635 IF (
ALLOCATED(projection_eigenvalues))
DEALLOCATE (projection_eigenvalues)
1636 IF (do_kpoints)
THEN
1640 DEALLOCATE (qs_env_kp)
1646 END SUBROUTINE wannier90_files
1665 sab_nl, para_env, success, reason, aligned_degenerate_blocks, &
1666 aligned_degenerate_max_size, aligned_degenerate_min_svalue, spin_channel)
1668 TYPE(
dbcsr_p_type),
POINTER :: matrix_s(:, :), matrix_ks(:, :)
1669 INTEGER,
POINTER :: cell_to_index(:, :, :)
1672 LOGICAL,
INTENT(OUT) :: success
1673 CHARACTER(LEN=*),
INTENT(OUT) :: reason
1674 INTEGER,
INTENT(OUT) :: aligned_degenerate_blocks, &
1675 aligned_degenerate_max_size
1676 REAL(kind=
dp),
INTENT(OUT) :: aligned_degenerate_min_svalue
1677 INTEGER,
INTENT(IN),
OPTIONAL :: spin_channel
1679 INTEGER :: blocks, first_spin, ispin, last_spin, &
1681 REAL(kind=
dp) :: min_svalue
1684 reason =
'Wannier90 export k-point MOs are not initialized'
1685 aligned_degenerate_blocks = 0
1686 aligned_degenerate_max_size = 0
1687 aligned_degenerate_min_svalue = 0.0_dp
1688 IF (.NOT.
ASSOCIATED(kpoint))
RETURN
1689 IF (.NOT.
ASSOCIATED(kpoint%kp_env))
RETURN
1690 IF (
SIZE(kpoint%kp_env) == 0)
RETURN
1692 last_spin =
SIZE(kpoint%kp_env(1)%kpoint_env%mos)
1693 IF (
PRESENT(spin_channel))
THEN
1694 cpassert(spin_channel >= 1 .AND. spin_channel <= last_spin)
1695 first_spin = spin_channel
1696 last_spin = spin_channel
1698 DO ispin = first_spin, last_spin
1699 CALL prepare_wannier90_spin_mos(kpoint, qs_kpoint, matrix_s, matrix_ks, cell_to_index, &
1700 sab_nl, para_env, ispin, success, reason, blocks, max_size, min_svalue)
1701 IF (.NOT. success)
RETURN
1702 IF (blocks > 0)
THEN
1703 IF (aligned_degenerate_blocks == 0) aligned_degenerate_min_svalue = min_svalue
1704 aligned_degenerate_min_svalue = min(aligned_degenerate_min_svalue, min_svalue)
1705 aligned_degenerate_blocks = aligned_degenerate_blocks + blocks
1706 aligned_degenerate_max_size = max(aligned_degenerate_max_size, max_size)
1727 SUBROUTINE prepare_wannier90_spin_mos(kpoint, qs_kpoint, matrix_s, matrix_ks, cell_to_index, &
1728 sab_nl, para_env, ispin, success, reason, aligned_degenerate_blocks, &
1729 aligned_degenerate_max_size, &
1730 aligned_degenerate_min_svalue)
1732 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s, matrix_ks
1733 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
1737 INTEGER,
INTENT(IN) :: ispin
1738 LOGICAL,
INTENT(OUT) :: success
1739 CHARACTER(LEN=*),
INTENT(OUT) :: reason
1740 INTEGER,
INTENT(OUT) :: aligned_degenerate_blocks, &
1741 aligned_degenerate_max_size
1742 REAL(kind=
dp),
INTENT(OUT) :: aligned_degenerate_min_svalue
1744 CHARACTER(LEN=default_string_length) :: best_reason, candidate_reason
1745 INTEGER :: aligned_blocks, aligned_max_size, candidate_aligned_blocks, &
1746 candidate_aligned_max_size, ik, ikpgr, ikred, isym_try, min_gap_band, min_gap_kpoint, &
1747 min_gap_spin, nao, nao_src, nmo, nmo_src, nsymmetry, num_candidates
1748 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: source_kpoint, sym_index
1749 INTEGER,
DIMENSION(2) :: kp_range, source_kp_range
1750 LOGICAL :: my_kpgrp, my_source_kpgrp, ok, &
1752 REAL(kind=
dp) :: aligned_min_svalue, band_gap, best_residual, candidate_residual, &
1753 degenerate_band_tol, local_min_band_gap, min_band_gap, source_owner_count, &
1754 source_window_min_svalue
1755 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigenvalues_buffer, occupation_buffer, &
1756 source_eigenvalues_buffer, &
1757 source_occupation_buffer
1758 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues, occupation
1760 TYPE(
cp_cfm_type) :: dst_cfm_full, src_cfm, src_cfm_full
1761 TYPE(
cp_cfm_type),
POINTER :: destination_cfm, source_cfm
1762 TYPE(
cp_cfm_type),
TARGET :: dst_cfm, empty_destination
1769 aligned_degenerate_blocks = 0
1770 aligned_degenerate_max_size = 0
1771 aligned_degenerate_min_svalue = huge(1.0_dp)
1772 NULLIFY (matrix_struct_source, matrix_struct_work)
1774 IF (.NOT.
ASSOCIATED(kpoint))
THEN
1775 reason =
"internal Wannier90 k-point object is not available"
1778 IF (.NOT.
ASSOCIATED(qs_kpoint))
THEN
1779 reason =
"SCF k-point object is not available"
1782 IF (.NOT.
ASSOCIATED(kpoint%kp_env) .OR. .NOT.
ASSOCIATED(qs_kpoint%kp_env))
THEN
1783 reason =
"k-point MO environments are not initialized"
1786 IF (.NOT.
ASSOCIATED(kpoint%blacs_env))
THEN
1787 reason =
"Wannier90 k-point BLACS environment is not initialized"
1791 CALL build_wannier90_scf_mapping(kpoint, qs_kpoint, source_kpoint, sym_index, ok, reason)
1792 IF (.NOT. ok)
RETURN
1793 nsymmetry = count(sym_index > 0)
1795 kp => kpoint%kp_env(1)%kpoint_env
1796 IF (.NOT.
ASSOCIATED(kp%mos(ispin)%cmo_coeff))
THEN
1797 reason =
"Wannier90 export k-point MOs are not complex-valued"
1798 DEALLOCATE (source_kpoint, sym_index)
1801 CALL get_mo_set(kp%mos(ispin), nao=nao, nmo=nmo)
1803 kp_source => qs_kpoint%kp_env(1)%kpoint_env
1804 IF (.NOT.
ASSOCIATED(kp_source%mos(ispin)%cmo_coeff))
THEN
1805 reason =
"SCF MOs are real-valued; complex symmetry phases cannot be reconstructed"
1806 DEALLOCATE (source_kpoint, sym_index)
1809 CALL get_mo_set(kp_source%mos(ispin), nao=nao_src, nmo=nmo_src)
1810 CALL para_env%max(nao_src)
1811 CALL para_env%max(nmo_src)
1812 IF (nao_src /= nao)
THEN
1813 reason =
"SCF and Wannier90 MO bases have different AO dimensions"
1814 DEALLOCATE (source_kpoint, sym_index)
1817 IF (nmo_src < nmo)
THEN
1818 reason =
"SCF MO set has fewer bands than the Wannier90 export"
1819 DEALLOCATE (source_kpoint, sym_index)
1822 source_window = nmo_src > nmo
1823 degenerate_band_tol = 1.0e-8_dp
1825 IF (source_kp_range(1) /= 1 .OR. source_kp_range(2) /= qs_kpoint%nkp)
THEN
1826 reason =
"SCF k-point symmetry data are distributed over k-point parallel groups"
1827 DEALLOCATE (source_kpoint, sym_index)
1833 IF (nsymmetry > 0 .AND. nmo_src > nmo)
THEN
1834 local_min_band_gap = huge(1.0_dp)
1838 DO ikred = source_kp_range(1), source_kp_range(2)
1839 ikpgr = ikred - source_kp_range(1) + 1
1840 kp_source => qs_kpoint%kp_env(ikpgr)%kpoint_env
1841 CALL get_mo_set(kp_source%mos(ispin), eigenvalues=eigenvalues)
1842 band_gap = abs(eigenvalues(nmo + 1) - eigenvalues(nmo))
1843 IF (band_gap < local_min_band_gap)
THEN
1844 local_min_band_gap = band_gap
1846 min_gap_kpoint = ikred
1847 min_gap_spin = ispin
1850 min_band_gap = local_min_band_gap
1851 CALL para_env%min(min_band_gap)
1852 IF (abs(local_min_band_gap - min_band_gap) > degenerate_band_tol*epsilon(1.0_dp))
THEN
1856 CALL para_env%max(min_gap_kpoint)
1857 CALL para_env%max(min_gap_spin)
1858 CALL para_env%max(min_gap_band)
1859 IF (min_band_gap < degenerate_band_tol)
THEN
1860 WRITE (reason,
"(A,ES9.2,A,I0,A,I0,A,I0)") &
1861 "degenerate atom/AO W90 reuse guarded: edge gap=", min_band_gap,
", k=", &
1862 min_gap_kpoint,
", s=", min_gap_spin,
", nband=", min_gap_band
1863 DEALLOCATE (source_kpoint, sym_index)
1867 blacs_env => kpoint%blacs_env
1869 para_env=para_env, context=blacs_env)
1872 IF (source_window)
THEN
1874 para_env=para_env, context=blacs_env)
1878 ALLOCATE (eigenvalues_buffer(nmo), occupation_buffer(nmo), &
1879 source_eigenvalues_buffer(nmo_src), source_occupation_buffer(nmo_src))
1884 DO ik = 1, kpoint%nkp
1885 ikred = source_kpoint(ik)
1886 my_kpgrp = (ik >= kp_range(1) .AND. ik <= kp_range(2))
1887 my_source_kpgrp = (ikred >= source_kp_range(1) .AND. ikred <= source_kp_range(2))
1888 source_eigenvalues_buffer(1:nmo_src) = 0.0_dp
1889 source_occupation_buffer(1:nmo_src) = 0.0_dp
1890 NULLIFY (source_cfm)
1891 IF (my_source_kpgrp)
THEN
1892 ikpgr = ikred - source_kp_range(1) + 1
1893 kp_source => qs_kpoint%kp_env(ikpgr)%kpoint_env
1894 source_cfm => kp_source%mos(ispin)%cmo_coeff
1895 CALL get_mo_set(kp_source%mos(ispin), eigenvalues=eigenvalues, &
1896 occupation_numbers=occupation)
1897 source_eigenvalues_buffer(1:nmo_src) = eigenvalues(1:nmo_src)
1898 source_occupation_buffer(1:nmo_src) = occupation(1:nmo_src)
1900 IF (source_window)
THEN
1901 CALL wannier90_copy_cfm_general(source_cfm, src_cfm_full, para_env)
1903 CALL wannier90_copy_cfm_general(source_cfm, src_cfm, para_env)
1905 IF (my_source_kpgrp)
THEN
1906 source_owner_count = 1.0_dp
1908 source_owner_count = 0.0_dp
1910 CALL para_env%sum(source_owner_count)
1911 CALL para_env%sum(source_eigenvalues_buffer)
1912 CALL para_env%sum(source_occupation_buffer)
1913 IF (source_owner_count > 0.0_dp)
THEN
1914 source_eigenvalues_buffer(1:nmo_src) = &
1915 source_eigenvalues_buffer(1:nmo_src)/source_owner_count
1916 source_occupation_buffer(1:nmo_src) = &
1917 source_occupation_buffer(1:nmo_src)/source_owner_count
1919 eigenvalues_buffer(1:nmo) = source_eigenvalues_buffer(1:nmo)
1920 occupation_buffer(1:nmo) = source_occupation_buffer(1:nmo)
1921 IF (source_window)
THEN
1928 aligned_max_size = 0
1929 aligned_min_svalue = 0.0_dp
1930 IF (sym_index(ik) > 0)
THEN
1931 kpsym => qs_kpoint%kp_sym(ikred)%kpoint_sym
1932 IF (
ASSOCIATED(
kpsym))
THEN
1934 best_residual = huge(1.0_dp)
1937 DO isym_try = 1,
kpsym%nwred
1939 kpsym%xkp(1:3, isym_try))) cycle
1940 num_candidates = num_candidates + 1
1942 qs_kpoint, ikred, isym_try, ok, &
1945 reason = candidate_reason
1948 CALL ritz_stabilize_wannier90_subspace(dst_cfm, matrix_s, matrix_ks, &
1949 kpoint%xkp(1:3, ik), cell_to_index, &
1950 sab_nl, ispin, eigenvalues_buffer, &
1951 degenerate_band_tol, ok, candidate_reason, &
1952 candidate_aligned_blocks, &
1953 candidate_aligned_max_size, &
1954 aligned_min_svalue, candidate_residual)
1955 IF (candidate_residual < best_residual)
THEN
1956 best_residual = candidate_residual
1957 best_reason = candidate_reason
1960 IF (source_window)
THEN
1962 ikred, isym_try, ok, candidate_reason)
1964 CALL ritz_reconstruct_wannier90_window(dst_cfm_full, dst_cfm, matrix_s, &
1965 matrix_ks, kpoint%xkp(1:3, ik), &
1966 cell_to_index, sab_nl, ispin, &
1967 eigenvalues_buffer, nmo, ok, &
1968 candidate_reason, source_window_min_svalue, &
1970 IF (candidate_residual < best_residual)
THEN
1971 best_residual = candidate_residual
1972 best_reason = candidate_reason
1976 CALL ritz_reconstruct_wannier90_window(dst_cfm, dst_cfm, matrix_s, matrix_ks, &
1977 kpoint%xkp(1:3, ik), cell_to_index, &
1978 sab_nl, ispin, eigenvalues_buffer, nmo, &
1979 ok, candidate_reason, source_window_min_svalue, &
1981 IF (candidate_residual < best_residual)
THEN
1982 best_residual = candidate_residual
1983 best_reason = candidate_reason
1988 aligned_blocks = candidate_aligned_blocks
1989 aligned_max_size = candidate_aligned_max_size
1990 sym_index(ik) = isym_try
1993 reason = candidate_reason
1995 IF (.NOT. ok .AND. num_candidates > 0 .AND. best_residual < huge(1.0_dp))
THEN
1996 WRITE (reason,
"(A,I0,A,ES9.2,A,I0,A,A32)") &
1997 "atom/AO W90 guarded: best/", num_candidates,
"=", best_residual, &
1998 " k=", ik,
" ", trim(best_reason)
1999 ELSE IF (.NOT. ok .AND. num_candidates == 0)
THEN
2000 reason =
"no matching SCF symmetry operation candidate"
2003 reason =
"SCF k-point symmetry operation is not available"
2007 ikred, sym_index(ik), ok, reason)
2009 IF (ok .AND. sym_index(ik) <= 0)
THEN
2012 CALL ritz_stabilize_wannier90_subspace(dst_cfm, matrix_s, matrix_ks, &
2013 kpoint%xkp(1:3, ik), cell_to_index, sab_nl, &
2014 ispin, eigenvalues_buffer, degenerate_band_tol, &
2015 ok, reason, aligned_blocks, aligned_max_size, &
2016 aligned_min_svalue, candidate_residual)
2017 IF (.NOT. ok .AND. source_window)
THEN
2019 ikred, sym_index(ik), ok, reason)
2021 CALL ritz_reconstruct_wannier90_window(dst_cfm_full, dst_cfm, matrix_s, matrix_ks, &
2022 kpoint%xkp(1:3, ik), cell_to_index, &
2023 sab_nl, ispin, eigenvalues_buffer, nmo, ok, &
2024 reason, source_window_min_svalue, &
2027 ELSE IF (.NOT. ok)
THEN
2028 CALL ritz_reconstruct_wannier90_window(dst_cfm, dst_cfm, matrix_s, matrix_ks, &
2029 kpoint%xkp(1:3, ik), &
2030 cell_to_index, sab_nl, ispin, &
2031 eigenvalues_buffer, nmo, ok, reason, &
2032 source_window_min_svalue, candidate_residual)
2039 IF (source_window)
THEN
2044 DEALLOCATE (source_kpoint, sym_index, eigenvalues_buffer, occupation_buffer, &
2045 source_eigenvalues_buffer, source_occupation_buffer)
2048 IF (sym_index(ik) /= 0)
THEN
2049 aligned_degenerate_blocks = aligned_degenerate_blocks + aligned_blocks
2050 aligned_degenerate_max_size = max(aligned_degenerate_max_size, aligned_max_size)
2051 IF (aligned_blocks > 0)
THEN
2052 aligned_degenerate_min_svalue = min(aligned_degenerate_min_svalue, aligned_min_svalue)
2057 ikpgr = ik - kp_range(1) + 1
2058 kp => kpoint%kp_env(ikpgr)%kpoint_env
2059 CALL get_mo_set(kp%mos(ispin), eigenvalues=eigenvalues, &
2060 occupation_numbers=occupation)
2061 eigenvalues(1:nmo) = eigenvalues_buffer(1:nmo)
2062 occupation(1:nmo) = occupation_buffer(1:nmo)
2063 destination_cfm => kp%mos(ispin)%cmo_coeff
2065 destination_cfm => empty_destination
2073 IF (source_window)
THEN
2078 DEALLOCATE (source_kpoint, sym_index, eigenvalues_buffer, occupation_buffer, &
2079 source_eigenvalues_buffer, source_occupation_buffer)
2080 IF (aligned_degenerate_blocks == 0) aligned_degenerate_min_svalue = 0.0_dp
2083 END SUBROUTINE prepare_wannier90_spin_mos
2093 SUBROUTINE save_wannier90_mo_snapshot(kpoint, ispin, para_env, mo, &
2094 eigenvalue_snapshot)
2096 INTEGER,
INTENT(IN) :: ispin
2098 COMPLEX(KIND=dp),
ALLOCATABLE, &
2099 DIMENSION(:, :, :),
INTENT(OUT) :: mo
2100 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :), &
2101 INTENT(OUT) :: eigenvalue_snapshot
2103 INTEGER :: ik, ikpgr, nao, nkp, nmo
2104 INTEGER,
DIMENSION(2) :: kp_range
2105 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: owner_weight
2106 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues
2110 kp => kpoint%kp_env(1)%kpoint_env
2111 CALL get_mo_set(kp%mos(ispin), nao=nao, nmo=nmo)
2112 ALLOCATE (mo(nao, nmo, nkp), &
2113 eigenvalue_snapshot(nmo, nkp), owner_weight(nkp))
2114 mo(:, :, :) = cmplx(0.0_dp, 0.0_dp, kind=
dp)
2115 eigenvalue_snapshot(:, :) = 0.0_dp
2116 owner_weight(:) = 0.0_dp
2117 DO ik = kp_range(1), kp_range(2)
2118 ikpgr = ik - kp_range(1) + 1
2119 kp => kpoint%kp_env(ikpgr)%kpoint_env
2121 CALL get_mo_set(kp%mos(ispin), eigenvalues=eigenvalues)
2122 eigenvalue_snapshot(1:nmo, ik) = eigenvalues(1:nmo)
2123 owner_weight(ik) = 1.0_dp
2125 CALL para_env%sum(mo)
2126 CALL para_env%sum(eigenvalue_snapshot)
2127 CALL para_env%sum(owner_weight)
2129 IF (owner_weight(ik) > 0.0_dp)
THEN
2130 mo(:, :, ik) = mo(:, :, ik)/owner_weight(ik)
2131 eigenvalue_snapshot(:, ik) = &
2132 eigenvalue_snapshot(:, ik)/owner_weight(ik)
2135 DEALLOCATE (owner_weight)
2137 END SUBROUTINE save_wannier90_mo_snapshot
2146 SUBROUTINE restore_wannier90_mo_snapshot(kpoint, ispin, mo, eigenvalue_snapshot)
2148 INTEGER,
INTENT(IN) :: ispin
2149 COMPLEX(KIND=dp),
DIMENSION(:, :, :),
INTENT(IN) :: mo
2150 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN) :: eigenvalue_snapshot
2152 INTEGER :: ik, ikpgr, nmo
2153 INTEGER,
DIMENSION(2) :: kp_range
2154 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues
2158 nmo =
SIZE(eigenvalue_snapshot, 1)
2159 DO ik = kp_range(1), kp_range(2)
2160 ikpgr = ik - kp_range(1) + 1
2161 kp => kpoint%kp_env(ikpgr)%kpoint_env
2163 CALL get_mo_set(kp%mos(ispin), eigenvalues=eigenvalues)
2164 eigenvalues(1:nmo) = eigenvalue_snapshot(1:nmo, ik)
2167 END SUBROUTINE restore_wannier90_mo_snapshot
2184 SUBROUTINE validate_wannier90_reused_mos(kpoint, matrix_s, cell_to_index, sab_nl, para_env, ispin, &
2185 reference_mo, reference_eigenvalues, &
2186 success, max_subspace_deviation, min_svalue, &
2187 max_eigenvalue_deviation)
2189 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s
2190 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
2194 INTEGER,
INTENT(IN) :: ispin
2195 COMPLEX(KIND=dp),
DIMENSION(:, :, :),
INTENT(IN) :: reference_mo
2196 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN) :: reference_eigenvalues
2197 LOGICAL,
INTENT(OUT) :: success
2198 REAL(kind=
dp),
INTENT(OUT) :: max_subspace_deviation, min_svalue, &
2199 max_eigenvalue_deviation
2201 REAL(kind=
dp),
PARAMETER :: eigenvalue_tol = 1.0e-8_dp, &
2202 subspace_tol = 1.0e-4_dp
2204 INTEGER :: ik, ikpgr, nao, nkp, nmo
2205 INTEGER,
DIMENSION(2) :: kp_range
2206 LOGICAL :: my_kpgrp, ok
2207 REAL(kind=
dp) :: candidate_deviation, candidate_svalue, &
2209 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigenvalue_buffer
2210 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues
2217 max_subspace_deviation = 0.0_dp
2218 min_svalue = huge(1.0_dp)
2219 max_eigenvalue_deviation = 0.0_dp
2220 NULLIFY (matrix_struct_work)
2223 kp => kpoint%kp_env(1)%kpoint_env
2224 CALL get_mo_set(kp%mos(ispin), nao=nao, nmo=nmo)
2225 cpassert(
SIZE(reference_mo, 1) == nao)
2226 cpassert(
SIZE(reference_mo, 2) == nmo)
2227 cpassert(
SIZE(reference_mo, 3) == nkp)
2229 matrix_struct_work => kp%mos(ispin)%cmo_coeff%matrix_struct
2232 ALLOCATE (eigenvalue_buffer(nmo))
2236 my_kpgrp = (ik >= kp_range(1) .AND. ik <= kp_range(2))
2237 NULLIFY (candidate_source)
2239 ikpgr = ik - kp_range(1) + 1
2240 kp => kpoint%kp_env(ikpgr)%kpoint_env
2241 candidate_source => kp%mos(ispin)%cmo_coeff
2242 CALL get_mo_set(kp%mos(ispin), eigenvalues=eigenvalues)
2243 eigenvalue_buffer(1:nmo) = eigenvalues(1:nmo)
2245 eigenvalue_buffer(1:nmo) = 0.0_dp
2247 CALL wannier90_copy_cfm_general(candidate_source, cand_cfm, para_env)
2249 owner_count = 1.0_dp
2251 owner_count = 0.0_dp
2253 CALL para_env%sum(owner_count)
2254 CALL para_env%sum(eigenvalue_buffer)
2255 IF (owner_count > 0.0_dp) eigenvalue_buffer(1:nmo) = eigenvalue_buffer(1:nmo)/owner_count
2256 max_eigenvalue_deviation = max(max_eigenvalue_deviation, &
2257 maxval(abs(eigenvalue_buffer(1:nmo) - &
2258 reference_eigenvalues(1:nmo, ik))))
2259 CALL measure_wannier90_subspace_error(ref_cfm, cand_cfm, matrix_s, &
2260 kpoint%xkp(1:3, ik), cell_to_index, sab_nl, para_env, &
2261 ok, candidate_deviation, candidate_svalue)
2263 max_subspace_deviation = huge(1.0_dp)
2265 max_subspace_deviation = max(max_subspace_deviation, candidate_deviation)
2266 min_svalue = min(min_svalue, candidate_svalue)
2269 CALL para_env%max(max_subspace_deviation)
2270 CALL para_env%min(min_svalue)
2271 CALL para_env%max(max_eigenvalue_deviation)
2272 success = max_subspace_deviation < subspace_tol .AND. max_eigenvalue_deviation < eigenvalue_tol
2274 DEALLOCATE (eigenvalue_buffer)
2278 END SUBROUTINE validate_wannier90_reused_mos
2296 SUBROUTINE diagnose_wannier90_scf_reuse_candidates(kpoint, qs_kpoint, matrix_s, matrix_ks, &
2297 cell_to_index, sab_nl, para_env, iw, ispin, &
2298 max_subspace_deviation, min_svalue, &
2299 max_metric_deviation, max_residual)
2301 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s, matrix_ks
2302 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
2306 INTEGER,
INTENT(IN) :: iw, ispin
2307 REAL(kind=
dp),
INTENT(OUT) :: max_subspace_deviation, min_svalue, &
2308 max_metric_deviation, max_residual
2310 REAL(kind=
dp),
PARAMETER :: print_tol = 1.0e-4_dp, &
2311 residual_print_tol = 1.0e-3_dp
2313 CHARACTER(LEN=default_string_length) :: reason
2314 INTEGER :: ik, ikpgr, ikred, isym_try, nao, &
2315 nao_src, nkp, nmo, nmo_src
2316 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: source_kpoint, sym_index
2317 INTEGER,
DIMENSION(2) :: kp_range, source_kp_range
2318 LOGICAL :: my_kpgrp, ok, source_window
2319 REAL(kind=
dp) :: best_deviation, best_metric_deviation, best_residual, best_svalue, &
2320 candidate_deviation, candidate_metric_deviation, candidate_metric_min, &
2321 candidate_residual, candidate_svalue, owner_count, ref_metric_deviation, ref_metric_min, &
2323 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigenvalues_buffer
2324 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues
2325 TYPE(
cp_cfm_type) :: dst_cfm, ref_cfm, src_cfm, src_cfm_full
2331 max_subspace_deviation = huge(1.0_dp)
2333 max_metric_deviation = huge(1.0_dp)
2334 max_residual = huge(1.0_dp)
2335 NULLIFY (matrix_struct_source, matrix_struct_work)
2337 CALL build_wannier90_scf_mapping(kpoint, qs_kpoint, source_kpoint, sym_index, ok, reason)
2338 IF (.NOT. ok)
RETURN
2339 kp => kpoint%kp_env(1)%kpoint_env
2340 kp_source => qs_kpoint%kp_env(1)%kpoint_env
2341 IF (.NOT.
ASSOCIATED(kp%mos(ispin)%cmo_coeff) .OR. &
2342 .NOT.
ASSOCIATED(kp_source%mos(ispin)%cmo_coeff))
THEN
2343 DEALLOCATE (source_kpoint, sym_index)
2346 CALL get_mo_set(kp%mos(ispin), nao=nao, nmo=nmo)
2347 CALL get_mo_set(kp_source%mos(ispin), nao=nao_src, nmo=nmo_src)
2348 CALL para_env%max(nao_src)
2349 CALL para_env%max(nmo_src)
2350 IF (nao_src /= nao .OR. nmo_src < nmo)
THEN
2351 DEALLOCATE (source_kpoint, sym_index)
2354 source_window = nmo_src > nmo
2357 IF (source_kp_range(1) /= 1 .OR. source_kp_range(2) /= qs_kpoint%nkp)
THEN
2358 DEALLOCATE (source_kpoint, sym_index)
2363 para_env=para_env, context=kpoint%blacs_env)
2367 ALLOCATE (eigenvalues_buffer(nmo))
2368 IF (source_window)
THEN
2370 para_env=para_env, context=kpoint%blacs_env)
2374 max_subspace_deviation = 0.0_dp
2375 min_svalue = huge(1.0_dp)
2376 max_metric_deviation = 0.0_dp
2377 max_residual = 0.0_dp
2379 my_kpgrp = (ik >= kp_range(1) .AND. ik <= kp_range(2))
2380 NULLIFY (source_cfm)
2382 ikpgr = ik - kp_range(1) + 1
2383 kp => kpoint%kp_env(ikpgr)%kpoint_env
2384 source_cfm => kp%mos(ispin)%cmo_coeff
2386 CALL wannier90_copy_cfm_general(source_cfm, ref_cfm, para_env)
2388 ikred = source_kpoint(ik)
2389 my_kpgrp = (ikred >= source_kp_range(1) .AND. ikred <= source_kp_range(2))
2390 NULLIFY (source_cfm)
2392 ikpgr = ikred - source_kp_range(1) + 1
2393 kp_source => qs_kpoint%kp_env(ikpgr)%kpoint_env
2394 source_cfm => kp_source%mos(ispin)%cmo_coeff
2395 CALL get_mo_set(kp_source%mos(ispin), eigenvalues=eigenvalues)
2396 eigenvalues_buffer(1:nmo) = eigenvalues(1:nmo)
2398 eigenvalues_buffer(1:nmo) = 0.0_dp
2400 IF (source_window)
THEN
2401 CALL wannier90_copy_cfm_general(source_cfm, src_cfm_full, para_env)
2403 CALL wannier90_copy_cfm_general(source_cfm, src_cfm, para_env)
2406 owner_count = 1.0_dp
2408 owner_count = 0.0_dp
2410 CALL para_env%sum(owner_count)
2411 CALL para_env%sum(eigenvalues_buffer)
2412 IF (owner_count > 0.0_dp) eigenvalues_buffer(1:nmo) = eigenvalues_buffer(1:nmo)/owner_count
2413 CALL measure_wannier90_eigenspace_quality(ref_cfm, matrix_s, matrix_ks, &
2414 kpoint%xkp(1:3, ik), cell_to_index, sab_nl, &
2415 para_env, ispin, eigenvalues_buffer, ok, &
2416 ref_metric_deviation, ref_metric_min, ref_residual)
2417 IF (ok .AND. para_env%is_source() .AND. iw > 0 .AND. &
2418 (ref_metric_deviation > print_tol .OR. ref_residual > residual_print_tol))
THEN
2419 WRITE (iw,
'(T2,A,I0,A,ES10.3,A,ES10.3,A,ES10.3)') &
2420 "WANNIER90| reference k=", ik,
" dM=", ref_metric_deviation, &
2421 " smin=", ref_metric_min,
" resid=", ref_residual
2423 IF (source_window)
THEN
2427 best_deviation = huge(1.0_dp)
2428 best_metric_deviation = 0.0_dp
2429 best_residual = 0.0_dp
2430 best_svalue = 0.0_dp
2431 IF (sym_index(ik) <= 0)
THEN
2433 ikred, sym_index(ik), ok, reason)
2435 CALL measure_wannier90_subspace_error(ref_cfm, dst_cfm, matrix_s, &
2436 kpoint%xkp(1:3, ik), cell_to_index, sab_nl, &
2437 para_env, ok, candidate_deviation, candidate_svalue)
2439 CALL measure_wannier90_eigenspace_quality(dst_cfm, matrix_s, matrix_ks, &
2440 kpoint%xkp(1:3, ik), cell_to_index, sab_nl, &
2441 para_env, ispin, eigenvalues_buffer, ok, &
2442 candidate_metric_deviation, &
2443 candidate_metric_min, candidate_residual)
2446 best_deviation = candidate_deviation
2447 best_metric_deviation = candidate_metric_deviation
2448 best_residual = candidate_residual
2449 best_svalue = candidate_svalue
2450 IF (para_env%is_source() .AND. iw > 0 .AND. &
2451 (candidate_deviation > print_tol .OR. candidate_metric_deviation > print_tol .OR. &
2452 candidate_residual > residual_print_tol))
THEN
2453 WRITE (iw,
'(T2,A,I0,A,I0,A,I0,A,ES10.3,A,ES10.3,A,ES10.3,A,ES10.3)') &
2454 "WANNIER90| reuse candidate k=", ik,
" src=", ikred,
" sym=", &
2455 sym_index(ik),
" dRef=", candidate_deviation,
" dM=", &
2456 candidate_metric_deviation,
" smin=", candidate_metric_min, &
2457 " resid=", candidate_residual
2461 ELSE IF (
ASSOCIATED(qs_kpoint%kp_sym))
THEN
2462 kpsym => qs_kpoint%kp_sym(ikred)%kpoint_sym
2463 IF (
ASSOCIATED(
kpsym))
THEN
2464 DO isym_try = 1,
kpsym%nwred
2466 kpsym%xkp(1:3, isym_try))) cycle
2468 qs_kpoint, ikred, isym_try, ok, reason)
2470 CALL measure_wannier90_subspace_error(ref_cfm, dst_cfm, &
2471 matrix_s, kpoint%xkp(1:3, ik), cell_to_index, &
2472 sab_nl, para_env, ok, candidate_deviation, &
2475 CALL measure_wannier90_eigenspace_quality(dst_cfm, matrix_s, matrix_ks, &
2476 kpoint%xkp(1:3, ik), cell_to_index, &
2477 sab_nl, para_env, ispin, &
2478 eigenvalues_buffer, ok, &
2479 candidate_metric_deviation, &
2480 candidate_metric_min, candidate_residual)
2482 IF (ok .AND. candidate_deviation < best_deviation)
THEN
2483 best_deviation = candidate_deviation
2484 best_metric_deviation = candidate_metric_deviation
2485 best_residual = candidate_residual
2486 best_svalue = candidate_svalue
2491 IF (best_deviation < huge(1.0_dp))
THEN
2492 max_subspace_deviation = max(max_subspace_deviation, best_deviation)
2493 min_svalue = min(min_svalue, best_svalue)
2494 max_metric_deviation = max(max_metric_deviation, best_metric_deviation)
2495 max_residual = max(max_residual, best_residual)
2498 CALL para_env%max(max_subspace_deviation)
2499 CALL para_env%min(min_svalue)
2500 CALL para_env%max(max_metric_deviation)
2501 CALL para_env%max(max_residual)
2503 IF (source_window)
THEN
2511 DEALLOCATE (eigenvalues_buffer)
2512 DEALLOCATE (source_kpoint, sym_index)
2514 END SUBROUTINE diagnose_wannier90_scf_reuse_candidates
2529 SUBROUTINE measure_wannier90_subspace_error(ref_cfm, cand_cfm, matrix_s, &
2530 xkp, cell_to_index, sab_nl, para_env, success, &
2531 max_subspace_deviation, min_svalue)
2532 TYPE(
cp_cfm_type),
INTENT(IN) :: ref_cfm, cand_cfm
2533 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s
2534 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: xkp
2535 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
2539 LOGICAL,
INTENT(OUT) :: success
2540 REAL(kind=
dp),
INTENT(OUT) :: max_subspace_deviation, min_svalue
2542 COMPLEX(KIND=dp),
ALLOCATABLE,
DIMENSION(:, :) :: metric_projected, metric_vectors, &
2543 overlap, ref_coeff, s_cand_coeff
2544 INTEGER :: ib, nao, nmo, nmo_candidate
2545 REAL(kind=
dp) :: singular_value
2546 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: metric_values
2551 max_subspace_deviation = huge(1.0_dp)
2553 NULLIFY (matrix_struct_metric)
2556 matrix_struct=matrix_struct_metric)
2558 IF (nmo_candidate /= nmo)
RETURN
2561 CALL apply_wannier90_kp_matrix(matrix_s, 1, xkp, cell_to_index, sab_nl, &
2564 ALLOCATE (ref_coeff(nao, nmo), s_cand_coeff(nao, nmo))
2568 ALLOCATE (overlap(nmo, nmo), &
2569 metric_projected(nmo, nmo), metric_vectors(nmo, nmo), metric_values(nmo))
2570 overlap(:, :) = matmul(conjg(transpose(ref_coeff)), s_cand_coeff)
2571 metric_projected(:, :) = matmul(conjg(transpose(overlap)), overlap)
2572 metric_projected(:, :) = 0.5_dp*(metric_projected + conjg(transpose(metric_projected)))
2573 CALL diag_complex(metric_projected, metric_vectors, metric_values)
2575 min_svalue = huge(1.0_dp)
2576 max_subspace_deviation = 0.0_dp
2578 singular_value = sqrt(max(metric_values(ib), 0.0_dp))
2579 min_svalue = min(min_svalue, singular_value)
2580 max_subspace_deviation = max(max_subspace_deviation, abs(singular_value - 1.0_dp))
2582 CALL para_env%max(max_subspace_deviation)
2583 CALL para_env%min(min_svalue)
2586 DEALLOCATE (ref_coeff, s_cand_coeff, overlap, metric_projected, metric_vectors, metric_values)
2589 END SUBROUTINE measure_wannier90_subspace_error
2607 SUBROUTINE measure_wannier90_eigenspace_quality(cand_cfm, matrix_s, matrix_ks, xkp, &
2608 cell_to_index, sab_nl, para_env, ispin, eigenvalues, &
2609 success, metric_deviation, min_metric_eigenvalue, &
2612 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s, matrix_ks
2613 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: xkp
2614 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
2618 INTEGER,
INTENT(IN) :: ispin
2619 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: eigenvalues
2620 LOGICAL,
INTENT(OUT) :: success
2621 REAL(kind=
dp),
INTENT(OUT) :: metric_deviation, min_metric_eigenvalue, &
2624 COMPLEX(KIND=dp),
ALLOCATABLE,
DIMENSION(:, :) :: h_coeff, metric_vectors, residual_block, &
2625 s_coeff, s_projected
2626 INTEGER :: ib, nao, nmo
2627 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: metric_values
2630 matrix_struct_projected
2633 metric_deviation = huge(1.0_dp)
2634 min_metric_eigenvalue = 0.0_dp
2635 residual_norm = huge(1.0_dp)
2636 NULLIFY (matrix_struct_metric, matrix_struct_projected)
2639 matrix_struct=matrix_struct_metric)
2640 IF (
SIZE(eigenvalues) < nmo)
RETURN
2645 CALL apply_wannier90_kp_matrix(matrix_s, 1, xkp, cell_to_index, sab_nl, &
2647 CALL apply_wannier90_kp_matrix(matrix_ks, ispin, xkp, cell_to_index, sab_nl, &
2650 ALLOCATE (h_coeff(nao, nmo), metric_vectors(nmo, nmo), &
2651 residual_block(nao, nmo), s_coeff(nao, nmo), s_projected(nmo, nmo), &
2656 para_env=matrix_struct_metric%para_env, &
2657 context=matrix_struct_metric%context)
2659 CALL parallel_gemm(
"C",
"N", nmo, nmo, nao, cmplx(1.0_dp, 0.0_dp, kind=
dp), cand_cfm, &
2660 s_cand, cmplx(0.0_dp, 0.0_dp, kind=
dp), metric_cfm)
2662 s_projected(:, :) = 0.5_dp*(s_projected + conjg(transpose(s_projected)))
2663 CALL diag_complex(s_projected, metric_vectors, metric_values)
2664 metric_deviation = maxval(abs(metric_values - 1.0_dp))
2665 min_metric_eigenvalue = minval(metric_values)
2667 residual_block(:, :) = h_coeff
2669 residual_block(:, ib) = residual_block(:, ib) - eigenvalues(ib)*s_coeff(:, ib)
2671 residual_norm = maxval(abs(residual_block))
2672 CALL para_env%max(metric_deviation)
2673 CALL para_env%min(min_metric_eigenvalue)
2674 CALL para_env%max(residual_norm)
2677 DEALLOCATE (h_coeff, metric_vectors, residual_block, s_coeff, s_projected, metric_values)
2683 END SUBROUTINE measure_wannier90_eigenspace_quality
2691 SUBROUTINE write_wannier90_amn(amn, para_env, filename)
2692 COMPLEX(KIND=dp),
INTENT(IN) :: amn(:, :, :)
2694 CHARACTER(LEN=*),
INTENT(IN) :: filename
2696 INTEGER :: ib, ik, iunit, iwann
2698 IF (.NOT. para_env%is_source())
RETURN
2699 CALL open_file(filename, unit_number=iunit, file_status=
'REPLACE', file_action=
'WRITE')
2700 WRITE (iunit,
'(A)')
'! Initial Wannier90 projections generated by CP2K'
2701 WRITE (iunit,
'(3I10)')
SIZE(amn, 1),
SIZE(amn, 3),
SIZE(amn, 2)
2702 DO ik = 1,
SIZE(amn, 3)
2703 DO iwann = 1,
SIZE(amn, 2)
2704 DO ib = 1,
SIZE(amn, 1)
2705 WRITE (iunit,
'(3I10,2ES24.16)') ib, iwann, ik, real(amn(ib, iwann, ik),
dp), &
2706 aimag(amn(ib, iwann, ik))
2711 END SUBROUTINE write_wannier90_amn
2718 SUBROUTINE build_wannier90_hybrid_groups(qs_env, groups)
2720 INTEGER,
ALLOCATABLE,
INTENT(OUT) :: groups(:, :)
2722 INTEGER :: iatom, ig, ikind, ip, is, iset, ishell, &
2723 n, ng, np, ns, nset, nsgf, offset, pass
2724 INTEGER,
ALLOCATABLE :: p_shells(:), s_shells(:)
2725 INTEGER,
POINTER :: first_sgf(:, :), l(:, :), nshell(:)
2730 CALL get_qs_env(qs_env, particle_set=particles, qs_kind_set=qs_kinds)
2735 DO iatom = 1,
SIZE(particles)
2737 CALL get_qs_kind(qs_kinds(ikind), basis_set=basis, nsgf=nsgf)
2738 IF (
ASSOCIATED(basis))
THEN
2739 CALL get_gto_basis_set(basis, nset=nset, nshell=nshell, l=l, first_sgf=first_sgf)
2740 ALLOCATE (s_shells(sum(nshell)), p_shells(sum(nshell)))
2744 DO ishell = 1, nshell(iset)
2745 n = offset + first_sgf(ishell, iset)
2746 SELECT CASE (l(ishell, iset))
2763 groups(:, ig) = [s_shells(is), n, n + 1, n + 2]
2767 DEALLOCATE (s_shells, p_shells)
2769 offset = offset + nsgf
2772 ALLOCATE (groups(4, ng))
2775 END SUBROUTINE build_wannier90_hybrid_groups
2789 SUBROUTINE build_wannier90_ao_projections(kpoint, matrix_s, sab_nl, para_env, ispin, bands, &
2790 apply_phase, phase_center, projections)
2795 INTEGER,
INTENT(IN) :: ispin, bands(:)
2796 LOGICAL,
INTENT(IN) :: apply_phase
2797 REAL(kind=
dp),
INTENT(IN) :: phase_center(3)
2798 COMPLEX(KIND=dp),
ALLOCATABLE,
INTENT(OUT) :: projections(:, :, :)
2800 COMPLEX(KIND=dp),
ALLOCATABLE :: buffer(:, :)
2801 INTEGER :: ik, iklocal, nao, nk, nmo
2802 INTEGER,
POINTER :: cell_to_index(:, :, :)
2803 REAL(kind=
dp) :: phase
2808 NULLIFY (matrix_struct, cell_to_index, source_cfm)
2809 CALL get_mo_set(kpoint%kp_env(1)%kpoint_env%mos(ispin), nao=nao, nmo=nmo)
2810 nk =
SIZE(kpoint%xkp, 2)
2813 para_env=para_env, context=kpoint%blacs_env)
2816 ALLOCATE (buffer(nmo, nao))
2817 IF (para_env%is_source())
THEN
2818 ALLOCATE (projections(
SIZE(bands), nao, nk))
2820 ALLOCATE (projections(0, 0, 0))
2823 IF (ik >= kpoint%kp_range(1) .AND. ik <= kpoint%kp_range(2))
THEN
2824 iklocal = ik - kpoint%kp_range(1) + 1
2825 source_cfm => kpoint%kp_env(iklocal)%kpoint_env%mos(ispin)%cmo_coeff
2827 NULLIFY (source_cfm)
2829 CALL wannier90_copy_cfm_general(source_cfm, mo_cfm, para_env)
2830 CALL apply_wannier90_kp_matrix(matrix_s, 1, kpoint%xkp(:, ik), cell_to_index, sab_nl, &
2833 IF (para_env%is_source())
THEN
2834 projections(:, :, ik) = conjg(buffer(bands, :))
2835 IF (apply_phase)
THEN
2837 phase = -
twopi*dot_product(kpoint%xkp(:, ik), phase_center)
2838 projections(:, :, ik) = projections(:, :, ik)*cmplx(cos(phase), sin(phase), kind=
dp)
2846 END SUBROUTINE build_wannier90_ao_projections
2860 SUBROUTINE transform_wannier90_overlap(cosmat, sinmat, bsign, kleft, kright, cell_to_index, &
2861 sab_nl, real_matrix, imag_matrix)
2862 TYPE(
dbcsr_p_type),
POINTER :: cosmat(:, :), sinmat(:, :)
2863 REAL(kind=
dp),
INTENT(IN) :: bsign, kleft(3), kright(3)
2864 INTEGER,
POINTER :: cell_to_index(:, :, :)
2866 TYPE(
dbcsr_type),
INTENT(INOUT) :: real_matrix, imag_matrix
2868 INTEGER :: direction, iatom, ic, icol, &
2869 image_cell(3), irow, jatom
2870 LOGICAL :: found, symmetric, transposed
2871 REAL(kind=
dp) :: ci, cr, phase
2872 REAL(kind=
dp),
POINTER :: cb(:, :), ib(:, :), rb(:, :), sb(:, :)
2882 ic = cell_to_index(image_cell(1), image_cell(2), image_cell(3))
2884 irow = min(iatom, jatom)
2885 icol = max(iatom, jatom)
2891 IF (direction == 1)
THEN
2894 transposed = iatom > jatom
2895 phase =
twopi*dot_product(kright, real(image_cell, kind=
dp))
2899 IF (iatom == jatom) cycle
2902 transposed = iatom < jatom
2903 phase = -
twopi*dot_product(kleft, real(image_cell, kind=
dp))
2911 IF (transposed)
THEN
2912 rb(:, :) = rb(:, :) + cr*transpose(cb) - bsign*ci*transpose(sb)
2913 ib(:, :) = ib(:, :) + ci*transpose(cb) + bsign*cr*transpose(sb)
2915 rb(:, :) = rb(:, :) + cr*cb(:, :) - bsign*ci*sb(:, :)
2916 ib(:, :) = ib(:, :) + ci*cb(:, :) + bsign*cr*sb(:, :)
2921 END SUBROUTINE transform_wannier90_overlap
2933 SUBROUTINE apply_wannier90_kp_matrix(rsmat, ispin, xkp, cell_to_index, sab_nl, &
2936 INTEGER,
INTENT(IN) :: ispin
2937 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: xkp
2938 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
2944 INTEGER :: nao, ncol
2948 TYPE(
dbcsr_type),
POINTER :: kmat_imag, kmat_imag_full, kmat_real, &
2951 NULLIFY (matrix_struct_ao, matrix_struct_coeff, kmat_imag, kmat_imag_full, kmat_real, &
2955 matrix_struct=matrix_struct_coeff)
2957 ALLOCATE (kmat_real, kmat_imag, kmat_real_full, kmat_imag_full)
2958 CALL dbcsr_create(kmat_real, template=rsmat(ispin, 1)%matrix, &
2959 matrix_type=dbcsr_type_symmetric)
2960 CALL dbcsr_create(kmat_imag, template=rsmat(ispin, 1)%matrix, &
2961 matrix_type=dbcsr_type_antisymmetric)
2962 CALL dbcsr_create(kmat_real_full, template=rsmat(ispin, 1)%matrix, &
2963 matrix_type=dbcsr_type_no_symmetry)
2964 CALL dbcsr_create(kmat_imag_full, template=rsmat(ispin, 1)%matrix, &
2965 matrix_type=dbcsr_type_no_symmetry)
2970 CALL rskp_transform(kmat_real, kmat_imag, rsmat=rsmat, ispin=ispin, &
2971 xkp=xkp, cell_to_index=cell_to_index, sab_nl=sab_nl)
2976 para_env=matrix_struct_coeff%para_env, &
2977 context=matrix_struct_coeff%context)
2985 CALL parallel_gemm(
"N",
"N", nao, ncol, nao, cmplx(1.0_dp, 0.0_dp, kind=
dp), kmat_cfm, &
2986 coeff, cmplx(0.0_dp, 0.0_dp, kind=
dp), result)
2997 END SUBROUTINE apply_wannier90_kp_matrix
3017 SUBROUTINE ritz_stabilize_wannier90_subspace(dst_cfm, matrix_s, matrix_ks, &
3018 xkp, cell_to_index, sab_nl, ispin, eigenvalues, &
3019 degenerate_band_tol, success, reason, aligned_blocks, &
3020 aligned_max_size, aligned_min_svalue, max_residual)
3022 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s, matrix_ks
3023 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: xkp
3024 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
3027 INTEGER,
INTENT(IN) :: ispin
3028 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: eigenvalues
3029 REAL(kind=
dp),
INTENT(IN) :: degenerate_band_tol
3030 LOGICAL,
INTENT(OUT) :: success
3031 CHARACTER(LEN=*),
INTENT(OUT) :: reason
3032 INTEGER,
INTENT(OUT) :: aligned_blocks, aligned_max_size
3033 REAL(kind=
dp),
INTENT(OUT) :: aligned_min_svalue, max_residual
3035 REAL(kind=
dp),
PARAMETER :: residual_tol = 1.0e-2_dp
3037 COMPLEX(KIND=dp),
ALLOCATABLE,
DIMENSION(:, :) :: block_coeff, dst_coeff, h_block, h_coeff, &
3038 h_projected, h_projected_work, metric_vectors, residual_block, ritz_vectors, s_block, &
3039 s_coeff, s_projected, stabilized
3040 INTEGER :: block_first, block_last, block_size, ib, &
3042 REAL(kind=
dp) :: metric_deviation, norm_value, &
3044 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: metric_values, ritz_values
3051 aligned_max_size = 0
3052 aligned_min_svalue = huge(1.0_dp)
3053 max_residual = 0.0_dp
3055 NULLIFY (matrix_struct_metric)
3057 matrix_struct=matrix_struct_metric)
3058 IF (
SIZE(eigenvalues) < nmo)
THEN
3059 reason =
"not enough eigenvalues for Wannier90 Ritz subspace stabilization"
3066 stabilize_subspace: block
3067 CALL apply_wannier90_kp_matrix(matrix_s, 1, xkp, cell_to_index, sab_nl, &
3069 CALL apply_wannier90_kp_matrix(matrix_ks, ispin, xkp, cell_to_index, sab_nl, &
3072 ALLOCATE (dst_coeff(nao, nmo), s_coeff(nao, nmo), h_coeff(nao, nmo))
3078 DO WHILE (block_first <= nmo)
3079 block_last = block_first
3080 DO WHILE (block_last < nmo)
3081 IF (abs(eigenvalues(block_last + 1) - eigenvalues(block_last)) >= degenerate_band_tol)
EXIT
3082 block_last = block_last + 1
3084 block_size = block_last - block_first + 1
3085 IF (block_size > 1)
THEN
3089 ALLOCATE (block_coeff(nao, block_size), h_block(nao, block_size), &
3090 h_projected(block_size, block_size), h_projected_work(block_size, block_size), &
3091 metric_vectors(block_size, block_size), residual_block(nao, block_size), &
3092 ritz_vectors(block_size, block_size), s_block(nao, block_size), &
3093 s_projected(block_size, block_size), stabilized(nao, block_size), &
3094 metric_values(block_size), ritz_values(block_size))
3095 block_coeff(:, :) = dst_coeff(:, block_first:block_last)
3096 s_block(:, :) = s_coeff(:, block_first:block_last)
3097 h_block(:, :) = h_coeff(:, block_first:block_last)
3098 s_projected(:, :) = matmul(conjg(transpose(block_coeff)), s_block)
3099 h_projected(:, :) = matmul(conjg(transpose(block_coeff)), h_block)
3100 s_projected(:, :) = 0.5_dp*(s_projected + conjg(transpose(s_projected)))
3101 h_projected(:, :) = 0.5_dp*(h_projected + conjg(transpose(h_projected)))
3103 CALL diag_complex(s_projected, metric_vectors, metric_values)
3104 aligned_min_svalue = min(aligned_min_svalue, minval(metric_values))
3105 metric_deviation = maxval(abs(metric_values - 1.0_dp))
3106 IF (minval(metric_values) < 1.0e-10_dp)
THEN
3107 WRITE (reason,
"(A,I0,A,ES9.2,A,ES9.2)") &
3108 "singular metric blk=", block_first,
" smin=", minval(metric_values), &
3109 " dS=", metric_deviation
3110 max_residual = huge(1.0_dp)
3111 EXIT stabilize_subspace
3114 DO ib = 1, block_size
3115 metric_vectors(:, ib) = metric_vectors(:, ib)/sqrt(metric_values(ib))
3117 h_projected_work(:, :) = matmul(h_projected, metric_vectors)
3118 h_projected(:, :) = matmul(conjg(transpose(metric_vectors)), h_projected_work)
3119 h_projected(:, :) = 0.5_dp*(h_projected + conjg(transpose(h_projected)))
3120 CALL diag_complex(h_projected, ritz_vectors, ritz_values)
3121 h_projected_work(:, :) = matmul(metric_vectors, ritz_vectors)
3122 ritz_vectors(:, :) = h_projected_work
3123 stabilized(:, :) = matmul(block_coeff, ritz_vectors)
3124 residual_block(:, :) = matmul(h_block, ritz_vectors)
3125 h_block(:, :) = residual_block
3126 residual_block(:, :) = matmul(s_block, ritz_vectors)
3127 s_block(:, :) = residual_block
3128 DO ib = 1, block_size
3129 norm_value = sqrt(abs(real(dot_product(stabilized(:, ib), s_block(:, ib)), kind=
dp)))
3130 IF (norm_value > epsilon(1.0_dp))
THEN
3131 stabilized(:, ib) = stabilized(:, ib)/norm_value
3132 h_block(:, ib) = h_block(:, ib)/norm_value
3133 s_block(:, ib) = s_block(:, ib)/norm_value
3136 residual_block(:, :) = h_block
3137 DO ib = 1, block_size
3138 residual_block(:, ib) = residual_block(:, ib) - &
3139 eigenvalues(block_first + ib - 1)*s_block(:, ib)
3141 residual_norm = maxval(abs(residual_block))
3142 max_residual = max(max_residual, residual_norm)
3143 IF (residual_norm > residual_tol)
THEN
3144 WRITE (reason,
"(A,I0,A,ES9.2)") &
3145 "blk=", block_first,
" dS=", metric_deviation
3146 EXIT stabilize_subspace
3149 dst_coeff(:, block_first:block_last) = stabilized
3150 h_coeff(:, block_first:block_last) = h_block
3151 s_coeff(:, block_first:block_last) = s_block
3152 aligned_blocks = aligned_blocks + 1
3153 aligned_max_size = max(aligned_max_size, block_size)
3154 DEALLOCATE (block_coeff, h_block, h_projected, h_projected_work, metric_vectors, &
3155 residual_block, ritz_vectors, s_block, s_projected, stabilized, metric_values, &
3158 block_first = block_last + 1
3162 residual_norm = maxval(abs(h_coeff(:, ib) - eigenvalues(ib)*s_coeff(:, ib)))
3163 max_residual = max(max_residual, residual_norm)
3165 IF (max_residual > residual_tol)
THEN
3166 WRITE (reason,
"(A,ES10.3)") &
3167 "atom/AO W90 reuse guarded: Ritz residual=", max_residual
3168 EXIT stabilize_subspace
3173 IF (aligned_blocks == 0) aligned_min_svalue = 0.0_dp
3175 END BLOCK stabilize_subspace
3180 END SUBROUTINE ritz_stabilize_wannier90_subspace
3199 SUBROUTINE ritz_reconstruct_wannier90_window(src_cfm, dst_cfm, matrix_s, &
3200 matrix_ks, xkp, cell_to_index, sab_nl, ispin, &
3201 eigenvalues, nmo_export, success, reason, min_svalue, &
3203 TYPE(cp_cfm_type),
INTENT(IN) :: src_cfm, dst_cfm
3204 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s, matrix_ks
3205 REAL(kind=dp),
DIMENSION(3),
INTENT(IN) :: xkp
3206 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
3207 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
3209 INTEGER,
INTENT(IN) :: ispin
3210 REAL(kind=dp),
DIMENSION(:),
INTENT(INOUT) :: eigenvalues
3211 INTEGER,
INTENT(IN) :: nmo_export
3212 LOGICAL,
INTENT(OUT) :: success
3213 CHARACTER(LEN=*),
INTENT(OUT) :: reason
3214 REAL(kind=dp),
INTENT(OUT) :: min_svalue, max_residual
3216 REAL(kind=dp),
PARAMETER :: eigenvalue_tol = 1.0e-6_dp, &
3217 residual_tol = 1.0e-7_dp
3219 COMPLEX(KIND=dp),
ALLOCATABLE,
DIMENSION(:, :) :: coeff_work, h_coeff, h_projected, &
3220 h_projected_work, metric_vectors, residual_block, ritz_vectors, s_coeff, s_projected, &
3221 source_coeff, stabilized
3222 INTEGER :: ib, nao, nmo_source
3223 REAL(kind=dp) :: max_eigenvalue_shift, metric_deviation, &
3225 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: metric_values, ritz_values, &
3227 TYPE(cp_cfm_type) :: h_src, s_src
3228 TYPE(cp_fm_struct_type),
POINTER :: matrix_struct_metric
3232 min_svalue = huge(1.0_dp)
3233 max_residual = huge(1.0_dp)
3235 NULLIFY (matrix_struct_metric)
3236 CALL cp_cfm_get_info(src_cfm, nrow_global=nao, ncol_global=nmo_source, &
3237 matrix_struct=matrix_struct_metric)
3238 IF (nmo_export > nmo_source)
THEN
3239 reason =
"Wannier90 export window is larger than the transformed SCF MO space"
3242 IF (
SIZE(eigenvalues) < nmo_export)
THEN
3243 reason =
"not enough eigenvalue storage for Wannier90 source-window reconstruction"
3247 CALL cp_cfm_create(s_src, matrix_struct_metric)
3248 CALL cp_cfm_create(h_src, matrix_struct_metric)
3250 CALL apply_wannier90_kp_matrix(matrix_s, 1, xkp, cell_to_index, sab_nl, &
3252 CALL apply_wannier90_kp_matrix(matrix_ks, ispin, xkp, cell_to_index, sab_nl, &
3255 ALLOCATE (source_coeff(nao, nmo_source), s_coeff(nao, nmo_source), &
3256 h_coeff(nao, nmo_source), h_projected(nmo_source, nmo_source), &
3257 h_projected_work(nmo_source, nmo_source), metric_vectors(nmo_source, nmo_source), &
3258 residual_block(nao, nmo_export), ritz_vectors(nmo_source, nmo_source), &
3259 s_projected(nmo_source, nmo_source), stabilized(nao, nmo_export), &
3260 coeff_work(nao, nmo_source), metric_values(nmo_source), ritz_values(nmo_source), &
3261 source_eigenvalues(nmo_export))
3262 source_eigenvalues(1:nmo_export) = eigenvalues(1:nmo_export)
3263 CALL cp_cfm_get_submatrix(src_cfm, source_coeff)
3264 CALL cp_cfm_get_submatrix(s_src, s_coeff)
3265 CALL cp_cfm_get_submatrix(h_src, h_coeff)
3266 s_projected(:, :) = matmul(conjg(transpose(source_coeff)), s_coeff)
3267 h_projected(:, :) = matmul(conjg(transpose(source_coeff)), h_coeff)
3268 s_projected(:, :) = 0.5_dp*(s_projected + conjg(transpose(s_projected)))
3269 h_projected(:, :) = 0.5_dp*(h_projected + conjg(transpose(h_projected)))
3271 reconstruct_window: block
3272 CALL diag_complex(s_projected, metric_vectors, metric_values)
3273 min_svalue = minval(metric_values)
3274 metric_deviation = maxval(abs(metric_values - 1.0_dp))
3275 IF (min_svalue < 1.0e-10_dp)
THEN
3276 WRITE (reason,
"(A,ES9.2,A,ES9.2)") &
3277 "singular expanded metric smin=", min_svalue,
" dS=", metric_deviation
3278 EXIT reconstruct_window
3281 DO ib = 1, nmo_source
3282 metric_vectors(:, ib) = metric_vectors(:, ib)/sqrt(metric_values(ib))
3284 h_projected_work(:, :) = matmul(h_projected, metric_vectors)
3285 h_projected(:, :) = matmul(conjg(transpose(metric_vectors)), h_projected_work)
3286 h_projected(:, :) = 0.5_dp*(h_projected + conjg(transpose(h_projected)))
3287 CALL diag_complex(h_projected, ritz_vectors, ritz_values)
3288 h_projected_work(:, :) = matmul(metric_vectors, ritz_vectors)
3289 ritz_vectors(:, :) = h_projected_work
3290 stabilized(:, :) = matmul(source_coeff, ritz_vectors(:, 1:nmo_export))
3291 coeff_work(:, :) = matmul(h_coeff, ritz_vectors)
3292 h_coeff(:, :) = coeff_work
3293 coeff_work(:, :) = matmul(s_coeff, ritz_vectors)
3294 s_coeff(:, :) = coeff_work
3295 DO ib = 1, nmo_export
3296 norm_value = sqrt(abs(real(dot_product(stabilized(:, ib), s_coeff(:, ib)), kind=dp)))
3297 IF (norm_value > epsilon(1.0_dp))
THEN
3298 stabilized(:, ib) = stabilized(:, ib)/norm_value
3299 h_coeff(:, ib) = h_coeff(:, ib)/norm_value
3300 s_coeff(:, ib) = s_coeff(:, ib)/norm_value
3303 residual_block(:, :) = h_coeff(:, 1:nmo_export)
3304 DO ib = 1, nmo_export
3305 residual_block(:, ib) = residual_block(:, ib) - ritz_values(ib)*s_coeff(:, ib)
3307 max_residual = maxval(abs(residual_block))
3308 IF (max_residual > residual_tol)
THEN
3309 WRITE (reason,
"(A,ES9.2)") &
3310 "expanded dS=", metric_deviation
3311 EXIT reconstruct_window
3313 max_eigenvalue_shift = maxval(abs(ritz_values(1:nmo_export) - source_eigenvalues(1:nmo_export)))
3314 IF (max_eigenvalue_shift > eigenvalue_tol)
THEN
3315 WRITE (reason,
"(A,ES9.2)") &
3316 "expanded dS=", metric_deviation
3317 EXIT reconstruct_window
3320 CALL cp_cfm_set_submatrix(dst_cfm, stabilized)
3323 END BLOCK reconstruct_window
3325 DEALLOCATE (source_coeff, s_coeff, h_coeff, h_projected, h_projected_work, metric_vectors, &
3326 residual_block, ritz_vectors, s_projected, stabilized, coeff_work, metric_values, &
3327 ritz_values, source_eigenvalues)
3328 CALL cp_cfm_release(s_src)
3329 CALL cp_cfm_release(h_src)
3331 END SUBROUTINE ritz_reconstruct_wannier90_window
3342 SUBROUTINE build_wannier90_scf_mapping(kpoint, qs_kpoint, source_kpoint, sym_index, success, &
3344 TYPE(kpoint_type),
POINTER :: kpoint, qs_kpoint
3345 INTEGER,
ALLOCATABLE,
DIMENSION(:),
INTENT(OUT) :: source_kpoint, sym_index
3346 LOGICAL,
INTENT(OUT) :: success
3347 CHARACTER(LEN=*),
INTENT(OUT) :: reason
3349 INTEGER :: ik, ikred, imatch, isym, nfull
3350 TYPE(kpoint_sym_type),
POINTER ::
kpsym
3355 ALLOCATE (source_kpoint(nfull), sym_index(nfull))
3356 source_kpoint(:) = 0
3359 DO ikred = 1, qs_kpoint%nkp
3360 imatch = find_matching_kpoint(kpoint%xkp, qs_kpoint%xkp(1:3, ikred))
3361 IF (imatch > 0 .AND. source_kpoint(imatch) == 0)
THEN
3362 source_kpoint(imatch) = ikred
3363 sym_index(imatch) = 0
3368 DO ikred = 1, qs_kpoint%nkp
3369 imatch = find_matching_kpoint(kpoint%xkp, -qs_kpoint%xkp(1:3, ikred))
3370 IF (imatch > 0 .AND. source_kpoint(imatch) == 0)
THEN
3371 source_kpoint(imatch) = ikred
3372 sym_index(imatch) = -1
3376 IF (
ASSOCIATED(qs_kpoint%kp_sym))
THEN
3377 DO ikred = 1, qs_kpoint%nkp
3378 kpsym => qs_kpoint%kp_sym(ikred)%kpoint_sym
3379 IF (.NOT.
ASSOCIATED(
kpsym)) cycle
3380 IF (.NOT.
kpsym%apply_symmetry) cycle
3381 DO isym = 1,
kpsym%nwred
3382 imatch = find_matching_kpoint(kpoint%xkp,
kpsym%xkp(1:3, isym))
3383 IF (imatch > 0 .AND. source_kpoint(imatch) == 0)
THEN
3384 source_kpoint(imatch) = ikred
3385 sym_index(imatch) = isym
3392 IF (source_kpoint(ik) == 0)
THEN
3393 reason =
"not all full-mesh k-points are represented by the SCF symmetry orbits"
3399 END SUBROUTINE build_wannier90_scf_mapping
3407 INTEGER FUNCTION find_matching_kpoint(xkp_mesh, xkp_search)
RESULT(ik_match)
3408 REAL(kind=dp),
DIMENSION(:, :),
INTENT(IN) :: xkp_mesh
3409 REAL(kind=dp),
DIMENSION(3),
INTENT(IN) :: xkp_search
3414 DO ik = 1,
SIZE(xkp_mesh, 2)
3415 IF (kpoint_same_periodic(xkp_mesh(1:3, ik), xkp_search))
THEN
3421 END FUNCTION find_matching_kpoint
3429 SUBROUTINE infer_wannier_mp_grid(kpt_latt, mp_grid, valid)
3430 REAL(kind=dp),
DIMENSION(:, :),
INTENT(IN) :: kpt_latt
3431 INTEGER,
DIMENSION(3),
INTENT(OUT) :: mp_grid
3432 LOGICAL,
INTENT(OUT) :: valid
3434 INTEGER :: coord_id, i, idim,
idx, n_unique, &
3435 num_kpts, stride, unique_id
3437 LOGICAL,
ALLOCATABLE,
DIMENSION(:) :: seen
3438 REAL(kind=dp) :: coord
3439 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :) :: unique_coord
3441 num_kpts =
SIZE(kpt_latt, 2)
3443 ALLOCATE (unique_coord(3, num_kpts))
3447 coord = kpt_latt(idim, i) - floor(kpt_latt(idim, i))
3448 IF (abs(coord - 1.0_dp) < 1.0e-8_dp) coord = 0.0_dp
3450 DO unique_id = 1, n_unique
3451 IF (abs(unique_coord(idim, unique_id) - coord) < 1.0e-8_dp)
THEN
3456 IF (.NOT. known)
THEN
3457 n_unique = n_unique + 1
3458 unique_coord(idim, n_unique) = coord
3461 mp_grid(idim) = n_unique
3463 valid = (mp_grid(1)*mp_grid(2)*mp_grid(3) == num_kpts)
3465 ALLOCATE (seen(num_kpts))
3471 coord = kpt_latt(idim, i) - floor(kpt_latt(idim, i))
3472 IF (abs(coord - 1.0_dp) < 1.0e-8_dp) coord = 0.0_dp
3474 DO unique_id = 1, mp_grid(idim)
3475 IF (abs(unique_coord(idim, unique_id) - coord) < 1.0e-8_dp)
THEN
3476 coord_id = unique_id
3480 cpassert(coord_id > 0)
3481 idx =
idx + (coord_id - 1)*stride
3482 stride = stride*mp_grid(idim)
3484 IF (seen(
idx)) valid = .false.
3487 valid = valid .AND. all(seen)
3490 DEALLOCATE (unique_coord)
3492 END SUBROUTINE infer_wannier_mp_grid
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
static GRID_HOST_DEVICE int idx(const orbital a)
Return coset index of given orbital angular momentum.
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
subroutine, public get_gto_basis_set(gto_basis_set, name, aliases, norm_type, kind_radius, ncgf, nset, nsgf, cgf_symbol, sgf_symbol, norm_cgf, set_radius, lmax, lmin, lx, ly, lz, m, ncgf_set, npgf, nsgf_set, nshell, cphi, pgf_radius, sphi, scon, zet, first_cgf, first_sgf, l, last_cgf, last_sgf, n, gcc, maxco, maxl, maxpgf, maxsgf_set, maxshell, maxso, nco_sum, npgf_sum, nshell_sum, maxder, short_kind_radius, npgf_seg_sum, ccon)
...
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public gresch2017
integer, save, public soluyanov2011
Handles all functions related to the CELL.
subroutine, public get_cell(cell, alpha, beta, gamma, deth, orthorhombic, abc, periodic, h, h_inv, symmetry_id, tag)
Get informations about a simulation cell.
methods related to the blacs parallel environment
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_get_submatrix(fm, target_m, start_row, start_col, n_rows, n_cols, transpose)
Extract a sub-matrix from the full matrix: op(target_m)(1:n_rows,1:n_cols) = fm(start_row:start_row+n...
subroutine, public cp_cfm_get_element(matrix, irow_global, icol_global, alpha)
Get the matrix element by its global index.
subroutine, public cp_cfm_copy_general(source, destination, para_env)
General copy of a cfm matrix to another cfm matrix. Uses non-blocking MPI rather than ScaLAPACK.
subroutine, public cp_cfm_release(matrix)
Releases a full matrix.
subroutine, public cp_fm_to_cfm(msourcer, msourcei, mtarget)
Construct a complex full matrix by taking its real and imaginary parts from two separate real-value f...
subroutine, public cp_cfm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
Creates a new full matrix with the given structure.
subroutine, public cp_cfm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, matrix_struct, para_env)
Returns information about a full matrix.
subroutine, public cp_cfm_set_submatrix(matrix, new_values, start_row, start_col, n_rows, n_cols, alpha, beta, transpose)
Set a sub-matrix of the full matrix: matrix(start_row:start_row+n_rows,start_col:start_col+n_cols) = ...
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_scale(matrix, alpha_scalar)
...
subroutine, public dbcsr_deallocate_matrix(matrix)
...
subroutine, public dbcsr_desymmetrize(matrix_a, matrix_b)
...
subroutine, public dbcsr_get_block_p(matrix, row, col, block, found, row_size, col_size)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
Routines that link DBCSR and CP2K concepts together.
subroutine, public cp_dbcsr_alloc_block_from_nbl(matrix, sab_orb, desymmetrize)
allocate the blocks of a dbcsr based on the neighbor list
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm, plan, check_plan)
Copy a DBCSR matrix to a BLACS matrix.
Utility routines to open and close files.
subroutine, public open_file(file_name, unit_number, file_status, file_form, file_action, file_position, file_pad, file_access, debug)
Opens a file and returns its logical unit number.
subroutine, public close_file(unit_number, file_status)
Closes an open file given by its logical unit number.
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
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...
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
integer, parameter, public default_path_length
Routines needed for kpoint calculation.
subroutine, public kpoint_initialize_mo_set(kpoint)
...
subroutine, public rskp_transform(rmatrix, cmatrix, rsmat, ispin, xkp, cell_to_index, sab_nl, is_complex, rs_sign)
Transformation of real space matrices to a kpoint.
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.
subroutine, public kpoint_initialize_mos(kpoint, mos, added_mos, for_aux_fit)
Initialize a set of MOs and density matrix for each kpoint (kpoint group).
subroutine, public kpoint_initialize(kpoint, particle_set, cell)
Generate the kpoints and initialize the kpoint environment.
subroutine, public kpoint_env_initialize(kpoint, para_env, blacs_env, with_aux_fit)
Initialize the kpoint environment.
Utilities for transforming k-point MO coefficients under symmetry operations.
logical function, public kpoint_same_periodic(xkp_a, xkp_b)
Compare two fractional k-points modulo reciprocal lattice vectors.
subroutine, public kpoint_transform_scf_mo(src, dst, qs_kpoint, ikred, isym, success, reason)
Transform one SCF MO coefficient matrix to an equivalent full-mesh k-point.
Types and basic routines needed for a kpoint calculation.
subroutine, public kpoint_release(kpoint)
Release a kpoint environment, deallocate all data.
subroutine, public get_kpoint_info(kpoint, kp_scheme, nkp_grid, kp_shift, symmetry, verbose, full_grid, use_real_wfn, eps_geo, parallel_group_size, kp_range, nkp, xkp, wkp, para_env, blacs_env_all, para_env_kp, para_env_inter_kp, blacs_env, kp_env, kp_aux_env, mpools, iogrp, nkp_groups, kp_dist, cell_to_index, index_to_cell, sab_nl, sab_nl_nosym, inversion_symmetry_only, symmetry_backend, symmetry_reduction_method, gamma_centered, lattice_fft)
Retrieve information from a kpoint environment.
subroutine, public kpoint_create(kpoint)
Create a kpoint environment.
Crystal-symmetry routines originating from the K290/ACMI code.
Machine interface based on Fortran 2003 and POSIX.
integer, parameter, public timestamp_length
subroutine, public m_timestamp(timestamp)
Returns a human readable timestamp.
Definition of mathematical constants and functions.
real(kind=dp), parameter, public twopi
Collection of simple mathematical functions and subroutines.
subroutine, public diag_complex(matrix, eigenvectors, eigenvalues)
Diagonalizes a local complex Hermitian matrix using LAPACK. Based on cp_cfm_heevd.
Interface to the message passing library MPI.
basic linear algebra operations for full matrixes
Define the data structure for the particle information.
Definition of physical constants:
real(kind=dp), parameter, public evolt
real(kind=dp), parameter, public angstrom
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)
Initialize a qs_env for kpoint calculations starting from a gamma point qs_env.
subroutine, public create_kp_from_gamma(qs_env, qs_env_kp, with_xc_terms)
...
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, cneo_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, hund_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, proj_shell_charge, lr_atom, do_mtlr, u_j_loop, ao_coef, init_u_ramping_each_scf, reltmat, ghost, monovalent, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
Definition and initialisation of the mo data type.
subroutine, public get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, uniform_occupation, kts, mu, flexible_electron_count, cmo_coeff)
Get the components of a MO set data structure.
Calculates the moment integrals <a|r^m|b> and <a|r x d/dr|b>.
subroutine, public build_berry_kpoint_matrix(qs_env, cosmat, sinmat, kvec, basis_type, ordered, ordered_kpoints)
...
Define the neighbor list data types and the corresponding functionality.
subroutine, public neighbor_list_iterator_create(iterator_set, nl, search, nthread)
Neighbor list iterator functions.
subroutine, public neighbor_list_iterator_release(iterator_set)
...
subroutine, public get_neighbor_list_set_p(neighbor_list_sets, nlist, symmetric)
Return the components of the first neighbor list set.
integer function, public neighbor_list_iterate(iterator_set, mepos)
...
subroutine, public get_iterator_info(iterator_set, mepos, ikind, jkind, nkind, ilist, nlist, inode, nnode, iatom, jatom, r, cell)
...
Different diagonalization schemes that can be used for the iterative solution of the eigenvalue probl...
subroutine, public do_general_diag_kp(matrix_ks, matrix_s, kpoints, scf_env, scf_control, update_p, diis_step, diis_error, qs_env, probe, added_mos_auto_grow, potential)
Kpoint diagonalization routine Transforms matrices to kpoint, distributes kpoint groups,...
module that contains the definitions of the scf types
Interface to Wannier90 code.
subroutine, public prepare_wannier90_scf_mos(kpoint, qs_kpoint, matrix_s, matrix_ks, cell_to_index, sab_nl, para_env, success, reason, aligned_degenerate_blocks, aligned_degenerate_max_size, aligned_degenerate_min_svalue, spin_channel)
Reconstruct a full Wannier90 k-point MO set from the SCF k-point MOs.
subroutine, public wannier90_interface(input, logger, qs_env)
...
parameters that control an scf iteration
subroutine, public v_soc_xyz_from_pseudopotential(qs_env, mat_v_soc_xyz)
V^SOC_µν^(α),R = ħ/2 < ϕ_µ cell O | sum_ℓ ΔV_ℓ^SO(r,r') L^(α) | ϕ_ν cell R>, α = x,...
Inversion action on CP2K Gaussian Bloch coefficients, including lattice phases.
subroutine, public gaussian_inversion_action(qs_env, k, center, mapping, phase, tolerance, status)
Construct sparse AO inversion at a TRIM for the operation r -> 2*center-r.
Versioned Gaussian-basis snapshots for cross-geometry topology overlaps. Atomic units,...
subroutine, public topology_state_begin(qs_env, filename, nao, nband, npoint, nspin, ntotal, spin_channel, bands, unit)
Write basis metadata; all ranks call, only the source writes.
subroutine, public topology_state_point(unit, point, k, eigenvalues, coefficients)
Write one point with eigenvalues in Hartree and physical AO coefficients.
Native character decomposition and metric-aware inversion representations.
subroutine, public inversion_representation(metric, coeff, mapping, phase, energies, check_tr, tolerance, energy_tolerance, counts, error, energy_error, status, diagnostics)
Inversion irreps of an isolated scalar or spinor eigenspace in an AO metric.
Exact inversion-subgroup EBR and symmetry-indicator analysis (spinful TR).
subroutine, public inversion_indicators(odd, pairs, dimension, strong, weak, z4, status)
Fu–Kane indices and inversion indicator with an explicit sign convention.
subroutine, public inversion_ebr_signature(odd, pairs, signed_atomic, nonnegative_atomic, coefficients, status)
Exact signed/nonnegative EBR-signature test for the inversion subgroup.
Local Wilson-loop linear algebra, independent of the electronic-structure representation....
real(kind=dp) function, public wcc_distance(a, b)
Minimum maximal cyclic matching distance between two WCC sets.
subroutine, public wilson_step(product, overlap, minimum_sv, status, sv_tol)
Multiply by the unitary polar factor of an overlap. Reject rank-deficient links.
subroutine, public z2_from_wcc(wcc, invariant, status, pair_tol)
Largest-gap crossing parity for an ordered time-reversal half-surface. Endpoint degeneracy is necessa...
logical function, public surface_resolved(wcc)
Conservative neighbouring-line movement and largest-gap separation checks.
subroutine, public wilson_spectrum(product, wcc, berry, status)
Sorted Wilson eigenphases in reduced units and total Berry phase in radians.
subroutine, public chern_from_wcc(wcc, invariant, winding, status, closure_tol)
First Chern number from determinant Wilson-phase winding on a closed surface. Both transverse endpoin...
Read explicit Wannier90 overlap connections, including nonuniform closed loops.
subroutine, public read_wannier90_nnkpts(filename, real_lattice, recip_lattice, kpt, nnlist, nncell)
Read and validate the cell, points, and directed connections of an nnkp file.
Gauge-covariant selection of fixed trial orbitals for Wannier90.
subroutine, public wannier90_window_mask(eigenvalues, num_wann, windows, window_set, allowed)
Restrict fixed trial selection to the bands admitted by disentanglement windows.
subroutine, public wannier90_select_projections(candidates, para_env, amn, pivots, min_svalue, anchor_kpoint)
Select the same trial orbitals at every k-point using a mesh-wide pivoted QR.
subroutine, public wannier90_hybrid_candidates(ao, groups, candidates)
Form tetrahedral s/p trials from the full AO bank before selecting projections.
Outtakes from Wannier90 code.
subroutine, public wannier_setup(mp_grid_loc, num_kpts_loc, real_lattice_loc, recip_lattice_loc, kpt_latt_loc, nntot_loc, nnlist_loc, nncell_loc, iounit)
...
Type defining parameters related to the simulation cell.
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
Represent a complex full matrix.
keeps the information about the structure of a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
Keeps information about a specific k-point.
Keeps symmetry information about a specific k-point.
Contains information about kpoints.
stores all the informations relevant to an mpi environment
Provides all information about a quickstep kind.