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