31 USE dbcsr_api,
ONLY: dbcsr_p_type
44 #include "./base/base_uses.f90"
48 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_tddfpt_utils'
55 REAL(kind=
dp) ::
value
80 TYPE(qs_p_env_type),
INTENT(INOUT) :: p_env
82 TYPE(qs_environment_type),
POINTER :: qs_env
88 CALL p_env_create(p_env, qs_env, orthogonal_orbitals=.true.)
95 CALL tddfpt_env_init(t_env, qs_env)
104 SUBROUTINE tddfpt_env_init(t_env, qs_env)
107 TYPE(qs_environment_type),
POINTER :: qs_env
109 INTEGER :: n_spins, spin
110 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s
111 TYPE(dft_control_type),
POINTER :: dft_control
113 NULLIFY (matrix_s, dft_control)
115 CALL get_qs_env(qs_env, matrix_s=matrix_s, dft_control=dft_control)
116 n_spins = dft_control%nspins
117 IF (dft_control%tddfpt_control%invert_S)
THEN
125 END SUBROUTINE tddfpt_env_init
135 TYPE(qs_p_env_type),
INTENT(INOUT) :: p_env
151 TYPE(cp_fm_type),
DIMENSION(:, :),
POINTER :: matrices
152 REAL(kind=
dp),
DIMENSION(:),
INTENT(OUT) :: energies
153 INTEGER,
INTENT(IN) :: n_v
154 TYPE(qs_environment_type),
POINTER :: qs_env
156 INTEGER :: i, n_cols, n_lumos, n_orbits, n_rows, &
157 n_spins, oo, spin, vo
159 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: guess, lumos
160 REAL(kind=
dp),
DIMENSION(:),
POINTER :: orbital_eigenvalues
161 TYPE(dft_control_type),
POINTER :: dft_control
164 TYPE(tddfpt_control_type),
POINTER :: tddfpt_control
168 NULLIFY (dft_control)
170 CALL get_qs_env(qs_env, dft_control=dft_control)
171 tddfpt_control => dft_control%tddfpt_control
172 n_spins = dft_control%nspins
175 IF (.NOT.
ASSOCIATED(tddfpt_control%lumos))
THEN
176 cpabort(
"LUMOS missing")
181 n_cols = matrices(1, spin)%matrix_struct%ncol_global
182 n_rows = matrices(1, spin)%matrix_struct%nrow_global
188 CALL get_mo_set(qs_env%mos(spin), eigenvalues=orbital_eigenvalues)
190 n_lumos = tddfpt_control%lumos(spin)%matrix_struct%ncol_global
192 n_orbits =
SIZE(orbital_eigenvalues)
198 evd = tddfpt_control%lumos_eigenvalues(1, spin) - orbital_eigenvalues(n_orbits)
199 ALLOCATE (sorter_start)
200 sorter_start%orbit = n_orbits
201 sorter_start%lumo = 1
202 sorter_start%value = evd
203 NULLIFY (sorter_start%next)
205 DO oo = n_orbits, 1, -1
208 IF (oo == n_orbits .AND. vo == 1) cycle
210 evd = tddfpt_control%lumos_eigenvalues(vo, spin) - orbital_eigenvalues(oo)
212 sorter_iterator => sorter_start
213 NULLIFY (sorter_pointer)
214 DO WHILE (
ASSOCIATED(sorter_iterator%next))
215 IF (sorter_iterator%next%value > evd)
THEN
216 sorter_pointer => sorter_iterator%next
219 sorter_iterator => sorter_iterator%next
222 ALLOCATE (sorter_iterator%next)
223 sorter_iterator%next%orbit = oo
224 sorter_iterator%next%lumo = vo
225 sorter_iterator%next%value = evd
226 sorter_iterator%next%next => sorter_pointer
231 ALLOCATE (lumos(n_rows, n_lumos), guess(n_rows, n_orbits))
233 start_col=1, n_cols=n_lumos)
238 sorter_iterator => sorter_start
239 DO i = 1, min(n_v, n_orbits*n_lumos)
241 CALL dcopy(n_rows, lumos(:, sorter_iterator%lumo), 1, &
242 guess(:, sorter_iterator%orbit), 1)
244 energies(i) = energies(i) + sorter_iterator%value/real(n_spins,
dp)
245 sorter_iterator => sorter_iterator%next
247 IF (n_v > n_orbits*n_lumos)
THEN
248 DO i = n_orbits*n_lumos + 1, n_v
250 energies(i) = 1.0e38_dp
257 DEALLOCATE (lumos, guess)
258 sorter_iterator => sorter_start
259 DO WHILE (
ASSOCIATED(sorter_iterator))
260 sorter_pointer => sorter_iterator
261 sorter_iterator => sorter_iterator%next
262 DEALLOCATE (sorter_pointer)
276 TYPE(qs_environment_type),
POINTER :: qs_env
279 INTEGER :: i, j, n_ev, n_spins, occ, output_unit, &
281 INTEGER,
DIMENSION(2) :: nhomos, nlumos, nrows
282 REAL(kind=
dp) :: contribution, summed_contributions
283 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: homo_coeff_col, lumo_coeff_col
284 TYPE(cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: s_lumos
285 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s
286 TYPE(dft_control_type),
POINTER :: dft_control
287 TYPE(tddfpt_control_type) :: t_control
289 NULLIFY (matrix_s, dft_control)
291 CALL get_qs_env(qs_env, matrix_s=matrix_s, dft_control=dft_control)
293 IF (output_unit > 0)
WRITE (output_unit, *)
294 IF (output_unit > 0)
WRITE (output_unit, *)
296 t_control = dft_control%tddfpt_control
297 n_ev = t_control%n_ev
298 n_spins = dft_control%nspins
300 ALLOCATE (s_lumos(n_spins))
303 nrows(spin) = t_control%lumos(spin)%matrix_struct%nrow_global
304 nhomos(spin) = t_env%evecs(1, spin)%matrix_struct%ncol_global
305 nlumos(spin) = t_control%lumos(spin)%matrix_struct%ncol_global
306 CALL cp_fm_create(s_lumos(spin), t_control%lumos(spin)%matrix_struct, &
309 s_lumos(spin), nlumos(spin), 1.0_dp, 0.0_dp)
312 ALLOCATE (homo_coeff_col(maxval(nrows(1:n_spins)), 1), &
313 lumo_coeff_col(maxval(nrows(1:n_spins)), 1))
315 IF (output_unit > 0)
THEN
316 WRITE (output_unit,
'(A,I3,5X,F15.6)')
" excited state : ", i, t_env%evals(i)*
evolt
317 WRITE (output_unit, *)
319 summed_contributions = 0.0_dp
321 IF (n_spins == 2)
THEN
323 IF (output_unit > 0)
WRITE (output_unit, *)
'alpha:'
325 IF (output_unit > 0)
WRITE (output_unit, *)
'beta:'
328 searchloop:
DO occ = nhomos(spin), 1, -1
330 1, occ, nrows(spin), 1)
331 DO virt = 1, nlumos(spin)
333 1, virt, nrows(spin), 1)
334 contribution = 0.0_dp
335 DO j = 1, nrows(spin)
336 contribution = contribution + homo_coeff_col(j, 1)*lumo_coeff_col(j, 1)
338 summed_contributions = summed_contributions + (contribution)**2
339 IF (abs(contribution) > 5.0e-2_dp)
THEN
340 IF (output_unit > 0)
WRITE (output_unit,
'(14X,I5,A,I5,10X,F8.3,5X,F8.3)') &
341 occ,
" ->", nhomos(spin) + virt, abs(contribution), summed_contributions
343 IF (abs(summed_contributions - 1.0_dp) < 1.0e-3_dp) cycle searchloop
347 IF (output_unit > 0)
WRITE (output_unit, *)
352 IF (output_unit > 0)
THEN
353 WRITE (output_unit,
'(T2,A,E14.6)')
' TDDFPT : CheckSum =', sqrt(sum(t_env%evals**2))
356 CALL cp_fm_release(s_lumos)
358 DEALLOCATE (homo_coeff_col, lumo_coeff_col)
370 TYPE(cp_fm_type),
DIMENSION(:),
INTENT(IN) :: x, tmp_vec
371 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: metric
373 INTEGER :: n_spins, spin
374 REAL(kind=
dp) :: norm, tmp
383 x(spin)%matrix_struct%ncol_global, &
385 CALL cp_fm_trace(x(spin), tmp_vec(spin), tmp)
410 TYPE(cp_fm_type),
DIMENSION(:),
INTENT(IN) :: x
411 TYPE(cp_fm_type),
DIMENSION(:, :),
INTENT(IN) :: v_set, sv_set
412 TYPE(cp_fm_type),
DIMENSION(:),
INTENT(IN) :: work
413 INTEGER,
INTENT(IN) :: n
415 CHARACTER(LEN=*),
PARAMETER :: routinen =
'reorthogonalize'
417 INTEGER :: handle, i, n_spins, spin
418 REAL(
dp) :: dot_product, tmp
420 CALL timeset(routinen, handle)
426 CALL cp_fm_to_fm(x(spin), work(spin))
432 CALL cp_fm_trace(sv_set(i, spin), work(spin), tmp)
433 dot_product = dot_product + tmp
437 -1.0_dp*dot_product, v_set(i, spin))
443 CALL timestop(handle)
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
DBCSR operations in CP2K.
subroutine, public cp_dbcsr_sm_fm_multiply(matrix, fm_in, fm_out, ncol, alpha, beta)
multiply a dbcsr with a fm matrix
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
basic linear algebra operations for full matrices
subroutine, public cp_fm_scale_and_add(alpha, matrix_a, beta, matrix_b)
calc A <- alpha*A + beta*B optimized for alpha == 1.0 (just add beta*B) and beta == 0....
subroutine, public cp_fm_scale(alpha, matrix_a)
scales a matrix matrix_a = alpha * matrix_b
various cholesky decomposition related routines
subroutine, public cp_fm_cholesky_invert(matrix, n, info_out)
used to replace the cholesky decomposition by the inverse
subroutine, public cp_fm_cholesky_decompose(matrix, n, info_out)
used to replace a symmetric positive def. matrix M with its cholesky decomposition U: M = U^T * U,...
represent a full matrix distributed on many processors
subroutine, public cp_fm_set_submatrix(fm, new_values, start_row, start_col, n_rows, n_cols, alpha, beta, transpose)
sets a submatrix of a full matrix fm(start_row:start_row+n_rows,start_col:start_col+n_cols) = alpha*o...
subroutine, public cp_fm_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_get_submatrix(fm, target_m, start_row, start_col, n_rows, n_cols, transpose)
gets a submatrix of a full matrix op(target_m)(1:n_rows,1:n_cols) =fm(start_row:start_row+n_rows,...
subroutine, public cp_fm_init_random(matrix, ncol, start_col)
fills a matrix with random numbers
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp)
creates a new full matrix with the given structure
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
Defines the basic variable types.
integer, parameter, public dp
Definition of physical constants:
real(kind=dp), parameter, public evolt
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_RI_aux_kp, matrix_s, matrix_s_RI_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, WannierCentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, rhs)
Get the QUICKSTEP environment.
Definition and initialisation of the mo data type.
subroutine, public get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, uniform_occupation, kTS, mu, flexible_electron_count)
Get the components of a MO set data structure.
Utility functions for the perturbation calculations.
subroutine, public p_env_psi0_changed(p_env, qs_env)
To be called after the value of psi0 has changed. Recalculates the quantities S_psi0 and m_epsilon.
subroutine, public p_env_create(p_env, qs_env, p1_option, p1_admm_option, orthogonal_orbitals, linres_control)
allocates and initializes the perturbation environment (no setup)
basis types for the calculation of the perturbation of density theory.
subroutine, public p_env_release(p_env)
relases the given p_env (see doc/ReferenceCounting.html)
subroutine, public tddfpt_env_deallocate(t_env)
...
subroutine, public tddfpt_env_allocate(t_env, p_env, qs_env)
...
subroutine, public reorthogonalize(X, V_set, SV_set, work, n)
...
subroutine, public find_contributions(qs_env, t_env)
...
logical, parameter debug_this_module
subroutine, public tddfpt_init(p_env, t_env, qs_env)
Initialize some necessary structures for a tddfpt calculation.
subroutine, public co_initial_guess(matrices, energies, n_v, qs_env)
...
subroutine, public tddfpt_cleanup(t_env, p_env)
...
subroutine, public normalize(X, tmp_vec, metric)
...