(git:374b731)
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-2024 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,&
23 USE cp_files, ONLY: close_file,&
35 USE dbcsr_api, ONLY: dbcsr_create,&
36 dbcsr_deallocate_matrix,&
37 dbcsr_p_type,&
38 dbcsr_set,&
39 dbcsr_type,&
40 dbcsr_type_antisymmetric,&
41 dbcsr_type_symmetric
46 USE kinds, ONLY: default_string_length,&
47 dp
53 USE kpoint_types, ONLY: get_kpoint_info,&
58 USE machine, ONLY: m_datum
59 USE mathconstants, ONLY: twopi
63 USE physcon, ONLY: angstrom,&
64 evolt
69 USE qs_mo_types, ONLY: get_mo_set,&
76 USE wannier90, ONLY: wannier_setup
77#include "./base/base_uses.f90"
78
79 IMPLICIT NONE
80 PRIVATE
81
82 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_wannier90'
83
84 TYPE berry_matrix_type
85 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: sinmat, cosmat
86 END TYPE berry_matrix_type
87
88 PUBLIC :: wannier90_interface
89
90! **************************************************************************************************
91
92CONTAINS
93
94! **************************************************************************************************
95!> \brief ...
96!> \param input ...
97!> \param logger ...
98!> \param qs_env ...
99! **************************************************************************************************
100 SUBROUTINE wannier90_interface(input, logger, qs_env)
101 TYPE(section_vals_type), POINTER :: input
102 TYPE(cp_logger_type), POINTER :: logger
103 TYPE(qs_environment_type), POINTER :: qs_env
104
105 CHARACTER(len=*), PARAMETER :: routinen = 'wannier90_interface'
106
107 INTEGER :: handle, iw
108 LOGICAL :: explicit
109 TYPE(section_vals_type), POINTER :: w_input
110
111 !--------------------------------------------------------------------------------------------!
112
113 CALL timeset(routinen, handle)
114 w_input => section_vals_get_subs_vals(section_vals=input, &
115 subsection_name="DFT%PRINT%WANNIER90")
116 CALL section_vals_get(w_input, explicit=explicit)
117 IF (explicit) THEN
118
120
121 IF (iw > 0) THEN
122 WRITE (iw, '(/,T2,A)') &
123 '!-----------------------------------------------------------------------------!'
124 WRITE (iw, '(T32,A)') "Interface to Wannier90"
125 WRITE (iw, '(T2,A)') &
126 '!-----------------------------------------------------------------------------!'
127 END IF
128
129 CALL wannier90_files(qs_env, w_input, iw)
130
131 IF (iw > 0) THEN
132 WRITE (iw, '(/,T2,A)') &
133 '!--------------------------------End of Wannier90-----------------------------!'
134 END IF
135 END IF
136 CALL timestop(handle)
137
138 END SUBROUTINE wannier90_interface
139
140! **************************************************************************************************
141!> \brief ...
142!> \param qs_env ...
143!> \param input ...
144!> \param iw ...
145! **************************************************************************************************
146 SUBROUTINE wannier90_files(qs_env, input, iw)
147 TYPE(qs_environment_type), POINTER :: qs_env
148 TYPE(section_vals_type), POINTER :: input
149 INTEGER, INTENT(IN) :: iw
150
151 INTEGER, PARAMETER :: num_nnmax = 12
152
153 CHARACTER(len=2) :: asym
154 CHARACTER(len=20), ALLOCATABLE, DIMENSION(:) :: atom_symbols
155 CHARACTER(LEN=256) :: datx
156 CHARACTER(len=default_string_length) :: filename, seed_name
157 INTEGER :: i, i_rep, ib, ib1, ib2, ibs, ik, ik2, ikk, ikpgr, ispin, iunit, ix, iy, iz, k, &
158 n_rep, nadd, nao, nbs, nexcl, nkp, nmo, nntot, nspins, num_atoms, num_bands, &
159 num_bands_tot, num_kpts, num_wann
160 INTEGER, ALLOCATABLE, DIMENSION(:) :: exclude_bands
161 INTEGER, ALLOCATABLE, DIMENSION(:, :) :: nblist, nnlist
162 INTEGER, ALLOCATABLE, DIMENSION(:, :, :) :: nncell
163 INTEGER, DIMENSION(2) :: kp_range
164 INTEGER, DIMENSION(3) :: mp_grid
165 INTEGER, DIMENSION(:), POINTER :: invals
166 INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index
167 LOGICAL :: diis_step, do_kpoints, gamma_only, &
168 my_kpgrp, mygrp, spinors
169 REAL(kind=dp) :: cmmn, ksign, rmmn
170 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: eigval
171 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: atoms_cart, b_latt, kpt_latt
172 REAL(kind=dp), DIMENSION(3) :: bvec
173 REAL(kind=dp), DIMENSION(3, 3) :: real_lattice, recip_lattice
174 REAL(kind=dp), DIMENSION(:), POINTER :: eigenvalues
175 REAL(kind=dp), DIMENSION(:, :), POINTER :: xkp
176 TYPE(berry_matrix_type), DIMENSION(:), POINTER :: berry_matrix
177 TYPE(cell_type), POINTER :: cell
178 TYPE(cp_blacs_env_type), POINTER :: blacs_env
179 TYPE(cp_fm_struct_type), POINTER :: matrix_struct_mmn, matrix_struct_work
180 TYPE(cp_fm_type) :: fm_tmp, mmn_imag, mmn_real
181 TYPE(cp_fm_type), DIMENSION(2) :: fmk1, fmk2
182 TYPE(cp_fm_type), POINTER :: fmdummy, fmi, fmr
183 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks, matrix_s
184 TYPE(dbcsr_type), POINTER :: cmatrix, rmatrix
185 TYPE(dft_control_type), POINTER :: dft_control
186 TYPE(kpoint_env_type), POINTER :: kp
187 TYPE(kpoint_type), POINTER :: kpoint
188 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
189 TYPE(mp_para_env_type), POINTER :: para_env
190 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
191 POINTER :: sab_nl
192 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
193 TYPE(qs_environment_type), POINTER :: qs_env_kp
194 TYPE(qs_scf_env_type), POINTER :: scf_env
195 TYPE(scf_control_type), POINTER :: scf_control
196
197 !--------------------------------------------------------------------------------------------!
198
199 ! add code for exclude_bands and projectors
200
201 ! generate all arrays needed for the setup call
202 CALL section_vals_val_get(input, "SEED_NAME", c_val=seed_name)
203 CALL section_vals_val_get(input, "MP_GRID", i_vals=invals)
204 CALL section_vals_val_get(input, "WANNIER_FUNCTIONS", i_val=num_wann)
205 CALL section_vals_val_get(input, "ADDED_MOS", i_val=nadd)
206 mp_grid(1:3) = invals(1:3)
207 num_kpts = mp_grid(1)*mp_grid(2)*mp_grid(3)
208 ! excluded bands
209 CALL section_vals_val_get(input, "EXCLUDE_BANDS", n_rep_val=n_rep)
210 nexcl = 0
211 DO i_rep = 1, n_rep
212 CALL section_vals_val_get(input, "EXCLUDE_BANDS", i_rep_val=i_rep, i_vals=invals)
213 nexcl = nexcl + SIZE(invals)
214 END DO
215 IF (nexcl > 0) THEN
216 ALLOCATE (exclude_bands(nexcl))
217 nexcl = 0
218 DO i_rep = 1, n_rep
219 CALL section_vals_val_get(input, "EXCLUDE_BANDS", i_rep_val=i_rep, i_vals=invals)
220 exclude_bands(nexcl + 1:nexcl + SIZE(invals)) = invals(:)
221 nexcl = nexcl + SIZE(invals)
222 END DO
223 END IF
224 !
225 ! lattice -> Angstrom
226 CALL get_qs_env(qs_env, cell=cell)
227 CALL get_cell(cell, h=real_lattice, h_inv=recip_lattice)
228 real_lattice(1:3, 1:3) = angstrom*real_lattice(1:3, 1:3)
229 recip_lattice(1:3, 1:3) = (twopi/angstrom)*transpose(recip_lattice(1:3, 1:3))
230 ! k-points
231 ALLOCATE (kpt_latt(3, num_kpts))
232 CALL get_qs_env(qs_env, particle_set=particle_set)
233 NULLIFY (kpoint)
234 CALL kpoint_create(kpoint)
235 kpoint%kp_scheme = "MONKHORST-PACK"
236 kpoint%symmetry = .false.
237 kpoint%nkp_grid(1:3) = mp_grid(1:3)
238 kpoint%verbose = .false.
239 kpoint%full_grid = .true.
240 kpoint%eps_geo = 1.0e-6_dp
241 kpoint%use_real_wfn = .false.
242 kpoint%parallel_group_size = 0
243 i = 0
244 DO ix = 0, mp_grid(1) - 1
245 DO iy = 0, mp_grid(2) - 1
246 DO iz = 0, mp_grid(3) - 1
247 i = i + 1
248 kpt_latt(1, i) = real(ix, kind=dp)/real(mp_grid(1), kind=dp)
249 kpt_latt(2, i) = real(iy, kind=dp)/real(mp_grid(2), kind=dp)
250 kpt_latt(3, i) = real(iz, kind=dp)/real(mp_grid(3), kind=dp)
251 END DO
252 END DO
253 END DO
254 kpoint%nkp = num_kpts
255 ALLOCATE (kpoint%xkp(3, num_kpts), kpoint%wkp(num_kpts))
256 kpoint%wkp(:) = 1._dp/real(num_kpts, kind=dp)
257 DO i = 1, num_kpts
258 kpoint%xkp(1:3, i) = (angstrom/twopi)*matmul(recip_lattice, kpt_latt(:, i))
259 END DO
260 ! number of bands in calculation
261 CALL get_qs_env(qs_env, mos=mos)
262 CALL get_mo_set(mo_set=mos(1), nao=nao, nmo=num_bands_tot)
263 num_bands_tot = min(nao, num_bands_tot + nadd)
264 num_bands = num_wann
265 num_atoms = SIZE(particle_set)
266 ALLOCATE (atoms_cart(3, num_atoms))
267 ALLOCATE (atom_symbols(num_atoms))
268 DO i = 1, num_atoms
269 atoms_cart(1:3, i) = particle_set(i)%r(1:3)
270 CALL get_atomic_kind(particle_set(i)%atomic_kind, element_symbol=asym)
271 atom_symbols(i) = asym
272 END DO
273 gamma_only = .false.
274 spinors = .false.
275 ! output
276 ALLOCATE (nnlist(num_kpts, num_nnmax))
277 ALLOCATE (nncell(3, num_kpts, num_nnmax))
278 nnlist = 0
279 nncell = 0
280 nntot = 0
281
282 IF (iw > 0) THEN
283 ! setup
284 CALL wannier_setup(mp_grid, num_kpts, real_lattice, recip_lattice, &
285 kpt_latt, nntot, nnlist, nncell, iw)
286 END IF
287
288 CALL get_qs_env(qs_env, para_env=para_env)
289 CALL para_env%sum(nntot)
290 CALL para_env%sum(nnlist)
291 CALL para_env%sum(nncell)
292
293 IF (para_env%is_source()) THEN
294 ! Write the Wannier90 input file "seed_name.win"
295 WRITE (filename, '(A,A)') trim(seed_name), ".win"
296 CALL open_file(filename, unit_number=iunit, file_status="UNKNOWN", file_action="WRITE")
297 !
298 CALL m_datum(datx)
299 WRITE (iunit, "(A)") "! Wannier90 input file generated by CP2K "
300 WRITE (iunit, "(A,/)") "! Creation date "//trim(datx)
301 !
302 WRITE (iunit, "(A,I5)") "num_wann = ", num_wann
303 IF (num_bands /= num_wann) THEN
304 WRITE (iunit, "(A,I5)") "num_bands = ", num_bands
305 END IF
306 WRITE (iunit, "(/,A,/)") "length_unit = bohr "
307 WRITE (iunit, "(/,A,/)") "! System"
308 WRITE (iunit, "(/,A)") "begin unit_cell_cart"
309 WRITE (iunit, "(A)") "bohr"
310 DO i = 1, 3
311 WRITE (iunit, "(3F12.6)") cell%hmat(i, 1:3)
312 END DO
313 WRITE (iunit, "(A,/)") "end unit_cell_cart"
314 WRITE (iunit, "(/,A)") "begin atoms_cart"
315 DO i = 1, num_atoms
316 WRITE (iunit, "(A,3F15.10)") atom_symbols(i), atoms_cart(1:3, i)
317 END DO
318 WRITE (iunit, "(A,/)") "end atoms_cart"
319 WRITE (iunit, "(/,A,/)") "! Kpoints"
320 WRITE (iunit, "(/,A,3I6/)") "mp_grid = ", mp_grid(1:3)
321 WRITE (iunit, "(A)") "begin kpoints"
322 DO i = 1, num_kpts
323 WRITE (iunit, "(3F12.6)") kpt_latt(1:3, i)
324 END DO
325 WRITE (iunit, "(A)") "end kpoints"
326 CALL close_file(iunit)
327 ELSE
328 iunit = -1
329 END IF
330
331 ! calculate bands
332 NULLIFY (qs_env_kp)
333 CALL get_qs_env(qs_env, do_kpoints=do_kpoints)
334 IF (do_kpoints) THEN
335 ! we already do kpoints
336 qs_env_kp => qs_env
337 ELSE
338 ! we start from gamma point only
339 ALLOCATE (qs_env_kp)
340 CALL create_kp_from_gamma(qs_env, qs_env_kp)
341 END IF
342 IF (iw > 0) THEN
343 WRITE (unit=iw, fmt="(/,T2,A)") "Start K-Point Calculation ... "
344 END IF
345 CALL get_qs_env(qs_env=qs_env_kp, para_env=para_env, blacs_env=blacs_env)
346 CALL kpoint_env_initialize(kpoint, para_env, blacs_env)
347 CALL kpoint_initialize_mos(kpoint, mos, nadd)
348 CALL kpoint_initialize_mo_set(kpoint)
349 !
350 CALL get_qs_env(qs_env=qs_env_kp, sab_orb=sab_nl, dft_control=dft_control)
351 CALL kpoint_init_cell_index(kpoint, sab_nl, para_env, dft_control)
352 !
353 CALL get_qs_env(qs_env=qs_env_kp, matrix_ks_kp=matrix_ks, matrix_s_kp=matrix_s, &
354 scf_env=scf_env, scf_control=scf_control)
355 CALL do_general_diag_kp(matrix_ks, matrix_s, kpoint, scf_env, scf_control, .false., diis_step)
356 !
357 IF (iw > 0) THEN
358 WRITE (iw, '(T69,A)') "... Finished"
359 END IF
360 !
361 ! Calculate and print Overlaps
362 !
363 IF (para_env%is_source()) THEN
364 WRITE (filename, '(A,A)') trim(seed_name), ".mmn"
365 CALL open_file(filename, unit_number=iunit, file_status="UNKNOWN", file_action="WRITE")
366 CALL m_datum(datx)
367 WRITE (iunit, "(A)") "! Wannier90 file generated by CP2K "//trim(datx)
368 WRITE (iunit, "(3I8)") num_bands, num_kpts, nntot
369 ELSE
370 iunit = -1
371 END IF
372 ! create a list of unique b vectors and a table of pointers
373 ! nblist(ik,i) -> +/- b_latt(1:3,x)
374 ALLOCATE (nblist(num_kpts, nntot))
375 ALLOCATE (b_latt(3, num_kpts*nntot))
376 nblist = 0
377 nbs = 0
378 DO ik = 1, num_kpts
379 DO i = 1, nntot
380 bvec(1:3) = kpt_latt(1:3, nnlist(ik, i)) - kpt_latt(1:3, ik) + nncell(1:3, ik, i)
381 ibs = 0
382 DO k = 1, nbs
383 IF (sum(abs(bvec(1:3) - b_latt(1:3, k))) < 1.e-6_dp) THEN
384 ibs = k
385 EXIT
386 END IF
387 IF (sum(abs(bvec(1:3) + b_latt(1:3, k))) < 1.e-6_dp) THEN
388 ibs = -k
389 EXIT
390 END IF
391 END DO
392 IF (ibs /= 0) THEN
393 ! old lattice vector
394 nblist(ik, i) = ibs
395 ELSE
396 ! new lattice vector
397 nbs = nbs + 1
398 b_latt(1:3, nbs) = bvec(1:3)
399 nblist(ik, i) = nbs
400 END IF
401 END DO
402 END DO
403 ! calculate all the operator matrices (a|bvec|b)
404 ALLOCATE (berry_matrix(nbs))
405 DO i = 1, nbs
406 NULLIFY (berry_matrix(i)%cosmat)
407 NULLIFY (berry_matrix(i)%sinmat)
408 bvec(1:3) = twopi*matmul(transpose(cell%h_inv(1:3, 1:3)), b_latt(1:3, i))
409 CALL build_berry_kpoint_matrix(qs_env_kp, berry_matrix(i)%cosmat, &
410 berry_matrix(i)%sinmat, bvec)
411 END DO
412 ! work matrices for MOs (all group)
413 kp => kpoint%kp_env(1)%kpoint_env
414 CALL get_mo_set(kp%mos(1, 1), nmo=nmo)
415 NULLIFY (matrix_struct_work)
416 CALL cp_fm_struct_create(matrix_struct_work, nrow_global=nao, &
417 ncol_global=nmo, &
418 para_env=para_env, &
419 context=blacs_env)
420 CALL cp_fm_create(fm_tmp, matrix_struct_work)
421 DO i = 1, 2
422 CALL cp_fm_create(fmk1(i), matrix_struct_work)
423 CALL cp_fm_create(fmk2(i), matrix_struct_work)
424 END DO
425 ! work matrices for Mmn(k,b) integrals
426 NULLIFY (matrix_struct_mmn)
427 CALL cp_fm_struct_create(matrix_struct_mmn, nrow_global=nmo, &
428 ncol_global=nmo, &
429 para_env=para_env, &
430 context=blacs_env)
431 CALL cp_fm_create(mmn_real, matrix_struct_mmn)
432 CALL cp_fm_create(mmn_imag, matrix_struct_mmn)
433 ! allocate some work matrices
434 ALLOCATE (rmatrix, cmatrix)
435 CALL dbcsr_create(rmatrix, template=matrix_s(1, 1)%matrix, &
436 matrix_type=dbcsr_type_symmetric)
437 CALL dbcsr_create(cmatrix, template=matrix_s(1, 1)%matrix, &
438 matrix_type=dbcsr_type_antisymmetric)
439 CALL cp_dbcsr_alloc_block_from_nbl(rmatrix, sab_nl)
440 CALL cp_dbcsr_alloc_block_from_nbl(cmatrix, sab_nl)
441 !
442 CALL get_kpoint_info(kpoint=kpoint, cell_to_index=cell_to_index)
443 NULLIFY (fmdummy)
444 nspins = dft_control%nspins
445 DO ispin = 1, nspins
446 ! loop over all k-points
447 DO ik = 1, num_kpts
448 ! get the MO coefficients for this k-point
449 my_kpgrp = (ik >= kpoint%kp_range(1) .AND. ik <= kpoint%kp_range(2))
450 IF (my_kpgrp) THEN
451 ikk = ik - kpoint%kp_range(1) + 1
452 kp => kpoint%kp_env(ikk)%kpoint_env
453 cpassert(SIZE(kp%mos, 1) == 2)
454 fmr => kp%mos(1, ispin)%mo_coeff
455 fmi => kp%mos(2, ispin)%mo_coeff
456 CALL cp_fm_copy_general(fmr, fmk1(1), para_env)
457 CALL cp_fm_copy_general(fmi, fmk1(2), para_env)
458 ELSE
459 NULLIFY (fmr, fmi, kp)
460 CALL cp_fm_copy_general(fmdummy, fmk1(1), para_env)
461 CALL cp_fm_copy_general(fmdummy, fmk1(2), para_env)
462 END IF
463 ! loop over all connected neighbors
464 DO i = 1, nntot
465 ! get the MO coefficients for the connected k-point
466 ik2 = nnlist(ik, i)
467 mygrp = (ik2 >= kpoint%kp_range(1) .AND. ik2 <= kpoint%kp_range(2))
468 IF (mygrp) THEN
469 ikk = ik2 - kpoint%kp_range(1) + 1
470 kp => kpoint%kp_env(ikk)%kpoint_env
471 cpassert(SIZE(kp%mos, 1) == 2)
472 fmr => kp%mos(1, ispin)%mo_coeff
473 fmi => kp%mos(2, ispin)%mo_coeff
474 CALL cp_fm_copy_general(fmr, fmk2(1), para_env)
475 CALL cp_fm_copy_general(fmi, fmk2(2), para_env)
476 ELSE
477 NULLIFY (fmr, fmi, kp)
478 CALL cp_fm_copy_general(fmdummy, fmk2(1), para_env)
479 CALL cp_fm_copy_general(fmdummy, fmk2(2), para_env)
480 END IF
481 !
482 ! transfer realspace overlaps to connected k-point
483 ibs = nblist(ik, i)
484 ksign = sign(1.0_dp, real(ibs, kind=dp))
485 ibs = abs(ibs)
486 CALL dbcsr_set(rmatrix, 0.0_dp)
487 CALL dbcsr_set(cmatrix, 0.0_dp)
488 CALL rskp_transform(rmatrix, cmatrix, rsmat=berry_matrix(ibs)%cosmat, ispin=1, &
489 xkp=kpoint%xkp(1:3, ik2), cell_to_index=cell_to_index, sab_nl=sab_nl, &
490 is_complex=.false., rs_sign=ksign)
491 CALL rskp_transform(cmatrix, rmatrix, rsmat=berry_matrix(ibs)%sinmat, ispin=1, &
492 xkp=kpoint%xkp(1:3, ik2), cell_to_index=cell_to_index, sab_nl=sab_nl, &
493 is_complex=.true., rs_sign=ksign)
494 !
495 ! calculate M_(mn)^(k,b)
496 CALL cp_dbcsr_sm_fm_multiply(rmatrix, fmk2(1), fm_tmp, nmo)
497 CALL parallel_gemm("T", "N", nmo, nmo, nao, 1.0_dp, fmk1(1), fm_tmp, 0.0_dp, mmn_real)
498 CALL parallel_gemm("T", "N", nmo, nmo, nao, 1.0_dp, fmk1(2), fm_tmp, 0.0_dp, mmn_imag)
499 CALL cp_dbcsr_sm_fm_multiply(rmatrix, fmk2(2), fm_tmp, nmo)
500 CALL parallel_gemm("T", "N", nmo, nmo, nao, 1.0_dp, fmk1(1), fm_tmp, 1.0_dp, mmn_imag)
501 CALL parallel_gemm("T", "N", nmo, nmo, nao, 1.0_dp, fmk1(2), fm_tmp, -1.0_dp, mmn_real)
502 CALL cp_dbcsr_sm_fm_multiply(cmatrix, fmk2(1), fm_tmp, nmo)
503 CALL parallel_gemm("T", "N", nmo, nmo, nao, 1.0_dp, fmk1(1), fm_tmp, 1.0_dp, mmn_imag)
504 CALL parallel_gemm("T", "N", nmo, nmo, nao, 1.0_dp, fmk1(2), fm_tmp, -1.0_dp, mmn_real)
505 CALL cp_dbcsr_sm_fm_multiply(cmatrix, fmk2(2), fm_tmp, nmo)
506 CALL parallel_gemm("T", "N", nmo, nmo, nao, 1.0_dp, fmk1(1), fm_tmp, -1.0_dp, mmn_real)
507 CALL parallel_gemm("T", "N", nmo, nmo, nao, 1.0_dp, fmk1(2), fm_tmp, -1.0_dp, mmn_imag)
508 !
509 ! write to output file
510 IF (para_env%is_source()) THEN
511 WRITE (iunit, "(2I8,3I5)") ik, ik2, nncell(1:3, ik, i)
512 END IF
513 DO ib2 = 1, nmo
514 DO ib1 = 1, nmo
515 CALL cp_fm_get_element(mmn_real, ib1, ib2, rmmn)
516 CALL cp_fm_get_element(mmn_imag, ib1, ib2, cmmn)
517 IF (para_env%is_source()) THEN
518 WRITE (iunit, "(2E30.14)") rmmn, cmmn
519 END IF
520 END DO
521 END DO
522 !
523 END DO
524 END DO
525 END DO
526 DO i = 1, nbs
527 CALL dbcsr_deallocate_matrix_set(berry_matrix(i)%cosmat)
528 CALL dbcsr_deallocate_matrix_set(berry_matrix(i)%sinmat)
529 END DO
530 DEALLOCATE (berry_matrix)
531 CALL cp_fm_struct_release(matrix_struct_work)
532 DO i = 1, 2
533 CALL cp_fm_release(fmk1(i))
534 CALL cp_fm_release(fmk2(i))
535 END DO
536 CALL cp_fm_release(fm_tmp)
537 CALL cp_fm_struct_release(matrix_struct_mmn)
538 CALL cp_fm_release(mmn_real)
539 CALL cp_fm_release(mmn_imag)
540 CALL dbcsr_deallocate_matrix(rmatrix)
541 CALL dbcsr_deallocate_matrix(cmatrix)
542 !
543 IF (para_env%is_source()) THEN
544 CALL close_file(iunit)
545 END IF
546 !
547 ! Calculate and print Projections
548 !
549 ! Print eigenvalues
550 nspins = dft_control%nspins
551 kp => kpoint%kp_env(1)%kpoint_env
552 CALL get_mo_set(kp%mos(1, 1), nmo=nmo)
553 ALLOCATE (eigval(nmo))
554 CALL get_kpoint_info(kpoint, nkp=nkp, kp_range=kp_range, xkp=xkp)
555 IF (para_env%is_source()) THEN
556 WRITE (filename, '(A,A)') trim(seed_name), ".eig"
557 CALL open_file(filename, unit_number=iunit, file_status="UNKNOWN", file_action="WRITE")
558 ELSE
559 iunit = -1
560 END IF
561 !
562 DO ik = 1, nkp
563 my_kpgrp = (ik >= kp_range(1) .AND. ik <= kp_range(2))
564 DO ispin = 1, nspins
565 IF (my_kpgrp) THEN
566 ikpgr = ik - kp_range(1) + 1
567 kp => kpoint%kp_env(ikpgr)%kpoint_env
568 CALL get_mo_set(kp%mos(1, ispin), eigenvalues=eigenvalues)
569 eigval(1:nmo) = eigenvalues(1:nmo)
570 ELSE
571 eigval(1:nmo) = 0.0_dp
572 END IF
573 CALL kpoint%para_env_inter_kp%sum(eigval)
574 eigval(1:nmo) = eigval(1:nmo)*evolt
575 ! output
576 IF (iunit > 0) THEN
577 DO ib = 1, nmo
578 WRITE (iunit, "(2I8,F24.14)") ib, ik, eigval(ib)
579 END DO
580 END IF
581 END DO
582 END DO
583 IF (para_env%is_source()) THEN
584 CALL close_file(iunit)
585 END IF
586 !
587 ! clean up
588 DEALLOCATE (kpt_latt, atoms_cart, atom_symbols, eigval)
589 DEALLOCATE (nnlist, nncell)
590 DEALLOCATE (nblist, b_latt)
591 IF (nexcl > 0) THEN
592 DEALLOCATE (exclude_bands)
593 END IF
594 IF (do_kpoints) THEN
595 NULLIFY (qs_env_kp)
596 ELSE
597 CALL qs_env_release(qs_env_kp)
598 DEALLOCATE (qs_env_kp)
599 NULLIFY (qs_env_kp)
600 END IF
601
602 CALL kpoint_release(kpoint)
603
604 END SUBROUTINE wannier90_files
605
606END 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:195
methods related to the blacs parallel environment
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
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:308
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:119
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_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
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp)
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...
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
subroutine, public m_datum(cal_date)
returns a datum in human readable format using a standard Fortran routine
Definition machine.F:270
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 qs_env_release(qs_env)
releases the given qs_env (see doc/ReferenceCounting.html)
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_nonbond, sab_almo, sab_kp, sab_kp_nosym, 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, ecoul_1c, rho0_s_rs, rho0_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, 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, rhs)
Get the QUICKSTEP environment.
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)
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:55
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