34 dbcsr_type_no_symmetry, dbcsr_type_symmetric
97#include "./base/base_uses.f90"
103 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'kpoint_methods'
126 CHARACTER(LEN=*),
PARAMETER :: routinen =
'kpoint_initialize'
128 INTEGER :: handle, i, ic, ik, iounit, ir, ira, is, &
129 isign, j, natom, nkind, nr, ns
130 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: atype
131 INTEGER,
ALLOCATABLE,
DIMENSION(:, :) :: agauge
132 INTEGER,
DIMENSION(3, 3) :: frot, krot
134 REAL(kind=
dp) :: eps_kpoint, wsum
135 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: coord, scoord
136 REAL(kind=
dp),
DIMENSION(3) :: diff, kgvec, srot
137 REAL(kind=
dp),
DIMENSION(3, 3) :: srotmat
138 REAL(kind=
dp),
DIMENSION(:),
POINTER :: wkp_full
139 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: xkp_full
143 CALL timeset(routinen, handle)
145 cpassert(
ASSOCIATED(kpoint))
147 SELECT CASE (kpoint%kp_scheme)
152 ALLOCATE (kpoint%xkp(3, 1), kpoint%wkp(1))
153 kpoint%xkp(1:3, 1) = 0.0_dp
154 kpoint%wkp(1) = 1.0_dp
155 ALLOCATE (kpoint%kp_sym(1))
156 NULLIFY (kpoint%kp_sym(1)%kpoint_sym)
158 CASE (
"MONKHORST-PACK",
"MACDONALD")
160 IF (.NOT. kpoint%symmetry)
THEN
163 ALLOCATE (coord(3, natom), scoord(3, natom), atype(natom))
166 coord(1, i) = sin(i*0.12345_dp)
167 coord(2, i) = cos(i*0.23456_dp)
168 coord(3, i) = sin(i*0.34567_dp)
172 natom =
SIZE(particle_set)
173 ALLOCATE (scoord(3, natom), atype(natom))
175 CALL get_atomic_kind(atomic_kind=particle_set(i)%atomic_kind, kind_number=atype(i))
179 IF (kpoint%verbose)
THEN
185 ALLOCATE (kpoint%atype(natom))
188 ALLOCATE (agauge(3, natom))
190 agauge(1:3, i) = -floor(scoord(1:3, i) + 0.5_dp - kpoint%eps_geo)
193 CALL crys_sym_gen(crys_sym, scoord, atype, cell%hmat, delta=kpoint%eps_geo, iounit=iounit, &
194 use_spglib=kpoint%symmetry)
195 CALL kpoint_gen(crys_sym, kpoint%nkp_grid, symm=kpoint%symmetry, shift=kpoint%kp_shift, &
196 full_grid=kpoint%full_grid, gamma_centered=kpoint%gamma_centered, &
197 inversion_symmetry_only=kpoint%inversion_symmetry_only, &
198 use_spglib_reduction= &
201 kpoint%nkp = crys_sym%nkpoint
202 ALLOCATE (kpoint%xkp(3, kpoint%nkp), kpoint%wkp(kpoint%nkp))
203 wsum = sum(crys_sym%wkpoint)
204 DO ik = 1, kpoint%nkp
205 kpoint%xkp(1:3, ik) = crys_sym%xkpoint(1:3, ik)
206 kpoint%wkp(ik) = crys_sym%wkpoint(ik)/wsum
209 eps_kpoint = max(1.e-12_dp, 10.0_dp*kpoint%eps_geo)
215 ALLOCATE (kpoint%kp_sym(kpoint%nkp))
216 DO ik = 1, kpoint%nkp
217 NULLIFY (kpoint%kp_sym(ik)%kpoint_sym)
219 kpsym => kpoint%kp_sym(ik)%kpoint_sym
220 IF (crys_sym%nrtot > 0 .AND. .NOT. crys_sym%fullgrid .AND. &
221 crys_sym%istriz == 1 .AND. .NOT. crys_sym%inversion_only)
THEN
223 kpsym%nwght = nint(crys_sym%wkpoint(ik))
227 DO is = 1,
SIZE(crys_sym%kplink, 2)
228 IF (crys_sym%kplink(2, is) == ik)
THEN
229 DO ic = 1, crys_sym%nrtot
230 srotmat = matmul(cell%h_inv, matmul(crys_sym%rt(1:3, 1:3, ic), cell%hmat))
231 frot(1:3, 1:3) = nint(srotmat(1:3, 1:3))
232 krot(1:3, 1:3) = nint(transpose(
inv_3x3(real(frot(1:3, 1:3), kind=
dp))))
234 ir = merge(crys_sym%ibrot(ic), -crys_sym%ibrot(ic), isign == 1)
235 IF (ir == crys_sym%kpop(is)) cycle
236 kgvec(1:3) = crys_sym%kpmesh(1:3, is) - &
237 matmul(real(merge(krot(1:3, 1:3), -krot(1:3, 1:3), &
238 isign == 1), kind=
dp), &
240 diff(1:3) = kgvec(1:3) - anint(kgvec(1:3))
241 IF (all(abs(diff(1:3)) < eps_kpoint)) ns = ns + 1
246 kpsym%apply_symmetry = .true.
247 natom =
SIZE(particle_set)
248 ALLOCATE (
kpsym%rot(3, 3, ns))
249 ALLOCATE (
kpsym%xkp(3, ns))
250 ALLOCATE (
kpsym%rotp(ns))
251 ALLOCATE (
kpsym%f0(natom, ns))
252 ALLOCATE (
kpsym%fcell(3, natom, ns))
253 ALLOCATE (
kpsym%kgphase(natom, ns))
255 DO is = 1,
SIZE(crys_sym%kplink, 2)
256 IF (crys_sym%kplink(2, is) == ik)
THEN
258 ir = crys_sym%kpop(is)
260 DO ic = 1, crys_sym%nrtot
261 IF (crys_sym%ibrot(ic) == ira)
THEN
263 kpsym%rot(1:3, 1:3, nr) = crys_sym%rt(1:3, 1:3, ic)
264 srotmat = matmul(cell%h_inv, matmul(crys_sym%rt(1:3, 1:3, ic), cell%hmat))
265 frot(1:3, 1:3) = nint(srotmat(1:3, 1:3))
266 kpsym%xkp(1:3, nr) = crys_sym%kpmesh(1:3, is)
267 krot(1:3, 1:3) = nint(transpose(
inv_3x3(real(frot(1:3, 1:3), kind=
dp))))
268 IF (ir < 0) krot(1:3, 1:3) = -krot(1:3, 1:3)
269 kgvec(1:3) =
kpsym%xkp(1:3, nr) - &
270 matmul(real(krot(1:3, 1:3), kind=
dp), &
272 kgvec(1:3) = anint(kgvec(1:3))
273 kpsym%f0(1:natom, nr) = crys_sym%f0(1:natom, ic)
275 srot(1:3) = matmul(srotmat, scoord(1:3, j)) + crys_sym%vt(1:3, ic)
276 kpsym%fcell(1:3, j, nr) = &
277 nint(srot(1:3) - scoord(1:3,
kpsym%f0(j, nr))) + &
278 matmul(frot(1:3, 1:3), agauge(1:3, j)) - &
279 agauge(1:3,
kpsym%f0(j, nr))
280 kpsym%kgphase(j, nr) = dot_product(kgvec(1:3), &
282 REAL(agauge(1:3, j), kind=
dp))
287 cpassert(ic <= crys_sym%nrtot)
290 DO is = 1,
SIZE(crys_sym%kplink, 2)
291 IF (crys_sym%kplink(2, is) == ik)
THEN
292 DO ic = 1, crys_sym%nrtot
293 srotmat = matmul(cell%h_inv, matmul(crys_sym%rt(1:3, 1:3, ic), cell%hmat))
294 frot(1:3, 1:3) = nint(srotmat(1:3, 1:3))
295 krot(1:3, 1:3) = nint(transpose(
inv_3x3(real(frot(1:3, 1:3), kind=
dp))))
297 ir = merge(crys_sym%ibrot(ic), -crys_sym%ibrot(ic), isign == 1)
298 IF (ir == crys_sym%kpop(is)) cycle
299 kgvec(1:3) = crys_sym%kpmesh(1:3, is) - &
300 matmul(real(merge(krot(1:3, 1:3), -krot(1:3, 1:3), &
301 isign == 1), kind=
dp), &
303 diff(1:3) = kgvec(1:3) - anint(kgvec(1:3))
304 IF (all(abs(diff(1:3)) < eps_kpoint))
THEN
307 kpsym%rot(1:3, 1:3, nr) = crys_sym%rt(1:3, 1:3, ic)
308 kpsym%xkp(1:3, nr) = crys_sym%kpmesh(1:3, is)
309 kgvec(1:3) = anint(kgvec(1:3))
310 kpsym%f0(1:natom, nr) = crys_sym%f0(1:natom, ic)
312 srot(1:3) = matmul(srotmat, scoord(1:3, j)) + crys_sym%vt(1:3, ic)
313 kpsym%fcell(1:3, j, nr) = &
314 nint(srot(1:3) - scoord(1:3,
kpsym%f0(j, nr))) + &
315 matmul(frot(1:3, 1:3), agauge(1:3, j)) - &
316 agauge(1:3,
kpsym%f0(j, nr))
317 kpsym%kgphase(j, nr) = dot_product(kgvec(1:3), &
319 REAL(agauge(1:3, j), kind=
dp))
330 IF (kpoint%symmetry)
THEN
331 nkind = maxval(atype)
333 ALLOCATE (kpoint%kind_rotmat(ns, nkind))
336 NULLIFY (kpoint%kind_rotmat(i, j)%rmat)
339 ALLOCATE (kpoint%ibrot(ns))
340 kpoint%ibrot(1:ns) = crys_sym%ibrot(1:ns)
344 DEALLOCATE (scoord, atype)
348 NULLIFY (xkp_full, wkp_full)
349 IF (
ASSOCIATED(kpoint%xkp_input))
THEN
350 xkp_full => kpoint%xkp_input
351 wkp_full => kpoint%wkp_input
353 xkp_full => kpoint%xkp
354 wkp_full => kpoint%wkp
356 cpassert(
ASSOCIATED(xkp_full))
357 cpassert(
ASSOCIATED(wkp_full))
358 IF (.NOT.
ASSOCIATED(kpoint%xkp_input))
THEN
359 ALLOCATE (kpoint%xkp_input(3,
SIZE(wkp_full)), kpoint%wkp_input(
SIZE(wkp_full)))
360 kpoint%xkp_input(1:3, 1:
SIZE(wkp_full)) = xkp_full(1:3, 1:
SIZE(wkp_full))
361 kpoint%wkp_input(1:
SIZE(wkp_full)) = wkp_full(1:
SIZE(wkp_full))
362 xkp_full => kpoint%xkp_input
363 wkp_full => kpoint%wkp_input
365 IF (.NOT. kpoint%symmetry)
THEN
366 IF (.NOT.
ASSOCIATED(kpoint%xkp))
THEN
367 kpoint%nkp =
SIZE(wkp_full)
368 ALLOCATE (kpoint%xkp(3, kpoint%nkp), kpoint%wkp(kpoint%nkp))
369 kpoint%xkp(1:3, 1:kpoint%nkp) = xkp_full(1:3, 1:kpoint%nkp)
370 kpoint%wkp(1:kpoint%nkp) = wkp_full(1:kpoint%nkp)
373 ALLOCATE (kpoint%kp_sym(kpoint%nkp))
375 NULLIFY (kpoint%kp_sym(i)%kpoint_sym)
379 IF (kpoint%verbose)
THEN
384 natom =
SIZE(particle_set)
385 ALLOCATE (scoord(3, natom), atype(natom))
387 CALL get_atomic_kind(atomic_kind=particle_set(i)%atomic_kind, kind_number=atype(i))
390 ALLOCATE (kpoint%atype(natom))
392 ALLOCATE (agauge(3, natom))
394 agauge(1:3, i) = -floor(scoord(1:3, i) + 0.5_dp - kpoint%eps_geo)
397 CALL crys_sym_gen(crys_sym, scoord, atype, cell%hmat, delta=kpoint%eps_geo, iounit=iounit, &
401 full_grid=kpoint%full_grid, &
402 inversion_symmetry_only=kpoint%inversion_symmetry_only, &
403 use_spglib_reduction= &
406 IF (
ASSOCIATED(kpoint%xkp))
THEN
407 DEALLOCATE (kpoint%xkp)
410 IF (
ASSOCIATED(kpoint%wkp))
THEN
411 DEALLOCATE (kpoint%wkp)
414 kpoint%nkp = crys_sym%nkpoint
415 ALLOCATE (kpoint%xkp(3, kpoint%nkp), kpoint%wkp(kpoint%nkp))
416 wsum = sum(crys_sym%wkpoint)
417 DO ik = 1, kpoint%nkp
418 kpoint%xkp(1:3, ik) = crys_sym%xkpoint(1:3, ik)
419 kpoint%wkp(ik) = crys_sym%wkpoint(ik)/wsum
422 eps_kpoint = max(1.e-12_dp, 10.0_dp*kpoint%eps_geo)
426 ALLOCATE (kpoint%kp_sym(kpoint%nkp))
427 DO ik = 1, kpoint%nkp
428 NULLIFY (kpoint%kp_sym(ik)%kpoint_sym)
430 kpsym => kpoint%kp_sym(ik)%kpoint_sym
431 IF (crys_sym%nrtot > 0 .AND. .NOT. crys_sym%fullgrid .AND. &
432 crys_sym%istriz == 1 .AND. .NOT. crys_sym%inversion_only)
THEN
433 kpsym%nwght = nint(crys_sym%wkpoint(ik))
436 DO is = 1,
SIZE(crys_sym%kplink, 2)
437 IF (crys_sym%kplink(2, is) == ik)
THEN
438 DO ic = 1, crys_sym%nrtot
439 srotmat = matmul(cell%h_inv, matmul(crys_sym%rt(1:3, 1:3, ic), cell%hmat))
440 frot(1:3, 1:3) = nint(srotmat(1:3, 1:3))
441 krot(1:3, 1:3) = nint(transpose(
inv_3x3(real(frot(1:3, 1:3), kind=
dp))))
443 ir = merge(crys_sym%ibrot(ic), -crys_sym%ibrot(ic), isign == 1)
444 IF (ir == crys_sym%kpop(is)) cycle
445 kgvec(1:3) = crys_sym%kpmesh(1:3, is) - &
446 matmul(real(merge(krot(1:3, 1:3), -krot(1:3, 1:3), &
447 isign == 1), kind=
dp), &
449 diff(1:3) = kgvec(1:3) - anint(kgvec(1:3))
450 IF (all(abs(diff(1:3)) < eps_kpoint)) ns = ns + 1
455 kpsym%apply_symmetry = .true.
456 ALLOCATE (
kpsym%rot(3, 3, ns))
457 ALLOCATE (
kpsym%xkp(3, ns))
458 ALLOCATE (
kpsym%rotp(ns))
459 ALLOCATE (
kpsym%f0(natom, ns))
460 ALLOCATE (
kpsym%fcell(3, natom, ns))
461 ALLOCATE (
kpsym%kgphase(natom, ns))
463 DO is = 1,
SIZE(crys_sym%kplink, 2)
464 IF (crys_sym%kplink(2, is) == ik)
THEN
466 ir = crys_sym%kpop(is)
468 DO ic = 1, crys_sym%nrtot
469 IF (crys_sym%ibrot(ic) == ira)
THEN
471 kpsym%rot(1:3, 1:3, nr) = crys_sym%rt(1:3, 1:3, ic)
472 srotmat = matmul(cell%h_inv, matmul(crys_sym%rt(1:3, 1:3, ic), cell%hmat))
473 frot(1:3, 1:3) = nint(srotmat(1:3, 1:3))
474 kpsym%xkp(1:3, nr) = crys_sym%kpmesh(1:3, is)
475 krot(1:3, 1:3) = nint(transpose(
inv_3x3(real(frot(1:3, 1:3), kind=
dp))))
476 IF (ir < 0) krot(1:3, 1:3) = -krot(1:3, 1:3)
477 kgvec(1:3) =
kpsym%xkp(1:3, nr) - &
478 matmul(real(krot(1:3, 1:3), kind=
dp), &
480 kgvec(1:3) = anint(kgvec(1:3))
481 kpsym%f0(1:natom, nr) = crys_sym%f0(1:natom, ic)
483 srot(1:3) = matmul(srotmat, scoord(1:3, j)) + crys_sym%vt(1:3, ic)
484 kpsym%fcell(1:3, j, nr) = &
485 nint(srot(1:3) - scoord(1:3,
kpsym%f0(j, nr))) + &
486 matmul(frot(1:3, 1:3), agauge(1:3, j)) - &
487 agauge(1:3,
kpsym%f0(j, nr))
488 kpsym%kgphase(j, nr) = dot_product(kgvec(1:3), &
490 REAL(agauge(1:3, j), kind=
dp))
495 cpassert(ic <= crys_sym%nrtot)
498 DO is = 1,
SIZE(crys_sym%kplink, 2)
499 IF (crys_sym%kplink(2, is) == ik)
THEN
500 DO ic = 1, crys_sym%nrtot
501 srotmat = matmul(cell%h_inv, matmul(crys_sym%rt(1:3, 1:3, ic), cell%hmat))
502 frot(1:3, 1:3) = nint(srotmat(1:3, 1:3))
503 krot(1:3, 1:3) = nint(transpose(
inv_3x3(real(frot(1:3, 1:3), kind=
dp))))
505 ir = merge(crys_sym%ibrot(ic), -crys_sym%ibrot(ic), isign == 1)
506 IF (ir == crys_sym%kpop(is)) cycle
507 kgvec(1:3) = crys_sym%kpmesh(1:3, is) - &
508 matmul(real(merge(krot(1:3, 1:3), -krot(1:3, 1:3), &
509 isign == 1), kind=
dp), &
511 diff(1:3) = kgvec(1:3) - anint(kgvec(1:3))
512 IF (all(abs(diff(1:3)) < eps_kpoint))
THEN
515 kpsym%rot(1:3, 1:3, nr) = crys_sym%rt(1:3, 1:3, ic)
516 kpsym%xkp(1:3, nr) = crys_sym%kpmesh(1:3, is)
517 kgvec(1:3) = anint(kgvec(1:3))
518 kpsym%f0(1:natom, nr) = crys_sym%f0(1:natom, ic)
520 srot(1:3) = matmul(srotmat, scoord(1:3, j)) + crys_sym%vt(1:3, ic)
521 kpsym%fcell(1:3, j, nr) = &
522 nint(srot(1:3) - scoord(1:3,
kpsym%f0(j, nr))) + &
523 matmul(frot(1:3, 1:3), agauge(1:3, j)) - &
524 agauge(1:3,
kpsym%f0(j, nr))
525 kpsym%kgphase(j, nr) = dot_product(kgvec(1:3), &
527 REAL(agauge(1:3, j), kind=
dp))
538 nkind = maxval(atype)
540 ALLOCATE (kpoint%kind_rotmat(ns, nkind))
543 NULLIFY (kpoint%kind_rotmat(i, j)%rmat)
546 ALLOCATE (kpoint%ibrot(ns))
547 kpoint%ibrot(1:ns) = crys_sym%ibrot(1:ns)
550 DEALLOCATE (scoord, atype)
554 cpabort(
"Option invalid or unavailable for kpoint%kp_scheme")
558 SELECT CASE (kpoint%kp_scheme)
562 cpassert(kpoint%nkp == 1)
563 cpassert(sum(abs(kpoint%xkp)) <= 1.e-12_dp)
564 cpassert(kpoint%wkp(1) == 1.0_dp)
565 cpassert(.NOT. kpoint%symmetry)
567 cpassert(kpoint%nkp >= 1)
568 CASE (
"MONKHORST-PACK",
"MACDONALD")
569 cpassert(kpoint%nkp >= 1)
571 IF (kpoint%use_real_wfn)
THEN
573 ikloop:
DO ik = 1, kpoint%nkp
575 spez = (kpoint%xkp(i, ik) == 0.0_dp .OR. kpoint%xkp(i, ik) == 0.5_dp)
576 IF (.NOT. spez)
EXIT ikloop
581 CALL cp_warn(__location__, &
582 "A calculation using real wavefunctions is requested. "// &
583 "We could not determine if the symmetry of the system allows real wavefunctions. ")
587 CALL timestop(handle)
603 LOGICAL,
INTENT(IN),
OPTIONAL :: with_aux_fit
605 CHARACTER(LEN=*),
PARAMETER :: routinen =
'kpoint_env_initialize'
607 INTEGER :: handle, igr, ik, ikk, ngr, niogrp, nkp, &
608 nkp_grp, nkp_loc, npe, unit_nr
609 INTEGER,
DIMENSION(2) :: dims, pos
616 CALL timeset(routinen, handle)
618 IF (
PRESENT(with_aux_fit))
THEN
619 aux_fit = with_aux_fit
624 kpoint%para_env => para_env
625 CALL kpoint%para_env%retain()
626 kpoint%blacs_env_all => blacs_env
627 CALL kpoint%blacs_env_all%retain()
629 cpassert(.NOT.
ASSOCIATED(kpoint%kp_env))
631 cpassert(.NOT.
ASSOCIATED(kpoint%kp_aux_env))
634 NULLIFY (kp_env, kp_aux_env)
636 npe = para_env%num_pe
639 ALLOCATE (kp_env(nkp))
641 NULLIFY (kp_env(ik)%kpoint_env)
643 kp => kp_env(ik)%kpoint_env
645 kp%wkp = kpoint%wkp(ik)
646 kp%xkp(1:3) = kpoint%xkp(1:3, ik)
649 kpoint%kp_env => kp_env
652 ALLOCATE (kp_aux_env(nkp))
654 NULLIFY (kp_aux_env(ik)%kpoint_env)
656 kp => kp_aux_env(ik)%kpoint_env
658 kp%wkp = kpoint%wkp(ik)
659 kp%xkp(1:3) = kpoint%xkp(1:3, ik)
663 kpoint%kp_aux_env => kp_aux_env
666 ALLOCATE (kpoint%kp_dist(2, 1))
667 kpoint%kp_dist(1, 1) = 1
668 kpoint%kp_dist(2, 1) = nkp
669 kpoint%kp_range(1) = 1
670 kpoint%kp_range(2) = nkp
673 kpoint%para_env_kp => para_env
674 CALL kpoint%para_env_kp%retain()
675 kpoint%para_env_inter_kp => para_env
676 CALL kpoint%para_env_inter_kp%retain()
677 kpoint%iogrp = .true.
678 kpoint%nkp_groups = 1
680 IF (kpoint%parallel_group_size == -1)
THEN
685 IF (mod(npe, igr) /= 0) cycle
687 IF (mod(nkp, nkp_grp) /= 0) cycle
690 ELSE IF (kpoint%parallel_group_size == 0)
THEN
693 ELSE IF (kpoint%parallel_group_size > 0)
THEN
694 ngr = min(kpoint%parallel_group_size, npe)
696 cpabort(
"kpoint%parallel_group_size cannot be smaller than -1")
702 cpassert(mod(nkp, nkp_grp) == 0)
703 nkp_loc = nkp/nkp_grp
705 IF ((dims(1)*dims(2) /= npe))
THEN
706 cpabort(
"Number of processors is not divisible by the kpoint group size.")
710 CALL comm_cart%create(comm_old=para_env, ndims=2, dims=dims)
711 pos = comm_cart%mepos_cart
712 ALLOCATE (para_env_kp)
713 CALL para_env_kp%from_split(comm_cart, pos(2))
714 ALLOCATE (para_env_inter_kp)
715 CALL para_env_inter_kp%from_split(comm_cart, pos(1))
716 CALL comm_cart%free()
719 IF (para_env%is_source()) niogrp = 1
720 CALL para_env_kp%sum(niogrp)
721 kpoint%iogrp = (niogrp == 1)
724 kpoint%para_env_kp => para_env_kp
725 kpoint%para_env_inter_kp => para_env_inter_kp
728 ALLOCATE (kpoint%kp_dist(2, nkp_grp))
730 kpoint%kp_dist(1:2, igr) =
get_limit(nkp, nkp_grp, igr - 1)
733 kpoint%kp_range(1:2) = kpoint%kp_dist(1:2, para_env_inter_kp%mepos + 1)
735 ALLOCATE (kp_env(nkp_loc))
737 NULLIFY (kp_env(ik)%kpoint_env)
738 ikk = kpoint%kp_range(1) + ik - 1
740 kp => kp_env(ik)%kpoint_env
742 kp%wkp = kpoint%wkp(ikk)
743 kp%xkp(1:3) = kpoint%xkp(1:3, ikk)
744 kp%is_local = (ngr == 1)
746 kpoint%kp_env => kp_env
749 ALLOCATE (kp_aux_env(nkp_loc))
751 NULLIFY (kp_aux_env(ik)%kpoint_env)
752 ikk = kpoint%kp_range(1) + ik - 1
754 kp => kp_aux_env(ik)%kpoint_env
756 kp%wkp = kpoint%wkp(ikk)
757 kp%xkp(1:3) = kpoint%xkp(1:3, ikk)
758 kp%is_local = (ngr == 1)
760 kpoint%kp_aux_env => kp_aux_env
765 IF (unit_nr > 0 .AND. kpoint%verbose)
THEN
767 WRITE (unit_nr, fmt=
"(T2,A,T71,I10)")
"KPOINTS| Number of kpoint groups ", nkp_grp
768 WRITE (unit_nr, fmt=
"(T2,A,T71,I10)")
"KPOINTS| Size of each kpoint group", ngr
769 WRITE (unit_nr, fmt=
"(T2,A,T71,I10)")
"KPOINTS| Number of kpoints per group", nkp_loc
771 kpoint%nkp_groups = nkp_grp
775 CALL timestop(handle)
789 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
790 INTEGER,
INTENT(IN),
OPTIONAL :: added_mos
791 LOGICAL,
OPTIONAL :: for_aux_fit
793 CHARACTER(LEN=*),
PARAMETER :: routinen =
'kpoint_initialize_mos'
795 INTEGER :: handle, ic, ik, is, nadd, nao, nc, &
796 nelectron, nkp_loc, nmo, nmorig(2), &
799 REAL(kind=
dp) :: flexible_electron_count, maxocc, n_el_f
807 CALL timeset(routinen, handle)
809 IF (
PRESENT(for_aux_fit))
THEN
810 aux_fit = for_aux_fit
815 cpassert(
ASSOCIATED(kpoint))
817 IF (.true. .OR.
ASSOCIATED(mos(1)%mo_coeff))
THEN
819 cpassert(
ASSOCIATED(kpoint%kp_aux_env))
822 IF (
PRESENT(added_mos))
THEN
828 IF (kpoint%use_real_wfn)
THEN
834 nkp_loc = kpoint%kp_range(2) - kpoint%kp_range(1) + 1
835 IF (nkp_loc > 0)
THEN
837 cpassert(
SIZE(kpoint%kp_aux_env) == nkp_loc)
839 cpassert(
SIZE(kpoint%kp_env) == nkp_loc)
844 kp => kpoint%kp_aux_env(ik)%kpoint_env
846 kp => kpoint%kp_env(ik)%kpoint_env
848 ALLOCATE (kp%mos(nc, nspin))
850 CALL get_mo_set(mos(is), nao=nao, nmo=nmo, nelectron=nelectron, &
851 n_el_f=n_el_f, maxocc=maxocc, flexible_electron_count=flexible_electron_count)
852 nmo = min(nao, nmo + nadd)
854 CALL allocate_mo_set(kp%mos(ic, is), nao, nmo, nelectron, n_el_f, maxocc, &
855 flexible_electron_count)
865 IF (
ASSOCIATED(kpoint%blacs_env))
THEN
866 blacs_env => kpoint%blacs_env
869 kpoint%blacs_env => blacs_env
875 nmo = min(nao, nmorig(is) + nadd)
883 blacs_env=blacs_env, para_env=kpoint%para_env_kp)
886 kpoint%mpools_aux_fit => mpools
888 kpoint%mpools => mpools
897 CALL mpools_get(mpools, ao_ao_fm_pools=ao_ao_fm_pools)
903 kp => kpoint%kp_aux_env(ik)%kpoint_env
905 kp => kpoint%kp_env(ik)%kpoint_env
909 ALLOCATE (kp%pmat(nc, nspin))
917 ALLOCATE (kp%wmat(nc, nspin))
931 CALL timestop(handle)
942 CHARACTER(LEN=*),
PARAMETER :: routinen =
'kpoint_initialize_mo_set'
944 INTEGER :: handle, ic, ik, ikk, ispin
947 TYPE(
mo_set_type),
DIMENSION(:, :),
POINTER :: moskp
949 CALL timeset(routinen, handle)
951 DO ik = 1,
SIZE(kpoint%kp_env)
952 CALL mpools_get(kpoint%mpools, ao_mo_fm_pools=ao_mo_fm_pools)
953 moskp => kpoint%kp_env(ik)%kpoint_env%mos
954 ikk = kpoint%kp_range(1) + ik - 1
955 cpassert(
ASSOCIATED(moskp))
956 DO ispin = 1,
SIZE(moskp, 2)
957 DO ic = 1,
SIZE(moskp, 1)
958 CALL get_mo_set(moskp(ic, ispin), mo_coeff=mo_coeff)
959 IF (.NOT.
ASSOCIATED(mo_coeff))
THEN
961 fm_pool=ao_mo_fm_pools(ispin)%pool, name=
"kpoints")
967 CALL timestop(handle)
985 INTEGER,
INTENT(OUT) :: nimages
987 CHARACTER(LEN=*),
PARAMETER :: routinen =
'kpoint_init_cell_index'
989 INTEGER :: handle, i1, i2, i3, ic, icount, it, &
991 INTEGER,
DIMENSION(3) :: cell, itm
992 INTEGER,
DIMENSION(:, :),
POINTER :: index_to_cell,
list
993 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index, cti
996 DIMENSION(:),
POINTER :: nl_iterator
998 NULLIFY (cell_to_index, index_to_cell)
1000 CALL timeset(routinen, handle)
1002 cpassert(
ASSOCIATED(kpoint))
1004 ALLOCATE (
list(3, 125))
1014 IF (cell(1) ==
list(1, ic) .AND. cell(2) ==
list(2, ic) .AND. &
1015 cell(3) ==
list(3, ic))
THEN
1022 IF (icount >
SIZE(
list, 2))
THEN
1025 list(1:3, icount) = cell(1:3)
1031 itm(1) = maxval(abs(
list(1, 1:icount)))
1032 itm(2) = maxval(abs(
list(2, 1:icount)))
1033 itm(3) = maxval(abs(
list(3, 1:icount)))
1034 CALL para_env%max(itm)
1035 it = maxval(itm(1:3))
1036 IF (
ASSOCIATED(kpoint%cell_to_index))
THEN
1037 DEALLOCATE (kpoint%cell_to_index)
1039 ALLOCATE (kpoint%cell_to_index(-itm(1):itm(1), -itm(2):itm(2), -itm(3):itm(3)))
1040 cell_to_index => kpoint%cell_to_index
1041 cti => cell_to_index
1047 cti(i1, i2, i3) = ic
1049 CALL para_env%sum(cti)
1051 DO i1 = -itm(1), itm(1)
1052 DO i2 = -itm(2), itm(2)
1053 DO i3 = -itm(3), itm(3)
1054 IF (cti(i1, i2, i3) == 0)
THEN
1055 cti(i1, i2, i3) = 1000000
1058 cti(i1, i2, i3) = (abs(i1) + abs(i2) + abs(i3))*1000 + abs(i3)*100 + abs(i2)*10 + abs(i1)
1059 cti(i1, i2, i3) = cti(i1, i2, i3) + (i1 + i2 + i3)
1065 IF (
ASSOCIATED(kpoint%index_to_cell))
THEN
1066 DEALLOCATE (kpoint%index_to_cell)
1068 ALLOCATE (kpoint%index_to_cell(3, ncount))
1069 index_to_cell => kpoint%index_to_cell
1072 i1 = cell(1) - 1 - itm(1)
1073 i2 = cell(2) - 1 - itm(2)
1074 i3 = cell(3) - 1 - itm(3)
1075 cti(i1, i2, i3) = 1000000
1076 index_to_cell(1, ic) = i1
1077 index_to_cell(2, ic) = i2
1078 index_to_cell(3, ic) = i3
1082 i1 = index_to_cell(1, ic)
1083 i2 = index_to_cell(2, ic)
1084 i3 = index_to_cell(3, ic)
1085 cti(i1, i2, i3) = ic
1089 kpoint%sab_nl => sab_nl
1092 nimages =
SIZE(index_to_cell, 2)
1096 CALL timestop(handle)
1113 xkp, cell_to_index, sab_nl, is_complex, rs_sign)
1118 INTEGER,
INTENT(IN) :: ispin
1119 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: xkp
1120 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
1123 LOGICAL,
INTENT(IN),
OPTIONAL :: is_complex
1124 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: rs_sign
1126 CHARACTER(LEN=*),
PARAMETER :: routinen =
'rskp_transform'
1128 INTEGER :: handle, iatom, ic, icol, irow, jatom, &
1130 INTEGER,
DIMENSION(3) :: cell
1131 LOGICAL :: do_symmetric, found, my_complex, &
1133 REAL(kind=
dp) :: arg, coskl, fsign, fsym, sinkl
1134 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: cblock, rblock, rsblock
1136 DIMENSION(:),
POINTER :: nl_iterator
1138 CALL timeset(routinen, handle)
1140 my_complex = .false.
1141 IF (
PRESENT(is_complex)) my_complex = is_complex
1144 IF (
PRESENT(rs_sign)) fsign = rs_sign
1146 wfn_real_only = .true.
1147 IF (
PRESENT(cmatrix)) wfn_real_only = .false.
1149 nimg =
SIZE(rsmat, 2)
1162 IF (do_symmetric .AND. (iatom > jatom))
THEN
1168 ic = cell_to_index(cell(1), cell(2), cell(3))
1169 IF (ic < 1 .OR. ic > nimg) cycle
1171 arg = real(cell(1),
dp)*xkp(1) + real(cell(2),
dp)*xkp(2) + real(cell(3),
dp)*xkp(3)
1172 IF (my_complex)
THEN
1173 coskl = fsign*fsym*cos(
twopi*arg)
1174 sinkl = fsign*sin(
twopi*arg)
1176 coskl = fsign*cos(
twopi*arg)
1177 sinkl = fsign*fsym*sin(
twopi*arg)
1181 block=rsblock, found=found)
1182 IF (.NOT. found) cycle
1184 IF (wfn_real_only)
THEN
1186 block=rblock, found=found)
1187 IF (.NOT. found) cycle
1188 rblock = rblock + coskl*rsblock
1191 block=rblock, found=found)
1192 IF (.NOT. found) cycle
1194 block=cblock, found=found)
1195 IF (.NOT. found) cycle
1196 rblock = rblock + coskl*rsblock
1197 cblock = cblock + sinkl*rsblock
1203 CALL timestop(handle)
1220 CHARACTER(LEN=*),
PARAMETER :: routinen =
'kpoint_set_mo_occupation'
1222 INTEGER :: handle, ik, ikpgr, ispin, kplocal, nao, &
1223 nb, ncol_global, ne_a, ne_b, &
1224 nelectron, nkp, nmo, nrow_global, nspin
1225 INTEGER,
DIMENSION(2) :: kp_range
1226 REAL(kind=
dp) :: kts, kts_spin(2), mu, mus(2), nel
1227 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: smatrix
1228 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: weig, wocc
1229 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :, :) :: icoeff, rcoeff
1230 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues, occupation, wkp
1236 CALL timeset(routinen, handle)
1240 kp => kpoint%kp_env(1)%kpoint_env
1241 nspin =
SIZE(kp%mos, 2)
1242 mo_set => kp%mos(1, 1)
1243 CALL get_mo_set(mo_set, nmo=nmo, nao=nao, nelectron=nelectron)
1245 IF (nspin == 2)
THEN
1246 CALL get_mo_set(kp%mos(1, 2), nmo=nb, nelectron=ne_b)
1249 ALLOCATE (weig(nmo, nkp, nspin), wocc(nmo, nkp, nspin))
1252 IF (
PRESENT(probe))
THEN
1253 ALLOCATE (rcoeff(nao, nmo, nkp, nspin), icoeff(nao, nmo, nkp, nspin))
1258 kplocal = kp_range(2) - kp_range(1) + 1
1259 DO ikpgr = 1, kplocal
1260 ik = kp_range(1) + ikpgr - 1
1261 kp => kpoint%kp_env(ikpgr)%kpoint_env
1263 mo_set => kp%mos(1, ispin)
1264 CALL get_mo_set(mo_set, eigenvalues=eigenvalues)
1265 weig(1:nmo, ik, ispin) = eigenvalues(1:nmo)
1266 IF (
PRESENT(probe))
THEN
1269 nrow_global=nrow_global, &
1270 ncol_global=ncol_global)
1271 ALLOCATE (smatrix(nrow_global, ncol_global))
1274 rcoeff(1:nao, 1:nmo, ik, ispin) = smatrix(1:nrow_global, 1:ncol_global)
1276 DEALLOCATE (smatrix)
1278 mo_set => kp%mos(2, ispin)
1282 nrow_global=nrow_global, &
1283 ncol_global=ncol_global)
1284 ALLOCATE (smatrix(nrow_global, ncol_global))
1287 icoeff(1:nao, 1:nmo, ik, ispin) = smatrix(1:nrow_global, 1:ncol_global)
1289 mo_set => kp%mos(1, ispin)
1291 DEALLOCATE (smatrix)
1296 CALL para_env_inter_kp%sum(weig)
1298 IF (
PRESENT(probe))
THEN
1299 CALL para_env_inter_kp%sum(rcoeff)
1300 CALL para_env_inter_kp%sum(icoeff)
1307 IF (
PRESENT(probe))
THEN
1308 smear%do_smear = .false.
1310 IF (nspin == 1)
THEN
1311 nel = real(nelectron, kind=
dp)
1312 CALL probe_occupancy_kp(wocc(:, :, :), mus(1), kts, weig(:, :, :), rcoeff(:, :, :, :), icoeff(:, :, :, :), 2.0d0, &
1315 nel = real(ne_a, kind=
dp) + real(ne_b, kind=
dp)
1316 CALL probe_occupancy_kp(wocc(:, :, :), mu, kts, weig(:, :, :), rcoeff(:, :, :, :), icoeff(:, :, :, :), 1.0d0, &
1322 DO ikpgr = 1, kplocal
1323 ik = kp_range(1) + ikpgr - 1
1324 kp => kpoint%kp_env(ikpgr)%kpoint_env
1326 mo_set => kp%mos(1, ispin)
1327 CALL get_mo_set(mo_set, eigenvalues=eigenvalues, occupation_numbers=occupation)
1328 eigenvalues(1:nmo) = weig(1:nmo, ik, ispin)
1329 occupation(1:nmo) = wocc(1:nmo, ik, ispin)
1331 mo_set%mu = mus(ispin)
1336 nrow_global=nrow_global, &
1337 ncol_global=ncol_global)
1338 ALLOCATE (smatrix(nrow_global, ncol_global))
1341 smatrix(1:nrow_global, 1:ncol_global) = rcoeff(1:nao, 1:nmo, ik, ispin)
1342 DEALLOCATE (smatrix)
1344 mo_set => kp%mos(2, ispin)
1349 nrow_global=nrow_global, &
1350 ncol_global=ncol_global)
1351 ALLOCATE (smatrix(nrow_global, ncol_global))
1354 smatrix(1:nrow_global, 1:ncol_global) = icoeff(1:nao, 1:nmo, ik, ispin)
1355 DEALLOCATE (smatrix)
1357 mo_set => kp%mos(1, ispin)
1362 DEALLOCATE (weig, wocc, rcoeff, icoeff)
1366 IF (
PRESENT(probe) .EQV. .false.)
THEN
1367 IF (smear%do_smear)
THEN
1368 SELECT CASE (smear%method)
1371 IF (nspin == 1)
THEN
1372 nel = real(nelectron, kind=
dp)
1373 CALL smearkp(wocc(:, :, 1), mus(1), kts, weig(:, :, 1), nel, wkp, &
1376 ELSE IF (smear%fixed_mag_mom > 0.0_dp)
THEN
1377 nel = real(ne_a, kind=
dp)
1378 CALL smearkp(wocc(:, :, 1), mus(1), kts, weig(:, :, 1), nel, wkp, &
1381 nel = real(ne_b, kind=
dp)
1382 CALL smearkp(wocc(:, :, 2), mus(2), kts, weig(:, :, 2), nel, wkp, &
1386 nel = real(ne_a, kind=
dp) + real(ne_b, kind=
dp)
1387 CALL smearkp2(wocc(:, :, :), mu, kts, weig(:, :, :), nel, wkp, &
1394 IF (nspin == 1)
THEN
1395 nel = real(nelectron, kind=
dp)
1396 CALL smearkp(wocc(:, :, 1), mus(1), kts, weig(:, :, 1), nel, wkp, &
1397 smear%smearing_width, 2.0_dp, smear%method)
1399 ELSE IF (smear%fixed_mag_mom > 0.0_dp)
THEN
1400 nel = real(ne_a, kind=
dp)
1401 CALL smearkp(wocc(:, :, 1), mus(1), kts, weig(:, :, 1), nel, wkp, &
1402 smear%smearing_width, 1.0_dp, smear%method)
1404 nel = real(ne_b, kind=
dp)
1405 CALL smearkp(wocc(:, :, 2), mus(2), kts, weig(:, :, 2), nel, wkp, &
1406 smear%smearing_width, 1.0_dp, smear%method)
1409 nel = real(ne_a, kind=
dp) + real(ne_b, kind=
dp)
1410 CALL smearkp2(wocc(:, :, :), mu, kts, weig(:, :, :), nel, wkp, &
1411 smear%smearing_width, smear%method)
1417 cpabort(
"kpoints: Selected smearing not (yet) supported")
1421 IF (nspin == 1)
THEN
1422 nel = real(nelectron, kind=
dp)
1423 CALL smearkp(wocc(:, :, 1), mus(1), kts, weig(:, :, 1), nel, wkp, &
1427 nel = real(ne_a, kind=
dp)
1428 CALL smearkp(wocc(:, :, 1), mus(1), kts, weig(:, :, 1), nel, wkp, &
1431 nel = real(ne_b, kind=
dp)
1432 CALL smearkp(wocc(:, :, 2), mus(2), kts, weig(:, :, 2), nel, wkp, &
1437 DO ikpgr = 1, kplocal
1438 ik = kp_range(1) + ikpgr - 1
1439 kp => kpoint%kp_env(ikpgr)%kpoint_env
1441 mo_set => kp%mos(1, ispin)
1442 CALL get_mo_set(mo_set, eigenvalues=eigenvalues, occupation_numbers=occupation)
1443 eigenvalues(1:nmo) = weig(1:nmo, ik, ispin)
1444 occupation(1:nmo) = wocc(1:nmo, ik, ispin)
1445 mo_set%kTS = kts_spin(ispin)
1446 mo_set%mu = mus(ispin)
1450 DEALLOCATE (weig, wocc)
1454 CALL timestop(handle)
1467 LOGICAL,
OPTIONAL :: energy_weighted, for_aux_fit
1469 CHARACTER(LEN=*),
PARAMETER :: routinen =
'kpoint_density_matrices'
1471 INTEGER :: handle, ikpgr, ispin, kplocal, nao, nmo, &
1473 INTEGER,
DIMENSION(2) :: kp_range
1474 LOGICAL :: aux_fit, wtype
1475 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues, occupation
1478 TYPE(
cp_fm_type),
POINTER :: cpmat, pmat, rpmat
1482 CALL timeset(routinen, handle)
1484 IF (
PRESENT(energy_weighted))
THEN
1485 wtype = energy_weighted
1491 IF (
PRESENT(for_aux_fit))
THEN
1492 aux_fit = for_aux_fit
1498 cpassert(
ASSOCIATED(kpoint%kp_aux_env))
1503 mo_set => kpoint%kp_aux_env(1)%kpoint_env%mos(1, 1)
1505 mo_set => kpoint%kp_env(1)%kpoint_env%mos(1, 1)
1508 CALL cp_fm_get_info(mo_set%mo_coeff, matrix_struct=matrix_struct)
1512 kplocal = kp_range(2) - kp_range(1) + 1
1513 DO ikpgr = 1, kplocal
1515 kp => kpoint%kp_aux_env(ikpgr)%kpoint_env
1517 kp => kpoint%kp_env(ikpgr)%kpoint_env
1519 nspin =
SIZE(kp%mos, 2)
1521 mo_set => kp%mos(1, ispin)
1523 CALL get_mo_set(mo_set, eigenvalues=eigenvalues)
1525 IF (kpoint%use_real_wfn)
THEN
1527 pmat => kp%wmat(1, ispin)
1529 pmat => kp%pmat(1, ispin)
1531 CALL get_mo_set(mo_set, occupation_numbers=occupation)
1537 CALL parallel_gemm(
"N",
"T", nao, nao, nmo, 1.0_dp, mo_set%mo_coeff, fwork, 0.0_dp, pmat)
1540 rpmat => kp%wmat(1, ispin)
1541 cpmat => kp%wmat(2, ispin)
1543 rpmat => kp%pmat(1, ispin)
1544 cpmat => kp%pmat(2, ispin)
1546 CALL get_mo_set(mo_set, occupation_numbers=occupation)
1553 CALL parallel_gemm(
"N",
"T", nao, nao, nmo, 1.0_dp, mo_set%mo_coeff, fwork, 0.0_dp, rpmat)
1554 mo_set => kp%mos(2, ispin)
1556 CALL parallel_gemm(
"N",
"T", nao, nao, nmo, 1.0_dp, mo_set%mo_coeff, fwork, 0.0_dp, cpmat)
1558 CALL parallel_gemm(
"N",
"T", nao, nao, nmo, -1.0_dp, fwork, mo_set%mo_coeff, 1.0_dp, cpmat)
1565 CALL parallel_gemm(
"N",
"T", nao, nao, nmo, 1.0_dp, mo_set%mo_coeff, fwork, 1.0_dp, rpmat)
1572 CALL timestop(handle)
1587 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT) :: pmat_diag
1589 CHARACTER(LEN=*),
PARAMETER :: routinen =
'lowdin_kp_trans'
1590 COMPLEX(KIND=dp),
PARAMETER :: cone = (1.0_dp, 0.0_dp), &
1591 czero = (0.0_dp, 0.0_dp)
1593 INTEGER :: handle, ikpgr, ispin, kplocal, nao, nspin
1594 INTEGER,
DIMENSION(2) :: kp_range
1595 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: dele
1600 TYPE(
cp_fm_type),
POINTER :: cpmat, pmat, rpmat, shalf
1604 CALL timeset(routinen, handle)
1606 nspin =
SIZE(pmat_diag, 2)
1611 matrix_struct=matrix_struct, nrow_global=nao)
1612 IF (kpoint%use_real_wfn)
THEN
1613 CALL cp_fm_create(f1work, matrix_struct, nrow=nao, ncol=nao)
1614 CALL cp_fm_create(f2work, matrix_struct, nrow=nao, ncol=nao)
1616 CALL cp_fm_create(f2work, matrix_struct, nrow=nao, ncol=nao)
1617 CALL cp_cfm_create(cf1work, matrix_struct, nrow=nao, ncol=nao)
1618 CALL cp_cfm_create(cf2work, matrix_struct, nrow=nao, ncol=nao)
1620 ALLOCATE (dele(nao))
1623 kplocal = kp_range(2) - kp_range(1) + 1
1624 DO ikpgr = 1, kplocal
1625 kp => kpoint%kp_env(ikpgr)%kpoint_env
1627 IF (kpoint%use_real_wfn)
THEN
1628 pmat => kp%pmat(1, ispin)
1630 CALL parallel_gemm(
"N",
"N", nao, nao, nao, 1.0_dp, pmat, shalf, 0.0_dp, f1work)
1631 CALL parallel_gemm(
"N",
"N", nao, nao, nao, 1.0_dp, shalf, f1work, 0.0_dp, f2work)
1633 rpmat => kp%pmat(1, ispin)
1634 cpmat => kp%pmat(2, ispin)
1637 CALL parallel_gemm(
"N",
"N", nao, nao, nao, cone, cf1work, cshalf, czero, cf2work)
1638 CALL parallel_gemm(
"N",
"N", nao, nao, nao, cone, cshalf, cf2work, czero, cf1work)
1642 pmat_diag(1:nao, ispin) = pmat_diag(1:nao, ispin) + kp%wkp*dele(1:nao)
1647 CALL para_env_inter_kp%sum(pmat_diag)
1649 IF (kpoint%use_real_wfn)
THEN
1659 CALL timestop(handle)
1674 INTEGER,
INTENT(IN) :: ispin
1676 TYPE(
cp_fm_type),
INTENT(INOUT),
OPTIONAL :: shalfc
1677 TYPE(
cp_cfm_type),
INTENT(INOUT),
OPTIONAL :: cshalfc
1681 TYPE(
cp_fm_type) :: cshalf_im, cshalf_re, shalf_im, shalf_re
1682 TYPE(
mo_set_type),
POINTER :: mo_set, mo_set_im, mo_set_re
1685 cpassert(
PRESENT(shalfc))
1686 mo_set => kp%mos(1, ispin)
1689 CALL parallel_gemm(
"N",
"N", nao, nmo, nao, 1.0_dp, kp%shalf, &
1690 mo_set%mo_coeff, 0.0_dp, shalfc)
1692 cpassert(
PRESENT(cshalfc))
1693 mo_set_re => kp%mos(1, ispin)
1694 mo_set_im => kp%mos(2, ispin)
1696 CALL cp_fm_get_info(mo_set_re%mo_coeff, matrix_struct=matrix_struct_mo)
1699 CALL cp_fm_create(shalf_re, matrix_struct_shalf, nrow=nao, ncol=nao)
1700 CALL cp_fm_create(shalf_im, matrix_struct_shalf, nrow=nao, ncol=nao)
1701 CALL cp_fm_create(cshalf_re, matrix_struct_mo, nrow=nao, ncol=nmo)
1702 CALL cp_fm_create(cshalf_im, matrix_struct_mo, nrow=nao, ncol=nmo)
1704 CALL cp_cfm_to_fm(kp%cshalf, mtargetr=shalf_re, mtargeti=shalf_im)
1707 CALL parallel_gemm(
"N",
"N", nao, nmo, nao, 1.0_dp, shalf_re, &
1708 mo_set_re%mo_coeff, 0.0_dp, cshalf_re)
1709 CALL parallel_gemm(
"N",
"N", nao, nmo, nao, -1.0_dp, shalf_im, &
1710 mo_set_im%mo_coeff, 1.0_dp, cshalf_re)
1713 CALL parallel_gemm(
"N",
"N", nao, nmo, nao, 1.0_dp, shalf_re, &
1714 mo_set_im%mo_coeff, 0.0_dp, cshalf_im)
1715 CALL parallel_gemm(
"N",
"N", nao, nmo, nao, 1.0_dp, shalf_im, &
1716 mo_set_re%mo_coeff, 1.0_dp, cshalf_im)
1744 LOGICAL,
INTENT(IN) :: wtype
1748 TYPE(
cp_fm_type),
DIMENSION(:),
INTENT(IN) :: fmwork
1749 LOGICAL,
OPTIONAL :: for_aux_fit
1750 TYPE(
cp_fm_type),
DIMENSION(:, :, :),
INTENT(IN), &
1751 OPTIONAL :: pmat_ext
1753 CHARACTER(LEN=*),
PARAMETER :: routinen =
'kpoint_density_transform'
1755 INTEGER :: handle, ic, ik, ikk, indx, ir, ira, is, &
1756 ispin, jr, nc, nimg, nkp, nspin
1757 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
1758 LOGICAL :: aux_fit, do_ext, do_symmetric, my_kpgrp, &
1759 real_only, reverse_phase
1760 REAL(kind=
dp) :: wkpx
1761 REAL(kind=
dp),
DIMENSION(:),
POINTER :: wkp
1762 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: xkp
1765 TYPE(
dbcsr_type),
POINTER :: cpmat, rpmat, scpmat, srpmat
1771 CALL timeset(routinen, handle)
1775 IF (
PRESENT(for_aux_fit))
THEN
1776 aux_fit = for_aux_fit
1782 IF (
PRESENT(pmat_ext)) do_ext = .true.
1785 cpassert(
ASSOCIATED(kpoint%kp_aux_env))
1791 matrix_type=merge(dbcsr_type_symmetric, dbcsr_type_no_symmetry, do_symmetric))
1796 matrix_type=merge(dbcsr_type_antisymmetric, dbcsr_type_no_symmetry, do_symmetric))
1799 IF (.NOT. kpoint%full_grid)
THEN
1811 cell_to_index=cell_to_index)
1814 kp => kpoint%kp_aux_env(1)%kpoint_env
1816 kp => kpoint%kp_env(1)%kpoint_env
1818 nspin =
SIZE(kp%mos, 2)
1819 nc =
SIZE(kp%mos, 1)
1820 nimg =
SIZE(denmat, 2)
1821 real_only = (nc == 1)
1823 reverse_phase = kpoint%gamma_centered .AND. any(mod(kpoint%nkp_grid(1:3), 2) == 0)
1825 para_env => kpoint%blacs_env_all%para_env
1826 ALLOCATE (info(nspin*nkp*nc))
1832 CALL dbcsr_set(denmat(ispin, ic)%matrix, 0.0_dp)
1836 my_kpgrp = (ik >= kpoint%kp_range(1) .AND. ik <= kpoint%kp_range(2))
1838 ikk = ik - kpoint%kp_range(1) + 1
1840 kp => kpoint%kp_aux_env(ikk)%kpoint_env
1842 kp => kpoint%kp_env(ikk)%kpoint_env
1848 cpassert(
SIZE(fmwork) >= nc)
1890 kpsym => kpoint%kp_sym(ik)%kpoint_sym
1891 cpassert(
ASSOCIATED(
kpsym))
1893 IF (
kpsym%apply_symmetry)
THEN
1894 wkpx = wkp(ik)/real(
kpsym%nwght, kind=
dp)
1895 DO is = 1,
kpsym%nwght
1896 ir = abs(
kpsym%rotp(is))
1898 DO jr = 1,
SIZE(kpoint%ibrot)
1899 IF (ir == kpoint%ibrot(jr)) ira = jr
1902 kind_rot => kpoint%kind_rotmat(ira, :)
1903 CALL symtrans_phase(srpmat, scpmat, rpmat, cpmat, real_only, kind_rot, &
1905 kpsym%fcell(:, :, is), kpoint%atype,
kpsym%xkp(1:3, is), &
1906 kpsym%rotp(is) < 0, reverse_phase)
1907 CALL transform_dmat(denmat, srpmat, scpmat, ispin, real_only, sab_nl, &
1908 cell_to_index,
kpsym%xkp(1:3, is), wkpx)
1912 CALL transform_dmat(denmat, rpmat, cpmat, ispin, real_only, sab_nl, &
1913 cell_to_index, xkp(1:3, ik), wkp(ik))
1922 my_kpgrp = (ik >= kpoint%kp_range(1) .AND. ik <= kpoint%kp_range(2))
1924 ikk = ik - kpoint%kp_range(1) + 1
1926 kp => kpoint%kp_aux_env(ikk)%kpoint_env
1928 kp => kpoint%kp_env(ikk)%kpoint_env
1948 IF (.NOT. kpoint%full_grid)
THEN
1953 CALL timestop(handle)
1969 SUBROUTINE transform_dmat(denmat, rpmat, cpmat, ispin, real_only, sab_nl, cell_to_index, xkp, wkp)
1973 INTEGER,
INTENT(IN) :: ispin
1974 LOGICAL,
INTENT(IN) :: real_only
1977 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
1978 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: xkp
1979 REAL(kind=
dp),
INTENT(IN) :: wkp
1981 CHARACTER(LEN=*),
PARAMETER :: routinen =
'transform_dmat'
1983 INTEGER :: handle, iatom, icell, icol, irow, jatom, &
1985 INTEGER,
DIMENSION(3) :: cell
1986 LOGICAL :: do_symmetric, found
1987 REAL(kind=
dp) :: arg, coskl, fc, sinkl
1988 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: cblock, dblock, rblock
1990 DIMENSION(:),
POINTER :: nl_iterator
1992 CALL timeset(routinen, handle)
1994 nimg =
SIZE(denmat, 2)
2010 IF (do_symmetric .AND. iatom > jatom)
THEN
2016 icell = cell_to_index(cell(1), cell(2), cell(3))
2017 IF (icell < 1 .OR. icell > nimg) cycle
2019 arg = real(cell(1),
dp)*xkp(1) + real(cell(2),
dp)*xkp(2) + real(cell(3),
dp)*xkp(3)
2020 coskl = wkp*cos(
twopi*arg)
2021 sinkl = wkp*fc*sin(
twopi*arg)
2023 CALL dbcsr_get_block_p(matrix=denmat(ispin, icell)%matrix, row=irow, col=icol, &
2024 block=dblock, found=found)
2025 IF (.NOT. found) cycle
2028 CALL dbcsr_get_block_p(matrix=rpmat, row=irow, col=icol, block=rblock, found=found)
2029 IF (.NOT. found) cycle
2030 dblock = dblock + coskl*rblock
2032 CALL dbcsr_get_block_p(matrix=rpmat, row=irow, col=icol, block=rblock, found=found)
2033 IF (.NOT. found) cycle
2034 CALL dbcsr_get_block_p(matrix=cpmat, row=irow, col=icol, block=cblock, found=found)
2035 IF (.NOT. found) cycle
2036 dblock = dblock + coskl*rblock
2037 dblock = dblock + sinkl*cblock
2042 CALL timestop(handle)
2044 END SUBROUTINE transform_dmat
2052 SUBROUTINE ensure_work_matrix(work, nrow, ncol)
2054 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :), &
2055 INTENT(INOUT) :: work
2056 INTEGER,
INTENT(IN) :: nrow, ncol
2058 IF (
ALLOCATED(work))
THEN
2059 IF (
SIZE(work, 1) == nrow .AND.
SIZE(work, 2) == ncol)
RETURN
2062 ALLOCATE (work(nrow, ncol))
2064 END SUBROUTINE ensure_work_matrix
2082 SUBROUTINE symtrans_phase(srpmat, scpmat, rpmat, cpmat, real_only, kmat, rot, f0, fcell, atype, &
2083 xkp, time_reversal, reverse_phase)
2085 TYPE(
dbcsr_type),
POINTER :: srpmat, scpmat, rpmat, cpmat
2086 LOGICAL,
INTENT(IN) :: real_only
2088 REAL(kind=
dp),
DIMENSION(3, 3),
INTENT(IN) :: rot
2089 INTEGER,
DIMENSION(:),
INTENT(IN) :: f0
2090 INTEGER,
DIMENSION(:, :),
INTENT(IN) :: fcell
2091 INTEGER,
DIMENSION(:),
INTENT(IN) :: atype
2092 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: xkp
2093 LOGICAL,
INTENT(IN) :: time_reversal, reverse_phase
2095 CHARACTER(LEN=*),
PARAMETER :: routinen =
'symtrans_phase'
2097 INTEGER :: handle, iatom, icol, ikind, ip, irow, &
2098 jcol, jkind, jp, jrow, mynode, natom, &
2100 INTEGER,
DIMENSION(3) :: shift
2101 LOGICAL :: dorot, found, has_phase, perm, trans
2102 REAL(kind=
dp) :: arg, coskl, dr, sinkl
2103 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: cwork, rwork, twork
2104 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: cblock, kroti, krotj, rblock, scblock, &
2109 CALL timeset(routinen, handle)
2114 IF (f0(iatom) == iatom) cycle
2120 IF (abs(sum(abs(rot)) - 3.0_dp) > 1.e-12_dp) dorot = .true.
2121 dr = abs(rot(1, 1) - 1.0_dp) + abs(rot(2, 2) - 1.0_dp) + abs(rot(3, 3) - 1.0_dp)
2122 IF (abs(dr) > 1.e-12_dp) dorot = .true.
2123 has_phase = any(fcell /= 0) .OR. time_reversal
2125 IF (.NOT. (dorot .OR. perm .OR. has_phase))
THEN
2127 IF (.NOT. real_only)
CALL dbcsr_copy(scpmat, cpmat)
2128 CALL timestop(handle)
2134 IF (numnodes /= 1 .AND. (perm .OR. has_phase))
THEN
2140 IF (.NOT. real_only)
CALL dbcsr_set(scpmat, 0.0_dp)
2145 IF (.NOT.
ALLOCATED(rwork))
THEN
2146 ALLOCATE (rwork(
SIZE(rblock, 1),
SIZE(rblock, 2)))
2147 ELSEIF (
SIZE(rwork, 1) /=
SIZE(rblock, 1) .OR.
SIZE(rwork, 2) /=
SIZE(rblock, 2))
THEN
2149 ALLOCATE (rwork(
SIZE(rblock, 1),
SIZE(rblock, 2)))
2151 IF (.NOT. real_only)
THEN
2152 IF (.NOT.
ALLOCATED(cwork))
THEN
2153 ALLOCATE (cwork(
SIZE(rblock, 1),
SIZE(rblock, 2)))
2154 ELSEIF (
SIZE(cwork, 1) /=
SIZE(rblock, 1) .OR.
SIZE(cwork, 2) /=
SIZE(rblock, 2))
THEN
2156 ALLOCATE (cwork(
SIZE(rblock, 1),
SIZE(rblock, 2)))
2162 kroti => kmat(ikind)%rmat
2163 krotj => kmat(jkind)%rmat
2165 IF (reverse_phase)
THEN
2166 shift = fcell(1:3, irow) - fcell(1:3, icol)
2168 shift = fcell(1:3, icol) - fcell(1:3, irow)
2170 arg = real(shift(1),
dp)*xkp(1) + real(shift(2),
dp)*xkp(2) + real(shift(3),
dp)*xkp(3)
2172 coskl = cos(
twopi*arg)
2173 sinkl = sin(
twopi*arg)
2175 IF (abs(sinkl) > 1.e-12_dp)
THEN
2176 CALL cp_abort(__location__,
"Real k-point wavefunctions cannot represent symmetry phases")
2178 rwork(:, :) = coskl*rblock
2180 CALL dbcsr_get_block_p(matrix=cpmat, row=irow, col=icol, block=cblock, found=found)
2181 rwork(:, :) = coskl*rblock
2182 IF (time_reversal)
THEN
2183 cwork(:, :) = -sinkl*rblock
2185 rwork(:, :) = rwork - sinkl*cblock
2186 cwork(:, :) = cwork - coskl*cblock
2189 cwork(:, :) = -sinkl*rblock
2191 rwork(:, :) = rwork + sinkl*cblock
2192 cwork(:, :) = cwork + coskl*cblock
2209 CALL dbcsr_get_block_p(matrix=srpmat, row=jrow, col=jcol, block=srblock, found=found)
2210 IF (.NOT. found)
THEN
2212 cpassert(owner /= mynode)
2216 CALL ensure_work_matrix(twork,
SIZE(krotj, 1),
SIZE(rwork, 1))
2217 CALL dgemm(
'N',
'T',
SIZE(krotj, 1),
SIZE(rwork, 1),
SIZE(krotj, 2), &
2218 1.0_dp, krotj,
SIZE(krotj, 1), rwork,
SIZE(rwork, 1), &
2219 0.0_dp, twork,
SIZE(twork, 1))
2220 CALL dgemm(
'N',
'T',
SIZE(twork, 1),
SIZE(kroti, 1),
SIZE(twork, 2), &
2221 1.0_dp, twork,
SIZE(twork, 1), kroti,
SIZE(kroti, 1), &
2222 1.0_dp, srblock,
SIZE(srblock, 1))
2224 CALL ensure_work_matrix(twork,
SIZE(kroti, 1),
SIZE(rwork, 2))
2225 CALL dgemm(
'N',
'N',
SIZE(kroti, 1),
SIZE(rwork, 2),
SIZE(kroti, 2), &
2226 1.0_dp, kroti,
SIZE(kroti, 1), rwork,
SIZE(rwork, 1), &
2227 0.0_dp, twork,
SIZE(twork, 1))
2228 CALL dgemm(
'N',
'T',
SIZE(twork, 1),
SIZE(krotj, 1),
SIZE(twork, 2), &
2229 1.0_dp, twork,
SIZE(twork, 1), krotj,
SIZE(krotj, 1), &
2230 1.0_dp, srblock,
SIZE(srblock, 1))
2233 IF (.NOT. real_only)
THEN
2234 CALL dbcsr_get_block_p(matrix=scpmat, row=jrow, col=jcol, block=scblock, found=found)
2237 CALL ensure_work_matrix(twork,
SIZE(krotj, 1),
SIZE(cwork, 1))
2238 CALL dgemm(
'N',
'T',
SIZE(krotj, 1),
SIZE(cwork, 1),
SIZE(krotj, 2), &
2239 1.0_dp, krotj,
SIZE(krotj, 1), cwork,
SIZE(cwork, 1), &
2240 0.0_dp, twork,
SIZE(twork, 1))
2241 CALL dgemm(
'N',
'T',
SIZE(twork, 1),
SIZE(kroti, 1),
SIZE(twork, 2), &
2242 -1.0_dp, twork,
SIZE(twork, 1), kroti,
SIZE(kroti, 1), &
2243 1.0_dp, scblock,
SIZE(scblock, 1))
2245 CALL ensure_work_matrix(twork,
SIZE(kroti, 1),
SIZE(cwork, 2))
2246 CALL dgemm(
'N',
'N',
SIZE(kroti, 1),
SIZE(cwork, 2),
SIZE(kroti, 2), &
2247 1.0_dp, kroti,
SIZE(kroti, 1), cwork,
SIZE(cwork, 1), &
2248 0.0_dp, twork,
SIZE(twork, 1))
2249 CALL dgemm(
'N',
'T',
SIZE(twork, 1),
SIZE(krotj, 1),
SIZE(twork, 2), &
2250 1.0_dp, twork,
SIZE(twork, 1), krotj,
SIZE(krotj, 1), &
2251 1.0_dp, scblock,
SIZE(scblock, 1))
2256 IF (numnodes /= 1 .AND. (perm .OR. has_phase))
THEN
2261 CALL timestop(handle)
2263 END SUBROUTINE symtrans_phase
2276 SUBROUTINE symtrans(smat, pmat, kmat, rot, f0, atype, symmetric, antisymmetric)
2279 REAL(kind=
dp),
DIMENSION(3, 3),
INTENT(IN) :: rot
2280 INTEGER,
DIMENSION(:),
INTENT(IN) :: f0, atype
2281 LOGICAL,
INTENT(IN),
OPTIONAL :: symmetric, antisymmetric
2283 CHARACTER(LEN=*),
PARAMETER :: routinen =
'symtrans'
2285 INTEGER :: handle, iatom, icol, ikind, ip, irow, &
2286 jcol, jkind, jp, jrow, natom, numnodes
2287 LOGICAL :: asym, dorot, found, perm, sym, trans
2288 REAL(kind=
dp) :: dr, fsign
2289 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: work
2290 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: kroti, krotj, pblock, sblock
2294 CALL timeset(routinen, handle)
2298 IF (
PRESENT(symmetric)) sym = symmetric
2300 IF (
PRESENT(antisymmetric)) asym = antisymmetric
2302 cpassert(.NOT. (sym .AND. asym))
2303 cpassert((sym .OR. asym))
2309 IF (f0(iatom) == iatom) cycle
2316 IF (abs(sum(abs(rot)) - 3.0_dp) > 1.e-12_dp) dorot = .true.
2317 dr = abs(rot(1, 1) - 1.0_dp) + abs(rot(2, 2) - 1.0_dp) + abs(rot(3, 3) - 1.0_dp)
2318 IF (abs(dr) > 1.e-12_dp) dorot = .true.
2321 IF (asym) fsign = -1.0_dp
2323 IF (dorot .OR. perm)
THEN
2324 CALL cp_abort(__location__,
"k-points need FULL_GRID currently. "// &
2325 "Reduced grids not yet working correctly")
2330 IF (numnodes == 1)
THEN
2346 CALL dbcsr_get_block_p(matrix=smat, row=jrow, col=jcol, block=sblock, found=found)
2350 kroti => kmat(ikind)%rmat
2351 krotj => kmat(jkind)%rmat
2354 CALL ensure_work_matrix(work,
SIZE(krotj, 2),
SIZE(pblock, 1))
2355 CALL dgemm(
'T',
'T',
SIZE(krotj, 2),
SIZE(pblock, 1),
SIZE(krotj, 1), &
2356 1.0_dp, krotj,
SIZE(krotj, 1), pblock,
SIZE(pblock, 1), &
2357 0.0_dp, work,
SIZE(work, 1))
2358 CALL dgemm(
'N',
'N',
SIZE(work, 1),
SIZE(kroti, 2),
SIZE(work, 2), &
2359 fsign, work,
SIZE(work, 1), kroti,
SIZE(kroti, 1), &
2360 0.0_dp, sblock,
SIZE(sblock, 1))
2362 CALL ensure_work_matrix(work,
SIZE(kroti, 2),
SIZE(pblock, 2))
2363 CALL dgemm(
'T',
'N',
SIZE(kroti, 2),
SIZE(pblock, 2),
SIZE(kroti, 1), &
2364 1.0_dp, kroti,
SIZE(kroti, 1), pblock,
SIZE(pblock, 1), &
2365 0.0_dp, work,
SIZE(work, 1))
2366 CALL dgemm(
'N',
'N',
SIZE(work, 1),
SIZE(krotj, 2),
SIZE(work, 2), &
2367 fsign, work,
SIZE(work, 1), krotj,
SIZE(krotj, 1), &
2368 0.0_dp, sblock,
SIZE(sblock, 1))
2375 CALL cp_abort(__location__,
"k-points need FULL_GRID currently. "// &
2376 "Reduced grids not yet working correctly")
2397 kroti => kmat(ikind)%rmat
2398 krotj => kmat(jkind)%rmat
2401 CALL ensure_work_matrix(work,
SIZE(krotj, 2),
SIZE(sblock, 1))
2402 CALL dgemm(
'T',
'T',
SIZE(krotj, 2),
SIZE(sblock, 1),
SIZE(krotj, 1), &
2403 1.0_dp, krotj,
SIZE(krotj, 1), sblock,
SIZE(sblock, 1), &
2404 0.0_dp, work,
SIZE(work, 1))
2405 CALL dgemm(
'N',
'N',
SIZE(work, 1),
SIZE(kroti, 2),
SIZE(work, 2), &
2406 fsign, work,
SIZE(work, 1), kroti,
SIZE(kroti, 1), &
2407 0.0_dp, sblock,
SIZE(sblock, 1))
2409 CALL ensure_work_matrix(work,
SIZE(kroti, 2),
SIZE(sblock, 2))
2410 CALL dgemm(
'T',
'N',
SIZE(kroti, 2),
SIZE(sblock, 2),
SIZE(kroti, 1), &
2411 1.0_dp, kroti,
SIZE(kroti, 1), sblock,
SIZE(sblock, 1), &
2412 0.0_dp, work,
SIZE(work, 1))
2413 CALL dgemm(
'N',
'N',
SIZE(work, 1),
SIZE(krotj, 2),
SIZE(work, 2), &
2414 fsign, work,
SIZE(work, 1), krotj,
SIZE(krotj, 1), &
2415 0.0_dp, sblock,
SIZE(sblock, 1))
2426 CALL timestop(handle)
2428 END SUBROUTINE symtrans
2434 SUBROUTINE matprint(mat)
2437 INTEGER :: i, icol, iounit, irow
2438 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: mblock
2446 IF (iounit > 0)
THEN
2447 WRITE (iounit,
'(A,2I4)')
'BLOCK ', irow, icol
2448 DO i = 1,
SIZE(mblock, 1)
2449 WRITE (iounit,
'(8F12.6)') mblock(i, :)
2456 END SUBROUTINE matprint
static void dgemm(const char transa, const char transb, const int m, const int n, const int k, const double alpha, const double *a, const int lda, const double *b, const int ldb, const double beta, double *c, const int ldc)
Convenient wrapper to hide Fortran nature of dgemm_, swapping a and b.
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.
subroutine, public real_to_scaled(s, r, cell)
Transform real to scaled cell coordinates. s=h_inv*r.
methods related to the blacs parallel environment
subroutine, public cp_blacs_env_create(blacs_env, para_env, blacs_grid_layout, blacs_repeatable, row_major, grid_2d)
allocates and initializes a type that represent a blacs context
Represents a complex full matrix distributed on many processors.
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_to_fm(msource, mtargetr, mtargeti)
Copy real and imaginary parts of a complex full matrix into separate real-value full matrices.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_deallocate_matrix(matrix)
...
logical function, public dbcsr_iterator_blocks_left(iterator)
...
subroutine, public dbcsr_iterator_stop(iterator)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_get_block_p(matrix, row, col, block, found, row_size, col_size)
...
subroutine, public dbcsr_replicate_all(matrix)
...
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
subroutine, public dbcsr_get_stored_coordinates(matrix, row, column, processor)
...
subroutine, public dbcsr_distribute(matrix)
...
subroutine, public dbcsr_iterator_next_block(iterator, row, column, block, block_number_argument_has_been_removed, row_size, col_size, row_offset, col_offset, transposed)
...
subroutine, public dbcsr_iterator_start(iterator, matrix, shared, dynamic, dynamic_byrows)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_distribution_get(dist, row_dist, col_dist, nrows, ncols, has_threads, group, mynode, numnodes, nprows, npcols, myprow, mypcol, pgrid, subgroups_defined, prow_group, pcol_group)
...
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_fm_to_dbcsr(fm, matrix, keep_sparsity)
Copy a BLACS matrix to a dbcsr matrix.
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_column_scale(matrixa, scaling)
scales column i of matrix a with scaling(i)
pool for for elements that are retained and released
subroutine, public fm_pool_create_fm(pool, element, name)
returns an element, allocating it if none is in the pool
subroutine, public fm_pool_give_back_fm(pool, element)
returns the element to the pool
represent the structure of a full matrix
represent a full matrix distributed on many processors
subroutine, public cp_fm_get_diag(matrix, diag)
returns the diagonal elements of a fm
subroutine, public cp_fm_start_copy_general(source, destination, para_env, info)
Initiates the copy operation: get distribution data, post MPI isend and irecvs.
subroutine, public cp_fm_cleanup_copy_general(info)
Completes the copy operation: wait for comms clean up MPI state.
subroutine, public cp_fm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
subroutine, public cp_fm_finish_copy_general(destination, info)
Completes the copy operation: wait for comms, unpack, clean up MPI state.
subroutine, public cp_fm_get_submatrix(fm, target_m, start_row, start_col, n_rows, n_cols, transpose)
gets a submatrix of a full matrix op(target_m)(1:n_rows,1:n_cols) =fm(start_row:start_row+n_rows,...
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...
K-points and crystal symmetry routines.
subroutine, public print_crys_symmetry(csym)
...
subroutine, public kpoint_gen(csym, nk, symm, shift, full_grid, gamma_centered, inversion_symmetry_only, use_spglib_reduction, use_spglib_backend)
...
subroutine, public release_csym_type(csym)
Release the CSYM type.
subroutine, public kpoint_gen_general(csym, xkp_in, wkp_in, symm, full_grid, inversion_symmetry_only, use_spglib_reduction, use_spglib_backend)
Reduce an explicitly supplied GENERAL k-point set.
subroutine, public print_kp_symmetry(csym)
...
subroutine, public crys_sym_gen(csym, scoor, types, hmat, delta, iounit, use_spglib)
...
subroutine, public probe_occupancy_kp(occ, fermi, kts, energies, rcoeff, icoeff, maxocc, probe, n, wk)
subroutine to calculate occupation number and 'Fermi' level using the
Defines the basic variable types.
integer, parameter, public dp
Routines needed for kpoint calculation.
subroutine, public lowdin_kp_mo_coeff(kp, ispin, use_real_wfn, shalfc, cshalfc)
Calculate S(k)^1/2 C(k) for real or complex k-point wavefunctions.
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_density_transform(kpoint, denmat, wtype, tempmat, sab_nl, fmwork, for_aux_fit, pmat_ext)
generate real space density matrices in DBCSR format
subroutine, public kpoint_density_matrices(kpoint, energy_weighted, for_aux_fit)
Calculate kpoint density matrices (rho(k), owned by kpoint groups)
subroutine, public lowdin_kp_trans(kpoint, pmat_diag)
Calculate Lowdin transformation of density matrix S^1/2 P S^1/2 Integrate diagonal elements over k-po...
subroutine, public kpoint_env_initialize(kpoint, para_env, blacs_env, with_aux_fit)
Initialize the kpoint environment.
subroutine, public kpoint_set_mo_occupation(kpoint, smear, probe)
Given the eigenvalues of all kpoints, calculates the occupation numbers.
Types and basic routines needed for a kpoint calculation.
subroutine, public kpoint_sym_create(kp_sym)
Create a single kpoint symmetry environment.
subroutine, public kpoint_env_create(kp_env)
Create a single 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, inversion_symmetry_only, symmetry_backend, symmetry_reduction_method, gamma_centered)
Retrieve information from a kpoint environment.
K-points and crystal symmetry routines based on.
An array-based list which grows on demand. When the internal array is full, a new array of twice the ...
Definition of mathematical constants and functions.
real(kind=dp), parameter, public twopi
Collection of simple mathematical functions and subroutines.
pure real(kind=dp) function, dimension(3, 3), public inv_3x3(a)
Returns the inverse of the 3 x 3 matrix a.
Utility routines for the memory handling.
Interface to the message passing library MPI.
basic linear algebra operations for full matrixes
Define the data structure for the particle information.
wrapper for the pools of matrixes
subroutine, public mpools_create(mpools)
creates a mpools
subroutine, public mpools_rebuild_fm_pools(mpools, mos, blacs_env, para_env, nmosub)
rebuilds the pools of the (ao x mo, ao x ao , mo x mo) full matrixes
subroutine, public mpools_get(mpools, ao_mo_fm_pools, ao_ao_fm_pools, mo_mo_fm_pools, ao_mosub_fm_pools, mosub_mosub_fm_pools, maxao_maxmo_fm_pool, maxao_maxao_fm_pool, maxmo_maxmo_fm_pool)
returns various attributes of the mpools (notably the pools contained in it)
Definition and initialisation of the mo data type.
subroutine, public set_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, uniform_occupation, kts, mu, flexible_electron_count)
Set the components of a MO set data structure.
subroutine, public init_mo_set(mo_set, fm_pool, fm_ref, fm_struct, name, counter)
initializes an allocated mo_set. eigenvalues, mo_coeff, occupation_numbers are valid only after this ...
subroutine, public allocate_mo_set(mo_set, nao, nmo, nelectron, n_el_f, maxocc, flexible_electron_count)
Allocates a mo set and partially initializes it (nao,nmo,nelectron, and flexible_electron_count are v...
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.
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)
...
parameters that control an scf iteration
Unified smearing module supporting four methods: smear_fermi_dirac — Fermi-Dirac distribution smear_g...
subroutine, public smearkp(f, mu, kts, e, nel, wk, sigma, maxocc, method)
Bisection search for mu given a target electron count (k-point case, single spin channel or spin-dege...
subroutine, public smearkp2(f, mu, kts, e, nel, wk, sigma, method)
Bisection search for mu (k-point, spin-polarised with a shared chemical potential across both spin ch...
All kind of helpful little routines.
pure integer function, dimension(2), public get_limit(m, n, me)
divide m entries into n parts, return size of part me
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.
to create arrays of pools
keeps the information about the structure of a full matrix
Stores the state of a copy between cp_fm_start_copy_general and cp_fm_finish_copy_general.
Rotation matrices for basis sets.
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
container for the pools of matrixes used by qs
contains the parameters needed by a scf run