(git:ccc2433)
xas_tdp_types.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 
8 !> *************************************************************************************************
9 !> \brief Define XAS TDP control type and associated create, release, etc subroutines, as well as
10 !> XAS TDP environment type and associated set, get, etc subroutines
11 !> \author AB (11.2017)
12 !> *************************************************************************************************
14  USE cp_array_utils, ONLY: cp_1d_i_p_type,&
15  cp_1d_r_p_type,&
16  cp_2d_i_p_type,&
17  cp_2d_r_p_type,&
18  cp_3d_r_p_type
19  USE cp_files, ONLY: file_exists
20  USE cp_fm_types, ONLY: cp_fm_release,&
21  cp_fm_type
22  USE dbcsr_api, ONLY: dbcsr_distribution_release,&
23  dbcsr_distribution_type,&
24  dbcsr_p_type,&
25  dbcsr_release,&
26  dbcsr_release_p,&
27  dbcsr_type
28  USE dbt_api, ONLY: dbt_destroy,&
29  dbt_type
31  distribution_2d_type
32  USE input_constants, ONLY: &
37  section_vals_type,&
39  USE kinds, ONLY: default_string_length,&
40  dp
41  USE libint_2c_3c, ONLY: libint_potential_type
43  USE mathlib, ONLY: erfc_cutoff
44  USE memory_utilities, ONLY: reallocate
45  USE message_passing, ONLY: mp_para_env_type
46  USE physcon, ONLY: bohr,&
47  evolt
49  grid_atom_type
51  harmonics_atom_type
52  USE qs_loc_types, ONLY: qs_loc_env_release,&
53  qs_loc_env_type
54  USE qs_ot_types, ONLY: qs_ot_settings_init,&
55  qs_ot_settings_type
56 #include "./base/base_uses.f90"
57 
58  IMPLICIT NONE
59 
60  PRIVATE
61 
62 ! **************************************************************************************************
63 !> \brief Type containing control information for TDP XAS calculations
64 !> \param define_excited whether excited atoms are chosen by kind or index
65 !> \param dipole_form whether the dipole moment is computed in the length or velocity representation
66 !> \param n_search # of lowest energy MOs to search for donor orbitals
67 !> \param check_only whether a check run for donor MOs is conducted
68 !> \param do_hfx whether exact exchange is included
69 !> \param do_xc wheter xc functional(s) is(are) included (libxc)
70 !> \param do_coulomb whether the coulomb kernel is computed, .FALSE. if no xc nor hfx => normal dft
71 !> \param sx the scaling applied to exact exchange
72 !> \param x_potential the potential used for exact exchange (incl. cutoff, t_c_file, omega)
73 !> \param ri_m_potential the potential used for exact exchange RI metric
74 !> \param do_ri_metric whether a metric is used fir the RI
75 !> \param eps_range the threshold to determine the effective range of the short range operator
76 !> \param eps_pgf the threshold to determine the extent of all pgf in the method
77 !> \param eps_filter threshold for dbcsr operations
78 !> \param ri_radius the radius of the sphere defining the neighbors in the RI projection of the dens
79 !> \param tamm_dancoff whether the calculations should be done in the Tamm-Dancoff approximation
80 !> \param do_quad whether the electric quadrupole transition moments should be computed
81 !> \param list_ex_atoms list of excited atom indices, kept empty if define_excited=by_kind
82 !> \param list_ex_kinds list of excited atom kinds, kept empty if define_excited=by_index
83 !> \param do_loc whether the core MOs should be localized
84 !> \param do_uks whether the calculation is spin-unrestricted
85 !> \param do_roks whether the calculation is restricted open-shell
86 !> \param do_singlet whether singlet excitations should be computed
87 !> \param do_triplet whether triplet excitations should be computed
88 !> \param do_spin_cons whether spin-conserving excitation (for open-shell) should be computed
89 !> \param do_spin_flip whether spin-flip excitation (for open-shell) should be computed
90 !> \param do_soc whether spin-orbit coupling should be included
91 !> \param n_excited the number of excited states to compute
92 !> \param e_range the energy range where to look for eigenvalues
93 !> \param state_types columns correspond to the states to excite for each atom kind/index
94 !> the number of rows is the number of times the keyword is repeated
95 !> \param grid_info the information about the atomic grids used for the xc kernel integrals
96 !> \param is_periodic self-explanatory
97 !> \param ot_settings settings for the iterative OT solver
98 !> \param do_ot whether iterative OT solver should be used
99 !> \param ot_max_iter maximum number ot OT iteration allowed
100 !> \param ot_eps_iter convergence threshold for OT diagonalization
101 ! **************************************************************************************************
102  TYPE xas_tdp_control_type
103  INTEGER :: define_excited = 0
104  INTEGER :: dipole_form = 0
105  INTEGER :: n_search = 0
106  INTEGER :: n_excited = 0
107  INTEGER :: ot_max_iter = 0
108  REAL(dp) :: e_range = 0.0_dp
109  REAL(dp) :: sx = 0.0_dp
110  REAL(dp) :: eps_range = 0.0_dp
111  REAL(dp) :: eps_screen = 0.0_dp
112  REAL(dp) :: eps_pgf = 0.0_dp
113  REAL(dp) :: eps_filter = 0.0_dp
114  REAL(dp) :: ot_eps_iter = 0.0_dp
115  TYPE(libint_potential_type) :: x_potential = libint_potential_type()
116  TYPE(libint_potential_type) :: ri_m_potential = libint_potential_type()
117  REAL(dp) :: ri_radius = 0.0_dp
118  LOGICAL :: do_ot = .false.
119  LOGICAL :: do_hfx = .false.
120  LOGICAL :: do_xc = .false.
121  LOGICAL :: do_coulomb = .false.
122  LOGICAL :: do_ri_metric = .false.
123  LOGICAL :: check_only = .false.
124  LOGICAL :: tamm_dancoff = .false.
125  LOGICAL :: do_quad = .false.
126  LOGICAL :: xyz_dip = .false.
127  LOGICAL :: do_loc = .false.
128  LOGICAL :: do_uks = .false.
129  LOGICAL :: do_roks = .false.
130  LOGICAL :: do_soc = .false.
131  LOGICAL :: do_singlet = .false.
132  LOGICAL :: do_triplet = .false.
133  LOGICAL :: do_spin_cons = .false.
134  LOGICAL :: do_spin_flip = .false.
135  LOGICAL :: is_periodic = .false.
136  INTEGER, DIMENSION(:), POINTER :: list_ex_atoms => null()
137  CHARACTER(len=default_string_length), &
138  DIMENSION(:), POINTER :: list_ex_kinds => null()
139  INTEGER, DIMENSION(:, :), POINTER :: state_types => null()
140  TYPE(section_vals_type), POINTER :: loc_subsection => null()
141  TYPE(section_vals_type), POINTER :: print_loc_subsection => null()
142  CHARACTER(len=default_string_length), &
143  DIMENSION(:, :), POINTER :: grid_info => null()
144  TYPE(qs_ot_settings_type), POINTER :: ot_settings => null()
145 
146  LOGICAL :: do_gw2x = .false.
147  LOGICAL :: xps_only = .false.
148  REAL(dp) :: gw2x_eps = 0.0_dp
149  LOGICAL :: pseudo_canonical = .false.
150  INTEGER :: max_gw2x_iter = 0
151  REAL(dp) :: c_os = 0.0_dp
152  REAL(dp) :: c_ss = 0.0_dp
153  INTEGER :: batch_size = 0
154 
155  END TYPE xas_tdp_control_type
156 
157 !> *************************************************************************************************
158 !> \brief Type containing informations such as inputs and results for TDP XAS calculations
159 !> \param state_type_char an array containing the general donor state types as char (1s, 2s, 2p, ...)
160 !> \param nex_atoms number of excited atoms
161 !> \param nex_kinds number of excited kinds
162 !> \param ex_atom_indices array containing the indices of the excited atoms
163 !> \param ex_kind_indices array containing the indices of the excited kinds
164 !> \param state_types columns correspond to the different donor states of each excited atom
165 !> \param qs_loc_env the environment type dealing with the possible localization of donor orbitals
166 !> \param mos_of_ex_atoms links lowest energy MOs to excited atoms. Elements of value 1 mark the
167 !> association between the MO irow and the excited atom icolumn. The third index is for spin
168 !> \param ri_inv_coul the inverse coulomb RI integral (P|Q)^-1, updated for each excited kind
169 !> based on basis functions of the RI_XAS basis for that kind
170 !> \param ri_inv_ex the inverse exchange RI integral (P|Q)^-1, updated for each excited kind
171 !> based on basis functions of the RI_XAS basis for that kind, and with the exchange operator
172 !> Optionally, if a RI metric is present, contains M^-1 (P|Q) M^-1
173 !> \param q_projector the projector on the unperturbed, unoccupied ground state as a dbcsr matrix,
174 !> for each spin
175 !> \param dipmat the dbcsr matrices containing the dipole in x,y,z directions evaluated on the
176 !> contracted spherical gaussians. It can either be in the length or the velocity
177 !> representation. For length representation, it has to be computed once with the origin on
178 !> each excited atom
179 !> \param quadmat the dbcsr matrices containing the electric quadrupole in x2, xy, xz, y2, yz and z2
180 !> directions in the AO basis. It is always in the length representation with the origin
181 !> set to the current excited atom
182 !> \param ri_3c_coul the tensor containing the RI 3-cetner Coulomb integrals (computed once)
183 !> \param ri_3c_ex the tensor containing the RI 3-center exchange integrals (computed for each ex atom)
184 !> \param opt_dist2d_coul an optimized distribution_2d for localized Coulomb 3-center integrals
185 !> \param opt_dist2d_ex an optimized distribution_2d for localized exchange 3-center integrals
186 !> \param ri_fxc the array of xc integrals of type (P|fxc|Q), for alpha-alpha, alpha-beta and beta-beta
187 !> \param fxc_avail a boolean telling whwther fxc is availavle on all procs
188 !> \param orb_soc the matrix where the SOC is evaluated wrt the orbital basis set, for x,y,z
189 !> \param matrix_shalf the SQRT of the orbital overlap matrix, stored for PDOS use
190 !> \param ot_prec roeconditioner for the OT solver
191 !> \param lumo_evecs the LUMOs used as guess for OT
192 !> \param lumo_evals the associated LUMO evals
193 !> *************************************************************************************************
194  TYPE xas_tdp_env_type
195  CHARACTER(len=2), DIMENSION(3) :: state_type_char = ""
196  INTEGER :: nex_atoms = 0
197  INTEGER :: nex_kinds = 0
198  INTEGER, DIMENSION(:), POINTER :: ex_atom_indices => null()
199  INTEGER, DIMENSION(:), POINTER :: ex_kind_indices => null()
200  INTEGER, DIMENSION(:, :), POINTER :: state_types => null()
201  TYPE(dbt_type), POINTER :: ri_3c_coul => null()
202  TYPE(dbt_type), POINTER :: ri_3c_ex => null()
203  TYPE(donor_state_type), DIMENSION(:), &
204  POINTER :: donor_states => null()
205  INTEGER, DIMENSION(:, :, :), POINTER :: mos_of_ex_atoms => null()
206  TYPE(qs_loc_env_type), POINTER :: qs_loc_env => null()
207  REAL(dp), DIMENSION(:, :), POINTER :: ri_inv_coul => null()
208  REAL(dp), DIMENSION(:, :), POINTER :: ri_inv_ex => null()
209  TYPE(distribution_2d_type), POINTER :: opt_dist2d_coul => null()
210  TYPE(distribution_2d_type), POINTER :: opt_dist2d_ex => null()
211  TYPE(dbcsr_p_type), DIMENSION(:), &
212  POINTER :: q_projector => null()
213  TYPE(dbcsr_p_type), DIMENSION(:), &
214  POINTER :: dipmat => null()
215  TYPE(dbcsr_p_type), DIMENSION(:), &
216  POINTER :: quadmat => null()
217  TYPE(cp_2d_r_p_type), DIMENSION(:, :), &
218  POINTER :: ri_fxc => null()
219  LOGICAL :: fxc_avail = .false.
220  TYPE(dbcsr_p_type), DIMENSION(:), &
221  POINTER :: orb_soc => null()
222  TYPE(cp_fm_type), POINTER :: matrix_shalf => null()
223  TYPE(cp_fm_type), DIMENSION(:), &
224  POINTER :: lumo_evecs => null()
225 
226  TYPE(cp_1d_r_p_type), DIMENSION(:), &
227  POINTER :: lumo_evals => null()
228  TYPE(dbcsr_p_type), DIMENSION(:), &
229  POINTER :: ot_prec => null()
230  TYPE(dbcsr_p_type), DIMENSION(:), &
231  POINTER :: fock_matrix => null()
232  TYPE(cp_fm_type), POINTER :: lumo_coeffs => null()
233  END TYPE xas_tdp_env_type
234 
235 !> *************************************************************************************************
236 !> \brief Type containing informations about a single donor state
237 !> \param at_index the index of the atom to which the state belongs
238 !> \param kind_index the index of the atomic kind to which the state belongs
239 !> \param ndo_mo the number of donor MOs per spin
240 !> \param at_symbol the chemical symbol of the atom to which the state belongs
241 !> \param state_type whether this is a 1s, 2s, etc state
242 !> \param energy_evals the energy eigenvalue of the donor state, for each spin
243 !> \param gw2x_evals the GW2X corrected energy eigenvalue of the donor state, for each spin
244 !> \param mo_indices indices of associated MOs. Greater than 1 when not a s-type state.
245 !> \param sc_coeffs solutions of the linear-response TDDFT equation for spin-conserving open-shell
246 !> \param sf_coeffs solutions of the linear-response TDDFT equation for spin-flip open-shell
247 !> \param sg_coeffs solutions of the linear-response TDDFT singlet equations
248 !> \param tp_coeffs solutions of the linear-response TDDFT triplet equations
249 !> \param gs_coeffs the ground state MO coefficients
250 !> \param contract_coeffs the subset of gs_coeffs centered on excited atom, used for RI contraction
251 !> \param sc_evals open-shell spin-conserving excitation energies
252 !> \param sf_evals open-shell spin-flip excitation energies
253 !> \param sg_evals singlet excitation energies => the eigenvalues of the linear response equation
254 !> \param tp_evals triplet excitation energies => the eigenvalues of the linear response equation
255 !> \param soc_evals excitation energies after inclusion of SOC
256 !> \param osc_str dipole oscilaltor strengths (sum and x,y,z contributions)
257 !> \param soc_osc_str dipole oscillator strengths after the inclusion of SOC (sum and x,y,z contributions)
258 !> \param quad_osc_str quadrupole oscilaltor strengths
259 !> \param soc_quad_osc_str quadrupole oscillator strengths after the inclusion of SOC
260 !> \param sc_matrix_tdp the dbcsr matrix to be diagonalized for open-shell spin-conserving calculations
261 !> \param sf_matrix_tdp the dbcsr matrix to be diagonalized for open-shell spin-flip calculations
262 !> \param sg_matrix_tdp the dbcsr matrix to be diagonalized to solve the problem for singlets
263 !> \param tp_matrix_tdp the dbcsr matrix to be diagonalized to solve the problem for triplets
264 !> \param metric the metric of the linear response problem M*c = omega*S*c and its inverse
265 !> \param matrix_aux the auxiliary matrix (A-D+E)^1/2 used to make the problem Hermitian
266 !> \param blk_size the col/row block size of the dbcsr matrices
267 !> \param dbcsr_dist the distribution of the dbcsr matrices
268 !> *************************************************************************************************
269  TYPE donor_state_type
270  INTEGER :: at_index = 0
271  INTEGER :: kind_index = 0
272  INTEGER :: ndo_mo = 0
273  CHARACTER(LEN=default_string_length) :: at_symbol = ""
274  INTEGER :: state_type = 0
275  INTEGER, DIMENSION(:), POINTER :: blk_size => null()
276  REAL(dp), DIMENSION(:, :), POINTER :: energy_evals => null()
277  REAL(dp), DIMENSION(:, :), POINTER :: gw2x_evals => null()
278  INTEGER, DIMENSION(:, :), POINTER :: mo_indices => null()
279  TYPE(cp_fm_type), POINTER :: sc_coeffs => null()
280  TYPE(cp_fm_type), POINTER :: sf_coeffs => null()
281  TYPE(cp_fm_type), POINTER :: sg_coeffs => null()
282  TYPE(cp_fm_type), POINTER :: tp_coeffs => null()
283  TYPE(cp_fm_type), POINTER :: gs_coeffs => null()
284  REAL(dp), DIMENSION(:, :), POINTER :: contract_coeffs => null()
285  REAL(dp), DIMENSION(:), POINTER :: sc_evals => null()
286  REAL(dp), DIMENSION(:), POINTER :: sf_evals => null()
287  REAL(dp), DIMENSION(:), POINTER :: sg_evals => null()
288  REAL(dp), DIMENSION(:), POINTER :: tp_evals => null()
289  REAL(dp), DIMENSION(:), POINTER :: soc_evals => null()
290  REAL(dp), DIMENSION(:, :), POINTER :: osc_str => null()
291  REAL(dp), DIMENSION(:, :), POINTER :: soc_osc_str => null()
292  REAL(dp), DIMENSION(:), POINTER :: quad_osc_str => null()
293  REAL(dp), DIMENSION(:), POINTER :: soc_quad_osc_str => null()
294  TYPE(dbcsr_type), POINTER :: sc_matrix_tdp => null()
295  TYPE(dbcsr_type), POINTER :: sf_matrix_tdp => null()
296  TYPE(dbcsr_type), POINTER :: sg_matrix_tdp => null()
297  TYPE(dbcsr_type), POINTER :: tp_matrix_tdp => null()
298  TYPE(dbcsr_p_type), DIMENSION(:), &
299  POINTER :: metric => null()
300  TYPE(dbcsr_type), POINTER :: matrix_aux => null()
301  TYPE(dbcsr_distribution_type), POINTER :: dbcsr_dist => null()
302 
303  END TYPE donor_state_type
304 
305 ! Some helper types for xas_tdp_atom
306  TYPE grid_atom_p_type
307  TYPE(grid_atom_type), POINTER :: grid_atom => null()
308  END TYPE grid_atom_p_type
309 
310  TYPE harmonics_atom_p_type
311  TYPE(harmonics_atom_type), POINTER :: harmonics_atom => null()
312  END TYPE harmonics_atom_p_type
313 
314  TYPE batch_info_type
315  TYPE(mp_para_env_type) :: para_env = mp_para_env_type()
316  INTEGER :: batch_size = 0
317  INTEGER :: nbatch = 0
318  INTEGER :: ibatch = 0
319  INTEGER :: ipe = 0
320  INTEGER, DIMENSION(:), ALLOCATABLE :: nso_proc
321  INTEGER, DIMENSION(:, :), ALLOCATABLE :: so_bo
322  TYPE(cp_2d_i_p_type), POINTER, DIMENSION(:) :: so_proc_info => null()
323  END TYPE batch_info_type
324 
325 ! **************************************************************************************************
326 !> \brief a environment type that contains all the info needed for XAS_TDP atomic grid calculations
327 !> \param ri_radius defines the neighbors in the RI projection of the density
328 !> \param nspins ...
329 !> \param excited_atoms the atoms for which RI xc-kernel calculations must be done
330 !> \param excited_kinds the kinds for which RI xc-kernel calculations must be done
331 !> \param grid_atom_set the set of atomic grid for each kind
332 !> \param ri_dcoeff the expansion coefficients to express the density in the RI basis for each atom
333 !> \param exat_neighbors the neighbors of each excited atom
334 !> \param ri_sphi_so contains the coefficient for direct contraction from so to sgf, for the ri basis
335 !> \param orb_sphi_so contains the coefficient for direct contraction from so to sgf, for the orb basis
336 !> \param ga the angular part of the spherical gaussians on the grid of excited kinds
337 !> \param gr the radial part of the spherical gaussians on the grid of excited kinds
338 !> \param dgr1 first radial part of the gradient of the RI spherical gaussians
339 !> \param dgr2 second radial part of the gradient of the RI spherical gaussians
340 !> \param dga1 first angular part of the gradient of the RI spherical gaussians
341 !> \param dga2 second angular part of the gradient of the RI spherical gaussians
342 !> *************************************************************************************************
343  TYPE xas_atom_env_type
344  INTEGER :: nspins = 0
345  REAL(dp) :: ri_radius = 0.0_dp
346  INTEGER, DIMENSION(:), POINTER :: excited_atoms => null()
347  INTEGER, DIMENSION(:), POINTER :: excited_kinds => null()
348  INTEGER, DIMENSION(:), POINTER :: proc_of_exat => null()
349  TYPE(grid_atom_p_type), DIMENSION(:), POINTER :: grid_atom_set => null()
350  TYPE(harmonics_atom_p_type), DIMENSION(:), &
351  POINTER :: harmonics_atom_set => null()
352  TYPE(cp_1d_r_p_type), DIMENSION(:, :, :), POINTER :: ri_dcoeff => null()
353  TYPE(cp_2d_r_p_type), DIMENSION(:), POINTER :: ri_sphi_so => null()
354  TYPE(cp_2d_r_p_type), DIMENSION(:), POINTER :: orb_sphi_so => null()
355  TYPE(cp_1d_i_p_type), DIMENSION(:), POINTER :: exat_neighbors => null()
356  TYPE(cp_2d_r_p_type), DIMENSION(:), POINTER :: ga => null(), gr => null(), dgr1 => null(), dgr2 => null()
357  TYPE(cp_3d_r_p_type), DIMENSION(:), POINTER :: dga1 => null(), dga2 => null()
358  END TYPE xas_atom_env_type
359 
360  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'xas_tdp_types'
361 
362 ! *** Public data types ***
363  PUBLIC :: xas_tdp_env_type, donor_state_type, xas_tdp_control_type, xas_atom_env_type, &
364  batch_info_type
365 
366 ! *** Public subroutines ***
372 
373 CONTAINS
374 
375 ! **************************************************************************************************
376 !> \brief Creates and initializes the xas_tdp_control_type
377 !> \param xas_tdp_control the type to initialize
378 ! **************************************************************************************************
379  SUBROUTINE xas_tdp_control_create(xas_tdp_control)
380 
381  TYPE(xas_tdp_control_type), POINTER :: xas_tdp_control
382 
383  cpassert(.NOT. ASSOCIATED(xas_tdp_control))
384  ALLOCATE (xas_tdp_control)
385 
386  xas_tdp_control%define_excited = xas_tdp_by_index
387  xas_tdp_control%n_search = -1
388  xas_tdp_control%dipole_form = xas_dip_vel
389  xas_tdp_control%do_hfx = .false.
390  xas_tdp_control%do_xc = .false.
391  xas_tdp_control%do_coulomb = .true.
392  xas_tdp_control%do_ri_metric = .false.
393  xas_tdp_control%sx = 1.0_dp
394  xas_tdp_control%eps_range = 1.0e-6_dp
395  xas_tdp_control%eps_screen = 1.0e-10_dp
396  xas_tdp_control%eps_pgf = -1.0_dp
397  xas_tdp_control%eps_filter = 1.0e-10_dp
398  xas_tdp_control%ri_radius = 0.0_dp
399  xas_tdp_control%x_potential%potential_type = do_potential_coulomb
400  xas_tdp_control%x_potential%cutoff_radius = 0.0_dp
401  xas_tdp_control%x_potential%omega = 0.0_dp
402  xas_tdp_control%x_potential%filename = " "
403  xas_tdp_control%ri_m_potential%potential_type = do_potential_coulomb
404  xas_tdp_control%ri_m_potential%cutoff_radius = 0.0_dp
405  xas_tdp_control%ri_m_potential%omega = 0.0_dp
406  xas_tdp_control%ri_m_potential%filename = " "
407  xas_tdp_control%check_only = .false.
408  xas_tdp_control%tamm_dancoff = .false.
409  xas_tdp_control%do_ot = .true.
410  xas_tdp_control%do_quad = .false.
411  xas_tdp_control%xyz_dip = .false.
412  xas_tdp_control%do_loc = .false.
413  xas_tdp_control%do_uks = .false.
414  xas_tdp_control%do_roks = .false.
415  xas_tdp_control%do_soc = .false.
416  xas_tdp_control%do_singlet = .false.
417  xas_tdp_control%do_triplet = .false.
418  xas_tdp_control%do_spin_cons = .false.
419  xas_tdp_control%do_spin_flip = .false.
420  xas_tdp_control%is_periodic = .false.
421  xas_tdp_control%n_excited = -1
422  xas_tdp_control%e_range = -1.0_dp
423  xas_tdp_control%ot_max_iter = 500
424  xas_tdp_control%ot_eps_iter = 1.0e-4_dp
425  xas_tdp_control%c_os = 1.0_dp
426  xas_tdp_control%c_ss = 1.0_dp
427  xas_tdp_control%batch_size = 64
428  xas_tdp_control%do_gw2x = .false.
429  xas_tdp_control%xps_only = .false.
430  NULLIFY (xas_tdp_control%state_types)
431  NULLIFY (xas_tdp_control%list_ex_atoms)
432  NULLIFY (xas_tdp_control%list_ex_kinds)
433  NULLIFY (xas_tdp_control%loc_subsection)
434  NULLIFY (xas_tdp_control%print_loc_subsection)
435  NULLIFY (xas_tdp_control%grid_info)
436  NULLIFY (xas_tdp_control%ot_settings)
437 
438  END SUBROUTINE xas_tdp_control_create
439 
440 ! **************************************************************************************************
441 !> \brief Releases the xas_tdp_control_type
442 !> \param xas_tdp_control the type to release
443 ! **************************************************************************************************
444  SUBROUTINE xas_tdp_control_release(xas_tdp_control)
445 
446  TYPE(xas_tdp_control_type), POINTER :: xas_tdp_control
447 
448  IF (ASSOCIATED(xas_tdp_control)) THEN
449  IF (ASSOCIATED(xas_tdp_control%list_ex_atoms)) THEN
450  DEALLOCATE (xas_tdp_control%list_ex_atoms)
451  END IF
452  IF (ASSOCIATED(xas_tdp_control%list_ex_kinds)) THEN
453  DEALLOCATE (xas_tdp_control%list_ex_kinds)
454  END IF
455  IF (ASSOCIATED(xas_tdp_control%state_types)) THEN
456  DEALLOCATE (xas_tdp_control%state_types)
457  END IF
458  IF (ASSOCIATED(xas_tdp_control%grid_info)) THEN
459  DEALLOCATE (xas_tdp_control%grid_info)
460  END IF
461  IF (ASSOCIATED(xas_tdp_control%loc_subsection)) THEN
462  !recursive, print_loc_subsection removed too
463  CALL section_vals_release(xas_tdp_control%loc_subsection)
464  END IF
465  IF (ASSOCIATED(xas_tdp_control%ot_settings)) THEN
466  DEALLOCATE (xas_tdp_control%ot_settings)
467  END IF
468  DEALLOCATE (xas_tdp_control)
469  END IF
470 
471  END SUBROUTINE xas_tdp_control_release
472 
473 ! **************************************************************************************************
474 !> \brief Reads the inputs and stores in xas_tdp_control_type
475 !> \param xas_tdp_control the type where inputs are stored
476 !> \param xas_tdp_section the section from which input are read
477 ! **************************************************************************************************
478  SUBROUTINE read_xas_tdp_control(xas_tdp_control, xas_tdp_section)
479 
480  TYPE(xas_tdp_control_type), POINTER :: xas_tdp_control
481  TYPE(section_vals_type), POINTER :: xas_tdp_section
482 
483  CHARACTER(len=default_string_length), &
484  DIMENSION(:), POINTER :: k_list
485  INTEGER :: excitation, irep, nexc, nrep, ot_method, &
486  xc_param
487  INTEGER, DIMENSION(:), POINTER :: a_list, t_list
488 
489  NULLIFY (k_list, a_list, t_list)
490 
491 ! Deal with the lone keywords
492 
493  CALL section_vals_val_get(xas_tdp_section, "CHECK_ONLY", &
494  l_val=xas_tdp_control%check_only)
495 
496  CALL section_vals_val_get(xas_tdp_section, "TAMM_DANCOFF", &
497  l_val=xas_tdp_control%tamm_dancoff)
498 
499  CALL section_vals_val_get(xas_tdp_section, "SPIN_ORBIT_COUPLING", &
500  l_val=xas_tdp_control%do_soc)
501 
502  CALL section_vals_val_get(xas_tdp_section, "DIPOLE_FORM", i_val=xas_tdp_control%dipole_form)
503 
504  CALL section_vals_val_get(xas_tdp_section, "QUADRUPOLE", l_val=xas_tdp_control%do_quad)
505 
506  CALL section_vals_val_get(xas_tdp_section, "XYZ_DIPOLE", l_val=xas_tdp_control%xyz_dip)
507 
508  CALL section_vals_val_get(xas_tdp_section, "EPS_PGF_XAS", n_rep_val=nrep)
509  IF (nrep > 0) CALL section_vals_val_get(xas_tdp_section, "EPS_PGF_XAS", r_val=xas_tdp_control%eps_pgf)
510 
511  CALL section_vals_val_get(xas_tdp_section, "EPS_FILTER", r_val=xas_tdp_control%eps_filter)
512 
513  CALL section_vals_val_get(xas_tdp_section, "GRID", n_rep_val=nrep)
514 
515  IF (.NOT. ASSOCIATED(xas_tdp_control%grid_info)) THEN
516  ALLOCATE (xas_tdp_control%grid_info(nrep, 3))
517  DO irep = 1, nrep
518  CALL section_vals_val_get(xas_tdp_section, "GRID", i_rep_val=irep, c_vals=k_list)
519  IF (SIZE(k_list) .NE. 3) cpabort("The GRID keyword needs three values")
520  xas_tdp_control%grid_info(irep, :) = k_list
521  END DO
522  END IF
523 
524  CALL section_vals_val_get(xas_tdp_section, "EXCITATIONS", n_rep_val=nrep)
525  DO irep = 1, nrep
526  CALL section_vals_val_get(xas_tdp_section, "EXCITATIONS", i_rep_val=irep, i_val=excitation)
527  IF (excitation == tddfpt_singlet) xas_tdp_control%do_singlet = .true.
528  IF (excitation == tddfpt_triplet) xas_tdp_control%do_triplet = .true.
529  IF (excitation == tddfpt_spin_cons) xas_tdp_control%do_spin_cons = .true.
530  IF (excitation == tddfpt_spin_flip) xas_tdp_control%do_spin_flip = .true.
531  END DO
532 
533  CALL section_vals_val_get(xas_tdp_section, "N_EXCITED", &
534  i_val=xas_tdp_control%n_excited)
535  CALL section_vals_val_get(xas_tdp_section, "ENERGY_RANGE", &
536  r_val=xas_tdp_control%e_range)
537  !store the range in Hartree, not eV
538  xas_tdp_control%e_range = xas_tdp_control%e_range/evolt
539 
540 ! Deal with the DONOR_STATES subsection
541 
542  CALL section_vals_val_get(xas_tdp_section, "DONOR_STATES%DEFINE_EXCITED", &
543  i_val=xas_tdp_control%define_excited)
544 
545  IF (.NOT. ASSOCIATED(xas_tdp_control%list_ex_kinds)) THEN
546  IF (xas_tdp_control%define_excited .EQ. xas_tdp_by_index) THEN
547 
548  ALLOCATE (xas_tdp_control%list_ex_kinds(0))
549 
550  ELSE IF (xas_tdp_control%define_excited .EQ. xas_tdp_by_kind) THEN
551 
552  CALL section_vals_val_get(xas_tdp_section, "DONOR_STATES%KIND_LIST", c_vals=k_list)
553 
554  IF (ASSOCIATED(k_list)) THEN
555  nexc = SIZE(k_list)
556  ALLOCATE (xas_tdp_control%list_ex_kinds(nexc))
557  xas_tdp_control%list_ex_kinds = k_list
558  END IF
559 
560  END IF
561  END IF
562 
563  IF (.NOT. ASSOCIATED(xas_tdp_control%list_ex_atoms)) THEN
564  IF (xas_tdp_control%define_excited .EQ. xas_tdp_by_kind) THEN
565 
566  ALLOCATE (xas_tdp_control%list_ex_atoms(0))
567 
568  ELSE IF (xas_tdp_control%define_excited .EQ. xas_tdp_by_index) THEN
569 
570  CALL section_vals_val_get(xas_tdp_section, "DONOR_STATES%ATOM_LIST", i_vals=a_list)
571 
572  IF (ASSOCIATED(a_list)) THEN
573  nexc = SIZE(a_list)
574  CALL reallocate(xas_tdp_control%list_ex_atoms, 1, nexc)
575  xas_tdp_control%list_ex_atoms = a_list
576  END IF
577 
578  END IF
579  END IF
580 
581  CALL section_vals_val_get(xas_tdp_section, "DONOR_STATES%STATE_TYPES", n_rep_val=nrep)
582 
583  IF (.NOT. ASSOCIATED(xas_tdp_control%state_types)) THEN
584  ALLOCATE (xas_tdp_control%state_types(nrep, nexc))
585  DO irep = 1, nrep
586  CALL section_vals_val_get(xas_tdp_section, "DONOR_STATES%STATE_TYPES", i_rep_val=irep, i_vals=t_list)
587  IF (SIZE(t_list) .NE. nexc) THEN
588  cpabort("The STATE_TYPES keywords do not have the correct number of entries.")
589  END IF
590  xas_tdp_control%state_types(irep, :) = t_list
591  END DO
592  END IF
593  IF (all(xas_tdp_control%state_types == 0)) cpabort("Please specify STATE_TYPES")
594 
595  CALL section_vals_val_get(xas_tdp_section, "DONOR_STATES%N_SEARCH", i_val=xas_tdp_control%n_search)
596 
597  CALL section_vals_val_get(xas_tdp_section, "DONOR_STATES%LOCALIZE", l_val=xas_tdp_control%do_loc)
598 
599 ! Deal with the KERNEL subsection
600  CALL section_vals_val_get(xas_tdp_section, "KERNEL%XC_FUNCTIONAL%_SECTION_PARAMETERS_", &
601  i_val=xc_param)
602  xas_tdp_control%do_xc = xc_param .NE. xc_none
603  CALL section_vals_val_get(xas_tdp_section, "KERNEL%EXACT_EXCHANGE%_SECTION_PARAMETERS_", &
604  l_val=xas_tdp_control%do_hfx)
605 
606  CALL section_vals_val_get(xas_tdp_section, "KERNEL%RI_REGION", r_val=xas_tdp_control%ri_radius)
607  xas_tdp_control%ri_radius = bohr*xas_tdp_control%ri_radius
608 
609  IF (xas_tdp_control%do_hfx) THEN
610  !The main exact echange potential and related params
611  CALL section_vals_val_get(xas_tdp_section, "KERNEL%EXACT_EXCHANGE%SCALE", &
612  r_val=xas_tdp_control%sx)
613  CALL section_vals_val_get(xas_tdp_section, "KERNEL%EXACT_EXCHANGE%POTENTIAL_TYPE", &
614  i_val=xas_tdp_control%x_potential%potential_type)
615  !truncated Coulomb
616  IF (xas_tdp_control%x_potential%potential_type == do_potential_truncated) THEN
617  CALL section_vals_val_get(xas_tdp_section, "KERNEL%EXACT_EXCHANGE%T_C_G_DATA", &
618  c_val=xas_tdp_control%x_potential%filename)
619  IF (.NOT. file_exists(xas_tdp_control%x_potential%filename)) THEN
620  cpabort("Could not find provided T_C_G_DATA file.")
621  END IF
622  CALL section_vals_val_get(xas_tdp_section, "KERNEL%EXACT_EXCHANGE%CUTOFF_RADIUS", &
623  r_val=xas_tdp_control%x_potential%cutoff_radius)
624  !store the range in bohrs
625  xas_tdp_control%x_potential%cutoff_radius = bohr*xas_tdp_control%x_potential%cutoff_radius
626  END IF
627 
628  !short range erfc
629  IF (xas_tdp_control%x_potential%potential_type == do_potential_short) THEN
630  CALL section_vals_val_get(xas_tdp_section, "KERNEL%EXACT_EXCHANGE%OMEGA", &
631  r_val=xas_tdp_control%x_potential%omega)
632  CALL section_vals_val_get(xas_tdp_section, "KERNEL%EXACT_EXCHANGE%EPS_RANGE", &
633  r_val=xas_tdp_control%eps_range)
634  !get the effective range (omega in 1/a0, range in a0)
635  CALL erfc_cutoff(xas_tdp_control%eps_range, xas_tdp_control%x_potential%omega, &
636  xas_tdp_control%x_potential%cutoff_radius)
637 
638  END IF
639 
640  CALL section_vals_val_get(xas_tdp_section, "KERNEL%EXACT_EXCHANGE%EPS_SCREENING", &
641  r_val=xas_tdp_control%eps_screen)
642  !The RI metric stuff
643  CALL section_vals_val_get(xas_tdp_section, "KERNEL%EXACT_EXCHANGE%RI_METRIC%_SECTION_PARAMETERS_", &
644  l_val=xas_tdp_control%do_ri_metric)
645  IF (xas_tdp_control%do_ri_metric) THEN
646 
647  CALL section_vals_val_get(xas_tdp_section, "KERNEL%EXACT_EXCHANGE%RI_METRIC%POTENTIAL_TYPE", &
648  i_val=xas_tdp_control%ri_m_potential%potential_type)
649 
650  !truncated Coulomb
651  IF (xas_tdp_control%ri_m_potential%potential_type == do_potential_truncated) THEN
652  CALL section_vals_val_get(xas_tdp_section, "KERNEL%EXACT_EXCHANGE%RI_METRIC%T_C_G_DATA", &
653  c_val=xas_tdp_control%ri_m_potential%filename)
654  IF (.NOT. file_exists(xas_tdp_control%ri_m_potential%filename)) THEN
655  cpabort("Could not find provided T_C_G_DATA file.")
656  END IF
657  CALL section_vals_val_get(xas_tdp_section, "KERNEL%EXACT_EXCHANGE%RI_METRIC%CUTOFF_RADIUS", &
658  r_val=xas_tdp_control%ri_m_potential%cutoff_radius)
659  !store the range in bohrs
660  xas_tdp_control%ri_m_potential%cutoff_radius = bohr*xas_tdp_control%ri_m_potential%cutoff_radius
661  END IF
662 
663  !short range erfc
664  IF (xas_tdp_control%ri_m_potential%potential_type == do_potential_short) THEN
665  CALL section_vals_val_get(xas_tdp_section, "KERNEL%EXACT_EXCHANGE%RI_METRIC%OMEGA", &
666  r_val=xas_tdp_control%ri_m_potential%omega)
667  !get the effective range (omega in 1/a0, range in a0)
668  CALL erfc_cutoff(xas_tdp_control%eps_range, xas_tdp_control%ri_m_potential%omega, &
669  xas_tdp_control%ri_m_potential%cutoff_radius)
670 
671  END IF
672  ELSE
673  !No defined metric, V-approximation, set all ri_m_potential params to those of x_pot
674  xas_tdp_control%ri_m_potential = xas_tdp_control%x_potential
675 
676  END IF
677 
678  END IF
679 
680  IF ((.NOT. xas_tdp_control%do_xc) .AND. (.NOT. xas_tdp_control%do_hfx)) THEN
681  !then no coulomb either and go full DFT
682  xas_tdp_control%do_coulomb = .false.
683  END IF
684 
685  !Set up OT settings
686  ALLOCATE (xas_tdp_control%ot_settings)
687  CALL qs_ot_settings_init(xas_tdp_control%ot_settings)
688  CALL section_vals_val_get(xas_tdp_section, "OT_SOLVER%_SECTION_PARAMETERS_", &
689  l_val=xas_tdp_control%do_ot)
690 
691  CALL section_vals_val_get(xas_tdp_section, "OT_SOLVER%MINIMIZER", i_val=ot_method)
692  SELECT CASE (ot_method)
693  CASE (ot_mini_cg)
694  xas_tdp_control%ot_settings%ot_method = "CG"
695  CASE (ot_mini_diis)
696  xas_tdp_control%ot_settings%ot_method = "DIIS"
697  END SELECT
698 
699  CALL section_vals_val_get(xas_tdp_section, "OT_SOLVER%MAX_ITER", &
700  i_val=xas_tdp_control%ot_max_iter)
701  CALL section_vals_val_get(xas_tdp_section, "OT_SOLVER%EPS_ITER", &
702  r_val=xas_tdp_control%ot_eps_iter)
703 
704  !GW2X
705  CALL section_vals_val_get(xas_tdp_section, "GW2X%_SECTION_PARAMETERS_", l_val=xas_tdp_control%do_gw2x)
706  IF (xas_tdp_control%do_gw2x) THEN
707  CALL section_vals_val_get(xas_tdp_section, "GW2X%EPS_GW2X", r_val=xas_tdp_control%gw2x_eps)
708  CALL section_vals_val_get(xas_tdp_section, "GW2X%XPS_ONLY", l_val=xas_tdp_control%xps_only)
709  CALL section_vals_val_get(xas_tdp_section, "GW2X%C_OS", r_val=xas_tdp_control%c_os)
710  CALL section_vals_val_get(xas_tdp_section, "GW2X%C_SS", r_val=xas_tdp_control%c_ss)
711  CALL section_vals_val_get(xas_tdp_section, "GW2X%MAX_GW2X_ITER", i_val=xas_tdp_control%max_gw2x_iter)
712  CALL section_vals_val_get(xas_tdp_section, "GW2X%PSEUDO_CANONICAL", l_val=xas_tdp_control%pseudo_canonical)
713  CALL section_vals_val_get(xas_tdp_section, "GW2X%BATCH_SIZE", i_val=xas_tdp_control%batch_size)
714  END IF
715 
716  END SUBROUTINE read_xas_tdp_control
717 
718 ! **************************************************************************************************
719 !> \brief Creates a TDP XAS environment type
720 !> \param xas_tdp_env the type to create
721 ! **************************************************************************************************
722  SUBROUTINE xas_tdp_env_create(xas_tdp_env)
723 
724  TYPE(xas_tdp_env_type), POINTER :: xas_tdp_env
725 
726  ALLOCATE (xas_tdp_env)
727 
728  xas_tdp_env%nex_atoms = 1
729  xas_tdp_env%nex_kinds = 1
730  xas_tdp_env%fxc_avail = .false.
731 
732  NULLIFY (xas_tdp_env%ex_atom_indices)
733  NULLIFY (xas_tdp_env%ex_kind_indices)
734  NULLIFY (xas_tdp_env%state_types)
735  NULLIFY (xas_tdp_env%donor_states)
736  NULLIFY (xas_tdp_env%qs_loc_env)
737  NULLIFY (xas_tdp_env%mos_of_ex_atoms)
738  NULLIFY (xas_tdp_env%ri_inv_coul)
739  NULLIFY (xas_tdp_env%ri_inv_ex)
740  NULLIFY (xas_tdp_env%opt_dist2d_coul)
741  NULLIFY (xas_tdp_env%opt_dist2d_ex)
742  NULLIFY (xas_tdp_env%q_projector)
743  NULLIFY (xas_tdp_env%dipmat)
744  NULLIFY (xas_tdp_env%quadmat)
745  NULLIFY (xas_tdp_env%ri_3c_coul)
746  NULLIFY (xas_tdp_env%ri_3c_ex)
747  NULLIFY (xas_tdp_env%ri_fxc)
748  NULLIFY (xas_tdp_env%orb_soc)
749  NULLIFY (xas_tdp_env%matrix_shalf)
750  NULLIFY (xas_tdp_env%lumo_evecs)
751  NULLIFY (xas_tdp_env%lumo_evals)
752  NULLIFY (xas_tdp_env%ot_prec)
753  NULLIFY (xas_tdp_env%lumo_coeffs)
754  NULLIFY (xas_tdp_env%fock_matrix)
755 
756 ! Putting the state types as char manually
757  xas_tdp_env%state_type_char(1) = "1s"
758  xas_tdp_env%state_type_char(2) = "2s"
759  xas_tdp_env%state_type_char(3) = "2p"
760 
761  END SUBROUTINE xas_tdp_env_create
762 
763 ! **************************************************************************************************
764 !> \brief Releases the TDP XAS environment type
765 !> \param xas_tdp_env the type to release
766 ! **************************************************************************************************
767  SUBROUTINE xas_tdp_env_release(xas_tdp_env)
768 
769  TYPE(xas_tdp_env_type), POINTER :: xas_tdp_env
770 
771  INTEGER :: i, j
772 
773  IF (ASSOCIATED(xas_tdp_env)) THEN
774  IF (ASSOCIATED(xas_tdp_env%ex_atom_indices)) THEN
775  DEALLOCATE (xas_tdp_env%ex_atom_indices)
776  END IF
777  IF (ASSOCIATED(xas_tdp_env%ex_kind_indices)) THEN
778  DEALLOCATE (xas_tdp_env%ex_kind_indices)
779  END IF
780 
781  IF (ASSOCIATED(xas_tdp_env%state_types)) THEN
782  DEALLOCATE (xas_tdp_env%state_types)
783  END IF
784  IF (ASSOCIATED(xas_tdp_env%donor_states)) THEN
785  CALL deallocate_donor_state_set(xas_tdp_env%donor_states)
786  END IF
787  IF (ASSOCIATED(xas_tdp_env%qs_loc_env)) THEN
788  CALL qs_loc_env_release(xas_tdp_env%qs_loc_env)
789  DEALLOCATE (xas_tdp_env%qs_loc_env)
790  END IF
791  IF (ASSOCIATED(xas_tdp_env%mos_of_ex_atoms)) THEN
792  DEALLOCATE (xas_tdp_env%mos_of_ex_atoms)
793  END IF
794  IF (ASSOCIATED(xas_tdp_env%ri_inv_coul)) THEN
795  DEALLOCATE (xas_tdp_env%ri_inv_coul)
796  END IF
797  IF (ASSOCIATED(xas_tdp_env%ri_inv_ex)) THEN
798  DEALLOCATE (xas_tdp_env%ri_inv_ex)
799  END IF
800  IF (ASSOCIATED(xas_tdp_env%opt_dist2d_coul)) THEN
801  CALL distribution_2d_release(xas_tdp_env%opt_dist2d_coul)
802  END IF
803  IF (ASSOCIATED(xas_tdp_env%opt_dist2d_ex)) THEN
804  CALL distribution_2d_release(xas_tdp_env%opt_dist2d_ex)
805  END IF
806  IF (ASSOCIATED(xas_tdp_env%q_projector)) THEN
807  DO i = 1, SIZE(xas_tdp_env%q_projector)
808  CALL dbcsr_release_p(xas_tdp_env%q_projector(i)%matrix)
809  END DO
810  DEALLOCATE (xas_tdp_env%q_projector)
811  END IF
812  IF (ASSOCIATED(xas_tdp_env%dipmat)) THEN
813  DO i = 1, SIZE(xas_tdp_env%dipmat)
814  CALL dbcsr_release_p(xas_tdp_env%dipmat(i)%matrix)
815  END DO
816  DEALLOCATE (xas_tdp_env%dipmat)
817  END IF
818  IF (ASSOCIATED(xas_tdp_env%quadmat)) THEN
819  DO i = 1, SIZE(xas_tdp_env%quadmat)
820  CALL dbcsr_release_p(xas_tdp_env%quadmat(i)%matrix)
821  END DO
822  DEALLOCATE (xas_tdp_env%quadmat)
823  END IF
824  IF (ASSOCIATED(xas_tdp_env%ri_3c_coul)) THEN
825  CALL dbt_destroy(xas_tdp_env%ri_3c_coul)
826  DEALLOCATE (xas_tdp_env%ri_3c_coul)
827  END IF
828  IF (ASSOCIATED(xas_tdp_env%ri_3c_ex)) THEN
829  CALL dbt_destroy(xas_tdp_env%ri_3c_ex)
830  DEALLOCATE (xas_tdp_env%ri_3c_ex)
831  END IF
832  IF (ASSOCIATED(xas_tdp_env%ri_fxc)) THEN
833  DO i = 1, SIZE(xas_tdp_env%ri_fxc, 1)
834  DO j = 1, SIZE(xas_tdp_env%ri_fxc, 2)
835  IF (ASSOCIATED(xas_tdp_env%ri_fxc(i, j)%array)) THEN
836  DEALLOCATE (xas_tdp_env%ri_fxc(i, j)%array)
837  END IF
838  END DO
839  END DO
840  DEALLOCATE (xas_tdp_env%ri_fxc)
841  END IF
842  IF (ASSOCIATED(xas_tdp_env%orb_soc)) THEN
843  DO i = 1, SIZE(xas_tdp_env%orb_soc)
844  CALL dbcsr_release(xas_tdp_env%orb_soc(i)%matrix)
845  DEALLOCATE (xas_tdp_env%orb_soc(i)%matrix)
846  END DO
847  DEALLOCATE (xas_tdp_env%orb_soc)
848  END IF
849 
850  CALL cp_fm_release(xas_tdp_env%lumo_evecs)
851 
852  IF (ASSOCIATED(xas_tdp_env%lumo_evals)) THEN
853  DO i = 1, SIZE(xas_tdp_env%lumo_evals)
854  DEALLOCATE (xas_tdp_env%lumo_evals(i)%array)
855  END DO
856  DEALLOCATE (xas_tdp_env%lumo_evals)
857  END IF
858  IF (ASSOCIATED(xas_tdp_env%ot_prec)) THEN
859  DO i = 1, SIZE(xas_tdp_env%ot_prec)
860  CALL dbcsr_release(xas_tdp_env%ot_prec(i)%matrix)
861  DEALLOCATE (xas_tdp_env%ot_prec(i)%matrix)
862  END DO
863  DEALLOCATE (xas_tdp_env%ot_prec)
864  END IF
865  IF (ASSOCIATED(xas_tdp_env%matrix_shalf)) THEN
866  CALL cp_fm_release(xas_tdp_env%matrix_shalf)
867  DEALLOCATE (xas_tdp_env%matrix_shalf)
868  NULLIFY (xas_tdp_env%matrix_shalf)
869  END IF
870  IF (ASSOCIATED(xas_tdp_env%fock_matrix)) THEN
871  DO i = 1, SIZE(xas_tdp_env%fock_matrix)
872  CALL dbcsr_release(xas_tdp_env%fock_matrix(i)%matrix)
873  DEALLOCATE (xas_tdp_env%fock_matrix(i)%matrix)
874  END DO
875  DEALLOCATE (xas_tdp_env%fock_matrix)
876  END IF
877  IF (ASSOCIATED(xas_tdp_env%lumo_coeffs)) THEN
878  CALL cp_fm_release(xas_tdp_env%lumo_coeffs)
879  DEALLOCATE (xas_tdp_env%lumo_coeffs)
880  NULLIFY (xas_tdp_env%lumo_coeffs)
881  END IF
882  DEALLOCATE (xas_tdp_env)
883  END IF
884  END SUBROUTINE xas_tdp_env_release
885 
886 ! **************************************************************************************************
887 !> \brief Sets values of selected variables within the TDP XAS environment type
888 !> \param xas_tdp_env ...
889 !> \param nex_atoms ...
890 !> \param nex_kinds ...
891 ! **************************************************************************************************
892  SUBROUTINE set_xas_tdp_env(xas_tdp_env, nex_atoms, nex_kinds)
893 
894  TYPE(xas_tdp_env_type), POINTER :: xas_tdp_env
895  INTEGER, INTENT(IN), OPTIONAL :: nex_atoms, nex_kinds
896 
897  cpassert(ASSOCIATED(xas_tdp_env))
898 
899  IF (PRESENT(nex_atoms)) xas_tdp_env%nex_atoms = nex_atoms
900  IF (PRESENT(nex_kinds)) xas_tdp_env%nex_kinds = nex_kinds
901 
902  END SUBROUTINE set_xas_tdp_env
903 
904 ! **************************************************************************************************
905 !> \brief Creates a donor_state
906 !> \param donor_state ...
907 ! **************************************************************************************************
908  SUBROUTINE donor_state_create(donor_state)
909 
910  TYPE(donor_state_type), INTENT(INOUT) :: donor_state
911 
912  NULLIFY (donor_state%energy_evals)
913  NULLIFY (donor_state%gw2x_evals)
914  NULLIFY (donor_state%mo_indices)
915  NULLIFY (donor_state%sc_coeffs)
916  NULLIFY (donor_state%sf_coeffs)
917  NULLIFY (donor_state%sg_coeffs)
918  NULLIFY (donor_state%tp_coeffs)
919  NULLIFY (donor_state%gs_coeffs)
920  NULLIFY (donor_state%contract_coeffs)
921  NULLIFY (donor_state%sc_evals)
922  NULLIFY (donor_state%sf_evals)
923  NULLIFY (donor_state%sg_evals)
924  NULLIFY (donor_state%tp_evals)
925  NULLIFY (donor_state%soc_evals)
926  NULLIFY (donor_state%soc_osc_str)
927  NULLIFY (donor_state%osc_str)
928  NULLIFY (donor_state%soc_quad_osc_str)
929  NULLIFY (donor_state%quad_osc_str)
930  NULLIFY (donor_state%sc_matrix_tdp)
931  NULLIFY (donor_state%sf_matrix_tdp)
932  NULLIFY (donor_state%sg_matrix_tdp)
933  NULLIFY (donor_state%tp_matrix_tdp)
934  NULLIFY (donor_state%metric)
935  NULLIFY (donor_state%matrix_aux)
936  NULLIFY (donor_state%blk_size)
937  NULLIFY (donor_state%dbcsr_dist)
938 
939  END SUBROUTINE donor_state_create
940 
941 ! **************************************************************************************************
942 !> \brief sets specified values of the donor state type
943 !> \param donor_state the type which values should be set
944 !> \param at_index ...
945 !> \param at_symbol ...
946 !> \param kind_index ...
947 !> \param state_type ...
948 ! **************************************************************************************************
949  SUBROUTINE set_donor_state(donor_state, at_index, at_symbol, kind_index, state_type)
950 
951  TYPE(donor_state_type), POINTER :: donor_state
952  INTEGER, INTENT(IN), OPTIONAL :: at_index
953  CHARACTER(LEN=default_string_length), OPTIONAL :: at_symbol
954  INTEGER, INTENT(IN), OPTIONAL :: kind_index, state_type
955 
956  cpassert(ASSOCIATED(donor_state))
957 
958  IF (PRESENT(at_index)) donor_state%at_index = at_index
959  IF (PRESENT(kind_index)) donor_state%kind_index = kind_index
960  IF (PRESENT(state_type)) donor_state%state_type = state_type
961  IF (PRESENT(at_symbol)) donor_state%at_symbol = at_symbol
962 
963  END SUBROUTINE set_donor_state
964 
965 ! **************************************************************************************************
966 !> \brief Deallocate a set of donor states
967 !> \param donor_state_set the set of donor states to deallocate
968 ! **************************************************************************************************
969  SUBROUTINE deallocate_donor_state_set(donor_state_set)
970  TYPE(donor_state_type), DIMENSION(:), POINTER :: donor_state_set
971 
972  INTEGER :: i, j
973 
974  IF (ASSOCIATED(donor_state_set)) THEN
975  DO i = 1, SIZE(donor_state_set)
976 
977  IF (ASSOCIATED(donor_state_set(i)%sc_coeffs)) THEN
978  CALL cp_fm_release(donor_state_set(i)%sc_coeffs)
979  DEALLOCATE (donor_state_set(i)%sc_coeffs)
980  END IF
981 
982  IF (ASSOCIATED(donor_state_set(i)%sf_coeffs)) THEN
983  CALL cp_fm_release(donor_state_set(i)%sf_coeffs)
984  DEALLOCATE (donor_state_set(i)%sf_coeffs)
985  END IF
986 
987  IF (ASSOCIATED(donor_state_set(i)%sg_coeffs)) THEN
988  CALL cp_fm_release(donor_state_set(i)%sg_coeffs)
989  DEALLOCATE (donor_state_set(i)%sg_coeffs)
990  END IF
991 
992  IF (ASSOCIATED(donor_state_set(i)%tp_coeffs)) THEN
993  CALL cp_fm_release(donor_state_set(i)%tp_coeffs)
994  DEALLOCATE (donor_state_set(i)%tp_coeffs)
995  END IF
996 
997  IF (ASSOCIATED(donor_state_set(i)%gs_coeffs)) THEN
998  CALL cp_fm_release(donor_state_set(i)%gs_coeffs)
999  DEALLOCATE (donor_state_set(i)%gs_coeffs)
1000  END IF
1001 
1002  IF (ASSOCIATED(donor_state_set(i)%contract_coeffs)) THEN
1003  DEALLOCATE (donor_state_set(i)%contract_coeffs)
1004  END IF
1005 
1006  IF (ASSOCIATED(donor_state_set(i)%sc_evals)) THEN
1007  DEALLOCATE (donor_state_set(i)%sc_evals)
1008  END IF
1009 
1010  IF (ASSOCIATED(donor_state_set(i)%sf_evals)) THEN
1011  DEALLOCATE (donor_state_set(i)%sf_evals)
1012  END IF
1013 
1014  IF (ASSOCIATED(donor_state_set(i)%sg_evals)) THEN
1015  DEALLOCATE (donor_state_set(i)%sg_evals)
1016  END IF
1017 
1018  IF (ASSOCIATED(donor_state_set(i)%tp_evals)) THEN
1019  DEALLOCATE (donor_state_set(i)%tp_evals)
1020  END IF
1021 
1022  IF (ASSOCIATED(donor_state_set(i)%soc_evals)) THEN
1023  DEALLOCATE (donor_state_set(i)%soc_evals)
1024  END IF
1025 
1026  IF (ASSOCIATED(donor_state_set(i)%osc_str)) THEN
1027  DEALLOCATE (donor_state_set(i)%osc_str)
1028  END IF
1029 
1030  IF (ASSOCIATED(donor_state_set(i)%soc_osc_str)) THEN
1031  DEALLOCATE (donor_state_set(i)%soc_osc_str)
1032  END IF
1033 
1034  IF (ASSOCIATED(donor_state_set(i)%quad_osc_str)) THEN
1035  DEALLOCATE (donor_state_set(i)%quad_osc_str)
1036  END IF
1037 
1038  IF (ASSOCIATED(donor_state_set(i)%soc_quad_osc_str)) THEN
1039  DEALLOCATE (donor_state_set(i)%soc_quad_osc_str)
1040  END IF
1041 
1042  IF (ASSOCIATED(donor_state_set(i)%energy_evals)) THEN
1043  DEALLOCATE (donor_state_set(i)%energy_evals)
1044  END IF
1045 
1046  IF (ASSOCIATED(donor_state_set(i)%gw2x_evals)) THEN
1047  DEALLOCATE (donor_state_set(i)%gw2x_evals)
1048  END IF
1049 
1050  IF (ASSOCIATED(donor_state_set(i)%mo_indices)) THEN
1051  DEALLOCATE (donor_state_set(i)%mo_indices)
1052  END IF
1053 
1054  IF (ASSOCIATED(donor_state_set(i)%sc_matrix_tdp)) THEN
1055  CALL dbcsr_release(donor_state_set(i)%sc_matrix_tdp)
1056  DEALLOCATE (donor_state_set(i)%sc_matrix_tdp)
1057  END IF
1058 
1059  IF (ASSOCIATED(donor_state_set(i)%sf_matrix_tdp)) THEN
1060  CALL dbcsr_release(donor_state_set(i)%sf_matrix_tdp)
1061  DEALLOCATE (donor_state_set(i)%sf_matrix_tdp)
1062  END IF
1063 
1064  IF (ASSOCIATED(donor_state_set(i)%sg_matrix_tdp)) THEN
1065  CALL dbcsr_release(donor_state_set(i)%sg_matrix_tdp)
1066  DEALLOCATE (donor_state_set(i)%sg_matrix_tdp)
1067  END IF
1068 
1069  IF (ASSOCIATED(donor_state_set(i)%tp_matrix_tdp)) THEN
1070  CALL dbcsr_release(donor_state_set(i)%tp_matrix_tdp)
1071  DEALLOCATE (donor_state_set(i)%tp_matrix_tdp)
1072  END IF
1073 
1074  IF (ASSOCIATED(donor_state_set(i)%metric)) THEN
1075  DO j = 1, SIZE(donor_state_set(i)%metric)
1076  IF (ASSOCIATED(donor_state_set(i)%metric(j)%matrix)) THEN
1077  CALL dbcsr_release(donor_state_set(i)%metric(j)%matrix)
1078  DEALLOCATE (donor_state_set(i)%metric(j)%matrix)
1079  END IF
1080  END DO
1081  DEALLOCATE (donor_state_set(i)%metric)
1082  END IF
1083 
1084  IF (ASSOCIATED(donor_state_set(i)%matrix_aux)) THEN
1085  CALL dbcsr_release(donor_state_set(i)%matrix_aux)
1086  DEALLOCATE (donor_state_set(i)%matrix_aux)
1087  END IF
1088 
1089  IF (ASSOCIATED(donor_state_set(i)%blk_size)) THEN
1090  DEALLOCATE (donor_state_set(i)%blk_size)
1091  END IF
1092 
1093  IF (ASSOCIATED(donor_state_set(i)%dbcsr_dist)) THEN
1094  CALL dbcsr_distribution_release(donor_state_set(i)%dbcsr_dist)
1095  DEALLOCATE (donor_state_set(i)%dbcsr_dist)
1096  END IF
1097  END DO
1098  DEALLOCATE (donor_state_set)
1099  END IF
1100 
1101  END SUBROUTINE deallocate_donor_state_set
1102 
1103 ! **************************************************************************************************
1104 !> \brief Deallocate a donor_state's heavy attributes
1105 !> \param donor_state ...
1106 ! **************************************************************************************************
1107  SUBROUTINE free_ds_memory(donor_state)
1108 
1109  TYPE(donor_state_type), POINTER :: donor_state
1110 
1111  INTEGER :: i
1112 
1113  IF (ASSOCIATED(donor_state%sc_evals)) DEALLOCATE (donor_state%sc_evals)
1114  IF (ASSOCIATED(donor_state%contract_coeffs)) DEALLOCATE (donor_state%contract_coeffs)
1115  IF (ASSOCIATED(donor_state%sf_evals)) DEALLOCATE (donor_state%sf_evals)
1116  IF (ASSOCIATED(donor_state%sg_evals)) DEALLOCATE (donor_state%sg_evals)
1117  IF (ASSOCIATED(donor_state%tp_evals)) DEALLOCATE (donor_state%tp_evals)
1118  IF (ASSOCIATED(donor_state%soc_evals)) DEALLOCATE (donor_state%soc_evals)
1119  IF (ASSOCIATED(donor_state%osc_str)) DEALLOCATE (donor_state%osc_str)
1120  IF (ASSOCIATED(donor_state%soc_osc_str)) DEALLOCATE (donor_state%soc_osc_str)
1121  IF (ASSOCIATED(donor_state%quad_osc_str)) DEALLOCATE (donor_state%quad_osc_str)
1122  IF (ASSOCIATED(donor_state%soc_quad_osc_str)) DEALLOCATE (donor_state%soc_quad_osc_str)
1123  IF (ASSOCIATED(donor_state%gs_coeffs)) THEN
1124  CALL cp_fm_release(donor_state%gs_coeffs)
1125  DEALLOCATE (donor_state%gs_coeffs)
1126  NULLIFY (donor_state%gs_coeffs)
1127  END IF
1128  IF (ASSOCIATED(donor_state%blk_size)) DEALLOCATE (donor_state%blk_size)
1129 
1130  IF (ASSOCIATED(donor_state%sc_coeffs)) THEN
1131  CALL cp_fm_release(donor_state%sc_coeffs)
1132  DEALLOCATE (donor_state%sc_coeffs)
1133  NULLIFY (donor_state%sc_coeffs)
1134  END IF
1135 
1136  IF (ASSOCIATED(donor_state%sf_coeffs)) THEN
1137  CALL cp_fm_release(donor_state%sf_coeffs)
1138  DEALLOCATE (donor_state%sf_coeffs)
1139  NULLIFY (donor_state%sf_coeffs)
1140  END IF
1141 
1142  IF (ASSOCIATED(donor_state%sg_coeffs)) THEN
1143  CALL cp_fm_release(donor_state%sg_coeffs)
1144  DEALLOCATE (donor_state%sg_coeffs)
1145  NULLIFY (donor_state%sg_coeffs)
1146  END IF
1147 
1148  IF (ASSOCIATED(donor_state%tp_coeffs)) THEN
1149  CALL cp_fm_release(donor_state%tp_coeffs)
1150  DEALLOCATE (donor_state%tp_coeffs)
1151  NULLIFY (donor_state%tp_coeffs)
1152  END IF
1153 
1154  IF (ASSOCIATED(donor_state%sc_matrix_tdp)) THEN
1155  CALL dbcsr_release(donor_state%sc_matrix_tdp)
1156  DEALLOCATE (donor_state%sc_matrix_tdp)
1157  END IF
1158 
1159  IF (ASSOCIATED(donor_state%sf_matrix_tdp)) THEN
1160  CALL dbcsr_release(donor_state%sf_matrix_tdp)
1161  DEALLOCATE (donor_state%sf_matrix_tdp)
1162  END IF
1163 
1164  IF (ASSOCIATED(donor_state%sg_matrix_tdp)) THEN
1165  CALL dbcsr_release(donor_state%sg_matrix_tdp)
1166  DEALLOCATE (donor_state%sg_matrix_tdp)
1167  END IF
1168 
1169  IF (ASSOCIATED(donor_state%tp_matrix_tdp)) THEN
1170  CALL dbcsr_release(donor_state%tp_matrix_tdp)
1171  DEALLOCATE (donor_state%tp_matrix_tdp)
1172  END IF
1173 
1174  IF (ASSOCIATED(donor_state%metric)) THEN
1175  DO i = 1, SIZE(donor_state%metric)
1176  IF (ASSOCIATED(donor_state%metric(i)%matrix)) THEN
1177  CALL dbcsr_release(donor_state%metric(i)%matrix)
1178  DEALLOCATE (donor_state%metric(i)%matrix)
1179  END IF
1180  END DO
1181  DEALLOCATE (donor_state%metric)
1182  END IF
1183 
1184  IF (ASSOCIATED(donor_state%matrix_aux)) THEN
1185  CALL dbcsr_release(donor_state%matrix_aux)
1186  DEALLOCATE (donor_state%matrix_aux)
1187  END IF
1188 
1189  IF (ASSOCIATED(donor_state%dbcsr_dist)) THEN
1190  CALL dbcsr_distribution_release(donor_state%dbcsr_dist)
1191  DEALLOCATE (donor_state%dbcsr_dist)
1192  END IF
1193 
1194  END SUBROUTINE free_ds_memory
1195 
1196 ! **************************************************************************************************
1197 !> \brief Creates a xas_atom_env type
1198 !> \param xas_atom_env ...
1199 ! **************************************************************************************************
1200  SUBROUTINE xas_atom_env_create(xas_atom_env)
1201 
1202  TYPE(xas_atom_env_type), POINTER :: xas_atom_env
1203 
1204  ALLOCATE (xas_atom_env)
1205 
1206  xas_atom_env%nspins = 1
1207  xas_atom_env%ri_radius = 0.0_dp
1208  NULLIFY (xas_atom_env%excited_atoms)
1209  NULLIFY (xas_atom_env%excited_kinds)
1210  NULLIFY (xas_atom_env%grid_atom_set)
1211  NULLIFY (xas_atom_env%harmonics_atom_set)
1212  NULLIFY (xas_atom_env%ri_dcoeff)
1213  NULLIFY (xas_atom_env%ri_sphi_so)
1214  NULLIFY (xas_atom_env%orb_sphi_so)
1215  NULLIFY (xas_atom_env%exat_neighbors)
1216  NULLIFY (xas_atom_env%gr)
1217  NULLIFY (xas_atom_env%ga)
1218  NULLIFY (xas_atom_env%dgr1)
1219  NULLIFY (xas_atom_env%dgr2)
1220  NULLIFY (xas_atom_env%dga1)
1221  NULLIFY (xas_atom_env%dga2)
1222 
1223  END SUBROUTINE xas_atom_env_create
1224 
1225 ! **************************************************************************************************
1226 !> \brief Releases the xas_atom_env type
1227 !> \param xas_atom_env the type to release
1228 ! **************************************************************************************************
1229  SUBROUTINE xas_atom_env_release(xas_atom_env)
1230 
1231  TYPE(xas_atom_env_type), POINTER :: xas_atom_env
1232 
1233  INTEGER :: i, j, k
1234 
1235  IF (ASSOCIATED(xas_atom_env%grid_atom_set)) THEN
1236  DO i = 1, SIZE(xas_atom_env%grid_atom_set)
1237  IF (ASSOCIATED(xas_atom_env%grid_atom_set(i)%grid_atom)) THEN
1238  CALL deallocate_grid_atom(xas_atom_env%grid_atom_set(i)%grid_atom)
1239  END IF
1240  END DO
1241  DEALLOCATE (xas_atom_env%grid_atom_set)
1242  END IF
1243 
1244  IF (ASSOCIATED(xas_atom_env%harmonics_atom_set)) THEN
1245  DO i = 1, SIZE(xas_atom_env%harmonics_atom_set)
1246  IF (ASSOCIATED(xas_atom_env%harmonics_atom_set(i)%harmonics_atom)) THEN
1247  CALL deallocate_harmonics_atom(xas_atom_env%harmonics_atom_set(i)%harmonics_atom)
1248  END IF
1249  END DO
1250  DEALLOCATE (xas_atom_env%harmonics_atom_set)
1251  END IF
1252 
1253  ! Note that excited_atoms and excited_kinds are not deallocated because they point to other
1254  ! ressources, namely xas_tdp_env.
1255 
1256  IF (ASSOCIATED(xas_atom_env%ri_dcoeff)) THEN
1257  DO i = 1, SIZE(xas_atom_env%ri_dcoeff, 1)
1258  DO j = 1, SIZE(xas_atom_env%ri_dcoeff, 2)
1259  DO k = 1, SIZE(xas_atom_env%ri_dcoeff, 3)
1260  IF (ASSOCIATED(xas_atom_env%ri_dcoeff(i, j, k)%array)) THEN
1261  DEALLOCATE (xas_atom_env%ri_dcoeff(i, j, k)%array)
1262  END IF
1263  END DO
1264  END DO
1265  END DO
1266  DEALLOCATE (xas_atom_env%ri_dcoeff)
1267  END IF
1268 
1269  IF (ASSOCIATED(xas_atom_env%ri_sphi_so)) THEN
1270  DO i = 1, SIZE(xas_atom_env%ri_sphi_so)
1271  IF (ASSOCIATED(xas_atom_env%ri_sphi_so(i)%array)) THEN
1272  DEALLOCATE (xas_atom_env%ri_sphi_so(i)%array)
1273  END IF
1274  END DO
1275  DEALLOCATE (xas_atom_env%ri_sphi_so)
1276  END IF
1277 
1278  IF (ASSOCIATED(xas_atom_env%exat_neighbors)) THEN
1279  DO i = 1, SIZE(xas_atom_env%exat_neighbors)
1280  IF (ASSOCIATED(xas_atom_env%exat_neighbors(i)%array)) THEN
1281  DEALLOCATE (xas_atom_env%exat_neighbors(i)%array)
1282  END IF
1283  END DO
1284  DEALLOCATE (xas_atom_env%exat_neighbors)
1285  END IF
1286 
1287  IF (ASSOCIATED(xas_atom_env%gr)) THEN
1288  DO i = 1, SIZE(xas_atom_env%gr)
1289  IF (ASSOCIATED(xas_atom_env%gr(i)%array)) THEN
1290  DEALLOCATE (xas_atom_env%gr(i)%array)
1291  END IF
1292  END DO
1293  DEALLOCATE (xas_atom_env%gr)
1294  END IF
1295 
1296  IF (ASSOCIATED(xas_atom_env%ga)) THEN
1297  DO i = 1, SIZE(xas_atom_env%ga)
1298  IF (ASSOCIATED(xas_atom_env%ga(i)%array)) THEN
1299  DEALLOCATE (xas_atom_env%ga(i)%array)
1300  END IF
1301  END DO
1302  DEALLOCATE (xas_atom_env%ga)
1303  END IF
1304 
1305  IF (ASSOCIATED(xas_atom_env%dgr1)) THEN
1306  DO i = 1, SIZE(xas_atom_env%dgr1)
1307  IF (ASSOCIATED(xas_atom_env%dgr1(i)%array)) THEN
1308  DEALLOCATE (xas_atom_env%dgr1(i)%array)
1309  END IF
1310  END DO
1311  DEALLOCATE (xas_atom_env%dgr1)
1312  END IF
1313 
1314  IF (ASSOCIATED(xas_atom_env%dgr2)) THEN
1315  DO i = 1, SIZE(xas_atom_env%dgr2)
1316  IF (ASSOCIATED(xas_atom_env%dgr2(i)%array)) THEN
1317  DEALLOCATE (xas_atom_env%dgr2(i)%array)
1318  END IF
1319  END DO
1320  DEALLOCATE (xas_atom_env%dgr2)
1321  END IF
1322 
1323  IF (ASSOCIATED(xas_atom_env%dga1)) THEN
1324  DO i = 1, SIZE(xas_atom_env%dga1)
1325  IF (ASSOCIATED(xas_atom_env%dga1(i)%array)) THEN
1326  DEALLOCATE (xas_atom_env%dga1(i)%array)
1327  END IF
1328  END DO
1329  DEALLOCATE (xas_atom_env%dga1)
1330  END IF
1331 
1332  IF (ASSOCIATED(xas_atom_env%dga2)) THEN
1333  DO i = 1, SIZE(xas_atom_env%dga2)
1334  IF (ASSOCIATED(xas_atom_env%dga2(i)%array)) THEN
1335  DEALLOCATE (xas_atom_env%dga2(i)%array)
1336  END IF
1337  END DO
1338  DEALLOCATE (xas_atom_env%dga2)
1339  END IF
1340 
1341  IF (ASSOCIATED(xas_atom_env%orb_sphi_so)) THEN
1342  DO i = 1, SIZE(xas_atom_env%orb_sphi_so)
1343  IF (ASSOCIATED(xas_atom_env%orb_sphi_so(i)%array)) THEN
1344  DEALLOCATE (xas_atom_env%orb_sphi_so(i)%array)
1345  END IF
1346  END DO
1347  DEALLOCATE (xas_atom_env%orb_sphi_so)
1348  END IF
1349 
1350  !Clean-up libint
1352 
1353  DEALLOCATE (xas_atom_env)
1354 
1355  END SUBROUTINE xas_atom_env_release
1356 
1357 ! **************************************************************************************************
1358 !> \brief Releases the memory heavy attribute of xas_tdp_env that are specific to the current
1359 !> excited atom
1360 !> \param xas_tdp_env ...
1361 !> \param atom the index of the current excited atom
1362 !> \param end_of_batch whether batch specific quantities should be freed
1363 ! **************************************************************************************************
1364  SUBROUTINE free_exat_memory(xas_tdp_env, atom, end_of_batch)
1365 
1366  TYPE(xas_tdp_env_type), POINTER :: xas_tdp_env
1367  INTEGER, INTENT(IN) :: atom
1368  LOGICAL :: end_of_batch
1369 
1370  INTEGER :: i
1371 
1372  IF (ASSOCIATED(xas_tdp_env%ri_fxc)) THEN
1373  DO i = 1, SIZE(xas_tdp_env%ri_fxc, 2)
1374  IF (ASSOCIATED(xas_tdp_env%ri_fxc(atom, i)%array)) THEN
1375  DEALLOCATE (xas_tdp_env%ri_fxc(atom, i)%array)
1376  END IF
1377  END DO
1378  END IF
1379 
1380  IF (end_of_batch) THEN
1381  IF (ASSOCIATED(xas_tdp_env%opt_dist2d_ex)) THEN
1382  CALL distribution_2d_release(xas_tdp_env%opt_dist2d_ex)
1383  END IF
1384 
1385  IF (ASSOCIATED(xas_tdp_env%ri_3c_ex)) THEN
1386  CALL dbt_destroy(xas_tdp_env%ri_3c_ex)
1387  DEALLOCATE (xas_tdp_env%ri_3c_ex)
1388  END IF
1389  END IF
1390 
1391  xas_tdp_env%fxc_avail = .false.
1392 
1393  END SUBROUTINE free_exat_memory
1394 
1395 ! **************************************************************************************************
1396 !> \brief Releases a batch_info type
1397 !> \param batch_info ...
1398 ! **************************************************************************************************
1399  SUBROUTINE release_batch_info(batch_info)
1400 
1401  TYPE(batch_info_type) :: batch_info
1402 
1403  INTEGER :: i
1404 
1405  CALL batch_info%para_env%free()
1406 
1407  IF (ASSOCIATED(batch_info%so_proc_info)) THEN
1408  DO i = 1, SIZE(batch_info%so_proc_info)
1409  IF (ASSOCIATED(batch_info%so_proc_info(i)%array)) THEN
1410  DEALLOCATE (batch_info%so_proc_info(i)%array)
1411  END IF
1412  END DO
1413  DEALLOCATE (batch_info%so_proc_info)
1414  END IF
1415 
1416  END SUBROUTINE release_batch_info
1417 
1418 ! **************************************************************************************************
1419 !> \brief Uses heuristics to determine a good batching of the processros for fxc integration
1420 !> \param batch_size ...
1421 !> \param nbatch ...
1422 !> \param nex_atom ...
1423 !> \param nprocs ...
1424 !> \note It is here and not in xas_tdp_atom because of circular dependencies issues
1425 ! **************************************************************************************************
1426  SUBROUTINE get_proc_batch_sizes(batch_size, nbatch, nex_atom, nprocs)
1427 
1428  INTEGER, INTENT(OUT) :: batch_size, nbatch
1429  INTEGER, INTENT(IN) :: nex_atom, nprocs
1430 
1431  INTEGER :: rest, test_size
1432 
1433  !We have essentially 2 cases nex_atom >= nprocs or nex_atom < nprocs
1434 
1435  IF (nex_atom >= nprocs) THEN
1436 
1437  !If nex_atom >= nprocs, we look from batch size (starting from 1, ending with 4) that yields
1438  !the best indicative load balance, i.e. the best spread of excited atom per batch
1439  rest = 100000
1440  DO test_size = 1, min(nprocs, 4)
1441  nbatch = nprocs/test_size
1442  IF (modulo(nex_atom, nbatch) < rest) THEN
1443  rest = modulo(nex_atom, nbatch)
1444  batch_size = test_size
1445  END IF
1446  END DO
1447  nbatch = nprocs/batch_size
1448 
1449  ELSE
1450 
1451  !If nex_atom < nprocs, simply devide processors in nex_atom batches
1452  !At most 128 ranks per atom, experiments have shown that if nprocs >>> nex_atom, crahes occur.
1453  !The 128 upper limit is based on trial and error
1454  nbatch = nex_atom
1455  batch_size = min(nprocs/nbatch, 128)
1456 
1457  END IF
1458 
1459  !Note: because of possible odd numbers of MPI ranks / excited atoms, a couple of procs can
1460  ! be excluded from the batching (max 4)
1461 
1462  END SUBROUTINE get_proc_batch_sizes
1463 
1464 END MODULE xas_tdp_types
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
Definition: grid_common.h:117
Definition: atom.F:9
various utilities that regard array of different kinds: output, allocation,... maybe it is not a good...
Utility routines to open and close files. Tracking of preconnections.
Definition: cp_files.F:16
logical function, public file_exists(file_name)
Checks if file exists, considering also the file discovery mechanism.
Definition: cp_files.F:494
represent a full matrix distributed on many processors
Definition: cp_fm_types.F:15
This is the start of a dbt_api, all publically needed functions are exported here....
Definition: dbt_api.F:17
stores a mapping of 2D info (e.g. matrix) on a 2D processor distribution (i.e. blacs grid) where cpus...
subroutine, public distribution_2d_release(distribution_2d)
...
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public tddfpt_singlet
integer, parameter, public ot_mini_cg
integer, parameter, public xas_dip_vel
integer, parameter, public tddfpt_triplet
integer, parameter, public ot_mini_diis
integer, parameter, public tddfpt_spin_flip
integer, parameter, public xas_tdp_by_kind
integer, parameter, public do_potential_truncated
integer, parameter, public xas_tdp_by_index
integer, parameter, public do_potential_coulomb
integer, parameter, public do_potential_short
integer, parameter, public tddfpt_spin_cons
integer, parameter, public xc_none
objects that represent the structure of input sections and the data contained in an input section
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
recursive subroutine, public section_vals_release(section_vals)
releases the given object
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public dp
Definition: kinds.F:34
integer, parameter, public default_string_length
Definition: kinds.F:57
2- and 3-center electron repulsion integral routines based on libint2 Currently available operators: ...
Definition: libint_2c_3c.F:14
Interface to the Libint-Library or a c++ wrapper.
subroutine, public cp_libint_static_cleanup()
Collection of simple mathematical functions and subroutines.
Definition: mathlib.F:15
subroutine, public erfc_cutoff(eps, omg, r_cutoff)
compute a truncation radius for the shortrange operator
Definition: mathlib.F:1689
Utility routines for the memory handling.
Interface to the message passing library MPI.
Definition of physical constants:
Definition: physcon.F:68
real(kind=dp), parameter, public evolt
Definition: physcon.F:183
real(kind=dp), parameter, public bohr
Definition: physcon.F:147
subroutine, public deallocate_grid_atom(grid_atom)
Deallocate a Gaussian-type orbital (GTO) basis set data set.
Definition: qs_grid_atom.F:105
subroutine, public deallocate_harmonics_atom(harmonics)
Deallocate the spherical harmonics set for the atom grid.
New version of the module for the localization of the molecular orbitals This should be able to use d...
Definition: qs_loc_types.F:25
subroutine, public qs_loc_env_release(qs_loc_env)
...
Definition: qs_loc_types.F:192
orbital transformations
Definition: qs_ot_types.F:15
subroutine, public qs_ot_settings_init(settings)
sets default values for the settings type
Definition: qs_ot_types.F:215
Define XAS TDP control type and associated create, release, etc subroutines, as well as XAS TDP envir...
Definition: xas_tdp_types.F:13
subroutine, public xas_tdp_env_create(xas_tdp_env)
Creates a TDP XAS environment type.
subroutine, public xas_tdp_env_release(xas_tdp_env)
Releases the TDP XAS environment type.
subroutine, public donor_state_create(donor_state)
Creates a donor_state.
subroutine, public get_proc_batch_sizes(batch_size, nbatch, nex_atom, nprocs)
Uses heuristics to determine a good batching of the processros for fxc integration.
subroutine, public xas_tdp_control_release(xas_tdp_control)
Releases the xas_tdp_control_type.
subroutine, public xas_atom_env_create(xas_atom_env)
Creates a xas_atom_env type.
subroutine, public set_xas_tdp_env(xas_tdp_env, nex_atoms, nex_kinds)
Sets values of selected variables within the TDP XAS environment type.
subroutine, public free_ds_memory(donor_state)
Deallocate a donor_state's heavy attributes.
subroutine, public release_batch_info(batch_info)
Releases a batch_info type.
subroutine, public set_donor_state(donor_state, at_index, at_symbol, kind_index, state_type)
sets specified values of the donor state type
subroutine, public xas_tdp_control_create(xas_tdp_control)
Creates and initializes the xas_tdp_control_type.
subroutine, public free_exat_memory(xas_tdp_env, atom, end_of_batch)
Releases the memory heavy attribute of xas_tdp_env that are specific to the current excited atom.
subroutine, public xas_atom_env_release(xas_atom_env)
Releases the xas_atom_env type.
subroutine, public read_xas_tdp_control(xas_tdp_control, xas_tdp_section)
Reads the inputs and stores in xas_tdp_control_type.