84 integrate_v_gaussian_rspace,&
106#include "./base/base_uses.f90"
111 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'ed_analysis'
128 INTEGER,
INTENT(IN) :: unit_nr
130 CHARACTER(len=*),
PARAMETER :: routinen =
'edmf_analysis'
132 INTEGER :: handle, iatom, ikind, iorb, ispin, jorb, &
133 nao, natom, nimages, nkind, no, norb, &
135 INTEGER,
DIMENSION(2) :: nocc
136 INTEGER,
DIMENSION(:),
POINTER :: refbas_blk_sizes
137 LOGICAL :: detailed_ener, do_hfx, ewald_correction, explicit, gapw, gapw_xc, &
138 ref_orb_canonical, skip_localize, uniform_occupation, uocc
139 REAL(kind=
dp) :: ateps, checksum, e1, e2, e_pot, ealpha, &
140 ecc, egcp, ehfx, ekts, evdw, focc, &
142 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: amval, atcore, ate1h, ate1xc, atecc, &
143 ateks, atener, atewald, odiag
144 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: atdet, atmul, mcharge, mweight
145 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: bcenter
146 REAL(kind=
dp),
DIMENSION(:),
POINTER :: occupation_numbers
150 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: c_iao_coef, ciao, fij_mat, orb_weight, &
155 TYPE(
dbcsr_p_type),
ALLOCATABLE,
DIMENSION(:) :: exc_mat, ks_mat, vhxc_mat
156 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: core_mat, matrix_h, matrix_hfx, &
157 matrix_ks, matrix_p, matrix_s, matrix_t
158 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: math, matp
165 TYPE(
mo_set_type),
DIMENSION(:),
POINTER :: mos, mos_loc
172 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
178 IF (.NOT. explicit)
RETURN
180 CALL timeset(routinen, handle)
182 IF (unit_nr > 0)
THEN
183 WRITE (unit=unit_nr, fmt=
"(/,4(T2,A))") &
184 "!-----------------------------------------------------------------------------!", &
185 "! ENERGY DECOMPOSITION ANALYSIS !", &
186 "! Janus J Eriksen, JCP 153 214109 (2020) !", &
187 "!-----------------------------------------------------------------------------!"
196 ewald_correction = (ealpha /= 0.0_dp)
198 CALL get_qs_env(qs_env, dft_control=dft_control)
199 nimages = dft_control%nimages
200 IF (nimages > 1)
THEN
201 IF (unit_nr > 0)
THEN
202 WRITE (unit=unit_nr, fmt=
"(T2,A)") &
203 "K-Points: MAO's determined and analyzed using Gamma-Point only."
206 gapw = dft_control%qs_control%gapw
207 gapw_xc = dft_control%qs_control%gapw_xc
208 IF (ewald_correction)
THEN
209 IF (gapw .OR. gapw_xc)
THEN
210 CALL cp_warn(__location__,
"Ewald Correction for GAPW and GAPW_XC not available.")
211 cpabort(
"Ewald Correction")
219 nspin = dft_control%nspins
220 ALLOCATE (mos_loc(nspin))
225 CALL get_mo_set(mos(ispin), uniform_occupation=uniform_occupation)
226 IF (.NOT. uniform_occupation) uocc = .false.
228 IF (unit_nr > 0)
THEN
230 WRITE (unit=unit_nr, fmt=
"(T2,A)") &
231 "MO's have a uniform occupation pattern"
233 WRITE (unit=unit_nr, fmt=
"(T2,A)") &
234 "MO's have varying occupations"
240 iao_env%do_iao = .true.
241 iao_env%do_charges = .true.
242 IF (skip_localize)
THEN
243 iao_env%do_bondorbitals = .false.
244 iao_env%do_center = .false.
246 iao_env%do_bondorbitals = .true.
247 iao_env%do_center = .true.
249 iao_env%eps_occ = 1.0e-4_dp
251 iao_env%pos_periodic = .NOT. all(cell%perd == 0)
259 IF (ref_orb_canonical)
THEN
260 CALL get_mo_set(mos_loc(ispin), mo_coeff=moref)
266 ALLOCATE (bcenter(5, no, nspin))
269 c_iao_coef=c_iao_coef, mos=mos_loc, bond_centers=bcenter)
272 IF (iao_env%do_bondorbitals .AND. iao_env%do_center)
THEN
278 smat => matrix_s(1)%matrix
279 ALLOCATE (rotmat(nspin))
281 CALL get_mo_set(mos_loc(ispin), mo_coeff=cloc)
287 template_fmstruct=cloc%matrix_struct)
292 CALL parallel_gemm(
'T',
'N', norb, norb, nao, 1.0_dp, moref, &
293 smo, 0.0_dp, rotmat(ispin))
299 ALLOCATE (fij_mat(nspin))
301 CALL cp_fm_create(fij_mat(ispin), rotmat(ispin)%matrix_struct)
305 CALL get_mo_set(mos(ispin), nmo=norb, occupation_numbers=occupation_numbers)
310 CALL parallel_gemm(
'N',
'N', norb, norb, norb, 1.0_dp, fij_mat(ispin), &
311 rotmat(ispin), 0.0_dp, smo)
312 CALL parallel_gemm(
'T',
'N', norb, norb, norb, 1.0_dp, rotmat(ispin), &
313 smo, 0.0_dp, fij_mat(ispin))
319 ALLOCATE (ciao(nspin))
321 CALL get_mo_set(mos_loc(ispin), mo_coeff=cloc)
327 template_fmstruct=cloc%matrix_struct)
332 CALL parallel_gemm(
'T',
'N', nref, norb, nao, 1.0_dp, c_iao_coef(ispin), &
333 smo, 0.0_dp, ciao(ispin))
338 CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set)
339 nkind =
SIZE(qs_kind_set)
340 ALLOCATE (ref_basis_set_list(nkind))
342 qs_kind => qs_kind_set(ikind)
343 NULLIFY (ref_basis_set_list(ikind)%gto_basis_set)
345 CALL get_qs_kind(qs_kind=qs_kind, basis_set=refbasis, basis_type=
"MIN")
346 IF (
ASSOCIATED(refbasis)) ref_basis_set_list(ikind)%gto_basis_set => refbasis
348 CALL get_qs_env(qs_env=qs_env, particle_set=particle_set, natom=natom)
349 ALLOCATE (refbas_blk_sizes(natom))
351 basis=ref_basis_set_list)
354 ALLOCATE (orb_weight(nspin))
355 ALLOCATE (mcharge(natom, 1))
357 CALL get_mo_set(mos_loc(ispin), mo_coeff=cloc)
360 template_fmstruct=cloc%matrix_struct)
368 dist=dbcsr_dist, matrix_type=dbcsr_type_symmetric, &
369 row_blk_size=refbas_blk_sizes, col_blk_size=refbas_blk_sizes)
374 template_fmstruct=ciao(1)%matrix_struct)
381 mo_coeff=cloc, nmo=norb, &
382 occupation_numbers=occupation_numbers)
386 CALL cp_fm_to_fm(ciao(ispin), cvec, ncol=1, source_start=iorb, target_start=1)
387 focc = occupation_numbers(iorb)
392 start_col=iorb, n_rows=natom, n_cols=1)
393 checksum = sum(mcharge(:, 1))
394 IF (abs(focc - checksum) > 1.e-6_dp)
THEN
395 CALL cp_warn(__location__,
"Sum of atomic orbital weights is incorrect")
396 IF (unit_nr > 0)
THEN
397 WRITE (unit=unit_nr, fmt=
"(T2,A,F10.6,T40,A,F10.6)") &
398 "Orbital occupation:", focc, &
399 "Sum of atomic orbital weights:", checksum
405 ALLOCATE (odiag(norb))
408 IF (odiag(iorb) < 1.e-8_dp) cycle
410 CALL cp_fm_to_fm(ciao(ispin), cvec, ncol=1, source_start=iorb, target_start=1)
413 IF (focc < 1.e-12_dp) cycle
414 CALL cp_fm_to_fm(ciao(ispin), cvec2, ncol=1, source_start=jorb, target_start=1)
418 checksum = sum(mcharge(:, 1))
420 IF (abs(focc - checksum) > 1.e-6_dp)
THEN
421 CALL cp_warn(__location__,
"Sum of atomic orbital weights is incorrect")
422 IF (unit_nr > 0)
THEN
423 WRITE (unit=unit_nr, fmt=
"(T2,A,F10.6,T40,A,F10.6)") &
424 "Orbital occupation:", focc, &
425 "Sum of atomic orbital weights:", checksum
428 mcharge(:, 1) = mcharge(:, 1)/focc
430 start_col=iorb, n_rows=natom, n_cols=1)
443 ALLOCATE (atener(natom), ateks(natom), atecc(natom), atcore(natom))
444 ALLOCATE (ate1xc(natom), ate1h(natom), atewald(natom))
452 IF (detailed_ener)
THEN
453 ALLOCATE (atdet(natom, 10), atmul(natom, 10), amval(natom))
462 CALL get_qs_env(qs_env, matrix_h=matrix_h, matrix_ks=matrix_ks, kinetic=matrix_t)
463 ALLOCATE (ks_mat(nspin), core_mat(1), vhxc_mat(nspin), exc_mat(1))
465 ALLOCATE (ks_mat(ispin)%matrix)
466 CALL dbcsr_create(ks_mat(ispin)%matrix, template=matrix_h(1)%matrix)
467 CALL dbcsr_copy(ks_mat(ispin)%matrix, matrix_h(1)%matrix)
468 CALL dbcsr_add(ks_mat(ispin)%matrix, matrix_ks(ispin)%matrix, 1.0_dp, 1.0_dp)
471 ALLOCATE (vhxc_mat(ispin)%matrix)
472 CALL dbcsr_create(vhxc_mat(ispin)%matrix, template=smat)
474 CALL dbcsr_set(vhxc_mat(ispin)%matrix, 0.0_dp)
477 ALLOCATE (core_mat(1)%matrix)
478 CALL dbcsr_create(core_mat(1)%matrix, template=matrix_h(1)%matrix)
479 CALL dbcsr_copy(core_mat(1)%matrix, matrix_h(1)%matrix)
480 CALL dbcsr_set(core_mat(1)%matrix, 0.0_dp)
482 ALLOCATE (exc_mat(1)%matrix)
485 CALL dbcsr_set(exc_mat(1)%matrix, 0.0_dp)
487 CALL vhxc_correction(qs_env, vhxc_mat, exc_mat, atecc, ate1xc, ate1h)
491 math(1:1, 1:1) => core_mat(1:1)
492 matp(1:nspin, 1:1) => matrix_p(1:nspin)
493 CALL core_matrices(qs_env, math, matp, .false., 0, atcore=atcore)
494 CALL group%sum(atcore)
496 IF (ewald_correction)
THEN
497 ALLOCATE (dve_mat%matrix)
498 CALL dbcsr_create(dve_mat%matrix, template=matrix_h(1)%matrix)
499 CALL dbcsr_copy(dve_mat%matrix, matrix_h(1)%matrix)
501 CALL vh_ewald_correction(qs_env, ealpha, dve_mat, atewald)
502 CALL group%sum(atewald)
506 CALL dbcsr_add(ks_mat(ispin)%matrix, vhxc_mat(ispin)%matrix, 1.0_dp, 1.0_dp)
507 CALL dbcsr_add(ks_mat(ispin)%matrix, core_mat(1)%matrix, 1.0_dp, -0.5_dp)
510 IF (detailed_ener .AND. do_hfx)
THEN
511 ALLOCATE (matrix_hfx(nspin))
513 ALLOCATE (matrix_hfx(nspin)%matrix)
514 CALL dbcsr_create(matrix_hfx(ispin)%matrix, template=smat)
515 CALL dbcsr_copy(matrix_hfx(ispin)%matrix, smat)
516 CALL dbcsr_set(matrix_hfx(ispin)%matrix, 0.0_dp)
518 CALL get_hfx_ks_matrix(qs_env, matrix_hfx)
522 CALL get_mo_set(mos_loc(ispin), mo_coeff=cloc, nmo=norb)
523 ALLOCATE (mweight(1, norb))
526 start_col=1, n_rows=1, n_cols=norb)
532 CALL dbcsr_dot(dkmat, ks_mat(ispin)%matrix, ecc)
533 ateks(iatom) = ateks(iatom) + ecc
535 IF (detailed_ener)
THEN
536 CALL dbcsr_dot(dkmat, matrix_t(1)%matrix, e1)
537 atdet(iatom, 1) = atdet(iatom, 1) + e1
538 CALL dbcsr_dot(dkmat, matrix_h(1)%matrix, e2)
539 atdet(iatom, 2) = atdet(iatom, 2) + (e2 - e1)
542 CALL dbcsr_dot(dkmat, matrix_hfx(ispin)%matrix, ehfx)
543 atdet(iatom, 5) = atdet(iatom, 5) + ehfx
548 CALL dbcsr_dot(dkmat, exc_mat(1)%matrix, e1)
549 atdet(iatom, 3) = atdet(iatom, 3) + ecc - e2 - e1 - ehfx
550 atdet(iatom, 4) = atdet(iatom, 4) + e1
552 IF (ewald_correction)
THEN
553 CALL dbcsr_dot(dkmat, dve_mat%matrix, ecc)
554 atewald(iatom) = atewald(iatom) + ecc
561 IF (detailed_ener)
THEN
563 CALL get_qs_env(qs_env, rho=rho, para_env=para_env)
569 atmul(1:natom, 1) = atmul(1:natom, 1) + amval(1:natom)
572 atmul(1:natom, 2) = atmul(1:natom, 2) + amval(1:natom)
573 atmul(1:natom, 3) = atmul(1:natom, 3) - amval(1:natom)
576 atmul(1:natom, 3) = atmul(1:natom, 3) + amval(1:natom)
580 atmul(1:natom, 5) = atmul(1:natom, 5) + 0.5_dp*amval(1:natom)
581 atmul(1:natom, 3) = atmul(1:natom, 3) - 0.5_dp*amval(1:natom)
585 atmul(1:natom, 4) = atmul(1:natom, 4) + amval(1:natom)
586 atmul(1:natom, 3) = atmul(1:natom, 3) - amval(1:natom)
588 atmul(1:natom, 2) = atmul(1:natom, 2) - atmul(1:natom, 1)
589 atmul(1:natom, 3) = atmul(1:natom, 3) + 0.5_dp*atmul(1:natom, 2)
590 atmul(1:natom, 2) = 0.5_dp*atmul(1:natom, 2) + 0.5_dp*atcore(1:natom)
597 DEALLOCATE (ks_mat(ispin)%matrix, vhxc_mat(ispin)%matrix)
601 DEALLOCATE (core_mat(1)%matrix)
603 DEALLOCATE (exc_mat(1)%matrix)
604 DEALLOCATE (ks_mat, core_mat, vhxc_mat, exc_mat)
606 DEALLOCATE (refbas_blk_sizes)
607 DEALLOCATE (ref_basis_set_list)
608 IF (detailed_ener .AND. do_hfx)
THEN
611 DEALLOCATE (matrix_hfx(ispin)%matrix)
613 DEALLOCATE (matrix_hfx)
615 IF (ewald_correction)
THEN
617 DEALLOCATE (dve_mat%matrix)
628 atener(1:natom) = ateks(1:natom)
630 atener(1:natom) = atener(1:natom) + 0.5_dp*atcore(1:natom)
632 CALL group%sum(atecc)
633 atener(1:natom) = atener(1:natom) + atecc(1:natom)
634 IF (detailed_ener) atdet(1:natom, 6) = atdet(1:natom, 6) + atecc(1:natom)
636 CALL group%sum(ate1xc)
637 CALL group%sum(ate1h)
638 atener(1:natom) = atener(1:natom) + ate1xc(1:natom) + ate1h(1:natom)
639 IF (detailed_ener)
THEN
640 IF (gapw .OR. gapw_xc) atdet(1:natom, 8) = atdet(1:natom, 8) + ate1xc(1:natom)
641 IF (gapw) atdet(1:natom, 9) = atdet(1:natom, 9) + ate1h(1:natom)
644 atecc(1:natom) = 0.0_dp
646 CALL group%sum(atecc)
647 atener(1:natom) = atener(1:natom) + atecc(1:natom)
648 IF (detailed_ener) atdet(1:natom, 7) = atdet(1:natom, 7) + atecc(1:natom)
649 IF (ewald_correction)
THEN
650 atewald(1:natom) = atewald(1:natom) - atecc(1:natom)
653 atecc(1:natom) = 0.0_dp
655 CALL group%sum(atecc)
656 atener(1:natom) = atener(1:natom) + atecc(1:natom)
657 IF (detailed_ener) atdet(1:natom, 7) = atdet(1:natom, 7) + atecc(1:natom)
658 IF (ewald_correction)
THEN
659 atewald(1:natom) = atewald(1:natom) - atecc(1:natom)
663 atecc(1:natom) = 0.0_dp
664 CALL get_qs_env(qs_env=qs_env, dispersion_env=dispersion_env)
667 CALL get_qs_env(qs_env=qs_env, gcp_env=gcp_env)
668 IF (
ASSOCIATED(gcp_env))
THEN
671 CALL group%sum(atecc)
672 atener(1:natom) = atener(1:natom) + atecc(1:natom)
673 IF (detailed_ener) atdet(1:natom, 10) = atdet(1:natom, 10) + atecc(1:natom)
676 ekts = energy%kts/real(natom, kind=
dp)
677 atener(1:natom) = atener(1:natom) + ekts
679 IF (detailed_ener)
THEN
680 atdet(1:natom, 3) = atdet(1:natom, 3) + 0.5_dp*atdet(1:natom, 2)
681 atdet(1:natom, 2) = 0.5_dp*atdet(1:natom, 2) + 0.5_dp*atcore(1:natom)
684 IF (detailed_ener)
THEN
685 IF (unit_nr > 0)
THEN
686 WRITE (unit_nr, fmt=
"(/,T2,A)")
"Detailed IAO Atomic Energy Components "
687 CALL write_atdet(unit_nr, atdet(:, 1),
"Kinetic Energy")
688 CALL write_atdet(unit_nr, atdet(:, 2),
"Short-Range Core and/or PP Energy")
689 CALL write_atdet(unit_nr, atdet(:, 3),
"Hartree Energy (long-ranged part)")
690 CALL write_atdet(unit_nr, atdet(:, 5),
"Exact Exchange Energy")
691 CALL write_atdet(unit_nr, atdet(:, 4),
"Exchange-Correlation Energy")
692 CALL write_atdet(unit_nr, atdet(:, 6),
"Atomic Core Hartree: Int(nc V(n+nc) dx")
693 CALL write_atdet(unit_nr, atdet(:, 7),
"Core Self Energy Corrections")
695 CALL write_atdet(unit_nr, atdet(:, 9),
"GAPW: 1-center Hartree Energy")
697 IF (gapw .OR. gapw_xc)
THEN
698 CALL write_atdet(unit_nr, atdet(:, 8),
"GAPW: 1-center XC Energy")
700 IF (abs(evdw) > 1.e-14_dp)
THEN
701 CALL write_atdet(unit_nr, atdet(:, 10),
"vdW Pairpotential Energy")
704 atecc(iatom) = sum(atdet(iatom, 1:10)) - atener(iatom)
706 CALL write_atdet(unit_nr, atecc(:),
"Missing Energy")
708 WRITE (unit_nr, fmt=
"(/,T2,A)")
"Detailed Mulliken Atomic Energy Components "
709 CALL write_atdet(unit_nr, atmul(:, 1),
"Kinetic Energy")
710 CALL write_atdet(unit_nr, atmul(:, 2),
"Short-Range Core and/or PP Energy")
711 CALL write_atdet(unit_nr, atmul(:, 3),
"Hartree Energy (long-ranged part)")
712 CALL write_atdet(unit_nr, atmul(:, 5),
"Exact Exchange Energy")
713 CALL write_atdet(unit_nr, atmul(:, 4),
"Exchange-Correlation Energy")
714 CALL write_atdet(unit_nr, atdet(:, 6),
"Atomic Core Hartree: Int(nc V(n+nc) dx")
715 CALL write_atdet(unit_nr, atdet(:, 7),
"Core Self Energy Corrections")
717 CALL write_atdet(unit_nr, atdet(:, 9),
"GAPW: 1-center Hartree Energy")
719 IF (gapw .OR. gapw_xc)
THEN
720 CALL write_atdet(unit_nr, atdet(:, 8),
"GAPW: 1-center XC Energy")
722 IF (abs(evdw) > 1.e-14_dp)
THEN
723 CALL write_atdet(unit_nr, atdet(:, 10),
"vdW Pairpotential Energy")
728 IF (unit_nr > 0)
THEN
731 CALL write_atener(unit_nr, particle_set, atener,
"Atomic Energy Decomposition")
732 sum_energy = sum(atener(:))
733 checksum = abs(e_pot - sum_energy)
734 WRITE (unit=unit_nr, fmt=
"((T2,A,T56,F25.13))") &
735 "Potential energy (Atomic):", sum_energy, &
736 "Potential energy (Total) :", e_pot, &
737 "Difference :", checksum
738 cpassert((checksum < ateps*abs(e_pot)))
740 IF (ewald_correction)
THEN
741 WRITE (unit=unit_nr, fmt=
"(/,(T2,A,F10.3,A))")
"Universal Ewald Parameter: ", ealpha,
" [Angstrom]"
742 CALL write_atener(unit_nr, particle_set, atewald,
"Change in Atomic Energy Decomposition")
743 sum_energy = sum(atewald(:))
744 WRITE (unit=unit_nr, fmt=
"((T2,A,T56,F25.13))") &
745 "Total Change in Potential energy:", sum_energy
749 IF (detailed_ener)
THEN
750 DEALLOCATE (atdet, atmul, amval)
753 IF (unit_nr > 0)
THEN
754 WRITE (unit=unit_nr, fmt=
"(/,T2,A)") &
755 "!--------------------------- END OF ED ANALYSIS ------------------------------!"
758 DEALLOCATE (atener, ateks, atecc, atcore, ate1xc, ate1h, atewald)
760 CALL timestop(handle)
773 SUBROUTINE vhxc_correction(qs_env, vhxc_mat, exc_mat, atecc, ate1xc, ate1h)
776 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: atecc, ate1xc, ate1h
778 CHARACTER(len=*),
PARAMETER :: routinen =
'vhxc_correction'
780 INTEGER :: handle, iatom, ispin, natom, nspins
781 LOGICAL :: do_admm_corr, gapw, gapw_xc
782 REAL(kind=
dp) :: eh1, exc1
785 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p
796 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
803 CALL timeset(routinen, handle)
805 CALL get_qs_env(qs_env, ks_env=ks_env, dft_control=dft_control, pw_env=pw_env)
807 nspins = dft_control%nspins
808 gapw = dft_control%qs_control%gapw
809 gapw_xc = dft_control%qs_control%gapw_xc
810 do_admm_corr = .false.
811 IF (dft_control%do_admm)
THEN
814 IF (do_admm_corr)
THEN
816 xc_section => admm_env%xc_section_aux
823 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
824 CALL auxbas_pw_pool%create_pw(xc_den)
825 ALLOCATE (vxc(nspins))
827 CALL auxbas_pw_pool%create_pw(vxc(ispin))
829 IF (needs%tau .OR. needs%tau_spin)
THEN
830 ALLOCATE (vtau(nspins))
832 CALL auxbas_pw_pool%create_pw(vtau(ispin))
837 CALL get_qs_env(qs_env, v_hartree_rspace=v_hartree_rspace)
838 CALL integrate_v_core_rspace(v_hartree_rspace, qs_env, atecc=atecc)
839 IF (gapw .OR. gapw_xc)
THEN
840 CALL get_qs_env(qs_env=qs_env, local_rho_set=local_rho_set, &
841 rho_atom_set=rho_atom_set, ecoul_1c=ecoul_1c, &
842 natom=natom, para_env=para_env)
846 CALL vh_1c_gg_integrals(qs_env, eh1, ecoul_1c, local_rho_set, para_env, tddft=.false.)
847 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set)
849 local_rho_set=local_rho_set, atener=atecc)
854 CALL get_qs_env(qs_env, rho_xc=rho_struct, dispersion_env=dispersion_env)
856 CALL get_qs_env(qs_env, rho=rho_struct, dispersion_env=dispersion_env)
859 cpassert(.NOT. do_admm_corr)
861 IF (needs%tau .OR. needs%tau_spin)
THEN
862 CALL qs_xc_density(ks_env, rho_struct, xc_section, dispersion_env=dispersion_env, &
863 xc_den=xc_den, vxc=vxc, vtau=vtau)
865 CALL qs_xc_density(ks_env, rho_struct, xc_section, dispersion_env=dispersion_env, &
866 xc_den=xc_den, vxc=vxc)
870 CALL pw_axpy(xc_den, vxc(ispin))
871 CALL pw_scale(vxc(ispin), vxc(ispin)%pw_grid%dvol)
872 CALL integrate_v_rspace(qs_env=qs_env, v_rspace=vxc(ispin), &
873 hmat=vhxc_mat(ispin), calculate_forces=.false., &
874 gapw=(gapw .OR. gapw_xc))
875 IF (needs%tau .OR. needs%tau_spin)
THEN
876 CALL pw_scale(vtau(ispin), -0.5_dp*vtau(ispin)%pw_grid%dvol)
877 CALL integrate_v_rspace(qs_env=qs_env, v_rspace=vtau(ispin), &
878 hmat=vhxc_mat(ispin), calculate_forces=.false., &
879 compute_tau=.true., gapw=(gapw .OR. gapw_xc))
882 CALL pw_scale(xc_den, xc_den%pw_grid%dvol)
883 CALL integrate_v_rspace(qs_env=qs_env, v_rspace=xc_den, &
884 hmat=exc_mat(1), calculate_forces=.false., &
885 gapw=(gapw .OR. gapw_xc))
887 IF (gapw .OR. gapw_xc)
THEN
889 CALL qs_rho_get(rho_struct, rho_ao_kp=matrix_p)
890 CALL update_ks_atom(qs_env, vhxc_mat, matrix_p, forces=.false., kscale=-0.5_dp)
893 ate1xc(iatom) = ate1xc(iatom) + &
894 rho_atom_set(iatom)%exc_h - rho_atom_set(iatom)%exc_s
898 ate1h(iatom) = ate1h(iatom) + &
899 ecoul_1c(iatom)%ecoul_1_h - ecoul_1c(iatom)%ecoul_1_s + &
900 ecoul_1c(iatom)%ecoul_1_z - ecoul_1c(iatom)%ecoul_1_0
905 CALL auxbas_pw_pool%give_back_pw(xc_den)
907 CALL auxbas_pw_pool%give_back_pw(vxc(ispin))
909 IF (needs%tau .OR. needs%tau_spin)
THEN
911 CALL auxbas_pw_pool%give_back_pw(vtau(ispin))
915 CALL timestop(handle)
917 END SUBROUTINE vhxc_correction
926 SUBROUTINE vh_ewald_correction(qs_env, ealpha, vh_mat, atewd)
928 REAL(kind=
dp),
INTENT(IN) :: ealpha
930 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: atewd
932 CHARACTER(len=*),
PARAMETER :: routinen =
'vh_ewald_correction'
934 INTEGER :: handle, ikind, ispin, natom, nkind
935 REAL(kind=
dp) :: eps_core_charge, rhotot, zeff
936 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: alpha, atcore, atecc, ccore
942 POINTER :: sab_orb, sac_ae
951 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
954 CALL timeset(routinen, handle)
957 ALLOCATE (atecc(natom), atcore(natom))
958 CALL get_qs_env(qs_env=qs_env, nkind=nkind, qs_kind_set=qs_kind_set, &
959 dft_control=dft_control)
960 ALLOCATE (alpha(nkind), ccore(nkind))
963 alpha(ikind) = ealpha
964 ccore(ikind) = zeff*(ealpha/
pi)**1.5_dp
968 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
969 poisson_env=poisson_env)
971 CALL auxbas_pw_pool%create_pw(v_hewd_gspace)
972 CALL auxbas_pw_pool%create_pw(v_hewd_rspace)
973 CALL auxbas_pw_pool%create_pw(rho_tot_ewd_g)
974 CALL auxbas_pw_pool%create_pw(rho_tot_ewd_r)
980 DO ispin = 1, dft_control%nspins
981 CALL pw_axpy(rho_r(ispin), rho_tot_ewd_r)
985 CALL pw_poisson_solve(poisson_env, density=rho_tot_ewd_g, vhartree=v_hewd_gspace)
987 CALL pw_scale(v_hewd_rspace, v_hewd_rspace%pw_grid%dvol)
989 CALL integrate_v_gaussian_rspace(v_hewd_rspace, qs_env, alpha, ccore, atecc)
990 atewd(1:natom) = atewd(1:natom) + atecc(1:natom)
993 CALL get_qs_env(qs_env, v_hartree_rspace=v_hartree_rspace)
994 CALL integrate_v_core_rspace(v_hartree_rspace, qs_env, atecc=atecc)
995 atewd(1:natom) = atewd(1:natom) - atecc(1:natom)
997 CALL pw_axpy(v_hartree_rspace, v_hewd_rspace, -1.0_dp)
999 CALL integrate_v_rspace(qs_env=qs_env, v_rspace=v_hewd_rspace, hmat=vh_mat, &
1000 calculate_forces=.false.)
1006 eps_core_charge = dft_control%qs_control%eps_core_charge
1007 ALLOCATE (e_mat%matrix)
1008 CALL dbcsr_create(e_mat%matrix, template=vh_mat%matrix)
1011 CALL get_qs_env(qs_env=qs_env, atomic_kind_set=atomic_kind_set, &
1012 particle_set=particle_set, sab_orb=sab_orb, sac_ppl=sac_ae)
1015 CALL build_erfc(e_mat, matrix_p, qs_kind_set, atomic_kind_set, particle_set, &
1016 alpha, ccore, eps_core_charge, sab_orb, sac_ae, atcore)
1017 atewd(1:natom) = atewd(1:natom) + 0.5_dp*atcore(1:natom)
1018 CALL dbcsr_add(vh_mat%matrix, e_mat%matrix, 1.0_dp, 0.5_dp)
1020 CALL get_qs_kind(qs_kind_set(ikind), alpha_core_charge=alpha(ikind), &
1021 ccore_charge=ccore(ikind))
1025 CALL build_erfc(e_mat, matrix_p, qs_kind_set, atomic_kind_set, particle_set, &
1026 alpha, ccore, eps_core_charge, sab_orb, sac_ae, atcore)
1027 atewd(1:natom) = atewd(1:natom) - 0.5_dp*atcore(1:natom)
1028 CALL dbcsr_add(vh_mat%matrix, e_mat%matrix, 1.0_dp, -0.5_dp)
1031 DEALLOCATE (e_mat%matrix)
1032 CALL auxbas_pw_pool%give_back_pw(v_hewd_gspace)
1033 CALL auxbas_pw_pool%give_back_pw(v_hewd_rspace)
1034 CALL auxbas_pw_pool%give_back_pw(rho_tot_ewd_g)
1035 CALL auxbas_pw_pool%give_back_pw(rho_tot_ewd_r)
1036 DEALLOCATE (atecc, atcore)
1037 DEALLOCATE (alpha, ccore)
1039 CALL timestop(handle)
1041 END SUBROUTINE vh_ewald_correction
1048 SUBROUTINE get_hfx_ks_matrix(qs_env, matrix_hfx)
1050 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_hfx
1052 CHARACTER(len=*),
PARAMETER :: routinen =
'get_hfx_ks_matrix'
1058 CALL timeset(routinen, handle)
1062 CALL tddft_hfx_matrix(matrix_hfx, matrix_p, qs_env, update_energy=.false., &
1063 recalc_integrals=.false.)
1065 CALL timestop(handle)
1067 END SUBROUTINE get_hfx_ks_matrix
1078 SUBROUTINE write_atener(iounit, particle_set, atener, label)
1080 INTEGER,
INTENT(IN) :: iounit
1082 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: atener
1083 CHARACTER(LEN=*),
INTENT(IN) :: label
1087 IF (iounit > 0)
THEN
1088 WRITE (unit=iounit, fmt=
"(/,T2,A)") trim(label)
1089 WRITE (unit=iounit, fmt=
"(T4,A,T30,A,T42,A,T54,A,T69,A)") &
1090 "Atom Element",
"X",
"Y",
"Z",
"Energy[a.u.]"
1091 natom =
SIZE(atener)
1093 WRITE (unit=iounit, fmt=
"(I6,T12,A2,T24,3F12.6,F21.10)") i, &
1094 trim(adjustl(particle_set(i)%atomic_kind%element_symbol)), &
1095 particle_set(i)%r(1:3)*
angstrom, atener(i)
1097 WRITE (unit=iounit, fmt=
"(A)")
""
1100 END SUBROUTINE write_atener
1111 SUBROUTINE write_atdet(iounit, atener, label)
1112 INTEGER,
INTENT(IN) :: iounit
1113 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: atener
1114 CHARACTER(LEN=*),
INTENT(IN) :: label
1118 IF (iounit > 0)
THEN
1119 natom =
SIZE(atener)
1120 WRITE (unit=iounit, fmt=
"(T2,A)") trim(label)
1121 WRITE (unit=iounit, fmt=
"(5G16.8)") atener(1:natom)
1124 END SUBROUTINE write_atdet
Types and set/get functions for auxiliary density matrix methods.
Define the atomic kind types and their sub types.
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public eriksen2020
Handles all functions related to the CELL.
Calculation of the nuclear attraction contribution to the core Hamiltonian <a|erfc|b> :we only calcul...
subroutine, public build_erfc(matrix_h, matrix_p, qs_kind_set, atomic_kind_set, particle_set, calpha, ccore, eps_core_charge, sab_orb, sac_ae, atcore)
Integrals = -Z*erfc(a*r)/r.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_scale(matrix, alpha_scalar)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
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_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
subroutine, public dbcsr_dot(matrix_a, matrix_b, trace)
Computes the dot product of two matrices, also known as the trace of their matrix product.
subroutine, public dbcsr_reserve_diag_blocks(matrix)
Reserves all diagonal blocks.
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
subroutine, public cp_dbcsr_plus_fm_fm_t(sparse_matrix, matrix_v, matrix_g, ncol, alpha, keep_sparsity, symmetry_mode)
performs the multiplication sparse_matrix+dense_mat*dens_mat^T if matrix_g is not explicitly given,...
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
subroutine, public cp_fm_get_diag(matrix, diag)
returns the diagonal elements of a fm
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_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_set_submatrix(fm, new_values, start_row, start_col, n_rows, n_cols, alpha, beta, transpose)
sets a submatrix of a full matrix fm(start_row:start_row+n_rows,start_col:start_col+n_cols) = alpha*o...
subroutine, public cp_fm_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
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,...
subroutine, public cp_fm_set_element(matrix, irow_global, icol_global, alpha)
sets an element of a matrix
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp)
creates a new full matrix with the given structure
Calculate Energy Decomposition analysis.
subroutine, public edmf_analysis(qs_env, input_section, unit_nr)
...
subroutine, public vh_1c_gg_integrals(qs_env, energy_hartree_1c, ecoul_1c, local_rho_set, para_env, tddft, local_rho_set_2nd, core_2nd)
Calculates one center GAPW Hartree energies and matrix elements Hartree potentials are input Takes po...
Utilities for hfx and admm methods.
subroutine, public tddft_hfx_matrix(matrix_ks, rho_ao, qs_env, update_energy, recalc_integrals, external_hfx_sections, external_x_data, external_para_env)
Add the hfx contributions to the Hamiltonian.
Calculate intrinsic atomic orbitals and analyze wavefunctions.
subroutine, public iao_wfn_analysis(qs_env, iao_env, unit_nr, c_iao_coef, mos, bond_centers)
...
subroutine, public print_center_spread(moments, nocc, print_section, iounit)
prints charge center and spreads for all orbitals
subroutine, public iao_charges(p_matrix, charges)
compute the atomic charges (orthogonal basis)
Calculate ntrinsic atomic orbitals and analyze wavefunctions.
subroutine, public iao_set_default(iao_env)
...
Defines the basic variable types.
integer, parameter, public dp
Definition of mathematical constants and functions.
real(kind=dp), parameter, public pi
Interface to the message passing library MPI.
compute mulliken charges we (currently) define them as c_i = 1/2 [ (PS)_{ii} + (SP)_{ii} ]
basic linear algebra operations for full matrixes
Define methods related to particle_type.
subroutine, public get_particle_set(particle_set, qs_kind_set, first_sgf, last_sgf, nsgf, nmao, basis)
Get the components of a particle set.
Define the data structure for the particle information.
Definition of physical constants:
real(kind=dp), parameter, public angstrom
container for various plainwaves related things
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
functions related to the poisson solver on regular grids
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Calculate the plane wave density by collocating the primitive Gaussian functions (pgf).
Calculation of the energies concerning the core charge distribution.
subroutine, public calculate_ecore_overlap(qs_env, para_env, calculate_forces, molecular, e_overlap_core, atecc)
Calculate the overlap energy of the core charge distribution.
subroutine, public calculate_ecore_self(qs_env, e_self_core, atecc)
Calculate the self energy of the core charge distribution.
subroutine, public calculate_ecore_alpha(qs_env, alpha, atecc)
Calculate the overlap and self energy of the core charge distribution for a given alpha Use a minimum...
Calculation of the core Hamiltonian integral matrix <a|H|b> over Cartesian Gaussian-type functions.
subroutine, public core_matrices(qs_env, matrix_h, matrix_p, calculate_forces, nder, atcore)
...
Calculation of dispersion using pair potentials.
subroutine, public calculate_dispersion_pairpot(qs_env, dispersion_env, energy, calculate_forces, atevdw)
...
Definition of disperson types for DFT calculations.
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, 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, 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)
Get the QUICKSTEP environment.
Calculation of gCP pair potentials.
subroutine, public calculate_gcp_pairpot(qs_env, gcp_env, energy, calculate_forces, ategcp)
...
Definition of gCP types for DFT calculations.
Integrate single or product functions over a potential on a RS grid.
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, init_u_ramping_each_scf, reltmat, ghost, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
routines that build the Kohn-Sham matrix contributions coming from local atomic densities
subroutine, public update_ks_atom(qs_env, ksmat, pmat, forces, tddft, rho_atom_external, kind_set_external, oce_external, sab_external, kscale, kintegral, kforce, fscale)
The correction to the KS matrix due to the GAPW local terms to the hartree and XC contributions is he...
collects routines that perform operations directly related to MOs
Definition and initialisation of the mo data type.
subroutine, public duplicate_mo_set(mo_set_new, mo_set_old)
allocate a new mo_set, and copy the old data
subroutine, public deallocate_mo_set(mo_set)
Deallocate a wavefunction data structure.
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 integrate_vhg0_rspace(qs_env, v_rspace, para_env, calculate_forces, local_rho_set, local_rho_set_2nd, atener, kforce, my_pools, my_rs_descs)
...
subroutine, public zero_rho_atom_integrals(rho_atom_set)
...
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_get(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
returns info about the density described by this object. If some representation is not available an e...
routines that build the integrals of the Vxc potential calculated for the atomic density in the basis...
subroutine, public calculate_vxc_atom(qs_env, energy_only, exc1, gradient_atom_set, adiabatic_rescale_factor, kind_set_external, rho_atom_set_external, xc_section_external)
...
subroutine, public qs_xc_density(ks_env, rho_struct, xc_section, dispersion_env, xc_ener, xc_den, vxc, vtau)
calculates the XC density: E_xc(r) - V_xc(r)*rho(r) or E_xc(r)/rho(r)
type(xc_rho_cflags_type) function, public xc_functionals_get_needs(functionals, lsd, calc_potential)
...
stores some data used in wavefunction fitting
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
keeps the information about the structure of a full matrix
stores all the informations relevant to an mpi environment
contained for different pw related things
environment for the poisson solver
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Provides all information about a quickstep kind.
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...
keeps the density in various representations, keeping track of which ones are valid.
contains a flag for each component of xc_rho_set, so that you can use it to tell which components you...