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 .EQ. 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) .EQ. 1) .AND. (all_nspins(2) .EQ. 1) .AND. (all_nspins(3) .EQ. 1))) &
155 open_shell_embed = .true.
158 IF (open_shell_embed)
THEN
160 IF (all_nspins(3) .EQ. 1)
THEN
163 total_spin = all_spins(1, 3) - all_spins(2, 3)
165 IF (all_nspins(1) .EQ. 1)
THEN
168 sub_spin_1 = all_spins(1, 1) - all_spins(2, 1)
170 IF (all_nspins(2) .EQ. 1)
THEN
173 sub_spin_2 = all_spins(1, 2) - all_spins(2, 2)
175 IF ((sub_spin_1 + sub_spin_2) .EQ. total_spin)
THEN
176 change_spin = .false.
178 IF (abs(sub_spin_1 - sub_spin_2) .EQ. total_spin)
THEN
181 cpabort(
"Spin states of subsystems are not compatible.")
187 cpabort(
"Reference subsystem must be the third FORCE_EVAL.")
205 SUBROUTINE init_embed_pot(qs_env, embed_pot, add_const_pot, Fermi_Amaldi, const_pot, open_shell_embed, &
206 spin_embed_pot, pot_diff, Coulomb_guess, grid_opt)
209 LOGICAL :: add_const_pot, fermi_amaldi
211 LOGICAL :: open_shell_embed
215 INTEGER :: nelectrons
216 INTEGER,
DIMENSION(2) :: nelectron_spin
217 REAL(kind=
dp) :: factor
223 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env, &
224 nelectron_spin=nelectron_spin, &
225 v_hartree_rspace=v_hartree_r_space)
228 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
233 CALL auxbas_pw_pool%create_pw(embed_pot)
237 IF (open_shell_embed)
THEN
238 NULLIFY (spin_embed_pot)
239 ALLOCATE (spin_embed_pot)
240 CALL auxbas_pw_pool%create_pw(spin_embed_pot)
248 CALL auxbas_pw_pool%create_pw(pot_diff)
253 IF (add_const_pot .AND. (.NOT. grid_opt))
THEN
257 CALL auxbas_pw_pool%create_pw(const_pot)
262 IF (fermi_amaldi)
THEN
265 NULLIFY (v_hartree_r_space)
266 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env, &
267 v_hartree_rspace=v_hartree_r_space)
268 CALL pw_copy(v_hartree_r_space, embed_pot)
271 nelectrons = nelectron_spin(1) + nelectron_spin(2)
272 factor = (real(nelectrons,
dp) - 1.0_dp)/(real(nelectrons,
dp))
278 IF (.NOT. grid_opt)
CALL pw_copy(embed_pot, embed_pot)
296 INTEGER :: diff_size, i_dens, size_prev_dens
308 CALL read_opt_embed_section(opt_embed, opt_embed_section)
311 IF (.NOT. opt_embed%grid_opt)
THEN
322 CALL make_lri_object(qs_env, opt_embed%lri)
326 IF (opt_embed%open_shell_embed)
THEN
327 opt_embed%dimen_var_aux = 2*opt_embed%dimen_aux
329 opt_embed%dimen_var_aux = opt_embed%dimen_aux
333 NULLIFY (opt_embed%embed_pot_grad, opt_embed%embed_pot_coef, opt_embed%step, fm_struct)
335 NULLIFY (opt_embed%prev_embed_pot_grad, opt_embed%prev_embed_pot_coef, opt_embed%prev_step)
337 nrow_global=opt_embed%dimen_var_aux, ncol_global=1)
338 ALLOCATE (opt_embed%embed_pot_grad, opt_embed%embed_pot_coef, &
339 opt_embed%prev_embed_pot_grad, opt_embed%prev_embed_pot_coef, &
340 opt_embed%step, opt_embed%prev_step)
341 CALL cp_fm_create(opt_embed%embed_pot_grad, fm_struct, name=
"pot_grad")
342 CALL cp_fm_create(opt_embed%embed_pot_coef, fm_struct, name=
"pot_coef")
343 CALL cp_fm_create(opt_embed%prev_embed_pot_grad, fm_struct, name=
"prev_pot_grad")
344 CALL cp_fm_create(opt_embed%prev_embed_pot_coef, fm_struct, name=
"prev_pot_coef")
345 CALL cp_fm_create(opt_embed%step, fm_struct, name=
"step")
346 CALL cp_fm_create(opt_embed%prev_step, fm_struct, name=
"prev_step")
358 NULLIFY (opt_embed%embed_pot_hess, opt_embed%prev_embed_pot_hess, fm_struct)
360 nrow_global=opt_embed%dimen_var_aux, ncol_global=opt_embed%dimen_var_aux)
361 ALLOCATE (opt_embed%embed_pot_hess, opt_embed%prev_embed_pot_hess)
362 CALL cp_fm_create(opt_embed%embed_pot_hess, fm_struct, name=
"pot_Hess")
363 CALL cp_fm_create(opt_embed%prev_embed_pot_hess, fm_struct, name=
"prev_pot_Hess")
367 NULLIFY (fm_struct, opt_embed%kinetic_mat)
369 nrow_global=opt_embed%dimen_aux, ncol_global=opt_embed%dimen_aux)
370 ALLOCATE (opt_embed%kinetic_mat)
371 CALL cp_fm_create(opt_embed%kinetic_mat, fm_struct, name=
"kinetic_mat")
376 CALL cp_fm_set_all(opt_embed%embed_pot_hess, 0.0_dp, -1.0_dp)
377 CALL cp_fm_set_all(opt_embed%prev_embed_pot_hess, 0.0_dp, -1.0_dp)
385 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
386 NULLIFY (opt_embed%prev_subsys_dens)
387 size_prev_dens = sum(opt_embed%all_nspins(1:(
SIZE(opt_embed%all_nspins) - 1)))
388 ALLOCATE (opt_embed%prev_subsys_dens(size_prev_dens))
389 DO i_dens = 1, size_prev_dens
390 CALL auxbas_pw_pool%create_pw(opt_embed%prev_subsys_dens(i_dens))
391 CALL pw_zero(opt_embed%prev_subsys_dens(i_dens))
393 ALLOCATE (opt_embed%max_subsys_dens_diff(size_prev_dens))
396 ALLOCATE (opt_embed%w_func(opt_embed%n_iter))
397 opt_embed%w_func = 0.0_dp
401 IF (opt_embed%open_shell_embed) diff_size = 2
402 ALLOCATE (opt_embed%max_diff(diff_size))
403 ALLOCATE (opt_embed%int_diff(diff_size))
404 ALLOCATE (opt_embed%int_diff_square(diff_size))
407 IF (opt_embed%fab)
THEN
408 NULLIFY (opt_embed%prev_embed_pot)
409 ALLOCATE (opt_embed%prev_embed_pot)
410 CALL auxbas_pw_pool%create_pw(opt_embed%prev_embed_pot)
411 CALL pw_zero(opt_embed%prev_embed_pot)
412 IF (opt_embed%open_shell_embed)
THEN
413 NULLIFY (opt_embed%prev_spin_embed_pot)
414 ALLOCATE (opt_embed%prev_spin_embed_pot)
415 CALL auxbas_pw_pool%create_pw(opt_embed%prev_spin_embed_pot)
416 CALL pw_zero(opt_embed%prev_spin_embed_pot)
421 opt_embed%allowed_decrease = 0.0001_dp
424 opt_embed%reg_term = 0.0_dp
427 opt_embed%accept_step = .true.
428 opt_embed%newton_step = .false.
429 opt_embed%last_accepted = 1
432 opt_embed%max_trad = opt_embed%trust_rad*7.900_dp
433 opt_embed%min_trad = opt_embed%trust_rad*0.125*0.065_dp
442 SUBROUTINE read_opt_embed_section(opt_embed, opt_embed_section)
446 INTEGER :: embed_guess, embed_optimizer
450 r_val=opt_embed%lambda)
453 i_val=opt_embed%n_iter)
456 r_val=opt_embed%trust_rad)
459 r_val=opt_embed%conv_max)
462 r_val=opt_embed%conv_int)
465 r_val=opt_embed%conv_max_spin)
468 r_val=opt_embed%conv_int_spin)
474 l_val=opt_embed%read_embed_pot)
477 l_val=opt_embed%read_embed_pot_cube)
480 l_val=opt_embed%grid_opt)
483 l_val=opt_embed%leeuwen)
489 r_val=opt_embed%vw_cutoff)
492 r_val=opt_embed%vw_smooth_cutoff_range)
495 SELECT CASE (embed_optimizer)
497 opt_embed%steep_desc = .true.
499 opt_embed%steep_desc = .false.
500 opt_embed%level_shift = .false.
502 opt_embed%steep_desc = .false.
503 opt_embed%level_shift = .true.
505 opt_embed%steep_desc = .true.
509 SELECT CASE (embed_guess)
511 opt_embed%add_const_pot = .false.
512 opt_embed%Fermi_Amaldi = .false.
513 opt_embed%Coulomb_guess = .false.
514 opt_embed%diff_guess = .false.
516 opt_embed%add_const_pot = .true.
517 opt_embed%Fermi_Amaldi = .false.
518 opt_embed%Coulomb_guess = .false.
519 opt_embed%diff_guess = .true.
521 opt_embed%add_const_pot = .true.
522 opt_embed%Fermi_Amaldi = .true.
523 opt_embed%Coulomb_guess = .false.
524 opt_embed%diff_guess = .false.
526 opt_embed%add_const_pot = .true.
527 opt_embed%Fermi_Amaldi = .true.
528 opt_embed%Coulomb_guess = .true.
529 opt_embed%diff_guess = .false.
531 opt_embed%add_const_pot = .false.
532 opt_embed%Fermi_Amaldi = .false.
533 opt_embed%Coulomb_guess = .false.
534 opt_embed%diff_guess = .false.
537 END SUBROUTINE read_opt_embed_section
548 INTEGER :: iatom, ikind, nsgf
549 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: kind_of
552 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
556 particle_set=particle_set, &
557 qs_kind_set=qs_kind_set, &
558 atomic_kind_set=atomic_kind_set)
563 DO iatom = 1,
SIZE(particle_set)
564 ikind = kind_of(iatom)
565 CALL get_qs_kind(qs_kind=qs_kind_set(ikind), nsgf=nsgf, basis_type=
"RI_AUX")
566 dimen_aux = dimen_aux + nsgf
576 SUBROUTINE make_lri_object(qs_env, lri)
580 INTEGER :: ikind, natom, nkind, nsgf
583 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
585 NULLIFY (atomic_kind, lri)
586 CALL get_qs_env(qs_env=qs_env, atomic_kind_set=atomic_kind_set, &
587 qs_kind_set=qs_kind_set)
588 nkind =
SIZE(atomic_kind_set)
590 ALLOCATE (lri(nkind))
593 NULLIFY (lri(ikind)%acoef)
594 NULLIFY (lri(ikind)%v_int)
595 atomic_kind => atomic_kind_set(ikind)
597 CALL get_qs_kind(qs_kind=qs_kind_set(ikind), nsgf=nsgf, basis_type=
"RI_AUX")
598 ALLOCATE (lri(ikind)%acoef(natom, nsgf))
599 lri(ikind)%acoef = 0._dp
600 ALLOCATE (lri(ikind)%v_int(natom, nsgf))
601 lri(ikind)%v_int = 0._dp
604 END SUBROUTINE make_lri_object
613 LOGICAL :: open_shell_embed
620 qs_env%given_embed_pot = .true.
621 NULLIFY (input, dft_control, embed_pot, spin_embed_pot, embed_pot, spin_embed_pot, &
625 dft_control=dft_control, &
628 open_shell_embed = .false.
629 IF (dft_control%nspins .EQ. 2) open_shell_embed = .true.
632 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool_subsys)
638 CALL auxbas_pw_pool_subsys%create_pw(embed_pot)
639 IF (open_shell_embed)
THEN
641 ALLOCATE (spin_embed_pot)
642 CALL auxbas_pw_pool_subsys%create_pw(spin_embed_pot)
645 CALL read_embed_pot_cube(embed_pot, spin_embed_pot, qs_section, open_shell_embed)
647 IF (.NOT. open_shell_embed)
THEN
648 CALL set_qs_env(qs_env=qs_env, embed_pot=embed_pot)
650 CALL set_qs_env(qs_env=qs_env, embed_pot=embed_pot, spin_embed_pot=spin_embed_pot)
670 IF (opt_embed%read_embed_pot) &
671 CALL read_embed_pot_vector(qs_env, embed_pot, spin_embed_pot, section, &
672 opt_embed%embed_pot_coef, opt_embed%open_shell_embed)
674 IF (opt_embed%read_embed_pot_cube) &
675 CALL read_embed_pot_cube(embed_pot, spin_embed_pot, section, opt_embed%open_shell_embed)
686 SUBROUTINE read_embed_pot_cube(embed_pot, spin_embed_pot, section, open_shell_embed)
689 LOGICAL :: open_shell_embed
691 CHARACTER(LEN=default_path_length) :: filename
693 REAL(kind=
dp) :: scaling_factor
697 INQUIRE (file=filename, exist=exist)
699 cpabort(
"Embedding cube file not found. ")
701 scaling_factor = 1.0_dp
705 IF (open_shell_embed)
THEN
708 INQUIRE (file=filename, exist=exist)
710 cpabort(
"Embedding spin cube file not found. ")
712 scaling_factor = 1.0_dp
716 END SUBROUTINE read_embed_pot_cube
727 SUBROUTINE read_embed_pot_vector(qs_env, embed_pot, spin_embed_pot, section, embed_pot_coef, open_shell_embed)
732 TYPE(
cp_fm_type),
INTENT(IN) :: embed_pot_coef
733 LOGICAL,
INTENT(IN) :: open_shell_embed
735 CHARACTER(LEN=default_path_length) :: filename
736 INTEGER :: dimen_aux, dimen_restart_basis, &
737 dimen_var_aux, l_global, lll, &
738 nrow_local, restart_unit
739 INTEGER,
DIMENSION(:),
POINTER :: row_indices
740 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: coef, coef_read
748 IF (open_shell_embed)
THEN
749 dimen_var_aux = dimen_aux*2
751 dimen_var_aux = dimen_aux
761 nrow_global=dimen_var_aux, ncol_global=1)
762 CALL cp_fm_create(my_embed_pot_coef, fm_struct, name=
"my_pot_coef")
771 ALLOCATE (coef(dimen_var_aux))
774 IF (para_env%is_source())
THEN
777 CALL embed_restart_file_name(filename, section)
780 file_action=
"READ", &
781 file_form=
"UNFORMATTED", &
783 unit_number=restart_unit)
785 READ (restart_unit) dimen_restart_basis
787 IF (.NOT. (dimen_restart_basis == dimen_aux)) &
788 cpabort(
"Wrong dimension of the embedding basis in the restart file.")
790 ALLOCATE (coef_read(dimen_var_aux))
793 READ (restart_unit) coef_read
794 coef(:) = coef_read(:)
795 DEALLOCATE (coef_read)
803 CALL para_env%bcast(coef)
808 nrow_local=nrow_local, &
809 row_indices=row_indices)
811 DO lll = 1, nrow_local
812 l_global = row_indices(lll)
813 my_embed_pot_coef%local_data(lll, 1) = coef(l_global)
822 CALL update_embed_pot(embed_pot_coef, dimen_aux, embed_pot, spin_embed_pot, &
823 qs_env, .false., open_shell_embed)
831 END SUBROUTINE read_embed_pot_vector
838 SUBROUTINE embed_restart_file_name(filename, section)
839 CHARACTER(LEN=default_path_length),
INTENT(OUT) :: filename
846 INQUIRE (file=filename, exist=exist)
848 cpabort(
"Embedding restart file not found. ")
850 END SUBROUTINE embed_restart_file_name
859 INTEGER :: i_dens, i_spin, ikind
861 IF (.NOT. opt_embed%grid_opt)
THEN
871 DEALLOCATE (opt_embed%embed_pot_grad, opt_embed%embed_pot_coef, &
872 opt_embed%step, opt_embed%prev_step, opt_embed%embed_pot_hess, &
873 opt_embed%prev_embed_pot_grad, opt_embed%prev_embed_pot_coef, &
874 opt_embed%prev_embed_pot_hess, opt_embed%kinetic_mat)
875 DEALLOCATE (opt_embed%w_func)
876 DEALLOCATE (opt_embed%max_diff)
877 DEALLOCATE (opt_embed%int_diff)
879 DO ikind = 1,
SIZE(opt_embed%lri)
880 DEALLOCATE (opt_embed%lri(ikind)%v_int)
881 DEALLOCATE (opt_embed%lri(ikind)%acoef)
883 DEALLOCATE (opt_embed%lri)
886 IF (
ASSOCIATED(opt_embed%prev_subsys_dens))
THEN
887 DO i_dens = 1,
SIZE(opt_embed%prev_subsys_dens)
888 CALL opt_embed%prev_subsys_dens(i_dens)%release()
890 DEALLOCATE (opt_embed%prev_subsys_dens)
892 DEALLOCATE (opt_embed%max_subsys_dens_diff)
894 DEALLOCATE (opt_embed%all_nspins)
896 IF (
ASSOCIATED(opt_embed%const_pot))
THEN
897 CALL opt_embed%const_pot%release()
898 DEALLOCATE (opt_embed%const_pot)
901 IF (
ASSOCIATED(opt_embed%pot_diff))
THEN
902 CALL opt_embed%pot_diff%release()
903 DEALLOCATE (opt_embed%pot_diff)
906 IF (
ASSOCIATED(opt_embed%prev_embed_pot))
THEN
907 CALL opt_embed%prev_embed_pot%release()
908 DEALLOCATE (opt_embed%prev_embed_pot)
910 IF (
ASSOCIATED(opt_embed%prev_spin_embed_pot))
THEN
911 CALL opt_embed%prev_spin_embed_pot%release()
912 DEALLOCATE (opt_embed%prev_spin_embed_pot)
914 IF (
ASSOCIATED(opt_embed%v_w))
THEN
915 DO i_spin = 1,
SIZE(opt_embed%v_w)
916 CALL opt_embed%v_w(i_spin)%release()
918 DEALLOCATE (opt_embed%v_w)
933 SUBROUTINE coulomb_guess(v_rspace, rhs, mapping_section, qs_env, nforce_eval, iforce_eval, eta)
935 REAL(kind=
dp),
DIMENSION(:),
POINTER :: rhs
938 INTEGER :: nforce_eval, iforce_eval
941 INTEGER :: iparticle, jparticle, natom
942 INTEGER,
DIMENSION(:),
POINTER :: map_index
943 REAL(kind=
dp) :: dvol, normalize_factor
944 REAL(kind=
dp),
DIMENSION(:),
POINTER :: rhs_subsys
955 CALL get_qs_env(qs_env=qs_env, subsys=subsys, pw_env=pw_env)
957 natom = particles%n_els
959 ALLOCATE (rhs_subsys(natom))
966 DO iparticle = 1, natom
967 jparticle = map_index(iparticle)
968 rhs_subsys(iparticle) = rhs(jparticle)
972 NULLIFY (auxbas_pw_pool)
974 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
975 poisson_env=poisson_env)
977 CALL auxbas_pw_pool%create_pw(v_resp_gspace)
979 CALL auxbas_pw_pool%create_pw(v_resp_rspace)
981 CALL auxbas_pw_pool%create_pw(rho_resp)
989 vhartree=v_resp_rspace)
990 dvol = v_resp_rspace%pw_grid%dvol
992 normalize_factor = sqrt((eta/
pi)**3)
994 CALL pw_scale(v_resp_rspace, normalize_factor)
997 CALL pw_copy(v_resp_rspace, v_rspace)
1000 CALL v_resp_gspace%release()
1001 CALL v_resp_rspace%release()
1002 CALL rho_resp%release()
1005 DEALLOCATE (map_index)
1007 DEALLOCATE (rhs_subsys)
1023 spin_embed_pot, spin_embed_pot_subsys, open_shell_embed, &
1030 LOGICAL :: open_shell_embed, change_spin_sign
1039 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool_subsys)
1042 NULLIFY (embed_pot_subsys)
1043 ALLOCATE (embed_pot_subsys)
1044 CALL auxbas_pw_pool_subsys%create_pw(embed_pot_subsys)
1047 CALL pw_copy(embed_pot, embed_pot_subsys)
1049 IF (open_shell_embed)
THEN
1050 NULLIFY (spin_embed_pot_subsys)
1051 ALLOCATE (spin_embed_pot_subsys)
1052 CALL auxbas_pw_pool_subsys%create_pw(spin_embed_pot_subsys)
1054 IF (change_spin_sign)
THEN
1055 CALL pw_axpy(spin_embed_pot, spin_embed_pot_subsys, -1.0_dp, 0.0_dp, allow_noncompatible_grids=.true.)
1057 CALL pw_copy(spin_embed_pot, spin_embed_pot_subsys)
1077 CHARACTER(LEN=*),
PARAMETER :: routinen =
'calculate_embed_pot_grad'
1083 embed_pot_coeff_spinless, &
1084 regular_term, spin_reg, spinless_reg
1089 CALL timeset(routinen, handle)
1093 CALL cp_fm_to_fm(opt_embed%embed_pot_grad, opt_embed%prev_embed_pot_grad)
1094 CALL cp_fm_to_fm(opt_embed%embed_pot_Hess, opt_embed%prev_embed_pot_Hess)
1098 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env, para_env=para_env)
1101 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
1104 CALL calculate_embed_pot_grad_inner(qs_env, opt_embed%dimen_aux, diff_rho_r, diff_rho_spin, &
1105 opt_embed%embed_pot_grad, &
1106 opt_embed%open_shell_embed, opt_embed%lri)
1109 IF (opt_embed%i_iter .EQ. 1)
THEN
1110 CALL compute_kinetic_mat(qs_env, opt_embed%kinetic_mat)
1114 matrix_struct=fm_struct)
1115 CALL cp_fm_create(regular_term, fm_struct, name=
"regular_term")
1120 IF (opt_embed%open_shell_embed)
THEN
1122 NULLIFY (fm_struct, blacs_env)
1126 CALL cp_fm_get_info(matrix=opt_embed%embed_pot_coef, context=blacs_env)
1128 nrow_global=opt_embed%dimen_aux, ncol_global=1)
1129 CALL cp_fm_create(embed_pot_coeff_spinless, fm_struct, name=
"pot_coeff_spinless")
1130 CALL cp_fm_create(embed_pot_coeff_spin, fm_struct, name=
"pot_coeff_spin")
1131 CALL cp_fm_create(spinless_reg, fm_struct, name=
"spinless_reg")
1132 CALL cp_fm_create(spin_reg, fm_struct, name=
"spin_reg")
1141 mtarget=embed_pot_coeff_spinless, &
1142 nrow=opt_embed%dimen_aux, ncol=1, &
1143 s_firstrow=1, s_firstcol=1, &
1144 t_firstrow=1, t_firstcol=1)
1146 mtarget=embed_pot_coeff_spin, &
1147 nrow=opt_embed%dimen_aux, ncol=1, &
1148 s_firstrow=opt_embed%dimen_aux + 1, s_firstcol=1, &
1149 t_firstrow=1, t_firstcol=1)
1151 CALL parallel_gemm(transa=
"N", transb=
"N", m=opt_embed%dimen_aux, n=1, &
1152 k=opt_embed%dimen_aux, alpha=1.0_dp, &
1153 matrix_a=opt_embed%kinetic_mat, matrix_b=embed_pot_coeff_spinless, &
1154 beta=0.0_dp, matrix_c=spinless_reg)
1155 CALL parallel_gemm(transa=
"N", transb=
"N", m=opt_embed%dimen_aux, n=1, &
1156 k=opt_embed%dimen_aux, alpha=1.0_dp, &
1157 matrix_a=opt_embed%kinetic_mat, matrix_b=embed_pot_coeff_spin, &
1158 beta=0.0_dp, matrix_c=spin_reg)
1161 mtarget=regular_term, &
1162 nrow=opt_embed%dimen_aux, ncol=1, &
1163 s_firstrow=1, s_firstcol=1, &
1164 t_firstrow=1, t_firstcol=1)
1166 mtarget=regular_term, &
1167 nrow=opt_embed%dimen_aux, ncol=1, &
1168 s_firstrow=1, s_firstcol=1, &
1169 t_firstrow=opt_embed%dimen_aux + 1, t_firstcol=1)
1177 CALL parallel_gemm(transa=
"N", transb=
"N", m=opt_embed%dimen_var_aux, n=1, &
1178 k=opt_embed%dimen_var_aux, alpha=1.0_dp, &
1179 matrix_a=opt_embed%kinetic_mat, matrix_b=opt_embed%embed_pot_coef, &
1180 beta=0.0_dp, matrix_c=regular_term)
1184 CALL cp_fm_scale_and_add(1.0_dp, opt_embed%embed_pot_grad, 4.0_dp*opt_embed%lambda, regular_term)
1187 CALL cp_fm_trace(opt_embed%embed_pot_coef, regular_term, opt_embed%reg_term)
1188 opt_embed%reg_term = 2.0_dp*opt_embed%lambda*opt_embed%reg_term
1193 CALL timestop(handle)
1208 SUBROUTINE calculate_embed_pot_grad_inner(qs_env, dimen_aux, rho_r, rho_spin, embed_pot_grad, &
1209 open_shell_embed, lri)
1211 INTEGER :: dimen_aux
1213 TYPE(
cp_fm_type),
INTENT(IN) :: embed_pot_grad
1214 LOGICAL :: open_shell_embed
1217 CHARACTER(LEN=*),
PARAMETER :: routinen =
'calculate_embed_pot_grad_inner'
1219 INTEGER :: handle, iatom, ikind, l_global, lll, &
1220 nrow_local, nsgf, start_pos
1221 INTEGER,
DIMENSION(:),
POINTER :: row_indices
1222 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: pot_grad
1228 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1232 CALL timeset(routinen, handle)
1235 particle_set=particle_set, &
1236 qs_kind_set=qs_kind_set, &
1237 dft_control=dft_control, &
1239 atomic_kind_set=atomic_kind_set, &
1243 IF (open_shell_embed)
THEN
1244 ALLOCATE (pot_grad(dimen_aux*2))
1246 ALLOCATE (pot_grad(dimen_aux))
1250 DO ikind = 1,
SIZE(lri)
1251 lri(ikind)%v_int = 0.0_dp
1256 DO ikind = 1,
SIZE(lri)
1257 CALL para_env%sum(lri(ikind)%v_int)
1262 DO ikind = 1,
SIZE(lri)
1263 DO iatom = 1,
SIZE(lri(ikind)%v_int, dim=1)
1264 nsgf =
SIZE(lri(ikind)%v_int(iatom, :))
1265 pot_grad(start_pos:start_pos + nsgf - 1) = lri(ikind)%v_int(iatom, :)
1266 start_pos = start_pos + nsgf
1271 IF (open_shell_embed)
THEN
1272 DO ikind = 1,
SIZE(lri)
1273 lri(ikind)%v_int = 0.0_dp
1278 DO ikind = 1,
SIZE(lri)
1279 CALL para_env%sum(lri(ikind)%v_int)
1282 start_pos = dimen_aux + 1
1283 DO ikind = 1,
SIZE(lri)
1284 DO iatom = 1,
SIZE(lri(ikind)%v_int, dim=1)
1285 nsgf =
SIZE(lri(ikind)%v_int(iatom, :))
1286 pot_grad(start_pos:start_pos + nsgf - 1) = lri(ikind)%v_int(iatom, :)
1287 start_pos = start_pos + nsgf
1293 pot_grad = pot_grad*rho_r%pw_grid%dvol
1297 nrow_local=nrow_local, &
1298 row_indices=row_indices)
1301 DO lll = 1, nrow_local
1302 l_global = row_indices(lll)
1303 embed_pot_grad%local_data(lll, 1) = pot_grad(l_global)
1306 DEALLOCATE (pot_grad)
1308 CALL timestop(handle)
1310 END SUBROUTINE calculate_embed_pot_grad_inner
1318 SUBROUTINE compute_kinetic_mat(qs_env, kinetic_mat)
1320 TYPE(
cp_fm_type),
INTENT(INOUT) :: kinetic_mat
1322 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_kinetic_mat'
1330 CALL timeset(routinen, handle)
1332 NULLIFY (ks_env, sab_orb, matrix_t)
1335 CALL get_qs_env(qs_env=qs_env, ks_env=ks_env, sab_orb=sab_orb)
1339 matrix_name=
"KINETIC ENERGY MATRIX", &
1340 basis_type=
"RI_AUX", &
1341 sab_nl=sab_orb, calculate_forces=.false.)
1349 CALL timestop(handle)
1351 END SUBROUTINE compute_kinetic_mat
1360 SUBROUTINE grid_regularize(potential, pw_env, lambda, reg_term)
1364 REAL(kind=
dp) :: lambda, reg_term
1367 INTEGER,
DIMENSION(3) :: lb, n, ub
1379 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
1381 CALL auxbas_pw_pool%create_pw(potential_g)
1383 CALL auxbas_pw_pool%create_pw(dr2_pot)
1385 CALL auxbas_pw_pool%create_pw(grid_reg)
1387 CALL auxbas_pw_pool%create_pw(grid_reg_g)
1395 CALL pw_dr2(potential_g, dr2_pot, i, i)
1396 CALL pw_axpy(dr2_pot, grid_reg_g, 1.0_dp)
1402 CALL pw_axpy(grid_reg, potential, -4.0_dp*lambda)
1408 CALL auxbas_pw_pool%create_pw(dpot(i))
1409 CALL auxbas_pw_pool%create_pw(dpot_g(i))
1412 CALL auxbas_pw_pool%create_pw(square_norm_dpot)
1417 CALL pw_copy(potential_g, dpot_g(i))
1422 lb(1:3) = square_norm_dpot%pw_grid%bounds_local(1, 1:3)
1423 ub(1:3) = square_norm_dpot%pw_grid%bounds_local(2, 1:3)
1430 square_norm_dpot%array(i, j, k) = (dpot(1)%array(i, j, k)* &
1431 dpot(1)%array(i, j, k) + &
1432 dpot(2)%array(i, j, k)* &
1433 dpot(2)%array(i, j, k) + &
1434 dpot(3)%array(i, j, k)* &
1435 dpot(3)%array(i, j, k))
1444 CALL auxbas_pw_pool%give_back_pw(potential_g)
1445 CALL auxbas_pw_pool%give_back_pw(dr2_pot)
1446 CALL auxbas_pw_pool%give_back_pw(grid_reg)
1447 CALL auxbas_pw_pool%give_back_pw(grid_reg_g)
1448 CALL auxbas_pw_pool%give_back_pw(square_norm_dpot)
1450 CALL auxbas_pw_pool%give_back_pw(dpot(i))
1451 CALL auxbas_pw_pool%give_back_pw(dpot_g(i))
1454 END SUBROUTINE grid_regularize
1467 SUBROUTINE opt_embed_step(diff_rho_r, diff_rho_spin, opt_embed, embed_pot, spin_embed_pot, rho_r_ref, qs_env)
1476 CHARACTER(LEN=*),
PARAMETER :: routinen =
'opt_embed_step'
1477 REAL(kind=
dp),
PARAMETER :: thresh = 0.000001_dp
1479 INTEGER :: handle, l_global, lll, nrow_local
1480 INTEGER,
DIMENSION(:),
POINTER :: row_indices
1481 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigenval
1483 TYPE(
cp_fm_type) :: diag_grad, diag_step, fm_u, fm_u_scale
1486 CALL timeset(routinen, handle)
1488 IF (opt_embed%grid_opt)
THEN
1490 opt_embed%step_len = opt_embed%trust_rad
1491 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
1492 IF (opt_embed%leeuwen)
THEN
1493 CALL leeuwen_baerends_potential_update(pw_env, embed_pot, spin_embed_pot, diff_rho_r, diff_rho_spin, &
1494 rho_r_ref, opt_embed%open_shell_embed, opt_embed%trust_rad)
1496 IF (opt_embed%fab)
THEN
1497 CALL fab_update(qs_env, rho_r_ref, opt_embed%prev_embed_pot, opt_embed%prev_spin_embed_pot, &
1498 embed_pot, spin_embed_pot, &
1499 diff_rho_r, diff_rho_spin, opt_embed%v_w, opt_embed%i_iter, opt_embed%trust_rad, &
1500 opt_embed%open_shell_embed, opt_embed%vw_cutoff, opt_embed%vw_smooth_cutoff_range)
1502 CALL grid_based_step(diff_rho_r, diff_rho_spin, pw_env, opt_embed, embed_pot, spin_embed_pot)
1508 IF (.NOT. opt_embed%accept_step) &
1512 IF (opt_embed%steep_desc)
THEN
1513 IF (opt_embed%i_iter .GT. 2) &
1514 opt_embed%trust_rad = barzilai_borwein(opt_embed%step, opt_embed%prev_step, &
1515 opt_embed%embed_pot_grad, opt_embed%prev_embed_pot_grad)
1516 IF (abs(opt_embed%trust_rad) .GT. opt_embed%max_trad)
THEN
1517 IF (opt_embed%trust_rad .GT. 0.0_dp)
THEN
1518 opt_embed%trust_rad = opt_embed%max_trad
1520 opt_embed%trust_rad = -opt_embed%max_trad
1524 CALL cp_fm_to_fm(opt_embed%step, opt_embed%prev_step)
1527 CALL cp_fm_scale_and_add(1.0_dp, opt_embed%step, opt_embed%trust_rad, opt_embed%embed_pot_grad)
1528 opt_embed%step_len = opt_embed%trust_rad
1532 IF (opt_embed%i_iter > 1)
THEN
1533 IF (opt_embed%accept_step) &
1534 CALL symm_rank_one_update(opt_embed%embed_pot_grad, opt_embed%prev_embed_pot_grad, &
1535 opt_embed%step, opt_embed%prev_embed_pot_Hess, opt_embed%embed_pot_Hess)
1544 ALLOCATE (eigenval(opt_embed%dimen_var_aux))
1547 matrix_struct=fm_struct)
1553 matrix_struct=fm_struct)
1554 CALL cp_fm_create(diag_grad, fm_struct, name=
"diag_grad")
1556 CALL cp_fm_create(diag_step, fm_struct, name=
"diag_step")
1560 CALL cp_fm_to_fm(opt_embed%embed_pot_hess, fm_u_scale)
1566 CALL cp_fm_to_fm(fm_u_scale, opt_embed%embed_pot_hess)
1569 CALL parallel_gemm(transa=
"T", transb=
"N", m=opt_embed%dimen_var_aux, n=1, &
1570 k=opt_embed%dimen_var_aux, alpha=1.0_dp, &
1571 matrix_a=fm_u, matrix_b=opt_embed%embed_pot_grad, beta=0.0_dp, &
1575 nrow_local=nrow_local, &
1576 row_indices=row_indices)
1578 DO lll = 1, nrow_local
1579 l_global = row_indices(lll)
1580 IF (abs(eigenval(l_global)) .GE. thresh)
THEN
1581 diag_step%local_data(lll, 1) = &
1582 -diag_grad%local_data(lll, 1)/(eigenval(l_global))
1584 diag_step%local_data(lll, 1) = 0.0_dp
1587 CALL cp_fm_trace(diag_step, diag_step, opt_embed%step_len)
1590 CALL parallel_gemm(transa=
"N", transb=
"N", m=opt_embed%dimen_var_aux, n=1, &
1591 k=opt_embed%dimen_var_aux, alpha=1.0_dp, &
1592 matrix_a=fm_u, matrix_b=diag_step, beta=0.0_dp, &
1593 matrix_c=opt_embed%step)
1603 CALL cp_fm_trace(opt_embed%step, opt_embed%step, opt_embed%step_len)
1604 IF (opt_embed%step_len .GT. opt_embed%trust_rad)
THEN
1606 IF (opt_embed%level_shift)
THEN
1608 CALL level_shift(opt_embed, diag_grad, eigenval, diag_step)
1610 CALL cp_fm_trace(diag_step, diag_step, opt_embed%step_len)
1611 CALL cp_fm_scale(opt_embed%trust_rad/opt_embed%step_len, diag_step)
1613 CALL cp_fm_trace(diag_step, diag_step, opt_embed%step_len)
1615 CALL parallel_gemm(transa=
"N", transb=
"N", m=opt_embed%dimen_var_aux, n=1, &
1616 k=opt_embed%dimen_var_aux, alpha=1.0_dp, &
1617 matrix_a=fm_u, matrix_b=diag_step, beta=0.0_dp, &
1618 matrix_c=opt_embed%step)
1619 CALL cp_fm_trace(opt_embed%step, opt_embed%step, opt_embed%step_len)
1622 opt_embed%newton_step = .false.
1624 opt_embed%newton_step = .true.
1628 DEALLOCATE (eigenval)
1640 CALL update_embed_pot(opt_embed%embed_pot_coef, opt_embed%dimen_aux, embed_pot, &
1641 spin_embed_pot, qs_env, opt_embed%add_const_pot, &
1642 opt_embed%open_shell_embed, opt_embed%const_pot)
1645 CALL timestop(handle)
1659 SUBROUTINE grid_based_step(diff_rho_r, diff_rho_spin, pw_env, opt_embed, embed_pot, spin_embed_pot)
1667 CHARACTER(LEN=*),
PARAMETER :: routinen =
'grid_based_step'
1670 REAL(kind=
dp) :: my_reg_term
1672 CALL timeset(routinen, handle)
1675 CALL pw_axpy(diff_rho_r, embed_pot, opt_embed%step_len)
1677 CALL grid_regularize(embed_pot, pw_env, opt_embed%lambda, my_reg_term)
1678 opt_embed%reg_term = opt_embed%reg_term + my_reg_term
1680 IF (opt_embed%open_shell_embed)
THEN
1681 CALL pw_axpy(diff_rho_spin, spin_embed_pot, opt_embed%step_len)
1682 CALL grid_regularize(spin_embed_pot, pw_env, opt_embed%lambda, my_reg_term)
1683 opt_embed%reg_term = opt_embed%reg_term + my_reg_term
1686 CALL timestop(handle)
1688 END SUBROUTINE grid_based_step
1703 SUBROUTINE update_embed_pot(embed_pot_coef, dimen_aux, embed_pot, spin_embed_pot, &
1704 qs_env, add_const_pot, open_shell_embed, const_pot)
1705 TYPE(
cp_fm_type),
INTENT(IN) :: embed_pot_coef
1706 INTEGER :: dimen_aux
1710 LOGICAL :: add_const_pot, open_shell_embed
1713 CHARACTER(LEN=*),
PARAMETER :: routinen =
'update_embed_pot'
1715 INTEGER :: handle, l_global, lll, nrow_local
1716 INTEGER,
DIMENSION(:),
POINTER :: row_indices
1717 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: wf_vector
1723 embed_pot_coef_spinless
1733 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1735 CALL timeset(routinen, handle)
1738 particle_set=particle_set, &
1739 qs_kind_set=qs_kind_set, &
1740 dft_control=dft_control, &
1742 atomic_kind_set=atomic_kind_set, &
1743 pw_env=pw_env, mos=mos, para_env=para_env)
1744 CALL get_mo_set(mo_set=mos(1), mo_coeff=mo_coeff)
1747 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
1750 CALL auxbas_pw_pool%create_pw(rho_g)
1752 CALL auxbas_pw_pool%create_pw(psi_l)
1755 ALLOCATE (wf_vector(dimen_aux))
1759 IF (open_shell_embed)
THEN
1763 nrow_global=dimen_aux, ncol_global=1)
1764 CALL cp_fm_create(embed_pot_coef_spinless, fm_struct, name=
"pot_coeff_spinless")
1765 CALL cp_fm_create(embed_pot_coef_spin, fm_struct, name=
"pot_coeff_spin")
1772 mtarget=embed_pot_coef_spinless, &
1773 nrow=dimen_aux, ncol=1, &
1774 s_firstrow=1, s_firstcol=1, &
1775 t_firstrow=1, t_firstcol=1)
1777 mtarget=embed_pot_coef_spin, &
1778 nrow=dimen_aux, ncol=1, &
1779 s_firstrow=dimen_aux + 1, s_firstcol=1, &
1780 t_firstrow=1, t_firstcol=1)
1784 nrow_local=nrow_local, &
1785 row_indices=row_indices)
1788 DO lll = 1, nrow_local
1789 l_global = row_indices(lll)
1790 wf_vector(l_global) = embed_pot_coef_spinless%local_data(lll, 1)
1792 CALL para_env%sum(wf_vector)
1796 qs_kind_set, cell, particle_set, pw_env, &
1797 dft_control%qs_control%eps_rho_rspace, &
1798 basis_type=
"RI_AUX")
1800 IF (add_const_pot)
THEN
1801 CALL pw_copy(const_pot, embed_pot)
1806 CALL pw_axpy(psi_l, embed_pot)
1811 nrow_local=nrow_local, &
1812 row_indices=row_indices)
1815 DO lll = 1, nrow_local
1816 l_global = row_indices(lll)
1817 wf_vector(l_global) = embed_pot_coef_spin%local_data(lll, 1)
1819 CALL para_env%sum(wf_vector)
1823 qs_kind_set, cell, particle_set, pw_env, &
1824 dft_control%qs_control%eps_rho_rspace, &
1825 basis_type=
"RI_AUX")
1828 CALL pw_axpy(psi_l, spin_embed_pot)
1833 nrow_local=nrow_local, &
1834 row_indices=row_indices)
1837 DO lll = 1, nrow_local
1838 l_global = row_indices(lll)
1839 wf_vector(l_global) = embed_pot_coef%local_data(lll, 1)
1841 CALL para_env%sum(wf_vector)
1845 qs_kind_set, cell, dft_control, particle_set, pw_env)
1848 qs_kind_set, cell, particle_set, pw_env, &
1849 dft_control%qs_control%eps_rho_rspace, &
1850 basis_type=
"RI_AUX")
1853 IF (add_const_pot)
THEN
1854 CALL pw_copy(const_pot, embed_pot)
1859 CALL pw_axpy(psi_l, embed_pot)
1863 DEALLOCATE (wf_vector)
1864 CALL auxbas_pw_pool%give_back_pw(psi_l)
1865 CALL auxbas_pw_pool%give_back_pw(rho_g)
1867 IF (open_shell_embed)
THEN
1872 CALL timestop(handle)
1874 END SUBROUTINE update_embed_pot
1885 SUBROUTINE inv_hessian_update(grad, prev_grad, step, prev_inv_Hess, inv_Hess)
1886 TYPE(
cp_fm_type),
INTENT(IN) :: grad, prev_grad, step, prev_inv_hess, &
1890 REAL(kind=
dp) :: factor1, s_dot_y, y_dot_b_inv_y
1892 TYPE(
cp_fm_type) :: b_inv_y, b_inv_y_s, s_s, s_y, s_y_b_inv, &
1897 nrow_global=mat_size)
1903 NULLIFY (fm_struct_mat, fm_struct_vec)
1906 matrix_struct=fm_struct_mat)
1908 matrix_struct=fm_struct_vec)
1911 CALL cp_fm_create(b_inv_y, fm_struct_vec, name=
"B_inv_y")
1916 CALL cp_fm_create(b_inv_y_s, fm_struct_mat, name=
"B_inv_y_s")
1917 CALL cp_fm_create(s_y_b_inv, fm_struct_mat, name=
"s_y_B_inv")
1932 CALL parallel_gemm(transa=
"N", transb=
"N", m=mat_size, n=1, &
1933 k=mat_size, alpha=1.0_dp, &
1934 matrix_a=prev_inv_hess, matrix_b=y, beta=0.0_dp, &
1937 CALL parallel_gemm(transa=
"N", transb=
"T", m=mat_size, n=mat_size, &
1938 k=1, alpha=1.0_dp, &
1939 matrix_a=step, matrix_b=step, beta=0.0_dp, &
1942 CALL parallel_gemm(transa=
"N", transb=
"T", m=mat_size, n=mat_size, &
1943 k=1, alpha=1.0_dp, &
1944 matrix_a=step, matrix_b=y, beta=0.0_dp, &
1954 factor1 = (s_dot_y + y_dot_b_inv_y)/(s_dot_y)**2
1959 CALL parallel_gemm(transa=
"N", transb=
"T", m=mat_size, n=mat_size, &
1960 k=1, alpha=1.0_dp, &
1961 matrix_a=b_inv_y, matrix_b=step, beta=0.0_dp, &
1964 CALL parallel_gemm(transa=
"N", transb=
"N", m=mat_size, n=mat_size, &
1965 k=mat_size, alpha=1.0_dp, &
1966 matrix_a=s_y, matrix_b=prev_inv_hess, beta=0.0_dp, &
1982 END SUBROUTINE inv_hessian_update
1992 SUBROUTINE hessian_update(grad, prev_grad, step, prev_Hess, Hess)
1993 TYPE(
cp_fm_type),
INTENT(IN) :: grad, prev_grad, step, prev_hess, hess
1996 REAL(kind=
dp) :: s_b_s, y_t_s
2000 TYPE(
cp_fm_type) :: b_s, b_s_s_b, s_t_b, y, y_y_t
2005 nrow_global=mat_size, para_env=para_env)
2019 NULLIFY (fm_struct_mat, fm_struct_vec, fm_struct_vec_t)
2022 matrix_struct=fm_struct_mat)
2024 matrix_struct=fm_struct_vec)
2026 nrow_global=1, ncol_global=mat_size)
2030 CALL cp_fm_create(s_t_b, fm_struct_vec_t, name=
"s_t_B")
2034 CALL cp_fm_create(b_s_s_b, fm_struct_mat, name=
"B_s_s_B")
2051 CALL parallel_gemm(transa=
"N", transb=
"T", m=mat_size, n=mat_size, &
2052 k=1, alpha=1.0_dp, &
2053 matrix_a=y, matrix_b=y, beta=0.0_dp, &
2061 CALL parallel_gemm(transa=
"N", transb=
"N", m=mat_size, n=1, &
2062 k=mat_size, alpha=1.0_dp, &
2063 matrix_a=hess, matrix_b=step, beta=0.0_dp, &
2068 CALL parallel_gemm(transa=
"T", transb=
"N", m=1, n=mat_size, &
2069 k=mat_size, alpha=1.0_dp, &
2070 matrix_a=step, matrix_b=hess, beta=0.0_dp, &
2073 CALL parallel_gemm(transa=
"N", transb=
"N", m=mat_size, n=mat_size, &
2074 k=1, alpha=1.0_dp, &
2075 matrix_a=b_s, matrix_b=s_t_b, beta=0.0_dp, &
2094 END SUBROUTINE hessian_update
2104 SUBROUTINE symm_rank_one_update(grad, prev_grad, step, prev_Hess, Hess)
2105 TYPE(
cp_fm_type),
INTENT(IN) :: grad, prev_grad, step, prev_hess, hess
2108 REAL(kind=
dp) :: factor
2119 NULLIFY (fm_struct_mat, fm_struct_vec)
2122 matrix_struct=fm_struct_mat)
2124 matrix_struct=fm_struct_vec)
2129 CALL cp_fm_create(y_b_x_y_b_x, fm_struct_mat, name=
"y_B_x_y_B_x")
2140 CALL parallel_gemm(transa=
"N", transb=
"N", m=mat_size, n=1, &
2141 k=mat_size, alpha=1.0_dp, &
2142 matrix_a=hess, matrix_b=step, beta=0.0_dp, &
2147 CALL parallel_gemm(transa=
"N", transb=
"T", m=mat_size, n=mat_size, &
2148 k=1, alpha=1.0_dp, &
2149 matrix_a=y, matrix_b=y, beta=0.0_dp, &
2150 matrix_c=y_b_x_y_b_x)
2163 END SUBROUTINE symm_rank_one_update
2173 CHARACTER(LEN=*),
PARAMETER :: routinen =
'step_control'
2176 REAL(kind=
dp) :: actual_ener_change, ener_ratio, &
2177 lin_term, pred_ener_change, quad_term
2181 CALL timeset(routinen, handle)
2185 matrix_struct=fm_struct)
2191 CALL cp_fm_trace(opt_embed%step, opt_embed%embed_pot_grad, lin_term)
2194 CALL parallel_gemm(transa=
"N", transb=
"N", m=opt_embed%dimen_aux, n=1, &
2195 k=opt_embed%dimen_aux, alpha=1.0_dp, &
2196 matrix_a=opt_embed%embed_pot_Hess, matrix_b=opt_embed%step, &
2197 beta=0.0_dp, matrix_c=h_b)
2200 pred_ener_change = lin_term + 0.5_dp*quad_term
2203 actual_ener_change = opt_embed%w_func(opt_embed%i_iter) - &
2204 opt_embed%w_func(opt_embed%last_accepted)
2206 ener_ratio = actual_ener_change/pred_ener_change
2210 IF (actual_ener_change .GT. 0.0_dp)
THEN
2212 opt_embed%accept_step = .true.
2215 IF ((ener_ratio .GT. 1.0_dp) .AND. (.NOT. opt_embed%newton_step) .AND. &
2216 (opt_embed%trust_rad .LT. opt_embed%max_trad)) &
2217 opt_embed%trust_rad = 2.0_dp*opt_embed%trust_rad
2221 IF (abs(actual_ener_change) .GE. opt_embed%allowed_decrease)
THEN
2222 opt_embed%accept_step = .false.
2225 IF (opt_embed%trust_rad .GE. opt_embed%min_trad) &
2226 opt_embed%trust_rad = 0.25_dp*opt_embed%trust_rad
2229 IF (opt_embed%accept_step) opt_embed%last_accepted = opt_embed%i_iter
2231 CALL timestop(handle)
2242 SUBROUTINE level_shift(opt_embed, diag_grad, eigenval, diag_step)
2245 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigenval
2248 CHARACTER(LEN=*),
PARAMETER :: routinen =
'level_shift'
2249 INTEGER,
PARAMETER :: max_iter = 25
2250 REAL(kind=
dp),
PARAMETER :: thresh = 0.00001_dp
2252 INTEGER :: handle, i_iter, l_global, lll, &
2253 min_index, nrow_local
2254 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: red_eigenval_map
2255 INTEGER,
DIMENSION(:),
POINTER :: row_indices
2256 LOGICAL :: converged, do_shift
2257 REAL(kind=
dp) :: diag_grad_norm, grad_min, hess_min, shift, shift_max, shift_min, step_len, &
2258 step_minus_trad, step_minus_trad_first, step_minus_trad_max, step_minus_trad_min
2261 CALL timeset(routinen, handle)
2265 nrow_local=nrow_local, &
2266 row_indices=row_indices, &
2269 min_index = minloc(abs(eigenval), dim=1)
2270 hess_min = eigenval(min_index)
2273 CALL cp_fm_trace(diag_grad, diag_grad, diag_grad_norm)
2275 IF (hess_min .LT. 0.0_dp)
THEN
2279 shift_max = hess_min + 0.1
2280 shift_min = diag_grad_norm/opt_embed%trust_rad
2289 step_minus_trad_max = shifted_step(diag_grad, eigenval, shift_max, opt_embed%trust_rad)
2290 step_minus_trad_min = shifted_step(diag_grad, eigenval, shift_min, opt_embed%trust_rad)
2295 IF (abs(step_minus_trad_max) .LE. thresh)
THEN
2298 IF (abs(step_minus_trad_min) .LE. thresh)
THEN
2301 DO i_iter = 1, max_iter
2302 shift = 0.5_dp*(shift_max + shift_min)
2303 step_minus_trad = shifted_step(diag_grad, eigenval, shift, opt_embed%trust_rad)
2304 IF (i_iter .EQ. 1) step_minus_trad_first = step_minus_trad
2305 IF (step_minus_trad .GT. 0.0_dp) shift_max = shift
2306 IF (step_minus_trad .LT. 0.0_dp) shift_min = shift
2308 IF (abs(step_minus_trad) .LT. thresh) converged = .true.
2311 IF (abs(step_minus_trad) .LT. abs(step_minus_trad_first)) do_shift = .true.
2315 IF (converged .OR. do_shift)
THEN
2316 DO lll = 1, nrow_local
2317 l_global = row_indices(lll)
2318 IF (abs(eigenval(l_global)) .GE. thresh)
THEN
2319 diag_step%local_data(lll, 1) = &
2320 -diag_grad%local_data(lll, 1)/(eigenval(l_global) - shift)
2322 diag_step%local_data(lll, 1) = 0.0_dp
2326 IF (.NOT. converged)
THEN
2328 CALL cp_fm_scale(opt_embed%trust_rad/step_len, diag_step)
2334 ALLOCATE (red_eigenval_map(opt_embed%dimen_var_aux))
2335 red_eigenval_map = 0
2336 DO lll = 1, nrow_local
2337 l_global = row_indices(lll)
2338 IF (eigenval(l_global) .GE. 0.0_dp)
THEN
2339 red_eigenval_map(l_global) = 1
2342 CALL para_env%sum(red_eigenval_map)
2347 DO lll = 1, nrow_local
2348 l_global = row_indices(lll)
2349 IF (red_eigenval_map(l_global) .EQ. 0)
THEN
2350 IF (abs(eigenval(l_global)) .GE. thresh)
THEN
2351 diag_step%local_data(lll, 1) = &
2352 -diag_grad%local_data(lll, 1)/(eigenval(l_global) - shift)
2354 diag_step%local_data(lll, 1) = 0.0_dp
2357 diag_step%local_data(lll, 1) = 0.0_dp
2366 CALL timestop(handle)
2368 END SUBROUTINE level_shift
2378 FUNCTION shifted_step(diag_grad, eigenval, shift, trust_rad)
RESULT(step_minus_trad)
2380 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:), &
2381 INTENT(IN) :: eigenval
2382 REAL(kind=
dp),
INTENT(IN) :: shift, trust_rad
2383 REAL(kind=
dp) :: step_minus_trad
2385 REAL(kind=
dp),
PARAMETER :: thresh = 0.000001_dp
2387 INTEGER :: l_global, lll, nrow_local
2388 INTEGER,
DIMENSION(:),
POINTER :: row_indices
2389 REAL(kind=
dp) :: step, step_1d
2393 nrow_local=nrow_local, &
2394 row_indices=row_indices, &
2398 DO lll = 1, nrow_local
2399 l_global = row_indices(lll)
2400 IF ((abs(eigenval(l_global)) .GE. thresh) .AND. (abs(diag_grad%local_data(lll, 1)) .GE. thresh))
THEN
2401 step_1d = -diag_grad%local_data(lll, 1)/(eigenval(l_global) + shift)
2402 step = step + step_1d**2
2406 CALL para_env%sum(step)
2408 step_minus_trad = sqrt(step) - trust_rad
2410 END FUNCTION shifted_step
2421 FUNCTION barzilai_borwein(step, prev_step, grad, prev_grad)
RESULT(length)
2422 TYPE(
cp_fm_type),
INTENT(IN) :: step, prev_step, grad, prev_grad
2423 REAL(kind=
dp) :: length
2425 REAL(kind=
dp) :: denominator, numerator
2433 matrix_struct=fm_struct)
2436 CALL cp_fm_create(grad_diff, fm_struct, name=
"grad_diff")
2437 CALL cp_fm_create(step_diff, fm_struct, name=
"step_diff")
2447 CALL cp_fm_trace(grad_diff, grad_diff, denominator)
2453 length = numerator/denominator
2455 END FUNCTION barzilai_borwein
2468 SUBROUTINE leeuwen_baerends_potential_update(pw_env, embed_pot, spin_embed_pot, diff_rho_r, diff_rho_spin, &
2469 rho_r_ref, open_shell_embed, step_len)
2475 LOGICAL,
INTENT(IN) :: open_shell_embed
2476 REAL(kind=
dp),
INTENT(IN) :: step_len
2478 CHARACTER(LEN=*),
PARAMETER :: routinen =
'Leeuwen_Baerends_potential_update'
2480 INTEGER :: handle, i, i_spin, j, k, nspins
2481 INTEGER,
DIMENSION(3) :: lb, ub
2482 REAL(kind=
dp) :: my_rho, rho_cutoff
2484 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: new_embed_pot, rho_n_1, temp_embed_pot
2486 CALL timeset(routinen, handle)
2488 rho_cutoff = epsilon(0.0_dp)
2491 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
2492 NULLIFY (new_embed_pot)
2495 IF (open_shell_embed) nspins = 2
2496 NULLIFY (new_embed_pot)
2497 ALLOCATE (new_embed_pot(nspins))
2498 DO i_spin = 1, nspins
2499 CALL auxbas_pw_pool%create_pw(new_embed_pot(i_spin))
2500 CALL pw_zero(new_embed_pot(i_spin))
2503 lb(1:3) = embed_pot%pw_grid%bounds_local(1, 1:3)
2504 ub(1:3) = embed_pot%pw_grid%bounds_local(2, 1:3)
2506 IF (.NOT. open_shell_embed)
THEN
2513 IF (rho_r_ref(1)%array(i, j, k) .GT. rho_cutoff)
THEN
2514 my_rho = rho_r_ref(1)%array(i, j, k)
2518 new_embed_pot(1)%array(i, j, k) = step_len*embed_pot%array(i, j, k)* &
2519 (diff_rho_r%array(i, j, k) + rho_r_ref(1)%array(i, j, k))/my_rho
2524 CALL pw_copy(new_embed_pot(1), embed_pot)
2529 ALLOCATE (rho_n_1(nspins))
2530 NULLIFY (temp_embed_pot)
2531 ALLOCATE (temp_embed_pot(nspins))
2532 DO i_spin = 1, nspins
2533 CALL auxbas_pw_pool%create_pw(rho_n_1(i_spin))
2535 CALL auxbas_pw_pool%create_pw(temp_embed_pot(i_spin))
2536 CALL pw_zero(temp_embed_pot(i_spin))
2538 CALL pw_copy(diff_rho_r, rho_n_1(1))
2539 CALL pw_copy(diff_rho_r, rho_n_1(2))
2540 CALL pw_axpy(diff_rho_spin, rho_n_1(1), 1.0_dp)
2541 CALL pw_axpy(diff_rho_spin, rho_n_1(2), -1.0_dp)
2542 CALL pw_scale(rho_n_1(1), a=0.5_dp)
2543 CALL pw_scale(rho_n_1(2), a=0.5_dp)
2545 CALL pw_copy(embed_pot, temp_embed_pot(1))
2546 CALL pw_copy(embed_pot, temp_embed_pot(2))
2547 CALL pw_axpy(spin_embed_pot, temp_embed_pot(1), 1.0_dp)
2548 CALL pw_axpy(spin_embed_pot, temp_embed_pot(2), -1.0_dp)
2550 IF (
SIZE(rho_r_ref) .EQ. 2)
THEN
2551 CALL pw_axpy(rho_r_ref(1), rho_n_1(1), 1.0_dp)
2552 CALL pw_axpy(rho_r_ref(2), rho_n_1(2), 1.0_dp)
2560 IF (rho_r_ref(1)%array(i, j, k) .GT. rho_cutoff)
THEN
2561 my_rho = rho_r_ref(1)%array(i, j, k)
2565 new_embed_pot(1)%array(i, j, k) = step_len*temp_embed_pot(1)%array(i, j, k)* &
2566 (rho_n_1(1)%array(i, j, k))/my_rho
2567 IF (rho_r_ref(2)%array(i, j, k) .GT. rho_cutoff)
THEN
2568 my_rho = rho_r_ref(2)%array(i, j, k)
2572 new_embed_pot(2)%array(i, j, k) = step_len*temp_embed_pot(2)%array(i, j, k)* &
2573 (rho_n_1(2)%array(i, j, k))/my_rho
2580 CALL pw_axpy(rho_r_ref(1), rho_n_1(1), 1.0_dp)
2589 IF (rho_r_ref(1)%array(i, j, k) .GT. rho_cutoff)
THEN
2590 my_rho = 0.5_dp*rho_r_ref(1)%array(i, j, k)
2594 new_embed_pot(1)%array(i, j, k) = step_len*temp_embed_pot(1)%array(i, j, k)* &
2595 (rho_n_1(1)%array(i, j, k))/my_rho
2596 new_embed_pot(2)%array(i, j, k) = step_len*temp_embed_pot(2)%array(i, j, k)* &
2597 (rho_n_1(2)%array(i, j, k))/my_rho
2604 CALL pw_copy(new_embed_pot(1), embed_pot)
2605 CALL pw_axpy(new_embed_pot(2), embed_pot, 1.0_dp)
2607 CALL pw_copy(new_embed_pot(1), spin_embed_pot)
2608 CALL pw_axpy(new_embed_pot(2), spin_embed_pot, -1.0_dp)
2609 CALL pw_scale(spin_embed_pot, a=0.5_dp)
2611 DO i_spin = 1, nspins
2612 CALL rho_n_1(i_spin)%release()
2613 CALL temp_embed_pot(i_spin)%release()
2615 DEALLOCATE (rho_n_1)
2616 DEALLOCATE (temp_embed_pot)
2619 DO i_spin = 1, nspins
2620 CALL new_embed_pot(i_spin)%release()
2623 DEALLOCATE (new_embed_pot)
2625 CALL timestop(handle)
2627 END SUBROUTINE leeuwen_baerends_potential_update
2646 SUBROUTINE fab_update(qs_env, rho_r_ref, prev_embed_pot, prev_spin_embed_pot, embed_pot, spin_embed_pot, &
2647 diff_rho_r, diff_rho_spin, v_w_ref, i_iter, step_len, open_shell_embed, &
2648 vw_cutoff, vw_smooth_cutoff_range)
2657 INTEGER,
INTENT(IN) :: i_iter
2658 REAL(kind=
dp) :: step_len
2659 LOGICAL :: open_shell_embed
2660 REAL(kind=
dp) :: vw_cutoff, vw_smooth_cutoff_range
2662 CHARACTER(LEN=*),
PARAMETER :: routinen =
'FAB_update'
2664 INTEGER :: handle, i_spin, nspins
2667 TYPE(
pw_r3d_rs_type),
ALLOCATABLE,
DIMENSION(:) :: new_embed_pot, temp_embed_pot, v_w
2670 CALL timeset(routinen, handle)
2677 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
2681 IF (i_iter .LE. 1)
THEN
2682 nspins =
SIZE(rho_r_ref)
2684 ALLOCATE (v_w_ref(nspins))
2685 DO i_spin = 1, nspins
2686 CALL auxbas_pw_pool%create_pw(v_w_ref(i_spin))
2688 CALL von_weizsacker(rho_r_ref, v_w_ref, qs_env, vw_cutoff, vw_smooth_cutoff_range)
2690 CALL pw_copy(embed_pot, prev_embed_pot)
2691 CALL pw_axpy(diff_rho_r, embed_pot, 0.5_dp)
2692 IF (open_shell_embed)
THEN
2693 CALL pw_copy(spin_embed_pot, prev_spin_embed_pot)
2694 CALL pw_axpy(diff_rho_r, embed_pot, 0.5_dp)
2702 IF (open_shell_embed) nspins = 2
2703 ALLOCATE (new_embed_pot(nspins))
2704 ALLOCATE (v_w(nspins))
2706 ALLOCATE (curr_rho(nspins))
2707 DO i_spin = 1, nspins
2708 CALL auxbas_pw_pool%create_pw(new_embed_pot(i_spin))
2709 CALL pw_zero(new_embed_pot(i_spin))
2711 CALL auxbas_pw_pool%create_pw(v_w(i_spin))
2714 CALL auxbas_pw_pool%create_pw(curr_rho(i_spin))
2715 CALL pw_zero(curr_rho(i_spin))
2720 IF (.NOT. open_shell_embed)
THEN
2722 CALL pw_copy(diff_rho_r, curr_rho(1))
2723 CALL pw_axpy(rho_r_ref(1), curr_rho(1), 1.0_dp)
2725 CALL von_weizsacker(curr_rho, v_w, qs_env, vw_cutoff, vw_smooth_cutoff_range)
2727 CALL pw_copy(prev_embed_pot, new_embed_pot(1))
2728 CALL pw_axpy(v_w(1), new_embed_pot(1), step_len)
2729 CALL pw_axpy(v_w_ref(1), new_embed_pot(1), -step_len)
2732 CALL pw_copy(embed_pot, prev_embed_pot)
2733 CALL pw_copy(new_embed_pot(1), embed_pot)
2737 CALL pw_copy(diff_rho_r, curr_rho(1))
2738 CALL pw_copy(diff_rho_r, curr_rho(2))
2739 CALL pw_axpy(diff_rho_spin, curr_rho(1), 1.0_dp)
2740 CALL pw_axpy(diff_rho_spin, curr_rho(2), -1.0_dp)
2741 CALL pw_scale(curr_rho(1), a=0.5_dp)
2742 CALL pw_scale(curr_rho(2), a=0.5_dp)
2744 IF (
SIZE(rho_r_ref) .EQ. 1)
THEN
2745 CALL pw_axpy(rho_r_ref(1), curr_rho(1), 0.5_dp)
2746 CALL pw_axpy(rho_r_ref(1), curr_rho(2), 0.5_dp)
2748 CALL pw_axpy(rho_r_ref(1), curr_rho(1), 1.0_dp)
2749 CALL pw_axpy(rho_r_ref(2), curr_rho(2), 1.0_dp)
2753 CALL von_weizsacker(curr_rho, v_w, qs_env, vw_cutoff, vw_smooth_cutoff_range)
2756 ALLOCATE (temp_embed_pot(nspins))
2757 DO i_spin = 1, nspins
2758 CALL auxbas_pw_pool%create_pw(temp_embed_pot(i_spin))
2759 CALL pw_zero(temp_embed_pot(i_spin))
2761 CALL pw_copy(embed_pot, temp_embed_pot(1))
2762 CALL pw_copy(embed_pot, temp_embed_pot(2))
2763 CALL pw_axpy(spin_embed_pot, temp_embed_pot(1), 1.0_dp)
2764 CALL pw_axpy(spin_embed_pot, temp_embed_pot(2), -1.0_dp)
2767 IF (
SIZE(v_w_ref) .EQ. 1)
THEN
2768 CALL pw_copy(temp_embed_pot(1), new_embed_pot(1))
2769 CALL pw_axpy(v_w(1), new_embed_pot(1), 0.5_dp*step_len)
2770 CALL pw_axpy(v_w_ref(1), new_embed_pot(1), -0.5_dp*step_len)
2772 CALL pw_copy(temp_embed_pot(2), new_embed_pot(2))
2773 CALL pw_axpy(v_w(2), new_embed_pot(2), 0.5_dp)
2774 CALL pw_axpy(v_w_ref(1), new_embed_pot(2), -0.5_dp)
2778 DO i_spin = 1, nspins
2779 CALL pw_copy(temp_embed_pot(i_spin), new_embed_pot(i_spin))
2780 CALL pw_axpy(v_w(1), new_embed_pot(i_spin), step_len)
2781 CALL pw_axpy(v_w_ref(i_spin), new_embed_pot(i_spin), -step_len)
2786 CALL pw_copy(embed_pot, prev_embed_pot)
2787 CALL pw_copy(spin_embed_pot, prev_spin_embed_pot)
2789 CALL pw_copy(new_embed_pot(1), embed_pot)
2790 CALL pw_axpy(new_embed_pot(2), embed_pot, 1.0_dp)
2792 CALL pw_copy(new_embed_pot(1), spin_embed_pot)
2793 CALL pw_axpy(new_embed_pot(2), spin_embed_pot, -1.0_dp)
2794 CALL pw_scale(spin_embed_pot, a=0.5_dp)
2796 DO i_spin = 1, nspins
2797 CALL temp_embed_pot(i_spin)%release()
2799 DEALLOCATE (temp_embed_pot)
2803 DO i_spin = 1, nspins
2804 CALL curr_rho(i_spin)%release()
2805 CALL new_embed_pot(i_spin)%release()
2806 CALL v_w(i_spin)%release()
2809 DEALLOCATE (new_embed_pot)
2811 DEALLOCATE (curr_rho)
2815 CALL timestop(handle)
2817 END SUBROUTINE fab_update
2827 SUBROUTINE von_weizsacker(rho_r, v_w, qs_env, vw_cutoff, vw_smooth_cutoff_range)
2831 REAL(kind=
dp),
INTENT(IN) :: vw_cutoff, vw_smooth_cutoff_range
2833 REAL(kind=
dp),
PARAMETER :: one_4 = 0.25_dp, one_8 = 0.125_dp
2835 INTEGER :: i, i_spin, j, k, nspins
2836 INTEGER,
DIMENSION(3) :: lb, ub
2837 REAL(kind=
dp) :: density_smooth_cut_range, my_rho, &
2839 REAL(kind=
dp),
DIMENSION(:, :, :),
POINTER :: rhoa, rhob
2848 rho_cutoff = epsilon(0.0_dp)
2850 nspins =
SIZE(rho_r)
2852 NULLIFY (xc_section)
2859 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
2863 ALLOCATE (rho_g(nspins))
2864 DO i_spin = 1, nspins
2865 CALL auxbas_pw_pool%create_pw(rho_g(i_spin))
2872 rho_r(1)%pw_grid%bounds_local, &
2879 IF (nspins .EQ. 2)
THEN
2880 needs%rho_spin = .true.
2881 needs%norm_drho_spin = .true.
2882 needs%laplace_rho_spin = .true.
2885 needs%norm_drho = .true.
2886 needs%laplace_rho = .true.
2897 r_val=density_smooth_cut_range)
2899 lb(1:3) = rho_r(1)%pw_grid%bounds_local(1, 1:3)
2900 ub(1:3) = rho_r(1)%pw_grid%bounds_local(2, 1:3)
2902 IF (nspins .EQ. 2)
THEN
2909 IF (rho_r(1)%array(i, j, k) .GT. rho_cutoff)
THEN
2910 my_rho = rho_r(1)%array(i, j, k)
2914 v_w(1)%array(i, j, k) = one_8*rho_set%norm_drhoa(i, j, k)**2/my_rho**2 - &
2915 one_4*rho_set%laplace_rhoa(i, j, k)/my_rho
2917 IF (rho_r(2)%array(i, j, k) .GT. rho_cutoff)
THEN
2918 my_rho = rho_r(2)%array(i, j, k)
2922 v_w(2)%array(i, j, k) = one_8*rho_set%norm_drhob(i, j, k)**2/my_rho**2 - &
2923 one_4*rho_set%laplace_rhob(i, j, k)/my_rho
2935 IF (rho_r(1)%array(i, j, k) .GT. rho_cutoff)
THEN
2936 my_rho = rho_r(1)%array(i, j, k)
2937 v_w(1)%array(i, j, k) = one_8*rho_set%norm_drho(i, j, k)**2/my_rho**2 - &
2938 one_4*rho_set%laplace_rho(i, j, k)/my_rho
2940 v_w(1)%array(i, j, k) = 0.0_dp
2950 IF (nspins == 2)
THEN
2951 density_smooth_cut_range = 0.5_dp*density_smooth_cut_range
2952 rho_cutoff = 0.5_dp*rho_cutoff
2954 DO i_spin = 1, nspins
2955 CALL smooth_cutoff(pot=v_w(i_spin)%array, rho=rho_r(i_spin)%array, rhoa=rhoa, rhob=rhob, &
2956 rho_cutoff=vw_cutoff, &
2957 rho_smooth_cutoff_range=vw_smooth_cutoff_range)
2962 DO i_spin = 1, nspins
2963 CALL rho_g(i_spin)%release()
2967 END SUBROUTINE von_weizsacker
2976 REAL(kind=
dp) :: total_max_diff
2978 INTEGER :: size_x, size_y, size_z
2979 REAL(kind=
dp) :: max_diff
2980 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: grid_3d
2985 size_x =
SIZE(diff_rho_r%array, 1)
2986 size_y =
SIZE(diff_rho_r%array, 2)
2987 size_z =
SIZE(diff_rho_r%array, 3)
2990 ALLOCATE (grid_3d(size_x, size_y, size_z))
2993 grid_3d(:, :, :) = diff_rho_r%array(:, :, :)
2996 max_diff = maxval(abs(grid_3d))
2997 total_max_diff = max_diff
2998 CALL diff_rho_r%pw_grid%para%group%max(total_max_diff)
3001 DEALLOCATE (grid_3d)
3015 INTEGER,
INTENT(IN) :: i_iter
3017 LOGICAL,
INTENT(IN) :: final_one
3019 CHARACTER(LEN=default_path_length) :: filename, my_pos_cube, title
3026 NULLIFY (subsys, input)
3036 "DFT%QS%OPT_EMBED%EMBED_DENS_DIFF"),
cp_p_file))
THEN
3037 my_pos_cube =
"REWIND"
3038 IF (.NOT. final_one)
THEN
3039 WRITE (filename,
'(a5,I3.3,a1,I1.1)')
"DIFF_", i_iter
3041 WRITE (filename,
'(a5,I3.3,a1,I1.1)')
"DIFF"
3044 extension=
".cube", middle_name=trim(filename), file_position=my_pos_cube, &
3045 log_filename=.false.)
3047 WRITE (title, *)
"EMBEDDING DENSITY DIFFERENCE ",
" optimization step ", i_iter
3048 CALL cp_pw_to_cube(diff_rho_r, unit_nr, title, particles=particles, &
3051 "DFT%QS%OPT_EMBED%EMBED_DENS_DIFF")
3066 INTEGER,
INTENT(IN) :: i_iter
3068 LOGICAL,
INTENT(IN) :: final_one
3070 CHARACTER(LEN=default_path_length) :: filename, my_pos_cube, title
3077 NULLIFY (subsys, input)
3087 "DFT%QS%OPT_EMBED%EMBED_DENS_DIFF"),
cp_p_file))
THEN
3088 my_pos_cube =
"REWIND"
3089 IF (.NOT. final_one)
THEN
3090 WRITE (filename,
'(a5,I3.3,a1,I1.1)')
"SPIN_DIFF_", i_iter
3092 WRITE (filename,
'(a9,I3.3,a1,I1.1)')
"SPIN_DIFF"
3095 extension=
".cube", middle_name=trim(filename), file_position=my_pos_cube, &
3096 log_filename=.false.)
3098 WRITE (title, *)
"EMBEDDING SPIN DENSITY DIFFERENCE ",
" optimization step ", i_iter
3099 CALL cp_pw_to_cube(spin_diff_rho_r, unit_nr, title, particles=particles, &
3102 "DFT%QS%OPT_EMBED%EMBED_DENS_DIFF")
3119 embed_pot_spin, open_shell_embed, grid_opt, final_one)
3121 INTEGER :: dimen_aux
3122 TYPE(
cp_fm_type),
INTENT(IN),
POINTER :: embed_pot_coef
3126 LOGICAL :: open_shell_embed, grid_opt, final_one
3128 CHARACTER(LEN=default_path_length) :: filename, my_pos_cube, title
3136 CALL get_qs_env(qs_env=qs_env, subsys=subsys, &
3140 IF (.NOT. grid_opt)
THEN
3143 "DFT%QS%OPT_EMBED%EMBED_POT_VECTOR"),
cp_p_file))
THEN
3144 IF (.NOT. final_one)
THEN
3145 WRITE (filename,
'(a10,I3.3)')
"embed_pot_", i_iter
3147 WRITE (filename,
'(a10,I3.3)')
"embed_pot"
3149 unit_nr =
cp_print_key_unit_nr(logger, input,
"DFT%QS%OPT_EMBED%EMBED_POT_VECTOR", extension=
".wfn", &
3150 file_form=
"UNFORMATTED", middle_name=trim(filename), file_position=
"REWIND")
3151 IF (unit_nr > 0)
THEN
3152 WRITE (unit_nr) dimen_aux
3155 IF (unit_nr > 0)
THEN
3167 "DFT%QS%OPT_EMBED%EMBED_POT_CUBE"),
cp_p_file))
THEN
3168 my_pos_cube =
"REWIND"
3169 IF (.NOT. final_one)
THEN
3170 WRITE (filename,
'(a10,I3.3)')
"embed_pot_", i_iter
3172 WRITE (filename,
'(a10,I3.3)')
"embed_pot"
3175 extension=
".cube", middle_name=trim(filename), file_position=my_pos_cube, &
3176 log_filename=.false.)
3178 WRITE (title, *)
"EMBEDDING POTENTIAL at optimization step ", i_iter
3179 CALL cp_pw_to_cube(embed_pot, unit_nr, title, particles=particles)
3183 "DFT%QS%OPT_EMBED%EMBED_POT_CUBE")
3184 IF (open_shell_embed)
THEN
3185 my_pos_cube =
"REWIND"
3186 IF (.NOT. final_one)
THEN
3187 WRITE (filename,
'(a15,I3.3)')
"spin_embed_pot_", i_iter
3189 WRITE (filename,
'(a15,I3.3)')
"spin_embed_pot"
3192 extension=
".cube", middle_name=trim(filename), file_position=my_pos_cube, &
3193 log_filename=.false.)
3195 WRITE (title, *)
"SPIN EMBEDDING POTENTIAL at optimization step ", i_iter
3196 CALL cp_pw_to_cube(embed_pot_spin, unit_nr, title, particles=particles)
3200 "DFT%QS%OPT_EMBED%EMBED_POT_CUBE")
3217 final_one, qs_env_cluster)
3222 LOGICAL :: open_shell_embed, final_one
3225 CHARACTER(LEN=default_path_length) :: filename
3226 INTEGER :: my_units, unit_nr
3227 LOGICAL :: angstrom, bohr
3235 CALL get_qs_env(qs_env=qs_env, input=input, pw_env=pw_env)
3243 "DFT%QS%OPT_EMBED%WRITE_SIMPLE_GRID"),
cp_p_file))
THEN
3249 SELECT CASE (my_units)
3263 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
3266 CALL auxbas_pw_pool%create_pw(pot_alpha)
3269 CALL pw_copy(embed_pot, pot_alpha)
3271 IF (open_shell_embed)
THEN
3272 CALL auxbas_pw_pool%create_pw(pot_beta)
3273 CALL pw_copy(embed_pot, pot_beta)
3275 CALL pw_axpy(embed_pot_spin, pot_alpha, 1.0_dp)
3276 CALL pw_axpy(embed_pot_spin, pot_beta, -1.0_dp)
3279 IF (.NOT. final_one)
THEN
3280 WRITE (filename,
'(a10,I3.3)')
"embed_pot_", i_iter
3282 WRITE (filename,
'(a10,I3.3)')
"embed_pot"
3284 unit_nr =
cp_print_key_unit_nr(logger, input,
"DFT%QS%OPT_EMBED%WRITE_SIMPLE_GRID", extension=
".dat", &
3285 middle_name=trim(filename), file_form=
"FORMATTED", file_position=
"REWIND")
3287 IF (open_shell_embed)
THEN
3289 stride=
section_get_ivals(dft_section,
"QS%OPT_EMBED%WRITE_SIMPLE_GRID%STRIDE"), &
3297 "DFT%QS%OPT_EMBED%WRITE_SIMPLE_GRID")
3299 CALL pot_alpha%release()
3300 IF (open_shell_embed)
THEN
3301 CALL pot_beta%release()
3308 CALL print_folded_coordinates(qs_env_cluster, input)
3317 SUBROUTINE print_folded_coordinates(qs_env, input)
3321 CHARACTER(LEN=2),
ALLOCATABLE,
DIMENSION(:) :: particles_el
3322 CHARACTER(LEN=default_path_length) :: filename
3323 INTEGER :: iat, n, unit_nr
3324 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: particles_r
3325 REAL(kind=
dp),
DIMENSION(3) :: center, r_pbc, s
3334 "DFT%QS%OPT_EMBED%WRITE_SIMPLE_GRID/FOLD_COORD"),
cp_p_file))
THEN
3335 CALL get_qs_env(qs_env=qs_env, cell=cell, subsys=subsys)
3339 WRITE (filename,
'(a14)')
"folded_cluster"
3341 "DFT%QS%OPT_EMBED%WRITE_SIMPLE_GRID/FOLD_COORD", extension=
".dat", &
3342 middle_name=trim(filename), file_form=
"FORMATTED", file_position=
"REWIND")
3343 IF (unit_nr > 0)
THEN
3346 ALLOCATE (particles_el(n))
3347 ALLOCATE (particles_r(3, n))
3349 CALL get_atomic_kind(particles%els(iat)%atomic_kind, element_symbol=particles_el(iat))
3350 particles_r(:, iat) = particles%els(iat)%r(:)
3354 center(:) = cell%hmat(:, 1)/2.0_dp + cell%hmat(:, 2)/2.0_dp + cell%hmat(:, 3)/2.0_dp
3357 DO iat = 1,
SIZE(particles_el)
3358 r_pbc(:) = particles_r(:, iat) - center
3359 s = matmul(cell%h_inv, r_pbc)
3361 r_pbc = matmul(cell%hmat, s)
3362 r_pbc = r_pbc + center
3363 WRITE (unit_nr,
'(a4,4f12.6)') particles_el(iat), r_pbc(:)
3367 "DFT%QS%OPT_EMBED%WRITE_SIMPLE_GRID/FOLD_COORD")
3369 DEALLOCATE (particles_el)
3370 DEALLOCATE (particles_r)
3375 END SUBROUTINE print_folded_coordinates
3384 INTEGER :: output_unit, step_num
3387 IF (output_unit > 0)
THEN
3388 WRITE (unit=output_unit, fmt=
"(/,T2,8('-'),A,I5,1X,12('-'))") &
3389 " Optimize embedding potential info at step = ", step_num
3390 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3391 " Functional value = ", opt_embed%w_func(step_num)
3392 IF (step_num .GT. 1)
THEN
3393 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3394 " Real energy change = ", opt_embed%w_func(step_num) - &
3395 opt_embed%w_func(step_num - 1)
3397 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3398 " Step size = ", opt_embed%step_len
3402 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3403 " Trust radius = ", opt_embed%trust_rad
3405 WRITE (unit=output_unit, fmt=
"(T2,51('-'))")
3419 INTEGER :: subsys_num
3421 INTEGER :: i_dens_start, i_spin, nspins
3425 NULLIFY (rho_r, rho)
3429 nspins = opt_embed%all_nspins(subsys_num)
3431 i_dens_start = sum(opt_embed%all_nspins(1:subsys_num)) - nspins + 1
3433 DO i_spin = 1, nspins
3434 opt_embed%prev_subsys_dens(i_dens_start + i_spin - 1)%array(:, :, :) = &
3435 rho_r(i_spin)%array(:, :, :)
3449 INTEGER :: subsys_num
3451 INTEGER :: i_dens_start, i_spin, nspins
3455 NULLIFY (rho_r, rho)
3459 nspins = opt_embed%all_nspins(subsys_num)
3461 i_dens_start = sum(opt_embed%all_nspins(1:subsys_num)) - nspins + 1
3463 DO i_spin = 1, nspins
3464 CALL pw_axpy(rho_r(i_spin), opt_embed%prev_subsys_dens(i_dens_start + i_spin - 1), 1.0_dp, -1.0_dp, &
3465 allow_noncompatible_grids=.true.)
3466 opt_embed%max_subsys_dens_diff(i_dens_start + i_spin - 1) = &
3467 max_dens_diff(opt_embed%prev_subsys_dens(i_dens_start + i_spin - 1))
3482 INTEGER :: output_unit
3484 INTEGER :: i_dens, i_dens_start, i_spin
3485 LOGICAL :: conv_int_diff, conv_max_diff
3486 REAL(kind=
dp) :: int_diff, int_diff_spin, &
3487 int_diff_square, int_diff_square_spin, &
3488 max_diff, max_diff_spin
3493 opt_embed%int_diff_square(1) =
pw_integral_ab(diff_rho_r, diff_rho_r)
3494 IF (opt_embed%open_shell_embed)
THEN
3497 opt_embed%int_diff_square(2) =
pw_integral_ab(diff_rho_spin, diff_rho_spin)
3501 max_diff = opt_embed%max_diff(1)
3505 IF (opt_embed%open_shell_embed)
THEN
3506 max_diff_spin = opt_embed%max_diff(2)
3507 IF ((max_diff .LE. opt_embed%conv_max) .AND. (max_diff_spin .LE. opt_embed%conv_max_spin))
THEN
3508 conv_max_diff = .true.
3510 conv_max_diff = .false.
3514 IF (max_diff .LE. opt_embed%conv_max)
THEN
3515 conv_max_diff = .true.
3517 conv_max_diff = .false.
3522 int_diff = opt_embed%int_diff(1)
3524 IF (opt_embed%open_shell_embed)
THEN
3525 int_diff_spin = opt_embed%int_diff(2)
3526 IF ((int_diff .LE. opt_embed%conv_int) .AND. (int_diff_spin .LE. opt_embed%conv_int_spin))
THEN
3527 conv_int_diff = .true.
3529 conv_int_diff = .false.
3533 IF (int_diff .LE. opt_embed%conv_int)
THEN
3534 conv_int_diff = .true.
3536 conv_int_diff = .false.
3541 int_diff_square = opt_embed%int_diff_square(1)
3543 IF (opt_embed%open_shell_embed) int_diff_square_spin = opt_embed%int_diff_square(2)
3545 IF ((conv_max_diff) .AND. (conv_int_diff))
THEN
3546 opt_embed%converged = .true.
3548 opt_embed%converged = .false.
3552 IF (output_unit > 0)
THEN
3553 WRITE (unit=output_unit, fmt=
"(/,T2,A)") &
3554 " Convergence check :"
3557 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3558 " Maximum density difference = ", max_diff
3559 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3560 " Convergence limit for max. density diff. = ", opt_embed%conv_max
3562 IF (opt_embed%open_shell_embed)
THEN
3564 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3565 " Maximum spin density difference = ", max_diff_spin
3566 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3567 " Convergence limit for max. spin dens.diff.= ", opt_embed%conv_max_spin
3571 IF (conv_max_diff)
THEN
3572 WRITE (unit=output_unit, fmt=
"(T2,2A)") &
3573 " Convergence in max. density diff. = ", &
3576 WRITE (unit=output_unit, fmt=
"(T2,2A)") &
3577 " Convergence in max. density diff. = ", &
3582 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3583 " Integrated density difference = ", int_diff
3584 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3585 " Conv. limit for integrated density diff. = ", opt_embed%conv_int
3586 IF (opt_embed%open_shell_embed)
THEN
3587 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3588 " Integrated spin density difference = ", int_diff_spin
3589 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3590 " Conv. limit for integrated spin dens.diff.= ", opt_embed%conv_int_spin
3593 IF (conv_int_diff)
THEN
3594 WRITE (unit=output_unit, fmt=
"(T2,2A)") &
3595 " Convergence in integrated density diff. = ", &
3598 WRITE (unit=output_unit, fmt=
"(T2,2A)") &
3599 " Convergence in integrated density diff. = ", &
3604 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3605 " Integrated squared density difference = ", int_diff_square
3606 IF (opt_embed%open_shell_embed)
THEN
3607 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3608 " Integrated squared spin density difference= ", int_diff_square_spin
3612 WRITE (unit=output_unit, fmt=
"(/,T2,A)") &
3613 " Maximum density change in:"
3614 DO i_dens = 1, (
SIZE(opt_embed%all_nspins) - 1)
3615 i_dens_start = sum(opt_embed%all_nspins(1:i_dens)) - opt_embed%all_nspins(i_dens) + 1
3616 DO i_spin = 1, opt_embed%all_nspins(i_dens)
3617 WRITE (unit=output_unit, fmt=
"(T4,A10,I3,A6,I3,A1,F20.10)") &
3618 " subsystem ", i_dens,
', spin', i_spin,
":", &
3619 opt_embed%max_subsys_dens_diff(i_dens_start + i_spin - 1)
3625 IF ((opt_embed%converged) .AND. (output_unit > 0))
THEN
3626 WRITE (unit=output_unit, fmt=
"(/,T2,A)") repeat(
"*", 79)
3627 WRITE (unit=output_unit, fmt=
"(T2,A,T25,A,T78,A)") &
3628 "***",
"EMBEDDING POTENTIAL OPTIMIZATION COMPLETED",
"***"
3629 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, use_sp)
creates a new full matrix with the given structure
various routines to log and control the output. The idea is that decisions about where to log should ...
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_pw_to_cube(pw, unit_nr, title, particles, stride, zero_tails, silent, mpi_io)
...
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.
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, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs)
Get the QUICKSTEP environment.
subroutine, public set_qs_env(qs_env, super_cell, mos, qmmm, qmmm_periodic, 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, 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)
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, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, init_u_ramping_each_scf, reltmat, ghost, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
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, 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_update(rho_set, rho_r, rho_g, tau, needs, xc_deriv_method_id, xc_rho_smooth_id, pw_pool)
updates the given rho set with the density given by rho_r (and rho_g). The rho set will contain the c...
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
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