72#include "./base/base_uses.f90"
80 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_loc_utils'
96 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: mo_loc_history
97 TYPE(
cp_fm_type),
DIMENSION(:),
INTENT(IN) :: mo_loc
99 CHARACTER(len=*),
PARAMETER :: routinen =
'retain_history'
101 INTEGER :: handle, i, ncol_hist, ncol_loc
103 CALL timeset(routinen, handle)
105 IF (.NOT.
ASSOCIATED(mo_loc_history))
THEN
106 ALLOCATE (mo_loc_history(
SIZE(mo_loc)))
107 DO i = 1,
SIZE(mo_loc_history)
108 CALL cp_fm_create(mo_loc_history(i), mo_loc(i)%matrix_struct)
112 DO i = 1,
SIZE(mo_loc_history)
115 cpassert(ncol_hist == ncol_loc)
119 CALL timestop(handle)
130 SUBROUTINE rotate_state_to_ref(mo_new, mo_ref, matrix_S)
132 TYPE(
cp_fm_type),
INTENT(IN) :: mo_new, mo_ref
135 CHARACTER(len=*),
PARAMETER :: routinen =
'rotate_state_to_ref'
137 INTEGER :: handle, ncol, ncol_ref, nrow
138 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigenvalues
142 CALL timeset(routinen, handle)
146 cpassert(ncol == ncol_ref)
148 NULLIFY (fm_struct_tmp)
152 ncol_global=ncol, para_env=mo_new%matrix_struct%para_env, &
153 context=mo_new%matrix_struct%context)
162 CALL parallel_gemm(
'T',
'N', ncol, ncol, nrow, 1.0_dp, mo_new, smo, 0.0_dp, o1)
165 CALL parallel_gemm(
'T',
'N', ncol, ncol, ncol, 1.0_dp, o1, o1, 0.0_dp, o2)
168 ALLOCATE (eigenvalues(ncol))
171 eigenvalues(:) = 1.0_dp/sqrt(eigenvalues(:))
173 CALL parallel_gemm(
'N',
'T', ncol, ncol, ncol, 1.0_dp, o3, o4, 0.0_dp, o2)
176 CALL parallel_gemm(
'N',
'N', ncol, ncol, ncol, 1.0_dp, o1, o2, 0.0_dp, o3)
179 CALL parallel_gemm(
'N',
'N', nrow, ncol, ncol, 1.0_dp, mo_new, o3, 0.0_dp, smo)
194 CALL timestop(handle)
196 END SUBROUTINE rotate_state_to_ref
213 SUBROUTINE qs_loc_env_init(qs_loc_env, localized_wfn_control, qs_env, myspin, do_localize, &
214 loc_coeff, mo_loc_history)
219 INTEGER,
INTENT(IN),
OPTIONAL :: myspin
220 LOGICAL,
INTENT(IN),
OPTIONAL :: do_localize
222 OPTIONAL :: loc_coeff
223 TYPE(
cp_fm_type),
DIMENSION(:),
OPTIONAL,
POINTER :: mo_loc_history
225 CHARACTER(len=*),
PARAMETER :: routinen =
'qs_loc_env_init'
227 INTEGER :: dim_op, handle, i, iatom, imo, imoloc, &
228 ispin, j, l_spin, lb, nao, naosub, &
229 natoms, nmo, nmosub, nspins, s_spin, ub
230 LOGICAL :: loc_coeff_spin_resolved
231 REAL(kind=
dp) :: my_occ, occ_imo
232 REAL(kind=
dp),
DIMENSION(:),
POINTER :: occupations
233 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: vecbuffer
236 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: moloc_coeff
237 TYPE(
cp_fm_type),
POINTER :: mat_ptr, mo_coeff
244 CALL timeset(routinen, handle)
246 NULLIFY (mos, matrix_s, moloc_coeff, particle_set, para_env, cell, &
247 local_molecules, occupations, mat_ptr)
248 IF (
PRESENT(do_localize)) qs_loc_env%do_localize = do_localize
249 IF (qs_loc_env%do_localize)
THEN
250 CALL get_qs_env(qs_env=qs_env, matrix_s=matrix_s, cell=cell, &
251 local_molecules=local_molecules, particle_set=particle_set, &
252 para_env=para_env, mos=mos)
253 nspins =
SIZE(mos, 1)
254 loc_coeff_spin_resolved = .false.
255 IF (
PRESENT(loc_coeff))
THEN
256 loc_coeff_spin_resolved = nspins*2 ==
SIZE(loc_coeff)
260 IF (
PRESENT(myspin))
THEN
264 IF (loc_coeff_spin_resolved)
THEN
265 ALLOCATE (moloc_coeff(s_spin:s_spin + 2*(l_spin - s_spin) + 1))
267 ALLOCATE (moloc_coeff(s_spin:l_spin))
269 DO ispin = s_spin, l_spin
270 NULLIFY (tmp_fm_struct, mo_coeff)
271 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, nao=nao, nmo=nmo)
272 nmosub = localized_wfn_control%nloc_states(ispin)
274 ncol_global=nmosub, para_env=para_env, context=mo_coeff%matrix_struct%context)
275 IF (loc_coeff_spin_resolved)
THEN
276 CALL cp_fm_create(moloc_coeff(2*ispin - 1), tmp_fm_struct)
284 cpassert(nao == naosub)
285 IF ((localized_wfn_control%do_homo) .OR. &
287 cpassert(nmo >= nmosub)
289 cpassert(nao - nmo >= nmosub)
296 IF (
PRESENT(loc_coeff))
ALLOCATE (mat_ptr)
298 DO ispin = s_spin, l_spin
299 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, &
300 occupation_numbers=occupations, nao=nao, nmo=nmo)
301 lb = localized_wfn_control%lu_bound_states(1, ispin)
302 ub = localized_wfn_control%lu_bound_states(2, ispin)
304 IF (
PRESENT(loc_coeff))
THEN
305 mat_ptr = loc_coeff(ispin)
309 IF ((localized_wfn_control%set_of_states ==
state_loc_list) .OR. &
311 ALLOCATE (vecbuffer(1, nao))
312 IF (localized_wfn_control%do_homo)
THEN
313 my_occ = occupations(localized_wfn_control%loc_states(1, ispin))
315 nmosub =
SIZE(localized_wfn_control%loc_states, 1)
322 imo = localized_wfn_control%loc_states(i, ispin)
323 IF (localized_wfn_control%do_homo)
THEN
324 occ_imo = occupations(imo)
325 IF (abs(occ_imo - my_occ) > localized_wfn_control%eps_occ)
THEN
326 IF (localized_wfn_control%localization_method /=
do_loc_none)
THEN
327 CALL cp_abort(__location__, &
328 "States with different occupations "// &
329 "cannot be rotated together")
335 nao, 1, transpose=.true.)
337 nao, 1, transpose=.true.)
339 DEALLOCATE (vecbuffer)
341 my_occ = occupations(lb)
342 occ_imo = occupations(ub)
343 IF (abs(occ_imo - my_occ) > localized_wfn_control%eps_occ)
THEN
344 IF (localized_wfn_control%localization_method /=
do_loc_none)
THEN
345 CALL cp_abort(__location__, &
346 "States with different occupations "// &
347 "cannot be rotated together")
350 nmosub = localized_wfn_control%nloc_states(ispin)
352 IF (loc_coeff_spin_resolved)
THEN
353 CALL cp_fm_to_fm(loc_coeff(2*ispin - 1), moloc_coeff(2*ispin - 1))
354 CALL cp_fm_to_fm(loc_coeff(2*ispin), moloc_coeff(2*ispin))
356 CALL cp_fm_to_fm(mat_ptr, moloc_coeff(ispin), nmosub, lb, 1)
362 IF (
PRESENT(mo_loc_history))
THEN
363 IF (localized_wfn_control%use_history .AND.
ASSOCIATED(mo_loc_history))
THEN
364 CALL rotate_state_to_ref(moloc_coeff(ispin), &
365 mo_loc_history(ispin), matrix_s(1)%matrix)
371 IF (
PRESENT(loc_coeff))
DEALLOCATE (mat_ptr)
373 CALL set_qs_loc_env(qs_loc_env=qs_loc_env, cell=cell, local_molecules=local_molecules, &
374 moloc_coeff=moloc_coeff, particle_set=particle_set, para_env=para_env, &
375 localized_wfn_control=localized_wfn_control)
378 NULLIFY (tmp_fm_struct, mo_coeff)
379 nmosub = maxval(localized_wfn_control%nloc_states)
382 ncol_global=nmosub, para_env=para_env, context=mo_coeff%matrix_struct%context)
384 IF (localized_wfn_control%operator_type ==
op_loc_berry)
THEN
385 IF (qs_loc_env%cell%orthorhombic)
THEN
391 ALLOCATE (qs_loc_env%op_sm_set(2, dim_op))
393 DO j = 1,
SIZE(qs_loc_env%op_sm_set, 1)
394 NULLIFY (qs_loc_env%op_sm_set(j, i)%matrix)
395 ALLOCATE (qs_loc_env%op_sm_set(j, i)%matrix)
396 CALL dbcsr_copy(qs_loc_env%op_sm_set(j, i)%matrix, matrix_s(1)%matrix, &
401 ELSE IF (localized_wfn_control%operator_type ==
op_loc_pipek)
THEN
402 natoms =
SIZE(qs_loc_env%particle_set, 1)
403 ALLOCATE (qs_loc_env%op_fm_set(natoms, 1))
405 DO ispin = 1,
SIZE(qs_loc_env%op_fm_set, 2)
408 CALL cp_fm_create(qs_loc_env%op_fm_set(iatom, ispin), tmp_fm_struct)
410 CALL cp_fm_get_info(qs_loc_env%op_fm_set(iatom, ispin), nrow_global=nmosub)
411 cpassert(nmo >= nmosub)
412 CALL cp_fm_set_all(qs_loc_env%op_fm_set(iatom, ispin), 0.0_dp)
416 cpabort(
"Type of operator not implemented")
420 IF (localized_wfn_control%operator_type ==
op_loc_berry)
THEN
424 CALL get_berry_operator(qs_loc_env, qs_env)
426 ELSE IF (localized_wfn_control%operator_type ==
op_loc_pipek)
THEN
433 qs_loc_env%molecular_states = .false.
434 qs_loc_env%wannier_states = .false.
436 CALL timestop(handle)
449 SUBROUTINE get_berry_operator(qs_loc_env, qs_env)
453 CHARACTER(len=*),
PARAMETER :: routinen =
'get_berry_operator'
455 INTEGER :: dim_op, handle
457 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: op_sm_set
459 CALL timeset(routinen, handle)
461 NULLIFY (cell, op_sm_set)
463 cell=cell, dim_op=dim_op)
466 CALL timestop(handle)
467 END SUBROUTINE get_berry_operator
489 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: op_sm_set
492 CHARACTER(len=*),
PARAMETER :: routinen =
'compute_berry_operator'
495 REAL(kind=
dp),
DIMENSION(3, 6) :: vector_k
497 CALL timeset(routinen, handle)
498 cpassert(dim_op == 3 .OR. dim_op == 6)
499 cpassert(
ASSOCIATED(cell))
501 vector_k(:, 1) =
twopi*cell%h_inv(1, :)
502 vector_k(:, 2) =
twopi*cell%h_inv(2, :)
503 vector_k(:, 3) =
twopi*cell%h_inv(3, :)
504 vector_k(:, 4) =
twopi*(cell%h_inv(1, :) + cell%h_inv(2, :))
505 vector_k(:, 5) =
twopi*(cell%h_inv(1, :) + cell%h_inv(3, :))
506 vector_k(:, 6) =
twopi*(cell%h_inv(2, :) + cell%h_inv(3, :))
509 force_periodic=.true., cell_external=cell)
511 CALL timestop(handle)
526 do_homo, evals, do_mixed)
529 TYPE(
mo_set_type),
DIMENSION(:),
POINTER :: mo_array
530 TYPE(
cp_fm_type),
DIMENSION(:),
INTENT(IN) :: coeff_localized
531 LOGICAL,
INTENT(IN) :: do_homo
534 LOGICAL,
INTENT(IN),
OPTIONAL ::
do_mixed
536 CHARACTER(LEN=*),
PARAMETER :: routinen =
'loc_write_restart'
538 CHARACTER(LEN=default_path_length) :: filename
539 CHARACTER(LEN=default_string_length) :: my_middle
540 INTEGER :: handle, ispin, max_block, nao, nloc, &
541 nmo, output_unit, rst_unit
542 LOGICAL :: my_do_mixed
546 CALL timeset(routinen, handle)
551 IF (qs_loc_env%do_localize)
THEN
555 section,
"LOC_RESTART"), &
561 my_do_mixed = .false.
564 my_middle =
"LOC_HOMO"
565 ELSE IF (my_do_mixed)
THEN
566 my_middle =
"LOC_MIXED"
568 my_middle =
"LOC_LUMO"
572 extension=
".wfn", file_status=
"REPLACE", file_action=
"WRITE", &
573 file_form=
"UNFORMATTED", middle_name=trim(my_middle))
576 middle_name=trim(my_middle), extension=
".wfn", &
579 IF (output_unit > 0)
THEN
580 WRITE (unit=output_unit, fmt=
"(/,T2,A, A/)") &
581 "LOCALIZATION| Write restart file for the localized MOS : ", &
585 IF (rst_unit > 0)
THEN
586 WRITE (rst_unit) qs_loc_env%localized_wfn_control%set_of_states
587 WRITE (rst_unit) qs_loc_env%localized_wfn_control%lu_bound_states
588 WRITE (rst_unit) qs_loc_env%localized_wfn_control%nloc_states
591 DO ispin = 1,
SIZE(coeff_localized)
592 associate(mo_coeff => coeff_localized(ispin))
593 CALL cp_fm_get_info(mo_coeff, nrow_global=nao, ncol_global=nmo, ncol_block=max_block)
594 nloc = qs_loc_env%localized_wfn_control%nloc_states(ispin)
595 IF (rst_unit > 0)
THEN
596 WRITE (rst_unit) qs_loc_env%localized_wfn_control%loc_states(1:nloc, ispin)
597 IF (do_homo .OR. my_do_mixed)
THEN
598 WRITE (rst_unit) nmo, &
599 mo_array(ispin)%homo, &
600 mo_array(ispin)%lfomo, &
601 mo_array(ispin)%nelectron
602 WRITE (rst_unit) mo_array(ispin)%eigenvalues(1:nmo), &
603 mo_array(ispin)%occupation_numbers(1:nmo)
606 WRITE (rst_unit) evals(ispin)%array(1:nmo)
621 CALL timestop(handle)
638 SUBROUTINE loc_read_restart(qs_loc_env, mos, mos_localized, section, section2, para_env, &
639 do_homo, restart_found, evals, do_mixed)
641 TYPE(qs_loc_env_type),
POINTER :: qs_loc_env
642 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos
643 TYPE(cp_fm_type),
DIMENSION(:),
INTENT(INOUT) :: mos_localized
644 TYPE(section_vals_type),
POINTER :: section, section2
645 TYPE(mp_para_env_type),
POINTER :: para_env
646 LOGICAL,
INTENT(IN) :: do_homo
647 LOGICAL,
INTENT(INOUT) :: restart_found
648 TYPE(cp_1d_r_p_type),
DIMENSION(:),
OPTIONAL, &
650 LOGICAL,
INTENT(IN),
OPTIONAL :: do_mixed
652 CHARACTER(len=*),
PARAMETER :: routinen =
'loc_read_restart'
654 CHARACTER(LEN=25) :: fname_key
655 CHARACTER(LEN=default_path_length) :: filename
656 CHARACTER(LEN=default_string_length) :: my_middle
657 INTEGER :: handle, homo_read, i, ispin, lfomo_read, max_nloc, n_rep_val, nao, &
658 nelectron_read, nloc, nmo, nmo_read, nspin, output_unit, rst_unit
659 LOGICAL :: file_exists, my_do_mixed
660 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: eig_read, occ_read
661 REAL(kind=dp),
DIMENSION(:, :),
POINTER :: vecbuffer
662 TYPE(cp_logger_type),
POINTER :: logger
663 TYPE(section_vals_type),
POINTER :: print_key
665 CALL timeset(routinen, handle)
667 logger => cp_get_default_logger()
669 nspin =
SIZE(mos_localized)
673 output_unit = cp_print_key_unit_nr(logger, section2, &
674 "PROGRAM_RUN_INFO", extension=
".Log")
676 my_do_mixed = .false.
677 IF (
PRESENT(do_mixed)) my_do_mixed = do_mixed
679 fname_key =
"LOCHOMO_RESTART_FILE_NAME"
680 ELSE IF (my_do_mixed)
THEN
681 fname_key =
"LOCMIXD_RESTART_FILE_NAME"
683 fname_key =
"LOCLUMO_RESTART_FILE_NAME"
684 IF (.NOT.
PRESENT(evals))
THEN
685 cpabort(
"Missing argument to localize unoccupied states.")
689 file_exists = .false.
690 CALL section_vals_val_get(section, fname_key, n_rep_val=n_rep_val)
691 IF (n_rep_val > 0)
THEN
692 CALL section_vals_val_get(section, fname_key, c_val=filename)
695 print_key => section_vals_get_subs_vals(section2,
"LOC_RESTART")
697 my_middle =
"LOC_HOMO"
698 ELSE IF (my_do_mixed)
THEN
699 my_middle =
"LOC_MIXED"
701 my_middle =
"LOC_LUMO"
703 filename = cp_print_key_generate_filename(logger, print_key, &
704 middle_name=trim(my_middle), extension=
".wfn", &
708 IF (para_env%is_source())
INQUIRE (file=filename, exist=file_exists)
710 IF (file_exists)
THEN
711 IF (para_env%is_source())
THEN
712 CALL open_file(file_name=filename, &
713 file_action=
"READ", &
714 file_form=
"UNFORMATTED", &
716 unit_number=rst_unit)
718 READ (rst_unit) qs_loc_env%localized_wfn_control%set_of_states
719 READ (rst_unit) qs_loc_env%localized_wfn_control%lu_bound_states
720 READ (rst_unit) qs_loc_env%localized_wfn_control%nloc_states
723 IF (output_unit > 0)
THEN
724 WRITE (output_unit,
"(/,T10,A)") &
725 "Restart file not available filename=<"//trim(filename)//
'>'
728 CALL para_env%bcast(file_exists)
730 IF (file_exists)
THEN
731 restart_found = .true.
733 CALL para_env%bcast(qs_loc_env%localized_wfn_control%set_of_states)
734 CALL para_env%bcast(qs_loc_env%localized_wfn_control%lu_bound_states)
735 CALL para_env%bcast(qs_loc_env%localized_wfn_control%nloc_states)
737 max_nloc = maxval(qs_loc_env%localized_wfn_control%nloc_states(:))
739 ALLOCATE (vecbuffer(1, nao))
740 IF (
ASSOCIATED(qs_loc_env%localized_wfn_control%loc_states))
THEN
741 DEALLOCATE (qs_loc_env%localized_wfn_control%loc_states)
743 ALLOCATE (qs_loc_env%localized_wfn_control%loc_states(max_nloc, 2))
744 qs_loc_env%localized_wfn_control%loc_states = 0
747 IF (do_homo .OR. do_mixed)
THEN
750 nmo =
SIZE(evals(ispin)%array, 1)
752 IF (para_env%is_source() .AND. (nmo > 0))
THEN
753 nloc = qs_loc_env%localized_wfn_control%nloc_states(ispin)
754 READ (rst_unit) qs_loc_env%localized_wfn_control%loc_states(1:nloc, ispin)
755 IF (do_homo .OR. do_mixed)
THEN
756 READ (rst_unit) nmo_read, homo_read, lfomo_read, nelectron_read
757 ALLOCATE (eig_read(nmo_read), occ_read(nmo_read))
760 READ (rst_unit) eig_read(1:nmo_read), occ_read(1:nmo_read)
762 READ (rst_unit) nmo_read
763 ALLOCATE (eig_read(nmo_read))
765 READ (rst_unit) eig_read(1:nmo_read)
767 IF (nmo_read < nmo)
THEN
768 CALL cp_warn(__location__, &
769 "The number of MOs on the restart unit is smaller than the number of "// &
770 "the allocated MOs. ")
772 IF (nmo_read > nmo)
THEN
773 CALL cp_warn(__location__, &
774 "The number of MOs on the restart unit is greater than the number of "// &
775 "the allocated MOs. The read MO set will be truncated!")
778 nmo = min(nmo, nmo_read)
779 IF (do_homo .OR. do_mixed)
THEN
780 mos(ispin)%eigenvalues(1:nmo) = eig_read(1:nmo)
781 mos(ispin)%occupation_numbers(1:nmo) = occ_read(1:nmo)
782 DEALLOCATE (eig_read, occ_read)
784 evals(ispin)%array(1:nmo) = eig_read(1:nmo)
785 DEALLOCATE (eig_read)
789 IF (do_homo .OR. do_mixed)
THEN
790 CALL para_env%bcast(mos(ispin)%eigenvalues)
791 CALL para_env%bcast(mos(ispin)%occupation_numbers)
793 CALL para_env%bcast(evals(ispin)%array)
797 IF (para_env%is_source())
THEN
798 READ (rst_unit) vecbuffer
800 vecbuffer(1, :) = 0.0_dp
802 CALL para_env%bcast(vecbuffer)
803 CALL cp_fm_set_submatrix(mos_localized(ispin), &
804 vecbuffer, 1, i, nao, 1, transpose=.true.)
808 CALL para_env%bcast(qs_loc_env%localized_wfn_control%loc_states)
810 DEALLOCATE (vecbuffer)
815 IF (para_env%is_source())
THEN
816 IF (file_exists)
CALL close_file(unit_number=rst_unit)
819 CALL timestop(handle)
821 END SUBROUTINE loc_read_restart
836 do_xas, nloc_xas, spin_xas)
838 TYPE(qs_loc_env_type),
POINTER :: qs_loc_env
839 TYPE(section_vals_type),
POINTER :: loc_section
840 LOGICAL,
INTENT(IN) :: do_homo
841 LOGICAL,
INTENT(IN),
OPTIONAL :: do_mixed, do_xas
842 INTEGER,
INTENT(IN),
OPTIONAL :: nloc_xas, spin_xas
844 LOGICAL :: my_do_mixed
845 TYPE(localized_wfn_control_type),
POINTER :: localized_wfn_control
847 NULLIFY (localized_wfn_control)
849 IF (
PRESENT(do_mixed))
THEN
850 my_do_mixed = do_mixed
852 my_do_mixed = .false.
854 CALL localized_wfn_control_create(localized_wfn_control)
855 CALL set_qs_loc_env(qs_loc_env, localized_wfn_control=localized_wfn_control)
856 CALL localized_wfn_control_release(localized_wfn_control)
857 CALL get_qs_loc_env(qs_loc_env, localized_wfn_control=localized_wfn_control)
858 localized_wfn_control%do_homo = do_homo
859 localized_wfn_control%do_mixed = my_do_mixed
860 CALL read_loc_section(localized_wfn_control, loc_section, qs_loc_env%do_localize, &
861 my_do_mixed, do_xas, nloc_xas, spin_xas)
878 SUBROUTINE qs_loc_init(qs_env, qs_loc_env, localize_section, mos_localized, &
879 do_homo, do_mo_cubes, mo_loc_history, evals, &
880 tot_zeff_corr, do_mixed)
882 TYPE(qs_environment_type),
POINTER :: qs_env
883 TYPE(qs_loc_env_type),
POINTER :: qs_loc_env
884 TYPE(section_vals_type),
POINTER :: localize_section
885 TYPE(cp_fm_type),
DIMENSION(:),
INTENT(INOUT) :: mos_localized
886 LOGICAL,
OPTIONAL :: do_homo, do_mo_cubes
887 TYPE(cp_fm_type),
DIMENSION(:),
OPTIONAL,
POINTER :: mo_loc_history
888 TYPE(cp_1d_r_p_type),
DIMENSION(:),
OPTIONAL, &
890 REAL(kind=dp),
INTENT(IN),
OPTIONAL :: tot_zeff_corr
891 LOGICAL,
OPTIONAL :: do_mixed
893 CHARACTER(len=*),
PARAMETER :: routinen =
'qs_loc_init'
895 INTEGER :: handle, homo, i, ilast_intocc, ilow, ispin, iup, n_mo(2), n_mos(2), nao, &
896 nelectron, nextra, nmoloc(2), nocc, npocc, nspin, output_unit
897 LOGICAL :: my_do_homo, my_do_mixed, my_do_mo_cubes, &
899 REAL(kind=dp) :: maxocc, my_tot_zeff_corr
900 REAL(kind=dp),
DIMENSION(:),
POINTER :: mo_eigenvalues, occupation
901 TYPE(cp_fm_type),
POINTER :: mo_coeff
902 TYPE(cp_logger_type),
POINTER :: logger
903 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: ks_rmpv, mo_derivs
904 TYPE(dft_control_type),
POINTER :: dft_control
905 TYPE(localized_wfn_control_type),
POINTER :: localized_wfn_control
906 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos
907 TYPE(mp_para_env_type),
POINTER :: para_env
908 TYPE(scf_control_type),
POINTER :: scf_control
909 TYPE(section_vals_type),
POINTER :: loc_print_section
911 CALL timeset(routinen, handle)
913 NULLIFY (mos, mo_coeff, mo_eigenvalues, occupation, ks_rmpv, mo_derivs, scf_control, para_env)
914 CALL get_qs_env(qs_env, &
917 mo_derivs=mo_derivs, &
918 scf_control=scf_control, &
919 dft_control=dft_control, &
922 loc_print_section => section_vals_get_subs_vals(localize_section,
"PRINT")
924 logger => cp_get_default_logger()
925 output_unit = cp_logger_get_default_io_unit(logger)
928 IF (
PRESENT(do_homo))
THEN
933 IF (
PRESENT(do_mo_cubes))
THEN
934 my_do_mo_cubes = do_mo_cubes
936 my_do_mo_cubes = .false.
938 IF (
PRESENT(do_mixed))
THEN
939 my_do_mixed = do_mixed
941 my_do_mixed = .false.
943 IF (
PRESENT(tot_zeff_corr))
THEN
944 my_tot_zeff_corr = tot_zeff_corr
946 my_tot_zeff_corr = 0.0_dp
948 restart_found = .false.
950 IF (qs_loc_env%do_localize)
THEN
952 CALL get_qs_loc_env(qs_loc_env, localized_wfn_control=localized_wfn_control)
953 IF (localized_wfn_control%loc_restart)
THEN
954 IF (localized_wfn_control%nextra > 0)
THEN
958 CALL loc_read_restart(qs_loc_env, mos, mos_localized, localize_section, &
959 loc_print_section, para_env, my_do_homo, restart_found, evals=evals, &
960 do_mixed=my_do_mixed)
961 IF (output_unit > 0)
WRITE (output_unit,
"(/,T2,A,A)")
"LOCALIZATION| ", &
962 " The orbitals to be localized are read from localization restart file."
963 nmoloc = localized_wfn_control%nloc_states
964 localized_wfn_control%nguess = nmoloc
965 IF (localized_wfn_control%nextra > 0)
THEN
968 localized_wfn_control%loc_restart = restart_found
969 localized_wfn_control%set_of_states = state_loc_mixed
971 CALL get_mo_set(mos(ispin), homo=homo, occupation_numbers=occupation, &
973 nextra = localized_wfn_control%nextra
976 IF (maxocc - occupation(i) < localized_wfn_control%eps_occ)
THEN
983 nmoloc(ispin) = nocc + nextra
984 localized_wfn_control%lu_bound_states(1, ispin) = 1
985 localized_wfn_control%lu_bound_states(2, ispin) = nmoloc(ispin)
986 localized_wfn_control%nloc_states(ispin) = nmoloc(ispin)
991 IF (.NOT. restart_found)
THEN
994 CALL get_mo_set(mos(ispin), nmo=n_mo(ispin), nelectron=nelectron, homo=homo, nao=nao, &
995 mo_coeff=mo_coeff, eigenvalues=mo_eigenvalues, occupation_numbers=occupation, &
998 IF ((.NOT. my_do_mo_cubes) &
999 .AND. my_do_homo .AND.
ASSOCIATED(qs_env%scf_env) &
1000 .AND. qs_env%scf_env%method == ot_method_nr .AND. (.NOT. dft_control%restricted))
THEN
1001 CALL make_mo_eig(mos, nspin, ks_rmpv, scf_control, mo_derivs)
1003 IF (localized_wfn_control%set_of_states == state_loc_all .AND. my_do_homo)
THEN
1004 nmoloc(ispin) = nint(nelectron/occupation(1))
1005 IF (n_mo(ispin) > homo)
THEN
1006 DO i = nmoloc(ispin), 1, -1
1007 IF (occupation(1) - occupation(i) < localized_wfn_control%eps_occ)
THEN
1013 ilast_intocc = nmoloc(ispin)
1015 nmoloc(ispin) = ilast_intocc
1016 localized_wfn_control%lu_bound_states(1, ispin) = 1
1017 localized_wfn_control%lu_bound_states(2, ispin) = ilast_intocc
1018 IF (nmoloc(ispin) /= n_mo(ispin))
THEN
1019 IF (output_unit > 0)
THEN
1020 WRITE (output_unit,
"(/,T2,A,I4,A,I6,A,/,T15,A,F12.6,A,F12.6,A)") &
1021 "LOCALIZATION| Spin ", ispin,
" The first ", &
1022 ilast_intocc,
" occupied orbitals are localized,",
" with energies from ", &
1023 mo_eigenvalues(1),
" to ", mo_eigenvalues(ilast_intocc),
" [a.u.]."
1026 ELSE IF (localized_wfn_control%set_of_states == energy_loc_range .AND. my_do_homo)
THEN
1029 DO i = 1, n_mo(ispin)
1030 IF (mo_eigenvalues(i) >= localized_wfn_control%lu_ene_bound(1))
THEN
1035 DO i = n_mo(ispin), 1, -1
1036 IF (mo_eigenvalues(i) <= localized_wfn_control%lu_ene_bound(2))
THEN
1041 localized_wfn_control%lu_bound_states(1, ispin) = ilow
1042 localized_wfn_control%lu_bound_states(2, ispin) = iup
1043 localized_wfn_control%nloc_states(ispin) = iup - ilow + 1
1044 nmoloc(ispin) = localized_wfn_control%nloc_states(ispin)
1045 IF (occupation(ilow) - occupation(iup) > localized_wfn_control%eps_occ)
THEN
1046 CALL cp_abort(__location__, &
1047 "The selected energy range includes orbitals with different occupation number. "// &
1048 "The localization procedure cannot be applied.")
1050 IF (output_unit > 0)
WRITE (output_unit,
"(/,T2,A,I4,A,I6,A)")
"LOCALIZATION| Spin ", ispin,
" : ", &
1051 nmoloc(ispin),
" orbitals in the selected energy range are localized."
1052 ELSE IF (localized_wfn_control%set_of_states == state_loc_all .AND. (.NOT. my_do_homo))
THEN
1053 nmoloc(ispin) = n_mo(ispin) - homo
1054 localized_wfn_control%lu_bound_states(1, ispin) = homo + 1
1055 localized_wfn_control%lu_bound_states(2, ispin) = n_mo(ispin)
1056 IF (output_unit > 0)
THEN
1057 WRITE (output_unit,
"(/,T2,A,I4,A,I6,A,/,T15,A,F12.6,A,F12.6,A)") &
1058 "LOCALIZATION| Spin ", ispin,
" The first ", &
1059 nmoloc(ispin),
" virtual orbitals are localized,",
" with energies from ", &
1060 mo_eigenvalues(homo + 1),
" to ", mo_eigenvalues(n_mo(ispin)),
" [a.u.]."
1062 ELSE IF (localized_wfn_control%set_of_states == state_loc_mixed)
THEN
1063 nextra = localized_wfn_control%nextra
1066 IF (maxocc - occupation(i) < localized_wfn_control%eps_occ)
THEN
1073 nmoloc(ispin) = nocc + nextra
1074 localized_wfn_control%lu_bound_states(1, ispin) = 1
1075 localized_wfn_control%lu_bound_states(2, ispin) = nmoloc(ispin)
1076 IF (output_unit > 0)
THEN
1077 WRITE (output_unit,
"(/,T2,A,I4,A,I6,A,/,T15,A,I6,/,T15,A,I6,/,T15,A,I6,/,T15,A,F12.6,A)") &
1078 "LOCALIZATION| Spin ", ispin,
" The first ", &
1079 nmoloc(ispin),
" orbitals are localized.", &
1080 "Number of fully occupied MOs: ", nocc, &
1081 "Number of partially occupied MOs: ", npocc, &
1082 "Number of extra degrees of freedom: ", nextra, &
1083 "Excess charge: ", my_tot_zeff_corr,
" electrons"
1086 nmoloc(ispin) = min(localized_wfn_control%nloc_states(1), n_mo(ispin))
1087 IF (output_unit > 0 .AND. my_do_homo)
WRITE (output_unit,
"(/,T2,A,I4,A,I6,A)")
"LOCALIZATION| Spin ", ispin, &
1088 " : ", nmoloc(ispin),
" occupied orbitals are localized, as given in the input list."
1089 IF (output_unit > 0 .AND. (.NOT. my_do_homo))
WRITE (output_unit,
"(/,T2,A,I4,A,I6,A)")
"LOCALIZATION| Spin ", &
1090 ispin,
" : ", nmoloc(ispin),
" unoccupied orbitals are localized, as given in the input list."
1091 IF (n_mo(ispin) > homo .AND. my_do_homo)
THEN
1092 ilow = localized_wfn_control%loc_states(1, ispin)
1093 DO i = 2, nmoloc(ispin)
1094 iup = localized_wfn_control%loc_states(i, ispin)
1095 IF (abs(occupation(ilow) - occupation(iup)) > localized_wfn_control%eps_occ)
THEN
1097 CALL cp_warn(__location__, &
1098 "User requested the calculation of localized wavefunction from a subset of MOs, "// &
1099 "including MOs with different occupations. Check the selected subset, "// &
1100 "the electronic density is not invariant with "// &
1101 "respect to rotations among orbitals with different occupation numbers!")
1107 n_mos(:) = nao - n_mo(:)
1108 IF (my_do_homo .OR. my_do_mixed) n_mos = n_mo
1112 IF (my_do_homo .OR. my_do_mixed)
THEN
1114 loc_coeff=mos_localized, mo_loc_history=mo_loc_history)
1118 CALL cp_warn(__location__, &
1119 "User requested the calculation of the localized wavefunction but the section "// &
1120 "LOCALIZE was not specified. Localization will not be performed!")
1123 CALL timestop(handle)
1139 SUBROUTINE read_loc_section(localized_wfn_control, loc_section, &
1140 localize, do_mixed, do_xas, nloc_xas, spin_channel_xas)
1142 TYPE(localized_wfn_control_type),
POINTER :: localized_wfn_control
1143 TYPE(section_vals_type),
POINTER :: loc_section
1144 LOGICAL,
INTENT(OUT) :: localize
1145 LOGICAL,
INTENT(IN),
OPTIONAL :: do_mixed, do_xas
1146 INTEGER,
INTENT(IN),
OPTIONAL :: nloc_xas, spin_channel_xas
1148 INTEGER :: i, ind, ir, n_list, n_rep, n_state, &
1149 nextra, nline, other_spin, &
1150 output_unit, spin_xas
1151 INTEGER,
DIMENSION(:),
POINTER ::
list, loc_list
1152 LOGICAL :: my_do_mixed, my_do_xas
1153 REAL(dp),
POINTER :: ene(:)
1154 TYPE(cp_logger_type),
POINTER :: logger
1155 TYPE(section_vals_type),
POINTER :: loc_print_section
1159 IF (
PRESENT(do_xas))
THEN
1161 cpassert(
PRESENT(nloc_xas))
1163 IF (
PRESENT(spin_channel_xas)) spin_xas = spin_channel_xas
1164 my_do_mixed = .false.
1165 IF (
PRESENT(do_mixed))
THEN
1166 my_do_mixed = do_mixed
1168 cpassert(
ASSOCIATED(loc_section))
1170 logger => cp_get_default_logger()
1172 CALL section_vals_val_get(loc_section,
"_SECTION_PARAMETERS_", l_val=localize)
1174 loc_print_section => section_vals_get_subs_vals(loc_section,
"PRINT")
1177 localized_wfn_control%lu_bound_states = 0
1178 localized_wfn_control%lu_ene_bound = 0.0_dp
1179 localized_wfn_control%nloc_states = 0
1180 localized_wfn_control%set_of_states = 0
1181 localized_wfn_control%nextra = 0
1184 CALL section_vals_val_get(loc_section,
"MAX_ITER", &
1185 i_val=localized_wfn_control%max_iter)
1186 CALL section_vals_val_get(loc_section,
"MAX_CRAZY_ANGLE", &
1187 r_val=localized_wfn_control%max_crazy_angle)
1188 CALL section_vals_val_get(loc_section,
"CRAZY_SCALE", &
1189 r_val=localized_wfn_control%crazy_scale)
1190 CALL section_vals_val_get(loc_section,
"EPS_OCCUPATION", &
1191 r_val=localized_wfn_control%eps_occ)
1192 CALL section_vals_val_get(loc_section,
"CRAZY_USE_DIAG", &
1193 l_val=localized_wfn_control%crazy_use_diag)
1194 CALL section_vals_val_get(loc_section,
"OUT_ITER_EACH", &
1195 i_val=localized_wfn_control%out_each)
1196 CALL section_vals_val_get(loc_section,
"EPS_LOCALIZATION", &
1197 r_val=localized_wfn_control%eps_localization)
1198 CALL section_vals_val_get(loc_section,
"MIN_OR_MAX", &
1199 i_val=localized_wfn_control%min_or_max)
1200 CALL section_vals_val_get(loc_section,
"JACOBI_FALLBACK", &
1201 l_val=localized_wfn_control%jacobi_fallback)
1202 CALL section_vals_val_get(loc_section,
"JACOBI_REFINEMENT", &
1203 l_val=localized_wfn_control%jacobi_refinement)
1204 CALL section_vals_val_get(loc_section,
"METHOD", &
1205 i_val=localized_wfn_control%localization_method)
1206 CALL section_vals_val_get(loc_section,
"OPERATOR", &
1207 i_val=localized_wfn_control%operator_type)
1208 CALL section_vals_val_get(loc_section,
"RESTART", &
1209 l_val=localized_wfn_control%loc_restart)
1210 CALL section_vals_val_get(loc_section,
"USE_HISTORY", &
1211 l_val=localized_wfn_control%use_history)
1212 CALL section_vals_val_get(loc_section,
"NEXTRA", &
1213 i_val=localized_wfn_control%nextra)
1214 CALL section_vals_val_get(loc_section,
"CPO_GUESS", &
1215 i_val=localized_wfn_control%coeff_po_guess)
1216 CALL section_vals_val_get(loc_section,
"CPO_GUESS_SPACE", &
1217 i_val=localized_wfn_control%coeff_po_guess_mo_space)
1218 CALL section_vals_val_get(loc_section,
"CG_PO", &
1219 l_val=localized_wfn_control%do_cg_po)
1221 IF (localized_wfn_control%do_homo)
THEN
1223 CALL section_vals_val_get(loc_section,
"LIST", n_rep_val=n_rep)
1228 CALL section_vals_val_get(loc_section,
"LIST", i_rep_val=ir, i_vals=
list)
1229 IF (
ASSOCIATED(
list))
THEN
1230 CALL reallocate(loc_list, 1, n_list +
SIZE(
list))
1231 DO i = 1,
SIZE(
list)
1232 loc_list(n_list + i) =
list(i)
1234 n_list = n_list +
SIZE(
list)
1237 IF (n_list /= 0)
THEN
1238 localized_wfn_control%set_of_states = state_loc_list
1239 ALLOCATE (localized_wfn_control%loc_states(n_list, 2))
1240 localized_wfn_control%loc_states = 0
1241 localized_wfn_control%loc_states(:, 1) = loc_list(:)
1242 localized_wfn_control%loc_states(:, 2) = loc_list(:)
1243 localized_wfn_control%nloc_states(1) = n_list
1244 localized_wfn_control%nloc_states(2) = n_list
1247 IF (spin_xas == 2) other_spin = 1
1248 localized_wfn_control%nloc_states(other_spin) = 0
1249 localized_wfn_control%loc_states(:, other_spin) = 0
1251 DEALLOCATE (loc_list)
1257 CALL section_vals_val_get(loc_section,
"LIST_UNOCCUPIED", n_rep_val=n_rep)
1262 CALL section_vals_val_get(loc_section,
"LIST_UNOCCUPIED", i_rep_val=ir, i_vals=
list)
1263 IF (
ASSOCIATED(
list))
THEN
1264 CALL reallocate(loc_list, 1, n_list +
SIZE(
list))
1265 DO i = 1,
SIZE(
list)
1266 loc_list(n_list + i) =
list(i)
1268 n_list = n_list +
SIZE(
list)
1271 IF (n_list /= 0)
THEN
1272 localized_wfn_control%set_of_states = state_loc_list
1273 ALLOCATE (localized_wfn_control%loc_states(n_list, 2))
1274 localized_wfn_control%loc_states = 0
1275 localized_wfn_control%loc_states(:, 1) = loc_list(:)
1276 localized_wfn_control%loc_states(:, 2) = loc_list(:)
1277 localized_wfn_control%nloc_states(1) = n_list
1278 DEALLOCATE (loc_list)
1283 IF (localized_wfn_control%set_of_states == 0)
THEN
1284 CALL section_vals_val_get(loc_section,
"ENERGY_RANGE", r_vals=ene)
1285 IF (ene(1) /= ene(2))
THEN
1286 localized_wfn_control%set_of_states = energy_loc_range
1287 localized_wfn_control%lu_ene_bound(1) = ene(1)
1288 localized_wfn_control%lu_ene_bound(2) = ene(2)
1293 IF (localized_wfn_control%set_of_states == 0)
THEN
1295 localized_wfn_control%set_of_states = state_loc_range
1296 localized_wfn_control%nloc_states(:) = 0
1297 localized_wfn_control%lu_bound_states(1, :) = 0
1298 localized_wfn_control%lu_bound_states(2, :) = 0
1299 localized_wfn_control%nloc_states(spin_xas) = nloc_xas
1300 localized_wfn_control%lu_bound_states(1, spin_xas) = 1
1301 localized_wfn_control%lu_bound_states(2, spin_xas) = nloc_xas
1302 ELSE IF (my_do_mixed)
THEN
1303 localized_wfn_control%set_of_states = state_loc_mixed
1304 nextra = localized_wfn_control%nextra
1306 localized_wfn_control%set_of_states = state_loc_all
1310 localized_wfn_control%print_centers = &
1311 btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
1312 "WANNIER_CENTERS"), cp_p_file)
1313 localized_wfn_control%print_spreads = &
1314 btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
1315 "WANNIER_SPREADS"), cp_p_file)
1316 localized_wfn_control%print_cubes = &
1317 btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
1318 "WANNIER_CUBES"), cp_p_file)
1320 output_unit = cp_print_key_unit_nr(logger, loc_print_section,
"PROGRAM_RUN_INFO", &
1323 IF (output_unit > 0)
THEN
1324 WRITE (unit=output_unit, fmt=
"(/,T2,A)") &
1325 "LOCALIZE| The spread relative to a set of orbitals is computed"
1327 SELECT CASE (localized_wfn_control%set_of_states)
1328 CASE (state_loc_all)
1329 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1330 "LOCALIZE| Orbitals to be localized: All orbitals"
1331 WRITE (unit=output_unit, fmt=
"(T2,A,/,T12,A,F16.8)") &
1332 "LOCALIZE| If fractional occupation, fully occupied MOs are those ", &
1333 "within occupation tolerance of ", localized_wfn_control%eps_occ
1334 CASE (state_loc_range)
1335 WRITE (unit=output_unit, fmt=
"(T2,A,T65,I8,A,I8)") &
1336 "LOCALIZE| Orbitals to be localized: Those with index between ", &
1337 localized_wfn_control%lu_bound_states(1, spin_xas),
" and ", &
1338 localized_wfn_control%lu_bound_states(2, spin_xas)
1339 CASE (state_loc_list)
1340 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1341 "LOCALIZE| Orbitals to be localized: Those with index in the following list"
1342 nline = localized_wfn_control%nloc_states(1)/10 + 1
1345 IF (ind + 10 < localized_wfn_control%nloc_states(1))
THEN
1346 WRITE (unit=output_unit, fmt=
"(T8,10I7)") localized_wfn_control%loc_states(ind + 1:ind + 10, 1)
1349 WRITE (unit=output_unit, fmt=
"(T8,10I7)") &
1350 localized_wfn_control%loc_states(ind + 1:localized_wfn_control%nloc_states(1), 1)
1351 ind = localized_wfn_control%nloc_states(1)
1354 CASE (energy_loc_range)
1355 WRITE (unit=output_unit, fmt=
"(T2,A,T65,/,f16.6,A,f16.6,A)") &
1356 "LOCALIZE| Orbitals to be localized: Those with energy in the range between ", &
1357 localized_wfn_control%lu_ene_bound(1),
" and ", localized_wfn_control%lu_ene_bound(2),
" a.u."
1358 CASE (state_loc_mixed)
1359 WRITE (unit=output_unit, fmt=
"(T2,A,I4,A)") &
1360 "LOCALIZE| Orbitals to be localized: Occupied orbitals + ", nextra,
" orbitals"
1362 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1363 "LOCALIZE| Orbitals to be localized: None "
1366 SELECT CASE (localized_wfn_control%operator_type)
1368 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1369 "LOCALIZE| Spread defined by the Berry phase operator "
1371 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1372 "LOCALIZE| Spread defined by the Boys phase operator "
1374 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1375 "LOCALIZE| Spread defined by the Pipek phase operator "
1378 SELECT CASE (localized_wfn_control%localization_method)
1379 CASE (do_loc_jacobi)
1380 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1381 "LOCALIZE| Optimal unitary transformation generated by Jacobi algorithm"
1383 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1384 "LOCALIZE| Optimal unitary transformation generated by Crazy angle algorithm"
1385 WRITE (unit=output_unit, fmt=
"(T2,A,F16.8)") &
1386 "LOCALIZE| maximum angle: ", localized_wfn_control%max_crazy_angle
1387 WRITE (unit=output_unit, fmt=
"(T2,A,F16.8)") &
1388 "LOCALIZE| scaling: ", localized_wfn_control%crazy_scale
1389 WRITE (unit=output_unit, fmt=
"(T2,A,L1)") &
1390 "LOCALIZE| use diag:", localized_wfn_control%crazy_use_diag
1392 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1393 "LOCALIZE| Optimal unitary transformation generated by gradient ascent algorithm "
1394 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1395 "LOCALIZE| for partially occupied wannier functions"
1396 CASE (do_loc_direct)
1397 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1398 "LOCALIZE| Optimal unitary transformation generated by direct algorithm"
1399 CASE (do_loc_l1_norm_sd)
1400 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1401 "LOCALIZE| Optimal unitary transformation generated by "
1402 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1403 "LOCALIZE| steepest descent algorithm applied on an approximate l1 norm"
1405 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1406 "LOCALIZE| No unitary transformation is applied"
1408 WRITE (unit=output_unit, fmt=
"(T2,A)") &
1409 "LOCALIZE| Pivoted QR decomposition is used to transform coefficients"
1414 CALL cp_print_key_finished_output(output_unit, logger, loc_print_section,
"PROGRAM_RUN_INFO")
1417 localized_wfn_control%localization_method = do_loc_none
1418 localized_wfn_control%localization_method = state_loc_none
1419 localized_wfn_control%print_centers = .false.
1420 localized_wfn_control%print_spreads = .false.
1421 localized_wfn_control%print_cubes = .false.
1424 END SUBROUTINE read_loc_section
1436 TYPE(localized_wfn_control_type) :: localized_wfn_control
1437 INTEGER,
DIMENSION(2),
INTENT(IN) :: nmoloc
1438 INTEGER,
INTENT(IN) :: nspins
1442 DO ispin = 1, nspins
1443 ALLOCATE (localized_wfn_control%centers_set(ispin)%array(6, nmoloc(ispin)))
1444 localized_wfn_control%centers_set(ispin)%array = 0.0_dp
1461 TYPE(localized_wfn_control_type) :: localized_wfn_control
1462 INTEGER,
DIMENSION(2),
INTENT(IN) :: nmoloc, nmo
1463 INTEGER,
INTENT(IN) :: nspins
1464 INTEGER,
INTENT(IN),
OPTIONAL :: my_spin
1466 CHARACTER(len=*),
PARAMETER :: routinen =
'set_loc_wfn_lists'
1468 INTEGER :: i, ispin, max_iloc, max_nmoloc, state
1470 CALL timeset(routinen, state)
1472 localized_wfn_control%nloc_states(1:2) = nmoloc(1:2)
1473 max_nmoloc = max(nmoloc(1), nmoloc(2))
1475 SELECT CASE (localized_wfn_control%set_of_states)
1476 CASE (state_loc_list)
1478 cpassert(
ASSOCIATED(localized_wfn_control%loc_states))
1479 DO ispin = 1, nspins
1480 localized_wfn_control%lu_bound_states(1, ispin) = 1
1481 localized_wfn_control%lu_bound_states(2, ispin) = nmoloc(ispin)
1482 IF (nmoloc(ispin) < 1)
THEN
1483 localized_wfn_control%lu_bound_states(1, ispin) = 0
1484 localized_wfn_control%loc_states(:, ispin) = 0
1487 CASE (state_loc_range)
1489 ALLOCATE (localized_wfn_control%loc_states(max_nmoloc, 2))
1490 localized_wfn_control%loc_states = 0
1491 DO ispin = 1, nspins
1492 localized_wfn_control%lu_bound_states(1, ispin) = &
1493 localized_wfn_control%lu_bound_states(1, my_spin)
1494 localized_wfn_control%lu_bound_states(2, ispin) = &
1495 localized_wfn_control%lu_bound_states(1, my_spin) + nmoloc(ispin) - 1
1496 max_iloc = localized_wfn_control%lu_bound_states(2, ispin)
1497 DO i = 1, nmoloc(ispin)
1498 localized_wfn_control%loc_states(i, ispin) = localized_wfn_control%lu_bound_states(1, ispin) + i - 1
1500 cpassert(max_iloc <= nmo(ispin))
1503 CASE (energy_loc_range)
1505 ALLOCATE (localized_wfn_control%loc_states(max_nmoloc, 2))
1506 localized_wfn_control%loc_states = 0
1507 DO ispin = 1, nspins
1508 DO i = 1, nmoloc(ispin)
1509 localized_wfn_control%loc_states(i, ispin) = localized_wfn_control%lu_bound_states(1, ispin) + i - 1
1512 CASE (state_loc_all)
1514 ALLOCATE (localized_wfn_control%loc_states(max_nmoloc, 2))
1515 localized_wfn_control%loc_states = 0
1517 IF (localized_wfn_control%lu_bound_states(1, 1) == 1)
THEN
1518 DO ispin = 1, nspins
1519 localized_wfn_control%lu_bound_states(1, ispin) = 1
1520 localized_wfn_control%lu_bound_states(2, ispin) = nmoloc(ispin)
1521 IF (nmoloc(ispin) < 1) localized_wfn_control%lu_bound_states(1, ispin) = 0
1522 DO i = 1, nmoloc(ispin)
1523 localized_wfn_control%loc_states(i, ispin) = i
1527 DO ispin = 1, nspins
1528 IF (nmoloc(ispin) < 1) localized_wfn_control%lu_bound_states(1, ispin) = 0
1529 DO i = 1, nmoloc(ispin)
1530 localized_wfn_control%loc_states(i, ispin) = &
1531 localized_wfn_control%lu_bound_states(1, ispin) + i - 1
1535 CASE (state_loc_mixed)
1537 ALLOCATE (localized_wfn_control%loc_states(max_nmoloc, 2))
1538 localized_wfn_control%loc_states = 0
1539 DO ispin = 1, nspins
1540 DO i = 1, nmoloc(ispin)
1541 localized_wfn_control%loc_states(i, ispin) = i
1546 CALL timestop(state)
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)
...
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_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
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,...
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.
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, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
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 reciprocal-space operators used by Berry localization. The operators contain the contrac...
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, hairy_probes, probe)
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, cmo_coeff)
Get the components of a MO set data structure.
subroutine, public build_exp_ikr_matrix(qs_env, op_sm_set, kvec, sab_orb_external, basis_type, force_periodic, cell_external)
Build real and imaginary AO matrices for exp(i*k*r).
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
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...