89#include "./base/base_uses.f90"
97 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_loc_utils'
113 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: mo_loc_history
114 TYPE(
cp_fm_type),
DIMENSION(:),
INTENT(IN) :: mo_loc
116 CHARACTER(len=*),
PARAMETER :: routinen =
'retain_history'
118 INTEGER :: handle, i, ncol_hist, ncol_loc
120 CALL timeset(routinen, handle)
122 IF (.NOT.
ASSOCIATED(mo_loc_history))
THEN
123 ALLOCATE (mo_loc_history(
SIZE(mo_loc)))
124 DO i = 1,
SIZE(mo_loc_history)
125 CALL cp_fm_create(mo_loc_history(i), mo_loc(i)%matrix_struct)
129 DO i = 1,
SIZE(mo_loc_history)
132 cpassert(ncol_hist == ncol_loc)
136 CALL timestop(handle)
147 SUBROUTINE rotate_state_to_ref(mo_new, mo_ref, matrix_S)
149 TYPE(
cp_fm_type),
INTENT(IN) :: mo_new, mo_ref
152 CHARACTER(len=*),
PARAMETER :: routinen =
'rotate_state_to_ref'
154 INTEGER :: handle, ncol, ncol_ref, nrow
155 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigenvalues
159 CALL timeset(routinen, handle)
163 cpassert(ncol == ncol_ref)
165 NULLIFY (fm_struct_tmp)
169 ncol_global=ncol, para_env=mo_new%matrix_struct%para_env, &
170 context=mo_new%matrix_struct%context)
179 CALL parallel_gemm(
'T',
'N', ncol, ncol, nrow, 1.0_dp, mo_new, smo, 0.0_dp, o1)
182 CALL parallel_gemm(
'T',
'N', ncol, ncol, ncol, 1.0_dp, o1, o1, 0.0_dp, o2)
185 ALLOCATE (eigenvalues(ncol))
188 eigenvalues(:) = 1.0_dp/sqrt(eigenvalues(:))
190 CALL parallel_gemm(
'N',
'T', ncol, ncol, ncol, 1.0_dp, o3, o4, 0.0_dp, o2)
193 CALL parallel_gemm(
'N',
'N', ncol, ncol, ncol, 1.0_dp, o1, o2, 0.0_dp, o3)
196 CALL parallel_gemm(
'N',
'N', nrow, ncol, ncol, 1.0_dp, mo_new, o3, 0.0_dp, smo)
211 CALL timestop(handle)
213 END SUBROUTINE rotate_state_to_ref
230 SUBROUTINE qs_loc_env_init(qs_loc_env, localized_wfn_control, qs_env, myspin, do_localize, &
231 loc_coeff, mo_loc_history)
236 INTEGER,
INTENT(IN),
OPTIONAL :: myspin
237 LOGICAL,
INTENT(IN),
OPTIONAL :: do_localize
239 OPTIONAL :: loc_coeff
240 TYPE(
cp_fm_type),
DIMENSION(:),
OPTIONAL,
POINTER :: mo_loc_history
242 CHARACTER(len=*),
PARAMETER :: routinen =
'qs_loc_env_init'
244 INTEGER :: dim_op, handle, i, iatom, imo, imoloc, &
245 ispin, j, l_spin, lb, nao, naosub, &
246 natoms, nmo, nmosub, nspins, s_spin, ub
247 REAL(kind=
dp) :: my_occ, occ_imo
248 REAL(kind=
dp),
DIMENSION(:),
POINTER :: occupations
249 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: vecbuffer
252 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: moloc_coeff
253 TYPE(
cp_fm_type),
POINTER :: mat_ptr, mo_coeff
260 CALL timeset(routinen, handle)
262 NULLIFY (mos, matrix_s, moloc_coeff, particle_set, para_env, cell, local_molecules, occupations, mat_ptr)
263 IF (
PRESENT(do_localize)) qs_loc_env%do_localize = do_localize
264 IF (qs_loc_env%do_localize)
THEN
265 CALL get_qs_env(qs_env=qs_env, matrix_s=matrix_s, cell=cell, &
266 local_molecules=local_molecules, particle_set=particle_set, &
267 para_env=para_env, mos=mos)
268 nspins =
SIZE(mos, 1)
271 IF (
PRESENT(myspin))
THEN
275 ALLOCATE (moloc_coeff(s_spin:l_spin))
276 DO ispin = s_spin, l_spin
277 NULLIFY (tmp_fm_struct, mo_coeff)
278 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, nao=nao, nmo=nmo)
279 nmosub = localized_wfn_control%nloc_states(ispin)
281 ncol_global=nmosub, para_env=para_env, context=mo_coeff%matrix_struct%context)
286 cpassert(nao == naosub)
287 IF ((localized_wfn_control%do_homo) .OR. &
289 cpassert(nmo >= nmosub)
291 cpassert(nao - nmo >= nmosub)
298 IF (
PRESENT(loc_coeff))
ALLOCATE (mat_ptr)
300 DO ispin = s_spin, l_spin
301 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, &
302 occupation_numbers=occupations, nao=nao, nmo=nmo)
303 lb = localized_wfn_control%lu_bound_states(1, ispin)
304 ub = localized_wfn_control%lu_bound_states(2, ispin)
306 IF (
PRESENT(loc_coeff))
THEN
307 mat_ptr = loc_coeff(ispin)
311 IF ((localized_wfn_control%set_of_states ==
state_loc_list) .OR. &
313 ALLOCATE (vecbuffer(1, nao))
314 IF (localized_wfn_control%do_homo)
THEN
315 my_occ = occupations(localized_wfn_control%loc_states(1, ispin))
317 nmosub =
SIZE(localized_wfn_control%loc_states, 1)
324 imo = localized_wfn_control%loc_states(i, ispin)
325 IF (localized_wfn_control%do_homo)
THEN
326 occ_imo = occupations(imo)
327 IF (abs(occ_imo - my_occ) > localized_wfn_control%eps_occ)
THEN
328 IF (localized_wfn_control%localization_method /=
do_loc_none) &
329 CALL cp_abort(__location__, &
330 "States with different occupations "// &
331 "cannot be rotated together")
336 nao, 1, transpose=.true.)
338 nao, 1, transpose=.true.)
340 DEALLOCATE (vecbuffer)
342 my_occ = occupations(lb)
343 occ_imo = occupations(ub)
344 IF (abs(occ_imo - my_occ) > localized_wfn_control%eps_occ)
THEN
345 IF (localized_wfn_control%localization_method /=
do_loc_none) &
346 CALL cp_abort(__location__, &
347 "States with different occupations "// &
348 "cannot be rotated together")
350 nmosub = localized_wfn_control%nloc_states(ispin)
351 CALL cp_fm_to_fm(mat_ptr, moloc_coeff(ispin), nmosub, lb, 1)
356 IF (
PRESENT(mo_loc_history))
THEN
357 IF (localized_wfn_control%use_history .AND.
ASSOCIATED(mo_loc_history))
THEN
358 CALL rotate_state_to_ref(moloc_coeff(ispin), &
359 mo_loc_history(ispin), matrix_s(1)%matrix)
365 IF (
PRESENT(loc_coeff))
DEALLOCATE (mat_ptr)
367 CALL set_qs_loc_env(qs_loc_env=qs_loc_env, cell=cell, local_molecules=local_molecules, &
368 moloc_coeff=moloc_coeff, particle_set=particle_set, para_env=para_env, &
369 localized_wfn_control=localized_wfn_control)
372 NULLIFY (tmp_fm_struct, mo_coeff)
373 nmosub = maxval(localized_wfn_control%nloc_states)
376 ncol_global=nmosub, para_env=para_env, context=mo_coeff%matrix_struct%context)
378 IF (localized_wfn_control%operator_type ==
op_loc_berry)
THEN
379 IF (qs_loc_env%cell%orthorhombic)
THEN
385 ALLOCATE (qs_loc_env%op_sm_set(2, dim_op))
387 DO j = 1,
SIZE(qs_loc_env%op_sm_set, 1)
388 NULLIFY (qs_loc_env%op_sm_set(j, i)%matrix)
389 ALLOCATE (qs_loc_env%op_sm_set(j, i)%matrix)
390 CALL dbcsr_copy(qs_loc_env%op_sm_set(j, i)%matrix, matrix_s(1)%matrix, &
392 CALL dbcsr_set(qs_loc_env%op_sm_set(j, i)%matrix, 0.0_dp)
396 ELSEIF (localized_wfn_control%operator_type ==
op_loc_pipek)
THEN
397 natoms =
SIZE(qs_loc_env%particle_set, 1)
398 ALLOCATE (qs_loc_env%op_fm_set(natoms, 1))
400 DO ispin = 1,
SIZE(qs_loc_env%op_fm_set, 2)
403 CALL cp_fm_create(qs_loc_env%op_fm_set(iatom, ispin), tmp_fm_struct)
405 CALL cp_fm_get_info(qs_loc_env%op_fm_set(iatom, ispin), nrow_global=nmosub)
406 cpassert(nmo >= nmosub)
407 CALL cp_fm_set_all(qs_loc_env%op_fm_set(iatom, ispin), 0.0_dp)
411 cpabort(
"Type of operator not implemented")
415 IF (localized_wfn_control%operator_type ==
op_loc_berry)
THEN
419 CALL get_berry_operator(qs_loc_env, qs_env)
421 ELSEIF (localized_wfn_control%operator_type ==
op_loc_pipek)
THEN
428 qs_loc_env%molecular_states = .false.
429 qs_loc_env%wannier_states = .false.
431 CALL timestop(handle)
444 SUBROUTINE get_berry_operator(qs_loc_env, qs_env)
448 CHARACTER(len=*),
PARAMETER :: routinen =
'get_berry_operator'
450 INTEGER :: dim_op, handle
452 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: op_sm_set
454 CALL timeset(routinen, handle)
456 NULLIFY (cell, op_sm_set)
458 cell=cell, dim_op=dim_op)
461 CALL timestop(handle)
462 END SUBROUTINE get_berry_operator
487 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: op_sm_set
490 CHARACTER(len=*),
PARAMETER :: routinen =
'compute_berry_operator'
492 INTEGER :: handle, i, iatom, icol, ikind, inode, irow, iset, jatom, jkind, jset, last_jatom, &
493 ldab, ldsa, ldsb, ldwork, maxl, ncoa, ncob, nkind, nrow, nseta, nsetb, sgfa, sgfb
494 INTEGER,
DIMENSION(3) :: perd0
495 INTEGER,
DIMENSION(:),
POINTER :: la_max, la_min, lb_max, lb_min, npgfa, &
497 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgfa, first_sgfb
498 LOGICAL :: found, new_atom_b
499 REAL(kind=
dp) :: dab, kvec(3), rab2, vector_k(3, 6)
500 REAL(kind=
dp),
DIMENSION(3) :: ra, rab, rb
501 REAL(kind=
dp),
DIMENSION(:),
POINTER :: set_radius_a, set_radius_b
502 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: cosab, rpgfa, rpgfb, sinab, sphi_a, &
503 sphi_b, work, zeta, zetb
504 TYPE(
block_p_type),
DIMENSION(:),
POINTER :: op_cos, op_sin
508 DIMENSION(:),
POINTER :: nl_iterator
512 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
515 CALL timeset(routinen, handle)
516 NULLIFY (qs_kind, qs_kind_set)
517 NULLIFY (particle_set)
519 NULLIFY (cosab, sinab, work)
520 NULLIFY (la_max, la_min, lb_max, lb_min, npgfa, npgfb, nsgfa, nsgfb)
521 NULLIFY (set_radius_a, set_radius_b, rpgfa, rpgfb, sphi_a, sphi_b, zeta, zetb)
523 CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set, &
524 particle_set=particle_set, sab_orb=sab_orb)
526 nkind =
SIZE(qs_kind_set)
529 maxco=ldwork, maxlgto=maxl)
531 ALLOCATE (cosab(ldab, ldab))
533 ALLOCATE (sinab(ldab, ldab))
535 ALLOCATE (work(ldwork, ldwork))
538 ALLOCATE (op_cos(dim_op))
539 ALLOCATE (op_sin(dim_op))
541 NULLIFY (op_cos(i)%block)
542 NULLIFY (op_sin(i)%block)
547 vector_k(:, 1) =
twopi*cell%h_inv(1, :)
548 vector_k(:, 2) =
twopi*cell%h_inv(2, :)
549 vector_k(:, 3) =
twopi*cell%h_inv(3, :)
550 vector_k(:, 4) =
twopi*(cell%h_inv(1, :) + cell%h_inv(2, :))
551 vector_k(:, 5) =
twopi*(cell%h_inv(1, :) + cell%h_inv(3, :))
552 vector_k(:, 6) =
twopi*(cell%h_inv(2, :) + cell%h_inv(3, :))
556 perd0(1:3) = cell%perd(1:3)
559 ALLOCATE (basis_set_list(nkind))
561 qs_kind => qs_kind_set(ikind)
562 CALL get_qs_kind(qs_kind=qs_kind, basis_set=basis_set_a)
563 IF (
ASSOCIATED(basis_set_a))
THEN
564 basis_set_list(ikind)%gto_basis_set => basis_set_a
566 NULLIFY (basis_set_list(ikind)%gto_basis_set)
572 iatom=iatom, jatom=jatom, r=rab)
573 basis_set_a => basis_set_list(ikind)%gto_basis_set
574 IF (.NOT.
ASSOCIATED(basis_set_a)) cycle
575 basis_set_b => basis_set_list(jkind)%gto_basis_set
576 IF (.NOT.
ASSOCIATED(basis_set_b)) cycle
577 ra =
pbc(particle_set(iatom)%r, cell)
579 first_sgfa => basis_set_a%first_sgf
580 la_max => basis_set_a%lmax
581 la_min => basis_set_a%lmin
582 npgfa => basis_set_a%npgf
583 nseta = basis_set_a%nset
584 nsgfa => basis_set_a%nsgf_set
585 rpgfa => basis_set_a%pgf_radius
586 set_radius_a => basis_set_a%set_radius
587 sphi_a => basis_set_a%sphi
588 zeta => basis_set_a%zet
590 first_sgfb => basis_set_b%first_sgf
591 lb_max => basis_set_b%lmax
592 lb_min => basis_set_b%lmin
593 npgfb => basis_set_b%npgf
594 nsetb = basis_set_b%nset
595 nsgfb => basis_set_b%nsgf_set
596 rpgfb => basis_set_b%pgf_radius
597 set_radius_b => basis_set_b%set_radius
598 sphi_b => basis_set_b%sphi
599 zetb => basis_set_b%zet
601 ldsa =
SIZE(sphi_a, 1)
602 ldsb =
SIZE(sphi_b, 1)
603 IF (inode == 1) last_jatom = 0
607 IF (jatom /= last_jatom)
THEN
615 IF (iatom <= jatom)
THEN
624 NULLIFY (op_cos(i)%block)
626 row=irow, col=icol, block=op_cos(i)%block, found=found)
627 NULLIFY (op_sin(i)%block)
629 row=irow, col=icol, block=op_sin(i)%block, found=found)
633 rab2 = rab(1)*rab(1) + rab(2)*rab(2) + rab(3)*rab(3)
639 ncoa = npgfa(iset)*
ncoset(la_max(iset))
640 sgfa = first_sgfa(1, iset)
644 ncob = npgfb(jset)*
ncoset(lb_max(jset))
645 sgfb = first_sgfb(1, jset)
647 IF (set_radius_a(iset) + set_radius_b(jset) >= dab)
THEN
651 kvec(1:3) = vector_k(1:3, i)
654 CALL cossin(la_max(iset), npgfa(iset), zeta(:, iset), rpgfa(:, iset), &
655 la_min(iset), lb_max(jset), npgfb(jset), zetb(:, jset), &
656 rpgfb(:, jset), lb_min(jset), &
657 ra, rb, kvec, cosab, sinab)
659 iatom, ncoa, nsgfa(iset), sgfa, sphi_a, ldsa, &
660 jatom, ncob, nsgfb(jset), sgfb, sphi_b, ldsb, &
661 cosab, sinab, ldab, work, ldwork)
676 cell%perd(1:3) = perd0(1:3)
679 NULLIFY (op_cos(i)%block)
680 NULLIFY (op_sin(i)%block)
682 DEALLOCATE (op_cos, op_sin)
684 DEALLOCATE (cosab, sinab, work, basis_set_list)
686 CALL timestop(handle)
700 do_homo, evals, do_mixed)
703 TYPE(
mo_set_type),
DIMENSION(:),
POINTER :: mo_array
704 TYPE(
cp_fm_type),
DIMENSION(:),
INTENT(IN) :: coeff_localized
705 LOGICAL,
INTENT(IN) :: do_homo
708 LOGICAL,
INTENT(IN),
OPTIONAL ::
do_mixed
710 CHARACTER(LEN=*),
PARAMETER :: routinen =
'loc_write_restart'
712 CHARACTER(LEN=default_path_length) :: filename
713 CHARACTER(LEN=default_string_length) :: my_middle
714 INTEGER :: handle, ispin, max_block, nao, nloc, &
715 nmo, output_unit, rst_unit
716 LOGICAL :: my_do_mixed
720 CALL timeset(routinen, handle)
725 IF (qs_loc_env%do_localize)
THEN
729 section,
"LOC_RESTART"), &
735 my_do_mixed = .false.
738 my_middle =
"LOC_HOMO"
739 ELSEIF (my_do_mixed)
THEN
740 my_middle =
"LOC_MIXED"
742 my_middle =
"LOC_LUMO"
746 extension=
".wfn", file_status=
"REPLACE", file_action=
"WRITE", &
747 file_form=
"UNFORMATTED", middle_name=trim(my_middle))
750 middle_name=trim(my_middle), extension=
".wfn", &
753 IF (output_unit > 0)
THEN
754 WRITE (unit=output_unit, fmt=
"(/,T2,A, A/)") &
755 "LOCALIZATION| Write restart file for the localized MOS : ", &
759 IF (rst_unit > 0)
THEN
760 WRITE (rst_unit) qs_loc_env%localized_wfn_control%set_of_states
761 WRITE (rst_unit) qs_loc_env%localized_wfn_control%lu_bound_states
762 WRITE (rst_unit) qs_loc_env%localized_wfn_control%nloc_states
765 DO ispin = 1,
SIZE(coeff_localized)
766 associate(mo_coeff => coeff_localized(ispin))
767 CALL cp_fm_get_info(mo_coeff, nrow_global=nao, ncol_global=nmo, ncol_block=max_block)
768 nloc = qs_loc_env%localized_wfn_control%nloc_states(ispin)
769 IF (rst_unit > 0)
THEN
770 WRITE (rst_unit) qs_loc_env%localized_wfn_control%loc_states(1:nloc, ispin)
771 IF (do_homo .OR. my_do_mixed)
THEN
772 WRITE (rst_unit) nmo, &
773 mo_array(ispin)%homo, &
774 mo_array(ispin)%lfomo, &
775 mo_array(ispin)%nelectron
776 WRITE (rst_unit) mo_array(ispin)%eigenvalues(1:nmo), &
777 mo_array(ispin)%occupation_numbers(1:nmo)
780 WRITE (rst_unit) evals(ispin)%array(1:nmo)
795 CALL timestop(handle)
812 SUBROUTINE loc_read_restart(qs_loc_env, mos, mos_localized, section, section2, para_env, &
813 do_homo, restart_found, evals, do_mixed)
815 TYPE(qs_loc_env_type),
POINTER :: qs_loc_env
816 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos
817 TYPE(cp_fm_type),
DIMENSION(:),
INTENT(INOUT) :: mos_localized
818 TYPE(section_vals_type),
POINTER :: section, section2
819 TYPE(mp_para_env_type),
POINTER :: para_env
820 LOGICAL,
INTENT(IN) :: do_homo
821 LOGICAL,
INTENT(INOUT) :: restart_found
822 TYPE(cp_1d_r_p_type),
DIMENSION(:),
OPTIONAL, &
824 LOGICAL,
INTENT(IN),
OPTIONAL :: do_mixed
826 CHARACTER(len=*),
PARAMETER :: routinen =
'loc_read_restart'
828 CHARACTER(LEN=25) :: fname_key
829 CHARACTER(LEN=default_path_length) :: filename
830 CHARACTER(LEN=default_string_length) :: my_middle
831 INTEGER :: handle, homo_read, i, ispin, lfomo_read, max_nloc, n_rep_val, nao, &
832 nelectron_read, nloc, nmo, nmo_read, nspin, output_unit, rst_unit
833 LOGICAL :: file_exists, my_do_mixed
834 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: eig_read, occ_read
835 REAL(kind=dp),
DIMENSION(:, :),
POINTER :: vecbuffer
836 TYPE(cp_logger_type),
POINTER :: logger
837 TYPE(section_vals_type),
POINTER :: print_key
839 CALL timeset(routinen, handle)
841 logger => cp_get_default_logger()
843 nspin =
SIZE(mos_localized)
847 output_unit = cp_print_key_unit_nr(logger, section2, &
848 "PROGRAM_RUN_INFO", extension=
".Log")
850 my_do_mixed = .false.
851 IF (
PRESENT(do_mixed)) my_do_mixed = do_mixed
853 fname_key =
"LOCHOMO_RESTART_FILE_NAME"
854 ELSEIF (my_do_mixed)
THEN
855 fname_key =
"LOCMIXD_RESTART_FILE_NAME"
857 fname_key =
"LOCLUMO_RESTART_FILE_NAME"
858 IF (.NOT.
PRESENT(evals)) &
859 cpabort(
"Missing argument to localize unoccupied states.")
862 file_exists = .false.
863 CALL section_vals_val_get(section, fname_key, n_rep_val=n_rep_val)
864 IF (n_rep_val > 0)
THEN
865 CALL section_vals_val_get(section, fname_key, c_val=filename)
868 print_key => section_vals_get_subs_vals(section2,
"LOC_RESTART")
870 my_middle =
"LOC_HOMO"
871 ELSEIF (my_do_mixed)
THEN
872 my_middle =
"LOC_MIXED"
874 my_middle =
"LOC_LUMO"
876 filename = cp_print_key_generate_filename(logger, print_key, &
877 middle_name=trim(my_middle), extension=
".wfn", &
881 IF (para_env%is_source())
INQUIRE (file=filename, exist=file_exists)
883 IF (file_exists)
THEN
884 IF (para_env%is_source())
THEN
885 CALL open_file(file_name=filename, &
886 file_action=
"READ", &
887 file_form=
"UNFORMATTED", &
889 unit_number=rst_unit)
891 READ (rst_unit) qs_loc_env%localized_wfn_control%set_of_states
892 READ (rst_unit) qs_loc_env%localized_wfn_control%lu_bound_states
893 READ (rst_unit) qs_loc_env%localized_wfn_control%nloc_states
896 IF (output_unit > 0)
WRITE (output_unit,
"(/,T10,A)") &
897 "Restart file not available filename=<"//trim(filename)//
'>'
899 CALL para_env%bcast(file_exists)
901 IF (file_exists)
THEN
902 restart_found = .true.
904 CALL para_env%bcast(qs_loc_env%localized_wfn_control%set_of_states)
905 CALL para_env%bcast(qs_loc_env%localized_wfn_control%lu_bound_states)
906 CALL para_env%bcast(qs_loc_env%localized_wfn_control%nloc_states)
908 max_nloc = maxval(qs_loc_env%localized_wfn_control%nloc_states(:))
910 ALLOCATE (vecbuffer(1, nao))
911 IF (
ASSOCIATED(qs_loc_env%localized_wfn_control%loc_states))
THEN
912 DEALLOCATE (qs_loc_env%localized_wfn_control%loc_states)
914 ALLOCATE (qs_loc_env%localized_wfn_control%loc_states(max_nloc, 2))
915 qs_loc_env%localized_wfn_control%loc_states = 0
918 IF (do_homo .OR. do_mixed)
THEN
921 nmo =
SIZE(evals(ispin)%array, 1)
923 IF (para_env%is_source() .AND. (nmo > 0))
THEN
924 nloc = qs_loc_env%localized_wfn_control%nloc_states(ispin)
925 READ (rst_unit) qs_loc_env%localized_wfn_control%loc_states(1:nloc, ispin)
926 IF (do_homo .OR. do_mixed)
THEN
927 READ (rst_unit) nmo_read, homo_read, lfomo_read, nelectron_read
928 ALLOCATE (eig_read(nmo_read), occ_read(nmo_read))
931 READ (rst_unit) eig_read(1:nmo_read), occ_read(1:nmo_read)
933 READ (rst_unit) nmo_read
934 ALLOCATE (eig_read(nmo_read))
936 READ (rst_unit) eig_read(1:nmo_read)
938 IF (nmo_read < nmo) &
939 CALL cp_warn(__location__, &
940 "The number of MOs on the restart unit is smaller than the number of "// &
941 "the allocated MOs. ")
942 IF (nmo_read > nmo) &
943 CALL cp_warn(__location__, &
944 "The number of MOs on the restart unit is greater than the number of "// &
945 "the allocated MOs. The read MO set will be truncated!")
947 nmo = min(nmo, nmo_read)
948 IF (do_homo .OR. do_mixed)
THEN
949 mos(ispin)%eigenvalues(1:nmo) = eig_read(1:nmo)
950 mos(ispin)%occupation_numbers(1:nmo) = occ_read(1:nmo)
951 DEALLOCATE (eig_read, occ_read)
953 evals(ispin)%array(1:nmo) = eig_read(1:nmo)
954 DEALLOCATE (eig_read)
958 IF (do_homo .OR. do_mixed)
THEN
959 CALL para_env%bcast(mos(ispin)%eigenvalues)
960 CALL para_env%bcast(mos(ispin)%occupation_numbers)
962 CALL para_env%bcast(evals(ispin)%array)
966 IF (para_env%is_source())
THEN
967 READ (rst_unit) vecbuffer
969 vecbuffer(1, :) = 0.0_dp
971 CALL para_env%bcast(vecbuffer)
972 CALL cp_fm_set_submatrix(mos_localized(ispin), &
973 vecbuffer, 1, i, nao, 1, transpose=.true.)
977 CALL para_env%bcast(qs_loc_env%localized_wfn_control%loc_states)
979 DEALLOCATE (vecbuffer)
984 IF (para_env%is_source())
THEN
985 IF (file_exists)
CALL close_file(unit_number=rst_unit)
988 CALL timestop(handle)
990 END SUBROUTINE loc_read_restart
1005 do_xas, nloc_xas, spin_xas)
1007 TYPE(qs_loc_env_type),
POINTER :: qs_loc_env
1008 TYPE(section_vals_type),
POINTER :: loc_section
1009 LOGICAL,
INTENT(IN) :: do_homo
1010 LOGICAL,
INTENT(IN),
OPTIONAL :: do_mixed, do_xas
1011 INTEGER,
INTENT(IN),
OPTIONAL :: nloc_xas, spin_xas
1013 LOGICAL :: my_do_mixed
1014 TYPE(localized_wfn_control_type),
POINTER :: localized_wfn_control
1016 NULLIFY (localized_wfn_control)
1018 IF (
PRESENT(do_mixed))
THEN
1019 my_do_mixed = do_mixed
1021 my_do_mixed = .false.
1023 CALL localized_wfn_control_create(localized_wfn_control)
1024 CALL set_qs_loc_env(qs_loc_env, localized_wfn_control=localized_wfn_control)
1025 CALL localized_wfn_control_release(localized_wfn_control)
1026 CALL get_qs_loc_env(qs_loc_env, localized_wfn_control=localized_wfn_control)
1027 localized_wfn_control%do_homo = do_homo
1028 localized_wfn_control%do_mixed = my_do_mixed
1029 CALL read_loc_section(localized_wfn_control, loc_section, qs_loc_env%do_localize, &
1030 my_do_mixed, do_xas, nloc_xas, spin_xas)
1047 SUBROUTINE qs_loc_init(qs_env, qs_loc_env, localize_section, mos_localized, &
1048 do_homo, do_mo_cubes, mo_loc_history, evals, &
1049 tot_zeff_corr, do_mixed)
1051 TYPE(qs_environment_type),
POINTER :: qs_env
1052 TYPE(qs_loc_env_type),
POINTER :: qs_loc_env
1053 TYPE(section_vals_type),
POINTER :: localize_section
1054 TYPE(cp_fm_type),
DIMENSION(:),
INTENT(INOUT) :: mos_localized
1055 LOGICAL,
OPTIONAL :: do_homo, do_mo_cubes
1056 TYPE(cp_fm_type),
DIMENSION(:),
OPTIONAL,
POINTER :: mo_loc_history
1057 TYPE(cp_1d_r_p_type),
DIMENSION(:),
OPTIONAL, &
1059 REAL(kind=dp),
INTENT(IN),
OPTIONAL :: tot_zeff_corr
1060 LOGICAL,
OPTIONAL :: do_mixed
1062 CHARACTER(len=*),
PARAMETER :: routinen =
'qs_loc_init'
1064 INTEGER :: handle, homo, i, ilast_intocc, ilow, ispin, iup, n_mo(2), n_mos(2), nao, &
1065 nelectron, nextra, nmoloc(2), nocc, npocc, nspin, output_unit
1066 LOGICAL :: my_do_homo, my_do_mixed, my_do_mo_cubes, &
1068 REAL(kind=dp) :: maxocc, my_tot_zeff_corr
1069 REAL(kind=dp),
DIMENSION(:),
POINTER :: mo_eigenvalues, occupation
1070 TYPE(cp_fm_type),
POINTER :: mo_coeff
1071 TYPE(cp_logger_type),
POINTER :: logger
1072 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: ks_rmpv, mo_derivs
1073 TYPE(dft_control_type),
POINTER :: dft_control
1074 TYPE(localized_wfn_control_type),
POINTER :: localized_wfn_control
1075 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos
1076 TYPE(mp_para_env_type),
POINTER :: para_env
1077 TYPE(scf_control_type),
POINTER :: scf_control
1078 TYPE(section_vals_type),
POINTER :: loc_print_section
1080 CALL timeset(routinen, handle)
1082 NULLIFY (mos, mo_coeff, mo_eigenvalues, occupation, ks_rmpv, mo_derivs, scf_control, para_env)
1083 CALL get_qs_env(qs_env, &
1085 matrix_ks=ks_rmpv, &
1086 mo_derivs=mo_derivs, &
1087 scf_control=scf_control, &
1088 dft_control=dft_control, &
1091 loc_print_section => section_vals_get_subs_vals(localize_section,
"PRINT")
1093 logger => cp_get_default_logger()
1094 output_unit = cp_logger_get_default_io_unit(logger)
1097 IF (
PRESENT(do_homo))
THEN
1098 my_do_homo = do_homo
1102 IF (
PRESENT(do_mo_cubes))
THEN
1103 my_do_mo_cubes = do_mo_cubes
1105 my_do_mo_cubes = .false.
1107 IF (
PRESENT(do_mixed))
THEN
1108 my_do_mixed = do_mixed
1110 my_do_mixed = .false.
1112 IF (
PRESENT(tot_zeff_corr))
THEN
1113 my_tot_zeff_corr = tot_zeff_corr
1115 my_tot_zeff_corr = 0.0_dp
1117 restart_found = .false.
1119 IF (qs_loc_env%do_localize)
THEN
1121 CALL get_qs_loc_env(qs_loc_env, localized_wfn_control=localized_wfn_control)
1122 IF (localized_wfn_control%loc_restart)
THEN
1123 IF (localized_wfn_control%nextra > 0)
THEN
1125 my_do_homo = .false.
1127 CALL loc_read_restart(qs_loc_env, mos, mos_localized, localize_section, &
1128 loc_print_section, para_env, my_do_homo, restart_found, evals=evals, &
1129 do_mixed=my_do_mixed)
1130 IF (output_unit > 0)
WRITE (output_unit,
"(/,T2,A,A)")
"LOCALIZATION| ", &
1131 " The orbitals to be localized are read from localization restart file."
1132 nmoloc = localized_wfn_control%nloc_states
1133 localized_wfn_control%nguess = nmoloc
1134 IF (localized_wfn_control%nextra > 0)
THEN
1137 localized_wfn_control%loc_restart = restart_found
1138 localized_wfn_control%set_of_states = state_loc_mixed
1140 CALL get_mo_set(mos(ispin), homo=homo, occupation_numbers=occupation, &
1142 nextra = localized_wfn_control%nextra
1145 IF (maxocc - occupation(i) < localized_wfn_control%eps_occ)
THEN
1152 nmoloc(ispin) = nocc + nextra
1153 localized_wfn_control%lu_bound_states(1, ispin) = 1
1154 localized_wfn_control%lu_bound_states(2, ispin) = nmoloc(ispin)
1155 localized_wfn_control%nloc_states(ispin) = nmoloc(ispin)
1157 my_do_homo = .false.
1160 IF (.NOT. restart_found)
THEN
1163 CALL get_mo_set(mos(ispin), nmo=n_mo(ispin), nelectron=nelectron, homo=homo, nao=nao, &
1164 mo_coeff=mo_coeff, eigenvalues=mo_eigenvalues, occupation_numbers=occupation, &
1167 IF ((.NOT. my_do_mo_cubes) &
1169 .AND. my_do_homo .AND. qs_env%scf_env%method == ot_method_nr .AND. (.NOT. dft_control%restricted))
THEN
1170 CALL make_mo_eig(mos, nspin, ks_rmpv, scf_control, mo_derivs)
1172 IF (localized_wfn_control%set_of_states == state_loc_all .AND. my_do_homo)
THEN
1173 nmoloc(ispin) = nint(nelectron/occupation(1))
1174 IF (n_mo(ispin) > homo)
THEN
1175 DO i = nmoloc(ispin), 1, -1
1176 IF (occupation(1) - occupation(i) < localized_wfn_control%eps_occ)
THEN
1182 ilast_intocc = nmoloc(ispin)
1184 nmoloc(ispin) = ilast_intocc
1185 localized_wfn_control%lu_bound_states(1, ispin) = 1
1186 localized_wfn_control%lu_bound_states(2, ispin) = ilast_intocc
1187 IF (nmoloc(ispin) /= n_mo(ispin))
THEN
1188 IF (output_unit > 0) &
1189 WRITE (output_unit,
"(/,T2,A,I4,A,I6,A,/,T15,A,F12.6,A,F12.6,A)") &
1190 "LOCALIZATION| Spin ", ispin,
" The first ", &
1191 ilast_intocc,
" occupied orbitals are localized,",
" with energies from ", &
1192 mo_eigenvalues(1),
" to ", mo_eigenvalues(ilast_intocc),
" [a.u.]."
1194 ELSE IF (localized_wfn_control%set_of_states == energy_loc_range .AND. my_do_homo)
THEN
1197 DO i = 1, n_mo(ispin)
1198 IF (mo_eigenvalues(i) >= localized_wfn_control%lu_ene_bound(1))
THEN
1203 DO i = n_mo(ispin), 1, -1
1204 IF (mo_eigenvalues(i) <= localized_wfn_control%lu_ene_bound(2))
THEN
1209 localized_wfn_control%lu_bound_states(1, ispin) = ilow
1210 localized_wfn_control%lu_bound_states(2, ispin) = iup
1211 localized_wfn_control%nloc_states(ispin) = iup - ilow + 1
1212 nmoloc(ispin) = localized_wfn_control%nloc_states(ispin)
1213 IF (occupation(ilow) - occupation(iup) > localized_wfn_control%eps_occ)
THEN
1214 CALL cp_abort(__location__, &
1215 "The selected energy range includes orbitals with different occupation number. "// &
1216 "The localization procedure cannot be applied.")
1218 IF (output_unit > 0)
WRITE (output_unit,
"(/,T2,A,I4,A,I6,A)")
"LOCALIZATION| Spin ", ispin,
" : ", &
1219 nmoloc(ispin),
" orbitals in the selected energy range are localized."
1220 ELSE IF (localized_wfn_control%set_of_states == state_loc_all .AND. (.NOT. my_do_homo))
THEN
1221 nmoloc(ispin) = n_mo(ispin) - homo
1222 localized_wfn_control%lu_bound_states(1, ispin) = homo + 1
1223 localized_wfn_control%lu_bound_states(2, ispin) = n_mo(ispin)
1224 IF (output_unit > 0) &
1225 WRITE (output_unit,
"(/,T2,A,I4,A,I6,A,/,T15,A,F12.6,A,F12.6,A)") &
1226 "LOCALIZATION| Spin ", ispin,
" The first ", &
1227 nmoloc(ispin),
" virtual orbitals are localized,",
" with energies from ", &
1228 mo_eigenvalues(homo + 1),
" to ", mo_eigenvalues(n_mo(ispin)),
" [a.u.]."
1229 ELSE IF (localized_wfn_control%set_of_states == state_loc_mixed)
THEN
1230 nextra = localized_wfn_control%nextra
1233 IF (maxocc - occupation(i) < localized_wfn_control%eps_occ)
THEN
1240 nmoloc(ispin) = nocc + nextra
1241 localized_wfn_control%lu_bound_states(1, ispin) = 1
1242 localized_wfn_control%lu_bound_states(2, ispin) = nmoloc(ispin)
1243 IF (output_unit > 0) &
1244 WRITE (output_unit,
"(/,T2,A,I4,A,I6,A,/,T15,A,I6,/,T15,A,I6,/,T15,A,I6,/,T15,A,F12.6,A)") &
1245 "LOCALIZATION| Spin ", ispin,
" The first ", &
1246 nmoloc(ispin),
" orbitals are localized.", &
1247 "Number of fully occupied MOs: ", nocc, &
1248 "Number of partially occupied MOs: ", npocc, &
1249 "Number of extra degrees of freedom: ", nextra, &
1250 "Excess charge: ", my_tot_zeff_corr,
" electrons"
1252 nmoloc(ispin) = min(localized_wfn_control%nloc_states(1), n_mo(ispin))
1253 IF (output_unit > 0 .AND. my_do_homo)
WRITE (output_unit,
"(/,T2,A,I4,A,I6,A)")
"LOCALIZATION| Spin ", ispin, &
1254 " : ", nmoloc(ispin),
" occupied orbitals are localized, as given in the input list."
1255 IF (output_unit > 0 .AND. (.NOT. my_do_homo))
WRITE (output_unit,
"(/,T2,A,I4,A,I6,A)")
"LOCALIZATION| Spin ", &
1256 ispin,
" : ", nmoloc(ispin),
" unoccupied orbitals are localized, as given in the input list."
1257 IF (n_mo(ispin) > homo .AND. my_do_homo)
THEN
1258 ilow = localized_wfn_control%loc_states(1, ispin)
1259 DO i = 2, nmoloc(ispin)
1260 iup = localized_wfn_control%loc_states(i, ispin)
1261 IF (abs(occupation(ilow) - occupation(iup)) > localized_wfn_control%eps_occ)
THEN
1263 CALL cp_warn(__location__, &
1264 "User requested the calculation of localized wavefunction from a subset of MOs, "// &
1265 "including MOs with different occupations. Check the selected subset, "// &
1266 "the electronic density is not invariant with "// &
1267 "respect to rotations among orbitals with different occupation numbers!")
1273 n_mos(:) = nao - n_mo(:)
1274 IF (my_do_homo .OR. my_do_mixed) n_mos = n_mo
1278 IF (my_do_homo .OR. my_do_mixed)
THEN
1280 loc_coeff=mos_localized, mo_loc_history=mo_loc_history)
1284 CALL cp_warn(__location__, &
1285 "User requested the calculation of the localized wavefunction but the section "// &
1286 "LOCALIZE was not specified. Localization will not be performed!")
1289 CALL timestop(handle)
1305 SUBROUTINE read_loc_section(localized_wfn_control, loc_section, &
1306 localize, do_mixed, do_xas, nloc_xas, spin_channel_xas)
1308 TYPE(localized_wfn_control_type),
POINTER :: localized_wfn_control
1309 TYPE(section_vals_type),
POINTER :: loc_section
1310 LOGICAL,
INTENT(OUT) :: localize
1311 LOGICAL,
INTENT(IN),
OPTIONAL :: do_mixed, do_xas
1312 INTEGER,
INTENT(IN),
OPTIONAL :: nloc_xas, spin_channel_xas
1314 INTEGER :: i, ind, ir, n_list, n_rep, n_state, &
1315 nextra, nline, other_spin, &
1316 output_unit, spin_xas
1317 INTEGER,
DIMENSION(:),
POINTER ::
list, loc_list
1318 LOGICAL :: my_do_mixed, my_do_xas
1319 REAL(dp),
POINTER :: ene(:)
1320 TYPE(cp_logger_type),
POINTER :: logger
1321 TYPE(section_vals_type),
POINTER :: loc_print_section
1325 IF (
PRESENT(do_xas))
THEN
1327 cpassert(
PRESENT(nloc_xas))
1329 IF (
PRESENT(spin_channel_xas)) spin_xas = spin_channel_xas
1330 my_do_mixed = .false.
1331 IF (
PRESENT(do_mixed))
THEN
1332 my_do_mixed = do_mixed
1334 cpassert(
ASSOCIATED(loc_section))
1336 logger => cp_get_default_logger()
1338 CALL section_vals_val_get(loc_section,
"_SECTION_PARAMETERS_", l_val=localize)
1340 loc_print_section => section_vals_get_subs_vals(loc_section,
"PRINT")
1343 localized_wfn_control%lu_bound_states = 0
1344 localized_wfn_control%lu_ene_bound = 0.0_dp
1345 localized_wfn_control%nloc_states = 0
1346 localized_wfn_control%set_of_states = 0
1347 localized_wfn_control%nextra = 0
1350 CALL section_vals_val_get(loc_section,
"MAX_ITER", &
1351 i_val=localized_wfn_control%max_iter)
1352 CALL section_vals_val_get(loc_section,
"MAX_CRAZY_ANGLE", &
1353 r_val=localized_wfn_control%max_crazy_angle)
1354 CALL section_vals_val_get(loc_section,
"CRAZY_SCALE", &
1355 r_val=localized_wfn_control%crazy_scale)
1356 CALL section_vals_val_get(loc_section,
"EPS_OCCUPATION", &
1357 r_val=localized_wfn_control%eps_occ)
1358 CALL section_vals_val_get(loc_section,
"CRAZY_USE_DIAG", &
1359 l_val=localized_wfn_control%crazy_use_diag)
1360 CALL section_vals_val_get(loc_section,
"OUT_ITER_EACH", &
1361 i_val=localized_wfn_control%out_each)
1362 CALL section_vals_val_get(loc_section,
"EPS_LOCALIZATION", &
1363 r_val=localized_wfn_control%eps_localization)
1364 CALL section_vals_val_get(loc_section,
"MIN_OR_MAX", &
1365 i_val=localized_wfn_control%min_or_max)
1366 CALL section_vals_val_get(loc_section,
"JACOBI_FALLBACK", &
1367 l_val=localized_wfn_control%jacobi_fallback)
1368 CALL section_vals_val_get(loc_section,
"JACOBI_REFINEMENT", &
1369 l_val=localized_wfn_control%jacobi_refinement)
1370 CALL section_vals_val_get(loc_section,
"METHOD", &
1371 i_val=localized_wfn_control%localization_method)
1372 CALL section_vals_val_get(loc_section,
"OPERATOR", &
1373 i_val=localized_wfn_control%operator_type)
1374 CALL section_vals_val_get(loc_section,
"RESTART", &
1375 l_val=localized_wfn_control%loc_restart)
1376 CALL section_vals_val_get(loc_section,
"USE_HISTORY", &
1377 l_val=localized_wfn_control%use_history)
1378 CALL section_vals_val_get(loc_section,
"NEXTRA", &
1379 i_val=localized_wfn_control%nextra)
1380 CALL section_vals_val_get(loc_section,
"CPO_GUESS", &
1381 i_val=localized_wfn_control%coeff_po_guess)
1382 CALL section_vals_val_get(loc_section,
"CPO_GUESS_SPACE", &
1383 i_val=localized_wfn_control%coeff_po_guess_mo_space)
1384 CALL section_vals_val_get(loc_section,
"CG_PO", &
1385 l_val=localized_wfn_control%do_cg_po)
1387 IF (localized_wfn_control%do_homo)
THEN
1389 CALL section_vals_val_get(loc_section,
"LIST", n_rep_val=n_rep)
1394 CALL section_vals_val_get(loc_section,
"LIST", i_rep_val=ir, i_vals=
list)
1395 IF (
ASSOCIATED(
list))
THEN
1396 CALL reallocate(loc_list, 1, n_list +
SIZE(
list))
1397 DO i = 1,
SIZE(
list)
1398 loc_list(n_list + i) =
list(i)
1400 n_list = n_list +
SIZE(
list)
1403 IF (n_list /= 0)
THEN
1404 localized_wfn_control%set_of_states = state_loc_list
1405 ALLOCATE (localized_wfn_control%loc_states(n_list, 2))
1406 localized_wfn_control%loc_states = 0
1407 localized_wfn_control%loc_states(:, 1) = loc_list(:)
1408 localized_wfn_control%loc_states(:, 2) = loc_list(:)
1409 localized_wfn_control%nloc_states(1) = n_list
1410 localized_wfn_control%nloc_states(2) = n_list
1413 IF (spin_xas == 2) other_spin = 1
1414 localized_wfn_control%nloc_states(other_spin) = 0
1415 localized_wfn_control%loc_states(:, other_spin) = 0
1417 DEALLOCATE (loc_list)
1423 CALL section_vals_val_get(loc_section,
"LIST_UNOCCUPIED", n_rep_val=n_rep)
1428 CALL section_vals_val_get(loc_section,
"LIST_UNOCCUPIED", i_rep_val=ir, i_vals=
list)
1429 IF (
ASSOCIATED(
list))
THEN
1430 CALL reallocate(loc_list, 1, n_list +
SIZE(
list))
1431 DO i = 1,
SIZE(
list)
1432 loc_list(n_list + i) =
list(i)
1434 n_list = n_list +
SIZE(
list)
1437 IF (n_list /= 0)
THEN
1438 localized_wfn_control%set_of_states = state_loc_list
1439 ALLOCATE (localized_wfn_control%loc_states(n_list, 2))
1440 localized_wfn_control%loc_states = 0
1441 localized_wfn_control%loc_states(:, 1) = loc_list(:)
1442 localized_wfn_control%loc_states(:, 2) = loc_list(:)
1443 localized_wfn_control%nloc_states(1) = n_list
1444 DEALLOCATE (loc_list)
1449 IF (localized_wfn_control%set_of_states == 0)
THEN
1450 CALL section_vals_val_get(loc_section,
"ENERGY_RANGE", r_vals=ene)
1451 IF (ene(1) /= ene(2))
THEN
1452 localized_wfn_control%set_of_states = energy_loc_range
1453 localized_wfn_control%lu_ene_bound(1) = ene(1)
1454 localized_wfn_control%lu_ene_bound(2) = ene(2)
1459 IF (localized_wfn_control%set_of_states == 0)
THEN
1461 localized_wfn_control%set_of_states = state_loc_range
1462 localized_wfn_control%nloc_states(:) = 0
1463 localized_wfn_control%lu_bound_states(1, :) = 0
1464 localized_wfn_control%lu_bound_states(2, :) = 0
1465 localized_wfn_control%nloc_states(spin_xas) = nloc_xas
1466 localized_wfn_control%lu_bound_states(1, spin_xas) = 1
1467 localized_wfn_control%lu_bound_states(2, spin_xas) = nloc_xas
1468 ELSE IF (my_do_mixed)
THEN
1469 localized_wfn_control%set_of_states = state_loc_mixed
1470 nextra = localized_wfn_control%nextra
1472 localized_wfn_control%set_of_states = state_loc_all
1476 localized_wfn_control%print_centers = &
1477 btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
1478 "WANNIER_CENTERS"), cp_p_file)
1479 localized_wfn_control%print_spreads = &
1480 btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
1481 "WANNIER_SPREADS"), cp_p_file)
1482 localized_wfn_control%print_cubes = &
1483 btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
1484 "WANNIER_CUBES"), cp_p_file)
1486 output_unit = cp_print_key_unit_nr(logger, loc_print_section,
"PROGRAM_RUN_INFO", &
1489 IF (output_unit > 0)
THEN
1490 WRITE (unit=output_unit, fmt=
"(/,T2,A)") &
1491 "LOCALIZE| The spread relative to a set of orbitals is computed"
1493 SELECT CASE (localized_wfn_control%set_of_states)
1494 CASE (state_loc_all)
1495 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1496 "LOCALIZE| Orbitals to be localized: All orbitals"
1497 WRITE (unit=output_unit, fmt=
"(T2,A,/,T12,A,F16.8)") &
1498 "LOCALIZE| If fractional occupation, fully occupied MOs are those ", &
1499 "within occupation tolerance of ", localized_wfn_control%eps_occ
1500 CASE (state_loc_range)
1501 WRITE (unit=output_unit, fmt=
"(T2,A,T65,I8,A,I8)") &
1502 "LOCALIZE| Orbitals to be localized: Those with index between ", &
1503 localized_wfn_control%lu_bound_states(1, spin_xas),
" and ", &
1504 localized_wfn_control%lu_bound_states(2, spin_xas)
1505 CASE (state_loc_list)
1506 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1507 "LOCALIZE| Orbitals to be localized: Those with index in the following list"
1508 nline = localized_wfn_control%nloc_states(1)/10 + 1
1511 IF (ind + 10 < localized_wfn_control%nloc_states(1))
THEN
1512 WRITE (unit=output_unit, fmt=
"(T8,10I7)") localized_wfn_control%loc_states(ind + 1:ind + 10, 1)
1515 WRITE (unit=output_unit, fmt=
"(T8,10I7)") &
1516 localized_wfn_control%loc_states(ind + 1:localized_wfn_control%nloc_states(1), 1)
1517 ind = localized_wfn_control%nloc_states(1)
1520 CASE (energy_loc_range)
1521 WRITE (unit=output_unit, fmt=
"(T2,A,T65,/,f16.6,A,f16.6,A)") &
1522 "LOCALIZE| Orbitals to be localized: Those with energy in the range between ", &
1523 localized_wfn_control%lu_ene_bound(1),
" and ", localized_wfn_control%lu_ene_bound(2),
" a.u."
1524 CASE (state_loc_mixed)
1525 WRITE (unit=output_unit, fmt=
"(T2,A,I4,A)") &
1526 "LOCALIZE| Orbitals to be localized: Occupied orbitals + ", nextra,
" orbitals"
1528 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1529 "LOCALIZE| Orbitals to be localized: None "
1532 SELECT CASE (localized_wfn_control%operator_type)
1534 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1535 "LOCALIZE| Spread defined by the Berry phase operator "
1537 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1538 "LOCALIZE| Spread defined by the Boys phase operator "
1540 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1541 "LOCALIZE| Spread defined by the Pipek phase operator "
1544 SELECT CASE (localized_wfn_control%localization_method)
1545 CASE (do_loc_jacobi)
1546 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1547 "LOCALIZE| Optimal unitary transformation generated by Jacobi algorithm"
1549 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1550 "LOCALIZE| Optimal unitary transformation generated by Crazy angle algorithm"
1551 WRITE (unit=output_unit, fmt=
"(T2,A,F16.8)") &
1552 "LOCALIZE| maximum angle: ", localized_wfn_control%max_crazy_angle
1553 WRITE (unit=output_unit, fmt=
"(T2,A,F16.8)") &
1554 "LOCALIZE| scaling: ", localized_wfn_control%crazy_scale
1555 WRITE (unit=output_unit, fmt=
"(T2,A,L1)") &
1556 "LOCALIZE| use diag:", localized_wfn_control%crazy_use_diag
1558 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1559 "LOCALIZE| Optimal unitary transformation generated by gradient ascent algorithm "
1560 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1561 "LOCALIZE| for partially occupied wannier functions"
1562 CASE (do_loc_direct)
1563 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1564 "LOCALIZE| Optimal unitary transformation generated by direct algorithm"
1565 CASE (do_loc_l1_norm_sd)
1566 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1567 "LOCALIZE| Optimal unitary transformation generated by "
1568 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1569 "LOCALIZE| steepest descent algorithm applied on an approximate l1 norm"
1571 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1572 "LOCALIZE| No unitary transformation is applied"
1574 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1575 "LOCALIZE| Pivoted QR decomposition is used to transform coefficients"
1580 CALL cp_print_key_finished_output(output_unit, logger, loc_print_section,
"PROGRAM_RUN_INFO")
1583 localized_wfn_control%localization_method = do_loc_none
1584 localized_wfn_control%localization_method = state_loc_none
1585 localized_wfn_control%print_centers = .false.
1586 localized_wfn_control%print_spreads = .false.
1587 localized_wfn_control%print_cubes = .false.
1590 END SUBROUTINE read_loc_section
1602 TYPE(localized_wfn_control_type) :: localized_wfn_control
1603 INTEGER,
DIMENSION(2),
INTENT(IN) :: nmoloc
1604 INTEGER,
INTENT(IN) :: nspins
1608 DO ispin = 1, nspins
1609 ALLOCATE (localized_wfn_control%centers_set(ispin)%array(6, nmoloc(ispin)))
1610 localized_wfn_control%centers_set(ispin)%array = 0.0_dp
1627 TYPE(localized_wfn_control_type) :: localized_wfn_control
1628 INTEGER,
DIMENSION(2),
INTENT(IN) :: nmoloc, nmo
1629 INTEGER,
INTENT(IN) :: nspins
1630 INTEGER,
INTENT(IN),
OPTIONAL :: my_spin
1632 CHARACTER(len=*),
PARAMETER :: routinen =
'set_loc_wfn_lists'
1634 INTEGER :: i, ispin, max_iloc, max_nmoloc, state
1636 CALL timeset(routinen, state)
1638 localized_wfn_control%nloc_states(1:2) = nmoloc(1:2)
1639 max_nmoloc = max(nmoloc(1), nmoloc(2))
1641 SELECT CASE (localized_wfn_control%set_of_states)
1642 CASE (state_loc_list)
1644 cpassert(
ASSOCIATED(localized_wfn_control%loc_states))
1645 DO ispin = 1, nspins
1646 localized_wfn_control%lu_bound_states(1, ispin) = 1
1647 localized_wfn_control%lu_bound_states(2, ispin) = nmoloc(ispin)
1648 IF (nmoloc(ispin) < 1)
THEN
1649 localized_wfn_control%lu_bound_states(1, ispin) = 0
1650 localized_wfn_control%loc_states(:, ispin) = 0
1653 CASE (state_loc_range)
1655 ALLOCATE (localized_wfn_control%loc_states(max_nmoloc, 2))
1656 localized_wfn_control%loc_states = 0
1657 DO ispin = 1, nspins
1658 localized_wfn_control%lu_bound_states(1, ispin) = &
1659 localized_wfn_control%lu_bound_states(1, my_spin)
1660 localized_wfn_control%lu_bound_states(2, ispin) = &
1661 localized_wfn_control%lu_bound_states(1, my_spin) + nmoloc(ispin) - 1
1662 max_iloc = localized_wfn_control%lu_bound_states(2, ispin)
1663 DO i = 1, nmoloc(ispin)
1664 localized_wfn_control%loc_states(i, ispin) = localized_wfn_control%lu_bound_states(1, ispin) + i - 1
1666 cpassert(max_iloc <= nmo(ispin))
1669 CASE (energy_loc_range)
1671 ALLOCATE (localized_wfn_control%loc_states(max_nmoloc, 2))
1672 localized_wfn_control%loc_states = 0
1673 DO ispin = 1, nspins
1674 DO i = 1, nmoloc(ispin)
1675 localized_wfn_control%loc_states(i, ispin) = localized_wfn_control%lu_bound_states(1, ispin) + i - 1
1678 CASE (state_loc_all)
1680 ALLOCATE (localized_wfn_control%loc_states(max_nmoloc, 2))
1681 localized_wfn_control%loc_states = 0
1683 IF (localized_wfn_control%lu_bound_states(1, 1) == 1)
THEN
1684 DO ispin = 1, nspins
1685 localized_wfn_control%lu_bound_states(1, ispin) = 1
1686 localized_wfn_control%lu_bound_states(2, ispin) = nmoloc(ispin)
1687 IF (nmoloc(ispin) < 1) localized_wfn_control%lu_bound_states(1, ispin) = 0
1688 DO i = 1, nmoloc(ispin)
1689 localized_wfn_control%loc_states(i, ispin) = i
1693 DO ispin = 1, nspins
1694 IF (nmoloc(ispin) < 1) localized_wfn_control%lu_bound_states(1, ispin) = 0
1695 DO i = 1, nmoloc(ispin)
1696 localized_wfn_control%loc_states(i, ispin) = &
1697 localized_wfn_control%lu_bound_states(1, ispin) + i - 1
1701 CASE (state_loc_mixed)
1703 ALLOCATE (localized_wfn_control%loc_states(max_nmoloc, 2))
1704 localized_wfn_control%loc_states = 0
1705 DO ispin = 1, nspins
1706 DO i = 1, nmoloc(ispin)
1707 localized_wfn_control%loc_states(i, ispin) = i
1712 CALL timestop(state)
Calculation of the moment integrals over Cartesian Gaussian-type functions.
subroutine, public contract_cossin(cos_block, sin_block, iatom, ncoa, nsgfa, sgfa, sphi_a, ldsa, jatom, ncob, nsgfb, sgfb, sphi_b, ldsb, cosab, sinab, ldab, work, ldwork)
...
subroutine, public cossin(la_max_set, npgfa, zeta, rpgfa, la_min_set, lb_max, npgfb, zetb, rpgfb, lb_min, rac, rbc, kvec, cosab, sinab, dcosab, dsinab)
...
collect pointers to a block of reals
Handles all functions related to the CELL.
various utilities that regard array of different kinds: output, allocation,... maybe it is not a good...
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_get_block_p(matrix, row, col, block, found, row_size, col_size)
...
subroutine, public dbcsr_set(matrix, alpha)
...
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
Utility routines to open and close files. Tracking of preconnections.
subroutine, public open_file(file_name, file_status, file_form, file_action, file_position, file_pad, unit_number, debug, skip_get_unit_number, file_access)
Opens the requested file using a free unit number.
subroutine, public close_file(unit_number, file_status, keep_preconnection)
Close an open file given by its logical unit number. Optionally, keep the file and unit preconnected.
basic linear algebra operations for full matrices
subroutine, public cp_fm_column_scale(matrixa, scaling)
scales column i of matrix a with scaling(i)
used for collecting some of the diagonalization schemes available for cp_fm_type. cp_fm_power also mo...
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...
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_write_unformatted(fm, unit)
...
subroutine, public cp_fm_set_submatrix(fm, new_values, start_row, start_col, n_rows, n_cols, alpha, beta, transpose)
sets a submatrix of a full matrix fm(start_row:start_row+n_rows,start_col:start_col+n_cols) = alpha*o...
subroutine, public cp_fm_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_get_submatrix(fm, target_m, start_row, start_col, n_rows, n_cols, transpose)
gets a submatrix of a full matrix op(target_m)(1:n_rows,1:n_cols) =fm(start_row:start_row+n_rows,...
subroutine, public cp_fm_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 ...
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...
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)
...
character(len=default_path_length) function, public cp_print_key_generate_filename(logger, print_key, middle_name, extension, my_local)
Utility function that returns a unit number to write the print key. Might open a file with a unique f...
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,...
integer, parameter, public cp_p_file
integer function, public cp_print_key_should_output(iteration_info, basis_section, print_key_path, used_print_key, first_time)
returns what should be done with the given property if btest(res,cp_p_store) then the property should...
stores a lists of integer that are local to a processor. The idea is that these integers represent ob...
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
integer, parameter, public default_path_length
An array-based list which grows on demand. When the internal array is full, a new array of twice the ...
Definition of mathematical constants and functions.
real(kind=dp), parameter, public twopi
Utility routines for the memory handling.
Interface to the message passing library MPI.
Provides Cartesian and spherical orbital pointers and indices.
integer, dimension(:), allocatable, public ncoset
basic linear algebra operations for full matrixes
Define the data structure for the particle information.
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs)
Get the QUICKSTEP environment.
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, init_u_ramping_each_scf, reltmat, ghost, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
subroutine, public get_qs_kind_set(qs_kind_set, all_potential_present, tnadd_potential_present, gth_potential_present, sgp_potential_present, paw_atom_present, dft_plus_u_atom_present, maxcgf, maxsgf, maxco, maxco_proj, maxgtops, maxlgto, maxlprj, maxnset, maxsgf_set, ncgf, npgf, nset, nsgf, nshell, maxpol, maxlppl, maxlppnl, maxppnl, nelectron, maxder, max_ngrid_rad, max_sph_harm, maxg_iso_not0, lmax_rho0, basis_rcut, basis_type, total_zeff_corr, npgf_seg)
Get attributes of an atomic kind set.
New version of the module for the localization of the molecular orbitals This should be able to use d...
subroutine, public localized_wfn_control_create(localized_wfn_control)
create the localized_wfn_control_type
subroutine, public localized_wfn_control_release(localized_wfn_control)
release the localized_wfn_control_type
subroutine, public get_qs_loc_env(qs_loc_env, cell, local_molecules, localized_wfn_control, moloc_coeff, op_sm_set, op_fm_set, para_env, particle_set, weights, dim_op)
...
subroutine, public set_qs_loc_env(qs_loc_env, cell, local_molecules, localized_wfn_control, moloc_coeff, op_sm_set, op_fm_set, para_env, particle_set, weights, dim_op)
...
Some utilities for the construction of the localization environment.
subroutine, public compute_berry_operator(qs_env, cell, op_sm_set, dim_op)
Computes the Berry operator for periodic systems used to define the spread of the MOS Here the matrix...
subroutine, public set_loc_wfn_lists(localized_wfn_control, nmoloc, nmo, nspins, my_spin)
create the lists of mos that are taken into account
subroutine, public loc_write_restart(qs_loc_env, section, mo_array, coeff_localized, do_homo, evals, do_mixed)
...
subroutine, public qs_loc_env_init(qs_loc_env, localized_wfn_control, qs_env, myspin, do_localize, loc_coeff, mo_loc_history)
allocates the data, and initializes the operators
subroutine, public set_loc_centers(localized_wfn_control, nmoloc, nspins)
create the center and spread array and the file names for the output
subroutine, public qs_loc_control_init(qs_loc_env, loc_section, do_homo, do_mixed, do_xas, nloc_xas, spin_xas)
initializes everything needed for localization of the HOMOs
subroutine, public retain_history(mo_loc_history, mo_loc)
copy old mos to new ones, allocating as necessary
subroutine, public qs_loc_init(qs_env, qs_loc_env, localize_section, mos_localized, do_homo, do_mo_cubes, mo_loc_history, evals, tot_zeff_corr, do_mixed)
initializes everything needed for localization of the molecular orbitals
Localization methods such as 2x2 Jacobi rotations Steepest Decents Conjugate Gradient.
subroutine, public initialize_weights(cell, weights)
...
collects routines that perform operations directly related to MOs
subroutine, public make_mo_eig(mos, nspins, ks_rmpv, scf_control, mo_derivs, admm_env)
Calculate KS eigenvalues starting from OF MOS.
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.
subroutine, public neighbor_list_iterator_create(iterator_set, nl, search, nthread)
Neighbor list iterator functions.
subroutine, public neighbor_list_iterator_release(iterator_set)
...
integer function, public neighbor_list_iterate(iterator_set, mepos)
...
subroutine, public get_iterator_info(iterator_set, mepos, ikind, jkind, nkind, ilist, nlist, inode, nnode, iatom, jatom, r, cell)
...
module that contains the definitions of the scf types
integer, parameter, public ot_method_nr
parameters that control an scf iteration
Type defining parameters related to the simulation cell.
represent a pointer to a 1d array
keeps the information about the structure of a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
structure to store local (to a processor) ordered lists of integers.
stores all the informations relevant to an mpi environment
Provides all information about a quickstep kind.
A type that holds controlling information for the calculation of the spread of wfn and the optimizati...
contains all the info needed by quickstep to calculate the spread of a selected set of orbitals and i...