(git:50ddb19)
Loading...
Searching...
No Matches
qs_initial_guess.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Routines to somehow generate an initial guess
10!> \par History
11!> 2006.03 Moved here from qs_scf.F [Joost VandeVondele]
12! **************************************************************************************************
21 USE cp_dbcsr_api, ONLY: &
27 dbcsr_dot,&
39 USE cp_fm_types, ONLY: &
51 USE hfx_types, ONLY: hfx_type
52 USE input_constants, ONLY: &
55 USE input_cp2k_hfx, ONLY: ri_mo
59 USE kinds, ONLY: default_path_length,&
60 dp
62 USE kpoint_types, ONLY: kpoint_type
73 USE qs_kind_types, ONLY: get_qs_kind,&
82 USE qs_mo_types, ONLY: get_mo_set,&
88 USE qs_rho_types, ONLY: qs_rho_get,&
90 USE qs_scf_methods, ONLY: eigensolver,&
99 USE util, ONLY: sort
100 USE xtb_types, ONLY: get_xtb_atom_param,&
102#include "./base/base_uses.f90"
103
104 IMPLICIT NONE
105
106 PRIVATE
107
108 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_initial_guess'
109
112
113 TYPE atom_matrix_type
114 REAL(KIND=dp), DIMENSION(:, :, :), POINTER :: mat => null()
115 END TYPE atom_matrix_type
116
117CONTAINS
118
119! **************************************************************************************************
120!> \brief can use a variety of methods to come up with an initial
121!> density matrix and optionally an initial wavefunction
122!> \param scf_env SCF environment information
123!> \param qs_env QS environment
124!> \par History
125!> 03.2006 moved here from qs_scf [Joost VandeVondele]
126!> 06.2007 allow to skip the initial guess [jgh]
127!> 08.2014 kpoints [JGH]
128!> 10.2019 tot_corr_zeff, switch_surf_dip [SGh]
129!> \note
130!> badly needs to be split in subroutines each doing one of the possible
131!> schemes
132! **************************************************************************************************
133 SUBROUTINE calculate_first_density_matrix(scf_env, qs_env)
134
135 TYPE(qs_scf_env_type), POINTER :: scf_env
136 TYPE(qs_environment_type), POINTER :: qs_env
137
138 CHARACTER(LEN=*), PARAMETER :: routinen = 'calculate_first_density_matrix'
139
140 CHARACTER(LEN=default_path_length) :: file_name, filename
141 INTEGER :: atom_a, density_guess, handle, homo, i, iatom, ic, icol, id_nr, ikind, irow, &
142 iseed(4), ispin, istart_col, istart_row, j, last_read, n, n_cols, n_rows, nao, natom, &
143 natoms, natoms_tmp, nblocks, nelectron, nmo, nmo_tmp, not_read, nsgf, nspin, nvec, ounit, &
144 safe_density_guess, size_atomic_kind_set, z
145 INTEGER, ALLOCATABLE, DIMENSION(:) :: first_sgf, kind_of, last_sgf
146 INTEGER, DIMENSION(2) :: nelectron_spin
147 INTEGER, DIMENSION(:), POINTER :: atom_list, elec_conf, nelec_kind, &
148 sort_kind
149 LOGICAL :: cneo_potential_present, did_guess, do_hfx_ri_mo, do_kpoints, do_std_diag, exist, &
150 has_unit_metric, natom_mismatch, need_mos, need_wm, ofgpw, owns_ortho, print_history_log, &
151 print_log
152 REAL(dp), ALLOCATABLE, DIMENSION(:, :) :: buff, buff2
153 REAL(dp), DIMENSION(:, :), POINTER :: pdata
154 REAL(kind=dp) :: checksum, eps, length, maxocc, occ, &
155 rscale, tot_corr_zeff, trps1, zeff
156 REAL(kind=dp), DIMENSION(0:3) :: edftb
157 TYPE(atom_matrix_type), DIMENSION(:), POINTER :: pmat
158 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
159 TYPE(atomic_kind_type), POINTER :: atomic_kind
160 TYPE(cp_fm_struct_type), POINTER :: ao_ao_struct, ao_mo_struct
161 TYPE(cp_fm_type) :: sv
162 TYPE(cp_fm_type), DIMENSION(:), POINTER :: work1
163 TYPE(cp_fm_type), POINTER :: mo_coeff, moa, mob, ortho, work2
164 TYPE(cp_logger_type), POINTER :: logger
165 TYPE(dbcsr_iterator_type) :: iter
166 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: h_core_sparse, matrix_ks, p_rmpv, &
167 s_sparse
168 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_h_kp, matrix_ks_kp, matrix_s_kp, &
169 rho_ao_kp
170 TYPE(dbcsr_type) :: mo_dbcsr, mo_tmp_dbcsr
171 TYPE(dft_control_type), POINTER :: dft_control
172 TYPE(gto_basis_set_type), POINTER :: orb_basis_set
173 TYPE(hfx_type), DIMENSION(:, :), POINTER :: x_data
174 TYPE(kpoint_type), POINTER :: kpoints
175 TYPE(mo_set_type), DIMENSION(:), POINTER :: mo_array, mos_last_converged
176 TYPE(mp_para_env_type), POINTER :: para_env
177 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
178 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
179 TYPE(qs_kind_type), POINTER :: qs_kind
180 TYPE(qs_rho_type), POINTER :: rho
181 TYPE(scf_control_type), POINTER :: scf_control
182 TYPE(section_vals_type), POINTER :: dft_section, input, subsys_section
183
184 logger => cp_get_default_logger()
185 NULLIFY (atomic_kind, qs_kind, mo_coeff, orb_basis_set, atomic_kind_set, &
186 qs_kind_set, particle_set, ortho, work2, work1, mo_array, s_sparse, &
187 scf_control, dft_control, p_rmpv, para_env, h_core_sparse, matrix_ks, rho, &
188 mos_last_converged)
189 NULLIFY (dft_section, input, subsys_section)
190 NULLIFY (matrix_s_kp, matrix_h_kp, matrix_ks_kp, rho_ao_kp)
191 NULLIFY (moa, mob)
192 NULLIFY (atom_list, elec_conf, kpoints)
193 edftb = 0.0_dp
194 tot_corr_zeff = 0.0_dp
195
196 CALL timeset(routinen, handle)
197
198 CALL get_qs_env(qs_env, &
199 atomic_kind_set=atomic_kind_set, &
200 qs_kind_set=qs_kind_set, &
201 particle_set=particle_set, &
202 mos=mo_array, &
203 matrix_s_kp=matrix_s_kp, &
204 matrix_h_kp=matrix_h_kp, &
205 matrix_ks_kp=matrix_ks_kp, &
206 input=input, &
207 scf_control=scf_control, &
208 dft_control=dft_control, &
209 has_unit_metric=has_unit_metric, &
210 do_kpoints=do_kpoints, &
211 kpoints=kpoints, &
212 rho=rho, &
213 nelectron_spin=nelectron_spin, &
214 para_env=para_env, &
215 x_data=x_data)
216
217 CALL qs_rho_get(rho, rho_ao_kp=rho_ao_kp)
218
219 IF (dft_control%switch_surf_dip) THEN
220 CALL get_qs_env(qs_env, mos_last_converged=mos_last_converged)
221 END IF
222
223 ! just initialize the first image, the other density are set to zero
224 DO ispin = 1, dft_control%nspins
225 DO ic = 1, SIZE(rho_ao_kp, 2)
226 CALL dbcsr_set(rho_ao_kp(ispin, ic)%matrix, 0.0_dp)
227 END DO
228 END DO
229 s_sparse => matrix_s_kp(:, 1)
230 h_core_sparse => matrix_h_kp(:, 1)
231 matrix_ks => matrix_ks_kp(:, 1)
232 p_rmpv => rho_ao_kp(:, 1)
233
234 work1 => scf_env%scf_work1
235 work2 => scf_env%scf_work2
236 ortho => scf_env%ortho
237
238 dft_section => section_vals_get_subs_vals(input, "DFT")
239
240 nspin = dft_control%nspins
241 ofgpw = dft_control%qs_control%ofgpw
242 density_guess = scf_control%density_guess
243 do_std_diag = .false.
244
245 do_hfx_ri_mo = .false.
246 IF (ASSOCIATED(x_data)) THEN
247 IF (x_data(1, 1)%do_hfx_ri) THEN
248 IF (x_data(1, 1)%ri_data%flavor == ri_mo) do_hfx_ri_mo = .true.
249 END IF
250 END IF
251
252 IF (ASSOCIATED(scf_env%krylov_space)) do_std_diag = (scf_env%krylov_space%eps_std_diag > 0.0_dp)
253
254 need_mos = scf_control%use_ot .OR. scf_env%method == ot_diag_method_nr .OR. &
255 (scf_env%method == block_krylov_diag_method_nr .AND. .NOT. do_std_diag) &
256 .OR. dft_control%do_admm .OR. scf_env%method == block_davidson_diag_method_nr &
257 .OR. do_hfx_ri_mo
258
259 safe_density_guess = atomic_guess
260 IF (dft_control%qs_control%semi_empirical .OR. dft_control%qs_control%dftb) THEN
261 IF (density_guess == atomic_guess) density_guess = mopac_guess
262 safe_density_guess = mopac_guess
263 END IF
264 IF (dft_control%qs_control%xtb) THEN
265 IF (do_kpoints) THEN
266 IF (density_guess == atomic_guess) density_guess = mopac_guess
267 safe_density_guess = mopac_guess
268 ELSE
269 IF (density_guess == atomic_guess) density_guess = core_guess
270 safe_density_guess = core_guess
271 END IF
272 END IF
273
274 IF (scf_control%use_ot .AND. &
275 (.NOT. ((density_guess == random_guess) .OR. &
276 (density_guess == atomic_guess) .OR. &
277 (density_guess == core_guess) .OR. &
278 (density_guess == mopac_guess) .OR. &
279 (density_guess == eht_guess) .OR. &
280 (density_guess == sparse_guess) .OR. &
281 (((density_guess == restart_guess) .OR. &
282 (density_guess == history_guess)) .AND. &
283 (scf_control%level_shift == 0.0_dp))))) THEN
284 CALL cp_abort(__location__, &
285 "OT needs GUESS ATOMIC / CORE / RANDOM / SPARSE / RESTART / HISTORY RESTART: other options NYI")
286 END IF
287
288 ! if a restart was requested, check that the file exists,
289 ! if not we fall back to an atomic guess. No kidding, the file name should remain
290 ! in sync with read_mo_set_from_restart
291 id_nr = 0
292 IF (density_guess == restart_guess) THEN
293 ! only check existence on I/O node, otherwise if file exists there but
294 ! not on compute nodes, everything goes crazy even though only I/O
295 ! node actually reads the file
296 IF (do_kpoints) THEN
297 IF (para_env%is_source()) THEN
298 CALL wfn_restart_file_name(file_name, exist, dft_section, logger, kp=.true.)
299 END IF
300 ELSE
301 IF (para_env%is_source()) THEN
302 CALL wfn_restart_file_name(file_name, exist, dft_section, logger)
303 END IF
304 END IF
305 CALL para_env%bcast(exist)
306 CALL para_env%bcast(file_name)
307 IF (.NOT. exist) THEN
308 CALL cp_warn(__location__, &
309 "User requested to restart the wavefunction from the file named: "// &
310 trim(file_name)//". This file does not exist. Please check the existence of"// &
311 " the file or change properly the value of the keyword WFN_RESTART_FILE_NAME."// &
312 " Calculation continues using ATOMIC GUESS. ")
313 density_guess = safe_density_guess
314 END IF
315 ELSE IF (density_guess == history_guess) THEN
316 IF (do_kpoints) THEN
317 cpabort("calculate_first_density_matrix: history_guess not implemented for k-points")
318 END IF
319 IF (para_env%is_source()) THEN
320 CALL wfn_restart_file_name(file_name, exist, dft_section, logger)
321 END IF
322 CALL para_env%bcast(exist)
323 CALL para_env%bcast(file_name)
324 nvec = qs_env%wf_history%memory_depth
325 not_read = nvec + 1
326 ! At this level we read the saved backup RESTART files..
327 DO i = 1, nvec
328 j = i - 1
329 filename = trim(file_name)
330 IF (j /= 0) THEN
331 filename = trim(file_name)//".bak-"//adjustl(cp_to_string(j))
332 END IF
333 IF (para_env%is_source()) THEN
334 INQUIRE (file=filename, exist=exist)
335 END IF
336 CALL para_env%bcast(exist)
337 IF ((.NOT. exist) .AND. (i < not_read)) THEN
338 not_read = i
339 END IF
340 END DO
341 IF (not_read == 1) THEN
342 density_guess = restart_guess
343 filename = trim(file_name)
344 IF (para_env%is_source()) INQUIRE (file=filename, exist=exist)
345 CALL para_env%bcast(exist)
346 IF (.NOT. exist) THEN
347 CALL cp_warn(__location__, &
348 "User requested to restart the wavefunction from a series of restart files named: "// &
349 trim(file_name)//" with extensions (.bak-n). These files do not exist."// &
350 " Even trying to switch to a plain restart wave-function failes because the"// &
351 " file named: "//trim(file_name)//" does not exist. Please check the existence of"// &
352 " the file or change properly the value of the keyword WFN_RESTART_FILE_NAME."// &
353 " Calculation continues using ATOMIC GUESS. ")
354 density_guess = safe_density_guess
355 END IF
356 END IF
357 last_read = not_read - 1
358 END IF
359
360 did_guess = .false.
361
362 IF (dft_control%correct_el_density_dip) THEN
363 tot_corr_zeff = qs_env%total_zeff_corr
364 IF ((abs(tot_corr_zeff) > 0.0_dp) .AND. (density_guess /= restart_guess)) THEN
365 CALL cp_warn(__location__, &
366 "Use SCF_GUESS RESTART in conjunction with "// &
367 "CORE_CORRECTION /= 0.0 and SURFACE_DIPOLE_CORRECTION TRUE. "// &
368 "It is always advisable to perform SURFACE_DIPOLE_CORRECTION "// &
369 "after a simulation without the surface dipole correction "// &
370 "and using the ensuing wavefunction restart file. ")
371 END IF
372 END IF
373
374 ounit = -1
375 print_log = .false.
376 print_history_log = .false.
377 IF (para_env%is_source()) THEN
378 CALL section_vals_val_get(dft_section, &
379 "SCF%PRINT%RESTART%LOG_PRINT_KEY", &
380 l_val=print_log)
381 CALL section_vals_val_get(dft_section, &
382 "SCF%PRINT%RESTART_HISTORY%LOG_PRINT_KEY", &
383 l_val=print_history_log)
384 IF (print_log .OR. print_history_log) THEN
385 ounit = cp_logger_get_default_io_unit(logger)
386 END IF
387 END IF
388
389 IF (density_guess == restart_guess) THEN
390 IF (ounit > 0) THEN
391 WRITE (unit=ounit, fmt="(/,T2,A)") &
392 "WFN_RESTART| Reading restart file"
393 END IF
394 IF (do_kpoints) THEN
395 natoms = SIZE(particle_set)
396 CALL read_kpoints_restart(rho_ao_kp, kpoints, work1, &
397 natoms, para_env, id_nr, dft_section, natom_mismatch)
398 IF (natom_mismatch) density_guess = safe_density_guess
399 ELSE
400 CALL read_mo_set_from_restart(mo_array, qs_kind_set, particle_set, para_env, &
401 id_nr=id_nr, multiplicity=dft_control%multiplicity, &
402 dft_section=dft_section, &
403 natom_mismatch=natom_mismatch, &
404 out_unit=ounit)
405
406 IF (natom_mismatch) THEN
407 density_guess = safe_density_guess
408 ELSE
409 DO ispin = 1, nspin
410 IF (scf_control%level_shift /= 0.0_dp) THEN
411 CALL get_mo_set(mo_set=mo_array(ispin), mo_coeff=mo_coeff)
412 CALL cp_fm_to_fm(mo_coeff, ortho)
413 END IF
414
415 ! make all nmo vectors present orthonormal
416 CALL get_mo_set(mo_set=mo_array(ispin), &
417 mo_coeff=mo_coeff, nmo=nmo, homo=homo)
418
419 IF (has_unit_metric) THEN
420 CALL make_basis_simple(mo_coeff, nmo)
421 ELSE IF (dft_control%smear) THEN
422 CALL make_basis_lowdin(vmatrix=mo_coeff, ncol=nmo, &
423 matrix_s=s_sparse(1)%matrix)
424 ELSE
425 ! ortho so that one can restart for different positions (basis sets?)
426 CALL make_basis_sm(mo_coeff, homo, s_sparse(1)%matrix)
427 END IF
428 ! only alpha spin is kept for restricted
429 IF (dft_control%restricted) EXIT
430 END DO
431 IF (dft_control%restricted) CALL mo_set_restrict(mo_array)
432
433 IF (.NOT. scf_control%diagonalization%mom) THEN
434 IF (dft_control%correct_surf_dip) THEN
435 IF (abs(tot_corr_zeff) > 0.0_dp) THEN
436 CALL set_mo_occupation(mo_array, smear=qs_env%scf_control%smear, &
437 tot_zeff_corr=tot_corr_zeff)
438 ELSE
439 CALL set_mo_occupation(mo_array, smear=qs_env%scf_control%smear)
440 END IF
441 ELSE
442 CALL set_mo_occupation(mo_array, smear=qs_env%scf_control%smear)
443 END IF
444 END IF
445
446 DO ispin = 1, nspin
447
448 IF (scf_control%use_ot .OR. scf_env%method == ot_diag_method_nr) THEN !fm->dbcsr
449 CALL copy_fm_to_dbcsr(mo_array(ispin)%mo_coeff, &
450 mo_array(ispin)%mo_coeff_b) !fm->dbcsr
451 END IF !fm->dbcsr
452
453 CALL calculate_density_matrix(mo_array(ispin), &
454 p_rmpv(ispin)%matrix)
455 END DO
456 END IF ! natom_mismatch
457
458 END IF
459
460 ! Maximum Overlap Method
461 IF (scf_control%diagonalization%mom) THEN
462 CALL do_mom_guess(nspin, mo_array, scf_control, p_rmpv)
463 END IF
464
465 did_guess = .true.
466 END IF
467
468 IF (density_guess == history_guess) THEN
469 IF (not_read > 1) THEN
470 IF (ounit > 0) THEN
471 WRITE (unit=ounit, fmt="(/,T2,A)") &
472 "WFN_RESTART| Reading restart file history"
473 END IF
474 DO i = 1, last_read
475 j = last_read - i
476 CALL read_mo_set_from_restart(mo_array, qs_kind_set, particle_set, para_env, &
477 id_nr=j, multiplicity=dft_control%multiplicity, &
478 dft_section=dft_section, out_unit=ounit)
479
480 DO ispin = 1, nspin
481 IF (scf_control%level_shift /= 0.0_dp) THEN
482 CALL get_mo_set(mo_set=mo_array(ispin), mo_coeff=mo_coeff)
483 CALL cp_fm_to_fm(mo_coeff, ortho)
484 END IF
485
486 ! make all nmo vectors present orthonormal
487 CALL get_mo_set(mo_set=mo_array(ispin), mo_coeff=mo_coeff, nmo=nmo, homo=homo)
488
489 IF (has_unit_metric) THEN
490 CALL make_basis_simple(mo_coeff, nmo)
491 ELSE
492 ! ortho so that one can restart for different positions (basis sets?)
493 CALL make_basis_sm(mo_coeff, homo, s_sparse(1)%matrix)
494 END IF
495 ! only alpha spin is kept for restricted
496 IF (dft_control%restricted) EXIT
497 END DO
498 IF (dft_control%restricted) CALL mo_set_restrict(mo_array)
499
500 DO ispin = 1, nspin
501 CALL set_mo_occupation(mo_set=mo_array(ispin), &
502 smear=qs_env%scf_control%smear)
503 END DO
504
505 DO ispin = 1, nspin
506 IF (scf_control%use_ot .OR. scf_env%method == ot_diag_method_nr) THEN !fm->dbcsr
507 CALL copy_fm_to_dbcsr(mo_array(ispin)%mo_coeff, &
508 mo_array(ispin)%mo_coeff_b) !fm->dbcsr
509 END IF !fm->dbcsr
510 CALL calculate_density_matrix(mo_array(ispin), p_rmpv(ispin)%matrix)
511 END DO
512
513 ! Write to extrapolation pipeline
514 CALL wfi_update(wf_history=qs_env%wf_history, qs_env=qs_env, dt=1.0_dp)
515 END DO
516 END IF
517
518 did_guess = .true.
519 END IF
520
521 IF (density_guess == random_guess) THEN
522
523 DO ispin = 1, nspin
524 CALL get_mo_set(mo_set=mo_array(ispin), &
525 mo_coeff=mo_coeff, nmo=nmo)
526 CALL cp_fm_init_random(mo_coeff, nmo)
527 IF (has_unit_metric) THEN
528 CALL make_basis_simple(mo_coeff, nmo)
529 ELSE
530 CALL make_basis_sm(mo_coeff, nmo, s_sparse(1)%matrix)
531 END IF
532 ! only alpha spin is kept for restricted
533 IF (dft_control%restricted) EXIT
534 END DO
535 IF (dft_control%restricted) CALL mo_set_restrict(mo_array)
536
537 DO ispin = 1, nspin
538 CALL set_mo_occupation(mo_set=mo_array(ispin), &
539 smear=qs_env%scf_control%smear)
540 END DO
541
542 DO ispin = 1, nspin
543
544 IF (scf_control%use_ot .OR. scf_env%method == ot_diag_method_nr) THEN !fm->dbcsr
545 CALL copy_fm_to_dbcsr(mo_array(ispin)%mo_coeff, &
546 mo_array(ispin)%mo_coeff_b) !fm->dbcsr
547 END IF !fm->dbcsr
548
549 CALL calculate_density_matrix(mo_array(ispin), p_rmpv(ispin)%matrix)
550 END DO
551
552 did_guess = .true.
553 END IF
554
555 IF (density_guess == core_guess) THEN
556
557 IF (do_kpoints) THEN
558 cpabort("calculate_first_density_matrix: core_guess not implemented for k-points")
559 END IF
560
561 CALL get_qs_kind_set(qs_kind_set, cneo_potential_present=cneo_potential_present)
562 IF (cneo_potential_present) THEN
563 cpabort("calculate_first_density_matrix: core_guess not implemented for CNEO")
564 END IF
565
566 owns_ortho = .false.
567 IF (.NOT. ASSOCIATED(work1)) THEN
568 need_wm = .true.
569 cpassert(.NOT. ASSOCIATED(work2))
570 cpassert(.NOT. ASSOCIATED(ortho))
571 ELSE
572 need_wm = .false.
573 cpassert(ASSOCIATED(work2))
574 IF (.NOT. ASSOCIATED(ortho)) THEN
575 ALLOCATE (ortho)
576 owns_ortho = .true.
577 END IF
578 END IF
579
580 IF (need_wm) THEN
581 CALL get_mo_set(mo_set=mo_array(1), mo_coeff=moa)
582 CALL cp_fm_get_info(moa, matrix_struct=ao_mo_struct)
583 CALL cp_fm_struct_get(ao_mo_struct, nrow_global=nao, nrow_block=nblocks)
584 CALL cp_fm_struct_create(fmstruct=ao_ao_struct, &
585 nrow_block=nblocks, &
586 ncol_block=nblocks, &
587 nrow_global=nao, &
588 ncol_global=nao, &
589 template_fmstruct=ao_mo_struct)
590 ALLOCATE (work1(1))
591 ALLOCATE (work2, ortho)
592 CALL cp_fm_create(work1(1), ao_ao_struct)
593 CALL cp_fm_create(work2, ao_ao_struct)
594 CALL cp_fm_create(ortho, ao_ao_struct)
595 CALL copy_dbcsr_to_fm(matrix_s_kp(1, 1)%matrix, ortho)
596 CALL cp_fm_cholesky_decompose(ortho)
597 CALL cp_fm_struct_release(ao_ao_struct)
598 END IF
599
600 ispin = 1
601 ! Load core Hamiltonian into work matrix
602 CALL copy_dbcsr_to_fm(h_core_sparse(1)%matrix, work1(ispin))
603
604 ! Diagonalize the core Hamiltonian matrix and retrieve a first set of
605 ! molecular orbitals (MOs)
606 IF (has_unit_metric) THEN
607 CALL eigensolver_simple(matrix_ks=work1(ispin), &
608 mo_set=mo_array(ispin), &
609 work=work2, &
610 do_level_shift=.false., &
611 level_shift=0.0_dp, &
612 use_jacobi=.false., jacobi_threshold=0._dp)
613 ELSE
614 CALL eigensolver(matrix_ks_fm=work1(ispin), &
615 mo_set=mo_array(ispin), &
616 ortho=ortho, &
617 work=work2, &
618 cholesky_method=scf_env%cholesky_method, &
619 do_level_shift=.false., &
620 level_shift=0.0_dp, &
621 use_jacobi=.false.)
622 END IF
623
624 ! Open shell case: copy alpha MOs to beta MOs
625 IF (nspin == 2) THEN
626 CALL get_mo_set(mo_set=mo_array(1), mo_coeff=moa)
627 CALL get_mo_set(mo_set=mo_array(2), mo_coeff=mob, nmo=nmo)
628 CALL cp_fm_to_fm(moa, mob, nmo)
629 END IF
630
631 ! Build an initial density matrix (for each spin in the case of
632 ! an open shell calculation) from the first MOs set
633 DO ispin = 1, nspin
634 CALL set_mo_occupation(mo_set=mo_array(ispin), smear=scf_control%smear)
635 CALL calculate_density_matrix(mo_array(ispin), p_rmpv(ispin)%matrix)
636 END DO
637
638 ! release intermediate matrices
639 IF (need_wm) THEN
640 CALL cp_fm_release(ortho)
641 CALL cp_fm_release(work2)
642 CALL cp_fm_release(work1(1))
643 DEALLOCATE (ortho, work2)
644 DEALLOCATE (work1)
645 NULLIFY (work1, work2, ortho)
646 ELSE IF (owns_ortho) THEN
647 DEALLOCATE (ortho)
648 END IF
649
650 did_guess = .true.
651 END IF
652
653 IF (density_guess == atomic_guess) THEN
654
655 subsys_section => section_vals_get_subs_vals(input, "SUBSYS")
656 ounit = cp_print_key_unit_nr(logger, subsys_section, "PRINT%KINDS", extension=".Log")
657 IF (ounit > 0) THEN
658 WRITE (unit=ounit, fmt="(/,(T2,A))") &
659 "Atomic guess: The first density matrix is obtained in terms of atomic orbitals", &
660 " and electronic configurations assigned to each atomic kind"
661 END IF
662
663 CALL calculate_atomic_block_dm(p_rmpv, s_sparse(1)%matrix, atomic_kind_set, qs_kind_set, &
664 nspin, nelectron_spin, ounit, para_env)
665
666 DO ispin = 1, nspin
667
668 ! The orbital transformation method (OT) requires not only an
669 ! initial density matrix, but also an initial wavefunction (MO set)
670 IF (ofgpw .AND. (scf_control%use_ot .OR. scf_env%method == ot_diag_method_nr)) THEN
671 ! get orbitals later
672 ELSE
673 IF (need_mos) THEN
674
675 IF (dft_control%restricted .AND. (ispin == 2)) THEN
676 CALL mo_set_restrict(mo_array)
677 ELSE
678 CALL get_mo_set(mo_set=mo_array(ispin), &
679 mo_coeff=mo_coeff, &
680 nmo=nmo, nao=nao, homo=homo)
681
682 CALL cp_fm_set_all(mo_coeff, 0.0_dp)
683 CALL cp_fm_init_random(mo_coeff, nmo)
684
685 CALL cp_fm_create(sv, mo_coeff%matrix_struct, "SV")
686 ! multiply times PS
687 IF (has_unit_metric) THEN
688 CALL cp_fm_to_fm(mo_coeff, sv)
689 ELSE
690 ! PS*C(:,1:nomo)+C(:,nomo+1:nmo) (nomo=NINT(nelectron/maxocc))
691 CALL cp_dbcsr_sm_fm_multiply(s_sparse(1)%matrix, mo_coeff, sv, nmo)
692 END IF
693 CALL cp_dbcsr_sm_fm_multiply(p_rmpv(ispin)%matrix, sv, mo_coeff, homo)
694
695 CALL cp_fm_release(sv)
696 ! and ortho the result
697 IF (has_unit_metric) THEN
698 CALL make_basis_simple(mo_coeff, nmo)
699 ELSE
700 CALL make_basis_sm(mo_coeff, nmo, s_sparse(1)%matrix)
701 END IF
702 END IF
703
704 CALL set_mo_occupation(mo_set=mo_array(ispin), &
705 smear=qs_env%scf_control%smear)
706
707 CALL copy_fm_to_dbcsr(mo_array(ispin)%mo_coeff, &
708 mo_array(ispin)%mo_coeff_b) !fm->dbcsr
709
710 CALL calculate_density_matrix(mo_array(ispin), &
711 p_rmpv(ispin)%matrix)
712 END IF
713 ! adjust el_density in case surface_dipole_correction is switched
714 ! on and CORE_CORRECTION is non-zero
715 IF (scf_env%method == general_diag_method_nr) THEN
716 IF (dft_control%correct_surf_dip) THEN
717 IF (abs(tot_corr_zeff) > 0.0_dp) THEN
718 CALL get_mo_set(mo_set=mo_array(ispin), &
719 mo_coeff=mo_coeff, &
720 nmo=nmo, nao=nao, homo=homo)
721
722 CALL cp_fm_set_all(mo_coeff, 0.0_dp)
723 CALL cp_fm_init_random(mo_coeff, nmo)
724
725 CALL cp_fm_create(sv, mo_coeff%matrix_struct, "SV")
726 ! multiply times PS
727 IF (has_unit_metric) THEN
728 CALL cp_fm_to_fm(mo_coeff, sv)
729 ELSE
730 ! PS*C(:,1:nomo)+C(:,nomo+1:nmo) (nomo=NINT(nelectron/maxocc))
731 CALL cp_dbcsr_sm_fm_multiply(s_sparse(1)%matrix, mo_coeff, sv, nmo)
732 END IF
733 CALL cp_dbcsr_sm_fm_multiply(p_rmpv(ispin)%matrix, sv, mo_coeff, homo)
734
735 CALL cp_fm_release(sv)
736 ! and ortho the result
737 IF (has_unit_metric) THEN
738 CALL make_basis_simple(mo_coeff, nmo)
739 ELSE
740 CALL make_basis_sm(mo_coeff, nmo, s_sparse(1)%matrix)
741 END IF
742
743 CALL set_mo_occupation(mo_set=mo_array(ispin), smear=qs_env%scf_control%smear, &
744 tot_zeff_corr=tot_corr_zeff)
745
746 CALL calculate_density_matrix(mo_array(ispin), &
747 p_rmpv(ispin)%matrix)
748 END IF
749 END IF
750 END IF
751
752 END IF
753
754 END DO
755
756 IF (ofgpw .AND. (scf_control%use_ot .OR. scf_env%method == ot_diag_method_nr)) THEN
757 ! We fit a function to the square root of the density
758 CALL qs_rho_update_rho(rho, qs_env)
759 cpassert(1 == 0)
760! CALL cp_fm_create(sv,mo_coeff%matrix_struct,"SV")
761! DO ispin=1,nspin
762! CALL integrate_ppl_rspace(qs%rho%rho_r(ispin),qs_env)
763! CALL cp_cfm_solve(overlap,mos)
764! CALL get_mo_set(mo_set=mo_array(ispin),&
765! mo_coeff=mo_coeff, nmo=nmo, nao=nao)
766! CALL cp_fm_init_random(mo_coeff,nmo)
767! END DO
768! CALL cp_fm_release(sv)
769 END IF
770
771 IF (scf_control%diagonalization%mom) THEN
772 CALL do_mom_guess(nspin, mo_array, scf_control, p_rmpv)
773 END IF
774
775 CALL cp_print_key_finished_output(ounit, logger, subsys_section, &
776 "PRINT%KINDS")
777
778 did_guess = .true.
779 END IF
780
781 IF (density_guess == sparse_guess) THEN
782
783 IF (ofgpw) THEN
784 cpabort("calculate_first_density_matrix: sparse_guess not implemented for OFGPW")
785 END IF
786 IF (.NOT. scf_control%use_ot) THEN
787 cpabort("calculate_first_density_matrix: sparse_guess implemented for OT only")
788 END IF
789 IF (do_kpoints) THEN
790 cpabort("calculate_first_density_matrix: sparse_guess not implemented for k-points")
791 END IF
792
793 eps = 1.0e-5_dp
794
795 ounit = cp_logger_get_default_io_unit(logger)
796 natoms = SIZE(particle_set)
797 ALLOCATE (kind_of(natoms))
798 ALLOCATE (first_sgf(natoms), last_sgf(natoms))
799
800 checksum = dbcsr_checksum(s_sparse(1)%matrix)
801 i = dbcsr_get_num_blocks(s_sparse(1)%matrix); CALL para_env%sum(i)
802 IF (ounit > 0) WRITE (ounit, *) 'S nblks', i, ' checksum', checksum
803 CALL dbcsr_filter(s_sparse(1)%matrix, eps)
804 checksum = dbcsr_checksum(s_sparse(1)%matrix)
805 i = dbcsr_get_num_blocks(s_sparse(1)%matrix); CALL para_env%sum(i)
806 IF (ounit > 0) WRITE (ounit, *) 'S nblks', i, ' checksum', checksum
807
808 CALL get_particle_set(particle_set, qs_kind_set, first_sgf=first_sgf, &
809 last_sgf=last_sgf)
810 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, kind_of=kind_of)
811
812 ALLOCATE (pmat(SIZE(atomic_kind_set)))
813
814 rscale = 1._dp
815 IF (nspin == 2) rscale = 0.5_dp
816 DO ikind = 1, SIZE(atomic_kind_set)
817 atomic_kind => atomic_kind_set(ikind)
818 qs_kind => qs_kind_set(ikind)
819 NULLIFY (pmat(ikind)%mat)
820 CALL calculate_atomic_orbitals(atomic_kind, qs_kind, pmat=pmat(ikind)%mat)
821 NULLIFY (atomic_kind)
822 END DO
823
824 DO ispin = 1, nspin
825 CALL get_mo_set(mo_set=mo_array(ispin), &
826 maxocc=maxocc, &
827 nelectron=nelectron)
828 !
829 CALL dbcsr_iterator_start(iter, p_rmpv(ispin)%matrix)
830 DO WHILE (dbcsr_iterator_blocks_left(iter))
831 CALL dbcsr_iterator_next_block(iter, irow, icol, pdata)
832 ikind = kind_of(irow)
833 IF (icol == irow) THEN
834 IF (ispin == 1) THEN
835 pdata(:, :) = pmat(ikind)%mat(:, :, 1)*rscale + &
836 pmat(ikind)%mat(:, :, 2)*rscale
837 ELSE
838 pdata(:, :) = pmat(ikind)%mat(:, :, 1)*rscale - &
839 pmat(ikind)%mat(:, :, 2)*rscale
840 END IF
841 END IF
842 END DO
843 CALL dbcsr_iterator_stop(iter)
844
845 !CALL dbcsr_verify_matrix(p_rmpv(ispin)%matrix)
846 checksum = dbcsr_checksum(p_rmpv(ispin)%matrix)
847 occ = dbcsr_get_occupation(p_rmpv(ispin)%matrix)
848 IF (ounit > 0) WRITE (ounit, *) 'P_init occ', occ, ' checksum', checksum
849 ! so far p needs to have the same sparsity as S
850 !CALL dbcsr_filter(p_rmpv(ispin)%matrix, eps)
851 !CALL dbcsr_verify_matrix(p_rmpv(ispin)%matrix)
852 checksum = dbcsr_checksum(p_rmpv(ispin)%matrix)
853 occ = dbcsr_get_occupation(p_rmpv(ispin)%matrix)
854 IF (ounit > 0) WRITE (ounit, *) 'P_init occ', occ, ' checksum', checksum
855
856 CALL dbcsr_dot(p_rmpv(ispin)%matrix, s_sparse(1)%matrix, trps1)
857 rscale = real(nelectron, dp)/trps1
858 CALL dbcsr_scale(p_rmpv(ispin)%matrix, rscale)
859
860 !CALL dbcsr_verify_matrix(p_rmpv(ispin)%matrix)
861 checksum = dbcsr_checksum(p_rmpv(ispin)%matrix)
862 occ = dbcsr_get_occupation(p_rmpv(ispin)%matrix)
863 IF (ounit > 0) WRITE (ounit, *) 'P occ', occ, ' checksum', checksum
864 !
865 ! The orbital transformation method (OT) requires not only an
866 ! initial density matrix, but also an initial wavefunction (MO set)
867 IF (dft_control%restricted .AND. (ispin == 2)) THEN
868 CALL mo_set_restrict(mo_array)
869 ELSE
870 CALL get_mo_set(mo_set=mo_array(ispin), &
871 mo_coeff=mo_coeff, &
872 nmo=nmo, nao=nao, homo=homo)
873 CALL cp_fm_set_all(mo_coeff, 0.0_dp)
874
875 n = maxval(last_sgf - first_sgf) + 1
876 size_atomic_kind_set = SIZE(atomic_kind_set)
877
878 ALLOCATE (buff(n, n), sort_kind(size_atomic_kind_set), &
879 nelec_kind(size_atomic_kind_set))
880 !
881 ! sort kind vs nbr electron
882 DO ikind = 1, size_atomic_kind_set
883 atomic_kind => atomic_kind_set(ikind)
884 qs_kind => qs_kind_set(ikind)
885 CALL get_atomic_kind(atomic_kind=atomic_kind, &
886 natom=natom, &
887 atom_list=atom_list, &
888 z=z)
889 CALL get_qs_kind(qs_kind, nsgf=nsgf, elec_conf=elec_conf, &
890 basis_set=orb_basis_set, zeff=zeff)
891 nelec_kind(ikind) = sum(elec_conf)
892 END DO
893 CALL sort(nelec_kind, size_atomic_kind_set, sort_kind)
894 !
895 ! a -very- naive sparse guess
896 nmo_tmp = nmo
897 natoms_tmp = natoms
898 istart_col = 1
899 iseed(1) = 4; iseed(2) = 3; iseed(3) = 2; iseed(4) = 1 ! set the seed for dlarnv
900 DO i = 1, size_atomic_kind_set
901 ikind = sort_kind(i)
902 atomic_kind => atomic_kind_set(ikind)
903 CALL get_atomic_kind(atomic_kind=atomic_kind, &
904 natom=natom, atom_list=atom_list)
905 DO iatom = 1, natom
906 !
907 atom_a = atom_list(iatom)
908 istart_row = first_sgf(atom_a)
909 n_rows = last_sgf(atom_a) - first_sgf(atom_a) + 1
910 !
911 ! compute the "potential" nbr of states for this atom
912 n_cols = max(int(real(nmo_tmp, dp)/real(natoms_tmp, dp)), 1)
913 IF (n_cols > n_rows) n_cols = n_rows
914 !
915 nmo_tmp = nmo_tmp - n_cols
916 natoms_tmp = natoms_tmp - 1
917 cpassert(nmo_tmp >= 0)
918 cpassert(natoms_tmp >= 0)
919 DO j = 1, n_cols
920 CALL dlarnv(1, iseed, n_rows, buff(1, j))
921 END DO
922 CALL cp_fm_set_submatrix(mo_coeff, buff, istart_row, istart_col, &
923 n_rows, n_cols)
924 istart_col = istart_col + n_cols
925 END DO
926 END DO
927
928 cpassert(istart_col > nmo)
929
930 DEALLOCATE (buff, nelec_kind, sort_kind)
931
932 IF (.false.) THEN
933 ALLOCATE (buff(nao, 1), buff2(nao, 1))
934 DO i = 1, nmo
935 CALL cp_fm_get_submatrix(mo_coeff, buff, 1, i, nao, 1)
936 IF (sum(buff**2) < 1e-10_dp) THEN
937 IF (ounit > 0) THEN
938 WRITE (ounit, *) 'wrong', i, sum(buff**2)
939 END IF
940 END IF
941 length = norm2(buff(:, 1))
942 buff(:, :) = buff(:, :)/length
943 DO j = i + 1, nmo
944 CALL cp_fm_get_submatrix(mo_coeff, buff2, 1, j, nao, 1)
945 length = norm2(buff2(:, 1))
946 buff2(:, :) = buff2(:, :)/length
947 IF (abs(dot_product(buff(:, 1), buff2(:, 1)) - 1.0_dp) < 1e-10_dp) THEN
948 IF (ounit > 0) THEN
949 WRITE (ounit, *) 'wrong2', i, j, dot_product(buff(:, 1), buff2(:, 1))
950 DO ikind = 1, nao
951 IF (abs(mo_coeff%local_data(ikind, i)) > 1e-10_dp) THEN
952 WRITE (ounit, *) 'c1', ikind, mo_coeff%local_data(ikind, i)
953 END IF
954 IF (abs(mo_coeff%local_data(ikind, j)) > 1e-10_dp) THEN
955 WRITE (ounit, *) 'c2', ikind, mo_coeff%local_data(ikind, j)
956 END IF
957 END DO
958 END IF
959 cpabort("Something went wrong with sparse_guess!")
960 END IF
961 END DO
962 END DO
963 DEALLOCATE (buff, buff2)
964
965 END IF
966 !
967 CALL cp_fm_to_dbcsr_row_template(mo_dbcsr, mo_coeff, s_sparse(1)%matrix)
968 !CALL dbcsr_verify_matrix(mo_dbcsr)
969 checksum = dbcsr_checksum(mo_dbcsr)
970
971 occ = dbcsr_get_occupation(mo_dbcsr)
972 IF (ounit > 0) WRITE (ounit, *) 'C occ', occ, ' checksum', checksum
973 CALL dbcsr_filter(mo_dbcsr, eps)
974 !CALL dbcsr_verify_matrix(mo_dbcsr)
975 occ = dbcsr_get_occupation(mo_dbcsr)
976 checksum = dbcsr_checksum(mo_dbcsr)
977 IF (ounit > 0) WRITE (ounit, *) 'C occ', occ, ' checksum', checksum
978 !
979 ! multiply times PS
980 IF (has_unit_metric) THEN
981 cpabort("has_unit_metric will be removed soon")
982 END IF
983 !
984 ! S*C
985 CALL dbcsr_copy(mo_tmp_dbcsr, mo_dbcsr, name="mo_tmp")
986 CALL dbcsr_multiply("N", "N", 1.0_dp, s_sparse(1)%matrix, mo_dbcsr, &
987 0.0_dp, mo_tmp_dbcsr, &
988 retain_sparsity=.true.)
989 !CALL dbcsr_verify_matrix(mo_tmp_dbcsr)
990 checksum = dbcsr_checksum(mo_tmp_dbcsr)
991 occ = dbcsr_get_occupation(mo_tmp_dbcsr)
992 IF (ounit > 0) WRITE (ounit, *) 'S*C occ', occ, ' checksum', checksum
993 CALL dbcsr_filter(mo_tmp_dbcsr, eps)
994 !CALL dbcsr_verify_matrix(mo_tmp_dbcsr)
995 checksum = dbcsr_checksum(mo_tmp_dbcsr)
996 occ = dbcsr_get_occupation(mo_tmp_dbcsr)
997 IF (ounit > 0) WRITE (ounit, *) 'S*C occ', occ, ' checksum', checksum
998 !
999 ! P*SC
1000 ! the destroy is needed for the moment to avoid memory leaks !
1001 ! This one is not needed because _destroy takes care of zeroing.
1002 CALL dbcsr_multiply("N", "N", 1.0_dp, p_rmpv(ispin)%matrix, &
1003 mo_tmp_dbcsr, 0.0_dp, mo_dbcsr)
1004 IF (.false.) CALL dbcsr_verify_matrix(mo_dbcsr)
1005 checksum = dbcsr_checksum(mo_dbcsr)
1006 occ = dbcsr_get_occupation(mo_dbcsr)
1007 IF (ounit > 0) WRITE (ounit, *) 'P*SC occ', occ, ' checksum', checksum
1008 CALL dbcsr_filter(mo_dbcsr, eps)
1009 !CALL dbcsr_verify_matrix(mo_dbcsr)
1010 checksum = dbcsr_checksum(mo_dbcsr)
1011 occ = dbcsr_get_occupation(mo_dbcsr)
1012 IF (ounit > 0) WRITE (ounit, *) 'P*SC occ', occ, ' checksum', checksum
1013 !
1014 CALL copy_dbcsr_to_fm(mo_dbcsr, mo_coeff)
1015
1016 CALL dbcsr_release(mo_dbcsr)
1017 CALL dbcsr_release(mo_tmp_dbcsr)
1018
1019 ! and ortho the result
1020 CALL make_basis_sm(mo_coeff, nmo, s_sparse(1)%matrix)
1021 END IF
1022
1023 CALL set_mo_occupation(mo_set=mo_array(ispin), &
1024 smear=qs_env%scf_control%smear)
1025
1026 CALL copy_fm_to_dbcsr(mo_array(ispin)%mo_coeff, &
1027 mo_array(ispin)%mo_coeff_b) !fm->dbcsr
1028
1029 CALL calculate_density_matrix(mo_array(ispin), &
1030 p_rmpv(ispin)%matrix)
1031 DO ikind = 1, SIZE(atomic_kind_set)
1032 IF (ASSOCIATED(pmat(ikind)%mat)) THEN
1033 DEALLOCATE (pmat(ikind)%mat)
1034 END IF
1035 END DO
1036 END DO
1037
1038 DEALLOCATE (pmat)
1039
1040 DEALLOCATE (kind_of)
1041
1042 DEALLOCATE (first_sgf, last_sgf)
1043
1044 did_guess = .true.
1045 END IF
1046 IF (density_guess == mopac_guess) THEN
1047
1048 CALL calculate_mopac_dm(p_rmpv, s_sparse(1)%matrix, has_unit_metric, dft_control, &
1049 particle_set, atomic_kind_set, qs_kind_set, &
1050 nspin, nelectron_spin, para_env)
1051
1052 DO ispin = 1, nspin
1053 ! The orbital transformation method (OT) requires not only an
1054 ! initial density matrix, but also an initial wavefunction (MO set)
1055 IF (need_mos) THEN
1056 IF (dft_control%restricted .AND. (ispin == 2)) THEN
1057 CALL mo_set_restrict(mo_array)
1058 ELSE
1059 CALL get_mo_set(mo_set=mo_array(ispin), &
1060 mo_coeff=mo_coeff, &
1061 nmo=nmo, homo=homo)
1062 CALL cp_fm_init_random(mo_coeff, nmo)
1063 CALL cp_fm_create(sv, mo_coeff%matrix_struct, "SV")
1064 ! multiply times PS
1065 IF (has_unit_metric) THEN
1066 CALL cp_fm_to_fm(mo_coeff, sv)
1067 ELSE
1068 CALL cp_dbcsr_sm_fm_multiply(s_sparse(1)%matrix, mo_coeff, sv, nmo)
1069 END IF
1070 ! here we could easily multiply with the diag that we actually have replicated already
1071 CALL cp_dbcsr_sm_fm_multiply(p_rmpv(ispin)%matrix, sv, mo_coeff, homo)
1072 CALL cp_fm_release(sv)
1073 ! and ortho the result
1074 IF (has_unit_metric) THEN
1075 CALL make_basis_simple(mo_coeff, nmo)
1076 ELSE
1077 CALL make_basis_sm(mo_coeff, nmo, s_sparse(1)%matrix)
1078 END IF
1079 END IF
1080
1081 CALL set_mo_occupation(mo_set=mo_array(ispin), &
1082 smear=qs_env%scf_control%smear)
1083 CALL copy_fm_to_dbcsr(mo_array(ispin)%mo_coeff, &
1084 mo_array(ispin)%mo_coeff_b)
1085
1086 CALL calculate_density_matrix(mo_array(ispin), &
1087 p_rmpv(ispin)%matrix)
1088 END IF
1089 END DO
1090
1091 did_guess = .true.
1092 END IF
1093 !
1094 ! EHT guess (gfn0-xTB)
1095 IF (density_guess == eht_guess) THEN
1096 CALL calculate_eht_guess(qs_env, mo_array)
1097 DO ispin = 1, nspin
1098 CALL calculate_density_matrix(mo_array(ispin), p_rmpv(ispin)%matrix)
1099 END DO
1100 did_guess = .true.
1101 END IF
1102 ! switch_surf_dip [SGh]
1103 IF (dft_control%switch_surf_dip) THEN
1104 DO ispin = 1, nspin
1105 CALL reassign_allocated_mos(mos_last_converged(ispin), &
1106 mo_array(ispin))
1107 END DO
1108 END IF
1109
1110 IF (density_guess == no_guess) THEN
1111 did_guess = .true.
1112 END IF
1113
1114 IF (.NOT. did_guess) THEN
1115 cpabort("An invalid keyword for the initial density guess was specified")
1116 END IF
1117
1118 CALL timestop(handle)
1119
1120 END SUBROUTINE calculate_first_density_matrix
1121
1122! **************************************************************************************************
1123!> \brief returns a block diagonal fock matrix.
1124!> \param matrix_f ...
1125!> \param atomic_kind_set ...
1126!> \param qs_kind_set ...
1127!> \param ounit ...
1128! **************************************************************************************************
1129 SUBROUTINE calculate_atomic_fock_matrix(matrix_f, atomic_kind_set, qs_kind_set, ounit)
1130 TYPE(dbcsr_type), INTENT(INOUT) :: matrix_f
1131 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
1132 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1133 INTEGER, INTENT(IN) :: ounit
1134
1135 CHARACTER(LEN=*), PARAMETER :: routinen = 'calculate_atomic_fock_matrix'
1136
1137 INTEGER :: handle, icol, ikind, irow
1138 INTEGER, ALLOCATABLE, DIMENSION(:) :: kind_of
1139 REAL(dp), DIMENSION(:, :), POINTER :: block
1140 TYPE(atom_matrix_type), ALLOCATABLE, DIMENSION(:) :: fmat
1141 TYPE(atomic_kind_type), POINTER :: atomic_kind
1142 TYPE(dbcsr_iterator_type) :: iter
1143 TYPE(qs_kind_type), POINTER :: qs_kind
1144
1145 CALL timeset(routinen, handle)
1146
1147 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, kind_of=kind_of)
1148 ALLOCATE (fmat(SIZE(atomic_kind_set)))
1149
1150 ! precompute the atomic blocks for each atomic-kind
1151 DO ikind = 1, SIZE(atomic_kind_set)
1152 atomic_kind => atomic_kind_set(ikind)
1153 qs_kind => qs_kind_set(ikind)
1154 NULLIFY (fmat(ikind)%mat)
1155 IF (ounit > 0) WRITE (unit=ounit, fmt="(/,T2,A)") &
1156 "Calculating atomic Fock matrix for atomic kind: "//trim(atomic_kind%name)
1157
1158 !Currently only ispin=1 is supported
1159 CALL calculate_atomic_orbitals(atomic_kind, qs_kind, iunit=ounit, &
1160 fmat=fmat(ikind)%mat)
1161 END DO
1162
1163 ! zero result matrix
1164 CALL dbcsr_set(matrix_f, 0.0_dp)
1165
1166 ! copy precomputed blocks onto diagonal of result matrix
1167 CALL dbcsr_iterator_start(iter, matrix_f)
1168 DO WHILE (dbcsr_iterator_blocks_left(iter))
1169 CALL dbcsr_iterator_next_block(iter, irow, icol, block)
1170 ikind = kind_of(irow)
1171 IF (icol == irow) block(:, :) = fmat(ikind)%mat(:, :, 1)
1172 END DO
1173 CALL dbcsr_iterator_stop(iter)
1174
1175 ! cleanup
1176 DO ikind = 1, SIZE(atomic_kind_set)
1177 DEALLOCATE (fmat(ikind)%mat)
1178 END DO
1179 DEALLOCATE (fmat)
1180
1181 CALL timestop(handle)
1182
1183 END SUBROUTINE calculate_atomic_fock_matrix
1184
1185! **************************************************************************************************
1186!> \brief returns a block diagonal density matrix. Blocks correspond to the mopac initial guess.
1187!> \param pmat ...
1188!> \param matrix_s ...
1189!> \param has_unit_metric ...
1190!> \param dft_control ...
1191!> \param particle_set ...
1192!> \param atomic_kind_set ...
1193!> \param qs_kind_set ...
1194!> \param nspin ...
1195!> \param nelectron_spin ...
1196!> \param para_env ...
1197! **************************************************************************************************
1198 SUBROUTINE calculate_mopac_dm(pmat, matrix_s, has_unit_metric, &
1199 dft_control, particle_set, atomic_kind_set, qs_kind_set, &
1200 nspin, nelectron_spin, para_env)
1201 TYPE(dbcsr_p_type), DIMENSION(:), INTENT(INOUT) :: pmat
1202 TYPE(dbcsr_type), INTENT(INOUT) :: matrix_s
1203 LOGICAL :: has_unit_metric
1204 TYPE(dft_control_type), POINTER :: dft_control
1205 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1206 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
1207 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1208 INTEGER, INTENT(IN) :: nspin
1209 INTEGER, DIMENSION(:), INTENT(IN) :: nelectron_spin
1210 TYPE(mp_para_env_type) :: para_env
1211
1212 CHARACTER(LEN=*), PARAMETER :: routinen = 'calculate_mopac_dm'
1213
1214 INTEGER :: atom_a, handle, iatom, ikind, iset, &
1215 isgf, isgfa, ishell, ispin, la, maxl, &
1216 maxll, na, nao, natom, ncount, nset, &
1217 nsgf, z
1218 INTEGER, ALLOCATABLE, DIMENSION(:) :: first_sgf
1219 INTEGER, DIMENSION(25) :: laox, naox
1220 INTEGER, DIMENSION(5) :: occupation
1221 INTEGER, DIMENSION(:), POINTER :: atom_list, elec_conf, nshell
1222 INTEGER, DIMENSION(:, :), POINTER :: first_sgfa, l, last_sgfa
1223 LOGICAL :: has_pot
1224 REAL(kind=dp) :: maxocc, my_sum, nelec, occ, paa, rscale, &
1225 trps1, trps2, yy, zeff
1226 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: econf, pdiag, sdiag
1227 REAL(kind=dp), DIMENSION(0:3) :: edftb
1228 TYPE(all_potential_type), POINTER :: all_potential
1229 TYPE(cneo_potential_type), POINTER :: cneo_potential
1230 TYPE(dbcsr_type), POINTER :: matrix_p
1231 TYPE(gth_potential_type), POINTER :: gth_potential
1232 TYPE(gto_basis_set_type), POINTER :: orb_basis_set
1233 TYPE(sgp_potential_type), POINTER :: sgp_potential
1234 TYPE(xtb_atom_type), POINTER :: xtb_kind
1235
1236 CALL timeset(routinen, handle)
1237
1238 DO ispin = 1, nspin
1239 matrix_p => pmat(ispin)%matrix
1240 CALL dbcsr_set(matrix_p, 0.0_dp)
1241 END DO
1242
1243 natom = SIZE(particle_set)
1244 CALL dbcsr_get_info(pmat(1)%matrix, nfullrows_total=nao)
1245 IF (nspin == 1) THEN
1246 maxocc = 2.0_dp
1247 ELSE
1248 maxocc = 1.0_dp
1249 END IF
1250
1251 ALLOCATE (first_sgf(natom))
1252
1253 CALL get_particle_set(particle_set, qs_kind_set, first_sgf=first_sgf)
1254 CALL get_qs_kind_set(qs_kind_set, maxlgto=maxl)
1255
1256 ALLOCATE (econf(0:maxl))
1257
1258 ALLOCATE (pdiag(nao))
1259 pdiag(:) = 0.0_dp
1260
1261 ALLOCATE (sdiag(nao))
1262 sdiag(:) = 0.0_dp
1263 IF (has_unit_metric) THEN
1264 sdiag(:) = 1.0_dp
1265 ELSE
1266 CALL dbcsr_get_diag(matrix_s, sdiag)
1267 CALL para_env%sum(sdiag)
1268 END IF
1269
1270 ncount = 0
1271 trps1 = 0.0_dp
1272 trps2 = 0.0_dp
1273 pdiag(:) = 0.0_dp
1274
1275 IF (sum(nelectron_spin) /= 0) THEN
1276 DO ikind = 1, SIZE(atomic_kind_set)
1277
1278 CALL get_atomic_kind(atomic_kind_set(ikind), natom=natom, atom_list=atom_list)
1279 CALL get_qs_kind(qs_kind_set(ikind), basis_set=orb_basis_set, &
1280 all_potential=all_potential, &
1281 gth_potential=gth_potential, &
1282 sgp_potential=sgp_potential, &
1283 cneo_potential=cneo_potential)
1284 has_pot = ASSOCIATED(all_potential) .OR. ASSOCIATED(gth_potential) .OR. &
1285 ASSOCIATED(sgp_potential) .OR. ASSOCIATED(cneo_potential)
1286
1287 IF (dft_control%qs_control%dftb) THEN
1288 CALL get_dftb_atom_param(qs_kind_set(ikind)%dftb_parameter, &
1289 lmax=maxll, occupation=edftb)
1290 maxll = min(maxll, maxl)
1291 econf(0:maxl) = edftb(0:maxl)
1292 ELSE IF (dft_control%qs_control%xtb) THEN
1293 CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_kind)
1294 CALL get_xtb_atom_param(xtb_kind, z=z, natorb=nsgf, nao=naox, lao=laox, occupation=occupation)
1295 ELSE IF (has_pot) THEN
1296 CALL get_atomic_kind(atomic_kind_set(ikind), z=z)
1297 CALL get_qs_kind(qs_kind_set(ikind), nsgf=nsgf, elec_conf=elec_conf, zeff=zeff)
1298 maxll = min(SIZE(elec_conf) - 1, maxl)
1299 econf(:) = 0.0_dp
1300 econf(0:maxll) = 0.5_dp*maxocc*real(elec_conf(0:maxll), dp)
1301 ELSE
1302 cycle
1303 END IF
1304
1305 ! MOPAC TYPE GUESS
1306 IF (dft_control%qs_control%dftb) THEN
1307 DO iatom = 1, natom
1308 atom_a = atom_list(iatom)
1309 isgfa = first_sgf(atom_a)
1310 DO la = 0, maxll
1311 SELECT CASE (la)
1312 CASE (0)
1313 pdiag(isgfa) = econf(0)
1314 CASE (1)
1315 pdiag(isgfa + 1) = econf(1)/3._dp
1316 pdiag(isgfa + 2) = econf(1)/3._dp
1317 pdiag(isgfa + 3) = econf(1)/3._dp
1318 CASE (2)
1319 pdiag(isgfa + 4) = econf(2)/5._dp
1320 pdiag(isgfa + 5) = econf(2)/5._dp
1321 pdiag(isgfa + 6) = econf(2)/5._dp
1322 pdiag(isgfa + 7) = econf(2)/5._dp
1323 pdiag(isgfa + 8) = econf(2)/5._dp
1324 CASE (3)
1325 pdiag(isgfa + 9) = econf(3)/7._dp
1326 pdiag(isgfa + 10) = econf(3)/7._dp
1327 pdiag(isgfa + 11) = econf(3)/7._dp
1328 pdiag(isgfa + 12) = econf(3)/7._dp
1329 pdiag(isgfa + 13) = econf(3)/7._dp
1330 pdiag(isgfa + 14) = econf(3)/7._dp
1331 pdiag(isgfa + 15) = econf(3)/7._dp
1332 CASE DEFAULT
1333 cpabort("Only 0, 1, 2, 3 are supported as the value of la")
1334 END SELECT
1335 END DO
1336 END DO
1337 ELSE IF (dft_control%qs_control%xtb) THEN
1338 DO iatom = 1, natom
1339 atom_a = atom_list(iatom)
1340 isgfa = first_sgf(atom_a)
1341 IF (z == 1 .AND. nsgf == 2) THEN
1342 ! Hydrogen 2s basis
1343 pdiag(isgfa) = 1.0_dp/real(nspin, dp)
1344 pdiag(isgfa + 1) = 0.0_dp
1345 ELSE
1346 DO isgf = 1, nsgf
1347 na = naox(isgf)
1348 la = laox(isgf)
1349 occ = real(occupation(la + 1), dp)/real(2*la + 1, dp)
1350 occ = occ/real(nspin, dp)
1351 pdiag(isgfa + isgf - 1) = occ
1352 END DO
1353 END IF
1354 END DO
1355 ELSE IF (dft_control%qs_control%semi_empirical) THEN
1356 yy = real(dft_control%charge, kind=dp)/real(nao, kind=dp)
1357 DO iatom = 1, natom
1358 atom_a = atom_list(iatom)
1359 isgfa = first_sgf(atom_a)
1360 SELECT CASE (nsgf)
1361 CASE (1) ! s-basis
1362 pdiag(isgfa) = (zeff - yy)*0.5_dp*maxocc
1363 CASE (4) ! sp-basis
1364 IF (z == 1) THEN
1365 ! special case: hydrogen with sp basis
1366 pdiag(isgfa) = (zeff - yy)*0.5_dp*maxocc
1367 pdiag(isgfa + 1) = 0._dp
1368 pdiag(isgfa + 2) = 0._dp
1369 pdiag(isgfa + 3) = 0._dp
1370 ELSE
1371 pdiag(isgfa) = (zeff*0.25_dp - yy)*0.5_dp*maxocc
1372 pdiag(isgfa + 1) = (zeff*0.25_dp - yy)*0.5_dp*maxocc
1373 pdiag(isgfa + 2) = (zeff*0.25_dp - yy)*0.5_dp*maxocc
1374 pdiag(isgfa + 3) = (zeff*0.25_dp - yy)*0.5_dp*maxocc
1375 END IF
1376 CASE (9) ! spd-basis
1377 IF (z < 21 .OR. z > 30 .AND. z < 39 .OR. z > 48 .AND. z < 57) THEN
1378 ! Main Group Element: The "d" shell is formally empty.
1379 pdiag(isgfa) = (zeff*0.25_dp - yy)*0.5_dp*maxocc
1380 pdiag(isgfa + 1) = (zeff*0.25_dp - yy)*0.5_dp*maxocc
1381 pdiag(isgfa + 2) = (zeff*0.25_dp - yy)*0.5_dp*maxocc
1382 pdiag(isgfa + 3) = (zeff*0.25_dp - yy)*0.5_dp*maxocc
1383 pdiag(isgfa + 4) = (-yy)*0.5_dp*maxocc
1384 pdiag(isgfa + 5) = (-yy)*0.5_dp*maxocc
1385 pdiag(isgfa + 6) = (-yy)*0.5_dp*maxocc
1386 pdiag(isgfa + 7) = (-yy)*0.5_dp*maxocc
1387 pdiag(isgfa + 8) = (-yy)*0.5_dp*maxocc
1388 ELSE IF (z < 99) THEN
1389 my_sum = zeff - 9.0_dp*yy
1390 ! First, put 2 electrons in the 's' shell
1391 pdiag(isgfa) = (max(0.0_dp, min(my_sum, 2.0_dp)))*0.5_dp*maxocc
1392 my_sum = my_sum - 2.0_dp
1393 IF (my_sum > 0.0_dp) THEN
1394 ! Now put as many electrons as possible into the 'd' shell
1395 pdiag(isgfa + 4) = (max(0.0_dp, min(my_sum*0.2_dp, 2.0_dp)))*0.5_dp*maxocc
1396 pdiag(isgfa + 5) = (max(0.0_dp, min(my_sum*0.2_dp, 2.0_dp)))*0.5_dp*maxocc
1397 pdiag(isgfa + 6) = (max(0.0_dp, min(my_sum*0.2_dp, 2.0_dp)))*0.5_dp*maxocc
1398 pdiag(isgfa + 7) = (max(0.0_dp, min(my_sum*0.2_dp, 2.0_dp)))*0.5_dp*maxocc
1399 pdiag(isgfa + 8) = (max(0.0_dp, min(my_sum*0.2_dp, 2.0_dp)))*0.5_dp*maxocc
1400 my_sum = max(0.0_dp, my_sum - 10.0_dp)
1401 ! Put the remaining electrons in the 'p' shell
1402 pdiag(isgfa + 1) = (my_sum/3.0_dp)*0.5_dp*maxocc
1403 pdiag(isgfa + 2) = (my_sum/3.0_dp)*0.5_dp*maxocc
1404 pdiag(isgfa + 3) = (my_sum/3.0_dp)*0.5_dp*maxocc
1405 END IF
1406 END IF
1407 CASE DEFAULT
1408 CALL cp_abort(__location__, &
1409 "Only 1 for s-basis, 4 for sp-basis and 9 for spd-basis "// &
1410 "are supported as the value of nsgf in the MOPAC type "// &
1411 "guess for semi-empirical methods")
1412 END SELECT
1413 END DO
1414 ELSE
1415 CALL get_gto_basis_set(gto_basis_set=orb_basis_set, &
1416 nset=nset, &
1417 nshell=nshell, &
1418 l=l, &
1419 first_sgf=first_sgfa, &
1420 last_sgf=last_sgfa)
1421
1422 DO iset = 1, nset
1423 DO ishell = 1, nshell(iset)
1424 la = l(ishell, iset)
1425 nelec = maxocc*real(2*la + 1, dp)
1426 IF (econf(la) > 0.0_dp) THEN
1427 IF (econf(la) >= nelec) THEN
1428 paa = maxocc
1429 econf(la) = econf(la) - nelec
1430 ELSE
1431 paa = maxocc*econf(la)/nelec
1432 econf(la) = 0.0_dp
1433 ncount = ncount + nint(nelec/maxocc)
1434 END IF
1435 DO isgfa = first_sgfa(ishell, iset), last_sgfa(ishell, iset)
1436 DO iatom = 1, natom
1437 atom_a = atom_list(iatom)
1438 isgf = first_sgf(atom_a) + isgfa - 1
1439 pdiag(isgf) = paa
1440 IF (paa == maxocc) THEN
1441 trps1 = trps1 + paa*sdiag(isgf)
1442 ELSE
1443 trps2 = trps2 + paa*sdiag(isgf)
1444 END IF
1445 END DO
1446 END DO
1447 END IF
1448 END DO ! ishell
1449 END DO ! iset
1450 END IF
1451 END DO ! ikind
1452
1453 IF (trps2 == 0.0_dp) THEN
1454 DO isgf = 1, nao
1455 IF (sdiag(isgf) > 0.0_dp) pdiag(isgf) = pdiag(isgf)/sdiag(isgf)
1456 END DO
1457 DO ispin = 1, nspin
1458 IF (nelectron_spin(ispin) /= 0) THEN
1459 rscale = sum(pdiag)/real(nelectron_spin(ispin), dp)
1460 matrix_p => pmat(ispin)%matrix
1461 pdiag = pdiag/rscale
1462 CALL dbcsr_set_diag(matrix_p, pdiag)
1463 pdiag = pdiag*rscale
1464 END IF
1465 END DO
1466 ELSE
1467 DO ispin = 1, nspin
1468 IF (nelectron_spin(ispin) /= 0) THEN
1469 rscale = (real(nelectron_spin(ispin), dp) - trps1)/trps2
1470 DO isgf = 1, nao
1471 IF (pdiag(isgf) < maxocc) pdiag(isgf) = rscale*pdiag(isgf)
1472 END DO
1473 matrix_p => pmat(ispin)%matrix
1474 CALL dbcsr_set_diag(matrix_p, pdiag)
1475 DO isgf = 1, nao
1476 IF (pdiag(isgf) < maxocc) pdiag(isgf) = pdiag(isgf)/rscale
1477 END DO
1478 END IF
1479 END DO
1480 END IF
1481 END IF
1482
1483 DEALLOCATE (econf)
1484
1485 DEALLOCATE (first_sgf)
1486
1487 DEALLOCATE (pdiag)
1488
1489 DEALLOCATE (sdiag)
1490
1491 CALL timestop(handle)
1492
1493 END SUBROUTINE calculate_mopac_dm
1494
1495END MODULE qs_initial_guess
calculate the orbitals for a given atomic kind type
subroutine, public calculate_atomic_orbitals(atomic_kind, qs_kind, agrid, iunit, pmat, fmat, density, wavefunction, wfninfo, confine, xc_section, nocc, which_l, which_n, proj_shell_charge, ao_coef)
...
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind_set(atomic_kind_set, atom_of_kind, kind_of, natom_of_kind, maxatom, natom, nshell, fist_potential_present, shell_present, shell_adiabatic, shell_check_distance, damping_present)
Get attributes of an atomic kind set.
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.
subroutine, public get_gto_basis_set(gto_basis_set, name, aliases, norm_type, kind_radius, ncgf, nset, nsgf, cgf_symbol, sgf_symbol, norm_cgf, set_radius, lmax, lmin, lx, ly, lz, m, ncgf_set, npgf, nsgf_set, nshell, cphi, pgf_radius, sphi, scon, zet, first_cgf, first_sgf, l, last_cgf, last_sgf, n, gcc, maxco, maxl, maxpgf, maxsgf_set, maxshell, maxso, nco_sum, npgf_sum, nshell_sum, maxder, short_kind_radius, npgf_seg_sum, ccon)
...
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_verify_matrix(matrix, verbosity, local)
...
subroutine, public dbcsr_scale(matrix, alpha_scalar)
...
logical function, public dbcsr_iterator_blocks_left(iterator)
...
subroutine, public dbcsr_iterator_stop(iterator)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_multiply(transa, transb, alpha, matrix_a, matrix_b, beta, matrix_c, first_row, last_row, first_column, last_column, first_k, last_k, retain_sparsity, filter_eps, flop)
...
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
subroutine, public dbcsr_iterator_next_block(iterator, row, column, block, block_number_argument_has_been_removed, row_size, col_size, row_offset, col_offset, transposed)
...
subroutine, public dbcsr_filter(matrix, eps)
...
real(kind=dp) function, public dbcsr_get_occupation(matrix)
...
subroutine, public dbcsr_iterator_start(iterator, matrix, shared, dynamic, dynamic_byrows)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
integer function, public dbcsr_get_num_blocks(matrix)
...
subroutine, public dbcsr_set_diag(matrix, diag)
Copies the diagonal elements from the given array into the given matrix.
real(kind=dp) function, public dbcsr_checksum(matrix, pos)
Calculates the checksum of a DBCSR matrix.
subroutine, public dbcsr_get_diag(matrix, diag)
Copies the diagonal elements from the given matrix into the given array.
subroutine, public dbcsr_dot(matrix_a, matrix_b, trace)
Computes the dot product of two matrices, also known as the trace of their matrix product.
DBCSR operations in CP2K.
subroutine, public cp_dbcsr_sm_fm_multiply(matrix, fm_in, fm_out, ncol, alpha, beta)
multiply a dbcsr with a fm matrix
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public cp_fm_to_dbcsr_row_template(matrix, fm_in, template)
Utility function to copy a specially shaped fm to dbcsr_matrix The result matrix will be the matrix i...
subroutine, public copy_fm_to_dbcsr(fm, matrix, keep_sparsity)
Copy a BLACS matrix to a dbcsr matrix.
various cholesky decomposition related routines
subroutine, public cp_fm_cholesky_decompose(matrix, n, info_out)
used to replace a symmetric positive def. matrix M with its cholesky decomposition U: M = U^T * U,...
represent 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_get(fmstruct, para_env, context, descriptor, ncol_block, nrow_block, nrow_global, ncol_global, first_p_pos, row_indices, col_indices, nrow_local, ncol_local, nrow_locals, ncol_locals, local_leading_dimension)
returns the values of various attributes of the 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_set_submatrix(fm, new_values, start_row, start_col, n_rows, n_cols, alpha, beta, transpose)
sets a submatrix of a full matrix fm(start_row:start_row+n_rows,start_col:start_col+n_cols) = alpha*o...
subroutine, public cp_fm_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
subroutine, public cp_fm_get_submatrix(fm, target_m, start_row, start_col, n_rows, n_cols, transpose)
gets a submatrix of a full matrix op(target_m)(1:n_rows,1:n_cols) =fm(start_row:start_row+n_rows,...
subroutine, public cp_fm_init_random(matrix, ncol, start_col)
fills a matrix with random numbers
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
Definition of the atomic potential types.
Types and set/get functions for HFX.
Definition hfx_types.F:16
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public core_guess
integer, parameter, public mopac_guess
integer, parameter, public no_guess
integer, parameter, public atomic_guess
integer, parameter, public history_guess
integer, parameter, public random_guess
integer, parameter, public sparse_guess
integer, parameter, public restart_guess
integer, parameter, public eht_guess
function that builds the hartree fock exchange section of the input
integer, parameter, public ri_mo
objects that represent the structure of input sections and the data contained in an input section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
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
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_path_length
Definition kinds.F:58
Restart file for k point calculations.
Definition kpoint_io.F:13
subroutine, public read_kpoints_restart(denmat, kpoints, fmwork, natom, para_env, id_nr, dft_section, natom_mismatch)
...
Definition kpoint_io.F:309
Types and basic routines needed for a kpoint calculation.
Interface to the message passing library MPI.
Define methods related to particle_type.
subroutine, public get_particle_set(particle_set, qs_kind_set, first_sgf, last_sgf, nsgf, nmao, basis, ncgf)
Get the components of a particle set.
Define the data structure for the particle information.
Routine to return block diagonal density matrix. Blocks correspond to the atomic densities.
subroutine, public calculate_atomic_block_dm(pmatrix, matrix_s, atomic_kind_set, qs_kind_set, nspin, nelectron_spin, ounit, para_env)
returns a block diagonal density matrix. Blocks correspond to the atomic densities.
Types used by CNEO-DFT (see J. Chem. Theory Comput. 2025, 21, 16, 7865–7877)
collects routines that calculate density matrices
Working with the DFTB parameter types.
subroutine, public get_dftb_atom_param(dftb_parameter, name, typ, defined, z, zeff, natorb, lmax, skself, occupation, eta, energy, cutoff, xi, di, rcdisp, dudq)
...
Generate an initial guess (dm and orb) from EHT calculation.
subroutine, public calculate_eht_guess(qs_env, mo_array)
EHT MO guess calclulation.
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
Routines to somehow generate an initial guess.
subroutine, public calculate_first_density_matrix(scf_env, qs_env)
can use a variety of methods to come up with an initial density matrix and optionally an initial wave...
subroutine, public calculate_mopac_dm(pmat, matrix_s, has_unit_metric, dft_control, particle_set, atomic_kind_set, qs_kind_set, nspin, nelectron_spin, para_env)
returns a block diagonal density matrix. Blocks correspond to the mopac initial guess.
subroutine, public calculate_atomic_fock_matrix(matrix_f, atomic_kind_set, qs_kind_set, ounit)
returns a block diagonal fock matrix.
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, cneo_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, hund_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, proj_shell_charge, lr_atom, do_mtlr, u_j_loop, ao_coef, init_u_ramping_each_scf, reltmat, ghost, monovalent, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
subroutine, public get_qs_kind_set(qs_kind_set, all_potential_present, tnadd_potential_present, gth_potential_present, sgp_potential_present, paw_atom_present, dft_plus_u_atom_present, maxcgf, maxsgf, maxco, maxco_proj, maxgtops, maxlgto, maxlprj, maxnset, maxsgf_set, ncgf, npgf, nset, nsgf, nshell, maxpol, maxlppl, maxlppnl, maxppnl, nelectron, maxder, max_ngrid_rad, max_sph_harm, maxg_iso_not0, lmax_rho0, basis_rcut, do_mtlr_present, basis_type, total_zeff_corr, npgf_seg, cneo_potential_present, nkind_q, natom_q)
Get attributes of an atomic kind set.
Definition and initialisation of the mo data type.
Definition qs_mo_io.F:21
subroutine, public wfn_restart_file_name(filename, exist, section, logger, kp, xas, rtp)
...
Definition qs_mo_io.F:458
subroutine, public read_mo_set_from_restart(mo_array, qs_kind_set, particle_set, para_env, id_nr, multiplicity, dft_section, natom_mismatch, cdft, out_unit)
...
Definition qs_mo_io.F:524
collects routines that perform operations directly related to MOs
subroutine, public make_basis_simple(vmatrix, ncol)
given a set of vectors, return an orthogonal (C^T C == 1) set spanning the same space (notice,...
subroutine, public make_basis_lowdin(vmatrix, ncol, matrix_s)
return a set of S orthonormal vectors (C^T S C == 1) where a Loedwin transformation is applied to kee...
subroutine, public make_basis_sm(vmatrix, ncol, matrix_s)
returns an S-orthonormal basis v (v^T S v ==1)
Set occupation of molecular orbitals.
Definition and initialisation of the mo data type.
Definition qs_mo_types.F:22
subroutine, public mo_set_restrict(mo_array, convert_dbcsr)
make the beta orbitals explicitly equal to the alpha orbitals effectively copying the orbital data
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.
subroutine, public reassign_allocated_mos(mo_set_new, mo_set_old)
reassign an already allocated mo_set
methods for deltaSCF calculations
subroutine, public do_mom_guess(nspins, mos, scf_control, p_rmpv)
initial guess for the maximum overlap method
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...
groups fairly general SCF methods, so that modules other than qs_scf can use them too split off from ...
subroutine, public eigensolver_simple(matrix_ks, mo_set, work, do_level_shift, level_shift, use_jacobi, jacobi_threshold)
...
subroutine, public eigensolver(matrix_ks_fm, mo_set, ortho, work, cholesky_method, do_level_shift, level_shift, matrix_u_fm, use_jacobi)
Diagonalise the Kohn-Sham matrix to get a new set of MO eigen- vectors and MO eigenvalues....
module that contains the definitions of the scf types
integer, parameter, public ot_diag_method_nr
integer, parameter, public block_davidson_diag_method_nr
integer, parameter, public block_krylov_diag_method_nr
integer, parameter, public general_diag_method_nr
Storage of past states of the qs_env. Methods to interpolate (or actually normally extrapolate) the n...
subroutine, public wfi_update(wf_history, qs_env, dt)
updates the snapshot buffer, taking a new snapshot
parameters that control an scf iteration
All kind of helpful little routines.
Definition util.F:14
Definition of the xTB parameter types.
Definition xtb_types.F:20
subroutine, public get_xtb_atom_param(xtb_parameter, symbol, aname, typ, defined, z, zeff, natorb, lmax, nao, lao, rcut, rcov, kx, eta, xgamma, alpha, zneff, nshell, nval, lval, kpoly, kappa, wall, hen, zeta, xi, kappa0, alpg, occupation, electronegativity, chmax, en, kqat2, kcn, kq)
...
Definition xtb_types.F:203
Provides all information about an atomic kind.
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...
stores some data used in construction of Kohn-Sham matrix
Definition hfx_types.F:514
Contains information about kpoints.
stores all the informations relevant to an mpi environment
Provides all information about a quickstep kind.
keeps the density in various representations, keeping track of which ones are valid.