35 dbcsr_type_no_symmetry
65#include "./base/base_uses.f90"
69 CHARACTER(LEN=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_mo_methods'
70 REAL(KIND=
dp),
PARAMETER :: empty_mo_norm = 100.0_dp*epsilon(1.0_dp)
79 MODULE PROCEDURE subspace_eigenvalues_ks_fm
80 MODULE PROCEDURE subspace_eigenvalues_ks_dbcsr
84 MODULE PROCEDURE make_basis_sv_fm
85 MODULE PROCEDURE make_basis_sv_dbcsr
89 MODULE PROCEDURE complete_mo_basis_real
90 MODULE PROCEDURE complete_mo_basis_complex
102 SUBROUTINE complete_mo_basis_real(mo_coeff, nocc, nactive, matrix_s)
104 INTEGER,
INTENT(IN) :: nocc, nactive
107 CHARACTER(LEN=*),
PARAMETER :: routineN =
'complete_mo_basis_real'
109 INTEGER :: handle, imo, nao, pass
110 REAL(KIND=
dp),
ALLOCATABLE,
DIMENSION(:) :: column_norm
114 cpassert(nocc >= 0 .AND. nocc <= nactive)
115 cpassert(nactive <= mo_coeff%matrix_struct%ncol_global)
116 IF (nactive == nocc)
RETURN
118 CALL timeset(routinen, handle)
119 nao = mo_coeff%matrix_struct%nrow_global
120 cpassert(nactive <= nao)
121 NULLIFY (active_struct)
122 CALL cp_fm_struct_create(active_struct, template_fmstruct=mo_coeff%matrix_struct, ncol_global=nactive)
125 CALL cp_fm_create(gram, active_struct, nrow=nactive, ncol=nactive)
127 ALLOCATE (column_norm(nactive))
129 IF (any(column_norm(nocc + 1:nactive) <= empty_mo_norm))
THEN
131 DO imo = nocc + 1, nactive
132 IF (column_norm(imo) > empty_mo_norm) cycle
133 CALL cp_fm_to_fm(s_coeff, coeff, 1, source_start=imo, target_start=imo)
136 DEALLOCATE (column_norm)
141 IF (
ASSOCIATED(matrix_s))
THEN
146 CALL parallel_gemm(
'T',
'N', nactive, nactive, nao, 1.0_dp, coeff, s_coeff, 0.0_dp, gram)
150 CALL cp_fm_to_fm(coeff, mo_coeff, nactive - nocc, source_start=nocc + 1, target_start=nocc + 1)
155 CALL timestop(handle)
156 END SUBROUTINE complete_mo_basis_real
165 SUBROUTINE complete_mo_basis_complex(mo_coeff, nocc, nactive, matrix_s)
167 INTEGER,
INTENT(IN) :: nocc, nactive
170 CHARACTER(LEN=*),
PARAMETER :: routineN =
'complete_mo_basis_complex'
172 INTEGER :: handle, imo, nao, pass
173 REAL(KIND=
dp),
ALLOCATABLE,
DIMENSION(:) :: column_norm
178 cpassert(nocc >= 0 .AND. nocc <= nactive)
179 cpassert(nactive <= mo_coeff%matrix_struct%ncol_global)
180 IF (nactive == nocc)
RETURN
182 CALL timeset(routinen, handle)
183 nao = mo_coeff%matrix_struct%nrow_global
184 cpassert(nactive <= nao)
185 NULLIFY (active_struct)
186 CALL cp_fm_struct_create(active_struct, template_fmstruct=mo_coeff%matrix_struct, ncol_global=nactive)
189 CALL cp_cfm_create(gram, active_struct, nrow=nactive, ncol=nactive)
191 ALLOCATE (column_norm(nactive))
193 IF (any(column_norm(nocc + 1:nactive) <= empty_mo_norm))
THEN
194 CALL cp_fm_create(random_coeff, active_struct, set_zero=.true.)
196 CALL cp_fm_to_cfm(msourcer=random_coeff, mtarget=s_coeff)
198 DO imo = nocc + 1, nactive
199 IF (column_norm(imo) > empty_mo_norm) cycle
200 CALL cp_cfm_to_cfm(s_coeff, coeff, 1, source_start=imo, target_start=imo)
203 DEALLOCATE (column_norm)
213 CALL cp_cfm_to_cfm(coeff, mo_coeff, nactive - nocc, source_start=nocc + 1, target_start=nocc + 1)
218 CALL timestop(handle)
219 END SUBROUTINE complete_mo_basis_complex
231 INTEGER,
INTENT(IN) :: ncol
234 CHARACTER(LEN=*),
PARAMETER :: routinen =
'make_basis_sm'
235 REAL(kind=
dp),
PARAMETER :: rone = 1.0_dp, rzero = 0.0_dp
237 INTEGER :: handle, n, ncol_global
241 IF (ncol == 0)
RETURN
243 CALL timeset(routinen, handle)
245 CALL cp_fm_get_info(matrix=vmatrix, nrow_global=n, ncol_global=ncol_global)
246 IF (ncol > ncol_global) cpabort(
"Wrong ncol value")
248 CALL cp_fm_create(svmatrix, vmatrix%matrix_struct,
"SV", set_zero=.true.)
251 NULLIFY (fm_struct_tmp)
253 para_env=vmatrix%matrix_struct%para_env, &
254 context=vmatrix%matrix_struct%context)
255 CALL cp_fm_create(overlap_vv, fm_struct_tmp,
"overlap_vv")
258 CALL parallel_gemm(
'T',
'N', ncol, ncol, n, rone, vmatrix, svmatrix, rzero, overlap_vv)
265 CALL timestop(handle)
277 SUBROUTINE make_basis_sv_fm(vmatrix, ncol, svmatrix)
280 INTEGER,
INTENT(IN) :: ncol
283 CHARACTER(LEN=*),
PARAMETER :: routineN =
'make_basis_sv_fm'
284 REAL(KIND=
dp),
PARAMETER :: rone = 1.0_dp, rzero = 0.0_dp
286 INTEGER :: handle, n, ncol_global
290 IF (ncol == 0)
RETURN
292 CALL timeset(routinen, handle)
293 NULLIFY (fm_struct_tmp)
295 CALL cp_fm_get_info(matrix=vmatrix, nrow_global=n, ncol_global=ncol_global)
296 IF (ncol > ncol_global) cpabort(
"Wrong ncol value")
299 para_env=vmatrix%matrix_struct%para_env, &
300 context=vmatrix%matrix_struct%context)
301 CALL cp_fm_create(overlap_vv, fm_struct_tmp,
"overlap_vv")
304 CALL parallel_gemm(
'T',
'N', ncol, ncol, n, rone, vmatrix, svmatrix, rzero, overlap_vv)
311 CALL timestop(handle)
313 END SUBROUTINE make_basis_sv_fm
323 SUBROUTINE make_basis_sv_dbcsr(vmatrix, ncol, svmatrix, para_env, blacs_env)
326 INTEGER,
INTENT(IN) :: ncol
331 CHARACTER(LEN=*),
PARAMETER :: routineN =
'make_basis_sv_dbcsr'
332 REAL(KIND=
dp),
PARAMETER :: rone = 1.0_dp, rzero = 0.0_dp
334 INTEGER :: handle, n, ncol_global
336 TYPE(
cp_fm_type) :: fm_svmatrix, fm_vmatrix, overlap_vv
338 IF (ncol == 0)
RETURN
340 CALL timeset(routinen, handle)
343 CALL dbcsr_get_info(vmatrix, nfullrows_total=n, nfullcols_total=ncol_global)
344 IF (ncol > ncol_global) cpabort(
"Wrong ncol value")
347 ncol_global=ncol, para_env=para_env)
348 CALL cp_fm_create(overlap_vv, fm_struct_tmp, name=
"fm_overlap_vv")
352 ncol_global=ncol_global, para_env=para_env)
353 CALL cp_fm_create(fm_vmatrix, fm_struct_tmp, name=
"fm_vmatrix")
354 CALL cp_fm_create(fm_svmatrix, fm_struct_tmp, name=
"fm_svmatrix")
360 CALL parallel_gemm(
'T',
'N', ncol, ncol, n, rone, fm_vmatrix, fm_svmatrix, rzero, overlap_vv)
372 CALL timestop(handle)
374 END SUBROUTINE make_basis_sv_dbcsr
392 INTEGER,
INTENT(IN) :: ncol
395 CHARACTER(LEN=*),
PARAMETER :: routinen =
'make_basis_cholesky'
396 REAL(kind=
dp),
PARAMETER :: rone = 1.0_dp, rzero = 0.0_dp
398 INTEGER :: handle, n, ncol_global
402 IF (ncol == 0)
RETURN
404 CALL timeset(routinen, handle)
405 NULLIFY (fm_struct_tmp)
407 CALL cp_fm_get_info(matrix=vmatrix, nrow_global=n, ncol_global=ncol_global)
408 IF (ncol > ncol_global) cpabort(
"Wrong ncol value")
411 para_env=vmatrix%matrix_struct%para_env, &
412 context=vmatrix%matrix_struct%context)
413 CALL cp_fm_create(overlap_vv, fm_struct_tmp,
"overlap_vv")
417 CALL cp_fm_syrk(
'U',
'T', n, rone, vmatrix, 1, 1, rzero, overlap_vv)
424 CALL timestop(handle)
443 INTEGER,
INTENT(IN) :: ncol
446 CHARACTER(LEN=*),
PARAMETER :: routinen =
'make_basis_lowdin'
447 REAL(kind=
dp),
PARAMETER :: rone = 1.0_dp, rzero = 0.0_dp
449 INTEGER :: handle, n, ncol_global, ndep
450 REAL(
dp) :: threshold
454 IF (ncol == 0)
RETURN
456 CALL timeset(routinen, handle)
457 NULLIFY (fm_struct_tmp)
458 threshold = 1.0e-7_dp
459 CALL cp_fm_get_info(matrix=vmatrix, nrow_global=n, ncol_global=ncol_global)
460 IF (ncol > ncol_global) cpabort(
"Wrong ncol value")
465 NULLIFY (fm_struct_tmp)
467 para_env=vmatrix%matrix_struct%para_env, &
468 context=vmatrix%matrix_struct%context)
475 CALL parallel_gemm(
'T',
'N', ncol, ncol, n, rone, vmatrix, sc, rzero, csc)
476 CALL cp_fm_power(csc, work, -0.5_dp, threshold, ndep)
477 CALL parallel_gemm(
'N',
'N', n, ncol, ncol, rone, vmatrix, csc, rzero, sc)
484 CALL timestop(handle)
499 INTEGER,
INTENT(IN) :: ncol
501 CHARACTER(LEN=*),
PARAMETER :: routinen =
'make_basis_simple'
502 REAL(kind=
dp),
PARAMETER :: rone = 1.0_dp, rzero = 0.0_dp
504 INTEGER :: handle, n, ncol_global
508 IF (ncol == 0)
RETURN
510 CALL timeset(routinen, handle)
512 NULLIFY (fm_struct_tmp)
514 CALL cp_fm_get_info(matrix=vmatrix, nrow_global=n, ncol_global=ncol_global)
515 IF (ncol > ncol_global) cpabort(
"Wrong ncol value")
518 para_env=vmatrix%matrix_struct%para_env, &
519 context=vmatrix%matrix_struct%context)
520 CALL cp_fm_create(overlap_vv, fm_struct_tmp,
"overlap_vv")
523 CALL parallel_gemm(
'T',
'N', ncol, ncol, n, rone, vmatrix, vmatrix, rzero, overlap_vv)
529 CALL timestop(handle)
550 SUBROUTINE subspace_eigenvalues_ks_fm(orbitals, ks_matrix, evals_arg, ionode, scr, &
551 do_rotation, co_rotate, co_rotate_dbcsr)
555 REAL(KIND=
dp),
DIMENSION(:),
OPTIONAL :: evals_arg
556 LOGICAL,
INTENT(IN),
OPTIONAL :: ionode
557 INTEGER,
INTENT(IN),
OPTIONAL :: scr
558 LOGICAL,
INTENT(IN),
OPTIONAL :: do_rotation
559 TYPE(
cp_fm_type),
INTENT(IN),
OPTIONAL :: co_rotate
560 TYPE(
dbcsr_type),
OPTIONAL,
POINTER :: co_rotate_dbcsr
562 CHARACTER(LEN=*),
PARAMETER :: routineN =
'subspace_eigenvalues_ks_fm'
564 INTEGER :: handle, i, j, n, ncol_global, nrow_global
565 LOGICAL :: compute_evecs, do_rotation_local
566 REAL(KIND=
dp),
ALLOCATABLE,
DIMENSION(:) :: evals
568 TYPE(
cp_fm_type) :: e_vectors, h_block, weighted_vectors, &
571 CALL timeset(routinen, handle)
573 do_rotation_local = .true.
574 IF (
PRESENT(do_rotation)) do_rotation_local = do_rotation
576 NULLIFY (fm_struct_tmp)
578 ncol_global=ncol_global, &
579 nrow_global=nrow_global)
581 IF (do_rotation_local)
THEN
582 compute_evecs = .true.
585 compute_evecs = .false.
587 compute_evecs = .true.
590 IF (ncol_global > 0)
THEN
592 ALLOCATE (evals(ncol_global))
594 CALL cp_fm_create(weighted_vectors, orbitals%matrix_struct,
"weighted_vectors")
595 CALL cp_fm_struct_create(fm_struct_tmp, nrow_global=ncol_global, ncol_global=ncol_global, &
596 para_env=orbitals%matrix_struct%para_env, &
597 context=orbitals%matrix_struct%context)
598 CALL cp_fm_create(h_block, fm_struct_tmp, name=
"h block")
599 IF (compute_evecs)
THEN
600 CALL cp_fm_create(e_vectors, fm_struct_tmp, name=
"e vectors")
607 CALL parallel_gemm(
'T',
'N', ncol_global, ncol_global, nrow_global, 1.0_dp, &
608 orbitals, weighted_vectors, 0.0_dp, h_block)
611 IF (compute_evecs)
THEN
618 IF (do_rotation_local)
THEN
619 CALL parallel_gemm(
'N',
'N', nrow_global, ncol_global, ncol_global, 1.0_dp, &
620 orbitals, e_vectors, 0.0_dp, weighted_vectors)
622 IF (
PRESENT(co_rotate))
THEN
623 CALL parallel_gemm(
'N',
'N', nrow_global, ncol_global, ncol_global, 1.0_dp, &
624 co_rotate, e_vectors, 0.0_dp, weighted_vectors)
627 IF (
PRESENT(co_rotate_dbcsr))
THEN
628 IF (
ASSOCIATED(co_rotate_dbcsr))
THEN
629 CALL cp_fm_create(weighted_vectors2, orbitals%matrix_struct,
"weighted_vectors")
631 CALL parallel_gemm(
'N',
'N', nrow_global, ncol_global, ncol_global, 1.0_dp, &
632 weighted_vectors2, e_vectors, 0.0_dp, weighted_vectors)
640 IF (
PRESENT(evals_arg))
THEN
641 n = min(
SIZE(evals_arg),
SIZE(evals))
642 evals_arg(1:n) = evals(1:n)
645 IF (
PRESENT(ionode) .OR.
PRESENT(scr))
THEN
646 IF (.NOT.
PRESENT(ionode)) cpabort(
"IONODE?")
647 IF (.NOT.
PRESENT(scr)) cpabort(
"SCR?")
649 DO i = 1, ncol_global, 4
650 j = min(3, ncol_global - i)
653 WRITE (scr,
'(1X,4F16.8)') evals(i:i + j)
655 WRITE (scr,
'(1X,3F16.8)') evals(i:i + j)
657 WRITE (scr,
'(1X,2F16.8)') evals(i:i + j)
659 WRITE (scr,
'(1X,1F16.8)') evals(i:i + j)
667 IF (compute_evecs)
THEN
675 CALL timestop(handle)
677 END SUBROUTINE subspace_eigenvalues_ks_fm
691 SUBROUTINE subspace_eigenvalues_ks_dbcsr(orbitals, ks_matrix, evals_arg, ionode, scr, &
692 do_rotation, co_rotate, para_env, blacs_env)
694 TYPE(
dbcsr_type),
POINTER :: orbitals, ks_matrix
695 REAL(KIND=
dp),
DIMENSION(:),
OPTIONAL :: evals_arg
696 LOGICAL,
INTENT(IN),
OPTIONAL :: ionode
697 INTEGER,
INTENT(IN),
OPTIONAL :: scr
698 LOGICAL,
INTENT(IN),
OPTIONAL :: do_rotation
699 TYPE(
dbcsr_type),
OPTIONAL,
POINTER :: co_rotate
703 CHARACTER(LEN=*),
PARAMETER :: routineN =
'subspace_eigenvalues_ks_dbcsr'
705 INTEGER :: handle, i, j, ncol_global, nrow_global
706 LOGICAL :: compute_evecs, do_rotation_local
707 REAL(KIND=
dp),
ALLOCATABLE,
DIMENSION(:) :: evals
708 TYPE(
dbcsr_type),
POINTER :: e_vectors, h_block, weighted_vectors
710 CALL timeset(routinen, handle)
712 do_rotation_local = .true.
713 IF (
PRESENT(do_rotation)) do_rotation_local = do_rotation
715 NULLIFY (e_vectors, h_block, weighted_vectors)
718 nfullcols_total=ncol_global, &
719 nfullrows_total=nrow_global)
721 IF (do_rotation_local)
THEN
722 compute_evecs = .true.
725 compute_evecs = .false.
727 compute_evecs = .true.
730 IF (ncol_global > 0)
THEN
732 ALLOCATE (evals(ncol_global))
735 CALL dbcsr_copy(weighted_vectors, orbitals, name=
"weighted_vectors")
739 sym=dbcsr_type_no_symmetry)
742 IF (compute_evecs)
THEN
745 sym=dbcsr_type_no_symmetry)
750 0.0_dp, weighted_vectors)
753 CALL dbcsr_multiply(
'T',
'N', 1.0_dp, orbitals, weighted_vectors, 0.0_dp, h_block)
758 IF (compute_evecs)
THEN
759 CALL cp_dbcsr_syevd(h_block, e_vectors, evals, para_env=para_env, blacs_env=blacs_env)
761 CALL cp_dbcsr_syevx(h_block, eigenvalues=evals, para_env=para_env, blacs_env=blacs_env)
765 IF (do_rotation_local)
THEN
766 CALL dbcsr_multiply(
'N',
'N', 1.0_dp, orbitals, e_vectors, 0.0_dp, weighted_vectors)
771 IF (
PRESENT(co_rotate))
THEN
772 IF (
ASSOCIATED(co_rotate))
THEN
773 CALL dbcsr_multiply(
'N',
'N', 1.0_dp, co_rotate, e_vectors, 0.0_dp, weighted_vectors)
783 IF (
PRESENT(evals_arg))
THEN
784 evals_arg(:) = evals(:)
787 IF (
PRESENT(ionode) .OR.
PRESENT(scr))
THEN
788 IF (.NOT.
PRESENT(ionode)) cpabort(
"IONODE?")
789 IF (.NOT.
PRESENT(scr)) cpabort(
"SCR?")
791 DO i = 1, ncol_global, 4
792 j = min(3, ncol_global - i)
795 WRITE (scr,
'(1X,4F16.8)') evals(i:i + j)
797 WRITE (scr,
'(1X,3F16.8)') evals(i:i + j)
799 WRITE (scr,
'(1X,2F16.8)') evals(i:i + j)
801 WRITE (scr,
'(1X,1F16.8)') evals(i:i + j)
809 IF (compute_evecs)
THEN
817 CALL timestop(handle)
819 END SUBROUTINE subspace_eigenvalues_ks_dbcsr
830 REAL(kind=
dp) :: orthonormality
831 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(IN) :: mo_array
832 TYPE(
dbcsr_type),
OPTIONAL,
POINTER :: matrix_s
834 CHARACTER(LEN=*),
PARAMETER :: routinen =
'calculate_orthonormality'
836 INTEGER :: handle, i, ispin, j, k, n, ncol_local, &
838 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
839 REAL(kind=
dp) :: alpha, max_alpha
843 NULLIFY (tmp_fm_struct)
845 CALL timeset(routinen, handle)
847 nspin =
SIZE(mo_array)
851 IF (
PRESENT(matrix_s))
THEN
853 CALL cp_fm_create(svec, mo_array(ispin)%mo_coeff%matrix_struct)
855 nrow_global=n, ncol_global=k)
860 para_env=mo_array(ispin)%mo_coeff%matrix_struct%para_env, &
861 context=mo_array(ispin)%mo_coeff%matrix_struct%context)
864 CALL parallel_gemm(
'T',
'N', k, k, n, 1.0_dp, mo_array(ispin)%mo_coeff, &
865 svec, 0.0_dp, overlap)
870 nrow_global=n, ncol_global=k)
872 para_env=mo_array(ispin)%mo_coeff%matrix_struct%para_env, &
873 context=mo_array(ispin)%mo_coeff%matrix_struct%context)
876 CALL parallel_gemm(
'T',
'N', k, k, n, 1.0_dp, mo_array(ispin)%mo_coeff, &
877 mo_array(ispin)%mo_coeff, 0.0_dp, overlap)
879 CALL cp_fm_get_info(overlap, nrow_local=nrow_local, ncol_local=ncol_local, &
880 row_indices=row_indices, col_indices=col_indices)
883 alpha = overlap%local_data(i, j)
884 IF (row_indices(i) == col_indices(j)) alpha = alpha - 1.0_dp
885 max_alpha = max(max_alpha, abs(alpha))
890 CALL mo_array(1)%mo_coeff%matrix_struct%para_env%max(max_alpha)
891 orthonormality = max_alpha
894 CALL timestop(handle)
909 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(IN) :: mo_array
910 REAL(kind=
dp) :: mo_mag_min, mo_mag_max
912 CHARACTER(LEN=*),
PARAMETER :: routinen =
'calculate_magnitude'
914 INTEGER :: handle, ispin, k, n, nspin
915 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: evals
919 NULLIFY (tmp_fm_struct)
921 CALL timeset(routinen, handle)
923 nspin =
SIZE(mo_array)
924 mo_mag_min = huge(0.0_dp)
925 mo_mag_max = -huge(0.0_dp)
928 nrow_global=n, ncol_global=k)
931 para_env=mo_array(ispin)%mo_coeff%matrix_struct%para_env, &
932 context=mo_array(ispin)%mo_coeff%matrix_struct%context)
936 CALL parallel_gemm(
'T',
'N', k, k, n, 1.0_dp, mo_array(ispin)%mo_coeff, &
937 mo_array(ispin)%mo_coeff, 0.0_dp, overlap)
939 mo_mag_min = min(minval(evals), mo_mag_min)
940 mo_mag_max = max(maxval(evals), mo_mag_max)
945 CALL timestop(handle)
963 SUBROUTINE make_mo_eig(mos, nspins, ks_rmpv, scf_control, mo_derivs, admm_env, &
966 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(INOUT) :: mos
967 INTEGER,
INTENT(IN) :: nspins
971 TYPE(
admm_type),
OPTIONAL,
POINTER :: admm_env
976 CHARACTER(LEN=*),
PARAMETER :: routinen =
'make_mo_eig'
978 INTEGER :: handle, homo, ispin, nmo, output_unit
979 REAL(kind=
dp),
DIMENSION(:),
POINTER :: mo_eigenvalues
983 CALL timeset(routinen, handle)
985 NULLIFY (mo_coeff_deriv, mo_coeff, mo_eigenvalues)
989 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, &
990 eigenvalues=mo_eigenvalues, homo=homo, nmo=nmo)
991 IF (output_unit > 0)
WRITE (output_unit, *)
" "
992 IF (output_unit > 0)
WRITE (output_unit, *)
" Eigenvalues of the occupied subspace spin ", ispin
996 IF (output_unit > 0)
WRITE (output_unit, *)
"---------------------------------------------"
998 IF (scf_control%use_ot .AND. &
999 .NOT. (any(scf_control%added_mos > 0) .AND. .NOT. scf_control%smear%do_smear))
THEN
1001 IF (
ASSOCIATED(mo_derivs))
THEN
1002 mo_coeff_deriv => mo_derivs(ispin)%matrix
1004 mo_coeff_deriv => null()
1008 IF (
PRESENT(admm_env))
THEN
1013 scr=output_unit, ionode=output_unit > 0, do_rotation=.true., &
1014 co_rotate_dbcsr=mo_coeff_deriv)
1017 IF (
PRESENT(admm_env))
THEN
1021 IF (output_unit > 0)
WRITE (output_unit,
'(4(1X,1F16.8))') mo_eigenvalues(1:homo)
1023 IF (.NOT. scf_control%diagonalization%mom)
THEN
1025 scf_control%smear%do_smear = .false.
1027 smear=scf_control%smear, &
1033 IF (output_unit > 0)
WRITE (output_unit,
'(T2,A,F12.6)') &
1034 "Fermi Energy [eV] :", mos(ispin)%mu*
evolt
1037 CALL timestop(handle)
1054 REAL(kind=
dp),
DIMENSION(:),
INTENT(OUT) :: orbital_energies
1055 REAL(kind=
dp),
INTENT(OUT) :: max_offdiag
1057 CHARACTER(LEN=*),
PARAMETER :: routinen =
'calculate_orbital_fock_elements'
1059 INTEGER :: handle, i, ncol_global, nrow_global
1060 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: fock
1062 TYPE(
cp_fm_type) :: h_block, weighted_vectors
1064 CALL timeset(routinen, handle)
1066 orbital_energies = 0.0_dp
1067 max_offdiag = 0.0_dp
1068 CALL cp_fm_get_info(matrix=orbitals, ncol_global=ncol_global, nrow_global=nrow_global)
1069 IF (ncol_global > 0)
THEN
1070 NULLIFY (fm_struct_tmp)
1071 CALL cp_fm_create(weighted_vectors, orbitals%matrix_struct,
"weighted_vectors")
1072 CALL cp_fm_struct_create(fm_struct_tmp, nrow_global=ncol_global, ncol_global=ncol_global, &
1073 para_env=orbitals%matrix_struct%para_env, &
1074 context=orbitals%matrix_struct%context)
1075 CALL cp_fm_create(h_block, fm_struct_tmp, name=
"h block")
1079 CALL parallel_gemm(
'T',
'N', ncol_global, ncol_global, nrow_global, 1.0_dp, &
1080 orbitals, weighted_vectors, 0.0_dp, h_block)
1082 ALLOCATE (fock(ncol_global, ncol_global))
1084 DO i = 1, min(ncol_global,
SIZE(orbital_energies))
1085 orbital_energies(i) = fock(i, i)
1087 DO i = 1, ncol_global
1090 max_offdiag = maxval(abs(fock))
1097 CALL timestop(handle)
1121 REAL(kind=
dp),
INTENT(IN) :: eps_canonical
1122 LOGICAL,
INTENT(OUT) :: rotated
1123 REAL(kind=
dp),
INTENT(OUT) :: max_offdiag
1124 TYPE(
dbcsr_type),
OPTIONAL,
POINTER :: mo_derivs
1126 CHARACTER(LEN=*),
PARAMETER :: routinen =
'make_mo_set_canonical'
1127 REAL(kind=
dp),
PARAMETER :: eps_occ = 1.0e-10_dp
1129 INTEGER :: first, handle, i, iblock, n, nmo, nocc, &
1131 LOGICAL :: do_derivs
1132 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: energies
1134 TYPE(
cp_fm_type) :: block_coeff, block_derivs, derivs
1136 CALL timeset(routinen, handle)
1140 IF (mo_set%use_mo_coeff_b)
CALL copy_dbcsr_to_fm(mo_set%mo_coeff_b, mo_set%mo_coeff)
1141 ALLOCATE (energies(nmo))
1143 DEALLOCATE (energies)
1145 IF (max_offdiag > eps_canonical .OR. eps_canonical <= 0.0_dp)
THEN
1147 IF (abs(mo_set%occupation_numbers(i)) > eps_occ .AND. &
1148 abs(mo_set%occupation_numbers(i) - mo_set%maxocc) > eps_occ)
THEN
1149 cpabort(
"Canonicalization of orbitals with fractional occupations is not possible")
1153 IF (
PRESENT(mo_derivs)) do_derivs =
ASSOCIATED(mo_derivs)
1155 nocc = count(mo_set%occupation_numbers(1:nmo) > eps_occ)
1156 CALL cp_fm_get_info(matrix=mo_set%mo_coeff, nrow_global=nrow_global)
1158 CALL cp_fm_create(derivs, mo_set%mo_coeff%matrix_struct, name=
"orbital derivatives")
1162 IF (iblock == 1)
THEN
1170 NULLIFY (fm_struct_tmp)
1172 template_fmstruct=mo_set%mo_coeff%matrix_struct)
1173 CALL cp_fm_create(block_coeff, fm_struct_tmp, name=
"canonicalized orbitals")
1174 CALL cp_fm_to_fm(mo_set%mo_coeff, block_coeff, n, first, 1)
1176 CALL cp_fm_create(block_derivs, fm_struct_tmp, name=
"rotated orbital derivatives")
1177 CALL cp_fm_to_fm(derivs, block_derivs, n, first, 1)
1179 evals_arg=mo_set%eigenvalues(first:first + n - 1), &
1180 do_rotation=.true., co_rotate=block_derivs)
1181 CALL cp_fm_to_fm(block_derivs, derivs, n, 1, first)
1185 evals_arg=mo_set%eigenvalues(first:first + n - 1), &
1189 CALL cp_fm_to_fm(block_coeff, mo_set%mo_coeff, n, 1, first)
1196 IF (mo_set%use_mo_coeff_b)
CALL copy_fm_to_dbcsr(mo_set%mo_coeff, mo_set%mo_coeff_b)
1200 CALL timestop(handle)
Types and set/get functions for auxiliary density matrix methods.
Contains methods used in the context of density fitting.
subroutine, public admm_uncorrect_for_eigenvalues(ispin, admm_env, ks_matrix)
...
subroutine, public admm_correct_for_eigenvalues(ispin, admm_env, ks_matrix)
...
methods related to the blacs parallel environment
Basic linear algebra operations for complex full matrices.
subroutine, public cp_cfm_vectorsnorm(matrix, norm_array, squared)
find the norm of each column norm_{j}= sqrt( \sum_{i} A_{ij}*conjg(A_{ij}) ) Complex-valued mirror of...
subroutine, public cp_cfm_triangular_multiply(triangular_matrix, matrix_b, side, transa_tr, invert_tr, uplo_tr, unit_diag_tr, n_rows, n_cols, alpha)
Multiplies in place by a triangular matrix: matrix_b = alpha op(triangular_matrix) matrix_b or (if si...
various cholesky decomposition related routines
subroutine, public cp_cfm_cholesky_decompose(matrix, n, info_out)
Used to replace a symmetric positive definite matrix M with its Cholesky decomposition U: M = U^T * U...
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_release(matrix)
Releases a full matrix.
subroutine, public cp_fm_to_cfm(msourcer, msourcei, mtarget)
Construct a complex full matrix by taking its real and imaginary parts from two separate real-value f...
subroutine, public cp_cfm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
Creates a new full matrix with the given structure.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_release_p(matrix)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_multiply(transa, transb, alpha, matrix_a, matrix_b, beta, matrix_c, first_row, last_row, first_column, last_column, first_k, last_k, retain_sparsity, filter_eps, flop)
...
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
subroutine, public dbcsr_init_p(matrix)
...
Interface to (sca)lapack for the Cholesky based procedures.
subroutine, public cp_dbcsr_syevx(matrix, eigenvectors, eigenvalues, neig, work_syevx, para_env, blacs_env)
compute eigenvalues and optionally eigenvectors of a real symmetric matrix using scalapack....
subroutine, public cp_dbcsr_syevd(matrix, eigenvectors, eigenvalues, para_env, blacs_env)
...
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, plan, check_plan)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public cp_dbcsr_m_by_n_from_template(matrix, template, m, n, sym)
Utility function to create an arbitrary shaped dbcsr matrix with the same processor grid as the templ...
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_syrk(uplo, trans, k, alpha, matrix_a, ia, ja, beta, matrix_c)
performs a rank-k update of a symmetric matrix_c matrix_c = beta * matrix_c + alpha * matrix_a * tran...
subroutine, public cp_fm_triangular_multiply(triangular_matrix, matrix_b, side, transpose_tr, invert_tr, uplo_tr, unit_diag_tr, n_rows, n_cols, alpha)
multiplies in place by a triangular matrix: matrix_b = alpha op(triangular_matrix) matrix_b or (if si...
various cholesky decomposition related routines
subroutine, public cp_fm_cholesky_decompose(matrix, n, info_out)
used to replace a symmetric positive def. matrix M with its cholesky decomposition U: M = U^T * U,...
used for collecting some of the diagonalization schemes available for cp_fm_type. cp_fm_power also mo...
subroutine, public cp_fm_power(matrix, work, exponent, threshold, n_dependent, verbose, eigvals)
...
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_syevx(matrix, eigenvectors, eigenvalues, neig, work_syevx)
compute eigenvalues and optionally eigenvectors of a real symmetric matrix using scalapack....
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
subroutine, public cp_fm_get_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_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
subroutine, public cp_fm_vectorsnorm(matrix, norm_array, squared)
find the norm of each column norm_{j}= sqrt( \sum_{i} A_{ij}*A_{ij} )
subroutine, public cp_fm_get_submatrix(fm, target_m, start_row, start_col, n_rows, n_cols, transpose)
gets a submatrix of a full matrix op(target_m)(1:n_rows,1:n_cols) =fm(start_row:start_row+n_rows,...
subroutine, public cp_fm_init_random(matrix, ncol, start_col)
fills a matrix with random numbers
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
Defines the basic variable types.
integer, parameter, public dp
Definition of mathematical constants and functions.
complex(kind=dp), parameter, public z_one
complex(kind=dp), parameter, public z_zero
Interface to the message passing library MPI.
basic linear algebra operations for full matrixes
Definition of physical constants:
real(kind=dp), parameter, public evolt
collects routines that perform operations directly related to MOs
subroutine, public make_basis_simple(vmatrix, ncol)
given a set of vectors, return an orthogonal (C^T C == 1) set spanning the same space (notice,...
subroutine, public make_basis_lowdin(vmatrix, ncol, matrix_s)
return a set of S orthonormal vectors (C^T S C == 1) where a Loedwin transformation is applied to kee...
subroutine, public make_basis_cholesky(vmatrix, ncol, ortho)
return a set of S orthonormal vectors (C^T S C == 1) where the cholesky decomposed form of S is passe...
subroutine, public calculate_magnitude(mo_array, mo_mag_min, mo_mag_max)
...
subroutine, public make_mo_set_canonical(mo_set, ks_matrix, eps_canonical, rotated, max_offdiag, mo_derivs)
Rotates the orbitals of an MO set into canonical orbitals (eigenvectors of the Fock matrix in the spa...
subroutine, public calculate_orbital_fock_elements(orbitals, ks_matrix, orbital_energies, max_offdiag)
Orbital energies <phi_i|F|phi_i> of a set of orbitals and the largest off-diagonal Fock matrix elemen...
subroutine, public make_basis_sm(vmatrix, ncol, matrix_s)
returns an S-orthonormal basis v (v^T S v ==1)
subroutine, public make_mo_eig(mos, nspins, ks_rmpv, scf_control, mo_derivs, admm_env, hairy_probes, probe)
Calculate KS eigenvalues starting from OF MOS.
subroutine, public calculate_orthonormality(orthonormality, mo_array, matrix_s)
...
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, cmo_coeff)
Get the components of a MO set data structure.
parameters that control an scf iteration
stores some data used in wavefunction fitting
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
Represent a complex full matrix.
keeps the information about the structure of a full matrix
stores all the informations relevant to an mpi environment