(git:d43dca4)
Loading...
Searching...
No Matches
xas_tp_scf.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 xas_scf for the tp method
10!> It is repeaated for every atom that have to be excited
11!> \par History
12!> created 05.2005
13!> \author MI (05.2005)
14! **************************************************************************************************
18 USE cell_types, ONLY: cell_type,&
19 pbc
23 USE cp_dbcsr_api, ONLY: dbcsr_copy,&
37 cp_p_file,&
47 USE kinds, ONLY: dp
48 USE machine, ONLY: m_flush,&
72 USE qs_ks_types, ONLY: qs_ks_did_change,&
74 USE qs_loc_main, ONLY: qs_loc_driver
75 USE qs_loc_types, ONLY: get_qs_loc_env,&
82 USE qs_mo_types, ONLY: get_mo_set,&
86 USE qs_rho_types, ONLY: qs_rho_get,&
88 USE qs_scf, ONLY: scf_env_cleanup,&
98 USE xas_env_types, ONLY: get_xas_env,&
103#include "./base/base_uses.f90"
104
105 IMPLICIT NONE
106 PRIVATE
107
108 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'xas_tp_scf'
109
110 ! *** Public subroutines ***
111
112 PUBLIC :: xas_do_tp_scf, xes_scf_once
113
114CONTAINS
115
116! **************************************************************************************************
117!> \brief perform an scf loop to calculate the xas spectrum
118!> given by the excitation of a inner state of a selected atom
119!> by using the transition potential method
120!> \param dft_control ...
121!> \param xas_env the environment for XAS calculations
122!> \param iatom ...
123!> \param istate keeps track of the state index for restart writing
124!> \param scf_env the scf_env where to perform the scf procedure
125!> \param qs_env the qs_env, the scf_env and xas_env live in
126!> \param xas_section ...
127!> \param scf_section ...
128!> \param converged ...
129!> \param should_stop ...
130!> \par History
131!> 05.2005 created [MI]
132!> \author MI
133! **************************************************************************************************
134 SUBROUTINE xas_do_tp_scf(dft_control, xas_env, iatom, istate, scf_env, qs_env, &
135 xas_section, scf_section, converged, should_stop)
136
137 TYPE(dft_control_type), POINTER :: dft_control
138 TYPE(xas_environment_type), POINTER :: xas_env
139 INTEGER, INTENT(IN) :: iatom, istate
140 TYPE(qs_scf_env_type), POINTER :: scf_env
141 TYPE(qs_environment_type), POINTER :: qs_env
142 TYPE(section_vals_type), POINTER :: xas_section, scf_section
143 LOGICAL, INTENT(OUT) :: converged, should_stop
144
145 CHARACTER(LEN=*), PARAMETER :: routinen = 'xas_do_tp_scf'
146
147 INTEGER :: handle, handle2, hole_spin, ispin, &
148 iter_count, my_spin, nspin, occ_spin, &
149 output_unit
150 LOGICAL :: diis_step, energy_only, exit_loop, gapw
151 REAL(kind=dp) :: t1, t2
152 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
153 TYPE(cp_logger_type), POINTER :: logger
154 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks, matrix_s
155 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: rho_ao_kp
156 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
157 TYPE(mp_para_env_type), POINTER :: para_env
158 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
159 TYPE(qs_charges_type), POINTER :: qs_charges
160 TYPE(qs_energy_type), POINTER :: energy
161 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
162 TYPE(qs_ks_env_type), POINTER :: ks_env
163 TYPE(qs_rho_type), POINTER :: rho
164 TYPE(scf_control_type), POINTER :: scf_control
165 TYPE(section_vals_type), POINTER :: dft_section
166 TYPE(xas_control_type), POINTER :: xas_control
167
168 CALL timeset(routinen, handle)
169 NULLIFY (xas_control, matrix_s, matrix_ks, para_env, rho_ao_kp)
170 NULLIFY (rho, energy, scf_control, logger, ks_env, mos, atomic_kind_set)
171 NULLIFY (qs_charges, particle_set, qs_kind_set)
172
173 logger => cp_get_default_logger()
174 t1 = m_walltime()
175 converged = .true.
176
177 cpassert(ASSOCIATED(xas_env))
178 cpassert(ASSOCIATED(scf_env))
179 cpassert(ASSOCIATED(qs_env))
180
181 CALL get_qs_env(qs_env=qs_env, &
182 atomic_kind_set=atomic_kind_set, &
183 matrix_s=matrix_s, energy=energy, &
184 qs_charges=qs_charges, &
185 ks_env=ks_env, para_env=para_env)
186
187 CALL get_xas_env(xas_env, scf_control=scf_control, spin_channel=my_spin)
188
189 energy_only = .false.
190 output_unit = cp_print_key_unit_nr(logger, xas_section, "PRINT%PROGRAM_RUN_INFO", &
191 extension=".xasLog")
192 IF (output_unit > 0) THEN
193 WRITE (unit=output_unit, fmt="(/,/,T2,A)") "XAS_TP_SCF WAVEFUNCTION OPTIMIZATION"
194 END IF
195
196 ! GAPW method must be used
197 gapw = dft_control%qs_control%gapw
198 cpassert(gapw)
199 xas_control => dft_control%xas_control
200
201 CALL cp_add_iter_level(logger%iter_info, "XAS_SCF")
202
203 CALL get_qs_env(qs_env, matrix_ks=matrix_ks, rho=rho, mos=mos)
204 CALL qs_rho_get(rho, rho_ao_kp=rho_ao_kp)
205
206 iter_count = 0
207 diis_step = .false.
208 nspin = dft_control%nspins
209
210 IF (output_unit > 0) THEN
211 WRITE (unit=output_unit, &
212 fmt="(/,T3,A,T12,A,T31,A,T40,A,T60,A,T75,A/,T3,A)") &
213 "Step", "Update method", "Time", "Convergence", "Total energy", "Change", &
214 repeat("-", 77)
215 END IF
216
217 ! *** SCF loop ***
218
219 energy%tot_old = 0.0_dp
220 scf_loop: DO
221 CALL timeset(routinen//"_inner_loop", handle2)
222
223 exit_loop = .false.
224 IF (output_unit > 0) CALL m_flush(output_unit)
225
226 iter_count = iter_count + 1
227 CALL cp_iterate(logger%iter_info, last=.false., iter_nr=iter_count)
228
229 ! ** here qs_env%rho%rho_r and qs_env%rho%rho_g should be up to date
230
231 CALL qs_ks_update_qs_env(qs_env, calculate_forces=.false., just_energy=energy_only)
232
233 SELECT CASE (scf_env%method)
234 CASE DEFAULT
235 CALL cp_abort(__location__, &
236 "unknown scf method method for core level spectroscopy"// &
237 cp_to_string(scf_env%method))
238
239 CASE (general_diag_method_nr) ! diagonalisation (default)
240
241 scf_env%iter_count = iter_count
242 CALL general_eigenproblem(scf_env, mos, matrix_ks, &
243 matrix_s, scf_control, scf_section, &
244 diis_step)
245
246 CALL find_excited_core_orbital(xas_env, mos, matrix_s)
247
248 ! set occupation for the respective spin channels
249 IF (my_spin == 1) THEN
250 hole_spin = 1 ! hole is generated in channel 1
251 occ_spin = 2
252 ELSE
253 hole_spin = 2
254 occ_spin = 1
255 END IF
256 CALL set_mo_occupation(mo_set=mos(hole_spin), &
257 smear=scf_control%smear, &
258 xas_env=xas_env)
259 CALL set_mo_occupation(mo_set=mos(occ_spin), &
260 smear=scf_control%smear)
261 DO ispin = 1, nspin
262 ! does not yet handle k-points
263 CALL calculate_density_matrix(mos(ispin), &
264 scf_env%p_mix_new(ispin, 1)%matrix)
265 END DO
266 energy%kTS = 0.0_dp
267 energy%efermi = 0.0_dp
268 DO ispin = 1, nspin
269 energy%kTS = energy%kTS + mos(ispin)%kTS
270 energy%efermi = energy%efermi + mos(ispin)%mu
271 END DO
272 energy%efermi = energy%efermi/real(nspin, kind=dp)
273
274 END SELECT
275
276 SELECT CASE (scf_env%mixing_method)
277 CASE (direct_mixing_nr)
278 CALL scf_env_density_mixing(scf_env%p_mix_new, &
279 scf_env%mixing_store, rho_ao_kp, para_env, scf_env%iter_delta, scf_env%iter_count, &
280 diis=diis_step)
283 ! Compute the difference p_out-p_in
284 CALL self_consistency_check(rho_ao_kp, scf_env%p_delta, para_env, scf_env%p_mix_new, &
285 delta=scf_env%iter_delta)
286 CASE (no_mixing_nr)
287 CASE DEFAULT
288 CALL cp_abort(__location__, &
289 "unknown scf mixing method: "// &
290 cp_to_string(scf_env%mixing_method))
291 END SELECT
292
293 t2 = m_walltime()
294
295 IF (output_unit > 0 .AND. scf_env%print_iter_line) THEN
296 WRITE (unit=output_unit, &
297 fmt="(T2,I5,1X,A,T20,E8.2,1X,F6.1,1X,F14.8,1X,F20.10,1X,ES9.2)") &
298 iter_count, trim(scf_env%iter_method), &
299 scf_env%iter_param, t2 - t1, scf_env%iter_delta, energy%total, &
300 energy%total - energy%tot_old
301 END IF
302 energy%tot_old = energy%total
303
304 ! ** convergence check
305 CALL external_control(should_stop, "XASSCF", target_time=qs_env%target_time, &
306 start_time=qs_env%start_time)
307 IF (scf_env%iter_delta < scf_control%eps_scf) THEN
308 IF (output_unit > 0) THEN
309 WRITE (unit=output_unit, fmt="(/,T3,A,I5,A/)") &
310 "*** SCF run converged in ", iter_count, " steps ***"
311 END IF
312 exit_loop = .true.
313 ELSE IF (should_stop .OR. iter_count == scf_control%max_scf) THEN
314 IF (output_unit > 0) THEN
315 WRITE (unit=output_unit, fmt="(/,T3,A,/)") &
316 "*** SCF run NOT converged ***"
317 END IF
318 converged = .false.
319 exit_loop = .true.
320 END IF
321 ! *** Exit if we have finished with the SCF inner loop ***
322 IF (exit_loop) THEN
323 ! now, print out energies and charges corresponding to the obtained wfn
324 ! (this actually is not 100% consistent at this point)!
325 CALL qs_scf_print_summary(output_unit, qs_env)
326 CALL cp_iterate(logger%iter_info, last=.true., iter_nr=iter_count)
327 END IF
328
329 ! ** Write restart file **
330 CALL xas_write_restart(xas_env, xas_section, qs_env, xas_control%xas_method, &
331 iatom, istate)
332
333 dft_section => section_vals_get_subs_vals(qs_env%input, "DFT")
334 CALL get_qs_env(qs_env=qs_env, mos=mos, particle_set=particle_set, qs_kind_set=qs_kind_set)
335 CALL write_mo_set_to_restart(mos, particle_set, dft_section=dft_section, qs_kind_set=qs_kind_set)
336
337 IF (exit_loop) THEN
338 CALL timestop(handle2)
339 EXIT scf_loop
340 END IF
341
342 IF (.NOT. btest(cp_print_key_should_output(logger%iter_info, &
343 xas_section, "PRINT%ITERATION_INFO/TIME_CUMUL"), cp_p_file)) t1 = m_walltime()
344
345 ! *** mixing methods have the new density matrix in p_mix_new
346 IF (scf_env%mixing_method > 0) THEN
347 DO ispin = 1, nspin
348 ! does not yet handle k-points
349 CALL dbcsr_copy(rho_ao_kp(ispin, 1)%matrix, scf_env%p_mix_new(ispin, 1)%matrix)
350 END DO
351 END IF
352
353 ! ** update qs_env%rho
354 CALL qs_rho_update_rho(rho, qs_env=qs_env)
355 IF (scf_env%mixing_method >= gspace_mixing_nr) THEN
356 CALL gspace_mixing(qs_env, scf_env%mixing_method, scf_env%mixing_store, rho, para_env, &
357 scf_env%iter_count)
358 END IF
359
360 CALL qs_ks_did_change(ks_env, rho_changed=.true.)
361 CALL timestop(handle2)
362
363 END DO scf_loop
364
365 IF (output_unit > 0) THEN
366 WRITE (unit=output_unit, fmt="(/,(T3,A,T55,F25.14))") &
367 "Ionization potential of the excited atom: ", xas_env%IP_energy
368 CALL m_flush(output_unit)
369 END IF
370
371 CALL para_env%sync()
372 CALL qs_ks_did_change(ks_env, rho_changed=.true.)
373
374 CALL cls_prepare_states(xas_control, xas_env, qs_env, iatom, xas_section, output_unit)
375
376 CALL para_env%sync()
377
378 CALL cp_print_key_finished_output(output_unit, logger, xas_section, &
379 "PRINT%PROGRAM_RUN_INFO")
380 CALL cp_rm_iter_level(logger%iter_info, "XAS_SCF")
381
382 CALL timestop(handle)
383
384 END SUBROUTINE xas_do_tp_scf
385! **************************************************************************************************
386!> \brief Post processing of the optimized wfn in XAS scheme, as preparation for
387!> the calculation of the spectrum
388!> \param xas_control ...
389!> \param xas_env the environment for XAS calculations
390!> \param qs_env the qs_env, the scf_env and xas_env live in
391!> \param iatom index of the excited atom
392!> \param xas_section ...
393!> \param output_unit ...
394!> \par History
395!> 05.2005 created [MI]
396!> \author MI
397! **************************************************************************************************
398 SUBROUTINE cls_prepare_states(xas_control, xas_env, qs_env, iatom, xas_section, output_unit)
399
401 TYPE(xas_environment_type), POINTER :: xas_env
402 TYPE(qs_environment_type), POINTER :: qs_env
403 INTEGER, INTENT(IN) :: iatom
404 TYPE(section_vals_type), POINTER :: xas_section
405 INTEGER, INTENT(IN) :: output_unit
406
407 CHARACTER(LEN=*), PARAMETER :: routinen = 'cls_prepare_states'
408
409 INTEGER :: handle, i, ikind, isgf, ispin, istate, j, my_kind, my_spin, my_state, nao, natom, &
410 nexc_search, nmo, nvirtual2, uno_iter, xas_estate
411 INTEGER, ALLOCATABLE, DIMENSION(:) :: first_sgf
412 INTEGER, DIMENSION(:), POINTER :: mykind_of_kind
413 REAL(dp), DIMENSION(:, :), POINTER :: centers_wfn
414 REAL(kind=dp) :: component, dist, max_overlap, ra(3), &
415 rac(3), rc(3), sto_state_overlap, &
416 uno_eps
417 REAL(kind=dp), DIMENSION(:), POINTER :: all_evals, eigenvalues, uno_evals
418 REAL(kind=dp), DIMENSION(:, :), POINTER :: vecbuffer, vecbuffer2
419 TYPE(atomic_kind_type), POINTER :: atomic_kind
420 TYPE(cell_type), POINTER :: cell
421 TYPE(cp_2d_r_p_type), DIMENSION(:), POINTER :: stogto_overlap
422 TYPE(cp_blacs_env_type), POINTER :: blacs_env
423 TYPE(cp_fm_type), POINTER :: all_vectors, excvec_coeff, &
424 excvec_overlap, mo_coeff, uno_orbs
425 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: kinetic, matrix_ks, matrix_s
426 TYPE(dft_control_type), POINTER :: dft_control
427 TYPE(localized_wfn_control_type), POINTER :: localized_wfn_control
428 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
429 TYPE(mp_para_env_type), POINTER :: para_env
430 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
431 TYPE(preconditioner_type), POINTER :: local_preconditioner
432 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
433 TYPE(qs_loc_env_type), POINTER :: qs_loc_env
434 TYPE(scf_control_type), POINTER :: scf_control
435 TYPE(section_vals_type), POINTER :: loc_section, print_loc_section
436
437 CALL timeset(routinen, handle)
438
439 NULLIFY (atomic_kind, dft_control, matrix_s, matrix_ks, qs_kind_set, kinetic)
440 NULLIFY (cell, particle_set, local_preconditioner, vecbuffer, vecbuffer2)
441 NULLIFY (dft_control, loc_section, mos, mo_coeff, eigenvalues)
442 NULLIFY (centers_wfn, mykind_of_kind, qs_loc_env, localized_wfn_control, stogto_overlap)
443 NULLIFY (all_evals, all_vectors, excvec_coeff, excvec_overlap, uno_evals, para_env, blacs_env)
444
445 cpassert(ASSOCIATED(xas_env))
446
447 CALL get_qs_env(qs_env, &
448 cell=cell, &
449 dft_control=dft_control, &
450 matrix_ks=matrix_ks, &
451 matrix_s=matrix_s, &
452 kinetic=kinetic, &
453 mos=mos, &
454 particle_set=particle_set, &
455 qs_kind_set=qs_kind_set, &
456 para_env=para_env, &
457 blacs_env=blacs_env)
458
459 ! Some elements from the xas_env
460 CALL get_xas_env(xas_env=xas_env, &
461 all_vectors=all_vectors, all_evals=all_evals, &
462 excvec_coeff=excvec_coeff, &
463 nvirtual2=nvirtual2, xas_estate=xas_estate, &
464 excvec_overlap=excvec_overlap, nexc_search=nexc_search, &
465 spin_channel=my_spin, scf_control=scf_control)
466 cpassert(ASSOCIATED(excvec_overlap))
467
468 CALL get_mo_set(mos(my_spin), mo_coeff=mo_coeff, nao=nao, &
469 eigenvalues=eigenvalues)
470
471 ALLOCATE (vecbuffer(1, nao))
472 vecbuffer = 0.0_dp
473 ALLOCATE (vecbuffer2(1, nao))
474 vecbuffer2 = 0.0_dp
475 natom = SIZE(particle_set, 1)
476 ALLOCATE (first_sgf(natom))
477 CALL get_particle_set(particle_set, qs_kind_set, first_sgf=first_sgf)
478 ALLOCATE (centers_wfn(3, nexc_search))
479 centers_wfn = 0.0_dp
480
481 ! Possible only for emission only
482 IF (scf_control%use_ot) THEN
483 IF (output_unit > 0) THEN
484 WRITE (unit=output_unit, fmt="(/,/,T2,A)") " Eigenstates are derived "// &
485 "from the MOs optimized by OT. Follows localization of the core states"// &
486 " to identify the excited orbital."
487 END IF
488
489 CALL get_xas_env(xas_env=xas_env, &
490 mykind_of_kind=mykind_of_kind, qs_loc_env=qs_loc_env, &
491 stogto_overlap=stogto_overlap)
492 CALL get_qs_loc_env(qs_loc_env=qs_loc_env, &
493 localized_wfn_control=localized_wfn_control)
494 loc_section => section_vals_get_subs_vals(xas_section, "LOCALIZE")
495 print_loc_section => section_vals_get_subs_vals(loc_section, "PRINT")
496 CALL qs_loc_driver(qs_env, qs_loc_env, print_loc_section, myspin=1)
497 ra(1:3) = particle_set(iatom)%r(1:3)
498
499 NULLIFY (atomic_kind)
500 atomic_kind => particle_set(iatom)%atomic_kind
501 CALL get_atomic_kind(atomic_kind=atomic_kind, &
502 kind_number=ikind)
503 my_kind = mykind_of_kind(ikind)
504
505 my_state = 0
506 CALL cp_fm_get_submatrix(mo_coeff, vecbuffer2, 1, my_state, &
507 nao, 1, transpose=.true.)
508
509 ! Rotate the wfn to get the eigenstate of the KS hamiltonian
510 ! Only ispin=1 should be needed
511 DO ispin = 1, dft_control%nspins
512 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, nmo=nmo, &
513 eigenvalues=eigenvalues)
514 CALL calculate_subspace_eigenvalues(mo_coeff, &
515 matrix_ks(ispin)%matrix, eigenvalues, &
516 do_rotation=.true.)
517 END DO ! ispin
518
519 !Search for the core state to be excited
520 max_overlap = 0.0_dp
521 DO istate = 1, nexc_search
522 centers_wfn(1, istate) = localized_wfn_control%centers_set(my_spin)%array(1, istate)
523 centers_wfn(2, istate) = localized_wfn_control%centers_set(my_spin)%array(2, istate)
524 centers_wfn(3, istate) = localized_wfn_control%centers_set(my_spin)%array(3, istate)
525
526 rc(1:3) = centers_wfn(1:3, istate)
527 rac = pbc(ra, rc, cell)
528 dist = rac(1)*rac(1) + rac(2)*rac(2) + rac(3)*rac(3)
529
530 IF (dist < 1.0_dp) THEN
531 CALL cp_fm_get_submatrix(mo_coeff, vecbuffer, 1, istate, &
532 nao, 1, transpose=.true.)
533 sto_state_overlap = 0.0_dp
534 DO i = 1, SIZE(stogto_overlap(my_kind)%array, 1)
535 component = 0.0_dp
536 DO j = 1, SIZE(stogto_overlap(my_kind)%array, 2)
537 isgf = first_sgf(iatom) + j - 1
538 component = component + stogto_overlap(my_kind)%array(i, j)*vecbuffer(1, isgf)
539 END DO ! j size
540 sto_state_overlap = sto_state_overlap + &
541 component*component
542 END DO ! i size
543
544 IF (sto_state_overlap > max_overlap) THEN
545 max_overlap = sto_state_overlap
546 my_state = istate
547 END IF
548 END IF
549 xas_estate = my_state
550 END DO ! istate
551
552 CALL get_mo_set(mos(my_spin), mo_coeff=mo_coeff)
553 CALL cp_fm_get_submatrix(mo_coeff, vecbuffer, 1, xas_estate, &
554 nao, 1, transpose=.true.)
555 CALL cp_fm_set_submatrix(excvec_coeff, vecbuffer2, 1, 1, &
556 nao, 1, transpose=.true.)
557 !
558 END IF
559
560 CALL para_env%sync()
561 !Calculate the virtual states from the KS matrix matrix_ks(1)
562 IF (nvirtual2 > 0) THEN
563 NULLIFY (mo_coeff)
564 CALL get_mo_set(mos(my_spin), mo_coeff=mo_coeff, nmo=nmo)
565 IF (output_unit > 0) THEN
566 WRITE (unit=output_unit, fmt="(/,/,T2,A,I5,A,I6,A)") " Calculation of ", nvirtual2, &
567 " additional virtual states of the subspace complementary to the"// &
568 " lowest ", nmo, " states"
569 END IF
570
571 NULLIFY (uno_orbs, uno_evals, local_preconditioner)
572 ALLOCATE (local_preconditioner)
573 CALL init_preconditioner(local_preconditioner, para_env=para_env, &
574 blacs_env=blacs_env)
575
576 CALL make_preconditioner(local_preconditioner, &
577 precon_type=ot_precond_full_kinetic, &
578 solver_type=ot_precond_solver_default, &
579 matrix_h=matrix_ks(my_spin)%matrix, &
580 matrix_s=matrix_s(1)%matrix, &
581 matrix_t=kinetic(1)%matrix, &
582 convert_precond_to_dbcsr=.true., &
583 mo_set=mos(my_spin), energy_gap=0.2_dp)
584
585 CALL get_xas_env(xas_env=xas_env, unoccupied_orbs=uno_orbs, &
586 unoccupied_evals=uno_evals, unoccupied_eps=uno_eps, unoccupied_max_iter=uno_iter)
587 CALL cp_fm_init_random(uno_orbs, nvirtual2)
588
589 CALL ot_eigensolver(matrix_h=matrix_ks(my_spin)%matrix, matrix_s=matrix_s(1)%matrix, &
590 matrix_c_fm=uno_orbs, matrix_orthogonal_space_fm=mo_coeff, &
591 preconditioner=local_preconditioner, eps_gradient=uno_eps, &
592 iter_max=uno_iter, size_ortho_space=nmo)
593
594 CALL calculate_subspace_eigenvalues(uno_orbs, matrix_ks(my_spin)%matrix, &
595 uno_evals, do_rotation=.true.)
596 CALL destroy_preconditioner(local_preconditioner)
597
598 DEALLOCATE (local_preconditioner)
599 END IF
600
601 CALL para_env%sync()
602 ! Prapare arrays for the calculation of the spectrum
603 IF (.NOT. xas_control%xas_method == xas_dscf) THEN
604 ! Copy the final vectors in the array
605 NULLIFY (all_vectors, all_evals)
606 CALL get_xas_env(xas_env=xas_env, all_vectors=all_vectors, &
607 all_evals=all_evals)
608 CALL get_mo_set(mos(my_spin), eigenvalues=eigenvalues, mo_coeff=mo_coeff, &
609 nmo=nmo)
610
611 CALL cp_fm_to_fm(mo_coeff, all_vectors, ncol=nmo, &
612 source_start=1, target_start=1)
613 DO istate = 1, nmo
614 all_evals(istate) = eigenvalues(istate)
615 END DO
616 IF (nvirtual2 > 0) THEN
617 CALL cp_fm_to_fm(uno_orbs, all_vectors, ncol=nvirtual2, &
618 source_start=1, target_start=1 + nmo)
619 DO istate = 1, nvirtual2
620 all_evals(istate + nmo) = uno_evals(istate)
621 END DO
622 END IF
623 END IF
624
625 DEALLOCATE (vecbuffer)
626 DEALLOCATE (vecbuffer2)
627 DEALLOCATE (centers_wfn, first_sgf)
628
629 CALL timestop(handle)
630
631 END SUBROUTINE cls_prepare_states
632
633! **************************************************************************************************
634!> \brief SCF for emission spectra calculations: vacancy in valence
635!> \param qs_env the qs_env, the scf_env and xas_env live in
636!> \param xas_env the environment for XAS calculations
637!> \param converged ...
638!> \param should_stop ...
639!> \par History
640!> 05.2005 created [MI]
641!> \author MI
642! **************************************************************************************************
643 SUBROUTINE xes_scf_once(qs_env, xas_env, converged, should_stop)
644
645 TYPE(qs_environment_type), POINTER :: qs_env
646 TYPE(xas_environment_type), POINTER :: xas_env
647 LOGICAL, INTENT(OUT) :: converged, should_stop
648
649 CHARACTER(LEN=*), PARAMETER :: routinen = 'xes_scf_once'
650
651 INTEGER :: handle, ispin, istate, my_spin, nmo, &
652 nvirtual, nvirtual2, output_unit, &
653 tsteps
654 REAL(kind=dp), DIMENSION(:), POINTER :: all_evals, eigenvalues
655 TYPE(cp_fm_type), POINTER :: all_vectors, mo_coeff
656 TYPE(cp_logger_type), POINTER :: logger
657 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks
658 TYPE(dft_control_type), POINTER :: dft_control
659 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
660 TYPE(mp_para_env_type), POINTER :: para_env
661 TYPE(qs_scf_env_type), POINTER :: scf_env
662 TYPE(scf_control_type), POINTER :: scf_control
663 TYPE(section_vals_type), POINTER :: dft_section, scf_section, xas_section
664 TYPE(xas_control_type), POINTER :: xas_control
665
666 NULLIFY (dft_control, scf_control, scf_env, matrix_ks, mos, para_env, xas_control)
667 NULLIFY (dft_section, xas_section, scf_section, all_vectors, mo_coeff, all_evals, eigenvalues)
668 NULLIFY (logger)
669 logger => cp_get_default_logger()
670 output_unit = cp_logger_get_default_io_unit(logger)
671
672 CALL timeset(routinen, handle)
673
674 cpassert(ASSOCIATED(xas_env))
675 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control, &
676 matrix_ks=matrix_ks, mos=mos, para_env=para_env)
677
678 xas_control => dft_control%xas_control
679 CALL get_xas_env(xas_env, scf_control=scf_control, spin_channel=my_spin)
680
681 dft_section => section_vals_get_subs_vals(qs_env%input, "DFT")
682 xas_section => section_vals_get_subs_vals(dft_section, "XAS")
683 scf_section => section_vals_get_subs_vals(xas_section, "SCF")
684
685 IF (xas_env%homo_occ == 0) THEN
686
687 NULLIFY (scf_env)
688 CALL get_xas_env(xas_env, scf_env=scf_env)
689 IF (.NOT. ASSOCIATED(scf_env)) THEN
690 CALL qs_scf_env_initialize(qs_env, scf_env, scf_control, scf_section)
691 CALL set_xas_env(xas_env, scf_env=scf_env)
692 ELSE
693 CALL qs_scf_env_initialize(qs_env, scf_env, scf_control, scf_section)
694 END IF
695
696 CALL scf_env_do_scf(scf_env=scf_env, scf_control=scf_control, qs_env=qs_env, &
697 converged=converged, should_stop=should_stop, total_scf_steps=tsteps)
698 CALL scf_env_cleanup(scf_env)
699
700 END IF
701
702 ! The eigenstate of the KS Hamiltonian are nedeed
703 NULLIFY (mo_coeff, eigenvalues)
704 IF (scf_control%use_ot) THEN
705 IF (output_unit > 0) THEN
706 WRITE (unit=output_unit, fmt="(/,T10,A,/)") &
707 "Get eigenstates and eigenvalues from ground state MOs"
708 END IF
709 DO ispin = 1, SIZE(mos)
710 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, &
711 eigenvalues=eigenvalues)
712 CALL calculate_subspace_eigenvalues(mo_coeff, &
713 matrix_ks(ispin)%matrix, eigenvalues, &
714 do_rotation=.true.)
715 END DO
716 END IF
717 CALL get_xas_env(xas_env=xas_env, all_vectors=all_vectors, &
718 all_evals=all_evals, nvirtual2=nvirtual2)
719 CALL get_mo_set(mos(my_spin), eigenvalues=eigenvalues, mo_coeff=mo_coeff, nmo=nmo)
720
721 CALL cp_fm_to_fm(mo_coeff, all_vectors, ncol=nmo, &
722 source_start=1, target_start=1)
723 DO istate = 1, nmo
724 all_evals(istate) = eigenvalues(istate)
725 END DO
726
727 IF (nvirtual2 /= 0) THEN
728 IF (output_unit > 0) THEN
729 WRITE (unit=output_unit, fmt="(/,T10,A,/)") &
730 "WARNING: for this XES calculation additional unoccupied MOs are not needed"
731 END IF
732 nvirtual2 = 0
733 nvirtual = nmo
734 CALL set_xas_env(xas_env=xas_env, nvirtual=nvirtual, nvirtual2=nvirtual2)
735 END IF
736
737 CALL timestop(handle)
738
739 END SUBROUTINE xes_scf_once
740
741END MODULE xas_tp_scf
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
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...
methods related to the blacs parallel environment
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
Routines to handle the external control of CP2K.
subroutine, public external_control(should_stop, flag, globenv, target_time, start_time, force_check)
External manipulations during a run : when the <PROJECT_NAME>.EXIT_$runtype command is sent the progr...
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
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_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
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...
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 function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
integer, parameter, public cp_p_file
subroutine, public cp_iterate(iteration_info, last, iter_nr, increment, iter_nr_out)
adds one to the actual iteration
subroutine, public cp_rm_iter_level(iteration_info, level_name, n_rlevel_att)
Removes an iteration level.
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...
subroutine, public cp_add_iter_level(iteration_info, level_name, n_rlevel_new)
Adds an iteration level.
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public xas_dscf
integer, parameter, public ot_precond_full_kinetic
integer, parameter, public ot_precond_solver_default
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
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Machine interface based on Fortran 2003 and POSIX.
Definition machine.F:17
subroutine, public m_flush(lunit)
flushes units if the &GLOBAL flag is set accordingly
Definition machine.F:136
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
Definition machine.F:153
Interface to the message passing library MPI.
Define methods related to particle_type.
subroutine, public get_particle_set(particle_set, qs_kind_set, first_sgf, last_sgf, nsgf, nmao, basis)
Get the components of a particle set.
Define the data structure for the particle information.
types of preconditioners
subroutine, public init_preconditioner(preconditioner_env, para_env, blacs_env)
...
subroutine, public destroy_preconditioner(preconditioner_env)
...
computes preconditioners, and implements methods to apply them currently used in qs_ot
subroutine, public make_preconditioner(preconditioner_env, precon_type, solver_type, matrix_h, matrix_s, matrix_t, mo_set, energy_gap, convert_precond_to_dbcsr, chol_type)
...
container for information about total charges on the grids
collects routines that calculate density matrices
module that contains the definitions of the scf types
integer, parameter, public broyden_mixing_nr
integer, parameter, public modified_broyden_mixing_nr
integer, parameter, public no_mixing_nr
integer, parameter, public direct_mixing_nr
integer, parameter, public multisecant_mixing_nr
integer, parameter, public pulay_mixing_nr
integer, parameter, public gspace_mixing_nr
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, 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.
subroutine, public gspace_mixing(qs_env, mixing_method, mixing_store, rho, para_env, iter_count)
Driver for the g-space mixing, calls the proper routine given the requested method.
Define the quickstep kind type and their sub types.
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 qs_ks_did_change(ks_env, s_mstruct_changed, rho_changed, potential_changed, full_reset)
tells that some of the things relevant to the ks calculation did change. has to be called when change...
Driver for the localization that should be general for all the methods available and all the definiti...
Definition qs_loc_main.F:22
subroutine, public qs_loc_driver(qs_env, qs_loc_env, print_loc_section, myspin, ext_mo_coeff)
set up the calculation of localized orbitals
Definition qs_loc_main.F:96
New version of the module for the localization of the molecular orbitals This should be able to use d...
subroutine, public get_qs_loc_env(qs_loc_env, cell, local_molecules, localized_wfn_control, moloc_coeff, op_sm_set, op_fm_set, para_env, particle_set, weights, dim_op)
...
subroutine, public self_consistency_check(rho_ao, p_delta, para_env, p_out, delta)
...
Definition and initialisation of the mo data type.
Definition qs_mo_io.F:21
subroutine, public write_mo_set_to_restart(mo_array, particle_set, dft_section, qs_kind_set, matrix_ks)
...
Definition qs_mo_io.F:107
collects routines that perform operations directly related to MOs
Set occupation of 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.
an eigen-space solver for the generalised symmetric eigenvalue problem for sparse matrices,...
subroutine, public ot_eigensolver(matrix_h, matrix_s, matrix_orthogonal_space_fm, matrix_c_fm, preconditioner, eps_gradient, iter_max, size_ortho_space, silent, ot_settings)
...
methods of the rho structure (defined in qs_rho_types)
subroutine, public qs_rho_update_rho(rho_struct, qs_env, rho_xc_external, local_rho_set, task_list_external, task_list_external_soft, pw_env_external, para_env_external)
updates rho_r and rho_g to the rhorho_ao. if use_kinetic_energy_density also computes tau_r and tau_g...
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_get(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
returns info about the density described by this object. If some representation is not available an e...
Different diagonalization schemes that can be used for the iterative solution of the eigenvalue probl...
subroutine, public general_eigenproblem(scf_env, mos, matrix_ks, matrix_s, scf_control, scf_section, diis_step)
the inner loop of scf, specific to diagonalization with S matrix basically, in goes the ks matrix out...
Utility routines for qs_scf.
subroutine, public qs_scf_env_initialize(qs_env, scf_env, scf_control, scf_section)
initializes input parameters if needed or restores values from previous runs to fill scf_env with the...
groups fairly general SCF methods, so that modules other than qs_scf can use them too split off from ...
subroutine, public scf_env_density_mixing(p_mix_new, mixing_store, rho_ao, para_env, iter_delta, iter_count, diis, invert)
perform (if requested) a density mixing
subroutine, public qs_scf_print_summary(output_unit, qs_env)
writes a summary of information after scf
module that contains the definitions of the scf types
integer, parameter, public general_diag_method_nr
Routines for the Quickstep SCF run.
Definition qs_scf.F:47
subroutine, public scf_env_cleanup(scf_env)
perform cleanup operations (like releasing temporary storage) at the end of the scf
Definition qs_scf.F:1000
subroutine, public scf_env_do_scf(scf_env, scf_control, qs_env, converged, should_stop, total_scf_steps)
perform an scf loop
Definition qs_scf.F:350
parameters that control an scf iteration
Defines control structures, which contain the parameters and the settings for the calculations.
Definition xas_control.F:12
define create destroy get and put information in xas_env to calculate the x-ray absorption spectra
subroutine, public set_xas_env(xas_env, nexc_search, spin_channel, nexc_atoms, nvirtual, nvirtual2, ip_energy, occ_estate, qs_loc_env, xas_estate, xas_nelectron, homo_occ, scf_env, scf_control)
...
subroutine, public get_xas_env(xas_env, exc_state, nao, nvirtual, nvirtual2, centers_wfn, atom_of_state, exc_atoms, nexc_states, type_of_state, mykind_of_atom, mykind_of_kind, state_of_atom, spectrum, groundstate_coeff, ostrength_sm, dip_fm_set, excvec_coeff, excvec_overlap, unoccupied_orbs, unoccupied_evals, unoccupied_max_iter, unoccupied_eps, all_vectors, all_evals, my_gto_basis, qs_loc_env, stogto_overlap, occ_estate, xas_nelectron, xas_estate, nexc_atoms, nexc_search, spin_channel, scf_env, scf_control)
...
Initialize the XAS orbitals for specific core excitations Either the GS orbitals are used as initial ...
Definition xas_restart.F:20
subroutine, public xas_write_restart(xas_env, xas_section, qs_env, xas_method, iatom, istate)
...
subroutine, public find_excited_core_orbital(xas_env, mos, matrix_s)
Find the index of the core orbital that has been excited by XAS.
xas_scf for the tp method It is repeaated for every atom that have to be excited
Definition xas_tp_scf.F:15
subroutine, public xas_do_tp_scf(dft_control, xas_env, iatom, istate, scf_env, qs_env, xas_section, scf_section, converged, should_stop)
perform an scf loop to calculate the xas spectrum given by the excitation of a inner state of a selec...
Definition xas_tp_scf.F:136
subroutine, public xes_scf_once(qs_env, xas_env, converged, should_stop)
SCF for emission spectra calculations: vacancy in valence.
Definition xas_tp_scf.F:644
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
represent a pointer to a 2d array
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
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...
stores all the informations relevant to an mpi environment
Container for information about total charges on the grids.
Provides all information about a quickstep kind.
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...
A type that holds controlling information for the calculation of the spread of wfn and the optimizati...
contains all the info needed by quickstep to calculate the spread of a selected set of orbitals and i...
keeps the density in various representations, keeping track of which ones are valid.
A type that holds controlling information for a xas calculation.
Definition xas_control.F:40