98#include "./base/base_uses.f90"
104 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'optimize_embedding_potential'
130 INTEGER :: ref_subsys_number
131 LOGICAL :: change_spin, open_shell_embed
132 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: all_nspins
134 INTEGER :: i_force_eval, nspins, sub_spin_1, &
135 sub_spin_2, total_spin
136 INTEGER,
DIMENSION(2) :: nelectron_spin
137 INTEGER,
DIMENSION(2, 3) :: all_spins
140 change_spin = .false.
141 open_shell_embed = .false.
142 ALLOCATE (all_nspins(ref_subsys_number))
143 IF (ref_subsys_number == 3)
THEN
145 DO i_force_eval = 1, ref_subsys_number
146 CALL get_qs_env(qs_env=force_env%sub_force_env(i_force_eval)%force_env%qs_env, &
147 nelectron_spin=nelectron_spin, dft_control=dft_control)
148 all_spins(:, i_force_eval) = nelectron_spin
149 nspins = dft_control%nspins
150 all_nspins(i_force_eval) = nspins
154 IF (.NOT. ((all_nspins(1) == 1) .AND. (all_nspins(2) == 1) .AND. (all_nspins(3) == 1)))
THEN
155 open_shell_embed = .true.
159 IF (open_shell_embed)
THEN
161 IF (all_nspins(3) == 1)
THEN
164 total_spin = all_spins(1, 3) - all_spins(2, 3)
166 IF (all_nspins(1) == 1)
THEN
169 sub_spin_1 = all_spins(1, 1) - all_spins(2, 1)
171 IF (all_nspins(2) == 1)
THEN
174 sub_spin_2 = all_spins(1, 2) - all_spins(2, 2)
176 IF ((sub_spin_1 + sub_spin_2) == total_spin)
THEN
177 change_spin = .false.
179 IF (abs(sub_spin_1 - sub_spin_2) == total_spin)
THEN
182 cpabort(
"Spin states of subsystems are not compatible.")
188 cpabort(
"Reference subsystem must be the third FORCE_EVAL.")
206 SUBROUTINE init_embed_pot(qs_env, embed_pot, add_const_pot, Fermi_Amaldi, const_pot, open_shell_embed, &
207 spin_embed_pot, pot_diff, Coulomb_guess, grid_opt)
210 LOGICAL :: add_const_pot, fermi_amaldi
212 LOGICAL :: open_shell_embed
216 INTEGER :: nelectrons
217 INTEGER,
DIMENSION(2) :: nelectron_spin
218 REAL(kind=
dp) :: factor
224 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env, &
225 nelectron_spin=nelectron_spin, &
226 v_hartree_rspace=v_hartree_r_space)
229 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
234 CALL auxbas_pw_pool%create_pw(embed_pot)
238 IF (open_shell_embed)
THEN
239 NULLIFY (spin_embed_pot)
240 ALLOCATE (spin_embed_pot)
241 CALL auxbas_pw_pool%create_pw(spin_embed_pot)
249 CALL auxbas_pw_pool%create_pw(pot_diff)
254 IF (add_const_pot .AND. (.NOT. grid_opt))
THEN
258 CALL auxbas_pw_pool%create_pw(const_pot)
263 IF (fermi_amaldi)
THEN
266 NULLIFY (v_hartree_r_space)
267 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env, &
268 v_hartree_rspace=v_hartree_r_space)
269 CALL pw_copy(v_hartree_r_space, embed_pot)
272 nelectrons = nelectron_spin(1) + nelectron_spin(2)
273 factor = (real(nelectrons,
dp) - 1.0_dp)/(real(nelectrons,
dp))
279 IF (.NOT. grid_opt)
CALL pw_copy(embed_pot, embed_pot)
297 INTEGER :: diff_size, i_dens, size_prev_dens
309 CALL read_opt_embed_section(opt_embed, opt_embed_section)
312 IF (.NOT. opt_embed%grid_opt)
THEN
323 CALL make_lri_object(qs_env, opt_embed%lri)
327 IF (opt_embed%open_shell_embed)
THEN
328 opt_embed%dimen_var_aux = 2*opt_embed%dimen_aux
330 opt_embed%dimen_var_aux = opt_embed%dimen_aux
334 NULLIFY (opt_embed%embed_pot_grad, opt_embed%embed_pot_coef, opt_embed%step, fm_struct)
336 NULLIFY (opt_embed%prev_embed_pot_grad, opt_embed%prev_embed_pot_coef, opt_embed%prev_step)
338 nrow_global=opt_embed%dimen_var_aux, ncol_global=1)
339 ALLOCATE (opt_embed%embed_pot_grad, opt_embed%embed_pot_coef, &
340 opt_embed%prev_embed_pot_grad, opt_embed%prev_embed_pot_coef, &
341 opt_embed%step, opt_embed%prev_step)
342 CALL cp_fm_create(opt_embed%embed_pot_grad, fm_struct, name=
"pot_grad")
343 CALL cp_fm_create(opt_embed%embed_pot_coef, fm_struct, name=
"pot_coef")
344 CALL cp_fm_create(opt_embed%prev_embed_pot_grad, fm_struct, name=
"prev_pot_grad")
345 CALL cp_fm_create(opt_embed%prev_embed_pot_coef, fm_struct, name=
"prev_pot_coef")
346 CALL cp_fm_create(opt_embed%step, fm_struct, name=
"step")
347 CALL cp_fm_create(opt_embed%prev_step, fm_struct, name=
"prev_step")
359 NULLIFY (opt_embed%embed_pot_hess, opt_embed%prev_embed_pot_hess, fm_struct)
361 nrow_global=opt_embed%dimen_var_aux, ncol_global=opt_embed%dimen_var_aux)
362 ALLOCATE (opt_embed%embed_pot_hess, opt_embed%prev_embed_pot_hess)
363 CALL cp_fm_create(opt_embed%embed_pot_hess, fm_struct, name=
"pot_Hess")
364 CALL cp_fm_create(opt_embed%prev_embed_pot_hess, fm_struct, name=
"prev_pot_Hess")
368 NULLIFY (fm_struct, opt_embed%kinetic_mat)
370 nrow_global=opt_embed%dimen_aux, ncol_global=opt_embed%dimen_aux)
371 ALLOCATE (opt_embed%kinetic_mat)
372 CALL cp_fm_create(opt_embed%kinetic_mat, fm_struct, name=
"kinetic_mat")
377 CALL cp_fm_set_all(opt_embed%embed_pot_hess, 0.0_dp, -1.0_dp)
378 CALL cp_fm_set_all(opt_embed%prev_embed_pot_hess, 0.0_dp, -1.0_dp)
386 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
387 NULLIFY (opt_embed%prev_subsys_dens)
388 size_prev_dens = sum(opt_embed%all_nspins(1:(
SIZE(opt_embed%all_nspins) - 1)))
389 ALLOCATE (opt_embed%prev_subsys_dens(size_prev_dens))
390 DO i_dens = 1, size_prev_dens
391 CALL auxbas_pw_pool%create_pw(opt_embed%prev_subsys_dens(i_dens))
392 CALL pw_zero(opt_embed%prev_subsys_dens(i_dens))
394 ALLOCATE (opt_embed%max_subsys_dens_diff(size_prev_dens))
397 ALLOCATE (opt_embed%w_func(opt_embed%n_iter))
398 opt_embed%w_func = 0.0_dp
402 IF (opt_embed%open_shell_embed) diff_size = 2
403 ALLOCATE (opt_embed%max_diff(diff_size))
404 ALLOCATE (opt_embed%int_diff(diff_size))
405 ALLOCATE (opt_embed%int_diff_square(diff_size))
408 IF (opt_embed%fab)
THEN
409 NULLIFY (opt_embed%prev_embed_pot)
410 ALLOCATE (opt_embed%prev_embed_pot)
411 CALL auxbas_pw_pool%create_pw(opt_embed%prev_embed_pot)
412 CALL pw_zero(opt_embed%prev_embed_pot)
413 IF (opt_embed%open_shell_embed)
THEN
414 NULLIFY (opt_embed%prev_spin_embed_pot)
415 ALLOCATE (opt_embed%prev_spin_embed_pot)
416 CALL auxbas_pw_pool%create_pw(opt_embed%prev_spin_embed_pot)
417 CALL pw_zero(opt_embed%prev_spin_embed_pot)
422 opt_embed%allowed_decrease = 0.0001_dp
425 opt_embed%reg_term = 0.0_dp
428 opt_embed%accept_step = .true.
429 opt_embed%newton_step = .false.
430 opt_embed%last_accepted = 1
433 opt_embed%max_trad = opt_embed%trust_rad*7.900_dp
434 opt_embed%min_trad = opt_embed%trust_rad*0.125*0.065_dp
443 SUBROUTINE read_opt_embed_section(opt_embed, opt_embed_section)
447 INTEGER :: embed_guess, embed_optimizer
451 r_val=opt_embed%lambda)
454 i_val=opt_embed%n_iter)
457 r_val=opt_embed%trust_rad)
460 r_val=opt_embed%conv_max)
463 r_val=opt_embed%conv_int)
466 r_val=opt_embed%conv_max_spin)
469 r_val=opt_embed%conv_int_spin)
475 l_val=opt_embed%read_embed_pot)
478 l_val=opt_embed%read_embed_pot_cube)
481 l_val=opt_embed%grid_opt)
484 l_val=opt_embed%leeuwen)
490 r_val=opt_embed%vw_cutoff)
493 r_val=opt_embed%vw_smooth_cutoff_range)
496 SELECT CASE (embed_optimizer)
498 opt_embed%steep_desc = .true.
500 opt_embed%steep_desc = .false.
501 opt_embed%level_shift = .false.
503 opt_embed%steep_desc = .false.
504 opt_embed%level_shift = .true.
506 opt_embed%steep_desc = .true.
510 SELECT CASE (embed_guess)
512 opt_embed%add_const_pot = .false.
513 opt_embed%Fermi_Amaldi = .false.
514 opt_embed%Coulomb_guess = .false.
515 opt_embed%diff_guess = .false.
517 opt_embed%add_const_pot = .true.
518 opt_embed%Fermi_Amaldi = .false.
519 opt_embed%Coulomb_guess = .false.
520 opt_embed%diff_guess = .true.
522 opt_embed%add_const_pot = .true.
523 opt_embed%Fermi_Amaldi = .true.
524 opt_embed%Coulomb_guess = .false.
525 opt_embed%diff_guess = .false.
527 opt_embed%add_const_pot = .true.
528 opt_embed%Fermi_Amaldi = .true.
529 opt_embed%Coulomb_guess = .true.
530 opt_embed%diff_guess = .false.
532 opt_embed%add_const_pot = .false.
533 opt_embed%Fermi_Amaldi = .false.
534 opt_embed%Coulomb_guess = .false.
535 opt_embed%diff_guess = .false.
538 END SUBROUTINE read_opt_embed_section
549 INTEGER :: iatom, ikind, nsgf
550 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: kind_of
553 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
557 particle_set=particle_set, &
558 qs_kind_set=qs_kind_set, &
559 atomic_kind_set=atomic_kind_set)
564 DO iatom = 1,
SIZE(particle_set)
565 ikind = kind_of(iatom)
566 CALL get_qs_kind(qs_kind=qs_kind_set(ikind), nsgf=nsgf, basis_type=
"RI_AUX")
567 dimen_aux = dimen_aux + nsgf
577 SUBROUTINE make_lri_object(qs_env, lri)
581 INTEGER :: ikind, natom, nkind, nsgf
584 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
586 NULLIFY (atomic_kind, lri)
587 CALL get_qs_env(qs_env=qs_env, atomic_kind_set=atomic_kind_set, &
588 qs_kind_set=qs_kind_set)
589 nkind =
SIZE(atomic_kind_set)
591 ALLOCATE (lri(nkind))
594 NULLIFY (lri(ikind)%acoef)
595 NULLIFY (lri(ikind)%v_int)
596 atomic_kind => atomic_kind_set(ikind)
598 CALL get_qs_kind(qs_kind=qs_kind_set(ikind), nsgf=nsgf, basis_type=
"RI_AUX")
599 ALLOCATE (lri(ikind)%acoef(natom, nsgf))
600 lri(ikind)%acoef = 0._dp
601 ALLOCATE (lri(ikind)%v_int(natom, nsgf))
602 lri(ikind)%v_int = 0._dp
605 END SUBROUTINE make_lri_object
614 LOGICAL :: open_shell_embed
621 qs_env%given_embed_pot = .true.
622 NULLIFY (input, dft_control, embed_pot, spin_embed_pot, embed_pot, spin_embed_pot, &
626 dft_control=dft_control, &
629 open_shell_embed = .false.
630 IF (dft_control%nspins == 2) open_shell_embed = .true.
633 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool_subsys)
639 CALL auxbas_pw_pool_subsys%create_pw(embed_pot)
640 IF (open_shell_embed)
THEN
642 ALLOCATE (spin_embed_pot)
643 CALL auxbas_pw_pool_subsys%create_pw(spin_embed_pot)
646 CALL read_embed_pot_cube(embed_pot, spin_embed_pot, qs_section, open_shell_embed)
648 IF (.NOT. open_shell_embed)
THEN
649 CALL set_qs_env(qs_env=qs_env, embed_pot=embed_pot)
651 CALL set_qs_env(qs_env=qs_env, embed_pot=embed_pot, spin_embed_pot=spin_embed_pot)
671 IF (opt_embed%read_embed_pot)
THEN
672 CALL read_embed_pot_vector(qs_env, embed_pot, spin_embed_pot, section, &
673 opt_embed%embed_pot_coef, opt_embed%open_shell_embed)
676 IF (opt_embed%read_embed_pot_cube)
THEN
677 CALL read_embed_pot_cube(embed_pot, spin_embed_pot, section, opt_embed%open_shell_embed)
689 SUBROUTINE read_embed_pot_cube(embed_pot, spin_embed_pot, section, open_shell_embed)
692 LOGICAL :: open_shell_embed
694 CHARACTER(LEN=default_path_length) :: filename
696 REAL(kind=
dp) :: scaling_factor
700 INQUIRE (file=filename, exist=exist)
701 IF (.NOT. exist)
THEN
702 cpabort(
"Embedding cube file not found. ")
705 scaling_factor = 1.0_dp
709 IF (open_shell_embed)
THEN
712 INQUIRE (file=filename, exist=exist)
713 IF (.NOT. exist)
THEN
714 cpabort(
"Embedding spin cube file not found. ")
717 scaling_factor = 1.0_dp
721 END SUBROUTINE read_embed_pot_cube
732 SUBROUTINE read_embed_pot_vector(qs_env, embed_pot, spin_embed_pot, section, embed_pot_coef, open_shell_embed)
737 TYPE(
cp_fm_type),
INTENT(IN) :: embed_pot_coef
738 LOGICAL,
INTENT(IN) :: open_shell_embed
740 CHARACTER(LEN=default_path_length) :: filename
741 INTEGER :: dimen_aux, dimen_restart_basis, &
742 dimen_var_aux, l_global, lll, &
743 nrow_local, restart_unit
744 INTEGER,
DIMENSION(:),
POINTER :: row_indices
745 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: coef, coef_read
753 IF (open_shell_embed)
THEN
754 dimen_var_aux = dimen_aux*2
756 dimen_var_aux = dimen_aux
766 nrow_global=dimen_var_aux, ncol_global=1)
767 CALL cp_fm_create(my_embed_pot_coef, fm_struct, name=
"my_pot_coef")
776 ALLOCATE (coef(dimen_var_aux))
779 IF (para_env%is_source())
THEN
782 CALL embed_restart_file_name(filename, section)
785 file_action=
"READ", &
786 file_form=
"UNFORMATTED", &
788 unit_number=restart_unit)
790 READ (restart_unit) dimen_restart_basis
792 IF (.NOT. (dimen_restart_basis == dimen_aux))
THEN
793 cpabort(
"Wrong dimension of the embedding basis in the restart file.")
796 ALLOCATE (coef_read(dimen_var_aux))
799 READ (restart_unit) coef_read
800 coef(:) = coef_read(:)
801 DEALLOCATE (coef_read)
809 CALL para_env%bcast(coef)
814 nrow_local=nrow_local, &
815 row_indices=row_indices)
817 DO lll = 1, nrow_local
818 l_global = row_indices(lll)
819 my_embed_pot_coef%local_data(lll, 1) = coef(l_global)
828 CALL update_embed_pot(embed_pot_coef, dimen_aux, embed_pot, spin_embed_pot, &
829 qs_env, .false., open_shell_embed)
837 END SUBROUTINE read_embed_pot_vector
844 SUBROUTINE embed_restart_file_name(filename, section)
845 CHARACTER(LEN=default_path_length),
INTENT(OUT) :: filename
852 INQUIRE (file=filename, exist=exist)
853 IF (.NOT. exist)
THEN
854 cpabort(
"Embedding restart file not found. ")
857 END SUBROUTINE embed_restart_file_name
866 INTEGER :: i_dens, i_spin, ikind
868 IF (.NOT. opt_embed%grid_opt)
THEN
878 DEALLOCATE (opt_embed%embed_pot_grad, opt_embed%embed_pot_coef, &
879 opt_embed%step, opt_embed%prev_step, opt_embed%embed_pot_hess, &
880 opt_embed%prev_embed_pot_grad, opt_embed%prev_embed_pot_coef, &
881 opt_embed%prev_embed_pot_hess, opt_embed%kinetic_mat)
882 DEALLOCATE (opt_embed%w_func)
883 DEALLOCATE (opt_embed%max_diff)
884 DEALLOCATE (opt_embed%int_diff)
886 DO ikind = 1,
SIZE(opt_embed%lri)
887 DEALLOCATE (opt_embed%lri(ikind)%v_int)
888 DEALLOCATE (opt_embed%lri(ikind)%acoef)
890 DEALLOCATE (opt_embed%lri)
893 IF (
ASSOCIATED(opt_embed%prev_subsys_dens))
THEN
894 DO i_dens = 1,
SIZE(opt_embed%prev_subsys_dens)
895 CALL opt_embed%prev_subsys_dens(i_dens)%release()
897 DEALLOCATE (opt_embed%prev_subsys_dens)
899 DEALLOCATE (opt_embed%max_subsys_dens_diff)
901 DEALLOCATE (opt_embed%all_nspins)
903 IF (
ASSOCIATED(opt_embed%const_pot))
THEN
904 CALL opt_embed%const_pot%release()
905 DEALLOCATE (opt_embed%const_pot)
908 IF (
ASSOCIATED(opt_embed%pot_diff))
THEN
909 CALL opt_embed%pot_diff%release()
910 DEALLOCATE (opt_embed%pot_diff)
913 IF (
ASSOCIATED(opt_embed%prev_embed_pot))
THEN
914 CALL opt_embed%prev_embed_pot%release()
915 DEALLOCATE (opt_embed%prev_embed_pot)
917 IF (
ASSOCIATED(opt_embed%prev_spin_embed_pot))
THEN
918 CALL opt_embed%prev_spin_embed_pot%release()
919 DEALLOCATE (opt_embed%prev_spin_embed_pot)
921 IF (
ASSOCIATED(opt_embed%v_w))
THEN
922 DO i_spin = 1,
SIZE(opt_embed%v_w)
923 CALL opt_embed%v_w(i_spin)%release()
925 DEALLOCATE (opt_embed%v_w)
940 SUBROUTINE coulomb_guess(v_rspace, rhs, mapping_section, qs_env, nforce_eval, iforce_eval, eta)
942 REAL(kind=
dp),
DIMENSION(:),
POINTER :: rhs
945 INTEGER :: nforce_eval, iforce_eval
948 INTEGER :: iparticle, jparticle, natom
949 INTEGER,
DIMENSION(:),
POINTER :: map_index
950 REAL(kind=
dp) :: dvol, normalize_factor
951 REAL(kind=
dp),
DIMENSION(:),
POINTER :: rhs_subsys
962 CALL get_qs_env(qs_env=qs_env, subsys=subsys, pw_env=pw_env)
964 natom = particles%n_els
966 ALLOCATE (rhs_subsys(natom))
973 DO iparticle = 1, natom
974 jparticle = map_index(iparticle)
975 rhs_subsys(iparticle) = rhs(jparticle)
979 NULLIFY (auxbas_pw_pool)
981 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
982 poisson_env=poisson_env)
984 CALL auxbas_pw_pool%create_pw(v_resp_gspace)
986 CALL auxbas_pw_pool%create_pw(v_resp_rspace)
988 CALL auxbas_pw_pool%create_pw(rho_resp)
996 vhartree=v_resp_rspace)
997 dvol = v_resp_rspace%pw_grid%dvol
999 normalize_factor = sqrt((eta/
pi)**3)
1001 CALL pw_scale(v_resp_rspace, normalize_factor)
1004 CALL pw_copy(v_resp_rspace, v_rspace)
1007 CALL v_resp_gspace%release()
1008 CALL v_resp_rspace%release()
1009 CALL rho_resp%release()
1012 DEALLOCATE (map_index)
1014 DEALLOCATE (rhs_subsys)
1030 spin_embed_pot, spin_embed_pot_subsys, open_shell_embed, &
1037 LOGICAL :: open_shell_embed, change_spin_sign
1046 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool_subsys)
1049 NULLIFY (embed_pot_subsys)
1050 ALLOCATE (embed_pot_subsys)
1051 CALL auxbas_pw_pool_subsys%create_pw(embed_pot_subsys)
1054 CALL pw_copy(embed_pot, embed_pot_subsys)
1056 IF (open_shell_embed)
THEN
1057 NULLIFY (spin_embed_pot_subsys)
1058 ALLOCATE (spin_embed_pot_subsys)
1059 CALL auxbas_pw_pool_subsys%create_pw(spin_embed_pot_subsys)
1061 IF (change_spin_sign)
THEN
1062 CALL pw_axpy(spin_embed_pot, spin_embed_pot_subsys, -1.0_dp, 0.0_dp, allow_noncompatible_grids=.true.)
1064 CALL pw_copy(spin_embed_pot, spin_embed_pot_subsys)
1084 CHARACTER(LEN=*),
PARAMETER :: routinen =
'calculate_embed_pot_grad'
1090 embed_pot_coeff_spinless, &
1091 regular_term, spin_reg, spinless_reg
1096 CALL timeset(routinen, handle)
1100 CALL cp_fm_to_fm(opt_embed%embed_pot_grad, opt_embed%prev_embed_pot_grad)
1101 CALL cp_fm_to_fm(opt_embed%embed_pot_Hess, opt_embed%prev_embed_pot_Hess)
1105 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env, para_env=para_env)
1108 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
1111 CALL calculate_embed_pot_grad_inner(qs_env, opt_embed%dimen_aux, diff_rho_r, diff_rho_spin, &
1112 opt_embed%embed_pot_grad, &
1113 opt_embed%open_shell_embed, opt_embed%lri)
1116 IF (opt_embed%i_iter == 1)
THEN
1117 CALL compute_kinetic_mat(qs_env, opt_embed%kinetic_mat)
1121 matrix_struct=fm_struct)
1122 CALL cp_fm_create(regular_term, fm_struct, name=
"regular_term")
1127 IF (opt_embed%open_shell_embed)
THEN
1129 NULLIFY (fm_struct, blacs_env)
1133 CALL cp_fm_get_info(matrix=opt_embed%embed_pot_coef, context=blacs_env)
1135 nrow_global=opt_embed%dimen_aux, ncol_global=1)
1136 CALL cp_fm_create(embed_pot_coeff_spinless, fm_struct, name=
"pot_coeff_spinless")
1137 CALL cp_fm_create(embed_pot_coeff_spin, fm_struct, name=
"pot_coeff_spin")
1138 CALL cp_fm_create(spinless_reg, fm_struct, name=
"spinless_reg")
1139 CALL cp_fm_create(spin_reg, fm_struct, name=
"spin_reg")
1148 mtarget=embed_pot_coeff_spinless, &
1149 nrow=opt_embed%dimen_aux, ncol=1, &
1150 s_firstrow=1, s_firstcol=1, &
1151 t_firstrow=1, t_firstcol=1)
1153 mtarget=embed_pot_coeff_spin, &
1154 nrow=opt_embed%dimen_aux, ncol=1, &
1155 s_firstrow=opt_embed%dimen_aux + 1, s_firstcol=1, &
1156 t_firstrow=1, t_firstcol=1)
1158 CALL parallel_gemm(transa=
"N", transb=
"N", m=opt_embed%dimen_aux, n=1, &
1159 k=opt_embed%dimen_aux, alpha=1.0_dp, &
1160 matrix_a=opt_embed%kinetic_mat, matrix_b=embed_pot_coeff_spinless, &
1161 beta=0.0_dp, matrix_c=spinless_reg)
1162 CALL parallel_gemm(transa=
"N", transb=
"N", m=opt_embed%dimen_aux, n=1, &
1163 k=opt_embed%dimen_aux, alpha=1.0_dp, &
1164 matrix_a=opt_embed%kinetic_mat, matrix_b=embed_pot_coeff_spin, &
1165 beta=0.0_dp, matrix_c=spin_reg)
1168 mtarget=regular_term, &
1169 nrow=opt_embed%dimen_aux, ncol=1, &
1170 s_firstrow=1, s_firstcol=1, &
1171 t_firstrow=1, t_firstcol=1)
1173 mtarget=regular_term, &
1174 nrow=opt_embed%dimen_aux, ncol=1, &
1175 s_firstrow=1, s_firstcol=1, &
1176 t_firstrow=opt_embed%dimen_aux + 1, t_firstcol=1)
1184 CALL parallel_gemm(transa=
"N", transb=
"N", m=opt_embed%dimen_var_aux, n=1, &
1185 k=opt_embed%dimen_var_aux, alpha=1.0_dp, &
1186 matrix_a=opt_embed%kinetic_mat, matrix_b=opt_embed%embed_pot_coef, &
1187 beta=0.0_dp, matrix_c=regular_term)
1191 CALL cp_fm_scale_and_add(1.0_dp, opt_embed%embed_pot_grad, 4.0_dp*opt_embed%lambda, regular_term)
1194 CALL cp_fm_trace(opt_embed%embed_pot_coef, regular_term, opt_embed%reg_term)
1195 opt_embed%reg_term = 2.0_dp*opt_embed%lambda*opt_embed%reg_term
1200 CALL timestop(handle)
1215 SUBROUTINE calculate_embed_pot_grad_inner(qs_env, dimen_aux, rho_r, rho_spin, embed_pot_grad, &
1216 open_shell_embed, lri)
1218 INTEGER :: dimen_aux
1220 TYPE(
cp_fm_type),
INTENT(IN) :: embed_pot_grad
1221 LOGICAL :: open_shell_embed
1224 CHARACTER(LEN=*),
PARAMETER :: routinen =
'calculate_embed_pot_grad_inner'
1226 INTEGER :: handle, iatom, ikind, l_global, lll, &
1227 nrow_local, nsgf, start_pos
1228 INTEGER,
DIMENSION(:),
POINTER :: row_indices
1229 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: pot_grad
1235 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1239 CALL timeset(routinen, handle)
1242 particle_set=particle_set, &
1243 qs_kind_set=qs_kind_set, &
1244 dft_control=dft_control, &
1246 atomic_kind_set=atomic_kind_set, &
1250 IF (open_shell_embed)
THEN
1251 ALLOCATE (pot_grad(dimen_aux*2))
1253 ALLOCATE (pot_grad(dimen_aux))
1257 DO ikind = 1,
SIZE(lri)
1258 lri(ikind)%v_int = 0.0_dp
1263 DO ikind = 1,
SIZE(lri)
1264 CALL para_env%sum(lri(ikind)%v_int)
1269 DO ikind = 1,
SIZE(lri)
1270 DO iatom = 1,
SIZE(lri(ikind)%v_int, dim=1)
1271 nsgf =
SIZE(lri(ikind)%v_int(iatom, :))
1272 pot_grad(start_pos:start_pos + nsgf - 1) = lri(ikind)%v_int(iatom, :)
1273 start_pos = start_pos + nsgf
1278 IF (open_shell_embed)
THEN
1279 DO ikind = 1,
SIZE(lri)
1280 lri(ikind)%v_int = 0.0_dp
1285 DO ikind = 1,
SIZE(lri)
1286 CALL para_env%sum(lri(ikind)%v_int)
1289 start_pos = dimen_aux + 1
1290 DO ikind = 1,
SIZE(lri)
1291 DO iatom = 1,
SIZE(lri(ikind)%v_int, dim=1)
1292 nsgf =
SIZE(lri(ikind)%v_int(iatom, :))
1293 pot_grad(start_pos:start_pos + nsgf - 1) = lri(ikind)%v_int(iatom, :)
1294 start_pos = start_pos + nsgf
1300 pot_grad = pot_grad*rho_r%pw_grid%dvol
1304 nrow_local=nrow_local, &
1305 row_indices=row_indices)
1308 DO lll = 1, nrow_local
1309 l_global = row_indices(lll)
1310 embed_pot_grad%local_data(lll, 1) = pot_grad(l_global)
1313 DEALLOCATE (pot_grad)
1315 CALL timestop(handle)
1317 END SUBROUTINE calculate_embed_pot_grad_inner
1325 SUBROUTINE compute_kinetic_mat(qs_env, kinetic_mat)
1327 TYPE(
cp_fm_type),
INTENT(INOUT) :: kinetic_mat
1329 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_kinetic_mat'
1337 CALL timeset(routinen, handle)
1339 NULLIFY (ks_env, sab_orb, matrix_t)
1342 CALL get_qs_env(qs_env=qs_env, ks_env=ks_env, sab_orb=sab_orb)
1346 matrix_name=
"KINETIC ENERGY MATRIX", &
1347 basis_type=
"RI_AUX", &
1348 sab_nl=sab_orb, calculate_forces=.false.)
1356 CALL timestop(handle)
1358 END SUBROUTINE compute_kinetic_mat
1367 SUBROUTINE grid_regularize(potential, pw_env, lambda, reg_term)
1371 REAL(kind=
dp) :: lambda, reg_term
1374 INTEGER,
DIMENSION(3) :: lb, n, ub
1386 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
1388 CALL auxbas_pw_pool%create_pw(potential_g)
1390 CALL auxbas_pw_pool%create_pw(dr2_pot)
1392 CALL auxbas_pw_pool%create_pw(grid_reg)
1394 CALL auxbas_pw_pool%create_pw(grid_reg_g)
1402 CALL pw_dr2(potential_g, dr2_pot, i, i)
1403 CALL pw_axpy(dr2_pot, grid_reg_g, 1.0_dp)
1409 CALL pw_axpy(grid_reg, potential, -4.0_dp*lambda)
1415 CALL auxbas_pw_pool%create_pw(dpot(i))
1416 CALL auxbas_pw_pool%create_pw(dpot_g(i))
1419 CALL auxbas_pw_pool%create_pw(square_norm_dpot)
1424 CALL pw_copy(potential_g, dpot_g(i))
1429 lb(1:3) = square_norm_dpot%pw_grid%bounds_local(1, 1:3)
1430 ub(1:3) = square_norm_dpot%pw_grid%bounds_local(2, 1:3)
1437 square_norm_dpot%array(i, j, k) = (dpot(1)%array(i, j, k)* &
1438 dpot(1)%array(i, j, k) + &
1439 dpot(2)%array(i, j, k)* &
1440 dpot(2)%array(i, j, k) + &
1441 dpot(3)%array(i, j, k)* &
1442 dpot(3)%array(i, j, k))
1451 CALL auxbas_pw_pool%give_back_pw(potential_g)
1452 CALL auxbas_pw_pool%give_back_pw(dr2_pot)
1453 CALL auxbas_pw_pool%give_back_pw(grid_reg)
1454 CALL auxbas_pw_pool%give_back_pw(grid_reg_g)
1455 CALL auxbas_pw_pool%give_back_pw(square_norm_dpot)
1457 CALL auxbas_pw_pool%give_back_pw(dpot(i))
1458 CALL auxbas_pw_pool%give_back_pw(dpot_g(i))
1461 END SUBROUTINE grid_regularize
1474 SUBROUTINE opt_embed_step(diff_rho_r, diff_rho_spin, opt_embed, embed_pot, spin_embed_pot, rho_r_ref, qs_env)
1483 CHARACTER(LEN=*),
PARAMETER :: routinen =
'opt_embed_step'
1484 REAL(kind=
dp),
PARAMETER :: thresh = 0.000001_dp
1486 INTEGER :: handle, l_global, lll, nrow_local
1487 INTEGER,
DIMENSION(:),
POINTER :: row_indices
1488 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigenval
1490 TYPE(
cp_fm_type) :: diag_grad, diag_step, fm_u, fm_u_scale
1493 CALL timeset(routinen, handle)
1495 IF (opt_embed%grid_opt)
THEN
1497 opt_embed%step_len = opt_embed%trust_rad
1498 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
1499 IF (opt_embed%leeuwen)
THEN
1500 CALL leeuwen_baerends_potential_update(pw_env, embed_pot, spin_embed_pot, diff_rho_r, diff_rho_spin, &
1501 rho_r_ref, opt_embed%open_shell_embed, opt_embed%trust_rad)
1503 IF (opt_embed%fab)
THEN
1504 CALL fab_update(qs_env, rho_r_ref, opt_embed%prev_embed_pot, opt_embed%prev_spin_embed_pot, &
1505 embed_pot, spin_embed_pot, &
1506 diff_rho_r, diff_rho_spin, opt_embed%v_w, opt_embed%i_iter, opt_embed%trust_rad, &
1507 opt_embed%open_shell_embed, opt_embed%vw_cutoff, opt_embed%vw_smooth_cutoff_range)
1509 CALL grid_based_step(diff_rho_r, diff_rho_spin, pw_env, opt_embed, embed_pot, spin_embed_pot)
1515 IF (.NOT. opt_embed%accept_step)
THEN
1520 IF (opt_embed%steep_desc)
THEN
1521 IF (opt_embed%i_iter > 2)
THEN
1522 opt_embed%trust_rad = barzilai_borwein(opt_embed%step, opt_embed%prev_step, &
1523 opt_embed%embed_pot_grad, opt_embed%prev_embed_pot_grad)
1525 IF (abs(opt_embed%trust_rad) > opt_embed%max_trad)
THEN
1526 IF (opt_embed%trust_rad > 0.0_dp)
THEN
1527 opt_embed%trust_rad = opt_embed%max_trad
1529 opt_embed%trust_rad = -opt_embed%max_trad
1533 CALL cp_fm_to_fm(opt_embed%step, opt_embed%prev_step)
1536 CALL cp_fm_scale_and_add(1.0_dp, opt_embed%step, opt_embed%trust_rad, opt_embed%embed_pot_grad)
1537 opt_embed%step_len = opt_embed%trust_rad
1541 IF (opt_embed%i_iter > 1)
THEN
1542 IF (opt_embed%accept_step)
THEN
1544 CALL symm_rank_one_update(opt_embed%embed_pot_grad, opt_embed%prev_embed_pot_grad, &
1545 opt_embed%step, opt_embed%prev_embed_pot_Hess, opt_embed%embed_pot_Hess)
1555 ALLOCATE (eigenval(opt_embed%dimen_var_aux))
1558 matrix_struct=fm_struct)
1564 matrix_struct=fm_struct)
1565 CALL cp_fm_create(diag_grad, fm_struct, name=
"diag_grad")
1567 CALL cp_fm_create(diag_step, fm_struct, name=
"diag_step")
1571 CALL cp_fm_to_fm(opt_embed%embed_pot_hess, fm_u_scale)
1577 CALL cp_fm_to_fm(fm_u_scale, opt_embed%embed_pot_hess)
1580 CALL parallel_gemm(transa=
"T", transb=
"N", m=opt_embed%dimen_var_aux, n=1, &
1581 k=opt_embed%dimen_var_aux, alpha=1.0_dp, &
1582 matrix_a=fm_u, matrix_b=opt_embed%embed_pot_grad, beta=0.0_dp, &
1586 nrow_local=nrow_local, &
1587 row_indices=row_indices)
1589 DO lll = 1, nrow_local
1590 l_global = row_indices(lll)
1591 IF (abs(eigenval(l_global)) >= thresh)
THEN
1592 diag_step%local_data(lll, 1) = &
1593 -diag_grad%local_data(lll, 1)/(eigenval(l_global))
1595 diag_step%local_data(lll, 1) = 0.0_dp
1598 CALL cp_fm_trace(diag_step, diag_step, opt_embed%step_len)
1601 CALL parallel_gemm(transa=
"N", transb=
"N", m=opt_embed%dimen_var_aux, n=1, &
1602 k=opt_embed%dimen_var_aux, alpha=1.0_dp, &
1603 matrix_a=fm_u, matrix_b=diag_step, beta=0.0_dp, &
1604 matrix_c=opt_embed%step)
1614 CALL cp_fm_trace(opt_embed%step, opt_embed%step, opt_embed%step_len)
1615 IF (opt_embed%step_len > opt_embed%trust_rad)
THEN
1617 IF (opt_embed%level_shift)
THEN
1619 CALL level_shift(opt_embed, diag_grad, eigenval, diag_step)
1621 CALL cp_fm_trace(diag_step, diag_step, opt_embed%step_len)
1622 CALL cp_fm_scale(opt_embed%trust_rad/opt_embed%step_len, diag_step)
1624 CALL cp_fm_trace(diag_step, diag_step, opt_embed%step_len)
1626 CALL parallel_gemm(transa=
"N", transb=
"N", m=opt_embed%dimen_var_aux, n=1, &
1627 k=opt_embed%dimen_var_aux, alpha=1.0_dp, &
1628 matrix_a=fm_u, matrix_b=diag_step, beta=0.0_dp, &
1629 matrix_c=opt_embed%step)
1630 CALL cp_fm_trace(opt_embed%step, opt_embed%step, opt_embed%step_len)
1633 opt_embed%newton_step = .false.
1635 opt_embed%newton_step = .true.
1639 DEALLOCATE (eigenval)
1651 CALL update_embed_pot(opt_embed%embed_pot_coef, opt_embed%dimen_aux, embed_pot, &
1652 spin_embed_pot, qs_env, opt_embed%add_const_pot, &
1653 opt_embed%open_shell_embed, opt_embed%const_pot)
1656 CALL timestop(handle)
1670 SUBROUTINE grid_based_step(diff_rho_r, diff_rho_spin, pw_env, opt_embed, embed_pot, spin_embed_pot)
1678 CHARACTER(LEN=*),
PARAMETER :: routinen =
'grid_based_step'
1681 REAL(kind=
dp) :: my_reg_term
1683 CALL timeset(routinen, handle)
1686 CALL pw_axpy(diff_rho_r, embed_pot, opt_embed%step_len)
1688 CALL grid_regularize(embed_pot, pw_env, opt_embed%lambda, my_reg_term)
1689 opt_embed%reg_term = opt_embed%reg_term + my_reg_term
1691 IF (opt_embed%open_shell_embed)
THEN
1692 CALL pw_axpy(diff_rho_spin, spin_embed_pot, opt_embed%step_len)
1693 CALL grid_regularize(spin_embed_pot, pw_env, opt_embed%lambda, my_reg_term)
1694 opt_embed%reg_term = opt_embed%reg_term + my_reg_term
1697 CALL timestop(handle)
1699 END SUBROUTINE grid_based_step
1714 SUBROUTINE update_embed_pot(embed_pot_coef, dimen_aux, embed_pot, spin_embed_pot, &
1715 qs_env, add_const_pot, open_shell_embed, const_pot)
1716 TYPE(
cp_fm_type),
INTENT(IN) :: embed_pot_coef
1717 INTEGER :: dimen_aux
1721 LOGICAL :: add_const_pot, open_shell_embed
1724 CHARACTER(LEN=*),
PARAMETER :: routinen =
'update_embed_pot'
1726 INTEGER :: handle, l_global, lll, nrow_local
1727 INTEGER,
DIMENSION(:),
POINTER :: row_indices
1728 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: wf_vector
1734 embed_pot_coef_spinless
1744 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1746 CALL timeset(routinen, handle)
1749 particle_set=particle_set, &
1750 qs_kind_set=qs_kind_set, &
1751 dft_control=dft_control, &
1753 atomic_kind_set=atomic_kind_set, &
1754 pw_env=pw_env, mos=mos, para_env=para_env)
1755 CALL get_mo_set(mo_set=mos(1), mo_coeff=mo_coeff)
1758 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
1761 CALL auxbas_pw_pool%create_pw(rho_g)
1763 CALL auxbas_pw_pool%create_pw(psi_l)
1766 ALLOCATE (wf_vector(dimen_aux))
1770 IF (open_shell_embed)
THEN
1774 nrow_global=dimen_aux, ncol_global=1)
1775 CALL cp_fm_create(embed_pot_coef_spinless, fm_struct, name=
"pot_coeff_spinless")
1776 CALL cp_fm_create(embed_pot_coef_spin, fm_struct, name=
"pot_coeff_spin")
1783 mtarget=embed_pot_coef_spinless, &
1784 nrow=dimen_aux, ncol=1, &
1785 s_firstrow=1, s_firstcol=1, &
1786 t_firstrow=1, t_firstcol=1)
1788 mtarget=embed_pot_coef_spin, &
1789 nrow=dimen_aux, ncol=1, &
1790 s_firstrow=dimen_aux + 1, s_firstcol=1, &
1791 t_firstrow=1, t_firstcol=1)
1795 nrow_local=nrow_local, &
1796 row_indices=row_indices)
1799 DO lll = 1, nrow_local
1800 l_global = row_indices(lll)
1801 wf_vector(l_global) = embed_pot_coef_spinless%local_data(lll, 1)
1803 CALL para_env%sum(wf_vector)
1807 qs_kind_set, cell, particle_set, pw_env, &
1808 dft_control%qs_control%eps_rho_rspace, &
1809 basis_type=
"RI_AUX")
1811 IF (add_const_pot)
THEN
1812 CALL pw_copy(const_pot, embed_pot)
1817 CALL pw_axpy(psi_l, embed_pot)
1822 nrow_local=nrow_local, &
1823 row_indices=row_indices)
1826 DO lll = 1, nrow_local
1827 l_global = row_indices(lll)
1828 wf_vector(l_global) = embed_pot_coef_spin%local_data(lll, 1)
1830 CALL para_env%sum(wf_vector)
1834 qs_kind_set, cell, particle_set, pw_env, &
1835 dft_control%qs_control%eps_rho_rspace, &
1836 basis_type=
"RI_AUX")
1839 CALL pw_axpy(psi_l, spin_embed_pot)
1844 nrow_local=nrow_local, &
1845 row_indices=row_indices)
1848 DO lll = 1, nrow_local
1849 l_global = row_indices(lll)
1850 wf_vector(l_global) = embed_pot_coef%local_data(lll, 1)
1852 CALL para_env%sum(wf_vector)
1856 qs_kind_set, cell, dft_control, particle_set, pw_env)
1859 qs_kind_set, cell, particle_set, pw_env, &
1860 dft_control%qs_control%eps_rho_rspace, &
1861 basis_type=
"RI_AUX")
1864 IF (add_const_pot)
THEN
1865 CALL pw_copy(const_pot, embed_pot)
1870 CALL pw_axpy(psi_l, embed_pot)
1874 DEALLOCATE (wf_vector)
1875 CALL auxbas_pw_pool%give_back_pw(psi_l)
1876 CALL auxbas_pw_pool%give_back_pw(rho_g)
1878 IF (open_shell_embed)
THEN
1883 CALL timestop(handle)
1885 END SUBROUTINE update_embed_pot
1896 SUBROUTINE inv_hessian_update(grad, prev_grad, step, prev_inv_Hess, inv_Hess)
1897 TYPE(
cp_fm_type),
INTENT(IN) :: grad, prev_grad, step, prev_inv_hess, &
1901 REAL(kind=
dp) :: factor1, s_dot_y, y_dot_b_inv_y
1903 TYPE(
cp_fm_type) :: b_inv_y, b_inv_y_s, s_s, s_y, s_y_b_inv, &
1908 nrow_global=mat_size)
1914 NULLIFY (fm_struct_mat, fm_struct_vec)
1917 matrix_struct=fm_struct_mat)
1919 matrix_struct=fm_struct_vec)
1922 CALL cp_fm_create(b_inv_y, fm_struct_vec, name=
"B_inv_y")
1927 CALL cp_fm_create(b_inv_y_s, fm_struct_mat, name=
"B_inv_y_s")
1928 CALL cp_fm_create(s_y_b_inv, fm_struct_mat, name=
"s_y_B_inv")
1943 CALL parallel_gemm(transa=
"N", transb=
"N", m=mat_size, n=1, &
1944 k=mat_size, alpha=1.0_dp, &
1945 matrix_a=prev_inv_hess, matrix_b=y, beta=0.0_dp, &
1948 CALL parallel_gemm(transa=
"N", transb=
"T", m=mat_size, n=mat_size, &
1949 k=1, alpha=1.0_dp, &
1950 matrix_a=step, matrix_b=step, beta=0.0_dp, &
1953 CALL parallel_gemm(transa=
"N", transb=
"T", m=mat_size, n=mat_size, &
1954 k=1, alpha=1.0_dp, &
1955 matrix_a=step, matrix_b=y, beta=0.0_dp, &
1965 factor1 = (s_dot_y + y_dot_b_inv_y)/(s_dot_y)**2
1970 CALL parallel_gemm(transa=
"N", transb=
"T", m=mat_size, n=mat_size, &
1971 k=1, alpha=1.0_dp, &
1972 matrix_a=b_inv_y, matrix_b=step, beta=0.0_dp, &
1975 CALL parallel_gemm(transa=
"N", transb=
"N", m=mat_size, n=mat_size, &
1976 k=mat_size, alpha=1.0_dp, &
1977 matrix_a=s_y, matrix_b=prev_inv_hess, beta=0.0_dp, &
1993 END SUBROUTINE inv_hessian_update
2003 SUBROUTINE hessian_update(grad, prev_grad, step, prev_Hess, Hess)
2004 TYPE(
cp_fm_type),
INTENT(IN) :: grad, prev_grad, step, prev_hess, hess
2007 REAL(kind=
dp) :: s_b_s, y_t_s
2011 TYPE(
cp_fm_type) :: b_s, b_s_s_b, s_t_b, y, y_y_t
2016 nrow_global=mat_size, para_env=para_env)
2030 NULLIFY (fm_struct_mat, fm_struct_vec, fm_struct_vec_t)
2033 matrix_struct=fm_struct_mat)
2035 matrix_struct=fm_struct_vec)
2037 nrow_global=1, ncol_global=mat_size)
2041 CALL cp_fm_create(s_t_b, fm_struct_vec_t, name=
"s_t_B")
2045 CALL cp_fm_create(b_s_s_b, fm_struct_mat, name=
"B_s_s_B")
2062 CALL parallel_gemm(transa=
"N", transb=
"T", m=mat_size, n=mat_size, &
2063 k=1, alpha=1.0_dp, &
2064 matrix_a=y, matrix_b=y, beta=0.0_dp, &
2072 CALL parallel_gemm(transa=
"N", transb=
"N", m=mat_size, n=1, &
2073 k=mat_size, alpha=1.0_dp, &
2074 matrix_a=hess, matrix_b=step, beta=0.0_dp, &
2079 CALL parallel_gemm(transa=
"T", transb=
"N", m=1, n=mat_size, &
2080 k=mat_size, alpha=1.0_dp, &
2081 matrix_a=step, matrix_b=hess, beta=0.0_dp, &
2084 CALL parallel_gemm(transa=
"N", transb=
"N", m=mat_size, n=mat_size, &
2085 k=1, alpha=1.0_dp, &
2086 matrix_a=b_s, matrix_b=s_t_b, beta=0.0_dp, &
2105 END SUBROUTINE hessian_update
2115 SUBROUTINE symm_rank_one_update(grad, prev_grad, step, prev_Hess, Hess)
2116 TYPE(
cp_fm_type),
INTENT(IN) :: grad, prev_grad, step, prev_hess, hess
2119 REAL(kind=
dp) :: factor
2130 NULLIFY (fm_struct_mat, fm_struct_vec)
2133 matrix_struct=fm_struct_mat)
2135 matrix_struct=fm_struct_vec)
2140 CALL cp_fm_create(y_b_x_y_b_x, fm_struct_mat, name=
"y_B_x_y_B_x")
2151 CALL parallel_gemm(transa=
"N", transb=
"N", m=mat_size, n=1, &
2152 k=mat_size, alpha=1.0_dp, &
2153 matrix_a=hess, matrix_b=step, beta=0.0_dp, &
2158 CALL parallel_gemm(transa=
"N", transb=
"T", m=mat_size, n=mat_size, &
2159 k=1, alpha=1.0_dp, &
2160 matrix_a=y, matrix_b=y, beta=0.0_dp, &
2161 matrix_c=y_b_x_y_b_x)
2174 END SUBROUTINE symm_rank_one_update
2184 CHARACTER(LEN=*),
PARAMETER :: routinen =
'step_control'
2187 REAL(kind=
dp) :: actual_ener_change, ener_ratio, &
2188 lin_term, pred_ener_change, quad_term
2192 CALL timeset(routinen, handle)
2196 matrix_struct=fm_struct)
2202 CALL cp_fm_trace(opt_embed%step, opt_embed%embed_pot_grad, lin_term)
2205 CALL parallel_gemm(transa=
"N", transb=
"N", m=opt_embed%dimen_aux, n=1, &
2206 k=opt_embed%dimen_aux, alpha=1.0_dp, &
2207 matrix_a=opt_embed%embed_pot_Hess, matrix_b=opt_embed%step, &
2208 beta=0.0_dp, matrix_c=h_b)
2211 pred_ener_change = lin_term + 0.5_dp*quad_term
2214 actual_ener_change = opt_embed%w_func(opt_embed%i_iter) - &
2215 opt_embed%w_func(opt_embed%last_accepted)
2217 ener_ratio = actual_ener_change/pred_ener_change
2221 IF (actual_ener_change > 0.0_dp)
THEN
2223 opt_embed%accept_step = .true.
2226 IF ((ener_ratio > 1.0_dp) .AND. (.NOT. opt_embed%newton_step) .AND. &
2227 (opt_embed%trust_rad < opt_embed%max_trad))
THEN
2228 opt_embed%trust_rad = 2.0_dp*opt_embed%trust_rad
2233 IF (abs(actual_ener_change) >= opt_embed%allowed_decrease)
THEN
2234 opt_embed%accept_step = .false.
2237 IF (opt_embed%trust_rad >= opt_embed%min_trad)
THEN
2238 opt_embed%trust_rad = 0.25_dp*opt_embed%trust_rad
2242 IF (opt_embed%accept_step) opt_embed%last_accepted = opt_embed%i_iter
2244 CALL timestop(handle)
2255 SUBROUTINE level_shift(opt_embed, diag_grad, eigenval, diag_step)
2258 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigenval
2261 CHARACTER(LEN=*),
PARAMETER :: routinen =
'level_shift'
2262 INTEGER,
PARAMETER :: max_iter = 25
2263 REAL(kind=
dp),
PARAMETER :: thresh = 0.00001_dp
2265 INTEGER :: handle, i_iter, l_global, lll, &
2266 min_index, nrow_local
2267 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: red_eigenval_map
2268 INTEGER,
DIMENSION(:),
POINTER :: row_indices
2269 LOGICAL :: converged, do_shift
2270 REAL(kind=
dp) :: diag_grad_norm, grad_min, hess_min, shift, shift_max, shift_min, step_len, &
2271 step_minus_trad, step_minus_trad_first, step_minus_trad_max, step_minus_trad_min
2274 CALL timeset(routinen, handle)
2278 nrow_local=nrow_local, &
2279 row_indices=row_indices, &
2282 min_index = minloc(abs(eigenval), dim=1)
2283 hess_min = eigenval(min_index)
2286 CALL cp_fm_trace(diag_grad, diag_grad, diag_grad_norm)
2288 IF (hess_min < 0.0_dp)
THEN
2292 shift_max = hess_min + 0.1
2293 shift_min = diag_grad_norm/opt_embed%trust_rad
2302 step_minus_trad_max = shifted_step(diag_grad, eigenval, shift_max, opt_embed%trust_rad)
2303 step_minus_trad_min = shifted_step(diag_grad, eigenval, shift_min, opt_embed%trust_rad)
2308 IF (abs(step_minus_trad_max) <= thresh)
THEN
2311 IF (abs(step_minus_trad_min) <= thresh)
THEN
2314 DO i_iter = 1, max_iter
2315 shift = 0.5_dp*(shift_max + shift_min)
2316 step_minus_trad = shifted_step(diag_grad, eigenval, shift, opt_embed%trust_rad)
2317 IF (i_iter == 1) step_minus_trad_first = step_minus_trad
2318 IF (step_minus_trad > 0.0_dp) shift_max = shift
2319 IF (step_minus_trad < 0.0_dp) shift_min = shift
2321 IF (abs(step_minus_trad) < thresh) converged = .true.
2324 IF (abs(step_minus_trad) < abs(step_minus_trad_first)) do_shift = .true.
2328 IF (converged .OR. do_shift)
THEN
2329 DO lll = 1, nrow_local
2330 l_global = row_indices(lll)
2331 IF (abs(eigenval(l_global)) >= thresh)
THEN
2332 diag_step%local_data(lll, 1) = &
2333 -diag_grad%local_data(lll, 1)/(eigenval(l_global) - shift)
2335 diag_step%local_data(lll, 1) = 0.0_dp
2339 IF (.NOT. converged)
THEN
2341 CALL cp_fm_scale(opt_embed%trust_rad/step_len, diag_step)
2347 ALLOCATE (red_eigenval_map(opt_embed%dimen_var_aux))
2348 red_eigenval_map = 0
2349 DO lll = 1, nrow_local
2350 l_global = row_indices(lll)
2351 IF (eigenval(l_global) >= 0.0_dp)
THEN
2352 red_eigenval_map(l_global) = 1
2355 CALL para_env%sum(red_eigenval_map)
2360 DO lll = 1, nrow_local
2361 l_global = row_indices(lll)
2362 IF (red_eigenval_map(l_global) == 0)
THEN
2363 IF (abs(eigenval(l_global)) >= thresh)
THEN
2364 diag_step%local_data(lll, 1) = &
2365 -diag_grad%local_data(lll, 1)/(eigenval(l_global) - shift)
2367 diag_step%local_data(lll, 1) = 0.0_dp
2370 diag_step%local_data(lll, 1) = 0.0_dp
2379 CALL timestop(handle)
2381 END SUBROUTINE level_shift
2391 FUNCTION shifted_step(diag_grad, eigenval, shift, trust_rad)
RESULT(step_minus_trad)
2393 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:), &
2394 INTENT(IN) :: eigenval
2395 REAL(kind=
dp),
INTENT(IN) :: shift, trust_rad
2396 REAL(kind=
dp) :: step_minus_trad
2398 REAL(kind=
dp),
PARAMETER :: thresh = 0.000001_dp
2400 INTEGER :: l_global, lll, nrow_local
2401 INTEGER,
DIMENSION(:),
POINTER :: row_indices
2402 REAL(kind=
dp) :: step, step_1d
2406 nrow_local=nrow_local, &
2407 row_indices=row_indices, &
2411 DO lll = 1, nrow_local
2412 l_global = row_indices(lll)
2413 IF ((abs(eigenval(l_global)) >= thresh) .AND. (abs(diag_grad%local_data(lll, 1)) >= thresh))
THEN
2414 step_1d = -diag_grad%local_data(lll, 1)/(eigenval(l_global) + shift)
2415 step = step + step_1d**2
2419 CALL para_env%sum(step)
2421 step_minus_trad = sqrt(step) - trust_rad
2423 END FUNCTION shifted_step
2434 FUNCTION barzilai_borwein(step, prev_step, grad, prev_grad)
RESULT(length)
2435 TYPE(
cp_fm_type),
INTENT(IN) :: step, prev_step, grad, prev_grad
2436 REAL(kind=
dp) :: length
2438 REAL(kind=
dp) :: denominator, numerator
2446 matrix_struct=fm_struct)
2449 CALL cp_fm_create(grad_diff, fm_struct, name=
"grad_diff")
2450 CALL cp_fm_create(step_diff, fm_struct, name=
"step_diff")
2460 CALL cp_fm_trace(grad_diff, grad_diff, denominator)
2466 length = numerator/denominator
2468 END FUNCTION barzilai_borwein
2481 SUBROUTINE leeuwen_baerends_potential_update(pw_env, embed_pot, spin_embed_pot, diff_rho_r, diff_rho_spin, &
2482 rho_r_ref, open_shell_embed, step_len)
2488 LOGICAL,
INTENT(IN) :: open_shell_embed
2489 REAL(kind=
dp),
INTENT(IN) :: step_len
2491 CHARACTER(LEN=*),
PARAMETER :: routinen =
'Leeuwen_Baerends_potential_update'
2493 INTEGER :: handle, i, i_spin, j, k, nspins
2494 INTEGER,
DIMENSION(3) :: lb, ub
2495 REAL(kind=
dp) :: my_rho, rho_cutoff
2497 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: new_embed_pot, rho_n_1, temp_embed_pot
2499 CALL timeset(routinen, handle)
2501 rho_cutoff = epsilon(0.0_dp)
2504 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
2505 NULLIFY (new_embed_pot)
2508 IF (open_shell_embed) nspins = 2
2509 NULLIFY (new_embed_pot)
2510 ALLOCATE (new_embed_pot(nspins))
2511 DO i_spin = 1, nspins
2512 CALL auxbas_pw_pool%create_pw(new_embed_pot(i_spin))
2513 CALL pw_zero(new_embed_pot(i_spin))
2516 lb(1:3) = embed_pot%pw_grid%bounds_local(1, 1:3)
2517 ub(1:3) = embed_pot%pw_grid%bounds_local(2, 1:3)
2519 IF (.NOT. open_shell_embed)
THEN
2526 IF (rho_r_ref(1)%array(i, j, k) > rho_cutoff)
THEN
2527 my_rho = rho_r_ref(1)%array(i, j, k)
2531 new_embed_pot(1)%array(i, j, k) = step_len*embed_pot%array(i, j, k)* &
2532 (diff_rho_r%array(i, j, k) + rho_r_ref(1)%array(i, j, k))/my_rho
2537 CALL pw_copy(new_embed_pot(1), embed_pot)
2542 ALLOCATE (rho_n_1(nspins))
2543 NULLIFY (temp_embed_pot)
2544 ALLOCATE (temp_embed_pot(nspins))
2545 DO i_spin = 1, nspins
2546 CALL auxbas_pw_pool%create_pw(rho_n_1(i_spin))
2548 CALL auxbas_pw_pool%create_pw(temp_embed_pot(i_spin))
2549 CALL pw_zero(temp_embed_pot(i_spin))
2551 CALL pw_copy(diff_rho_r, rho_n_1(1))
2552 CALL pw_copy(diff_rho_r, rho_n_1(2))
2553 CALL pw_axpy(diff_rho_spin, rho_n_1(1), 1.0_dp)
2554 CALL pw_axpy(diff_rho_spin, rho_n_1(2), -1.0_dp)
2555 CALL pw_scale(rho_n_1(1), a=0.5_dp)
2556 CALL pw_scale(rho_n_1(2), a=0.5_dp)
2558 CALL pw_copy(embed_pot, temp_embed_pot(1))
2559 CALL pw_copy(embed_pot, temp_embed_pot(2))
2560 CALL pw_axpy(spin_embed_pot, temp_embed_pot(1), 1.0_dp)
2561 CALL pw_axpy(spin_embed_pot, temp_embed_pot(2), -1.0_dp)
2563 IF (
SIZE(rho_r_ref) == 2)
THEN
2564 CALL pw_axpy(rho_r_ref(1), rho_n_1(1), 1.0_dp)
2565 CALL pw_axpy(rho_r_ref(2), rho_n_1(2), 1.0_dp)
2573 IF (rho_r_ref(1)%array(i, j, k) > rho_cutoff)
THEN
2574 my_rho = rho_r_ref(1)%array(i, j, k)
2578 new_embed_pot(1)%array(i, j, k) = step_len*temp_embed_pot(1)%array(i, j, k)* &
2579 (rho_n_1(1)%array(i, j, k))/my_rho
2580 IF (rho_r_ref(2)%array(i, j, k) > rho_cutoff)
THEN
2581 my_rho = rho_r_ref(2)%array(i, j, k)
2585 new_embed_pot(2)%array(i, j, k) = step_len*temp_embed_pot(2)%array(i, j, k)* &
2586 (rho_n_1(2)%array(i, j, k))/my_rho
2593 CALL pw_axpy(rho_r_ref(1), rho_n_1(1), 1.0_dp)
2602 IF (rho_r_ref(1)%array(i, j, k) > rho_cutoff)
THEN
2603 my_rho = 0.5_dp*rho_r_ref(1)%array(i, j, k)
2607 new_embed_pot(1)%array(i, j, k) = step_len*temp_embed_pot(1)%array(i, j, k)* &
2608 (rho_n_1(1)%array(i, j, k))/my_rho
2609 new_embed_pot(2)%array(i, j, k) = step_len*temp_embed_pot(2)%array(i, j, k)* &
2610 (rho_n_1(2)%array(i, j, k))/my_rho
2617 CALL pw_copy(new_embed_pot(1), embed_pot)
2618 CALL pw_axpy(new_embed_pot(2), embed_pot, 1.0_dp)
2620 CALL pw_copy(new_embed_pot(1), spin_embed_pot)
2621 CALL pw_axpy(new_embed_pot(2), spin_embed_pot, -1.0_dp)
2622 CALL pw_scale(spin_embed_pot, a=0.5_dp)
2624 DO i_spin = 1, nspins
2625 CALL rho_n_1(i_spin)%release()
2626 CALL temp_embed_pot(i_spin)%release()
2628 DEALLOCATE (rho_n_1)
2629 DEALLOCATE (temp_embed_pot)
2632 DO i_spin = 1, nspins
2633 CALL new_embed_pot(i_spin)%release()
2636 DEALLOCATE (new_embed_pot)
2638 CALL timestop(handle)
2640 END SUBROUTINE leeuwen_baerends_potential_update
2659 SUBROUTINE fab_update(qs_env, rho_r_ref, prev_embed_pot, prev_spin_embed_pot, embed_pot, spin_embed_pot, &
2660 diff_rho_r, diff_rho_spin, v_w_ref, i_iter, step_len, open_shell_embed, &
2661 vw_cutoff, vw_smooth_cutoff_range)
2670 INTEGER,
INTENT(IN) :: i_iter
2671 REAL(kind=
dp) :: step_len
2672 LOGICAL :: open_shell_embed
2673 REAL(kind=
dp) :: vw_cutoff, vw_smooth_cutoff_range
2675 CHARACTER(LEN=*),
PARAMETER :: routinen =
'FAB_update'
2677 INTEGER :: handle, i_spin, nspins
2680 TYPE(
pw_r3d_rs_type),
ALLOCATABLE,
DIMENSION(:) :: new_embed_pot, temp_embed_pot, v_w
2683 CALL timeset(routinen, handle)
2690 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
2694 IF (i_iter <= 1)
THEN
2695 nspins =
SIZE(rho_r_ref)
2697 ALLOCATE (v_w_ref(nspins))
2698 DO i_spin = 1, nspins
2699 CALL auxbas_pw_pool%create_pw(v_w_ref(i_spin))
2701 CALL von_weizsacker(rho_r_ref, v_w_ref, qs_env, vw_cutoff, vw_smooth_cutoff_range)
2703 CALL pw_copy(embed_pot, prev_embed_pot)
2704 CALL pw_axpy(diff_rho_r, embed_pot, 0.5_dp)
2705 IF (open_shell_embed)
THEN
2706 CALL pw_copy(spin_embed_pot, prev_spin_embed_pot)
2707 CALL pw_axpy(diff_rho_r, embed_pot, 0.5_dp)
2715 IF (open_shell_embed) nspins = 2
2716 ALLOCATE (new_embed_pot(nspins))
2717 ALLOCATE (v_w(nspins))
2719 ALLOCATE (curr_rho(nspins))
2720 DO i_spin = 1, nspins
2721 CALL auxbas_pw_pool%create_pw(new_embed_pot(i_spin))
2722 CALL pw_zero(new_embed_pot(i_spin))
2724 CALL auxbas_pw_pool%create_pw(v_w(i_spin))
2727 CALL auxbas_pw_pool%create_pw(curr_rho(i_spin))
2728 CALL pw_zero(curr_rho(i_spin))
2733 IF (.NOT. open_shell_embed)
THEN
2735 CALL pw_copy(diff_rho_r, curr_rho(1))
2736 CALL pw_axpy(rho_r_ref(1), curr_rho(1), 1.0_dp)
2738 CALL von_weizsacker(curr_rho, v_w, qs_env, vw_cutoff, vw_smooth_cutoff_range)
2740 CALL pw_copy(prev_embed_pot, new_embed_pot(1))
2741 CALL pw_axpy(v_w(1), new_embed_pot(1), step_len)
2742 CALL pw_axpy(v_w_ref(1), new_embed_pot(1), -step_len)
2745 CALL pw_copy(embed_pot, prev_embed_pot)
2746 CALL pw_copy(new_embed_pot(1), embed_pot)
2750 CALL pw_copy(diff_rho_r, curr_rho(1))
2751 CALL pw_copy(diff_rho_r, curr_rho(2))
2752 CALL pw_axpy(diff_rho_spin, curr_rho(1), 1.0_dp)
2753 CALL pw_axpy(diff_rho_spin, curr_rho(2), -1.0_dp)
2754 CALL pw_scale(curr_rho(1), a=0.5_dp)
2755 CALL pw_scale(curr_rho(2), a=0.5_dp)
2757 IF (
SIZE(rho_r_ref) == 1)
THEN
2758 CALL pw_axpy(rho_r_ref(1), curr_rho(1), 0.5_dp)
2759 CALL pw_axpy(rho_r_ref(1), curr_rho(2), 0.5_dp)
2761 CALL pw_axpy(rho_r_ref(1), curr_rho(1), 1.0_dp)
2762 CALL pw_axpy(rho_r_ref(2), curr_rho(2), 1.0_dp)
2766 CALL von_weizsacker(curr_rho, v_w, qs_env, vw_cutoff, vw_smooth_cutoff_range)
2769 ALLOCATE (temp_embed_pot(nspins))
2770 DO i_spin = 1, nspins
2771 CALL auxbas_pw_pool%create_pw(temp_embed_pot(i_spin))
2772 CALL pw_zero(temp_embed_pot(i_spin))
2774 CALL pw_copy(embed_pot, temp_embed_pot(1))
2775 CALL pw_copy(embed_pot, temp_embed_pot(2))
2776 CALL pw_axpy(spin_embed_pot, temp_embed_pot(1), 1.0_dp)
2777 CALL pw_axpy(spin_embed_pot, temp_embed_pot(2), -1.0_dp)
2780 IF (
SIZE(v_w_ref) == 1)
THEN
2781 CALL pw_copy(temp_embed_pot(1), new_embed_pot(1))
2782 CALL pw_axpy(v_w(1), new_embed_pot(1), 0.5_dp*step_len)
2783 CALL pw_axpy(v_w_ref(1), new_embed_pot(1), -0.5_dp*step_len)
2785 CALL pw_copy(temp_embed_pot(2), new_embed_pot(2))
2786 CALL pw_axpy(v_w(2), new_embed_pot(2), 0.5_dp)
2787 CALL pw_axpy(v_w_ref(1), new_embed_pot(2), -0.5_dp)
2791 DO i_spin = 1, nspins
2792 CALL pw_copy(temp_embed_pot(i_spin), new_embed_pot(i_spin))
2793 CALL pw_axpy(v_w(1), new_embed_pot(i_spin), step_len)
2794 CALL pw_axpy(v_w_ref(i_spin), new_embed_pot(i_spin), -step_len)
2799 CALL pw_copy(embed_pot, prev_embed_pot)
2800 CALL pw_copy(spin_embed_pot, prev_spin_embed_pot)
2802 CALL pw_copy(new_embed_pot(1), embed_pot)
2803 CALL pw_axpy(new_embed_pot(2), embed_pot, 1.0_dp)
2805 CALL pw_copy(new_embed_pot(1), spin_embed_pot)
2806 CALL pw_axpy(new_embed_pot(2), spin_embed_pot, -1.0_dp)
2807 CALL pw_scale(spin_embed_pot, a=0.5_dp)
2809 DO i_spin = 1, nspins
2810 CALL temp_embed_pot(i_spin)%release()
2812 DEALLOCATE (temp_embed_pot)
2816 DO i_spin = 1, nspins
2817 CALL curr_rho(i_spin)%release()
2818 CALL new_embed_pot(i_spin)%release()
2819 CALL v_w(i_spin)%release()
2822 DEALLOCATE (new_embed_pot)
2824 DEALLOCATE (curr_rho)
2828 CALL timestop(handle)
2830 END SUBROUTINE fab_update
2840 SUBROUTINE von_weizsacker(rho_r, v_w, qs_env, vw_cutoff, vw_smooth_cutoff_range)
2844 REAL(kind=
dp),
INTENT(IN) :: vw_cutoff, vw_smooth_cutoff_range
2846 REAL(kind=
dp),
PARAMETER :: one_4 = 0.25_dp, one_8 = 0.125_dp
2848 INTEGER :: i, i_spin, j, k, nspins
2849 INTEGER,
DIMENSION(3) :: lb, ub
2850 REAL(kind=
dp) :: density_smooth_cut_range, my_rho, &
2852 REAL(kind=
dp),
DIMENSION(:, :, :),
POINTER :: rhoa, rhob
2861 rho_cutoff = epsilon(0.0_dp)
2863 nspins =
SIZE(rho_r)
2865 NULLIFY (xc_section)
2872 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
2876 ALLOCATE (rho_g(nspins))
2877 DO i_spin = 1, nspins
2878 CALL auxbas_pw_pool%create_pw(rho_g(i_spin))
2885 rho_r(1)%pw_grid%bounds_local, &
2892 IF (nspins == 2)
THEN
2893 needs%rho_spin = .true.
2894 needs%norm_drho_spin = .true.
2895 needs%laplace_rho_spin = .true.
2898 needs%norm_drho = .true.
2899 needs%laplace_rho = .true.
2910 r_val=density_smooth_cut_range)
2912 lb(1:3) = rho_r(1)%pw_grid%bounds_local(1, 1:3)
2913 ub(1:3) = rho_r(1)%pw_grid%bounds_local(2, 1:3)
2915 IF (nspins == 2)
THEN
2922 IF (rho_r(1)%array(i, j, k) > rho_cutoff)
THEN
2923 my_rho = rho_r(1)%array(i, j, k)
2927 v_w(1)%array(i, j, k) = one_8*rho_set%norm_drhoa(i, j, k)**2/my_rho**2 - &
2928 one_4*rho_set%laplace_rhoa(i, j, k)/my_rho
2930 IF (rho_r(2)%array(i, j, k) > rho_cutoff)
THEN
2931 my_rho = rho_r(2)%array(i, j, k)
2935 v_w(2)%array(i, j, k) = one_8*rho_set%norm_drhob(i, j, k)**2/my_rho**2 - &
2936 one_4*rho_set%laplace_rhob(i, j, k)/my_rho
2948 IF (rho_r(1)%array(i, j, k) > rho_cutoff)
THEN
2949 my_rho = rho_r(1)%array(i, j, k)
2950 v_w(1)%array(i, j, k) = one_8*rho_set%norm_drho(i, j, k)**2/my_rho**2 - &
2951 one_4*rho_set%laplace_rho(i, j, k)/my_rho
2953 v_w(1)%array(i, j, k) = 0.0_dp
2963 IF (nspins == 2)
THEN
2964 density_smooth_cut_range = 0.5_dp*density_smooth_cut_range
2965 rho_cutoff = 0.5_dp*rho_cutoff
2967 DO i_spin = 1, nspins
2968 CALL smooth_cutoff(pot=v_w(i_spin)%array, rho=rho_r(i_spin)%array, rhoa=rhoa, rhob=rhob, &
2969 rho_cutoff=vw_cutoff, &
2970 rho_smooth_cutoff_range=vw_smooth_cutoff_range)
2975 DO i_spin = 1, nspins
2976 CALL rho_g(i_spin)%release()
2980 END SUBROUTINE von_weizsacker
2989 REAL(kind=
dp) :: total_max_diff
2991 INTEGER :: size_x, size_y, size_z
2992 REAL(kind=
dp) :: max_diff
2993 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: grid_3d
2998 size_x =
SIZE(diff_rho_r%array, 1)
2999 size_y =
SIZE(diff_rho_r%array, 2)
3000 size_z =
SIZE(diff_rho_r%array, 3)
3003 ALLOCATE (grid_3d(size_x, size_y, size_z))
3006 grid_3d(:, :, :) = diff_rho_r%array(:, :, :)
3009 max_diff = maxval(abs(grid_3d))
3010 total_max_diff = max_diff
3011 CALL diff_rho_r%pw_grid%para%group%max(total_max_diff)
3014 DEALLOCATE (grid_3d)
3028 INTEGER,
INTENT(IN) :: i_iter
3030 LOGICAL,
INTENT(IN) :: final_one
3032 CHARACTER(LEN=default_path_length) :: filename, my_pos_cube, title
3039 NULLIFY (subsys, input)
3049 "DFT%QS%OPT_EMBED%EMBED_DENS_DIFF"),
cp_p_file))
THEN
3050 my_pos_cube =
"REWIND"
3051 IF (.NOT. final_one)
THEN
3052 WRITE (filename,
'(a5,I3.3,a1,I1.1)')
"DIFF_", i_iter
3054 WRITE (filename,
'(a5,I3.3,a1,I1.1)')
"DIFF"
3057 extension=
".cube", middle_name=trim(filename), file_position=my_pos_cube, &
3058 log_filename=.false.)
3060 WRITE (title, *)
"EMBEDDING DENSITY DIFFERENCE ",
" optimization step ", i_iter
3061 CALL cp_pw_to_cube(diff_rho_r, unit_nr, title, particles=particles, &
3064 "DFT%QS%OPT_EMBED%EMBED_DENS_DIFF")
3079 INTEGER,
INTENT(IN) :: i_iter
3081 LOGICAL,
INTENT(IN) :: final_one
3083 CHARACTER(LEN=default_path_length) :: filename, my_pos_cube, title
3090 NULLIFY (subsys, input)
3100 "DFT%QS%OPT_EMBED%EMBED_DENS_DIFF"),
cp_p_file))
THEN
3101 my_pos_cube =
"REWIND"
3102 IF (.NOT. final_one)
THEN
3103 WRITE (filename,
'(a5,I3.3,a1,I1.1)')
"SPIN_DIFF_", i_iter
3105 WRITE (filename,
'(a9,I3.3,a1,I1.1)')
"SPIN_DIFF"
3108 extension=
".cube", middle_name=trim(filename), file_position=my_pos_cube, &
3109 log_filename=.false.)
3111 WRITE (title, *)
"EMBEDDING SPIN DENSITY DIFFERENCE ",
" optimization step ", i_iter
3112 CALL cp_pw_to_cube(spin_diff_rho_r, unit_nr, title, particles=particles, &
3115 "DFT%QS%OPT_EMBED%EMBED_DENS_DIFF")
3132 embed_pot_spin, open_shell_embed, grid_opt, final_one)
3134 INTEGER :: dimen_aux
3135 TYPE(
cp_fm_type),
INTENT(IN),
POINTER :: embed_pot_coef
3139 LOGICAL :: open_shell_embed, grid_opt, final_one
3141 CHARACTER(LEN=default_path_length) :: filename, my_pos_cube, title
3149 CALL get_qs_env(qs_env=qs_env, subsys=subsys, &
3153 IF (.NOT. grid_opt)
THEN
3156 "DFT%QS%OPT_EMBED%EMBED_POT_VECTOR"),
cp_p_file))
THEN
3157 IF (.NOT. final_one)
THEN
3158 WRITE (filename,
'(a10,I3.3)')
"embed_pot_", i_iter
3160 WRITE (filename,
'(a10,I3.3)')
"embed_pot"
3162 unit_nr =
cp_print_key_unit_nr(logger, input,
"DFT%QS%OPT_EMBED%EMBED_POT_VECTOR", extension=
".wfn", &
3163 file_form=
"UNFORMATTED", middle_name=trim(filename), file_position=
"REWIND")
3164 IF (unit_nr > 0)
THEN
3165 WRITE (unit_nr) dimen_aux
3168 IF (unit_nr > 0)
THEN
3180 "DFT%QS%OPT_EMBED%EMBED_POT_CUBE"),
cp_p_file))
THEN
3181 my_pos_cube =
"REWIND"
3182 IF (.NOT. final_one)
THEN
3183 WRITE (filename,
'(a10,I3.3)')
"embed_pot_", i_iter
3185 WRITE (filename,
'(a10,I3.3)')
"embed_pot"
3188 extension=
".cube", middle_name=trim(filename), file_position=my_pos_cube, &
3189 log_filename=.false.)
3191 WRITE (title, *)
"EMBEDDING POTENTIAL at optimization step ", i_iter
3192 CALL cp_pw_to_cube(embed_pot, unit_nr, title, particles=particles)
3196 "DFT%QS%OPT_EMBED%EMBED_POT_CUBE")
3197 IF (open_shell_embed)
THEN
3198 my_pos_cube =
"REWIND"
3199 IF (.NOT. final_one)
THEN
3200 WRITE (filename,
'(a15,I3.3)')
"spin_embed_pot_", i_iter
3202 WRITE (filename,
'(a15,I3.3)')
"spin_embed_pot"
3205 extension=
".cube", middle_name=trim(filename), file_position=my_pos_cube, &
3206 log_filename=.false.)
3208 WRITE (title, *)
"SPIN EMBEDDING POTENTIAL at optimization step ", i_iter
3209 CALL cp_pw_to_cube(embed_pot_spin, unit_nr, title, particles=particles)
3213 "DFT%QS%OPT_EMBED%EMBED_POT_CUBE")
3230 final_one, qs_env_cluster)
3235 LOGICAL :: open_shell_embed, final_one
3238 CHARACTER(LEN=default_path_length) :: filename
3239 INTEGER :: my_units, unit_nr
3240 LOGICAL :: angstrom, bohr
3248 CALL get_qs_env(qs_env=qs_env, input=input, pw_env=pw_env)
3256 "DFT%QS%OPT_EMBED%WRITE_SIMPLE_GRID"),
cp_p_file))
THEN
3262 SELECT CASE (my_units)
3276 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
3279 CALL auxbas_pw_pool%create_pw(pot_alpha)
3282 CALL pw_copy(embed_pot, pot_alpha)
3284 IF (open_shell_embed)
THEN
3285 CALL auxbas_pw_pool%create_pw(pot_beta)
3286 CALL pw_copy(embed_pot, pot_beta)
3288 CALL pw_axpy(embed_pot_spin, pot_alpha, 1.0_dp)
3289 CALL pw_axpy(embed_pot_spin, pot_beta, -1.0_dp)
3292 IF (.NOT. final_one)
THEN
3293 WRITE (filename,
'(a10,I3.3)')
"embed_pot_", i_iter
3295 WRITE (filename,
'(a10,I3.3)')
"embed_pot"
3297 unit_nr =
cp_print_key_unit_nr(logger, input,
"DFT%QS%OPT_EMBED%WRITE_SIMPLE_GRID", extension=
".dat", &
3298 middle_name=trim(filename), file_form=
"FORMATTED", file_position=
"REWIND")
3300 IF (open_shell_embed)
THEN
3302 stride=
section_get_ivals(dft_section,
"QS%OPT_EMBED%WRITE_SIMPLE_GRID%STRIDE"), &
3310 "DFT%QS%OPT_EMBED%WRITE_SIMPLE_GRID")
3312 CALL pot_alpha%release()
3313 IF (open_shell_embed)
THEN
3314 CALL pot_beta%release()
3321 CALL print_folded_coordinates(qs_env_cluster, input)
3330 SUBROUTINE print_folded_coordinates(qs_env, input)
3334 CHARACTER(LEN=2),
ALLOCATABLE,
DIMENSION(:) :: particles_el
3335 CHARACTER(LEN=default_path_length) :: filename
3336 INTEGER :: iat, n, unit_nr
3337 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: particles_r
3338 REAL(kind=
dp),
DIMENSION(3) :: center, r_pbc, s
3347 "DFT%QS%OPT_EMBED%WRITE_SIMPLE_GRID/FOLD_COORD"),
cp_p_file))
THEN
3348 CALL get_qs_env(qs_env=qs_env, cell=cell, subsys=subsys)
3352 WRITE (filename,
'(a14)')
"folded_cluster"
3354 "DFT%QS%OPT_EMBED%WRITE_SIMPLE_GRID/FOLD_COORD", extension=
".dat", &
3355 middle_name=trim(filename), file_form=
"FORMATTED", file_position=
"REWIND")
3356 IF (unit_nr > 0)
THEN
3359 ALLOCATE (particles_el(n))
3360 ALLOCATE (particles_r(3, n))
3362 CALL get_atomic_kind(particles%els(iat)%atomic_kind, element_symbol=particles_el(iat))
3363 particles_r(:, iat) = particles%els(iat)%r(:)
3367 center(:) = cell%hmat(:, 1)/2.0_dp + cell%hmat(:, 2)/2.0_dp + cell%hmat(:, 3)/2.0_dp
3370 DO iat = 1,
SIZE(particles_el)
3371 r_pbc(:) = particles_r(:, iat) - center
3372 s = matmul(cell%h_inv, r_pbc)
3374 r_pbc = matmul(cell%hmat, s)
3375 r_pbc = r_pbc + center
3376 WRITE (unit_nr,
'(a4,4f12.6)') particles_el(iat), r_pbc(:)
3380 "DFT%QS%OPT_EMBED%WRITE_SIMPLE_GRID/FOLD_COORD")
3382 DEALLOCATE (particles_el)
3383 DEALLOCATE (particles_r)
3388 END SUBROUTINE print_folded_coordinates
3397 INTEGER :: output_unit, step_num
3400 IF (output_unit > 0)
THEN
3401 WRITE (unit=output_unit, fmt=
"(/,T2,8('-'),A,I5,1X,12('-'))") &
3402 " Optimize embedding potential info at step = ", step_num
3403 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3404 " Functional value = ", opt_embed%w_func(step_num)
3405 IF (step_num > 1)
THEN
3406 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3407 " Real energy change = ", opt_embed%w_func(step_num) - &
3408 opt_embed%w_func(step_num - 1)
3410 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3411 " Step size = ", opt_embed%step_len
3415 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3416 " Trust radius = ", opt_embed%trust_rad
3418 WRITE (unit=output_unit, fmt=
"(T2,51('-'))")
3432 INTEGER :: subsys_num
3434 INTEGER :: i_dens_start, i_spin, nspins
3438 NULLIFY (rho_r, rho)
3442 nspins = opt_embed%all_nspins(subsys_num)
3444 i_dens_start = sum(opt_embed%all_nspins(1:subsys_num)) - nspins + 1
3446 DO i_spin = 1, nspins
3447 opt_embed%prev_subsys_dens(i_dens_start + i_spin - 1)%array(:, :, :) = &
3448 rho_r(i_spin)%array(:, :, :)
3462 INTEGER :: subsys_num
3464 INTEGER :: i_dens_start, i_spin, nspins
3468 NULLIFY (rho_r, rho)
3472 nspins = opt_embed%all_nspins(subsys_num)
3474 i_dens_start = sum(opt_embed%all_nspins(1:subsys_num)) - nspins + 1
3476 DO i_spin = 1, nspins
3477 CALL pw_axpy(rho_r(i_spin), opt_embed%prev_subsys_dens(i_dens_start + i_spin - 1), 1.0_dp, -1.0_dp, &
3478 allow_noncompatible_grids=.true.)
3479 opt_embed%max_subsys_dens_diff(i_dens_start + i_spin - 1) = &
3480 max_dens_diff(opt_embed%prev_subsys_dens(i_dens_start + i_spin - 1))
3495 INTEGER :: output_unit
3497 INTEGER :: i_dens, i_dens_start, i_spin
3498 LOGICAL :: conv_int_diff, conv_max_diff
3499 REAL(kind=
dp) :: int_diff, int_diff_spin, &
3500 int_diff_square, int_diff_square_spin, &
3501 max_diff, max_diff_spin
3506 opt_embed%int_diff_square(1) =
pw_integral_ab(diff_rho_r, diff_rho_r)
3507 IF (opt_embed%open_shell_embed)
THEN
3510 opt_embed%int_diff_square(2) =
pw_integral_ab(diff_rho_spin, diff_rho_spin)
3514 max_diff = opt_embed%max_diff(1)
3518 IF (opt_embed%open_shell_embed)
THEN
3519 max_diff_spin = opt_embed%max_diff(2)
3520 IF ((max_diff <= opt_embed%conv_max) .AND. (max_diff_spin <= opt_embed%conv_max_spin))
THEN
3521 conv_max_diff = .true.
3523 conv_max_diff = .false.
3527 IF (max_diff <= opt_embed%conv_max)
THEN
3528 conv_max_diff = .true.
3530 conv_max_diff = .false.
3535 int_diff = opt_embed%int_diff(1)
3537 IF (opt_embed%open_shell_embed)
THEN
3538 int_diff_spin = opt_embed%int_diff(2)
3539 IF ((int_diff <= opt_embed%conv_int) .AND. (int_diff_spin <= opt_embed%conv_int_spin))
THEN
3540 conv_int_diff = .true.
3542 conv_int_diff = .false.
3546 IF (int_diff <= opt_embed%conv_int)
THEN
3547 conv_int_diff = .true.
3549 conv_int_diff = .false.
3554 int_diff_square = opt_embed%int_diff_square(1)
3556 IF (opt_embed%open_shell_embed) int_diff_square_spin = opt_embed%int_diff_square(2)
3558 IF ((conv_max_diff) .AND. (conv_int_diff))
THEN
3559 opt_embed%converged = .true.
3561 opt_embed%converged = .false.
3565 IF (output_unit > 0)
THEN
3566 WRITE (unit=output_unit, fmt=
"(/,T2,A)") &
3567 " Convergence check :"
3570 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3571 " Maximum density difference = ", max_diff
3572 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3573 " Convergence limit for max. density diff. = ", opt_embed%conv_max
3575 IF (opt_embed%open_shell_embed)
THEN
3577 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3578 " Maximum spin density difference = ", max_diff_spin
3579 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3580 " Convergence limit for max. spin dens.diff.= ", opt_embed%conv_max_spin
3584 IF (conv_max_diff)
THEN
3585 WRITE (unit=output_unit, fmt=
"(T2,2A)") &
3586 " Convergence in max. density diff. = ", &
3589 WRITE (unit=output_unit, fmt=
"(T2,2A)") &
3590 " Convergence in max. density diff. = ", &
3595 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3596 " Integrated density difference = ", int_diff
3597 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3598 " Conv. limit for integrated density diff. = ", opt_embed%conv_int
3599 IF (opt_embed%open_shell_embed)
THEN
3600 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3601 " Integrated spin density difference = ", int_diff_spin
3602 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3603 " Conv. limit for integrated spin dens.diff.= ", opt_embed%conv_int_spin
3606 IF (conv_int_diff)
THEN
3607 WRITE (unit=output_unit, fmt=
"(T2,2A)") &
3608 " Convergence in integrated density diff. = ", &
3611 WRITE (unit=output_unit, fmt=
"(T2,2A)") &
3612 " Convergence in integrated density diff. = ", &
3617 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3618 " Integrated squared density difference = ", int_diff_square
3619 IF (opt_embed%open_shell_embed)
THEN
3620 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3621 " Integrated squared spin density difference= ", int_diff_square_spin
3625 WRITE (unit=output_unit, fmt=
"(/,T2,A)") &
3626 " Maximum density change in:"
3627 DO i_dens = 1, (
SIZE(opt_embed%all_nspins) - 1)
3628 i_dens_start = sum(opt_embed%all_nspins(1:i_dens)) - opt_embed%all_nspins(i_dens) + 1
3629 DO i_spin = 1, opt_embed%all_nspins(i_dens)
3630 WRITE (unit=output_unit, fmt=
"(T4,A10,I3,A6,I3,A1,F20.10)") &
3631 " subsystem ", i_dens,
', spin', i_spin,
":", &
3632 opt_embed%max_subsys_dens_diff(i_dens_start + i_spin - 1)
3638 IF ((opt_embed%converged) .AND. (output_unit > 0))
THEN
3639 WRITE (unit=output_unit, fmt=
"(/,T2,A)") repeat(
"*", 79)
3640 WRITE (unit=output_unit, fmt=
"(T2,A,T25,A,T78,A)") &
3641 "***",
"EMBEDDING POTENTIAL OPTIMIZATION COMPLETED",
"***"
3642 WRITE (unit=output_unit, fmt=
"(T2,A)") repeat(
"*", 79)
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind_set(atomic_kind_set, atom_of_kind, kind_of, natom_of_kind, maxatom, natom, nshell, fist_potential_present, shell_present, shell_adiabatic, shell_check_distance, damping_present)
Get attributes of an atomic kind set.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
Handles all functions related to the CELL.
methods related to the blacs parallel environment
subroutine, public cp_blacs_env_release(blacs_env)
releases the given blacs_env
subroutine, public cp_blacs_env_create(blacs_env, para_env, blacs_grid_layout, blacs_repeatable, row_major, grid_2d)
allocates and initializes a type that represent a blacs context
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS 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)
subroutine, public cp_fm_scale_and_add(alpha, matrix_a, beta, matrix_b)
calc A <- alpha*A + beta*B optimized for alpha == 1.0 (just add beta*B) and beta == 0....
subroutine, public cp_fm_scale(alpha, matrix_a)
scales a matrix matrix_a = alpha * matrix_b
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_copy_general(source, destination, para_env)
General copy of a fm matrix to another fm matrix. Uses non-blocking MPI rather than ScaLAPACK.
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_get_element(matrix, irow_global, icol_global, alpha, local)
returns an element of a fm this value is valid on every cpu using this call is expensive
subroutine, public cp_fm_to_fm_submat(msource, mtarget, nrow, ncol, s_firstrow, s_firstcol, t_firstrow, t_firstcol)
copy just a part ot the matrix
subroutine, public cp_fm_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
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...
A wrapper around pw_to_cube() which accepts particle_list_type.
subroutine, public cp_cube_to_pw(grid, filename, scaling, silent)
Thin wrapper around routine cube_to_pw.
subroutine, public cp_pw_to_simple_volumetric(pw, unit_nr, stride, pw2)
Prints grid in a simple format: X Y Z value.
subroutine, public cp_pw_to_cube(pw, unit_nr, title, particles, zeff, stride, max_file_size_mb, zero_tails, silent, mpi_io)
...
Interface for the force calculations.
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_path_length
contains the types and subroutines for dealing with the lri_env lri : local resolution of the identit...
Definition of mathematical constants and functions.
real(kind=dp), parameter, public pi
Interface to the message passing library MPI.
subroutine, public get_subsys_map_index(mapping_section, natom, iforce_eval, nforce_eval, map_index, force_eval_embed)
performs mapping of the subsystems of different force_eval
subroutine, public print_embed_restart(qs_env, dimen_aux, embed_pot_coef, embed_pot, i_iter, embed_pot_spin, open_shell_embed, grid_opt, final_one)
Print embedding potential as a cube and as a binary (for restarting)
subroutine, public make_subsys_embed_pot(qs_env, embed_pot, embed_pot_subsys, spin_embed_pot, spin_embed_pot_subsys, open_shell_embed, change_spin_sign)
Creates a subsystem embedding potential.
subroutine, public print_rho_spin_diff(spin_diff_rho_r, i_iter, qs_env, final_one)
Prints a cube for the (spin_rho_A + spin_rho_B - spin_rho_ref) to be minimized in embedding.
subroutine, public get_max_subsys_diff(opt_embed, force_env, subsys_num)
...
subroutine, public print_emb_opt_info(output_unit, step_num, opt_embed)
...
subroutine, public init_embed_pot(qs_env, embed_pot, add_const_pot, fermi_amaldi, const_pot, open_shell_embed, spin_embed_pot, pot_diff, coulomb_guess, grid_opt)
...
subroutine, public understand_spin_states(force_env, ref_subsys_number, change_spin, open_shell_embed, all_nspins)
Find out whether we need to swap alpha- and beta- spind densities in the second subsystem.
subroutine, public read_embed_pot(qs_env, embed_pot, spin_embed_pot, section, opt_embed)
...
subroutine, public given_embed_pot(qs_env)
Read the external embedding potential, not to be optimized.
subroutine, public find_aux_dimen(qs_env, dimen_aux)
Find the dimension of the auxiliary basis for the expansion of the embedding potential.
subroutine, public get_prev_density(opt_embed, force_env, subsys_num)
...
subroutine, public coulomb_guess(v_rspace, rhs, mapping_section, qs_env, nforce_eval, iforce_eval, eta)
Calculates subsystem Coulomb potential from the RESP charges of the total system.
subroutine, public print_rho_diff(diff_rho_r, i_iter, qs_env, final_one)
Prints a cube for the (rho_A + rho_B - rho_ref) to be minimized in embedding.
subroutine, public conv_check_embed(opt_embed, diff_rho_r, diff_rho_spin, output_unit)
...
real(kind=dp) function, public max_dens_diff(diff_rho_r)
...
subroutine, public step_control(opt_embed)
Controls the step, changes the trust radius if needed in maximization of the V_emb.
subroutine, public opt_embed_step(diff_rho_r, diff_rho_spin, opt_embed, embed_pot, spin_embed_pot, rho_r_ref, qs_env)
Takes maximization step in embedding potential optimization.
subroutine, public calculate_embed_pot_grad(qs_env, diff_rho_r, diff_rho_spin, opt_embed)
Calculates the derivative of the embedding potential wrt to the expansion coefficients.
subroutine, public print_pot_simple_grid(qs_env, embed_pot, embed_pot_spin, i_iter, open_shell_embed, final_one, qs_env_cluster)
Prints a volumetric file: X Y Z value for interfacing with external programs.
subroutine, public prepare_embed_opt(qs_env, opt_embed, opt_embed_section)
Creates and allocates objects for optimization of embedding potential.
subroutine, public release_opt_embed(opt_embed)
Deallocate stuff for optimizing embedding potential.
basic linear algebra operations for full matrixes
represent a simple array based list of the given type
Define the data structure for the particle information.
container for various plainwaves related things
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
subroutine, public pw_derive(pw, n)
Calculate the derivative of a plane wave vector.
subroutine, public pw_dr2(pw, pwdr2, i, j)
Calculate the tensorial 2nd derivative of a plane wave vector.
functions related to the poisson solver on regular grids
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Calculate the plane wave density by collocating the primitive Gaussian functions (pgf).
subroutine, public collocate_function(vector, rho, rho_gspace, atomic_kind_set, qs_kind_set, cell, particle_set, pw_env, eps_rho_rspace, basis_type)
maps a given function on the grid
subroutine, public calculate_wavefunction(mo_vectors, ivector, rho, rho_gspace, atomic_kind_set, qs_kind_set, cell, dft_control, particle_set, pw_env, basis_type)
maps a given wavefunction on the grid
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.
subroutine, public set_qs_env(qs_env, super_cell, mos, qmmm, qmmm_periodic, mimic, ewald_env, ewald_pw, mpools, rho_external, external_vxc, mask, scf_control, rel_control, qs_charges, ks_env, ks_qmmm_env, wf_history, scf_env, active_space, input, oce, rho_atom_set, rho0_atom_set, rho0_mpole, run_rtp, rtp, rhoz_set, rhoz_tot, ecoul_1c, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, efield, rhoz_cneo_set, linres_control, xas_env, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, ls_scf_env, do_transport, transport_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, harris_env, gcp_env, mp2_env, bs_env, kg_env, force, kpoints, wanniercentres, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Set the QUICKSTEP environment.
Build up the plane wave density by collocating the primitive Gaussian functions (pgf).
subroutine, public integrate_v_rspace_one_center(v_rspace, qs_env, int_res, calculate_forces, basis_type, atomlist)
computes integrals of product of v_rspace times a one-center function required for LRIGPW
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, cneo_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, init_u_ramping_each_scf, reltmat, ghost, monovalent, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
Calculation of kinetic energy matrix and forces.
subroutine, public build_kinetic_matrix(ks_env, matrix_t, matrixkp_t, matrix_name, basis_type, sab_nl, calculate_forces, matrix_p, matrixkp_p, ext_kpoints, eps_filter, nderivative)
Calculation of the kinetic energy matrix over Cartesian Gaussian functions.
Definition and initialisation of the mo data type.
subroutine, public get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, uniform_occupation, kts, mu, flexible_electron_count)
Get the components of a MO set data structure.
Define the neighbor list data types and the corresponding functionality.
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...
types that represent a quickstep subsys
subroutine, public qs_subsys_get(subsys, atomic_kinds, atomic_kind_set, particles, particle_set, local_particles, molecules, molecule_set, molecule_kinds, molecule_kind_set, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, natom, nparticle, ncore, nshell, nkind, atprop, virial, results, cell, cell_ref, use_ref_cell, energy, force, qs_kind_set, cp_subsys, nelectron_total, nelectron_spin)
...
elemental subroutine, public xc_rho_cflags_setall(cflags, value)
sets all the flags to the given value
subroutine, public xc_rho_set_create(rho_set, local_bounds, rho_cutoff, drho_cutoff, tau_cutoff)
allocates and does (minimal) initialization of a rho_set
subroutine, public xc_rho_set_release(rho_set, pw_pool)
releases the given rho_set
subroutine, public xc_rho_set_update(rho_set, rho_r, rho_g, tau, needs, xc_deriv_method_id, xc_rho_smooth_id, pw_pool, spinflip)
updates the given rho set with the density given by rho_r (and rho_g). The rho set will contain the c...
Exchange and Correlation functional calculations.
subroutine, public smooth_cutoff(pot, rho, rhoa, rhob, rho_cutoff, rho_smooth_cutoff_range, e_0, e_0_scale_factor)
smooths the cutoff on rho with a function smoothderiv_rho that is 0 for rho<rho_cutoff and 1 for rho>...
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
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...
Type containing main data for embedding potential optimization.
wrapper to abstract the force evaluation of the various methods
stores all the informations relevant to an mpi environment
represent a list of objects
contained for different pw related things
environment for the poisson solver
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Provides all information about a quickstep kind.
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...
keeps the density in various representations, keeping track of which ones are valid.
contains a flag for each component of xc_rho_set, so that you can use it to tell which components you...
represent a density, with all the representation and data needed to perform a functional evaluation