(git:ab76537)
Loading...
Searching...
No Matches
qs_wannier90.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Interface to Wannier90 code
10!> \par History
11!> 06.2016 created [JGH]
12!> \author JGH
13! **************************************************************************************************
16 USE cell_types, ONLY: cell_type,&
20 USE cp_dbcsr_api, ONLY: dbcsr_create,&
23 dbcsr_set,&
25 dbcsr_type_antisymmetric,&
26 dbcsr_type_symmetric
30 USE cp_files, ONLY: close_file,&
46 USE kinds, ONLY: default_string_length,&
47 dp
53 USE kpoint_types, ONLY: get_kpoint_info,&
58 USE machine, ONLY: m_timestamp,&
60 USE mathconstants, ONLY: twopi
64 USE physcon, ONLY: angstrom,&
65 evolt
70 USE qs_mo_types, ONLY: get_mo_set,&
77 USE wannier90, ONLY: wannier_setup
78#include "./base/base_uses.f90"
79
80 IMPLICIT NONE
81 PRIVATE
82
83 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_wannier90'
84
85 TYPE berry_matrix_type
86 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: sinmat => null(), cosmat => null()
87 END TYPE berry_matrix_type
88
89 PUBLIC :: wannier90_interface
90
91! **************************************************************************************************
92
93CONTAINS
94
95! **************************************************************************************************
96!> \brief ...
97!> \param input ...
98!> \param logger ...
99!> \param qs_env ...
100! **************************************************************************************************
101 SUBROUTINE wannier90_interface(input, logger, qs_env)
102 TYPE(section_vals_type), POINTER :: input
103 TYPE(cp_logger_type), POINTER :: logger
104 TYPE(qs_environment_type), POINTER :: qs_env
105
106 CHARACTER(len=*), PARAMETER :: routinen = 'wannier90_interface'
107
108 INTEGER :: handle, iw
109 LOGICAL :: explicit
110 TYPE(section_vals_type), POINTER :: w_input
111
112 !--------------------------------------------------------------------------------------------!
113
114 CALL timeset(routinen, handle)
115 w_input => section_vals_get_subs_vals(section_vals=input, &
116 subsection_name="DFT%PRINT%WANNIER90")
117 CALL section_vals_get(w_input, explicit=explicit)
118 IF (explicit) THEN
119
121
122 IF (iw > 0) THEN
123 WRITE (iw, '(/,T2,A)') &
124 '!-----------------------------------------------------------------------------!'
125 WRITE (iw, '(T32,A)') "Interface to Wannier90"
126 WRITE (iw, '(T2,A)') &
127 '!-----------------------------------------------------------------------------!'
128 END IF
129
130 CALL wannier90_files(qs_env, w_input, iw)
131
132 IF (iw > 0) THEN
133 WRITE (iw, '(/,T2,A)') &
134 '!--------------------------------End of Wannier90-----------------------------!'
135 END IF
136 END IF
137 CALL timestop(handle)
138
139 END SUBROUTINE wannier90_interface
140
141! **************************************************************************************************
142!> \brief ...
143!> \param qs_env ...
144!> \param input ...
145!> \param iw ...
146! **************************************************************************************************
147 SUBROUTINE wannier90_files(qs_env, input, iw)
148 TYPE(qs_environment_type), POINTER :: qs_env
149 TYPE(section_vals_type), POINTER :: input
150 INTEGER, INTENT(IN) :: iw
151
152 INTEGER, PARAMETER :: num_nnmax = 12
153
154 CHARACTER(len=2) :: asym
155 CHARACTER(len=20), ALLOCATABLE, DIMENSION(:) :: atom_symbols
156 CHARACTER(len=default_string_length) :: filename, seed_name
157 CHARACTER(LEN=timestamp_length) :: timestamp
158 INTEGER :: i, i_rep, ib, ib1, ib2, ibs, ik, ik2, ikk, ikpgr, ispin, iunit, ix, iy, iz, k, &
159 n_rep, nadd, nao, nbs, nexcl, nkp, nmo, nntot, nspins, num_atoms, num_bands, &
160 num_bands_tot, num_kpts, num_wann
161 INTEGER, ALLOCATABLE, DIMENSION(:) :: exclude_bands
162 INTEGER, ALLOCATABLE, DIMENSION(:, :) :: nblist, nnlist
163 INTEGER, ALLOCATABLE, DIMENSION(:, :, :) :: nncell
164 INTEGER, DIMENSION(2) :: kp_range
165 INTEGER, DIMENSION(3) :: mp_grid
166 INTEGER, DIMENSION(:), POINTER :: invals
167 INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index
168 LOGICAL :: diis_step, do_kpoints, gamma_only, &
169 my_kpgrp, mygrp, spinors
170 REAL(kind=dp) :: cmmn, ksign, rmmn
171 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: eigval
172 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: atoms_cart, b_latt, kpt_latt
173 REAL(kind=dp), DIMENSION(3) :: bvec
174 REAL(kind=dp), DIMENSION(3, 3) :: real_lattice, recip_lattice
175 REAL(kind=dp), DIMENSION(:), POINTER :: eigenvalues
176 REAL(kind=dp), DIMENSION(:, :), POINTER :: xkp
177 TYPE(berry_matrix_type), DIMENSION(:), POINTER :: berry_matrix
178 TYPE(cell_type), POINTER :: cell
179 TYPE(cp_blacs_env_type), POINTER :: blacs_env
180 TYPE(cp_fm_struct_type), POINTER :: matrix_struct_mmn, matrix_struct_work
181 TYPE(cp_fm_type) :: fm_tmp, mmn_imag, mmn_real
182 TYPE(cp_fm_type), DIMENSION(2) :: fmk1, fmk2
183 TYPE(cp_fm_type), POINTER :: fmdummy, fmi, fmr
184 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks, matrix_s
185 TYPE(dbcsr_type), POINTER :: cmatrix, rmatrix
186 TYPE(dft_control_type), POINTER :: dft_control
187 TYPE(kpoint_env_type), POINTER :: kp
188 TYPE(kpoint_type), POINTER :: kpoint
189 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
190 TYPE(mp_para_env_type), POINTER :: para_env
191 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
192 POINTER :: sab_nl
193 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
194 TYPE(qs_environment_type), POINTER :: qs_env_kp
195 TYPE(qs_scf_env_type), POINTER :: scf_env
196 TYPE(scf_control_type), POINTER :: scf_control
197
198 !--------------------------------------------------------------------------------------------!
199
200 ! add code for exclude_bands and projectors
201
202 ! generate all arrays needed for the setup call
203 CALL section_vals_val_get(input, "SEED_NAME", c_val=seed_name)
204 CALL section_vals_val_get(input, "MP_GRID", i_vals=invals)
205 CALL section_vals_val_get(input, "WANNIER_FUNCTIONS", i_val=num_wann)
206 CALL section_vals_val_get(input, "ADDED_MOS", i_val=nadd)
207 mp_grid(1:3) = invals(1:3)
208 num_kpts = mp_grid(1)*mp_grid(2)*mp_grid(3)
209 ! excluded bands
210 CALL section_vals_val_get(input, "EXCLUDE_BANDS", n_rep_val=n_rep)
211 nexcl = 0
212 DO i_rep = 1, n_rep
213 CALL section_vals_val_get(input, "EXCLUDE_BANDS", i_rep_val=i_rep, i_vals=invals)
214 nexcl = nexcl + SIZE(invals)
215 END DO
216 IF (nexcl > 0) THEN
217 ALLOCATE (exclude_bands(nexcl))
218 nexcl = 0
219 DO i_rep = 1, n_rep
220 CALL section_vals_val_get(input, "EXCLUDE_BANDS", i_rep_val=i_rep, i_vals=invals)
221 exclude_bands(nexcl + 1:nexcl + SIZE(invals)) = invals(:)
222 nexcl = nexcl + SIZE(invals)
223 END DO
224 END IF
225 !
226 ! lattice -> Angstrom
227 CALL get_qs_env(qs_env, cell=cell)
228 CALL get_cell(cell, h=real_lattice, h_inv=recip_lattice)
229 real_lattice(1:3, 1:3) = angstrom*real_lattice(1:3, 1:3)
230 recip_lattice(1:3, 1:3) = (twopi/angstrom)*transpose(recip_lattice(1:3, 1:3))
231 ! k-points
232 ALLOCATE (kpt_latt(3, num_kpts))
233 CALL get_qs_env(qs_env, particle_set=particle_set)
234 NULLIFY (kpoint)
235 CALL kpoint_create(kpoint)
236 kpoint%kp_scheme = "MONKHORST-PACK"
237 kpoint%symmetry = .false.
238 kpoint%nkp_grid(1:3) = mp_grid(1:3)
239 kpoint%verbose = .false.
240 kpoint%full_grid = .true.
241 kpoint%eps_geo = 1.0e-6_dp
242 kpoint%use_real_wfn = .false.
243 kpoint%parallel_group_size = 0
244 i = 0
245 DO ix = 0, mp_grid(1) - 1
246 DO iy = 0, mp_grid(2) - 1
247 DO iz = 0, mp_grid(3) - 1
248 i = i + 1
249 kpt_latt(1, i) = real(ix, kind=dp)/real(mp_grid(1), kind=dp)
250 kpt_latt(2, i) = real(iy, kind=dp)/real(mp_grid(2), kind=dp)
251 kpt_latt(3, i) = real(iz, kind=dp)/real(mp_grid(3), kind=dp)
252 END DO
253 END DO
254 END DO
255 kpoint%nkp = num_kpts
256 ALLOCATE (kpoint%xkp(3, num_kpts), kpoint%wkp(num_kpts))
257 kpoint%wkp(:) = 1._dp/real(num_kpts, kind=dp)
258 DO i = 1, num_kpts
259 kpoint%xkp(1:3, i) = (angstrom/twopi)*matmul(recip_lattice, kpt_latt(:, i))
260 END DO
261 ! number of bands in calculation
262 CALL get_qs_env(qs_env, mos=mos)
263 CALL get_mo_set(mo_set=mos(1), nao=nao, nmo=num_bands_tot)
264 num_bands_tot = min(nao, num_bands_tot + nadd)
265 num_bands = num_wann
266 num_atoms = SIZE(particle_set)
267 ALLOCATE (atoms_cart(3, num_atoms))
268 ALLOCATE (atom_symbols(num_atoms))
269 DO i = 1, num_atoms
270 atoms_cart(1:3, i) = particle_set(i)%r(1:3)
271 CALL get_atomic_kind(particle_set(i)%atomic_kind, element_symbol=asym)
272 atom_symbols(i) = asym
273 END DO
274 gamma_only = .false.
275 spinors = .false.
276 ! output
277 ALLOCATE (nnlist(num_kpts, num_nnmax))
278 ALLOCATE (nncell(3, num_kpts, num_nnmax))
279 nnlist = 0
280 nncell = 0
281 nntot = 0
282
283 IF (iw > 0) THEN
284 ! setup
285 CALL wannier_setup(mp_grid, num_kpts, real_lattice, recip_lattice, &
286 kpt_latt, nntot, nnlist, nncell, iw)
287 END IF
288
289 CALL get_qs_env(qs_env, para_env=para_env)
290 CALL para_env%sum(nntot)
291 CALL para_env%sum(nnlist)
292 CALL para_env%sum(nncell)
293
294 IF (para_env%is_source()) THEN
295 ! Write the Wannier90 input file "seed_name.win"
296 WRITE (filename, '(A,A)') trim(seed_name), ".win"
297 CALL open_file(filename, unit_number=iunit, file_status="UNKNOWN", file_action="WRITE")
298 !
299 CALL m_timestamp(timestamp)
300 WRITE (iunit, "(A)") "! Wannier90 input file generated by CP2K "
301 WRITE (iunit, "(A,/)") "! Creation date "//timestamp
302 !
303 WRITE (iunit, "(A,I5)") "num_wann = ", num_wann
304 IF (num_bands /= num_wann) THEN
305 WRITE (iunit, "(A,I5)") "num_bands = ", num_bands
306 END IF
307 WRITE (iunit, "(/,A,/)") "length_unit = bohr "
308 WRITE (iunit, "(/,A,/)") "! System"
309 WRITE (iunit, "(/,A)") "begin unit_cell_cart"
310 WRITE (iunit, "(A)") "bohr"
311 DO i = 1, 3
312 WRITE (iunit, "(3F12.6)") cell%hmat(i, 1:3)
313 END DO
314 WRITE (iunit, "(A,/)") "end unit_cell_cart"
315 WRITE (iunit, "(/,A)") "begin atoms_cart"
316 DO i = 1, num_atoms
317 WRITE (iunit, "(A,3F15.10)") atom_symbols(i), atoms_cart(1:3, i)
318 END DO
319 WRITE (iunit, "(A,/)") "end atoms_cart"
320 WRITE (iunit, "(/,A,/)") "! Kpoints"
321 WRITE (iunit, "(/,A,3I6/)") "mp_grid = ", mp_grid(1:3)
322 WRITE (iunit, "(A)") "begin kpoints"
323 DO i = 1, num_kpts
324 WRITE (iunit, "(3F12.6)") kpt_latt(1:3, i)
325 END DO
326 WRITE (iunit, "(A)") "end kpoints"
327 CALL close_file(iunit)
328 ELSE
329 iunit = -1
330 END IF
331
332 ! calculate bands
333 NULLIFY (qs_env_kp)
334 CALL get_qs_env(qs_env, do_kpoints=do_kpoints)
335 IF (do_kpoints) THEN
336 ! we already do kpoints
337 qs_env_kp => qs_env
338 ELSE
339 ! we start from gamma point only
340 ALLOCATE (qs_env_kp)
341 CALL create_kp_from_gamma(qs_env, qs_env_kp)
342 END IF
343 IF (iw > 0) THEN
344 WRITE (unit=iw, fmt="(/,T2,A)") "Start K-Point Calculation ..."
345 END IF
346 CALL get_qs_env(qs_env=qs_env_kp, para_env=para_env, blacs_env=blacs_env)
347 CALL kpoint_env_initialize(kpoint, para_env, blacs_env)
348 CALL kpoint_initialize_mos(kpoint, mos, nadd)
349 CALL kpoint_initialize_mo_set(kpoint)
350 !
351 CALL get_qs_env(qs_env=qs_env_kp, sab_orb=sab_nl, dft_control=dft_control)
352 CALL kpoint_init_cell_index(kpoint, sab_nl, para_env, dft_control)
353 !
354 CALL get_qs_env(qs_env=qs_env_kp, matrix_ks_kp=matrix_ks, matrix_s_kp=matrix_s, &
355 scf_env=scf_env, scf_control=scf_control)
356 CALL do_general_diag_kp(matrix_ks, matrix_s, kpoint, scf_env, scf_control, .false., diis_step)
357 !
358 IF (iw > 0) THEN
359 WRITE (iw, '(T69,A)') "... Finished"
360 END IF
361 !
362 ! Calculate and print Overlaps
363 !
364 IF (para_env%is_source()) THEN
365 WRITE (filename, '(A,A)') trim(seed_name), ".mmn"
366 CALL open_file(filename, unit_number=iunit, file_status="UNKNOWN", file_action="WRITE")
367 CALL m_timestamp(timestamp)
368 WRITE (iunit, "(A)") "! Wannier90 file generated by CP2K "//timestamp
369 WRITE (iunit, "(3I8)") num_bands, num_kpts, nntot
370 ELSE
371 iunit = -1
372 END IF
373 ! create a list of unique b vectors and a table of pointers
374 ! nblist(ik,i) -> +/- b_latt(1:3,x)
375 ALLOCATE (nblist(num_kpts, nntot))
376 ALLOCATE (b_latt(3, num_kpts*nntot))
377 nblist = 0
378 nbs = 0
379 DO ik = 1, num_kpts
380 DO i = 1, nntot
381 bvec(1:3) = kpt_latt(1:3, nnlist(ik, i)) - kpt_latt(1:3, ik) + nncell(1:3, ik, i)
382 ibs = 0
383 DO k = 1, nbs
384 IF (sum(abs(bvec(1:3) - b_latt(1:3, k))) < 1.e-6_dp) THEN
385 ibs = k
386 EXIT
387 END IF
388 IF (sum(abs(bvec(1:3) + b_latt(1:3, k))) < 1.e-6_dp) THEN
389 ibs = -k
390 EXIT
391 END IF
392 END DO
393 IF (ibs /= 0) THEN
394 ! old lattice vector
395 nblist(ik, i) = ibs
396 ELSE
397 ! new lattice vector
398 nbs = nbs + 1
399 b_latt(1:3, nbs) = bvec(1:3)
400 nblist(ik, i) = nbs
401 END IF
402 END DO
403 END DO
404 ! calculate all the operator matrices (a|bvec|b)
405 ALLOCATE (berry_matrix(nbs))
406 DO i = 1, nbs
407 NULLIFY (berry_matrix(i)%cosmat)
408 NULLIFY (berry_matrix(i)%sinmat)
409 bvec(1:3) = twopi*matmul(transpose(cell%h_inv(1:3, 1:3)), b_latt(1:3, i))
410 CALL build_berry_kpoint_matrix(qs_env_kp, berry_matrix(i)%cosmat, &
411 berry_matrix(i)%sinmat, bvec)
412 END DO
413 ! work matrices for MOs (all group)
414 kp => kpoint%kp_env(1)%kpoint_env
415 CALL get_mo_set(kp%mos(1, 1), nmo=nmo)
416 NULLIFY (matrix_struct_work)
417 CALL cp_fm_struct_create(matrix_struct_work, nrow_global=nao, &
418 ncol_global=nmo, &
419 para_env=para_env, &
420 context=blacs_env)
421 CALL cp_fm_create(fm_tmp, matrix_struct_work)
422 DO i = 1, 2
423 CALL cp_fm_create(fmk1(i), matrix_struct_work)
424 CALL cp_fm_create(fmk2(i), matrix_struct_work)
425 END DO
426 ! work matrices for Mmn(k,b) integrals
427 NULLIFY (matrix_struct_mmn)
428 CALL cp_fm_struct_create(matrix_struct_mmn, nrow_global=nmo, &
429 ncol_global=nmo, &
430 para_env=para_env, &
431 context=blacs_env)
432 CALL cp_fm_create(mmn_real, matrix_struct_mmn)
433 CALL cp_fm_create(mmn_imag, matrix_struct_mmn)
434 ! allocate some work matrices
435 ALLOCATE (rmatrix, cmatrix)
436 CALL dbcsr_create(rmatrix, template=matrix_s(1, 1)%matrix, &
437 matrix_type=dbcsr_type_symmetric)
438 CALL dbcsr_create(cmatrix, template=matrix_s(1, 1)%matrix, &
439 matrix_type=dbcsr_type_antisymmetric)
440 CALL cp_dbcsr_alloc_block_from_nbl(rmatrix, sab_nl)
441 CALL cp_dbcsr_alloc_block_from_nbl(cmatrix, sab_nl)
442 !
443 CALL get_kpoint_info(kpoint=kpoint, cell_to_index=cell_to_index)
444 NULLIFY (fmdummy)
445 nspins = dft_control%nspins
446 DO ispin = 1, nspins
447 ! loop over all k-points
448 DO ik = 1, num_kpts
449 ! get the MO coefficients for this k-point
450 my_kpgrp = (ik >= kpoint%kp_range(1) .AND. ik <= kpoint%kp_range(2))
451 IF (my_kpgrp) THEN
452 ikk = ik - kpoint%kp_range(1) + 1
453 kp => kpoint%kp_env(ikk)%kpoint_env
454 cpassert(SIZE(kp%mos, 1) == 2)
455 fmr => kp%mos(1, ispin)%mo_coeff
456 fmi => kp%mos(2, ispin)%mo_coeff
457 CALL cp_fm_copy_general(fmr, fmk1(1), para_env)
458 CALL cp_fm_copy_general(fmi, fmk1(2), para_env)
459 ELSE
460 NULLIFY (fmr, fmi, kp)
461 CALL cp_fm_copy_general(fmdummy, fmk1(1), para_env)
462 CALL cp_fm_copy_general(fmdummy, fmk1(2), para_env)
463 END IF
464 ! loop over all connected neighbors
465 DO i = 1, nntot
466 ! get the MO coefficients for the connected k-point
467 ik2 = nnlist(ik, i)
468 mygrp = (ik2 >= kpoint%kp_range(1) .AND. ik2 <= kpoint%kp_range(2))
469 IF (mygrp) THEN
470 ikk = ik2 - kpoint%kp_range(1) + 1
471 kp => kpoint%kp_env(ikk)%kpoint_env
472 cpassert(SIZE(kp%mos, 1) == 2)
473 fmr => kp%mos(1, ispin)%mo_coeff
474 fmi => kp%mos(2, ispin)%mo_coeff
475 CALL cp_fm_copy_general(fmr, fmk2(1), para_env)
476 CALL cp_fm_copy_general(fmi, fmk2(2), para_env)
477 ELSE
478 NULLIFY (fmr, fmi, kp)
479 CALL cp_fm_copy_general(fmdummy, fmk2(1), para_env)
480 CALL cp_fm_copy_general(fmdummy, fmk2(2), para_env)
481 END IF
482 !
483 ! transfer realspace overlaps to connected k-point
484 ibs = nblist(ik, i)
485 ksign = sign(1.0_dp, real(ibs, kind=dp))
486 ibs = abs(ibs)
487 CALL dbcsr_set(rmatrix, 0.0_dp)
488 CALL dbcsr_set(cmatrix, 0.0_dp)
489 CALL rskp_transform(rmatrix, cmatrix, rsmat=berry_matrix(ibs)%cosmat, ispin=1, &
490 xkp=kpoint%xkp(1:3, ik2), cell_to_index=cell_to_index, sab_nl=sab_nl, &
491 is_complex=.false., rs_sign=ksign)
492 CALL rskp_transform(cmatrix, rmatrix, rsmat=berry_matrix(ibs)%sinmat, ispin=1, &
493 xkp=kpoint%xkp(1:3, ik2), cell_to_index=cell_to_index, sab_nl=sab_nl, &
494 is_complex=.true., rs_sign=ksign)
495 !
496 ! calculate M_(mn)^(k,b)
497 CALL cp_dbcsr_sm_fm_multiply(rmatrix, fmk2(1), fm_tmp, nmo)
498 CALL parallel_gemm("T", "N", nmo, nmo, nao, 1.0_dp, fmk1(1), fm_tmp, 0.0_dp, mmn_real)
499 CALL parallel_gemm("T", "N", nmo, nmo, nao, 1.0_dp, fmk1(2), fm_tmp, 0.0_dp, mmn_imag)
500 CALL cp_dbcsr_sm_fm_multiply(rmatrix, fmk2(2), fm_tmp, nmo)
501 CALL parallel_gemm("T", "N", nmo, nmo, nao, 1.0_dp, fmk1(1), fm_tmp, 1.0_dp, mmn_imag)
502 CALL parallel_gemm("T", "N", nmo, nmo, nao, 1.0_dp, fmk1(2), fm_tmp, -1.0_dp, mmn_real)
503 CALL cp_dbcsr_sm_fm_multiply(cmatrix, fmk2(1), fm_tmp, nmo)
504 CALL parallel_gemm("T", "N", nmo, nmo, nao, 1.0_dp, fmk1(1), fm_tmp, 1.0_dp, mmn_imag)
505 CALL parallel_gemm("T", "N", nmo, nmo, nao, 1.0_dp, fmk1(2), fm_tmp, -1.0_dp, mmn_real)
506 CALL cp_dbcsr_sm_fm_multiply(cmatrix, fmk2(2), fm_tmp, nmo)
507 CALL parallel_gemm("T", "N", nmo, nmo, nao, 1.0_dp, fmk1(1), fm_tmp, -1.0_dp, mmn_real)
508 CALL parallel_gemm("T", "N", nmo, nmo, nao, 1.0_dp, fmk1(2), fm_tmp, -1.0_dp, mmn_imag)
509 !
510 ! write to output file
511 IF (para_env%is_source()) THEN
512 WRITE (iunit, "(2I8,3I5)") ik, ik2, nncell(1:3, ik, i)
513 END IF
514 DO ib2 = 1, nmo
515 DO ib1 = 1, nmo
516 CALL cp_fm_get_element(mmn_real, ib1, ib2, rmmn)
517 CALL cp_fm_get_element(mmn_imag, ib1, ib2, cmmn)
518 IF (para_env%is_source()) THEN
519 WRITE (iunit, "(2E30.14)") rmmn, cmmn
520 END IF
521 END DO
522 END DO
523 !
524 END DO
525 END DO
526 END DO
527 DO i = 1, nbs
528 CALL dbcsr_deallocate_matrix_set(berry_matrix(i)%cosmat)
529 CALL dbcsr_deallocate_matrix_set(berry_matrix(i)%sinmat)
530 END DO
531 DEALLOCATE (berry_matrix)
532 CALL cp_fm_struct_release(matrix_struct_work)
533 DO i = 1, 2
534 CALL cp_fm_release(fmk1(i))
535 CALL cp_fm_release(fmk2(i))
536 END DO
537 CALL cp_fm_release(fm_tmp)
538 CALL cp_fm_struct_release(matrix_struct_mmn)
539 CALL cp_fm_release(mmn_real)
540 CALL cp_fm_release(mmn_imag)
541 CALL dbcsr_deallocate_matrix(rmatrix)
542 CALL dbcsr_deallocate_matrix(cmatrix)
543 !
544 IF (para_env%is_source()) THEN
545 CALL close_file(iunit)
546 END IF
547 !
548 ! Calculate and print Projections
549 !
550 ! Print eigenvalues
551 nspins = dft_control%nspins
552 kp => kpoint%kp_env(1)%kpoint_env
553 CALL get_mo_set(kp%mos(1, 1), nmo=nmo)
554 ALLOCATE (eigval(nmo))
555 CALL get_kpoint_info(kpoint, nkp=nkp, kp_range=kp_range, xkp=xkp)
556 IF (para_env%is_source()) THEN
557 WRITE (filename, '(A,A)') trim(seed_name), ".eig"
558 CALL open_file(filename, unit_number=iunit, file_status="UNKNOWN", file_action="WRITE")
559 ELSE
560 iunit = -1
561 END IF
562 !
563 DO ik = 1, nkp
564 my_kpgrp = (ik >= kp_range(1) .AND. ik <= kp_range(2))
565 DO ispin = 1, nspins
566 IF (my_kpgrp) THEN
567 ikpgr = ik - kp_range(1) + 1
568 kp => kpoint%kp_env(ikpgr)%kpoint_env
569 CALL get_mo_set(kp%mos(1, ispin), eigenvalues=eigenvalues)
570 eigval(1:nmo) = eigenvalues(1:nmo)
571 ELSE
572 eigval(1:nmo) = 0.0_dp
573 END IF
574 CALL kpoint%para_env_inter_kp%sum(eigval)
575 eigval(1:nmo) = eigval(1:nmo)*evolt
576 ! output
577 IF (iunit > 0) THEN
578 DO ib = 1, nmo
579 WRITE (iunit, "(2I8,F24.14)") ib, ik, eigval(ib)
580 END DO
581 END IF
582 END DO
583 END DO
584 IF (para_env%is_source()) THEN
585 CALL close_file(iunit)
586 END IF
587 !
588 ! clean up
589 DEALLOCATE (kpt_latt, atoms_cart, atom_symbols, eigval)
590 DEALLOCATE (nnlist, nncell)
591 DEALLOCATE (nblist, b_latt)
592 IF (nexcl > 0) THEN
593 DEALLOCATE (exclude_bands)
594 END IF
595 IF (do_kpoints) THEN
596 NULLIFY (qs_env_kp)
597 ELSE
598 CALL qs_env_release(qs_env_kp)
599 DEALLOCATE (qs_env_kp)
600 NULLIFY (qs_env_kp)
601 END IF
602
603 CALL kpoint_release(kpoint)
604
605 END SUBROUTINE wannier90_files
606
607END MODULE qs_wannier90
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.
Handles all functions related to the CELL.
Definition cell_types.F:15
subroutine, public get_cell(cell, alpha, beta, gamma, deth, orthorhombic, abc, periodic, h, h_inv, symmetry_id, tag)
Get informations about a simulation cell.
Definition cell_types.F:200
methods related to the blacs parallel environment
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_deallocate_matrix(matrix)
...
subroutine, public dbcsr_set(matrix, alpha)
...
DBCSR operations in CP2K.
subroutine, public cp_dbcsr_sm_fm_multiply(matrix, fm_in, fm_out, ncol, alpha, beta)
multiply a dbcsr with a fm matrix
Utility routines to open and close files. Tracking of preconnections.
Definition cp_files.F:16
subroutine, public open_file(file_name, file_status, file_form, file_action, file_position, file_pad, unit_number, debug, skip_get_unit_number, file_access)
Opens the requested file using a free unit number.
Definition cp_files.F:311
subroutine, public close_file(unit_number, file_status, keep_preconnection)
Close an open file given by its logical unit number. Optionally, keep the file and unit preconnected.
Definition cp_files.F:122
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
Definition cp_fm_types.F:15
subroutine, public cp_fm_copy_general(source, destination, para_env)
General copy of a fm matrix to another fm matrix. Uses non-blocking MPI rather than ScaLAPACK.
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp, nrow, ncol, set_zero)
creates a new full matrix with the given structure
subroutine, public cp_fm_get_element(matrix, irow_global, icol_global, alpha, local)
returns an element of a fm this value is valid on every cpu using this call is expensive
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...
objects that represent the structure of input sections and the data contained in an input section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_get(section_vals, ref_count, n_repetition, n_subs_vals_rep, section, explicit)
returns various attributes about the section_vals
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
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_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_init_cell_index(kpoint, sab_nl, para_env, dft_control)
Generates the mapping of cell indices and linear RS index CELL (0,0,0) is always mapped to index 1.
subroutine, public kpoint_env_initialize(kpoint, para_env, blacs_env, with_aux_fit)
Initialize the kpoint environment.
Types and basic routines needed for a kpoint calculation.
subroutine, public kpoint_release(kpoint)
Release a kpoint environment, deallocate all data.
subroutine, public kpoint_create(kpoint)
Create a kpoint environment.
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)
Retrieve information from a kpoint environment.
Machine interface based on Fortran 2003 and POSIX.
Definition machine.F:17
integer, parameter, public timestamp_length
Definition machine.F:58
subroutine, public m_timestamp(timestamp)
Returns a human readable timestamp.
Definition machine.F:393
Definition of mathematical constants and functions.
real(kind=dp), parameter, public twopi
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:
Definition physcon.F:68
real(kind=dp), parameter, public evolt
Definition physcon.F:183
real(kind=dp), parameter, public angstrom
Definition physcon.F:144
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, 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, 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, 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.
Definition qs_gamma2kp.F:14
subroutine, public create_kp_from_gamma(qs_env, qs_env_kp, with_xc_terms)
...
Definition qs_gamma2kp.F:63
Definition and initialisation of the mo data type.
Definition qs_mo_types.F:22
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)
Get the components of a MO set data structure.
Calculates the moment integrals <a|r^m|b> and <a|r x d/dr|b>
Definition qs_moments.F:14
subroutine, public build_berry_kpoint_matrix(qs_env, cosmat, sinmat, kvec, basis_type)
...
Define the neighbor list data types and the corresponding functionality.
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)
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 wannier90_interface(input, logger, qs_env)
...
parameters that control an scf iteration
Outtakes from Wannier90 code.
Definition wannier90.F:66
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)
...
Definition wannier90.F:140
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
keeps the information about the structure of a full matrix
represent 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.
Contains information about kpoints.
stores all the informations relevant to an mpi environment