42 USE dbcsr_api,
ONLY: dbcsr_p_type
66 pw_axpy, pw_copy,
pw_derive,
pw_dr2, pw_integral_ab, pw_integrate_function, pw_scale, &
97 #include "./base/base_uses.f90"
103 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'optimize_embedding_potential'
128 TYPE(force_env_type),
POINTER :: force_env
129 INTEGER :: ref_subsys_number
130 LOGICAL :: change_spin, open_shell_embed
131 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: all_nspins
133 INTEGER :: i_force_eval, nspins, sub_spin_1, &
134 sub_spin_2, total_spin
135 INTEGER,
DIMENSION(2) :: nelectron_spin
136 INTEGER,
DIMENSION(2, 3) :: all_spins
137 TYPE(dft_control_type),
POINTER :: dft_control
139 change_spin = .false.
140 open_shell_embed = .false.
141 ALLOCATE (all_nspins(ref_subsys_number))
142 IF (ref_subsys_number .EQ. 3)
THEN
144 DO i_force_eval = 1, ref_subsys_number
145 CALL get_qs_env(qs_env=force_env%sub_force_env(i_force_eval)%force_env%qs_env, &
146 nelectron_spin=nelectron_spin, dft_control=dft_control)
147 all_spins(:, i_force_eval) = nelectron_spin
148 nspins = dft_control%nspins
149 all_nspins(i_force_eval) = nspins
153 IF (.NOT. ((all_nspins(1) .EQ. 1) .AND. (all_nspins(2) .EQ. 1) .AND. (all_nspins(3) .EQ. 1))) &
154 open_shell_embed = .true.
157 IF (open_shell_embed)
THEN
159 IF (all_nspins(3) .EQ. 1)
THEN
162 total_spin = all_spins(1, 3) - all_spins(2, 3)
164 IF (all_nspins(1) .EQ. 1)
THEN
167 sub_spin_1 = all_spins(1, 1) - all_spins(2, 1)
169 IF (all_nspins(2) .EQ. 1)
THEN
172 sub_spin_2 = all_spins(1, 2) - all_spins(2, 2)
174 IF ((sub_spin_1 + sub_spin_2) .EQ. total_spin)
THEN
175 change_spin = .false.
177 IF (abs(sub_spin_1 - sub_spin_2) .EQ. total_spin)
THEN
180 cpabort(
"Spin states of subsystems are not compatible.")
186 cpabort(
"Reference subsystem must be the third FORCE_EVAL.")
204 SUBROUTINE init_embed_pot(qs_env, embed_pot, add_const_pot, Fermi_Amaldi, const_pot, open_shell_embed, &
205 spin_embed_pot, pot_diff, Coulomb_guess, grid_opt)
206 TYPE(qs_environment_type),
POINTER :: qs_env
207 TYPE(pw_r3d_rs_type),
POINTER :: embed_pot
208 LOGICAL :: add_const_pot, fermi_amaldi
209 TYPE(pw_r3d_rs_type),
POINTER :: const_pot
210 LOGICAL :: open_shell_embed
211 TYPE(pw_r3d_rs_type),
POINTER :: spin_embed_pot, pot_diff
214 INTEGER :: nelectrons
215 INTEGER,
DIMENSION(2) :: nelectron_spin
216 REAL(kind=
dp) :: factor
217 TYPE(pw_env_type),
POINTER :: pw_env
218 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
219 TYPE(pw_r3d_rs_type),
POINTER :: v_hartree_r_space
222 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env, &
223 nelectron_spin=nelectron_spin, &
224 v_hartree_rspace=v_hartree_r_space)
227 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
232 CALL auxbas_pw_pool%create_pw(embed_pot)
233 CALL pw_zero(embed_pot)
236 IF (open_shell_embed)
THEN
237 NULLIFY (spin_embed_pot)
238 ALLOCATE (spin_embed_pot)
239 CALL auxbas_pw_pool%create_pw(spin_embed_pot)
240 CALL pw_zero(spin_embed_pot)
247 CALL auxbas_pw_pool%create_pw(pot_diff)
248 CALL pw_zero(pot_diff)
252 IF (add_const_pot .AND. (.NOT. grid_opt))
THEN
256 CALL auxbas_pw_pool%create_pw(const_pot)
257 CALL pw_zero(const_pot)
261 IF (fermi_amaldi)
THEN
264 NULLIFY (v_hartree_r_space)
265 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env, &
266 v_hartree_rspace=v_hartree_r_space)
267 CALL pw_copy(v_hartree_r_space, embed_pot)
270 nelectrons = nelectron_spin(1) + nelectron_spin(2)
271 factor = (real(nelectrons,
dp) - 1.0_dp)/(real(nelectrons,
dp))
274 CALL pw_scale(embed_pot, a=factor)
277 IF (.NOT. grid_opt)
CALL pw_copy(embed_pot, embed_pot)
291 TYPE(qs_environment_type),
POINTER :: qs_env
292 TYPE(opt_embed_pot_type) :: opt_embed
293 TYPE(section_vals_type),
POINTER :: opt_embed_section
295 INTEGER :: diff_size, i_dens, size_prev_dens
296 TYPE(cp_blacs_env_type),
POINTER :: blacs_env
297 TYPE(cp_fm_struct_type),
POINTER :: fm_struct
298 TYPE(mp_para_env_type),
POINTER :: para_env
299 TYPE(pw_env_type),
POINTER :: pw_env
300 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
307 CALL read_opt_embed_section(opt_embed, opt_embed_section)
310 IF (.NOT. opt_embed%grid_opt)
THEN
321 CALL make_lri_object(qs_env, opt_embed%lri)
325 IF (opt_embed%open_shell_embed)
THEN
326 opt_embed%dimen_var_aux = 2*opt_embed%dimen_aux
328 opt_embed%dimen_var_aux = opt_embed%dimen_aux
332 NULLIFY (opt_embed%embed_pot_grad, opt_embed%embed_pot_coef, opt_embed%step, fm_struct)
334 NULLIFY (opt_embed%prev_embed_pot_grad, opt_embed%prev_embed_pot_coef, opt_embed%prev_step)
336 nrow_global=opt_embed%dimen_var_aux, ncol_global=1)
337 ALLOCATE (opt_embed%embed_pot_grad, opt_embed%embed_pot_coef, &
338 opt_embed%prev_embed_pot_grad, opt_embed%prev_embed_pot_coef, &
339 opt_embed%step, opt_embed%prev_step)
340 CALL cp_fm_create(opt_embed%embed_pot_grad, fm_struct, name=
"pot_grad")
341 CALL cp_fm_create(opt_embed%embed_pot_coef, fm_struct, name=
"pot_coef")
342 CALL cp_fm_create(opt_embed%prev_embed_pot_grad, fm_struct, name=
"prev_pot_grad")
343 CALL cp_fm_create(opt_embed%prev_embed_pot_coef, fm_struct, name=
"prev_pot_coef")
344 CALL cp_fm_create(opt_embed%step, fm_struct, name=
"step")
345 CALL cp_fm_create(opt_embed%prev_step, fm_struct, name=
"prev_step")
357 NULLIFY (opt_embed%embed_pot_hess, opt_embed%prev_embed_pot_hess, fm_struct)
359 nrow_global=opt_embed%dimen_var_aux, ncol_global=opt_embed%dimen_var_aux)
360 ALLOCATE (opt_embed%embed_pot_hess, opt_embed%prev_embed_pot_hess)
361 CALL cp_fm_create(opt_embed%embed_pot_hess, fm_struct, name=
"pot_Hess")
362 CALL cp_fm_create(opt_embed%prev_embed_pot_hess, fm_struct, name=
"prev_pot_Hess")
366 NULLIFY (fm_struct, opt_embed%kinetic_mat)
368 nrow_global=opt_embed%dimen_aux, ncol_global=opt_embed%dimen_aux)
369 ALLOCATE (opt_embed%kinetic_mat)
370 CALL cp_fm_create(opt_embed%kinetic_mat, fm_struct, name=
"kinetic_mat")
375 CALL cp_fm_set_all(opt_embed%embed_pot_hess, 0.0_dp, -1.0_dp)
376 CALL cp_fm_set_all(opt_embed%prev_embed_pot_hess, 0.0_dp, -1.0_dp)
384 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
385 NULLIFY (opt_embed%prev_subsys_dens)
386 size_prev_dens = sum(opt_embed%all_nspins(1:(
SIZE(opt_embed%all_nspins) - 1)))
387 ALLOCATE (opt_embed%prev_subsys_dens(size_prev_dens))
388 DO i_dens = 1, size_prev_dens
389 CALL auxbas_pw_pool%create_pw(opt_embed%prev_subsys_dens(i_dens))
390 CALL pw_zero(opt_embed%prev_subsys_dens(i_dens))
392 ALLOCATE (opt_embed%max_subsys_dens_diff(size_prev_dens))
395 ALLOCATE (opt_embed%w_func(opt_embed%n_iter))
396 opt_embed%w_func = 0.0_dp
400 IF (opt_embed%open_shell_embed) diff_size = 2
401 ALLOCATE (opt_embed%max_diff(diff_size))
402 ALLOCATE (opt_embed%int_diff(diff_size))
403 ALLOCATE (opt_embed%int_diff_square(diff_size))
406 IF (opt_embed%fab)
THEN
407 NULLIFY (opt_embed%prev_embed_pot)
408 ALLOCATE (opt_embed%prev_embed_pot)
409 CALL auxbas_pw_pool%create_pw(opt_embed%prev_embed_pot)
410 CALL pw_zero(opt_embed%prev_embed_pot)
411 IF (opt_embed%open_shell_embed)
THEN
412 NULLIFY (opt_embed%prev_spin_embed_pot)
413 ALLOCATE (opt_embed%prev_spin_embed_pot)
414 CALL auxbas_pw_pool%create_pw(opt_embed%prev_spin_embed_pot)
415 CALL pw_zero(opt_embed%prev_spin_embed_pot)
420 opt_embed%allowed_decrease = 0.0001_dp
423 opt_embed%reg_term = 0.0_dp
426 opt_embed%accept_step = .true.
427 opt_embed%newton_step = .false.
428 opt_embed%last_accepted = 1
431 opt_embed%max_trad = opt_embed%trust_rad*7.900_dp
432 opt_embed%min_trad = opt_embed%trust_rad*0.125*0.065_dp
441 SUBROUTINE read_opt_embed_section(opt_embed, opt_embed_section)
442 TYPE(opt_embed_pot_type) :: opt_embed
443 TYPE(section_vals_type),
POINTER :: opt_embed_section
445 INTEGER :: embed_guess, embed_optimizer
449 r_val=opt_embed%lambda)
452 i_val=opt_embed%n_iter)
455 r_val=opt_embed%trust_rad)
458 r_val=opt_embed%conv_max)
461 r_val=opt_embed%conv_int)
464 r_val=opt_embed%conv_max_spin)
467 r_val=opt_embed%conv_int_spin)
473 l_val=opt_embed%read_embed_pot)
476 l_val=opt_embed%read_embed_pot_cube)
479 l_val=opt_embed%grid_opt)
482 l_val=opt_embed%leeuwen)
488 r_val=opt_embed%vw_cutoff)
491 r_val=opt_embed%vw_smooth_cutoff_range)
494 SELECT CASE (embed_optimizer)
496 opt_embed%steep_desc = .true.
498 opt_embed%steep_desc = .false.
499 opt_embed%level_shift = .false.
501 opt_embed%steep_desc = .false.
502 opt_embed%level_shift = .true.
504 opt_embed%steep_desc = .true.
508 SELECT CASE (embed_guess)
510 opt_embed%add_const_pot = .false.
511 opt_embed%Fermi_Amaldi = .false.
512 opt_embed%Coulomb_guess = .false.
513 opt_embed%diff_guess = .false.
515 opt_embed%add_const_pot = .true.
516 opt_embed%Fermi_Amaldi = .false.
517 opt_embed%Coulomb_guess = .false.
518 opt_embed%diff_guess = .true.
520 opt_embed%add_const_pot = .true.
521 opt_embed%Fermi_Amaldi = .true.
522 opt_embed%Coulomb_guess = .false.
523 opt_embed%diff_guess = .false.
525 opt_embed%add_const_pot = .true.
526 opt_embed%Fermi_Amaldi = .true.
527 opt_embed%Coulomb_guess = .true.
528 opt_embed%diff_guess = .false.
530 opt_embed%add_const_pot = .false.
531 opt_embed%Fermi_Amaldi = .false.
532 opt_embed%Coulomb_guess = .false.
533 opt_embed%diff_guess = .false.
536 END SUBROUTINE read_opt_embed_section
544 TYPE(qs_environment_type),
POINTER :: qs_env
547 INTEGER :: iatom, ikind, nsgf
548 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: kind_of
549 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
550 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
551 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
555 particle_set=particle_set, &
556 qs_kind_set=qs_kind_set, &
557 atomic_kind_set=atomic_kind_set)
562 DO iatom = 1,
SIZE(particle_set)
563 ikind = kind_of(iatom)
564 CALL get_qs_kind(qs_kind=qs_kind_set(ikind), nsgf=nsgf, basis_type=
"RI_AUX")
565 dimen_aux = dimen_aux + nsgf
575 SUBROUTINE make_lri_object(qs_env, lri)
576 TYPE(qs_environment_type),
POINTER :: qs_env
577 TYPE(lri_kind_type),
DIMENSION(:),
POINTER :: lri
579 INTEGER :: ikind, natom, nkind, nsgf
580 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
581 TYPE(atomic_kind_type),
POINTER :: atomic_kind
582 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
584 NULLIFY (atomic_kind, lri)
585 CALL get_qs_env(qs_env=qs_env, atomic_kind_set=atomic_kind_set, &
586 qs_kind_set=qs_kind_set)
587 nkind =
SIZE(atomic_kind_set)
589 ALLOCATE (lri(nkind))
592 NULLIFY (lri(ikind)%acoef)
593 NULLIFY (lri(ikind)%v_int)
594 atomic_kind => atomic_kind_set(ikind)
596 CALL get_qs_kind(qs_kind=qs_kind_set(ikind), nsgf=nsgf, basis_type=
"RI_AUX")
597 ALLOCATE (lri(ikind)%acoef(natom, nsgf))
598 lri(ikind)%acoef = 0._dp
599 ALLOCATE (lri(ikind)%v_int(natom, nsgf))
600 lri(ikind)%v_int = 0._dp
603 END SUBROUTINE make_lri_object
610 TYPE(qs_environment_type),
POINTER :: qs_env
612 LOGICAL :: open_shell_embed
613 TYPE(dft_control_type),
POINTER :: dft_control
614 TYPE(pw_env_type),
POINTER :: pw_env
615 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool_subsys
616 TYPE(pw_r3d_rs_type),
POINTER :: embed_pot, spin_embed_pot
617 TYPE(section_vals_type),
POINTER :: input, qs_section
619 qs_env%given_embed_pot = .true.
620 NULLIFY (input, dft_control, embed_pot, spin_embed_pot, embed_pot, spin_embed_pot, &
624 dft_control=dft_control, &
627 open_shell_embed = .false.
628 IF (dft_control%nspins .EQ. 2) open_shell_embed = .true.
631 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool_subsys)
637 CALL auxbas_pw_pool_subsys%create_pw(embed_pot)
638 IF (open_shell_embed)
THEN
640 ALLOCATE (spin_embed_pot)
641 CALL auxbas_pw_pool_subsys%create_pw(spin_embed_pot)
644 CALL read_embed_pot_cube(embed_pot, spin_embed_pot, qs_section, open_shell_embed)
646 IF (.NOT. open_shell_embed)
THEN
647 CALL set_qs_env(qs_env=qs_env, embed_pot=embed_pot)
649 CALL set_qs_env(qs_env=qs_env, embed_pot=embed_pot, spin_embed_pot=spin_embed_pot)
663 TYPE(qs_environment_type),
POINTER :: qs_env
664 TYPE(pw_r3d_rs_type),
POINTER :: embed_pot, spin_embed_pot
665 TYPE(section_vals_type),
POINTER :: section
666 TYPE(opt_embed_pot_type) :: opt_embed
669 IF (opt_embed%read_embed_pot) &
670 CALL read_embed_pot_vector(qs_env, embed_pot, spin_embed_pot, section, &
671 opt_embed%embed_pot_coef, opt_embed%open_shell_embed)
673 IF (opt_embed%read_embed_pot_cube) &
674 CALL read_embed_pot_cube(embed_pot, spin_embed_pot, section, opt_embed%open_shell_embed)
685 SUBROUTINE read_embed_pot_cube(embed_pot, spin_embed_pot, section, open_shell_embed)
686 TYPE(pw_r3d_rs_type),
INTENT(IN) :: embed_pot, spin_embed_pot
687 TYPE(section_vals_type),
POINTER :: section
688 LOGICAL :: open_shell_embed
690 CHARACTER(LEN=default_path_length) :: filename
692 REAL(kind=
dp) :: scaling_factor
696 INQUIRE (file=filename, exist=exist)
698 cpabort(
"Embedding cube file not found. ")
700 scaling_factor = 1.0_dp
704 IF (open_shell_embed)
THEN
707 INQUIRE (file=filename, exist=exist)
709 cpabort(
"Embedding spin cube file not found. ")
711 scaling_factor = 1.0_dp
715 END SUBROUTINE read_embed_pot_cube
726 SUBROUTINE read_embed_pot_vector(qs_env, embed_pot, spin_embed_pot, section, embed_pot_coef, open_shell_embed)
727 TYPE(qs_environment_type),
POINTER :: qs_env
728 TYPE(pw_r3d_rs_type),
INTENT(INOUT) :: embed_pot
729 TYPE(pw_r3d_rs_type),
INTENT(IN),
POINTER :: spin_embed_pot
730 TYPE(section_vals_type),
POINTER :: section
731 TYPE(cp_fm_type),
INTENT(IN) :: embed_pot_coef
732 LOGICAL,
INTENT(IN) :: open_shell_embed
734 CHARACTER(LEN=default_path_length) :: filename
735 INTEGER :: dimen_aux, dimen_restart_basis, &
736 dimen_var_aux, l_global, lll, &
737 nrow_local, restart_unit
738 INTEGER,
DIMENSION(:),
POINTER :: row_indices
739 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: coef, coef_read
740 TYPE(cp_blacs_env_type),
POINTER :: blacs_env
741 TYPE(cp_fm_struct_type),
POINTER :: fm_struct
742 TYPE(cp_fm_type) :: my_embed_pot_coef
743 TYPE(mp_para_env_type),
POINTER :: para_env
747 IF (open_shell_embed)
THEN
748 dimen_var_aux = dimen_aux*2
750 dimen_var_aux = dimen_aux
760 nrow_global=dimen_var_aux, ncol_global=1)
761 CALL cp_fm_create(my_embed_pot_coef, fm_struct, name=
"my_pot_coef")
770 ALLOCATE (coef(dimen_var_aux))
773 IF (para_env%is_source())
THEN
776 CALL embed_restart_file_name(filename, section)
779 file_action=
"READ", &
780 file_form=
"UNFORMATTED", &
782 unit_number=restart_unit)
784 READ (restart_unit) dimen_restart_basis
786 IF (.NOT. (dimen_restart_basis == dimen_aux)) &
787 cpabort(
"Wrong dimension of the embedding basis in the restart file.")
789 ALLOCATE (coef_read(dimen_var_aux))
792 READ (restart_unit) coef_read
793 coef(:) = coef_read(:)
794 DEALLOCATE (coef_read)
802 CALL para_env%bcast(coef)
807 nrow_local=nrow_local, &
808 row_indices=row_indices)
810 DO lll = 1, nrow_local
811 l_global = row_indices(lll)
812 my_embed_pot_coef%local_data(lll, 1) = coef(l_global)
821 CALL update_embed_pot(embed_pot_coef, dimen_aux, embed_pot, spin_embed_pot, &
822 qs_env, .false., open_shell_embed)
825 CALL cp_fm_release(my_embed_pot_coef)
830 END SUBROUTINE read_embed_pot_vector
837 SUBROUTINE embed_restart_file_name(filename, section)
838 CHARACTER(LEN=default_path_length),
INTENT(OUT) :: filename
839 TYPE(section_vals_type),
POINTER :: section
845 INQUIRE (file=filename, exist=exist)
847 cpabort(
"Embedding restart file not found. ")
849 END SUBROUTINE embed_restart_file_name
856 TYPE(opt_embed_pot_type) :: opt_embed
858 INTEGER :: i_dens, i_spin, ikind
860 IF (.NOT. opt_embed%grid_opt)
THEN
861 CALL cp_fm_release(opt_embed%embed_pot_grad)
862 CALL cp_fm_release(opt_embed%embed_pot_coef)
863 CALL cp_fm_release(opt_embed%step)
864 CALL cp_fm_release(opt_embed%prev_step)
865 CALL cp_fm_release(opt_embed%embed_pot_hess)
866 CALL cp_fm_release(opt_embed%prev_embed_pot_grad)
867 CALL cp_fm_release(opt_embed%prev_embed_pot_coef)
868 CALL cp_fm_release(opt_embed%prev_embed_pot_hess)
869 CALL cp_fm_release(opt_embed%kinetic_mat)
870 DEALLOCATE (opt_embed%embed_pot_grad, opt_embed%embed_pot_coef, &
871 opt_embed%step, opt_embed%prev_step, opt_embed%embed_pot_hess, &
872 opt_embed%prev_embed_pot_grad, opt_embed%prev_embed_pot_coef, &
873 opt_embed%prev_embed_pot_hess, opt_embed%kinetic_mat)
874 DEALLOCATE (opt_embed%w_func)
875 DEALLOCATE (opt_embed%max_diff)
876 DEALLOCATE (opt_embed%int_diff)
878 DO ikind = 1,
SIZE(opt_embed%lri)
879 DEALLOCATE (opt_embed%lri(ikind)%v_int)
880 DEALLOCATE (opt_embed%lri(ikind)%acoef)
882 DEALLOCATE (opt_embed%lri)
885 IF (
ASSOCIATED(opt_embed%prev_subsys_dens))
THEN
886 DO i_dens = 1,
SIZE(opt_embed%prev_subsys_dens)
887 CALL opt_embed%prev_subsys_dens(i_dens)%release()
889 DEALLOCATE (opt_embed%prev_subsys_dens)
891 DEALLOCATE (opt_embed%max_subsys_dens_diff)
893 DEALLOCATE (opt_embed%all_nspins)
895 IF (
ASSOCIATED(opt_embed%const_pot))
THEN
896 CALL opt_embed%const_pot%release()
897 DEALLOCATE (opt_embed%const_pot)
900 IF (
ASSOCIATED(opt_embed%pot_diff))
THEN
901 CALL opt_embed%pot_diff%release()
902 DEALLOCATE (opt_embed%pot_diff)
905 IF (
ASSOCIATED(opt_embed%prev_embed_pot))
THEN
906 CALL opt_embed%prev_embed_pot%release()
907 DEALLOCATE (opt_embed%prev_embed_pot)
909 IF (
ASSOCIATED(opt_embed%prev_spin_embed_pot))
THEN
910 CALL opt_embed%prev_spin_embed_pot%release()
911 DEALLOCATE (opt_embed%prev_spin_embed_pot)
913 IF (
ASSOCIATED(opt_embed%v_w))
THEN
914 DO i_spin = 1,
SIZE(opt_embed%v_w)
915 CALL opt_embed%v_w(i_spin)%release()
917 DEALLOCATE (opt_embed%v_w)
932 SUBROUTINE coulomb_guess(v_rspace, rhs, mapping_section, qs_env, nforce_eval, iforce_eval, eta)
933 TYPE(pw_r3d_rs_type) :: v_rspace
934 REAL(kind=
dp),
DIMENSION(:),
POINTER :: rhs
935 TYPE(section_vals_type),
POINTER :: mapping_section
936 TYPE(qs_environment_type),
POINTER :: qs_env
937 INTEGER :: nforce_eval, iforce_eval
940 INTEGER :: iparticle, jparticle, natom
941 INTEGER,
DIMENSION(:),
POINTER :: map_index
942 REAL(kind=
dp) :: dvol, normalize_factor
943 REAL(kind=
dp),
DIMENSION(:),
POINTER :: rhs_subsys
944 TYPE(particle_list_type),
POINTER :: particles
945 TYPE(pw_c1d_gs_type) :: v_resp_gspace
946 TYPE(pw_env_type),
POINTER :: pw_env
947 TYPE(pw_poisson_type),
POINTER :: poisson_env
948 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
949 TYPE(pw_r3d_rs_type) :: rho_resp, v_resp_rspace
950 TYPE(qs_subsys_type),
POINTER :: subsys
954 CALL get_qs_env(qs_env=qs_env, subsys=subsys, pw_env=pw_env)
956 natom = particles%n_els
958 ALLOCATE (rhs_subsys(natom))
965 DO iparticle = 1, natom
966 jparticle = map_index(iparticle)
967 rhs_subsys(iparticle) = rhs(jparticle)
971 NULLIFY (auxbas_pw_pool)
973 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
974 poisson_env=poisson_env)
976 CALL auxbas_pw_pool%create_pw(v_resp_gspace)
978 CALL auxbas_pw_pool%create_pw(v_resp_rspace)
980 CALL auxbas_pw_pool%create_pw(rho_resp)
983 CALL pw_zero(rho_resp)
984 CALL calculate_rho_resp_all(rho_resp, rhs_subsys, natom, eta, qs_env)
987 CALL pw_poisson_solve(poisson_env, rho_resp, &
988 vhartree=v_resp_rspace)
989 dvol = v_resp_rspace%pw_grid%dvol
990 CALL pw_scale(v_resp_rspace, dvol)
991 normalize_factor = sqrt((eta/
pi)**3)
993 CALL pw_scale(v_resp_rspace, normalize_factor)
996 CALL pw_copy(v_resp_rspace, v_rspace)
999 CALL v_resp_gspace%release()
1000 CALL v_resp_rspace%release()
1001 CALL rho_resp%release()
1004 DEALLOCATE (map_index)
1006 DEALLOCATE (rhs_subsys)
1022 spin_embed_pot, spin_embed_pot_subsys, open_shell_embed, &
1024 TYPE(qs_environment_type),
POINTER :: qs_env
1025 TYPE(pw_r3d_rs_type),
INTENT(IN) :: embed_pot
1026 TYPE(pw_r3d_rs_type),
POINTER :: embed_pot_subsys
1027 TYPE(pw_r3d_rs_type),
INTENT(IN),
POINTER :: spin_embed_pot
1028 TYPE(pw_r3d_rs_type),
POINTER :: spin_embed_pot_subsys
1029 LOGICAL :: open_shell_embed, change_spin_sign
1031 TYPE(pw_env_type),
POINTER :: pw_env
1032 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool_subsys
1038 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool_subsys)
1041 NULLIFY (embed_pot_subsys)
1042 ALLOCATE (embed_pot_subsys)
1043 CALL auxbas_pw_pool_subsys%create_pw(embed_pot_subsys)
1046 CALL pw_copy(embed_pot, embed_pot_subsys)
1048 IF (open_shell_embed)
THEN
1049 NULLIFY (spin_embed_pot_subsys)
1050 ALLOCATE (spin_embed_pot_subsys)
1051 CALL auxbas_pw_pool_subsys%create_pw(spin_embed_pot_subsys)
1053 IF (change_spin_sign)
THEN
1054 CALL pw_axpy(spin_embed_pot, spin_embed_pot_subsys, -1.0_dp, 0.0_dp, allow_noncompatible_grids=.true.)
1056 CALL pw_copy(spin_embed_pot, spin_embed_pot_subsys)
1072 TYPE(qs_environment_type),
POINTER :: qs_env
1073 TYPE(pw_r3d_rs_type),
INTENT(IN) :: diff_rho_r, diff_rho_spin
1074 TYPE(opt_embed_pot_type) :: opt_embed
1076 CHARACTER(LEN=*),
PARAMETER :: routinen =
'calculate_embed_pot_grad'
1079 TYPE(cp_blacs_env_type),
POINTER :: blacs_env
1080 TYPE(cp_fm_struct_type),
POINTER :: fm_struct
1081 TYPE(cp_fm_type) :: embed_pot_coeff_spin, &
1082 embed_pot_coeff_spinless, &
1083 regular_term, spin_reg, spinless_reg
1084 TYPE(mp_para_env_type),
POINTER :: para_env
1085 TYPE(pw_env_type),
POINTER :: pw_env
1086 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
1088 CALL timeset(routinen, handle)
1092 CALL cp_fm_to_fm(opt_embed%embed_pot_grad, opt_embed%prev_embed_pot_grad)
1093 CALL cp_fm_to_fm(opt_embed%embed_pot_Hess, opt_embed%prev_embed_pot_Hess)
1097 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env, para_env=para_env)
1100 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
1103 CALL calculate_embed_pot_grad_inner(qs_env, opt_embed%dimen_aux, diff_rho_r, diff_rho_spin, &
1104 opt_embed%embed_pot_grad, &
1105 opt_embed%open_shell_embed, opt_embed%lri)
1108 IF (opt_embed%i_iter .EQ. 1)
THEN
1109 CALL compute_kinetic_mat(qs_env, opt_embed%kinetic_mat)
1113 matrix_struct=fm_struct)
1114 CALL cp_fm_create(regular_term, fm_struct, name=
"regular_term")
1119 IF (opt_embed%open_shell_embed)
THEN
1121 NULLIFY (fm_struct, blacs_env)
1125 CALL cp_fm_get_info(matrix=opt_embed%embed_pot_coef, context=blacs_env)
1127 nrow_global=opt_embed%dimen_aux, ncol_global=1)
1128 CALL cp_fm_create(embed_pot_coeff_spinless, fm_struct, name=
"pot_coeff_spinless")
1129 CALL cp_fm_create(embed_pot_coeff_spin, fm_struct, name=
"pot_coeff_spin")
1130 CALL cp_fm_create(spinless_reg, fm_struct, name=
"spinless_reg")
1131 CALL cp_fm_create(spin_reg, fm_struct, name=
"spin_reg")
1140 mtarget=embed_pot_coeff_spinless, &
1141 nrow=opt_embed%dimen_aux, ncol=1, &
1142 s_firstrow=1, s_firstcol=1, &
1143 t_firstrow=1, t_firstcol=1)
1145 mtarget=embed_pot_coeff_spin, &
1146 nrow=opt_embed%dimen_aux, ncol=1, &
1147 s_firstrow=opt_embed%dimen_aux + 1, s_firstcol=1, &
1148 t_firstrow=1, t_firstcol=1)
1150 CALL parallel_gemm(transa=
"N", transb=
"N", m=opt_embed%dimen_aux, n=1, &
1151 k=opt_embed%dimen_aux, alpha=1.0_dp, &
1152 matrix_a=opt_embed%kinetic_mat, matrix_b=embed_pot_coeff_spinless, &
1153 beta=0.0_dp, matrix_c=spinless_reg)
1154 CALL parallel_gemm(transa=
"N", transb=
"N", m=opt_embed%dimen_aux, n=1, &
1155 k=opt_embed%dimen_aux, alpha=1.0_dp, &
1156 matrix_a=opt_embed%kinetic_mat, matrix_b=embed_pot_coeff_spin, &
1157 beta=0.0_dp, matrix_c=spin_reg)
1160 mtarget=regular_term, &
1161 nrow=opt_embed%dimen_aux, ncol=1, &
1162 s_firstrow=1, s_firstcol=1, &
1163 t_firstrow=1, t_firstcol=1)
1165 mtarget=regular_term, &
1166 nrow=opt_embed%dimen_aux, ncol=1, &
1167 s_firstrow=1, s_firstcol=1, &
1168 t_firstrow=opt_embed%dimen_aux + 1, t_firstcol=1)
1170 CALL cp_fm_release(embed_pot_coeff_spinless)
1171 CALL cp_fm_release(embed_pot_coeff_spin)
1172 CALL cp_fm_release(spin_reg)
1173 CALL cp_fm_release(spinless_reg)
1176 CALL parallel_gemm(transa=
"N", transb=
"N", m=opt_embed%dimen_var_aux, n=1, &
1177 k=opt_embed%dimen_var_aux, alpha=1.0_dp, &
1178 matrix_a=opt_embed%kinetic_mat, matrix_b=opt_embed%embed_pot_coef, &
1179 beta=0.0_dp, matrix_c=regular_term)
1183 CALL cp_fm_scale_and_add(1.0_dp, opt_embed%embed_pot_grad, 4.0_dp*opt_embed%lambda, regular_term)
1186 CALL cp_fm_trace(opt_embed%embed_pot_coef, regular_term, opt_embed%reg_term)
1187 opt_embed%reg_term = 2.0_dp*opt_embed%lambda*opt_embed%reg_term
1190 CALL cp_fm_release(regular_term)
1192 CALL timestop(handle)
1207 SUBROUTINE calculate_embed_pot_grad_inner(qs_env, dimen_aux, rho_r, rho_spin, embed_pot_grad, &
1208 open_shell_embed, lri)
1209 TYPE(qs_environment_type),
POINTER :: qs_env
1210 INTEGER :: dimen_aux
1211 TYPE(pw_r3d_rs_type),
INTENT(IN) :: rho_r, rho_spin
1212 TYPE(cp_fm_type),
INTENT(IN) :: embed_pot_grad
1213 LOGICAL :: open_shell_embed
1214 TYPE(lri_kind_type),
DIMENSION(:),
POINTER :: lri
1216 CHARACTER(LEN=*),
PARAMETER :: routinen =
'calculate_embed_pot_grad_inner'
1218 INTEGER :: handle, iatom, ikind, l_global, lll, &
1219 nrow_local, nsgf, start_pos
1220 INTEGER,
DIMENSION(:),
POINTER :: row_indices
1221 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: pot_grad
1222 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
1223 TYPE(cell_type),
POINTER :: cell
1224 TYPE(dft_control_type),
POINTER :: dft_control
1225 TYPE(mp_para_env_type),
POINTER :: para_env
1226 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
1227 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1231 CALL timeset(routinen, handle)
1234 particle_set=particle_set, &
1235 qs_kind_set=qs_kind_set, &
1236 dft_control=dft_control, &
1238 atomic_kind_set=atomic_kind_set, &
1242 IF (open_shell_embed)
THEN
1243 ALLOCATE (pot_grad(dimen_aux*2))
1245 ALLOCATE (pot_grad(dimen_aux))
1249 DO ikind = 1,
SIZE(lri)
1250 lri(ikind)%v_int = 0.0_dp
1255 DO ikind = 1,
SIZE(lri)
1256 CALL para_env%sum(lri(ikind)%v_int)
1261 DO ikind = 1,
SIZE(lri)
1262 DO iatom = 1,
SIZE(lri(ikind)%v_int, dim=1)
1263 nsgf =
SIZE(lri(ikind)%v_int(iatom, :))
1264 pot_grad(start_pos:start_pos + nsgf - 1) = lri(ikind)%v_int(iatom, :)
1265 start_pos = start_pos + nsgf
1270 IF (open_shell_embed)
THEN
1271 DO ikind = 1,
SIZE(lri)
1272 lri(ikind)%v_int = 0.0_dp
1277 DO ikind = 1,
SIZE(lri)
1278 CALL para_env%sum(lri(ikind)%v_int)
1281 start_pos = dimen_aux + 1
1282 DO ikind = 1,
SIZE(lri)
1283 DO iatom = 1,
SIZE(lri(ikind)%v_int, dim=1)
1284 nsgf =
SIZE(lri(ikind)%v_int(iatom, :))
1285 pot_grad(start_pos:start_pos + nsgf - 1) = lri(ikind)%v_int(iatom, :)
1286 start_pos = start_pos + nsgf
1292 pot_grad = pot_grad*rho_r%pw_grid%dvol
1296 nrow_local=nrow_local, &
1297 row_indices=row_indices)
1300 DO lll = 1, nrow_local
1301 l_global = row_indices(lll)
1302 embed_pot_grad%local_data(lll, 1) = pot_grad(l_global)
1305 DEALLOCATE (pot_grad)
1307 CALL timestop(handle)
1309 END SUBROUTINE calculate_embed_pot_grad_inner
1317 SUBROUTINE compute_kinetic_mat(qs_env, kinetic_mat)
1318 TYPE(qs_environment_type),
POINTER :: qs_env
1319 TYPE(cp_fm_type),
INTENT(IN) :: kinetic_mat
1321 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_kinetic_mat'
1324 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_t
1325 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
1327 TYPE(qs_ks_env_type),
POINTER :: ks_env
1329 CALL timeset(routinen, handle)
1331 NULLIFY (ks_env, sab_orb, matrix_t)
1334 CALL get_qs_env(qs_env=qs_env, ks_env=ks_env, sab_orb=sab_orb)
1338 matrix_name=
"KINETIC ENERGY MATRIX", &
1339 basis_type=
"RI_AUX", &
1340 sab_nl=sab_orb, calculate_forces=.false.)
1348 CALL timestop(handle)
1350 END SUBROUTINE compute_kinetic_mat
1359 SUBROUTINE grid_regularize(potential, pw_env, lambda, reg_term)
1361 TYPE(pw_r3d_rs_type),
INTENT(INOUT) :: potential
1362 TYPE(pw_env_type),
POINTER :: pw_env
1363 REAL(kind=
dp) :: lambda, reg_term
1366 INTEGER,
DIMENSION(3) :: lb, n, ub
1367 TYPE(pw_c1d_gs_type) :: dr2_pot, grid_reg_g, potential_g
1368 TYPE(pw_c1d_gs_type),
DIMENSION(3) :: dpot_g
1369 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
1370 TYPE(pw_r3d_rs_type) :: grid_reg, square_norm_dpot
1371 TYPE(pw_r3d_rs_type),
DIMENSION(3) :: dpot
1378 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
1380 CALL auxbas_pw_pool%create_pw(potential_g)
1382 CALL auxbas_pw_pool%create_pw(dr2_pot)
1384 CALL auxbas_pw_pool%create_pw(grid_reg)
1386 CALL auxbas_pw_pool%create_pw(grid_reg_g)
1387 CALL pw_zero(grid_reg_g)
1390 CALL pw_transfer(potential, potential_g)
1394 CALL pw_dr2(potential_g, dr2_pot, i, i)
1395 CALL pw_axpy(dr2_pot, grid_reg_g, 1.0_dp)
1398 CALL pw_transfer(grid_reg_g, grid_reg)
1401 CALL pw_axpy(grid_reg, potential, -4.0_dp*lambda)
1407 CALL auxbas_pw_pool%create_pw(dpot(i))
1408 CALL auxbas_pw_pool%create_pw(dpot_g(i))
1411 CALL auxbas_pw_pool%create_pw(square_norm_dpot)
1416 CALL pw_copy(potential_g, dpot_g(i))
1418 CALL pw_transfer(dpot_g(i), dpot(i))
1421 lb(1:3) = square_norm_dpot%pw_grid%bounds_local(1, 1:3)
1422 ub(1:3) = square_norm_dpot%pw_grid%bounds_local(2, 1:3)
1429 square_norm_dpot%array(i, j, k) = (dpot(1)%array(i, j, k)* &
1430 dpot(1)%array(i, j, k) + &
1431 dpot(2)%array(i, j, k)* &
1432 dpot(2)%array(i, j, k) + &
1433 dpot(3)%array(i, j, k)* &
1434 dpot(3)%array(i, j, k))
1440 reg_term = 2*lambda*pw_integrate_function(fun=square_norm_dpot)
1443 CALL auxbas_pw_pool%give_back_pw(potential_g)
1444 CALL auxbas_pw_pool%give_back_pw(dr2_pot)
1445 CALL auxbas_pw_pool%give_back_pw(grid_reg)
1446 CALL auxbas_pw_pool%give_back_pw(grid_reg_g)
1447 CALL auxbas_pw_pool%give_back_pw(square_norm_dpot)
1449 CALL auxbas_pw_pool%give_back_pw(dpot(i))
1450 CALL auxbas_pw_pool%give_back_pw(dpot_g(i))
1453 END SUBROUTINE grid_regularize
1466 SUBROUTINE opt_embed_step(diff_rho_r, diff_rho_spin, opt_embed, embed_pot, spin_embed_pot, rho_r_ref, qs_env)
1468 TYPE(pw_r3d_rs_type),
INTENT(INOUT) :: diff_rho_r, diff_rho_spin
1469 TYPE(opt_embed_pot_type) :: opt_embed
1470 TYPE(pw_r3d_rs_type),
INTENT(INOUT) :: embed_pot
1471 TYPE(pw_r3d_rs_type),
INTENT(IN),
POINTER :: spin_embed_pot
1472 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r_ref
1473 TYPE(qs_environment_type),
POINTER :: qs_env
1475 CHARACTER(LEN=*),
PARAMETER :: routinen =
'opt_embed_step'
1476 REAL(kind=
dp),
PARAMETER :: thresh = 0.000001_dp
1478 INTEGER :: handle, l_global, lll, nrow_local
1479 INTEGER,
DIMENSION(:),
POINTER :: row_indices
1480 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigenval
1481 TYPE(cp_fm_struct_type),
POINTER :: fm_struct
1482 TYPE(cp_fm_type) :: diag_grad, diag_step, fm_u, fm_u_scale
1483 TYPE(pw_env_type),
POINTER :: pw_env
1485 CALL timeset(routinen, handle)
1487 IF (opt_embed%grid_opt)
THEN
1489 opt_embed%step_len = opt_embed%trust_rad
1490 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
1491 IF (opt_embed%leeuwen)
THEN
1492 CALL leeuwen_baerends_potential_update(pw_env, embed_pot, spin_embed_pot, diff_rho_r, diff_rho_spin, &
1493 rho_r_ref, opt_embed%open_shell_embed, opt_embed%trust_rad)
1495 IF (opt_embed%fab)
THEN
1496 CALL fab_update(qs_env, rho_r_ref, opt_embed%prev_embed_pot, opt_embed%prev_spin_embed_pot, &
1497 embed_pot, spin_embed_pot, &
1498 diff_rho_r, diff_rho_spin, opt_embed%v_w, opt_embed%i_iter, opt_embed%trust_rad, &
1499 opt_embed%open_shell_embed, opt_embed%vw_cutoff, opt_embed%vw_smooth_cutoff_range)
1501 CALL grid_based_step(diff_rho_r, diff_rho_spin, pw_env, opt_embed, embed_pot, spin_embed_pot)
1507 IF (.NOT. opt_embed%accept_step) &
1511 IF (opt_embed%steep_desc)
THEN
1512 IF (opt_embed%i_iter .GT. 2) &
1513 opt_embed%trust_rad = barzilai_borwein(opt_embed%step, opt_embed%prev_step, &
1514 opt_embed%embed_pot_grad, opt_embed%prev_embed_pot_grad)
1515 IF (abs(opt_embed%trust_rad) .GT. opt_embed%max_trad)
THEN
1516 IF (opt_embed%trust_rad .GT. 0.0_dp)
THEN
1517 opt_embed%trust_rad = opt_embed%max_trad
1519 opt_embed%trust_rad = -opt_embed%max_trad
1523 CALL cp_fm_to_fm(opt_embed%step, opt_embed%prev_step)
1526 CALL cp_fm_scale_and_add(1.0_dp, opt_embed%step, opt_embed%trust_rad, opt_embed%embed_pot_grad)
1527 opt_embed%step_len = opt_embed%trust_rad
1531 IF (opt_embed%i_iter > 1)
THEN
1532 IF (opt_embed%accept_step) &
1533 CALL symm_rank_one_update(opt_embed%embed_pot_grad, opt_embed%prev_embed_pot_grad, &
1534 opt_embed%step, opt_embed%prev_embed_pot_Hess, opt_embed%embed_pot_Hess)
1543 ALLOCATE (eigenval(opt_embed%dimen_var_aux))
1546 matrix_struct=fm_struct)
1552 matrix_struct=fm_struct)
1553 CALL cp_fm_create(diag_grad, fm_struct, name=
"diag_grad")
1555 CALL cp_fm_create(diag_step, fm_struct, name=
"diag_step")
1559 CALL cp_fm_to_fm(opt_embed%embed_pot_hess, fm_u_scale)
1565 CALL cp_fm_to_fm(fm_u_scale, opt_embed%embed_pot_hess)
1568 CALL parallel_gemm(transa=
"T", transb=
"N", m=opt_embed%dimen_var_aux, n=1, &
1569 k=opt_embed%dimen_var_aux, alpha=1.0_dp, &
1570 matrix_a=fm_u, matrix_b=opt_embed%embed_pot_grad, beta=0.0_dp, &
1574 nrow_local=nrow_local, &
1575 row_indices=row_indices)
1577 DO lll = 1, nrow_local
1578 l_global = row_indices(lll)
1579 IF (abs(eigenval(l_global)) .GE. thresh)
THEN
1580 diag_step%local_data(lll, 1) = &
1581 -diag_grad%local_data(lll, 1)/(eigenval(l_global))
1583 diag_step%local_data(lll, 1) = 0.0_dp
1586 CALL cp_fm_trace(diag_step, diag_step, opt_embed%step_len)
1589 CALL parallel_gemm(transa=
"N", transb=
"N", m=opt_embed%dimen_var_aux, n=1, &
1590 k=opt_embed%dimen_var_aux, alpha=1.0_dp, &
1591 matrix_a=fm_u, matrix_b=diag_step, beta=0.0_dp, &
1592 matrix_c=opt_embed%step)
1595 CALL cp_fm_to_fm(fm_u, fm_u_scale)
1598 CALL cp_fm_release(fm_u_scale)
1602 CALL cp_fm_trace(opt_embed%step, opt_embed%step, opt_embed%step_len)
1603 IF (opt_embed%step_len .GT. opt_embed%trust_rad)
THEN
1605 IF (opt_embed%level_shift)
THEN
1607 CALL level_shift(opt_embed, diag_grad, eigenval, diag_step)
1609 CALL cp_fm_trace(diag_step, diag_step, opt_embed%step_len)
1610 CALL cp_fm_scale(opt_embed%trust_rad/opt_embed%step_len, diag_step)
1612 CALL cp_fm_trace(diag_step, diag_step, opt_embed%step_len)
1614 CALL parallel_gemm(transa=
"N", transb=
"N", m=opt_embed%dimen_var_aux, n=1, &
1615 k=opt_embed%dimen_var_aux, alpha=1.0_dp, &
1616 matrix_a=fm_u, matrix_b=diag_step, beta=0.0_dp, &
1617 matrix_c=opt_embed%step)
1618 CALL cp_fm_trace(opt_embed%step, opt_embed%step, opt_embed%step_len)
1621 opt_embed%newton_step = .false.
1623 opt_embed%newton_step = .true.
1627 DEALLOCATE (eigenval)
1629 CALL cp_fm_release(diag_grad)
1630 CALL cp_fm_release(diag_step)
1631 CALL cp_fm_release(fm_u)
1639 CALL update_embed_pot(opt_embed%embed_pot_coef, opt_embed%dimen_aux, embed_pot, &
1640 spin_embed_pot, qs_env, opt_embed%add_const_pot, &
1641 opt_embed%open_shell_embed, opt_embed%const_pot)
1644 CALL timestop(handle)
1658 SUBROUTINE grid_based_step(diff_rho_r, diff_rho_spin, pw_env, opt_embed, embed_pot, spin_embed_pot)
1660 TYPE(pw_r3d_rs_type),
INTENT(INOUT) :: diff_rho_r, diff_rho_spin
1661 TYPE(pw_env_type),
POINTER :: pw_env
1662 TYPE(opt_embed_pot_type) :: opt_embed
1663 TYPE(pw_r3d_rs_type),
INTENT(INOUT) :: embed_pot
1664 TYPE(pw_r3d_rs_type),
POINTER :: spin_embed_pot
1666 CHARACTER(LEN=*),
PARAMETER :: routinen =
'grid_based_step'
1669 REAL(kind=
dp) :: my_reg_term
1671 CALL timeset(routinen, handle)
1674 CALL pw_axpy(diff_rho_r, embed_pot, opt_embed%step_len)
1676 CALL grid_regularize(embed_pot, pw_env, opt_embed%lambda, my_reg_term)
1677 opt_embed%reg_term = opt_embed%reg_term + my_reg_term
1679 IF (opt_embed%open_shell_embed)
THEN
1680 CALL pw_axpy(diff_rho_spin, spin_embed_pot, opt_embed%step_len)
1681 CALL grid_regularize(spin_embed_pot, pw_env, opt_embed%lambda, my_reg_term)
1682 opt_embed%reg_term = opt_embed%reg_term + my_reg_term
1685 CALL timestop(handle)
1687 END SUBROUTINE grid_based_step
1702 SUBROUTINE update_embed_pot(embed_pot_coef, dimen_aux, embed_pot, spin_embed_pot, &
1703 qs_env, add_const_pot, open_shell_embed, const_pot)
1704 TYPE(cp_fm_type),
INTENT(IN) :: embed_pot_coef
1705 INTEGER :: dimen_aux
1706 TYPE(pw_r3d_rs_type),
INTENT(INOUT) :: embed_pot
1707 TYPE(pw_r3d_rs_type),
INTENT(IN),
POINTER :: spin_embed_pot
1708 TYPE(qs_environment_type),
POINTER :: qs_env
1709 LOGICAL :: add_const_pot, open_shell_embed
1710 TYPE(pw_r3d_rs_type),
INTENT(IN),
OPTIONAL :: const_pot
1712 CHARACTER(LEN=*),
PARAMETER :: routinen =
'update_embed_pot'
1714 INTEGER :: handle, l_global, lll, nrow_local
1715 INTEGER,
DIMENSION(:),
POINTER :: row_indices
1716 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: wf_vector
1717 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
1718 TYPE(cell_type),
POINTER :: cell
1719 TYPE(cp_blacs_env_type),
POINTER :: blacs_env
1720 TYPE(cp_fm_struct_type),
POINTER :: fm_struct
1721 TYPE(cp_fm_type) :: embed_pot_coef_spin, &
1722 embed_pot_coef_spinless
1723 TYPE(cp_fm_type),
POINTER :: mo_coeff
1724 TYPE(dft_control_type),
POINTER :: dft_control
1725 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos
1726 TYPE(mp_para_env_type),
POINTER :: para_env
1727 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
1728 TYPE(pw_c1d_gs_type) :: rho_g
1729 TYPE(pw_env_type),
POINTER :: pw_env
1730 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
1731 TYPE(pw_r3d_rs_type) :: psi_l
1732 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1734 CALL timeset(routinen, handle)
1737 particle_set=particle_set, &
1738 qs_kind_set=qs_kind_set, &
1739 dft_control=dft_control, &
1741 atomic_kind_set=atomic_kind_set, &
1742 pw_env=pw_env, mos=mos, para_env=para_env)
1743 CALL get_mo_set(mo_set=mos(1), mo_coeff=mo_coeff)
1746 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
1749 CALL auxbas_pw_pool%create_pw(rho_g)
1751 CALL auxbas_pw_pool%create_pw(psi_l)
1754 ALLOCATE (wf_vector(dimen_aux))
1758 IF (open_shell_embed)
THEN
1762 nrow_global=dimen_aux, ncol_global=1)
1763 CALL cp_fm_create(embed_pot_coef_spinless, fm_struct, name=
"pot_coeff_spinless")
1764 CALL cp_fm_create(embed_pot_coef_spin, fm_struct, name=
"pot_coeff_spin")
1771 mtarget=embed_pot_coef_spinless, &
1772 nrow=dimen_aux, ncol=1, &
1773 s_firstrow=1, s_firstcol=1, &
1774 t_firstrow=1, t_firstcol=1)
1776 mtarget=embed_pot_coef_spin, &
1777 nrow=dimen_aux, ncol=1, &
1778 s_firstrow=dimen_aux + 1, s_firstcol=1, &
1779 t_firstrow=1, t_firstcol=1)
1783 nrow_local=nrow_local, &
1784 row_indices=row_indices)
1787 DO lll = 1, nrow_local
1788 l_global = row_indices(lll)
1789 wf_vector(l_global) = embed_pot_coef_spinless%local_data(lll, 1)
1791 CALL para_env%sum(wf_vector)
1795 qs_kind_set, cell, dft_control, particle_set, pw_env, &
1796 basis_type=
"RI_AUX", &
1797 external_vector=wf_vector)
1799 IF (add_const_pot)
THEN
1800 CALL pw_copy(const_pot, embed_pot)
1802 CALL pw_zero(embed_pot)
1805 CALL pw_axpy(psi_l, embed_pot)
1810 nrow_local=nrow_local, &
1811 row_indices=row_indices)
1814 DO lll = 1, nrow_local
1815 l_global = row_indices(lll)
1816 wf_vector(l_global) = embed_pot_coef_spin%local_data(lll, 1)
1818 CALL para_env%sum(wf_vector)
1822 qs_kind_set, cell, dft_control, particle_set, pw_env, &
1823 basis_type=
"RI_AUX", &
1824 external_vector=wf_vector)
1826 CALL pw_zero(spin_embed_pot)
1827 CALL pw_axpy(psi_l, spin_embed_pot)
1832 nrow_local=nrow_local, &
1833 row_indices=row_indices)
1836 DO lll = 1, nrow_local
1837 l_global = row_indices(lll)
1838 wf_vector(l_global) = embed_pot_coef%local_data(lll, 1)
1840 CALL para_env%sum(wf_vector)
1844 qs_kind_set, cell, dft_control, particle_set, pw_env)
1847 qs_kind_set, cell, dft_control, particle_set, pw_env, &
1848 basis_type=
"RI_AUX", &
1849 external_vector=wf_vector)
1852 IF (add_const_pot)
THEN
1853 CALL pw_copy(const_pot, embed_pot)
1855 CALL pw_zero(embed_pot)
1858 CALL pw_axpy(psi_l, embed_pot)
1862 DEALLOCATE (wf_vector)
1863 CALL auxbas_pw_pool%give_back_pw(psi_l)
1864 CALL auxbas_pw_pool%give_back_pw(rho_g)
1866 IF (open_shell_embed)
THEN
1867 CALL cp_fm_release(embed_pot_coef_spin)
1868 CALL cp_fm_release(embed_pot_coef_spinless)
1871 CALL timestop(handle)
1873 END SUBROUTINE update_embed_pot
1884 SUBROUTINE inv_hessian_update(grad, prev_grad, step, prev_inv_Hess, inv_Hess)
1885 TYPE(cp_fm_type),
INTENT(IN) :: grad, prev_grad, step, prev_inv_hess, &
1889 REAL(kind=
dp) :: factor1, s_dot_y, y_dot_b_inv_y
1890 TYPE(cp_fm_struct_type),
POINTER :: fm_struct_mat, fm_struct_vec
1891 TYPE(cp_fm_type) :: b_inv_y, b_inv_y_s, s_s, s_y, s_y_b_inv, &
1896 nrow_global=mat_size)
1899 CALL cp_fm_to_fm(prev_inv_hess, inv_hess)
1902 NULLIFY (fm_struct_mat, fm_struct_vec)
1905 matrix_struct=fm_struct_mat)
1907 matrix_struct=fm_struct_vec)
1910 CALL cp_fm_create(b_inv_y, fm_struct_vec, name=
"B_inv_y")
1915 CALL cp_fm_create(b_inv_y_s, fm_struct_mat, name=
"B_inv_y_s")
1916 CALL cp_fm_create(s_y_b_inv, fm_struct_mat, name=
"s_y_B_inv")
1927 CALL cp_fm_to_fm(grad, y)
1931 CALL parallel_gemm(transa=
"N", transb=
"N", m=mat_size, n=1, &
1932 k=mat_size, alpha=1.0_dp, &
1933 matrix_a=prev_inv_hess, matrix_b=y, beta=0.0_dp, &
1936 CALL parallel_gemm(transa=
"N", transb=
"T", m=mat_size, n=mat_size, &
1937 k=1, alpha=1.0_dp, &
1938 matrix_a=step, matrix_b=step, beta=0.0_dp, &
1941 CALL parallel_gemm(transa=
"N", transb=
"T", m=mat_size, n=mat_size, &
1942 k=1, alpha=1.0_dp, &
1943 matrix_a=step, matrix_b=y, beta=0.0_dp, &
1946 CALL cp_fm_trace(step, y, s_dot_y)
1948 CALL cp_fm_trace(y, y, s_dot_y)
1949 CALL cp_fm_trace(step, step, s_dot_y)
1951 CALL cp_fm_trace(y, b_inv_y, y_dot_b_inv_y)
1953 factor1 = (s_dot_y + y_dot_b_inv_y)/(s_dot_y)**2
1958 CALL parallel_gemm(transa=
"N", transb=
"T", m=mat_size, n=mat_size, &
1959 k=1, alpha=1.0_dp, &
1960 matrix_a=b_inv_y, matrix_b=step, beta=0.0_dp, &
1963 CALL parallel_gemm(transa=
"N", transb=
"N", m=mat_size, n=mat_size, &
1964 k=mat_size, alpha=1.0_dp, &
1965 matrix_a=s_y, matrix_b=prev_inv_hess, beta=0.0_dp, &
1974 CALL cp_fm_release(y)
1975 CALL cp_fm_release(b_inv_y)
1976 CALL cp_fm_release(s_s)
1977 CALL cp_fm_release(s_y)
1978 CALL cp_fm_release(b_inv_y_s)
1979 CALL cp_fm_release(s_y_b_inv)
1981 END SUBROUTINE inv_hessian_update
1991 SUBROUTINE hessian_update(grad, prev_grad, step, prev_Hess, Hess)
1992 TYPE(cp_fm_type),
INTENT(IN) :: grad, prev_grad, step, prev_hess, hess
1995 REAL(kind=
dp) :: s_b_s, y_t_s
1996 TYPE(cp_blacs_env_type),
POINTER :: blacs_env
1997 TYPE(cp_fm_struct_type),
POINTER :: fm_struct_mat, fm_struct_vec, &
1999 TYPE(cp_fm_type) :: b_s, b_s_s_b, s_t_b, y, y_y_t
2000 TYPE(mp_para_env_type),
POINTER :: para_env
2004 nrow_global=mat_size, para_env=para_env)
2007 CALL cp_fm_to_fm(prev_hess, hess)
2018 NULLIFY (fm_struct_mat, fm_struct_vec, fm_struct_vec_t)
2021 matrix_struct=fm_struct_mat)
2023 matrix_struct=fm_struct_vec)
2025 nrow_global=1, ncol_global=mat_size)
2029 CALL cp_fm_create(s_t_b, fm_struct_vec_t, name=
"s_t_B")
2033 CALL cp_fm_create(b_s_s_b, fm_struct_mat, name=
"B_s_s_B")
2046 CALL cp_fm_to_fm(grad, y)
2050 CALL parallel_gemm(transa=
"N", transb=
"T", m=mat_size, n=mat_size, &
2051 k=1, alpha=1.0_dp, &
2052 matrix_a=y, matrix_b=y, beta=0.0_dp, &
2055 CALL cp_fm_trace(y, step, y_t_s)
2060 CALL parallel_gemm(transa=
"N", transb=
"N", m=mat_size, n=1, &
2061 k=mat_size, alpha=1.0_dp, &
2062 matrix_a=hess, matrix_b=step, beta=0.0_dp, &
2065 CALL cp_fm_trace(b_s, step, s_b_s)
2067 CALL parallel_gemm(transa=
"T", transb=
"N", m=1, n=mat_size, &
2068 k=mat_size, alpha=1.0_dp, &
2069 matrix_a=step, matrix_b=hess, beta=0.0_dp, &
2072 CALL parallel_gemm(transa=
"N", transb=
"N", m=mat_size, n=mat_size, &
2073 k=1, alpha=1.0_dp, &
2074 matrix_a=b_s, matrix_b=s_t_b, beta=0.0_dp, &
2087 CALL cp_fm_release(y_y_t)
2088 CALL cp_fm_release(b_s_s_b)
2089 CALL cp_fm_release(b_s)
2090 CALL cp_fm_release(s_t_b)
2091 CALL cp_fm_release(y)
2093 END SUBROUTINE hessian_update
2103 SUBROUTINE symm_rank_one_update(grad, prev_grad, step, prev_Hess, Hess)
2104 TYPE(cp_fm_type),
INTENT(IN) :: grad, prev_grad, step, prev_hess, hess
2107 REAL(kind=
dp) :: factor
2108 TYPE(cp_fm_struct_type),
POINTER :: fm_struct_mat, fm_struct_vec
2109 TYPE(cp_fm_type) :: b_x, y, y_b_x_y_b_x
2115 CALL cp_fm_to_fm(prev_hess, hess)
2118 NULLIFY (fm_struct_mat, fm_struct_vec)
2121 matrix_struct=fm_struct_mat)
2123 matrix_struct=fm_struct_vec)
2128 CALL cp_fm_create(y_b_x_y_b_x, fm_struct_mat, name=
"y_B_x_y_B_x")
2136 CALL cp_fm_to_fm(grad, y)
2139 CALL parallel_gemm(transa=
"N", transb=
"N", m=mat_size, n=1, &
2140 k=mat_size, alpha=1.0_dp, &
2141 matrix_a=hess, matrix_b=step, beta=0.0_dp, &
2146 CALL parallel_gemm(transa=
"N", transb=
"T", m=mat_size, n=mat_size, &
2147 k=1, alpha=1.0_dp, &
2148 matrix_a=y, matrix_b=y, beta=0.0_dp, &
2149 matrix_c=y_b_x_y_b_x)
2152 CALL cp_fm_trace(y, step, factor)
2158 CALL cp_fm_release(y)
2159 CALL cp_fm_release(b_x)
2160 CALL cp_fm_release(y_b_x_y_b_x)
2162 END SUBROUTINE symm_rank_one_update
2170 TYPE(opt_embed_pot_type) :: opt_embed
2172 CHARACTER(LEN=*),
PARAMETER :: routinen =
'step_control'
2175 REAL(kind=
dp) :: actual_ener_change, ener_ratio, &
2176 lin_term, pred_ener_change, quad_term
2177 TYPE(cp_fm_struct_type),
POINTER :: fm_struct
2178 TYPE(cp_fm_type) :: h_b
2180 CALL timeset(routinen, handle)
2184 matrix_struct=fm_struct)
2190 CALL cp_fm_trace(opt_embed%step, opt_embed%embed_pot_grad, lin_term)
2193 CALL parallel_gemm(transa=
"N", transb=
"N", m=opt_embed%dimen_aux, n=1, &
2194 k=opt_embed%dimen_aux, alpha=1.0_dp, &
2195 matrix_a=opt_embed%embed_pot_Hess, matrix_b=opt_embed%step, &
2196 beta=0.0_dp, matrix_c=h_b)
2197 CALL cp_fm_trace(opt_embed%step, h_b, quad_term)
2199 pred_ener_change = lin_term + 0.5_dp*quad_term
2202 actual_ener_change = opt_embed%w_func(opt_embed%i_iter) - &
2203 opt_embed%w_func(opt_embed%last_accepted)
2205 ener_ratio = actual_ener_change/pred_ener_change
2207 CALL cp_fm_release(h_b)
2209 IF (actual_ener_change .GT. 0.0_dp)
THEN
2211 opt_embed%accept_step = .true.
2214 IF ((ener_ratio .GT. 1.0_dp) .AND. (.NOT. opt_embed%newton_step) .AND. &
2215 (opt_embed%trust_rad .LT. opt_embed%max_trad)) &
2216 opt_embed%trust_rad = 2.0_dp*opt_embed%trust_rad
2220 IF (abs(actual_ener_change) .GE. opt_embed%allowed_decrease)
THEN
2221 opt_embed%accept_step = .false.
2224 IF (opt_embed%trust_rad .GE. opt_embed%min_trad) &
2225 opt_embed%trust_rad = 0.25_dp*opt_embed%trust_rad
2228 IF (opt_embed%accept_step) opt_embed%last_accepted = opt_embed%i_iter
2230 CALL timestop(handle)
2241 SUBROUTINE level_shift(opt_embed, diag_grad, eigenval, diag_step)
2242 TYPE(opt_embed_pot_type) :: opt_embed
2243 TYPE(cp_fm_type),
INTENT(IN) :: diag_grad
2244 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigenval
2245 TYPE(cp_fm_type),
INTENT(IN) :: diag_step
2247 CHARACTER(LEN=*),
PARAMETER :: routinen =
'level_shift'
2248 INTEGER,
PARAMETER :: max_iter = 25
2249 REAL(kind=
dp),
PARAMETER :: thresh = 0.00001_dp
2251 INTEGER :: handle, i_iter, l_global, lll, &
2252 min_index, nrow_local
2253 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: red_eigenval_map
2254 INTEGER,
DIMENSION(:),
POINTER :: row_indices
2255 LOGICAL :: converged, do_shift
2256 REAL(kind=
dp) :: diag_grad_norm, grad_min, hess_min, shift, shift_max, shift_min, step_len, &
2257 step_minus_trad, step_minus_trad_first, step_minus_trad_max, step_minus_trad_min
2258 TYPE(mp_para_env_type),
POINTER :: para_env
2260 CALL timeset(routinen, handle)
2264 nrow_local=nrow_local, &
2265 row_indices=row_indices, &
2268 min_index = minloc(abs(eigenval), dim=1)
2269 hess_min = eigenval(min_index)
2272 CALL cp_fm_trace(diag_grad, diag_grad, diag_grad_norm)
2274 IF (hess_min .LT. 0.0_dp)
THEN
2278 shift_max = hess_min + 0.1
2279 shift_min = diag_grad_norm/opt_embed%trust_rad
2288 step_minus_trad_max = shifted_step(diag_grad, eigenval, shift_max, opt_embed%trust_rad)
2289 step_minus_trad_min = shifted_step(diag_grad, eigenval, shift_min, opt_embed%trust_rad)
2294 IF (abs(step_minus_trad_max) .LE. thresh)
THEN
2297 IF (abs(step_minus_trad_min) .LE. thresh)
THEN
2300 DO i_iter = 1, max_iter
2301 shift = 0.5_dp*(shift_max + shift_min)
2302 step_minus_trad = shifted_step(diag_grad, eigenval, shift, opt_embed%trust_rad)
2303 IF (i_iter .EQ. 1) step_minus_trad_first = step_minus_trad
2304 IF (step_minus_trad .GT. 0.0_dp) shift_max = shift
2305 IF (step_minus_trad .LT. 0.0_dp) shift_min = shift
2307 IF (abs(step_minus_trad) .LT. thresh) converged = .true.
2310 IF (abs(step_minus_trad) .LT. abs(step_minus_trad_first)) do_shift = .true.
2314 IF (converged .OR. do_shift)
THEN
2315 DO lll = 1, nrow_local
2316 l_global = row_indices(lll)
2317 IF (abs(eigenval(l_global)) .GE. thresh)
THEN
2318 diag_step%local_data(lll, 1) = &
2319 -diag_grad%local_data(lll, 1)/(eigenval(l_global) - shift)
2321 diag_step%local_data(lll, 1) = 0.0_dp
2325 IF (.NOT. converged)
THEN
2326 CALL cp_fm_trace(diag_step, diag_step, step_len)
2327 CALL cp_fm_scale(opt_embed%trust_rad/step_len, diag_step)
2333 ALLOCATE (red_eigenval_map(opt_embed%dimen_var_aux))
2334 red_eigenval_map = 0
2335 DO lll = 1, nrow_local
2336 l_global = row_indices(lll)
2337 IF (eigenval(l_global) .GE. 0.0_dp)
THEN
2338 red_eigenval_map(l_global) = 1
2341 CALL para_env%sum(red_eigenval_map)
2346 DO lll = 1, nrow_local
2347 l_global = row_indices(lll)
2348 IF (red_eigenval_map(l_global) .EQ. 0)
THEN
2349 IF (abs(eigenval(l_global)) .GE. thresh)
THEN
2350 diag_step%local_data(lll, 1) = &
2351 -diag_grad%local_data(lll, 1)/(eigenval(l_global) - shift)
2353 diag_step%local_data(lll, 1) = 0.0_dp
2356 diag_step%local_data(lll, 1) = 0.0_dp
2361 CALL cp_fm_trace(diag_step, diag_step, step_len)
2365 CALL timestop(handle)
2367 END SUBROUTINE level_shift
2377 FUNCTION shifted_step(diag_grad, eigenval, shift, trust_rad)
RESULT(step_minus_trad)
2378 TYPE(cp_fm_type),
INTENT(IN) :: diag_grad
2379 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:), &
2380 INTENT(IN) :: eigenval
2381 REAL(kind=
dp),
INTENT(IN) :: shift, trust_rad
2382 REAL(kind=
dp) :: step_minus_trad
2384 REAL(kind=
dp),
PARAMETER :: thresh = 0.000001_dp
2386 INTEGER :: l_global, lll, nrow_local
2387 INTEGER,
DIMENSION(:),
POINTER :: row_indices
2388 REAL(kind=
dp) :: step, step_1d
2389 TYPE(mp_para_env_type),
POINTER :: para_env
2392 nrow_local=nrow_local, &
2393 row_indices=row_indices, &
2397 DO lll = 1, nrow_local
2398 l_global = row_indices(lll)
2399 IF ((abs(eigenval(l_global)) .GE. thresh) .AND. (abs(diag_grad%local_data(lll, 1)) .GE. thresh))
THEN
2400 step_1d = -diag_grad%local_data(lll, 1)/(eigenval(l_global) + shift)
2401 step = step + step_1d**2
2405 CALL para_env%sum(step)
2407 step_minus_trad = sqrt(step) - trust_rad
2409 END FUNCTION shifted_step
2420 FUNCTION barzilai_borwein(step, prev_step, grad, prev_grad)
RESULT(length)
2421 TYPE(cp_fm_type),
INTENT(IN) :: step, prev_step, grad, prev_grad
2422 REAL(kind=
dp) :: length
2424 REAL(kind=
dp) :: denominator, numerator
2425 TYPE(cp_fm_struct_type),
POINTER :: fm_struct
2426 TYPE(cp_fm_type) :: grad_diff, step_diff
2432 matrix_struct=fm_struct)
2435 CALL cp_fm_create(grad_diff, fm_struct, name=
"grad_diff")
2436 CALL cp_fm_create(step_diff, fm_struct, name=
"step_diff")
2439 CALL cp_fm_to_fm(grad, grad_diff)
2440 CALL cp_fm_to_fm(step, step_diff)
2445 CALL cp_fm_trace(step_diff, grad_diff, numerator)
2446 CALL cp_fm_trace(grad_diff, grad_diff, denominator)
2449 CALL cp_fm_release(grad_diff)
2450 CALL cp_fm_release(step_diff)
2452 length = numerator/denominator
2454 END FUNCTION barzilai_borwein
2467 SUBROUTINE leeuwen_baerends_potential_update(pw_env, embed_pot, spin_embed_pot, diff_rho_r, diff_rho_spin, &
2468 rho_r_ref, open_shell_embed, step_len)
2469 TYPE(pw_env_type),
POINTER :: pw_env
2470 TYPE(pw_r3d_rs_type),
INTENT(INOUT) :: embed_pot
2471 TYPE(pw_r3d_rs_type),
INTENT(IN),
POINTER :: spin_embed_pot
2472 TYPE(pw_r3d_rs_type),
INTENT(IN) :: diff_rho_r, diff_rho_spin
2473 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r_ref
2474 LOGICAL,
INTENT(IN) :: open_shell_embed
2475 REAL(kind=
dp),
INTENT(IN) :: step_len
2477 CHARACTER(LEN=*),
PARAMETER :: routinen =
'Leeuwen_Baerends_potential_update'
2479 INTEGER :: handle, i, i_spin, j, k, nspins
2480 INTEGER,
DIMENSION(3) :: lb, ub
2481 REAL(kind=
dp) :: my_rho, rho_cutoff
2482 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
2483 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: new_embed_pot, rho_n_1, temp_embed_pot
2485 CALL timeset(routinen, handle)
2487 rho_cutoff = epsilon(0.0_dp)
2490 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
2491 NULLIFY (new_embed_pot)
2494 IF (open_shell_embed) nspins = 2
2495 NULLIFY (new_embed_pot)
2496 ALLOCATE (new_embed_pot(nspins))
2497 DO i_spin = 1, nspins
2498 CALL auxbas_pw_pool%create_pw(new_embed_pot(i_spin))
2499 CALL pw_zero(new_embed_pot(i_spin))
2502 lb(1:3) = embed_pot%pw_grid%bounds_local(1, 1:3)
2503 ub(1:3) = embed_pot%pw_grid%bounds_local(2, 1:3)
2505 IF (.NOT. open_shell_embed)
THEN
2512 IF (rho_r_ref(1)%array(i, j, k) .GT. rho_cutoff)
THEN
2513 my_rho = rho_r_ref(1)%array(i, j, k)
2517 new_embed_pot(1)%array(i, j, k) = step_len*embed_pot%array(i, j, k)* &
2518 (diff_rho_r%array(i, j, k) + rho_r_ref(1)%array(i, j, k))/my_rho
2523 CALL pw_copy(new_embed_pot(1), embed_pot)
2528 ALLOCATE (rho_n_1(nspins))
2529 NULLIFY (temp_embed_pot)
2530 ALLOCATE (temp_embed_pot(nspins))
2531 DO i_spin = 1, nspins
2532 CALL auxbas_pw_pool%create_pw(rho_n_1(i_spin))
2533 CALL pw_zero(rho_n_1(i_spin))
2534 CALL auxbas_pw_pool%create_pw(temp_embed_pot(i_spin))
2535 CALL pw_zero(temp_embed_pot(i_spin))
2537 CALL pw_copy(diff_rho_r, rho_n_1(1))
2538 CALL pw_copy(diff_rho_r, rho_n_1(2))
2539 CALL pw_axpy(diff_rho_spin, rho_n_1(1), 1.0_dp)
2540 CALL pw_axpy(diff_rho_spin, rho_n_1(2), -1.0_dp)
2541 CALL pw_scale(rho_n_1(1), a=0.5_dp)
2542 CALL pw_scale(rho_n_1(2), a=0.5_dp)
2544 CALL pw_copy(embed_pot, temp_embed_pot(1))
2545 CALL pw_copy(embed_pot, temp_embed_pot(2))
2546 CALL pw_axpy(spin_embed_pot, temp_embed_pot(1), 1.0_dp)
2547 CALL pw_axpy(spin_embed_pot, temp_embed_pot(2), -1.0_dp)
2549 IF (
SIZE(rho_r_ref) .EQ. 2)
THEN
2550 CALL pw_axpy(rho_r_ref(1), rho_n_1(1), 1.0_dp)
2551 CALL pw_axpy(rho_r_ref(2), rho_n_1(2), 1.0_dp)
2559 IF (rho_r_ref(1)%array(i, j, k) .GT. rho_cutoff)
THEN
2560 my_rho = rho_r_ref(1)%array(i, j, k)
2564 new_embed_pot(1)%array(i, j, k) = step_len*temp_embed_pot(1)%array(i, j, k)* &
2565 (rho_n_1(1)%array(i, j, k))/my_rho
2566 IF (rho_r_ref(2)%array(i, j, k) .GT. rho_cutoff)
THEN
2567 my_rho = rho_r_ref(2)%array(i, j, k)
2571 new_embed_pot(2)%array(i, j, k) = step_len*temp_embed_pot(2)%array(i, j, k)* &
2572 (rho_n_1(2)%array(i, j, k))/my_rho
2579 CALL pw_axpy(rho_r_ref(1), rho_n_1(1), 1.0_dp)
2588 IF (rho_r_ref(1)%array(i, j, k) .GT. rho_cutoff)
THEN
2589 my_rho = 0.5_dp*rho_r_ref(1)%array(i, j, k)
2593 new_embed_pot(1)%array(i, j, k) = step_len*temp_embed_pot(1)%array(i, j, k)* &
2594 (rho_n_1(1)%array(i, j, k))/my_rho
2595 new_embed_pot(2)%array(i, j, k) = step_len*temp_embed_pot(2)%array(i, j, k)* &
2596 (rho_n_1(2)%array(i, j, k))/my_rho
2603 CALL pw_copy(new_embed_pot(1), embed_pot)
2604 CALL pw_axpy(new_embed_pot(2), embed_pot, 1.0_dp)
2605 CALL pw_scale(embed_pot, a=0.5_dp)
2606 CALL pw_copy(new_embed_pot(1), spin_embed_pot)
2607 CALL pw_axpy(new_embed_pot(2), spin_embed_pot, -1.0_dp)
2608 CALL pw_scale(spin_embed_pot, a=0.5_dp)
2610 DO i_spin = 1, nspins
2611 CALL rho_n_1(i_spin)%release()
2612 CALL temp_embed_pot(i_spin)%release()
2614 DEALLOCATE (rho_n_1)
2615 DEALLOCATE (temp_embed_pot)
2618 DO i_spin = 1, nspins
2619 CALL new_embed_pot(i_spin)%release()
2622 DEALLOCATE (new_embed_pot)
2624 CALL timestop(handle)
2626 END SUBROUTINE leeuwen_baerends_potential_update
2645 SUBROUTINE fab_update(qs_env, rho_r_ref, prev_embed_pot, prev_spin_embed_pot, embed_pot, spin_embed_pot, &
2646 diff_rho_r, diff_rho_spin, v_w_ref, i_iter, step_len, open_shell_embed, &
2647 vw_cutoff, vw_smooth_cutoff_range)
2648 TYPE(qs_environment_type),
POINTER :: qs_env
2649 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r_ref
2650 TYPE(pw_r3d_rs_type),
INTENT(INOUT) :: prev_embed_pot
2651 TYPE(pw_r3d_rs_type),
INTENT(IN),
POINTER :: prev_spin_embed_pot
2652 TYPE(pw_r3d_rs_type),
INTENT(INOUT) :: embed_pot
2653 TYPE(pw_r3d_rs_type),
INTENT(IN),
POINTER :: spin_embed_pot
2654 TYPE(pw_r3d_rs_type),
INTENT(IN) :: diff_rho_r, diff_rho_spin
2655 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: v_w_ref
2656 INTEGER,
INTENT(IN) :: i_iter
2657 REAL(kind=
dp) :: step_len
2658 LOGICAL :: open_shell_embed
2659 REAL(kind=
dp) :: vw_cutoff, vw_smooth_cutoff_range
2661 CHARACTER(LEN=*),
PARAMETER :: routinen =
'FAB_update'
2663 INTEGER :: handle, i_spin, nspins
2664 TYPE(pw_env_type),
POINTER :: pw_env
2665 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
2666 TYPE(pw_r3d_rs_type),
ALLOCATABLE,
DIMENSION(:) :: new_embed_pot, temp_embed_pot, v_w
2667 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: curr_rho
2669 CALL timeset(routinen, handle)
2676 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
2680 IF (i_iter .LE. 1)
THEN
2681 nspins =
SIZE(rho_r_ref)
2683 ALLOCATE (v_w_ref(nspins))
2684 DO i_spin = 1, nspins
2685 CALL auxbas_pw_pool%create_pw(v_w_ref(i_spin))
2687 CALL von_weizsacker(rho_r_ref, v_w_ref, qs_env, vw_cutoff, vw_smooth_cutoff_range)
2689 CALL pw_copy(embed_pot, prev_embed_pot)
2690 CALL pw_axpy(diff_rho_r, embed_pot, 0.5_dp)
2691 IF (open_shell_embed)
THEN
2692 CALL pw_copy(spin_embed_pot, prev_spin_embed_pot)
2693 CALL pw_axpy(diff_rho_r, embed_pot, 0.5_dp)
2701 IF (open_shell_embed) nspins = 2
2702 ALLOCATE (new_embed_pot(nspins))
2703 ALLOCATE (v_w(nspins))
2705 ALLOCATE (curr_rho(nspins))
2706 DO i_spin = 1, nspins
2707 CALL auxbas_pw_pool%create_pw(new_embed_pot(i_spin))
2708 CALL pw_zero(new_embed_pot(i_spin))
2710 CALL auxbas_pw_pool%create_pw(v_w(i_spin))
2711 CALL pw_zero(v_w(i_spin))
2713 CALL auxbas_pw_pool%create_pw(curr_rho(i_spin))
2714 CALL pw_zero(curr_rho(i_spin))
2719 IF (.NOT. open_shell_embed)
THEN
2721 CALL pw_copy(diff_rho_r, curr_rho(1))
2722 CALL pw_axpy(rho_r_ref(1), curr_rho(1), 1.0_dp)
2724 CALL von_weizsacker(curr_rho, v_w, qs_env, vw_cutoff, vw_smooth_cutoff_range)
2726 CALL pw_copy(prev_embed_pot, new_embed_pot(1))
2727 CALL pw_axpy(v_w(1), new_embed_pot(1), step_len)
2728 CALL pw_axpy(v_w_ref(1), new_embed_pot(1), -step_len)
2731 CALL pw_copy(embed_pot, prev_embed_pot)
2732 CALL pw_copy(new_embed_pot(1), embed_pot)
2736 CALL pw_copy(diff_rho_r, curr_rho(1))
2737 CALL pw_copy(diff_rho_r, curr_rho(2))
2738 CALL pw_axpy(diff_rho_spin, curr_rho(1), 1.0_dp)
2739 CALL pw_axpy(diff_rho_spin, curr_rho(2), -1.0_dp)
2740 CALL pw_scale(curr_rho(1), a=0.5_dp)
2741 CALL pw_scale(curr_rho(2), a=0.5_dp)
2743 IF (
SIZE(rho_r_ref) .EQ. 1)
THEN
2744 CALL pw_axpy(rho_r_ref(1), curr_rho(1), 0.5_dp)
2745 CALL pw_axpy(rho_r_ref(1), curr_rho(2), 0.5_dp)
2747 CALL pw_axpy(rho_r_ref(1), curr_rho(1), 1.0_dp)
2748 CALL pw_axpy(rho_r_ref(2), curr_rho(2), 1.0_dp)
2752 CALL von_weizsacker(curr_rho, v_w, qs_env, vw_cutoff, vw_smooth_cutoff_range)
2755 ALLOCATE (temp_embed_pot(nspins))
2756 DO i_spin = 1, nspins
2757 CALL auxbas_pw_pool%create_pw(temp_embed_pot(i_spin))
2758 CALL pw_zero(temp_embed_pot(i_spin))
2760 CALL pw_copy(embed_pot, temp_embed_pot(1))
2761 CALL pw_copy(embed_pot, temp_embed_pot(2))
2762 CALL pw_axpy(spin_embed_pot, temp_embed_pot(1), 1.0_dp)
2763 CALL pw_axpy(spin_embed_pot, temp_embed_pot(2), -1.0_dp)
2766 IF (
SIZE(v_w_ref) .EQ. 1)
THEN
2767 CALL pw_copy(temp_embed_pot(1), new_embed_pot(1))
2768 CALL pw_axpy(v_w(1), new_embed_pot(1), 0.5_dp*step_len)
2769 CALL pw_axpy(v_w_ref(1), new_embed_pot(1), -0.5_dp*step_len)
2771 CALL pw_copy(temp_embed_pot(2), new_embed_pot(2))
2772 CALL pw_axpy(v_w(2), new_embed_pot(2), 0.5_dp)
2773 CALL pw_axpy(v_w_ref(1), new_embed_pot(2), -0.5_dp)
2777 DO i_spin = 1, nspins
2778 CALL pw_copy(temp_embed_pot(i_spin), new_embed_pot(i_spin))
2779 CALL pw_axpy(v_w(1), new_embed_pot(i_spin), step_len)
2780 CALL pw_axpy(v_w_ref(i_spin), new_embed_pot(i_spin), -step_len)
2785 CALL pw_copy(embed_pot, prev_embed_pot)
2786 CALL pw_copy(spin_embed_pot, prev_spin_embed_pot)
2788 CALL pw_copy(new_embed_pot(1), embed_pot)
2789 CALL pw_axpy(new_embed_pot(2), embed_pot, 1.0_dp)
2790 CALL pw_scale(embed_pot, a=0.5_dp)
2791 CALL pw_copy(new_embed_pot(1), spin_embed_pot)
2792 CALL pw_axpy(new_embed_pot(2), spin_embed_pot, -1.0_dp)
2793 CALL pw_scale(spin_embed_pot, a=0.5_dp)
2795 DO i_spin = 1, nspins
2796 CALL temp_embed_pot(i_spin)%release()
2798 DEALLOCATE (temp_embed_pot)
2802 DO i_spin = 1, nspins
2803 CALL curr_rho(i_spin)%release()
2804 CALL new_embed_pot(i_spin)%release()
2805 CALL v_w(i_spin)%release()
2808 DEALLOCATE (new_embed_pot)
2810 DEALLOCATE (curr_rho)
2814 CALL timestop(handle)
2816 END SUBROUTINE fab_update
2826 SUBROUTINE von_weizsacker(rho_r, v_w, qs_env, vw_cutoff, vw_smooth_cutoff_range)
2827 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r
2828 TYPE(pw_r3d_rs_type),
DIMENSION(:),
INTENT(IN) :: v_w
2829 TYPE(qs_environment_type),
POINTER :: qs_env
2830 REAL(kind=
dp),
INTENT(IN) :: vw_cutoff, vw_smooth_cutoff_range
2832 REAL(kind=
dp),
PARAMETER :: one_4 = 0.25_dp, one_8 = 0.125_dp
2834 INTEGER :: i, i_spin, j, k, nspins
2835 INTEGER,
DIMENSION(3) :: lb, ub
2836 REAL(kind=
dp) :: density_smooth_cut_range, my_rho, &
2838 REAL(kind=
dp),
DIMENSION(:, :, :),
POINTER :: rhoa, rhob
2839 TYPE(pw_c1d_gs_type),
DIMENSION(:),
POINTER :: rho_g
2840 TYPE(pw_env_type),
POINTER :: pw_env
2841 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
2842 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: tau
2843 TYPE(section_vals_type),
POINTER :: input, xc_section
2844 TYPE(xc_rho_cflags_type) :: needs
2845 TYPE(xc_rho_set_type) :: rho_set
2847 rho_cutoff = epsilon(0.0_dp)
2849 nspins =
SIZE(rho_r)
2851 NULLIFY (xc_section)
2858 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
2862 ALLOCATE (rho_g(nspins))
2863 DO i_spin = 1, nspins
2864 CALL auxbas_pw_pool%create_pw(rho_g(i_spin))
2865 CALL pw_transfer(rho_r(i_spin), rho_g(i_spin))
2871 rho_r(1)%pw_grid%bounds_local, &
2878 IF (nspins .EQ. 2)
THEN
2879 needs%rho_spin = .true.
2880 needs%norm_drho_spin = .true.
2881 needs%laplace_rho_spin = .true.
2884 needs%norm_drho = .true.
2885 needs%laplace_rho = .true.
2896 r_val=density_smooth_cut_range)
2898 lb(1:3) = rho_r(1)%pw_grid%bounds_local(1, 1:3)
2899 ub(1:3) = rho_r(1)%pw_grid%bounds_local(2, 1:3)
2901 IF (nspins .EQ. 2)
THEN
2908 IF (rho_r(1)%array(i, j, k) .GT. rho_cutoff)
THEN
2909 my_rho = rho_r(1)%array(i, j, k)
2913 v_w(1)%array(i, j, k) = one_8*rho_set%norm_drhoa(i, j, k)**2/my_rho**2 - &
2914 one_4*rho_set%laplace_rhoa(i, j, k)/my_rho
2916 IF (rho_r(2)%array(i, j, k) .GT. rho_cutoff)
THEN
2917 my_rho = rho_r(2)%array(i, j, k)
2921 v_w(2)%array(i, j, k) = one_8*rho_set%norm_drhob(i, j, k)**2/my_rho**2 - &
2922 one_4*rho_set%laplace_rhob(i, j, k)/my_rho
2934 IF (rho_r(1)%array(i, j, k) .GT. rho_cutoff)
THEN
2935 my_rho = rho_r(1)%array(i, j, k)
2936 v_w(1)%array(i, j, k) = one_8*rho_set%norm_drho(i, j, k)**2/my_rho**2 - &
2937 one_4*rho_set%laplace_rho(i, j, k)/my_rho
2939 v_w(1)%array(i, j, k) = 0.0_dp
2949 IF (nspins == 2)
THEN
2950 density_smooth_cut_range = 0.5_dp*density_smooth_cut_range
2951 rho_cutoff = 0.5_dp*rho_cutoff
2953 DO i_spin = 1, nspins
2954 CALL smooth_cutoff(pot=v_w(i_spin)%array, rho=rho_r(i_spin)%array, rhoa=rhoa, rhob=rhob, &
2955 rho_cutoff=vw_cutoff, &
2956 rho_smooth_cutoff_range=vw_smooth_cutoff_range)
2961 DO i_spin = 1, nspins
2962 CALL rho_g(i_spin)%release()
2966 END SUBROUTINE von_weizsacker
2974 TYPE(pw_r3d_rs_type),
INTENT(IN) :: diff_rho_r
2975 REAL(kind=
dp) :: total_max_diff
2977 INTEGER :: size_x, size_y, size_z
2978 REAL(kind=
dp) :: max_diff
2979 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: grid_3d
2984 size_x =
SIZE(diff_rho_r%array, 1)
2985 size_y =
SIZE(diff_rho_r%array, 2)
2986 size_z =
SIZE(diff_rho_r%array, 3)
2989 ALLOCATE (grid_3d(size_x, size_y, size_z))
2992 grid_3d(:, :, :) = diff_rho_r%array(:, :, :)
2995 max_diff = maxval(abs(grid_3d))
2996 total_max_diff = max_diff
2997 CALL diff_rho_r%pw_grid%para%group%max(total_max_diff)
3000 DEALLOCATE (grid_3d)
3013 TYPE(pw_r3d_rs_type),
INTENT(IN) :: diff_rho_r
3014 INTEGER,
INTENT(IN) :: i_iter
3015 TYPE(qs_environment_type),
INTENT(IN),
POINTER :: qs_env
3016 LOGICAL,
INTENT(IN) :: final_one
3018 CHARACTER(LEN=default_path_length) :: filename, my_pos_cube, title
3020 TYPE(cp_logger_type),
POINTER :: logger
3021 TYPE(particle_list_type),
POINTER :: particles
3022 TYPE(qs_subsys_type),
POINTER :: subsys
3023 TYPE(section_vals_type),
POINTER :: dft_section, input
3025 NULLIFY (subsys, input)
3035 "DFT%QS%OPT_EMBED%EMBED_DENS_DIFF"),
cp_p_file))
THEN
3036 my_pos_cube =
"REWIND"
3037 IF (.NOT. final_one)
THEN
3038 WRITE (filename,
'(a5,I3.3,a1,I1.1)')
"DIFF_", i_iter
3040 WRITE (filename,
'(a5,I3.3,a1,I1.1)')
"DIFF"
3043 extension=
".cube", middle_name=trim(filename), file_position=my_pos_cube, &
3044 log_filename=.false.)
3046 WRITE (title, *)
"EMBEDDING DENSITY DIFFERENCE ",
" optimization step ", i_iter
3047 CALL cp_pw_to_cube(diff_rho_r, unit_nr, title, particles=particles, &
3050 "DFT%QS%OPT_EMBED%EMBED_DENS_DIFF")
3064 TYPE(pw_r3d_rs_type),
INTENT(IN) :: spin_diff_rho_r
3065 INTEGER,
INTENT(IN) :: i_iter
3066 TYPE(qs_environment_type),
INTENT(IN),
POINTER :: qs_env
3067 LOGICAL,
INTENT(IN) :: final_one
3069 CHARACTER(LEN=default_path_length) :: filename, my_pos_cube, title
3071 TYPE(cp_logger_type),
POINTER :: logger
3072 TYPE(particle_list_type),
POINTER :: particles
3073 TYPE(qs_subsys_type),
POINTER :: subsys
3074 TYPE(section_vals_type),
POINTER :: dft_section, input
3076 NULLIFY (subsys, input)
3086 "DFT%QS%OPT_EMBED%EMBED_DENS_DIFF"),
cp_p_file))
THEN
3087 my_pos_cube =
"REWIND"
3088 IF (.NOT. final_one)
THEN
3089 WRITE (filename,
'(a5,I3.3,a1,I1.1)')
"SPIN_DIFF_", i_iter
3091 WRITE (filename,
'(a9,I3.3,a1,I1.1)')
"SPIN_DIFF"
3094 extension=
".cube", middle_name=trim(filename), file_position=my_pos_cube, &
3095 log_filename=.false.)
3097 WRITE (title, *)
"EMBEDDING SPIN DENSITY DIFFERENCE ",
" optimization step ", i_iter
3098 CALL cp_pw_to_cube(spin_diff_rho_r, unit_nr, title, particles=particles, &
3101 "DFT%QS%OPT_EMBED%EMBED_DENS_DIFF")
3118 embed_pot_spin, open_shell_embed, grid_opt, final_one)
3119 TYPE(qs_environment_type),
POINTER :: qs_env
3120 INTEGER :: dimen_aux
3121 TYPE(cp_fm_type),
INTENT(IN),
POINTER :: embed_pot_coef
3122 TYPE(pw_r3d_rs_type),
INTENT(IN) :: embed_pot
3124 TYPE(pw_r3d_rs_type),
INTENT(IN),
POINTER :: embed_pot_spin
3125 LOGICAL :: open_shell_embed, grid_opt, final_one
3127 CHARACTER(LEN=default_path_length) :: filename, my_pos_cube, title
3129 TYPE(cp_logger_type),
POINTER :: logger
3130 TYPE(particle_list_type),
POINTER :: particles
3131 TYPE(qs_subsys_type),
POINTER :: subsys
3132 TYPE(section_vals_type),
POINTER :: dft_section, input
3135 CALL get_qs_env(qs_env=qs_env, subsys=subsys, &
3139 IF (.NOT. grid_opt)
THEN
3142 "DFT%QS%OPT_EMBED%EMBED_POT_VECTOR"),
cp_p_file))
THEN
3143 IF (.NOT. final_one)
THEN
3144 WRITE (filename,
'(a10,I3.3)')
"embed_pot_", i_iter
3146 WRITE (filename,
'(a10,I3.3)')
"embed_pot"
3148 unit_nr =
cp_print_key_unit_nr(logger, input,
"DFT%QS%OPT_EMBED%EMBED_POT_VECTOR", extension=
".wfn", &
3149 file_form=
"UNFORMATTED", middle_name=trim(filename), file_position=
"REWIND")
3150 IF (unit_nr > 0)
THEN
3151 WRITE (unit_nr) dimen_aux
3154 IF (unit_nr > 0)
THEN
3166 "DFT%QS%OPT_EMBED%EMBED_POT_CUBE"),
cp_p_file))
THEN
3167 my_pos_cube =
"REWIND"
3168 IF (.NOT. final_one)
THEN
3169 WRITE (filename,
'(a10,I3.3)')
"embed_pot_", i_iter
3171 WRITE (filename,
'(a10,I3.3)')
"embed_pot"
3174 extension=
".cube", middle_name=trim(filename), file_position=my_pos_cube, &
3175 log_filename=.false.)
3177 WRITE (title, *)
"EMBEDDING POTENTIAL at optimization step ", i_iter
3178 CALL cp_pw_to_cube(embed_pot, unit_nr, title, particles=particles)
3182 "DFT%QS%OPT_EMBED%EMBED_POT_CUBE")
3183 IF (open_shell_embed)
THEN
3184 my_pos_cube =
"REWIND"
3185 IF (.NOT. final_one)
THEN
3186 WRITE (filename,
'(a15,I3.3)')
"spin_embed_pot_", i_iter
3188 WRITE (filename,
'(a15,I3.3)')
"spin_embed_pot"
3191 extension=
".cube", middle_name=trim(filename), file_position=my_pos_cube, &
3192 log_filename=.false.)
3194 WRITE (title, *)
"SPIN EMBEDDING POTENTIAL at optimization step ", i_iter
3195 CALL cp_pw_to_cube(embed_pot_spin, unit_nr, title, particles=particles)
3199 "DFT%QS%OPT_EMBED%EMBED_POT_CUBE")
3216 final_one, qs_env_cluster)
3217 TYPE(qs_environment_type),
POINTER :: qs_env
3218 TYPE(pw_r3d_rs_type),
INTENT(IN) :: embed_pot
3219 TYPE(pw_r3d_rs_type),
INTENT(IN),
POINTER :: embed_pot_spin
3221 LOGICAL :: open_shell_embed, final_one
3222 TYPE(qs_environment_type),
POINTER :: qs_env_cluster
3224 CHARACTER(LEN=default_path_length) :: filename
3225 INTEGER :: my_units, unit_nr
3226 LOGICAL :: angstrom, bohr
3227 TYPE(cp_logger_type),
POINTER :: logger
3228 TYPE(pw_env_type),
POINTER :: pw_env
3229 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
3230 TYPE(pw_r3d_rs_type) :: pot_alpha, pot_beta
3231 TYPE(section_vals_type),
POINTER :: dft_section, input
3234 CALL get_qs_env(qs_env=qs_env, input=input, pw_env=pw_env)
3242 "DFT%QS%OPT_EMBED%WRITE_SIMPLE_GRID"),
cp_p_file))
THEN
3248 SELECT CASE (my_units)
3262 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
3265 CALL auxbas_pw_pool%create_pw(pot_alpha)
3266 CALL pw_zero(pot_alpha)
3268 CALL pw_copy(embed_pot, pot_alpha)
3270 IF (open_shell_embed)
THEN
3271 CALL auxbas_pw_pool%create_pw(pot_beta)
3272 CALL pw_copy(embed_pot, pot_beta)
3274 CALL pw_axpy(embed_pot_spin, pot_alpha, 1.0_dp)
3275 CALL pw_axpy(embed_pot_spin, pot_beta, -1.0_dp)
3278 IF (.NOT. final_one)
THEN
3279 WRITE (filename,
'(a10,I3.3)')
"embed_pot_", i_iter
3281 WRITE (filename,
'(a10,I3.3)')
"embed_pot"
3283 unit_nr =
cp_print_key_unit_nr(logger, input,
"DFT%QS%OPT_EMBED%WRITE_SIMPLE_GRID", extension=
".dat", &
3284 middle_name=trim(filename), file_form=
"FORMATTED", file_position=
"REWIND")
3286 IF (open_shell_embed)
THEN
3288 stride=
section_get_ivals(dft_section,
"QS%OPT_EMBED%WRITE_SIMPLE_GRID%STRIDE"), &
3296 "DFT%QS%OPT_EMBED%WRITE_SIMPLE_GRID")
3298 CALL pot_alpha%release()
3299 IF (open_shell_embed)
THEN
3300 CALL pot_beta%release()
3307 CALL print_folded_coordinates(qs_env_cluster, input)
3316 SUBROUTINE print_folded_coordinates(qs_env, input)
3317 TYPE(qs_environment_type),
POINTER :: qs_env
3318 TYPE(section_vals_type),
POINTER :: input
3320 CHARACTER(LEN=2),
ALLOCATABLE,
DIMENSION(:) :: particles_el
3321 CHARACTER(LEN=default_path_length) :: filename
3322 INTEGER :: iat, n, unit_nr
3323 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: particles_r
3324 REAL(kind=
dp),
DIMENSION(3) :: center, r_pbc, s
3325 TYPE(cell_type),
POINTER :: cell
3326 TYPE(cp_logger_type),
POINTER :: logger
3327 TYPE(particle_list_type),
POINTER :: particles
3328 TYPE(qs_subsys_type),
POINTER :: subsys
3333 "DFT%QS%OPT_EMBED%WRITE_SIMPLE_GRID/FOLD_COORD"),
cp_p_file))
THEN
3334 CALL get_qs_env(qs_env=qs_env, cell=cell, subsys=subsys)
3338 WRITE (filename,
'(a14)')
"folded_cluster"
3340 "DFT%QS%OPT_EMBED%WRITE_SIMPLE_GRID/FOLD_COORD", extension=
".dat", &
3341 middle_name=trim(filename), file_form=
"FORMATTED", file_position=
"REWIND")
3342 IF (unit_nr > 0)
THEN
3345 ALLOCATE (particles_el(n))
3346 ALLOCATE (particles_r(3, n))
3348 CALL get_atomic_kind(particles%els(iat)%atomic_kind, element_symbol=particles_el(iat))
3349 particles_r(:, iat) = particles%els(iat)%r(:)
3353 center(:) = cell%hmat(:, 1)/2.0_dp + cell%hmat(:, 2)/2.0_dp + cell%hmat(:, 3)/2.0_dp
3356 DO iat = 1,
SIZE(particles_el)
3357 r_pbc(:) = particles_r(:, iat) - center
3358 s = matmul(cell%h_inv, r_pbc)
3360 r_pbc = matmul(cell%hmat, s)
3361 r_pbc = r_pbc + center
3362 WRITE (unit_nr,
'(a4,4f12.6)') particles_el(iat), r_pbc(:)
3366 "DFT%QS%OPT_EMBED%WRITE_SIMPLE_GRID/FOLD_COORD")
3368 DEALLOCATE (particles_el)
3369 DEALLOCATE (particles_r)
3374 END SUBROUTINE print_folded_coordinates
3383 INTEGER :: output_unit, step_num
3384 TYPE(opt_embed_pot_type) :: opt_embed
3386 IF (output_unit > 0)
THEN
3387 WRITE (unit=output_unit, fmt=
"(/,T2,8('-'),A,I5,1X,12('-'))") &
3388 " Optimize embedding potential info at step = ", step_num
3389 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3390 " Functional value = ", opt_embed%w_func(step_num)
3391 IF (step_num .GT. 1)
THEN
3392 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3393 " Real energy change = ", opt_embed%w_func(step_num) - &
3394 opt_embed%w_func(step_num - 1)
3396 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3397 " Step size = ", opt_embed%step_len
3401 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3402 " Trust radius = ", opt_embed%trust_rad
3404 WRITE (unit=output_unit, fmt=
"(T2,51('-'))")
3416 TYPE(opt_embed_pot_type) :: opt_embed
3417 TYPE(force_env_type),
POINTER :: force_env
3418 INTEGER :: subsys_num
3420 INTEGER :: i_dens_start, i_spin, nspins
3421 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r
3422 TYPE(qs_rho_type),
POINTER :: rho
3424 NULLIFY (rho_r, rho)
3428 nspins = opt_embed%all_nspins(subsys_num)
3430 i_dens_start = sum(opt_embed%all_nspins(1:subsys_num)) - nspins + 1
3432 DO i_spin = 1, nspins
3433 opt_embed%prev_subsys_dens(i_dens_start + i_spin - 1)%array(:, :, :) = &
3434 rho_r(i_spin)%array(:, :, :)
3446 TYPE(opt_embed_pot_type) :: opt_embed
3447 TYPE(force_env_type),
POINTER :: force_env
3448 INTEGER :: subsys_num
3450 INTEGER :: i_dens_start, i_spin, nspins
3451 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r
3452 TYPE(qs_rho_type),
POINTER :: rho
3454 NULLIFY (rho_r, rho)
3458 nspins = opt_embed%all_nspins(subsys_num)
3460 i_dens_start = sum(opt_embed%all_nspins(1:subsys_num)) - nspins + 1
3462 DO i_spin = 1, nspins
3463 CALL pw_axpy(rho_r(i_spin), opt_embed%prev_subsys_dens(i_dens_start + i_spin - 1), 1.0_dp, -1.0_dp, &
3464 allow_noncompatible_grids=.true.)
3465 opt_embed%max_subsys_dens_diff(i_dens_start + i_spin - 1) = &
3466 max_dens_diff(opt_embed%prev_subsys_dens(i_dens_start + i_spin - 1))
3479 TYPE(opt_embed_pot_type) :: opt_embed
3480 TYPE(pw_r3d_rs_type),
INTENT(IN) :: diff_rho_r, diff_rho_spin
3481 INTEGER :: output_unit
3483 INTEGER :: i_dens, i_dens_start, i_spin
3484 LOGICAL :: conv_int_diff, conv_max_diff
3485 REAL(kind=
dp) :: int_diff, int_diff_spin, &
3486 int_diff_square, int_diff_square_spin, &
3487 max_diff, max_diff_spin
3491 opt_embed%int_diff(1) = pw_integrate_function(fun=diff_rho_r, oprt=
'ABS')
3492 opt_embed%int_diff_square(1) = pw_integral_ab(diff_rho_r, diff_rho_r)
3493 IF (opt_embed%open_shell_embed)
THEN
3495 opt_embed%int_diff(2) = pw_integrate_function(fun=diff_rho_spin, oprt=
'ABS')
3496 opt_embed%int_diff_square(2) = pw_integral_ab(diff_rho_spin, diff_rho_spin)
3500 max_diff = opt_embed%max_diff(1)
3504 IF (opt_embed%open_shell_embed)
THEN
3505 max_diff_spin = opt_embed%max_diff(2)
3506 IF ((max_diff .LE. opt_embed%conv_max) .AND. (max_diff_spin .LE. opt_embed%conv_max_spin))
THEN
3507 conv_max_diff = .true.
3509 conv_max_diff = .false.
3513 IF (max_diff .LE. opt_embed%conv_max)
THEN
3514 conv_max_diff = .true.
3516 conv_max_diff = .false.
3521 int_diff = opt_embed%int_diff(1)
3523 IF (opt_embed%open_shell_embed)
THEN
3524 int_diff_spin = opt_embed%int_diff(2)
3525 IF ((int_diff .LE. opt_embed%conv_int) .AND. (int_diff_spin .LE. opt_embed%conv_int_spin))
THEN
3526 conv_int_diff = .true.
3528 conv_int_diff = .false.
3532 IF (int_diff .LE. opt_embed%conv_int)
THEN
3533 conv_int_diff = .true.
3535 conv_int_diff = .false.
3540 int_diff_square = opt_embed%int_diff_square(1)
3542 IF (opt_embed%open_shell_embed) int_diff_square_spin = opt_embed%int_diff_square(2)
3544 IF ((conv_max_diff) .AND. (conv_int_diff))
THEN
3545 opt_embed%converged = .true.
3547 opt_embed%converged = .false.
3551 IF (output_unit > 0)
THEN
3552 WRITE (unit=output_unit, fmt=
"(/,T2,A)") &
3553 " Convergence check :"
3556 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3557 " Maximum density difference = ", max_diff
3558 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3559 " Convergence limit for max. density diff. = ", opt_embed%conv_max
3561 IF (opt_embed%open_shell_embed)
THEN
3563 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3564 " Maximum spin density difference = ", max_diff_spin
3565 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3566 " Convergence limit for max. spin dens.diff.= ", opt_embed%conv_max_spin
3570 IF (conv_max_diff)
THEN
3571 WRITE (unit=output_unit, fmt=
"(T2,2A)") &
3572 " Convergence in max. density diff. = ", &
3575 WRITE (unit=output_unit, fmt=
"(T2,2A)") &
3576 " Convergence in max. density diff. = ", &
3581 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3582 " Integrated density difference = ", int_diff
3583 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3584 " Conv. limit for integrated density diff. = ", opt_embed%conv_int
3585 IF (opt_embed%open_shell_embed)
THEN
3586 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3587 " Integrated spin density difference = ", int_diff_spin
3588 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3589 " Conv. limit for integrated spin dens.diff.= ", opt_embed%conv_int_spin
3592 IF (conv_int_diff)
THEN
3593 WRITE (unit=output_unit, fmt=
"(T2,2A)") &
3594 " Convergence in integrated density diff. = ", &
3597 WRITE (unit=output_unit, fmt=
"(T2,2A)") &
3598 " Convergence in integrated density diff. = ", &
3603 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3604 " Integrated squared density difference = ", int_diff_square
3605 IF (opt_embed%open_shell_embed)
THEN
3606 WRITE (unit=output_unit, fmt=
"(T2,A,F20.10)") &
3607 " Integrated squared spin density difference= ", int_diff_square_spin
3611 WRITE (unit=output_unit, fmt=
"(/,T2,A)") &
3612 " Maximum density change in:"
3613 DO i_dens = 1, (
SIZE(opt_embed%all_nspins) - 1)
3614 i_dens_start = sum(opt_embed%all_nspins(1:i_dens)) - opt_embed%all_nspins(i_dens) + 1
3615 DO i_spin = 1, opt_embed%all_nspins(i_dens)
3616 WRITE (unit=output_unit, fmt=
"(T4,A10,I3,A6,I3,A1,F20.10)") &
3617 " subsystem ", i_dens,
', spin', i_spin,
":", &
3618 opt_embed%max_subsys_dens_diff(i_dens_start + i_spin - 1)
3624 IF ((opt_embed%converged) .AND. (output_unit > 0))
THEN
3625 WRITE (unit=output_unit, fmt=
"(/,T2,A)") repeat(
"*", 79)
3626 WRITE (unit=output_unit, fmt=
"(T2,A,T25,A,T78,A)") &
3627 "***",
"EMBEDDING POTENTIAL OPTIMIZATION COMPLETED",
"***"
3628 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 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.
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)
...
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 calculate_wavefunction(mo_vectors, ivector, rho, rho_gspace, atomic_kind_set, qs_kind_set, cell, dft_control, particle_set, pw_env, basis_type, external_vector)
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_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, 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, 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, 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, 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, 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_r3d_rs_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_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>...