49 cp_fm_to_fm, cp_fm_type
54 USE dbcsr_api,
ONLY: &
55 dbcsr_copy, dbcsr_create, dbcsr_deallocate_matrix, dbcsr_desymmetrize, dbcsr_p_type, &
56 dbcsr_set, dbcsr_type, dbcsr_type_antisymmetric, dbcsr_type_no_symmetry, &
120 #include "./base/base_uses.f90"
126 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_scf_diagonalization'
149 matrix_s, scf_control, scf_section, &
152 TYPE(qs_scf_env_type),
POINTER :: scf_env
153 TYPE(mo_set_type),
DIMENSION(:),
INTENT(IN) :: mos
154 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s
155 TYPE(scf_control_type),
POINTER :: scf_control
156 TYPE(section_vals_type),
POINTER :: scf_section
157 LOGICAL,
INTENT(INOUT) :: diis_step
159 INTEGER :: ispin, nspin
160 LOGICAL :: do_level_shift, owns_ortho, use_jacobi
161 REAL(kind=
dp) :: diis_error, eps_diis
162 TYPE(cp_fm_type),
POINTER :: ortho
163 TYPE(dbcsr_type),
POINTER :: ortho_dbcsr
165 nspin =
SIZE(matrix_ks)
166 NULLIFY (ortho, ortho_dbcsr)
170 scf_env%scf_work1(ispin))
173 eps_diis = scf_control%eps_diis
175 IF (scf_env%iter_count > 1 .AND. .NOT. scf_env%skip_diis)
THEN
176 CALL qs_diis_b_step(scf_env%scf_diis_buffer, mos, scf_env%scf_work1, &
177 scf_env%scf_work2, scf_env%iter_delta, diis_error, diis_step, &
178 eps_diis, scf_control%nmixing, &
180 scf_section=scf_section)
185 do_level_shift = ((scf_control%level_shift /= 0.0_dp) .AND. &
186 ((scf_control%density_guess ==
core_guess) .OR. &
187 (scf_env%iter_count > 1)))
189 IF ((scf_env%iter_count > 1) .AND. &
190 (scf_env%iter_delta < scf_control%diagonalization%eps_jacobi))
THEN
197 scf_env%iter_param = diis_error
199 scf_env%iter_method =
"DIIS/Jacobi"
201 scf_env%iter_method =
"DIIS/Diag."
204 IF (scf_env%mixing_method == 0)
THEN
205 scf_env%iter_method =
"NoMix/Diag."
206 ELSE IF (scf_env%mixing_method == 1)
THEN
207 scf_env%iter_param = scf_env%p_mix_alpha
209 scf_env%iter_method =
"P_Mix/Jacobi"
211 scf_env%iter_method =
"P_Mix/Diag."
213 ELSEIF (scf_env%mixing_method > 1)
THEN
214 scf_env%iter_param = scf_env%mixing_store%alpha
216 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Jacobi"
218 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Diag."
224 ortho_dbcsr => scf_env%ortho_dbcsr
226 CALL eigensolver_dbcsr(matrix_ks=matrix_ks(ispin)%matrix, matrix_ks_fm=scf_env%scf_work1(ispin), &
228 ortho_dbcsr=ortho_dbcsr, &
229 ksbuf1=scf_env%buf1_dbcsr, ksbuf2=scf_env%buf2_dbcsr)
234 ortho => scf_env%ortho_m1
236 ortho => scf_env%ortho
240 IF (.NOT.
ASSOCIATED(ortho))
THEN
246 IF (do_level_shift)
THEN
247 CALL eigensolver(matrix_ks_fm=scf_env%scf_work1(ispin), &
250 work=scf_env%scf_work2, &
251 cholesky_method=scf_env%cholesky_method, &
252 do_level_shift=do_level_shift, &
253 level_shift=scf_control%level_shift, &
254 matrix_u_fm=scf_env%ortho, &
255 use_jacobi=use_jacobi)
257 CALL eigensolver(matrix_ks_fm=scf_env%scf_work1(ispin), &
260 work=scf_env%scf_work2, &
261 cholesky_method=scf_env%cholesky_method, &
262 do_level_shift=do_level_shift, &
263 level_shift=scf_control%level_shift, &
264 use_jacobi=use_jacobi)
268 IF (owns_ortho)
DEALLOCATE (ortho)
270 ortho => scf_env%ortho
273 IF (.NOT.
ASSOCIATED(ortho))
THEN
278 IF (do_level_shift)
THEN
283 work=scf_env%scf_work2, &
284 do_level_shift=do_level_shift, &
285 level_shift=scf_control%level_shift, &
286 matrix_u_fm=scf_env%ortho_m1, &
287 use_jacobi=use_jacobi, &
288 jacobi_threshold=scf_control%diagonalization%jacobi_threshold)
295 work=scf_env%scf_work2, &
296 do_level_shift=do_level_shift, &
297 level_shift=scf_control%level_shift, &
298 use_jacobi=use_jacobi, &
299 jacobi_threshold=scf_control%diagonalization%jacobi_threshold)
303 IF (owns_ortho)
DEALLOCATE (ortho)
319 matrix_s, scf_control, scf_section, &
322 TYPE(qs_scf_env_type),
POINTER :: scf_env
323 TYPE(mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
324 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s
325 TYPE(scf_control_type),
POINTER :: scf_control
326 TYPE(section_vals_type),
POINTER :: scf_section
327 LOGICAL,
INTENT(INOUT) :: diis_step
329 INTEGER :: ispin, nspin
330 REAL(kind=
dp) :: total_zeff_corr
332 nspin =
SIZE(matrix_ks)
335 matrix_s, scf_control, scf_section, diis_step)
337 total_zeff_corr = 0.0_dp
338 total_zeff_corr = scf_env%sum_zeff_corr
340 IF (abs(total_zeff_corr) > 0.0_dp)
THEN
341 CALL set_mo_occupation(mo_array=mos, &
342 smear=scf_control%smear, tot_zeff_corr=total_zeff_corr)
344 CALL set_mo_occupation(mo_array=mos, &
345 smear=scf_control%smear)
349 CALL calculate_density_matrix(mos(ispin), &
350 scf_env%p_mix_new(ispin, 1)%matrix)
374 diis_step, diis_error, qs_env)
376 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks, matrix_s
377 TYPE(kpoint_type),
POINTER :: kpoints
378 TYPE(qs_scf_env_type),
POINTER :: scf_env
379 TYPE(scf_control_type),
POINTER :: scf_control
380 LOGICAL,
INTENT(IN) :: update_p
381 LOGICAL,
INTENT(INOUT) :: diis_step
382 REAL(
dp),
INTENT(INOUT),
OPTIONAL :: diis_error
383 TYPE(qs_environment_type),
OPTIONAL,
POINTER :: qs_env
385 CHARACTER(len=*),
PARAMETER :: routinen =
'do_general_diag_kp'
386 COMPLEX(KIND=dp),
PARAMETER :: cone = cmplx(1.0_dp, 0.0_dp, kind=
dp), &
387 czero = cmplx(0.0_dp, 0.0_dp, kind=
dp), ione = cmplx(0.0_dp, 1.0_dp, kind=
dp)
389 COMPLEX(KIND=dp),
ALLOCATABLE,
DIMENSION(:) :: coeffs
390 INTEGER :: handle, ib, igroup, ik, ikp, indx, &
391 ispin, jb, kplocal, nb, nkp, &
393 INTEGER,
DIMENSION(2) :: kp_range
394 INTEGER,
DIMENSION(:, :),
POINTER :: kp_dist
395 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
396 LOGICAL :: do_diis, my_kpgrp, use_real_wfn
397 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues
398 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: xkp
399 TYPE(copy_info_type),
ALLOCATABLE,
DIMENSION(:, :) :: info
400 TYPE(cp_cfm_type) :: cksmat, cmos, csmat, cwork
401 TYPE(cp_fm_pool_p_type),
DIMENSION(:),
POINTER :: ao_ao_fm_pools
402 TYPE(cp_fm_struct_type),
POINTER :: matrix_struct, mo_struct
403 TYPE(cp_fm_type) :: fmdummy, fmlocal, rksmat, rsmat
404 TYPE(cp_fm_type),
DIMENSION(:),
POINTER :: fmwork
405 TYPE(cp_fm_type),
POINTER :: imos, mo_coeff, rmos
406 TYPE(dbcsr_type),
POINTER :: cmatrix, rmatrix, tmpmat
407 TYPE(kpoint_env_type),
POINTER :: kp
408 TYPE(mp_para_env_type),
POINTER :: para_env, para_env_global
409 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
411 TYPE(qs_matrix_pools_type),
POINTER :: mpools
412 TYPE(section_vals_type),
POINTER :: scf_section
414 CALL timeset(routinen, handle)
417 CALL get_kpoint_info(kpoints, nkp=nkp, xkp=xkp, use_real_wfn=use_real_wfn, kp_range=kp_range, &
418 nkp_groups=nkp_groups, kp_dist=kp_dist, sab_nl=sab_nl, &
419 cell_to_index=cell_to_index)
420 cpassert(
ASSOCIATED(sab_nl))
421 kplocal = kp_range(2) - kp_range(1) + 1
425 IF (scf_env%iter_count > 1 .AND. .NOT. scf_env%skip_diis .AND. .NOT. use_real_wfn &
426 .AND.
PRESENT(diis_error) .AND.
PRESENT(qs_env)) do_diis = .true.
429 ALLOCATE (rmatrix, cmatrix, tmpmat)
430 CALL dbcsr_create(rmatrix, template=matrix_ks(1, 1)%matrix, &
431 matrix_type=dbcsr_type_symmetric)
432 CALL dbcsr_create(cmatrix, template=matrix_ks(1, 1)%matrix, &
433 matrix_type=dbcsr_type_antisymmetric)
434 CALL dbcsr_create(tmpmat, template=matrix_ks(1, 1)%matrix, &
435 matrix_type=dbcsr_type_no_symmetry)
439 fmwork => scf_env%scf_work1
443 CALL mpools_get(mpools, ao_ao_fm_pools=ao_ao_fm_pools)
448 IF (use_real_wfn)
THEN
455 kp => kpoints%kp_env(1)%kpoint_env
456 CALL get_mo_set(kp%mos(1, 1), mo_coeff=mo_coeff)
461 para_env => kpoints%blacs_env_all%para_env
462 nspin =
SIZE(matrix_ks, 1)
463 ALLOCATE (info(kplocal*nspin*nkp_groups, 4))
469 DO igroup = 1, nkp_groups
471 ik = kp_dist(1, igroup) + ikp - 1
472 my_kpgrp = (ik >= kpoints%kp_range(1) .AND. ik <= kpoints%kp_range(2))
474 IF (use_real_wfn)
THEN
476 CALL dbcsr_set(rmatrix, 0.0_dp)
477 CALL rskp_transform(rmatrix=rmatrix, rsmat=matrix_ks, ispin=ispin, &
478 xkp=xkp(1:3, ik), cell_to_index=cell_to_index, sab_nl=sab_nl)
479 CALL dbcsr_desymmetrize(rmatrix, tmpmat)
482 CALL dbcsr_set(rmatrix, 0.0_dp)
484 xkp=xkp(1:3, ik), cell_to_index=cell_to_index, sab_nl=sab_nl)
485 CALL dbcsr_desymmetrize(rmatrix, tmpmat)
489 CALL dbcsr_set(rmatrix, 0.0_dp)
490 CALL dbcsr_set(cmatrix, 0.0_dp)
491 CALL rskp_transform(rmatrix=rmatrix, cmatrix=cmatrix, rsmat=matrix_ks, ispin=ispin, &
492 xkp=xkp(1:3, ik), cell_to_index=cell_to_index, sab_nl=sab_nl)
493 CALL dbcsr_desymmetrize(rmatrix, tmpmat)
495 CALL dbcsr_desymmetrize(cmatrix, tmpmat)
498 CALL dbcsr_set(rmatrix, 0.0_dp)
499 CALL dbcsr_set(cmatrix, 0.0_dp)
500 CALL rskp_transform(rmatrix=rmatrix, cmatrix=cmatrix, rsmat=matrix_s, ispin=1, &
501 xkp=xkp(1:3, ik), cell_to_index=cell_to_index, sab_nl=sab_nl)
502 CALL dbcsr_desymmetrize(rmatrix, tmpmat)
504 CALL dbcsr_desymmetrize(cmatrix, tmpmat)
511 IF (use_real_wfn)
THEN
538 CALL get_qs_env(qs_env, para_env=para_env_global)
544 DO igroup = 1, nkp_groups
546 ik = kp_dist(1, igroup) + ikp - 1
547 my_kpgrp = (ik >= kpoints%kp_range(1) .AND. ik <= kpoints%kp_range(2))
561 kp => kpoints%kp_env(ikp)%kpoint_env
563 ispin, ikp, kplocal, scf_section)
568 ALLOCATE (coeffs(nb))
569 CALL qs_diis_b_step_kp(kpoints%scf_diis_buffer, coeffs, ib, nb, scf_env%iter_delta, diis_error, &
570 diis_step, scf_control%eps_diis, nspin, nkp, kplocal, scf_control%nmixing, &
571 scf_section, para_env_global)
576 kp => kpoints%kp_env(ikp)%kpoint_env
577 CALL cp_cfm_to_cfm(kpoints%scf_diis_buffer%smat(ikp), csmat)
579 CALL cp_cfm_scale(czero, cksmat)
581 CALL cp_cfm_scale_and_add(cone, cksmat, coeffs(jb), kpoints%scf_diis_buffer%param(jb, ispin, ikp))
584 CALL get_mo_set(kp%mos(1, ispin), mo_coeff=rmos, eigenvalues=eigenvalues)
585 CALL get_mo_set(kp%mos(2, ispin), mo_coeff=imos)
588 scf_control%eps_eigval)
590 CALL cp_cfm_geeig(cksmat, csmat, cmos, eigenvalues, cwork)
593 kp%mos(2, ispin)%eigenvalues = eigenvalues
604 DO igroup = 1, nkp_groups
606 ik = kp_dist(1, igroup) + ikp - 1
607 my_kpgrp = (ik >= kpoints%kp_range(1) .AND. ik <= kpoints%kp_range(2))
610 IF (use_real_wfn)
THEN
628 kp => kpoints%kp_env(ikp)%kpoint_env
629 IF (use_real_wfn)
THEN
630 CALL get_mo_set(kp%mos(1, ispin), mo_coeff=mo_coeff, eigenvalues=eigenvalues)
633 scf_control%eps_eigval)
635 CALL cp_fm_geeig(rksmat, rsmat, mo_coeff, eigenvalues, fmlocal)
638 CALL get_mo_set(kp%mos(1, ispin), mo_coeff=rmos, eigenvalues=eigenvalues)
639 CALL get_mo_set(kp%mos(2, ispin), mo_coeff=imos)
642 scf_control%eps_eigval)
644 CALL cp_cfm_geeig(cksmat, csmat, cmos, eigenvalues, cwork)
647 kp%mos(2, ispin)%eigenvalues = eigenvalues
659 DO igroup = 1, nkp_groups
661 ik = kp_dist(1, igroup) + ikp - 1
662 my_kpgrp = (ik >= kpoints%kp_range(1) .AND. ik <= kpoints%kp_range(2))
664 IF (use_real_wfn)
THEN
688 matrix_s(1, 1)%matrix, sab_nl, fmwork)
691 CALL dbcsr_deallocate_matrix(rmatrix)
692 CALL dbcsr_deallocate_matrix(cmatrix)
693 CALL dbcsr_deallocate_matrix(tmpmat)
695 IF (use_real_wfn)
THEN
696 CALL cp_fm_release(rksmat)
697 CALL cp_fm_release(rsmat)
706 CALL timestop(handle)
726 ks_env, scf_section, scf_control)
728 TYPE(qs_environment_type),
POINTER :: qs_env
729 TYPE(qs_scf_env_type),
POINTER :: scf_env
730 TYPE(subspace_env_type),
POINTER :: subspace_env
731 TYPE(mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
732 TYPE(qs_rho_type),
POINTER :: rho
733 TYPE(qs_ks_env_type),
POINTER :: ks_env
734 TYPE(section_vals_type),
POINTER :: scf_section
735 TYPE(scf_control_type),
POINTER :: scf_control
737 CHARACTER(LEN=*),
PARAMETER :: routinen =
'do_scf_diag_subspace'
738 REAL(kind=
dp),
PARAMETER :: rone = 1.0_dp, rzero = 0.0_dp
740 INTEGER :: handle, i, iloop, ispin, nao, nmo, &
743 REAL(
dp) :: ene_diff, ene_old, iter_delta, max_val, &
744 sum_band, sum_val, t1, t2
745 REAL(kind=
dp),
DIMENSION(:),
POINTER :: mo_eigenvalues, mo_occupations
746 TYPE(cp_1d_r_p_type),
ALLOCATABLE,
DIMENSION(:) :: eval_first, occ_first
747 TYPE(cp_fm_type) :: work
748 TYPE(cp_fm_type),
POINTER :: c0, chc, evec, mo_coeff
749 TYPE(cp_logger_type),
POINTER :: logger
750 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s, rho_ao
751 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: rho_ao_kp
752 TYPE(dft_control_type),
POINTER :: dft_control
753 TYPE(mp_para_env_type),
POINTER :: para_env
754 TYPE(qs_energy_type),
POINTER :: energy
755 TYPE(rho_atom_type),
DIMENSION(:),
POINTER :: rho_atom
757 CALL timeset(routinen, handle)
758 NULLIFY (c0, chc, energy, evec, matrix_ks, mo_coeff, mo_eigenvalues, &
759 mo_occupations, dft_control, rho_ao, rho_ao_kp)
767 CALL qs_rho_get(rho, rho_ao=rho_ao, rho_ao_kp=rho_ao_kp)
769 ALLOCATE (eval_first(nspin))
770 ALLOCATE (occ_first(nspin))
774 eigenvalues=mo_eigenvalues, &
775 occupation_numbers=mo_occupations)
776 ALLOCATE (eval_first(ispin)%array(nmo))
777 ALLOCATE (occ_first(ispin)%array(nmo))
778 eval_first(ispin)%array(1:nmo) = mo_eigenvalues(1:nmo)
779 occ_first(ispin)%array(1:nmo) = mo_occupations(1:nmo)
784 CALL dbcsr_copy(subspace_env%p_matrix_store(ispin)%matrix, rho_ao(ispin)%matrix)
785 CALL dbcsr_copy(rho_ao(ispin)%matrix, scf_env%p_mix_new(ispin, 1)%matrix)
788 subspace_env%p_matrix_mix => scf_env%p_mix_new
790 NULLIFY (matrix_ks, energy, para_env, matrix_s)
792 matrix_ks=matrix_ks, &
796 dft_control=dft_control)
800 CALL mixing_allocate(qs_env, subspace_env%mixing_method, scf_env%p_mix_new, &
801 scf_env%p_delta, nspin, subspace_env%mixing_store)
802 IF (dft_control%qs_control%gapw)
THEN
803 CALL get_qs_env(qs_env=qs_env, rho_atom_set=rho_atom)
804 CALL mixing_init(subspace_env%mixing_method, rho, subspace_env%mixing_store, &
805 para_env, rho_atom=rho_atom)
806 ELSEIF (dft_control%qs_control%dftb .OR. dft_control%qs_control%xtb)
THEN
808 ELSEIF (dft_control%qs_control%semi_empirical)
THEN
809 cpabort(
'SE Code not possible')
811 CALL mixing_init(subspace_env%mixing_method, rho, subspace_env%mixing_store, para_env)
817 IF (output_unit > 0)
THEN
818 WRITE (output_unit,
"(/T19,A)")
'<<<<<<<<< SUBSPACE ROTATION <<<<<<<<<<'
819 WRITE (output_unit,
"(T4,A,T13,A,T21,A,T38,A,T51,A,T65,A/,T4,A)") &
820 "In-step",
"Time",
"Convergence",
"Band ene.",
"Total ene.",
"Energy diff.", repeat(
"-", 74)
828 DO iloop = 1, subspace_env%max_iter
831 ene_old = energy%total
835 just_energy=.false., print_active=.false.)
840 DO ispin = 1,
SIZE(matrix_ks)
844 eigenvalues=mo_eigenvalues, &
845 occupation_numbers=mo_occupations, &
849 chc => subspace_env%chc_mat(ispin)
850 evec => subspace_env%c_vec(ispin)
851 c0 => subspace_env%c0(ispin)
852 CALL cp_fm_to_fm(mo_coeff, c0)
855 CALL parallel_gemm(
'T',
'N', nmo, nmo, nao, rone, c0, work, rzero, chc)
856 CALL cp_fm_release(work)
861 CALL parallel_gemm(
'N',
'N', nao, nmo, nmo, rone, c0, evec, rzero, mo_coeff)
863 CALL set_mo_occupation(mo_set=mos(ispin), &
864 smear=scf_control%smear)
867 CALL calculate_density_matrix(mos(ispin), &
868 subspace_env%p_matrix_mix(ispin, 1)%matrix)
871 sum_band = sum_band + mo_eigenvalues(i)*mo_occupations(i)
879 scf_env%mixing_store, rho_ao_kp, para_env, iter_delta, iloop)
882 subspace_env%p_matrix_mix, delta=iter_delta)
887 CALL dbcsr_copy(rho_ao(ispin)%matrix, subspace_env%p_matrix_mix(ispin, 1)%matrix)
893 CALL gspace_mixing(qs_env, scf_env%mixing_method, subspace_env%mixing_store, &
894 rho, para_env, scf_env%iter_count)
897 ene_diff = energy%total - ene_old
898 converged = (abs(ene_diff) < subspace_env%eps_ene .AND. &
899 iter_delta < subspace_env%eps_adapt*scf_env%iter_delta)
901 IF (output_unit > 0)
THEN
902 WRITE (output_unit,
"(T4,I5,T11,F8.3,T18,E14.4,T34,F12.5,T46,F16.8,T62,E14.4)") &
903 iloop, t2 - t1, iter_delta, sum_band, energy%total, ene_diff
907 IF (output_unit > 0)
WRITE (output_unit,
"(T10,A,I6,A,/)") &
908 " Reached convergence in ", iloop,
" iterations "
914 NULLIFY (subspace_env%p_matrix_mix)
917 CALL dbcsr_copy(scf_env%p_mix_new(ispin, 1)%matrix, rho_ao(ispin)%matrix)
918 CALL dbcsr_copy(rho_ao(ispin)%matrix, subspace_env%p_matrix_store(ispin)%matrix)
920 DEALLOCATE (eval_first(ispin)%array, occ_first(ispin)%array)
922 DEALLOCATE (eval_first, occ_first)
924 CALL timestop(handle)
936 TYPE(subspace_env_type),
POINTER :: subspace_env
937 TYPE(qs_environment_type),
POINTER :: qs_env
938 TYPE(mo_set_type),
DIMENSION(:),
INTENT(IN) :: mos
940 CHARACTER(LEN=*),
PARAMETER :: routinen =
'diag_subspace_allocate'
942 INTEGER :: handle, i, ispin, nmo, nspin
943 TYPE(cp_fm_struct_type),
POINTER :: fm_struct_tmp
944 TYPE(cp_fm_type),
POINTER :: mo_coeff
945 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s
946 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
949 CALL timeset(routinen, handle)
951 NULLIFY (sab_orb, matrix_s)
952 CALL get_qs_env(qs_env=qs_env, sab_orb=sab_orb, &
957 IF (.NOT.
ASSOCIATED(subspace_env%p_matrix_store))
THEN
961 ALLOCATE (subspace_env%p_matrix_store(i)%matrix)
962 CALL dbcsr_create(matrix=subspace_env%p_matrix_store(i)%matrix, template=matrix_s(1)%matrix, &
963 name=
"DENSITY_STORE", matrix_type=dbcsr_type_symmetric, nze=0)
966 CALL dbcsr_set(subspace_env%p_matrix_store(i)%matrix, 0.0_dp)
971 ALLOCATE (subspace_env%chc_mat(nspin))
972 ALLOCATE (subspace_env%c_vec(nspin))
973 ALLOCATE (subspace_env%c0(nspin))
976 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, nmo=nmo)
977 CALL cp_fm_create(subspace_env%c0(ispin), mo_coeff%matrix_struct)
978 NULLIFY (fm_struct_tmp)
980 para_env=mo_coeff%matrix_struct%para_env, &
981 context=mo_coeff%matrix_struct%context)
982 CALL cp_fm_create(subspace_env%chc_mat(ispin), fm_struct_tmp,
"chc")
983 CALL cp_fm_create(subspace_env%c_vec(ispin), fm_struct_tmp,
"vec")
987 CALL timestop(handle)
1004 scf_section, diis_step)
1006 TYPE(qs_scf_env_type),
POINTER :: scf_env
1007 TYPE(mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
1008 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks
1009 TYPE(scf_control_type),
POINTER :: scf_control
1010 TYPE(section_vals_type),
POINTER :: scf_section
1011 LOGICAL,
INTENT(INOUT) :: diis_step
1013 INTEGER :: ispin, nspin
1014 LOGICAL :: do_level_shift, use_jacobi
1015 REAL(kind=
dp) :: diis_error
1017 nspin =
SIZE(matrix_ks)
1022 IF (scf_env%iter_count > 1 .AND. .NOT. scf_env%skip_diis)
THEN
1023 CALL qs_diis_b_step(scf_env%scf_diis_buffer, mos, scf_env%scf_work1, &
1024 scf_env%scf_work2, scf_env%iter_delta, diis_error, diis_step, &
1025 scf_control%eps_diis, scf_control%nmixing, &
1026 scf_section=scf_section)
1031 IF ((scf_env%iter_count > 1) .AND. (scf_env%iter_delta < scf_control%diagonalization%eps_jacobi))
THEN
1034 use_jacobi = .false.
1037 do_level_shift = ((scf_control%level_shift /= 0.0_dp) .AND. &
1038 ((scf_control%density_guess ==
core_guess) .OR. (scf_env%iter_count > 1)))
1040 scf_env%iter_param = diis_error
1041 IF (use_jacobi)
THEN
1042 scf_env%iter_method =
"DIIS/Jacobi"
1044 scf_env%iter_method =
"DIIS/Diag."
1047 IF (scf_env%mixing_method == 1)
THEN
1048 scf_env%iter_param = scf_env%p_mix_alpha
1049 IF (use_jacobi)
THEN
1050 scf_env%iter_method =
"P_Mix/Jacobi"
1052 scf_env%iter_method =
"P_Mix/Diag."
1054 ELSEIF (scf_env%mixing_method > 1)
THEN
1055 scf_env%iter_param = scf_env%mixing_store%alpha
1056 IF (use_jacobi)
THEN
1057 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Jacobi"
1059 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Diag."
1063 scf_env%iter_delta = 0.0_dp
1067 mo_set=mos(ispin), &
1068 work=scf_env%scf_work2, &
1069 do_level_shift=do_level_shift, &
1070 level_shift=scf_control%level_shift, &
1071 use_jacobi=use_jacobi, &
1072 jacobi_threshold=scf_control%diagonalization%jacobi_threshold)
1075 CALL set_mo_occupation(mo_array=mos, &
1076 smear=scf_control%smear)
1080 CALL calculate_density_matrix(mos(ispin), &
1081 scf_env%p_mix_new(ispin, 1)%matrix)
1100 scf_control, scf_section, diis_step)
1102 TYPE(qs_scf_env_type),
POINTER :: scf_env
1103 TYPE(mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
1104 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s
1105 TYPE(scf_control_type),
POINTER :: scf_control
1106 TYPE(section_vals_type),
POINTER :: scf_section
1107 LOGICAL,
INTENT(INOUT) :: diis_step
1109 INTEGER :: homo, ispin, nmo, nspin
1110 REAL(kind=
dp) :: diis_error, eps_iter
1111 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues
1112 TYPE(cp_fm_type),
POINTER :: mo_coeff
1114 NULLIFY (eigenvalues)
1116 nspin =
SIZE(matrix_ks)
1120 scf_env%scf_work1(ispin))
1123 IF ((scf_env%iter_count > 1) .AND. (.NOT. scf_env%skip_diis))
THEN
1124 CALL qs_diis_b_step(scf_env%scf_diis_buffer, mos, scf_env%scf_work1, &
1125 scf_env%scf_work2, scf_env%iter_delta, diis_error, diis_step, &
1126 scf_control%eps_diis, scf_control%nmixing, &
1127 s_matrix=matrix_s, &
1128 scf_section=scf_section)
1133 eps_iter = scf_control%diagonalization%eps_iter
1135 scf_env%iter_param = diis_error
1136 scf_env%iter_method =
"DIIS/OTdiag"
1139 matrix_ks(ispin)%matrix, keep_sparsity=.true.)
1141 eps_iter = max(eps_iter, scf_control%diagonalization%eps_adapt*diis_error)
1143 IF (scf_env%mixing_method == 1)
THEN
1144 scf_env%iter_param = scf_env%p_mix_alpha
1145 scf_env%iter_method =
"P_Mix/OTdiag."
1146 ELSEIF (scf_env%mixing_method > 1)
THEN
1147 scf_env%iter_param = scf_env%mixing_store%alpha
1148 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/OTdiag."
1152 scf_env%iter_delta = 0.0_dp
1156 mo_coeff=mo_coeff, &
1157 eigenvalues=eigenvalues, &
1161 matrix_s=matrix_s(1)%matrix, &
1162 matrix_c_fm=mo_coeff, &
1164 eps_gradient=eps_iter, &
1165 iter_max=scf_control%diagonalization%max_iter, &
1167 ot_settings=scf_control%diagonalization%ot_settings)
1168 CALL calculate_subspace_eigenvalues(mo_coeff, matrix_ks(ispin)%matrix, &
1169 evals_arg=eigenvalues, &
1173 mos(ispin)%mo_coeff_b)
1177 CALL set_mo_occupation(mo_array=mos, &
1178 smear=scf_control%smear)
1182 CALL calculate_density_matrix(mos(ispin), &
1183 scf_env%p_mix_new(ispin, 1)%matrix)
1206 scf_control, scf_section, diis_step, &
1213 TYPE(qs_scf_env_type),
POINTER :: scf_env
1214 TYPE(mo_set_type),
DIMENSION(:),
INTENT(IN) :: mos
1215 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s
1216 TYPE(scf_control_type),
POINTER :: scf_control
1217 TYPE(section_vals_type),
POINTER :: scf_section
1218 LOGICAL,
INTENT(INOUT) :: diis_step
1219 LOGICAL,
INTENT(IN) :: orthogonal_basis
1221 CHARACTER(LEN=*),
PARAMETER :: routinen =
'do_roks_diag'
1223 INTEGER :: handle, homoa, homob, imo, nalpha, nao, &
1225 REAL(kind=
dp) :: diis_error, level_shift_loc
1226 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eiga, eigb, occa, occb
1227 TYPE(cp_fm_type),
POINTER :: ksa, ksb, mo2ao, moa, mob, ortho, work
1231 CALL timeset(routinen, handle)
1234 ortho => scf_env%ortho_m1
1236 ortho => scf_env%ortho
1238 work => scf_env%scf_work2
1240 ksa => scf_env%scf_work1(1)
1241 ksb => scf_env%scf_work1(2)
1254 occupation_numbers=occa, &
1261 occupation_numbers=occb, &
1266 IF ((scf_control%level_shift /= 0.0_dp) .AND. &
1267 ((scf_control%density_guess ==
core_guess) .OR. &
1269 (scf_env%iter_count > 1)))
THEN
1270 level_shift_loc = scf_control%level_shift
1272 level_shift_loc = 0.0_dp
1275 IF ((scf_env%iter_count > 1) .OR. &
1276 (scf_control%density_guess ==
core_guess) .OR. &
1282 CALL cp_fm_symm(
"L",
"U", nao, nao, 1.0_dp, ksa, moa, 0.0_dp, work)
1283 CALL parallel_gemm(
"T",
"N", nao, nao, nao, 1.0_dp, moa, work, 0.0_dp, ksa)
1285 CALL cp_fm_symm(
"L",
"U", nao, nao, 1.0_dp, ksb, moa, 0.0_dp, work)
1286 CALL parallel_gemm(
"T",
"N", nao, nao, nao, 1.0_dp, moa, work, 0.0_dp, ksb)
1292 CALL combine_ks_matrices(ksa, ksb, occa, occb, scf_control%roks_f, &
1295 CALL combine_ks_matrices(ksa, ksb, occa, occb, scf_control%roks_parameter)
1297 cpabort(
"Unknown ROKS scheme requested")
1303 IF (orthogonal_basis)
THEN
1316 CALL parallel_gemm(
"N",
"T", nao, nao, nao, 1.0_dp, ksa, mo2ao, 0.0_dp, work)
1317 CALL parallel_gemm(
"N",
"N", nao, nao, nao, 1.0_dp, mo2ao, work, 0.0_dp, ksa)
1325 CALL cp_fm_to_fm(ksb, ksa)
1331 IF (scf_env%iter_count > 1)
THEN
1332 IF (orthogonal_basis)
THEN
1335 kc=scf_env%scf_work1, &
1337 delta=scf_env%iter_delta, &
1338 error_max=diis_error, &
1339 diis_step=diis_step, &
1340 eps_diis=scf_control%eps_diis, &
1341 scf_section=scf_section, &
1346 kc=scf_env%scf_work1, &
1348 delta=scf_env%iter_delta, &
1349 error_max=diis_error, &
1350 diis_step=diis_step, &
1351 eps_diis=scf_control%eps_diis, &
1352 scf_section=scf_section, &
1353 s_matrix=matrix_s, &
1359 scf_env%iter_param = diis_error
1360 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 scf_env%iter_method =
"P_Mix/Diag."
1365 ELSEIF (scf_env%mixing_method > 1)
THEN
1366 scf_env%iter_param = scf_env%mixing_store%alpha
1367 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Diag."
1371 scf_env%iter_delta = 0.0_dp
1373 IF (level_shift_loc /= 0.0_dp)
THEN
1378 CALL cp_fm_symm(
"L",
"U", nao, nao, 1.0_dp, ksa, moa, 0.0_dp, work)
1379 CALL parallel_gemm(
"T",
"N", nao, nao, nao, 1.0_dp, moa, work, 0.0_dp, ksa)
1383 DO imo = homob + 1, homoa
1386 DO imo = homoa + 1, nmo
1390 ELSE IF (.NOT. orthogonal_basis)
THEN
1393 SELECT CASE (scf_env%cholesky_method)
1399 "SOLVE", pos=
"RIGHT")
1401 "SOLVE", pos=
"LEFT", transa=
"T")
1405 "MULTIPLY", pos=
"RIGHT")
1407 "MULTIPLY", pos=
"LEFT", transa=
"T")
1409 CALL cp_fm_symm(
"L",
"U", nao, nao, 1.0_dp, ksa, ortho, 0.0_dp, work)
1410 CALL parallel_gemm(
"N",
"N", nao, nao, nao, 1.0_dp, ortho, work, 0.0_dp, ksa)
1421 IF (level_shift_loc /= 0.0_dp)
THEN
1423 CALL cp_fm_to_fm(moa, ortho)
1424 CALL parallel_gemm(
"N",
"N", nao, nmo, nao, 1.0_dp, ortho, work, 0.0_dp, moa)
1426 IF (orthogonal_basis)
THEN
1427 CALL cp_fm_to_fm(work, moa)
1429 SELECT CASE (scf_env%cholesky_method)
1435 CALL parallel_gemm(
"N",
"N", nao, nmo, nao, 1.0_dp, ortho, work, 0.0_dp, moa)
1442 IF (level_shift_loc /= 0.0_dp)
THEN
1443 DO imo = homob + 1, homoa
1444 eiga(imo) = eiga(imo) - 0.5_dp*level_shift_loc
1446 DO imo = homoa + 1, nmo
1447 eiga(imo) = eiga(imo) - level_shift_loc
1454 CALL cp_fm_to_fm(moa, mob)
1459 CALL calculate_density_matrix(mos(1), scf_env%p_mix_new(1, 1)%matrix)
1460 CALL calculate_density_matrix(mos(2), scf_env%p_mix_new(2, 1)%matrix)
1462 CALL timestop(handle)
1480 scf_control, scf_section, check_moconv_only)
1482 TYPE(qs_scf_env_type),
POINTER :: scf_env
1483 TYPE(mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
1484 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks
1485 TYPE(scf_control_type),
POINTER :: scf_control
1486 TYPE(section_vals_type),
POINTER :: scf_section
1487 LOGICAL,
INTENT(IN),
OPTIONAL :: check_moconv_only
1489 CHARACTER(LEN=*),
PARAMETER :: routinen =
'do_block_krylov_diag'
1490 REAL(kind=
dp),
PARAMETER :: rone = 1.0_dp, rzero = 0.0_dp
1492 INTEGER :: handle, homo, ispin, iter, nao, nmo, &
1494 LOGICAL :: converged, my_check_moconv_only
1495 REAL(
dp) :: eps_iter, t1, t2
1496 REAL(kind=
dp),
DIMENSION(:),
POINTER :: mo_eigenvalues
1497 TYPE(cp_fm_type),
POINTER :: c0, c1, chc, evec, ks, mo_coeff, ortho, &
1499 TYPE(cp_logger_type),
POINTER :: logger
1502 CALL timeset(routinen, handle)
1505 extension=
".scfLog")
1507 my_check_moconv_only = .false.
1508 IF (
PRESENT(check_moconv_only)) my_check_moconv_only = check_moconv_only
1510 NULLIFY (mo_coeff, ortho, work, ks)
1511 NULLIFY (mo_eigenvalues)
1515 ortho => scf_env%ortho_m1
1517 ortho => scf_env%ortho
1519 work => scf_env%scf_work2
1521 DO ispin = 1,
SIZE(matrix_ks)
1523 scf_env%scf_work1(ispin))
1526 IF (scf_env%mixing_method == 1)
THEN
1527 scf_env%iter_param = scf_env%p_mix_alpha
1528 scf_env%iter_method =
"P_Mix/Lanczos"
1531 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Lanc."
1534 DO ispin = 1,
SIZE(matrix_ks)
1536 ks => scf_env%scf_work1(ispin)
1543 eigenvalues=mo_eigenvalues, &
1547 c0 => scf_env%krylov_space%mo_conv(ispin)
1548 c1 => scf_env%krylov_space%mo_refine(ispin)
1549 SELECT CASE (scf_env%cholesky_method)
1556 "SOLVE", pos=
"RIGHT")
1558 "SOLVE", pos=
"LEFT", transa=
"T")
1562 "MULTIPLY", pos=
"RIGHT")
1564 "MULTIPLY", pos=
"LEFT", transa=
"T")
1568 scf_env%krylov_space%nmo_nc = nmo
1569 scf_env%krylov_space%nmo_conv = 0
1572 IF (output_unit > 0)
THEN
1573 WRITE (output_unit,
"(/T15,A)")
'<<<<<<<<< LANCZOS REFINEMENT <<<<<<<<<<'
1574 WRITE (output_unit,
"(T8,A,T15,A,T23,A,T36,A,T49,A,T60,A,/,T8,A)") &
1575 " Spin ",
" Cycle ", &
1576 " conv. MOS ",
" B2MAX ",
" B2MIN ",
" Time", repeat(
"-", 60)
1578 eps_iter = max(scf_env%krylov_space%eps_conv, scf_env%krylov_space%eps_adapt*scf_env%iter_delta)
1582 IF (my_check_moconv_only)
THEN
1585 nao, eps_iter, ispin, check_moconv_only=my_check_moconv_only)
1587 IF (output_unit > 0) &
1588 WRITE (output_unit,
'(T8,I3,T16,I5,T24,I6,T33,E12.4,2x,E12.4,T60,F8.3)') &
1589 ispin, iter, scf_env%krylov_space%nmo_conv, &
1590 scf_env%krylov_space%max_res_norm, scf_env%krylov_space%min_res_norm, t2 - t1
1595 DO iter = 1, scf_env%krylov_space%max_iter
1597 nao, eps_iter, ispin)
1599 IF (output_unit > 0)
THEN
1600 WRITE (output_unit,
'(T8,I3,T16,I5,T24,I6,T33,E12.4,2x,E12.4,T60,F8.3)') &
1601 ispin, iter, scf_env%krylov_space%nmo_conv, &
1602 scf_env%krylov_space%max_res_norm, scf_env%krylov_space%min_res_norm, t2 - t1
1605 IF (scf_env%krylov_space%max_res_norm < eps_iter)
THEN
1607 IF (output_unit > 0)
WRITE (output_unit, *) &
1608 " Reached convergence in ", iter,
" iterations "
1613 IF (.NOT. converged .AND. output_unit > 0)
THEN
1614 WRITE (output_unit,
"(T4, A)")
" WARNING Lanczos refinement could "// &
1615 "not converge all the mos:"
1616 WRITE (output_unit,
"(T40,A,T70,I10)")
" number of not converged mos ", &
1617 scf_env%krylov_space%nmo_nc
1618 WRITE (output_unit,
"(T40,A,T70,E10.2)")
" max norm of the residual ", &
1619 scf_env%krylov_space%max_res_norm
1627 chc => scf_env%krylov_space%chc_mat(ispin)
1628 evec => scf_env%krylov_space%c_vec(ispin)
1629 CALL parallel_gemm(
'N',
'N', nao, nmo, nao, rone, ks, c0, rzero, work)
1630 CALL parallel_gemm(
'T',
'N', nmo, nmo, nao, rone, c0, work, rzero, chc)
1634 CALL parallel_gemm(
'N',
'N', nao, nmo, nmo, rone, c0, evec, rzero, c1)
1635 c0 => scf_env%krylov_space%mo_refine(ispin)
1644 CALL set_mo_occupation(mo_set=mos(ispin), &
1645 smear=scf_control%smear)
1648 CALL calculate_density_matrix(mos(ispin), &
1649 scf_env%p_mix_new(ispin, 1)%matrix)
1653 IF (output_unit > 0)
THEN
1654 WRITE (output_unit,
"(T15,A/)")
'<<<<<<<<< END LANCZOS REFINEMENT <<<<<<<<<<'
1660 CALL timestop(handle)
1680 scf_control, scf_section, check_moconv_only)
1682 TYPE(qs_environment_type),
POINTER :: qs_env
1683 TYPE(qs_scf_env_type),
POINTER :: scf_env
1684 TYPE(mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
1685 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s
1686 TYPE(scf_control_type),
POINTER :: scf_control
1687 TYPE(section_vals_type),
POINTER :: scf_section
1688 LOGICAL,
INTENT(IN),
OPTIONAL :: check_moconv_only
1690 CHARACTER(LEN=*),
PARAMETER :: routinen =
'do_block_davidson_diag'
1692 INTEGER :: handle, ispin, nspins, output_unit
1693 LOGICAL :: do_prec, my_check_moconv_only
1694 TYPE(cp_logger_type),
POINTER :: logger
1697 CALL timeset(routinen, handle)
1700 extension=
".scfLog")
1702 IF (output_unit > 0) &
1703 WRITE (output_unit,
"(/T15,A)")
'<<<<<<<<< DAVIDSON ITERATIONS <<<<<<<<<<'
1705 IF (scf_env%mixing_method == 1)
THEN
1706 scf_env%iter_param = scf_env%p_mix_alpha
1707 scf_env%iter_method =
"P_Mix/Dav."
1709 scf_env%iter_param = scf_env%mixing_store%alpha
1710 scf_env%iter_method = trim(scf_env%mixing_store%iter_method)//
"/Dav."
1713 my_check_moconv_only = .false.
1714 IF (
PRESENT(check_moconv_only)) my_check_moconv_only = check_moconv_only
1716 IF (scf_env%block_davidson_env(1)%prec_type /= 0 .AND. &
1717 scf_env%iter_count >= scf_env%block_davidson_env(1)%first_prec)
THEN
1721 nspins =
SIZE(matrix_ks)
1723 IF (do_prec .AND. (scf_env%iter_count == scf_env%block_davidson_env(1)%first_prec .OR. &
1724 modulo(scf_env%iter_count, scf_env%block_davidson_env(1)%niter_new_prec) == 0))
THEN
1726 prec_type=scf_env%block_davidson_env(1)%prec_type, nspins=nspins)
1728 scf_env%block_davidson_env(1)%prec_type, &
1729 scf_env%block_davidson_env(1)%solver_type, &
1730 scf_env%block_davidson_env(1)%energy_gap, nspins, &
1731 convert_to_dbcsr=scf_env%block_davidson_env(1)%use_sparse_mos, &
1735 DO ispin = 1, nspins
1736 IF (scf_env%block_davidson_env(ispin)%use_sparse_mos)
THEN
1737 IF (.NOT. do_prec)
THEN
1739 matrix_ks(ispin)%matrix, matrix_s(1)%matrix, output_unit)
1742 matrix_ks(ispin)%matrix, matrix_s(1)%matrix, output_unit, &
1743 scf_env%ot_preconditioner(ispin)%preconditioner)
1747 IF (.NOT. do_prec)
THEN
1749 matrix_ks(ispin)%matrix, matrix_s(1)%matrix, output_unit)
1752 matrix_ks(ispin)%matrix, matrix_s(1)%matrix, output_unit, &
1753 scf_env%ot_preconditioner(ispin)%preconditioner)
1758 CALL set_mo_occupation(mo_array=mos, &
1759 smear=scf_control%smear)
1761 DO ispin = 1, nspins
1763 CALL calculate_density_matrix(mos(ispin), &
1764 scf_env%p_mix_new(ispin, 1)%matrix)
1767 IF (output_unit > 0)
THEN
1768 WRITE (output_unit,
"(T15,A/)")
'<<<<<<<<< END DAVIDSON ITERATION <<<<<<<<<<'
1774 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...
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_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_create(matrix, matrix_struct, name)
Creates a new full matrix with the given structure.
subroutine, public cp_cfm_release(matrix)
Releases 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...
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_upper_to_full(matrix, work)
given an upper triangular matrix 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_reduce(matrix, matrixb, itype)
reduce a matrix pencil A,B to normal form B has to be cholesky decomposed with cp_fm_cholesky_decompo...
subroutine, public cp_fm_cholesky_restore(matrix, neig, matrixb, matrixout, op, pos, transa)
...
used for collecting some of the diagonalization schemes available for cp_fm_type. cp_fm_power also mo...
subroutine, public cp_fm_geeig(amatrix, bmatrix, eigenvectors, eigenvalues, work)
General Eigenvalue Problem AX = BXE Single option version: Cholesky decomposition of B.
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...
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_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.
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp)
creates a new full matrix with the given structure
various routines to log and control the output. The idea is that decisions about where to log should ...
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)
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)
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
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, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_RI_aux_kp, matrix_s, matrix_s_RI_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, WannierCentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, rhs)
Get the QUICKSTEP environment.
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 itrative diagonalization by the block-Davidson appr...
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 do_general_diag_kp(matrix_ks, matrix_s, kpoints, scf_env, scf_control, update_p, diis_step, diis_error, qs_env)
Kpoint diagonalization routine Transforms matrices to kpoint, distributes kpoint groups,...
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)
...
module that contains the algorithms to perform an itrative diagonalization by the block-Lanczos appro...
subroutine, public lanczos_refinement(krylov_space, ks, c0, c1, eval, nao, eps_iter, ispin, check_moconv_only)
lanczos refinement by blocks of not-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_symm(matrix_ks_fm, mo_set, ortho, work, do_level_shift, level_shift, matrix_u_fm, use_jacobi, jacobi_threshold)
...
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....
module that contains the definitions of the scf types
parameters that control an scf iteration