(git:b6ef100)
Loading...
Searching...
No Matches
rt_propagation_methods.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 Routines for propagating the orbitals
10!> \author Florian Schiffmann (02.09)
11! **************************************************************************************************
13 USE bibliography, ONLY: kolafa2004,&
14 kuhne2007,&
16 cite_reference
17 USE cell_types, ONLY: cell_type
21 USE cp_cfm_types, ONLY: cp_cfm_create,&
26 USE cp_dbcsr_api, ONLY: &
31 dbcsr_type, dbcsr_type_antisymmetric
43 USE cp_fm_types, ONLY: cp_fm_create,&
53 USE cp_output_handling, ONLY: cp_p_file,&
56 USE input_constants, ONLY: do_arnoldi,&
57 do_bch,&
58 do_em,&
59 do_pade,&
64 USE kinds, ONLY: dp
66 USE mathlib, ONLY: binomial
69 USE pw_env_types, ONLY: pw_env_get,&
72 USE pw_types, ONLY: pw_c1d_gs_type,&
79 USE qs_ks_types, ONLY: set_ks_env
80 USE qs_loc_dipole, ONLY: loc_dipole
87 USE qs_mo_types, ONLY: get_mo_set,&
96 USE rt_propagation_types, ONLY: get_rtp,&
103#include "../base/base_uses.f90"
104
105 IMPLICIT NONE
106
107 PRIVATE
108
109 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'rt_propagation_methods'
110
111 PUBLIC :: propagation_step, &
113 calc_sinvh, &
116
117CONTAINS
118
119! **************************************************************************************************
120!> \brief performs a single propagation step a(t+Dt)=U(t+Dt,t)*a(0)
121!> and calculates the new exponential
122!> \param qs_env ...
123!> \param rtp ...
124!> \param rtp_control ...
125!> \author Florian Schiffmann (02.09)
126! **************************************************************************************************
127
128 SUBROUTINE propagation_step(qs_env, rtp, rtp_control)
129
130 TYPE(qs_environment_type), POINTER :: qs_env
131 TYPE(rt_prop_type), POINTER :: rtp
132 TYPE(rtp_control_type), POINTER :: rtp_control
133
134 CHARACTER(len=*), PARAMETER :: routinen = 'propagation_step'
135
136 INTEGER :: aspc_order, handle, i, im, re, unit_nr
137 TYPE(cell_type), POINTER :: cell
138 TYPE(cp_fm_type), DIMENSION(:), POINTER :: delta_mos, mos_new
139 TYPE(cp_logger_type), POINTER :: logger
140 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: delta_p, h_last_iter, ks_mix, ks_mix_im, &
141 matrix_ks, matrix_ks_im, matrix_s, &
142 rho_new
143 TYPE(dft_control_type), POINTER :: dft_control
144
145 CALL timeset(routinen, handle)
146
147 logger => cp_get_default_logger()
148 IF (logger%para_env%is_source()) THEN
149 unit_nr = cp_logger_get_default_unit_nr(logger, local=.true.)
150 ELSE
151 unit_nr = -1
152 END IF
153
154 NULLIFY (cell, delta_p, rho_new, delta_mos, mos_new)
155 NULLIFY (ks_mix, ks_mix_im)
156 ! get everything needed and set some values
157 CALL get_qs_env(qs_env, cell=cell, matrix_s=matrix_s, dft_control=dft_control)
158
159 IF (rtp%iter == 1) THEN
160 CALL qs_energies_init(qs_env, .false.)
161 !the above recalculates matrix_s, but matrix not changed if ions are fixed
162 IF (rtp_control%fixed_ions) CALL set_ks_env(qs_env%ks_env, s_mstruct_changed=.false.)
163
164 ! add additional terms to matrix_h and matrix_h_im in the case of applied electric field,
165 ! either in the lengh or velocity gauge.
166 ! should be called after qs_energies_init and before qs_ks_update_qs_env
167 IF (dft_control%apply_efield_field) THEN
168 IF (any(cell%perd(1:3) /= 0)) THEN
169 cpabort("Length gauge (efield) and periodicity are not compatible")
170 END IF
172 ELSE IF (rtp_control%velocity_gauge) THEN
173 IF (dft_control%apply_vector_potential) THEN
174 CALL update_vector_potential(qs_env, dft_control)
175 END IF
176 CALL velocity_gauge_ks_matrix(qs_env, subtract_nl_term=.false.)
177 END IF
178
179 CALL get_qs_env(qs_env, matrix_s=matrix_s)
180 IF (.NOT. rtp_control%fixed_ions) THEN
181 CALL s_matrices_create(matrix_s, rtp)
182 END IF
183 rtp%delta_iter = 100.0_dp
184 rtp%mixing_factor = 1.0_dp
185 rtp%mixing = .false.
186 aspc_order = rtp_control%aspc_order
187 CALL aspc_extrapolate(rtp, matrix_s, aspc_order)
188 IF (rtp%linear_scaling) THEN
189 CALL calc_update_rho_sparse(qs_env)
190 ELSE
191 CALL calc_update_rho(qs_env)
192 END IF
193 CALL qs_ks_update_qs_env(qs_env, calculate_forces=.false.)
194 END IF
195 IF (.NOT. rtp_control%fixed_ions) THEN
196 CALL calc_s_derivs(qs_env)
197 END IF
198 rtp%converged = .false.
199
200 IF (rtp%linear_scaling) THEN
201 ! keep temporary copy of the starting density matrix to check for convergence
202 CALL get_rtp(rtp=rtp, rho_new=rho_new)
203 NULLIFY (delta_p)
204 CALL dbcsr_allocate_matrix_set(delta_p, SIZE(rho_new))
205 DO i = 1, SIZE(rho_new)
206 CALL dbcsr_init_p(delta_p(i)%matrix)
207 CALL dbcsr_create(delta_p(i)%matrix, template=rho_new(i)%matrix)
208 CALL dbcsr_copy(delta_p(i)%matrix, rho_new(i)%matrix)
209 END DO
210 ELSE
211 ! keep temporary copy of the starting mos to check for convergence
212 CALL get_rtp(rtp=rtp, mos_new=mos_new)
213 ALLOCATE (delta_mos(SIZE(mos_new)))
214 DO i = 1, SIZE(mos_new)
215 CALL cp_fm_create(delta_mos(i), &
216 matrix_struct=mos_new(i)%matrix_struct, &
217 name="delta_mos"//trim(adjustl(cp_to_string(i))))
218 CALL cp_fm_to_fm(mos_new(i), delta_mos(i))
219 END DO
220 END IF
221
222 CALL get_qs_env(qs_env, &
223 matrix_ks=matrix_ks, &
224 matrix_ks_im=matrix_ks_im)
225
226 CALL get_rtp(rtp=rtp, h_last_iter=h_last_iter)
227 IF (rtp%mixing) THEN
228 IF (unit_nr > 0) THEN
229 WRITE (unit_nr, '(t3,a,2f16.8)') "Mixing the Hamiltonians to improve robustness, mixing factor: ", rtp%mixing_factor
230 END IF
231 CALL dbcsr_allocate_matrix_set(ks_mix, SIZE(matrix_ks))
232 CALL dbcsr_allocate_matrix_set(ks_mix_im, SIZE(matrix_ks))
233 DO i = 1, SIZE(matrix_ks)
234 CALL dbcsr_init_p(ks_mix(i)%matrix)
235 CALL dbcsr_create(ks_mix(i)%matrix, template=matrix_ks(1)%matrix)
236 CALL dbcsr_init_p(ks_mix_im(i)%matrix)
237 CALL dbcsr_create(ks_mix_im(i)%matrix, template=matrix_ks(1)%matrix, matrix_type=dbcsr_type_antisymmetric)
238 END DO
239 DO i = 1, SIZE(matrix_ks)
240 re = 2*i - 1
241 im = 2*i
242 CALL dbcsr_add(ks_mix(i)%matrix, matrix_ks(i)%matrix, 0.0_dp, rtp%mixing_factor)
243 CALL dbcsr_add(ks_mix(i)%matrix, h_last_iter(re)%matrix, 1.0_dp, 1.0_dp - rtp%mixing_factor)
244 IF (rtp%propagate_complex_ks) THEN
245 CALL dbcsr_add(ks_mix_im(i)%matrix, matrix_ks_im(i)%matrix, 0.0_dp, rtp%mixing_factor)
246 CALL dbcsr_add(ks_mix_im(i)%matrix, h_last_iter(im)%matrix, 1.0_dp, 1.0_dp - rtp%mixing_factor)
247 END IF
248 END DO
249 CALL calc_sinvh(rtp, ks_mix, ks_mix_im, rtp_control)
250 DO i = 1, SIZE(matrix_ks)
251 re = 2*i - 1
252 im = 2*i
253 CALL dbcsr_copy(h_last_iter(re)%matrix, ks_mix(i)%matrix)
254 IF (rtp%propagate_complex_ks) THEN
255 CALL dbcsr_copy(h_last_iter(im)%matrix, ks_mix_im(i)%matrix)
256 END IF
257 END DO
258 CALL dbcsr_deallocate_matrix_set(ks_mix)
259 CALL dbcsr_deallocate_matrix_set(ks_mix_im)
260 ELSE
261 CALL calc_sinvh(rtp, matrix_ks, matrix_ks_im, rtp_control)
262 DO i = 1, SIZE(matrix_ks)
263 re = 2*i - 1
264 im = 2*i
265 CALL dbcsr_copy(h_last_iter(re)%matrix, matrix_ks(i)%matrix)
266 IF (rtp%propagate_complex_ks) THEN
267 CALL dbcsr_copy(h_last_iter(im)%matrix, matrix_ks_im(i)%matrix)
268 END IF
269 END DO
270 END IF
271
272 CALL compute_propagator_matrix(rtp, rtp_control%propagator)
273
274 SELECT CASE (rtp_control%mat_exp)
275 CASE (do_pade, do_taylor)
276 IF (rtp%linear_scaling) THEN
277 CALL propagate_exp_density(rtp, rtp_control)
278 CALL calc_update_rho_sparse(qs_env)
279 ELSE
280 CALL propagate_exp(rtp, rtp_control)
281 CALL calc_update_rho(qs_env)
282 END IF
283 CASE (do_arnoldi)
284 CALL propagate_arnoldi(rtp, rtp_control)
285 CALL calc_update_rho(qs_env)
286 CASE (do_bch)
287 CALL propagate_bch(rtp, rtp_control)
288 CALL calc_update_rho_sparse(qs_env)
289 END SELECT
290 CALL step_finalize(qs_env, rtp_control, delta_mos, delta_p)
291 IF (rtp%linear_scaling) THEN
292 CALL dbcsr_deallocate_matrix_set(delta_p)
293 ELSE
294 CALL cp_fm_release(delta_mos)
295 END IF
296
297 CALL timestop(handle)
298
299 END SUBROUTINE propagation_step
300
301! **************************************************************************************************
302!> \brief Performs all the stuff to finish the step:
303!> convergence checks
304!> copying stuff into right place for the next step
305!> updating the history for extrapolation
306!> \param qs_env ...
307!> \param rtp_control ...
308!> \param delta_mos ...
309!> \param delta_P ...
310!> \author Florian Schiffmann (02.09)
311! **************************************************************************************************
312
313 SUBROUTINE step_finalize(qs_env, rtp_control, delta_mos, delta_P)
314 TYPE(qs_environment_type), POINTER :: qs_env
315 TYPE(rtp_control_type), POINTER :: rtp_control
316 TYPE(cp_fm_type), DIMENSION(:), POINTER :: delta_mos
317 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: delta_p
318
319 CHARACTER(len=*), PARAMETER :: routinen = 'step_finalize'
320
321 INTEGER :: handle, i, ihist
322 TYPE(cp_fm_type), DIMENSION(:), POINTER :: mos_new, mos_old
323 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: exp_h_new, exp_h_old, matrix_ks, &
324 matrix_ks_im, rho_new, rho_old, s_mat
325 TYPE(qs_energy_type), POINTER :: energy
326 TYPE(rt_prop_type), POINTER :: rtp
327
328 CALL timeset(routinen, handle)
329
330 CALL get_qs_env(qs_env=qs_env, rtp=rtp, matrix_s=s_mat, &
331 matrix_ks=matrix_ks, matrix_ks_im=matrix_ks_im, energy=energy)
332 CALL get_rtp(rtp=rtp, exp_h_old=exp_h_old, exp_h_new=exp_h_new)
333
334 IF (rtp_control%sc_check_start < rtp%iter) THEN
335 rtp%delta_iter_old = rtp%delta_iter
336 IF (rtp%linear_scaling) THEN
337 CALL rt_convergence_density(rtp, delta_p, rtp%delta_iter)
338 ELSE
339 CALL rt_convergence(rtp, s_mat(1)%matrix, delta_mos, rtp%delta_iter)
340 END IF
341 rtp%converged = (rtp%delta_iter < rtp_control%eps_ener)
342 !Apply mixing if scf loop is not converging
343
344 !It would be better to redo the current step with mixixng,
345 !but currently the decision is made to use mixing from the next step on
346 IF (rtp_control%sc_check_start < rtp%iter + 1) THEN
347 IF (rtp%delta_iter/rtp%delta_iter_old > 0.9) THEN
348 rtp%mixing_factor = max(rtp%mixing_factor/2.0_dp, 0.125_dp)
349 rtp%mixing = .true.
350 END IF
351 END IF
352 END IF
353
354 IF (rtp%converged) THEN
355 IF (rtp%linear_scaling) THEN
356 CALL get_rtp(rtp=rtp, rho_old=rho_old, rho_new=rho_new)
357 CALL purify_mcweeny_complex_nonorth(rho_new, s_mat, rtp%filter_eps, rtp%filter_eps_small, &
358 rtp_control%mcweeny_max_iter, rtp_control%mcweeny_eps)
359 IF (rtp_control%mcweeny_max_iter > 0) CALL calc_update_rho_sparse(qs_env)
360 CALL report_density_occupation(rtp%filter_eps, rho_new)
361 DO i = 1, SIZE(rho_new)
362 CALL dbcsr_copy(rho_old(i)%matrix, rho_new(i)%matrix)
363 END DO
364 ELSE
365 CALL get_rtp(rtp=rtp, mos_old=mos_old, mos_new=mos_new)
366 DO i = 1, SIZE(mos_new)
367 CALL cp_fm_to_fm(mos_new(i), mos_old(i))
368 END DO
369 END IF
370 IF (rtp_control%propagator == do_em) CALL calc_sinvh(rtp, matrix_ks, matrix_ks_im, rtp_control)
371 DO i = 1, SIZE(exp_h_new)
372 CALL dbcsr_copy(exp_h_old(i)%matrix, exp_h_new(i)%matrix)
373 END DO
374 ihist = mod(rtp%istep, rtp_control%aspc_order) + 1
375 IF (rtp_control%fixed_ions) THEN
376 CALL put_data_to_history(rtp, rho=rho_new, mos=mos_new, ihist=ihist)
377 ELSE
378 CALL put_data_to_history(rtp, rho=rho_new, mos=mos_new, s_mat=s_mat, ihist=ihist)
379 END IF
380 END IF
381
382 rtp%energy_new = energy%total
383
384 CALL timestop(handle)
385
386 END SUBROUTINE step_finalize
387
388! **************************************************************************************************
389!> \brief computes the propagator matrix for EM/ETRS, RTP/EMD
390!> \param rtp ...
391!> \param propagator ...
392!> \author Florian Schiffmann (02.09)
393! **************************************************************************************************
394
395 SUBROUTINE compute_propagator_matrix(rtp, propagator)
396 TYPE(rt_prop_type), POINTER :: rtp
397 INTEGER :: propagator
398
399 CHARACTER(len=*), PARAMETER :: routinen = 'compute_propagator_matrix'
400
401 INTEGER :: handle, i
402 REAL(kind=dp) :: dt, prefac
403 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: exp_h_new, exp_h_old, propagator_matrix
404
405 CALL timeset(routinen, handle)
406 CALL get_rtp(rtp=rtp, exp_h_new=exp_h_new, exp_h_old=exp_h_old, &
407 propagator_matrix=propagator_matrix, dt=dt)
408
409 prefac = -0.5_dp*dt
410
411 DO i = 1, SIZE(exp_h_new)
412 CALL dbcsr_add(propagator_matrix(i)%matrix, exp_h_new(i)%matrix, 0.0_dp, prefac)
413 IF (propagator == do_em) THEN
414 CALL dbcsr_add(propagator_matrix(i)%matrix, exp_h_old(i)%matrix, 1.0_dp, prefac)
415 END IF
416 END DO
417
418 CALL timestop(handle)
419
420 END SUBROUTINE compute_propagator_matrix
421
422! **************************************************************************************************
423!> \brief computes S_inv*H, if needed Sinv*B and S_inv*H_imag and store these quantities to the
424!> \brief exp_H for the real and imag part (for RTP and EMD)
425!> \param rtp ...
426!> \param matrix_ks ...
427!> \param matrix_ks_im ...
428!> \param rtp_control ...
429!> \author Florian Schiffmann (02.09)
430! **************************************************************************************************
431
432 SUBROUTINE calc_sinvh(rtp, matrix_ks, matrix_ks_im, rtp_control)
433 TYPE(rt_prop_type), POINTER :: rtp
434 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks, matrix_ks_im
435 TYPE(rtp_control_type), POINTER :: rtp_control
436
437 CHARACTER(len=*), PARAMETER :: routinen = 'calc_SinvH'
438 REAL(kind=dp), PARAMETER :: one = 1.0_dp, zero = 0.0_dp
439
440 INTEGER :: handle, im, ispin, re
441 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: exp_h, sinvb, sinvh, sinvh_imag
442 TYPE(dbcsr_type) :: matrix_ks_nosym
443 TYPE(dbcsr_type), POINTER :: b_mat, s_inv
444
445 CALL timeset(routinen, handle)
446 CALL get_rtp(rtp=rtp, s_inv=s_inv, exp_h_new=exp_h)
447 DO ispin = 1, SIZE(matrix_ks)
448 re = ispin*2 - 1
449 im = ispin*2
450 CALL dbcsr_set(exp_h(re)%matrix, zero)
451 CALL dbcsr_set(exp_h(im)%matrix, zero)
452 END DO
453 CALL dbcsr_create(matrix_ks_nosym, template=matrix_ks(1)%matrix, matrix_type="N")
454
455 ! Real part of S_inv x H -> imag part of exp_H
456 DO ispin = 1, SIZE(matrix_ks)
457 re = ispin*2 - 1
458 im = ispin*2
459 CALL dbcsr_desymmetrize(matrix_ks(ispin)%matrix, matrix_ks_nosym)
460 CALL dbcsr_multiply("N", "N", one, s_inv, matrix_ks_nosym, zero, exp_h(im)%matrix, &
461 filter_eps=rtp%filter_eps)
462 IF (.NOT. rtp_control%fixed_ions) THEN
463 CALL get_rtp(rtp=rtp, sinvh=sinvh)
464 CALL dbcsr_copy(sinvh(ispin)%matrix, exp_h(im)%matrix)
465 END IF
466 END DO
467
468 ! Imag part of S_inv x H -> real part of exp_H
469 IF (rtp%propagate_complex_ks) THEN
470 DO ispin = 1, SIZE(matrix_ks)
471 re = ispin*2 - 1
472 im = ispin*2
473 CALL dbcsr_set(matrix_ks_nosym, 0.0_dp)
474 CALL dbcsr_desymmetrize(matrix_ks_im(ispin)%matrix, matrix_ks_nosym)
475 ! - SinvH_imag is added to exp_H(re)%matrix
476 CALL dbcsr_multiply("N", "N", -one, s_inv, matrix_ks_nosym, zero, exp_h(re)%matrix, &
477 filter_eps=rtp%filter_eps)
478 IF (.NOT. rtp_control%fixed_ions) THEN
479 CALL get_rtp(rtp=rtp, sinvh_imag=sinvh_imag)
480 ! -SinvH_imag is saved
481 CALL dbcsr_copy(sinvh_imag(ispin)%matrix, exp_h(re)%matrix)
482 END IF
483 END DO
484 END IF
485 ! EMD case: the real part of exp_H should be updated with B
486 IF (.NOT. rtp_control%fixed_ions) THEN
487 CALL get_rtp(rtp=rtp, b_mat=b_mat, sinvb=sinvb)
488 CALL dbcsr_set(matrix_ks_nosym, 0.0_dp)
489 CALL dbcsr_multiply("N", "N", one, s_inv, b_mat, zero, matrix_ks_nosym, filter_eps=rtp%filter_eps)
490 DO ispin = 1, SIZE(matrix_ks)
491 re = ispin*2 - 1
492 im = ispin*2
493 ! + SinvB is added to exp_H(re)%matrix
494 CALL dbcsr_add(exp_h(re)%matrix, matrix_ks_nosym, 1.0_dp, 1.0_dp)
495 ! + SinvB is saved
496 CALL dbcsr_copy(sinvb(ispin)%matrix, matrix_ks_nosym)
497 END DO
498 END IF
499 ! Otherwise no real part for exp_H
500
501 CALL dbcsr_release(matrix_ks_nosym)
502 CALL timestop(handle)
503
504 END SUBROUTINE calc_sinvh
505
506! **************************************************************************************************
507!> \brief calculates the needed overlap-like matrices
508!> depending on the way the exponential is calculated, only S^-1 is needed
509!> \param s_mat ...
510!> \param rtp ...
511!> \author Florian Schiffmann (02.09)
512! **************************************************************************************************
513
514 SUBROUTINE s_matrices_create(s_mat, rtp)
515
516 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: s_mat
517 TYPE(rt_prop_type), POINTER :: rtp
518
519 CHARACTER(len=*), PARAMETER :: routinen = 's_matrices_create'
520 REAL(kind=dp), PARAMETER :: one = 1.0_dp, zero = 0.0_dp
521
522 INTEGER :: handle
523 TYPE(dbcsr_type), POINTER :: s_half, s_inv, s_minus_half
524
525 CALL timeset(routinen, handle)
526
527 CALL get_rtp(rtp=rtp, s_inv=s_inv)
528
529 IF (rtp%linear_scaling) THEN
530 CALL get_rtp(rtp=rtp, s_half=s_half, s_minus_half=s_minus_half)
531 CALL matrix_sqrt_newton_schulz(s_half, s_minus_half, s_mat(1)%matrix, rtp%filter_eps, &
532 rtp%newton_schulz_order, rtp%lanzcos_threshold, rtp%lanzcos_max_iter)
533 CALL dbcsr_multiply("N", "N", one, s_minus_half, s_minus_half, zero, s_inv, &
534 filter_eps=rtp%filter_eps)
535 ELSE
536 CALL dbcsr_copy(s_inv, s_mat(1)%matrix)
537 CALL cp_dbcsr_cholesky_decompose(s_inv, para_env=rtp%ao_ao_fmstruct%para_env, &
538 blacs_env=rtp%ao_ao_fmstruct%context)
539 CALL cp_dbcsr_cholesky_invert(s_inv, para_env=rtp%ao_ao_fmstruct%para_env, &
540 blacs_env=rtp%ao_ao_fmstruct%context, uplo_to_full=.true.)
541 END IF
542
543 CALL timestop(handle)
544 END SUBROUTINE s_matrices_create
545
546! **************************************************************************************************
547!> \brief Calculates the frobenius norm of a complex matrix represented by two real matrices
548!> \param frob_norm ...
549!> \param mat_re ...
550!> \param mat_im ...
551!> \author Samuel Andermatt (04.14)
552! **************************************************************************************************
553
554 SUBROUTINE complex_frobenius_norm(frob_norm, mat_re, mat_im)
555
556 REAL(kind=dp), INTENT(out) :: frob_norm
557 TYPE(dbcsr_type), POINTER :: mat_re, mat_im
558
559 CHARACTER(len=*), PARAMETER :: routinen = 'complex_frobenius_norm'
560 REAL(kind=dp), PARAMETER :: one = 1.0_dp, zero = 0.0_dp
561
562 INTEGER :: col_atom, handle, row_atom
563 LOGICAL :: found
564 REAL(dp), DIMENSION(:, :), POINTER :: block_values, block_values2
565 TYPE(dbcsr_iterator_type) :: iter
566 TYPE(dbcsr_type), POINTER :: tmp
567
568 CALL timeset(routinen, handle)
569
570 NULLIFY (tmp)
571 ALLOCATE (tmp)
572 CALL dbcsr_create(tmp, template=mat_re)
573 !make sure the tmp has the same sparsity pattern as the real and the complex part combined
574 CALL dbcsr_add(tmp, mat_re, zero, one)
575 CALL dbcsr_add(tmp, mat_im, zero, one)
576 CALL dbcsr_set(tmp, zero)
577 !calculate the hadamard product
578 CALL dbcsr_iterator_start(iter, tmp)
579 DO WHILE (dbcsr_iterator_blocks_left(iter))
580 CALL dbcsr_iterator_next_block(iter, row_atom, col_atom, block_values)
581 CALL dbcsr_get_block_p(mat_re, row_atom, col_atom, block_values2, found=found)
582 IF (found) THEN
583 block_values = block_values2*block_values2
584 END IF
585 CALL dbcsr_get_block_p(mat_im, row_atom, col_atom, block_values2, found=found)
586 IF (found) THEN
587 block_values = block_values + block_values2*block_values2
588 END IF
589 block_values = sqrt(block_values)
590 END DO
591 CALL dbcsr_iterator_stop(iter)
592 frob_norm = dbcsr_frobenius_norm(tmp)
593
595
596 CALL timestop(handle)
597
598 END SUBROUTINE complex_frobenius_norm
599
600! **************************************************************************************************
601!> \brief Does McWeeny for complex matrices in the non-orthogonal basis
602!> \param P ...
603!> \param s_mat ...
604!> \param eps ...
605!> \param eps_small ...
606!> \param max_iter ...
607!> \param threshold ...
608!> \author Samuel Andermatt (04.14)
609! **************************************************************************************************
610
611 SUBROUTINE purify_mcweeny_complex_nonorth(P, s_mat, eps, eps_small, max_iter, threshold)
612
613 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: p, s_mat
614 REAL(kind=dp), INTENT(in) :: eps, eps_small
615 INTEGER, INTENT(in) :: max_iter
616 REAL(kind=dp), INTENT(in) :: threshold
617
618 CHARACTER(len=*), PARAMETER :: routinen = 'purify_mcweeny_complex_nonorth'
619 REAL(kind=dp), PARAMETER :: one = 1.0_dp, zero = 0.0_dp
620
621 INTEGER :: handle, i, im, imax, ispin, re, unit_nr
622 REAL(kind=dp) :: frob_norm
623 TYPE(cp_logger_type), POINTER :: logger
624 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: ps, psp, tmp
625
626 CALL timeset(routinen, handle)
627
628 logger => cp_get_default_logger()
629 IF (logger%para_env%is_source()) THEN
630 unit_nr = cp_logger_get_default_unit_nr(logger, local=.true.)
631 ELSE
632 unit_nr = -1
633 END IF
634
635 NULLIFY (tmp, ps, psp)
636 CALL dbcsr_allocate_matrix_set(tmp, SIZE(p))
637 CALL dbcsr_allocate_matrix_set(psp, SIZE(p))
638 CALL dbcsr_allocate_matrix_set(ps, SIZE(p))
639 DO i = 1, SIZE(p)
640 CALL dbcsr_init_p(ps(i)%matrix)
641 CALL dbcsr_create(ps(i)%matrix, template=p(1)%matrix)
642 CALL dbcsr_init_p(psp(i)%matrix)
643 CALL dbcsr_create(psp(i)%matrix, template=p(1)%matrix)
644 CALL dbcsr_init_p(tmp(i)%matrix)
645 CALL dbcsr_create(tmp(i)%matrix, template=p(1)%matrix)
646 END DO
647 IF (SIZE(p) == 2) THEN
648 CALL dbcsr_scale(p(1)%matrix, one/2)
649 CALL dbcsr_scale(p(2)%matrix, one/2)
650 END IF
651 DO ispin = 1, SIZE(p)/2
652 re = 2*ispin - 1
653 im = 2*ispin
654 imax = max(max_iter, 1) !if max_iter is 0 then only the deviation from idempotency needs to be calculated
655 DO i = 1, imax
656 CALL dbcsr_multiply("N", "N", one, p(re)%matrix, s_mat(1)%matrix, &
657 zero, ps(re)%matrix, filter_eps=eps_small)
658 CALL dbcsr_multiply("N", "N", one, p(im)%matrix, s_mat(1)%matrix, &
659 zero, ps(im)%matrix, filter_eps=eps_small)
660 CALL cp_complex_dbcsr_gemm_3("N", "N", one, ps(re)%matrix, ps(im)%matrix, &
661 p(re)%matrix, p(im)%matrix, zero, psp(re)%matrix, psp(im)%matrix, &
662 filter_eps=eps_small)
663 CALL dbcsr_copy(tmp(re)%matrix, psp(re)%matrix)
664 CALL dbcsr_copy(tmp(im)%matrix, psp(im)%matrix)
665 CALL dbcsr_add(tmp(re)%matrix, p(re)%matrix, 1.0_dp, -1.0_dp)
666 CALL dbcsr_add(tmp(im)%matrix, p(im)%matrix, 1.0_dp, -1.0_dp)
667 CALL complex_frobenius_norm(frob_norm, tmp(re)%matrix, tmp(im)%matrix)
668 IF (unit_nr > 0) WRITE (unit_nr, '(t3,a,2f16.8)') "Deviation from idempotency: ", frob_norm
669 IF (frob_norm > threshold .AND. max_iter > 0) THEN
670 CALL dbcsr_copy(p(re)%matrix, psp(re)%matrix)
671 CALL dbcsr_copy(p(im)%matrix, psp(im)%matrix)
672 CALL cp_complex_dbcsr_gemm_3("N", "N", -2.0_dp, ps(re)%matrix, ps(im)%matrix, &
673 psp(re)%matrix, psp(im)%matrix, 3.0_dp, p(re)%matrix, p(im)%matrix, &
674 filter_eps=eps_small)
675 CALL dbcsr_filter(p(re)%matrix, eps)
676 CALL dbcsr_filter(p(im)%matrix, eps)
677 !make sure P is exactly hermitian
678 CALL dbcsr_transposed(tmp(re)%matrix, p(re)%matrix)
679 CALL dbcsr_add(p(re)%matrix, tmp(re)%matrix, one/2, one/2)
680 CALL dbcsr_transposed(tmp(im)%matrix, p(im)%matrix)
681 CALL dbcsr_add(p(im)%matrix, tmp(im)%matrix, one/2, -one/2)
682 ELSE
683 EXIT
684 END IF
685 END DO
686 !make sure P is hermitian
687 CALL dbcsr_transposed(tmp(re)%matrix, p(re)%matrix)
688 CALL dbcsr_add(p(re)%matrix, tmp(re)%matrix, one/2, one/2)
689 CALL dbcsr_transposed(tmp(im)%matrix, p(im)%matrix)
690 CALL dbcsr_add(p(im)%matrix, tmp(im)%matrix, one/2, -one/2)
691 END DO
692 IF (SIZE(p) == 2) THEN
693 CALL dbcsr_scale(p(1)%matrix, one*2)
694 CALL dbcsr_scale(p(2)%matrix, one*2)
695 END IF
699
700 CALL timestop(handle)
701
702 END SUBROUTINE purify_mcweeny_complex_nonorth
703
704! **************************************************************************************************
705!> \brief ...
706!> \param rtp ...
707!> \param matrix_s ...
708!> \param aspc_order ...
709! **************************************************************************************************
710 SUBROUTINE aspc_extrapolate(rtp, matrix_s, aspc_order)
711 TYPE(rt_prop_type), POINTER :: rtp
712 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
713 INTEGER, INTENT(in) :: aspc_order
714
715 CHARACTER(len=*), PARAMETER :: routinen = 'aspc_extrapolate'
716 COMPLEX(KIND=dp), PARAMETER :: cone = (1.0_dp, 0.0_dp), &
717 czero = (0.0_dp, 0.0_dp)
718 REAL(kind=dp), PARAMETER :: one = 1.0_dp, zero = 0.0_dp
719
720 INTEGER :: handle, i, iaspc, icol_local, ihist, &
721 imat, k, kdbl, n, naspc, ncol_local, &
722 nmat
723 REAL(kind=dp) :: alpha
724 TYPE(cp_cfm_type) :: cfm_tmp, cfm_tmp1, csc
725 TYPE(cp_fm_struct_type), POINTER :: matrix_struct, matrix_struct_new
726 TYPE(cp_fm_type) :: fm_tmp, fm_tmp1, fm_tmp2
727 TYPE(cp_fm_type), DIMENSION(:), POINTER :: mos_new
728 TYPE(cp_fm_type), DIMENSION(:, :), POINTER :: mo_hist
729 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: rho_new, s_hist
730 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: rho_hist
731
732 NULLIFY (rho_hist)
733 CALL timeset(routinen, handle)
734 CALL cite_reference(kolafa2004)
735 CALL cite_reference(kuhne2007)
736
737 IF (rtp%linear_scaling) THEN
738 CALL get_rtp(rtp=rtp, rho_new=rho_new)
739 ELSE
740 CALL get_rtp(rtp=rtp, mos_new=mos_new)
741 END IF
742
743 naspc = min(rtp%istep, aspc_order)
744 IF (rtp%linear_scaling) THEN
745 nmat = SIZE(rho_new)
746 rho_hist => rtp%history%rho_history
747 DO imat = 1, nmat
748 DO iaspc = 1, naspc
749 alpha = (-1.0_dp)**(iaspc + 1)*real(iaspc, kind=dp)* &
750 binomial(2*naspc, naspc - iaspc)/binomial(2*naspc - 2, naspc - 1)
751 ihist = mod(rtp%istep - iaspc, aspc_order) + 1
752 IF (iaspc == 1) THEN
753 CALL dbcsr_add(rho_new(imat)%matrix, rho_hist(imat, ihist)%matrix, zero, alpha)
754 ELSE
755 CALL dbcsr_add(rho_new(imat)%matrix, rho_hist(imat, ihist)%matrix, one, alpha)
756 END IF
757 END DO
758 END DO
759 ELSE
760 mo_hist => rtp%history%mo_history
761 nmat = SIZE(mos_new)
762 DO imat = 1, nmat
763 DO iaspc = 1, naspc
764 alpha = (-1.0_dp)**(iaspc + 1)*real(iaspc, kind=dp)* &
765 binomial(2*naspc, naspc - iaspc)/binomial(2*naspc - 2, naspc - 1)
766 ihist = mod(rtp%istep - iaspc, aspc_order) + 1
767 IF (iaspc == 1) THEN
768 CALL cp_fm_scale_and_add(zero, mos_new(imat), alpha, mo_hist(imat, ihist))
769 ELSE
770 CALL cp_fm_scale_and_add(one, mos_new(imat), alpha, mo_hist(imat, ihist))
771 END IF
772 END DO
773 END DO
774
775 mo_hist => rtp%history%mo_history
776 s_hist => rtp%history%s_history
777 DO i = 1, SIZE(mos_new)/2
778 NULLIFY (matrix_struct, matrix_struct_new)
779
780 CALL cp_fm_struct_double(matrix_struct, &
781 mos_new(2*i)%matrix_struct, &
782 mos_new(2*i)%matrix_struct%context, &
783 .true., .false.)
784
785 CALL cp_fm_create(fm_tmp, matrix_struct)
786 CALL cp_fm_create(fm_tmp1, matrix_struct)
787 CALL cp_fm_create(fm_tmp2, mos_new(2*i)%matrix_struct)
788 CALL cp_cfm_create(cfm_tmp, mos_new(2*i)%matrix_struct)
789 CALL cp_cfm_create(cfm_tmp1, mos_new(2*i)%matrix_struct)
790
791 CALL cp_fm_get_info(fm_tmp, ncol_global=kdbl)
792
793 CALL cp_fm_get_info(mos_new(2*i), &
794 nrow_global=n, &
795 ncol_global=k, &
796 ncol_local=ncol_local)
797
798 CALL cp_fm_struct_create(matrix_struct_new, &
799 template_fmstruct=mos_new(2*i)%matrix_struct, &
800 nrow_global=k, &
801 ncol_global=k)
802 CALL cp_cfm_create(csc, matrix_struct_new)
803
804 CALL cp_fm_struct_release(matrix_struct_new)
805 CALL cp_fm_struct_release(matrix_struct)
806
807 ! first the most recent
808
809! reorthogonalize vectors
810 DO icol_local = 1, ncol_local
811 fm_tmp%local_data(:, icol_local) = mos_new(2*i - 1)%local_data(:, icol_local)
812 fm_tmp%local_data(:, icol_local + ncol_local) = mos_new(2*i)%local_data(:, icol_local)
813 END DO
814
815 CALL cp_dbcsr_sm_fm_multiply(matrix_s(1)%matrix, fm_tmp, fm_tmp1, kdbl)
816
817 DO icol_local = 1, ncol_local
818 cfm_tmp%local_data(:, icol_local) = cmplx(fm_tmp1%local_data(:, icol_local), &
819 fm_tmp1%local_data(:, icol_local + ncol_local), dp)
820 cfm_tmp1%local_data(:, icol_local) = cmplx(mos_new(2*i - 1)%local_data(:, icol_local), &
821 mos_new(2*i)%local_data(:, icol_local), dp)
822 END DO
823 CALL parallel_gemm('C', 'N', k, k, n, cone, cfm_tmp1, cfm_tmp, czero, csc)
825 CALL cp_cfm_triangular_multiply(csc, cfm_tmp1, n_cols=k, side='R', invert_tr=.true.)
826 DO icol_local = 1, ncol_local
827 mos_new(2*i - 1)%local_data(:, icol_local) = real(cfm_tmp1%local_data(:, icol_local), dp)
828 mos_new(2*i)%local_data(:, icol_local) = aimag(cfm_tmp1%local_data(:, icol_local))
829 END DO
830
831! deallocate work matrices
832 CALL cp_cfm_release(csc)
833 CALL cp_fm_release(fm_tmp)
834 CALL cp_fm_release(fm_tmp1)
835 CALL cp_fm_release(fm_tmp2)
836 CALL cp_cfm_release(cfm_tmp)
837 CALL cp_cfm_release(cfm_tmp1)
838 END DO
839
840 END IF
841
842 CALL timestop(handle)
843
844 END SUBROUTINE aspc_extrapolate
845
846! **************************************************************************************************
847!> \brief ...
848!> \param rtp ...
849!> \param mos ...
850!> \param rho ...
851!> \param s_mat ...
852!> \param ihist ...
853! **************************************************************************************************
854 SUBROUTINE put_data_to_history(rtp, mos, rho, s_mat, ihist)
855 TYPE(rt_prop_type), POINTER :: rtp
856 TYPE(cp_fm_type), DIMENSION(:), POINTER :: mos
857 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: rho
858 TYPE(dbcsr_p_type), DIMENSION(:), OPTIONAL, &
859 POINTER :: s_mat
860 INTEGER :: ihist
861
862 INTEGER :: i
863
864 IF (rtp%linear_scaling) THEN
865 DO i = 1, SIZE(rho)
866 CALL dbcsr_copy(rtp%history%rho_history(i, ihist)%matrix, rho(i)%matrix)
867 END DO
868 ELSE
869 DO i = 1, SIZE(mos)
870 CALL cp_fm_to_fm(mos(i), rtp%history%mo_history(i, ihist))
871 END DO
872 IF (PRESENT(s_mat)) THEN
873 IF (ASSOCIATED(rtp%history%s_history(ihist)%matrix)) THEN ! the sparsity might be different
874 ! (future struct:check)
875 CALL dbcsr_deallocate_matrix(rtp%history%s_history(ihist)%matrix)
876 END IF
877 ALLOCATE (rtp%history%s_history(ihist)%matrix)
878 CALL dbcsr_copy(rtp%history%s_history(ihist)%matrix, s_mat(1)%matrix)
879 END IF
880 END IF
881
882 END SUBROUTINE put_data_to_history
883
884! **************************************************************************************************
885!> \brief Computes Maximally localised Wannier functions and print properties according to
886!> FORCE_EVAL%DFT%LOCALIZE, adapted from qs_scf_post_gpw::scf_post_calculation_gpw
887!> \param qs_env QuickStep environment
888!> \param rtp Real time propagation environment
889!> \par History 03/2020 created [LS]
890!> \author Lukas Schreder
891! **************************************************************************************************
892 SUBROUTINE rtp_localize(qs_env, rtp)
893
894 TYPE(qs_environment_type), INTENT(IN), POINTER :: qs_env
895 TYPE(rt_prop_type), INTENT(IN), POINTER :: rtp
896
897 CHARACTER(len=*), PARAMETER :: routinen = 'rtp_localize'
898
899 INTEGER :: handle, ispin, output_unit
900 INTEGER, DIMENSION(:, :, :), POINTER :: marked_states
901 LOGICAL :: do_homo, do_mo_cubes, do_wannier_cubes, &
902 p_loc
903 REAL(kind=dp), DIMENSION(:), POINTER :: mo_eigenvalues
904 TYPE(cp_1d_r_p_type), DIMENSION(:), POINTER :: occupied_evals
905 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: mo_localized, occupied_orbs
906 TYPE(cp_fm_type), DIMENSION(:), POINTER :: mo_coeff
907 TYPE(cp_logger_type), POINTER :: logger
908 TYPE(dft_control_type), POINTER :: dft_control
909 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
910 TYPE(particle_list_type), POINTER :: particles
911 TYPE(pw_c1d_gs_type) :: wf_g
912 TYPE(pw_env_type), POINTER :: pw_env
913 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
914 TYPE(pw_r3d_rs_type) :: wf_r
915 TYPE(qs_loc_env_type), POINTER :: qs_loc_env
916 TYPE(section_vals_type), POINTER :: dft_section, input, loc_print_section, &
917 loc_section, print_key
918
919 CALL timeset(routinen, handle)
920
921 ! Localization of propagated orbitals requires MO coefficients
922 IF (rtp%linear_scaling) THEN
923 CALL timestop(handle)
924 RETURN
925 END IF
926
927 CALL cite_reference(schreder2021)
928
929 NULLIFY (auxbas_pw_pool, dft_control, dft_section, input, loc_print_section, &
930 loc_section, logger, marked_states, mo_coeff, mo_eigenvalues, mos, &
931 occupied_evals, particles, print_key, pw_env, qs_loc_env)
932
933 logger => cp_get_default_logger()
934 output_unit = cp_logger_get_default_io_unit(logger)
935
936 IF (output_unit > 0) THEN
937 WRITE (unit=output_unit, fmt="(A)") "LOCALIZE| Localizing propagated orbitals"
938 END IF
939
940 ! get section properties
941 CALL get_qs_env(qs_env, dft_control=dft_control, input=input, pw_env=pw_env)
942 ! get propagated MO coeffs
943 CALL get_rtp(rtp, mos_new=mo_coeff)
944 dft_section => section_vals_get_subs_vals(input, "DFT")
945 loc_section => section_vals_get_subs_vals(dft_section, "LOCALIZE")
946 loc_print_section => section_vals_get_subs_vals(loc_section, "PRINT")
947
948 ! what properties to print out
949 print_key => section_vals_get_subs_vals(loc_print_section, "MOLECULAR_DIPOLES")
950 p_loc = btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
951
952 print_key => section_vals_get_subs_vals(loc_print_section, "TOTAL_DIPOLE")
953 p_loc = p_loc &
954 .OR. btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
955 print_key => section_vals_get_subs_vals(loc_print_section, "WANNIER_CENTERS")
956 p_loc = p_loc &
957 .OR. btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
958 print_key => section_vals_get_subs_vals(loc_print_section, "WANNIER_SPREADS")
959 p_loc = p_loc &
960 .OR. btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
961 print_key => section_vals_get_subs_vals(loc_print_section, "WANNIER_CUBES")
962 p_loc = p_loc &
963 .OR. btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
964 print_key => section_vals_get_subs_vals(loc_print_section, "MOLECULAR_STATES")
965 p_loc = p_loc &
966 .OR. btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
967 print_key => section_vals_get_subs_vals(loc_print_section, "MOLECULAR_MOMENTS")
968 p_loc = p_loc &
969 .OR. btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
970 print_key => section_vals_get_subs_vals(loc_print_section, "LOCALIZED_MOMENTS")
971 p_loc = p_loc &
972 .OR. btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
973 print_key => section_vals_get_subs_vals(loc_print_section, "WANNIER_STATES")
974 p_loc = p_loc &
975 .OR. btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
976
977 do_wannier_cubes = btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
978 "WANNIER_CUBES"), cp_p_file)
979
980 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
981 CALL auxbas_pw_pool%create_pw(wf_r)
982 CALL auxbas_pw_pool%create_pw(wf_g)
983
984 IF (p_loc) THEN
985 ALLOCATE (occupied_evals(dft_control%nspins))
986 ALLOCATE (occupied_orbs(SIZE(mo_coeff)))
987 ALLOCATE (mo_localized(SIZE(mo_coeff)))
988 CALL get_qs_env(qs_env, mos=mos)
989 CALL get_rtp(rtp, mos_new=mo_coeff)
990 DO ispin = 1, SIZE(mo_coeff)
991 occupied_orbs(ispin) = mo_coeff(ispin)
992 CALL cp_fm_create(mo_localized(ispin), mo_coeff(ispin)%matrix_struct)
993 CALL cp_fm_to_fm(mo_coeff(ispin), mo_localized(ispin))
994 END DO
995
996 DO ispin = 1, dft_control%nspins
997 CALL get_mo_set(mos(ispin), eigenvalues=mo_eigenvalues)
998 occupied_evals(ispin)%array => mo_eigenvalues
999 END DO
1000
1001 do_homo = .true.
1002 ALLOCATE (qs_loc_env)
1003 CALL qs_loc_env_create(qs_loc_env)
1004 CALL qs_loc_control_init(qs_loc_env, loc_section, do_homo=do_homo)
1005 CALL qs_loc_init(qs_env, qs_loc_env, loc_section, mo_localized, do_homo, do_mo_cubes)
1006 CALL get_localization_info(qs_env, qs_loc_env, loc_section, mo_localized, wf_r, wf_g, &
1007 particles, occupied_orbs, occupied_evals, marked_states)
1008 CALL loc_dipole(input, dft_control, qs_loc_env, logger, qs_env)
1009
1010 DO ispin = 1, SIZE(mo_localized)
1011 CALL cp_fm_release(mo_localized(ispin))
1012 END DO
1013 DEALLOCATE (mo_localized)
1014 DEALLOCATE (occupied_orbs)
1015 DEALLOCATE (occupied_evals)
1016 CALL qs_loc_env_release(qs_loc_env)
1017 DEALLOCATE (qs_loc_env)
1018 IF (ASSOCIATED(marked_states)) THEN
1019 DEALLOCATE (marked_states)
1020 END IF
1021 END IF
1022
1023 CALL auxbas_pw_pool%give_back_pw(wf_r)
1024 CALL auxbas_pw_pool%give_back_pw(wf_g)
1025
1026 CALL timestop(handle)
1027
1028 END SUBROUTINE rtp_localize
1029
1030END MODULE rt_propagation_methods
static int imax(int x, int y)
Returns the larger of two given integers (missing from the C standard)
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public kuhne2007
integer, save, public schreder2021
integer, save, public kolafa2004
Handles all functions related to the CELL.
Definition cell_types.F:15
various utilities that regard array of different kinds: output, allocation,... maybe it is not a good...
Basic linear algebra operations for complex full matrices.
subroutine, public cp_cfm_triangular_multiply(triangular_matrix, matrix_b, side, transa_tr, invert_tr, uplo_tr, unit_diag_tr, n_rows, n_cols, alpha)
Multiplies in place by a triangular matrix: matrix_b = alpha op(triangular_matrix) matrix_b or (if si...
various cholesky decomposition related routines
subroutine, public cp_cfm_cholesky_decompose(matrix, n, info_out)
Used to replace a symmetric positive definite matrix M with its Cholesky decomposition U: M = U^T * U...
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_release(matrix)
Releases a full matrix.
subroutine, public cp_cfm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
Creates a new full matrix with the given structure.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_transposed(transposed, normal, shallow_data_copy, transpose_distribution, use_distribution)
...
subroutine, public dbcsr_scale(matrix, alpha_scalar)
...
subroutine, public dbcsr_deallocate_matrix(matrix)
...
logical function, public dbcsr_iterator_blocks_left(iterator)
...
subroutine, public dbcsr_iterator_stop(iterator)
...
subroutine, public dbcsr_desymmetrize(matrix_a, matrix_b)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_get_block_p(matrix, row, col, block, found, row_size, col_size)
...
subroutine, public dbcsr_multiply(transa, transb, alpha, matrix_a, matrix_b, beta, matrix_c, first_row, last_row, first_column, last_column, first_k, last_k, retain_sparsity, filter_eps, flop)
...
subroutine, public dbcsr_init_p(matrix)
...
subroutine, public dbcsr_iterator_next_block(iterator, row, column, block, block_number_argument_has_been_removed, row_size, col_size, row_offset, col_offset, transposed)
...
subroutine, public dbcsr_filter(matrix, eps)
...
subroutine, public dbcsr_iterator_start(iterator, matrix, shared, dynamic, dynamic_byrows)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
Interface to (sca)lapack for the Cholesky based procedures.
subroutine, public cp_dbcsr_cholesky_decompose(matrix, n, para_env, blacs_env)
used to replace a symmetric positive def. matrix M with its cholesky decomposition U: M = U^T * U,...
subroutine, public cp_dbcsr_cholesky_invert(matrix, n, para_env, blacs_env, uplo_to_full)
used to replace the cholesky decomposition by the inverse
real(dp) function, public dbcsr_frobenius_norm(matrix)
Compute the frobenius norm of a dbcsr matrix.
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
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....
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_double(fmstruct, struct, context, col, row)
creates a struct with twice the number of blocks on each core. If matrix A has to be multiplied with ...
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
subroutine, public cp_fm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
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 ...
recursive integer function, public cp_logger_get_default_unit_nr(logger, local, skip_not_ionode)
asks the default unit number of the given logger. try to use cp_logger_get_unit_nr
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...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer, parameter, public cp_p_file
integer function, public cp_print_key_should_output(iteration_info, basis_section, print_key_path, used_print_key, first_time)
returns what should be done with the given property if btest(res,cp_p_store) then the property should...
all routins needed for a nonperiodic electric field
subroutine, public efield_potential_lengh_gauge(qs_env)
Replace the original implementation of the electric-electronic interaction in the length gauge....
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_bch
integer, parameter, public do_pade
integer, parameter, public do_taylor
integer, parameter, public do_em
integer, parameter, public do_arnoldi
objects that represent the structure of input sections and the data contained in an input section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
Routines useful for iterative matrix calculations.
subroutine, public matrix_sqrt_newton_schulz(matrix_sqrt, matrix_sqrt_inv, matrix, threshold, order, eps_lanczos, max_iter_lanczos, symmetrize, converged, iounit)
compute the sqrt of a matrix via the sign function and the corresponding Newton-Schulz iterations the...
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Routines for calculating a complex matrix exponential with dbcsr matrices. Based on the code in matri...
subroutine, public cp_complex_dbcsr_gemm_3(transa, transb, alpha, a_re, a_im, b_re, b_im, beta, c_re, c_im, filter_eps)
Convenience function. Computes the matrix multiplications needed for the multiplication of complex sp...
Collection of simple mathematical functions and subroutines.
Definition mathlib.F:15
elemental real(kind=dp) function, public binomial(n, k)
The binomial coefficient n over k for 0 <= k <= n is calculated, otherwise zero is returned.
Definition mathlib.F:214
basic linear algebra operations for full matrixes
represent a simple array based list of the given type
container for various plainwaves related things
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Utility subroutine for qs energy calculation.
subroutine, public qs_energies_init(qs_env, calc_forces)
Refactoring of qs_energies_scf. Driver routine for the initial setup and calculations for a qs energy...
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, mimic, 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_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, 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, matrix_vhxc, 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, xcint_weights, 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, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_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, harris_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, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
routines that build the Kohn-Sham matrix (i.e calculate the coulomb and xc parts
subroutine, public qs_ks_update_qs_env(qs_env, calculate_forces, just_energy, print_active)
updates the Kohn Sham matrix of the given qs_env (facility method)
subroutine, public set_ks_env(ks_env, v_hartree_rspace, s_mstruct_changed, rho_changed, exc_accint, potential_changed, forces_up_to_date, complex_ks, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, kinetic, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_ks_im_kp, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, vee, neighbor_list_id, kpoints, sab_orb, sab_all, sac_ae, sac_ppl, sac_lri, sap_ppnl, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_vdw, sab_scp, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, task_list, task_list_soft, subsys, dft_control, dbcsr_dist, distribution_2d, pw_env, para_env, blacs_env)
...
subroutine, public loc_dipole(input, dft_control, qs_loc_env, logger, qs_env)
Computes and prints the Dipole (using localized charges)
subroutine, public get_localization_info(qs_env, qs_loc_env, loc_section, mo_local, wf_r, wf_g, particles, coeff, evals, marked_states)
Performs localization of the orbitals.
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)
...
subroutine, public qs_loc_env_create(qs_loc_env)
...
Some utilities for the construction of the localization environment.
subroutine, public qs_loc_control_init(qs_loc_env, loc_section, do_homo, do_mixed, do_xas, nloc_xas, spin_xas)
initializes everything needed for localization of the HOMOs
subroutine, public qs_loc_init(qs_env, qs_loc_env, localize_section, mos_localized, do_homo, do_mo_cubes, mo_loc_history, evals, tot_zeff_corr, do_mixed)
initializes everything needed for localization of the molecular orbitals
Definition and initialisation of the mo data type.
Definition qs_mo_types.F:22
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.
Routines for calculating a complex matrix exponential.
subroutine, public propagate_exp(rtp, rtp_control)
performs propagations if explicit matrix exponentials are used ETRS: exp(i*H(t+dt)*dt/2)*exp(i*H(t)*d...
subroutine, public propagate_bch(rtp, rtp_control)
Propagation using the Baker-Campbell-Hausdorff expansion, currently only works for rtp.
subroutine, public propagate_exp_density(rtp, rtp_control)
Propagation of the density matrix instead of the atomic orbitals via a matrix exponential.
subroutine, public propagate_arnoldi(rtp, rtp_control)
computes U_prop*MOs using arnoldi subspace algorithm
Routines for propagating the orbitals.
subroutine, public rtp_localize(qs_env, rtp)
Computes Maximally localised Wannier functions and print properties according to FORCE_EVALDFTLOCALIZ...
subroutine, public calc_sinvh(rtp, matrix_ks, matrix_ks_im, rtp_control)
computes S_inv*H, if needed Sinv*B and S_inv*H_imag and store these quantities to the
subroutine, public propagation_step(qs_env, rtp, rtp_control)
performs a single propagation step a(t+Dt)=U(t+Dt,t)*a(0) and calculates the new exponential
subroutine, public put_data_to_history(rtp, mos, rho, s_mat, ihist)
...
subroutine, public s_matrices_create(s_mat, rtp)
calculates the needed overlap-like matrices depending on the way the exponential is calculated,...
Routine for the real time propagation output.
subroutine, public report_density_occupation(filter_eps, rho)
Reports the sparsity pattern of the complex density matrix.
subroutine, public rt_convergence(rtp, matrix_s, delta_mos, delta_eps)
computes the convergence criterion for RTP and EMD
subroutine, public rt_convergence_density(rtp, delta_p, delta_eps)
computes the convergence criterion for RTP and EMD based on the density matrix
Types and set_get for real time propagation depending on runtype and diagonalization method different...
subroutine, public get_rtp(rtp, exp_h_old, exp_h_new, h_last_iter, rho_old, rho_next, rho_new, mos, mos_new, mos_old, mos_next, s_inv, s_half, s_minus_half, b_mat, c_mat, propagator_matrix, mixing, mixing_factor, s_der, dt, nsteps, sinvh, sinvh_imag, sinvb, admm_mos)
...
Routines needed for EMD.
subroutine, public calc_update_rho_sparse(qs_env)
Copies the density matrix back into the qs_envrhorho_ao.
subroutine, public calc_s_derivs(qs_env)
Calculates dS/dR respectily the velocity weighted derivatves only needed for ehrenfest MD.
subroutine, public calc_update_rho(qs_env)
calculates the density from the complex MOs and passes the density to qs_env.
Routines to perform the RTP in the velocity gauge.
subroutine, public velocity_gauge_ks_matrix(qs_env, subtract_nl_term)
...
subroutine, public update_vector_potential(qs_env, dft_control)
Update the vector potential in the case where a time-dependant electric field is apply.
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
represent a pointer to a 1d array
Represent a complex full matrix.
keeps the information about the structure of a full matrix
represent a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
contained for different pw related things
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
contains all the info needed by quickstep to calculate the spread of a selected set of orbitals and i...