Line data Source code
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 DFTB
10 : !> \par History
11 : !> Started as a copy from the GPW file
12 : !> - Revise MO information printout (10.05.2021, MK)
13 : !> \author JHU (03.2013)
14 : ! **************************************************************************************************
15 : MODULE qs_scf_post_tb
16 : USE atomic_kind_types, ONLY: atomic_kind_type,&
17 : get_atomic_kind
18 : USE cell_types, ONLY: cell_type,&
19 : pbc
20 : USE cp_array_utils, ONLY: cp_1d_r_p_type
21 : USE cp_blacs_env, ONLY: cp_blacs_env_type
22 : USE cp_control_types, ONLY: dft_control_type
23 : USE cp_dbcsr_api, ONLY: dbcsr_p_type,&
24 : dbcsr_type
25 : USE cp_dbcsr_operations, ONLY: copy_dbcsr_to_fm
26 : USE cp_dbcsr_output, ONLY: cp_dbcsr_write_sparse_matrix
27 : USE cp_fm_cholesky, ONLY: cp_fm_cholesky_decompose,&
28 : cp_fm_cholesky_reduce,&
29 : cp_fm_cholesky_restore
30 : USE cp_fm_diag, ONLY: choose_eigv_solver
31 : USE cp_fm_struct, ONLY: cp_fm_struct_create,&
32 : cp_fm_struct_release,&
33 : cp_fm_struct_type
34 : USE cp_fm_types, ONLY: cp_fm_create,&
35 : cp_fm_get_info,&
36 : cp_fm_init_random,&
37 : cp_fm_release,&
38 : cp_fm_to_fm_submat,&
39 : cp_fm_type
40 : USE cp_log_handling, ONLY: cp_get_default_logger,&
41 : cp_logger_get_default_io_unit,&
42 : cp_logger_type
43 : USE cp_output_handling, ONLY: cp_p_file,&
44 : cp_print_key_finished_output,&
45 : cp_print_key_should_output,&
46 : cp_print_key_unit_nr
47 : USE cp_realspace_grid_cube, ONLY: cp_pw_to_cube
48 : USE cp_result_methods, ONLY: cp_results_erase,&
49 : put_results
50 : USE cp_result_types, ONLY: cp_result_type
51 : USE eeq_method, ONLY: eeq_print
52 : USE input_constants, ONLY: ot_precond_full_all
53 : USE input_section_types, ONLY: section_get_ival,&
54 : section_get_ivals,&
55 : section_get_lval,&
56 : section_get_rval,&
57 : section_vals_get,&
58 : section_vals_get_subs_vals,&
59 : section_vals_type,&
60 : section_vals_val_get
61 : USE kinds, ONLY: default_path_length,&
62 : default_string_length,&
63 : dp
64 : USE machine, ONLY: m_flush
65 : USE mathconstants, ONLY: twopi,&
66 : z_one,&
67 : z_zero
68 : USE memory_utilities, ONLY: reallocate
69 : USE message_passing, ONLY: mp_para_env_type
70 : USE molden_utils, ONLY: write_mos_molden
71 : USE moments_utils, ONLY: get_reference_point
72 : USE mulliken, ONLY: mulliken_charges
73 : USE particle_list_types, ONLY: particle_list_type
74 : USE particle_types, ONLY: particle_type
75 : USE physcon, ONLY: debye
76 : USE population_analyses, ONLY: lowdin_population_analysis
77 : USE preconditioner_types, ONLY: preconditioner_type
78 : USE pw_env_methods, ONLY: pw_env_create,&
79 : pw_env_rebuild
80 : USE pw_env_types, ONLY: pw_env_get,&
81 : pw_env_release,&
82 : pw_env_type
83 : USE pw_grid_types, ONLY: pw_grid_type
84 : USE pw_methods, ONLY: pw_axpy,&
85 : pw_copy,&
86 : pw_derive,&
87 : pw_scale,&
88 : pw_transfer,&
89 : pw_zero
90 : USE pw_poisson_types, ONLY: do_ewald_none,&
91 : greens_fn_type,&
92 : pw_green_create,&
93 : pw_green_release,&
94 : pw_poisson_analytic,&
95 : pw_poisson_parameter_type
96 : USE pw_pool_types, ONLY: pw_pool_p_type,&
97 : pw_pool_type
98 : USE pw_types, ONLY: pw_c1d_gs_type,&
99 : pw_r3d_rs_type
100 : USE qs_collocate_density, ONLY: calculate_rho_core,&
101 : calculate_rho_elec,&
102 : calculate_wavefunction
103 : USE qs_dftb_types, ONLY: qs_dftb_atom_type
104 : USE qs_dftb_utils, ONLY: get_dftb_atom_param
105 : USE qs_dos, ONLY: calculate_dos,&
106 : calculate_dos_kp
107 : USE qs_elf_methods, ONLY: qs_elf_calc
108 : USE qs_energy_window, ONLY: energy_windows
109 : USE qs_environment_types, ONLY: get_qs_env,&
110 : qs_environment_type
111 : USE qs_kind_types, ONLY: get_qs_kind,&
112 : qs_kind_type
113 : USE qs_ks_types, ONLY: get_ks_env,&
114 : qs_ks_env_type,&
115 : set_ks_env
116 : USE qs_mo_methods, ONLY: calculate_subspace_eigenvalues,&
117 : make_mo_eig
118 : USE qs_mo_occupation, ONLY: set_mo_occupation
119 : USE qs_mo_types, ONLY: get_mo_set,&
120 : mo_set_type
121 : USE qs_ot_eigensolver, ONLY: ot_eigensolver
122 : USE qs_pdos, ONLY: calculate_projected_dos
123 : USE qs_rho_methods, ONLY: qs_rho_rebuild
124 : USE qs_rho_types, ONLY: qs_rho_get,&
125 : qs_rho_set,&
126 : qs_rho_type
127 : USE qs_scf_csr_write, ONLY: write_hcore_matrix_csr,&
128 : write_ks_matrix_csr,&
129 : write_p_matrix_csr,&
130 : write_s_matrix_csr
131 : USE qs_scf_output, ONLY: qs_scf_write_mos
132 : USE qs_scf_types, ONLY: ot_method_nr,&
133 : qs_scf_env_type
134 : USE qs_scf_wfn_mix, ONLY: wfn_mix
135 : USE qs_subsys_types, ONLY: qs_subsys_get,&
136 : qs_subsys_type
137 : USE scf_control_types, ONLY: scf_control_type
138 : USE stm_images, ONLY: th_stm_image
139 : USE task_list_methods, ONLY: generate_qs_task_list
140 : USE task_list_types, ONLY: allocate_task_list,&
141 : task_list_type
142 : USE xtb_qresp, ONLY: build_xtb_qresp
143 : USE xtb_types, ONLY: get_xtb_atom_param,&
144 : xtb_atom_type
145 : #include "./base/base_uses.f90"
146 :
147 : IMPLICIT NONE
148 : PRIVATE
149 :
150 : ! Global parameters
151 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_scf_post_tb'
152 : PUBLIC :: scf_post_calculation_tb, make_lumo_tb
153 :
154 : ! **************************************************************************************************
155 :
156 : CONTAINS
157 :
158 : ! **************************************************************************************************
159 : !> \brief collects possible post - scf calculations and prints info / computes properties.
160 : !> \param qs_env ...
161 : !> \param tb_type ...
162 : !> \param no_mos ...
163 : !> \par History
164 : !> 03.2013 copy of scf_post_gpw
165 : !> \author JHU
166 : !> \note
167 : ! **************************************************************************************************
168 6778 : SUBROUTINE scf_post_calculation_tb(qs_env, tb_type, no_mos)
169 :
170 : TYPE(qs_environment_type), POINTER :: qs_env
171 : CHARACTER(LEN=*) :: tb_type
172 : LOGICAL, INTENT(IN) :: no_mos
173 :
174 : CHARACTER(len=*), PARAMETER :: routineN = 'scf_post_calculation_tb'
175 :
176 : CHARACTER(LEN=6) :: ana
177 : CHARACTER(LEN=default_string_length) :: aname
178 : INTEGER :: after, gfn_type, handle, homo, iat, iatom, ikind, img, ispin, iw, nat, natom, &
179 : nkind, nlumo_stm, nlumos, nspins, print_level, unit_nr
180 : LOGICAL :: do_cube, do_kpoints, explicit, gfn0, &
181 : has_homo, omit_headers, print_it, &
182 : rebuild, vdip
183 : REAL(KIND=dp) :: zeff
184 6778 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: mcharge, zcharge
185 : REAL(KIND=dp), DIMENSION(2, 2) :: homo_lumo
186 6778 : REAL(KIND=dp), DIMENSION(:), POINTER :: echarge, mo_eigenvalues
187 6778 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: charges
188 6778 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
189 6778 : TYPE(cp_1d_r_p_type), DIMENSION(:), POINTER :: unoccupied_evals_stm
190 6778 : TYPE(cp_fm_type), DIMENSION(:), POINTER :: unoccupied_orbs_stm
191 : TYPE(cp_fm_type), POINTER :: mo_coeff
192 : TYPE(cp_logger_type), POINTER :: logger
193 6778 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: ks_rmpv, mo_derivs
194 6778 : TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks, matrix_p, matrix_s
195 : TYPE(dbcsr_type), POINTER :: mo_coeff_deriv
196 : TYPE(dft_control_type), POINTER :: dft_control
197 6778 : TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
198 : TYPE(mp_para_env_type), POINTER :: para_env
199 : TYPE(particle_list_type), POINTER :: particles
200 6778 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
201 : TYPE(qs_dftb_atom_type), POINTER :: dftb_kind
202 6778 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
203 : TYPE(qs_rho_type), POINTER :: rho
204 : TYPE(qs_scf_env_type), POINTER :: scf_env
205 : TYPE(qs_subsys_type), POINTER :: subsys
206 : TYPE(scf_control_type), POINTER :: scf_control
207 : TYPE(section_vals_type), POINTER :: dft_section, moments_section, print_key, &
208 : print_section, sprint_section, &
209 : wfn_mix_section
210 : TYPE(xtb_atom_type), POINTER :: xtb_kind
211 :
212 6778 : CALL timeset(routineN, handle)
213 :
214 6778 : logger => cp_get_default_logger()
215 :
216 6778 : gfn0 = .FALSE.
217 6778 : vdip = .FALSE.
218 6778 : CALL get_qs_env(qs_env, dft_control=dft_control)
219 11458 : SELECT CASE (TRIM(tb_type))
220 : CASE ("DFTB")
221 : CASE ("xTB")
222 4680 : gfn_type = dft_control%qs_control%xtb_control%gfn_type
223 4680 : gfn0 = (gfn_type == 0)
224 4680 : vdip = dft_control%qs_control%xtb_control%var_dipole
225 : CASE DEFAULT
226 6778 : CPABORT("unknown TB type")
227 : END SELECT
228 :
229 6778 : CPASSERT(ASSOCIATED(qs_env))
230 6778 : NULLIFY (rho, para_env, matrix_s, matrix_p)
231 : CALL get_qs_env(qs_env, scf_env=scf_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, &
232 : rho=rho, natom=natom, para_env=para_env, &
233 6778 : particle_set=particle_set, do_kpoints=do_kpoints, matrix_s_kp=matrix_s)
234 6778 : nspins = dft_control%nspins
235 6778 : CALL qs_rho_get(rho, rho_ao_kp=matrix_p)
236 : ! Mulliken charges
237 40668 : ALLOCATE (charges(natom, nspins), mcharge(natom))
238 : !
239 6778 : CALL mulliken_charges(matrix_p, matrix_s, para_env, charges)
240 : !
241 20334 : ALLOCATE (zcharge(natom))
242 6778 : nkind = SIZE(atomic_kind_set)
243 22762 : DO ikind = 1, nkind
244 15984 : CALL get_atomic_kind(atomic_kind_set(ikind), natom=nat)
245 20250 : SELECT CASE (TRIM(tb_type))
246 : CASE ("DFTB")
247 4266 : CALL get_qs_kind(qs_kind_set(ikind), dftb_parameter=dftb_kind)
248 15984 : CALL get_dftb_atom_param(dftb_kind, zeff=zeff)
249 : CASE ("xTB")
250 11718 : CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_kind)
251 11718 : CALL get_xtb_atom_param(xtb_kind, zeff=zeff)
252 : CASE DEFAULT
253 31968 : CPABORT("unknown TB type")
254 : END SELECT
255 100368 : DO iatom = 1, nat
256 61622 : iat = atomic_kind_set(ikind)%atom_list(iatom)
257 125186 : mcharge(iat) = zeff - SUM(charges(iat, 1:nspins))
258 77606 : zcharge(iat) = zeff
259 : END DO
260 : END DO
261 :
262 6778 : dft_section => section_vals_get_subs_vals(qs_env%input, "DFT")
263 6778 : print_section => section_vals_get_subs_vals(dft_section, "PRINT")
264 :
265 : ! Mulliken
266 6778 : print_key => section_vals_get_subs_vals(print_section, "MULLIKEN")
267 6778 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
268 : unit_nr = cp_print_key_unit_nr(logger, print_section, "MULLIKEN", &
269 490 : extension=".mulliken", log_filename=.FALSE.)
270 490 : IF (unit_nr > 0) THEN
271 256 : WRITE (UNIT=unit_nr, FMT="(/,/,T2,A)") "MULLIKEN POPULATION ANALYSIS"
272 256 : IF (nspins == 1) THEN
273 : WRITE (UNIT=unit_nr, FMT="(/,T2,A,T70,A)") &
274 249 : " # Atom Element Kind Atomic population", " Net charge"
275 739 : DO ikind = 1, nkind
276 490 : CALL get_atomic_kind(atomic_kind_set(ikind), natom=nat)
277 490 : aname = ""
278 144 : SELECT CASE (tb_type)
279 : CASE ("DFTB")
280 144 : CALL get_qs_kind(qs_kind_set(ikind), dftb_parameter=dftb_kind)
281 144 : CALL get_dftb_atom_param(dftb_kind, name=aname)
282 : CASE ("xTB")
283 346 : CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_kind)
284 346 : CALL get_xtb_atom_param(xtb_kind, symbol=aname)
285 : CASE DEFAULT
286 490 : CPABORT("unknown TB type")
287 : END SELECT
288 490 : ana = ADJUSTR(TRIM(ADJUSTL(aname)))
289 3315 : DO iatom = 1, nat
290 2086 : iat = atomic_kind_set(ikind)%atom_list(iatom)
291 : WRITE (UNIT=unit_nr, &
292 : FMT="(T2,I7,5X,A6,I6,T39,F12.6,T69,F12.6)") &
293 2576 : iat, ADJUSTL(ana), ikind, charges(iat, 1), mcharge(iat)
294 : END DO
295 : END DO
296 : WRITE (UNIT=unit_nr, &
297 : FMT="(T2,A,T39,F12.6,T69,F12.6,/)") &
298 4421 : "# Total charge", SUM(charges(:, 1)), SUM(mcharge(:))
299 : ELSE
300 : WRITE (UNIT=unit_nr, FMT="(/,T2,A)") &
301 7 : "# Atom Element Kind Atomic population (alpha,beta) Net charge Spin moment"
302 21 : DO ikind = 1, nkind
303 14 : CALL get_atomic_kind(atomic_kind_set(ikind), natom=nat)
304 14 : aname = ""
305 3 : SELECT CASE (tb_type)
306 : CASE ("DFTB")
307 3 : CALL get_qs_kind(qs_kind_set(ikind), dftb_parameter=dftb_kind)
308 3 : CALL get_dftb_atom_param(dftb_kind, name=aname)
309 : CASE ("xTB")
310 11 : CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_kind)
311 11 : CALL get_xtb_atom_param(xtb_kind, symbol=aname)
312 : CASE DEFAULT
313 14 : CPABORT("unknown TB type")
314 : END SELECT
315 14 : ana = ADJUSTR(TRIM(ADJUSTL(aname)))
316 62 : DO iatom = 1, nat
317 27 : iat = atomic_kind_set(ikind)%atom_list(iatom)
318 : WRITE (UNIT=unit_nr, &
319 : FMT="(T2,I6,3X,A6,I6,T29,4(1X,F12.6))") &
320 27 : iat, ADJUSTL(ana), ikind, charges(iat, 1:2), mcharge(iat), &
321 68 : charges(iat, 1) - charges(iat, 2)
322 : END DO
323 : END DO
324 : WRITE (UNIT=unit_nr, &
325 : FMT="(T2,A,T29,4(1X,F12.6),/)") &
326 88 : "# Total charge and spin", SUM(charges(:, 1)), SUM(charges(:, 2)), SUM(mcharge(:))
327 : END IF
328 256 : CALL m_flush(unit_nr)
329 : END IF
330 490 : CALL cp_print_key_finished_output(unit_nr, logger, print_key)
331 : END IF
332 :
333 : ! Compute the Lowdin charges
334 6778 : print_key => section_vals_get_subs_vals(print_section, "LOWDIN")
335 6778 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
336 42 : SELECT CASE (tb_type)
337 : CASE ("DFTB")
338 42 : CPWARN("Lowdin population analysis not implemented for DFTB method.")
339 : CASE ("xTB")
340 : unit_nr = cp_print_key_unit_nr(logger, print_section, "LOWDIN", extension=".lowdin", &
341 4 : log_filename=.FALSE.)
342 4 : print_level = 1
343 4 : CALL section_vals_val_get(print_key, "PRINT_GOP", l_val=print_it)
344 4 : IF (print_it) print_level = 2
345 4 : CALL section_vals_val_get(print_key, "PRINT_ALL", l_val=print_it)
346 4 : IF (print_it) print_level = 3
347 4 : IF (do_kpoints) THEN
348 2 : CPWARN("Lowdin charges not implemented for k-point calculations!")
349 : ELSE
350 2 : CALL lowdin_population_analysis(qs_env, unit_nr, print_level)
351 : END IF
352 4 : CALL cp_print_key_finished_output(unit_nr, logger, print_section, "LOWDIN")
353 : CASE DEFAULT
354 54 : CPABORT("unknown TB type")
355 : END SELECT
356 : END IF
357 :
358 : ! EEQ Charges
359 6778 : print_key => section_vals_get_subs_vals(print_section, "EEQ_CHARGES")
360 6778 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
361 : unit_nr = cp_print_key_unit_nr(logger, print_section, "EEQ_CHARGES", &
362 2 : extension=".eeq", log_filename=.FALSE.)
363 2 : CALL eeq_print(qs_env, unit_nr, print_level, ext=gfn0)
364 2 : CALL cp_print_key_finished_output(unit_nr, logger, print_key)
365 : END IF
366 :
367 : ! Hirshfeld
368 6778 : print_key => section_vals_get_subs_vals(print_section, "HIRSHFELD")
369 6778 : CALL section_vals_get(print_key, explicit=explicit)
370 6778 : IF (explicit) THEN
371 0 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
372 0 : CPWARN("Hirshfeld charges not available for TB methods.")
373 : END IF
374 : END IF
375 :
376 : ! MAO
377 6778 : print_key => section_vals_get_subs_vals(print_section, "MAO_ANALYSIS")
378 6778 : CALL section_vals_get(print_key, explicit=explicit)
379 6778 : IF (explicit) THEN
380 0 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
381 0 : CPWARN("MAO analysis not available for TB methods.")
382 : END IF
383 : END IF
384 :
385 : ! ED
386 6778 : print_key => section_vals_get_subs_vals(print_section, "ENERGY_DECOMPOSITION_ANALYSIS")
387 6778 : CALL section_vals_get(print_key, explicit=explicit)
388 6778 : IF (explicit) THEN
389 0 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
390 0 : CPWARN("ED analysis not available for TB methods.")
391 : END IF
392 : END IF
393 :
394 : ! Dipole Moments
395 6778 : print_key => section_vals_get_subs_vals(print_section, "MOMENTS")
396 6778 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
397 : unit_nr = cp_print_key_unit_nr(logger, print_section, "MOMENTS", &
398 966 : extension=".data", middle_name="tb_dipole", log_filename=.FALSE.)
399 966 : moments_section => section_vals_get_subs_vals(print_section, "MOMENTS")
400 966 : IF (gfn0) THEN
401 156 : NULLIFY (echarge)
402 156 : CALL get_qs_env(qs_env, eeq=echarge)
403 156 : CPASSERT(ASSOCIATED(echarge))
404 156 : IF (vdip) THEN
405 56 : CALL build_xtb_qresp(qs_env, mcharge)
406 280 : mcharge(1:natom) = echarge(1:natom) - mcharge(1:natom)
407 : END IF
408 156 : CALL tb_dipole(qs_env, moments_section, unit_nr, mcharge)
409 : ELSE
410 810 : CALL tb_dipole(qs_env, moments_section, unit_nr, mcharge)
411 : END IF
412 966 : CALL cp_print_key_finished_output(unit_nr, logger, print_key)
413 : END IF
414 :
415 6778 : DEALLOCATE (charges, mcharge)
416 :
417 : ! MO
418 6778 : IF (.NOT. no_mos) THEN
419 6648 : print_key => section_vals_get_subs_vals(print_section, "MO")
420 6648 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
421 124 : CALL qs_scf_write_mos(qs_env, scf_env, final_mos=.TRUE.)
422 124 : IF (.NOT. do_kpoints) THEN
423 78 : SELECT CASE (tb_type)
424 : CASE ("DFTB")
425 : CASE ("xTB")
426 78 : sprint_section => section_vals_get_subs_vals(dft_section, "PRINT%MO_MOLDEN")
427 78 : CALL get_qs_env(qs_env, mos=mos)
428 78 : CALL write_mos_molden(mos, qs_kind_set, particle_set, sprint_section)
429 : CASE DEFAULT
430 120 : CPABORT("Unknown TB type")
431 : END SELECT
432 : END IF
433 : END IF
434 : END IF
435 :
436 : ! Wavefunction mixing
437 6778 : IF (.NOT. no_mos) THEN
438 6648 : wfn_mix_section => section_vals_get_subs_vals(dft_section, "PRINT%WFN_MIX")
439 6648 : CALL section_vals_get(wfn_mix_section, explicit=explicit)
440 6648 : IF (explicit .AND. .NOT. qs_env%run_rtp) CALL wfn_mix_tb(qs_env, dft_section, scf_env)
441 : END IF
442 :
443 6778 : IF (.NOT. no_mos) THEN
444 6648 : print_key => section_vals_get_subs_vals(print_section, "DOS")
445 6648 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
446 2 : IF (do_kpoints) THEN
447 2 : CALL calculate_dos_kp(qs_env, dft_section)
448 : ELSE
449 0 : CALL get_qs_env(qs_env, mos=mos)
450 0 : CALL calculate_dos(mos, dft_section)
451 : END IF
452 : END IF
453 : END IF
454 :
455 : ! PDOS
456 6778 : IF (.NOT. no_mos) THEN
457 6648 : print_key => section_vals_get_subs_vals(print_section, "PDOS")
458 6648 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
459 18 : IF (do_kpoints) THEN
460 14 : CPWARN("Projected density of states not implemented for k-points.")
461 : ELSE
462 4 : CALL get_qs_env(qs_env, mos=mos, matrix_ks=ks_rmpv)
463 8 : DO ispin = 1, dft_control%nspins
464 4 : IF (scf_env%method == ot_method_nr) THEN
465 : CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, &
466 0 : eigenvalues=mo_eigenvalues)
467 0 : IF (ASSOCIATED(qs_env%mo_derivs)) THEN
468 0 : mo_coeff_deriv => qs_env%mo_derivs(ispin)%matrix
469 : ELSE
470 0 : mo_coeff_deriv => NULL()
471 : END IF
472 : CALL calculate_subspace_eigenvalues(mo_coeff, ks_rmpv(ispin)%matrix, mo_eigenvalues, &
473 : do_rotation=.TRUE., &
474 0 : co_rotate_dbcsr=mo_coeff_deriv)
475 0 : CALL set_mo_occupation(mo_set=mos(ispin))
476 : END IF
477 8 : IF (dft_control%nspins == 2) THEN
478 : CALL calculate_projected_dos(mos(ispin), atomic_kind_set, &
479 0 : qs_kind_set, particle_set, qs_env, dft_section, ispin=ispin)
480 : ELSE
481 : CALL calculate_projected_dos(mos(ispin), atomic_kind_set, &
482 4 : qs_kind_set, particle_set, qs_env, dft_section)
483 : END IF
484 : END DO
485 : END IF
486 : END IF
487 : END IF
488 :
489 : ! can we do CUBE files?
490 : SELECT CASE (tb_type)
491 : CASE ("DFTB")
492 : do_cube = .FALSE.
493 4680 : rebuild = .FALSE.
494 : CASE ("xTB")
495 4680 : do_cube = .TRUE.
496 4680 : rebuild = .TRUE.
497 : CASE DEFAULT
498 6778 : CPABORT("unknown TB type")
499 : END SELECT
500 :
501 : ! Energy Windows for LS code
502 6778 : print_key => section_vals_get_subs_vals(print_section, "ENERGY_WINDOWS")
503 6778 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
504 46 : IF (do_cube) THEN
505 4 : IF (do_kpoints) THEN
506 2 : CPWARN("Energy Windows not implemented for k-points.")
507 : ELSE
508 : IF (rebuild) THEN
509 2 : CALL rebuild_pw_env(qs_env)
510 : rebuild = .FALSE.
511 : END IF
512 2 : CALL energy_windows(qs_env)
513 : END IF
514 : ELSE
515 42 : CPWARN("Energy Windows not implemented for TB methods.")
516 : END IF
517 : END IF
518 :
519 : ! DENSITY CUBE FILE
520 6778 : print_key => section_vals_get_subs_vals(print_section, "E_DENSITY_CUBE")
521 6778 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
522 44 : IF (do_cube) THEN
523 2 : IF (rebuild) THEN
524 2 : CALL rebuild_pw_env(qs_env)
525 2 : rebuild = .FALSE.
526 : END IF
527 2 : CALL print_e_density(qs_env, zcharge, print_key)
528 : ELSE
529 42 : CPWARN("Electronic density cube file not implemented for TB methods.")
530 : END IF
531 : END IF
532 :
533 : ! TOTAL DENSITY CUBE FILE
534 6778 : print_key => section_vals_get_subs_vals(print_section, "TOT_DENSITY_CUBE")
535 6778 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
536 46 : IF (do_cube) THEN
537 4 : IF (rebuild) THEN
538 2 : CALL rebuild_pw_env(qs_env)
539 2 : rebuild = .FALSE.
540 : END IF
541 4 : CALL print_density_cubes(qs_env, zcharge, print_key, total_density=.TRUE.)
542 : ELSE
543 42 : CPWARN("Total density cube file not implemented for TB methods.")
544 : END IF
545 : END IF
546 :
547 : ! V_Hartree CUBE FILE
548 6778 : print_key => section_vals_get_subs_vals(print_section, "V_HARTREE_CUBE")
549 6778 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
550 44 : IF (do_cube) THEN
551 2 : IF (rebuild) THEN
552 0 : CALL rebuild_pw_env(qs_env)
553 0 : rebuild = .FALSE.
554 : END IF
555 2 : CALL print_density_cubes(qs_env, zcharge, print_key, v_hartree=.TRUE.)
556 : ELSE
557 42 : CPWARN("Hartree potential cube file not implemented for TB methods.")
558 : END IF
559 : END IF
560 :
561 : ! EFIELD CUBE FILE
562 6778 : print_key => section_vals_get_subs_vals(print_section, "EFIELD_CUBE")
563 6778 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
564 44 : IF (do_cube) THEN
565 2 : IF (rebuild) THEN
566 0 : CALL rebuild_pw_env(qs_env)
567 0 : rebuild = .FALSE.
568 : END IF
569 2 : CALL print_density_cubes(qs_env, zcharge, print_key, efield=.TRUE.)
570 : ELSE
571 42 : CPWARN("Efield cube file not implemented for TB methods.")
572 : END IF
573 : END IF
574 :
575 : ! ELF
576 6778 : print_key => section_vals_get_subs_vals(print_section, "ELF_CUBE")
577 6778 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
578 44 : IF (do_cube) THEN
579 2 : IF (rebuild) THEN
580 0 : CALL rebuild_pw_env(qs_env)
581 0 : rebuild = .FALSE.
582 : END IF
583 2 : CALL print_elf(qs_env, zcharge, print_key)
584 : ELSE
585 42 : CPWARN("ELF not implemented for TB methods.")
586 : END IF
587 : END IF
588 :
589 : ! MO CUBES
590 6778 : IF (.NOT. no_mos) THEN
591 6648 : print_key => section_vals_get_subs_vals(print_section, "MO_CUBES")
592 6648 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
593 44 : IF (do_cube) THEN
594 2 : IF (rebuild) THEN
595 2 : CALL rebuild_pw_env(qs_env)
596 2 : rebuild = .FALSE.
597 : END IF
598 2 : CALL print_mo_cubes(qs_env, zcharge, print_key)
599 : ELSE
600 42 : CPWARN("Printing of MO cube files not implemented for TB methods.")
601 : END IF
602 : END IF
603 : END IF
604 :
605 : ! STM
606 6778 : IF (.NOT. no_mos) THEN
607 6648 : print_key => section_vals_get_subs_vals(print_section, "STM")
608 6648 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
609 2 : IF (do_cube) THEN
610 2 : IF (rebuild) THEN
611 2 : CALL rebuild_pw_env(qs_env)
612 2 : rebuild = .FALSE.
613 : END IF
614 2 : IF (do_kpoints) THEN
615 0 : CPWARN("STM not implemented for k-point calculations!")
616 : ELSE
617 2 : nlumo_stm = section_get_ival(print_key, "NLUMO")
618 2 : CPASSERT(.NOT. dft_control%restricted)
619 : CALL get_qs_env(qs_env, mos=mos, mo_derivs=mo_derivs, &
620 2 : scf_control=scf_control, matrix_ks=ks_rmpv)
621 2 : CALL make_mo_eig(mos, dft_control%nspins, ks_rmpv, scf_control, mo_derivs)
622 4 : DO ispin = 1, dft_control%nspins
623 2 : CALL get_mo_set(mo_set=mos(ispin), eigenvalues=mo_eigenvalues, homo=homo)
624 4 : homo_lumo(ispin, 1) = mo_eigenvalues(homo)
625 : END DO
626 2 : has_homo = .TRUE.
627 2 : NULLIFY (unoccupied_orbs_stm, unoccupied_evals_stm)
628 2 : IF (nlumo_stm > 0) THEN
629 8 : ALLOCATE (unoccupied_orbs_stm(dft_control%nspins))
630 8 : ALLOCATE (unoccupied_evals_stm(dft_control%nspins))
631 : CALL make_lumo_tb(qs_env, scf_env, unoccupied_orbs_stm, unoccupied_evals_stm, &
632 2 : nlumo_stm, nlumos)
633 : END IF
634 :
635 2 : CALL get_qs_env(qs_env, subsys=subsys)
636 2 : CALL qs_subsys_get(subsys, particles=particles)
637 : CALL th_stm_image(qs_env, print_key, particles, unoccupied_orbs_stm, &
638 2 : unoccupied_evals_stm)
639 :
640 2 : IF (nlumo_stm > 0) THEN
641 4 : DO ispin = 1, dft_control%nspins
642 4 : DEALLOCATE (unoccupied_evals_stm(ispin)%array)
643 : END DO
644 2 : DEALLOCATE (unoccupied_evals_stm)
645 2 : CALL cp_fm_release(unoccupied_orbs_stm)
646 : END IF
647 : END IF
648 : END IF
649 : END IF
650 : END IF
651 :
652 : ! Write the density matrix
653 6778 : CALL get_qs_env(qs_env, matrix_ks_kp=matrix_ks)
654 6778 : CALL section_vals_val_get(print_section, "AO_MATRICES%OMIT_HEADERS", l_val=omit_headers)
655 6778 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_section, &
656 : "AO_MATRICES/DENSITY"), cp_p_file)) THEN
657 : iw = cp_print_key_unit_nr(logger, print_section, "AO_MATRICES/DENSITY", &
658 50 : extension=".Log")
659 50 : CALL section_vals_val_get(print_section, "AO_MATRICES%NDIGITS", i_val=after)
660 50 : after = MIN(MAX(after, 1), 16)
661 100 : DO ispin = 1, dft_control%nspins
662 150 : DO img = 1, SIZE(matrix_p, 2)
663 : CALL cp_dbcsr_write_sparse_matrix(matrix_p(ispin, img)%matrix, 4, after, qs_env, &
664 100 : para_env, output_unit=iw, omit_headers=omit_headers)
665 : END DO
666 : END DO
667 50 : CALL cp_print_key_finished_output(iw, logger, print_section, "AO_MATRICES/DENSITY")
668 : END IF
669 :
670 : ! The xTB matrix itself
671 6778 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_section, &
672 : "AO_MATRICES/KOHN_SHAM_MATRIX"), cp_p_file)) THEN
673 : iw = cp_print_key_unit_nr(logger, print_section, "AO_MATRICES/KOHN_SHAM_MATRIX", &
674 50 : extension=".Log")
675 50 : CALL section_vals_val_get(print_section, "AO_MATRICES%NDIGITS", i_val=after)
676 50 : after = MIN(MAX(after, 1), 16)
677 100 : DO ispin = 1, dft_control%nspins
678 150 : DO img = 1, SIZE(matrix_ks, 2)
679 : CALL cp_dbcsr_write_sparse_matrix(matrix_ks(ispin, img)%matrix, 4, after, qs_env, para_env, &
680 100 : output_unit=iw, omit_headers=omit_headers)
681 : END DO
682 : END DO
683 50 : CALL cp_print_key_finished_output(iw, logger, print_section, "AO_MATRICES/KOHN_SHAM_MATRIX")
684 : END IF
685 :
686 : ! these print keys are not supported in TB
687 :
688 : ! V_XC CUBE FILE
689 6778 : print_key => section_vals_get_subs_vals(print_section, "V_XC_CUBE")
690 6778 : CALL section_vals_get(print_key, explicit=explicit)
691 6778 : IF (explicit) THEN
692 0 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
693 0 : CPWARN("XC potential cube file not available for TB methods.")
694 : END IF
695 : END IF
696 :
697 : ! Electric field gradients
698 6778 : print_key => section_vals_get_subs_vals(print_section, "ELECTRIC_FIELD_GRADIENT")
699 6778 : CALL section_vals_get(print_key, explicit=explicit)
700 6778 : IF (explicit) THEN
701 0 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
702 0 : CPWARN("Electric field gradient not implemented for TB methods.")
703 : END IF
704 : END IF
705 :
706 : ! KINETIC ENERGY
707 6778 : print_key => section_vals_get_subs_vals(print_section, "KINETIC_ENERGY")
708 6778 : CALL section_vals_get(print_key, explicit=explicit)
709 6778 : IF (explicit) THEN
710 0 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
711 0 : CPWARN("Kinetic energy not available for TB methods.")
712 : END IF
713 : END IF
714 :
715 : ! Xray diffraction spectrum
716 6778 : print_key => section_vals_get_subs_vals(print_section, "XRAY_DIFFRACTION_SPECTRUM")
717 6778 : CALL section_vals_get(print_key, explicit=explicit)
718 6778 : IF (explicit) THEN
719 0 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
720 0 : CPWARN("Xray diffraction spectrum not implemented for TB methods.")
721 : END IF
722 : END IF
723 :
724 : ! EPR Hyperfine Coupling
725 6778 : print_key => section_vals_get_subs_vals(print_section, "HYPERFINE_COUPLING_TENSOR")
726 6778 : CALL section_vals_get(print_key, explicit=explicit)
727 6778 : IF (explicit) THEN
728 0 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
729 0 : CPWARN("Hyperfine Coupling not implemented for TB methods.")
730 : END IF
731 : END IF
732 :
733 : ! PLUS_U
734 6778 : print_key => section_vals_get_subs_vals(print_section, "PLUS_U")
735 6778 : CALL section_vals_get(print_key, explicit=explicit)
736 6778 : IF (explicit) THEN
737 0 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
738 0 : CPWARN("DFT+U method not implemented for TB methods.")
739 : END IF
740 : END IF
741 :
742 6778 : CALL write_ks_matrix_csr(qs_env, qs_env%input)
743 6778 : CALL write_s_matrix_csr(qs_env, qs_env%input)
744 6778 : CALL write_hcore_matrix_csr(qs_env, qs_env%input)
745 6778 : CALL write_p_matrix_csr(qs_env, qs_env%input)
746 :
747 6778 : DEALLOCATE (zcharge)
748 :
749 6778 : CALL timestop(handle)
750 :
751 74558 : END SUBROUTINE scf_post_calculation_tb
752 :
753 : ! **************************************************************************************************
754 : !> \brief ...
755 : !> \param qs_env ...
756 : !> \param input ...
757 : !> \param unit_nr ...
758 : !> \param charges ...
759 : ! **************************************************************************************************
760 966 : SUBROUTINE tb_dipole(qs_env, input, unit_nr, charges)
761 :
762 : TYPE(qs_environment_type), POINTER :: qs_env
763 : TYPE(section_vals_type), POINTER :: input
764 : INTEGER, INTENT(in) :: unit_nr
765 : REAL(KIND=dp), DIMENSION(:), INTENT(in) :: charges
766 :
767 : CHARACTER(LEN=default_string_length) :: description, dipole_type
768 : COMPLEX(KIND=dp) :: dzeta, dzphase(3), zeta, zphase(3)
769 : COMPLEX(KIND=dp), DIMENSION(3) :: dggamma, ggamma
770 : INTEGER :: i, iat, ikind, j, nat, reference
771 : LOGICAL :: do_berry
772 : REAL(KIND=dp) :: charge_tot, ci(3), dci(3), dipole(3), dipole_deriv(3), drcc(3), dria(3), &
773 : dtheta, gvec(3), q, rcc(3), ria(3), theta, tmp(3), via(3)
774 966 : REAL(KIND=dp), DIMENSION(:), POINTER :: ref_point
775 966 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
776 : TYPE(cell_type), POINTER :: cell
777 : TYPE(cp_result_type), POINTER :: results
778 966 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
779 :
780 966 : NULLIFY (atomic_kind_set, cell, results)
781 : CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, &
782 966 : particle_set=particle_set, cell=cell, results=results)
783 :
784 : ! Reference point
785 966 : reference = section_get_ival(input, keyword_name="REFERENCE")
786 966 : NULLIFY (ref_point)
787 966 : description = '[DIPOLE]'
788 966 : CALL section_vals_val_get(input, "REF_POINT", r_vals=ref_point)
789 966 : CALL section_vals_val_get(input, "PERIODIC", l_val=do_berry)
790 :
791 966 : CALL get_reference_point(rcc, drcc, qs_env=qs_env, reference=reference, ref_point=ref_point)
792 :
793 : ! Dipole deriv will be the derivative of the Dipole(dM/dt=\sum e_j v_j)
794 966 : dipole_deriv = 0.0_dp
795 966 : dipole = 0.0_dp
796 966 : IF (do_berry) THEN
797 610 : dipole_type = "periodic (Berry phase)"
798 2440 : rcc = pbc(rcc, cell)
799 610 : charge_tot = 0._dp
800 3888 : charge_tot = SUM(charges)
801 9760 : ria = twopi*MATMUL(cell%h_inv, rcc)
802 2440 : zphase = CMPLX(COS(ria), SIN(ria), dp)**charge_tot
803 :
804 9760 : dria = twopi*MATMUL(cell%h_inv, drcc)
805 2440 : dzphase = charge_tot*CMPLX(-SIN(ria), COS(ria), dp)**(charge_tot - 1.0_dp)*dria
806 :
807 2440 : ggamma = z_one
808 610 : dggamma = z_zero
809 2050 : DO ikind = 1, SIZE(atomic_kind_set)
810 1440 : CALL get_atomic_kind(atomic_kind_set(ikind), natom=nat)
811 5328 : DO i = 1, nat
812 3278 : iat = atomic_kind_set(ikind)%atom_list(i)
813 13112 : ria = particle_set(iat)%r(:)
814 13112 : ria = pbc(ria, cell)
815 13112 : via = particle_set(iat)%v(:)
816 3278 : q = charges(iat)
817 14552 : DO j = 1, 3
818 39336 : gvec = twopi*cell%h_inv(j, :)
819 39336 : theta = SUM(ria(:)*gvec(:))
820 39336 : dtheta = SUM(via(:)*gvec(:))
821 9834 : zeta = CMPLX(COS(theta), SIN(theta), KIND=dp)**(-q)
822 9834 : dzeta = -q*CMPLX(-SIN(theta), COS(theta), KIND=dp)**(-q - 1.0_dp)*dtheta
823 9834 : dggamma(j) = dggamma(j)*zeta + ggamma(j)*dzeta
824 13112 : ggamma(j) = ggamma(j)*zeta
825 : END DO
826 : END DO
827 : END DO
828 2440 : dggamma = dggamma*zphase + ggamma*dzphase
829 2440 : ggamma = ggamma*zphase
830 2440 : IF (ALL(REAL(ggamma, KIND=dp) /= 0.0_dp)) THEN
831 2440 : tmp = AIMAG(ggamma)/REAL(ggamma, KIND=dp)
832 2440 : ci = -ATAN(tmp)
833 : dci = -(1.0_dp/(1.0_dp + tmp**2))* &
834 2440 : (AIMAG(dggamma)*REAL(ggamma, KIND=dp) - AIMAG(ggamma)*REAL(dggamma, KIND=dp))/(REAL(ggamma, KIND=dp))**2
835 9760 : dipole = MATMUL(cell%hmat, ci)/twopi
836 9760 : dipole_deriv = MATMUL(cell%hmat, dci)/twopi
837 : END IF
838 : ELSE
839 356 : dipole_type = "non-periodic"
840 1660 : DO i = 1, SIZE(particle_set)
841 : ! no pbc(particle_set(i)%r(:),cell) so that the total dipole is the sum of the molecular dipoles
842 5216 : ria = particle_set(i)%r(:)
843 1304 : q = charges(i)
844 5216 : dipole = dipole + q*(ria - rcc)
845 5572 : dipole_deriv(:) = dipole_deriv(:) + q*(particle_set(i)%v(:) - drcc)
846 : END DO
847 : END IF
848 966 : CALL cp_results_erase(results=results, description=description)
849 : CALL put_results(results=results, description=description, &
850 966 : values=dipole(1:3))
851 966 : IF (unit_nr > 0) THEN
852 : WRITE (unit_nr, '(/,T2,A,T31,A50)') &
853 523 : 'TB_DIPOLE| Dipole type', ADJUSTR(TRIM(dipole_type))
854 523 : WRITE (unit_nr, "(T2,A,T30,3(1X,F16.8))") "TB_DIPOLE| Ref. Point [Bohr]", rcc
855 : WRITE (unit_nr, '(T2,A,T30,3(1X,F16.8))') &
856 523 : 'TB_DIPOLE| Moment [a.u.]', dipole(1:3)
857 : WRITE (unit_nr, '(T2,A,T30,3(1X,F16.8))') &
858 2092 : 'TB_DIPOLE| Moment [Debye]', dipole(1:3)*debye
859 : WRITE (unit_nr, '(T2,A,T30,3(1X,F16.8))') &
860 523 : 'TB_DIPOLE| Derivative [a.u.]', dipole_deriv(1:3)
861 : END IF
862 :
863 966 : END SUBROUTINE tb_dipole
864 :
865 : ! **************************************************************************************************
866 : !> \brief computes the MOs and calls the wavefunction mixing routine.
867 : !> \param qs_env ...
868 : !> \param dft_section ...
869 : !> \param scf_env ...
870 : !> \author Florian Schiffmann
871 : !> \note
872 : ! **************************************************************************************************
873 :
874 2 : SUBROUTINE wfn_mix_tb(qs_env, dft_section, scf_env)
875 :
876 : TYPE(qs_environment_type), POINTER :: qs_env
877 : TYPE(section_vals_type), POINTER :: dft_section
878 : TYPE(qs_scf_env_type), POINTER :: scf_env
879 :
880 : INTEGER :: ispin, nao, nmo, output_unit
881 2 : REAL(dp), DIMENSION(:), POINTER :: mo_eigenvalues
882 2 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
883 : TYPE(cp_fm_struct_type), POINTER :: ao_ao_fmstruct, ao_lumo_struct
884 : TYPE(cp_fm_type) :: KS_tmp, MO_tmp, S_tmp, work
885 2 : TYPE(cp_fm_type), DIMENSION(:), POINTER :: lumos
886 : TYPE(cp_fm_type), POINTER :: mo_coeff
887 : TYPE(cp_logger_type), POINTER :: logger
888 2 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks, matrix_s
889 2 : TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
890 : TYPE(mp_para_env_type), POINTER :: para_env
891 2 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
892 2 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
893 : TYPE(section_vals_type), POINTER :: wfn_mix_section
894 :
895 4 : logger => cp_get_default_logger()
896 : CALL get_qs_env(qs_env=qs_env, matrix_s=matrix_s, matrix_ks=matrix_ks, &
897 : particle_set=particle_set, atomic_kind_set=atomic_kind_set, &
898 2 : qs_kind_set=qs_kind_set, mos=mos, para_env=para_env)
899 :
900 2 : wfn_mix_section => section_vals_get_subs_vals(dft_section, "PRINT%WFN_MIX")
901 :
902 2 : CALL get_mo_set(mos(1), mo_coeff=mo_coeff, nao=nao)
903 :
904 : CALL cp_fm_struct_create(fmstruct=ao_ao_fmstruct, nrow_global=nao, ncol_global=nao, &
905 2 : template_fmstruct=mo_coeff%matrix_struct)
906 2 : CALL cp_fm_create(S_tmp, matrix_struct=ao_ao_fmstruct)
907 2 : CALL cp_fm_create(KS_tmp, matrix_struct=ao_ao_fmstruct)
908 2 : CALL cp_fm_create(MO_tmp, matrix_struct=ao_ao_fmstruct)
909 2 : CALL cp_fm_create(work, matrix_struct=ao_ao_fmstruct)
910 10 : ALLOCATE (lumos(SIZE(mos)))
911 :
912 2 : CALL copy_dbcsr_to_fm(matrix_s(1)%matrix, S_tmp)
913 2 : CALL cp_fm_cholesky_decompose(S_tmp)
914 :
915 6 : DO ispin = 1, SIZE(mos)
916 4 : CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, eigenvalues=mo_eigenvalues, nmo=nmo)
917 : CALL cp_fm_struct_create(fmstruct=ao_lumo_struct, nrow_global=nao, ncol_global=nao - nmo, &
918 4 : template_fmstruct=mo_coeff%matrix_struct)
919 :
920 4 : CALL cp_fm_create(lumos(ispin), matrix_struct=ao_lumo_struct)
921 4 : CALL copy_dbcsr_to_fm(matrix_ks(ispin)%matrix, KS_tmp)
922 4 : CALL cp_fm_cholesky_reduce(KS_tmp, S_tmp)
923 4 : CALL choose_eigv_solver(KS_tmp, work, mo_eigenvalues)
924 4 : CALL cp_fm_cholesky_restore(work, nao, S_tmp, MO_tmp, "SOLVE")
925 4 : CALL cp_fm_to_fm_submat(MO_tmp, mo_coeff, nao, nmo, 1, 1, 1, 1)
926 4 : CALL cp_fm_to_fm_submat(MO_tmp, lumos(ispin), nao, nao - nmo, 1, nmo + 1, 1, 1)
927 :
928 10 : CALL cp_fm_struct_release(ao_lumo_struct)
929 : END DO
930 :
931 2 : output_unit = cp_logger_get_default_io_unit(logger)
932 : CALL wfn_mix(mos, particle_set, dft_section, qs_kind_set, para_env, output_unit, &
933 2 : unoccupied_orbs=lumos, scf_env=scf_env, matrix_s=matrix_s)
934 :
935 2 : CALL cp_fm_release(lumos)
936 2 : CALL cp_fm_release(S_tmp)
937 2 : CALL cp_fm_release(MO_tmp)
938 2 : CALL cp_fm_release(KS_tmp)
939 2 : CALL cp_fm_release(work)
940 2 : CALL cp_fm_struct_release(ao_ao_fmstruct)
941 :
942 6 : END SUBROUTINE wfn_mix_tb
943 :
944 : ! **************************************************************************************************
945 : !> \brief Gets the lumos, and eigenvalues for the lumos
946 : !> \param qs_env ...
947 : !> \param scf_env ...
948 : !> \param unoccupied_orbs ...
949 : !> \param unoccupied_evals ...
950 : !> \param nlumo ...
951 : !> \param nlumos ...
952 : ! **************************************************************************************************
953 2 : SUBROUTINE make_lumo_tb(qs_env, scf_env, unoccupied_orbs, unoccupied_evals, nlumo, nlumos)
954 :
955 : TYPE(qs_environment_type), POINTER :: qs_env
956 : TYPE(qs_scf_env_type), POINTER :: scf_env
957 : TYPE(cp_fm_type), DIMENSION(:), POINTER :: unoccupied_orbs
958 : TYPE(cp_1d_r_p_type), DIMENSION(:), INTENT(INOUT) :: unoccupied_evals
959 : INTEGER :: nlumo
960 : INTEGER, INTENT(OUT) :: nlumos
961 :
962 : INTEGER :: homo, iounit, ispin, n, nao, nmo
963 : TYPE(cp_blacs_env_type), POINTER :: blacs_env
964 : TYPE(cp_fm_struct_type), POINTER :: fm_struct_tmp
965 : TYPE(cp_fm_type), POINTER :: mo_coeff
966 : TYPE(cp_logger_type), POINTER :: logger
967 2 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: ks_rmpv, matrix_s
968 : TYPE(dft_control_type), POINTER :: dft_control
969 2 : TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
970 : TYPE(mp_para_env_type), POINTER :: para_env
971 : TYPE(preconditioner_type), POINTER :: local_preconditioner
972 : TYPE(scf_control_type), POINTER :: scf_control
973 :
974 2 : NULLIFY (mos, ks_rmpv, scf_control, dft_control, para_env, blacs_env)
975 : CALL get_qs_env(qs_env, &
976 : mos=mos, &
977 : matrix_ks=ks_rmpv, &
978 : scf_control=scf_control, &
979 : dft_control=dft_control, &
980 : matrix_s=matrix_s, &
981 : para_env=para_env, &
982 2 : blacs_env=blacs_env)
983 :
984 2 : logger => cp_get_default_logger()
985 2 : iounit = cp_logger_get_default_io_unit(logger)
986 :
987 4 : DO ispin = 1, dft_control%nspins
988 2 : NULLIFY (unoccupied_evals(ispin)%array)
989 : ! Always write eigenvalues
990 2 : IF (iounit > 0) WRITE (iounit, *) " "
991 2 : IF (iounit > 0) WRITE (iounit, *) " Lowest Eigenvalues of the unoccupied subspace spin ", ispin
992 2 : IF (iounit > 0) WRITE (iounit, FMT='(1X,A)') "-----------------------------------------------------"
993 2 : CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, homo=homo, nao=nao, nmo=nmo)
994 2 : CALL cp_fm_get_info(mo_coeff, nrow_global=n)
995 2 : nlumos = MAX(1, MIN(nlumo, nao - nmo))
996 2 : IF (nlumo == -1) nlumos = nao - nmo
997 6 : ALLOCATE (unoccupied_evals(ispin)%array(nlumos))
998 : CALL cp_fm_struct_create(fm_struct_tmp, para_env=para_env, context=blacs_env, &
999 2 : nrow_global=n, ncol_global=nlumos)
1000 2 : CALL cp_fm_create(unoccupied_orbs(ispin), fm_struct_tmp, name="lumos")
1001 2 : CALL cp_fm_struct_release(fm_struct_tmp)
1002 2 : CALL cp_fm_init_random(unoccupied_orbs(ispin), nlumos)
1003 :
1004 : ! the full_all preconditioner makes not much sense for lumos search
1005 2 : NULLIFY (local_preconditioner)
1006 2 : IF (ASSOCIATED(scf_env%ot_preconditioner)) THEN
1007 2 : local_preconditioner => scf_env%ot_preconditioner(1)%preconditioner
1008 : ! this one can for sure not be right (as it has to match a given C0)
1009 2 : IF (local_preconditioner%in_use == ot_precond_full_all) THEN
1010 2 : NULLIFY (local_preconditioner)
1011 : END IF
1012 : END IF
1013 :
1014 : CALL ot_eigensolver(matrix_h=ks_rmpv(ispin)%matrix, matrix_s=matrix_s(1)%matrix, &
1015 : matrix_c_fm=unoccupied_orbs(ispin), &
1016 : matrix_orthogonal_space_fm=mo_coeff, &
1017 : eps_gradient=scf_control%eps_lumos, &
1018 : preconditioner=local_preconditioner, &
1019 : iter_max=scf_control%max_iter_lumos, &
1020 2 : size_ortho_space=nmo)
1021 :
1022 : CALL calculate_subspace_eigenvalues(unoccupied_orbs(ispin), ks_rmpv(ispin)%matrix, &
1023 : unoccupied_evals(ispin)%array, scr=iounit, &
1024 6 : ionode=iounit > 0)
1025 :
1026 : END DO
1027 :
1028 2 : END SUBROUTINE make_lumo_tb
1029 :
1030 : ! **************************************************************************************************
1031 : !> \brief ...
1032 : !> \param qs_env ...
1033 : ! **************************************************************************************************
1034 10 : SUBROUTINE rebuild_pw_env(qs_env)
1035 :
1036 : TYPE(qs_environment_type), POINTER :: qs_env
1037 :
1038 : LOGICAL :: skip_load_balance_distributed
1039 : TYPE(cell_type), POINTER :: cell
1040 : TYPE(dft_control_type), POINTER :: dft_control
1041 : TYPE(pw_env_type), POINTER :: new_pw_env
1042 : TYPE(qs_ks_env_type), POINTER :: ks_env
1043 : TYPE(qs_rho_type), POINTER :: rho
1044 : TYPE(task_list_type), POINTER :: task_list
1045 :
1046 10 : CALL get_qs_env(qs_env, ks_env=ks_env, dft_control=dft_control, pw_env=new_pw_env)
1047 10 : IF (.NOT. ASSOCIATED(new_pw_env)) THEN
1048 0 : CALL pw_env_create(new_pw_env)
1049 0 : CALL set_ks_env(ks_env, pw_env=new_pw_env)
1050 0 : CALL pw_env_release(new_pw_env)
1051 : END IF
1052 10 : CALL get_qs_env(qs_env, pw_env=new_pw_env, dft_control=dft_control, cell=cell)
1053 :
1054 260 : new_pw_env%cell_hmat = cell%hmat
1055 10 : CALL pw_env_rebuild(new_pw_env, qs_env=qs_env)
1056 :
1057 10 : NULLIFY (task_list)
1058 10 : CALL get_ks_env(ks_env, task_list=task_list)
1059 10 : IF (.NOT. ASSOCIATED(task_list)) THEN
1060 10 : CALL allocate_task_list(task_list)
1061 10 : CALL set_ks_env(ks_env, task_list=task_list)
1062 : END IF
1063 10 : skip_load_balance_distributed = dft_control%qs_control%skip_load_balance_distributed
1064 : CALL generate_qs_task_list(ks_env, task_list, basis_type="ORB", &
1065 : reorder_rs_grid_ranks=.TRUE., &
1066 10 : skip_load_balance_distributed=skip_load_balance_distributed)
1067 10 : CALL get_qs_env(qs_env, rho=rho)
1068 10 : CALL qs_rho_rebuild(rho, qs_env=qs_env, rebuild_ao=.FALSE., rebuild_grids=.TRUE.)
1069 :
1070 10 : END SUBROUTINE rebuild_pw_env
1071 :
1072 : ! **************************************************************************************************
1073 : !> \brief ...
1074 : !> \param qs_env ...
1075 : !> \param zcharge ...
1076 : !> \param cube_section ...
1077 : ! **************************************************************************************************
1078 2 : SUBROUTINE print_e_density(qs_env, zcharge, cube_section)
1079 :
1080 : TYPE(qs_environment_type), POINTER :: qs_env
1081 : REAL(KIND=dp), DIMENSION(:), INTENT(IN) :: zcharge
1082 : TYPE(section_vals_type), POINTER :: cube_section
1083 :
1084 : CHARACTER(LEN=default_path_length) :: filename, mpi_filename, my_pos_cube
1085 : INTEGER :: iounit, ispin, unit_nr
1086 : LOGICAL :: append_cube, mpi_io
1087 2 : REAL(KIND=dp), DIMENSION(:), POINTER :: tot_rho_r
1088 : TYPE(cp_logger_type), POINTER :: logger
1089 2 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: rho_ao
1090 2 : TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: rho_ao_kp
1091 : TYPE(dft_control_type), POINTER :: dft_control
1092 : TYPE(particle_list_type), POINTER :: particles
1093 2 : TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g
1094 : TYPE(pw_env_type), POINTER :: pw_env
1095 2 : TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
1096 : TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
1097 2 : TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r
1098 : TYPE(qs_ks_env_type), POINTER :: ks_env
1099 : TYPE(qs_rho_type), POINTER :: rho
1100 : TYPE(qs_subsys_type), POINTER :: subsys
1101 :
1102 2 : CALL get_qs_env(qs_env, dft_control=dft_control)
1103 :
1104 2 : append_cube = section_get_lval(cube_section, "APPEND")
1105 2 : my_pos_cube = "REWIND"
1106 2 : IF (append_cube) my_pos_cube = "APPEND"
1107 :
1108 2 : logger => cp_get_default_logger()
1109 2 : iounit = cp_logger_get_default_io_unit(logger)
1110 :
1111 : ! we need to construct the density on a realspace grid
1112 2 : CALL get_qs_env(qs_env, ks_env=ks_env, rho=rho)
1113 2 : NULLIFY (rho_r, rho_g, tot_rho_r)
1114 : CALL qs_rho_get(rho, rho_ao_kp=rho_ao_kp, &
1115 2 : rho_r=rho_r, rho_g=rho_g, tot_rho_r=tot_rho_r)
1116 6 : DO ispin = 1, dft_control%nspins
1117 4 : rho_ao => rho_ao_kp(ispin, :)
1118 : CALL calculate_rho_elec(matrix_p_kp=rho_ao, &
1119 : rho=rho_r(ispin), &
1120 : rho_gspace=rho_g(ispin), &
1121 : total_rho=tot_rho_r(ispin), &
1122 6 : ks_env=ks_env)
1123 : END DO
1124 2 : CALL qs_rho_set(rho, rho_r_valid=.TRUE., rho_g_valid=.TRUE.)
1125 :
1126 2 : CALL get_qs_env(qs_env, subsys=subsys)
1127 2 : CALL qs_subsys_get(subsys, particles=particles)
1128 :
1129 2 : IF (dft_control%nspins > 1) THEN
1130 2 : IF (iounit > 0) THEN
1131 : WRITE (UNIT=iounit, FMT="(/,T2,A,T51,2F15.6)") &
1132 1 : "Integrated alpha and beta electronic density:", tot_rho_r(1:2)
1133 : END IF
1134 2 : CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
1135 2 : CALL pw_env_get(pw_env=pw_env, auxbas_pw_pool=auxbas_pw_pool, pw_pools=pw_pools)
1136 : BLOCK
1137 : TYPE(pw_r3d_rs_type) :: rho_elec_rspace
1138 2 : CALL auxbas_pw_pool%create_pw(pw=rho_elec_rspace)
1139 2 : CALL pw_copy(rho_r(1), rho_elec_rspace)
1140 2 : CALL pw_axpy(rho_r(2), rho_elec_rspace)
1141 2 : filename = "ELECTRON_DENSITY"
1142 2 : mpi_io = .TRUE.
1143 : unit_nr = cp_print_key_unit_nr(logger, cube_section, '', &
1144 : extension=".cube", middle_name=TRIM(filename), &
1145 : file_position=my_pos_cube, log_filename=.FALSE., mpi_io=mpi_io, &
1146 2 : fout=mpi_filename)
1147 2 : IF (iounit > 0) THEN
1148 1 : IF (.NOT. mpi_io) THEN
1149 0 : INQUIRE (UNIT=unit_nr, NAME=filename)
1150 : ELSE
1151 1 : filename = mpi_filename
1152 : END IF
1153 : WRITE (UNIT=iounit, FMT="(T2,A,/,T2,A79)") &
1154 1 : "The sum of alpha and beta density is written in cube file format to the file:", ADJUSTR(TRIM(filename))
1155 : END IF
1156 : CALL cp_pw_to_cube(rho_elec_rspace, unit_nr, "SUM OF ALPHA AND BETA DENSITY", &
1157 : particles=particles, zeff=zcharge, stride=section_get_ivals(cube_section, "STRIDE"), &
1158 2 : mpi_io=mpi_io)
1159 2 : CALL cp_print_key_finished_output(unit_nr, logger, cube_section, '', mpi_io=mpi_io)
1160 2 : CALL pw_copy(rho_r(1), rho_elec_rspace)
1161 2 : CALL pw_axpy(rho_r(2), rho_elec_rspace, alpha=-1.0_dp)
1162 2 : filename = "SPIN_DENSITY"
1163 2 : mpi_io = .TRUE.
1164 : unit_nr = cp_print_key_unit_nr(logger, cube_section, '', &
1165 : extension=".cube", middle_name=TRIM(filename), &
1166 : file_position=my_pos_cube, log_filename=.FALSE., mpi_io=mpi_io, &
1167 2 : fout=mpi_filename)
1168 2 : IF (iounit > 0) THEN
1169 1 : IF (.NOT. mpi_io) THEN
1170 0 : INQUIRE (UNIT=unit_nr, NAME=filename)
1171 : ELSE
1172 1 : filename = mpi_filename
1173 : END IF
1174 : WRITE (UNIT=iounit, FMT="(T2,A,/,T2,A79)") &
1175 1 : "The spin density is written in cube file format to the file:", ADJUSTR(TRIM(filename))
1176 : END IF
1177 : CALL cp_pw_to_cube(rho_elec_rspace, unit_nr, "SPIN DENSITY", &
1178 : particles=particles, zeff=zcharge, &
1179 2 : stride=section_get_ivals(cube_section, "STRIDE"), mpi_io=mpi_io)
1180 2 : CALL cp_print_key_finished_output(unit_nr, logger, cube_section, '', mpi_io=mpi_io)
1181 2 : CALL auxbas_pw_pool%give_back_pw(rho_elec_rspace)
1182 : END BLOCK
1183 : ELSE
1184 0 : IF (iounit > 0) THEN
1185 : WRITE (UNIT=iounit, FMT="(/,T2,A,T66,F15.6)") &
1186 0 : "Integrated electronic density:", tot_rho_r(1)
1187 : END IF
1188 0 : filename = "ELECTRON_DENSITY"
1189 0 : mpi_io = .TRUE.
1190 : unit_nr = cp_print_key_unit_nr(logger, cube_section, '', &
1191 : extension=".cube", middle_name=TRIM(filename), &
1192 : file_position=my_pos_cube, log_filename=.FALSE., mpi_io=mpi_io, &
1193 0 : fout=mpi_filename)
1194 0 : IF (iounit > 0) THEN
1195 0 : IF (.NOT. mpi_io) THEN
1196 0 : INQUIRE (UNIT=unit_nr, NAME=filename)
1197 : ELSE
1198 0 : filename = mpi_filename
1199 : END IF
1200 : WRITE (UNIT=iounit, FMT="(T2,A,/,T2,A79)") &
1201 0 : "The electron density is written in cube file format to the file:", ADJUSTR(TRIM(filename))
1202 : END IF
1203 : CALL cp_pw_to_cube(rho_r(1), unit_nr, "ELECTRON DENSITY", &
1204 : particles=particles, zeff=zcharge, &
1205 0 : stride=section_get_ivals(cube_section, "STRIDE"), mpi_io=mpi_io)
1206 0 : CALL cp_print_key_finished_output(unit_nr, logger, cube_section, '', mpi_io=mpi_io)
1207 : END IF ! nspins
1208 :
1209 2 : END SUBROUTINE print_e_density
1210 : ! **************************************************************************************************
1211 : !> \brief ...
1212 : !> \param qs_env ...
1213 : !> \param zcharge ...
1214 : !> \param cube_section ...
1215 : !> \param total_density ...
1216 : !> \param v_hartree ...
1217 : !> \param efield ...
1218 : ! **************************************************************************************************
1219 8 : SUBROUTINE print_density_cubes(qs_env, zcharge, cube_section, total_density, v_hartree, efield)
1220 :
1221 : TYPE(qs_environment_type), POINTER :: qs_env
1222 : REAL(KIND=dp), DIMENSION(:), INTENT(IN) :: zcharge
1223 : TYPE(section_vals_type), POINTER :: cube_section
1224 : LOGICAL, INTENT(IN), OPTIONAL :: total_density, v_hartree, efield
1225 :
1226 : CHARACTER(len=1), DIMENSION(3), PARAMETER :: cdir = ["x", "y", "z"]
1227 :
1228 : CHARACTER(LEN=default_path_length) :: filename, mpi_filename, my_pos_cube
1229 : INTEGER :: id, iounit, ispin, nd(3), unit_nr
1230 : LOGICAL :: append_cube, mpi_io, my_efield, &
1231 : my_total_density, my_v_hartree
1232 : REAL(KIND=dp) :: total_rho_core_rspace, udvol
1233 8 : REAL(KIND=dp), DIMENSION(:), POINTER :: tot_rho_r
1234 : TYPE(cell_type), POINTER :: cell
1235 : TYPE(cp_logger_type), POINTER :: logger
1236 8 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: rho_ao
1237 8 : TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: rho_ao_kp
1238 : TYPE(dft_control_type), POINTER :: dft_control
1239 : TYPE(particle_list_type), POINTER :: particles
1240 : TYPE(pw_c1d_gs_type) :: rho_core
1241 8 : TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g
1242 : TYPE(pw_env_type), POINTER :: pw_env
1243 : TYPE(pw_poisson_parameter_type) :: poisson_params
1244 8 : TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
1245 : TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
1246 : TYPE(pw_r3d_rs_type) :: rho_tot_rspace
1247 8 : TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r
1248 : TYPE(qs_ks_env_type), POINTER :: ks_env
1249 : TYPE(qs_rho_type), POINTER :: rho
1250 : TYPE(qs_subsys_type), POINTER :: subsys
1251 :
1252 8 : CALL get_qs_env(qs_env, cell=cell, dft_control=dft_control)
1253 :
1254 8 : append_cube = section_get_lval(cube_section, "APPEND")
1255 8 : my_pos_cube = "REWIND"
1256 8 : IF (append_cube) my_pos_cube = "APPEND"
1257 :
1258 8 : IF (PRESENT(total_density)) THEN
1259 4 : my_total_density = total_density
1260 : ELSE
1261 : my_total_density = .FALSE.
1262 : END IF
1263 8 : IF (PRESENT(v_hartree)) THEN
1264 2 : my_v_hartree = v_hartree
1265 : ELSE
1266 : my_v_hartree = .FALSE.
1267 : END IF
1268 8 : IF (PRESENT(efield)) THEN
1269 2 : my_efield = efield
1270 : ELSE
1271 : my_efield = .FALSE.
1272 : END IF
1273 :
1274 8 : logger => cp_get_default_logger()
1275 8 : iounit = cp_logger_get_default_io_unit(logger)
1276 :
1277 : ! we need to construct the density on a realspace grid
1278 8 : CALL get_qs_env(qs_env, ks_env=ks_env, rho=rho)
1279 8 : NULLIFY (rho_r, rho_g, tot_rho_r)
1280 : CALL qs_rho_get(rho, rho_ao_kp=rho_ao_kp, &
1281 8 : rho_r=rho_r, rho_g=rho_g, tot_rho_r=tot_rho_r)
1282 18 : DO ispin = 1, dft_control%nspins
1283 10 : rho_ao => rho_ao_kp(ispin, :)
1284 : CALL calculate_rho_elec(matrix_p_kp=rho_ao, &
1285 : rho=rho_r(ispin), &
1286 : rho_gspace=rho_g(ispin), &
1287 : total_rho=tot_rho_r(ispin), &
1288 18 : ks_env=ks_env)
1289 : END DO
1290 8 : CALL qs_rho_set(rho, rho_r_valid=.TRUE., rho_g_valid=.TRUE.)
1291 :
1292 8 : CALL get_qs_env(qs_env, subsys=subsys)
1293 8 : CALL qs_subsys_get(subsys, particles=particles)
1294 :
1295 8 : CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
1296 8 : CALL pw_env_get(pw_env=pw_env, auxbas_pw_pool=auxbas_pw_pool, pw_pools=pw_pools)
1297 8 : CALL auxbas_pw_pool%create_pw(pw=rho_core)
1298 8 : CALL calculate_rho_core(rho_core, total_rho_core_rspace, qs_env)
1299 :
1300 8 : IF (iounit > 0) THEN
1301 : WRITE (UNIT=iounit, FMT="(/,T2,A,T66,F15.6)") &
1302 9 : "Integrated electronic density:", SUM(tot_rho_r(:))
1303 : WRITE (UNIT=iounit, FMT="(T2,A,T66,F15.6)") &
1304 4 : "Integrated core density:", total_rho_core_rspace
1305 : END IF
1306 :
1307 8 : CALL auxbas_pw_pool%create_pw(pw=rho_tot_rspace)
1308 8 : CALL pw_transfer(rho_core, rho_tot_rspace)
1309 18 : DO ispin = 1, dft_control%nspins
1310 18 : CALL pw_axpy(rho_r(ispin), rho_tot_rspace)
1311 : END DO
1312 :
1313 8 : IF (my_total_density) THEN
1314 4 : filename = "TOTAL_DENSITY"
1315 4 : mpi_io = .TRUE.
1316 : unit_nr = cp_print_key_unit_nr(logger, cube_section, '', &
1317 : extension=".cube", middle_name=TRIM(filename), file_position=my_pos_cube, &
1318 4 : log_filename=.FALSE., mpi_io=mpi_io, fout=mpi_filename)
1319 4 : IF (iounit > 0) THEN
1320 2 : IF (.NOT. mpi_io) THEN
1321 0 : INQUIRE (UNIT=unit_nr, NAME=filename)
1322 : ELSE
1323 2 : filename = mpi_filename
1324 : END IF
1325 : WRITE (UNIT=iounit, FMT="(T2,A,/,T2,A79)") &
1326 2 : "The total density is written in cube file format to the file:", ADJUSTR(TRIM(filename))
1327 : END IF
1328 : CALL cp_pw_to_cube(rho_tot_rspace, unit_nr, "TOTAL DENSITY", &
1329 : particles=particles, zeff=zcharge, &
1330 4 : stride=section_get_ivals(cube_section, "STRIDE"), mpi_io=mpi_io)
1331 4 : CALL cp_print_key_finished_output(unit_nr, logger, cube_section, '', mpi_io=mpi_io)
1332 : END IF
1333 8 : IF (my_v_hartree .OR. my_efield) THEN
1334 : BLOCK
1335 : TYPE(pw_c1d_gs_type) :: rho_tot_gspace
1336 4 : CALL auxbas_pw_pool%create_pw(pw=rho_tot_gspace)
1337 4 : CALL pw_transfer(rho_tot_rspace, rho_tot_gspace)
1338 4 : poisson_params%solver = pw_poisson_analytic
1339 16 : poisson_params%periodic = cell%perd
1340 4 : poisson_params%ewald_type = do_ewald_none
1341 8 : BLOCK
1342 4 : TYPE(greens_fn_type) :: green_fft
1343 : TYPE(pw_grid_type), POINTER :: pwdummy
1344 4 : NULLIFY (pwdummy)
1345 4 : CALL pw_green_create(green_fft, poisson_params, cell%hmat, auxbas_pw_pool, pwdummy, pwdummy)
1346 746500 : rho_tot_gspace%array(:) = rho_tot_gspace%array(:)*green_fft%influence_fn%array(:)
1347 8 : CALL pw_green_release(green_fft, auxbas_pw_pool)
1348 : END BLOCK
1349 4 : IF (my_v_hartree) THEN
1350 : BLOCK
1351 : TYPE(pw_r3d_rs_type) :: vhartree
1352 2 : CALL auxbas_pw_pool%create_pw(pw=vhartree)
1353 2 : CALL pw_transfer(rho_tot_gspace, vhartree)
1354 2 : filename = "V_HARTREE"
1355 2 : mpi_io = .TRUE.
1356 : unit_nr = cp_print_key_unit_nr(logger, cube_section, '', &
1357 : extension=".cube", middle_name=TRIM(filename), file_position=my_pos_cube, &
1358 2 : log_filename=.FALSE., mpi_io=mpi_io, fout=mpi_filename)
1359 2 : IF (iounit > 0) THEN
1360 1 : IF (.NOT. mpi_io) THEN
1361 0 : INQUIRE (UNIT=unit_nr, NAME=filename)
1362 : ELSE
1363 1 : filename = mpi_filename
1364 : END IF
1365 : WRITE (UNIT=iounit, FMT="(T2,A,/,T2,A79)") &
1366 1 : "The Hartree potential is written in cube file format to the file:", ADJUSTR(TRIM(filename))
1367 : END IF
1368 : CALL cp_pw_to_cube(vhartree, unit_nr, "Hartree Potential", &
1369 : particles=particles, zeff=zcharge, &
1370 2 : stride=section_get_ivals(cube_section, "STRIDE"), mpi_io=mpi_io)
1371 2 : CALL cp_print_key_finished_output(unit_nr, logger, cube_section, '', mpi_io=mpi_io)
1372 2 : CALL auxbas_pw_pool%give_back_pw(vhartree)
1373 : END BLOCK
1374 : END IF
1375 4 : IF (my_efield) THEN
1376 : BLOCK
1377 : TYPE(pw_c1d_gs_type) :: vhartree
1378 2 : CALL auxbas_pw_pool%create_pw(pw=vhartree)
1379 2 : udvol = 1.0_dp/rho_tot_rspace%pw_grid%dvol
1380 8 : DO id = 1, 3
1381 6 : CALL pw_transfer(rho_tot_gspace, vhartree)
1382 6 : nd = 0
1383 6 : nd(id) = 1
1384 6 : CALL pw_derive(vhartree, nd)
1385 6 : CALL pw_transfer(vhartree, rho_tot_rspace)
1386 6 : CALL pw_scale(rho_tot_rspace, udvol)
1387 :
1388 6 : filename = "EFIELD_"//cdir(id)
1389 6 : mpi_io = .TRUE.
1390 : unit_nr = cp_print_key_unit_nr(logger, cube_section, '', &
1391 : extension=".cube", middle_name=TRIM(filename), file_position=my_pos_cube, &
1392 6 : log_filename=.FALSE., mpi_io=mpi_io, fout=mpi_filename)
1393 6 : IF (iounit > 0) THEN
1394 3 : IF (.NOT. mpi_io) THEN
1395 0 : INQUIRE (UNIT=unit_nr, NAME=filename)
1396 : ELSE
1397 3 : filename = mpi_filename
1398 : END IF
1399 : WRITE (UNIT=iounit, FMT="(T2,A,/,T2,A79)") &
1400 3 : "The Efield is written in cube file format to the file:", ADJUSTR(TRIM(filename))
1401 : END IF
1402 : CALL cp_pw_to_cube(rho_tot_rspace, unit_nr, "EFIELD "//cdir(id), &
1403 : particles=particles, zeff=zcharge, &
1404 6 : stride=section_get_ivals(cube_section, "STRIDE"), mpi_io=mpi_io)
1405 8 : CALL cp_print_key_finished_output(unit_nr, logger, cube_section, '', mpi_io=mpi_io)
1406 : END DO
1407 2 : CALL auxbas_pw_pool%give_back_pw(vhartree)
1408 : END BLOCK
1409 : END IF
1410 4 : CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
1411 : END BLOCK
1412 : END IF
1413 :
1414 8 : CALL auxbas_pw_pool%give_back_pw(rho_tot_rspace)
1415 8 : CALL auxbas_pw_pool%give_back_pw(rho_core)
1416 :
1417 32 : END SUBROUTINE print_density_cubes
1418 :
1419 : ! **************************************************************************************************
1420 : !> \brief ...
1421 : !> \param qs_env ...
1422 : !> \param zcharge ...
1423 : !> \param elf_section ...
1424 : ! **************************************************************************************************
1425 2 : SUBROUTINE print_elf(qs_env, zcharge, elf_section)
1426 :
1427 : TYPE(qs_environment_type), POINTER :: qs_env
1428 : REAL(KIND=dp), DIMENSION(:), INTENT(IN) :: zcharge
1429 : TYPE(section_vals_type), POINTER :: elf_section
1430 :
1431 : CHARACTER(LEN=default_path_length) :: filename, mpi_filename, my_pos_cube, &
1432 : title
1433 : INTEGER :: iounit, ispin, unit_nr
1434 : LOGICAL :: append_cube, mpi_io
1435 : REAL(KIND=dp) :: rho_cutoff
1436 2 : REAL(KIND=dp), DIMENSION(:), POINTER :: tot_rho_r
1437 : TYPE(cp_logger_type), POINTER :: logger
1438 2 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: rho_ao
1439 2 : TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: rho_ao_kp
1440 : TYPE(dft_control_type), POINTER :: dft_control
1441 : TYPE(particle_list_type), POINTER :: particles
1442 2 : TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g
1443 : TYPE(pw_env_type), POINTER :: pw_env
1444 2 : TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
1445 : TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
1446 2 : TYPE(pw_r3d_rs_type), ALLOCATABLE, DIMENSION(:) :: elf_r
1447 2 : TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r
1448 : TYPE(qs_ks_env_type), POINTER :: ks_env
1449 : TYPE(qs_rho_type), POINTER :: rho
1450 : TYPE(qs_subsys_type), POINTER :: subsys
1451 :
1452 4 : logger => cp_get_default_logger()
1453 2 : iounit = cp_logger_get_default_io_unit(logger)
1454 :
1455 : ! we need to construct the density on a realspace grid
1456 2 : CALL get_qs_env(qs_env, dft_control=dft_control, ks_env=ks_env, rho=rho)
1457 2 : NULLIFY (rho_r, rho_g, tot_rho_r)
1458 : CALL qs_rho_get(rho, rho_ao_kp=rho_ao_kp, &
1459 2 : rho_r=rho_r, rho_g=rho_g, tot_rho_r=tot_rho_r)
1460 6 : DO ispin = 1, dft_control%nspins
1461 4 : rho_ao => rho_ao_kp(ispin, :)
1462 : CALL calculate_rho_elec(matrix_p_kp=rho_ao, &
1463 : rho=rho_r(ispin), &
1464 : rho_gspace=rho_g(ispin), &
1465 : total_rho=tot_rho_r(ispin), &
1466 6 : ks_env=ks_env)
1467 : END DO
1468 2 : CALL qs_rho_set(rho, rho_r_valid=.TRUE., rho_g_valid=.TRUE.)
1469 :
1470 2 : CALL get_qs_env(qs_env, subsys=subsys)
1471 2 : CALL qs_subsys_get(subsys, particles=particles)
1472 :
1473 10 : ALLOCATE (elf_r(dft_control%nspins))
1474 2 : CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
1475 2 : CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, pw_pools=pw_pools)
1476 6 : DO ispin = 1, dft_control%nspins
1477 4 : CALL auxbas_pw_pool%create_pw(elf_r(ispin))
1478 6 : CALL pw_zero(elf_r(ispin))
1479 : END DO
1480 :
1481 2 : IF (iounit > 0) THEN
1482 : WRITE (UNIT=iounit, FMT="(/,T2,A)") &
1483 1 : "ELF is computed on the real space grid -----"
1484 : END IF
1485 2 : rho_cutoff = section_get_rval(elf_section, "density_cutoff")
1486 2 : CALL qs_elf_calc(qs_env, elf_r, rho_cutoff)
1487 :
1488 : ! write ELF into cube file
1489 2 : append_cube = section_get_lval(elf_section, "APPEND")
1490 2 : my_pos_cube = "REWIND"
1491 2 : IF (append_cube) my_pos_cube = "APPEND"
1492 6 : DO ispin = 1, dft_control%nspins
1493 4 : WRITE (filename, '(a5,I1.1)') "ELF_S", ispin
1494 4 : WRITE (title, *) "ELF spin ", ispin
1495 4 : mpi_io = .TRUE.
1496 : unit_nr = cp_print_key_unit_nr(logger, elf_section, '', extension=".cube", &
1497 : middle_name=TRIM(filename), file_position=my_pos_cube, &
1498 4 : log_filename=.FALSE., mpi_io=mpi_io, fout=mpi_filename)
1499 4 : IF (iounit > 0) THEN
1500 2 : IF (.NOT. mpi_io) THEN
1501 0 : INQUIRE (UNIT=unit_nr, NAME=filename)
1502 : ELSE
1503 2 : filename = mpi_filename
1504 : END IF
1505 : WRITE (UNIT=iounit, FMT="(T2,A,/,T2,A79)") &
1506 2 : "ELF is written in cube file format to the file:", ADJUSTR(TRIM(filename))
1507 : END IF
1508 :
1509 : CALL cp_pw_to_cube(elf_r(ispin), unit_nr, title, particles=particles, zeff=zcharge, &
1510 4 : stride=section_get_ivals(elf_section, "STRIDE"), mpi_io=mpi_io)
1511 4 : CALL cp_print_key_finished_output(unit_nr, logger, elf_section, '', mpi_io=mpi_io)
1512 :
1513 6 : CALL auxbas_pw_pool%give_back_pw(elf_r(ispin))
1514 : END DO
1515 :
1516 2 : DEALLOCATE (elf_r)
1517 :
1518 2 : END SUBROUTINE print_elf
1519 : ! **************************************************************************************************
1520 : !> \brief ...
1521 : !> \param qs_env ...
1522 : !> \param zcharge ...
1523 : !> \param cube_section ...
1524 : ! **************************************************************************************************
1525 2 : SUBROUTINE print_mo_cubes(qs_env, zcharge, cube_section)
1526 :
1527 : TYPE(qs_environment_type), POINTER :: qs_env
1528 : REAL(KIND=dp), DIMENSION(:), INTENT(IN) :: zcharge
1529 : TYPE(section_vals_type), POINTER :: cube_section
1530 :
1531 : CHARACTER(LEN=default_path_length) :: filename, my_pos_cube, title
1532 : INTEGER :: homo, i, ifirst, ilast, iounit, ir, &
1533 : ispin, ivector, n_rep, nhomo, nlist, &
1534 : nlumo, nmo, shomo, unit_nr
1535 2 : INTEGER, DIMENSION(:), POINTER :: list, list_index
1536 : LOGICAL :: append_cube, mpi_io, write_cube
1537 : REAL(KIND=dp) :: homo_lumo(2, 2)
1538 2 : REAL(KIND=dp), DIMENSION(:), POINTER :: mo_eigenvalues
1539 2 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
1540 : TYPE(cell_type), POINTER :: cell
1541 : TYPE(cp_fm_type), POINTER :: mo_coeff
1542 : TYPE(cp_logger_type), POINTER :: logger
1543 2 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: ks_rmpv, mo_derivs
1544 : TYPE(dft_control_type), POINTER :: dft_control
1545 2 : TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
1546 : TYPE(particle_list_type), POINTER :: particles
1547 2 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1548 : TYPE(pw_c1d_gs_type) :: wf_g
1549 : TYPE(pw_env_type), POINTER :: pw_env
1550 2 : TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
1551 : TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
1552 : TYPE(pw_r3d_rs_type) :: wf_r
1553 2 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1554 : TYPE(qs_subsys_type), POINTER :: subsys
1555 : TYPE(scf_control_type), POINTER :: scf_control
1556 :
1557 4 : logger => cp_get_default_logger()
1558 2 : iounit = cp_logger_get_default_io_unit(logger)
1559 :
1560 2 : CALL get_qs_env(qs_env, mos=mos, matrix_ks=ks_rmpv, scf_control=scf_control)
1561 2 : CALL get_qs_env(qs_env, dft_control=dft_control, mo_derivs=mo_derivs)
1562 2 : CALL make_mo_eig(mos, dft_control%nspins, ks_rmpv, scf_control, mo_derivs)
1563 2 : NULLIFY (mo_eigenvalues)
1564 2 : homo = 0
1565 6 : DO ispin = 1, dft_control%nspins
1566 4 : CALL get_mo_set(mo_set=mos(ispin), eigenvalues=mo_eigenvalues, homo=shomo)
1567 4 : homo_lumo(ispin, 1) = mo_eigenvalues(shomo)
1568 6 : homo = MAX(homo, shomo)
1569 : END DO
1570 2 : write_cube = section_get_lval(cube_section, "WRITE_CUBE")
1571 2 : nlumo = section_get_ival(cube_section, "NLUMO")
1572 2 : nhomo = section_get_ival(cube_section, "NHOMO")
1573 2 : NULLIFY (list_index)
1574 2 : CALL section_vals_val_get(cube_section, "HOMO_LIST", n_rep_val=n_rep)
1575 2 : IF (n_rep > 0) THEN
1576 2 : nlist = 0
1577 4 : DO ir = 1, n_rep
1578 2 : NULLIFY (list)
1579 2 : CALL section_vals_val_get(cube_section, "HOMO_LIST", i_rep_val=ir, i_vals=list)
1580 4 : IF (ASSOCIATED(list)) THEN
1581 2 : CALL reallocate(list_index, 1, nlist + SIZE(list))
1582 14 : DO i = 1, SIZE(list)
1583 14 : list_index(i + nlist) = list(i)
1584 : END DO
1585 2 : nlist = nlist + SIZE(list)
1586 : END IF
1587 : END DO
1588 14 : nhomo = MAXVAL(list_index)
1589 : ELSE
1590 0 : IF (nhomo == -1) nhomo = homo
1591 0 : nlist = homo - MAX(1, homo - nhomo + 1) + 1
1592 0 : ALLOCATE (list_index(nlist))
1593 0 : DO i = 1, nlist
1594 0 : list_index(i) = MAX(1, homo - nhomo + 1) + i - 1
1595 : END DO
1596 : END IF
1597 :
1598 2 : CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
1599 2 : CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, pw_pools=pw_pools)
1600 2 : CALL auxbas_pw_pool%create_pw(wf_r)
1601 2 : CALL auxbas_pw_pool%create_pw(wf_g)
1602 :
1603 2 : CALL get_qs_env(qs_env, subsys=subsys)
1604 2 : CALL qs_subsys_get(subsys, particles=particles)
1605 :
1606 2 : append_cube = section_get_lval(cube_section, "APPEND")
1607 2 : my_pos_cube = "REWIND"
1608 2 : IF (append_cube) THEN
1609 0 : my_pos_cube = "APPEND"
1610 : END IF
1611 :
1612 : CALL get_qs_env(qs_env=qs_env, &
1613 : atomic_kind_set=atomic_kind_set, &
1614 : qs_kind_set=qs_kind_set, &
1615 : cell=cell, &
1616 2 : particle_set=particle_set)
1617 :
1618 2 : IF (nhomo >= 0) THEN
1619 6 : DO ispin = 1, dft_control%nspins
1620 : ! Prints the cube files of OCCUPIED ORBITALS
1621 : CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, &
1622 4 : eigenvalues=mo_eigenvalues, homo=homo, nmo=nmo)
1623 6 : IF (write_cube) THEN
1624 28 : DO i = 1, nlist
1625 24 : ivector = list_index(i)
1626 24 : IF (ivector > homo) CYCLE
1627 : CALL calculate_wavefunction(mo_coeff, ivector, wf_r, wf_g, atomic_kind_set, qs_kind_set, &
1628 24 : cell, dft_control, particle_set, pw_env)
1629 24 : WRITE (filename, '(a4,I5.5,a1,I1.1)') "WFN_", ivector, "_", ispin
1630 24 : mpi_io = .TRUE.
1631 : unit_nr = cp_print_key_unit_nr(logger, cube_section, '', extension=".cube", &
1632 : middle_name=TRIM(filename), file_position=my_pos_cube, &
1633 24 : log_filename=.FALSE., mpi_io=mpi_io)
1634 24 : WRITE (title, *) "WAVEFUNCTION ", ivector, " spin ", ispin, " i.e. HOMO - ", ivector - homo
1635 : CALL cp_pw_to_cube(wf_r, unit_nr, title, particles=particles, zeff=zcharge, &
1636 24 : stride=section_get_ivals(cube_section, "STRIDE"), mpi_io=mpi_io)
1637 28 : CALL cp_print_key_finished_output(unit_nr, logger, cube_section, '', mpi_io=mpi_io)
1638 : END DO
1639 : END IF
1640 : END DO
1641 : END IF
1642 :
1643 2 : IF (nlumo /= 0) THEN
1644 6 : DO ispin = 1, dft_control%nspins
1645 : ! Prints the cube files of UNOCCUPIED ORBITALS
1646 : CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, &
1647 4 : eigenvalues=mo_eigenvalues, homo=homo, nmo=nmo)
1648 6 : IF (write_cube) THEN
1649 4 : ifirst = homo + 1
1650 4 : IF (nlumo == -1) THEN
1651 0 : ilast = nmo
1652 : ELSE
1653 4 : ilast = ifirst + nlumo - 1
1654 4 : ilast = MIN(nmo, ilast)
1655 : END IF
1656 12 : DO ivector = ifirst, ilast
1657 : CALL calculate_wavefunction(mo_coeff, ivector, wf_r, wf_g, atomic_kind_set, &
1658 8 : qs_kind_set, cell, dft_control, particle_set, pw_env)
1659 8 : WRITE (filename, '(a4,I5.5,a1,I1.1)') "WFN_", ivector, "_", ispin
1660 8 : mpi_io = .TRUE.
1661 : unit_nr = cp_print_key_unit_nr(logger, cube_section, '', extension=".cube", &
1662 : middle_name=TRIM(filename), file_position=my_pos_cube, &
1663 8 : log_filename=.FALSE., mpi_io=mpi_io)
1664 8 : WRITE (title, *) "WAVEFUNCTION ", ivector, " spin ", ispin, " i.e. LUMO + ", ivector - ifirst
1665 : CALL cp_pw_to_cube(wf_r, unit_nr, title, particles=particles, zeff=zcharge, &
1666 8 : stride=section_get_ivals(cube_section, "STRIDE"), mpi_io=mpi_io)
1667 12 : CALL cp_print_key_finished_output(unit_nr, logger, cube_section, '', mpi_io=mpi_io)
1668 : END DO
1669 : END IF
1670 : END DO
1671 : END IF
1672 :
1673 2 : CALL auxbas_pw_pool%give_back_pw(wf_g)
1674 2 : CALL auxbas_pw_pool%give_back_pw(wf_r)
1675 2 : IF (ASSOCIATED(list_index)) DEALLOCATE (list_index)
1676 :
1677 2 : END SUBROUTINE print_mo_cubes
1678 :
1679 : ! **************************************************************************************************
1680 :
1681 : END MODULE qs_scf_post_tb
|