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