(git:419edc0)
Loading...
Searching...
No Matches
qs_scf_post_gpw.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Does all kind of post scf calculations for GPW/GAPW
10!> \par History
11!> Started as a copy from the relevant part of qs_scf
12!> Start to adapt for k-points [07.2015, JGH]
13!> \author Joost VandeVondele (10.2003)
14! **************************************************************************************************
16 USE admm_types, ONLY: admm_type
19 USE ai_onecenter, ONLY: sg_overlap
25 USE cell_types, ONLY: cell_type
29 USE cp_dbcsr_api, ONLY: dbcsr_add,&
35 USE cp_ddapc_util, ONLY: get_ddapc
40 USE cp_fm_types, ONLY: cp_fm_create,&
50 USE cp_output_handling, ONLY: cp_p_file,&
55 USE dct, ONLY: pw_shrink
56 USE ed_analysis, ONLY: edmf_analysis
57 USE eeq_method, ONLY: eeq_print
59 USE hfx_ri, ONLY: print_ri_hfx
70 USE iao_types, ONLY: iao_env_type,&
72 USE input_constants, ONLY: &
83 USE kinds, ONLY: default_path_length,&
85 dp
86 USE kpoint_types, ONLY: kpoint_type
88 USE mathconstants, ONLY: pi
94 USE mulliken, ONLY: mulliken_charges
95 USE orbital_pointers, ONLY: indso
98 USE physcon, ONLY: angstrom,&
99 evolt
103 USE ps_implicit_types, ONLY: mixed_bc,&
105 neumann_bc,&
107 USE pw_env_types, ONLY: pw_env_get,&
109 USE pw_grids, ONLY: get_pw_grid_info
110 USE pw_methods, ONLY: pw_axpy,&
111 pw_copy,&
112 pw_derive,&
114 pw_scale,&
116 pw_zero
120 USE pw_pool_types, ONLY: pw_pool_p_type,&
122 USE pw_types, ONLY: pw_c1d_gs_type,&
124 USE qs_chargemol, ONLY: write_wfx
129 USE qs_dos, ONLY: calculate_dos,&
132 USE qs_elf_methods, ONLY: qs_elf_calc
138 USE qs_epr_hyp, ONLY: qs_epr_hyp_calc
141 USE qs_kind_types, ONLY: get_qs_kind,&
146 USE qs_loc_dipole, ONLY: loc_dipole
162 USE qs_mo_types, ONLY: get_mo_set,&
175 USE qs_resp, ONLY: resp_fit
176 USE qs_rho0_types, ONLY: get_rho0_mpole,&
181 USE qs_rho_types, ONLY: qs_rho_get,&
186 USE qs_scf_types, ONLY: ot_method_nr,&
188 USE qs_scf_wfn_mix, ONLY: wfn_mix
189 USE qs_subsys_types, ONLY: qs_subsys_get,&
194 USE stm_images, ONLY: th_stm_image
196 USE trexio_utils, ONLY: write_trexio
197 USE virial_types, ONLY: virial_type
201#include "./base/base_uses.f90"
202
203 IMPLICIT NONE
204 PRIVATE
205
206 ! Global parameters
207 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_scf_post_gpw'
208 PUBLIC :: scf_post_calculation_gpw, &
212
213 PUBLIC :: make_lumo_gpw
214
215! **************************************************************************************************
216
217CONTAINS
218
219! **************************************************************************************************
220!> \brief collects possible post - scf calculations and prints info / computes properties.
221!> \param qs_env the qs_env in which the qs_env lives
222!> \param wf_type ...
223!> \param do_mp2 ...
224!> \par History
225!> 02.2003 created [fawzi]
226!> 10.2004 moved here from qs_scf [Joost VandeVondele]
227!> started splitting out different subroutines
228!> 10.2015 added header for wave-function correlated methods [Vladimir Rybkin]
229!> \author fawzi
230!> \note
231!> this function changes mo_eigenvectors and mo_eigenvalues, depending on the print keys.
232!> In particular, MO_CUBES causes the MOs to be rotated to make them eigenstates of the KS
233!> matrix, and mo_eigenvalues is updated accordingly. This can, for unconverged wavefunctions,
234!> change afterwards slightly the forces (hence small numerical differences between MD
235!> with and without the debug print level). Ideally this should not happen...
236! **************************************************************************************************
237 SUBROUTINE scf_post_calculation_gpw(qs_env, wf_type, do_mp2)
238
239 TYPE(qs_environment_type), POINTER :: qs_env
240 CHARACTER(6), OPTIONAL :: wf_type
241 LOGICAL, OPTIONAL :: do_mp2
242
243 CHARACTER(len=*), PARAMETER :: routinen = 'scf_post_calculation_gpw'
244
245 INTEGER :: handle, homo, ispin, min_lumos, n_rep, &
246 nchk_nmoloc, nhomo, nlumo, nlumo_stm, &
247 nlumos, nmo, nspins, output_unit, &
248 unit_nr
249 INTEGER, DIMENSION(:, :, :), POINTER :: marked_states
250 LOGICAL :: check_write, compute_lumos, do_homo, do_kpoints, do_mixed, do_mo_cubes, do_stm, &
251 do_wannier_cubes, has_homo, has_lumo, loc_explicit, loc_print_explicit, my_do_mp2, &
252 my_localized_wfn, p_loc, p_loc_homo, p_loc_lumo, p_loc_mixed
253 REAL(dp) :: e_kin
254 REAL(kind=dp) :: gap, homo_lumo(2, 2), total_zeff_corr
255 REAL(kind=dp), DIMENSION(:), POINTER :: mo_eigenvalues
256 TYPE(admm_type), POINTER :: admm_env
257 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
258 TYPE(cp_1d_r_p_type), DIMENSION(:), POINTER :: mixed_evals, occupied_evals, &
259 unoccupied_evals, unoccupied_evals_stm
260 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: mixed_orbs, occupied_orbs
261 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:), &
262 TARGET :: homo_localized, lumo_localized, &
263 mixed_localized
264 TYPE(cp_fm_type), DIMENSION(:), POINTER :: lumo_ptr, mo_loc_history, &
265 unoccupied_orbs, unoccupied_orbs_stm
266 TYPE(cp_fm_type), POINTER :: mo_coeff
267 TYPE(cp_logger_type), POINTER :: logger
268 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: ks_rmpv, matrix_p_mp2, matrix_s, &
269 mo_derivs
270 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: kinetic_m, rho_ao
271 TYPE(dft_control_type), POINTER :: dft_control
272 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
273 TYPE(molecule_type), POINTER :: molecule_set(:)
274 TYPE(mp_para_env_type), POINTER :: para_env
275 TYPE(particle_list_type), POINTER :: particles
276 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
277 TYPE(pw_c1d_gs_type) :: wf_g
278 TYPE(pw_env_type), POINTER :: pw_env
279 TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
280 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
281 TYPE(pw_r3d_rs_type) :: wf_r
282 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
283 TYPE(qs_loc_env_type), POINTER :: qs_loc_env_homo, qs_loc_env_lumo, &
284 qs_loc_env_mixed
285 TYPE(qs_rho_type), POINTER :: rho
286 TYPE(qs_scf_env_type), POINTER :: scf_env
287 TYPE(qs_subsys_type), POINTER :: subsys
288 TYPE(scf_control_type), POINTER :: scf_control
289 TYPE(section_vals_type), POINTER :: dft_section, input, loc_print_section, &
290 localize_section, print_key, &
291 stm_section
292
293 CALL timeset(routinen, handle)
294
295 logger => cp_get_default_logger()
296 output_unit = cp_logger_get_default_io_unit(logger)
297
298 ! Print out the type of wavefunction to distinguish between SCF and post-SCF
299 my_do_mp2 = .false.
300 IF (PRESENT(do_mp2)) my_do_mp2 = do_mp2
301 IF (PRESENT(wf_type)) THEN
302 IF (output_unit > 0) THEN
303 WRITE (unit=output_unit, fmt='(/,(T1,A))') repeat("-", 40)
304 WRITE (unit=output_unit, fmt='(/,(T3,A,T19,A,T25,A))') "Properties from ", wf_type, " density"
305 WRITE (unit=output_unit, fmt='(/,(T1,A))') repeat("-", 40)
306 END IF
307 END IF
308
309 ! Writes the data that is already available in qs_env
310 CALL get_qs_env(qs_env, scf_env=scf_env)
311
312 my_localized_wfn = .false.
313 NULLIFY (admm_env, dft_control, pw_env, auxbas_pw_pool, pw_pools, mos, rho, &
314 mo_coeff, ks_rmpv, matrix_s, qs_loc_env_homo, qs_loc_env_lumo, scf_control, &
315 unoccupied_orbs, mo_eigenvalues, unoccupied_evals, &
316 unoccupied_evals_stm, molecule_set, mo_derivs, &
317 subsys, particles, input, print_key, kinetic_m, marked_states, &
318 mixed_evals, qs_loc_env_mixed)
319 NULLIFY (lumo_ptr, rho_ao)
320
321 has_homo = .false.
322 has_lumo = .false.
323 p_loc = .false.
324 p_loc_homo = .false.
325 p_loc_lumo = .false.
326 p_loc_mixed = .false.
327
328 cpassert(ASSOCIATED(scf_env))
329 cpassert(ASSOCIATED(qs_env))
330 ! Here we start with data that needs a postprocessing...
331 CALL get_qs_env(qs_env, &
332 dft_control=dft_control, &
333 molecule_set=molecule_set, &
334 scf_control=scf_control, &
335 do_kpoints=do_kpoints, &
336 input=input, &
337 subsys=subsys, &
338 rho=rho, &
339 pw_env=pw_env, &
340 particle_set=particle_set, &
341 atomic_kind_set=atomic_kind_set, &
342 qs_kind_set=qs_kind_set)
343 CALL qs_subsys_get(subsys, particles=particles)
344
345 CALL qs_rho_get(rho, rho_ao_kp=rho_ao)
346
347 IF (my_do_mp2) THEN
348 ! Get the HF+MP2 density
349 CALL get_qs_env(qs_env, matrix_p_mp2=matrix_p_mp2)
350 DO ispin = 1, dft_control%nspins
351 CALL dbcsr_add(rho_ao(ispin, 1)%matrix, matrix_p_mp2(ispin)%matrix, 1.0_dp, 1.0_dp)
352 END DO
353 CALL qs_rho_update_rho(rho, qs_env=qs_env)
354 CALL qs_ks_did_change(qs_env%ks_env, rho_changed=.true.)
355 ! In MP2 case update the Hartree potential
356 CALL update_hartree_with_mp2(rho, qs_env)
357 END IF
358
359 CALL write_available_results(qs_env, scf_env)
360
361 ! **** the kinetic energy
362 IF (cp_print_key_should_output(logger%iter_info, input, &
363 "DFT%PRINT%KINETIC_ENERGY") /= 0) THEN
364 CALL get_qs_env(qs_env, kinetic_kp=kinetic_m)
365 cpassert(ASSOCIATED(kinetic_m))
366 cpassert(ASSOCIATED(kinetic_m(1, 1)%matrix))
367 CALL calculate_ptrace(kinetic_m, rho_ao, e_kin, dft_control%nspins)
368 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%KINETIC_ENERGY", &
369 extension=".Log")
370 IF (unit_nr > 0) THEN
371 WRITE (unit_nr, '(T3,A,T55,F25.14)') "Electronic kinetic energy:", e_kin
372 END IF
373 CALL cp_print_key_finished_output(unit_nr, logger, input, &
374 "DFT%PRINT%KINETIC_ENERGY")
375 END IF
376
377 ! Atomic Charges that require further computation
378 CALL qs_scf_post_charges(input, logger, qs_env)
379
380 ! Moments of charge distribution
381 CALL qs_scf_post_moments(input, logger, qs_env, output_unit)
382
383 ! Determine if we need to computer properties using the localized centers
384 dft_section => section_vals_get_subs_vals(input, "DFT")
385 localize_section => section_vals_get_subs_vals(dft_section, "LOCALIZE")
386 loc_print_section => section_vals_get_subs_vals(localize_section, "PRINT")
387 CALL section_vals_get(localize_section, explicit=loc_explicit)
388 CALL section_vals_get(loc_print_section, explicit=loc_print_explicit)
389
390 ! Print_keys controlled by localization
391 IF (loc_print_explicit) THEN
392 print_key => section_vals_get_subs_vals(loc_print_section, "MOLECULAR_DIPOLES")
393 p_loc = btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
394 print_key => section_vals_get_subs_vals(loc_print_section, "TOTAL_DIPOLE")
395 p_loc = p_loc .OR. btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
396 print_key => section_vals_get_subs_vals(loc_print_section, "WANNIER_CENTERS")
397 p_loc = p_loc .OR. btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
398 print_key => section_vals_get_subs_vals(loc_print_section, "WANNIER_SPREADS")
399 p_loc = p_loc .OR. btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
400 print_key => section_vals_get_subs_vals(loc_print_section, "WANNIER_CUBES")
401 p_loc = p_loc .OR. btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
402 print_key => section_vals_get_subs_vals(loc_print_section, "MOLECULAR_STATES")
403 p_loc = p_loc .OR. btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
404 print_key => section_vals_get_subs_vals(loc_print_section, "MOLECULAR_MOMENTS")
405 p_loc = p_loc .OR. btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
406 print_key => section_vals_get_subs_vals(loc_print_section, "WANNIER_STATES")
407 p_loc = p_loc .OR. btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
408 ELSE
409 p_loc = .false.
410 END IF
411 IF (loc_explicit) THEN
412 p_loc_homo = (section_get_ival(localize_section, "STATES") == do_loc_homo .OR. &
413 section_get_ival(localize_section, "STATES") == do_loc_both) .AND. p_loc
414 p_loc_lumo = (section_get_ival(localize_section, "STATES") == do_loc_lumo .OR. &
415 section_get_ival(localize_section, "STATES") == do_loc_both) .AND. p_loc
416 p_loc_mixed = (section_get_ival(localize_section, "STATES") == do_loc_mixed) .AND. p_loc
417 CALL section_vals_val_get(localize_section, "LIST_UNOCCUPIED", n_rep_val=n_rep)
418 ELSE
419 p_loc_homo = .false.
420 p_loc_lumo = .false.
421 p_loc_mixed = .false.
422 n_rep = 0
423 END IF
424
425 IF (n_rep == 0 .AND. p_loc_lumo) THEN
426 CALL cp_abort(__location__, "No LIST_UNOCCUPIED was specified, "// &
427 "therefore localization of unoccupied states will be skipped!")
428 p_loc_lumo = .false.
429 END IF
430
431 ! Control for STM
432 stm_section => section_vals_get_subs_vals(input, "DFT%PRINT%STM")
433 CALL section_vals_get(stm_section, explicit=do_stm)
434 nlumo_stm = 0
435 IF (do_stm) nlumo_stm = section_get_ival(stm_section, "NLUMO")
436
437 ! check for CUBES (MOs and WANNIERS)
438 do_mo_cubes = btest(cp_print_key_should_output(logger%iter_info, dft_section, "PRINT%MO_CUBES") &
439 , cp_p_file)
440 IF (loc_print_explicit) THEN
441 do_wannier_cubes = btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
442 "WANNIER_CUBES"), cp_p_file)
443 ELSE
444 do_wannier_cubes = .false.
445 END IF
446 nlumo = section_get_ival(dft_section, "PRINT%MO_CUBES%NLUMO")
447 nhomo = section_get_ival(dft_section, "PRINT%MO_CUBES%NHOMO")
448
449 ! Setup the grids needed to compute a wavefunction given a vector..
450 IF (((do_mo_cubes .OR. do_wannier_cubes) .AND. (nlumo /= 0 .OR. nhomo /= 0)) .OR. p_loc) THEN
451 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
452 pw_pools=pw_pools)
453 CALL auxbas_pw_pool%create_pw(wf_r)
454 CALL auxbas_pw_pool%create_pw(wf_g)
455 END IF
456
457 IF (dft_control%restricted) THEN
458 !For ROKS usefull only first term
459 nspins = 1
460 ELSE
461 nspins = dft_control%nspins
462 END IF
463 !Some info about ROKS
464 IF (dft_control%restricted .AND. (do_mo_cubes .OR. p_loc_homo)) THEN
465 CALL cp_abort(__location__, "Unclear how we define MOs / localization in the restricted case ... ")
466 ! It is possible to obtain Wannier centers for ROKS without rotations for SINGLE OCCUPIED ORBITALS
467 END IF
468 ! Makes the MOs eigenstates, computes eigenvalues, write cubes
469 IF (do_kpoints) THEN
470 cpwarn_if(do_mo_cubes, "Print MO cubes not implemented for k-point calculations")
471 ELSE
472 CALL get_qs_env(qs_env, &
473 mos=mos, &
474 matrix_ks=ks_rmpv)
475 IF ((do_mo_cubes .AND. nhomo /= 0) .OR. do_stm) THEN
476 CALL get_qs_env(qs_env, mo_derivs=mo_derivs)
477 IF (dft_control%do_admm) THEN
478 CALL get_qs_env(qs_env, admm_env=admm_env)
479 CALL make_mo_eig(mos, nspins, ks_rmpv, scf_control, mo_derivs, admm_env=admm_env)
480 ELSE
481 CALL make_mo_eig(mos, nspins, ks_rmpv, scf_control, mo_derivs)
482 END IF
483 DO ispin = 1, dft_control%nspins
484 CALL get_mo_set(mo_set=mos(ispin), eigenvalues=mo_eigenvalues, homo=homo)
485 homo_lumo(ispin, 1) = mo_eigenvalues(homo)
486 END DO
487 has_homo = .true.
488 END IF
489 IF (do_mo_cubes .AND. nhomo /= 0) THEN
490 DO ispin = 1, nspins
491 ! Prints the cube files of OCCUPIED ORBITALS
492 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, &
493 eigenvalues=mo_eigenvalues, homo=homo, nmo=nmo)
494 CALL qs_scf_post_occ_cubes(input, dft_section, dft_control, logger, qs_env, &
495 mo_coeff, wf_g, wf_r, particles, homo, ispin)
496 END DO
497 END IF
498 END IF
499
500 ! Initialize the localization environment, needed e.g. for wannier functions and molecular states
501 ! Gets localization info for the occupied orbs
502 ! - Possibly gets wannier functions
503 ! - Possibly gets molecular states
504 IF (p_loc_homo) THEN
505 IF (do_kpoints) THEN
506 cpwarn("Localization not implemented for k-point calculations!")
507 ELSEIF (dft_control%restricted &
508 .AND. (section_get_ival(localize_section, "METHOD") .NE. do_loc_none) &
509 .AND. (section_get_ival(localize_section, "METHOD") .NE. do_loc_jacobi)) THEN
510 cpabort("ROKS works only with LOCALIZE METHOD NONE or JACOBI")
511 ELSE
512 ALLOCATE (occupied_orbs(dft_control%nspins))
513 ALLOCATE (occupied_evals(dft_control%nspins))
514 ALLOCATE (homo_localized(dft_control%nspins))
515 DO ispin = 1, dft_control%nspins
516 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, &
517 eigenvalues=mo_eigenvalues)
518 occupied_orbs(ispin) = mo_coeff
519 occupied_evals(ispin)%array => mo_eigenvalues
520 CALL cp_fm_create(homo_localized(ispin), occupied_orbs(ispin)%matrix_struct)
521 CALL cp_fm_to_fm(occupied_orbs(ispin), homo_localized(ispin))
522 END DO
523
524 CALL get_qs_env(qs_env, mo_loc_history=mo_loc_history)
525 do_homo = .true.
526
527 ALLOCATE (qs_loc_env_homo)
528 CALL qs_loc_env_create(qs_loc_env_homo)
529 CALL qs_loc_control_init(qs_loc_env_homo, localize_section, do_homo=do_homo)
530 CALL qs_loc_init(qs_env, qs_loc_env_homo, localize_section, homo_localized, do_homo, &
531 do_mo_cubes, mo_loc_history=mo_loc_history)
532 CALL get_localization_info(qs_env, qs_loc_env_homo, localize_section, homo_localized, &
533 wf_r, wf_g, particles, occupied_orbs, occupied_evals, marked_states)
534
535 !retain the homo_localized for future use
536 IF (qs_loc_env_homo%localized_wfn_control%use_history) THEN
537 CALL retain_history(mo_loc_history, homo_localized)
538 CALL set_qs_env(qs_env, mo_loc_history=mo_loc_history)
539 END IF
540
541 !write restart for localization of occupied orbitals
542 CALL loc_write_restart(qs_loc_env_homo, loc_print_section, mos, &
543 homo_localized, do_homo)
544 CALL cp_fm_release(homo_localized)
545 DEALLOCATE (occupied_orbs)
546 DEALLOCATE (occupied_evals)
547 ! Print Total Dipole if the localization has been performed
548 IF (qs_loc_env_homo%do_localize) THEN
549 CALL loc_dipole(input, dft_control, qs_loc_env_homo, logger, qs_env)
550 END IF
551 END IF
552 END IF
553
554 ! Gets the lumos, and eigenvalues for the lumos, and localize them if requested
555 IF (do_kpoints) THEN
556 IF (do_mo_cubes .OR. p_loc_lumo) THEN
557 ! nothing at the moment, not implemented
558 cpwarn("Localization and MO related output not implemented for k-point calculations!")
559 END IF
560 ELSE
561 compute_lumos = do_mo_cubes .AND. nlumo .NE. 0
562 compute_lumos = compute_lumos .OR. p_loc_lumo
563
564 DO ispin = 1, dft_control%nspins
565 CALL get_mo_set(mo_set=mos(ispin), homo=homo, nmo=nmo)
566 compute_lumos = compute_lumos .AND. homo == nmo
567 END DO
568
569 IF (do_mo_cubes .AND. .NOT. compute_lumos) THEN
570
571 nlumo = section_get_ival(dft_section, "PRINT%MO_CUBES%NLUMO")
572 DO ispin = 1, dft_control%nspins
573
574 CALL get_mo_set(mo_set=mos(ispin), homo=homo, nmo=nmo, eigenvalues=mo_eigenvalues)
575 IF (nlumo > nmo - homo) THEN
576 ! this case not yet implemented
577 ELSE
578 IF (nlumo .EQ. -1) THEN
579 nlumo = nmo - homo
580 END IF
581 IF (output_unit > 0) WRITE (output_unit, *) " "
582 IF (output_unit > 0) WRITE (output_unit, *) " Lowest eigenvalues of the unoccupied subspace spin ", ispin
583 IF (output_unit > 0) WRITE (output_unit, *) "---------------------------------------------"
584 IF (output_unit > 0) WRITE (output_unit, '(4(1X,1F16.8))') mo_eigenvalues(homo + 1:homo + nlumo)
585
586 ! Prints the cube files of UNOCCUPIED ORBITALS
587 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff)
588 CALL qs_scf_post_unocc_cubes(input, dft_section, dft_control, logger, qs_env, &
589 mo_coeff, wf_g, wf_r, particles, nlumo, homo, ispin, lumo=homo + 1)
590 END IF
591 END DO
592
593 END IF
594
595 IF (compute_lumos) THEN
596 check_write = .true.
597 min_lumos = nlumo
598 IF (nlumo == 0) check_write = .false.
599 IF (p_loc_lumo) THEN
600 do_homo = .false.
601 ALLOCATE (qs_loc_env_lumo)
602 CALL qs_loc_env_create(qs_loc_env_lumo)
603 CALL qs_loc_control_init(qs_loc_env_lumo, localize_section, do_homo=do_homo)
604 min_lumos = max(maxval(qs_loc_env_lumo%localized_wfn_control%loc_states(:, :)), nlumo)
605 END IF
606
607 ALLOCATE (unoccupied_orbs(dft_control%nspins))
608 ALLOCATE (unoccupied_evals(dft_control%nspins))
609 CALL make_lumo_gpw(qs_env, scf_env, unoccupied_orbs, unoccupied_evals, min_lumos, nlumos)
610 lumo_ptr => unoccupied_orbs
611 DO ispin = 1, dft_control%nspins
612 has_lumo = .true.
613 homo_lumo(ispin, 2) = unoccupied_evals(ispin)%array(1)
614 CALL get_mo_set(mo_set=mos(ispin), homo=homo)
615 IF (check_write) THEN
616 IF (p_loc_lumo .AND. nlumo .NE. -1) nlumos = min(nlumo, nlumos)
617 ! Prints the cube files of UNOCCUPIED ORBITALS
618 CALL qs_scf_post_unocc_cubes(input, dft_section, dft_control, logger, qs_env, &
619 unoccupied_orbs(ispin), wf_g, wf_r, particles, nlumos, homo, ispin)
620 END IF
621 END DO
622
623 IF (p_loc_lumo) THEN
624 ALLOCATE (lumo_localized(dft_control%nspins))
625 DO ispin = 1, dft_control%nspins
626 CALL cp_fm_create(lumo_localized(ispin), unoccupied_orbs(ispin)%matrix_struct)
627 CALL cp_fm_to_fm(unoccupied_orbs(ispin), lumo_localized(ispin))
628 END DO
629 CALL qs_loc_init(qs_env, qs_loc_env_lumo, localize_section, lumo_localized, do_homo, do_mo_cubes, &
630 evals=unoccupied_evals)
631 CALL qs_loc_env_init(qs_loc_env_lumo, qs_loc_env_lumo%localized_wfn_control, qs_env, &
632 loc_coeff=unoccupied_orbs)
633 CALL get_localization_info(qs_env, qs_loc_env_lumo, localize_section, &
634 lumo_localized, wf_r, wf_g, particles, &
635 unoccupied_orbs, unoccupied_evals, marked_states)
636 CALL loc_write_restart(qs_loc_env_lumo, loc_print_section, mos, homo_localized, do_homo, &
637 evals=unoccupied_evals)
638 lumo_ptr => lumo_localized
639 END IF
640 END IF
641
642 IF (has_homo .AND. has_lumo) THEN
643 IF (output_unit > 0) WRITE (output_unit, *) " "
644 DO ispin = 1, dft_control%nspins
645 IF (.NOT. scf_control%smear%do_smear) THEN
646 gap = homo_lumo(ispin, 2) - homo_lumo(ispin, 1)
647 IF (output_unit > 0) WRITE (output_unit, '(T2,A,F12.6)') &
648 "HOMO - LUMO gap [eV] :", gap*evolt
649 END IF
650 END DO
651 END IF
652 END IF
653
654 IF (p_loc_mixed) THEN
655 IF (do_kpoints) THEN
656 cpwarn("Localization not implemented for k-point calculations!")
657 ELSEIF (dft_control%restricted) THEN
658 IF (output_unit > 0) WRITE (output_unit, *) &
659 " Unclear how we define MOs / localization in the restricted case... skipping"
660 ELSE
661
662 ALLOCATE (mixed_orbs(dft_control%nspins))
663 ALLOCATE (mixed_evals(dft_control%nspins))
664 ALLOCATE (mixed_localized(dft_control%nspins))
665 DO ispin = 1, dft_control%nspins
666 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, &
667 eigenvalues=mo_eigenvalues)
668 mixed_orbs(ispin) = mo_coeff
669 mixed_evals(ispin)%array => mo_eigenvalues
670 CALL cp_fm_create(mixed_localized(ispin), mixed_orbs(ispin)%matrix_struct)
671 CALL cp_fm_to_fm(mixed_orbs(ispin), mixed_localized(ispin))
672 END DO
673
674 CALL get_qs_env(qs_env, mo_loc_history=mo_loc_history)
675 do_homo = .false.
676 do_mixed = .true.
677 total_zeff_corr = scf_env%sum_zeff_corr
678 ALLOCATE (qs_loc_env_mixed)
679 CALL qs_loc_env_create(qs_loc_env_mixed)
680 CALL qs_loc_control_init(qs_loc_env_mixed, localize_section, do_homo=do_homo, do_mixed=do_mixed)
681 CALL qs_loc_init(qs_env, qs_loc_env_mixed, localize_section, mixed_localized, do_homo, &
682 do_mo_cubes, mo_loc_history=mo_loc_history, tot_zeff_corr=total_zeff_corr, &
684
685 DO ispin = 1, dft_control%nspins
686 CALL cp_fm_get_info(mixed_localized(ispin), ncol_global=nchk_nmoloc)
687 END DO
688
689 CALL get_localization_info(qs_env, qs_loc_env_mixed, localize_section, mixed_localized, &
690 wf_r, wf_g, particles, mixed_orbs, mixed_evals, marked_states)
691
692 !retain the homo_localized for future use
693 IF (qs_loc_env_mixed%localized_wfn_control%use_history) THEN
694 CALL retain_history(mo_loc_history, mixed_localized)
695 CALL set_qs_env(qs_env, mo_loc_history=mo_loc_history)
696 END IF
697
698 !write restart for localization of occupied orbitals
699 CALL loc_write_restart(qs_loc_env_mixed, loc_print_section, mos, &
700 mixed_localized, do_homo, do_mixed=do_mixed)
701 CALL cp_fm_release(mixed_localized)
702 DEALLOCATE (mixed_orbs)
703 DEALLOCATE (mixed_evals)
704 ! Print Total Dipole if the localization has been performed
705! Revisit the formalism later
706 !IF (qs_loc_env_mixed%do_localize) THEN
707 ! CALL loc_dipole(input, dft_control, qs_loc_env_mixed, logger, qs_env)
708 !END IF
709 END IF
710 END IF
711
712 ! Deallocate grids needed to compute wavefunctions
713 IF (((do_mo_cubes .OR. do_wannier_cubes) .AND. (nlumo /= 0 .OR. nhomo /= 0)) .OR. p_loc) THEN
714 CALL auxbas_pw_pool%give_back_pw(wf_r)
715 CALL auxbas_pw_pool%give_back_pw(wf_g)
716 END IF
717
718 ! Destroy the localization environment
719 IF (.NOT. do_kpoints) THEN
720 IF (p_loc_homo) THEN
721 CALL qs_loc_env_release(qs_loc_env_homo)
722 DEALLOCATE (qs_loc_env_homo)
723 END IF
724 IF (p_loc_lumo) THEN
725 CALL qs_loc_env_release(qs_loc_env_lumo)
726 DEALLOCATE (qs_loc_env_lumo)
727 END IF
728 IF (p_loc_mixed) THEN
729 CALL qs_loc_env_release(qs_loc_env_mixed)
730 DEALLOCATE (qs_loc_env_mixed)
731 END IF
732 END IF
733
734 ! generate a mix of wfns, and write to a restart
735 IF (do_kpoints) THEN
736 ! nothing at the moment, not implemented
737 ELSE
738 CALL get_qs_env(qs_env, matrix_s=matrix_s, para_env=para_env)
739 CALL wfn_mix(mos, particle_set, dft_section, qs_kind_set, para_env, &
740 output_unit, unoccupied_orbs=lumo_ptr, scf_env=scf_env, &
741 matrix_s=matrix_s, marked_states=marked_states)
742
743 IF (p_loc_lumo) CALL cp_fm_release(lumo_localized)
744 END IF
745 IF (ASSOCIATED(marked_states)) THEN
746 DEALLOCATE (marked_states)
747 END IF
748
749 ! This is just a deallocation for printing MO_CUBES or TDDFPT
750 IF (.NOT. do_kpoints) THEN
751 IF (compute_lumos) THEN
752 DO ispin = 1, dft_control%nspins
753 DEALLOCATE (unoccupied_evals(ispin)%array)
754 CALL cp_fm_release(unoccupied_orbs(ispin))
755 END DO
756 DEALLOCATE (unoccupied_evals)
757 DEALLOCATE (unoccupied_orbs)
758 END IF
759 END IF
760
761 !stm images
762 IF (do_stm) THEN
763 IF (do_kpoints) THEN
764 cpwarn("STM not implemented for k-point calculations!")
765 ELSE
766 NULLIFY (unoccupied_orbs_stm, unoccupied_evals_stm)
767 IF (nlumo_stm > 0) THEN
768 ALLOCATE (unoccupied_orbs_stm(dft_control%nspins))
769 ALLOCATE (unoccupied_evals_stm(dft_control%nspins))
770 CALL make_lumo_gpw(qs_env, scf_env, unoccupied_orbs_stm, unoccupied_evals_stm, &
771 nlumo_stm, nlumos)
772 END IF
773
774 CALL th_stm_image(qs_env, stm_section, particles, unoccupied_orbs_stm, &
775 unoccupied_evals_stm)
776
777 IF (nlumo_stm > 0) THEN
778 DO ispin = 1, dft_control%nspins
779 DEALLOCATE (unoccupied_evals_stm(ispin)%array)
780 END DO
781 DEALLOCATE (unoccupied_evals_stm)
782 CALL cp_fm_release(unoccupied_orbs_stm)
783 END IF
784 END IF
785 END IF
786
787 ! Print coherent X-ray diffraction spectrum
788 CALL qs_scf_post_xray(input, dft_section, logger, qs_env, output_unit)
789
790 ! Calculation of Electric Field Gradients
791 CALL qs_scf_post_efg(input, logger, qs_env)
792
793 ! Calculation of ET
794 CALL qs_scf_post_et(input, qs_env, dft_control)
795
796 ! Calculation of EPR Hyperfine Coupling Tensors
797 CALL qs_scf_post_epr(input, logger, qs_env)
798
799 ! Calculation of properties needed for BASIS_MOLOPT optimizations
800 CALL qs_scf_post_molopt(input, logger, qs_env)
801
802 ! Calculate ELF
803 CALL qs_scf_post_elf(input, logger, qs_env)
804
805 ! Use Wannier90 interface
806 CALL wannier90_interface(input, logger, qs_env)
807
808 IF (my_do_mp2) THEN
809 ! Get everything back
810 DO ispin = 1, dft_control%nspins
811 CALL dbcsr_add(rho_ao(ispin, 1)%matrix, matrix_p_mp2(ispin)%matrix, 1.0_dp, -1.0_dp)
812 END DO
813 CALL qs_rho_update_rho(rho, qs_env=qs_env)
814 CALL qs_ks_did_change(qs_env%ks_env, rho_changed=.true.)
815 END IF
816
817 CALL timestop(handle)
818
819 END SUBROUTINE scf_post_calculation_gpw
820
821! **************************************************************************************************
822!> \brief Gets the lumos, and eigenvalues for the lumos
823!> \param qs_env ...
824!> \param scf_env ...
825!> \param unoccupied_orbs ...
826!> \param unoccupied_evals ...
827!> \param nlumo ...
828!> \param nlumos ...
829! **************************************************************************************************
830 SUBROUTINE make_lumo_gpw(qs_env, scf_env, unoccupied_orbs, unoccupied_evals, nlumo, nlumos)
831
832 TYPE(qs_environment_type), POINTER :: qs_env
833 TYPE(qs_scf_env_type), POINTER :: scf_env
834 TYPE(cp_fm_type), DIMENSION(:), INTENT(INOUT) :: unoccupied_orbs
835 TYPE(cp_1d_r_p_type), DIMENSION(:), POINTER :: unoccupied_evals
836 INTEGER, INTENT(IN) :: nlumo
837 INTEGER, INTENT(OUT) :: nlumos
838
839 CHARACTER(len=*), PARAMETER :: routinen = 'make_lumo_gpw'
840
841 INTEGER :: handle, homo, ispin, n, nao, nmo, &
842 output_unit
843 TYPE(admm_type), POINTER :: admm_env
844 TYPE(cp_blacs_env_type), POINTER :: blacs_env
845 TYPE(cp_fm_struct_type), POINTER :: fm_struct_tmp
846 TYPE(cp_fm_type), POINTER :: mo_coeff
847 TYPE(cp_logger_type), POINTER :: logger
848 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: ks_rmpv, matrix_s
849 TYPE(dft_control_type), POINTER :: dft_control
850 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
851 TYPE(mp_para_env_type), POINTER :: para_env
852 TYPE(preconditioner_type), POINTER :: local_preconditioner
853 TYPE(scf_control_type), POINTER :: scf_control
854
855 CALL timeset(routinen, handle)
856
857 NULLIFY (mos, ks_rmpv, scf_control, dft_control, admm_env, para_env, blacs_env)
858 CALL get_qs_env(qs_env, &
859 mos=mos, &
860 matrix_ks=ks_rmpv, &
861 scf_control=scf_control, &
862 dft_control=dft_control, &
863 matrix_s=matrix_s, &
864 admm_env=admm_env, &
865 para_env=para_env, &
866 blacs_env=blacs_env)
867
868 logger => cp_get_default_logger()
869 output_unit = cp_logger_get_default_io_unit(logger)
870
871 DO ispin = 1, dft_control%nspins
872 NULLIFY (unoccupied_evals(ispin)%array)
873 ! Always write eigenvalues
874 IF (output_unit > 0) WRITE (output_unit, *) " "
875 IF (output_unit > 0) WRITE (output_unit, *) " Lowest Eigenvalues of the unoccupied subspace spin ", ispin
876 IF (output_unit > 0) WRITE (output_unit, fmt='(1X,A)') "-----------------------------------------------------"
877 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, homo=homo, nao=nao, nmo=nmo)
878 CALL cp_fm_get_info(mo_coeff, nrow_global=n)
879 nlumos = max(1, min(nlumo, nao - nmo))
880 IF (nlumo == -1) nlumos = nao - nmo
881 ALLOCATE (unoccupied_evals(ispin)%array(nlumos))
882 CALL cp_fm_struct_create(fm_struct_tmp, para_env=para_env, context=blacs_env, &
883 nrow_global=n, ncol_global=nlumos)
884 CALL cp_fm_create(unoccupied_orbs(ispin), fm_struct_tmp, name="lumos")
885 CALL cp_fm_struct_release(fm_struct_tmp)
886 CALL cp_fm_init_random(unoccupied_orbs(ispin), nlumos)
887
888 ! the full_all preconditioner makes not much sense for lumos search
889 NULLIFY (local_preconditioner)
890 IF (ASSOCIATED(scf_env%ot_preconditioner)) THEN
891 local_preconditioner => scf_env%ot_preconditioner(1)%preconditioner
892 ! this one can for sure not be right (as it has to match a given C0)
893 IF (local_preconditioner%in_use == ot_precond_full_all) THEN
894 NULLIFY (local_preconditioner)
895 END IF
896 END IF
897
898 ! ** If we do ADMM, we add have to modify the kohn-sham matrix
899 IF (dft_control%do_admm) THEN
900 CALL admm_correct_for_eigenvalues(ispin, admm_env, ks_rmpv(ispin)%matrix)
901 END IF
902
903 CALL ot_eigensolver(matrix_h=ks_rmpv(ispin)%matrix, matrix_s=matrix_s(1)%matrix, &
904 matrix_c_fm=unoccupied_orbs(ispin), &
905 matrix_orthogonal_space_fm=mo_coeff, &
906 eps_gradient=scf_control%eps_lumos, &
907 preconditioner=local_preconditioner, &
908 iter_max=scf_control%max_iter_lumos, &
909 size_ortho_space=nmo)
910
911 CALL calculate_subspace_eigenvalues(unoccupied_orbs(ispin), ks_rmpv(ispin)%matrix, &
912 unoccupied_evals(ispin)%array, scr=output_unit, &
913 ionode=output_unit > 0)
914
915 ! ** If we do ADMM, we restore the original kohn-sham matrix
916 IF (dft_control%do_admm) THEN
917 CALL admm_uncorrect_for_eigenvalues(ispin, admm_env, ks_rmpv(ispin)%matrix)
918 END IF
919
920 END DO
921
922 CALL timestop(handle)
923
924 END SUBROUTINE make_lumo_gpw
925! **************************************************************************************************
926!> \brief Computes and Prints Atomic Charges with several methods
927!> \param input ...
928!> \param logger ...
929!> \param qs_env the qs_env in which the qs_env lives
930! **************************************************************************************************
931 SUBROUTINE qs_scf_post_charges(input, logger, qs_env)
932 TYPE(section_vals_type), POINTER :: input
933 TYPE(cp_logger_type), POINTER :: logger
934 TYPE(qs_environment_type), POINTER :: qs_env
935
936 CHARACTER(len=*), PARAMETER :: routinen = 'qs_scf_post_charges'
937
938 INTEGER :: handle, print_level, unit_nr
939 LOGICAL :: do_kpoints, print_it
940 TYPE(section_vals_type), POINTER :: density_fit_section, print_key
941
942 CALL timeset(routinen, handle)
943
944 CALL get_qs_env(qs_env=qs_env, do_kpoints=do_kpoints)
945
946 ! Mulliken charges require no further computation and are printed from write_mo_free_results
947
948 ! Compute the Lowdin charges
949 print_key => section_vals_get_subs_vals(input, "DFT%PRINT%LOWDIN")
950 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
951 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%LOWDIN", extension=".lowdin", &
952 log_filename=.false.)
953 print_level = 1
954 CALL section_vals_val_get(print_key, "PRINT_GOP", l_val=print_it)
955 IF (print_it) print_level = 2
956 CALL section_vals_val_get(print_key, "PRINT_ALL", l_val=print_it)
957 IF (print_it) print_level = 3
958 IF (do_kpoints) THEN
959 cpwarn("Lowdin charges not implemented for k-point calculations!")
960 ELSE
961 CALL lowdin_population_analysis(qs_env, unit_nr, print_level)
962 END IF
963 CALL cp_print_key_finished_output(unit_nr, logger, input, "DFT%PRINT%LOWDIN")
964 END IF
965
966 ! Compute the RESP charges
967 CALL resp_fit(qs_env)
968
969 ! Compute the Density Derived Atomic Point charges with the Bloechl scheme
970 print_key => section_vals_get_subs_vals(input, "PROPERTIES%FIT_CHARGE")
971 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
972 unit_nr = cp_print_key_unit_nr(logger, input, "PROPERTIES%FIT_CHARGE", extension=".Fitcharge", &
973 log_filename=.false.)
974 density_fit_section => section_vals_get_subs_vals(input, "DFT%DENSITY_FITTING")
975 CALL get_ddapc(qs_env, .false., density_fit_section, iwc=unit_nr)
976 CALL cp_print_key_finished_output(unit_nr, logger, input, "PROPERTIES%FIT_CHARGE")
977 END IF
978
979 CALL timestop(handle)
980
981 END SUBROUTINE qs_scf_post_charges
982
983! **************************************************************************************************
984!> \brief Computes and prints the Cube Files for MO
985!> \param input ...
986!> \param dft_section ...
987!> \param dft_control ...
988!> \param logger ...
989!> \param qs_env the qs_env in which the qs_env lives
990!> \param mo_coeff ...
991!> \param wf_g ...
992!> \param wf_r ...
993!> \param particles ...
994!> \param homo ...
995!> \param ispin ...
996! **************************************************************************************************
997 SUBROUTINE qs_scf_post_occ_cubes(input, dft_section, dft_control, logger, qs_env, &
998 mo_coeff, wf_g, wf_r, particles, homo, ispin)
999 TYPE(section_vals_type), POINTER :: input, dft_section
1000 TYPE(dft_control_type), POINTER :: dft_control
1001 TYPE(cp_logger_type), POINTER :: logger
1002 TYPE(qs_environment_type), POINTER :: qs_env
1003 TYPE(cp_fm_type), INTENT(IN) :: mo_coeff
1004 TYPE(pw_c1d_gs_type), INTENT(INOUT) :: wf_g
1005 TYPE(pw_r3d_rs_type), INTENT(INOUT) :: wf_r
1006 TYPE(particle_list_type), POINTER :: particles
1007 INTEGER, INTENT(IN) :: homo, ispin
1008
1009 CHARACTER(len=*), PARAMETER :: routinen = 'qs_scf_post_occ_cubes'
1010
1011 CHARACTER(LEN=default_path_length) :: filename, my_pos_cube, title
1012 INTEGER :: handle, i, ir, ivector, n_rep, nhomo, &
1013 nlist, unit_nr
1014 INTEGER, DIMENSION(:), POINTER :: list, list_index
1015 LOGICAL :: append_cube, mpi_io
1016 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
1017 TYPE(cell_type), POINTER :: cell
1018 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1019 TYPE(pw_env_type), POINTER :: pw_env
1020 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1021
1022 CALL timeset(routinen, handle)
1023
1024 NULLIFY (list_index)
1025
1026 IF (btest(cp_print_key_should_output(logger%iter_info, dft_section, "PRINT%MO_CUBES") &
1027 , cp_p_file) .AND. section_get_lval(dft_section, "PRINT%MO_CUBES%WRITE_CUBE")) THEN
1028 nhomo = section_get_ival(dft_section, "PRINT%MO_CUBES%NHOMO")
1029 append_cube = section_get_lval(dft_section, "PRINT%MO_CUBES%APPEND")
1030 my_pos_cube = "REWIND"
1031 IF (append_cube) THEN
1032 my_pos_cube = "APPEND"
1033 END IF
1034 CALL section_vals_val_get(dft_section, "PRINT%MO_CUBES%HOMO_LIST", n_rep_val=n_rep)
1035 IF (n_rep > 0) THEN ! write the cubes of the list
1036 nlist = 0
1037 DO ir = 1, n_rep
1038 NULLIFY (list)
1039 CALL section_vals_val_get(dft_section, "PRINT%MO_CUBES%HOMO_LIST", i_rep_val=ir, &
1040 i_vals=list)
1041 IF (ASSOCIATED(list)) THEN
1042 CALL reallocate(list_index, 1, nlist + SIZE(list))
1043 DO i = 1, SIZE(list)
1044 list_index(i + nlist) = list(i)
1045 END DO
1046 nlist = nlist + SIZE(list)
1047 END IF
1048 END DO
1049 ELSE
1050
1051 IF (nhomo == -1) nhomo = homo
1052 nlist = homo - max(1, homo - nhomo + 1) + 1
1053 ALLOCATE (list_index(nlist))
1054 DO i = 1, nlist
1055 list_index(i) = max(1, homo - nhomo + 1) + i - 1
1056 END DO
1057 END IF
1058 DO i = 1, nlist
1059 ivector = list_index(i)
1060 CALL get_qs_env(qs_env=qs_env, &
1061 atomic_kind_set=atomic_kind_set, &
1062 qs_kind_set=qs_kind_set, &
1063 cell=cell, &
1064 particle_set=particle_set, &
1065 pw_env=pw_env)
1066 CALL calculate_wavefunction(mo_coeff, ivector, wf_r, wf_g, atomic_kind_set, qs_kind_set, &
1067 cell, dft_control, particle_set, pw_env)
1068 WRITE (filename, '(a4,I5.5,a1,I1.1)') "WFN_", ivector, "_", ispin
1069 mpi_io = .true.
1070 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%MO_CUBES", extension=".cube", &
1071 middle_name=trim(filename), file_position=my_pos_cube, log_filename=.false., &
1072 mpi_io=mpi_io)
1073 WRITE (title, *) "WAVEFUNCTION ", ivector, " spin ", ispin, " i.e. HOMO - ", ivector - homo
1074 CALL cp_pw_to_cube(wf_r, unit_nr, title, particles=particles, &
1075 stride=section_get_ivals(dft_section, "PRINT%MO_CUBES%STRIDE"), mpi_io=mpi_io)
1076 CALL cp_print_key_finished_output(unit_nr, logger, input, "DFT%PRINT%MO_CUBES", mpi_io=mpi_io)
1077 END DO
1078 IF (ASSOCIATED(list_index)) DEALLOCATE (list_index)
1079 END IF
1080
1081 CALL timestop(handle)
1082
1083 END SUBROUTINE qs_scf_post_occ_cubes
1084
1085! **************************************************************************************************
1086!> \brief Computes and prints the Cube Files for MO
1087!> \param input ...
1088!> \param dft_section ...
1089!> \param dft_control ...
1090!> \param logger ...
1091!> \param qs_env the qs_env in which the qs_env lives
1092!> \param unoccupied_orbs ...
1093!> \param wf_g ...
1094!> \param wf_r ...
1095!> \param particles ...
1096!> \param nlumos ...
1097!> \param homo ...
1098!> \param ispin ...
1099!> \param lumo ...
1100! **************************************************************************************************
1101 SUBROUTINE qs_scf_post_unocc_cubes(input, dft_section, dft_control, logger, qs_env, &
1102 unoccupied_orbs, wf_g, wf_r, particles, nlumos, homo, ispin, lumo)
1103
1104 TYPE(section_vals_type), POINTER :: input, dft_section
1105 TYPE(dft_control_type), POINTER :: dft_control
1106 TYPE(cp_logger_type), POINTER :: logger
1107 TYPE(qs_environment_type), POINTER :: qs_env
1108 TYPE(cp_fm_type), INTENT(IN) :: unoccupied_orbs
1109 TYPE(pw_c1d_gs_type), INTENT(INOUT) :: wf_g
1110 TYPE(pw_r3d_rs_type), INTENT(INOUT) :: wf_r
1111 TYPE(particle_list_type), POINTER :: particles
1112 INTEGER, INTENT(IN) :: nlumos, homo, ispin
1113 INTEGER, INTENT(IN), OPTIONAL :: lumo
1114
1115 CHARACTER(len=*), PARAMETER :: routinen = 'qs_scf_post_unocc_cubes'
1116
1117 CHARACTER(LEN=default_path_length) :: filename, my_pos_cube, title
1118 INTEGER :: handle, ifirst, index_mo, ivector, &
1119 unit_nr
1120 LOGICAL :: append_cube, mpi_io
1121 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
1122 TYPE(cell_type), POINTER :: cell
1123 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1124 TYPE(pw_env_type), POINTER :: pw_env
1125 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1126
1127 CALL timeset(routinen, handle)
1128
1129 IF (btest(cp_print_key_should_output(logger%iter_info, dft_section, "PRINT%MO_CUBES"), cp_p_file) &
1130 .AND. section_get_lval(dft_section, "PRINT%MO_CUBES%WRITE_CUBE")) THEN
1131 NULLIFY (qs_kind_set, particle_set, pw_env, cell)
1132 append_cube = section_get_lval(dft_section, "PRINT%MO_CUBES%APPEND")
1133 my_pos_cube = "REWIND"
1134 IF (append_cube) THEN
1135 my_pos_cube = "APPEND"
1136 END IF
1137 ifirst = 1
1138 IF (PRESENT(lumo)) ifirst = lumo
1139 DO ivector = ifirst, ifirst + nlumos - 1
1140 CALL get_qs_env(qs_env=qs_env, &
1141 atomic_kind_set=atomic_kind_set, &
1142 qs_kind_set=qs_kind_set, &
1143 cell=cell, &
1144 particle_set=particle_set, &
1145 pw_env=pw_env)
1146 CALL calculate_wavefunction(unoccupied_orbs, ivector, wf_r, wf_g, atomic_kind_set, &
1147 qs_kind_set, cell, dft_control, particle_set, pw_env)
1148
1149 IF (ifirst == 1) THEN
1150 index_mo = homo + ivector
1151 ELSE
1152 index_mo = ivector
1153 END IF
1154 WRITE (filename, '(a4,I5.5,a1,I1.1)') "WFN_", index_mo, "_", ispin
1155 mpi_io = .true.
1156
1157 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%MO_CUBES", extension=".cube", &
1158 middle_name=trim(filename), file_position=my_pos_cube, log_filename=.false., &
1159 mpi_io=mpi_io)
1160 WRITE (title, *) "WAVEFUNCTION ", index_mo, " spin ", ispin, " i.e. LUMO + ", ifirst + ivector - 2
1161 CALL cp_pw_to_cube(wf_r, unit_nr, title, particles=particles, &
1162 stride=section_get_ivals(dft_section, "PRINT%MO_CUBES%STRIDE"), mpi_io=mpi_io)
1163 CALL cp_print_key_finished_output(unit_nr, logger, input, "DFT%PRINT%MO_CUBES", mpi_io=mpi_io)
1164 END DO
1165 END IF
1166
1167 CALL timestop(handle)
1168
1169 END SUBROUTINE qs_scf_post_unocc_cubes
1170
1171! **************************************************************************************************
1172!> \brief Computes and prints electric moments
1173!> \param input ...
1174!> \param logger ...
1175!> \param qs_env the qs_env in which the qs_env lives
1176!> \param output_unit ...
1177! **************************************************************************************************
1178 SUBROUTINE qs_scf_post_moments(input, logger, qs_env, output_unit)
1179 TYPE(section_vals_type), POINTER :: input
1180 TYPE(cp_logger_type), POINTER :: logger
1181 TYPE(qs_environment_type), POINTER :: qs_env
1182 INTEGER, INTENT(IN) :: output_unit
1183
1184 CHARACTER(len=*), PARAMETER :: routinen = 'qs_scf_post_moments'
1185
1186 CHARACTER(LEN=default_path_length) :: filename
1187 INTEGER :: handle, maxmom, reference, unit_nr
1188 LOGICAL :: com_nl, do_kpoints, magnetic, periodic, &
1189 second_ref_point, vel_reprs
1190 REAL(kind=dp), DIMENSION(:), POINTER :: ref_point
1191 TYPE(section_vals_type), POINTER :: print_key
1192
1193 CALL timeset(routinen, handle)
1194
1195 print_key => section_vals_get_subs_vals(section_vals=input, &
1196 subsection_name="DFT%PRINT%MOMENTS")
1197
1198 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
1199
1200 maxmom = section_get_ival(section_vals=input, &
1201 keyword_name="DFT%PRINT%MOMENTS%MAX_MOMENT")
1202 periodic = section_get_lval(section_vals=input, &
1203 keyword_name="DFT%PRINT%MOMENTS%PERIODIC")
1204 reference = section_get_ival(section_vals=input, &
1205 keyword_name="DFT%PRINT%MOMENTS%REFERENCE")
1206 magnetic = section_get_lval(section_vals=input, &
1207 keyword_name="DFT%PRINT%MOMENTS%MAGNETIC")
1208 vel_reprs = section_get_lval(section_vals=input, &
1209 keyword_name="DFT%PRINT%MOMENTS%VEL_REPRS")
1210 com_nl = section_get_lval(section_vals=input, &
1211 keyword_name="DFT%PRINT%MOMENTS%COM_NL")
1212 second_ref_point = section_get_lval(section_vals=input, &
1213 keyword_name="DFT%PRINT%MOMENTS%SECOND_REFERENCE_POINT")
1214
1215 NULLIFY (ref_point)
1216 CALL section_vals_val_get(input, "DFT%PRINT%MOMENTS%REF_POINT", r_vals=ref_point)
1217 unit_nr = cp_print_key_unit_nr(logger=logger, basis_section=input, &
1218 print_key_path="DFT%PRINT%MOMENTS", extension=".dat", &
1219 middle_name="moments", log_filename=.false.)
1220
1221 IF (output_unit > 0) THEN
1222 IF (unit_nr /= output_unit) THEN
1223 INQUIRE (unit=unit_nr, name=filename)
1224 WRITE (unit=output_unit, fmt="(/,T2,A,2(/,T3,A),/)") &
1225 "MOMENTS", "The electric/magnetic moments are written to file:", &
1226 trim(filename)
1227 ELSE
1228 WRITE (unit=output_unit, fmt="(/,T2,A)") "ELECTRIC/MAGNETIC MOMENTS"
1229 END IF
1230 END IF
1231
1232 CALL get_qs_env(qs_env, do_kpoints=do_kpoints)
1233
1234 IF (do_kpoints) THEN
1235 cpwarn("Moments not implemented for k-point calculations!")
1236 ELSE
1237 IF (periodic) THEN
1238 CALL qs_moment_berry_phase(qs_env, magnetic, maxmom, reference, ref_point, unit_nr)
1239 ELSE
1240 CALL qs_moment_locop(qs_env, magnetic, maxmom, reference, ref_point, unit_nr, vel_reprs, com_nl)
1241 END IF
1242 END IF
1243
1244 CALL cp_print_key_finished_output(unit_nr=unit_nr, logger=logger, &
1245 basis_section=input, print_key_path="DFT%PRINT%MOMENTS")
1246
1247 IF (second_ref_point) THEN
1248 reference = section_get_ival(section_vals=input, &
1249 keyword_name="DFT%PRINT%MOMENTS%REFERENCE_2")
1250
1251 NULLIFY (ref_point)
1252 CALL section_vals_val_get(input, "DFT%PRINT%MOMENTS%REF_POINT_2", r_vals=ref_point)
1253 unit_nr = cp_print_key_unit_nr(logger=logger, basis_section=input, &
1254 print_key_path="DFT%PRINT%MOMENTS", extension=".dat", &
1255 middle_name="moments_refpoint_2", log_filename=.false.)
1256
1257 IF (output_unit > 0) THEN
1258 IF (unit_nr /= output_unit) THEN
1259 INQUIRE (unit=unit_nr, name=filename)
1260 WRITE (unit=output_unit, fmt="(/,T2,A,2(/,T3,A),/)") &
1261 "MOMENTS", "The electric/magnetic moments for the second reference point are written to file:", &
1262 trim(filename)
1263 ELSE
1264 WRITE (unit=output_unit, fmt="(/,T2,A)") "ELECTRIC/MAGNETIC MOMENTS"
1265 END IF
1266 END IF
1267 IF (do_kpoints) THEN
1268 cpwarn("Moments not implemented for k-point calculations!")
1269 ELSE
1270 IF (periodic) THEN
1271 CALL qs_moment_berry_phase(qs_env, magnetic, maxmom, reference, ref_point, unit_nr)
1272 ELSE
1273 CALL qs_moment_locop(qs_env, magnetic, maxmom, reference, ref_point, unit_nr, vel_reprs, com_nl)
1274 END IF
1275 END IF
1276 CALL cp_print_key_finished_output(unit_nr=unit_nr, logger=logger, &
1277 basis_section=input, print_key_path="DFT%PRINT%MOMENTS")
1278 END IF
1279
1280 END IF
1281
1282 CALL timestop(handle)
1283
1284 END SUBROUTINE qs_scf_post_moments
1285
1286! **************************************************************************************************
1287!> \brief Computes and prints the X-ray diffraction spectrum.
1288!> \param input ...
1289!> \param dft_section ...
1290!> \param logger ...
1291!> \param qs_env the qs_env in which the qs_env lives
1292!> \param output_unit ...
1293! **************************************************************************************************
1294 SUBROUTINE qs_scf_post_xray(input, dft_section, logger, qs_env, output_unit)
1295
1296 TYPE(section_vals_type), POINTER :: input, dft_section
1297 TYPE(cp_logger_type), POINTER :: logger
1298 TYPE(qs_environment_type), POINTER :: qs_env
1299 INTEGER, INTENT(IN) :: output_unit
1300
1301 CHARACTER(LEN=*), PARAMETER :: routinen = 'qs_scf_post_xray'
1302
1303 CHARACTER(LEN=default_path_length) :: filename
1304 INTEGER :: handle, unit_nr
1305 REAL(kind=dp) :: q_max
1306 TYPE(section_vals_type), POINTER :: print_key
1307
1308 CALL timeset(routinen, handle)
1309
1310 print_key => section_vals_get_subs_vals(section_vals=input, &
1311 subsection_name="DFT%PRINT%XRAY_DIFFRACTION_SPECTRUM")
1312
1313 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
1314 q_max = section_get_rval(section_vals=dft_section, &
1315 keyword_name="PRINT%XRAY_DIFFRACTION_SPECTRUM%Q_MAX")
1316 unit_nr = cp_print_key_unit_nr(logger=logger, &
1317 basis_section=input, &
1318 print_key_path="DFT%PRINT%XRAY_DIFFRACTION_SPECTRUM", &
1319 extension=".dat", &
1320 middle_name="xrd", &
1321 log_filename=.false.)
1322 IF (output_unit > 0) THEN
1323 INQUIRE (unit=unit_nr, name=filename)
1324 WRITE (unit=output_unit, fmt="(/,/,T2,A)") &
1325 "X-RAY DIFFRACTION SPECTRUM"
1326 IF (unit_nr /= output_unit) THEN
1327 WRITE (unit=output_unit, fmt="(/,T3,A,/,/,T3,A,/)") &
1328 "The coherent X-ray diffraction spectrum is written to the file:", &
1329 trim(filename)
1330 END IF
1331 END IF
1332 CALL xray_diffraction_spectrum(qs_env=qs_env, &
1333 unit_number=unit_nr, &
1334 q_max=q_max)
1335 CALL cp_print_key_finished_output(unit_nr=unit_nr, &
1336 logger=logger, &
1337 basis_section=input, &
1338 print_key_path="DFT%PRINT%XRAY_DIFFRACTION_SPECTRUM")
1339 END IF
1340
1341 CALL timestop(handle)
1342
1343 END SUBROUTINE qs_scf_post_xray
1344
1345! **************************************************************************************************
1346!> \brief Computes and prints Electric Field Gradient
1347!> \param input ...
1348!> \param logger ...
1349!> \param qs_env the qs_env in which the qs_env lives
1350! **************************************************************************************************
1351 SUBROUTINE qs_scf_post_efg(input, logger, qs_env)
1352 TYPE(section_vals_type), POINTER :: input
1353 TYPE(cp_logger_type), POINTER :: logger
1354 TYPE(qs_environment_type), POINTER :: qs_env
1355
1356 CHARACTER(len=*), PARAMETER :: routinen = 'qs_scf_post_efg'
1357
1358 INTEGER :: handle
1359 TYPE(section_vals_type), POINTER :: print_key
1360
1361 CALL timeset(routinen, handle)
1362
1363 print_key => section_vals_get_subs_vals(section_vals=input, &
1364 subsection_name="DFT%PRINT%ELECTRIC_FIELD_GRADIENT")
1365 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), &
1366 cp_p_file)) THEN
1367 CALL qs_efg_calc(qs_env=qs_env)
1368 END IF
1369
1370 CALL timestop(handle)
1371
1372 END SUBROUTINE qs_scf_post_efg
1373
1374! **************************************************************************************************
1375!> \brief Computes the Electron Transfer Coupling matrix element
1376!> \param input ...
1377!> \param qs_env the qs_env in which the qs_env lives
1378!> \param dft_control ...
1379! **************************************************************************************************
1380 SUBROUTINE qs_scf_post_et(input, qs_env, dft_control)
1381 TYPE(section_vals_type), POINTER :: input
1382 TYPE(qs_environment_type), POINTER :: qs_env
1383 TYPE(dft_control_type), POINTER :: dft_control
1384
1385 CHARACTER(len=*), PARAMETER :: routinen = 'qs_scf_post_et'
1386
1387 INTEGER :: handle, ispin
1388 LOGICAL :: do_et
1389 TYPE(cp_fm_type), DIMENSION(:), POINTER :: my_mos
1390 TYPE(section_vals_type), POINTER :: et_section
1391
1392 CALL timeset(routinen, handle)
1393
1394 do_et = .false.
1395 et_section => section_vals_get_subs_vals(input, "PROPERTIES%ET_COUPLING")
1396 CALL section_vals_get(et_section, explicit=do_et)
1397 IF (do_et) THEN
1398 IF (qs_env%et_coupling%first_run) THEN
1399 NULLIFY (my_mos)
1400 ALLOCATE (my_mos(dft_control%nspins))
1401 ALLOCATE (qs_env%et_coupling%et_mo_coeff(dft_control%nspins))
1402 DO ispin = 1, dft_control%nspins
1403 CALL cp_fm_create(matrix=my_mos(ispin), &
1404 matrix_struct=qs_env%mos(ispin)%mo_coeff%matrix_struct, &
1405 name="FIRST_RUN_COEFF"//trim(adjustl(cp_to_string(ispin)))//"MATRIX")
1406 CALL cp_fm_to_fm(qs_env%mos(ispin)%mo_coeff, &
1407 my_mos(ispin))
1408 END DO
1409 CALL set_et_coupling_type(qs_env%et_coupling, et_mo_coeff=my_mos)
1410 DEALLOCATE (my_mos)
1411 END IF
1412 END IF
1413
1414 CALL timestop(handle)
1415
1416 END SUBROUTINE qs_scf_post_et
1417
1418! **************************************************************************************************
1419!> \brief compute the electron localization function
1420!>
1421!> \param input ...
1422!> \param logger ...
1423!> \param qs_env ...
1424!> \par History
1425!> 2012-07 Created [MI]
1426! **************************************************************************************************
1427 SUBROUTINE qs_scf_post_elf(input, logger, qs_env)
1428 TYPE(section_vals_type), POINTER :: input
1429 TYPE(cp_logger_type), POINTER :: logger
1430 TYPE(qs_environment_type), POINTER :: qs_env
1431
1432 CHARACTER(len=*), PARAMETER :: routinen = 'qs_scf_post_elf'
1433
1434 CHARACTER(LEN=default_path_length) :: filename, mpi_filename, my_pos_cube, &
1435 title
1436 INTEGER :: handle, ispin, output_unit, unit_nr
1437 LOGICAL :: append_cube, gapw, mpi_io
1438 REAL(dp) :: rho_cutoff
1439 TYPE(dft_control_type), POINTER :: dft_control
1440 TYPE(particle_list_type), POINTER :: particles
1441 TYPE(pw_env_type), POINTER :: pw_env
1442 TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
1443 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
1444 TYPE(pw_r3d_rs_type), ALLOCATABLE, DIMENSION(:) :: elf_r
1445 TYPE(qs_subsys_type), POINTER :: subsys
1446 TYPE(section_vals_type), POINTER :: elf_section
1447
1448 CALL timeset(routinen, handle)
1449 output_unit = cp_logger_get_default_io_unit(logger)
1450
1451 elf_section => section_vals_get_subs_vals(input, "DFT%PRINT%ELF_CUBE")
1452 IF (btest(cp_print_key_should_output(logger%iter_info, input, &
1453 "DFT%PRINT%ELF_CUBE"), cp_p_file)) THEN
1454
1455 NULLIFY (dft_control, pw_env, auxbas_pw_pool, pw_pools, particles, subsys)
1456 CALL get_qs_env(qs_env, dft_control=dft_control, pw_env=pw_env, subsys=subsys)
1457 CALL qs_subsys_get(subsys, particles=particles)
1458
1459 gapw = dft_control%qs_control%gapw
1460 IF (.NOT. gapw) THEN
1461 ! allocate
1462 ALLOCATE (elf_r(dft_control%nspins))
1463 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
1464 pw_pools=pw_pools)
1465 DO ispin = 1, dft_control%nspins
1466 CALL auxbas_pw_pool%create_pw(elf_r(ispin))
1467 CALL pw_zero(elf_r(ispin))
1468 END DO
1469
1470 IF (output_unit > 0) THEN
1471 WRITE (unit=output_unit, fmt="(/,T15,A,/)") &
1472 " ----- ELF is computed on the real space grid -----"
1473 END IF
1474 rho_cutoff = section_get_rval(elf_section, "density_cutoff")
1475 CALL qs_elf_calc(qs_env, elf_r, rho_cutoff)
1476
1477 ! write ELF into cube file
1478 append_cube = section_get_lval(elf_section, "APPEND")
1479 my_pos_cube = "REWIND"
1480 IF (append_cube) THEN
1481 my_pos_cube = "APPEND"
1482 END IF
1483
1484 DO ispin = 1, dft_control%nspins
1485 WRITE (filename, '(a5,I1.1)') "ELF_S", ispin
1486 WRITE (title, *) "ELF spin ", ispin
1487 mpi_io = .true.
1488 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%ELF_CUBE", extension=".cube", &
1489 middle_name=trim(filename), file_position=my_pos_cube, log_filename=.false., &
1490 mpi_io=mpi_io, fout=mpi_filename)
1491 IF (output_unit > 0) THEN
1492 IF (.NOT. mpi_io) THEN
1493 INQUIRE (unit=unit_nr, name=filename)
1494 ELSE
1495 filename = mpi_filename
1496 END IF
1497 WRITE (unit=output_unit, fmt="(/,T2,A,/,/,T2,A)") &
1498 "ELF is written in cube file format to the file:", &
1499 trim(filename)
1500 END IF
1501
1502 CALL cp_pw_to_cube(elf_r(ispin), unit_nr, title, particles=particles, &
1503 stride=section_get_ivals(elf_section, "STRIDE"), mpi_io=mpi_io)
1504 CALL cp_print_key_finished_output(unit_nr, logger, input, "DFT%PRINT%ELF_CUBE", mpi_io=mpi_io)
1505
1506 CALL auxbas_pw_pool%give_back_pw(elf_r(ispin))
1507 END DO
1508
1509 ! deallocate
1510 DEALLOCATE (elf_r)
1511
1512 ELSE
1513 ! not implemented
1514 cpwarn("ELF not implemented for GAPW calculations!")
1515 END IF
1516
1517 END IF ! print key
1518
1519 CALL timestop(handle)
1520
1521 END SUBROUTINE qs_scf_post_elf
1522
1523! **************************************************************************************************
1524!> \brief computes the condition number of the overlap matrix and
1525!> prints the value of the total energy. This is needed
1526!> for BASIS_MOLOPT optimizations
1527!> \param input ...
1528!> \param logger ...
1529!> \param qs_env the qs_env in which the qs_env lives
1530!> \par History
1531!> 2007-07 Created [Joost VandeVondele]
1532! **************************************************************************************************
1533 SUBROUTINE qs_scf_post_molopt(input, logger, qs_env)
1534 TYPE(section_vals_type), POINTER :: input
1535 TYPE(cp_logger_type), POINTER :: logger
1536 TYPE(qs_environment_type), POINTER :: qs_env
1537
1538 CHARACTER(len=*), PARAMETER :: routinen = 'qs_scf_post_molopt'
1539
1540 INTEGER :: handle, nao, unit_nr
1541 REAL(kind=dp) :: s_cond_number
1542 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: eigenvalues
1543 TYPE(cp_fm_struct_type), POINTER :: ao_ao_fmstruct
1544 TYPE(cp_fm_type) :: fm_s, fm_work
1545 TYPE(cp_fm_type), POINTER :: mo_coeff
1546 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
1547 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
1548 TYPE(qs_energy_type), POINTER :: energy
1549 TYPE(section_vals_type), POINTER :: print_key
1550
1551 CALL timeset(routinen, handle)
1552
1553 print_key => section_vals_get_subs_vals(section_vals=input, &
1554 subsection_name="DFT%PRINT%BASIS_MOLOPT_QUANTITIES")
1555 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), &
1556 cp_p_file)) THEN
1557
1558 CALL get_qs_env(qs_env, energy=energy, matrix_s=matrix_s, mos=mos)
1559
1560 ! set up the two needed full matrices, using mo_coeff as a template
1561 CALL get_mo_set(mo_set=mos(1), mo_coeff=mo_coeff, nao=nao)
1562 CALL cp_fm_struct_create(fmstruct=ao_ao_fmstruct, &
1563 nrow_global=nao, ncol_global=nao, &
1564 template_fmstruct=mo_coeff%matrix_struct)
1565 CALL cp_fm_create(fm_s, matrix_struct=ao_ao_fmstruct, &
1566 name="fm_s")
1567 CALL cp_fm_create(fm_work, matrix_struct=ao_ao_fmstruct, &
1568 name="fm_work")
1569 CALL cp_fm_struct_release(ao_ao_fmstruct)
1570 ALLOCATE (eigenvalues(nao))
1571
1572 CALL copy_dbcsr_to_fm(matrix_s(1)%matrix, fm_s)
1573 CALL choose_eigv_solver(fm_s, fm_work, eigenvalues)
1574
1575 CALL cp_fm_release(fm_s)
1576 CALL cp_fm_release(fm_work)
1577
1578 s_cond_number = maxval(abs(eigenvalues))/max(minval(abs(eigenvalues)), epsilon(0.0_dp))
1579
1580 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%BASIS_MOLOPT_QUANTITIES", &
1581 extension=".molopt")
1582
1583 IF (unit_nr > 0) THEN
1584 ! please keep this format fixed, needs to be grepable for molopt
1585 ! optimizations
1586 WRITE (unit_nr, '(T2,A28,2A25)') "", "Tot. Ener.", "S Cond. Numb."
1587 WRITE (unit_nr, '(T2,A28,2E25.17)') "BASIS_MOLOPT_QUANTITIES", energy%total, s_cond_number
1588 END IF
1589
1590 CALL cp_print_key_finished_output(unit_nr, logger, input, &
1591 "DFT%PRINT%BASIS_MOLOPT_QUANTITIES")
1592
1593 END IF
1594
1595 CALL timestop(handle)
1596
1597 END SUBROUTINE qs_scf_post_molopt
1598
1599! **************************************************************************************************
1600!> \brief Dumps EPR
1601!> \param input ...
1602!> \param logger ...
1603!> \param qs_env the qs_env in which the qs_env lives
1604! **************************************************************************************************
1605 SUBROUTINE qs_scf_post_epr(input, logger, qs_env)
1606 TYPE(section_vals_type), POINTER :: input
1607 TYPE(cp_logger_type), POINTER :: logger
1608 TYPE(qs_environment_type), POINTER :: qs_env
1609
1610 CHARACTER(len=*), PARAMETER :: routinen = 'qs_scf_post_epr'
1611
1612 INTEGER :: handle
1613 TYPE(section_vals_type), POINTER :: print_key
1614
1615 CALL timeset(routinen, handle)
1616
1617 print_key => section_vals_get_subs_vals(section_vals=input, &
1618 subsection_name="DFT%PRINT%HYPERFINE_COUPLING_TENSOR")
1619 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), &
1620 cp_p_file)) THEN
1621 CALL qs_epr_hyp_calc(qs_env=qs_env)
1622 END IF
1623
1624 CALL timestop(handle)
1625
1626 END SUBROUTINE qs_scf_post_epr
1627
1628! **************************************************************************************************
1629!> \brief Interface routine to trigger writing of results available from normal
1630!> SCF. Can write MO-dependent and MO free results (needed for call from
1631!> the linear scaling code)
1632!> \param qs_env the qs_env in which the qs_env lives
1633!> \param scf_env ...
1634! **************************************************************************************************
1635 SUBROUTINE write_available_results(qs_env, scf_env)
1636 TYPE(qs_environment_type), POINTER :: qs_env
1637 TYPE(qs_scf_env_type), OPTIONAL, POINTER :: scf_env
1638
1639 CHARACTER(len=*), PARAMETER :: routinen = 'write_available_results'
1640
1641 INTEGER :: handle
1642
1643 CALL timeset(routinen, handle)
1644
1645 ! those properties that require MOs (not suitable density matrix based methods)
1646 CALL write_mo_dependent_results(qs_env, scf_env)
1647
1648 ! those that depend only on the density matrix, they should be linear scaling in their implementation
1649 CALL write_mo_free_results(qs_env)
1650
1651 CALL timestop(handle)
1652
1653 END SUBROUTINE write_available_results
1654
1655! **************************************************************************************************
1656!> \brief Write QS results available if MO's are present (if switched on through the print_keys)
1657!> Writes only MO dependent results. Split is necessary as ls_scf does not
1658!> provide MO's
1659!> \param qs_env the qs_env in which the qs_env lives
1660!> \param scf_env ...
1661! **************************************************************************************************
1662 SUBROUTINE write_mo_dependent_results(qs_env, scf_env)
1663 TYPE(qs_environment_type), POINTER :: qs_env
1664 TYPE(qs_scf_env_type), OPTIONAL, POINTER :: scf_env
1665
1666 CHARACTER(len=*), PARAMETER :: routinen = 'write_mo_dependent_results'
1667
1668 INTEGER :: handle, homo, ispin, nmo, output_unit
1669 LOGICAL :: all_equal, do_kpoints, explicit
1670 REAL(kind=dp) :: maxocc, s_square, s_square_ideal, &
1671 total_abs_spin_dens, total_spin_dens
1672 REAL(kind=dp), DIMENSION(:), POINTER :: mo_eigenvalues, occupation_numbers
1673 TYPE(admm_type), POINTER :: admm_env
1674 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
1675 TYPE(cell_type), POINTER :: cell
1676 TYPE(cp_fm_type), POINTER :: mo_coeff
1677 TYPE(cp_logger_type), POINTER :: logger
1678 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: ks_rmpv, matrix_s
1679 TYPE(dbcsr_type), POINTER :: mo_coeff_deriv
1680 TYPE(dft_control_type), POINTER :: dft_control
1681 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
1682 TYPE(molecule_type), POINTER :: molecule_set(:)
1683 TYPE(particle_list_type), POINTER :: particles
1684 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1685 TYPE(pw_env_type), POINTER :: pw_env
1686 TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
1687 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
1688 TYPE(pw_r3d_rs_type) :: wf_r
1689 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r
1690 TYPE(qs_energy_type), POINTER :: energy
1691 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1692 TYPE(qs_rho_type), POINTER :: rho
1693 TYPE(qs_subsys_type), POINTER :: subsys
1694 TYPE(scf_control_type), POINTER :: scf_control
1695 TYPE(section_vals_type), POINTER :: dft_section, input, sprint_section, &
1696 trexio_section
1697
1698! TYPE(kpoint_type), POINTER :: kpoints
1699
1700 CALL timeset(routinen, handle)
1701
1702 NULLIFY (cell, dft_control, pw_env, auxbas_pw_pool, pw_pools, mo_coeff, &
1703 mo_coeff_deriv, mo_eigenvalues, mos, atomic_kind_set, qs_kind_set, &
1704 particle_set, rho, ks_rmpv, matrix_s, scf_control, dft_section, &
1705 molecule_set, input, particles, subsys, rho_r)
1706
1707 logger => cp_get_default_logger()
1708 output_unit = cp_logger_get_default_io_unit(logger)
1709
1710 cpassert(ASSOCIATED(qs_env))
1711 CALL get_qs_env(qs_env, &
1712 dft_control=dft_control, &
1713 molecule_set=molecule_set, &
1714 atomic_kind_set=atomic_kind_set, &
1715 particle_set=particle_set, &
1716 qs_kind_set=qs_kind_set, &
1717 admm_env=admm_env, &
1718 scf_control=scf_control, &
1719 input=input, &
1720 cell=cell, &
1721 subsys=subsys)
1722 CALL qs_subsys_get(subsys, particles=particles)
1723 CALL get_qs_env(qs_env, rho=rho)
1724 CALL qs_rho_get(rho, rho_r=rho_r)
1725
1726 ! k points
1727 CALL get_qs_env(qs_env, do_kpoints=do_kpoints)
1728
1729 ! Write last MO information to output file if requested
1730 dft_section => section_vals_get_subs_vals(input, "DFT")
1731 IF (.NOT. qs_env%run_rtp) THEN
1732 CALL qs_scf_write_mos(qs_env, scf_env, final_mos=.true.)
1733 trexio_section => section_vals_get_subs_vals(dft_section, "PRINT%TREXIO")
1734 CALL section_vals_get(trexio_section, explicit=explicit)
1735 IF (explicit) THEN
1736 CALL write_trexio(qs_env, trexio_section)
1737 END IF
1738 IF (.NOT. do_kpoints) THEN
1739 CALL get_qs_env(qs_env, mos=mos, matrix_ks=ks_rmpv)
1740 CALL write_dm_binary_restart(mos, dft_section, ks_rmpv)
1741 sprint_section => section_vals_get_subs_vals(dft_section, "PRINT%MO_MOLDEN")
1742 CALL write_mos_molden(mos, qs_kind_set, particle_set, sprint_section)
1743 ! Write Chargemol .wfx
1744 IF (btest(cp_print_key_should_output(logger%iter_info, &
1745 dft_section, "PRINT%CHARGEMOL"), &
1746 cp_p_file)) THEN
1747 CALL write_wfx(qs_env, dft_section)
1748 END IF
1749 END IF
1750
1751 ! DOS printout after the SCF cycle is completed
1752 IF (btest(cp_print_key_should_output(logger%iter_info, dft_section, "PRINT%DOS") &
1753 , cp_p_file)) THEN
1754 IF (do_kpoints) THEN
1755 CALL calculate_dos_kp(qs_env, dft_section)
1756 ELSE
1757 CALL get_qs_env(qs_env, mos=mos)
1758 CALL calculate_dos(mos, dft_section)
1759 END IF
1760 END IF
1761
1762 ! Print the projected density of states (pDOS) for each atomic kind
1763 IF (btest(cp_print_key_should_output(logger%iter_info, dft_section, "PRINT%PDOS"), &
1764 cp_p_file)) THEN
1765 IF (do_kpoints) THEN
1766 cpwarn("Projected density of states (pDOS) is not implemented for k points")
1767 ELSE
1768 CALL get_qs_env(qs_env, &
1769 mos=mos, &
1770 matrix_ks=ks_rmpv)
1771 DO ispin = 1, dft_control%nspins
1772 ! With ADMM, we have to modify the Kohn-Sham matrix
1773 IF (dft_control%do_admm) THEN
1774 CALL admm_correct_for_eigenvalues(ispin, admm_env, ks_rmpv(ispin)%matrix)
1775 END IF
1776 IF (PRESENT(scf_env)) THEN
1777 IF (scf_env%method == ot_method_nr) THEN
1778 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, &
1779 eigenvalues=mo_eigenvalues)
1780 IF (ASSOCIATED(qs_env%mo_derivs)) THEN
1781 mo_coeff_deriv => qs_env%mo_derivs(ispin)%matrix
1782 ELSE
1783 mo_coeff_deriv => null()
1784 END IF
1785 CALL calculate_subspace_eigenvalues(mo_coeff, ks_rmpv(ispin)%matrix, mo_eigenvalues, &
1786 do_rotation=.true., &
1787 co_rotate_dbcsr=mo_coeff_deriv)
1788 CALL set_mo_occupation(mo_set=mos(ispin))
1789 END IF
1790 END IF
1791 IF (dft_control%nspins == 2) THEN
1792 CALL calculate_projected_dos(mos(ispin), atomic_kind_set, &
1793 qs_kind_set, particle_set, qs_env, dft_section, ispin=ispin)
1794 ELSE
1795 CALL calculate_projected_dos(mos(ispin), atomic_kind_set, &
1796 qs_kind_set, particle_set, qs_env, dft_section)
1797 END IF
1798 ! With ADMM, we have to undo the modification of the Kohn-Sham matrix
1799 IF (dft_control%do_admm) THEN
1800 CALL admm_uncorrect_for_eigenvalues(ispin, admm_env, ks_rmpv(ispin)%matrix)
1801 END IF
1802 END DO
1803 END IF
1804 END IF
1805 END IF
1806
1807 ! Integrated absolute spin density and spin contamination ***
1808 IF (dft_control%nspins == 2) THEN
1809 CALL get_qs_env(qs_env, mos=mos)
1810 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
1811 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
1812 pw_pools=pw_pools)
1813 CALL auxbas_pw_pool%create_pw(wf_r)
1814 CALL pw_copy(rho_r(1), wf_r)
1815 CALL pw_axpy(rho_r(2), wf_r, alpha=-1._dp)
1816 total_spin_dens = pw_integrate_function(wf_r)
1817 IF (output_unit > 0) WRITE (unit=output_unit, fmt='(/,(T3,A,T61,F20.10))') &
1818 "Integrated spin density: ", total_spin_dens
1819 total_abs_spin_dens = pw_integrate_function(wf_r, oprt="ABS")
1820 IF (output_unit > 0) WRITE (unit=output_unit, fmt='((T3,A,T61,F20.10))') &
1821 "Integrated absolute spin density: ", total_abs_spin_dens
1822 CALL auxbas_pw_pool%give_back_pw(wf_r)
1823 !
1824 ! XXX Fix Me XXX
1825 ! should be extended to the case where added MOs are present
1826 ! should be extended to the k-point case
1827 !
1828 IF (do_kpoints) THEN
1829 cpwarn("Spin contamination estimate not implemented for k-points.")
1830 ELSE
1831 all_equal = .true.
1832 DO ispin = 1, dft_control%nspins
1833 CALL get_mo_set(mo_set=mos(ispin), &
1834 occupation_numbers=occupation_numbers, &
1835 homo=homo, &
1836 nmo=nmo, &
1837 maxocc=maxocc)
1838 IF (nmo > 0) THEN
1839 all_equal = all_equal .AND. &
1840 (all(occupation_numbers(1:homo) == maxocc) .AND. &
1841 all(occupation_numbers(homo + 1:nmo) == 0.0_dp))
1842 END IF
1843 END DO
1844 IF (.NOT. all_equal) THEN
1845 IF (output_unit > 0) WRITE (unit=output_unit, fmt="(T3,A)") &
1846 "WARNING: S**2 computation does not yet treat fractional occupied orbitals"
1847 ELSE
1848 CALL get_qs_env(qs_env=qs_env, &
1849 matrix_s=matrix_s, &
1850 energy=energy)
1851 CALL compute_s_square(mos=mos, matrix_s=matrix_s, s_square=s_square, &
1852 s_square_ideal=s_square_ideal)
1853 IF (output_unit > 0) WRITE (unit=output_unit, fmt='(T3,A,T51,2F15.6)') &
1854 "Ideal and single determinant S**2 : ", s_square_ideal, s_square
1855 energy%s_square = s_square
1856 END IF
1857 END IF
1858 END IF
1859
1860 CALL timestop(handle)
1861
1862 END SUBROUTINE write_mo_dependent_results
1863
1864! **************************************************************************************************
1865!> \brief Write QS results always available (if switched on through the print_keys)
1866!> Can be called from ls_scf
1867!> \param qs_env the qs_env in which the qs_env lives
1868! **************************************************************************************************
1869 SUBROUTINE write_mo_free_results(qs_env)
1870 TYPE(qs_environment_type), POINTER :: qs_env
1871
1872 CHARACTER(len=*), PARAMETER :: routinen = 'write_mo_free_results'
1873 CHARACTER(len=1), DIMENSION(3), PARAMETER :: cdir = (/"x", "y", "z"/)
1874
1875 CHARACTER(LEN=2) :: element_symbol
1876 CHARACTER(LEN=default_path_length) :: filename, mpi_filename, my_pos_cube, &
1877 my_pos_voro
1878 CHARACTER(LEN=default_string_length) :: name, print_density
1879 INTEGER :: after, handle, i, iat, id, ikind, img, iso, ispin, iw, l, n_rep_hf, natom, nd(3), &
1880 ngto, niso, nkind, np, nr, output_unit, print_level, should_print_bqb, should_print_voro, &
1881 unit_nr, unit_nr_voro
1882 LOGICAL :: append_cube, append_voro, do_hfx, do_kpoints, mpi_io, omit_headers, print_it, &
1883 rho_r_valid, voro_print_txt, write_ks, write_xc, xrd_interface
1884 REAL(kind=dp) :: norm_factor, q_max, rho_hard, rho_soft, &
1885 rho_total, rho_total_rspace, udvol, &
1886 volume
1887 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: bfun
1888 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: aedens, ccdens, ppdens
1889 REAL(kind=dp), DIMENSION(3) :: dr
1890 REAL(kind=dp), DIMENSION(:), POINTER :: my_q0
1891 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
1892 TYPE(atomic_kind_type), POINTER :: atomic_kind
1893 TYPE(cell_type), POINTER :: cell
1894 TYPE(cp_logger_type), POINTER :: logger
1895 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_hr
1896 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: ks_rmpv, matrix_vxc, rho_ao
1897 TYPE(dft_control_type), POINTER :: dft_control
1898 TYPE(grid_atom_type), POINTER :: grid_atom
1899 TYPE(iao_env_type) :: iao_env
1900 TYPE(mp_para_env_type), POINTER :: para_env
1901 TYPE(particle_list_type), POINTER :: particles
1902 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1903 TYPE(pw_c1d_gs_type) :: aux_g, rho_elec_gspace
1904 TYPE(pw_c1d_gs_type), POINTER :: rho0_s_gs, rho_core
1905 TYPE(pw_env_type), POINTER :: pw_env
1906 TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
1907 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
1908 TYPE(pw_r3d_rs_type) :: aux_r, rho_elec_rspace, wf_r
1909 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r
1910 TYPE(pw_r3d_rs_type), POINTER :: mb_rho, v_hartree_rspace, vee
1911 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1912 TYPE(qs_kind_type), POINTER :: qs_kind
1913 TYPE(qs_rho_type), POINTER :: rho
1914 TYPE(qs_subsys_type), POINTER :: subsys
1915 TYPE(rho0_mpole_type), POINTER :: rho0_mpole
1916 TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho_atom_set
1917 TYPE(rho_atom_type), POINTER :: rho_atom
1918 TYPE(section_vals_type), POINTER :: dft_section, hfx_section, input, &
1919 print_key, print_key_bqb, &
1920 print_key_voro, xc_section
1921
1922 CALL timeset(routinen, handle)
1923 NULLIFY (cell, dft_control, pw_env, auxbas_pw_pool, pw_pools, hfx_section, &
1924 atomic_kind_set, qs_kind_set, particle_set, rho, ks_rmpv, rho_ao, rho_r, &
1925 dft_section, xc_section, input, particles, subsys, matrix_vxc, v_hartree_rspace, &
1926 vee)
1927
1928 logger => cp_get_default_logger()
1929 output_unit = cp_logger_get_default_io_unit(logger)
1930
1931 cpassert(ASSOCIATED(qs_env))
1932 CALL get_qs_env(qs_env, &
1933 atomic_kind_set=atomic_kind_set, &
1934 qs_kind_set=qs_kind_set, &
1935 particle_set=particle_set, &
1936 cell=cell, &
1937 para_env=para_env, &
1938 dft_control=dft_control, &
1939 input=input, &
1940 do_kpoints=do_kpoints, &
1941 subsys=subsys)
1942 dft_section => section_vals_get_subs_vals(input, "DFT")
1943 CALL qs_subsys_get(subsys, particles=particles)
1944
1945 CALL get_qs_env(qs_env, rho=rho)
1946 CALL qs_rho_get(rho, rho_r=rho_r)
1947
1948 ! Print the total density (electronic + core charge)
1949 IF (btest(cp_print_key_should_output(logger%iter_info, input, &
1950 "DFT%PRINT%TOT_DENSITY_CUBE"), cp_p_file)) THEN
1951 NULLIFY (rho_core, rho0_s_gs)
1952 append_cube = section_get_lval(input, "DFT%PRINT%TOT_DENSITY_CUBE%APPEND")
1953 my_pos_cube = "REWIND"
1954 IF (append_cube) THEN
1955 my_pos_cube = "APPEND"
1956 END IF
1957
1958 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env, rho_core=rho_core, &
1959 rho0_s_gs=rho0_s_gs)
1960 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
1961 pw_pools=pw_pools)
1962 CALL auxbas_pw_pool%create_pw(wf_r)
1963 IF (dft_control%qs_control%gapw) THEN
1964 IF (dft_control%qs_control%gapw_control%nopaw_as_gpw) THEN
1965 CALL pw_axpy(rho_core, rho0_s_gs)
1966 CALL pw_transfer(rho0_s_gs, wf_r)
1967 CALL pw_axpy(rho_core, rho0_s_gs, -1.0_dp)
1968 ELSE
1969 CALL pw_transfer(rho0_s_gs, wf_r)
1970 END IF
1971 ELSE
1972 CALL pw_transfer(rho_core, wf_r)
1973 END IF
1974 DO ispin = 1, dft_control%nspins
1975 CALL pw_axpy(rho_r(ispin), wf_r)
1976 END DO
1977 filename = "TOTAL_DENSITY"
1978 mpi_io = .true.
1979 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%TOT_DENSITY_CUBE", &
1980 extension=".cube", middle_name=trim(filename), file_position=my_pos_cube, &
1981 log_filename=.false., mpi_io=mpi_io)
1982 CALL cp_pw_to_cube(wf_r, unit_nr, "TOTAL DENSITY", &
1983 particles=particles, &
1984 stride=section_get_ivals(dft_section, "PRINT%TOT_DENSITY_CUBE%STRIDE"), mpi_io=mpi_io)
1985 CALL cp_print_key_finished_output(unit_nr, logger, input, &
1986 "DFT%PRINT%TOT_DENSITY_CUBE", mpi_io=mpi_io)
1987 CALL auxbas_pw_pool%give_back_pw(wf_r)
1988 END IF
1989
1990 ! Write cube file with electron density
1991 IF (btest(cp_print_key_should_output(logger%iter_info, input, &
1992 "DFT%PRINT%E_DENSITY_CUBE"), cp_p_file)) THEN
1993 CALL section_vals_val_get(dft_section, &
1994 keyword_name="PRINT%E_DENSITY_CUBE%DENSITY_INCLUDE", &
1995 c_val=print_density)
1996 print_density = trim(print_density)
1997 append_cube = section_get_lval(input, "DFT%PRINT%E_DENSITY_CUBE%APPEND")
1998 my_pos_cube = "REWIND"
1999 IF (append_cube) THEN
2000 my_pos_cube = "APPEND"
2001 END IF
2002 ! Write the info on core densities for the interface between cp2k and the XRD code
2003 ! together with the valence density they are used to compute the form factor (Fourier transform)
2004 xrd_interface = section_get_lval(input, "DFT%PRINT%E_DENSITY_CUBE%XRD_INTERFACE")
2005 IF (xrd_interface) THEN
2006 !cube file only contains soft density (GAPW)
2007 IF (dft_control%qs_control%gapw) print_density = "SOFT_DENSITY"
2008
2009 filename = "ELECTRON_DENSITY"
2010 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%E_DENSITY_CUBE", &
2011 extension=".xrd", middle_name=trim(filename), &
2012 file_position=my_pos_cube, log_filename=.false.)
2013 ngto = section_get_ival(input, "DFT%PRINT%E_DENSITY_CUBE%NGAUSS")
2014 IF (output_unit > 0) THEN
2015 INQUIRE (unit=unit_nr, name=filename)
2016 WRITE (unit=output_unit, fmt="(/,T2,A,/,/,T2,A)") &
2017 "The electron density (atomic part) is written to the file:", &
2018 trim(filename)
2019 END IF
2020
2021 xc_section => section_vals_get_subs_vals(input, "DFT%XC")
2022 nkind = SIZE(atomic_kind_set)
2023 IF (unit_nr > 0) THEN
2024 WRITE (unit_nr, *) "Atomic (core) densities"
2025 WRITE (unit_nr, *) "Unit cell"
2026 WRITE (unit_nr, fmt="(3F20.12)") cell%hmat(1, 1), cell%hmat(1, 2), cell%hmat(1, 3)
2027 WRITE (unit_nr, fmt="(3F20.12)") cell%hmat(2, 1), cell%hmat(2, 2), cell%hmat(2, 3)
2028 WRITE (unit_nr, fmt="(3F20.12)") cell%hmat(3, 1), cell%hmat(3, 2), cell%hmat(3, 3)
2029 WRITE (unit_nr, *) "Atomic types"
2030 WRITE (unit_nr, *) nkind
2031 END IF
2032 ! calculate atomic density and core density
2033 ALLOCATE (ppdens(ngto, 2, nkind), aedens(ngto, 2, nkind), ccdens(ngto, 2, nkind))
2034 DO ikind = 1, nkind
2035 atomic_kind => atomic_kind_set(ikind)
2036 qs_kind => qs_kind_set(ikind)
2037 CALL get_atomic_kind(atomic_kind, name=name, element_symbol=element_symbol)
2038 CALL calculate_atomic_density(ppdens(:, :, ikind), atomic_kind, qs_kind, ngto, &
2039 iunit=output_unit, confine=.true.)
2040 CALL calculate_atomic_density(aedens(:, :, ikind), atomic_kind, qs_kind, ngto, &
2041 iunit=output_unit, allelectron=.true., confine=.true.)
2042 ccdens(:, 1, ikind) = aedens(:, 1, ikind)
2043 ccdens(:, 2, ikind) = 0._dp
2044 CALL project_function_a(ccdens(1:ngto, 2, ikind), ccdens(1:ngto, 1, ikind), &
2045 ppdens(1:ngto, 2, ikind), ppdens(1:ngto, 1, ikind), 0)
2046 ccdens(:, 2, ikind) = aedens(:, 2, ikind) - ccdens(:, 2, ikind)
2047 IF (unit_nr > 0) THEN
2048 WRITE (unit_nr, fmt="(I6,A10,A20)") ikind, trim(element_symbol), trim(name)
2049 WRITE (unit_nr, fmt="(I6)") ngto
2050 WRITE (unit_nr, *) " Total density"
2051 WRITE (unit_nr, fmt="(2G24.12)") (aedens(i, 1, ikind), aedens(i, 2, ikind), i=1, ngto)
2052 WRITE (unit_nr, *) " Core density"
2053 WRITE (unit_nr, fmt="(2G24.12)") (ccdens(i, 1, ikind), ccdens(i, 2, ikind), i=1, ngto)
2054 END IF
2055 NULLIFY (atomic_kind)
2056 END DO
2057
2058 IF (dft_control%qs_control%gapw) THEN
2059 CALL get_qs_env(qs_env=qs_env, rho_atom_set=rho_atom_set)
2060
2061 IF (unit_nr > 0) THEN
2062 WRITE (unit_nr, *) "Coordinates and GAPW density"
2063 END IF
2064 np = particles%n_els
2065 DO iat = 1, np
2066 CALL get_atomic_kind(particles%els(iat)%atomic_kind, kind_number=ikind)
2067 CALL get_qs_kind(qs_kind_set(ikind), grid_atom=grid_atom)
2068 rho_atom => rho_atom_set(iat)
2069 IF (ASSOCIATED(rho_atom%rho_rad_h(1)%r_coef)) THEN
2070 nr = SIZE(rho_atom%rho_rad_h(1)%r_coef, 1)
2071 niso = SIZE(rho_atom%rho_rad_h(1)%r_coef, 2)
2072 ELSE
2073 nr = 0
2074 niso = 0
2075 END IF
2076 CALL para_env%sum(nr)
2077 CALL para_env%sum(niso)
2078
2079 ALLOCATE (bfun(nr, niso))
2080 bfun = 0._dp
2081 DO ispin = 1, dft_control%nspins
2082 IF (ASSOCIATED(rho_atom%rho_rad_h(1)%r_coef)) THEN
2083 bfun(:, :) = bfun + rho_atom%rho_rad_h(ispin)%r_coef - rho_atom%rho_rad_s(ispin)%r_coef
2084 END IF
2085 END DO
2086 CALL para_env%sum(bfun)
2087 ccdens(:, 1, ikind) = ppdens(:, 1, ikind)
2088 ccdens(:, 2, ikind) = 0._dp
2089 IF (unit_nr > 0) THEN
2090 WRITE (unit_nr, '(I10,I5,3f12.6)') iat, ikind, particles%els(iat)%r
2091 END IF
2092 DO iso = 1, niso
2093 l = indso(1, iso)
2094 CALL project_function_b(ccdens(:, 2, ikind), ccdens(:, 1, ikind), bfun(:, iso), grid_atom, l)
2095 IF (unit_nr > 0) THEN
2096 WRITE (unit_nr, fmt="(3I6)") iso, l, ngto
2097 WRITE (unit_nr, fmt="(2G24.12)") (ccdens(i, 1, ikind), ccdens(i, 2, ikind), i=1, ngto)
2098 END IF
2099 END DO
2100 DEALLOCATE (bfun)
2101 END DO
2102 ELSE
2103 IF (unit_nr > 0) THEN
2104 WRITE (unit_nr, *) "Coordinates"
2105 np = particles%n_els
2106 DO iat = 1, np
2107 CALL get_atomic_kind(particles%els(iat)%atomic_kind, kind_number=ikind)
2108 WRITE (unit_nr, '(I10,I5,3f12.6)') iat, ikind, particles%els(iat)%r
2109 END DO
2110 END IF
2111 END IF
2112
2113 DEALLOCATE (ppdens, aedens, ccdens)
2114
2115 CALL cp_print_key_finished_output(unit_nr, logger, input, &
2116 "DFT%PRINT%E_DENSITY_CUBE")
2117
2118 END IF
2119 IF (dft_control%qs_control%gapw .AND. print_density == "TOTAL_DENSITY") THEN
2120 ! total density in g-space not implemented for k-points
2121 cpassert(.NOT. do_kpoints)
2122 ! Print total electronic density
2123 CALL get_qs_env(qs_env=qs_env, &
2124 pw_env=pw_env)
2125 CALL pw_env_get(pw_env=pw_env, &
2126 auxbas_pw_pool=auxbas_pw_pool, &
2127 pw_pools=pw_pools)
2128 CALL auxbas_pw_pool%create_pw(pw=rho_elec_rspace)
2129 CALL pw_zero(rho_elec_rspace)
2130 CALL auxbas_pw_pool%create_pw(pw=rho_elec_gspace)
2131 CALL pw_zero(rho_elec_gspace)
2132 CALL get_pw_grid_info(pw_grid=rho_elec_gspace%pw_grid, &
2133 dr=dr, &
2134 vol=volume)
2135 q_max = sqrt(sum((pi/dr(:))**2))
2136 CALL calculate_rhotot_elec_gspace(qs_env=qs_env, &
2137 auxbas_pw_pool=auxbas_pw_pool, &
2138 rhotot_elec_gspace=rho_elec_gspace, &
2139 q_max=q_max, &
2140 rho_hard=rho_hard, &
2141 rho_soft=rho_soft)
2142 rho_total = rho_hard + rho_soft
2143 CALL get_pw_grid_info(pw_grid=rho_elec_gspace%pw_grid, &
2144 vol=volume)
2145 ! rhotot pw coefficients are by default scaled by grid volume
2146 ! need to undo this to get proper charge from printed cube
2147 CALL pw_scale(rho_elec_gspace, 1.0_dp/volume)
2148
2149 CALL pw_transfer(rho_elec_gspace, rho_elec_rspace)
2150 rho_total_rspace = pw_integrate_function(rho_elec_rspace, isign=-1)
2151 filename = "TOTAL_ELECTRON_DENSITY"
2152 mpi_io = .true.
2153 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%E_DENSITY_CUBE", &
2154 extension=".cube", middle_name=trim(filename), &
2155 file_position=my_pos_cube, log_filename=.false., mpi_io=mpi_io, &
2156 fout=mpi_filename)
2157 IF (output_unit > 0) THEN
2158 IF (.NOT. mpi_io) THEN
2159 INQUIRE (unit=unit_nr, name=filename)
2160 ELSE
2161 filename = mpi_filename
2162 END IF
2163 WRITE (unit=output_unit, fmt="(/,T2,A,/,/,T2,A)") &
2164 "The total electron density is written in cube file format to the file:", &
2165 trim(filename)
2166 WRITE (unit=output_unit, fmt="(/,(T2,A,F20.10))") &
2167 "q(max) [1/Angstrom] :", q_max/angstrom, &
2168 "Soft electronic charge (G-space) :", rho_soft, &
2169 "Hard electronic charge (G-space) :", rho_hard, &
2170 "Total electronic charge (G-space):", rho_total, &
2171 "Total electronic charge (R-space):", rho_total_rspace
2172 END IF
2173 CALL cp_pw_to_cube(rho_elec_rspace, unit_nr, "TOTAL ELECTRON DENSITY", &
2174 particles=particles, &
2175 stride=section_get_ivals(dft_section, "PRINT%E_DENSITY_CUBE%STRIDE"), mpi_io=mpi_io)
2176 CALL cp_print_key_finished_output(unit_nr, logger, input, &
2177 "DFT%PRINT%E_DENSITY_CUBE", mpi_io=mpi_io)
2178 ! Print total spin density for spin-polarized systems
2179 IF (dft_control%nspins > 1) THEN
2180 CALL pw_zero(rho_elec_gspace)
2181 CALL pw_zero(rho_elec_rspace)
2182 CALL calculate_rhotot_elec_gspace(qs_env=qs_env, &
2183 auxbas_pw_pool=auxbas_pw_pool, &
2184 rhotot_elec_gspace=rho_elec_gspace, &
2185 q_max=q_max, &
2186 rho_hard=rho_hard, &
2187 rho_soft=rho_soft, &
2188 fsign=-1.0_dp)
2189 rho_total = rho_hard + rho_soft
2190
2191 ! rhotot pw coefficients are by default scaled by grid volume
2192 ! need to undo this to get proper charge from printed cube
2193 CALL pw_scale(rho_elec_gspace, 1.0_dp/volume)
2194
2195 CALL pw_transfer(rho_elec_gspace, rho_elec_rspace)
2196 rho_total_rspace = pw_integrate_function(rho_elec_rspace, isign=-1)
2197 filename = "TOTAL_SPIN_DENSITY"
2198 mpi_io = .true.
2199 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%E_DENSITY_CUBE", &
2200 extension=".cube", middle_name=trim(filename), &
2201 file_position=my_pos_cube, log_filename=.false., mpi_io=mpi_io, &
2202 fout=mpi_filename)
2203 IF (output_unit > 0) THEN
2204 IF (.NOT. mpi_io) THEN
2205 INQUIRE (unit=unit_nr, name=filename)
2206 ELSE
2207 filename = mpi_filename
2208 END IF
2209 WRITE (unit=output_unit, fmt="(/,T2,A,/,/,T2,A)") &
2210 "The total spin density is written in cube file format to the file:", &
2211 trim(filename)
2212 WRITE (unit=output_unit, fmt="(/,(T2,A,F20.10))") &
2213 "q(max) [1/Angstrom] :", q_max/angstrom, &
2214 "Soft part of the spin density (G-space):", rho_soft, &
2215 "Hard part of the spin density (G-space):", rho_hard, &
2216 "Total spin density (G-space) :", rho_total, &
2217 "Total spin density (R-space) :", rho_total_rspace
2218 END IF
2219 CALL cp_pw_to_cube(rho_elec_rspace, unit_nr, "TOTAL SPIN DENSITY", &
2220 particles=particles, &
2221 stride=section_get_ivals(dft_section, "PRINT%E_DENSITY_CUBE%STRIDE"), mpi_io=mpi_io)
2222 CALL cp_print_key_finished_output(unit_nr, logger, input, &
2223 "DFT%PRINT%E_DENSITY_CUBE", mpi_io=mpi_io)
2224 END IF
2225 CALL auxbas_pw_pool%give_back_pw(rho_elec_gspace)
2226 CALL auxbas_pw_pool%give_back_pw(rho_elec_rspace)
2227
2228 ELSE IF (print_density == "SOFT_DENSITY" .OR. .NOT. dft_control%qs_control%gapw) THEN
2229 IF (dft_control%nspins > 1) THEN
2230 CALL get_qs_env(qs_env=qs_env, &
2231 pw_env=pw_env)
2232 CALL pw_env_get(pw_env=pw_env, &
2233 auxbas_pw_pool=auxbas_pw_pool, &
2234 pw_pools=pw_pools)
2235 CALL auxbas_pw_pool%create_pw(pw=rho_elec_rspace)
2236 CALL pw_copy(rho_r(1), rho_elec_rspace)
2237 CALL pw_axpy(rho_r(2), rho_elec_rspace)
2238 filename = "ELECTRON_DENSITY"
2239 mpi_io = .true.
2240 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%E_DENSITY_CUBE", &
2241 extension=".cube", middle_name=trim(filename), &
2242 file_position=my_pos_cube, log_filename=.false., mpi_io=mpi_io, &
2243 fout=mpi_filename)
2244 IF (output_unit > 0) THEN
2245 IF (.NOT. mpi_io) THEN
2246 INQUIRE (unit=unit_nr, name=filename)
2247 ELSE
2248 filename = mpi_filename
2249 END IF
2250 WRITE (unit=output_unit, fmt="(/,T2,A,/,/,T2,A)") &
2251 "The sum of alpha and beta density is written in cube file format to the file:", &
2252 trim(filename)
2253 END IF
2254 CALL cp_pw_to_cube(rho_elec_rspace, unit_nr, "SUM OF ALPHA AND BETA DENSITY", &
2255 particles=particles, stride=section_get_ivals(dft_section, "PRINT%E_DENSITY_CUBE%STRIDE"), &
2256 mpi_io=mpi_io)
2257 CALL cp_print_key_finished_output(unit_nr, logger, input, &
2258 "DFT%PRINT%E_DENSITY_CUBE", mpi_io=mpi_io)
2259 CALL pw_copy(rho_r(1), rho_elec_rspace)
2260 CALL pw_axpy(rho_r(2), rho_elec_rspace, alpha=-1.0_dp)
2261 filename = "SPIN_DENSITY"
2262 mpi_io = .true.
2263 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%E_DENSITY_CUBE", &
2264 extension=".cube", middle_name=trim(filename), &
2265 file_position=my_pos_cube, log_filename=.false., mpi_io=mpi_io, &
2266 fout=mpi_filename)
2267 IF (output_unit > 0) THEN
2268 IF (.NOT. mpi_io) THEN
2269 INQUIRE (unit=unit_nr, name=filename)
2270 ELSE
2271 filename = mpi_filename
2272 END IF
2273 WRITE (unit=output_unit, fmt="(/,T2,A,/,/,T2,A)") &
2274 "The spin density is written in cube file format to the file:", &
2275 trim(filename)
2276 END IF
2277 CALL cp_pw_to_cube(rho_elec_rspace, unit_nr, "SPIN DENSITY", &
2278 particles=particles, &
2279 stride=section_get_ivals(dft_section, "PRINT%E_DENSITY_CUBE%STRIDE"), mpi_io=mpi_io)
2280 CALL cp_print_key_finished_output(unit_nr, logger, input, &
2281 "DFT%PRINT%E_DENSITY_CUBE", mpi_io=mpi_io)
2282 CALL auxbas_pw_pool%give_back_pw(rho_elec_rspace)
2283 ELSE
2284 filename = "ELECTRON_DENSITY"
2285 mpi_io = .true.
2286 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%E_DENSITY_CUBE", &
2287 extension=".cube", middle_name=trim(filename), &
2288 file_position=my_pos_cube, log_filename=.false., mpi_io=mpi_io, &
2289 fout=mpi_filename)
2290 IF (output_unit > 0) THEN
2291 IF (.NOT. mpi_io) THEN
2292 INQUIRE (unit=unit_nr, name=filename)
2293 ELSE
2294 filename = mpi_filename
2295 END IF
2296 WRITE (unit=output_unit, fmt="(/,T2,A,/,/,T2,A)") &
2297 "The electron density is written in cube file format to the file:", &
2298 trim(filename)
2299 END IF
2300 CALL cp_pw_to_cube(rho_r(1), unit_nr, "ELECTRON DENSITY", &
2301 particles=particles, &
2302 stride=section_get_ivals(dft_section, "PRINT%E_DENSITY_CUBE%STRIDE"), mpi_io=mpi_io)
2303 CALL cp_print_key_finished_output(unit_nr, logger, input, &
2304 "DFT%PRINT%E_DENSITY_CUBE", mpi_io=mpi_io)
2305 END IF ! nspins
2306
2307 ELSE IF (dft_control%qs_control%gapw .AND. print_density == "TOTAL_HARD_APPROX") THEN
2308 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env, rho0_mpole=rho0_mpole, natom=natom)
2309 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, pw_pools=pw_pools)
2310 CALL auxbas_pw_pool%create_pw(rho_elec_rspace)
2311
2312 NULLIFY (my_q0)
2313 ALLOCATE (my_q0(natom))
2314 my_q0 = 0.0_dp
2315
2316 ! (eta/pi)**3: normalization for 3d gaussian of form exp(-eta*r**2)
2317 norm_factor = sqrt((rho0_mpole%zet0_h/pi)**3)
2318
2319 ! store hard part of electronic density in array
2320 DO iat = 1, natom
2321 my_q0(iat) = sum(rho0_mpole%mp_rho(iat)%Q0(1:dft_control%nspins))*norm_factor
2322 END DO
2323 ! multiply coeff with gaussian and put on realspace grid
2324 ! coeff is the gaussian prefactor, eta the gaussian exponent
2325 CALL calculate_rho_resp_all(rho_elec_rspace, coeff=my_q0, natom=natom, eta=rho0_mpole%zet0_h, qs_env=qs_env)
2326 rho_hard = pw_integrate_function(rho_elec_rspace, isign=-1)
2327
2328 rho_soft = 0.0_dp
2329 DO ispin = 1, dft_control%nspins
2330 CALL pw_axpy(rho_r(ispin), rho_elec_rspace)
2331 rho_soft = rho_soft + pw_integrate_function(rho_r(ispin), isign=-1)
2332 END DO
2333
2334 rho_total_rspace = rho_soft + rho_hard
2335
2336 filename = "ELECTRON_DENSITY"
2337 mpi_io = .true.
2338 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%E_DENSITY_CUBE", &
2339 extension=".cube", middle_name=trim(filename), &
2340 file_position=my_pos_cube, log_filename=.false., mpi_io=mpi_io, &
2341 fout=mpi_filename)
2342 IF (output_unit > 0) THEN
2343 IF (.NOT. mpi_io) THEN
2344 INQUIRE (unit=unit_nr, name=filename)
2345 ELSE
2346 filename = mpi_filename
2347 END IF
2348 WRITE (unit=output_unit, fmt="(/,T2,A,/,/,T2,A)") &
2349 "The electron density is written in cube file format to the file:", &
2350 trim(filename)
2351 WRITE (unit=output_unit, fmt="(/,(T2,A,F20.10))") &
2352 "Soft electronic charge (R-space) :", rho_soft, &
2353 "Hard electronic charge (R-space) :", rho_hard, &
2354 "Total electronic charge (R-space):", rho_total_rspace
2355 END IF
2356 CALL cp_pw_to_cube(rho_elec_rspace, unit_nr, "ELECTRON DENSITY", &
2357 particles=particles, stride=section_get_ivals(dft_section, "PRINT%E_DENSITY_CUBE%STRIDE"), &
2358 mpi_io=mpi_io)
2359 CALL cp_print_key_finished_output(unit_nr, logger, input, &
2360 "DFT%PRINT%E_DENSITY_CUBE", mpi_io=mpi_io)
2361
2362 !------------
2363 IF (dft_control%nspins > 1) THEN
2364 DO iat = 1, natom
2365 my_q0(iat) = (rho0_mpole%mp_rho(iat)%Q0(1) - rho0_mpole%mp_rho(iat)%Q0(2))*norm_factor
2366 END DO
2367 CALL pw_zero(rho_elec_rspace)
2368 CALL calculate_rho_resp_all(rho_elec_rspace, coeff=my_q0, natom=natom, eta=rho0_mpole%zet0_h, qs_env=qs_env)
2369 rho_hard = pw_integrate_function(rho_elec_rspace, isign=-1)
2370
2371 CALL pw_axpy(rho_r(1), rho_elec_rspace)
2372 CALL pw_axpy(rho_r(2), rho_elec_rspace, alpha=-1.0_dp)
2373 rho_soft = pw_integrate_function(rho_r(1), isign=-1) &
2374 - pw_integrate_function(rho_r(2), isign=-1)
2375
2376 rho_total_rspace = rho_soft + rho_hard
2377
2378 filename = "SPIN_DENSITY"
2379 mpi_io = .true.
2380 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%E_DENSITY_CUBE", &
2381 extension=".cube", middle_name=trim(filename), &
2382 file_position=my_pos_cube, log_filename=.false., mpi_io=mpi_io, &
2383 fout=mpi_filename)
2384 IF (output_unit > 0) THEN
2385 IF (.NOT. mpi_io) THEN
2386 INQUIRE (unit=unit_nr, name=filename)
2387 ELSE
2388 filename = mpi_filename
2389 END IF
2390 WRITE (unit=output_unit, fmt="(/,T2,A,/,/,T2,A)") &
2391 "The spin density is written in cube file format to the file:", &
2392 trim(filename)
2393 WRITE (unit=output_unit, fmt="(/,(T2,A,F20.10))") &
2394 "Soft part of the spin density :", rho_soft, &
2395 "Hard part of the spin density :", rho_hard, &
2396 "Total spin density (R-space) :", rho_total_rspace
2397 END IF
2398 CALL cp_pw_to_cube(rho_elec_rspace, unit_nr, "SPIN DENSITY", &
2399 particles=particles, &
2400 stride=section_get_ivals(dft_section, "PRINT%E_DENSITY_CUBE%STRIDE"), mpi_io=mpi_io)
2401 CALL cp_print_key_finished_output(unit_nr, logger, input, &
2402 "DFT%PRINT%E_DENSITY_CUBE", mpi_io=mpi_io)
2403 END IF ! nspins
2404 CALL auxbas_pw_pool%give_back_pw(rho_elec_rspace)
2405 DEALLOCATE (my_q0)
2406 END IF ! print_density
2407 END IF ! print key
2408
2409 IF (btest(cp_print_key_should_output(logger%iter_info, &
2410 dft_section, "PRINT%ENERGY_WINDOWS"), cp_p_file) .AND. .NOT. do_kpoints) THEN
2411 CALL energy_windows(qs_env)
2412 END IF
2413
2414 ! Print the hartree potential
2415 IF (btest(cp_print_key_should_output(logger%iter_info, input, &
2416 "DFT%PRINT%V_HARTREE_CUBE"), cp_p_file)) THEN
2417
2418 CALL get_qs_env(qs_env=qs_env, &
2419 pw_env=pw_env, &
2420 v_hartree_rspace=v_hartree_rspace)
2421 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
2422 CALL auxbas_pw_pool%create_pw(aux_r)
2423
2424 append_cube = section_get_lval(input, "DFT%PRINT%V_HARTREE_CUBE%APPEND")
2425 my_pos_cube = "REWIND"
2426 IF (append_cube) THEN
2427 my_pos_cube = "APPEND"
2428 END IF
2429 mpi_io = .true.
2430 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
2431 CALL pw_env_get(pw_env)
2432 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%V_HARTREE_CUBE", &
2433 extension=".cube", middle_name="v_hartree", file_position=my_pos_cube, mpi_io=mpi_io)
2434 udvol = 1.0_dp/v_hartree_rspace%pw_grid%dvol
2435
2436 CALL pw_copy(v_hartree_rspace, aux_r)
2437 CALL pw_scale(aux_r, udvol)
2438
2439 CALL cp_pw_to_cube(aux_r, unit_nr, "HARTREE POTENTIAL", particles=particles, &
2440 stride=section_get_ivals(dft_section, &
2441 "PRINT%V_HARTREE_CUBE%STRIDE"), mpi_io=mpi_io)
2442 CALL cp_print_key_finished_output(unit_nr, logger, input, &
2443 "DFT%PRINT%V_HARTREE_CUBE", mpi_io=mpi_io)
2444
2445 CALL auxbas_pw_pool%give_back_pw(aux_r)
2446 END IF
2447
2448 ! Print the external potential
2449 IF (btest(cp_print_key_should_output(logger%iter_info, input, &
2450 "DFT%PRINT%EXTERNAL_POTENTIAL_CUBE"), cp_p_file)) THEN
2451 IF (dft_control%apply_external_potential) THEN
2452 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env, vee=vee)
2453 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
2454 CALL auxbas_pw_pool%create_pw(aux_r)
2455
2456 append_cube = section_get_lval(input, "DFT%PRINT%EXTERNAL_POTENTIAL_CUBE%APPEND")
2457 my_pos_cube = "REWIND"
2458 IF (append_cube) THEN
2459 my_pos_cube = "APPEND"
2460 END IF
2461 mpi_io = .true.
2462 CALL pw_env_get(pw_env)
2463 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%EXTERNAL_POTENTIAL_CUBE", &
2464 extension=".cube", middle_name="ext_pot", file_position=my_pos_cube, mpi_io=mpi_io)
2465
2466 CALL pw_copy(vee, aux_r)
2467
2468 CALL cp_pw_to_cube(aux_r, unit_nr, "EXTERNAL POTENTIAL", particles=particles, &
2469 stride=section_get_ivals(dft_section, &
2470 "PRINT%EXTERNAL_POTENTIAL_CUBE%STRIDE"), mpi_io=mpi_io)
2471 CALL cp_print_key_finished_output(unit_nr, logger, input, &
2472 "DFT%PRINT%EXTERNAL_POTENTIAL_CUBE", mpi_io=mpi_io)
2473
2474 CALL auxbas_pw_pool%give_back_pw(aux_r)
2475 END IF
2476 END IF
2477
2478 ! Print the Electrical Field Components
2479 IF (btest(cp_print_key_should_output(logger%iter_info, input, &
2480 "DFT%PRINT%EFIELD_CUBE"), cp_p_file)) THEN
2481
2482 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
2483 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
2484 CALL auxbas_pw_pool%create_pw(aux_r)
2485 CALL auxbas_pw_pool%create_pw(aux_g)
2486
2487 append_cube = section_get_lval(input, "DFT%PRINT%EFIELD_CUBE%APPEND")
2488 my_pos_cube = "REWIND"
2489 IF (append_cube) THEN
2490 my_pos_cube = "APPEND"
2491 END IF
2492 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env, &
2493 v_hartree_rspace=v_hartree_rspace)
2494 CALL pw_env_get(pw_env)
2495 udvol = 1.0_dp/v_hartree_rspace%pw_grid%dvol
2496 DO id = 1, 3
2497 mpi_io = .true.
2498 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%EFIELD_CUBE", &
2499 extension=".cube", middle_name="efield_"//cdir(id), file_position=my_pos_cube, &
2500 mpi_io=mpi_io)
2501
2502 CALL pw_transfer(v_hartree_rspace, aux_g)
2503 nd = 0
2504 nd(id) = 1
2505 CALL pw_derive(aux_g, nd)
2506 CALL pw_transfer(aux_g, aux_r)
2507 CALL pw_scale(aux_r, udvol)
2508
2509 CALL cp_pw_to_cube(aux_r, &
2510 unit_nr, "ELECTRIC FIELD", particles=particles, &
2511 stride=section_get_ivals(dft_section, &
2512 "PRINT%EFIELD_CUBE%STRIDE"), mpi_io=mpi_io)
2513 CALL cp_print_key_finished_output(unit_nr, logger, input, &
2514 "DFT%PRINT%EFIELD_CUBE", mpi_io=mpi_io)
2515 END DO
2516
2517 CALL auxbas_pw_pool%give_back_pw(aux_r)
2518 CALL auxbas_pw_pool%give_back_pw(aux_g)
2519 END IF
2520
2521 ! Write cube files from the local energy
2522 CALL qs_scf_post_local_energy(input, logger, qs_env)
2523
2524 ! Write cube files from the local stress tensor
2525 CALL qs_scf_post_local_stress(input, logger, qs_env)
2526
2527 ! Write cube files from the implicit Poisson solver
2528 CALL qs_scf_post_ps_implicit(input, logger, qs_env)
2529
2530 ! post SCF Transport
2531 CALL qs_scf_post_transport(qs_env)
2532
2533 CALL section_vals_val_get(input, "DFT%PRINT%AO_MATRICES%OMIT_HEADERS", l_val=omit_headers)
2534 ! Write the density matrices
2535 IF (btest(cp_print_key_should_output(logger%iter_info, input, &
2536 "DFT%PRINT%AO_MATRICES/DENSITY"), cp_p_file)) THEN
2537 iw = cp_print_key_unit_nr(logger, input, "DFT%PRINT%AO_MATRICES/DENSITY", &
2538 extension=".Log")
2539 CALL section_vals_val_get(input, "DFT%PRINT%AO_MATRICES%NDIGITS", i_val=after)
2540 CALL qs_rho_get(rho, rho_ao_kp=rho_ao)
2541 after = min(max(after, 1), 16)
2542 DO ispin = 1, dft_control%nspins
2543 DO img = 1, dft_control%nimages
2544 CALL cp_dbcsr_write_sparse_matrix(rho_ao(ispin, img)%matrix, 4, after, qs_env, &
2545 para_env, output_unit=iw, omit_headers=omit_headers)
2546 END DO
2547 END DO
2548 CALL cp_print_key_finished_output(iw, logger, input, &
2549 "DFT%PRINT%AO_MATRICES/DENSITY")
2550 END IF
2551
2552 ! Write the Kohn-Sham matrices
2553 write_ks = btest(cp_print_key_should_output(logger%iter_info, input, &
2554 "DFT%PRINT%AO_MATRICES/KOHN_SHAM_MATRIX"), cp_p_file)
2555 write_xc = btest(cp_print_key_should_output(logger%iter_info, input, &
2556 "DFT%PRINT%AO_MATRICES/MATRIX_VXC"), cp_p_file)
2557 ! we need to update stuff before writing, potentially computing the matrix_vxc
2558 IF (write_ks .OR. write_xc) THEN
2559 IF (write_xc) qs_env%requires_matrix_vxc = .true.
2560 CALL qs_ks_did_change(qs_env%ks_env, rho_changed=.true.)
2561 CALL qs_ks_update_qs_env(qs_env, calculate_forces=.false., &
2562 just_energy=.false.)
2563 IF (write_xc) qs_env%requires_matrix_vxc = .false.
2564 END IF
2565
2566 ! Write the Kohn-Sham matrices
2567 IF (write_ks) THEN
2568 iw = cp_print_key_unit_nr(logger, input, "DFT%PRINT%AO_MATRICES/KOHN_SHAM_MATRIX", &
2569 extension=".Log")
2570 CALL get_qs_env(qs_env=qs_env, matrix_ks_kp=ks_rmpv)
2571 CALL section_vals_val_get(input, "DFT%PRINT%AO_MATRICES%NDIGITS", i_val=after)
2572 after = min(max(after, 1), 16)
2573 DO ispin = 1, dft_control%nspins
2574 DO img = 1, dft_control%nimages
2575 CALL cp_dbcsr_write_sparse_matrix(ks_rmpv(ispin, img)%matrix, 4, after, qs_env, &
2576 para_env, output_unit=iw, omit_headers=omit_headers)
2577 END DO
2578 END DO
2579 CALL cp_print_key_finished_output(iw, logger, input, &
2580 "DFT%PRINT%AO_MATRICES/KOHN_SHAM_MATRIX")
2581 END IF
2582
2583 ! write csr matrices
2584 ! matrices in terms of the PAO basis will be taken care of in pao_post_scf.
2585 IF (.NOT. dft_control%qs_control%pao) THEN
2586 CALL write_ks_matrix_csr(qs_env, input)
2587 CALL write_s_matrix_csr(qs_env, input)
2588 END IF
2589
2590 ! write adjacency matrix
2591 CALL write_adjacency_matrix(qs_env, input)
2592
2593 ! Write the xc matrix
2594 IF (write_xc) THEN
2595 CALL get_qs_env(qs_env=qs_env, matrix_vxc_kp=matrix_vxc)
2596 cpassert(ASSOCIATED(matrix_vxc))
2597 iw = cp_print_key_unit_nr(logger, input, "DFT%PRINT%AO_MATRICES/MATRIX_VXC", &
2598 extension=".Log")
2599 CALL section_vals_val_get(input, "DFT%PRINT%AO_MATRICES%NDIGITS", i_val=after)
2600 after = min(max(after, 1), 16)
2601 DO ispin = 1, dft_control%nspins
2602 DO img = 1, dft_control%nimages
2603 CALL cp_dbcsr_write_sparse_matrix(matrix_vxc(ispin, img)%matrix, 4, after, qs_env, &
2604 para_env, output_unit=iw, omit_headers=omit_headers)
2605 END DO
2606 END DO
2607 CALL cp_print_key_finished_output(iw, logger, input, &
2608 "DFT%PRINT%AO_MATRICES/MATRIX_VXC")
2609 END IF
2610
2611 ! Write the [H,r] commutator matrices
2612 IF (btest(cp_print_key_should_output(logger%iter_info, input, &
2613 "DFT%PRINT%AO_MATRICES/COMMUTATOR_HR"), cp_p_file)) THEN
2614 iw = cp_print_key_unit_nr(logger, input, "DFT%PRINT%AO_MATRICES/COMMUTATOR_HR", &
2615 extension=".Log")
2616 CALL section_vals_val_get(input, "DFT%PRINT%AO_MATRICES%NDIGITS", i_val=after)
2617 NULLIFY (matrix_hr)
2618 CALL build_com_hr_matrix(qs_env, matrix_hr)
2619 after = min(max(after, 1), 16)
2620 DO img = 1, 3
2621 CALL cp_dbcsr_write_sparse_matrix(matrix_hr(img)%matrix, 4, after, qs_env, &
2622 para_env, output_unit=iw, omit_headers=omit_headers)
2623 END DO
2624 CALL dbcsr_deallocate_matrix_set(matrix_hr)
2625 CALL cp_print_key_finished_output(iw, logger, input, &
2626 "DFT%PRINT%AO_MATRICES/COMMUTATOR_HR")
2627 END IF
2628
2629 ! Compute the Mulliken charges
2630 print_key => section_vals_get_subs_vals(input, "DFT%PRINT%MULLIKEN")
2631 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
2632 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%MULLIKEN", extension=".mulliken", log_filename=.false.)
2633 print_level = 1
2634 CALL section_vals_val_get(print_key, "PRINT_GOP", l_val=print_it)
2635 IF (print_it) print_level = 2
2636 CALL section_vals_val_get(print_key, "PRINT_ALL", l_val=print_it)
2637 IF (print_it) print_level = 3
2638 CALL mulliken_population_analysis(qs_env, unit_nr, print_level)
2639 CALL cp_print_key_finished_output(unit_nr, logger, input, "DFT%PRINT%MULLIKEN")
2640 END IF
2641
2642 ! Compute the Hirshfeld charges
2643 print_key => section_vals_get_subs_vals(input, "DFT%PRINT%HIRSHFELD")
2644 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
2645 ! we check if real space density is available
2646 NULLIFY (rho)
2647 CALL get_qs_env(qs_env=qs_env, rho=rho)
2648 CALL qs_rho_get(rho, rho_r_valid=rho_r_valid)
2649 IF (rho_r_valid) THEN
2650 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%HIRSHFELD", extension=".hirshfeld", log_filename=.false.)
2651 CALL hirshfeld_charges(qs_env, print_key, unit_nr)
2652 CALL cp_print_key_finished_output(unit_nr, logger, input, "DFT%PRINT%HIRSHFELD")
2653 END IF
2654 END IF
2655
2656 ! Compute EEQ charges
2657 print_key => section_vals_get_subs_vals(input, "DFT%PRINT%EEQ_CHARGES")
2658 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
2659 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%EEQ_CHARGES", extension=".eeq", log_filename=.false.)
2660 print_level = 1
2661 CALL eeq_print(qs_env, unit_nr, print_level, ext=.false.)
2662 CALL cp_print_key_finished_output(unit_nr, logger, input, "DFT%PRINT%MULLIKEN")
2663 END IF
2664
2665 ! Do a Voronoi Integration or write a compressed BQB File
2666 print_key_voro => section_vals_get_subs_vals(input, "DFT%PRINT%VORONOI")
2667 print_key_bqb => section_vals_get_subs_vals(input, "DFT%PRINT%E_DENSITY_BQB")
2668 IF (btest(cp_print_key_should_output(logger%iter_info, print_key_voro), cp_p_file)) THEN
2669 should_print_voro = 1
2670 ELSE
2671 should_print_voro = 0
2672 END IF
2673 IF (btest(cp_print_key_should_output(logger%iter_info, print_key_bqb), cp_p_file)) THEN
2674 should_print_bqb = 1
2675 ELSE
2676 should_print_bqb = 0
2677 END IF
2678 IF ((should_print_voro /= 0) .OR. (should_print_bqb /= 0)) THEN
2679
2680 ! we check if real space density is available
2681 NULLIFY (rho)
2682 CALL get_qs_env(qs_env=qs_env, rho=rho)
2683 CALL qs_rho_get(rho, rho_r_valid=rho_r_valid)
2684 IF (rho_r_valid) THEN
2685
2686 IF (dft_control%nspins > 1) THEN
2687 CALL get_qs_env(qs_env=qs_env, &
2688 pw_env=pw_env)
2689 CALL pw_env_get(pw_env=pw_env, &
2690 auxbas_pw_pool=auxbas_pw_pool, &
2691 pw_pools=pw_pools)
2692 NULLIFY (mb_rho)
2693 ALLOCATE (mb_rho)
2694 CALL auxbas_pw_pool%create_pw(pw=mb_rho)
2695 CALL pw_copy(rho_r(1), mb_rho)
2696 CALL pw_axpy(rho_r(2), mb_rho)
2697 !CALL voronoi_analysis(qs_env, rho_elec_rspace, print_key, unit_nr)
2698 ELSE
2699 mb_rho => rho_r(1)
2700 !CALL voronoi_analysis( qs_env, rho_r(1), print_key, unit_nr )
2701 END IF ! nspins
2702
2703 IF (should_print_voro /= 0) THEN
2704 CALL section_vals_val_get(print_key_voro, "OUTPUT_TEXT", l_val=voro_print_txt)
2705 IF (voro_print_txt) THEN
2706 append_voro = section_get_lval(input, "DFT%PRINT%VORONOI%APPEND")
2707 my_pos_voro = "REWIND"
2708 IF (append_voro) THEN
2709 my_pos_voro = "APPEND"
2710 END IF
2711 unit_nr_voro = cp_print_key_unit_nr(logger, input, "DFT%PRINT%VORONOI", extension=".voronoi", &
2712 file_position=my_pos_voro, log_filename=.false.)
2713 ELSE
2714 unit_nr_voro = 0
2715 END IF
2716 ELSE
2717 unit_nr_voro = 0
2718 END IF
2719
2720 CALL entry_voronoi_or_bqb(should_print_voro, should_print_bqb, print_key_voro, print_key_bqb, &
2721 unit_nr_voro, qs_env, mb_rho)
2722
2723 IF (dft_control%nspins > 1) THEN
2724 CALL auxbas_pw_pool%give_back_pw(mb_rho)
2725 DEALLOCATE (mb_rho)
2726 END IF
2727
2728 IF (unit_nr_voro > 0) THEN
2729 CALL cp_print_key_finished_output(unit_nr_voro, logger, input, "DFT%PRINT%VORONOI")
2730 END IF
2731
2732 END IF
2733 END IF
2734
2735 ! MAO analysis
2736 print_key => section_vals_get_subs_vals(input, "DFT%PRINT%MAO_ANALYSIS")
2737 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
2738 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%MAO_ANALYSIS", extension=".mao", log_filename=.false.)
2739 CALL mao_analysis(qs_env, print_key, unit_nr)
2740 CALL cp_print_key_finished_output(unit_nr, logger, input, "DFT%PRINT%MAO_ANALYSIS")
2741 END IF
2742
2743 ! MINBAS analysis
2744 print_key => section_vals_get_subs_vals(input, "DFT%PRINT%MINBAS_ANALYSIS")
2745 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
2746 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%MINBAS_ANALYSIS", extension=".mao", log_filename=.false.)
2747 CALL minbas_analysis(qs_env, print_key, unit_nr)
2748 CALL cp_print_key_finished_output(unit_nr, logger, input, "DFT%PRINT%MINBAS_ANALYSIS")
2749 END IF
2750
2751 ! IAO analysis
2752 print_key => section_vals_get_subs_vals(input, "DFT%PRINT%IAO_ANALYSIS")
2753 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
2754 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%IAO_ANALYSIS", extension=".iao", log_filename=.false.)
2755 CALL iao_read_input(iao_env, print_key, cell)
2756 IF (iao_env%do_iao) THEN
2757 CALL iao_wfn_analysis(qs_env, iao_env, unit_nr)
2758 END IF
2759 CALL cp_print_key_finished_output(unit_nr, logger, input, "DFT%PRINT%IAO_ANALYSIS")
2760 END IF
2761
2762 ! Energy Decomposition Analysis
2763 print_key => section_vals_get_subs_vals(input, "DFT%PRINT%ENERGY_DECOMPOSITION_ANALYSIS")
2764 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
2765 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%ENERGY_DECOMPOSITION_ANALYSIS", &
2766 extension=".mao", log_filename=.false.)
2767 CALL edmf_analysis(qs_env, print_key, unit_nr)
2768 CALL cp_print_key_finished_output(unit_nr, logger, input, "DFT%PRINT%ENERGY_DECOMPOSITION_ANALYSIS")
2769 END IF
2770
2771 ! Print the density in the RI-HFX basis
2772 hfx_section => section_vals_get_subs_vals(input, "DFT%XC%HF")
2773 CALL section_vals_get(hfx_section, explicit=do_hfx)
2774 CALL section_vals_get(hfx_section, n_repetition=n_rep_hf)
2775 IF (do_hfx) THEN
2776 DO i = 1, n_rep_hf
2777 IF (qs_env%x_data(i, 1)%do_hfx_ri) CALL print_ri_hfx(qs_env%x_data(i, 1)%ri_data, qs_env)
2778 END DO
2779 END IF
2780
2781 CALL timestop(handle)
2782
2783 END SUBROUTINE write_mo_free_results
2784
2785! **************************************************************************************************
2786!> \brief Calculates Hirshfeld charges
2787!> \param qs_env the qs_env where to calculate the charges
2788!> \param input_section the input section for Hirshfeld charges
2789!> \param unit_nr the output unit number
2790! **************************************************************************************************
2791 SUBROUTINE hirshfeld_charges(qs_env, input_section, unit_nr)
2792 TYPE(qs_environment_type), POINTER :: qs_env
2793 TYPE(section_vals_type), POINTER :: input_section
2794 INTEGER, INTENT(IN) :: unit_nr
2795
2796 INTEGER :: i, iat, ikind, natom, nkind, nspin, &
2797 radius_type, refc, shapef
2798 INTEGER, DIMENSION(:), POINTER :: atom_list
2799 LOGICAL :: do_radius, do_sc, paw_atom
2800 REAL(kind=dp) :: zeff
2801 REAL(kind=dp), DIMENSION(:), POINTER :: radii
2802 REAL(kind=dp), DIMENSION(:, :), POINTER :: charges
2803 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
2804 TYPE(atomic_kind_type), POINTER :: atomic_kind
2805 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_p, matrix_s
2806 TYPE(dft_control_type), POINTER :: dft_control
2807 TYPE(hirshfeld_type), POINTER :: hirshfeld_env
2808 TYPE(mp_para_env_type), POINTER :: para_env
2809 TYPE(mpole_rho_atom), DIMENSION(:), POINTER :: mp_rho
2810 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
2811 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
2812 TYPE(qs_rho_type), POINTER :: rho
2813 TYPE(rho0_mpole_type), POINTER :: rho0_mpole
2814
2815 NULLIFY (hirshfeld_env)
2816 NULLIFY (radii)
2817 CALL create_hirshfeld_type(hirshfeld_env)
2818 !
2819 CALL get_qs_env(qs_env, nkind=nkind, natom=natom)
2820 ALLOCATE (hirshfeld_env%charges(natom))
2821 ! input options
2822 CALL section_vals_val_get(input_section, "SELF_CONSISTENT", l_val=do_sc)
2823 CALL section_vals_val_get(input_section, "USER_RADIUS", l_val=do_radius)
2824 CALL section_vals_val_get(input_section, "SHAPE_FUNCTION", i_val=shapef)
2825 CALL section_vals_val_get(input_section, "REFERENCE_CHARGE", i_val=refc)
2826 IF (do_radius) THEN
2827 radius_type = radius_user
2828 CALL section_vals_val_get(input_section, "ATOMIC_RADII", r_vals=radii)
2829 IF (.NOT. SIZE(radii) == nkind) &
2830 CALL cp_abort(__location__, &
2831 "Length of keyword HIRSHFELD\ATOMIC_RADII does not "// &
2832 "match number of atomic kinds in the input coordinate file.")
2833 ELSE
2834 radius_type = radius_covalent
2835 END IF
2836 CALL set_hirshfeld_info(hirshfeld_env, shape_function_type=shapef, &
2837 iterative=do_sc, ref_charge=refc, &
2838 radius_type=radius_type)
2839 ! shape function
2840 CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set, atomic_kind_set=atomic_kind_set)
2841 CALL create_shape_function(hirshfeld_env, qs_kind_set, atomic_kind_set, &
2842 radii_list=radii)
2843 ! reference charges
2844 CALL get_qs_env(qs_env, rho=rho)
2845 CALL qs_rho_get(rho, rho_ao_kp=matrix_p)
2846 nspin = SIZE(matrix_p, 1)
2847 ALLOCATE (charges(natom, nspin))
2848 SELECT CASE (refc)
2849 CASE (ref_charge_atomic)
2850 DO ikind = 1, nkind
2851 CALL get_qs_kind(qs_kind_set(ikind), zeff=zeff)
2852 atomic_kind => atomic_kind_set(ikind)
2853 CALL get_atomic_kind(atomic_kind, atom_list=atom_list)
2854 DO iat = 1, SIZE(atom_list)
2855 i = atom_list(iat)
2856 hirshfeld_env%charges(i) = zeff
2857 END DO
2858 END DO
2859 CASE (ref_charge_mulliken)
2860 CALL get_qs_env(qs_env, matrix_s_kp=matrix_s, para_env=para_env)
2861 CALL mulliken_charges(matrix_p, matrix_s, para_env, charges)
2862 DO iat = 1, natom
2863 hirshfeld_env%charges(iat) = sum(charges(iat, :))
2864 END DO
2865 CASE DEFAULT
2866 cpabort("Unknown type of reference charge for Hirshfeld partitioning.")
2867 END SELECT
2868 !
2869 charges = 0.0_dp
2870 IF (hirshfeld_env%iterative) THEN
2871 ! Hirshfeld-I charges
2872 CALL comp_hirshfeld_i_charges(qs_env, hirshfeld_env, charges, unit_nr)
2873 ELSE
2874 ! Hirshfeld charges
2875 CALL comp_hirshfeld_charges(qs_env, hirshfeld_env, charges)
2876 END IF
2877 CALL get_qs_env(qs_env, particle_set=particle_set, dft_control=dft_control)
2878 IF (dft_control%qs_control%gapw) THEN
2879 ! GAPW: add core charges (rho_hard - rho_soft)
2880 CALL get_qs_env(qs_env, rho0_mpole=rho0_mpole)
2881 CALL get_rho0_mpole(rho0_mpole, mp_rho=mp_rho)
2882 DO iat = 1, natom
2883 atomic_kind => particle_set(iat)%atomic_kind
2884 CALL get_atomic_kind(atomic_kind, kind_number=ikind)
2885 CALL get_qs_kind(qs_kind_set(ikind), paw_atom=paw_atom)
2886 IF (paw_atom) THEN
2887 charges(iat, 1:nspin) = charges(iat, 1:nspin) + mp_rho(iat)%q0(1:nspin)
2888 END IF
2889 END DO
2890 END IF
2891 !
2892 IF (unit_nr > 0) THEN
2893 CALL write_hirshfeld_charges(charges, hirshfeld_env, particle_set, &
2894 qs_kind_set, unit_nr)
2895 END IF
2896 ! Save the charges to the results under the tag [HIRSHFELD-CHARGES]
2897 CALL save_hirshfeld_charges(charges, particle_set, qs_kind_set, qs_env)
2898 !
2899 CALL release_hirshfeld_type(hirshfeld_env)
2900 DEALLOCATE (charges)
2901
2902 END SUBROUTINE hirshfeld_charges
2903
2904! **************************************************************************************************
2905!> \brief ...
2906!> \param ca ...
2907!> \param a ...
2908!> \param cb ...
2909!> \param b ...
2910!> \param l ...
2911! **************************************************************************************************
2912 SUBROUTINE project_function_a(ca, a, cb, b, l)
2913 ! project function cb on ca
2914 REAL(kind=dp), DIMENSION(:), INTENT(OUT) :: ca
2915 REAL(kind=dp), DIMENSION(:), INTENT(IN) :: a, cb, b
2916 INTEGER, INTENT(IN) :: l
2917
2918 INTEGER :: info, n
2919 INTEGER, ALLOCATABLE, DIMENSION(:) :: ipiv
2920 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: smat, tmat, v
2921
2922 n = SIZE(ca)
2923 ALLOCATE (smat(n, n), tmat(n, n), v(n, 1), ipiv(n))
2924
2925 CALL sg_overlap(smat, l, a, a)
2926 CALL sg_overlap(tmat, l, a, b)
2927 v(:, 1) = matmul(tmat, cb)
2928 CALL dgesv(n, 1, smat, n, ipiv, v, n, info)
2929 cpassert(info == 0)
2930 ca(:) = v(:, 1)
2931
2932 DEALLOCATE (smat, tmat, v, ipiv)
2933
2934 END SUBROUTINE project_function_a
2935
2936! **************************************************************************************************
2937!> \brief ...
2938!> \param ca ...
2939!> \param a ...
2940!> \param bfun ...
2941!> \param grid_atom ...
2942!> \param l ...
2943! **************************************************************************************************
2944 SUBROUTINE project_function_b(ca, a, bfun, grid_atom, l)
2945 ! project function f on ca
2946 REAL(kind=dp), DIMENSION(:), INTENT(OUT) :: ca
2947 REAL(kind=dp), DIMENSION(:), INTENT(IN) :: a, bfun
2948 TYPE(grid_atom_type), POINTER :: grid_atom
2949 INTEGER, INTENT(IN) :: l
2950
2951 INTEGER :: i, info, n, nr
2952 INTEGER, ALLOCATABLE, DIMENSION(:) :: ipiv
2953 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: afun
2954 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: smat, v
2955
2956 n = SIZE(ca)
2957 nr = grid_atom%nr
2958 ALLOCATE (smat(n, n), v(n, 1), ipiv(n), afun(nr))
2959
2960 CALL sg_overlap(smat, l, a, a)
2961 DO i = 1, n
2962 afun(:) = grid_atom%rad(:)**l*exp(-a(i)*grid_atom%rad2(:))
2963 v(i, 1) = sum(afun(:)*bfun(:)*grid_atom%wr(:))
2964 END DO
2965 CALL dgesv(n, 1, smat, n, ipiv, v, n, info)
2966 cpassert(info == 0)
2967 ca(:) = v(:, 1)
2968
2969 DEALLOCATE (smat, v, ipiv, afun)
2970
2971 END SUBROUTINE project_function_b
2972
2973! **************************************************************************************************
2974!> \brief Performs printing of cube files from local energy
2975!> \param input input
2976!> \param logger the logger
2977!> \param qs_env the qs_env in which the qs_env lives
2978!> \par History
2979!> 07.2019 created
2980!> \author JGH
2981! **************************************************************************************************
2982 SUBROUTINE qs_scf_post_local_energy(input, logger, qs_env)
2983 TYPE(section_vals_type), POINTER :: input
2984 TYPE(cp_logger_type), POINTER :: logger
2985 TYPE(qs_environment_type), POINTER :: qs_env
2986
2987 CHARACTER(len=*), PARAMETER :: routinen = 'qs_scf_post_local_energy'
2988
2989 CHARACTER(LEN=default_path_length) :: filename, my_pos_cube
2990 INTEGER :: handle, io_unit, natom, unit_nr
2991 LOGICAL :: append_cube, gapw, gapw_xc, mpi_io
2992 TYPE(dft_control_type), POINTER :: dft_control
2993 TYPE(particle_list_type), POINTER :: particles
2994 TYPE(pw_env_type), POINTER :: pw_env
2995 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
2996 TYPE(pw_r3d_rs_type) :: eden
2997 TYPE(qs_subsys_type), POINTER :: subsys
2998 TYPE(section_vals_type), POINTER :: dft_section
2999
3000 CALL timeset(routinen, handle)
3001 io_unit = cp_logger_get_default_io_unit(logger)
3002 IF (btest(cp_print_key_should_output(logger%iter_info, input, &
3003 "DFT%PRINT%LOCAL_ENERGY_CUBE"), cp_p_file)) THEN
3004 dft_section => section_vals_get_subs_vals(input, "DFT")
3005 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control, natom=natom)
3006 gapw = dft_control%qs_control%gapw
3007 gapw_xc = dft_control%qs_control%gapw_xc
3008 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env, subsys=subsys)
3009 CALL qs_subsys_get(subsys, particles=particles)
3010 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
3011 CALL auxbas_pw_pool%create_pw(eden)
3012 !
3013 CALL qs_local_energy(qs_env, eden)
3014 !
3015 append_cube = section_get_lval(input, "DFT%PRINT%LOCAL_ENERGY_CUBE%APPEND")
3016 IF (append_cube) THEN
3017 my_pos_cube = "APPEND"
3018 ELSE
3019 my_pos_cube = "REWIND"
3020 END IF
3021 mpi_io = .true.
3022 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%LOCAL_ENERGY_CUBE", &
3023 extension=".cube", middle_name="local_energy", &
3024 file_position=my_pos_cube, mpi_io=mpi_io)
3025 CALL cp_pw_to_cube(eden, &
3026 unit_nr, "LOCAL ENERGY", particles=particles, &
3027 stride=section_get_ivals(dft_section, &
3028 "PRINT%LOCAL_ENERGY_CUBE%STRIDE"), mpi_io=mpi_io)
3029 IF (io_unit > 0) THEN
3030 INQUIRE (unit=unit_nr, name=filename)
3031 IF (gapw .OR. gapw_xc) THEN
3032 WRITE (unit=io_unit, fmt="(/,T3,A,A)") &
3033 "The soft part of the local energy is written to the file: ", trim(adjustl(filename))
3034 ELSE
3035 WRITE (unit=io_unit, fmt="(/,T3,A,A)") &
3036 "The local energy is written to the file: ", trim(adjustl(filename))
3037 END IF
3038 END IF
3039 CALL cp_print_key_finished_output(unit_nr, logger, input, &
3040 "DFT%PRINT%LOCAL_ENERGY_CUBE", mpi_io=mpi_io)
3041 !
3042 CALL auxbas_pw_pool%give_back_pw(eden)
3043 END IF
3044 CALL timestop(handle)
3045
3046 END SUBROUTINE qs_scf_post_local_energy
3047
3048! **************************************************************************************************
3049!> \brief Performs printing of cube files from local energy
3050!> \param input input
3051!> \param logger the logger
3052!> \param qs_env the qs_env in which the qs_env lives
3053!> \par History
3054!> 07.2019 created
3055!> \author JGH
3056! **************************************************************************************************
3057 SUBROUTINE qs_scf_post_local_stress(input, logger, qs_env)
3058 TYPE(section_vals_type), POINTER :: input
3059 TYPE(cp_logger_type), POINTER :: logger
3060 TYPE(qs_environment_type), POINTER :: qs_env
3061
3062 CHARACTER(len=*), PARAMETER :: routinen = 'qs_scf_post_local_stress'
3063
3064 CHARACTER(LEN=default_path_length) :: filename, my_pos_cube
3065 INTEGER :: handle, io_unit, natom, unit_nr
3066 LOGICAL :: append_cube, gapw, gapw_xc, mpi_io
3067 REAL(kind=dp) :: beta
3068 TYPE(dft_control_type), POINTER :: dft_control
3069 TYPE(particle_list_type), POINTER :: particles
3070 TYPE(pw_env_type), POINTER :: pw_env
3071 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
3072 TYPE(pw_r3d_rs_type) :: stress
3073 TYPE(qs_subsys_type), POINTER :: subsys
3074 TYPE(section_vals_type), POINTER :: dft_section
3075
3076 CALL timeset(routinen, handle)
3077 io_unit = cp_logger_get_default_io_unit(logger)
3078 IF (btest(cp_print_key_should_output(logger%iter_info, input, &
3079 "DFT%PRINT%LOCAL_STRESS_CUBE"), cp_p_file)) THEN
3080 dft_section => section_vals_get_subs_vals(input, "DFT")
3081 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control, natom=natom)
3082 gapw = dft_control%qs_control%gapw
3083 gapw_xc = dft_control%qs_control%gapw_xc
3084 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env, subsys=subsys)
3085 CALL qs_subsys_get(subsys, particles=particles)
3086 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
3087 CALL auxbas_pw_pool%create_pw(stress)
3088 !
3089 ! use beta=0: kinetic energy density in symmetric form
3090 beta = 0.0_dp
3091 CALL qs_local_stress(qs_env, beta=beta)
3092 !
3093 append_cube = section_get_lval(input, "DFT%PRINT%LOCAL_STRESS_CUBE%APPEND")
3094 IF (append_cube) THEN
3095 my_pos_cube = "APPEND"
3096 ELSE
3097 my_pos_cube = "REWIND"
3098 END IF
3099 mpi_io = .true.
3100 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%LOCAL_STRESS_CUBE", &
3101 extension=".cube", middle_name="local_stress", &
3102 file_position=my_pos_cube, mpi_io=mpi_io)
3103 CALL cp_pw_to_cube(stress, &
3104 unit_nr, "LOCAL STRESS", particles=particles, &
3105 stride=section_get_ivals(dft_section, &
3106 "PRINT%LOCAL_STRESS_CUBE%STRIDE"), mpi_io=mpi_io)
3107 IF (io_unit > 0) THEN
3108 INQUIRE (unit=unit_nr, name=filename)
3109 WRITE (unit=io_unit, fmt="(/,T3,A)") "Write 1/3*Tr(sigma) to cube file"
3110 IF (gapw .OR. gapw_xc) THEN
3111 WRITE (unit=io_unit, fmt="(T3,A,A)") &
3112 "The soft part of the local stress is written to the file: ", trim(adjustl(filename))
3113 ELSE
3114 WRITE (unit=io_unit, fmt="(T3,A,A)") &
3115 "The local stress is written to the file: ", trim(adjustl(filename))
3116 END IF
3117 END IF
3118 CALL cp_print_key_finished_output(unit_nr, logger, input, &
3119 "DFT%PRINT%LOCAL_STRESS_CUBE", mpi_io=mpi_io)
3120 !
3121 CALL auxbas_pw_pool%give_back_pw(stress)
3122 END IF
3123
3124 CALL timestop(handle)
3125
3126 END SUBROUTINE qs_scf_post_local_stress
3127
3128! **************************************************************************************************
3129!> \brief Performs printing of cube files related to the implicit Poisson solver
3130!> \param input input
3131!> \param logger the logger
3132!> \param qs_env the qs_env in which the qs_env lives
3133!> \par History
3134!> 03.2016 refactored from write_mo_free_results [Hossein Bani-Hashemian]
3135!> \author Mohammad Hossein Bani-Hashemian
3136! **************************************************************************************************
3137 SUBROUTINE qs_scf_post_ps_implicit(input, logger, qs_env)
3138 TYPE(section_vals_type), POINTER :: input
3139 TYPE(cp_logger_type), POINTER :: logger
3140 TYPE(qs_environment_type), POINTER :: qs_env
3141
3142 CHARACTER(len=*), PARAMETER :: routinen = 'qs_scf_post_ps_implicit'
3143
3144 CHARACTER(LEN=default_path_length) :: filename, my_pos_cube
3145 INTEGER :: boundary_condition, handle, i, j, &
3146 n_cstr, n_tiles, unit_nr
3147 LOGICAL :: append_cube, do_cstr_charge_cube, do_dielectric_cube, do_dirichlet_bc_cube, &
3148 has_dirichlet_bc, has_implicit_ps, mpi_io, tile_cubes
3149 TYPE(particle_list_type), POINTER :: particles
3150 TYPE(pw_env_type), POINTER :: pw_env
3151 TYPE(pw_poisson_type), POINTER :: poisson_env
3152 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
3153 TYPE(pw_r3d_rs_type) :: aux_r
3154 TYPE(pw_r3d_rs_type), POINTER :: dirichlet_tile
3155 TYPE(qs_subsys_type), POINTER :: subsys
3156 TYPE(section_vals_type), POINTER :: dft_section
3157
3158 CALL timeset(routinen, handle)
3159
3160 NULLIFY (pw_env, auxbas_pw_pool, dft_section, particles)
3161
3162 dft_section => section_vals_get_subs_vals(input, "DFT")
3163 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env, subsys=subsys)
3164 CALL qs_subsys_get(subsys, particles=particles)
3165 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
3166
3167 has_implicit_ps = .false.
3168 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
3169 IF (pw_env%poisson_env%parameters%solver .EQ. pw_poisson_implicit) has_implicit_ps = .true.
3170
3171 ! Write the dielectric constant into a cube file
3172 do_dielectric_cube = btest(cp_print_key_should_output(logger%iter_info, input, &
3173 "DFT%PRINT%IMPLICIT_PSOLVER%DIELECTRIC_CUBE"), cp_p_file)
3174 IF (has_implicit_ps .AND. do_dielectric_cube) THEN
3175 append_cube = section_get_lval(input, "DFT%PRINT%IMPLICIT_PSOLVER%DIELECTRIC_CUBE%APPEND")
3176 my_pos_cube = "REWIND"
3177 IF (append_cube) THEN
3178 my_pos_cube = "APPEND"
3179 END IF
3180 mpi_io = .true.
3181 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%IMPLICIT_PSOLVER%DIELECTRIC_CUBE", &
3182 extension=".cube", middle_name="DIELECTRIC_CONSTANT", file_position=my_pos_cube, &
3183 mpi_io=mpi_io)
3184 CALL pw_env_get(pw_env, poisson_env=poisson_env, auxbas_pw_pool=auxbas_pw_pool)
3185 CALL auxbas_pw_pool%create_pw(aux_r)
3186
3187 boundary_condition = pw_env%poisson_env%parameters%ps_implicit_params%boundary_condition
3188 SELECT CASE (boundary_condition)
3190 CALL pw_copy(poisson_env%implicit_env%dielectric%eps, aux_r)
3191 CASE (mixed_bc, neumann_bc)
3192 CALL pw_shrink(pw_env%poisson_env%parameters%ps_implicit_params%neumann_directions, &
3193 pw_env%poisson_env%implicit_env%dct_env%dests_shrink, &
3194 pw_env%poisson_env%implicit_env%dct_env%srcs_shrink, &
3195 pw_env%poisson_env%implicit_env%dct_env%bounds_local_shftd, &
3196 poisson_env%implicit_env%dielectric%eps, aux_r)
3197 END SELECT
3198
3199 CALL cp_pw_to_cube(aux_r, unit_nr, "DIELECTRIC CONSTANT", particles=particles, &
3200 stride=section_get_ivals(dft_section, "PRINT%IMPLICIT_PSOLVER%DIELECTRIC_CUBE%STRIDE"), &
3201 mpi_io=mpi_io)
3202 CALL cp_print_key_finished_output(unit_nr, logger, input, &
3203 "DFT%PRINT%IMPLICIT_PSOLVER%DIELECTRIC_CUBE", mpi_io=mpi_io)
3204
3205 CALL auxbas_pw_pool%give_back_pw(aux_r)
3206 END IF
3207
3208 ! Write Dirichlet constraint charges into a cube file
3209 do_cstr_charge_cube = btest(cp_print_key_should_output(logger%iter_info, input, &
3210 "DFT%PRINT%IMPLICIT_PSOLVER%DIRICHLET_CSTR_CHARGE_CUBE"), cp_p_file)
3211
3212 has_dirichlet_bc = .false.
3213 IF (has_implicit_ps) THEN
3214 boundary_condition = pw_env%poisson_env%parameters%ps_implicit_params%boundary_condition
3215 IF (boundary_condition .EQ. mixed_periodic_bc .OR. boundary_condition .EQ. mixed_bc) THEN
3216 has_dirichlet_bc = .true.
3217 END IF
3218 END IF
3219
3220 IF (has_implicit_ps .AND. do_cstr_charge_cube .AND. has_dirichlet_bc) THEN
3221 append_cube = section_get_lval(input, &
3222 "DFT%PRINT%IMPLICIT_PSOLVER%DIRICHLET_CSTR_CHARGE_CUBE%APPEND")
3223 my_pos_cube = "REWIND"
3224 IF (append_cube) THEN
3225 my_pos_cube = "APPEND"
3226 END IF
3227 mpi_io = .true.
3228 unit_nr = cp_print_key_unit_nr(logger, input, &
3229 "DFT%PRINT%IMPLICIT_PSOLVER%DIRICHLET_CSTR_CHARGE_CUBE", &
3230 extension=".cube", middle_name="dirichlet_cstr_charge", file_position=my_pos_cube, &
3231 mpi_io=mpi_io)
3232 CALL pw_env_get(pw_env, poisson_env=poisson_env, auxbas_pw_pool=auxbas_pw_pool)
3233 CALL auxbas_pw_pool%create_pw(aux_r)
3234
3235 boundary_condition = pw_env%poisson_env%parameters%ps_implicit_params%boundary_condition
3236 SELECT CASE (boundary_condition)
3237 CASE (mixed_periodic_bc)
3238 CALL pw_copy(poisson_env%implicit_env%cstr_charge, aux_r)
3239 CASE (mixed_bc)
3240 CALL pw_shrink(pw_env%poisson_env%parameters%ps_implicit_params%neumann_directions, &
3241 pw_env%poisson_env%implicit_env%dct_env%dests_shrink, &
3242 pw_env%poisson_env%implicit_env%dct_env%srcs_shrink, &
3243 pw_env%poisson_env%implicit_env%dct_env%bounds_local_shftd, &
3244 poisson_env%implicit_env%cstr_charge, aux_r)
3245 END SELECT
3246
3247 CALL cp_pw_to_cube(aux_r, unit_nr, "DIRICHLET CONSTRAINT CHARGE", particles=particles, &
3248 stride=section_get_ivals(dft_section, "PRINT%IMPLICIT_PSOLVER%DIRICHLET_CSTR_CHARGE_CUBE%STRIDE"), &
3249 mpi_io=mpi_io)
3250 CALL cp_print_key_finished_output(unit_nr, logger, input, &
3251 "DFT%PRINT%IMPLICIT_PSOLVER%DIRICHLET_CSTR_CHARGE_CUBE", mpi_io=mpi_io)
3252
3253 CALL auxbas_pw_pool%give_back_pw(aux_r)
3254 END IF
3255
3256 ! Write Dirichlet type constranits into cube files
3257 do_dirichlet_bc_cube = btest(cp_print_key_should_output(logger%iter_info, input, &
3258 "DFT%PRINT%IMPLICIT_PSOLVER%DIRICHLET_BC_CUBE"), cp_p_file)
3259 has_dirichlet_bc = .false.
3260 IF (has_implicit_ps) THEN
3261 boundary_condition = pw_env%poisson_env%parameters%ps_implicit_params%boundary_condition
3262 IF (boundary_condition .EQ. mixed_periodic_bc .OR. boundary_condition .EQ. mixed_bc) THEN
3263 has_dirichlet_bc = .true.
3264 END IF
3265 END IF
3266
3267 IF (has_implicit_ps .AND. has_dirichlet_bc .AND. do_dirichlet_bc_cube) THEN
3268 append_cube = section_get_lval(input, "DFT%PRINT%IMPLICIT_PSOLVER%DIRICHLET_BC_CUBE%APPEND")
3269 my_pos_cube = "REWIND"
3270 IF (append_cube) THEN
3271 my_pos_cube = "APPEND"
3272 END IF
3273 tile_cubes = section_get_lval(input, "DFT%PRINT%IMPLICIT_PSOLVER%DIRICHLET_BC_CUBE%TILE_CUBES")
3274
3275 CALL pw_env_get(pw_env, poisson_env=poisson_env, auxbas_pw_pool=auxbas_pw_pool)
3276 CALL auxbas_pw_pool%create_pw(aux_r)
3277 CALL pw_zero(aux_r)
3278
3279 IF (tile_cubes) THEN
3280 ! one cube file per tile
3281 n_cstr = SIZE(poisson_env%implicit_env%contacts)
3282 DO j = 1, n_cstr
3283 n_tiles = poisson_env%implicit_env%contacts(j)%dirichlet_bc%n_tiles
3284 DO i = 1, n_tiles
3285 filename = "dirichlet_cstr_"//trim(adjustl(cp_to_string(j)))// &
3286 "_tile_"//trim(adjustl(cp_to_string(i)))
3287 mpi_io = .true.
3288 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%IMPLICIT_PSOLVER%DIRICHLET_BC_CUBE", &
3289 extension=".cube", middle_name=filename, file_position=my_pos_cube, &
3290 mpi_io=mpi_io)
3291
3292 CALL pw_copy(poisson_env%implicit_env%contacts(j)%dirichlet_bc%tiles(i)%tile%tile_pw, aux_r)
3293
3294 CALL cp_pw_to_cube(aux_r, unit_nr, "DIRICHLET TYPE CONSTRAINT", particles=particles, &
3295 stride=section_get_ivals(dft_section, "PRINT%IMPLICIT_PSOLVER%DIRICHLET_BC_CUBE%STRIDE"), &
3296 mpi_io=mpi_io)
3297 CALL cp_print_key_finished_output(unit_nr, logger, input, &
3298 "DFT%PRINT%IMPLICIT_PSOLVER%DIRICHLET_BC_CUBE", mpi_io=mpi_io)
3299 END DO
3300 END DO
3301 ELSE
3302 ! a single cube file
3303 NULLIFY (dirichlet_tile)
3304 ALLOCATE (dirichlet_tile)
3305 CALL auxbas_pw_pool%create_pw(dirichlet_tile)
3306 CALL pw_zero(dirichlet_tile)
3307 mpi_io = .true.
3308 unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%IMPLICIT_PSOLVER%DIRICHLET_BC_CUBE", &
3309 extension=".cube", middle_name="DIRICHLET_CSTR", file_position=my_pos_cube, &
3310 mpi_io=mpi_io)
3311
3312 n_cstr = SIZE(poisson_env%implicit_env%contacts)
3313 DO j = 1, n_cstr
3314 n_tiles = poisson_env%implicit_env%contacts(j)%dirichlet_bc%n_tiles
3315 DO i = 1, n_tiles
3316 CALL pw_copy(poisson_env%implicit_env%contacts(j)%dirichlet_bc%tiles(i)%tile%tile_pw, dirichlet_tile)
3317 CALL pw_axpy(dirichlet_tile, aux_r)
3318 END DO
3319 END DO
3320
3321 CALL cp_pw_to_cube(aux_r, unit_nr, "DIRICHLET TYPE CONSTRAINT", particles=particles, &
3322 stride=section_get_ivals(dft_section, "PRINT%IMPLICIT_PSOLVER%DIRICHLET_BC_CUBE%STRIDE"), &
3323 mpi_io=mpi_io)
3324 CALL cp_print_key_finished_output(unit_nr, logger, input, &
3325 "DFT%PRINT%IMPLICIT_PSOLVER%DIRICHLET_BC_CUBE", mpi_io=mpi_io)
3326 CALL auxbas_pw_pool%give_back_pw(dirichlet_tile)
3327 DEALLOCATE (dirichlet_tile)
3328 END IF
3329
3330 CALL auxbas_pw_pool%give_back_pw(aux_r)
3331 END IF
3332
3333 CALL timestop(handle)
3334
3335 END SUBROUTINE qs_scf_post_ps_implicit
3336
3337!**************************************************************************************************
3338!> \brief write an adjacency (interaction) matrix
3339!> \param qs_env qs environment
3340!> \param input the input
3341!> \author Mohammad Hossein Bani-Hashemian
3342! **************************************************************************************************
3343 SUBROUTINE write_adjacency_matrix(qs_env, input)
3344 TYPE(qs_environment_type), POINTER :: qs_env
3345 TYPE(section_vals_type), POINTER :: input
3346
3347 CHARACTER(len=*), PARAMETER :: routinen = 'write_adjacency_matrix'
3348
3349 INTEGER :: adjm_size, colind, handle, iatom, ikind, &
3350 ind, jatom, jkind, k, natom, nkind, &
3351 output_unit, rowind, unit_nr
3352 INTEGER, ALLOCATABLE, DIMENSION(:) :: interact_adjm
3353 LOGICAL :: do_adjm_write, do_symmetric
3354 TYPE(cp_logger_type), POINTER :: logger
3355 TYPE(gto_basis_set_p_type), DIMENSION(:), POINTER :: basis_set_list_a, basis_set_list_b
3356 TYPE(gto_basis_set_type), POINTER :: basis_set_a, basis_set_b
3357 TYPE(mp_para_env_type), POINTER :: para_env
3359 DIMENSION(:), POINTER :: nl_iterator
3360 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
3361 POINTER :: nl
3362 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
3363 TYPE(section_vals_type), POINTER :: dft_section
3364
3365 CALL timeset(routinen, handle)
3366
3367 NULLIFY (dft_section)
3368
3369 logger => cp_get_default_logger()
3370 output_unit = cp_logger_get_default_io_unit(logger)
3371
3372 dft_section => section_vals_get_subs_vals(input, "DFT")
3373 do_adjm_write = btest(cp_print_key_should_output(logger%iter_info, dft_section, &
3374 "PRINT%ADJMAT_WRITE"), cp_p_file)
3375
3376 IF (do_adjm_write) THEN
3377 NULLIFY (qs_kind_set, nl_iterator)
3378 NULLIFY (basis_set_list_a, basis_set_list_b, basis_set_a, basis_set_b)
3379
3380 CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set, sab_orb=nl, natom=natom, para_env=para_env)
3381
3382 nkind = SIZE(qs_kind_set)
3383 cpassert(SIZE(nl) .GT. 0)
3384 CALL get_neighbor_list_set_p(neighbor_list_sets=nl, symmetric=do_symmetric)
3385 cpassert(do_symmetric)
3386 ALLOCATE (basis_set_list_a(nkind), basis_set_list_b(nkind))
3387 CALL basis_set_list_setup(basis_set_list_a, "ORB", qs_kind_set)
3388 CALL basis_set_list_setup(basis_set_list_b, "ORB", qs_kind_set)
3389
3390 adjm_size = ((natom + 1)*natom)/2
3391 ALLOCATE (interact_adjm(4*adjm_size))
3392 interact_adjm = 0
3393
3394 NULLIFY (nl_iterator)
3395 CALL neighbor_list_iterator_create(nl_iterator, nl)
3396 DO WHILE (neighbor_list_iterate(nl_iterator) .EQ. 0)
3397 CALL get_iterator_info(nl_iterator, &
3398 ikind=ikind, jkind=jkind, &
3399 iatom=iatom, jatom=jatom)
3400
3401 basis_set_a => basis_set_list_a(ikind)%gto_basis_set
3402 IF (.NOT. ASSOCIATED(basis_set_a)) cycle
3403 basis_set_b => basis_set_list_b(jkind)%gto_basis_set
3404 IF (.NOT. ASSOCIATED(basis_set_b)) cycle
3405
3406 ! move everything to the upper triangular part
3407 IF (iatom .LE. jatom) THEN
3408 rowind = iatom
3409 colind = jatom
3410 ELSE
3411 rowind = jatom
3412 colind = iatom
3413 ! swap the kinds too
3414 ikind = ikind + jkind
3415 jkind = ikind - jkind
3416 ikind = ikind - jkind
3417 END IF
3418
3419 ! indexing upper triangular matrix
3420 ind = adjm_size - (natom - rowind + 1)*((natom - rowind + 1) + 1)/2 + colind - rowind + 1
3421 ! convert the upper triangular matrix into a adjm_size x 4 matrix
3422 ! columns are: iatom, jatom, ikind, jkind
3423 interact_adjm((ind - 1)*4 + 1) = rowind
3424 interact_adjm((ind - 1)*4 + 2) = colind
3425 interact_adjm((ind - 1)*4 + 3) = ikind
3426 interact_adjm((ind - 1)*4 + 4) = jkind
3427 END DO
3428
3429 CALL para_env%sum(interact_adjm)
3430
3431 unit_nr = cp_print_key_unit_nr(logger, dft_section, "PRINT%ADJMAT_WRITE", &
3432 extension=".adjmat", file_form="FORMATTED", &
3433 file_status="REPLACE")
3434 IF (unit_nr .GT. 0) THEN
3435 WRITE (unit_nr, "(1A,2X,1A,5X,1A,4X,A5,3X,A5)") "#", "iatom", "jatom", "ikind", "jkind"
3436 DO k = 1, 4*adjm_size, 4
3437 ! print only the interacting atoms
3438 IF (interact_adjm(k) .GT. 0 .AND. interact_adjm(k + 1) .GT. 0) THEN
3439 WRITE (unit_nr, "(I8,2X,I8,3X,I6,2X,I6)") interact_adjm(k:k + 3)
3440 END IF
3441 END DO
3442 END IF
3443
3444 CALL cp_print_key_finished_output(unit_nr, logger, dft_section, "PRINT%ADJMAT_WRITE")
3445
3446 CALL neighbor_list_iterator_release(nl_iterator)
3447 DEALLOCATE (basis_set_list_a, basis_set_list_b)
3448 END IF
3449
3450 CALL timestop(handle)
3451
3452 END SUBROUTINE write_adjacency_matrix
3453
3454! **************************************************************************************************
3455!> \brief Updates Hartree potential with MP2 density. Important for REPEAT charges
3456!> \param rho ...
3457!> \param qs_env ...
3458!> \author Vladimir Rybkin
3459! **************************************************************************************************
3460 SUBROUTINE update_hartree_with_mp2(rho, qs_env)
3461 TYPE(qs_rho_type), POINTER :: rho
3462 TYPE(qs_environment_type), POINTER :: qs_env
3463
3464 LOGICAL :: use_virial
3465 TYPE(pw_c1d_gs_type) :: rho_tot_gspace, v_hartree_gspace
3466 TYPE(pw_c1d_gs_type), POINTER :: rho_core
3467 TYPE(pw_env_type), POINTER :: pw_env
3468 TYPE(pw_poisson_type), POINTER :: poisson_env
3469 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
3470 TYPE(pw_r3d_rs_type), POINTER :: v_hartree_rspace
3471 TYPE(qs_energy_type), POINTER :: energy
3472 TYPE(virial_type), POINTER :: virial
3473
3474 NULLIFY (auxbas_pw_pool, pw_env, poisson_env, energy, rho_core, v_hartree_rspace, virial)
3475 CALL get_qs_env(qs_env, pw_env=pw_env, energy=energy, &
3476 rho_core=rho_core, virial=virial, &
3477 v_hartree_rspace=v_hartree_rspace)
3478
3479 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
3480
3481 IF (.NOT. use_virial) THEN
3482
3483 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
3484 poisson_env=poisson_env)
3485 CALL auxbas_pw_pool%create_pw(v_hartree_gspace)
3486 CALL auxbas_pw_pool%create_pw(rho_tot_gspace)
3487
3488 CALL calc_rho_tot_gspace(rho_tot_gspace, qs_env, rho)
3489 CALL pw_poisson_solve(poisson_env, rho_tot_gspace, energy%hartree, &
3490 v_hartree_gspace, rho_core=rho_core)
3491
3492 CALL pw_transfer(v_hartree_gspace, v_hartree_rspace)
3493 CALL pw_scale(v_hartree_rspace, v_hartree_rspace%pw_grid%dvol)
3494
3495 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
3496 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
3497 END IF
3498
3499 END SUBROUTINE update_hartree_with_mp2
3500
3501END MODULE qs_scf_post_gpw
static double norm_factor(double alpha, int L)
Types and set/get functions for auxiliary density matrix methods.
Definition admm_types.F:15
Contains methods used in the context of density fitting.
Definition admm_utils.F:15
subroutine, public admm_uncorrect_for_eigenvalues(ispin, admm_env, ks_matrix)
...
Definition admm_utils.F:127
subroutine, public admm_correct_for_eigenvalues(ispin, admm_env, ks_matrix)
...
Definition admm_utils.F:53
subroutine, public sg_overlap(smat, l, pa, pb)
...
calculate the orbitals for a given atomic kind type
subroutine, public calculate_atomic_density(density, atomic_kind, qs_kind, ngto, iunit, optbasis, allelectron, confine)
...
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_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
DBCSR output in CP2K.
subroutine, public cp_dbcsr_write_sparse_matrix(sparse_matrix, before, after, qs_env, para_env, first_row, last_row, first_col, last_col, scale, output_unit, omit_headers)
...
Density Derived atomic point charges from a QM calculation (see Bloechl, J. Chem. Phys....
recursive subroutine, public get_ddapc(qs_env, calc_force, density_fit_section, density_type, qout1, qout2, out_radii, dq_out, ext_rho_tot_g, itype_of_density, iwc)
Computes the Density Derived Atomic Point Charges.
used for collecting some of the diagonalization schemes available for cp_fm_type. cp_fm_power also mo...
Definition cp_fm_diag.F:17
subroutine, public choose_eigv_solver(matrix, eigenvectors, eigenvalues, info)
Choose the Eigensolver depending on which library is available ELPA seems to be unstable for small sy...
Definition cp_fm_diag.F:229
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_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_init_random(matrix, ncol, start_col)
fills a matrix with random numbers
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp)
creates a new full matrix with the given structure
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
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
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...
A wrapper around pw_to_cube() which accepts particle_list_type.
subroutine, public cp_pw_to_cube(pw, unit_nr, title, particles, stride, zero_tails, silent, mpi_io)
...
the type I Discrete Cosine Transform (DCT-I)
Definition dct.F:16
subroutine, public pw_shrink(neumann_directions, dests_shrink, srcs_shrink, bounds_local_shftd, pw_in, pw_shrinked)
shrinks an evenly symmetric pw_r3d_rs_type data to a pw_r3d_rs_type data that is 8 times smaller (the...
Definition dct.F:700
Calculate Energy Decomposition analysis.
Definition ed_analysis.F:14
subroutine, public edmf_analysis(qs_env, input_section, unit_nr)
...
Calculation of charge equilibration method.
Definition eeq_method.F:12
subroutine, public eeq_print(qs_env, iounit, print_level, ext)
...
Definition eeq_method.F:124
Definition and initialisation of the et_coupling data type.
subroutine, public set_et_coupling_type(et_coupling, et_mo_coeff, rest_mat)
...
RI-methods for HFX.
Definition hfx_ri.F:12
subroutine, public print_ri_hfx(ri_data, qs_env)
Print RI-HFX quantities, as required by the PRINT subsection.
Definition hfx_ri.F:3627
Calculate Hirshfeld charges and related functions.
subroutine, public comp_hirshfeld_charges(qs_env, hirshfeld_env, charges)
...
subroutine, public create_shape_function(hirshfeld_env, qs_kind_set, atomic_kind_set, radius, radii_list)
creates kind specific shape functions for Hirshfeld charges
subroutine, public write_hirshfeld_charges(charges, hirshfeld_env, particle_set, qs_kind_set, unit_nr)
...
subroutine, public comp_hirshfeld_i_charges(qs_env, hirshfeld_env, charges, ounit)
...
subroutine, public save_hirshfeld_charges(charges, particle_set, qs_kind_set, qs_env)
saves the Hirshfeld charges to the results structure
The types needed for the calculation of Hirshfeld charges and related functions.
subroutine, public create_hirshfeld_type(hirshfeld_env)
...
subroutine, public set_hirshfeld_info(hirshfeld_env, shape_function_type, iterative, ref_charge, fnorm, radius_type, use_bohr)
Set values of a Hirshfeld env.
subroutine, public release_hirshfeld_type(hirshfeld_env)
...
Calculate intrinsic atomic orbitals and analyze wavefunctions.
subroutine, public iao_wfn_analysis(qs_env, iao_env, unit_nr, c_iao_coef, mos, bond_centers)
...
Calculate ntrinsic atomic orbitals and analyze wavefunctions.
Definition iao_types.F:14
subroutine, public iao_read_input(iao_env, iao_section, cell)
...
Definition iao_types.F:116
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_loc_jacobi
integer, parameter, public ref_charge_atomic
integer, parameter, public do_loc_mixed
integer, parameter, public do_loc_none
integer, parameter, public do_loc_lumo
integer, parameter, public radius_user
integer, parameter, public radius_covalent
integer, parameter, public ref_charge_mulliken
integer, parameter, public do_loc_homo
integer, parameter, public do_mixed
integer, parameter, public do_loc_both
integer, parameter, public ot_precond_full_all
objects that represent the structure of input sections and the data contained in an input section
real(kind=dp) function, public section_get_rval(section_vals, keyword_name)
...
integer function, dimension(:), pointer, public section_get_ivals(section_vals, keyword_name)
...
integer function, public section_get_ival(section_vals, keyword_name)
...
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
subroutine, public section_vals_get(section_vals, ref_count, n_repetition, n_subs_vals_rep, section, explicit)
returns various attributes about the section_vals
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
logical function, public section_get_lval(section_vals, keyword_name)
...
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
integer, parameter, public default_path_length
Definition kinds.F:58
Types and basic routines needed for a kpoint calculation.
An array-based list which grows on demand. When the internal array is full, a new array of twice the ...
Definition list.F:24
Calculate MAO's and analyze wavefunctions.
subroutine, public mao_analysis(qs_env, input_section, unit_nr)
...
Definition of mathematical constants and functions.
real(kind=dp), parameter, public pi
Utility routines for the memory handling.
Interface to the message passing library MPI.
Calculate localized minimal basis and analyze wavefunctions.
subroutine, public minbas_analysis(qs_env, input_section, unit_nr)
...
Functions handling the MOLDEN format. Split from mode_selective.
subroutine, public write_mos_molden(mos, qs_kind_set, particle_set, print_section)
Write out the MOs in molden format for visualisation.
Define the data structure for the molecule information.
compute mulliken charges we (currently) define them as c_i = 1/2 [ (PS)_{ii} + (SP)_{ii} ]
Definition mulliken.F:13
Provides Cartesian and spherical orbital pointers and indices.
integer, dimension(:, :), allocatable, public indso
represent a simple array based list of the given type
Define the data structure for the particle information.
Definition of physical constants:
Definition physcon.F:68
real(kind=dp), parameter, public evolt
Definition physcon.F:183
real(kind=dp), parameter, public angstrom
Definition physcon.F:144
Provide various population analyses and print the requested output information.
subroutine, public lowdin_population_analysis(qs_env, output_unit, print_level)
Perform a Lowdin population analysis based on a symmetric orthogonalisation of the density matrix usi...
subroutine, public mulliken_population_analysis(qs_env, output_unit, print_level)
Perform a Mulliken population analysis.
types of preconditioners
computes preconditioners, and implements methods to apply them currently used in qs_ot
Types containing essential information for running implicit (iterative) Poisson solver.
integer, parameter, public neumann_bc
integer, parameter, public mixed_bc
integer, parameter, public mixed_periodic_bc
integer, parameter, public periodic_bc
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
This module defines the grid data type and some basic operations on it.
Definition pw_grids.F:36
subroutine, public get_pw_grid_info(pw_grid, id_nr, mode, vol, dvol, npts, ngpts, ngpts_cut, dr, cutoff, orthorhombic, gvectors, gsquare)
Access to information stored in the pw_grid_type.
Definition pw_grids.F:185
subroutine, public pw_derive(pw, n)
Calculate the derivative of a plane wave vector.
functions related to the poisson solver on regular grids
integer, parameter, public pw_poisson_implicit
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Write wfx file, works as interface to chargemol and multiwfn.
subroutine, public write_wfx(qs_env, dft_section)
...
Calculate the plane wave density by collocating the primitive Gaussian functions (pgf).
subroutine, public calculate_wavefunction(mo_vectors, ivector, rho, rho_gspace, atomic_kind_set, qs_kind_set, cell, dft_control, particle_set, pw_env, basis_type)
maps a given wavefunction on the grid
Calculation of commutator [H,r] matrices.
subroutine, public build_com_hr_matrix(qs_env, matrix_hr)
Calculation of the [H,r] commutators matrices over Cartesian Gaussian functions.
Calculation of the energies concerning the core charge distribution.
Calculation and writing of density of states.
Definition qs_dos.F:14
subroutine, public calculate_dos(mos, dft_section)
Compute and write density of states.
Definition qs_dos.F:59
subroutine, public calculate_dos_kp(qs_env, dft_section)
Compute and write density of states (kpoints)
Definition qs_dos.F:206
Calculates electric field gradients H.M. Petrili, P.E. Blochl, P. Blaha, K. Schwarz,...
subroutine, public qs_efg_calc(qs_env)
...
Does all kind of post scf calculations for GPW/GAPW.
subroutine, public qs_elf_calc(qs_env, elf_r, rho_cutoff)
...
Does all kind of post scf calculations for GPW/GAPW.
subroutine, public energy_windows(qs_env)
...
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, 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)
Get the QUICKSTEP environment.
subroutine, public set_qs_env(qs_env, super_cell, mos, qmmm, qmmm_periodic, ewald_env, ewald_pw, mpools, rho_external, external_vxc, mask, scf_control, rel_control, qs_charges, ks_env, ks_qmmm_env, wf_history, scf_env, active_space, input, oce, rho_atom_set, rho0_atom_set, rho0_mpole, run_rtp, rtp, rhoz_set, rhoz_tot, ecoul_1c, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, efield, linres_control, xas_env, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, ls_scf_env, do_transport, transport_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, harris_env, gcp_env, mp2_env, bs_env, kg_env, force, kpoints, wanniercentres, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs)
Set the QUICKSTEP environment.
Calculates hyperfine values.
Definition qs_epr_hyp.F:15
subroutine, public qs_epr_hyp_calc(qs_env)
...
Definition qs_epr_hyp.F:75
Some utility functions for the calculation of integrals.
subroutine, public basis_set_list_setup(basis_set_list, basis_type, qs_kind_set)
Set up an easy accessible list of the basis sets for all kinds.
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, init_u_ramping_each_scf, reltmat, ghost, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
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 calc_rho_tot_gspace(rho_tot_gspace, qs_env, rho, skip_nuclear_density)
...
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...
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 loc_write_restart(qs_loc_env, section, mo_array, coeff_localized, do_homo, evals, do_mixed)
...
subroutine, public qs_loc_env_init(qs_loc_env, localized_wfn_control, qs_env, myspin, do_localize, loc_coeff, mo_loc_history)
allocates the data, and initializes the operators
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 retain_history(mo_loc_history, mo_loc)
copy old mos to new ones, allocating as necessary
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
Routines for calculating local energy and stress tensor.
subroutine, public qs_local_stress(qs_env, stress_tensor, beta)
Routine to calculate the local stress.
subroutine, public qs_local_energy(qs_env, energy_density)
Routine to calculate the local energy.
Definition and initialisation of the mo data type.
Definition qs_mo_io.F:21
subroutine, public write_dm_binary_restart(mo_array, dft_section, tmpl_matrix)
calculates density matrix from mo set and writes the density matrix into a binary restart file
Definition qs_mo_io.F:170
collects routines that perform operations directly related to MOs
subroutine, public make_mo_eig(mos, nspins, ks_rmpv, scf_control, mo_derivs, admm_env)
Calculate KS eigenvalues starting from OF 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.
Calculates the moment integrals <a|r^m|b> and <a|r x d/dr|b>
Definition qs_moments.F:14
subroutine, public qs_moment_locop(qs_env, magnetic, nmoments, reference, ref_point, unit_number, vel_reprs, com_nl)
...
subroutine, public qs_moment_berry_phase(qs_env, magnetic, nmoments, reference, ref_point, unit_number)
...
Define the neighbor list data types and the corresponding functionality.
subroutine, public neighbor_list_iterator_create(iterator_set, nl, search, nthread)
Neighbor list iterator functions.
subroutine, public neighbor_list_iterator_release(iterator_set)
...
subroutine, public get_neighbor_list_set_p(neighbor_list_sets, nlist, symmetric)
Return the components of the first neighbor list set.
integer function, public neighbor_list_iterate(iterator_set, mepos)
...
subroutine, public get_iterator_info(iterator_set, mepos, ikind, jkind, nkind, ilist, nlist, inode, nnode, iatom, jatom, r, cell)
...
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)
...
Calculation and writing of projected density of states The DOS is computed per angular momentum and p...
Definition qs_pdos.F:15
subroutine, public calculate_projected_dos(mo_set, atomic_kind_set, qs_kind_set, particle_set, qs_env, dft_section, ispin, xas_mittle, external_matrix_shalf)
Compute and write projected density of states.
Definition qs_pdos.F:139
provides a resp fit for gas phase systems
Definition qs_resp.F:16
subroutine, public resp_fit(qs_env)
performs resp fit and generates RESP charges
Definition qs_resp.F:132
subroutine, public get_rho0_mpole(rho0_mpole, g0_h, vg0_h, iat, ikind, lmax_0, l0_ikind, mp_gau_ikind, mp_rho, norm_g0l_h, qlm_gg, qlm_car, qlm_tot, zet0_h, igrid_zet0_s, rpgf0_h, rpgf0_s, max_rpgf0_s, rho0_s_rs, rho0_s_gs)
...
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...
Functions to print the KS and S matrix in the CSR format to file.
subroutine, public write_s_matrix_csr(qs_env, input)
writing the overlap matrix in csr format into a file
subroutine, public write_ks_matrix_csr(qs_env, input)
writing the KS matrix in csr format into a file
subroutine, public qs_scf_write_mos(qs_env, scf_env, final_mos)
Write the MO eigenvector, eigenvalues, and occupation numbers to the output unit.
Does all kind of post scf calculations for GPW/GAPW.
subroutine, public make_lumo_gpw(qs_env, scf_env, unoccupied_orbs, unoccupied_evals, nlumo, nlumos)
Gets the lumos, and eigenvalues for the lumos.
subroutine, public write_mo_free_results(qs_env)
Write QS results always available (if switched on through the print_keys) Can be called from ls_scf.
subroutine, public qs_scf_post_moments(input, logger, qs_env, output_unit)
Computes and prints electric moments.
subroutine, public write_mo_dependent_results(qs_env, scf_env)
Write QS results available if MO's are present (if switched on through the print_keys) Writes only MO...
subroutine, public scf_post_calculation_gpw(qs_env, wf_type, do_mp2)
collects possible post - scf calculations and prints info / computes properties.
module that contains the definitions of the scf types
integer, parameter, public ot_method_nr
Does all kind of post scf calculations for GPW/GAPW.
subroutine, public wfn_mix(mos, particle_set, dft_section, qs_kind_set, para_env, output_unit, unoccupied_orbs, scf_env, matrix_s, marked_states, for_rtp)
writes a new 'mixed' set of mos to restart file, without touching the current MOs
types that represent a quickstep subsys
subroutine, public qs_subsys_get(subsys, atomic_kinds, atomic_kind_set, particles, particle_set, local_particles, molecules, molecule_set, molecule_kinds, molecule_kind_set, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, natom, nparticle, ncore, nshell, nkind, atprop, virial, results, cell, cell_ref, use_ref_cell, energy, force, qs_kind_set, cp_subsys, nelectron_total, nelectron_spin)
...
Interface to Wannier90 code.
subroutine, public wannier90_interface(input, logger, qs_env)
...
Methods related to (\cal S)^2 (i.e. spin)
subroutine, public compute_s_square(mos, matrix_s, s_square, s_square_ideal, mo_derivs, strength)
Compute the expectation value <(\cal S)^2> of the single determinant defined by the spin up (alpha) a...
parameters that control an scf iteration
Calculation of STM image as post processing of an electronic structure calculation,...
Definition stm_images.F:15
subroutine, public th_stm_image(qs_env, stm_section, particles, unoccupied_orbs, unoccupied_evals)
Driver for the calculation of STM image, as post processing of a ground-state electronic structure ca...
Definition stm_images.F:90
routines for DFT+NEGF calculations (coupling with the quantum transport code OMEN)
Definition transport.F:19
subroutine, public qs_scf_post_transport(qs_env)
post scf calculations for transport
Definition transport.F:747
The module to read/write TREX IO files for interfacing CP2K with other programs.
subroutine, public write_trexio(qs_env, trexio_section, energy_derivative)
Write a trexio file.
Interface for Voronoi Integration and output of BQB files.
subroutine, public entry_voronoi_or_bqb(do_voro, do_bqb, input_voro, input_bqb, unit_voro, qs_env, rspace_pw)
Does a Voronoi integration of density or stores the density to compressed BQB format.
subroutine, public xray_diffraction_spectrum(qs_env, unit_number, q_max)
Calculate the coherent X-ray diffraction spectrum using the total electronic density in reciprocal sp...
subroutine, public calculate_rhotot_elec_gspace(qs_env, auxbas_pw_pool, rhotot_elec_gspace, q_max, rho_hard, rho_soft, fsign)
The total electronic density in reciprocal space (g-space) is calculated.
stores some data used in wavefunction fitting
Definition admm_types.F:120
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Definition cell_types.F:55
represent a pointer to a 1d array
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
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...
quantities needed for a Hirshfeld based partitioning of real space
Contains information about kpoints.
stores all the informations relevant to an mpi environment
contained for different pw related things
environment for the poisson solver
to create arrays of pools
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Provides all information about a quickstep kind.
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.