102#include "./base/base_uses.f90"
108 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'almo_scf'
112 LOGICAL,
PARAMETER :: debug_mode = .false.
113 LOGICAL,
PARAMETER :: safe_mode = .false.
127 LOGICAL,
INTENT(IN) :: calc_forces
129 CHARACTER(len=*),
PARAMETER :: routinen =
'almo_entry_scf'
134 CALL timeset(routinen, handle)
139 CALL get_qs_env(qs_env, almo_scf_env=almo_scf_env)
142 CALL almo_scf_init(qs_env, almo_scf_env, calc_forces)
145 CALL almo_scf_initial_guess(qs_env, almo_scf_env)
148 CALL almo_scf_main(qs_env, almo_scf_env)
151 CALL almo_scf_delocalization(qs_env, almo_scf_env)
154 CALL construct_nlmos(qs_env, almo_scf_env)
160 CALL almo_scf_post(qs_env, almo_scf_env)
163 CALL almo_scf_clean_up(almo_scf_env)
165 CALL timestop(handle)
179 SUBROUTINE almo_scf_init(qs_env, almo_scf_env, calc_forces)
182 LOGICAL,
INTENT(IN) :: calc_forces
184 CHARACTER(len=*),
PARAMETER :: routinen =
'almo_scf_init'
186 INTEGER :: ao, handle, i, iao, idomain, ispin, &
187 multip, naos, natoms, ndomains, nelec, &
188 nelec_a, nelec_b, nmols, nspins, &
196 CALL timeset(routinen, handle)
200 IF (logger%para_env%is_source())
THEN
208 almo_scf_env%opt_block_diag_pcg%optimizer_type =
optimizer_pcg
218 nelectron_total=almo_scf_env%nelectrons_total, &
220 dft_control=dft_control, &
221 molecule_set=molecule_set, &
223 has_unit_metric=almo_scf_env%orthogonal_basis, &
224 para_env=almo_scf_env%para_env, &
225 blacs_env=almo_scf_env%blacs_env, &
226 nelectron_spin=almo_scf_env%nelectrons_spin)
227 CALL almo_scf_env%para_env%retain()
228 CALL almo_scf_env%blacs_env%retain()
231 almo_scf_env%nspins = dft_control%nspins
232 almo_scf_env%nmolecules =
SIZE(molecule_set)
234 nfullrows_total=naos, nblkrows_total=almo_scf_env%natoms)
235 almo_scf_env%naos = naos
237 almo_scf_env%smear = dft_control%smear
238 IF (almo_scf_env%smear)
THEN
240 IF ((almo_scf_env%almo_update_algorithm /=
almo_scf_diag) .OR. &
242 (almo_scf_env%xalmo_update_algorithm /=
almo_scf_diag)))
THEN
243 cpabort(
"ALMO smearing is currently implemented for DIAG algorithm only")
246 cpabort(
"Only Fermi-Dirac smearing is currently compatible with ALMO")
248 almo_scf_env%smear_e_temp = qs_env%scf_control%smear%electronic_temperature
251 cpabort(
"ALMO smearing was designed to work with molecular fragments only")
256 nmols = almo_scf_env%nmolecules
257 natoms = almo_scf_env%natoms
261 almo_scf_env%ndomains = almo_scf_env%nmolecules
263 almo_scf_env%ndomains = almo_scf_env%natoms
266 IF (
ALLOCATED(almo_scf_env%activate) .AND. almo_scf_env%activate(1) > 1)
THEN
267 DEALLOCATE (almo_scf_env%activate)
270 IF (.NOT.
ALLOCATED(almo_scf_env%activate))
THEN
271 ALLOCATE (almo_scf_env%activate(1))
272 almo_scf_env%activate = 0
275 IF (almo_scf_env%activate(1) == 1)
THEN
277 ndomains =
SIZE(almo_scf_env%multiplicity_of_domain)
278 nspins =
SIZE(almo_scf_env%multiplicity_of_domain)
280 nspins = almo_scf_env%nspins
281 ndomains = almo_scf_env%ndomains
284 IF (almo_scf_env%activate(1) == 0)
THEN
286 ALLOCATE (almo_scf_env%charge_of_domain(ndomains))
287 ALLOCATE (almo_scf_env%multiplicity_of_domain(ndomains))
292 ALLOCATE (almo_scf_env%domain_index_of_atom(natoms))
293 ALLOCATE (almo_scf_env%domain_index_of_ao(naos))
294 ALLOCATE (almo_scf_env%first_atom_of_domain(ndomains))
295 ALLOCATE (almo_scf_env%last_atom_of_domain(ndomains))
296 ALLOCATE (almo_scf_env%nbasis_of_domain(ndomains))
297 ALLOCATE (almo_scf_env%nocc_of_domain(ndomains, nspins))
298 ALLOCATE (almo_scf_env%real_ne_of_domain(ndomains, nspins))
299 ALLOCATE (almo_scf_env%nvirt_full_of_domain(ndomains, nspins))
300 ALLOCATE (almo_scf_env%nvirt_of_domain(ndomains, nspins))
301 ALLOCATE (almo_scf_env%nvirt_disc_of_domain(ndomains, nspins))
302 ALLOCATE (almo_scf_env%mu_of_domain(ndomains, nspins))
303 ALLOCATE (almo_scf_env%cpu_of_domain(ndomains))
308 IF (almo_scf_env%activate(1) == 1)
THEN
310 atom_to_mol=almo_scf_env%domain_index_of_atom, &
311 mol_to_first_atom=almo_scf_env%first_atom_of_domain, &
312 mol_to_last_atom=almo_scf_env%last_atom_of_domain, &
313 mol_to_nelectrons=almo_scf_env%nocc_of_domain(1:ndomains, 1), &
314 mol_to_nbasis=almo_scf_env%nbasis_of_domain)
318 atom_to_mol=almo_scf_env%domain_index_of_atom, &
319 mol_to_first_atom=almo_scf_env%first_atom_of_domain, &
320 mol_to_last_atom=almo_scf_env%last_atom_of_domain, &
321 mol_to_nelectrons=almo_scf_env%nocc_of_domain(1:ndomains, 1), &
322 mol_to_nbasis=almo_scf_env%nbasis_of_domain, &
323 mol_to_charge=almo_scf_env%charge_of_domain, &
324 mol_to_multiplicity=almo_scf_env%multiplicity_of_domain)
330 DO idomain = 1, ndomains
331 IF (almo_scf_env%activate(1) == 1)
THEN
332 nelec = almo_scf_env%nocc_of_domain(idomain, 1) - almo_scf_env%charge_of_domain(idomain)
334 nelec = almo_scf_env%nocc_of_domain(idomain, 1)
337 multip = almo_scf_env%multiplicity_of_domain(idomain)
338 nelec_a = (nelec + multip - 1)/2
341 IF (almo_scf_env%smear)
THEN
342 cpwarn_if(multip > 1,
"BEWARE: Non singlet state detected, treating it as closed-shell")
345 almo_scf_env%real_ne_of_domain(idomain, :) = real(nelec, kind=
dp)/2.0_dp
348 almo_scf_env%nocc_of_domain(idomain, :) = ceiling(almo_scf_env%real_ne_of_domain(idomain, :)) &
349 + (almo_scf_env%last_atom_of_domain(idomain) &
350 - almo_scf_env%first_atom_of_domain(idomain) + 1)
352 almo_scf_env%nocc_of_domain(idomain, 1) = nelec_a
353 nelec_b = nelec - nelec_a
354 IF (almo_scf_env%activate(1) == 1)
THEN
355 almo_scf_env%nocc_of_domain(idomain, 2) = nelec_b
358 IF (nelec_a /= nelec_b)
THEN
359 IF (nspins == 1)
THEN
361 cpabort(
"odd e- -- use unrestricted methods")
369 almo_scf_env%nvirt_full_of_domain(:, ispin) = &
370 almo_scf_env%nbasis_of_domain(:) - &
371 almo_scf_env%nocc_of_domain(:, ispin)
373 SELECT CASE (almo_scf_env%deloc_truncate_virt)
375 almo_scf_env%nvirt_of_domain(:, ispin) = &
376 almo_scf_env%nvirt_full_of_domain(:, ispin)
377 almo_scf_env%nvirt_disc_of_domain(:, ispin) = 0
379 DO idomain = 1, ndomains
380 almo_scf_env%nvirt_of_domain(idomain, ispin) = &
381 min(almo_scf_env%deloc_virt_per_domain, &
382 almo_scf_env%nvirt_full_of_domain(idomain, ispin))
383 almo_scf_env%nvirt_disc_of_domain(idomain, ispin) = &
384 almo_scf_env%nvirt_full_of_domain(idomain, ispin) - &
385 almo_scf_env%nvirt_of_domain(idomain, ispin)
388 DO idomain = 1, ndomains
389 almo_scf_env%nvirt_of_domain(idomain, ispin) = &
390 min(almo_scf_env%nocc_of_domain(idomain, ispin), &
391 almo_scf_env%nvirt_full_of_domain(idomain, ispin))
392 almo_scf_env%nvirt_disc_of_domain(idomain, ispin) = &
393 almo_scf_env%nvirt_full_of_domain(idomain, ispin) - &
394 almo_scf_env%nvirt_of_domain(idomain, ispin)
397 cpabort(
"illegal method for virtual space truncation")
402 almo_scf_env%domain_index_of_atom(1:natoms) = [(i, i=1, natoms)]
406 DO idomain = 1, ndomains
407 DO iao = 1, almo_scf_env%nbasis_of_domain(idomain)
408 almo_scf_env%domain_index_of_ao(ao) = idomain
413 almo_scf_env%mu_of_domain(:, :) = almo_scf_env%mu
418 ALLOCATE (almo_scf_env%domain_index_of_ao_block(natoms))
419 almo_scf_env%domain_index_of_ao_block(:) = &
420 almo_scf_env%domain_index_of_atom(:)
422 ALLOCATE (almo_scf_env%domain_index_of_ao_block(nmols))
424 almo_scf_env%domain_index_of_ao_block(:) = [(i, i=1, nmols)]
428 ALLOCATE (almo_scf_env%domain_index_of_mo_block(natoms))
429 almo_scf_env%domain_index_of_mo_block(:) = &
430 almo_scf_env%domain_index_of_atom(:)
432 ALLOCATE (almo_scf_env%domain_index_of_mo_block(nmols))
434 almo_scf_env%domain_index_of_mo_block(:) = [(i, i=1, nmols)]
440 almo_scf_env%need_previous_ks = .true.
446 almo_scf_env%need_virtuals = .true.
447 almo_scf_env%need_orbital_energies = .true.
450 almo_scf_env%calc_forces = calc_forces
451 IF (calc_forces)
THEN
456 cpabort(
"Forces for perturbative methods are NYI. Change DELOCALIZE_METHOD")
459 IF (almo_scf_env%almo_history%istore > (almo_scf_env%almo_history%nstore + 1))
THEN
460 IF (almo_scf_env%opt_block_diag_pcg%eps_error_early > 0.0_dp)
THEN
461 almo_scf_env%opt_block_diag_pcg%eps_error = almo_scf_env%opt_block_diag_pcg%eps_error_early
462 almo_scf_env%opt_block_diag_pcg%early_stopping_on = .true.
463 IF (unit_nr > 0)
WRITE (*, *)
"ALMO_OPTIMIZER_PCG: EPS_ERROR_EARLY is on"
465 IF (almo_scf_env%opt_block_diag_diis%eps_error_early > 0.0_dp)
THEN
466 almo_scf_env%opt_block_diag_diis%eps_error = almo_scf_env%opt_block_diag_diis%eps_error_early
467 almo_scf_env%opt_block_diag_diis%early_stopping_on = .true.
468 IF (unit_nr > 0)
WRITE (*, *)
"ALMO_OPTIMIZER_DIIS: EPS_ERROR_EARLY is on"
470 IF (almo_scf_env%opt_block_diag_pcg%max_iter_early > 0)
THEN
471 almo_scf_env%opt_block_diag_pcg%max_iter = almo_scf_env%opt_block_diag_pcg%max_iter_early
472 almo_scf_env%opt_block_diag_pcg%early_stopping_on = .true.
473 IF (unit_nr > 0)
WRITE (*, *)
"ALMO_OPTIMIZER_PCG: MAX_ITER_EARLY is on"
475 IF (almo_scf_env%opt_block_diag_diis%max_iter_early > 0)
THEN
476 almo_scf_env%opt_block_diag_diis%max_iter = almo_scf_env%opt_block_diag_diis%max_iter_early
477 almo_scf_env%opt_block_diag_diis%early_stopping_on = .true.
478 IF (unit_nr > 0)
WRITE (*, *)
"ALMO_OPTIMIZER_DIIS: MAX_ITER_EARLY is on"
481 almo_scf_env%opt_block_diag_diis%early_stopping_on = .false.
482 almo_scf_env%opt_block_diag_pcg%early_stopping_on = .false.
484 IF (almo_scf_env%xalmo_history%istore > (almo_scf_env%xalmo_history%nstore + 1))
THEN
485 IF (almo_scf_env%opt_xalmo_pcg%eps_error_early > 0.0_dp)
THEN
486 almo_scf_env%opt_xalmo_pcg%eps_error = almo_scf_env%opt_xalmo_pcg%eps_error_early
487 almo_scf_env%opt_xalmo_pcg%early_stopping_on = .true.
488 IF (unit_nr > 0)
WRITE (*, *)
"XALMO_OPTIMIZER_PCG: EPS_ERROR_EARLY is on"
490 IF (almo_scf_env%opt_xalmo_pcg%max_iter_early > 0.0_dp)
THEN
491 almo_scf_env%opt_xalmo_pcg%max_iter = almo_scf_env%opt_xalmo_pcg%max_iter_early
492 almo_scf_env%opt_xalmo_pcg%early_stopping_on = .true.
493 IF (unit_nr > 0)
WRITE (*, *)
"XALMO_OPTIMIZER_PCG: MAX_ITER_EARLY is on"
496 almo_scf_env%opt_xalmo_pcg%early_stopping_on = .false.
501 CALL almo_scf_env_create_matrices(almo_scf_env, matrix_s(1)%matrix)
504 almo_scf_env%s_inv_done = .false.
505 almo_scf_env%s_sqrt_done = .false.
506 CALL almo_scf_init_ao_overlap(matrix_s(1)%matrix, almo_scf_env)
513 CALL almo_scf_print_job_info(almo_scf_env, unit_nr)
516 ALLOCATE (almo_scf_env%domain_preconditioner(ndomains, nspins))
520 ALLOCATE (almo_scf_env%domain_ks_xx(ndomains, nspins))
524 ALLOCATE (almo_scf_env%domain_s_inv(ndomains, nspins))
526 ALLOCATE (almo_scf_env%domain_s_sqrt_inv(ndomains, nspins))
528 ALLOCATE (almo_scf_env%domain_s_sqrt(ndomains, nspins))
530 ALLOCATE (almo_scf_env%domain_t(ndomains, nspins))
532 ALLOCATE (almo_scf_env%domain_err(ndomains, nspins))
534 ALLOCATE (almo_scf_env%domain_r_down_up(ndomains, nspins))
539 almo_scf_env%matrix_ks, &
540 almo_scf_env%mat_distr_aos, &
541 almo_scf_env%eps_filter)
544 CALL timestop(handle)
546 END SUBROUTINE almo_scf_init
557 SUBROUTINE almo_scf_initial_guess(qs_env, almo_scf_env)
561 CHARACTER(len=*),
PARAMETER :: routinen =
'almo_scf_initial_guess'
563 CHARACTER(LEN=default_path_length) :: file_name, project_name
564 INTEGER :: handle, iaspc, ispin, istore, naspc, &
566 INTEGER,
DIMENSION(2) :: nelectron_spin
567 LOGICAL :: aspc_guess, has_unit_metric
568 REAL(kind=
dp) :: alpha, cs_pos, energy, kts_sum
572 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s, rho_ao
577 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
580 CALL timeset(routinen, handle)
582 NULLIFY (rho, rho_ao)
586 IF (logger%para_env%is_source())
THEN
594 dft_control=dft_control, &
596 atomic_kind_set=atomic_kind_set, &
597 qs_kind_set=qs_kind_set, &
598 particle_set=particle_set, &
599 has_unit_metric=has_unit_metric, &
601 nelectron_spin=nelectron_spin, &
602 mscfg_env=mscfg_env, &
606 cpassert(
ASSOCIATED(mscfg_env))
612 IF (almo_scf_env%almo_history%istore == 0)
THEN
618 nspins = almo_scf_env%nspins
621 IF (.NOT. aspc_guess)
THEN
623 SELECT CASE (almo_scf_env%almo_scf_guess)
632 almo_scf_env%matrix_t_blk(ispin), ispin)
634 almo_scf_env%eps_filter)
640 IF (dft_control%qs_control%dftb .OR. dft_control%qs_control%semi_empirical .OR. &
641 dft_control%qs_control%xtb)
THEN
643 matrix_s(1)%matrix, has_unit_metric, &
644 dft_control, particle_set, atomic_kind_set, qs_kind_set, &
645 nspins, nelectron_spin, &
649 nspins, nelectron_spin, unit_nr, para_env)
655 almo_scf_env%matrix_p_blk(ispin), almo_scf_env%mat_distr_aos)
657 almo_scf_env%eps_filter)
666 project_name = logger%iter_info%project_name
669 WRITE (file_name,
'(A,I0,A)') trim(project_name)//
"_ALMO_SPIN_", ispin,
"_RESTART.mo"
670 CALL dbcsr_get_info(almo_scf_env%matrix_t_blk(ispin), distribution=dist)
671 CALL dbcsr_binary_read(file_name, distribution=dist, matrix_new=almo_scf_env%matrix_t_blk(ispin))
672 cs_pos =
dbcsr_checksum(almo_scf_env%matrix_t_blk(ispin), pos=.true.)
673 IF (unit_nr > 0)
THEN
674 WRITE (unit_nr,
'(T2,A,E20.8)')
"Read restart ALMO "//trim(file_name)//
" with checksum: ", cs_pos
684 naspc = min(almo_scf_env%almo_history%istore, almo_scf_env%almo_history%nstore)
685 IF (unit_nr > 0)
THEN
686 WRITE (unit_nr, fmt=
"(/,T2,A,/,/,T3,A,I0)") &
687 "Parameters for the always stable predictor-corrector (ASPC) method:", &
688 "ASPC order: ", naspc
695 istore = mod(almo_scf_env%almo_history%istore - iaspc, almo_scf_env%almo_history%nstore) + 1
696 alpha = (-1.0_dp)**(iaspc + 1)*real(iaspc, kind=
dp)* &
698 IF (unit_nr > 0)
THEN
699 WRITE (unit_nr, fmt=
"(T3,A2,I0,A4,F10.6)") &
700 "B(", iaspc,
") = ", alpha
703 CALL dbcsr_copy(almo_scf_env%matrix_t_blk(ispin), &
704 almo_scf_env%almo_history%matrix_t(ispin), &
705 keep_sparsity=.true.)
706 CALL dbcsr_scale(almo_scf_env%matrix_t_blk(ispin), alpha)
709 almo_scf_env%almo_history%matrix_p_up_down(ispin, istore), &
710 almo_scf_env%almo_history%matrix_t(ispin), &
711 1.0_dp, almo_scf_env%matrix_t_blk(ispin), &
712 retain_sparsity=.true.)
723 overlap=almo_scf_env%matrix_sigma_blk(ispin), &
724 metric=almo_scf_env%matrix_s_blk(1), &
725 retain_locality=.true., &
726 only_normalize=.false., &
727 nocc_of_domain=almo_scf_env%nocc_of_domain(:, ispin), &
728 eps_filter=almo_scf_env%eps_filter, &
729 order_lanczos=almo_scf_env%order_lanczos, &
730 eps_lanczos=almo_scf_env%eps_lanczos, &
731 max_iter_lanczos=almo_scf_env%max_iter_lanczos)
734 IF (almo_scf_env%smear)
THEN
736 mo_energies=almo_scf_env%mo_energies(:, ispin), &
737 mu_of_domain=almo_scf_env%mu_of_domain(:, ispin), &
738 real_ne_of_domain=almo_scf_env%real_ne_of_domain(:, ispin), &
739 spin_kts=almo_scf_env%kTS(ispin), &
740 smear_e_temp=almo_scf_env%smear_e_temp, &
741 ndomains=almo_scf_env%ndomains, &
742 nocc_of_domain=almo_scf_env%nocc_of_domain(:, ispin))
746 p=almo_scf_env%matrix_p(ispin), &
747 eps_filter=almo_scf_env%eps_filter, &
748 orthog_orbs=.false., &
749 nocc_of_domain=almo_scf_env%nocc_of_domain(:, ispin), &
750 s=almo_scf_env%matrix_s(1), &
751 sigma=almo_scf_env%matrix_sigma(ispin), &
752 sigma_inv=almo_scf_env%matrix_sigma_inv(ispin), &
754 smear=almo_scf_env%smear, &
755 algorithm=almo_scf_env%sigma_inv_algorithm, &
756 eps_lanczos=almo_scf_env%eps_lanczos, &
757 max_iter_lanczos=almo_scf_env%max_iter_lanczos, &
758 inv_eps_factor=almo_scf_env%matrix_iter_eps_error_factor, &
759 para_env=almo_scf_env%para_env, &
760 blacs_env=almo_scf_env%blacs_env)
765 IF (nspins == 1)
THEN
768 IF (almo_scf_env%smear)
THEN
769 almo_scf_env%kTS(1) = almo_scf_env%kTS(1)*2.0_dp
773 IF (almo_scf_env%smear)
THEN
774 kts_sum = sum(almo_scf_env%kTS)
780 almo_scf_env%matrix_p, &
781 almo_scf_env%matrix_ks, &
783 almo_scf_env%eps_filter, &
784 almo_scf_env%mat_distr_aos, &
785 smear=almo_scf_env%smear, &
788 IF (unit_nr > 0)
THEN
790 WRITE (unit_nr,
'(T2,A38,F40.10)')
"Single-molecule energy:", &
791 sum(mscfg_env%energy_of_frag)
793 WRITE (unit_nr,
'(T2,A38,F40.10)')
"Energy of the initial guess:", energy
794 WRITE (unit_nr,
'()')
797 CALL timestop(handle)
799 END SUBROUTINE almo_scf_initial_guess
808 SUBROUTINE almo_scf_store_extrapolation_data(almo_scf_env)
811 CHARACTER(len=*),
PARAMETER :: routinen =
'almo_scf_store_extrapolation_data'
813 INTEGER :: handle, ispin, istore, unit_nr
814 LOGICAL :: delocalization_uses_extrapolation
816 TYPE(
dbcsr_type) :: matrix_no_tmp1, matrix_no_tmp2, &
817 matrix_no_tmp3, matrix_no_tmp4
819 CALL timeset(routinen, handle)
823 IF (logger%para_env%is_source())
THEN
829 IF (almo_scf_env%almo_history%nstore > 0)
THEN
831 almo_scf_env%almo_history%istore = almo_scf_env%almo_history%istore + 1
833 DO ispin = 1,
SIZE(almo_scf_env%matrix_t_blk)
835 istore = mod(almo_scf_env%almo_history%istore - 1, almo_scf_env%almo_history%nstore) + 1
837 IF (almo_scf_env%almo_history%istore == 1)
THEN
838 CALL dbcsr_create(almo_scf_env%almo_history%matrix_t(ispin), &
839 template=almo_scf_env%matrix_t_blk(ispin), &
840 matrix_type=dbcsr_type_no_symmetry)
842 CALL dbcsr_copy(almo_scf_env%almo_history%matrix_t(ispin), &
843 almo_scf_env%matrix_t_blk(ispin))
845 IF (almo_scf_env%almo_history%istore <= almo_scf_env%almo_history%nstore)
THEN
846 CALL dbcsr_create(almo_scf_env%almo_history%matrix_p_up_down(ispin, istore), &
847 template=almo_scf_env%matrix_s(1), &
848 matrix_type=dbcsr_type_no_symmetry)
851 CALL dbcsr_create(matrix_no_tmp1, template=almo_scf_env%matrix_t_blk(ispin), &
852 matrix_type=dbcsr_type_no_symmetry)
853 CALL dbcsr_create(matrix_no_tmp2, template=almo_scf_env%matrix_t_blk(ispin), &
854 matrix_type=dbcsr_type_no_symmetry)
858 almo_scf_env%matrix_t_blk(ispin), &
859 0.0_dp, matrix_no_tmp1, &
860 filter_eps=almo_scf_env%eps_filter)
862 almo_scf_env%matrix_sigma_inv_0deloc(ispin), &
863 0.0_dp, matrix_no_tmp2, &
864 filter_eps=almo_scf_env%eps_filter)
866 almo_scf_env%matrix_t_blk(ispin), &
868 0.0_dp, almo_scf_env%almo_history%matrix_p_up_down(ispin, istore), &
869 filter_eps=almo_scf_env%eps_filter)
879 delocalization_uses_extrapolation = &
882 IF (almo_scf_env%xalmo_history%nstore > 0 .AND. &
883 delocalization_uses_extrapolation)
THEN
885 almo_scf_env%xalmo_history%istore = almo_scf_env%xalmo_history%istore + 1
887 DO ispin = 1,
SIZE(almo_scf_env%matrix_t)
889 istore = mod(almo_scf_env%xalmo_history%istore - 1, almo_scf_env%xalmo_history%nstore) + 1
891 IF (almo_scf_env%xalmo_history%istore == 1)
THEN
892 CALL dbcsr_create(almo_scf_env%xalmo_history%matrix_t(ispin), &
893 template=almo_scf_env%matrix_t(ispin), &
894 matrix_type=dbcsr_type_no_symmetry)
896 CALL dbcsr_copy(almo_scf_env%xalmo_history%matrix_t(ispin), &
897 almo_scf_env%matrix_t(ispin))
899 IF (almo_scf_env%xalmo_history%istore <= almo_scf_env%xalmo_history%nstore)
THEN
904 CALL dbcsr_create(almo_scf_env%xalmo_history%matrix_p_up_down(ispin, istore), &
905 template=almo_scf_env%matrix_s(1), &
906 matrix_type=dbcsr_type_no_symmetry)
909 CALL dbcsr_create(matrix_no_tmp3, template=almo_scf_env%matrix_t(ispin), &
910 matrix_type=dbcsr_type_no_symmetry)
911 CALL dbcsr_create(matrix_no_tmp4, template=almo_scf_env%matrix_t(ispin), &
912 matrix_type=dbcsr_type_no_symmetry)
916 almo_scf_env%matrix_t(ispin), &
917 0.0_dp, matrix_no_tmp3, &
918 filter_eps=almo_scf_env%eps_filter)
920 almo_scf_env%matrix_sigma_inv(ispin), &
921 0.0_dp, matrix_no_tmp4, &
922 filter_eps=almo_scf_env%eps_filter)
924 almo_scf_env%matrix_t(ispin), &
926 0.0_dp, almo_scf_env%xalmo_history%matrix_p_up_down(ispin, istore), &
927 filter_eps=almo_scf_env%eps_filter)
942 CALL timestop(handle)
944 END SUBROUTINE almo_scf_store_extrapolation_data
954 SUBROUTINE almo_scf_print_job_info(almo_scf_env, unit_nr)
957 INTEGER,
INTENT(IN) :: unit_nr
959 CHARACTER(len=*),
PARAMETER :: routinen =
'almo_scf_print_job_info'
961 CHARACTER(len=13) :: neig_string
962 CHARACTER(len=33) :: deloc_method_string
963 INTEGER :: handle, idomain, index1_prev, sum_temp
964 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: nneighbors
966 CALL timeset(routinen, handle)
968 IF (unit_nr > 0)
THEN
969 WRITE (unit_nr,
'()')
970 WRITE (unit_nr,
'(T2,A,A,A)') repeat(
"-", 32),
" ALMO SETTINGS ", repeat(
"-", 32)
972 WRITE (unit_nr,
'(T2,A,T48,E33.3)')
"eps_filter:", almo_scf_env%eps_filter
974 IF (almo_scf_env%almo_update_algorithm ==
almo_scf_skip)
THEN
975 WRITE (unit_nr,
'(T2,A)')
"skip optimization of block-diagonal ALMOs"
977 WRITE (unit_nr,
'(T2,A)')
"optimization of block-diagonal ALMOs:"
978 SELECT CASE (almo_scf_env%almo_update_algorithm)
991 SELECT CASE (almo_scf_env%deloc_method)
993 deloc_method_string =
"NONE"
995 deloc_method_string =
"FULL_X"
997 deloc_method_string =
"FULL_SCF"
999 deloc_method_string =
"FULL_X_THEN_SCF"
1001 deloc_method_string =
"XALMO_1DIAG"
1003 deloc_method_string =
"XALMO_X"
1005 deloc_method_string =
"XALMO_SCF"
1007 WRITE (unit_nr,
'(T2,A,T48,A33)')
"delocalization:", trim(deloc_method_string)
1011 SELECT CASE (almo_scf_env%deloc_method)
1013 WRITE (unit_nr,
'(T2,A,T48,A33)')
"delocalization cutoff radius:", &
1015 deloc_method_string =
"FULL_X_THEN_SCF"
1017 WRITE (unit_nr,
'(T2,A,T48,F33.5)')
"XALMO cutoff radius:", &
1018 almo_scf_env%quencher_r0_factor
1024 WRITE (unit_nr,
'(T2,A)')
"optimization of extended orbitals:"
1025 SELECT CASE (almo_scf_env%xalmo_update_algorithm)
1068 WRITE (unit_nr,
'(T2,A)') repeat(
"-", 79)
1069 WRITE (unit_nr,
'(T2,A,T48,I33)')
"Total fragments:", &
1070 almo_scf_env%ndomains
1072 sum_temp = sum(almo_scf_env%nbasis_of_domain(:))
1073 WRITE (unit_nr,
'(T2,A,T53,I5,F9.2,I5,I9)') &
1074 "Basis set size per fragment (min, av, max, total):", &
1075 minval(almo_scf_env%nbasis_of_domain(:)), &
1076 (1.0_dp*sum_temp)/almo_scf_env%ndomains, &
1077 maxval(almo_scf_env%nbasis_of_domain(:)), &
1085 sum_temp = sum(almo_scf_env%nocc_of_domain(:, :))
1086 WRITE (unit_nr,
'(T2,A,T53,I5,F9.2,I5,I9)') &
1087 "Occupied MOs per fragment (min, av, max, total):", &
1088 minval(sum(almo_scf_env%nocc_of_domain, dim=2)), &
1089 (1.0_dp*sum_temp)/almo_scf_env%ndomains, &
1090 maxval(sum(almo_scf_env%nocc_of_domain, dim=2)), &
1098 sum_temp = sum(almo_scf_env%nvirt_of_domain(:, :))
1099 WRITE (unit_nr,
'(T2,A,T53,I5,F9.2,I5,I9)') &
1100 "Virtual MOs per fragment (min, av, max, total):", &
1101 minval(sum(almo_scf_env%nvirt_of_domain, dim=2)), &
1102 (1.0_dp*sum_temp)/almo_scf_env%ndomains, &
1103 maxval(sum(almo_scf_env%nvirt_of_domain, dim=2)), &
1111 sum_temp = sum(almo_scf_env%charge_of_domain(:))
1112 WRITE (unit_nr,
'(T2,A,T53,I5,F9.2,I5,I9)') &
1113 "Charges per fragment (min, av, max, total):", &
1114 minval(almo_scf_env%charge_of_domain(:)), &
1115 (1.0_dp*sum_temp)/almo_scf_env%ndomains, &
1116 maxval(almo_scf_env%charge_of_domain(:)), &
1125 ALLOCATE (nneighbors(almo_scf_env%ndomains))
1127 DO idomain = 1, almo_scf_env%ndomains
1129 IF (idomain == 1)
THEN
1132 index1_prev = almo_scf_env%domain_map(1)%index1(idomain - 1)
1135 SELECT CASE (almo_scf_env%deloc_method)
1137 nneighbors(idomain) = 0
1139 nneighbors(idomain) = almo_scf_env%ndomains - 1
1141 nneighbors(idomain) = almo_scf_env%domain_map(1)%index1(idomain) - index1_prev - 1
1143 nneighbors(idomain) = -1
1148 sum_temp = sum(nneighbors(:))
1149 WRITE (unit_nr,
'(T2,A,T53,I5,F9.2,I5,I9)') &
1150 "Deloc. neighbors of fragment (min, av, max, total):", &
1151 minval(nneighbors(:)), &
1152 (1.0_dp*sum_temp)/almo_scf_env%ndomains, &
1153 maxval(nneighbors(:)), &
1156 WRITE (unit_nr,
'(T2,A)') repeat(
"-", 79)
1157 WRITE (unit_nr,
'()')
1159 IF (almo_scf_env%ndomains <= 64)
THEN
1162 WRITE (unit_nr,
'(T2,A10,A13,A13,A13,A13,A13)') &
1163 "Fragment",
"Basis Set",
"Occupied",
"Virtual",
"Charge",
"Deloc Neig"
1164 WRITE (unit_nr,
'(T2,A)') repeat(
"-", 79)
1165 DO idomain = 1, almo_scf_env%ndomains
1167 SELECT CASE (almo_scf_env%deloc_method)
1169 neig_string =
"NONE"
1173 WRITE (neig_string,
'(I13)') nneighbors(idomain)
1178 WRITE (unit_nr,
'(T2,I10,I13,I13,I13,I13,A13)') &
1179 idomain, almo_scf_env%nbasis_of_domain(idomain), &
1180 sum(almo_scf_env%nocc_of_domain(idomain, :)), &
1181 sum(almo_scf_env%nvirt_of_domain(idomain, :)), &
1183 almo_scf_env%charge_of_domain(idomain), &
1184 adjustr(trim(neig_string))
1188 SELECT CASE (almo_scf_env%deloc_method)
1191 WRITE (unit_nr,
'(T2,A)') repeat(
"-", 79)
1194 WRITE (unit_nr,
'(T2,A78)') &
1195 "Neighbor lists (including self)"
1196 WRITE (unit_nr,
'(T2,A)') repeat(
"-", 79)
1197 DO idomain = 1, almo_scf_env%ndomains
1199 IF (idomain == 1)
THEN
1202 index1_prev = almo_scf_env%domain_map(1)%index1(idomain - 1)
1205 WRITE (unit_nr,
'(T2,I10,":")') idomain
1206 WRITE (unit_nr,
'(T12,11I6)') &
1207 almo_scf_env%domain_map(1)%pairs &
1208 (index1_prev:almo_scf_env%domain_map(1)%index1(idomain) - 1, 1)
1216 WRITE (unit_nr,
'(T2,A)')
"The system is too big to print details for each fragment."
1220 WRITE (unit_nr,
'(T2,A)') repeat(
"-", 79)
1222 WRITE (unit_nr,
'()')
1224 DEALLOCATE (nneighbors)
1228 CALL timestop(handle)
1230 END SUBROUTINE almo_scf_print_job_info
1241 SUBROUTINE almo_scf_init_ao_overlap(matrix_s, almo_scf_env)
1245 CHARACTER(len=*),
PARAMETER :: routinen =
'almo_scf_init_ao_overlap'
1247 INTEGER :: handle, unit_nr
1250 CALL timeset(routinen, handle)
1254 IF (logger%para_env%is_source())
THEN
1262 IF (almo_scf_env%orthogonal_basis)
THEN
1263 CALL dbcsr_set(almo_scf_env%matrix_s(1), 0.0_dp)
1265 CALL dbcsr_set(almo_scf_env%matrix_s_blk(1), 0.0_dp)
1268 CALL matrix_qs_to_almo(matrix_s, almo_scf_env%matrix_s(1), almo_scf_env%mat_distr_aos)
1269 CALL dbcsr_copy(almo_scf_env%matrix_s_blk(1), &
1270 almo_scf_env%matrix_s(1), keep_sparsity=.true.)
1273 CALL dbcsr_filter(almo_scf_env%matrix_s(1), almo_scf_env%eps_filter)
1274 CALL dbcsr_filter(almo_scf_env%matrix_s_blk(1), almo_scf_env%eps_filter)
1276 IF (almo_scf_env%almo_update_algorithm ==
almo_scf_diag)
THEN
1278 almo_scf_env%matrix_s_blk_sqrt_inv(1), &
1279 almo_scf_env%matrix_s_blk(1), &
1280 threshold=almo_scf_env%eps_filter, &
1281 order=almo_scf_env%order_lanczos, &
1283 eps_lanczos=almo_scf_env%eps_lanczos, &
1284 max_iter_lanczos=almo_scf_env%max_iter_lanczos)
1287 almo_scf_env%matrix_s_blk(1), &
1288 threshold=almo_scf_env%eps_filter, &
1289 filter_eps=almo_scf_env%eps_filter)
1292 CALL timestop(handle)
1294 END SUBROUTINE almo_scf_init_ao_overlap
1305 SUBROUTINE almo_scf_main(qs_env, almo_scf_env)
1309 CHARACTER(len=*),
PARAMETER :: routinen =
'almo_scf_main'
1311 INTEGER :: handle, ispin, unit_nr
1314 CALL timeset(routinen, handle)
1318 IF (logger%para_env%is_source())
THEN
1324 SELECT CASE (almo_scf_env%almo_update_algorithm)
1327 SELECT CASE (almo_scf_env%almo_update_algorithm)
1332 almo_scf_env=almo_scf_env, &
1333 optimizer=almo_scf_env%opt_block_diag_pcg, &
1334 quench_t=almo_scf_env%quench_t_blk, &
1335 matrix_t_in=almo_scf_env%matrix_t_blk, &
1336 matrix_t_out=almo_scf_env%matrix_t_blk, &
1337 assume_t0_q0x=.false., &
1338 perturbation_only=.false., &
1344 almo_scf_env=almo_scf_env, &
1345 optimizer=almo_scf_env%opt_block_diag_trustr, &
1346 quench_t=almo_scf_env%quench_t_blk, &
1347 matrix_t_in=almo_scf_env%matrix_t_blk, &
1348 matrix_t_out=almo_scf_env%matrix_t_blk, &
1349 perturbation_only=.false., &
1354 DO ispin = 1, almo_scf_env%nspins
1356 overlap=almo_scf_env%matrix_sigma_blk(ispin), &
1357 metric=almo_scf_env%matrix_s_blk(1), &
1358 retain_locality=.true., &
1359 only_normalize=.false., &
1360 nocc_of_domain=almo_scf_env%nocc_of_domain(:, ispin), &
1361 eps_filter=almo_scf_env%eps_filter, &
1362 order_lanczos=almo_scf_env%order_lanczos, &
1363 eps_lanczos=almo_scf_env%eps_lanczos, &
1364 max_iter_lanczos=almo_scf_env%max_iter_lanczos)
1371 almo_scf_env%opt_block_diag_diis)
1376 DO ispin = 1, almo_scf_env%nspins
1377 CALL dbcsr_copy(almo_scf_env%matrix_ks_0deloc(ispin), &
1378 almo_scf_env%matrix_ks(ispin))
1379 CALL dbcsr_copy(almo_scf_env%matrix_sigma_inv_0deloc(ispin), &
1380 almo_scf_env%matrix_sigma_inv(ispin))
1383 CALL timestop(handle)
1385 END SUBROUTINE almo_scf_main
1395 SUBROUTINE almo_scf_delocalization(qs_env, almo_scf_env)
1400 CHARACTER(len=*),
PARAMETER :: routinen =
'almo_scf_delocalization'
1402 INTEGER :: handle, ispin, unit_nr
1403 LOGICAL :: almo_experimental
1405 TYPE(
dbcsr_type),
ALLOCATABLE,
DIMENSION(:) :: no_quench
1408 CALL timeset(routinen, handle)
1412 IF (logger%para_env%is_source())
THEN
1423 arbitrary_optimizer%max_iter = 3
1424 arbitrary_optimizer%eps_error = 1.0e-6_dp
1425 arbitrary_optimizer%ndiis = 2
1427 SELECT CASE (almo_scf_env%deloc_method)
1434 ALLOCATE (no_quench(almo_scf_env%nspins))
1436 template=almo_scf_env%matrix_t(1), &
1437 matrix_type=dbcsr_type_no_symmetry)
1440 IF (almo_scf_env%nspins > 1)
THEN
1441 DO ispin = 2, almo_scf_env%nspins
1443 template=almo_scf_env%matrix_t(1), &
1444 matrix_type=dbcsr_type_no_symmetry)
1445 CALL dbcsr_copy(no_quench(ispin), no_quench(1))
1451 SELECT CASE (almo_scf_env%deloc_method)
1454 DO ispin = 1, almo_scf_env%nspins
1455 CALL dbcsr_copy(almo_scf_env%matrix_t(ispin), &
1456 almo_scf_env%matrix_t_blk(ispin))
1484 IF (almo_scf_env%xalmo_update_algorithm ==
almo_scf_pcg)
THEN
1487 almo_scf_env=almo_scf_env, &
1488 optimizer=almo_scf_env%opt_xalmo_pcg, &
1489 quench_t=no_quench, &
1490 matrix_t_in=almo_scf_env%matrix_t_blk, &
1491 matrix_t_out=almo_scf_env%matrix_t, &
1493 perturbation_only=.true., &
1499 almo_scf_env=almo_scf_env, &
1500 optimizer=almo_scf_env%opt_xalmo_trustr, &
1501 quench_t=no_quench, &
1502 matrix_t_in=almo_scf_env%matrix_t_blk, &
1503 matrix_t_out=almo_scf_env%matrix_t, &
1504 perturbation_only=.true., &
1509 cpabort(
"Other algorithms do not exist")
1515 IF (almo_scf_env%xalmo_update_algorithm ==
almo_scf_diag)
THEN
1517 almo_scf_env%perturbative_delocalization = .true.
1518 DO ispin = 1, almo_scf_env%nspins
1519 CALL dbcsr_copy(almo_scf_env%matrix_t(ispin), &
1520 almo_scf_env%matrix_t_blk(ispin))
1523 arbitrary_optimizer)
1527 cpabort(
"Other algorithms do not exist")
1533 IF (almo_scf_env%xalmo_update_algorithm ==
almo_scf_pcg)
THEN
1536 almo_scf_env=almo_scf_env, &
1537 optimizer=almo_scf_env%opt_xalmo_pcg, &
1538 quench_t=almo_scf_env%quench_t, &
1539 matrix_t_in=almo_scf_env%matrix_t_blk, &
1540 matrix_t_out=almo_scf_env%matrix_t, &
1542 perturbation_only=.true., &
1548 almo_scf_env=almo_scf_env, &
1549 optimizer=almo_scf_env%opt_xalmo_trustr, &
1550 quench_t=almo_scf_env%quench_t, &
1551 matrix_t_in=almo_scf_env%matrix_t_blk, &
1552 matrix_t_out=almo_scf_env%matrix_t, &
1553 perturbation_only=.true., &
1558 cpabort(
"Other algorithms do not exist")
1564 IF (almo_scf_env%xalmo_update_algorithm ==
almo_scf_diag)
THEN
1566 cpabort(
"Should not be here: convergence will fail!")
1568 almo_scf_env%perturbative_delocalization = .false.
1569 DO ispin = 1, almo_scf_env%nspins
1570 CALL dbcsr_copy(almo_scf_env%matrix_t(ispin), &
1571 almo_scf_env%matrix_t_blk(ispin))
1574 arbitrary_optimizer)
1576 ELSE IF (almo_scf_env%xalmo_update_algorithm ==
almo_scf_pcg)
THEN
1579 almo_scf_env=almo_scf_env, &
1580 optimizer=almo_scf_env%opt_xalmo_pcg, &
1581 quench_t=almo_scf_env%quench_t, &
1582 matrix_t_in=almo_scf_env%matrix_t_blk, &
1583 matrix_t_out=almo_scf_env%matrix_t, &
1585 perturbation_only=.false., &
1589 almo_experimental = .false.
1590 IF (almo_experimental)
THEN
1591 almo_scf_env%perturbative_delocalization = .true.
1597 arbitrary_optimizer)
1603 almo_scf_env=almo_scf_env, &
1604 optimizer=almo_scf_env%opt_xalmo_trustr, &
1605 quench_t=almo_scf_env%quench_t, &
1606 matrix_t_in=almo_scf_env%matrix_t_blk, &
1607 matrix_t_out=almo_scf_env%matrix_t, &
1608 perturbation_only=.false., &
1613 cpabort(
"Other algorithms do not exist")
1619 cpabort(
"Illegal delocalization method")
1623 SELECT CASE (almo_scf_env%deloc_method)
1626 IF (almo_scf_env%deloc_truncate_virt /=
virt_full)
THEN
1627 cpabort(
"full scf is NYI for truncated virtual space")
1630 IF (almo_scf_env%xalmo_update_algorithm ==
almo_scf_pcg)
THEN
1633 almo_scf_env=almo_scf_env, &
1634 optimizer=almo_scf_env%opt_xalmo_pcg, &
1635 quench_t=no_quench, &
1636 matrix_t_in=almo_scf_env%matrix_t, &
1637 matrix_t_out=almo_scf_env%matrix_t, &
1638 assume_t0_q0x=.false., &
1639 perturbation_only=.false., &
1645 almo_scf_env=almo_scf_env, &
1646 optimizer=almo_scf_env%opt_xalmo_trustr, &
1647 quench_t=no_quench, &
1648 matrix_t_in=almo_scf_env%matrix_t, &
1649 matrix_t_out=almo_scf_env%matrix_t, &
1650 perturbation_only=.false., &
1655 cpabort(
"Other algorithms do not exist")
1662 SELECT CASE (almo_scf_env%deloc_method)
1664 DO ispin = 1, almo_scf_env%nspins
1667 DEALLOCATE (no_quench)
1670 CALL timestop(handle)
1672 END SUBROUTINE almo_scf_delocalization
1682 SUBROUTINE construct_nlmos(qs_env, almo_scf_env)
1689 IF (almo_scf_env%construct_nlmos)
THEN
1691 DO ispin = 1, almo_scf_env%nspins
1694 overlap=almo_scf_env%matrix_sigma(ispin), &
1695 metric=almo_scf_env%matrix_s(1), &
1696 retain_locality=.false., &
1697 only_normalize=.false., &
1698 nocc_of_domain=almo_scf_env%nocc_of_domain(:, ispin), &
1699 eps_filter=almo_scf_env%eps_filter, &
1700 order_lanczos=almo_scf_env%order_lanczos, &
1701 eps_lanczos=almo_scf_env%eps_lanczos, &
1702 max_iter_lanczos=almo_scf_env%max_iter_lanczos)
1705 CALL construct_nlmos_wrapper(qs_env, almo_scf_env, virtuals=.false.)
1707 IF (almo_scf_env%opt_nlmo_pcg%opt_penalty%virtual_nlmos)
THEN
1708 CALL construct_virtuals(almo_scf_env)
1709 CALL construct_nlmos_wrapper(qs_env, almo_scf_env, virtuals=.true.)
1712 IF (almo_scf_env%opt_nlmo_pcg%opt_penalty%compactification_filter_start > 0.0_dp)
THEN
1713 CALL nlmo_compactification(qs_env, almo_scf_env, almo_scf_env%matrix_t)
1718 END SUBROUTINE construct_nlmos
1729 SUBROUTINE construct_nlmos_wrapper(qs_env, almo_scf_env, virtuals)
1733 LOGICAL,
INTENT(IN) :: virtuals
1735 REAL(kind=
dp) :: det_diff, prev_determinant
1737 almo_scf_env%overlap_determinant = 1.0
1739 almo_scf_env%opt_nlmo_pcg%opt_penalty%penalty_strength = &
1740 -1.0_dp*almo_scf_env%opt_nlmo_pcg%opt_penalty%penalty_strength
1743 prev_determinant = 10.0_dp
1744 DO WHILE (almo_scf_env%overlap_determinant > almo_scf_env%opt_nlmo_pcg%opt_penalty%final_determinant)
1746 IF (.NOT. virtuals)
THEN
1748 optimizer=almo_scf_env%opt_nlmo_pcg, &
1749 matrix_s=almo_scf_env%matrix_s(1), &
1750 matrix_mo_in=almo_scf_env%matrix_t, &
1751 matrix_mo_out=almo_scf_env%matrix_t, &
1752 template_matrix_sigma=almo_scf_env%matrix_sigma_inv, &
1753 overlap_determinant=almo_scf_env%overlap_determinant, &
1754 mat_distr_aos=almo_scf_env%mat_distr_aos, &
1755 virtuals=virtuals, &
1756 eps_filter=almo_scf_env%eps_filter)
1759 optimizer=almo_scf_env%opt_nlmo_pcg, &
1760 matrix_s=almo_scf_env%matrix_s(1), &
1761 matrix_mo_in=almo_scf_env%matrix_v, &
1762 matrix_mo_out=almo_scf_env%matrix_v, &
1763 template_matrix_sigma=almo_scf_env%matrix_sigma_vv, &
1764 overlap_determinant=almo_scf_env%overlap_determinant, &
1765 mat_distr_aos=almo_scf_env%mat_distr_aos, &
1766 virtuals=virtuals, &
1767 eps_filter=almo_scf_env%eps_filter)
1771 det_diff = prev_determinant - almo_scf_env%overlap_determinant
1772 almo_scf_env%opt_nlmo_pcg%opt_penalty%penalty_strength = &
1773 almo_scf_env%opt_nlmo_pcg%opt_penalty%penalty_strength/ &
1774 abs(almo_scf_env%opt_nlmo_pcg%opt_penalty%penalty_strength_dec_factor)
1776 IF (det_diff < almo_scf_env%opt_nlmo_pcg%opt_penalty%determinant_tolerance)
THEN
1779 prev_determinant = almo_scf_env%overlap_determinant
1783 END SUBROUTINE construct_nlmos_wrapper
1792 SUBROUTINE construct_virtuals(almo_scf_env)
1797 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigenvalues
1798 TYPE(
dbcsr_type) :: tempnv1, tempvocc1, tempvocc2, tempvv1, &
1801 DO ispin = 1, almo_scf_env%nspins
1804 template=almo_scf_env%matrix_v(ispin), &
1805 matrix_type=dbcsr_type_no_symmetry)
1807 template=almo_scf_env%matrix_vo(ispin), &
1808 matrix_type=dbcsr_type_no_symmetry)
1810 template=almo_scf_env%matrix_vo(ispin), &
1811 matrix_type=dbcsr_type_no_symmetry)
1813 template=almo_scf_env%matrix_sigma_vv(ispin), &
1814 matrix_type=dbcsr_type_no_symmetry)
1816 template=almo_scf_env%matrix_sigma_vv(ispin), &
1817 matrix_type=dbcsr_type_no_symmetry)
1821 keep_sparsity=.false.)
1825 almo_scf_env%matrix_s(1), &
1826 almo_scf_env%matrix_v(ispin), &
1828 filter_eps=almo_scf_env%eps_filter)
1832 almo_scf_env%matrix_t(ispin), &
1833 0.0_dp, tempvocc1, &
1834 filter_eps=almo_scf_env%eps_filter)
1838 almo_scf_env%matrix_sigma_inv(ispin), &
1839 0.0_dp, tempvocc2, &
1840 filter_eps=almo_scf_env%eps_filter)
1843 almo_scf_env%matrix_t(ispin), &
1846 filter_eps=almo_scf_env%eps_filter)
1848 CALL dbcsr_add(almo_scf_env%matrix_v(ispin), tempnv1, 1.0_dp, -1.0_dp)
1852 almo_scf_env%matrix_s(1), &
1853 almo_scf_env%matrix_v(ispin), &
1855 filter_eps=almo_scf_env%eps_filter)
1858 almo_scf_env%matrix_v(ispin), &
1861 filter_eps=almo_scf_env%eps_filter)
1865 metric=almo_scf_env%matrix_s(1), &
1866 retain_locality=.false., &
1867 only_normalize=.false., &
1868 nocc_of_domain=almo_scf_env%nocc_of_domain(:, ispin), &
1869 eps_filter=almo_scf_env%eps_filter, &
1870 order_lanczos=almo_scf_env%order_lanczos, &
1871 eps_lanczos=almo_scf_env%eps_lanczos, &
1872 max_iter_lanczos=almo_scf_env%max_iter_lanczos)
1876 almo_scf_env%matrix_ks(ispin), &
1877 almo_scf_env%matrix_v(ispin), &
1879 filter_eps=almo_scf_env%eps_filter)
1882 almo_scf_env%matrix_v(ispin), &
1885 filter_eps=almo_scf_env%eps_filter)
1888 ALLOCATE (eigenvalues(n))
1891 para_env=almo_scf_env%para_env, &
1892 blacs_env=almo_scf_env%blacs_env)
1893 DEALLOCATE (eigenvalues)
1896 almo_scf_env%matrix_v(ispin), &
1899 filter_eps=almo_scf_env%eps_filter)
1901 CALL dbcsr_copy(almo_scf_env%matrix_v(ispin), tempnv1)
1911 END SUBROUTINE construct_virtuals
1922 SUBROUTINE nlmo_compactification(qs_env, almo_scf_env, matrix)
1926 TYPE(
dbcsr_type),
ALLOCATABLE,
DIMENSION(:), &
1927 INTENT(IN) :: matrix
1929 INTEGER :: iblock_col, iblock_col_size, iblock_row, &
1930 iblock_row_size, icol, irow, ispin, &
1931 ncols, nrows, nspins, unit_nr
1932 LOGICAL :: element_by_element
1933 REAL(kind=
dp) :: energy, eps_local, eps_start, &
1934 max_element, spin_factor
1935 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: occ, retained
1936 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: data_p
1939 TYPE(
dbcsr_type),
ALLOCATABLE,
DIMENSION(:) :: matrix_p_tmp, matrix_t_tmp
1944 IF (logger%para_env%is_source())
THEN
1950 nspins =
SIZE(matrix)
1951 element_by_element = .false.
1953 IF (nspins == 1)
THEN
1954 spin_factor = 2.0_dp
1956 spin_factor = 1.0_dp
1959 ALLOCATE (matrix_t_tmp(nspins))
1960 ALLOCATE (matrix_p_tmp(nspins))
1961 ALLOCATE (retained(nspins))
1964 DO ispin = 1, nspins
1968 template=matrix(ispin), &
1969 matrix_type=dbcsr_type_no_symmetry)
1970 CALL dbcsr_copy(matrix_t_tmp(ispin), matrix(ispin))
1973 template=almo_scf_env%matrix_p(ispin), &
1974 matrix_type=dbcsr_type_no_symmetry)
1975 CALL dbcsr_copy(matrix_p_tmp(ispin), almo_scf_env%matrix_p(ispin))
1979 IF (unit_nr > 0)
THEN
1981 WRITE (unit_nr,
'(T2,A)') &
1982 "Energy dependence on the (block-by-block) filtering of the NLMO coefficients"
1983 IF (unit_nr > 0)
WRITE (unit_nr,
'(T2,A13,A20,A20,A25)') &
1984 "EPS filter",
"Occupation Alpha",
"Occupation Beta",
"Energy"
1987 eps_start = almo_scf_env%opt_nlmo_pcg%opt_penalty%compactification_filter_start
1988 eps_local = max(eps_start, 10e-14_dp)
1992 IF (eps_local > 0.11_dp)
EXIT
1994 DO ispin = 1, nspins
2001 row_size=iblock_row_size, col_size=iblock_col_size)
2002 DO icol = 1, iblock_col_size
2004 IF (element_by_element)
THEN
2006 DO irow = 1, iblock_row_size
2007 IF (abs(data_p(irow, icol)) < eps_local)
THEN
2008 data_p(irow, icol) = 0.0_dp
2010 retained(ispin) = retained(ispin) + 1
2016 max_element = 0.0_dp
2017 DO irow = 1, iblock_row_size
2018 IF (abs(data_p(irow, icol)) > max_element)
THEN
2019 max_element = abs(data_p(irow, icol))
2022 IF (max_element < eps_local)
THEN
2023 DO irow = 1, iblock_row_size
2024 data_p(irow, icol) = 0.0_dp
2027 retained(ispin) = retained(ispin) + iblock_row_size
2039 nfullrows_total=nrows, &
2040 nfullcols_total=ncols)
2041 CALL group%sum(retained(ispin))
2044 occ(ispin) = retained(ispin)/nrows/ncols
2048 t=matrix_t_tmp(ispin), &
2049 p=matrix_p_tmp(ispin), &
2050 eps_filter=almo_scf_env%eps_filter, &
2051 orthog_orbs=.false., &
2052 nocc_of_domain=almo_scf_env%nocc_of_domain(:, ispin), &
2053 s=almo_scf_env%matrix_s(1), &
2054 sigma=almo_scf_env%matrix_sigma(ispin), &
2055 sigma_inv=almo_scf_env%matrix_sigma_inv(ispin), &
2056 use_guess=.false., &
2057 algorithm=almo_scf_env%sigma_inv_algorithm, &
2058 inv_eps_factor=almo_scf_env%matrix_iter_eps_error_factor, &
2059 inverse_accelerator=almo_scf_env%order_lanczos, &
2060 eps_lanczos=almo_scf_env%eps_lanczos, &
2061 max_iter_lanczos=almo_scf_env%max_iter_lanczos, &
2062 para_env=almo_scf_env%para_env, &
2063 blacs_env=almo_scf_env%blacs_env)
2066 CALL dbcsr_scale(matrix_p_tmp(ispin), spin_factor)
2073 almo_scf_env%matrix_ks, &
2075 almo_scf_env%eps_filter, &
2076 almo_scf_env%mat_distr_aos)
2078 IF (nspins < 2) occ(2) = occ(1)
2079 IF (unit_nr > 0)
WRITE (unit_nr,
'(T2,E13.3,F20.10,F20.10,F25.15)') &
2080 eps_local, occ(1), occ(2), energy
2082 eps_local = 2.0_dp*eps_local
2086 DO ispin = 1, nspins
2093 DEALLOCATE (matrix_t_tmp)
2094 DEALLOCATE (matrix_p_tmp)
2096 DEALLOCATE (retained)
2098 END SUBROUTINE nlmo_compactification
2109 SUBROUTINE almo_scf_post(qs_env, almo_scf_env)
2113 CHARACTER(len=*),
PARAMETER :: routinen =
'almo_scf_post'
2115 INTEGER :: handle, ispin
2118 TYPE(
dbcsr_type),
ALLOCATABLE,
DIMENSION(:) :: matrix_t_processed
2122 CALL timeset(routinen, handle)
2125 CALL almo_scf_store_extrapolation_data(almo_scf_env)
2128 ALLOCATE (matrix_t_processed(almo_scf_env%nspins))
2131 DO ispin = 1, almo_scf_env%nspins
2134 template=almo_scf_env%matrix_t(ispin), &
2135 matrix_type=dbcsr_type_no_symmetry)
2138 almo_scf_env%matrix_t(ispin))
2140 IF (almo_scf_env%return_orthogonalized_mos)
THEN
2143 overlap=almo_scf_env%matrix_sigma(ispin), &
2144 metric=almo_scf_env%matrix_s(1), &
2145 retain_locality=.false., &
2146 only_normalize=.false., &
2147 nocc_of_domain=almo_scf_env%nocc_of_domain(:, ispin), &
2148 eps_filter=almo_scf_env%eps_filter, &
2149 order_lanczos=almo_scf_env%order_lanczos, &
2150 eps_lanczos=almo_scf_env%eps_lanczos, &
2151 max_iter_lanczos=almo_scf_env%max_iter_lanczos, &
2152 smear=almo_scf_env%smear)
2168 NULLIFY (mos, mo_coeff, scf_env)
2170 CALL get_qs_env(qs_env, mos=mos, scf_env=scf_env)
2172 DO ispin = 1, almo_scf_env%nspins
2176 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff)
2180 DO ispin = 1, almo_scf_env%nspins
2183 DEALLOCATE (matrix_t_processed)
2187 CALL almo_post_scf_compute_properties(qs_env)
2190 IF (almo_scf_env%calc_forces)
THEN
2192 IF (
ASSOCIATED(matrix_w))
THEN
2195 cpabort(
"Matrix W is needed but not associated")
2199 CALL timestop(handle)
2201 END SUBROUTINE almo_scf_post
2211 SUBROUTINE almo_scf_env_create_matrices(almo_scf_env, matrix_s0)
2216 CHARACTER(len=*),
PARAMETER :: routinen =
'almo_scf_env_create_matrices'
2218 INTEGER :: handle, ispin, nspins
2220 CALL timeset(routinen, handle)
2222 nspins = almo_scf_env%nspins
2226 matrix_qs=matrix_s0, &
2227 almo_scf_env=almo_scf_env, &
2230 symmetry_new=dbcsr_type_symmetric, &
2232 init_domains=.false.)
2234 matrix_qs=matrix_s0, &
2235 almo_scf_env=almo_scf_env, &
2238 symmetry_new=dbcsr_type_symmetric, &
2240 init_domains=.true.)
2241 IF (almo_scf_env%almo_update_algorithm ==
almo_scf_diag)
THEN
2243 matrix_qs=matrix_s0, &
2244 almo_scf_env=almo_scf_env, &
2245 name_new=
"S_BLK_SQRT_INV", &
2247 symmetry_new=dbcsr_type_symmetric, &
2249 init_domains=.true.)
2251 matrix_qs=matrix_s0, &
2252 almo_scf_env=almo_scf_env, &
2253 name_new=
"S_BLK_SQRT", &
2255 symmetry_new=dbcsr_type_symmetric, &
2257 init_domains=.true.)
2260 matrix_qs=matrix_s0, &
2261 almo_scf_env=almo_scf_env, &
2262 name_new=
"S_BLK_INV", &
2264 symmetry_new=dbcsr_type_symmetric, &
2266 init_domains=.true.)
2270 ALLOCATE (almo_scf_env%matrix_t_blk(nspins))
2271 ALLOCATE (almo_scf_env%quench_t_blk(nspins))
2272 ALLOCATE (almo_scf_env%matrix_err_blk(nspins))
2273 ALLOCATE (almo_scf_env%matrix_err_xx(nspins))
2274 ALLOCATE (almo_scf_env%matrix_sigma(nspins))
2275 ALLOCATE (almo_scf_env%matrix_sigma_inv(nspins))
2276 ALLOCATE (almo_scf_env%matrix_sigma_sqrt(nspins))
2277 ALLOCATE (almo_scf_env%matrix_sigma_sqrt_inv(nspins))
2278 ALLOCATE (almo_scf_env%matrix_sigma_blk(nspins))
2279 ALLOCATE (almo_scf_env%matrix_sigma_inv_0deloc(nspins))
2280 ALLOCATE (almo_scf_env%matrix_t(nspins))
2281 ALLOCATE (almo_scf_env%matrix_t_tr(nspins))
2282 DO ispin = 1, nspins
2285 matrix_qs=matrix_s0, &
2286 almo_scf_env=almo_scf_env, &
2289 symmetry_new=dbcsr_type_no_symmetry, &
2291 init_domains=.true.)
2294 matrix_qs=matrix_s0, &
2295 almo_scf_env=almo_scf_env, &
2298 symmetry_new=dbcsr_type_no_symmetry, &
2300 init_domains=.true.)
2303 matrix_qs=matrix_s0, &
2304 almo_scf_env=almo_scf_env, &
2305 name_new=
"ERR_BLK", &
2307 symmetry_new=dbcsr_type_no_symmetry, &
2309 init_domains=.true.)
2312 matrix_qs=matrix_s0, &
2313 almo_scf_env=almo_scf_env, &
2314 name_new=
"ERR_XX", &
2316 symmetry_new=dbcsr_type_no_symmetry, &
2318 init_domains=.false.)
2322 matrix_qs=matrix_s0, &
2323 almo_scf_env=almo_scf_env, &
2326 symmetry_new=dbcsr_type_no_symmetry, &
2328 init_domains=.false.)
2331 matrix_qs=matrix_s0, &
2332 almo_scf_env=almo_scf_env, &
2335 symmetry_new=dbcsr_type_symmetric, &
2337 init_domains=.false.)
2340 matrix_qs=matrix_s0, &
2341 almo_scf_env=almo_scf_env, &
2342 name_new=
"SIG_BLK", &
2344 symmetry_new=dbcsr_type_symmetric, &
2346 init_domains=.true.)
2349 matrix_qs=matrix_s0, &
2350 almo_scf_env=almo_scf_env, &
2351 name_new=
"SIGINV_BLK", &
2353 symmetry_new=dbcsr_type_symmetric, &
2355 init_domains=.true.)
2358 matrix_new=almo_scf_env%matrix_sigma_inv(ispin), &
2359 matrix_qs=matrix_s0, &
2360 almo_scf_env=almo_scf_env, &
2361 name_new=
"SIGINV", &
2363 symmetry_new=dbcsr_type_symmetric, &
2365 init_domains=.false.)
2368 matrix_new=almo_scf_env%matrix_t(ispin), &
2369 matrix_qs=matrix_s0, &
2370 almo_scf_env=almo_scf_env, &
2373 symmetry_new=dbcsr_type_no_symmetry, &
2375 init_domains=.false.)
2376 CALL dbcsr_create(almo_scf_env%matrix_sigma_sqrt(ispin), &
2377 template=almo_scf_env%matrix_sigma(ispin), &
2378 matrix_type=dbcsr_type_no_symmetry)
2379 CALL dbcsr_create(almo_scf_env%matrix_sigma_sqrt_inv(ispin), &
2380 template=almo_scf_env%matrix_sigma(ispin), &
2381 matrix_type=dbcsr_type_no_symmetry)
2385 IF (almo_scf_env%need_virtuals)
THEN
2386 ALLOCATE (almo_scf_env%matrix_v_blk(nspins))
2387 ALLOCATE (almo_scf_env%matrix_v_full_blk(nspins))
2388 ALLOCATE (almo_scf_env%matrix_v(nspins))
2389 ALLOCATE (almo_scf_env%matrix_vo(nspins))
2390 ALLOCATE (almo_scf_env%matrix_x(nspins))
2391 ALLOCATE (almo_scf_env%matrix_ov(nspins))
2392 ALLOCATE (almo_scf_env%matrix_ov_full(nspins))
2393 ALLOCATE (almo_scf_env%matrix_sigma_vv(nspins))
2394 ALLOCATE (almo_scf_env%matrix_sigma_vv_blk(nspins))
2395 ALLOCATE (almo_scf_env%matrix_sigma_vv_sqrt(nspins))
2396 ALLOCATE (almo_scf_env%matrix_sigma_vv_sqrt_inv(nspins))
2397 ALLOCATE (almo_scf_env%matrix_vv_full_blk(nspins))
2399 IF (almo_scf_env%deloc_truncate_virt /=
virt_full)
THEN
2400 ALLOCATE (almo_scf_env%matrix_k_blk(nspins))
2401 ALLOCATE (almo_scf_env%matrix_k_blk_ones(nspins))
2402 ALLOCATE (almo_scf_env%matrix_k_tr(nspins))
2403 ALLOCATE (almo_scf_env%matrix_v_disc(nspins))
2404 ALLOCATE (almo_scf_env%matrix_v_disc_blk(nspins))
2405 ALLOCATE (almo_scf_env%matrix_ov_disc(nspins))
2406 ALLOCATE (almo_scf_env%matrix_vv_disc_blk(nspins))
2407 ALLOCATE (almo_scf_env%matrix_vv_disc(nspins))
2408 ALLOCATE (almo_scf_env%opt_k_t_dd(nspins))
2409 ALLOCATE (almo_scf_env%opt_k_t_rr(nspins))
2410 ALLOCATE (almo_scf_env%opt_k_denom(nspins))
2413 DO ispin = 1, nspins
2415 matrix_qs=matrix_s0, &
2416 almo_scf_env=almo_scf_env, &
2417 name_new=
"V_FULL_BLK", &
2419 symmetry_new=dbcsr_type_no_symmetry, &
2421 init_domains=.false.)
2423 matrix_qs=matrix_s0, &
2424 almo_scf_env=almo_scf_env, &
2427 symmetry_new=dbcsr_type_no_symmetry, &
2429 init_domains=.false.)
2431 matrix_qs=matrix_s0, &
2432 almo_scf_env=almo_scf_env, &
2435 symmetry_new=dbcsr_type_no_symmetry, &
2437 init_domains=.false.)
2439 matrix_qs=matrix_s0, &
2440 almo_scf_env=almo_scf_env, &
2441 name_new=
"OV_FULL", &
2443 symmetry_new=dbcsr_type_no_symmetry, &
2445 init_domains=.false.)
2447 matrix_qs=matrix_s0, &
2448 almo_scf_env=almo_scf_env, &
2451 symmetry_new=dbcsr_type_no_symmetry, &
2453 init_domains=.false.)
2455 matrix_qs=matrix_s0, &
2456 almo_scf_env=almo_scf_env, &
2459 symmetry_new=dbcsr_type_no_symmetry, &
2461 init_domains=.false.)
2463 matrix_qs=matrix_s0, &
2464 almo_scf_env=almo_scf_env, &
2467 symmetry_new=dbcsr_type_no_symmetry, &
2469 init_domains=.false.)
2471 matrix_qs=matrix_s0, &
2472 almo_scf_env=almo_scf_env, &
2473 name_new=
"SIG_VV", &
2475 symmetry_new=dbcsr_type_symmetric, &
2477 init_domains=.false.)
2479 matrix_qs=matrix_s0, &
2480 almo_scf_env=almo_scf_env, &
2481 name_new=
"VV_FULL_BLK", &
2483 symmetry_new=dbcsr_type_no_symmetry, &
2485 init_domains=.true.)
2487 matrix_qs=matrix_s0, &
2488 almo_scf_env=almo_scf_env, &
2489 name_new=
"SIG_VV_BLK", &
2491 symmetry_new=dbcsr_type_symmetric, &
2493 init_domains=.true.)
2494 CALL dbcsr_create(almo_scf_env%matrix_sigma_vv_sqrt(ispin), &
2495 template=almo_scf_env%matrix_sigma_vv(ispin), &
2496 matrix_type=dbcsr_type_no_symmetry)
2497 CALL dbcsr_create(almo_scf_env%matrix_sigma_vv_sqrt_inv(ispin), &
2498 template=almo_scf_env%matrix_sigma_vv(ispin), &
2499 matrix_type=dbcsr_type_no_symmetry)
2501 IF (almo_scf_env%deloc_truncate_virt /=
virt_full)
THEN
2503 matrix_qs=matrix_s0, &
2504 almo_scf_env=almo_scf_env, &
2505 name_new=
"OPT_K_U_RR", &
2507 symmetry_new=dbcsr_type_no_symmetry, &
2509 init_domains=.false.)
2511 matrix_qs=matrix_s0, &
2512 almo_scf_env=almo_scf_env, &
2513 name_new=
"VV_DISC", &
2515 symmetry_new=dbcsr_type_symmetric, &
2517 init_domains=.false.)
2519 matrix_qs=matrix_s0, &
2520 almo_scf_env=almo_scf_env, &
2521 name_new=
"OPT_K_U_DD", &
2523 symmetry_new=dbcsr_type_no_symmetry, &
2525 init_domains=.false.)
2527 matrix_qs=matrix_s0, &
2528 almo_scf_env=almo_scf_env, &
2529 name_new=
"VV_DISC_BLK", &
2531 symmetry_new=dbcsr_type_symmetric, &
2533 init_domains=.true.)
2535 matrix_qs=matrix_s0, &
2536 almo_scf_env=almo_scf_env, &
2539 symmetry_new=dbcsr_type_no_symmetry, &
2541 init_domains=.true.)
2543 matrix_qs=matrix_s0, &
2544 almo_scf_env=almo_scf_env, &
2545 name_new=
"K_BLK_1", &
2547 symmetry_new=dbcsr_type_no_symmetry, &
2549 init_domains=.true.)
2551 matrix_qs=matrix_s0, &
2552 almo_scf_env=almo_scf_env, &
2553 name_new=
"OPT_K_DENOM", &
2555 symmetry_new=dbcsr_type_no_symmetry, &
2557 init_domains=.false.)
2559 matrix_qs=matrix_s0, &
2560 almo_scf_env=almo_scf_env, &
2563 symmetry_new=dbcsr_type_no_symmetry, &
2565 init_domains=.false.)
2567 matrix_qs=matrix_s0, &
2568 almo_scf_env=almo_scf_env, &
2569 name_new=
"V_DISC_BLK", &
2571 symmetry_new=dbcsr_type_no_symmetry, &
2573 init_domains=.false.)
2575 matrix_qs=matrix_s0, &
2576 almo_scf_env=almo_scf_env, &
2577 name_new=
"V_DISC", &
2579 symmetry_new=dbcsr_type_no_symmetry, &
2581 init_domains=.false.)
2583 matrix_qs=matrix_s0, &
2584 almo_scf_env=almo_scf_env, &
2585 name_new=
"OV_DISC", &
2587 symmetry_new=dbcsr_type_no_symmetry, &
2589 init_domains=.false.)
2597 IF (almo_scf_env%need_orbital_energies)
THEN
2598 ALLOCATE (almo_scf_env%matrix_eoo(nspins))
2599 ALLOCATE (almo_scf_env%matrix_evv_full(nspins))
2600 DO ispin = 1, nspins
2602 matrix_qs=matrix_s0, &
2603 almo_scf_env=almo_scf_env, &
2606 symmetry_new=dbcsr_type_no_symmetry, &
2608 init_domains=.false.)
2610 matrix_qs=matrix_s0, &
2611 almo_scf_env=almo_scf_env, &
2612 name_new=
"E_VIRT", &
2614 symmetry_new=dbcsr_type_no_symmetry, &
2616 init_domains=.false.)
2621 ALLOCATE (almo_scf_env%matrix_p(nspins))
2622 ALLOCATE (almo_scf_env%matrix_p_blk(nspins))
2623 ALLOCATE (almo_scf_env%matrix_ks(nspins))
2624 ALLOCATE (almo_scf_env%matrix_ks_blk(nspins))
2625 IF (almo_scf_env%need_previous_ks) &
2626 ALLOCATE (almo_scf_env%matrix_ks_0deloc(nspins))
2627 DO ispin = 1, nspins
2630 template=almo_scf_env%matrix_s(1), &
2631 matrix_type=dbcsr_type_symmetric)
2633 template=almo_scf_env%matrix_s(1), &
2634 matrix_type=dbcsr_type_symmetric)
2635 IF (almo_scf_env%need_previous_ks)
THEN
2636 CALL dbcsr_create(almo_scf_env%matrix_ks_0deloc(ispin), &
2637 template=almo_scf_env%matrix_s(1), &
2638 matrix_type=dbcsr_type_symmetric)
2641 matrix_qs=matrix_s0, &
2642 almo_scf_env=almo_scf_env, &
2645 symmetry_new=dbcsr_type_symmetric, &
2647 init_domains=.true.)
2649 matrix_qs=matrix_s0, &
2650 almo_scf_env=almo_scf_env, &
2651 name_new=
"KS_BLK", &
2653 symmetry_new=dbcsr_type_symmetric, &
2655 init_domains=.true.)
2658 CALL timestop(handle)
2660 END SUBROUTINE almo_scf_env_create_matrices
2670 SUBROUTINE almo_scf_clean_up(almo_scf_env)
2674 CHARACTER(len=*),
PARAMETER :: routinen =
'almo_scf_clean_up'
2676 INTEGER :: handle, ispin, unit_nr
2679 CALL timeset(routinen, handle)
2683 IF (logger%para_env%is_source())
THEN
2692 IF (almo_scf_env%almo_update_algorithm ==
almo_scf_diag)
THEN
2698 DO ispin = 1, almo_scf_env%nspins
2707 CALL dbcsr_release(almo_scf_env%matrix_sigma_inv_0deloc(ispin))
2711 CALL dbcsr_release(almo_scf_env%matrix_sigma_sqrt_inv(ispin))
2716 IF (almo_scf_env%need_previous_ks)
THEN
2719 IF (almo_scf_env%need_virtuals)
THEN
2729 CALL dbcsr_release(almo_scf_env%matrix_sigma_vv_sqrt(ispin))
2730 CALL dbcsr_release(almo_scf_env%matrix_sigma_vv_sqrt_inv(ispin))
2732 IF (almo_scf_env%deloc_truncate_virt /=
virt_full)
THEN
2746 IF (almo_scf_env%need_orbital_energies)
THEN
2753 DEALLOCATE (almo_scf_env%matrix_p)
2754 DEALLOCATE (almo_scf_env%matrix_p_blk)
2755 DEALLOCATE (almo_scf_env%matrix_ks)
2756 DEALLOCATE (almo_scf_env%matrix_ks_blk)
2757 DEALLOCATE (almo_scf_env%matrix_t_blk)
2758 DEALLOCATE (almo_scf_env%matrix_err_blk)
2759 DEALLOCATE (almo_scf_env%matrix_err_xx)
2760 DEALLOCATE (almo_scf_env%matrix_t)
2761 DEALLOCATE (almo_scf_env%matrix_t_tr)
2762 DEALLOCATE (almo_scf_env%matrix_sigma)
2763 DEALLOCATE (almo_scf_env%matrix_sigma_blk)
2764 DEALLOCATE (almo_scf_env%matrix_sigma_inv_0deloc)
2765 DEALLOCATE (almo_scf_env%matrix_sigma_sqrt)
2766 DEALLOCATE (almo_scf_env%matrix_sigma_sqrt_inv)
2767 DEALLOCATE (almo_scf_env%matrix_sigma_inv)
2768 DEALLOCATE (almo_scf_env%quench_t)
2769 DEALLOCATE (almo_scf_env%quench_t_blk)
2770 IF (almo_scf_env%need_virtuals)
THEN
2771 DEALLOCATE (almo_scf_env%matrix_v_blk)
2772 DEALLOCATE (almo_scf_env%matrix_v_full_blk)
2773 DEALLOCATE (almo_scf_env%matrix_v)
2774 DEALLOCATE (almo_scf_env%matrix_vo)
2775 DEALLOCATE (almo_scf_env%matrix_x)
2776 DEALLOCATE (almo_scf_env%matrix_ov)
2777 DEALLOCATE (almo_scf_env%matrix_ov_full)
2778 DEALLOCATE (almo_scf_env%matrix_sigma_vv)
2779 DEALLOCATE (almo_scf_env%matrix_sigma_vv_blk)
2780 DEALLOCATE (almo_scf_env%matrix_sigma_vv_sqrt)
2781 DEALLOCATE (almo_scf_env%matrix_sigma_vv_sqrt_inv)
2782 DEALLOCATE (almo_scf_env%matrix_vv_full_blk)
2783 IF (almo_scf_env%deloc_truncate_virt /=
virt_full)
THEN
2784 DEALLOCATE (almo_scf_env%matrix_k_tr)
2785 DEALLOCATE (almo_scf_env%matrix_k_blk)
2786 DEALLOCATE (almo_scf_env%matrix_v_disc)
2787 DEALLOCATE (almo_scf_env%matrix_v_disc_blk)
2788 DEALLOCATE (almo_scf_env%matrix_ov_disc)
2789 DEALLOCATE (almo_scf_env%matrix_vv_disc_blk)
2790 DEALLOCATE (almo_scf_env%matrix_vv_disc)
2791 DEALLOCATE (almo_scf_env%matrix_k_blk_ones)
2792 DEALLOCATE (almo_scf_env%opt_k_t_dd)
2793 DEALLOCATE (almo_scf_env%opt_k_t_rr)
2794 DEALLOCATE (almo_scf_env%opt_k_denom)
2797 IF (almo_scf_env%need_previous_ks)
THEN
2798 DEALLOCATE (almo_scf_env%matrix_ks_0deloc)
2800 IF (almo_scf_env%need_orbital_energies)
THEN
2801 DEALLOCATE (almo_scf_env%matrix_eoo)
2802 DEALLOCATE (almo_scf_env%matrix_evv_full)
2806 DO ispin = 1, almo_scf_env%nspins
2808 almo_scf_env%domain_preconditioner(:, ispin))
2817 DEALLOCATE (almo_scf_env%domain_preconditioner)
2818 DEALLOCATE (almo_scf_env%domain_s_inv)
2819 DEALLOCATE (almo_scf_env%domain_s_sqrt_inv)
2820 DEALLOCATE (almo_scf_env%domain_s_sqrt)
2821 DEALLOCATE (almo_scf_env%domain_ks_xx)
2822 DEALLOCATE (almo_scf_env%domain_t)
2823 DEALLOCATE (almo_scf_env%domain_err)
2824 DEALLOCATE (almo_scf_env%domain_r_down_up)
2825 DO ispin = 1, almo_scf_env%nspins
2826 DEALLOCATE (almo_scf_env%domain_map(ispin)%pairs)
2827 DEALLOCATE (almo_scf_env%domain_map(ispin)%index1)
2829 DEALLOCATE (almo_scf_env%domain_map)
2830 DEALLOCATE (almo_scf_env%domain_index_of_ao)
2831 DEALLOCATE (almo_scf_env%domain_index_of_atom)
2832 DEALLOCATE (almo_scf_env%first_atom_of_domain)
2833 DEALLOCATE (almo_scf_env%last_atom_of_domain)
2834 DEALLOCATE (almo_scf_env%nbasis_of_domain)
2835 IF (
ALLOCATED(almo_scf_env%nocc_of_domain))
THEN
2836 DEALLOCATE (almo_scf_env%nocc_of_domain)
2838 DEALLOCATE (almo_scf_env%real_ne_of_domain)
2839 DEALLOCATE (almo_scf_env%nvirt_full_of_domain)
2840 DEALLOCATE (almo_scf_env%nvirt_of_domain)
2841 DEALLOCATE (almo_scf_env%nvirt_disc_of_domain)
2842 DEALLOCATE (almo_scf_env%mu_of_domain)
2843 DEALLOCATE (almo_scf_env%cpu_of_domain)
2844 DEALLOCATE (almo_scf_env%charge_of_domain)
2845 DEALLOCATE (almo_scf_env%multiplicity_of_domain)
2846 DEALLOCATE (almo_scf_env%activate)
2847 IF (almo_scf_env%smear)
THEN
2848 DEALLOCATE (almo_scf_env%mo_energies)
2849 DEALLOCATE (almo_scf_env%kTS)
2852 DEALLOCATE (almo_scf_env%domain_index_of_ao_block)
2853 DEALLOCATE (almo_scf_env%domain_index_of_mo_block)
2858 CALL timestop(handle)
2860 END SUBROUTINE almo_scf_clean_up
2871 SUBROUTINE almo_post_scf_compute_properties(qs_env)
2876 END SUBROUTINE almo_post_scf_compute_properties
Subroutines for ALMO SCF.
subroutine, public distribute_domains(almo_scf_env)
Load balancing of the submatrix computations.
subroutine, public almo_scf_p_blk_to_t_blk(almo_scf_env, ionic)
computes occupied ALMOs from the superimposed atomic density blocks
subroutine, public almo_scf_t_to_proj(t, p, eps_filter, orthog_orbs, nocc_of_domain, s, sigma, sigma_inv, use_guess, smear, algorithm, para_env, blacs_env, eps_lanczos, max_iter_lanczos, inverse_accelerator, inv_eps_factor)
computes the idempotent density matrix from MOs MOs can be either orthogonal or non-orthogonal
subroutine, public orthogonalize_mos(ket, overlap, metric, retain_locality, only_normalize, nocc_of_domain, eps_filter, order_lanczos, eps_lanczos, max_iter_lanczos, overlap_sqrti, smear)
orthogonalize MOs
subroutine, public almo_scf_t_rescaling(matrix_t, mo_energies, mu_of_domain, real_ne_of_domain, spin_kts, smear_e_temp, ndomains, nocc_of_domain)
Apply an occupation-rescaling trick to ALMOs for smearing. Partially occupied orbitals are considered...
Optimization routines for all ALMO-based SCF methods.
subroutine, public almo_scf_xalmo_trustr(qs_env, almo_scf_env, optimizer, quench_t, matrix_t_in, matrix_t_out, perturbation_only, special_case)
Optimization of ALMOs using trust region minimizers.
subroutine, public almo_scf_xalmo_pcg(qs_env, almo_scf_env, optimizer, quench_t, matrix_t_in, matrix_t_out, assume_t0_q0x, perturbation_only, special_case)
Optimization of ALMOs using PCG-like minimizers.
subroutine, public almo_scf_xalmo_eigensolver(qs_env, almo_scf_env, optimizer)
An eigensolver-based SCF to optimize extended ALMOs (i.e. ALMOs on overlapping domains)
subroutine, public almo_scf_construct_nlmos(qs_env, optimizer, matrix_s, matrix_mo_in, matrix_mo_out, template_matrix_sigma, overlap_determinant, mat_distr_aos, virtuals, eps_filter)
Optimization of NLMOs using PCG minimizers.
subroutine, public almo_scf_block_diagonal(qs_env, almo_scf_env, optimizer)
An SCF procedure that optimizes block-diagonal ALMOs using DIIS.
Interface between ALMO SCF and QS.
subroutine, public construct_qs_mos(qs_env, almo_scf_env)
Create MOs in the QS env to be able to return ALMOs to QS.
subroutine, public almo_dm_to_almo_ks(qs_env, matrix_p, matrix_ks, energy_total, eps_filter, mat_distr_aos, smear, kts_sum)
uses the ALMO density matrix to compute ALMO KS matrix and the new energy
subroutine, public calculate_w_matrix_almo(matrix_w, almo_scf_env)
Compute matrix W (energy-weighted density matrix) that is needed for the evaluation of forces.
subroutine, public matrix_almo_create(matrix_new, matrix_qs, almo_scf_env, name_new, size_keys, symmetry_new, spin_key, init_domains)
create the ALMO matrix templates
subroutine, public init_almo_ks_matrix_via_qs(qs_env, matrix_ks, mat_distr_aos, eps_filter)
Initialization of the QS and ALMO KS matrix.
subroutine, public matrix_qs_to_almo(matrix_qs, matrix_almo, mat_distr_aos)
convert between two types of matrices: QS style to ALMO style
subroutine, public almo_scf_construct_quencher(qs_env, almo_scf_env)
Creates the matrix that imposes absolute locality on MOs.
Types for all ALMO-based methods.
integer, parameter, public almo_mat_dim_occ
integer, parameter, public almo_mat_dim_virt_full
integer, parameter, public almo_mat_dim_aobasis
subroutine, public print_optimizer_options(optimizer, unit_nr)
Prints out the options of an optimizer.
integer, parameter, public almo_mat_dim_virt
integer, parameter, public almo_mat_dim_virt_disc
Routines for all ALMO-based SCF methods 'RZK-warning' marks unresolved issues.
subroutine, public almo_entry_scf(qs_env, calc_forces)
The entry point into ALMO SCF routines.
Define the atomic kind types and their sub types.
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public scheiber2018
integer, save, public kuhne2007
integer, save, public staub2019
integer, save, public khaliullin2013
integer, save, public rullan2026
integer, save, public kolafa2004
methods related to the blacs parallel environment
subroutine, public cp_blacs_env_release(blacs_env)
releases the given blacs_env
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_scale(matrix, alpha_scalar)
...
logical function, public dbcsr_iterator_blocks_left(iterator)
...
subroutine, public dbcsr_iterator_stop(iterator)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_multiply(transa, transb, alpha, matrix_a, matrix_b, beta, matrix_c, first_row, last_row, first_column, last_column, first_k, last_k, retain_sparsity, filter_eps, flop)
...
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
subroutine, public dbcsr_work_create(matrix, nblks_guess, sizedata_guess, n, work_mutable)
...
subroutine, public dbcsr_iterator_next_block(iterator, row, column, block, block_number_argument_has_been_removed, row_size, col_size, row_offset, col_offset, transposed)
...
subroutine, public dbcsr_filter(matrix, eps)
...
subroutine, public dbcsr_finalize(matrix)
...
subroutine, public dbcsr_iterator_start(iterator, matrix, shared, dynamic, dynamic_byrows)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_binary_read(filepath, distribution, matrix_new)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
real(kind=dp) function, public dbcsr_checksum(matrix, pos)
Calculates the checksum of a DBCSR matrix.
subroutine, public dbcsr_add_on_diag(matrix, alpha)
Adds the given scalar to the diagonal of the matrix. Reserves any missing diagonal blocks.
subroutine, public dbcsr_reserve_all_blocks(matrix)
Reserves all blocks.
subroutine, public dbcsr_init_random(matrix, keep_sparsity)
Fills the given matrix with random numbers.
Interface to (sca)lapack for the Cholesky based procedures.
subroutine, public cp_dbcsr_syevd(matrix, eigenvectors, eigenvalues, para_env, blacs_env)
...
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
represent a full matrix distributed on many processors
various routines to log and control the output. The idea is that decisions about where to log should ...
recursive integer function, public cp_logger_get_default_unit_nr(logger, local, skip_not_ionode)
asks the default unit number of the given logger. try to use cp_logger_get_unit_nr
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
Subroutines to handle submatrices.
Routines useful for iterative matrix calculations.
subroutine, public invert_hotelling(matrix_inverse, matrix, threshold, use_inv_as_guess, norm_convergence, filter_eps, accelerator_order, max_iter_lanczos, eps_lanczos, silent)
invert a symmetric positive definite matrix by Hotelling's method explicit symmetrization makes this ...
subroutine, public matrix_sqrt_newton_schulz(matrix_sqrt, matrix_sqrt_inv, matrix, threshold, order, eps_lanczos, max_iter_lanczos, symmetrize, converged, iounit)
compute the sqrt of a matrix via the sign function and the corresponding Newton-Schulz iterations the...
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_path_length
Collection of simple mathematical functions and subroutines.
elemental real(kind=dp) function, public binomial(n, k)
The binomial coefficient n over k for 0 <= k <= n is calculated, otherwise zero is returned.
Interface to the message passing library MPI.
subroutine, public mp_para_env_release(para_env)
releases the para object (to be called when you don't want anymore the shared copy of this object)
Define the data structure for the molecule information.
subroutine, public get_molecule_set_info(molecule_set, atom_to_mol, mol_to_first_atom, mol_to_last_atom, mol_to_nelectrons, mol_to_nbasis, mol_to_charge, mol_to_multiplicity)
returns information about molecules in the set.
Types used to generate the molecular SCF guess.
subroutine, public get_matrix_from_submatrices(mscfg_env, matrix_out, iset)
Creates a distributed matrix from MOs on fragments.
Define the data structure for the particle information.
Routine to return block diagonal density matrix. Blocks correspond to the atomic densities.
subroutine, public calculate_atomic_block_dm(pmatrix, matrix_s, atomic_kind_set, qs_kind_set, nspin, nelectron_spin, ounit, para_env)
returns a block diagonal density matrix. Blocks correspond to the atomic densities.
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
Routines to somehow generate an initial guess.
subroutine, public calculate_mopac_dm(pmat, matrix_s, has_unit_metric, dft_control, particle_set, atomic_kind_set, qs_kind_set, nspin, nelectron_spin, para_env)
returns a block diagonal density matrix. Blocks correspond to the mopac initial guess.
Define the quickstep kind type and their sub types.
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.
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_get(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
returns info about the density described by this object. If some representation is not available an e...
Utility routines for qs_scf.
subroutine, public qs_scf_compute_properties(qs_env, wf_type, do_mp2)
computes properties for a given hamilonian using the current wfn
module that contains the definitions of the scf types
Provides all information about an atomic kind.
type of a logger, at the moment it contains just a print level starting at which level it should be l...
stores all the informations relevant to an mpi environment
Provides all information about a quickstep kind.
keeps the density in various representations, keeping track of which ones are valid.