133 CHARACTER(LEN=*),
PARAMETER :: routinen =
'current_response'
135 CHARACTER(LEN=default_path_length) :: my_pos
136 INTEGER :: first_center, handle, i, icenter, idir, ii, iii, ispin, ist_true, istate, j, &
137 jcenter, jstate, max_nbr_center, max_states, nao, natom, nbr_center(2), ncubes, nmo, &
138 nspins, nstates(2), output_unit
139 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: first_sgf, last_sgf
140 INTEGER,
DIMENSION(:),
POINTER :: list_cubes, row_blk_sizes
141 INTEGER,
DIMENSION(:, :, :),
POINTER :: statetrueindex
142 LOGICAL :: append_cube, should_stop
143 REAL(
dp) :: dk(3), dkl(3), dl(3)
144 REAL(
dp),
ALLOCATABLE,
DIMENSION(:) :: dkl_vec_ii, dkl_vec_iii
145 REAL(
dp),
ALLOCATABLE,
DIMENSION(:, :) :: vecbuf_dklxp0
150 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_work_ii, fm_work_iii, h1_psi0, psi1
151 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: hpsi0_ptr, psi0_order
152 TYPE(
cp_fm_type),
DIMENSION(:, :),
POINTER :: p_psi0, psi1_d, psi1_p, psi1_rxp, &
164 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
168 CALL timeset(routinen, handle)
170 NULLIFY (cell, dft_control, linres_control, lr_section, current_section, &
171 logger, mpools, mo_coeff, para_env, &
173 list_cubes, statetrueindex, centers_set, center_list, psi1_p, psi1_rxp, psi1_d, &
174 p_psi0, rxp_psi0, psi0_order, op_p_ao, sab_orb, particle_set)
179 "PROPERTIES%LINRES%CURRENT")
182 extension=
".linresLog")
183 IF (output_unit > 0)
THEN
184 WRITE (unit=output_unit, fmt=
"(T10,A,/)") &
185 "*** Self consistent optimization of the response wavefunctions ***"
189 dft_control=dft_control, &
190 mpools=mpools, cell=cell, &
191 linres_control=linres_control, &
193 particle_set=particle_set, &
194 qs_kind_set=qs_kind_set, &
195 dbcsr_dist=dbcsr_dist, &
198 nspins = dft_control%nspins
203 centers_set=centers_set, &
204 nbr_center=nbr_center, &
205 center_list=center_list, &
206 list_cubes=list_cubes, &
207 statetrueindex=statetrueindex, &
213 psi0_order=psi0_order)
216 IF (current_env%full)
THEN
217 ALLOCATE (psi1(nspins), h1_psi0(nspins))
219 mo_coeff => psi0_order(ispin)
220 NULLIFY (tmp_fm_struct)
222 ncol_global=nstates(ispin), &
223 context=mo_coeff%matrix_struct%context)
230 natom =
SIZE(particle_set, 1)
231 ALLOCATE (first_sgf(natom))
232 ALLOCATE (last_sgf(natom))
234 first_sgf=first_sgf, &
236 ALLOCATE (row_blk_sizes(natom))
237 CALL dbcsr_convert_offsets_to_sizes(first_sgf, row_blk_sizes, last_sgf)
238 DEALLOCATE (first_sgf, last_sgf)
242 ALLOCATE (op_p_ao(1)%matrix)
245 dist=dbcsr_dist, matrix_type=dbcsr_type_antisymmetric, &
246 row_blk_size=row_blk_sizes, col_blk_size=row_blk_sizes, &
251 DEALLOCATE (row_blk_sizes)
254 CALL dbcsr_set(op_p_ao(1)%matrix, 0.0_dp)
256 ALLOCATE (op_p_ao(idir)%matrix)
257 CALL dbcsr_copy(op_p_ao(idir)%matrix, op_p_ao(1)%matrix, &
258 "current_env%op_p_ao"//
"-"//trim(adjustl(
cp_to_string(idir))))
259 CALL dbcsr_set(op_p_ao(idir)%matrix, 0.0_dp)
273 IF (current_env%full)
CALL cp_fm_set_all(psi1_d(ispin, idir), 0.0_dp)
282 IF (linres_control%linres_restart)
THEN
294 should_stop = .false.
295 current_env%all_pert_op_done = .false.
298 IF (should_stop)
EXIT
299 IF (output_unit > 0)
THEN
300 WRITE (output_unit,
"(T10,A)")
"Response to the perturbation operator P_"//achar(idir + 119)
304 hpsi0_ptr => p_psi0(:, idir)
307 linres_control%converged = .false.
308 CALL linres_solver(p_env, qs_env, psi1_p(:, idir), hpsi0_ptr, psi0_order, output_unit, should_stop)
313 &
"PRINT%RESPONSE_FUNCTION_CUBES"),
cp_p_file))
THEN
314 ncubes =
SIZE(list_cubes, 1)
316 append_cube =
section_get_lval(current_section,
"PRINT%RESPONSE_FUNCTION_CUBES%APPEND")
318 IF (append_cube)
THEN
324 CALL qs_print_cubes(qs_env, psi1_p(ispin, idir), ncubes, list_cubes, &
325 centers_set(ispin)%array, print_key,
'psi1_p', &
326 idir=idir, ispin=ispin, file_position=my_pos)
336 IF (should_stop)
EXIT
337 IF (output_unit > 0)
THEN
338 WRITE (output_unit,
"(T10,A)")
"Response to the perturbation operator L_"//achar(idir + 119)
342 hpsi0_ptr => rxp_psi0(:, idir)
345 linres_control%converged = .false.
346 CALL linres_solver(p_env, qs_env, psi1_rxp(:, idir), hpsi0_ptr, psi0_order, output_unit, should_stop)
350 &
"PRINT%RESPONSE_FUNCTION_CUBES"),
cp_p_file))
THEN
351 ncubes =
SIZE(list_cubes, 1)
355 CALL qs_print_cubes(qs_env, psi1_rxp(ispin, idir), ncubes, list_cubes, &
356 centers_set(ispin)%array, print_key,
'psi1_rxp', &
357 idir=idir, ispin=ispin, file_position=my_pos)
364 IF (.NOT. should_stop) current_env%all_pert_op_done = .true.
367 IF (current_env%full)
THEN
368 current_env%all_pert_op_done = .false.
376 max_nbr_center = maxval(nbr_center(1:nspins))
377 max_states = maxval(nstates(1:nspins))
379 ALLOCATE (vecbuf_dklxp0(1, nao), fm_work_ii(nspins), fm_work_iii(nspins), &
380 dkl_vec_ii(max_states), dkl_vec_iii(max_states))
381 vecbuf_dklxp0(1, nao) = 0.0_dp
385 mo_coeff => psi0_order(ispin)
386 NULLIFY (tmp_fm_struct)
388 ncol_global=nmo, para_env=para_env, &
389 context=mo_coeff%matrix_struct%context)
399 IF (should_stop)
EXIT
404 IF (linres_control%linres_restart)
THEN
405 CALL linres_read_restart(qs_env, lr_section, psi1_d(:, idir), idir,
"nmr_dxp-", ind=first_center)
407 IF (first_center > 0)
THEN
408 IF (output_unit > 0)
THEN
409 WRITE (output_unit,
"(T10,A,I4,A)")&
410 &
"Response to the perturbation operators (dk-dl)xp up to state ", &
411 first_center,
" have been read from restart"
417 DO icenter = 1, max_nbr_center
419 IF (should_stop)
EXIT
420 IF (icenter > first_center)
THEN
421 IF (output_unit > 0)
THEN
422 WRITE (output_unit,
"(T10,A,I4,A)")&
423 &
"Response to the perturbation operator (dk-dl)xp for -state- ", &
424 icenter,
" in dir. "//achar(idir + 119)
429 mo_coeff => psi0_order(ispin)
432 IF (icenter .GT. nbr_center(ispin))
THEN
440 dkl_vec_ii(:) = 0.0_dp
441 dkl_vec_iii(:) = 0.0_dp
443 ist_true = statetrueindex(idir, icenter, ispin)
447 dk(1:3) = centers_set(ispin)%array(1:3, ist_true)
449 DO jcenter = 1, nbr_center(ispin)
450 dl(1:3) = centers_set(ispin)%array(1:3, jcenter)
451 dkl =
pbc(dl, dk, cell)
452 DO j = center_list(ispin)%array(1, jcenter), center_list(ispin)%array(1, jcenter + 1) - 1
453 jstate = center_list(ispin)%array(2, j)
454 dkl_vec_ii(jstate) = dkl(ii)
455 dkl_vec_iii(jstate) = dkl(iii)
467 fm_work_iii(ispin), ncol=nmo, alpha=-1.0_dp)
471 CALL cp_fm_to_fm(fm_work_iii(ispin), h1_psi0(ispin))
481 fm_work_ii(ispin), ncol=nmo, alpha=-1.0_dp)
486 & -1.0_dp, fm_work_ii(ispin))
491 CALL linres_solver(p_env, qs_env, psi1, h1_psi0, psi0_order, output_unit, should_stop)
493 IF (output_unit > 0)
THEN
494 WRITE (output_unit,
"(T10,A,/)")&
495 &
"Store the psi1 vector for the calculation of the response current density "
501 IF (icenter .GT. nbr_center(ispin)) cycle
504 ist_true = statetrueindex(idir, icenter, ispin)
505 DO i = center_list(ispin)%array(1, ist_true), center_list(ispin)%array(1, ist_true + 1) - 1
506 istate = center_list(ispin)%array(2, i)
509 CALL cp_fm_to_fm(psi1(ispin), psi1_d(ispin, idir), 1, istate, istate)
511 current_env%full_done(idir*ispin, icenter) = .true.
516 current_env%full_done(idir*ispin, icenter) = .true.
525 &
"PRINT%RESPONSE_FUNCTION_CUBES"),
cp_p_file))
THEN
526 ncubes =
SIZE(list_cubes, 1)
530 ncubes, list_cubes, centers_set(ispin)%array, print_key,
'psi1_D', &
531 idir=idir, ispin=ispin, file_position=my_pos)
536 IF (.NOT. should_stop) current_env%all_pert_op_done = .true.
541 DEALLOCATE (dkl_vec_ii, dkl_vec_iii, vecbuf_dklxp0)
546 IF (current_env%full)
THEN
553 &
"PRINT%PROGRAM_RUN_INFO")
555 CALL timestop(handle)
571 CHARACTER(LEN=*),
PARAMETER :: routinen =
'current_env_init'
573 INTEGER :: handle, homo, i, iao, iatom, ibox, icenter, icount, idir, ii, ini, ir, is, ispin, &
574 istate, istate2, istate_next, ix, iy, iz, j, jstate, k, max_nbr_center, max_states, n, &
575 n_rep, nao, natom, nbr_box, ncubes, nmo, nspins, nstate, nstate_list(2), output_unit
576 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: buff, first_sgf, last_sgf
577 INTEGER,
ALLOCATABLE,
DIMENSION(:, :) :: state_list
578 INTEGER,
DIMENSION(:),
POINTER :: bounds,
list, nbox, &
579 selected_states_on_atom_list
580 LOGICAL :: force_no_full, gapw, is0, &
582 LOGICAL,
ALLOCATABLE,
DIMENSION(:, :) :: state_done
583 REAL(
dp) :: center(3), center2(3), dist, mdist, &
585 REAL(
dp),
ALLOCATABLE,
DIMENSION(:, :) :: rbuff
586 REAL(
dp),
DIMENSION(:),
POINTER :: common_center
587 REAL(
dp),
DIMENSION(:, :),
POINTER :: center_array
604 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
610 CALL timeset(routinen, handle)
612 NULLIFY (atomic_kind_set, qs_kind_set, cell, dft_control, linres_control, scf_control, &
613 logger, mos, mpools, current_section, particle_set, mo_coeff, &
614 auxbas_pw_pool, pw_env, jrho1_atom_set, common_center, tmp_fm_struct, &
615 para_env, qs_loc_env, localized_wfn_control, rho_g, rho_r)
619 atomic_kind_set=atomic_kind_set, &
620 qs_kind_set=qs_kind_set, &
622 dft_control=dft_control, &
623 linres_control=linres_control, &
626 particle_set=particle_set, &
628 scf_control=scf_control, &
631 gapw = dft_control%qs_control%gapw
632 nspins = dft_control%nspins
633 natom =
SIZE(particle_set, 1)
639 max_states = max(max_states, nmo)
646 CALL get_mo_set(mo_set=mos(ispin), nmo=nmo, homo=homo, &
647 uniform_occupation=uniform_occupation)
650 IF (nmo .NE. homo) cpabort(
"nmo != homo")
659 IF (.NOT. uniform_occupation) cpabort(
"nmo != homo")
666 extension=
".linresLog")
668 IF (output_unit > 0)
THEN
669 WRITE (output_unit,
"(/,T20,A,/)")
"*** Start current Calculation ***"
670 WRITE (output_unit,
"(T10,A,/)")
"Inizialization of the current environment"
674 current_env%gauge_init = .false.
675 current_env%chi_tensor(:, :, :) = 0.0_dp
676 current_env%chi_tensor_loc(:, :, :) = 0.0_dp
677 current_env%nao = nao
678 current_env%full = .true.
679 current_env%do_selected_states = .false.
686 SELECT CASE (current_env%gauge)
688 current_env%gauge_name =
"R"
690 current_env%gauge_name =
"R_AND_STEP_FUNCTION"
692 current_env%gauge_name =
"ATOM"
694 cpabort(
"Unknown gauge, try again...")
699 r_val=current_env%gauge_atom_radius)
702 l_val=current_env%use_old_gauge_atom)
708 l_val=current_env%use_old_gauge_atom)
715 SELECT CASE (current_env%orb_center)
718 current_env%orb_center_name =
"WANNIER"
721 current_env%orb_center_name =
"COMMON"
722 current_env%full = .false.
728 current_env%orb_center_name =
"ATOM"
731 current_env%orb_center_name =
"BOX"
736 cpabort(
"Unknown orbital center, try again...")
740 IF (force_no_full) current_env%full = .false.
748 cpassert(linres_control%localized_psi0)
749 IF (output_unit > 0)
THEN
750 WRITE (output_unit,
'(A)') &
751 ' To get CURRENT parameters within PBC you need localized zero order orbitals '
753 qs_loc_env => linres_control%qs_loc_env
754 CALL get_qs_loc_env(qs_loc_env, localized_wfn_control=localized_wfn_control)
757 ALLOCATE (current_env%centers_set(nspins), current_env%center_list(nspins), &
758 state_list(max_states, nspins))
759 state_list(:, :) = huge(0)
760 nstate_list(:) = huge(0)
765 IF (current_env%do_qmmm)
THEN
767 DO istate = 1,
SIZE(localized_wfn_control%centers_set(ispin)%array, 2)
769 r(:) =
pbc(localized_wfn_control%centers_set(ispin)%array(:, istate), cell)
770 IF (r(1) .LT. 0.0_dp)
THEN
771 localized_wfn_control%centers_set(ispin)%array(1, istate) = &
772 r(1) + cell%hmat(1, 1)
774 IF (r(2) .LT. 0.0_dp)
THEN
775 localized_wfn_control%centers_set(ispin)%array(2, istate) = &
776 r(2) + cell%hmat(2, 2)
778 IF (r(3) .LT. 0.0_dp)
THEN
779 localized_wfn_control%centers_set(ispin)%array(3, istate) = &
780 r(3) + cell%hmat(3, 3)
791 r_val=current_env%selected_states_atom_radius)
794 current_env%do_selected_states = n_rep .GT. 0
797 IF (linres_control%preconditioner_type .EQ.
ot_precond_full_all .AND. current_env%do_selected_states) &
798 cpabort(
"Selected states doesnt work with the preconditioner FULL_ALL")
801 NULLIFY (current_env%selected_states_on_atom_list)
806 i_rep_val=ir, i_vals=
list)
807 IF (
ASSOCIATED(
list))
THEN
808 CALL reallocate(current_env%selected_states_on_atom_list, 1, n +
SIZE(
list))
809 DO ini = 1,
SIZE(
list)
810 current_env%selected_states_on_atom_list(ini + n) =
list(ini)
817 IF (current_env%do_selected_states)
THEN
818 selected_states_on_atom_list => current_env%selected_states_on_atom_list
820 center_array => localized_wfn_control%centers_set(ispin)%array
822 DO istate = 1,
SIZE(center_array, 2)
823 DO i = 1,
SIZE(selected_states_on_atom_list, 1)
824 iatom = selected_states_on_atom_list(i)
825 r(:) =
pbc(center_array(1:3, istate) - particle_set(iatom)%r(:), cell)
827 IF ((dot_product(r, r)) .LE. (current_env%selected_states_atom_radius &
828 *current_env%selected_states_atom_radius)) &
833 state_list(nstate, ispin) = istate
838 nstate_list(ispin) = nstate
842 center_array => localized_wfn_control%centers_set(ispin)%array
844 DO istate = 1,
SIZE(center_array, 2)
846 state_list(nstate, ispin) = istate
848 nstate_list(ispin) = nstate
856 nstate = nstate_list(ispin)
857 current_env%nstates(ispin) = nstate
859 ALLOCATE (current_env%center_list(ispin)%array(2, nstate + 1), &
860 current_env%centers_set(ispin)%array(3, nstate))
861 current_env%center_list(ispin)%array(:, :) = huge(0)
862 current_env%centers_set(ispin)%array(:, :) = huge(0.0_dp)
864 center_array => localized_wfn_control%centers_set(ispin)%array
867 SELECT CASE (current_env%orb_center)
871 current_env%nbr_center(ispin) = nstate
873 istate = state_list(is, ispin)
874 current_env%centers_set(ispin)%array(1:3, is) = center_array(1:3, istate)
875 current_env%center_list(ispin)%array(1, is) = is
876 current_env%center_list(ispin)%array(2, is) = istate
878 current_env%center_list(ispin)%array(1, nstate + 1) = nstate + 1
883 current_env%centers_set(ispin)%array(:, 1) = common_center(:)
884 current_env%nbr_center(ispin) = 1
885 current_env%center_list(ispin)%array(1, 1) = 1
886 current_env%center_list(ispin)%array(1, 2) = nstate + 1
888 istate = state_list(is, ispin)
889 current_env%center_list(ispin)%array(2, is) = istate
895 ALLOCATE (buff(nstate_list(ispin)))
899 istate = state_list(is, ispin)
902 r =
pbc(particle_set(iatom)%r(:), cell)
903 rab =
pbc(r, center_array(1:3, istate), cell)
904 dist = sqrt(rab(1)**2 + rab(2)**2 + rab(3)**2)
905 IF (dist .LT. mdist)
THEN
914 current_env%center_list(ispin)%array(1, 1) = 1
919 istate = state_list(is, ispin)
920 IF (buff(is) .EQ. iatom)
THEN
924 current_env%center_list(ispin)%array(2, i) = istate
928 IF (output_unit > 0)
THEN
929 WRITE (output_unit,
'(T2,A,I6,A,I6)')
'clustering ', j,
' center(s) on atom ', iatom
931 current_env%center_list(ispin)%array(1, ii + 1) = &
932 current_env%center_list(ispin)%array(1, ii) + j
933 current_env%centers_set(ispin)%array(:, ii) = &
934 pbc(particle_set(iatom)%r, cell)
938 current_env%nbr_center(ispin) = ii - 1
944 nbr_box = nbox(1)*nbox(2)*nbox(3)
945 ALLOCATE (rbuff(3, nbr_box), buff(nstate))
946 rbuff(:, :) = huge(0.0_dp)
953 rbuff(1, ibox) = cell%hmat(1, 1)*((real(ix,
dp) - 0.5_dp)/real(nbox(1),
dp) - 0.5_dp)
954 rbuff(2, ibox) = cell%hmat(2, 2)*((real(iy,
dp) - 0.5_dp)/real(nbox(2),
dp) - 0.5_dp)
955 rbuff(3, ibox) = cell%hmat(3, 3)*((real(iz,
dp) - 0.5_dp)/real(nbox(3),
dp) - 0.5_dp)
962 istate = state_list(is, ispin)
965 rab(:) =
pbc(rbuff(:, ibox), center_array(1:3, istate), cell)
966 dist = sqrt(rab(1)**2 + rab(2)**2 + rab(3)**2)
967 IF (dist .LT. mdist)
THEN
976 current_env%center_list(ispin)%array(1, 1) = 1
981 istate = state_list(is, ispin)
982 IF (buff(is) .EQ. ibox)
THEN
986 current_env%center_list(ispin)%array(2, i) = istate
990 IF (output_unit > 0)
THEN
991 WRITE (output_unit,
'(T2,A,I6,A,I6)')
'clustering ', j,
' center(s) on box ', ibox
993 current_env%center_list(ispin)%array(1, ii + 1) = &
994 current_env%center_list(ispin)%array(1, ii) + j
995 current_env%centers_set(ispin)%array(:, ii) = rbuff(:, ibox)
999 current_env%nbr_center(ispin) = ii - 1
1001 DEALLOCATE (buff, rbuff)
1003 cpabort(
"Unknown orbital center, try again...")
1010 ALLOCATE (current_env%psi0_order(nspins))
1011 DO ispin = 1, nspins
1012 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff)
1013 NULLIFY (tmp_fm_struct)
1015 ncol_global=nstate_list(ispin), para_env=para_env, &
1016 context=mo_coeff%matrix_struct%context)
1017 CALL cp_fm_create(current_env%psi0_order(ispin), tmp_fm_struct)
1023 DO ispin = 1, nspins
1024 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff)
1026 DO icenter = 1, current_env%nbr_center(ispin)
1027 DO i = current_env%center_list(ispin)%array(1, icenter), &
1028 current_env%center_list(ispin)%array(1, icenter + 1) - 1
1030 istate = current_env%center_list(ispin)%array(2, i)
1033 IF (current_env%do_selected_states)
THEN
1036 current_env%center_list(ispin)%array(2, i) = jstate
1037 CALL cp_fm_to_fm(mo_coeff, current_env%psi0_order(ispin), 1, istate, jstate)
1040 CALL cp_fm_to_fm(mo_coeff, current_env%psi0_order(ispin), 1, istate, istate)
1049 IF (current_env%do_qmmm .AND.&
1053 IF (output_unit > 0)
THEN
1054 WRITE (output_unit, *)
'WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING '
1055 WRITE (output_unit, *)
'orbital center shifted to match the '
1056 WRITE (output_unit, *)
'center of the box (L/2 L/2 L/2) (superdirty...)'
1057 WRITE (output_unit, *)
'WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING '
1059 DO ispin = 1, nspins
1060 DO istate = 1, current_env%nbr_center(ispin)
1061 IF (current_env%centers_set(ispin)%array(1, istate) .LE. 0.0_dp)
THEN
1062 current_env%centers_set(ispin)%array(1, istate) = &
1063 current_env%centers_set(ispin)%array(1, istate) + cell%hmat(1, 1)
1065 IF (current_env%centers_set(ispin)%array(2, istate) .LE. 0.0_dp)
THEN
1066 current_env%centers_set(ispin)%array(2, istate) = &
1067 current_env%centers_set(ispin)%array(2, istate) + cell%hmat(2, 2)
1069 IF (current_env%centers_set(ispin)%array(3, istate) .LE. 0.0_dp)
THEN
1070 current_env%centers_set(ispin)%array(3, istate) = &
1071 current_env%centers_set(ispin)%array(3, istate) + cell%hmat(3, 3)
1076 DO ispin = 1, nspins
1077 IF (output_unit > 0)
THEN
1078 WRITE (output_unit,
'(/,T2,A,I2)')
"WANNIER CENTERS for spin ", ispin
1079 WRITE (output_unit,
'(/,T18,A)')
"--------------- Shifted Centers --------------- "
1080 DO istate = 1, current_env%nbr_center(ispin)
1081 WRITE (output_unit,
'(T5,A,I6,3F12.6)') &
1082 'state ', istate, current_env%centers_set(ispin)%array(1:3, istate)
1091 max_nbr_center = maxval(current_env%nbr_center(1:nspins))
1092 current_env%nao = nao
1093 ALLOCATE (current_env%statetrueindex(3, max_nbr_center, nspins))
1094 current_env%statetrueindex(:, :, :) = 0
1096 ALLOCATE (state_done(3, max_nbr_center))
1097 DO ispin = 1, nspins
1098 state_done(:, :) = .false.
1099 current_env%statetrueindex(1, 1, ispin) = 1
1100 center(1) = current_env%centers_set(ispin)%array(1, 1)
1101 center(2) = current_env%centers_set(ispin)%array(2, 1)
1102 center(3) = current_env%centers_set(ispin)%array(3, 1)
1103 state_done(1, 1) = .true.
1109 IF (idir == 1) ini = 2
1110 DO istate = ini, current_env%nbr_center(ispin)
1111 mdist = huge(0.0_dp)
1113 DO istate2 = 1, current_env%nbr_center(ispin)
1114 IF (.NOT. state_done(idir, istate2))
THEN
1115 center2(1) = current_env%centers_set(ispin)%array(1, istate2)
1116 center2(2) = current_env%centers_set(ispin)%array(2, istate2)
1117 center2(3) = current_env%centers_set(ispin)%array(3, istate2)
1119 rab =
pbc(center, center2, cell)
1121 dist = sqrt(rab(j)*rab(j) + rab(k)*rab(k))
1123 IF (dist .LT. mdist)
THEN
1125 istate_next = istate2
1131 state_done(idir, istate_next) = .true.
1132 current_env%statetrueindex(idir, icount, ispin) = istate_next
1133 center(1) = current_env%centers_set(ispin)%array(1, istate_next)
1134 center(2) = current_env%centers_set(ispin)%array(2, istate_next)
1135 center(3) = current_env%centers_set(ispin)%array(3, istate_next)
1140 DEALLOCATE (state_done)
1142 DO ispin = 1, nspins
1143 DO icenter = 1, current_env%nbr_center(ispin)
1144 current_env%statetrueindex(:, icenter, ispin) = icenter
1150 IF (output_unit > 0)
THEN
1151 WRITE (output_unit,
"(T2,A,T60,A)")
"CURRENT| Gauge used", &
1152 repeat(
' ', 20 - len_trim(current_env%gauge_name))//trim(current_env%gauge_name)
1153 WRITE (output_unit,
"(T2,A,T79,L1)")
"CURRENT| Use old gauge code", current_env%use_old_gauge_atom
1154 WRITE (output_unit,
"(T2,A,T79,L1)")
"CURRENT| Compute chi for PBC calculation", current_env%chi_pbc
1156 WRITE (output_unit,
"(T2,A,T68,E12.6)")
"CURRENT| Radius for building the gauge", &
1157 current_env%gauge_atom_radius
1159 WRITE (output_unit,
"(T2,A,T60,A)")
"CURRENT| Orbital center used", &
1160 repeat(
' ', 20 - len_trim(current_env%orb_center_name))//trim(current_env%orb_center_name)
1162 WRITE (output_unit,
"(T2,A,T50,3F10.6)")
"CURRENT| Common center", common_center(1:3)
1164 WRITE (output_unit,
"(T2,A,T60,3I5)")
"CURRENT| Nbr boxes in each direction", nbox(1:3)
1167 DO ispin = 1, nspins
1169 WRITE (output_unit,
'(T2,A,I6,A,I6,A,I2)')
'CURRENT| Compute', &
1170 nstate_list(ispin),
' selected response functions out of', &
1171 nmo,
' for spin ', ispin
1173 WRITE (output_unit,
'(T2,A,I6,A,I2)')
'CURRENT| There is a total of ', &
1174 current_env%nbr_center(ispin),
' (clustered) center(s) for spin ', ispin
1179 &
"PRINT%RESPONSE_FUNCTION_CUBES"),
cp_p_file))
THEN
1181 NULLIFY (bounds,
list)
1184 &
"PRINT%RESPONSE_FUNCTION_CUBES%CUBES_LU_BOUNDS", &
1186 ncubes = bounds(2) - bounds(1) + 1
1187 IF (ncubes > 0)
THEN
1188 ALLOCATE (current_env%list_cubes(ncubes))
1190 current_env%list_cubes(ir) = bounds(1) + (ir - 1)
1193 IF (.NOT.
ASSOCIATED(current_env%list_cubes))
THEN
1200 i_rep_val=ir, i_vals=
list)
1201 IF (
ASSOCIATED(
list))
THEN
1203 DO ini = 1,
SIZE(
list)
1204 current_env%list_cubes(ini + ncubes) =
list(ini)
1206 ncubes = ncubes +
SIZE(
list)
1210 IF (.NOT.
ASSOCIATED(current_env%list_cubes))
THEN
1211 ALLOCATE (current_env%list_cubes(max_states))
1212 DO ir = 1, max_states
1213 current_env%list_cubes(ir) = ir
1218 &
"PRINT%CURRENT_CUBES"),
cp_p_file))
THEN
1234 ALLOCATE (current_env%p_psi0(nspins, 3), current_env%rxp_psi0(nspins, 3), &
1235 current_env%psi1_p(nspins, 3), current_env%psi1_rxp(nspins, 3))
1236 IF (current_env%full)
THEN
1237 ALLOCATE (current_env%psi1_D(nspins, 3))
1239 DO ispin = 1, nspins
1240 mo_coeff => current_env%psi0_order(ispin)
1241 NULLIFY (tmp_fm_struct)
1243 ncol_global=current_env%nstates(ispin), &
1244 context=mo_coeff%matrix_struct%context)
1246 CALL cp_fm_create(current_env%psi1_p(ispin, idir), tmp_fm_struct)
1247 CALL cp_fm_create(current_env%psi1_rxp(ispin, idir), tmp_fm_struct)
1248 CALL cp_fm_create(current_env%p_psi0(ispin, idir), tmp_fm_struct)
1249 CALL cp_fm_create(current_env%rxp_psi0(ispin, idir), tmp_fm_struct)
1250 IF (current_env%full)
THEN
1251 CALL cp_fm_create(current_env%psi1_D(ispin, idir), tmp_fm_struct)
1258 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
1259 ALLOCATE (current_env%jrho1_set(3))
1261 NULLIFY (rho_r, rho_g)
1262 ALLOCATE (rho_r(nspins), rho_g(nspins))
1263 DO ispin = 1, nspins
1264 CALL auxbas_pw_pool%create_pw(rho_r(ispin))
1266 CALL auxbas_pw_pool%create_pw(rho_g(ispin))
1269 NULLIFY (current_env%jrho1_set(idir)%rho)
1270 ALLOCATE (current_env%jrho1_set(idir)%rho)
1272 CALL qs_rho_set(current_env%jrho1_set(idir)%rho, &
1273 rho_r=rho_r, rho_g=rho_g)
1279 CALL set_current_env(current_env=current_env, jrho1_atom_set=jrho1_atom_set)
1282 ALLOCATE (current_env%basisfun_center(3, current_env%nao), &
1283 first_sgf(natom), last_sgf(natom))
1284 current_env%basisfun_center = 0.0_dp
1286 first_sgf=first_sgf, &
1291 DO iao = first_sgf(iatom), last_sgf(iatom)
1293 current_env%basisfun_center(idir, iao) = particle_set(iatom)%r(idir)
1298 DEALLOCATE (first_sgf, last_sgf, state_list)
1300 current_env%simple_done(1:6) = .false.
1302 ALLOCATE (current_env%full_done(3*nspins, max_nbr_center))
1303 current_env%full_done = .false.
1306 ALLOCATE (current_env%rs_gauge(3, pw_env%gridlevel_info%ngrid_levels))
1309 CALL timestop(handle)
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs)
Get the QUICKSTEP environment.