(git:e7e05ae)
qs_tddfpt2_lri_utils.F
Go to the documentation of this file.
1 !--------------------------------------------------------------------------------------------------!
2 ! CP2K: A general program to perform molecular dynamics simulations !
3 ! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4 ! !
5 ! SPDX-License-Identifier: GPL-2.0-or-later !
6 !--------------------------------------------------------------------------------------------------!
7 
9 
10  USE atomic_kind_types, ONLY: atomic_kind_type
15  gto_basis_set_type,&
18  USE cell_types, ONLY: cell_type
19  USE cp_control_types, ONLY: dft_control_type,&
20  tddfpt2_control_type
22  USE dbcsr_api, ONLY: dbcsr_copy,&
23  dbcsr_deallocate_matrix,&
24  dbcsr_p_type
25  USE distribution_1d_types, ONLY: distribution_1d_type
26  USE distribution_2d_types, ONLY: distribution_2d_type
29  section_vals_type,&
31  USE kinds, ONLY: dp
35  USE lri_environment_types, ONLY: lri_environment_type,&
36  lri_kind_type
38  USE message_passing, ONLY: mp_para_env_type
39  USE molecule_types, ONLY: molecule_type
42  USE particle_types, ONLY: particle_type
43  USE qs_environment_types, ONLY: get_qs_env,&
44  qs_environment_type
46  USE qs_kernel_types, ONLY: kernel_env_type
47  USE qs_kind_types, ONLY: get_qs_kind,&
49  qs_kind_type
50  USE qs_neighbor_list_types, ONLY: neighbor_list_set_p_type
51  USE qs_neighbor_lists, ONLY: atom2d_build,&
54  local_atoms_type,&
58  tddfpt_subgroup_env_type
59 #include "./base/base_uses.f90"
60 
61  IMPLICIT NONE
62 
63  PRIVATE
64 
65  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_tddfpt2_lri_utils'
66 
68 
69 CONTAINS
70 
71 ! **************************************************************************************************
72 !> \brief Initialize LRI environment, basis, neighborlists and matrices
73 !> \param qs_env ...
74 !> \param kernel_env ...
75 !> \param lri_section ...
76 !> \param tddfpt_print_section ...
77 ! **************************************************************************************************
78  SUBROUTINE tddfpt2_lri_init(qs_env, kernel_env, lri_section, tddfpt_print_section)
79 
80  TYPE(qs_environment_type), INTENT(IN), POINTER :: qs_env
81  TYPE(kernel_env_type) :: kernel_env
82  TYPE(section_vals_type), INTENT(IN), POINTER :: lri_section, tddfpt_print_section
83 
84  CHARACTER(len=*), PARAMETER :: routinen = 'tddfpt2_lri_init'
85 
86  INTEGER :: basis_sort, handle, ikind, lmax_sphere, &
87  maxl, maxlgto, maxlgto_lri, nkind
88  LOGICAL :: explicit, mic, molecule_only, &
89  redefine_interaction_radii
90  LOGICAL, ALLOCATABLE, DIMENSION(:) :: orb_present
91  REAL(dp) :: subcells
92  REAL(dp), ALLOCATABLE, DIMENSION(:) :: orb_radius
93  REAL(dp), ALLOCATABLE, DIMENSION(:, :) :: pair_radius
94  TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
95  TYPE(cell_type), POINTER :: cell
96  TYPE(dft_control_type), POINTER :: dft_control
97  TYPE(distribution_1d_type), POINTER :: distribution_1d
98  TYPE(distribution_2d_type), POINTER :: distribution_2d
99  TYPE(gto_basis_set_type), POINTER :: orb_basis_set, p_lri_aux_basis
100  TYPE(local_atoms_type), ALLOCATABLE, DIMENSION(:) :: atom2d
101  TYPE(lri_environment_type), POINTER :: lri_env
102  TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
103  TYPE(mp_para_env_type), POINTER :: para_env
104  TYPE(neighbor_list_set_p_type), DIMENSION(:), &
105  POINTER :: soo_list
106  TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
107  TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
108  TYPE(qs_kind_type), POINTER :: qs_kind
109  TYPE(section_vals_type), POINTER :: neighbor_list_section, print_section
110  TYPE(tddfpt2_control_type), POINTER :: tddfpt2_control
111 
112  CALL timeset(routinen, handle)
113 
114  CALL get_qs_env(qs_env, dft_control=dft_control)
115  tddfpt2_control => dft_control%tddfpt2_control
116 
117  NULLIFY (kernel_env%full_kernel%lri_env)
118  ! initialize lri_env
119  CALL lri_env_init(kernel_env%full_kernel%lri_env, lri_section)
120  NULLIFY (lri_env)
121  lri_env => kernel_env%full_kernel%lri_env
122  redefine_interaction_radii = .false.
123 
124  ! exact_1c_terms not implemented
125  IF (lri_env%exact_1c_terms) THEN
126  cpabort("TDDFT with LRI and exact one-center terms not implemented")
127  END IF
128 
129  ! check if LRI_AUX basis is available
130  CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set)
131  nkind = SIZE(qs_kind_set)
132  DO ikind = 1, nkind
133  NULLIFY (p_lri_aux_basis)
134  qs_kind => qs_kind_set(ikind)
135  CALL get_qs_kind(qs_kind, basis_set=p_lri_aux_basis, basis_type="P_LRI_AUX")
136  IF (.NOT. (ASSOCIATED(p_lri_aux_basis))) THEN
137  ! Generate a default basis
138  redefine_interaction_radii = .true.
139  CALL create_lri_aux_basis_set(p_lri_aux_basis, qs_kind, &
140  dft_control%auto_basis_p_lri_aux, lri_env%exact_1c_terms, &
141  tda_kernel=.true.)
142  CALL add_basis_set_to_container(qs_kind%basis_sets, p_lri_aux_basis, "P_LRI_AUX")
143  END IF
144  END DO !nkind
145  ! needs to be done here if p_lri_aux_basis is not specified explicitly
146  IF (redefine_interaction_radii) THEN
147  DO ikind = 1, nkind
148  CALL get_qs_kind(qs_kind_set(ikind), basis_set=p_lri_aux_basis, basis_type="P_LRI_AUX")
149  IF (ASSOCIATED(p_lri_aux_basis)) THEN
150  CALL init_orb_basis_set(p_lri_aux_basis) ! standardly done in init_qs_kind
151  basis_sort = 0
152  CALL sort_gto_basis_set(p_lri_aux_basis, basis_sort)
153  CALL init_interaction_radii_orb_basis(p_lri_aux_basis, dft_control%qs_control%eps_pgf_orb)
154  END IF
155  END DO
156  END IF
157 
158  print_section => section_vals_get_subs_vals(tddfpt_print_section, "BASIS_SET_FILE")
159  CALL section_vals_get(print_section, explicit=explicit)
160  IF (explicit) THEN
161  CALL print_basis_set_file(qs_env, print_section)
162  END IF
163 
164  !set maxl as in qs_environment for gs lri
165  CALL get_qs_kind_set(qs_kind_set, maxlgto=maxlgto)
166  CALL get_qs_kind_set(qs_kind_set, maxlgto=maxlgto_lri, basis_type="P_LRI_AUX")
167  !take maxlgto from lri basis if larger (usually)
168  maxlgto = max(maxlgto, maxlgto_lri)
169  lmax_sphere = 2*maxlgto
170  maxl = max(2*maxlgto, lmax_sphere) + 1
171 
172  CALL init_orbital_pointers(maxl)
173  CALL init_spherical_harmonics(maxl, 0)
174 
175  ! initialize LRI basis sets
176  CALL lri_env_basis("P_LRI", qs_env, lri_env, qs_kind_set)
177 
178 ! check for debugging that automatically generated basis is available
179 ! DO ikind= 1, nkind
180 ! qs_kind => qs_kind_set(ikind)
181 ! CALL get_qs_kind(qs_kind, basis_set=p_lri_aux_basis, basis_type="P_LRI_AUX")
182 ! CALL get_gto_basis_set(gto_basis_set=p_lri_aux_basis, set_radius=set_radius,&
183 ! pgf_radius=pgf_radius)
184 ! END DO !nkind
185 
186  ! set up LRI neighbor list soo_list => same as in qs_neighbor_lists for ground-state LRI
187  NULLIFY (cell, para_env, particle_set)
188  CALL get_qs_env(qs_env, para_env=para_env, cell=cell, particle_set=particle_set)
189 
190  NULLIFY (distribution_1d, distribution_2d, atomic_kind_set, molecule_set)
191  CALL get_qs_env(qs_env, local_particles=distribution_1d, distribution_2d=distribution_2d, &
192  atomic_kind_set=atomic_kind_set, molecule_set=molecule_set)
193 
194  ALLOCATE (atom2d(nkind))
195  molecule_only = .false. !this still needs to be checked
196  CALL atom2d_build(atom2d, distribution_1d, distribution_2d, atomic_kind_set, &
197  molecule_set, molecule_only, particle_set=particle_set)
198 
199  ALLOCATE (orb_present(nkind), orb_radius(nkind), pair_radius(nkind, nkind))
200  orb_radius(:) = 0.0_dp
201  pair_radius(:, :) = 0.0_dp
202  orb_present(:) = .false.
203  DO ikind = 1, nkind
204  CALL get_qs_kind(qs_kind_set(ikind), basis_set=orb_basis_set, basis_type="ORB")
205  IF (ASSOCIATED(orb_basis_set)) THEN
206  orb_present(ikind) = .true.
207  CALL get_gto_basis_set(gto_basis_set=orb_basis_set, kind_radius=orb_radius(ikind))
208  ELSE
209  orb_present(ikind) = .false.
210  END IF
211  END DO ! ikind
212 
213  CALL pair_radius_setup(orb_present, orb_present, orb_radius, orb_radius, pair_radius)
214 
215  NULLIFY (soo_list)
216  soo_list => lri_env%soo_list
217  mic = .true. !enforcing minimum image convention
218  CALL section_vals_val_get(qs_env%input, "DFT%SUBCELLS", r_val=subcells)
219  CALL build_neighbor_lists(soo_list, particle_set, atom2d, cell, pair_radius, &
220  mic=mic, molecular=molecule_only, subcells=subcells, nlname="soo_list")
221 
222  ! make this a TDDFT neighborlist
223  neighbor_list_section => section_vals_get_subs_vals(qs_env%input, "DFT%PRINT%NEIGHBOR_LISTS")
224  CALL write_neighbor_lists(soo_list, particle_set, cell, para_env, neighbor_list_section, &
225  "/SOO_LIST", "soo_list", "ORBITAL ORBITAL (RI)")
226  lri_env%soo_list => soo_list
227 
228  CALL atom2d_cleanup(atom2d)
229 
230  DEALLOCATE (orb_present, orb_radius, pair_radius)
231 
232  ! calculate LRI integrals
233  lri_env%ppl_ri = .false. ! make sure that option is not available for ES
234  CALL build_lri_matrices(lri_env, qs_env)
235  kernel_env%full_kernel%lri_env => lri_env
236 
237 ! CALL get_condition_number_of_overlap(lri_env)
238 
239  CALL timestop(handle)
240 
241  END SUBROUTINE tddfpt2_lri_init
242 ! **************************************************************************************************
243 !> \brief Calculate contribution to response vector for LRI
244 !> \param qs_env ...
245 !> \param sub_env ...
246 !> \param lri_env ...
247 !> \param lri_v_int ...
248 !> \param A_ia_munu_sub ...
249 ! **************************************************************************************************
250  SUBROUTINE tddfpt2_lri_amat(qs_env, sub_env, lri_env, lri_v_int, A_ia_munu_sub)
251  TYPE(qs_environment_type), INTENT(IN), POINTER :: qs_env
252  TYPE(tddfpt_subgroup_env_type), INTENT(IN) :: sub_env
253  TYPE(lri_environment_type), INTENT(IN), POINTER :: lri_env
254  TYPE(lri_kind_type), DIMENSION(:), INTENT(IN), &
255  POINTER :: lri_v_int
256  TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: a_ia_munu_sub
257 
258  CHARACTER(len=*), PARAMETER :: routinen = 'tddfpt2_lri_Amat'
259 
260  INTEGER :: handle, ispin, nspins
261  TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
262  TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: dummymat, matrix_s
263 
264  CALL timeset(routinen, handle)
265  NULLIFY (atomic_kind_set)
266  NULLIFY (matrix_s)
267  CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, matrix_s=matrix_s)
268  nspins = SIZE(a_ia_munu_sub)
269  DO ispin = 1, nspins!
270  !no kpoints for excited states => using dummy matrix with no cell index
271  NULLIFY (dummymat)
272  CALL dbcsr_allocate_matrix_set(dummymat, 1)
273  CALL tddfpt_dbcsr_create_by_dist(dummymat(1)%matrix, template=matrix_s(1)%matrix, &
274  dbcsr_dist=sub_env%dbcsr_dist, sab=sub_env%sab_orb)
275 
276  CALL dbcsr_copy(a_ia_munu_sub(ispin)%matrix, dummymat(1)%matrix)
277 
278  CALL calculate_lri_ks_matrix(lri_env, lri_v_int, dummymat, atomic_kind_set)
279 
280  CALL dbcsr_copy(a_ia_munu_sub(ispin)%matrix, dummymat(1)%matrix)
281 
282  CALL dbcsr_deallocate_matrix(dummymat(1)%matrix)
283  DEALLOCATE (dummymat)
284  END DO
285  CALL timestop(handle)
286 
287  END SUBROUTINE tddfpt2_lri_amat
288 ! **************************************************************************************************
289 END MODULE qs_tddfpt2_lri_utils
Define the atomic kind types and their sub types.
Automatic generation of auxiliary basis sets of different kind.
Definition: auto_basis.F:15
subroutine, public create_lri_aux_basis_set(lri_aux_basis_set, qs_kind, basis_cntrl, exact_1c_terms, tda_kernel)
Create a LRI_AUX basis set using some heuristics.
Definition: auto_basis.F:224
subroutine, public add_basis_set_to_container(container, basis_set, basis_set_type)
...
Print basis sets in CP2K format.
subroutine, public print_basis_set_file(qs_env, base_section)
...
subroutine, public sort_gto_basis_set(basis_set, sort_method)
sort basis sets w.r.t. radius
subroutine, public init_orb_basis_set(gto_basis_set)
Initialise a Gaussian-type orbital (GTO) basis set data set.
subroutine, public get_gto_basis_set(gto_basis_set, name, aliases, norm_type, kind_radius, ncgf, nset, nsgf, cgf_symbol, sgf_symbol, norm_cgf, set_radius, lmax, lmin, lx, ly, lz, m, ncgf_set, npgf, nsgf_set, nshell, cphi, pgf_radius, sphi, scon, zet, first_cgf, first_sgf, l, last_cgf, last_sgf, n, gcc, maxco, maxl, maxpgf, maxsgf_set, maxshell, maxso, nco_sum, npgf_sum, nshell_sum, maxder, short_kind_radius)
...
Handles all functions related to the CELL.
Definition: cell_types.F:15
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
DBCSR operations in CP2K.
stores a lists of integer that are local to a processor. The idea is that these integers represent ob...
stores a mapping of 2D info (e.g. matrix) on a 2D processor distribution (i.e. blacs grid) where cpus...
objects that represent the structure of input sections and the data contained in an input section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_get(section_vals, ref_count, n_repetition, n_subs_vals_rep, section, explicit)
returns various attributes about the section_vals
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public dp
Definition: kinds.F:34
initializes the environment for lri lri : local resolution of the identity
subroutine, public lri_env_init(lri_env, lri_section)
initializes the lri env
subroutine, public lri_env_basis(ri_type, qs_env, lri_env, qs_kind_set)
initializes the lri env
Calculates integral matrices for LRIGPW method lri : local resolution of the identity.
subroutine, public build_lri_matrices(lri_env, qs_env)
creates and initializes an lri_env
contains the types and subroutines for dealing with the lri_env lri : local resolution of the identit...
routines that build the Kohn-Sham matrix for the LRIGPW and xc parts
subroutine, public calculate_lri_ks_matrix(lri_env, lri_v_int, h_matrix, atomic_kind_set, cell_to_index)
update of LRIGPW KS matrix
Interface to the message passing library MPI.
Define the data structure for the molecule information.
Provides Cartesian and spherical orbital pointers and indices.
subroutine, public init_orbital_pointers(maxl)
Initialize or update the orbital pointers.
Calculation of the spherical harmonics and the corresponding orbital transformation matrices.
subroutine, public init_spherical_harmonics(maxl, output_unit)
Initialize or update the orbital transformation matrices.
Define the data structure for the particle information.
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.
Calculate the interaction radii for the operator matrix calculation.
subroutine, public init_interaction_radii_orb_basis(orb_basis_set, eps_pgf_orb, eps_pgf_short)
...
Define the quickstep kind type and their sub types.
Definition: qs_kind_types.F:23
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.
subroutine, public get_qs_kind_set(qs_kind_set, all_potential_present, tnadd_potential_present, gth_potential_present, sgp_potential_present, paw_atom_present, dft_plus_u_atom_present, maxcgf, maxsgf, maxco, maxco_proj, maxgtops, maxlgto, maxlprj, maxnset, maxsgf_set, ncgf, npgf, nset, nsgf, nshell, maxpol, maxlppl, maxlppnl, maxppnl, nelectron, maxder, max_ngrid_rad, max_sph_harm, maxg_iso_not0, lmax_rho0, basis_rcut, basis_type, total_zeff_corr)
Get attributes of an atomic kind set.
Define the neighbor list data types and the corresponding functionality.
Generate the atomic neighbor lists.
subroutine, public atom2d_cleanup(atom2d)
free the internals of atom2d
subroutine, public pair_radius_setup(present_a, present_b, radius_a, radius_b, pair_radius, prmin)
...
subroutine, public build_neighbor_lists(ab_list, particle_set, atom, cell, pair_radius, subcells, mic, symmetric, molecular, subset_of_mol, current_subset, operator_type, nlname, atomb_to_keep)
Build simple pair neighbor lists.
subroutine, public write_neighbor_lists(ab, particle_set, cell, para_env, neighbor_list_section, nl_type, middle_name, nlname)
Write a set of neighbor lists to the output unit.
subroutine, public atom2d_build(atom2d, distribution_1d, distribution_2d, atomic_kind_set, molecule_set, molecule_only, particle_set)
Build some distribution structure of atoms, refactored from build_qs_neighbor_lists.
subroutine, public tddfpt2_lri_amat(qs_env, sub_env, lri_env, lri_v_int, A_ia_munu_sub)
Calculate contribution to response vector for LRI.
subroutine, public tddfpt2_lri_init(qs_env, kernel_env, lri_section, tddfpt_print_section)
Initialize LRI environment, basis, neighborlists and matrices.
subroutine, public tddfpt_dbcsr_create_by_dist(matrix, template, dbcsr_dist, sab)
Create a DBCSR matrix based on a template matrix, distribution object, and the list of neighbours.