132#include "./base/base_uses.f90"
138 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_scf_diagonalization'
162 matrix_s, scf_control, scf_section, &
167 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s
170 LOGICAL,
INTENT(INOUT) :: diis_step
172 INTEGER :: ispin, nao, nspin
173 LOGICAL :: do_level_shift, owns_ortho, use_jacobi
174 REAL(kind=
dp) :: diis_error, eps_diis
178 nspin =
SIZE(matrix_ks)
179 NULLIFY (ortho, ortho_dbcsr)
183 scf_env%scf_work1(ispin))
186 eps_diis = scf_control%eps_diis
188 IF (scf_env%iter_count > 1 .AND. .NOT. scf_env%skip_diis)
THEN
189 CALL qs_diis_b_step(scf_env%scf_diis_buffer, mos, scf_env%scf_work1, &
190 scf_env%scf_work2, scf_env%iter_delta, diis_error, diis_step, &
191 eps_diis, scf_control%nmixing, &
193 scf_section=scf_section)
198 do_level_shift = ((scf_control%level_shift /= 0.0_dp) .AND. &
199 ((scf_control%density_guess ==
core_guess) .OR. &
200 (scf_env%iter_count > 1)))
202 IF ((scf_env%iter_count > 1) .AND. &
203 (scf_env%iter_delta < scf_control%diagonalization%eps_jacobi))
THEN
210 scf_env%iter_param = diis_error
212 scf_env%iter_method =
"DIIS/Jacobi"
214 scf_env%iter_method =
"DIIS/Diag."
217 IF (scf_env%mixing_method == 0)
THEN
218 scf_env%iter_method =
"NoMix/Diag."
219 ELSE IF (scf_env%mixing_method == 1)
THEN
220 scf_env%iter_param = scf_env%p_mix_alpha
222 scf_env%iter_method =
"P_Mix/Jacobi"
224 scf_env%iter_method =
"P_Mix/Diag."
226 ELSEIF (scf_env%mixing_method > 1)
THEN
227 scf_env%iter_param = scf_env%mixing_store%alpha
229 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Jacobi"
231 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Diag."
237 ortho_dbcsr => scf_env%ortho_dbcsr
239 CALL eigensolver_dbcsr(matrix_ks=matrix_ks(ispin)%matrix, matrix_ks_fm=scf_env%scf_work1(ispin), &
241 ortho_dbcsr=ortho_dbcsr, &
242 ksbuf1=scf_env%buf1_dbcsr, ksbuf2=scf_env%buf2_dbcsr)
247 ortho => scf_env%ortho_m1
249 ortho => scf_env%ortho
253 IF (.NOT.
ASSOCIATED(ortho))
THEN
263 matrix_s=matrix_s(ispin)%matrix, &
265 work=scf_env%scf_work2)
267 IF (do_level_shift)
THEN
268 CALL eigensolver(matrix_ks_fm=scf_env%scf_work1(ispin), &
271 work=scf_env%scf_work2, &
272 cholesky_method=scf_env%cholesky_method, &
273 do_level_shift=do_level_shift, &
274 level_shift=scf_control%level_shift, &
275 matrix_u_fm=scf_env%ortho, &
276 use_jacobi=use_jacobi)
278 CALL eigensolver(matrix_ks_fm=scf_env%scf_work1(ispin), &
281 work=scf_env%scf_work2, &
282 cholesky_method=scf_env%cholesky_method, &
283 do_level_shift=do_level_shift, &
284 level_shift=scf_control%level_shift, &
285 use_jacobi=use_jacobi)
290 IF (owns_ortho)
DEALLOCATE (ortho)
292 ortho => scf_env%ortho
295 IF (.NOT.
ASSOCIATED(ortho))
THEN
300 IF (do_level_shift)
THEN
302 IF (
ASSOCIATED(scf_env%scf_work1_red) .AND.
ASSOCIATED(scf_env%scf_work2_red) &
303 .AND.
ASSOCIATED(scf_env%ortho_red) .AND.
ASSOCIATED(scf_env%ortho_m1_red))
THEN
307 work=scf_env%scf_work2, &
308 do_level_shift=do_level_shift, &
309 level_shift=scf_control%level_shift, &
310 matrix_u_fm=scf_env%ortho_m1, &
311 use_jacobi=use_jacobi, &
312 jacobi_threshold=scf_control%diagonalization%jacobi_threshold, &
313 matrix_ks_fm_red=scf_env%scf_work1_red(ispin), &
314 ortho_red=scf_env%ortho_red, &
315 work_red=scf_env%scf_work2_red, &
316 matrix_u_fm_red=scf_env%ortho_m1_red)
321 work=scf_env%scf_work2, &
322 do_level_shift=do_level_shift, &
323 level_shift=scf_control%level_shift, &
324 matrix_u_fm=scf_env%ortho_m1, &
325 use_jacobi=use_jacobi, &
326 jacobi_threshold=scf_control%diagonalization%jacobi_threshold)
331 IF (
ASSOCIATED(scf_env%scf_work1_red) .AND.
ASSOCIATED(scf_env%scf_work2_red) &
332 .AND.
ASSOCIATED(scf_env%ortho_red))
THEN
336 work=scf_env%scf_work2, &
337 do_level_shift=do_level_shift, &
338 level_shift=scf_control%level_shift, &
339 use_jacobi=use_jacobi, &
340 jacobi_threshold=scf_control%diagonalization%jacobi_threshold, &
341 matrix_ks_fm_red=scf_env%scf_work1_red(ispin), &
342 ortho_red=scf_env%ortho_red, &
343 work_red=scf_env%scf_work2_red)
348 work=scf_env%scf_work2, &
349 do_level_shift=do_level_shift, &
350 level_shift=scf_control%level_shift, &
351 use_jacobi=use_jacobi, &
352 jacobi_threshold=scf_control%diagonalization%jacobi_threshold)
357 IF (owns_ortho)
DEALLOCATE (ortho)
374 matrix_s, scf_control, scf_section, &
378 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
379 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s
382 LOGICAL,
INTENT(INOUT) :: diis_step
386 INTEGER :: ispin, nspin
387 REAL(kind=
dp) :: total_zeff_corr
389 nspin =
SIZE(matrix_ks)
392 matrix_s, scf_control, scf_section, diis_step)
394 total_zeff_corr = 0.0_dp
395 total_zeff_corr = scf_env%sum_zeff_corr
397 IF (abs(total_zeff_corr) > 0.0_dp)
THEN
399 smear=scf_control%smear, tot_zeff_corr=total_zeff_corr)
401 IF (
PRESENT(probe) .EQV. .true.)
THEN
402 scf_control%smear%do_smear = .false.
404 smear=scf_control%smear, &
408 smear=scf_control%smear)
414 scf_env%p_mix_new(ispin, 1)%matrix)
439 diis_step, diis_error, qs_env, probe)
441 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks, matrix_s
445 LOGICAL,
INTENT(IN) :: update_p
446 LOGICAL,
INTENT(INOUT) :: diis_step
447 REAL(
dp),
INTENT(INOUT),
OPTIONAL :: diis_error
452 CHARACTER(len=*),
PARAMETER :: routinen =
'do_general_diag_kp'
454 COMPLEX(KIND=dp),
ALLOCATABLE,
DIMENSION(:) :: coeffs
455 INTEGER :: handle, ib, igroup, ik, ikp, indx, &
456 ispin, jb, kplocal, nb, nkp, &
458 INTEGER,
DIMENSION(2) :: kp_range
459 INTEGER,
DIMENSION(:, :),
POINTER :: kp_dist
460 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
461 LOGICAL :: do_diis, my_kpgrp, use_real_wfn
462 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues
463 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: xkp
468 TYPE(
cp_fm_type) :: fmdummy, fmlocal, rksmat, rsmat
469 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: fmwork
470 TYPE(
cp_fm_type),
POINTER :: imos, mo_coeff, rmos
471 TYPE(
dbcsr_type),
POINTER :: cmatrix, rmatrix, tmpmat
479 CALL timeset(routinen, handle)
482 CALL get_kpoint_info(kpoints, nkp=nkp, xkp=xkp, use_real_wfn=use_real_wfn, kp_range=kp_range, &
483 nkp_groups=nkp_groups, kp_dist=kp_dist, sab_nl=sab_nl, &
484 cell_to_index=cell_to_index)
485 cpassert(
ASSOCIATED(sab_nl))
486 kplocal = kp_range(2) - kp_range(1) + 1
490 IF (scf_env%iter_count > 1 .AND. .NOT. scf_env%skip_diis .AND. .NOT. use_real_wfn &
491 .AND.
PRESENT(diis_error) .AND.
PRESENT(qs_env)) do_diis = .true.
494 ALLOCATE (rmatrix, cmatrix, tmpmat)
495 CALL dbcsr_create(rmatrix, template=matrix_ks(1, 1)%matrix, &
496 matrix_type=dbcsr_type_symmetric)
497 CALL dbcsr_create(cmatrix, template=matrix_ks(1, 1)%matrix, &
498 matrix_type=dbcsr_type_antisymmetric)
499 CALL dbcsr_create(tmpmat, template=matrix_ks(1, 1)%matrix, &
500 matrix_type=dbcsr_type_no_symmetry)
504 fmwork => scf_env%scf_work1
508 CALL mpools_get(mpools, ao_ao_fm_pools=ao_ao_fm_pools)
513 IF (use_real_wfn)
THEN
520 kp => kpoints%kp_env(1)%kpoint_env
521 CALL get_mo_set(kp%mos(1, 1), mo_coeff=mo_coeff)
526 para_env => kpoints%blacs_env_all%para_env
527 nspin =
SIZE(matrix_ks, 1)
528 ALLOCATE (info(kplocal*nspin*nkp_groups, 4))
534 DO igroup = 1, nkp_groups
536 ik = kp_dist(1, igroup) + ikp - 1
537 my_kpgrp = (ik >= kpoints%kp_range(1) .AND. ik <= kpoints%kp_range(2))
539 IF (use_real_wfn)
THEN
542 CALL rskp_transform(rmatrix=rmatrix, rsmat=matrix_ks, ispin=ispin, &
543 xkp=xkp(1:3, ik), cell_to_index=cell_to_index, sab_nl=sab_nl)
549 xkp=xkp(1:3, ik), cell_to_index=cell_to_index, sab_nl=sab_nl)
556 CALL rskp_transform(rmatrix=rmatrix, cmatrix=cmatrix, rsmat=matrix_ks, ispin=ispin, &
557 xkp=xkp(1:3, ik), cell_to_index=cell_to_index, sab_nl=sab_nl)
565 CALL rskp_transform(rmatrix=rmatrix, cmatrix=cmatrix, rsmat=matrix_s, ispin=1, &
566 xkp=xkp(1:3, ik), cell_to_index=cell_to_index, sab_nl=sab_nl)
576 IF (use_real_wfn)
THEN
603 CALL get_qs_env(qs_env, para_env=para_env_global)
609 DO igroup = 1, nkp_groups
611 ik = kp_dist(1, igroup) + ikp - 1
612 my_kpgrp = (ik >= kpoints%kp_range(1) .AND. ik <= kpoints%kp_range(2))
626 kp => kpoints%kp_env(ikp)%kpoint_env
628 ispin, ikp, kplocal, scf_section)
633 ALLOCATE (coeffs(nb))
634 CALL qs_diis_b_step_kp(kpoints%scf_diis_buffer, coeffs, ib, nb, scf_env%iter_delta, diis_error, &
635 diis_step, scf_control%eps_diis, nspin, nkp, kplocal, scf_control%nmixing, &
636 scf_section, para_env_global)
641 kp => kpoints%kp_env(ikp)%kpoint_env
649 CALL get_mo_set(kp%mos(1, ispin), mo_coeff=rmos, eigenvalues=eigenvalues)
650 CALL get_mo_set(kp%mos(2, ispin), mo_coeff=imos)
653 scf_control%eps_eigval)
655 CALL cp_cfm_geeig(cksmat, csmat, cmos, eigenvalues, cwork)
658 kp%mos(2, ispin)%eigenvalues = eigenvalues
669 DO igroup = 1, nkp_groups
671 ik = kp_dist(1, igroup) + ikp - 1
672 my_kpgrp = (ik >= kpoints%kp_range(1) .AND. ik <= kpoints%kp_range(2))
675 IF (use_real_wfn)
THEN
693 kp => kpoints%kp_env(ikp)%kpoint_env
694 IF (use_real_wfn)
THEN
695 CALL get_mo_set(kp%mos(1, ispin), mo_coeff=mo_coeff, eigenvalues=eigenvalues)
698 scf_control%eps_eigval)
700 CALL cp_fm_geeig(rksmat, rsmat, mo_coeff, eigenvalues, fmlocal)
703 CALL get_mo_set(kp%mos(1, ispin), mo_coeff=rmos, eigenvalues=eigenvalues)
704 CALL get_mo_set(kp%mos(2, ispin), mo_coeff=imos)
707 scf_control%eps_eigval)
709 CALL cp_cfm_geeig(cksmat, csmat, cmos, eigenvalues, cwork)
712 kp%mos(2, ispin)%eigenvalues = eigenvalues
724 DO igroup = 1, nkp_groups
726 ik = kp_dist(1, igroup) + ikp - 1
727 my_kpgrp = (ik >= kpoints%kp_range(1) .AND. ik <= kpoints%kp_range(2))
729 IF (use_real_wfn)
THEN
747 IF (
PRESENT(probe) .EQV. .true.)
THEN
748 scf_control%smear%do_smear = .false.
758 matrix_s(1, 1)%matrix, sab_nl, fmwork)
765 IF (use_real_wfn)
THEN
776 CALL timestop(handle)
795 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks, matrix_s
797 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: fmwork
799 CHARACTER(len=*),
PARAMETER :: routinen =
'diag_kp_basic'
801 INTEGER :: handle, igroup, ik, ikp, indx, ispin, &
802 kplocal, nkp, nkp_groups, nspin
803 INTEGER,
DIMENSION(2) :: kp_range
804 INTEGER,
DIMENSION(:, :),
POINTER :: kp_dist
805 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
806 LOGICAL :: my_kpgrp, use_real_wfn
807 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues
808 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: xkp
813 TYPE(
cp_fm_type) :: fmdummy, fmlocal, rksmat, rsmat
814 TYPE(
cp_fm_type),
POINTER :: imos, mo_coeff, rmos
815 TYPE(
dbcsr_type),
POINTER :: cmatrix, rmatrix, tempmat, tmpmat
822 CALL timeset(routinen, handle)
825 CALL get_kpoint_info(kpoints, nkp=nkp, xkp=xkp, use_real_wfn=use_real_wfn, kp_range=kp_range, &
826 nkp_groups=nkp_groups, kp_dist=kp_dist, sab_nl=sab_nl, &
827 cell_to_index=cell_to_index)
828 cpassert(
ASSOCIATED(sab_nl))
829 kplocal = kp_range(2) - kp_range(1) + 1
832 tempmat => matrix_ks(1, 1)%matrix
835 ALLOCATE (rmatrix, cmatrix, tmpmat)
836 CALL dbcsr_create(rmatrix, template=tempmat, matrix_type=dbcsr_type_symmetric)
837 CALL dbcsr_create(cmatrix, template=tempmat, matrix_type=dbcsr_type_antisymmetric)
838 CALL dbcsr_create(tmpmat, template=tempmat, matrix_type=dbcsr_type_no_symmetry)
844 CALL mpools_get(mpools, ao_ao_fm_pools=ao_ao_fm_pools)
849 IF (use_real_wfn)
THEN
856 kp => kpoints%kp_env(1)%kpoint_env
857 CALL get_mo_set(kp%mos(1, 1), mo_coeff=mo_coeff)
862 para_env => kpoints%blacs_env_all%para_env
863 nspin =
SIZE(matrix_ks, 1)
864 ALLOCATE (info(kplocal*nspin*nkp_groups, 4))
870 DO igroup = 1, nkp_groups
872 ik = kp_dist(1, igroup) + ikp - 1
873 my_kpgrp = (ik >= kpoints%kp_range(1) .AND. ik <= kpoints%kp_range(2))
875 IF (use_real_wfn)
THEN
878 CALL rskp_transform(rmatrix=rmatrix, rsmat=matrix_ks, ispin=ispin, &
879 xkp=xkp(1:3, ik), cell_to_index=cell_to_index, sab_nl=sab_nl)
885 xkp=xkp(1:3, ik), cell_to_index=cell_to_index, sab_nl=sab_nl)
892 CALL rskp_transform(rmatrix=rmatrix, cmatrix=cmatrix, rsmat=matrix_ks, ispin=ispin, &
893 xkp=xkp(1:3, ik), cell_to_index=cell_to_index, sab_nl=sab_nl)
901 CALL rskp_transform(rmatrix=rmatrix, cmatrix=cmatrix, rsmat=matrix_s, ispin=1, &
902 xkp=xkp(1:3, ik), cell_to_index=cell_to_index, sab_nl=sab_nl)
912 IF (use_real_wfn)
THEN
941 DO igroup = 1, nkp_groups
943 ik = kp_dist(1, igroup) + ikp - 1
944 my_kpgrp = (ik >= kpoints%kp_range(1) .AND. ik <= kpoints%kp_range(2))
947 IF (use_real_wfn)
THEN
965 kp => kpoints%kp_env(ikp)%kpoint_env
966 IF (use_real_wfn)
THEN
967 CALL get_mo_set(kp%mos(1, ispin), mo_coeff=mo_coeff, eigenvalues=eigenvalues)
968 CALL cp_fm_geeig(rksmat, rsmat, mo_coeff, eigenvalues, fmlocal)
970 CALL get_mo_set(kp%mos(1, ispin), mo_coeff=rmos, eigenvalues=eigenvalues)
971 CALL get_mo_set(kp%mos(2, ispin), mo_coeff=imos)
972 CALL cp_cfm_geeig(cksmat, csmat, cmos, eigenvalues, cwork)
974 kp%mos(2, ispin)%eigenvalues = eigenvalues
985 DO igroup = 1, nkp_groups
987 ik = kp_dist(1, igroup) + ikp - 1
988 my_kpgrp = (ik >= kpoints%kp_range(1) .AND. ik <= kpoints%kp_range(2))
990 IF (use_real_wfn)
THEN
1010 IF (use_real_wfn)
THEN
1021 CALL timestop(handle)
1041 ks_env, scf_section, scf_control)
1046 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
1052 CHARACTER(LEN=*),
PARAMETER :: routinen =
'do_scf_diag_subspace'
1053 REAL(kind=
dp),
PARAMETER :: rone = 1.0_dp, rzero = 0.0_dp
1055 INTEGER :: handle, i, iloop, ispin, nao, nmo, &
1057 LOGICAL :: converged
1058 REAL(
dp) :: ene_diff, ene_old, iter_delta, max_val, &
1059 sum_band, sum_val, t1, t2
1060 REAL(kind=
dp),
DIMENSION(:),
POINTER :: mo_eigenvalues, mo_occupations
1061 TYPE(
cp_1d_r_p_type),
ALLOCATABLE,
DIMENSION(:) :: eval_first, occ_first
1063 TYPE(
cp_fm_type),
POINTER :: c0, chc, evec, mo_coeff
1065 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s, rho_ao
1066 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: rho_ao_kp
1072 CALL timeset(routinen, handle)
1073 NULLIFY (c0, chc, energy, evec, matrix_ks, mo_coeff, mo_eigenvalues, &
1074 mo_occupations, dft_control, rho_ao, rho_ao_kp)
1078 extension=
".scfLog")
1082 CALL qs_rho_get(rho, rho_ao=rho_ao, rho_ao_kp=rho_ao_kp)
1084 ALLOCATE (eval_first(nspin))
1085 ALLOCATE (occ_first(nspin))
1089 eigenvalues=mo_eigenvalues, &
1090 occupation_numbers=mo_occupations)
1091 ALLOCATE (eval_first(ispin)%array(nmo))
1092 ALLOCATE (occ_first(ispin)%array(nmo))
1093 eval_first(ispin)%array(1:nmo) = mo_eigenvalues(1:nmo)
1094 occ_first(ispin)%array(1:nmo) = mo_occupations(1:nmo)
1099 CALL dbcsr_copy(subspace_env%p_matrix_store(ispin)%matrix, rho_ao(ispin)%matrix)
1100 CALL dbcsr_copy(rho_ao(ispin)%matrix, scf_env%p_mix_new(ispin, 1)%matrix)
1103 subspace_env%p_matrix_mix => scf_env%p_mix_new
1105 NULLIFY (matrix_ks, energy, para_env, matrix_s)
1107 matrix_ks=matrix_ks, &
1109 matrix_s=matrix_s, &
1110 para_env=para_env, &
1111 dft_control=dft_control)
1115 CALL mixing_allocate(qs_env, subspace_env%mixing_method, scf_env%p_mix_new, &
1116 scf_env%p_delta, nspin, subspace_env%mixing_store)
1117 IF (dft_control%qs_control%gapw)
THEN
1118 CALL get_qs_env(qs_env=qs_env, rho_atom_set=rho_atom)
1119 CALL mixing_init(subspace_env%mixing_method, rho, subspace_env%mixing_store, &
1120 para_env, rho_atom=rho_atom)
1121 ELSEIF (dft_control%qs_control%dftb .OR. dft_control%qs_control%xtb)
THEN
1123 ELSEIF (dft_control%qs_control%semi_empirical)
THEN
1124 cpabort(
'SE Code not possible')
1126 CALL mixing_init(subspace_env%mixing_method, rho, subspace_env%mixing_store, para_env)
1132 IF (output_unit > 0)
THEN
1133 WRITE (output_unit,
"(/T19,A)")
'<<<<<<<<< SUBSPACE ROTATION <<<<<<<<<<'
1134 WRITE (output_unit,
"(T4,A,T13,A,T21,A,T38,A,T51,A,T65,A/,T4,A)") &
1135 "In-step",
"Time",
"Convergence",
"Band ene.",
"Total ene.",
"Energy diff.", repeat(
"-", 74)
1143 DO iloop = 1, subspace_env%max_iter
1146 ene_old = energy%total
1150 just_energy=.false., print_active=.false.)
1155 DO ispin = 1,
SIZE(matrix_ks)
1159 eigenvalues=mo_eigenvalues, &
1160 occupation_numbers=mo_occupations, &
1164 chc => subspace_env%chc_mat(ispin)
1165 evec => subspace_env%c_vec(ispin)
1166 c0 => subspace_env%c0(ispin)
1170 CALL parallel_gemm(
'T',
'N', nmo, nmo, nao, rone, c0, work, rzero, chc)
1176 CALL parallel_gemm(
'N',
'N', nao, nmo, nmo, rone, c0, evec, rzero, mo_coeff)
1179 smear=scf_control%smear)
1183 subspace_env%p_matrix_mix(ispin, 1)%matrix)
1186 sum_band = sum_band + mo_eigenvalues(i)*mo_occupations(i)
1194 scf_env%mixing_store, rho_ao_kp, para_env, iter_delta, iloop)
1197 subspace_env%p_matrix_mix, delta=iter_delta)
1202 CALL dbcsr_copy(rho_ao(ispin)%matrix, subspace_env%p_matrix_mix(ispin, 1)%matrix)
1208 CALL gspace_mixing(qs_env, scf_env%mixing_method, subspace_env%mixing_store, &
1209 rho, para_env, scf_env%iter_count)
1212 ene_diff = energy%total - ene_old
1213 converged = (abs(ene_diff) < subspace_env%eps_ene .AND. &
1214 iter_delta < subspace_env%eps_adapt*scf_env%iter_delta)
1216 IF (output_unit > 0)
THEN
1217 WRITE (output_unit,
"(T4,I5,T11,F8.3,T18,E14.4,T34,F12.5,T46,F16.8,T62,E14.4)") &
1218 iloop, t2 - t1, iter_delta, sum_band, energy%total, ene_diff
1222 IF (output_unit > 0)
WRITE (output_unit,
"(T10,A,I6,A,/)") &
1223 " Reached convergence in ", iloop,
" iterations "
1229 NULLIFY (subspace_env%p_matrix_mix)
1232 CALL dbcsr_copy(scf_env%p_mix_new(ispin, 1)%matrix, rho_ao(ispin)%matrix)
1233 CALL dbcsr_copy(rho_ao(ispin)%matrix, subspace_env%p_matrix_store(ispin)%matrix)
1235 DEALLOCATE (eval_first(ispin)%array, occ_first(ispin)%array)
1237 DEALLOCATE (eval_first, occ_first)
1239 CALL timestop(handle)
1253 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(IN) :: mos
1255 CHARACTER(LEN=*),
PARAMETER :: routinen =
'diag_subspace_allocate'
1257 INTEGER :: handle, i, ispin, nmo, nspin
1264 CALL timeset(routinen, handle)
1266 NULLIFY (sab_orb, matrix_s)
1267 CALL get_qs_env(qs_env=qs_env, sab_orb=sab_orb, &
1272 IF (.NOT.
ASSOCIATED(subspace_env%p_matrix_store))
THEN
1276 ALLOCATE (subspace_env%p_matrix_store(i)%matrix)
1277 CALL dbcsr_create(matrix=subspace_env%p_matrix_store(i)%matrix, template=matrix_s(1)%matrix, &
1278 name=
"DENSITY_STORE", matrix_type=dbcsr_type_symmetric)
1281 CALL dbcsr_set(subspace_env%p_matrix_store(i)%matrix, 0.0_dp)
1286 ALLOCATE (subspace_env%chc_mat(nspin))
1287 ALLOCATE (subspace_env%c_vec(nspin))
1288 ALLOCATE (subspace_env%c0(nspin))
1291 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, nmo=nmo)
1292 CALL cp_fm_create(subspace_env%c0(ispin), mo_coeff%matrix_struct)
1293 NULLIFY (fm_struct_tmp)
1295 para_env=mo_coeff%matrix_struct%para_env, &
1296 context=mo_coeff%matrix_struct%context)
1297 CALL cp_fm_create(subspace_env%chc_mat(ispin), fm_struct_tmp,
"chc")
1298 CALL cp_fm_create(subspace_env%c_vec(ispin), fm_struct_tmp,
"vec")
1302 CALL timestop(handle)
1319 scf_section, diis_step)
1322 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
1326 LOGICAL,
INTENT(INOUT) :: diis_step
1328 INTEGER :: ispin, nspin
1329 LOGICAL :: do_level_shift, use_jacobi
1330 REAL(kind=
dp) :: diis_error
1332 nspin =
SIZE(matrix_ks)
1337 IF (scf_env%iter_count > 1 .AND. .NOT. scf_env%skip_diis)
THEN
1338 CALL qs_diis_b_step(scf_env%scf_diis_buffer, mos, scf_env%scf_work1, &
1339 scf_env%scf_work2, scf_env%iter_delta, diis_error, diis_step, &
1340 scf_control%eps_diis, scf_control%nmixing, &
1341 scf_section=scf_section)
1346 IF ((scf_env%iter_count > 1) .AND. (scf_env%iter_delta < scf_control%diagonalization%eps_jacobi))
THEN
1349 use_jacobi = .false.
1352 do_level_shift = ((scf_control%level_shift /= 0.0_dp) .AND. &
1353 ((scf_control%density_guess ==
core_guess) .OR. (scf_env%iter_count > 1)))
1355 scf_env%iter_param = diis_error
1356 IF (use_jacobi)
THEN
1357 scf_env%iter_method =
"DIIS/Jacobi"
1359 scf_env%iter_method =
"DIIS/Diag."
1362 IF (scf_env%mixing_method == 1)
THEN
1363 scf_env%iter_param = scf_env%p_mix_alpha
1364 IF (use_jacobi)
THEN
1365 scf_env%iter_method =
"P_Mix/Jacobi"
1367 scf_env%iter_method =
"P_Mix/Diag."
1369 ELSEIF (scf_env%mixing_method > 1)
THEN
1370 scf_env%iter_param = scf_env%mixing_store%alpha
1371 IF (use_jacobi)
THEN
1372 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Jacobi"
1374 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Diag."
1378 scf_env%iter_delta = 0.0_dp
1382 mo_set=mos(ispin), &
1383 work=scf_env%scf_work2, &
1384 do_level_shift=do_level_shift, &
1385 level_shift=scf_control%level_shift, &
1386 use_jacobi=use_jacobi, &
1387 jacobi_threshold=scf_control%diagonalization%jacobi_threshold)
1391 smear=scf_control%smear)
1396 scf_env%p_mix_new(ispin, 1)%matrix)
1415 scf_control, scf_section, diis_step)
1418 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
1419 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s
1422 LOGICAL,
INTENT(INOUT) :: diis_step
1424 INTEGER :: homo, ispin, nmo, nspin
1425 REAL(kind=
dp) :: diis_error, eps_iter
1426 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues
1429 NULLIFY (eigenvalues)
1431 nspin =
SIZE(matrix_ks)
1435 scf_env%scf_work1(ispin))
1438 IF ((scf_env%iter_count > 1) .AND. (.NOT. scf_env%skip_diis))
THEN
1439 CALL qs_diis_b_step(scf_env%scf_diis_buffer, mos, scf_env%scf_work1, &
1440 scf_env%scf_work2, scf_env%iter_delta, diis_error, diis_step, &
1441 scf_control%eps_diis, scf_control%nmixing, &
1442 s_matrix=matrix_s, &
1443 scf_section=scf_section)
1448 eps_iter = scf_control%diagonalization%eps_iter
1450 scf_env%iter_param = diis_error
1451 scf_env%iter_method =
"DIIS/OTdiag"
1454 matrix_ks(ispin)%matrix, keep_sparsity=.true.)
1456 eps_iter = max(eps_iter, scf_control%diagonalization%eps_adapt*diis_error)
1458 IF (scf_env%mixing_method == 1)
THEN
1459 scf_env%iter_param = scf_env%p_mix_alpha
1460 scf_env%iter_method =
"P_Mix/OTdiag."
1461 ELSEIF (scf_env%mixing_method > 1)
THEN
1462 scf_env%iter_param = scf_env%mixing_store%alpha
1463 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/OTdiag."
1467 scf_env%iter_delta = 0.0_dp
1471 mo_coeff=mo_coeff, &
1472 eigenvalues=eigenvalues, &
1476 matrix_s=matrix_s(1)%matrix, &
1477 matrix_c_fm=mo_coeff, &
1479 eps_gradient=eps_iter, &
1480 iter_max=scf_control%diagonalization%max_iter, &
1482 ot_settings=scf_control%diagonalization%ot_settings)
1484 evals_arg=eigenvalues, &
1487 mos(ispin)%mo_coeff_b)
1492 smear=scf_control%smear)
1497 scf_env%p_mix_new(ispin, 1)%matrix)
1520 scf_control, scf_section, diis_step, &
1528 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(IN) :: mos
1529 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s
1532 LOGICAL,
INTENT(INOUT) :: diis_step
1533 LOGICAL,
INTENT(IN) :: orthogonal_basis
1535 CHARACTER(LEN=*),
PARAMETER :: routinen =
'do_roks_diag'
1537 INTEGER :: handle, homoa, homob, imo, nalpha, nao, &
1539 REAL(kind=
dp) :: diis_error, level_shift_loc
1540 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eiga, eigb, occa, occb
1541 TYPE(
cp_fm_type),
POINTER :: ksa, ksb, mo2ao, moa, mob, ortho, work
1545 CALL timeset(routinen, handle)
1548 ortho => scf_env%ortho_m1
1550 ortho => scf_env%ortho
1552 work => scf_env%scf_work2
1554 ksa => scf_env%scf_work1(1)
1555 ksb => scf_env%scf_work1(2)
1568 occupation_numbers=occa, &
1575 occupation_numbers=occb, &
1580 IF ((scf_control%level_shift /= 0.0_dp) .AND. &
1581 ((scf_control%density_guess ==
core_guess) .OR. &
1583 (scf_env%iter_count > 1)))
THEN
1584 level_shift_loc = scf_control%level_shift
1586 level_shift_loc = 0.0_dp
1589 IF ((scf_env%iter_count > 1) .OR. &
1590 (scf_control%density_guess ==
core_guess) .OR. &
1596 CALL cp_fm_symm(
"L",
"U", nao, nao, 1.0_dp, ksa, moa, 0.0_dp, work)
1597 CALL parallel_gemm(
"T",
"N", nao, nao, nao, 1.0_dp, moa, work, 0.0_dp, ksa)
1599 CALL cp_fm_symm(
"L",
"U", nao, nao, 1.0_dp, ksb, moa, 0.0_dp, work)
1600 CALL parallel_gemm(
"T",
"N", nao, nao, nao, 1.0_dp, moa, work, 0.0_dp, ksb)
1611 cpabort(
"Unknown ROKS scheme requested")
1617 IF (orthogonal_basis)
THEN
1630 CALL parallel_gemm(
"N",
"T", nao, nao, nao, 1.0_dp, ksa, mo2ao, 0.0_dp, work)
1631 CALL parallel_gemm(
"N",
"N", nao, nao, nao, 1.0_dp, mo2ao, work, 0.0_dp, ksa)
1645 IF (scf_env%iter_count > 1)
THEN
1646 IF (orthogonal_basis)
THEN
1649 kc=scf_env%scf_work1, &
1651 delta=scf_env%iter_delta, &
1652 error_max=diis_error, &
1653 diis_step=diis_step, &
1654 eps_diis=scf_control%eps_diis, &
1655 scf_section=scf_section, &
1657 cpassert(scf_env%iter_delta == scf_env%iter_delta)
1661 kc=scf_env%scf_work1, &
1663 delta=scf_env%iter_delta, &
1664 error_max=diis_error, &
1665 diis_step=diis_step, &
1666 eps_diis=scf_control%eps_diis, &
1667 scf_section=scf_section, &
1668 s_matrix=matrix_s, &
1674 scf_env%iter_param = diis_error
1675 scf_env%iter_method =
"DIIS/Diag."
1677 IF (scf_env%mixing_method == 1)
THEN
1678 scf_env%iter_param = scf_env%p_mix_alpha
1679 scf_env%iter_method =
"P_Mix/Diag."
1680 ELSEIF (scf_env%mixing_method > 1)
THEN
1681 scf_env%iter_param = scf_env%mixing_store%alpha
1682 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Diag."
1686 scf_env%iter_delta = 0.0_dp
1688 IF (level_shift_loc /= 0.0_dp)
THEN
1693 CALL cp_fm_symm(
"L",
"U", nao, nao, 1.0_dp, ksa, moa, 0.0_dp, work)
1694 CALL parallel_gemm(
"T",
"N", nao, nao, nao, 1.0_dp, moa, work, 0.0_dp, ksa)
1698 DO imo = homob + 1, homoa
1701 DO imo = homoa + 1, nmo
1705 ELSE IF (.NOT. orthogonal_basis)
THEN
1708 SELECT CASE (scf_env%cholesky_method)
1714 "SOLVE", pos=
"RIGHT")
1716 "SOLVE", pos=
"LEFT", transa=
"T")
1720 "MULTIPLY", pos=
"RIGHT")
1722 "MULTIPLY", pos=
"LEFT", transa=
"T")
1724 CALL cp_fm_symm(
"L",
"U", nao, nao, 1.0_dp, ksa, ortho, 0.0_dp, work)
1725 CALL parallel_gemm(
"N",
"N", nao, nao, nao, 1.0_dp, ortho, work, 0.0_dp, ksa)
1736 IF (level_shift_loc /= 0.0_dp)
THEN
1739 CALL parallel_gemm(
"N",
"N", nao, nmo, nao, 1.0_dp, ortho, work, 0.0_dp, moa)
1741 IF (orthogonal_basis)
THEN
1744 SELECT CASE (scf_env%cholesky_method)
1750 CALL parallel_gemm(
"N",
"N", nao, nmo, nao, 1.0_dp, ortho, work, 0.0_dp, moa)
1757 IF (level_shift_loc /= 0.0_dp)
THEN
1758 DO imo = homob + 1, homoa
1759 eiga(imo) = eiga(imo) - 0.5_dp*level_shift_loc
1761 DO imo = homoa + 1, nmo
1762 eiga(imo) = eiga(imo) - level_shift_loc
1777 CALL timestop(handle)
1795 scf_control, scf_section, check_moconv_only)
1798 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
1802 LOGICAL,
INTENT(IN),
OPTIONAL :: check_moconv_only
1804 CHARACTER(LEN=*),
PARAMETER :: routinen =
'do_block_krylov_diag'
1805 REAL(kind=
dp),
PARAMETER :: rone = 1.0_dp, rzero = 0.0_dp
1807 INTEGER :: handle, homo, ispin, iter, nao, nmo, &
1809 LOGICAL :: converged, my_check_moconv_only
1810 REAL(
dp) :: eps_iter, t1, t2
1811 REAL(kind=
dp),
DIMENSION(:),
POINTER :: mo_eigenvalues
1812 TYPE(
cp_fm_type),
POINTER :: c0, c1, chc, evec, ks, mo_coeff, ortho, &
1817 CALL timeset(routinen, handle)
1820 extension=
".scfLog")
1822 my_check_moconv_only = .false.
1823 IF (
PRESENT(check_moconv_only)) my_check_moconv_only = check_moconv_only
1825 NULLIFY (mo_coeff, ortho, work, ks)
1826 NULLIFY (mo_eigenvalues)
1830 ortho => scf_env%ortho_m1
1832 ortho => scf_env%ortho
1834 work => scf_env%scf_work2
1836 DO ispin = 1,
SIZE(matrix_ks)
1838 scf_env%scf_work1(ispin))
1841 IF (scf_env%mixing_method == 1)
THEN
1842 scf_env%iter_param = scf_env%p_mix_alpha
1843 scf_env%iter_method =
"P_Mix/Lanczos"
1846 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Lanc."
1849 DO ispin = 1,
SIZE(matrix_ks)
1851 ks => scf_env%scf_work1(ispin)
1858 eigenvalues=mo_eigenvalues, &
1862 c0 => scf_env%krylov_space%mo_conv(ispin)
1863 c1 => scf_env%krylov_space%mo_refine(ispin)
1864 SELECT CASE (scf_env%cholesky_method)
1871 "SOLVE", pos=
"RIGHT")
1873 "SOLVE", pos=
"LEFT", transa=
"T")
1877 "MULTIPLY", pos=
"RIGHT")
1879 "MULTIPLY", pos=
"LEFT", transa=
"T")
1883 scf_env%krylov_space%nmo_nc = nmo
1884 scf_env%krylov_space%nmo_conv = 0
1887 IF (output_unit > 0)
THEN
1888 WRITE (output_unit,
"(/T15,A)")
'<<<<<<<<< LANCZOS REFINEMENT <<<<<<<<<<'
1889 WRITE (output_unit,
"(T8,A,T15,A,T23,A,T36,A,T49,A,T60,A,/,T8,A)") &
1890 " Spin ",
" Cycle ", &
1891 " conv. MOS ",
" B2MAX ",
" B2MIN ",
" Time", repeat(
"-", 60)
1893 eps_iter = max(scf_env%krylov_space%eps_conv, scf_env%krylov_space%eps_adapt*scf_env%iter_delta)
1897 IF (my_check_moconv_only)
THEN
1900 nao, eps_iter, ispin, check_moconv_only=my_check_moconv_only)
1902 IF (output_unit > 0) &
1903 WRITE (output_unit,
'(T8,I3,T16,I5,T24,I6,T33,E12.4,2x,E12.4,T60,F8.3)') &
1904 ispin, iter, scf_env%krylov_space%nmo_conv, &
1905 scf_env%krylov_space%max_res_norm, scf_env%krylov_space%min_res_norm, t2 - t1
1910 DO iter = 1, scf_env%krylov_space%max_iter
1912 nao, eps_iter, ispin)
1914 IF (output_unit > 0)
THEN
1915 WRITE (output_unit,
'(T8,I3,T16,I5,T24,I6,T33,E12.4,2x,E12.4,T60,F8.3)') &
1916 ispin, iter, scf_env%krylov_space%nmo_conv, &
1917 scf_env%krylov_space%max_res_norm, scf_env%krylov_space%min_res_norm, t2 - t1
1920 IF (scf_env%krylov_space%max_res_norm < eps_iter)
THEN
1922 IF (output_unit > 0)
WRITE (output_unit, *) &
1923 " Reached convergence in ", iter,
" iterations "
1928 IF (.NOT. converged .AND. output_unit > 0)
THEN
1929 WRITE (output_unit,
"(T4, A)")
" WARNING Lanczos refinement could "// &
1930 "not converge all the mos:"
1931 WRITE (output_unit,
"(T40,A,T70,I10)")
" number of not converged mos ", &
1932 scf_env%krylov_space%nmo_nc
1933 WRITE (output_unit,
"(T40,A,T70,E10.2)")
" max norm of the residual ", &
1934 scf_env%krylov_space%max_res_norm
1942 chc => scf_env%krylov_space%chc_mat(ispin)
1943 evec => scf_env%krylov_space%c_vec(ispin)
1944 CALL parallel_gemm(
'N',
'N', nao, nmo, nao, rone, ks, c0, rzero, work)
1945 CALL parallel_gemm(
'T',
'N', nmo, nmo, nao, rone, c0, work, rzero, chc)
1949 CALL parallel_gemm(
'N',
'N', nao, nmo, nmo, rone, c0, evec, rzero, c1)
1950 c0 => scf_env%krylov_space%mo_refine(ispin)
1960 smear=scf_control%smear)
1964 scf_env%p_mix_new(ispin, 1)%matrix)
1968 IF (output_unit > 0)
THEN
1969 WRITE (output_unit,
"(T15,A/)")
'<<<<<<<<< END LANCZOS REFINEMENT <<<<<<<<<<'
1975 CALL timestop(handle)
1995 scf_control, scf_section, check_moconv_only)
1999 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
2000 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s
2003 LOGICAL,
INTENT(IN),
OPTIONAL :: check_moconv_only
2005 CHARACTER(LEN=*),
PARAMETER :: routinen =
'do_block_davidson_diag'
2007 INTEGER :: handle, ispin, nspins, output_unit
2008 LOGICAL :: do_prec, my_check_moconv_only
2012 CALL timeset(routinen, handle)
2015 extension=
".scfLog")
2017 IF (output_unit > 0) &
2018 WRITE (output_unit,
"(/T15,A)")
'<<<<<<<<< DAVIDSON ITERATIONS <<<<<<<<<<'
2020 IF (scf_env%mixing_method == 1)
THEN
2021 scf_env%iter_param = scf_env%p_mix_alpha
2022 scf_env%iter_method =
"P_Mix/Dav."
2024 scf_env%iter_param = scf_env%mixing_store%alpha
2025 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Dav."
2028 my_check_moconv_only = .false.
2029 IF (
PRESENT(check_moconv_only)) my_check_moconv_only = check_moconv_only
2031 IF (scf_env%block_davidson_env(1)%prec_type /= 0 .AND. &
2032 scf_env%iter_count >= scf_env%block_davidson_env(1)%first_prec)
THEN
2036 nspins =
SIZE(matrix_ks)
2038 IF (do_prec .AND. (scf_env%iter_count == scf_env%block_davidson_env(1)%first_prec .OR. &
2039 modulo(scf_env%iter_count, scf_env%block_davidson_env(1)%niter_new_prec) == 0))
THEN
2041 prec_type=scf_env%block_davidson_env(1)%prec_type, nspins=nspins)
2043 scf_env%block_davidson_env(1)%prec_type, &
2044 scf_env%block_davidson_env(1)%solver_type, &
2045 scf_env%block_davidson_env(1)%energy_gap, nspins, &
2046 convert_to_dbcsr=scf_env%block_davidson_env(1)%use_sparse_mos, &
2050 DO ispin = 1, nspins
2051 IF (scf_env%block_davidson_env(ispin)%use_sparse_mos)
THEN
2052 IF (.NOT. do_prec)
THEN
2054 matrix_ks(ispin)%matrix, matrix_s(1)%matrix, output_unit)
2057 matrix_ks(ispin)%matrix, matrix_s(1)%matrix, output_unit, &
2058 scf_env%ot_preconditioner(ispin)%preconditioner)
2062 IF (.NOT. do_prec)
THEN
2064 matrix_ks(ispin)%matrix, matrix_s(1)%matrix, output_unit)
2067 matrix_ks(ispin)%matrix, matrix_s(1)%matrix, output_unit, &
2068 scf_env%ot_preconditioner(ispin)%preconditioner)
2074 smear=scf_control%smear)
2076 DO ispin = 1, nspins
2079 scf_env%p_mix_new(ispin, 1)%matrix)
2082 IF (output_unit > 0)
THEN
2083 WRITE (output_unit,
"(T15,A/)")
'<<<<<<<<< END DAVIDSON ITERATION <<<<<<<<<<'
2089 CALL timestop(handle)
2104 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s
2108 CHARACTER(len=*),
PARAMETER :: routinen =
'diag_kp_smat'
2109 COMPLEX(KIND=dp),
PARAMETER :: cone = (1.0_dp, 0.0_dp), &
2110 czero = (0.0_dp, 0.0_dp)
2112 COMPLEX(KIND=dp),
ALLOCATABLE,
DIMENSION(:) :: ceig
2113 INTEGER :: handle, igroup, ik, ikp, indx, kplocal, &
2114 nao, nkp, nkp_groups
2115 INTEGER,
DIMENSION(2) :: kp_range
2116 INTEGER,
DIMENSION(:, :),
POINTER :: kp_dist
2117 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
2118 LOGICAL :: my_kpgrp, use_real_wfn
2119 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigenvalues
2120 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: xkp
2126 TYPE(
dbcsr_type),
POINTER :: cmatrix, rmatrix, tmpmat
2133 CALL timeset(routinen, handle)
2136 CALL get_kpoint_info(kpoints, nkp=nkp, xkp=xkp, use_real_wfn=use_real_wfn, kp_range=kp_range, &
2137 nkp_groups=nkp_groups, kp_dist=kp_dist, sab_nl=sab_nl, &
2138 cell_to_index=cell_to_index)
2139 cpassert(
ASSOCIATED(sab_nl))
2140 kplocal = kp_range(2) - kp_range(1) + 1
2143 ALLOCATE (rmatrix, cmatrix, tmpmat)
2144 CALL dbcsr_create(rmatrix, template=matrix_s(1, 1)%matrix, &
2145 matrix_type=dbcsr_type_symmetric)
2146 CALL dbcsr_create(cmatrix, template=matrix_s(1, 1)%matrix, &
2147 matrix_type=dbcsr_type_antisymmetric)
2148 CALL dbcsr_create(tmpmat, template=matrix_s(1, 1)%matrix, &
2149 matrix_type=dbcsr_type_no_symmetry)
2155 CALL mpools_get(mpools, ao_ao_fm_pools=ao_ao_fm_pools)
2160 IF (use_real_wfn)
THEN
2168 ALLOCATE (eigenvalues(nao), ceig(nao))
2170 para_env => kpoints%blacs_env_all%para_env
2171 ALLOCATE (info(kplocal*nkp_groups, 2))
2176 DO igroup = 1, nkp_groups
2178 ik = kp_dist(1, igroup) + ikp - 1
2179 my_kpgrp = (ik >= kpoints%kp_range(1) .AND. ik <= kpoints%kp_range(2))
2181 IF (use_real_wfn)
THEN
2184 xkp=xkp(1:3, ik), cell_to_index=cell_to_index, sab_nl=sab_nl)
2190 CALL rskp_transform(rmatrix=rmatrix, cmatrix=cmatrix, rsmat=matrix_s, ispin=1, &
2191 xkp=xkp(1:3, ik), cell_to_index=cell_to_index, sab_nl=sab_nl)
2200 IF (use_real_wfn)
THEN
2221 DO igroup = 1, nkp_groups
2223 ik = kp_dist(1, igroup) + ikp - 1
2224 my_kpgrp = (ik >= kpoints%kp_range(1) .AND. ik <= kpoints%kp_range(2))
2227 IF (use_real_wfn)
THEN
2240 kp => kpoints%kp_env(ikp)%kpoint_env
2241 IF (use_real_wfn)
THEN
2246 cpassert(all(eigenvalues(1:nao) >= 0.0_dp))
2247 IF (use_real_wfn)
THEN
2250 eigenvalues(1:nao) = sqrt(eigenvalues(1:nao))
2253 CALL parallel_gemm(
"N",
"T", nao, nao, nao, 1.0_dp, rsmat, fmlocal, &
2258 ceig(1:nao) = sqrt(eigenvalues(1:nao))
2261 CALL parallel_gemm(
"N",
"C", nao, nao, nao, cone, csmat, cwork, &
2269 DO igroup = 1, nkp_groups
2271 ik = kp_dist(1, igroup) + ikp - 1
2272 my_kpgrp = (ik >= kpoints%kp_range(1) .AND. ik <= kpoints%kp_range(2))
2274 IF (use_real_wfn)
THEN
2285 DEALLOCATE (eigenvalues, ceig)
2291 IF (use_real_wfn)
THEN
2299 CALL timestop(handle)
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
various utilities that regard array of different kinds: output, allocation,... maybe it is not a good...
Basic linear algebra operations for complex full matrices.
subroutine, public cp_cfm_scale_and_add(alpha, matrix_a, beta, matrix_b)
Scale and add two BLACS matrices (a = alpha*a + beta*b).
subroutine, public cp_cfm_scale_and_add_fm(alpha, matrix_a, beta, matrix_b)
Scale and add two BLACS matrices (a = alpha*a + beta*b). where b is a real matrix (adapted from cp_cf...
subroutine, public cp_cfm_column_scale(matrix_a, scaling)
Scales columns of the full matrix by corresponding factors.
used for collecting diagonalization schemes available for cp_cfm_type
subroutine, public cp_cfm_geeig(amatrix, bmatrix, eigenvectors, eigenvalues, work)
General Eigenvalue Problem AX = BXE Single option version: Cholesky decomposition of B.
subroutine, public cp_cfm_heevd(matrix, eigenvectors, eigenvalues)
Perform a diagonalisation of a complex matrix.
subroutine, public cp_cfm_geeig_canon(amatrix, bmatrix, eigenvectors, eigenvalues, work, epseig)
General Eigenvalue Problem AX = BXE Use canonical orthogonalization.
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_release(matrix)
Releases a full matrix.
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_set_all(matrix, alpha, beta)
Set all elements of the full matrix to alpha. Besides, set all diagonal matrix elements to beta (if g...
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)
...
subroutine, public dbcsr_desymmetrize(matrix_a, matrix_b)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_set(matrix, alpha)
...
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 cp_dbcsr_sm_fm_multiply(matrix, fm_in, fm_out, ncol, alpha, beta)
multiply a dbcsr with a fm matrix
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
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)
subroutine, public cp_fm_uplo_to_full(matrix, work, uplo)
given a triangular matrix according to uplo, computes the corresponding full matrix
subroutine, public cp_fm_symm(side, uplo, m, n, alpha, matrix_a, matrix_b, beta, matrix_c)
computes matrix_c = beta * matrix_c + alpha * matrix_a * matrix_b computes matrix_c = beta * matrix_c...
various cholesky decomposition related routines
subroutine, public cp_fm_cholesky_restore(fm_matrix, neig, fm_matrixb, fm_matrixout, op, pos, transa)
apply Cholesky decomposition op can be "SOLVE" (out = U^-1 * in) or "MULTIPLY" (out = U * in) pos can...
subroutine, public cp_fm_cholesky_reduce(matrix, matrixb, itype)
reduce a matrix pencil A,B to normal form B has to be cholesky decomposed with cp_fm_cholesky_decompo...
used for collecting some of the diagonalization schemes available for cp_fm_type. cp_fm_power also mo...
integer, parameter, public fm_diag_type_cusolver
logical, save, public direct_generalized_diagonalization
subroutine, public cp_fm_geeig(amatrix, bmatrix, eigenvectors, eigenvalues, work)
General Eigenvalue Problem AX = BXE. Use cuSOLVERMp directly when requested and large enough; otherwi...
subroutine, public choose_eigv_solver(matrix, eigenvectors, eigenvalues, info)
Choose the Eigensolver depending on which library is available ELPA seems to be unstable for small sy...
integer, save, public diag_type
integer, parameter, public cusolver_n_min
subroutine, public cp_fm_geeig_canon(amatrix, bmatrix, eigenvectors, eigenvalues, work, epseig)
General Eigenvalue Problem AX = BXE Use canonical diagonalization : U*s**(-1/2)
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
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_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, use_sp, nrow, ncol, set_zero)
creates a new full matrix with the given structure
subroutine, public cp_fm_add_to_element(matrix, irow_global, icol_global, alpha)
...
subroutine, public cp_fm_finish_copy_general(destination, info)
Completes the copy operation: wait for comms, unpack, clean up MPI state.
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
Defines the basic variable types.
integer, parameter, public dp
Routines needed for kpoint calculation.
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_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 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 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)
Retrieve information from a kpoint environment.
Machine interface based on Fortran 2003 and POSIX.
subroutine, public m_flush(lunit)
flushes units if the &GLOBAL flag is set accordingly
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
Definition of mathematical constants and functions.
complex(kind=dp), parameter, public z_one
complex(kind=dp), parameter, public gaussi
complex(kind=dp), parameter, public z_zero
Interface to the message passing library MPI.
basic linear algebra operations for full matrixes
computes preconditioners, and implements methods to apply them currently used in qs_ot
subroutine, public restart_preconditioner(qs_env, preconditioner, prec_type, nspins)
Allows for a restart of the preconditioner depending on the method it purges all arrays or keeps them...
subroutine, public prepare_preconditioner(qs_env, mos, matrix_ks, matrix_s, ot_preconditioner, prec_type, solver_type, energy_gap, nspins, has_unit_metric, convert_to_dbcsr, chol_type, full_mo_set)
...
collects routines that calculate density matrices
module that contains the definitions of the scf types
integer, parameter, public direct_mixing_nr
integer, parameter, public gspace_mixing_nr
Apply the direct inversion in the iterative subspace (DIIS) of Pulay in the framework of an SCF itera...
subroutine, public qs_diis_b_info_kp(diis_buffer, ib, nb)
Update info about the current buffer step ib and the current number of buffers nb.
subroutine, public qs_diis_b_calc_err_kp(diis_buffer, ib, mos, kc, sc, ispin, ikp, nkp_local, scf_section)
Calculate and store the error for a given k-point.
subroutine, public qs_diis_b_step_kp(diis_buffer, coeffs, ib, nb, delta, error_max, diis_step, eps_diis, nspin, nkp, nkp_local, nmixing, scf_section, para_env)
Update the SCF DIIS buffer, and if appropriate does a diis step, for k-points.
subroutine, public qs_diis_b_step(diis_buffer, mo_array, kc, sc, delta, error_max, diis_step, eps_diis, nmixing, s_matrix, scf_section, roks)
Update the SCF DIIS buffer, and if appropriate does a diis step.
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
subroutine, public gspace_mixing(qs_env, mixing_method, mixing_store, rho, para_env, iter_count)
Driver for the g-space mixing, calls the proper routine given the requested method.
routines that build the Kohn-Sham matrix (i.e calculate the coulomb and xc parts
subroutine, public qs_ks_update_qs_env(qs_env, calculate_forces, just_energy, print_active)
updates the Kohn Sham matrix of the given qs_env (facility method)
subroutine, public qs_ks_did_change(ks_env, s_mstruct_changed, rho_changed, potential_changed, full_reset)
tells that some of the things relevant to the ks calculation did change. has to be called when change...
wrapper for the pools of 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)
elemental subroutine, public charge_mixing_init(mixing_store)
initialiation needed when charge mixing is used
subroutine, public mixing_init(mixing_method, rho, mixing_store, para_env, rho_atom)
initialiation needed when gspace mixing is used
subroutine, public mixing_allocate(qs_env, mixing_method, p_mix_new, p_delta, nspins, mixing_store)
allocation needed when density mixing is used
subroutine, public self_consistency_check(rho_ao, p_delta, para_env, p_out, delta)
...
collects routines that perform operations directly related to MOs
Set occupation of molecular orbitals.
Definition and initialisation of the mo data type.
subroutine, public get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, uniform_occupation, kts, mu, flexible_electron_count)
Get the components of a MO set data structure.
Define the neighbor list data types and the corresponding functionality.
an eigen-space solver for the generalised symmetric eigenvalue problem for sparse matrices,...
subroutine, public ot_eigensolver(matrix_h, matrix_s, matrix_orthogonal_space_fm, matrix_c_fm, preconditioner, eps_gradient, iter_max, size_ortho_space, silent, ot_settings)
...
methods of the rho structure (defined in qs_rho_types)
subroutine, public qs_rho_update_rho(rho_struct, qs_env, rho_xc_external, local_rho_set, task_list_external, task_list_external_soft, pw_env_external, para_env_external)
updates rho_r and rho_g to the rhorho_ao. if use_kinetic_energy_density also computes tau_r and tau_g...
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...
module that contains the algorithms to perform an iterative diagonalization by the block-Davidson app...
subroutine, public generate_extended_space_sparse(bdav_env, mo_set, matrix_h, matrix_s, output_unit, preconditioner)
...
subroutine, public generate_extended_space(bdav_env, mo_set, matrix_h, matrix_s, output_unit, preconditioner)
...
Different diagonalization schemes that can be used for the iterative solution of the eigenvalue probl...
subroutine, public general_eigenproblem(scf_env, mos, matrix_ks, matrix_s, scf_control, scf_section, diis_step)
the inner loop of scf, specific to diagonalization with S matrix basically, in goes the ks matrix out...
subroutine, public diag_subspace_allocate(subspace_env, qs_env, mos)
...
subroutine, public do_ot_diag(scf_env, mos, matrix_ks, matrix_s, scf_control, scf_section, diis_step)
the inner loop of scf, specific to iterative diagonalization using OT with S matrix; basically,...
subroutine, public do_block_davidson_diag(qs_env, scf_env, mos, matrix_ks, matrix_s, scf_control, scf_section, check_moconv_only)
iterative diagonalization using the block davidson space approach
subroutine, public do_roks_diag(scf_env, mos, matrix_ks, matrix_s, scf_control, scf_section, diis_step, orthogonal_basis)
Solve a set restricted open Kohn-Sham (ROKS) equations based on the alpha and beta Kohn-Sham matrices...
subroutine, public diag_kp_basic(matrix_ks, matrix_s, kpoints, fmwork)
Kpoint diagonalization routine Transforms matrices to kpoint, distributes kpoint groups,...
subroutine, public do_scf_diag_subspace(qs_env, scf_env, subspace_env, mos, rho, ks_env, scf_section, scf_control)
inner loop within MOS subspace, to refine occupation and density, before next diagonalization of the ...
subroutine, public do_block_krylov_diag(scf_env, mos, matrix_ks, scf_control, scf_section, check_moconv_only)
iterative diagonalization using the block Krylov-space approach
subroutine, public do_special_diag(scf_env, mos, matrix_ks, scf_control, scf_section, diis_step)
the inner loop of scf, specific to diagonalization without S matrix basically, in goes the ks matrix ...
subroutine, public do_general_diag(scf_env, mos, matrix_ks, matrix_s, scf_control, scf_section, diis_step, probe)
...
subroutine, public do_general_diag_kp(matrix_ks, matrix_s, kpoints, scf_env, scf_control, update_p, diis_step, diis_error, qs_env, probe)
Kpoint diagonalization routine Transforms matrices to kpoint, distributes kpoint groups,...
subroutine, public diag_kp_smat(matrix_s, kpoints, fmwork)
Kpoint diagonalization routine Transforms matrices to kpoint, distributes kpoint groups,...
module that contains the algorithms to perform an iterative diagonalization by the block-Lanczos appr...
subroutine, public lanczos_refinement(krylov_space, ks, c0, c1, eval, nao, eps_iter, ispin, check_moconv_only)
lanczos refinement by blocks of non-converged MOs
subroutine, public lanczos_refinement_2v(krylov_space, ks, c0, c1, eval, nao, eps_iter, ispin, check_moconv_only)
...
groups fairly general SCF methods, so that modules other than qs_scf can use them too split off from ...
subroutine, public eigensolver_simple(matrix_ks, mo_set, work, do_level_shift, level_shift, use_jacobi, jacobi_threshold)
...
subroutine, public eigensolver_dbcsr(matrix_ks, matrix_ks_fm, mo_set, ortho_dbcsr, ksbuf1, ksbuf2)
...
subroutine, public scf_env_density_mixing(p_mix_new, mixing_store, rho_ao, para_env, iter_delta, iter_count, diis, invert)
perform (if requested) a density mixing
subroutine, public eigensolver(matrix_ks_fm, mo_set, ortho, work, cholesky_method, do_level_shift, level_shift, matrix_u_fm, use_jacobi)
Diagonalise the Kohn-Sham matrix to get a new set of MO eigen- vectors and MO eigenvalues....
subroutine, public eigensolver_symm(matrix_ks_fm, mo_set, ortho, work, do_level_shift, level_shift, matrix_u_fm, use_jacobi, jacobi_threshold, ortho_red, work_red, matrix_ks_fm_red, matrix_u_fm_red)
...
subroutine, public eigensolver_generalized(matrix_ks_fm, matrix_s, mo_set, work)
Solve the generalized eigenvalue problem using cusolverMpSygvd.
module that contains the definitions of the scf types
parameters that control an scf iteration
represent a pointer to a 1d array
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.
type of a logger, at the moment it contains just a print level starting at which level it should be l...
Keeps information about a specific k-point.
Contains information about kpoints.
stores all the informations relevant to an mpi environment
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...
container for the pools of matrixes used by qs
keeps the density in various representations, keeping track of which ones are valid.