(git:db0abe2)
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 ! The cube density initializes the first KS potential. Keep an atomic AO
244 ! density matrix and MO set as auxiliary state until the first regular
245 ! solver step creates a density matrix consistent with that potential.
246 IF (density_guess == external_density_guess) density_guess = atomic_guess
247 do_std_diag = .false.
248
249 do_hfx_ri_mo = .false.
250 IF (ASSOCIATED(x_data)) THEN
251 IF (x_data(1, 1)%do_hfx_ri) THEN
252 IF (x_data(1, 1)%ri_data%flavor == ri_mo) do_hfx_ri_mo = .true.
253 END IF
254 END IF
255
256 IF (ASSOCIATED(scf_env%krylov_settings)) do_std_diag = (scf_env%krylov_settings%eps_std_diag > 0.0_dp)
257
258 need_mos = scf_control%use_ot .OR. scf_env%method == ot_diag_method_nr .OR. &
259 (scf_env%method == block_krylov_diag_method_nr .AND. .NOT. do_kpoints .AND. .NOT. do_std_diag) &
260 .OR. dft_control%do_admm .OR. do_hfx_ri_mo .OR. &
261 (scf_env%method == block_davidson_diag_method_nr .AND. .NOT. do_kpoints)
262
263 safe_density_guess = atomic_guess
264 IF (dft_control%qs_control%semi_empirical .OR. dft_control%qs_control%dftb) THEN
265 IF (density_guess == atomic_guess) density_guess = mopac_guess
266 safe_density_guess = mopac_guess
267 END IF
268 IF (dft_control%qs_control%xtb) THEN
269 IF (do_kpoints) THEN
270 IF (density_guess == atomic_guess) density_guess = mopac_guess
271 safe_density_guess = mopac_guess
272 ELSE
273 IF (density_guess == atomic_guess) density_guess = core_guess
274 safe_density_guess = core_guess
275 END IF
276 END IF
277
278 IF (scf_control%use_ot .AND. &
279 (.NOT. ((density_guess == random_guess) .OR. &
280 (density_guess == atomic_guess) .OR. &
281 (density_guess == core_guess) .OR. &
282 (density_guess == mopac_guess) .OR. &
283 (density_guess == eht_guess) .OR. &
284 (density_guess == sparse_guess) .OR. &
285 (((density_guess == restart_guess) .OR. &
286 (density_guess == history_guess)) .AND. &
287 (scf_control%level_shift == 0.0_dp))))) THEN
288 CALL cp_abort(__location__, &
289 "OT needs GUESS ATOMIC / CORE / RANDOM / SPARSE / RESTART / HISTORY RESTART: other options NYI")
290 END IF
291
292 ! if a restart was requested, check that the file exists,
293 ! if not we fall back to an atomic guess. No kidding, the file name should remain
294 ! in sync with read_mo_set_from_restart
295 id_nr = 0
296 IF (density_guess == restart_guess) THEN
297 ! only check existence on I/O node, otherwise if file exists there but
298 ! not on compute nodes, everything goes crazy even though only I/O
299 ! node actually reads the file
300 IF (do_kpoints) THEN
301 IF (para_env%is_source()) THEN
302 CALL wfn_restart_file_name(file_name, exist, dft_section, logger, kp=.true.)
303 END IF
304 ELSE
305 IF (para_env%is_source()) THEN
306 CALL wfn_restart_file_name(file_name, exist, dft_section, logger)
307 END IF
308 END IF
309 CALL para_env%bcast(exist)
310 CALL para_env%bcast(file_name)
311 IF (.NOT. exist) THEN
312 CALL cp_warn(__location__, &
313 "User requested to restart the wavefunction from the file named: "// &
314 trim(file_name)//". This file does not exist. Please check the existence of"// &
315 " the file or change properly the value of the keyword WFN_RESTART_FILE_NAME."// &
316 " Calculation continues using ATOMIC GUESS. ")
317 density_guess = safe_density_guess
318 END IF
319 ELSE IF (density_guess == history_guess) THEN
320 IF (do_kpoints) THEN
321 cpabort("calculate_first_density_matrix: history_guess not implemented for k-points")
322 END IF
323 IF (para_env%is_source()) THEN
324 CALL wfn_restart_file_name(file_name, exist, dft_section, logger)
325 END IF
326 CALL para_env%bcast(exist)
327 CALL para_env%bcast(file_name)
328 nvec = qs_env%wf_history%memory_depth
329 not_read = nvec + 1
330 ! At this level we read the saved backup RESTART files..
331 DO i = 1, nvec
332 j = i - 1
333 filename = trim(file_name)
334 IF (j /= 0) THEN
335 filename = trim(file_name)//".bak-"//adjustl(cp_to_string(j))
336 END IF
337 IF (para_env%is_source()) THEN
338 INQUIRE (file=filename, exist=exist)
339 END IF
340 CALL para_env%bcast(exist)
341 IF ((.NOT. exist) .AND. (i < not_read)) THEN
342 not_read = i
343 END IF
344 END DO
345 IF (not_read == 1) THEN
346 density_guess = restart_guess
347 filename = trim(file_name)
348 IF (para_env%is_source()) INQUIRE (file=filename, exist=exist)
349 CALL para_env%bcast(exist)
350 IF (.NOT. exist) THEN
351 CALL cp_warn(__location__, &
352 "User requested to restart the wavefunction from a series of restart files named: "// &
353 trim(file_name)//" with extensions (.bak-n). These files do not exist."// &
354 " Even trying to switch to a plain restart wave-function failes because the"// &
355 " file named: "//trim(file_name)//" does not exist. Please check the existence of"// &
356 " the file or change properly the value of the keyword WFN_RESTART_FILE_NAME."// &
357 " Calculation continues using ATOMIC GUESS. ")
358 density_guess = safe_density_guess
359 END IF
360 END IF
361 last_read = not_read - 1
362 END IF
363
364 did_guess = .false.
365
366 IF (dft_control%correct_el_density_dip) THEN
367 tot_corr_zeff = qs_env%total_zeff_corr
368 IF ((abs(tot_corr_zeff) > 0.0_dp) .AND. (density_guess /= restart_guess)) THEN
369 CALL cp_warn(__location__, &
370 "Use SCF_GUESS RESTART in conjunction with "// &
371 "CORE_CORRECTION /= 0.0 and SURFACE_DIPOLE_CORRECTION TRUE. "// &
372 "It is always advisable to perform SURFACE_DIPOLE_CORRECTION "// &
373 "after a simulation without the surface dipole correction "// &
374 "and using the ensuing wavefunction restart file. ")
375 END IF
376 END IF
377
378 ounit = -1
379 print_log = .false.
380 print_history_log = .false.
381 IF (para_env%is_source()) THEN
382 CALL section_vals_val_get(dft_section, &
383 "SCF%PRINT%RESTART%LOG_PRINT_KEY", &
384 l_val=print_log)
385 CALL section_vals_val_get(dft_section, &
386 "SCF%PRINT%RESTART_HISTORY%LOG_PRINT_KEY", &
387 l_val=print_history_log)
388 IF (print_log .OR. print_history_log) THEN
389 ounit = cp_logger_get_default_io_unit(logger)
390 END IF
391 END IF
392
393 IF (density_guess == restart_guess) THEN
394 IF (ounit > 0) THEN
395 WRITE (unit=ounit, fmt="(/,T2,A)") &
396 "WFN_RESTART| Reading restart file"
397 END IF
398 IF (do_kpoints) THEN
399 natoms = SIZE(particle_set)
400 CALL read_kpoints_restart(rho_ao_kp, kpoints, work1, &
401 natoms, para_env, id_nr, dft_section, natom_mismatch)
402 IF (natom_mismatch) density_guess = safe_density_guess
403 ELSE
404 CALL read_mo_set_from_restart(mo_array, qs_kind_set, particle_set, para_env, &
405 id_nr=id_nr, multiplicity=dft_control%multiplicity, &
406 dft_section=dft_section, &
407 natom_mismatch=natom_mismatch, &
408 out_unit=ounit)
409
410 IF (natom_mismatch) THEN
411 density_guess = safe_density_guess
412 ELSE
413 DO ispin = 1, nspin
414 ! make all nmo vectors present orthonormal
415 CALL get_mo_set(mo_set=mo_array(ispin), &
416 mo_coeff=mo_coeff, nmo=nmo, homo=homo)
417
418 IF (has_unit_metric) THEN
419 CALL make_basis_simple(mo_coeff, nmo)
420 ELSE IF (dft_control%smear) THEN
421 CALL make_basis_lowdin(vmatrix=mo_coeff, ncol=nmo, &
422 matrix_s=s_sparse(1)%matrix)
423 ELSE
424 ! ortho so that one can restart for different positions (basis sets?)
425 CALL make_basis_sm(mo_coeff, homo, s_sparse(1)%matrix)
426 END IF
427 ! only alpha spin is kept for restricted
428 IF (dft_control%restricted) EXIT
429 END DO
430 IF (dft_control%restricted) CALL mo_set_restrict(mo_array)
431
432 IF (.NOT. scf_control%diagonalization%mom) THEN
433 IF (dft_control%correct_surf_dip) THEN
434 IF (abs(tot_corr_zeff) > 0.0_dp) THEN
435 CALL set_mo_occupation(mo_array, smear=qs_env%scf_control%smear, &
436 tot_zeff_corr=tot_corr_zeff)
437 ELSE
438 CALL set_mo_occupation(mo_array, smear=qs_env%scf_control%smear)
439 END IF
440 ELSE
441 CALL set_mo_occupation(mo_array, smear=qs_env%scf_control%smear)
442 END IF
443 END IF
444
445 DO ispin = 1, nspin
446
447 IF (scf_control%use_ot .OR. scf_env%method == ot_diag_method_nr) THEN !fm->dbcsr
448 CALL copy_fm_to_dbcsr(mo_array(ispin)%mo_coeff, &
449 mo_array(ispin)%mo_coeff_b) !fm->dbcsr
450 END IF !fm->dbcsr
451
452 CALL calculate_density_matrix(mo_array(ispin), &
453 p_rmpv(ispin)%matrix)
454 END DO
455 END IF ! natom_mismatch
456
457 END IF
458
459 ! Maximum Overlap Method
460 IF (scf_control%diagonalization%mom) THEN
461 CALL do_mom_guess(nspin, mo_array, scf_control, p_rmpv)
462 END IF
463
464 did_guess = .true.
465 END IF
466
467 IF (density_guess == history_guess) THEN
468 IF (not_read > 1) THEN
469 IF (ounit > 0) THEN
470 WRITE (unit=ounit, fmt="(/,T2,A)") &
471 "WFN_RESTART| Reading restart file history"
472 END IF
473 DO i = 1, last_read
474 j = last_read - i
475 CALL read_mo_set_from_restart(mo_array, qs_kind_set, particle_set, para_env, &
476 id_nr=j, multiplicity=dft_control%multiplicity, &
477 dft_section=dft_section, out_unit=ounit)
478
479 DO ispin = 1, nspin
480 ! make all nmo vectors present orthonormal
481 CALL get_mo_set(mo_set=mo_array(ispin), mo_coeff=mo_coeff, nmo=nmo, homo=homo)
482
483 IF (has_unit_metric) THEN
484 CALL make_basis_simple(mo_coeff, nmo)
485 ELSE
486 ! ortho so that one can restart for different positions (basis sets?)
487 CALL make_basis_sm(mo_coeff, homo, s_sparse(1)%matrix)
488 END IF
489 ! only alpha spin is kept for restricted
490 IF (dft_control%restricted) EXIT
491 END DO
492 IF (dft_control%restricted) CALL mo_set_restrict(mo_array)
493
494 DO ispin = 1, nspin
495 CALL set_mo_occupation(mo_set=mo_array(ispin), &
496 smear=qs_env%scf_control%smear)
497 END DO
498
499 DO ispin = 1, nspin
500 IF (scf_control%use_ot .OR. scf_env%method == ot_diag_method_nr) THEN !fm->dbcsr
501 CALL copy_fm_to_dbcsr(mo_array(ispin)%mo_coeff, &
502 mo_array(ispin)%mo_coeff_b) !fm->dbcsr
503 END IF !fm->dbcsr
504 CALL calculate_density_matrix(mo_array(ispin), p_rmpv(ispin)%matrix)
505 END DO
506
507 ! Write to extrapolation pipeline
508 CALL wfi_update(wf_history=qs_env%wf_history, qs_env=qs_env, dt=1.0_dp)
509 END DO
510 END IF
511
512 did_guess = .true.
513 END IF
514
515 IF (density_guess == random_guess) THEN
516
517 DO ispin = 1, nspin
518 CALL get_mo_set(mo_set=mo_array(ispin), &
519 mo_coeff=mo_coeff, nmo=nmo)
520 CALL cp_fm_init_random(mo_coeff, nmo)
521 IF (has_unit_metric) THEN
522 CALL make_basis_simple(mo_coeff, nmo)
523 ELSE
524 CALL make_basis_sm(mo_coeff, nmo, s_sparse(1)%matrix)
525 END IF
526 ! only alpha spin is kept for restricted
527 IF (dft_control%restricted) EXIT
528 END DO
529 IF (dft_control%restricted) CALL mo_set_restrict(mo_array)
530
531 DO ispin = 1, nspin
532 CALL set_mo_occupation(mo_set=mo_array(ispin), &
533 smear=qs_env%scf_control%smear)
534 END DO
535
536 DO ispin = 1, nspin
537
538 IF (scf_control%use_ot .OR. scf_env%method == ot_diag_method_nr) THEN !fm->dbcsr
539 CALL copy_fm_to_dbcsr(mo_array(ispin)%mo_coeff, &
540 mo_array(ispin)%mo_coeff_b) !fm->dbcsr
541 END IF !fm->dbcsr
542
543 CALL calculate_density_matrix(mo_array(ispin), p_rmpv(ispin)%matrix)
544 END DO
545
546 did_guess = .true.
547 END IF
548
549 IF (density_guess == core_guess) THEN
550
551 IF (do_kpoints) THEN
552 cpabort("calculate_first_density_matrix: core_guess not implemented for k-points")
553 END IF
554
555 CALL get_qs_kind_set(qs_kind_set, cneo_potential_present=cneo_potential_present)
556 IF (cneo_potential_present) THEN
557 cpabort("calculate_first_density_matrix: core_guess not implemented for CNEO")
558 END IF
559
560 owns_ortho = .false.
561 IF (.NOT. ASSOCIATED(work1)) THEN
562 need_wm = .true.
563 cpassert(.NOT. ASSOCIATED(work2))
564 cpassert(.NOT. ASSOCIATED(ortho))
565 ELSE
566 need_wm = .false.
567 cpassert(ASSOCIATED(work2))
568 IF (.NOT. ASSOCIATED(ortho)) THEN
569 ALLOCATE (ortho)
570 owns_ortho = .true.
571 END IF
572 END IF
573
574 IF (need_wm) THEN
575 CALL get_mo_set(mo_set=mo_array(1), mo_coeff=moa)
576 CALL cp_fm_get_info(moa, matrix_struct=ao_mo_struct)
577 CALL cp_fm_struct_get(ao_mo_struct, nrow_global=nao, nrow_block=nblocks)
578 CALL cp_fm_struct_create(fmstruct=ao_ao_struct, &
579 nrow_block=nblocks, &
580 ncol_block=nblocks, &
581 nrow_global=nao, &
582 ncol_global=nao, &
583 template_fmstruct=ao_mo_struct)
584 ALLOCATE (work1(1))
585 ALLOCATE (work2, ortho)
586 CALL cp_fm_create(work1(1), ao_ao_struct)
587 CALL cp_fm_create(work2, ao_ao_struct)
588 CALL cp_fm_create(ortho, ao_ao_struct)
589 CALL copy_dbcsr_to_fm(matrix_s_kp(1, 1)%matrix, ortho)
590 CALL cp_fm_cholesky_decompose(ortho)
591 CALL cp_fm_struct_release(ao_ao_struct)
592 END IF
593
594 ispin = 1
595 ! Load core Hamiltonian into work matrix
596 CALL copy_dbcsr_to_fm(h_core_sparse(1)%matrix, work1(ispin))
597
598 ! Diagonalize the core Hamiltonian matrix and retrieve a first set of
599 ! molecular orbitals (MOs)
600 IF (has_unit_metric) THEN
601 CALL eigensolver_simple(matrix_ks=work1(ispin), &
602 mo_set=mo_array(ispin), &
603 work=work2, &
604 do_level_shift=.false., &
605 level_shift=0.0_dp, &
606 use_jacobi=.false., jacobi_threshold=0._dp)
607 ELSE
608 CALL eigensolver(matrix_ks_fm=work1(ispin), &
609 mo_set=mo_array(ispin), &
610 ortho=ortho, &
611 work=work2, &
612 cholesky_method=scf_env%cholesky_method, &
613 do_level_shift=.false., &
614 level_shift=0.0_dp, &
615 use_jacobi=.false.)
616 END IF
617
618 ! Open shell case: copy alpha MOs to beta MOs
619 IF (nspin == 2) THEN
620 CALL get_mo_set(mo_set=mo_array(1), mo_coeff=moa)
621 CALL get_mo_set(mo_set=mo_array(2), mo_coeff=mob, nmo=nmo)
622 CALL cp_fm_to_fm(moa, mob, nmo)
623 END IF
624
625 ! Build an initial density matrix (for each spin in the case of
626 ! an open shell calculation) from the first MOs set
627 DO ispin = 1, nspin
628 CALL set_mo_occupation(mo_set=mo_array(ispin), smear=scf_control%smear)
629 CALL calculate_density_matrix(mo_array(ispin), p_rmpv(ispin)%matrix)
630 END DO
631
632 ! release intermediate matrices
633 IF (need_wm) THEN
634 CALL cp_fm_release(ortho)
635 CALL cp_fm_release(work2)
636 CALL cp_fm_release(work1(1))
637 DEALLOCATE (ortho, work2)
638 DEALLOCATE (work1)
639 NULLIFY (work1, work2, ortho)
640 ELSE IF (owns_ortho) THEN
641 DEALLOCATE (ortho)
642 END IF
643
644 did_guess = .true.
645 END IF
646
647 IF (density_guess == atomic_guess) THEN
648
649 subsys_section => section_vals_get_subs_vals(input, "SUBSYS")
650 ounit = cp_print_key_unit_nr(logger, subsys_section, "PRINT%KINDS", extension=".Log")
651 IF (ounit > 0) THEN
652 WRITE (unit=ounit, fmt="(/,(T2,A))") &
653 "Atomic guess: The first density matrix is obtained in terms of atomic orbitals", &
654 " and electronic configurations assigned to each atomic kind"
655 END IF
656
657 CALL calculate_atomic_block_dm(p_rmpv, s_sparse(1)%matrix, atomic_kind_set, qs_kind_set, &
658 nspin, nelectron_spin, ounit, para_env)
659
660 DO ispin = 1, nspin
661
662 ! The orbital transformation method (OT) requires not only an
663 ! initial density matrix, but also an initial wavefunction (MO set)
664 IF (ofgpw .AND. (scf_control%use_ot .OR. scf_env%method == ot_diag_method_nr)) THEN
665 ! get orbitals later
666 ELSE
667 IF (need_mos) THEN
668
669 IF (dft_control%restricted .AND. (ispin == 2)) THEN
670 CALL mo_set_restrict(mo_array)
671 ELSE
672 CALL get_mo_set(mo_set=mo_array(ispin), &
673 mo_coeff=mo_coeff, &
674 nmo=nmo, nao=nao, homo=homo)
675
676 CALL cp_fm_set_all(mo_coeff, 0.0_dp)
677 CALL cp_fm_init_random(mo_coeff, nmo)
678
679 CALL cp_fm_create(sv, mo_coeff%matrix_struct, "SV")
680 ! multiply times PS
681 IF (has_unit_metric) THEN
682 CALL cp_fm_to_fm(mo_coeff, sv)
683 ELSE
684 ! PS*C(:,1:nomo)+C(:,nomo+1:nmo) (nomo=NINT(nelectron/maxocc))
685 CALL cp_dbcsr_sm_fm_multiply(s_sparse(1)%matrix, mo_coeff, sv, nmo)
686 END IF
687 CALL cp_dbcsr_sm_fm_multiply(p_rmpv(ispin)%matrix, sv, mo_coeff, homo)
688
689 CALL cp_fm_release(sv)
690 ! and ortho the result
691 IF (has_unit_metric) THEN
692 CALL make_basis_simple(mo_coeff, nmo)
693 ELSE
694 CALL make_basis_sm(mo_coeff, nmo, s_sparse(1)%matrix)
695 END IF
696 END IF
697
698 CALL set_mo_occupation(mo_set=mo_array(ispin), &
699 smear=qs_env%scf_control%smear)
700
701 CALL copy_fm_to_dbcsr(mo_array(ispin)%mo_coeff, &
702 mo_array(ispin)%mo_coeff_b) !fm->dbcsr
703
704 CALL calculate_density_matrix(mo_array(ispin), &
705 p_rmpv(ispin)%matrix)
706 END IF
707 ! adjust el_density in case surface_dipole_correction is switched
708 ! on and CORE_CORRECTION is non-zero
709 IF (scf_env%method == general_diag_method_nr) THEN
710 IF (dft_control%correct_surf_dip) THEN
711 IF (abs(tot_corr_zeff) > 0.0_dp) THEN
712 CALL get_mo_set(mo_set=mo_array(ispin), &
713 mo_coeff=mo_coeff, &
714 nmo=nmo, nao=nao, homo=homo)
715
716 CALL cp_fm_set_all(mo_coeff, 0.0_dp)
717 CALL cp_fm_init_random(mo_coeff, nmo)
718
719 CALL cp_fm_create(sv, mo_coeff%matrix_struct, "SV")
720 ! multiply times PS
721 IF (has_unit_metric) THEN
722 CALL cp_fm_to_fm(mo_coeff, sv)
723 ELSE
724 ! PS*C(:,1:nomo)+C(:,nomo+1:nmo) (nomo=NINT(nelectron/maxocc))
725 CALL cp_dbcsr_sm_fm_multiply(s_sparse(1)%matrix, mo_coeff, sv, nmo)
726 END IF
727 CALL cp_dbcsr_sm_fm_multiply(p_rmpv(ispin)%matrix, sv, mo_coeff, homo)
728
729 CALL cp_fm_release(sv)
730 ! and ortho the result
731 IF (has_unit_metric) THEN
732 CALL make_basis_simple(mo_coeff, nmo)
733 ELSE
734 CALL make_basis_sm(mo_coeff, nmo, s_sparse(1)%matrix)
735 END IF
736
737 CALL set_mo_occupation(mo_set=mo_array(ispin), smear=qs_env%scf_control%smear, &
738 tot_zeff_corr=tot_corr_zeff)
739
740 CALL calculate_density_matrix(mo_array(ispin), &
741 p_rmpv(ispin)%matrix)
742 END IF
743 END IF
744 END IF
745
746 END IF
747
748 END DO
749
750 IF (ofgpw .AND. (scf_control%use_ot .OR. scf_env%method == ot_diag_method_nr)) THEN
751 ! We fit a function to the square root of the density
752 CALL qs_rho_update_rho(rho, qs_env)
753 cpassert(1 == 0)
754! CALL cp_fm_create(sv,mo_coeff%matrix_struct,"SV")
755! DO ispin=1,nspin
756! CALL integrate_ppl_rspace(qs%rho%rho_r(ispin),qs_env)
757! CALL cp_cfm_solve(overlap,mos)
758! CALL get_mo_set(mo_set=mo_array(ispin),&
759! mo_coeff=mo_coeff, nmo=nmo, nao=nao)
760! CALL cp_fm_init_random(mo_coeff,nmo)
761! END DO
762! CALL cp_fm_release(sv)
763 END IF
764
765 IF (scf_control%diagonalization%mom) THEN
766 CALL do_mom_guess(nspin, mo_array, scf_control, p_rmpv)
767 END IF
768
769 CALL cp_print_key_finished_output(ounit, logger, subsys_section, &
770 "PRINT%KINDS")
771
772 did_guess = .true.
773 END IF
774
775 IF (density_guess == sparse_guess) THEN
776
777 IF (ofgpw) THEN
778 cpabort("calculate_first_density_matrix: sparse_guess not implemented for OFGPW")
779 END IF
780 IF (.NOT. scf_control%use_ot) THEN
781 cpabort("calculate_first_density_matrix: sparse_guess implemented for OT only")
782 END IF
783 IF (do_kpoints) THEN
784 cpabort("calculate_first_density_matrix: sparse_guess not implemented for k-points")
785 END IF
786
787 eps = 1.0e-5_dp
788
789 ounit = cp_logger_get_default_io_unit(logger)
790 natoms = SIZE(particle_set)
791 ALLOCATE (kind_of(natoms))
792 ALLOCATE (first_sgf(natoms), last_sgf(natoms))
793
794 checksum = dbcsr_checksum(s_sparse(1)%matrix)
795 i = dbcsr_get_num_blocks(s_sparse(1)%matrix); CALL para_env%sum(i)
796 IF (ounit > 0) WRITE (ounit, *) 'S nblks', i, ' checksum', checksum
797 CALL dbcsr_filter(s_sparse(1)%matrix, eps)
798 checksum = dbcsr_checksum(s_sparse(1)%matrix)
799 i = dbcsr_get_num_blocks(s_sparse(1)%matrix); CALL para_env%sum(i)
800 IF (ounit > 0) WRITE (ounit, *) 'S nblks', i, ' checksum', checksum
801
802 CALL get_particle_set(particle_set, qs_kind_set, first_sgf=first_sgf, &
803 last_sgf=last_sgf)
804 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, kind_of=kind_of)
805
806 ALLOCATE (pmat(SIZE(atomic_kind_set)))
807
808 rscale = 1._dp
809 IF (nspin == 2) rscale = 0.5_dp
810 DO ikind = 1, SIZE(atomic_kind_set)
811 atomic_kind => atomic_kind_set(ikind)
812 qs_kind => qs_kind_set(ikind)
813 NULLIFY (pmat(ikind)%mat)
814 CALL calculate_atomic_orbitals(atomic_kind, qs_kind, pmat=pmat(ikind)%mat)
815 NULLIFY (atomic_kind)
816 END DO
817
818 DO ispin = 1, nspin
819 CALL get_mo_set(mo_set=mo_array(ispin), &
820 maxocc=maxocc, &
821 nelectron=nelectron)
822 !
823 CALL dbcsr_iterator_start(iter, p_rmpv(ispin)%matrix)
824 DO WHILE (dbcsr_iterator_blocks_left(iter))
825 CALL dbcsr_iterator_next_block(iter, irow, icol, pdata)
826 ikind = kind_of(irow)
827 IF (icol == irow) THEN
828 IF (ispin == 1) THEN
829 pdata(:, :) = pmat(ikind)%mat(:, :, 1)*rscale + &
830 pmat(ikind)%mat(:, :, 2)*rscale
831 ELSE
832 pdata(:, :) = pmat(ikind)%mat(:, :, 1)*rscale - &
833 pmat(ikind)%mat(:, :, 2)*rscale
834 END IF
835 END IF
836 END DO
837 CALL dbcsr_iterator_stop(iter)
838
839 !CALL dbcsr_verify_matrix(p_rmpv(ispin)%matrix)
840 checksum = dbcsr_checksum(p_rmpv(ispin)%matrix)
841 occ = dbcsr_get_occupation(p_rmpv(ispin)%matrix)
842 IF (ounit > 0) WRITE (ounit, *) 'P_init occ', occ, ' checksum', checksum
843 ! so far p needs to have the same sparsity as S
844 !CALL dbcsr_filter(p_rmpv(ispin)%matrix, eps)
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
850 CALL dbcsr_dot(p_rmpv(ispin)%matrix, s_sparse(1)%matrix, trps1)
851 rscale = real(nelectron, dp)/trps1
852 CALL dbcsr_scale(p_rmpv(ispin)%matrix, rscale)
853
854 !CALL dbcsr_verify_matrix(p_rmpv(ispin)%matrix)
855 checksum = dbcsr_checksum(p_rmpv(ispin)%matrix)
856 occ = dbcsr_get_occupation(p_rmpv(ispin)%matrix)
857 IF (ounit > 0) WRITE (ounit, *) 'P occ', occ, ' checksum', checksum
858 !
859 ! The orbital transformation method (OT) requires not only an
860 ! initial density matrix, but also an initial wavefunction (MO set)
861 IF (dft_control%restricted .AND. (ispin == 2)) THEN
862 CALL mo_set_restrict(mo_array)
863 ELSE
864 CALL get_mo_set(mo_set=mo_array(ispin), &
865 mo_coeff=mo_coeff, &
866 nmo=nmo, nao=nao, homo=homo)
867 CALL cp_fm_set_all(mo_coeff, 0.0_dp)
868
869 n = maxval(last_sgf - first_sgf) + 1
870 size_atomic_kind_set = SIZE(atomic_kind_set)
871
872 ALLOCATE (buff(n, n), sort_kind(size_atomic_kind_set), &
873 nelec_kind(size_atomic_kind_set))
874 !
875 ! sort kind vs nbr electron
876 DO ikind = 1, size_atomic_kind_set
877 atomic_kind => atomic_kind_set(ikind)
878 qs_kind => qs_kind_set(ikind)
879 CALL get_atomic_kind(atomic_kind=atomic_kind, &
880 natom=natom, &
881 atom_list=atom_list, &
882 z=z)
883 CALL get_qs_kind(qs_kind, nsgf=nsgf, elec_conf=elec_conf, &
884 basis_set=orb_basis_set, zeff=zeff)
885 nelec_kind(ikind) = sum(elec_conf)
886 END DO
887 CALL sort(nelec_kind, size_atomic_kind_set, sort_kind)
888 !
889 ! a -very- naive sparse guess
890 nmo_tmp = nmo
891 natoms_tmp = natoms
892 istart_col = 1
893 iseed(1) = 4; iseed(2) = 3; iseed(3) = 2; iseed(4) = 1 ! set the seed for dlarnv
894 DO i = 1, size_atomic_kind_set
895 ikind = sort_kind(i)
896 atomic_kind => atomic_kind_set(ikind)
897 CALL get_atomic_kind(atomic_kind=atomic_kind, &
898 natom=natom, atom_list=atom_list)
899 DO iatom = 1, natom
900 !
901 atom_a = atom_list(iatom)
902 istart_row = first_sgf(atom_a)
903 n_rows = last_sgf(atom_a) - first_sgf(atom_a) + 1
904 !
905 ! compute the "potential" nbr of states for this atom
906 n_cols = max(int(real(nmo_tmp, dp)/real(natoms_tmp, dp)), 1)
907 IF (n_cols > n_rows) n_cols = n_rows
908 !
909 nmo_tmp = nmo_tmp - n_cols
910 natoms_tmp = natoms_tmp - 1
911 cpassert(nmo_tmp >= 0)
912 cpassert(natoms_tmp >= 0)
913 DO j = 1, n_cols
914 CALL dlarnv(1, iseed, n_rows, buff(1, j))
915 END DO
916 CALL cp_fm_set_submatrix(mo_coeff, buff, istart_row, istart_col, &
917 n_rows, n_cols)
918 istart_col = istart_col + n_cols
919 END DO
920 END DO
921
922 cpassert(istart_col > nmo)
923
924 DEALLOCATE (buff, nelec_kind, sort_kind)
925
926 IF (.false.) THEN
927 ALLOCATE (buff(nao, 1), buff2(nao, 1))
928 DO i = 1, nmo
929 CALL cp_fm_get_submatrix(mo_coeff, buff, 1, i, nao, 1)
930 IF (sum(buff**2) < 1e-10_dp) THEN
931 IF (ounit > 0) THEN
932 WRITE (ounit, *) 'wrong', i, sum(buff**2)
933 END IF
934 END IF
935 length = norm2(buff(:, 1))
936 buff(:, :) = buff(:, :)/length
937 DO j = i + 1, nmo
938 CALL cp_fm_get_submatrix(mo_coeff, buff2, 1, j, nao, 1)
939 length = norm2(buff2(:, 1))
940 buff2(:, :) = buff2(:, :)/length
941 IF (abs(dot_product(buff(:, 1), buff2(:, 1)) - 1.0_dp) < 1e-10_dp) THEN
942 IF (ounit > 0) THEN
943 WRITE (ounit, *) 'wrong2', i, j, dot_product(buff(:, 1), buff2(:, 1))
944 DO ikind = 1, nao
945 IF (abs(mo_coeff%local_data(ikind, i)) > 1e-10_dp) THEN
946 WRITE (ounit, *) 'c1', ikind, mo_coeff%local_data(ikind, i)
947 END IF
948 IF (abs(mo_coeff%local_data(ikind, j)) > 1e-10_dp) THEN
949 WRITE (ounit, *) 'c2', ikind, mo_coeff%local_data(ikind, j)
950 END IF
951 END DO
952 END IF
953 cpabort("Something went wrong with sparse_guess!")
954 END IF
955 END DO
956 END DO
957 DEALLOCATE (buff, buff2)
958
959 END IF
960 !
961 CALL cp_fm_to_dbcsr_row_template(mo_dbcsr, mo_coeff, s_sparse(1)%matrix)
962 !CALL dbcsr_verify_matrix(mo_dbcsr)
963 checksum = dbcsr_checksum(mo_dbcsr)
964
965 occ = dbcsr_get_occupation(mo_dbcsr)
966 IF (ounit > 0) WRITE (ounit, *) 'C occ', occ, ' checksum', checksum
967 CALL dbcsr_filter(mo_dbcsr, eps)
968 !CALL dbcsr_verify_matrix(mo_dbcsr)
969 occ = dbcsr_get_occupation(mo_dbcsr)
970 checksum = dbcsr_checksum(mo_dbcsr)
971 IF (ounit > 0) WRITE (ounit, *) 'C occ', occ, ' checksum', checksum
972 !
973 ! multiply times PS
974 IF (has_unit_metric) THEN
975 cpabort("has_unit_metric will be removed soon")
976 END IF
977 !
978 ! S*C
979 CALL dbcsr_copy(mo_tmp_dbcsr, mo_dbcsr, name="mo_tmp")
980 CALL dbcsr_multiply("N", "N", 1.0_dp, s_sparse(1)%matrix, mo_dbcsr, &
981 0.0_dp, mo_tmp_dbcsr, &
982 retain_sparsity=.true.)
983 !CALL dbcsr_verify_matrix(mo_tmp_dbcsr)
984 checksum = dbcsr_checksum(mo_tmp_dbcsr)
985 occ = dbcsr_get_occupation(mo_tmp_dbcsr)
986 IF (ounit > 0) WRITE (ounit, *) 'S*C occ', occ, ' checksum', checksum
987 CALL dbcsr_filter(mo_tmp_dbcsr, eps)
988 !CALL dbcsr_verify_matrix(mo_tmp_dbcsr)
989 checksum = dbcsr_checksum(mo_tmp_dbcsr)
990 occ = dbcsr_get_occupation(mo_tmp_dbcsr)
991 IF (ounit > 0) WRITE (ounit, *) 'S*C occ', occ, ' checksum', checksum
992 !
993 ! P*SC
994 ! the destroy is needed for the moment to avoid memory leaks !
995 ! This one is not needed because _destroy takes care of zeroing.
996 CALL dbcsr_multiply("N", "N", 1.0_dp, p_rmpv(ispin)%matrix, &
997 mo_tmp_dbcsr, 0.0_dp, mo_dbcsr)
998 IF (.false.) CALL dbcsr_verify_matrix(mo_dbcsr)
999 checksum = dbcsr_checksum(mo_dbcsr)
1000 occ = dbcsr_get_occupation(mo_dbcsr)
1001 IF (ounit > 0) WRITE (ounit, *) 'P*SC occ', occ, ' checksum', checksum
1002 CALL dbcsr_filter(mo_dbcsr, eps)
1003 !CALL dbcsr_verify_matrix(mo_dbcsr)
1004 checksum = dbcsr_checksum(mo_dbcsr)
1005 occ = dbcsr_get_occupation(mo_dbcsr)
1006 IF (ounit > 0) WRITE (ounit, *) 'P*SC occ', occ, ' checksum', checksum
1007 !
1008 CALL copy_dbcsr_to_fm(mo_dbcsr, mo_coeff)
1009
1010 CALL dbcsr_release(mo_dbcsr)
1011 CALL dbcsr_release(mo_tmp_dbcsr)
1012
1013 ! and ortho the result
1014 CALL make_basis_sm(mo_coeff, nmo, s_sparse(1)%matrix)
1015 END IF
1016
1017 CALL set_mo_occupation(mo_set=mo_array(ispin), &
1018 smear=qs_env%scf_control%smear)
1019
1020 CALL copy_fm_to_dbcsr(mo_array(ispin)%mo_coeff, &
1021 mo_array(ispin)%mo_coeff_b) !fm->dbcsr
1022
1023 CALL calculate_density_matrix(mo_array(ispin), &
1024 p_rmpv(ispin)%matrix)
1025 DO ikind = 1, SIZE(atomic_kind_set)
1026 IF (ASSOCIATED(pmat(ikind)%mat)) THEN
1027 DEALLOCATE (pmat(ikind)%mat)
1028 END IF
1029 END DO
1030 END DO
1031
1032 DEALLOCATE (pmat)
1033
1034 DEALLOCATE (kind_of)
1035
1036 DEALLOCATE (first_sgf, last_sgf)
1037
1038 did_guess = .true.
1039 END IF
1040 IF (density_guess == mopac_guess) THEN
1041
1042 CALL calculate_mopac_dm(p_rmpv, s_sparse(1)%matrix, has_unit_metric, dft_control, &
1043 particle_set, atomic_kind_set, qs_kind_set, &
1044 nspin, nelectron_spin, para_env)
1045
1046 DO ispin = 1, nspin
1047 ! The orbital transformation method (OT) requires not only an
1048 ! initial density matrix, but also an initial wavefunction (MO set)
1049 IF (need_mos) THEN
1050 IF (dft_control%restricted .AND. (ispin == 2)) THEN
1051 CALL mo_set_restrict(mo_array)
1052 ELSE
1053 CALL get_mo_set(mo_set=mo_array(ispin), &
1054 mo_coeff=mo_coeff, &
1055 nmo=nmo, homo=homo)
1056 CALL cp_fm_init_random(mo_coeff, nmo)
1057 CALL cp_fm_create(sv, mo_coeff%matrix_struct, "SV")
1058 ! multiply times PS
1059 IF (has_unit_metric) THEN
1060 CALL cp_fm_to_fm(mo_coeff, sv)
1061 ELSE
1062 CALL cp_dbcsr_sm_fm_multiply(s_sparse(1)%matrix, mo_coeff, sv, nmo)
1063 END IF
1064 ! here we could easily multiply with the diag that we actually have replicated already
1065 CALL cp_dbcsr_sm_fm_multiply(p_rmpv(ispin)%matrix, sv, mo_coeff, homo)
1066 CALL cp_fm_release(sv)
1067 ! and ortho the result
1068 IF (has_unit_metric) THEN
1069 CALL make_basis_simple(mo_coeff, nmo)
1070 ELSE
1071 CALL make_basis_sm(mo_coeff, nmo, s_sparse(1)%matrix)
1072 END IF
1073 END IF
1074
1075 CALL set_mo_occupation(mo_set=mo_array(ispin), &
1076 smear=qs_env%scf_control%smear)
1077 CALL copy_fm_to_dbcsr(mo_array(ispin)%mo_coeff, &
1078 mo_array(ispin)%mo_coeff_b)
1079
1080 CALL calculate_density_matrix(mo_array(ispin), &
1081 p_rmpv(ispin)%matrix)
1082 END IF
1083 END DO
1084
1085 did_guess = .true.
1086 END IF
1087 !
1088 ! EHT guess (gfn0-xTB)
1089 IF (density_guess == eht_guess) THEN
1090 CALL calculate_eht_guess(qs_env, mo_array)
1091 DO ispin = 1, nspin
1092 CALL calculate_density_matrix(mo_array(ispin), p_rmpv(ispin)%matrix)
1093 END DO
1094 did_guess = .true.
1095 END IF
1096 ! switch_surf_dip [SGh]
1097 IF (dft_control%switch_surf_dip) THEN
1098 DO ispin = 1, nspin
1099 CALL reassign_allocated_mos(mos_last_converged(ispin), &
1100 mo_array(ispin))
1101 END DO
1102 END IF
1103
1104 IF (density_guess == no_guess) THEN
1105 did_guess = .true.
1106 END IF
1107
1108 IF (.NOT. did_guess) THEN
1109 cpabort("An invalid keyword for the initial density guess was specified")
1110 END IF
1111
1112 CALL timestop(handle)
1113
1114 END SUBROUTINE calculate_first_density_matrix
1115
1116! **************************************************************************************************
1117!> \brief returns a block diagonal fock matrix.
1118!> \param matrix_f ...
1119!> \param atomic_kind_set ...
1120!> \param qs_kind_set ...
1121!> \param ounit ...
1122! **************************************************************************************************
1123 SUBROUTINE calculate_atomic_fock_matrix(matrix_f, atomic_kind_set, qs_kind_set, ounit)
1124 TYPE(dbcsr_type), INTENT(INOUT) :: matrix_f
1125 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
1126 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1127 INTEGER, INTENT(IN) :: ounit
1128
1129 CHARACTER(LEN=*), PARAMETER :: routinen = 'calculate_atomic_fock_matrix'
1130
1131 INTEGER :: handle, icol, ikind, irow
1132 INTEGER, ALLOCATABLE, DIMENSION(:) :: kind_of
1133 REAL(dp), DIMENSION(:, :), POINTER :: block
1134 TYPE(atom_matrix_type), ALLOCATABLE, DIMENSION(:) :: fmat
1135 TYPE(atomic_kind_type), POINTER :: atomic_kind
1136 TYPE(dbcsr_iterator_type) :: iter
1137 TYPE(qs_kind_type), POINTER :: qs_kind
1138
1139 CALL timeset(routinen, handle)
1140
1141 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, kind_of=kind_of)
1142 ALLOCATE (fmat(SIZE(atomic_kind_set)))
1143
1144 ! precompute the atomic blocks for each atomic-kind
1145 DO ikind = 1, SIZE(atomic_kind_set)
1146 atomic_kind => atomic_kind_set(ikind)
1147 qs_kind => qs_kind_set(ikind)
1148 NULLIFY (fmat(ikind)%mat)
1149 IF (ounit > 0) WRITE (unit=ounit, fmt="(/,T2,A)") &
1150 "Calculating atomic Fock matrix for atomic kind: "//trim(atomic_kind%name)
1151
1152 !Currently only ispin=1 is supported
1153 CALL calculate_atomic_orbitals(atomic_kind, qs_kind, iunit=ounit, &
1154 fmat=fmat(ikind)%mat)
1155 END DO
1156
1157 ! zero result matrix
1158 CALL dbcsr_set(matrix_f, 0.0_dp)
1159
1160 ! copy precomputed blocks onto diagonal of result matrix
1161 CALL dbcsr_iterator_start(iter, matrix_f)
1162 DO WHILE (dbcsr_iterator_blocks_left(iter))
1163 CALL dbcsr_iterator_next_block(iter, irow, icol, block)
1164 ikind = kind_of(irow)
1165 IF (icol == irow) block(:, :) = fmat(ikind)%mat(:, :, 1)
1166 END DO
1167 CALL dbcsr_iterator_stop(iter)
1168
1169 ! cleanup
1170 DO ikind = 1, SIZE(atomic_kind_set)
1171 DEALLOCATE (fmat(ikind)%mat)
1172 END DO
1173 DEALLOCATE (fmat)
1174
1175 CALL timestop(handle)
1176
1177 END SUBROUTINE calculate_atomic_fock_matrix
1178
1179! **************************************************************************************************
1180!> \brief returns a block diagonal density matrix. Blocks correspond to the mopac initial guess.
1181!> \param pmat ...
1182!> \param matrix_s ...
1183!> \param has_unit_metric ...
1184!> \param dft_control ...
1185!> \param particle_set ...
1186!> \param atomic_kind_set ...
1187!> \param qs_kind_set ...
1188!> \param nspin ...
1189!> \param nelectron_spin ...
1190!> \param para_env ...
1191! **************************************************************************************************
1192 SUBROUTINE calculate_mopac_dm(pmat, matrix_s, has_unit_metric, &
1193 dft_control, particle_set, atomic_kind_set, qs_kind_set, &
1194 nspin, nelectron_spin, para_env)
1195 TYPE(dbcsr_p_type), DIMENSION(:), INTENT(INOUT) :: pmat
1196 TYPE(dbcsr_type), INTENT(INOUT) :: matrix_s
1197 LOGICAL :: has_unit_metric
1198 TYPE(dft_control_type), POINTER :: dft_control
1199 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1200 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
1201 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1202 INTEGER, INTENT(IN) :: nspin
1203 INTEGER, DIMENSION(:), INTENT(IN) :: nelectron_spin
1204 TYPE(mp_para_env_type) :: para_env
1205
1206 CHARACTER(LEN=*), PARAMETER :: routinen = 'calculate_mopac_dm'
1207
1208 INTEGER :: atom_a, handle, iatom, ikind, iset, &
1209 isgf, isgfa, ishell, ispin, la, maxl, &
1210 maxll, na, nao, natom, ncount, nset, &
1211 nsgf, z
1212 INTEGER, ALLOCATABLE, DIMENSION(:) :: first_sgf
1213 INTEGER, DIMENSION(25) :: laox, naox
1214 INTEGER, DIMENSION(5) :: occupation
1215 INTEGER, DIMENSION(:), POINTER :: atom_list, elec_conf, nshell
1216 INTEGER, DIMENSION(:, :), POINTER :: first_sgfa, l, last_sgfa
1217 LOGICAL :: has_pot
1218 REAL(kind=dp) :: maxocc, my_sum, nelec, occ, paa, rscale, &
1219 trps1, trps2, yy, zeff
1220 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: econf, pdiag, sdiag
1221 REAL(kind=dp), DIMENSION(0:3) :: edftb
1222 TYPE(all_potential_type), POINTER :: all_potential
1223 TYPE(cneo_potential_type), POINTER :: cneo_potential
1224 TYPE(dbcsr_type), POINTER :: matrix_p
1225 TYPE(gth_potential_type), POINTER :: gth_potential
1226 TYPE(gto_basis_set_type), POINTER :: orb_basis_set
1227 TYPE(sgp_potential_type), POINTER :: sgp_potential
1228 TYPE(xtb_atom_type), POINTER :: xtb_kind
1229
1230 CALL timeset(routinen, handle)
1231
1232 DO ispin = 1, nspin
1233 matrix_p => pmat(ispin)%matrix
1234 CALL dbcsr_set(matrix_p, 0.0_dp)
1235 END DO
1236
1237 natom = SIZE(particle_set)
1238 CALL dbcsr_get_info(pmat(1)%matrix, nfullrows_total=nao)
1239 IF (nspin == 1) THEN
1240 maxocc = 2.0_dp
1241 ELSE
1242 maxocc = 1.0_dp
1243 END IF
1244
1245 ALLOCATE (first_sgf(natom))
1246
1247 CALL get_particle_set(particle_set, qs_kind_set, first_sgf=first_sgf)
1248 CALL get_qs_kind_set(qs_kind_set, maxlgto=maxl)
1249
1250 ALLOCATE (econf(0:maxl))
1251
1252 ALLOCATE (pdiag(nao))
1253 pdiag(:) = 0.0_dp
1254
1255 ALLOCATE (sdiag(nao))
1256 sdiag(:) = 0.0_dp
1257 IF (has_unit_metric) THEN
1258 sdiag(:) = 1.0_dp
1259 ELSE
1260 CALL dbcsr_get_diag(matrix_s, sdiag)
1261 CALL para_env%sum(sdiag)
1262 END IF
1263
1264 ncount = 0
1265 trps1 = 0.0_dp
1266 trps2 = 0.0_dp
1267 pdiag(:) = 0.0_dp
1268
1269 IF (sum(nelectron_spin) /= 0) THEN
1270 DO ikind = 1, SIZE(atomic_kind_set)
1271
1272 CALL get_atomic_kind(atomic_kind_set(ikind), natom=natom, atom_list=atom_list)
1273 CALL get_qs_kind(qs_kind_set(ikind), basis_set=orb_basis_set, &
1274 all_potential=all_potential, &
1275 gth_potential=gth_potential, &
1276 sgp_potential=sgp_potential, &
1277 cneo_potential=cneo_potential)
1278 has_pot = ASSOCIATED(all_potential) .OR. ASSOCIATED(gth_potential) .OR. &
1279 ASSOCIATED(sgp_potential) .OR. ASSOCIATED(cneo_potential)
1280
1281 IF (dft_control%qs_control%dftb) THEN
1282 CALL get_dftb_atom_param(qs_kind_set(ikind)%dftb_parameter, &
1283 lmax=maxll, occupation=edftb)
1284 maxll = min(maxll, maxl)
1285 econf(0:maxl) = edftb(0:maxl)
1286 ELSE IF (dft_control%qs_control%xtb) THEN
1287 CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_kind)
1288 CALL get_xtb_atom_param(xtb_kind, z=z, natorb=nsgf, nao=naox, lao=laox, occupation=occupation)
1289 ELSE IF (has_pot) THEN
1290 CALL get_atomic_kind(atomic_kind_set(ikind), z=z)
1291 CALL get_qs_kind(qs_kind_set(ikind), nsgf=nsgf, elec_conf=elec_conf, zeff=zeff)
1292 maxll = min(SIZE(elec_conf) - 1, maxl)
1293 econf(:) = 0.0_dp
1294 econf(0:maxll) = 0.5_dp*maxocc*real(elec_conf(0:maxll), dp)
1295 ELSE
1296 cycle
1297 END IF
1298
1299 ! MOPAC TYPE GUESS
1300 IF (dft_control%qs_control%dftb) THEN
1301 DO iatom = 1, natom
1302 atom_a = atom_list(iatom)
1303 isgfa = first_sgf(atom_a)
1304 DO la = 0, maxll
1305 SELECT CASE (la)
1306 CASE (0)
1307 pdiag(isgfa) = econf(0)
1308 CASE (1)
1309 pdiag(isgfa + 1) = econf(1)/3._dp
1310 pdiag(isgfa + 2) = econf(1)/3._dp
1311 pdiag(isgfa + 3) = econf(1)/3._dp
1312 CASE (2)
1313 pdiag(isgfa + 4) = econf(2)/5._dp
1314 pdiag(isgfa + 5) = econf(2)/5._dp
1315 pdiag(isgfa + 6) = econf(2)/5._dp
1316 pdiag(isgfa + 7) = econf(2)/5._dp
1317 pdiag(isgfa + 8) = econf(2)/5._dp
1318 CASE (3)
1319 pdiag(isgfa + 9) = econf(3)/7._dp
1320 pdiag(isgfa + 10) = econf(3)/7._dp
1321 pdiag(isgfa + 11) = econf(3)/7._dp
1322 pdiag(isgfa + 12) = econf(3)/7._dp
1323 pdiag(isgfa + 13) = econf(3)/7._dp
1324 pdiag(isgfa + 14) = econf(3)/7._dp
1325 pdiag(isgfa + 15) = econf(3)/7._dp
1326 CASE DEFAULT
1327 cpabort("Only 0, 1, 2, 3 are supported as the value of la")
1328 END SELECT
1329 END DO
1330 END DO
1331 ELSE IF (dft_control%qs_control%xtb) THEN
1332 DO iatom = 1, natom
1333 atom_a = atom_list(iatom)
1334 isgfa = first_sgf(atom_a)
1335 IF (z == 1 .AND. nsgf == 2) THEN
1336 ! Hydrogen 2s basis
1337 pdiag(isgfa) = 1.0_dp/real(nspin, dp)
1338 pdiag(isgfa + 1) = 0.0_dp
1339 ELSE
1340 DO isgf = 1, nsgf
1341 na = naox(isgf)
1342 la = laox(isgf)
1343 occ = real(occupation(la + 1), dp)/real(2*la + 1, dp)
1344 occ = occ/real(nspin, dp)
1345 pdiag(isgfa + isgf - 1) = occ
1346 END DO
1347 END IF
1348 END DO
1349 ELSE IF (dft_control%qs_control%semi_empirical) THEN
1350 yy = real(dft_control%charge, kind=dp)/real(nao, kind=dp)
1351 DO iatom = 1, natom
1352 atom_a = atom_list(iatom)
1353 isgfa = first_sgf(atom_a)
1354 SELECT CASE (nsgf)
1355 CASE (1) ! s-basis
1356 pdiag(isgfa) = (zeff - yy)*0.5_dp*maxocc
1357 CASE (4) ! sp-basis
1358 IF (z == 1) THEN
1359 ! special case: hydrogen with sp basis
1360 pdiag(isgfa) = (zeff - yy)*0.5_dp*maxocc
1361 pdiag(isgfa + 1) = 0._dp
1362 pdiag(isgfa + 2) = 0._dp
1363 pdiag(isgfa + 3) = 0._dp
1364 ELSE
1365 pdiag(isgfa) = (zeff*0.25_dp - yy)*0.5_dp*maxocc
1366 pdiag(isgfa + 1) = (zeff*0.25_dp - yy)*0.5_dp*maxocc
1367 pdiag(isgfa + 2) = (zeff*0.25_dp - yy)*0.5_dp*maxocc
1368 pdiag(isgfa + 3) = (zeff*0.25_dp - yy)*0.5_dp*maxocc
1369 END IF
1370 CASE (9) ! spd-basis
1371 IF (z < 21 .OR. z > 30 .AND. z < 39 .OR. z > 48 .AND. z < 57) THEN
1372 ! Main Group Element: The "d" shell is formally empty.
1373 pdiag(isgfa) = (zeff*0.25_dp - yy)*0.5_dp*maxocc
1374 pdiag(isgfa + 1) = (zeff*0.25_dp - yy)*0.5_dp*maxocc
1375 pdiag(isgfa + 2) = (zeff*0.25_dp - yy)*0.5_dp*maxocc
1376 pdiag(isgfa + 3) = (zeff*0.25_dp - yy)*0.5_dp*maxocc
1377 pdiag(isgfa + 4) = (-yy)*0.5_dp*maxocc
1378 pdiag(isgfa + 5) = (-yy)*0.5_dp*maxocc
1379 pdiag(isgfa + 6) = (-yy)*0.5_dp*maxocc
1380 pdiag(isgfa + 7) = (-yy)*0.5_dp*maxocc
1381 pdiag(isgfa + 8) = (-yy)*0.5_dp*maxocc
1382 ELSE IF (z < 99) THEN
1383 my_sum = zeff - 9.0_dp*yy
1384 ! First, put 2 electrons in the 's' shell
1385 pdiag(isgfa) = (max(0.0_dp, min(my_sum, 2.0_dp)))*0.5_dp*maxocc
1386 my_sum = my_sum - 2.0_dp
1387 IF (my_sum > 0.0_dp) THEN
1388 ! Now put as many electrons as possible into the 'd' shell
1389 pdiag(isgfa + 4) = (max(0.0_dp, min(my_sum*0.2_dp, 2.0_dp)))*0.5_dp*maxocc
1390 pdiag(isgfa + 5) = (max(0.0_dp, min(my_sum*0.2_dp, 2.0_dp)))*0.5_dp*maxocc
1391 pdiag(isgfa + 6) = (max(0.0_dp, min(my_sum*0.2_dp, 2.0_dp)))*0.5_dp*maxocc
1392 pdiag(isgfa + 7) = (max(0.0_dp, min(my_sum*0.2_dp, 2.0_dp)))*0.5_dp*maxocc
1393 pdiag(isgfa + 8) = (max(0.0_dp, min(my_sum*0.2_dp, 2.0_dp)))*0.5_dp*maxocc
1394 my_sum = max(0.0_dp, my_sum - 10.0_dp)
1395 ! Put the remaining electrons in the 'p' shell
1396 pdiag(isgfa + 1) = (my_sum/3.0_dp)*0.5_dp*maxocc
1397 pdiag(isgfa + 2) = (my_sum/3.0_dp)*0.5_dp*maxocc
1398 pdiag(isgfa + 3) = (my_sum/3.0_dp)*0.5_dp*maxocc
1399 END IF
1400 END IF
1401 CASE DEFAULT
1402 CALL cp_abort(__location__, &
1403 "Only 1 for s-basis, 4 for sp-basis and 9 for spd-basis "// &
1404 "are supported as the value of nsgf in the MOPAC type "// &
1405 "guess for semi-empirical methods")
1406 END SELECT
1407 END DO
1408 ELSE
1409 CALL get_gto_basis_set(gto_basis_set=orb_basis_set, &
1410 nset=nset, &
1411 nshell=nshell, &
1412 l=l, &
1413 first_sgf=first_sgfa, &
1414 last_sgf=last_sgfa)
1415
1416 DO iset = 1, nset
1417 DO ishell = 1, nshell(iset)
1418 la = l(ishell, iset)
1419 nelec = maxocc*real(2*la + 1, dp)
1420 IF (econf(la) > 0.0_dp) THEN
1421 IF (econf(la) >= nelec) THEN
1422 paa = maxocc
1423 econf(la) = econf(la) - nelec
1424 ELSE
1425 paa = maxocc*econf(la)/nelec
1426 econf(la) = 0.0_dp
1427 ncount = ncount + nint(nelec/maxocc)
1428 END IF
1429 DO isgfa = first_sgfa(ishell, iset), last_sgfa(ishell, iset)
1430 DO iatom = 1, natom
1431 atom_a = atom_list(iatom)
1432 isgf = first_sgf(atom_a) + isgfa - 1
1433 pdiag(isgf) = paa
1434 IF (paa == maxocc) THEN
1435 trps1 = trps1 + paa*sdiag(isgf)
1436 ELSE
1437 trps2 = trps2 + paa*sdiag(isgf)
1438 END IF
1439 END DO
1440 END DO
1441 END IF
1442 END DO ! ishell
1443 END DO ! iset
1444 END IF
1445 END DO ! ikind
1446
1447 IF (trps2 == 0.0_dp) THEN
1448 DO isgf = 1, nao
1449 IF (sdiag(isgf) > 0.0_dp) pdiag(isgf) = pdiag(isgf)/sdiag(isgf)
1450 END DO
1451 DO ispin = 1, nspin
1452 IF (nelectron_spin(ispin) /= 0) THEN
1453 rscale = sum(pdiag)/real(nelectron_spin(ispin), dp)
1454 matrix_p => pmat(ispin)%matrix
1455 pdiag = pdiag/rscale
1456 CALL dbcsr_set_diag(matrix_p, pdiag)
1457 pdiag = pdiag*rscale
1458 END IF
1459 END DO
1460 ELSE
1461 DO ispin = 1, nspin
1462 IF (nelectron_spin(ispin) /= 0) THEN
1463 rscale = (real(nelectron_spin(ispin), dp) - trps1)/trps2
1464 DO isgf = 1, nao
1465 IF (pdiag(isgf) < maxocc) pdiag(isgf) = rscale*pdiag(isgf)
1466 END DO
1467 matrix_p => pmat(ispin)%matrix
1468 CALL dbcsr_set_diag(matrix_p, pdiag)
1469 DO isgf = 1, nao
1470 IF (pdiag(isgf) < maxocc) pdiag(isgf) = pdiag(isgf)/rscale
1471 END DO
1472 END IF
1473 END DO
1474 END IF
1475 END IF
1476
1477 DEALLOCATE (econf)
1478
1479 DEALLOCATE (first_sgf)
1480
1481 DEALLOCATE (pdiag)
1482
1483 DEALLOCATE (sdiag)
1484
1485 CALL timestop(handle)
1486
1487 END SUBROUTINE calculate_mopac_dm
1488
1489END 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, plan, check_plan)
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...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
integer 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, file_access)
...
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 external_density_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:460
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:526
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, cmo_coeff)
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, ngauss, electronegativity, chmax, en, kqat2, kcn, kq)
...
Definition xtb_types.F:206
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:474
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.