(git:9111030)
Loading...
Searching...
No Matches
dm_ls_scf.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Routines for a linear scaling quickstep SCF run based on the density
10!> matrix
11!> \par History
12!> 2010.10 created [Joost VandeVondele]
13!> \author Joost VandeVondele
14! **************************************************************************************************
17 USE bibliography, ONLY: kolafa2004,&
18 kuhne2007,&
19 cite_reference
21 USE cp_dbcsr_api, ONLY: &
25 dbcsr_type_no_symmetry
42 USE dm_ls_scf_qs, ONLY: &
55 USE kinds, ONLY: default_path_length,&
57 dp
58 USE machine, ONLY: m_flush,&
60 USE mathlib, ONLY: binomial
86#include "./base/base_uses.f90"
87
88 IMPLICIT NONE
89
90 PRIVATE
91
92 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'dm_ls_scf'
93
95
96CONTAINS
97
98! **************************************************************************************************
99!> \brief perform an linear scaling scf procedure: entry point
100!>
101!> \param qs_env ...
102!> \param nonscf ...
103!> \par History
104!> 2010.10 created [Joost VandeVondele]
105!> \author Joost VandeVondele
106! **************************************************************************************************
107 SUBROUTINE ls_scf(qs_env, nonscf)
108 TYPE(qs_environment_type), POINTER :: qs_env
109 LOGICAL, INTENT(IN), OPTIONAL :: nonscf
110
111 CHARACTER(len=*), PARAMETER :: routinen = 'ls_scf'
112
113 INTEGER :: handle
114 LOGICAL :: do_scf, pao_is_done
115 TYPE(ls_scf_env_type), POINTER :: ls_scf_env
116
117 CALL timeset(routinen, handle)
118 do_scf = .true.
119 IF (PRESENT(nonscf)) do_scf = .NOT. nonscf
120
121 ! Moved here from qs_environment to remove dependencies
122 CALL ls_scf_create(qs_env)
123 CALL get_qs_env(qs_env, ls_scf_env=ls_scf_env)
124
125 IF (do_scf) THEN
126 CALL pao_optimization_start(qs_env, ls_scf_env)
127 pao_is_done = .false.
128 DO WHILE (.NOT. pao_is_done)
129 CALL ls_scf_init_scf(qs_env, ls_scf_env, .false.)
130 CALL pao_update(qs_env, ls_scf_env, pao_is_done)
131 CALL ls_scf_main(qs_env, ls_scf_env, .false.)
132 CALL pao_post_scf(qs_env, ls_scf_env, pao_is_done)
133 CALL ls_scf_post(qs_env, ls_scf_env)
134 END DO
135 CALL pao_optimization_end(ls_scf_env)
136 ELSE
137 CALL ls_scf_init_scf(qs_env, ls_scf_env, .true.)
138 CALL ls_scf_main(qs_env, ls_scf_env, .true.)
139 CALL ls_scf_post(qs_env, ls_scf_env)
140 END IF
141
142 CALL timestop(handle)
143
144 END SUBROUTINE ls_scf
145
146! **************************************************************************************************
147!> \brief initialization needed for scf
148!> \param qs_env ...
149!> \param ls_scf_env ...
150!> \param nonscf ...
151!> \par History
152!> 2010.10 created [Joost VandeVondele]
153!> \author Joost VandeVondele
154! **************************************************************************************************
155 SUBROUTINE ls_scf_init_scf(qs_env, ls_scf_env, nonscf)
156 TYPE(qs_environment_type), POINTER :: qs_env
157 TYPE(ls_scf_env_type) :: ls_scf_env
158 LOGICAL, INTENT(IN) :: nonscf
159
160 CHARACTER(len=*), PARAMETER :: routinen = 'ls_scf_init_scf'
161
162 INTEGER :: handle, ispin, nspin, unit_nr
163 TYPE(cp_logger_type), POINTER :: logger
164 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s, matrix_w
165 TYPE(dft_control_type), POINTER :: dft_control
166 TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
167 TYPE(qs_ks_env_type), POINTER :: ks_env
168 TYPE(section_vals_type), POINTER :: input
169
170 CALL timeset(routinen, handle)
171
172 ! get a useful output_unit
173 logger => cp_get_default_logger()
174 IF (logger%para_env%is_source()) THEN
175 unit_nr = cp_logger_get_default_unit_nr(logger, local=.true.)
176 ELSE
177 unit_nr = -1
178 END IF
179
180 ! get basic quantities from the qs_env
181 CALL get_qs_env(qs_env, nelectron_total=ls_scf_env%nelectron_total, &
182 matrix_s=matrix_s, &
183 matrix_w=matrix_w, &
184 ks_env=ks_env, &
185 dft_control=dft_control, &
186 molecule_set=molecule_set, &
187 input=input, &
188 has_unit_metric=ls_scf_env%has_unit_metric, &
189 para_env=ls_scf_env%para_env, &
190 nelectron_spin=ls_scf_env%nelectron_spin)
191
192 ! needs forces ? There might be a better way to flag this
193 ls_scf_env%calculate_forces = ASSOCIATED(matrix_w)
194
195 ! some basic initialization of the QS side of things
196 CALL ls_scf_init_qs(qs_env)
197
198 ! create the matrix template for use in the ls procedures
199 CALL matrix_ls_create(matrix_ls=ls_scf_env%matrix_s, matrix_qs=matrix_s(1)%matrix, &
200 ls_mstruct=ls_scf_env%ls_mstruct)
201
202 nspin = ls_scf_env%nspins
203 IF (ALLOCATED(ls_scf_env%matrix_p)) THEN
204 DO ispin = 1, SIZE(ls_scf_env%matrix_p)
205 CALL dbcsr_release(ls_scf_env%matrix_p(ispin))
206 END DO
207 ELSE
208 ALLOCATE (ls_scf_env%matrix_p(nspin))
209 END IF
210
211 DO ispin = 1, nspin
212 CALL dbcsr_create(ls_scf_env%matrix_p(ispin), template=ls_scf_env%matrix_s, &
213 matrix_type=dbcsr_type_no_symmetry)
214 END DO
215
216 ALLOCATE (ls_scf_env%matrix_ks(nspin))
217 DO ispin = 1, nspin
218 CALL dbcsr_create(ls_scf_env%matrix_ks(ispin), template=ls_scf_env%matrix_s, &
219 matrix_type=dbcsr_type_no_symmetry)
220 END DO
221
222 ! set up matrix S, and needed functions of S
223 CALL ls_scf_init_matrix_s(matrix_s(1)%matrix, ls_scf_env)
224
225 ! get the initial guess for the SCF
226 CALL ls_scf_initial_guess(qs_env, ls_scf_env, nonscf)
227
228 IF (ls_scf_env%do_rho_mixing) THEN
229 CALL rho_mixing_ls_init(qs_env, ls_scf_env)
230 END IF
231
232 IF (ls_scf_env%do_pexsi) THEN
233 CALL pexsi_init_scf(ks_env, ls_scf_env%pexsi, matrix_s(1)%matrix)
234 END IF
235
236 IF (qs_env%do_transport) THEN
237 CALL transport_initialize(ks_env, qs_env%transport_env, matrix_s(1)%matrix)
238 END IF
239
240 CALL timestop(handle)
241
242 END SUBROUTINE ls_scf_init_scf
243
244! **************************************************************************************************
245!> \brief deal with the scf initial guess
246!> \param qs_env ...
247!> \param ls_scf_env ...
248!> \param nonscf ...
249!> \par History
250!> 2012.11 created [Joost VandeVondele]
251!> \author Joost VandeVondele
252! **************************************************************************************************
253 SUBROUTINE ls_scf_initial_guess(qs_env, ls_scf_env, nonscf)
254 TYPE(qs_environment_type), POINTER :: qs_env
255 TYPE(ls_scf_env_type) :: ls_scf_env
256 LOGICAL, INTENT(IN) :: nonscf
257
258 CHARACTER(len=*), PARAMETER :: routinen = 'ls_scf_initial_guess'
259 INTEGER, PARAMETER :: aspc_guess = 2, atomic_guess = 1, &
260 restart_guess = 3
261
262 CHARACTER(LEN=default_path_length) :: file_name, project_name
263 INTEGER :: handle, iaspc, initial_guess_type, &
264 ispin, istore, naspc, unit_nr
265 REAL(kind=dp) :: alpha, cs_pos
266 TYPE(cp_logger_type), POINTER :: logger
267 TYPE(dbcsr_distribution_type) :: dist
268 TYPE(dbcsr_type) :: matrix_tmp1
269
270 IF (ls_scf_env%do_pao) RETURN ! pao has its own initial guess
271
272 CALL timeset(routinen, handle)
273
274 ! get a useful output_unit
275 logger => cp_get_default_logger()
276 IF (logger%para_env%is_source()) THEN
277 unit_nr = cp_logger_get_default_unit_nr(logger, local=.true.)
278 ELSE
279 unit_nr = -1
280 END IF
281
282 IF (unit_nr > 0) WRITE (unit_nr, '()')
283 ! if there is no history go for the atomic guess, otherwise extrapolate the dm history
284 IF (ls_scf_env%scf_history%istore == 0) THEN
285 IF (ls_scf_env%restart_read) THEN
286 initial_guess_type = restart_guess
287 ELSE
288 initial_guess_type = atomic_guess
289 END IF
290 ELSE
291 initial_guess_type = aspc_guess
292 END IF
293
294 ! how to get the initial guess
295 SELECT CASE (initial_guess_type)
296 CASE (atomic_guess)
297 CALL ls_scf_qs_atomic_guess(qs_env, ls_scf_env, ls_scf_env%energy_init, nonscf)
298 IF (unit_nr > 0) WRITE (unit_nr, '()')
299 CASE (restart_guess)
300 project_name = logger%iter_info%project_name
301 DO ispin = 1, SIZE(ls_scf_env%matrix_p)
302 WRITE (file_name, '(A,I0,A)') trim(project_name)//"_LS_DM_SPIN_", ispin, "_RESTART.dm"
303 CALL dbcsr_get_info(ls_scf_env%matrix_p(1), distribution=dist)
304 CALL dbcsr_binary_read(file_name, distribution=dist, matrix_new=ls_scf_env%matrix_p(ispin))
305 cs_pos = dbcsr_checksum(ls_scf_env%matrix_p(ispin), pos=.true.)
306 IF (unit_nr > 0) THEN
307 WRITE (unit_nr, '(T2,A,E20.8)') "Read restart DM "//trim(file_name)//" with checksum: ", cs_pos
308 END IF
309 END DO
310
311 ! directly go to computing the corresponding energy and ks matrix
312 IF (nonscf) THEN
313 CALL ls_nonscf_ks(qs_env, ls_scf_env, ls_scf_env%energy_init)
314 ELSE
315 CALL ls_scf_dm_to_ks(qs_env, ls_scf_env, ls_scf_env%energy_init, iscf=0)
316 END IF
317 CASE (aspc_guess)
318 CALL cite_reference(kolafa2004)
319 CALL cite_reference(kuhne2007)
320 naspc = min(ls_scf_env%scf_history%istore, ls_scf_env%scf_history%nstore)
321 DO ispin = 1, SIZE(ls_scf_env%matrix_p)
322 ! actual extrapolation
323 CALL dbcsr_set(ls_scf_env%matrix_p(ispin), 0.0_dp)
324 DO iaspc = 1, naspc
325 alpha = (-1.0_dp)**(iaspc + 1)*real(iaspc, kind=dp)* &
326 binomial(2*naspc, naspc - iaspc)/binomial(2*naspc - 2, naspc - 1)
327 istore = mod(ls_scf_env%scf_history%istore - iaspc, ls_scf_env%scf_history%nstore) + 1
328 CALL dbcsr_add(ls_scf_env%matrix_p(ispin), ls_scf_env%scf_history%matrix(ispin, istore), 1.0_dp, alpha)
329 END DO
330 END DO
331 END SELECT
332
333 ! which cases need getting purified and non-orthogonal ?
334 SELECT CASE (initial_guess_type)
336 ! do nothing
337 CASE (aspc_guess)
338 ! purification can't be done on the pexsi matrix, which is not necessarily idempotent,
339 ! and not stored in an ortho basis form
340 IF (.NOT. (ls_scf_env%do_pexsi)) THEN
341 DO ispin = 1, SIZE(ls_scf_env%matrix_p)
342 ! linear combination of P's is not idempotent. A bit of McWeeny is needed to ensure it is again
343 IF (SIZE(ls_scf_env%matrix_p) == 1) CALL dbcsr_scale(ls_scf_env%matrix_p(ispin), 0.5_dp)
344 ! to ensure that noisy blocks do not build up during MD (in particular with curvy) filter that guess a bit more
345 CALL dbcsr_filter(ls_scf_env%matrix_p(ispin), ls_scf_env%eps_filter**(2.0_dp/3.0_dp))
346 CALL purify_mcweeny(ls_scf_env%matrix_p(ispin:ispin), ls_scf_env%eps_filter, 3)
347 IF (SIZE(ls_scf_env%matrix_p) == 1) CALL dbcsr_scale(ls_scf_env%matrix_p(ispin), 2.0_dp)
348
349 IF (ls_scf_env%use_s_sqrt) THEN
350 ! need to get P in the non-orthogonal basis if it was stored differently
351 CALL dbcsr_create(matrix_tmp1, template=ls_scf_env%matrix_s, &
352 matrix_type=dbcsr_type_no_symmetry)
353 CALL dbcsr_multiply("N", "N", 1.0_dp, ls_scf_env%matrix_s_sqrt_inv, ls_scf_env%matrix_p(ispin), &
354 0.0_dp, matrix_tmp1, filter_eps=ls_scf_env%eps_filter)
355 CALL dbcsr_multiply("N", "N", 1.0_dp, matrix_tmp1, ls_scf_env%matrix_s_sqrt_inv, &
356 0.0_dp, ls_scf_env%matrix_p(ispin), &
357 filter_eps=ls_scf_env%eps_filter)
358 CALL dbcsr_release(matrix_tmp1)
359
360 IF (ls_scf_env%has_s_preconditioner) THEN
361 CALL apply_matrix_preconditioner(ls_scf_env%matrix_p(ispin), "forward", &
362 ls_scf_env%matrix_bs_sqrt, ls_scf_env%matrix_bs_sqrt_inv)
363 END IF
364 END IF
365 END DO
366 END IF
367
368 ! compute corresponding energy and ks matrix
369 IF (nonscf) THEN
370 CALL ls_nonscf_ks(qs_env, ls_scf_env, ls_scf_env%energy_init)
371 ELSE
372 CALL ls_scf_dm_to_ks(qs_env, ls_scf_env, ls_scf_env%energy_init, iscf=0)
373 END IF
374 END SELECT
375
376 IF (unit_nr > 0) THEN
377 WRITE (unit_nr, '(T2,A,F20.9)') "Energy with the initial guess:", ls_scf_env%energy_init
378 WRITE (unit_nr, '()')
379 END IF
380
381 CALL timestop(handle)
382
383 END SUBROUTINE ls_scf_initial_guess
384
385! **************************************************************************************************
386!> \brief store a history of matrices for later use in ls_scf_initial_guess
387!> \param ls_scf_env ...
388!> \par History
389!> 2012.11 created [Joost VandeVondele]
390!> \author Joost VandeVondele
391! **************************************************************************************************
392 SUBROUTINE ls_scf_store_result(ls_scf_env)
393 TYPE(ls_scf_env_type) :: ls_scf_env
394
395 CHARACTER(len=*), PARAMETER :: routinen = 'ls_scf_store_result'
396
397 CHARACTER(LEN=default_path_length) :: file_name, project_name
398 INTEGER :: handle, ispin, istore, unit_nr
399 REAL(kind=dp) :: cs_pos
400 TYPE(cp_logger_type), POINTER :: logger
401 TYPE(dbcsr_type) :: matrix_tmp1
402
403 CALL timeset(routinen, handle)
404
405 ! get a useful output_unit
406 logger => cp_get_default_logger()
407 IF (logger%para_env%is_source()) THEN
408 unit_nr = cp_logger_get_default_unit_nr(logger, local=.true.)
409 ELSE
410 unit_nr = -1
411 END IF
412
413 IF (ls_scf_env%restart_write) THEN
414 DO ispin = 1, SIZE(ls_scf_env%matrix_p)
415 project_name = logger%iter_info%project_name
416 WRITE (file_name, '(A,I0,A)') trim(project_name)//"_LS_DM_SPIN_", ispin, "_RESTART.dm"
417 cs_pos = dbcsr_checksum(ls_scf_env%matrix_p(ispin), pos=.true.)
418 IF (unit_nr > 0) THEN
419 WRITE (unit_nr, '(T2,A,E20.8)') "Writing restart DM "//trim(file_name)//" with checksum: ", cs_pos
420 END IF
421 IF (ls_scf_env%do_transport .OR. ls_scf_env%do_pexsi) THEN
422 IF (unit_nr > 0) THEN
423 WRITE (unit_nr, '(T6,A)') "The restart DM "//trim(file_name)//" has the sparsity of S, therefore,"
424 WRITE (unit_nr, '(T6,A)') "not compatible with methods that require a full DM! "
425 END IF
426 END IF
427 CALL dbcsr_binary_write(ls_scf_env%matrix_p(ispin), file_name)
428 END DO
429 END IF
430
431 IF (ls_scf_env%scf_history%nstore > 0) THEN
432 ls_scf_env%scf_history%istore = ls_scf_env%scf_history%istore + 1
433 DO ispin = 1, SIZE(ls_scf_env%matrix_p)
434 istore = mod(ls_scf_env%scf_history%istore - 1, ls_scf_env%scf_history%nstore) + 1
435 CALL dbcsr_copy(ls_scf_env%scf_history%matrix(ispin, istore), ls_scf_env%matrix_p(ispin))
436
437 ! if we have the sqrt around, we use it to go to the orthogonal basis
438 IF (ls_scf_env%use_s_sqrt) THEN
439 ! usually sqrt(S) * P * sqrt(S) should be available, or could be stored at least,
440 ! so that the next multiplications could be saved.
441 CALL dbcsr_create(matrix_tmp1, template=ls_scf_env%matrix_s, &
442 matrix_type=dbcsr_type_no_symmetry)
443
444 IF (ls_scf_env%has_s_preconditioner) THEN
445 CALL apply_matrix_preconditioner(ls_scf_env%scf_history%matrix(ispin, istore), "backward", &
446 ls_scf_env%matrix_bs_sqrt, ls_scf_env%matrix_bs_sqrt_inv)
447 END IF
448 CALL dbcsr_multiply("N", "N", 1.0_dp, ls_scf_env%matrix_s_sqrt, ls_scf_env%scf_history%matrix(ispin, istore), &
449 0.0_dp, matrix_tmp1, filter_eps=ls_scf_env%eps_filter)
450 CALL dbcsr_multiply("N", "N", 1.0_dp, matrix_tmp1, ls_scf_env%matrix_s_sqrt, &
451 0.0_dp, ls_scf_env%scf_history%matrix(ispin, istore), &
452 filter_eps=ls_scf_env%eps_filter)
453 CALL dbcsr_release(matrix_tmp1)
454 END IF
455
456 END DO
457 END IF
458
459 CALL timestop(handle)
460
461 END SUBROUTINE ls_scf_store_result
462
463! **************************************************************************************************
464!> \brief Main SCF routine. Can we keep it clean ?
465!> \param qs_env ...
466!> \param ls_scf_env ...
467!> \param nonscf ...
468!> \par History
469!> 2010.10 created [Joost VandeVondele]
470!> \author Joost VandeVondele
471! **************************************************************************************************
472 SUBROUTINE ls_scf_main(qs_env, ls_scf_env, nonscf)
473 TYPE(qs_environment_type), POINTER :: qs_env
474 TYPE(ls_scf_env_type) :: ls_scf_env
475 LOGICAL, INTENT(IN), OPTIONAL :: nonscf
476
477 CHARACTER(len=*), PARAMETER :: routinen = 'ls_scf_main'
478
479 INTEGER :: handle, iscf, ispin, &
480 nelectron_spin_real, nmixing, nspin, &
481 unit_nr
482 LOGICAL :: check_convergence, diis_step, do_transport, extra_scf, maxscf_reached, &
483 scf_converged, should_stop, transm_maxscf_reached, transm_scf_converged
484 REAL(kind=dp) :: energy_diff, energy_new, energy_old, &
485 eps_diis, t1, t2, tdiag
486 TYPE(cp_logger_type), POINTER :: logger
487 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks, matrix_s
488 TYPE(dbcsr_type), ALLOCATABLE, DIMENSION(:) :: matrix_ks_deviation, matrix_mixing_old
489 TYPE(energy_correction_type), POINTER :: ec_env
490 TYPE(qs_diis_buffer_type_sparse), POINTER :: diis_buffer
491 TYPE(transport_env_type), POINTER :: transport_env
492
493 CALL timeset(routinen, handle)
494
495 ! get a useful output_unit
496 logger => cp_get_default_logger()
497 IF (logger%para_env%is_source()) THEN
498 unit_nr = cp_logger_get_default_unit_nr(logger, local=.true.)
499 ELSE
500 unit_nr = -1
501 END IF
502
503 nspin = ls_scf_env%nspins
504
505 ! old quantities, useful for mixing
506 ALLOCATE (matrix_mixing_old(nspin), matrix_ks_deviation(nspin))
507 DO ispin = 1, nspin
508 CALL dbcsr_create(matrix_mixing_old(ispin), template=ls_scf_env%matrix_ks(ispin))
509
510 CALL dbcsr_create(matrix_ks_deviation(ispin), template=ls_scf_env%matrix_ks(ispin))
511 CALL dbcsr_set(matrix_ks_deviation(ispin), 0.0_dp)
512 END DO
513 ls_scf_env%homo_spin(:) = 0.0_dp
514 ls_scf_env%lumo_spin(:) = 0.0_dp
515
516 transm_scf_converged = .false.
517 transm_maxscf_reached = .false.
518
519 energy_old = 0.0_dp
520 IF (ls_scf_env%scf_history%istore > 0) energy_old = ls_scf_env%energy_init
521 check_convergence = .true.
522 iscf = 0
523 IF (ls_scf_env%ls_diis) THEN
524 diis_step = .false.
525 eps_diis = ls_scf_env%eps_diis
526 nmixing = ls_scf_env%nmixing
527 NULLIFY (diis_buffer)
528 ALLOCATE (diis_buffer)
529 CALL qs_diis_b_create_sparse(diis_buffer, &
530 nbuffer=ls_scf_env%max_diis)
531 CALL qs_diis_b_clear_sparse(diis_buffer)
532 CALL get_qs_env(qs_env, matrix_s=matrix_s)
533 END IF
534
535 CALL get_qs_env(qs_env, transport_env=transport_env, do_transport=do_transport)
536
537 ! the real SCF loop
538 DO
539
540 ! check on max SCF or timing/exit
541 CALL external_control(should_stop, "SCF", start_time=qs_env%start_time, target_time=qs_env%target_time)
542 IF (do_transport) THEN
543 maxscf_reached = should_stop .OR. iscf >= ls_scf_env%max_scf
544 ! one extra scf step for post-processing in transmission calculations
545 IF (transport_env%params%method == transport_transmission) THEN
546 IF (transm_maxscf_reached) THEN
547 IF (unit_nr > 0) WRITE (unit_nr, '(T2,A)') "SCF not converged! "
548 EXIT
549 END IF
550 transm_maxscf_reached = maxscf_reached
551 ELSE
552 IF (maxscf_reached) THEN
553 IF (unit_nr > 0) WRITE (unit_nr, '(T2,A)') "SCF not converged! "
554 EXIT
555 END IF
556 END IF
557 ELSE
558 IF (should_stop .OR. iscf >= ls_scf_env%max_scf) THEN
559 IF (unit_nr > 0) WRITE (unit_nr, '(T2,A)') "SCF not converged! "
560 ! Skip Harris functional calculation if ground-state is NOT converged
561 IF (qs_env%energy_correction) THEN
562 CALL get_qs_env(qs_env, ec_env=ec_env)
563 IF (ec_env%skip_ec) ec_env%do_skip = .true.
564 END IF
565 EXIT
566 END IF
567 END IF
568
569 t1 = m_walltime()
570 iscf = iscf + 1
571
572 ! first get a copy of the current KS matrix
573 CALL get_qs_env(qs_env, matrix_ks=matrix_ks)
574 DO ispin = 1, nspin
575 CALL matrix_qs_to_ls(ls_scf_env%matrix_ks(ispin), matrix_ks(ispin)%matrix, &
576 ls_scf_env%ls_mstruct, covariant=.true.)
577 IF (ls_scf_env%has_s_preconditioner) THEN
578 CALL apply_matrix_preconditioner(ls_scf_env%matrix_ks(ispin), "forward", &
579 ls_scf_env%matrix_bs_sqrt, ls_scf_env%matrix_bs_sqrt_inv)
580 END IF
581 CALL dbcsr_filter(ls_scf_env%matrix_ks(ispin), ls_scf_env%eps_filter)
582 END DO
583 ! run curvy steps if required. Needs an idempotent DM (either perification or restart)
584 IF ((iscf > 1 .OR. ls_scf_env%scf_history%istore > 0) .AND. ls_scf_env%curvy_steps) THEN
585 CALL dm_ls_curvy_optimization(ls_scf_env, energy_old, check_convergence)
586 ELSE
587 ! turn the KS matrix in a density matrix
588 DO ispin = 1, nspin
589 IF (nonscf) THEN
590 CALL dbcsr_copy(matrix_mixing_old(ispin), ls_scf_env%matrix_ks(ispin))
591 ELSE IF (ls_scf_env%do_rho_mixing) THEN
592 CALL dbcsr_copy(matrix_mixing_old(ispin), ls_scf_env%matrix_ks(ispin))
593 ELSE
594 IF (iscf == 1) THEN
595 ! initialize the mixing matrix with the current state if needed
596 CALL dbcsr_copy(matrix_mixing_old(ispin), ls_scf_env%matrix_ks(ispin))
597 ELSE
598 IF (ls_scf_env%ls_diis) THEN ! ------- IF-DIIS+MIX--- START
599 IF (diis_step .AND. (iscf - 1) >= ls_scf_env%iter_ini_diis) THEN
600 IF (unit_nr > 0) THEN
601 WRITE (unit_nr, '(A61)') &
602 '*************************************************************'
603 WRITE (unit_nr, '(A50,2(I3,A1),L1,A1)') &
604 " Using DIIS mixed KS: (iscf,INI_DIIS,DIIS_STEP)=(", &
605 iscf, ",", ls_scf_env%iter_ini_diis, ",", diis_step, ")"
606 WRITE (unit_nr, '(A52)') &
607 " KS_nw= DIIS-Linear-Combination-Previous KS matrices"
608 WRITE (unit_nr, '(61A)') &
609 "*************************************************************"
610 END IF
611 CALL dbcsr_copy(matrix_mixing_old(ispin), & ! out
612 ls_scf_env%matrix_ks(ispin)) ! in
613 ELSE
614 IF (unit_nr > 0) THEN
615 WRITE (unit_nr, '(A57)') &
616 "*********************************************************"
617 WRITE (unit_nr, '(A23,F5.3,A25,I3)') &
618 " Using MIXING_FRACTION=", ls_scf_env%mixing_fraction, &
619 " to mix KS matrix: iscf=", iscf
620 WRITE (unit_nr, '(A7,F5.3,A6,F5.3,A7)') &
621 " KS_nw=", ls_scf_env%mixing_fraction, "*KS + ", &
622 1.0_dp - ls_scf_env%mixing_fraction, "*KS_old"
623 WRITE (unit_nr, '(A57)') &
624 "*********************************************************"
625 END IF
626 ! perform the mixing of ks matrices
627 CALL dbcsr_add(matrix_mixing_old(ispin), &
628 ls_scf_env%matrix_ks(ispin), &
629 1.0_dp - ls_scf_env%mixing_fraction, &
630 ls_scf_env%mixing_fraction)
631 END IF
632 ELSE ! otherwise
633 IF (unit_nr > 0) THEN
634 WRITE (unit_nr, '(A57)') &
635 "*********************************************************"
636 WRITE (unit_nr, '(A23,F5.3,A25,I3)') &
637 " Using MIXING_FRACTION=", ls_scf_env%mixing_fraction, &
638 " to mix KS matrix: iscf=", iscf
639 WRITE (unit_nr, '(A7,F5.3,A6,F5.3,A7)') &
640 " KS_nw=", ls_scf_env%mixing_fraction, "*KS + ", &
641 1.0_dp - ls_scf_env%mixing_fraction, "*KS_old"
642 WRITE (unit_nr, '(A57)') &
643 "*********************************************************"
644 END IF
645 ! perform the mixing of ks matrices
646 CALL dbcsr_add(matrix_mixing_old(ispin), &
647 ls_scf_env%matrix_ks(ispin), &
648 1.0_dp - ls_scf_env%mixing_fraction, &
649 ls_scf_env%mixing_fraction)
650 END IF ! ------- IF-DIIS+MIX--- END
651 END IF
652 END IF
653
654 ! compute the density matrix that matches it
655 ! we need the proper number of states
656 nelectron_spin_real = ls_scf_env%nelectron_spin(ispin)
657 IF (ls_scf_env%nspins == 1) nelectron_spin_real = nelectron_spin_real/2
658
659 IF (do_transport) THEN
660 IF (ls_scf_env%has_s_preconditioner) THEN
661 cpabort("NOT YET IMPLEMENTED with S preconditioner. ")
662 END IF
663 IF (ls_scf_env%ls_mstruct%cluster_type /= ls_cluster_atomic) THEN
664 cpabort("NOT YET IMPLEMENTED with molecular clustering. ")
665 END IF
666
667 extra_scf = maxscf_reached .OR. scf_converged
668 ! get the current Kohn-Sham matrix (ks) and return matrix_p evaluated using an external C routine
669 CALL external_scf_method(transport_env, ls_scf_env%matrix_s, matrix_mixing_old(ispin), &
670 ls_scf_env%matrix_p(ispin), nelectron_spin_real, ls_scf_env%natoms, &
671 energy_diff, iscf, extra_scf)
672
673 ELSE
674 SELECT CASE (ls_scf_env%purification_method)
675 CASE (ls_scf_sign)
676 CALL density_matrix_sign(ls_scf_env%matrix_p(ispin), ls_scf_env%mu_spin(ispin), ls_scf_env%fixed_mu, &
677 ls_scf_env%sign_method, ls_scf_env%sign_order, matrix_mixing_old(ispin), &
678 ls_scf_env%matrix_s, ls_scf_env%matrix_s_inv, nelectron_spin_real, &
679 ls_scf_env%eps_filter, ls_scf_env%sign_symmetric, ls_scf_env%submatrix_sign_method, &
680 ls_scf_env%matrix_s_sqrt_inv)
681 CASE (ls_scf_tc2)
682 CALL density_matrix_tc2(ls_scf_env%matrix_p(ispin), matrix_mixing_old(ispin), ls_scf_env%matrix_s_sqrt_inv, &
683 nelectron_spin_real, ls_scf_env%eps_filter, ls_scf_env%homo_spin(ispin), &
684 ls_scf_env%lumo_spin(ispin), non_monotonic=ls_scf_env%non_monotonic, &
685 eps_lanczos=ls_scf_env%eps_lanczos, max_iter_lanczos=ls_scf_env%max_iter_lanczos, &
686 iounit=-1)
687 CASE (ls_scf_trs4)
688 CALL density_matrix_trs4(ls_scf_env%matrix_p(ispin), matrix_mixing_old(ispin), ls_scf_env%matrix_s_sqrt_inv, &
689 nelectron_spin_real, ls_scf_env%eps_filter, ls_scf_env%homo_spin(ispin), &
690 ls_scf_env%lumo_spin(ispin), ls_scf_env%mu_spin(ispin), &
691 dynamic_threshold=ls_scf_env%dynamic_threshold, &
692 matrix_ks_deviation=matrix_ks_deviation(ispin), &
693 eps_lanczos=ls_scf_env%eps_lanczos, max_iter_lanczos=ls_scf_env%max_iter_lanczos, &
694 iounit=-1)
695 CASE (ls_scf_pexsi)
696 IF (ls_scf_env%has_s_preconditioner) THEN
697 cpabort("S preconditioning not implemented in combination with the PEXSI library. ")
698 END IF
699 IF (ls_scf_env%ls_mstruct%cluster_type /= ls_cluster_atomic) THEN
700 CALL cp_abort(__location__, &
701 "Molecular clustering not implemented in combination with the PEXSI library. ")
702 END IF
703 CALL density_matrix_pexsi(ls_scf_env%pexsi, ls_scf_env%matrix_p(ispin), ls_scf_env%pexsi%matrix_w(ispin), &
704 ls_scf_env%pexsi%kTS(ispin), matrix_mixing_old(ispin), ls_scf_env%matrix_s, &
705 nelectron_spin_real, ls_scf_env%mu_spin(ispin), iscf, ispin)
706 END SELECT
707 END IF
708
709 IF (ls_scf_env%has_s_preconditioner) THEN
710 CALL apply_matrix_preconditioner(ls_scf_env%matrix_p(ispin), "forward", &
711 ls_scf_env%matrix_bs_sqrt, ls_scf_env%matrix_bs_sqrt_inv)
712 END IF
713 CALL dbcsr_filter(ls_scf_env%matrix_p(ispin), ls_scf_env%eps_filter)
714
715 IF (ls_scf_env%nspins == 1) CALL dbcsr_scale(ls_scf_env%matrix_p(ispin), 2.0_dp)
716
717 END DO
718 END IF
719
720 ! compute the corresponding new energy KS matrix and new energy
721 IF (nonscf) THEN
722 CALL ls_nonscf_energy(qs_env, ls_scf_env)
723 ELSE
724 CALL ls_scf_dm_to_ks(qs_env, ls_scf_env, energy_new, iscf)
725 END IF
726
727 IF (ls_scf_env%do_pexsi) THEN
728 CALL pexsi_to_qs(ls_scf_env, qs_env, kts=ls_scf_env%pexsi%kTS)
729 END IF
730
731 t2 = m_walltime()
732 IF (nonscf) THEN
733 tdiag = t2 - t1
734 CALL qs_nonscf_print_summary(qs_env, tdiag, ls_scf_env%nelectron_total, unit_nr)
735 EXIT
736 ELSE
737 ! report current SCF loop
738 energy_diff = energy_new - energy_old
739 energy_old = energy_new
740 IF (unit_nr > 0) THEN
741 WRITE (unit_nr, *)
742 WRITE (unit_nr, '(T2,A,I6,F20.9,F20.9,F12.6)') "SCF", iscf, energy_new, energy_diff, t2 - t1
743 WRITE (unit_nr, *)
744 CALL m_flush(unit_nr)
745 END IF
746 END IF
747
748 IF (do_transport) THEN
749 scf_converged = check_convergence .AND. abs(energy_diff) < ls_scf_env%eps_scf*ls_scf_env%nelectron_total
750 ! one extra scf step for post-processing in transmission calculations
751 IF (transport_env%params%method == transport_transmission) THEN
752 IF (transm_scf_converged) EXIT
753 transm_scf_converged = scf_converged
754 ELSE
755 IF (scf_converged) THEN
756 IF (unit_nr > 0) WRITE (unit_nr, '(/,T2,A,I5,A/)') "SCF run converged in ", iscf, " steps."
757 EXIT
758 END IF
759 END IF
760 ELSE
761 ! exit criterion on the energy only for the time being
762 IF (check_convergence .AND. abs(energy_diff) < ls_scf_env%eps_scf*ls_scf_env%nelectron_total) THEN
763 IF (unit_nr > 0) WRITE (unit_nr, '(/,T2,A,I5,A/)') "SCF run converged in ", iscf, " steps."
764 ! Skip Harris functional calculation if ground-state is NOT converged
765 IF (qs_env%energy_correction) THEN
766 CALL get_qs_env(qs_env, ec_env=ec_env)
767 IF (ec_env%skip_ec) ec_env%do_skip = .false.
768 END IF
769 EXIT
770 END IF
771 END IF
772
773 IF (ls_scf_env%ls_diis) THEN
774! diis_buffer, buffer with 1) Kohn-Sham history matrix,
775! 2) KS error history matrix (f=KPS-SPK),
776! 3) B matrix (for finding DIIS weighting coefficients)
777 CALL qs_diis_b_step_4lscf(diis_buffer, qs_env, ls_scf_env, unit_nr, &
778 iscf, diis_step, eps_diis, nmixing, matrix_s(1)%matrix, &
779 ls_scf_env%eps_filter)
780 END IF
781
782 IF (ls_scf_env%do_pexsi) THEN
783 CALL pexsi_set_convergence_tolerance(ls_scf_env%pexsi, energy_diff, &
784 ls_scf_env%eps_scf*ls_scf_env%nelectron_total, &
785 ! initialize in second scf step of first SCF cycle:
786 (iscf == 2) .AND. (ls_scf_env%scf_history%istore == 0), &
787 check_convergence)
788 END IF
789
790 END DO
791
792 ! free storage
793 IF (ls_scf_env%ls_diis) THEN
794 CALL qs_diis_b_release_sparse(diis_buffer)
795 DEALLOCATE (diis_buffer)
796 END IF
797 DO ispin = 1, nspin
798 CALL dbcsr_release(matrix_mixing_old(ispin))
799 CALL dbcsr_release(matrix_ks_deviation(ispin))
800 END DO
801 DEALLOCATE (matrix_mixing_old, matrix_ks_deviation)
802
803 CALL timestop(handle)
804
805 END SUBROUTINE ls_scf_main
806
807! **************************************************************************************************
808!> \brief after SCF we have a density matrix, and the self consistent KS matrix
809!> analyze its properties.
810!> \param qs_env ...
811!> \param ls_scf_env ...
812!> \par History
813!> 2010.10 created [Joost VandeVondele]
814!> \author Joost VandeVondele
815! **************************************************************************************************
816 SUBROUTINE ls_scf_post(qs_env, ls_scf_env)
817 TYPE(qs_environment_type), POINTER :: qs_env
818 TYPE(ls_scf_env_type) :: ls_scf_env
819
820 CHARACTER(len=*), PARAMETER :: routinen = 'ls_scf_post'
821
822 INTEGER :: handle, ispin, unit_nr
823 REAL(kind=dp) :: occ
824 TYPE(cp_logger_type), POINTER :: logger
825 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_w
826 TYPE(dft_control_type), POINTER :: dft_control
827
828 CALL timeset(routinen, handle)
829
830 CALL get_qs_env(qs_env, dft_control=dft_control)
831
832 ! get a useful output_unit
833 logger => cp_get_default_logger()
834 IF (logger%para_env%is_source()) THEN
835 unit_nr = cp_logger_get_default_unit_nr(logger, local=.true.)
836 ELSE
837 unit_nr = -1
838 END IF
839
840 ! store the matrix for a next scf run
841 IF (.NOT. ls_scf_env%do_pao) THEN
842 CALL ls_scf_store_result(ls_scf_env)
843 END IF
844
845 ! write homo and lumo energy and occupation (if not already part of the output)
846 IF (ls_scf_env%curvy_steps) THEN
847 CALL post_scf_homo_lumo(ls_scf_env)
848
849 ! always report P occ
850 IF (unit_nr > 0) WRITE (unit_nr, *) ""
851 DO ispin = 1, ls_scf_env%nspins
852 occ = dbcsr_get_occupation(ls_scf_env%matrix_p(ispin))
853 IF (unit_nr > 0) WRITE (unit_nr, '(T2,A,F20.12)') "Density matrix (P) occupation ", occ
854 END DO
855 END IF
856
857 ! compute the matrix_w if associated
858 IF (ls_scf_env%calculate_forces) THEN
859 CALL get_qs_env(qs_env, matrix_w=matrix_w)
860 cpassert(ASSOCIATED(matrix_w))
861 IF (ls_scf_env%do_pexsi) THEN
862 CALL pexsi_to_qs(ls_scf_env, qs_env, matrix_w=ls_scf_env%pexsi%matrix_w)
863 ELSE
864 CALL calculate_w_matrix_ls(matrix_w, ls_scf_env)
865 END IF
866 END IF
867
868 ! compute properties
869
870 IF (ls_scf_env%perform_mu_scan) CALL post_scf_mu_scan(ls_scf_env)
871
872 IF (ls_scf_env%report_all_sparsities) CALL post_scf_sparsities(ls_scf_env)
873
874 IF (dft_control%qs_control%dftb) THEN
875 CALL scf_post_calculation_tb(qs_env, "DFTB", .true.)
876 ELSE IF (dft_control%qs_control%xtb) THEN
877 CALL scf_post_calculation_tb(qs_env, "xTB", .true.)
878 ELSE
879 CALL write_mo_free_results(qs_env)
880 END IF
881
882 IF (ls_scf_env%chebyshev%compute_chebyshev) CALL compute_chebyshev(qs_env, ls_scf_env)
883
884 IF (.true.) CALL post_scf_experiment()
885
886 IF (dft_control%qs_control%dftb .OR. dft_control%qs_control%xtb) THEN
887 !
888 ELSE
889 CALL qs_scf_post_moments(qs_env%input, logger, qs_env, unit_nr)
890 END IF
891
892 ! clean up used data
893
894 CALL dbcsr_release(ls_scf_env%matrix_s)
895 CALL deallocate_curvy_data(ls_scf_env%curvy_data)
896
897 IF (ls_scf_env%has_s_preconditioner) THEN
898 CALL dbcsr_release(ls_scf_env%matrix_bs_sqrt)
899 CALL dbcsr_release(ls_scf_env%matrix_bs_sqrt_inv)
900 END IF
901
902 IF (ls_scf_env%needs_s_inv) THEN
903 CALL dbcsr_release(ls_scf_env%matrix_s_inv)
904 END IF
905
906 IF (ls_scf_env%use_s_sqrt) THEN
907 CALL dbcsr_release(ls_scf_env%matrix_s_sqrt)
908 CALL dbcsr_release(ls_scf_env%matrix_s_sqrt_inv)
909 END IF
910
911 DO ispin = 1, SIZE(ls_scf_env%matrix_ks)
912 CALL dbcsr_release(ls_scf_env%matrix_ks(ispin))
913 END DO
914 DEALLOCATE (ls_scf_env%matrix_ks)
915
916 IF (ls_scf_env%do_pexsi) THEN
917 CALL pexsi_finalize_scf(ls_scf_env%pexsi, ls_scf_env%mu_spin)
918 END IF
919
920 CALL timestop(handle)
921
922 END SUBROUTINE ls_scf_post
923
924! **************************************************************************************************
925!> \brief Compute the HOMO LUMO energies post SCF
926!> \param ls_scf_env ...
927!> \par History
928!> 2013.06 created [Joost VandeVondele]
929!> \author Joost VandeVondele
930! **************************************************************************************************
931 SUBROUTINE post_scf_homo_lumo(ls_scf_env)
932 TYPE(ls_scf_env_type) :: ls_scf_env
933
934 CHARACTER(len=*), PARAMETER :: routinen = 'post_scf_homo_lumo'
935
936 INTEGER :: handle, ispin, nspin, unit_nr
937 LOGICAL :: converged
938 REAL(kind=dp) :: eps_max, eps_min, homo, lumo
939 TYPE(cp_logger_type), POINTER :: logger
940 TYPE(dbcsr_type) :: matrix_k, matrix_p, matrix_tmp
941
942 CALL timeset(routinen, handle)
943
944 ! get a useful output_unit
945 logger => cp_get_default_logger()
946 IF (logger%para_env%is_source()) THEN
947 unit_nr = cp_logger_get_default_unit_nr(logger, local=.true.)
948 ELSE
949 unit_nr = -1
950 END IF
951
952 IF (unit_nr > 0) WRITE (unit_nr, '(T2,A)') ""
953
954 ! TODO: remove these limitations
955 cpassert(.NOT. ls_scf_env%has_s_preconditioner)
956 cpassert(ls_scf_env%use_s_sqrt)
957
958 nspin = ls_scf_env%nspins
959
960 CALL dbcsr_create(matrix_p, template=ls_scf_env%matrix_p(1), matrix_type=dbcsr_type_no_symmetry)
961
962 CALL dbcsr_create(matrix_k, template=ls_scf_env%matrix_p(1), matrix_type=dbcsr_type_no_symmetry)
963
964 CALL dbcsr_create(matrix_tmp, template=ls_scf_env%matrix_p(1), matrix_type=dbcsr_type_no_symmetry)
965
966 DO ispin = 1, nspin
967 ! ortho basis ks
968 CALL dbcsr_multiply("N", "N", 1.0_dp, ls_scf_env%matrix_s_sqrt_inv, ls_scf_env%matrix_ks(ispin), &
969 0.0_dp, matrix_tmp, filter_eps=ls_scf_env%eps_filter)
970 CALL dbcsr_multiply("N", "N", 1.0_dp, matrix_tmp, ls_scf_env%matrix_s_sqrt_inv, &
971 0.0_dp, matrix_k, filter_eps=ls_scf_env%eps_filter)
972
973 ! extremal eigenvalues ks
974 CALL arnoldi_extremal(matrix_k, eps_max, eps_min, max_iter=ls_scf_env%max_iter_lanczos, &
975 threshold=ls_scf_env%eps_lanczos, converged=converged)
976
977 ! ortho basis p
978 CALL dbcsr_multiply("N", "N", 1.0_dp, ls_scf_env%matrix_s_sqrt, ls_scf_env%matrix_p(ispin), &
979 0.0_dp, matrix_tmp, filter_eps=ls_scf_env%eps_filter)
980 CALL dbcsr_multiply("N", "N", 1.0_dp, matrix_tmp, ls_scf_env%matrix_s_sqrt, &
981 0.0_dp, matrix_p, filter_eps=ls_scf_env%eps_filter)
982 IF (nspin == 1) CALL dbcsr_scale(matrix_p, 0.5_dp)
983
984 ! go compute homo lumo
985 CALL compute_homo_lumo(matrix_k, matrix_p, eps_min, eps_max, ls_scf_env%eps_filter, &
986 ls_scf_env%max_iter_lanczos, ls_scf_env%eps_lanczos, homo, lumo, unit_nr)
987
988 END DO
989
990 CALL dbcsr_release(matrix_p)
991 CALL dbcsr_release(matrix_k)
992 CALL dbcsr_release(matrix_tmp)
993
994 CALL timestop(handle)
995
996 END SUBROUTINE post_scf_homo_lumo
997
998! **************************************************************************************************
999!> \brief Compute the density matrix for various values of the chemical potential
1000!> \param ls_scf_env ...
1001!> \par History
1002!> 2010.10 created [Joost VandeVondele]
1003!> \author Joost VandeVondele
1004! **************************************************************************************************
1005 SUBROUTINE post_scf_mu_scan(ls_scf_env)
1006 TYPE(ls_scf_env_type) :: ls_scf_env
1007
1008 CHARACTER(len=*), PARAMETER :: routinen = 'post_scf_mu_scan'
1009
1010 INTEGER :: handle, imu, ispin, nelectron_spin_real, &
1011 nmu, nspin, unit_nr
1012 REAL(kind=dp) :: mu, t1, t2, trace
1013 TYPE(cp_logger_type), POINTER :: logger
1014 TYPE(dbcsr_type) :: matrix_p
1015
1016 CALL timeset(routinen, handle)
1017
1018 ! get a useful output_unit
1019 logger => cp_get_default_logger()
1020 IF (logger%para_env%is_source()) THEN
1021 unit_nr = cp_logger_get_default_unit_nr(logger, local=.true.)
1022 ELSE
1023 unit_nr = -1
1024 END IF
1025
1026 nspin = ls_scf_env%nspins
1027
1028 CALL dbcsr_create(matrix_p, template=ls_scf_env%matrix_p(1))
1029
1030 nmu = 10
1031 DO imu = 0, nmu
1032
1033 t1 = m_walltime()
1034
1035 mu = -0.4_dp + imu*(0.1_dp + 0.4_dp)/nmu
1036
1037 IF (unit_nr > 0) WRITE (unit_nr, *) "------- starting with mu ", mu
1038
1039 DO ispin = 1, nspin
1040 ! we need the proper number of states
1041 nelectron_spin_real = ls_scf_env%nelectron_spin(ispin)
1042 IF (ls_scf_env%nspins == 1) nelectron_spin_real = nelectron_spin_real/2
1043
1044 CALL density_matrix_sign_fixed_mu(matrix_p, trace, mu, ls_scf_env%sign_method, &
1045 ls_scf_env%sign_order, ls_scf_env%matrix_ks(ispin), &
1046 ls_scf_env%matrix_s, ls_scf_env%matrix_s_inv, &
1047 ls_scf_env%eps_filter, ls_scf_env%sign_symmetric, &
1048 ls_scf_env%submatrix_sign_method, ls_scf_env%matrix_s_sqrt_inv)
1049 END DO
1050
1051 t2 = m_walltime()
1052
1053 IF (unit_nr > 0) WRITE (unit_nr, *) " obtained ", mu, trace, t2 - t1
1054
1055 END DO
1056
1057 CALL dbcsr_release(matrix_p)
1058
1059 CALL timestop(handle)
1060
1061 END SUBROUTINE post_scf_mu_scan
1062
1063! **************************************************************************************************
1064!> \brief Report on the sparsities of various interesting matrices.
1065!>
1066!> \param ls_scf_env ...
1067!> \par History
1068!> 2010.10 created [Joost VandeVondele]
1069!> \author Joost VandeVondele
1070! **************************************************************************************************
1071 SUBROUTINE post_scf_sparsities(ls_scf_env)
1072 TYPE(ls_scf_env_type) :: ls_scf_env
1073
1074 CHARACTER(len=*), PARAMETER :: routinen = 'post_scf_sparsities'
1075
1076 CHARACTER(LEN=default_string_length) :: title
1077 INTEGER :: handle, ispin, nspin, unit_nr
1078 TYPE(cp_logger_type), POINTER :: logger
1079 TYPE(dbcsr_type) :: matrix_tmp1, matrix_tmp2
1080
1081 CALL timeset(routinen, handle)
1082
1083 ! get a useful output_unit
1084 logger => cp_get_default_logger()
1085 IF (logger%para_env%is_source()) THEN
1086 unit_nr = cp_logger_get_default_unit_nr(logger, local=.true.)
1087 ELSE
1088 unit_nr = -1
1089 END IF
1090
1091 nspin = ls_scf_env%nspins
1092
1093 IF (unit_nr > 0) THEN
1094 WRITE (unit_nr, '()')
1095 WRITE (unit_nr, '(T2,A,E17.3)') "Sparsity reports for eps_filter: ", ls_scf_env%eps_filter
1096 WRITE (unit_nr, '()')
1097 END IF
1098
1099 CALL report_matrix_sparsity(ls_scf_env%matrix_s, unit_nr, "overlap matrix (S)", &
1100 ls_scf_env%eps_filter)
1101
1102 DO ispin = 1, nspin
1103 WRITE (title, '(A,I3)') "Kohn-Sham matrix (H) for spin ", ispin
1104 CALL report_matrix_sparsity(ls_scf_env%matrix_ks(ispin), unit_nr, title, &
1105 ls_scf_env%eps_filter)
1106 END DO
1107
1108 CALL dbcsr_create(matrix_tmp1, template=ls_scf_env%matrix_s, matrix_type=dbcsr_type_no_symmetry)
1109 CALL dbcsr_create(matrix_tmp2, template=ls_scf_env%matrix_s, matrix_type=dbcsr_type_no_symmetry)
1110
1111 DO ispin = 1, nspin
1112 WRITE (title, '(A,I3)') "Density matrix (P) for spin ", ispin
1113 CALL report_matrix_sparsity(ls_scf_env%matrix_p(ispin), unit_nr, title, &
1114 ls_scf_env%eps_filter)
1115
1116 CALL dbcsr_multiply("N", "N", 1.0_dp, ls_scf_env%matrix_s, ls_scf_env%matrix_p(ispin), &
1117 0.0_dp, matrix_tmp1, filter_eps=ls_scf_env%eps_filter)
1118
1119 WRITE (title, '(A,I3,A)') "S * P(", ispin, ")"
1120 CALL report_matrix_sparsity(matrix_tmp1, unit_nr, title, ls_scf_env%eps_filter)
1121
1122 CALL dbcsr_multiply("N", "N", 1.0_dp, matrix_tmp1, ls_scf_env%matrix_s, &
1123 0.0_dp, matrix_tmp2, filter_eps=ls_scf_env%eps_filter)
1124 WRITE (title, '(A,I3,A)') "S * P(", ispin, ") * S"
1125 CALL report_matrix_sparsity(matrix_tmp2, unit_nr, title, ls_scf_env%eps_filter)
1126 END DO
1127
1128 IF (ls_scf_env%needs_s_inv) THEN
1129 CALL report_matrix_sparsity(ls_scf_env%matrix_s_inv, unit_nr, "inv(S)", &
1130 ls_scf_env%eps_filter)
1131 DO ispin = 1, nspin
1132 CALL dbcsr_multiply("N", "N", 1.0_dp, ls_scf_env%matrix_s_inv, ls_scf_env%matrix_ks(ispin), &
1133 0.0_dp, matrix_tmp1, filter_eps=ls_scf_env%eps_filter)
1134
1135 WRITE (title, '(A,I3,A)') "inv(S) * H(", ispin, ")"
1136 CALL report_matrix_sparsity(matrix_tmp1, unit_nr, title, ls_scf_env%eps_filter)
1137 END DO
1138 END IF
1139
1140 IF (ls_scf_env%use_s_sqrt) THEN
1141
1142 CALL report_matrix_sparsity(ls_scf_env%matrix_s_sqrt, unit_nr, "sqrt(S)", &
1143 ls_scf_env%eps_filter)
1144 CALL report_matrix_sparsity(ls_scf_env%matrix_s_sqrt_inv, unit_nr, "inv(sqrt(S))", &
1145 ls_scf_env%eps_filter)
1146
1147 DO ispin = 1, nspin
1148 CALL dbcsr_multiply("N", "N", 1.0_dp, ls_scf_env%matrix_s_sqrt_inv, ls_scf_env%matrix_ks(ispin), &
1149 0.0_dp, matrix_tmp1, filter_eps=ls_scf_env%eps_filter)
1150 CALL dbcsr_multiply("N", "N", 1.0_dp, matrix_tmp1, ls_scf_env%matrix_s_sqrt_inv, &
1151 0.0_dp, matrix_tmp2, filter_eps=ls_scf_env%eps_filter)
1152 WRITE (title, '(A,I3,A)') "inv(sqrt(S)) * H(", ispin, ") * inv(sqrt(S))"
1153 CALL report_matrix_sparsity(matrix_tmp2, unit_nr, title, ls_scf_env%eps_filter)
1154 END DO
1155
1156 DO ispin = 1, nspin
1157 CALL dbcsr_multiply("N", "N", 1.0_dp, ls_scf_env%matrix_s_sqrt, ls_scf_env%matrix_p(ispin), &
1158 0.0_dp, matrix_tmp1, filter_eps=ls_scf_env%eps_filter)
1159 CALL dbcsr_multiply("N", "N", 1.0_dp, matrix_tmp1, ls_scf_env%matrix_s_sqrt, &
1160 0.0_dp, matrix_tmp2, filter_eps=ls_scf_env%eps_filter)
1161 WRITE (title, '(A,I3,A)') "sqrt(S) * P(", ispin, ") * sqrt(S)"
1162 CALL report_matrix_sparsity(matrix_tmp2, unit_nr, title, ls_scf_env%eps_filter)
1163 END DO
1164
1165 END IF
1166
1167 CALL dbcsr_release(matrix_tmp1)
1168 CALL dbcsr_release(matrix_tmp2)
1169
1170 CALL timestop(handle)
1171
1172 END SUBROUTINE post_scf_sparsities
1173
1174! **************************************************************************************************
1175!> \brief Helper routine to report on the sparsity of a single matrix,
1176!> for several filtering values
1177!> \param matrix ...
1178!> \param unit_nr ...
1179!> \param title ...
1180!> \param eps ...
1181!> \par History
1182!> 2010.10 created [Joost VandeVondele]
1183!> \author Joost VandeVondele
1184! **************************************************************************************************
1185 SUBROUTINE report_matrix_sparsity(matrix, unit_nr, title, eps)
1186 TYPE(dbcsr_type) :: matrix
1187 INTEGER :: unit_nr
1188 CHARACTER(LEN=*) :: title
1189 REAL(kind=dp) :: eps
1190
1191 CHARACTER(len=*), PARAMETER :: routinen = 'report_matrix_sparsity'
1192
1193 INTEGER :: handle
1194 REAL(kind=dp) :: eps_local, occ
1195 TYPE(dbcsr_type) :: matrix_tmp
1196
1197 CALL timeset(routinen, handle)
1198 CALL dbcsr_create(matrix_tmp, template=matrix, name=trim(title))
1199 CALL dbcsr_copy(matrix_tmp, matrix, name=trim(title))
1200
1201 IF (unit_nr > 0) THEN
1202 WRITE (unit_nr, '(T2,A)') "Sparsity for : "//trim(title)
1203 END IF
1204
1205 eps_local = max(eps, 10e-14_dp)
1206 DO
1207 IF (eps_local > 1.1_dp) EXIT
1208 CALL dbcsr_filter(matrix_tmp, eps_local)
1209 occ = dbcsr_get_occupation(matrix_tmp)
1210 IF (unit_nr > 0) WRITE (unit_nr, '(T2,F16.12,A3,F16.12)') eps_local, " : ", occ
1211 eps_local = eps_local*10
1212 END DO
1213
1214 CALL dbcsr_release(matrix_tmp)
1215
1216 CALL timestop(handle)
1217
1218 END SUBROUTINE report_matrix_sparsity
1219
1220! **************************************************************************************************
1221!> \brief Compute matrix_w as needed for the forces
1222!> \param matrix_w ...
1223!> \param ls_scf_env ...
1224!> \par History
1225!> 2010.11 created [Joost VandeVondele]
1226!> \author Joost VandeVondele
1227! **************************************************************************************************
1228 SUBROUTINE calculate_w_matrix_ls(matrix_w, ls_scf_env)
1229 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_w
1230 TYPE(ls_scf_env_type) :: ls_scf_env
1231
1232 CHARACTER(len=*), PARAMETER :: routinen = 'calculate_w_matrix_ls'
1233
1234 INTEGER :: handle, ispin
1235 REAL(kind=dp) :: scaling
1236 TYPE(dbcsr_type) :: matrix_tmp1, matrix_tmp2, matrix_tmp3
1237
1238 CALL timeset(routinen, handle)
1239
1240 CALL dbcsr_create(matrix_tmp1, template=ls_scf_env%matrix_s, matrix_type=dbcsr_type_no_symmetry)
1241 CALL dbcsr_create(matrix_tmp2, template=ls_scf_env%matrix_s, matrix_type=dbcsr_type_no_symmetry)
1242 CALL dbcsr_create(matrix_tmp3, template=ls_scf_env%matrix_s, matrix_type=dbcsr_type_no_symmetry)
1243
1244 IF (ls_scf_env%nspins == 1) THEN
1245 scaling = 0.5_dp
1246 ELSE
1247 scaling = 1.0_dp
1248 END IF
1249
1250 DO ispin = 1, ls_scf_env%nspins
1251
1252 CALL dbcsr_copy(matrix_tmp3, ls_scf_env%matrix_ks(ispin))
1253 IF (ls_scf_env%has_s_preconditioner) THEN
1254 CALL apply_matrix_preconditioner(matrix_tmp3, "backward", &
1255 ls_scf_env%matrix_bs_sqrt, ls_scf_env%matrix_bs_sqrt_inv)
1256 END IF
1257 CALL dbcsr_filter(matrix_tmp3, ls_scf_env%eps_filter)
1258
1259 CALL dbcsr_multiply("N", "N", scaling, ls_scf_env%matrix_p(ispin), matrix_tmp3, &
1260 0.0_dp, matrix_tmp1, filter_eps=ls_scf_env%eps_filter)
1261 CALL dbcsr_multiply("N", "N", 1.0_dp, matrix_tmp1, ls_scf_env%matrix_p(ispin), &
1262 0.0_dp, matrix_tmp2, filter_eps=ls_scf_env%eps_filter)
1263 CALL matrix_ls_to_qs(matrix_w(ispin)%matrix, matrix_tmp2, ls_scf_env%ls_mstruct, covariant=.false.)
1264 END DO
1265
1266 CALL dbcsr_release(matrix_tmp1)
1267 CALL dbcsr_release(matrix_tmp2)
1268 CALL dbcsr_release(matrix_tmp3)
1269
1270 CALL timestop(handle)
1271
1272 END SUBROUTINE calculate_w_matrix_ls
1273
1274! **************************************************************************************************
1275!> \brief a place for quick experiments
1276!> \par History
1277!> 2010.11 created [Joost VandeVondele]
1278!> \author Joost VandeVondele
1279! **************************************************************************************************
1280 SUBROUTINE post_scf_experiment()
1281
1282 CHARACTER(len=*), PARAMETER :: routinen = 'post_scf_experiment'
1283
1284 INTEGER :: handle, unit_nr
1285 TYPE(cp_logger_type), POINTER :: logger
1286
1287 CALL timeset(routinen, handle)
1288
1289 ! get a useful output_unit
1290 logger => cp_get_default_logger()
1291 IF (logger%para_env%is_source()) THEN
1292 unit_nr = cp_logger_get_default_unit_nr(logger, local=.true.)
1293 ELSE
1294 unit_nr = -1
1295 END IF
1296
1297 CALL timestop(handle)
1298 END SUBROUTINE post_scf_experiment
1299
1300END MODULE dm_ls_scf
arnoldi iteration using dbcsr
Definition arnoldi_api.F:16
subroutine, public arnoldi_extremal(matrix_a, max_ev, min_ev, converged, threshold, max_iter)
simple wrapper to estimate extremal eigenvalues with arnoldi, using the old lanczos interface this hi...
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public kuhne2007
integer, save, public kolafa2004
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_scale(matrix, alpha_scalar)
...
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_filter(matrix, eps)
...
subroutine, public dbcsr_binary_write(matrix, filepath)
...
real(kind=dp) function, public dbcsr_get_occupation(matrix)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_binary_read(filepath, distribution, matrix_new)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
real(kind=dp) function, public dbcsr_checksum(matrix, pos)
Calculates the checksum of a DBCSR matrix.
Routines to handle the external control of CP2K.
subroutine, public external_control(should_stop, flag, globenv, target_time, start_time, force_check)
External manipulations during a run : when the <PROJECT_NAME>.EXIT_$runtype command is sent the progr...
various routines to log and control the output. The idea is that decisions about where to log should ...
recursive integer function, public cp_logger_get_default_unit_nr(logger, local, skip_not_ionode)
asks the default unit number of the given logger. try to use cp_logger_get_unit_nr
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
Routines using linear scaling chebyshev methods.
subroutine, public compute_chebyshev(qs_env, ls_scf_env)
compute properties based on chebyshev expansion
Routines for a linear scaling quickstep SCF run based on the density matrix.
subroutine, public ls_scf_create(qs_env)
Creation and basic initialization of the LS type.
density matrix optimization using exponential transformations
subroutine, public dm_ls_curvy_optimization(ls_scf_env, energy, check_conv)
driver routine for Head-Gordon curvy step approach
subroutine, public deallocate_curvy_data(curvy_data)
...
lower level routines for linear scaling SCF
subroutine, public density_matrix_trs4(matrix_p, matrix_ks, matrix_s_sqrt_inv, nelectron, threshold, e_homo, e_lumo, e_mu, dynamic_threshold, matrix_ks_deviation, max_iter_lanczos, eps_lanczos, converged, iounit)
compute the density matrix using a trace-resetting algorithm
subroutine, public ls_scf_init_matrix_s(matrix_s, ls_scf_env)
initialize S matrix related properties (sqrt, inverse...) Might be factored-out since this seems comm...
subroutine, public density_matrix_sign_fixed_mu(matrix_p, trace, mu, sign_method, sign_order, matrix_ks, matrix_s, matrix_s_inv, threshold, sign_symmetric, submatrix_sign_method, matrix_s_sqrt_inv)
for a fixed mu, compute the corresponding density matrix and its trace
subroutine, public apply_matrix_preconditioner(matrix, direction, matrix_bs_sqrt, matrix_bs_sqrt_inv)
apply a preconditioner either forward (precondition) inv(sqrt(bs)) * A * inv(sqrt(bs)) backward (rest...
subroutine, public density_matrix_sign(matrix_p, mu, fixed_mu, sign_method, sign_order, matrix_ks, matrix_s, matrix_s_inv, nelectron, threshold, sign_symmetric, submatrix_sign_method, matrix_s_sqrt_inv)
compute the density matrix with a trace that is close to nelectron. take a mu as input,...
subroutine, public density_matrix_tc2(matrix_p, matrix_ks, matrix_s_sqrt_inv, nelectron, threshold, e_homo, e_lumo, non_monotonic, eps_lanczos, max_iter_lanczos, iounit)
compute the density matrix using a non monotonic trace conserving algorithm based on SIAM DOI....
subroutine, public compute_homo_lumo(matrix_k, matrix_p, eps_min, eps_max, threshold, max_iter_lanczos, eps_lanczos, homo, lumo, unit_nr)
compute the homo and lumo given a KS matrix and a density matrix in the orthonormalized basis and the...
Routines for a linear scaling quickstep SCF run based on the density matrix, with a focus on the inte...
subroutine, public ls_scf_qs_atomic_guess(qs_env, ls_scf_env, energy, nonscf)
get an atomic initial guess
subroutine, public ls_nonscf_ks(qs_env, ls_scf_env, energy_new)
use the external density in ls_scf_env to compute the new KS matrix
subroutine, public matrix_ls_to_qs(matrix_qs, matrix_ls, ls_mstruct, covariant, keep_sparsity)
second link to QS, copy a LS matrix to QS matrix used to isolate QS style matrices from LS style will...
subroutine, public ls_scf_dm_to_ks(qs_env, ls_scf_env, energy_new, iscf)
use the density matrix in ls_scf_env to compute the new energy and KS matrix
subroutine, public rho_mixing_ls_init(qs_env, ls_scf_env)
Initialize g-space density mixing.
subroutine, public ls_nonscf_energy(qs_env, ls_scf_env)
use the new density matrix in ls_scf_env to compute the new energy
subroutine, public matrix_ls_create(matrix_ls, matrix_qs, ls_mstruct)
create a matrix for use (and as a template) in ls based on a qs template
subroutine, public matrix_qs_to_ls(matrix_ls, matrix_qs, ls_mstruct, covariant)
first link to QS, copy a QS matrix to LS matrix used to isolate QS style matrices from LS style will ...
subroutine, public ls_scf_init_qs(qs_env)
further required initialization of QS. Might be factored-out since this seems common code with the ot...
Types needed for a linear scaling quickstep SCF run based on the density matrix.
Routines for a linear scaling quickstep SCF run based on the density matrix.
Definition dm_ls_scf.F:15
subroutine, public post_scf_sparsities(ls_scf_env)
Report on the sparsities of various interesting matrices.
Definition dm_ls_scf.F:1072
subroutine, public calculate_w_matrix_ls(matrix_w, ls_scf_env)
Compute matrix_w as needed for the forces.
Definition dm_ls_scf.F:1229
subroutine, public ls_scf(qs_env, nonscf)
perform an linear scaling scf procedure: entry point
Definition dm_ls_scf.F:108
Types needed for a for a Energy Correction.
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public atomic_guess
integer, parameter, public ls_scf_pexsi
integer, parameter, public ls_scf_trs4
integer, parameter, public ls_scf_sign
integer, parameter, public ls_scf_tc2
integer, parameter, public transport_transmission
integer, parameter, public restart_guess
integer, parameter, public ls_cluster_atomic
objects that represent the structure of input sections and the data contained in an input section
Routines useful for iterative matrix calculations.
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
integer, parameter, public default_path_length
Definition kinds.F:58
Machine interface based on Fortran 2003 and POSIX.
Definition machine.F:17
subroutine, public m_flush(lunit)
flushes units if the &GLOBAL flag is set accordingly
Definition machine.F:124
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
Definition machine.F:141
Collection of simple mathematical functions and subroutines.
Definition mathlib.F:15
elemental real(kind=dp) function, public binomial(n, k)
The binomial coefficient n over k for 0 <= k <= n is calculated, otherwise zero is returned.
Definition mathlib.F:214
Define the data structure for the molecule information.
Main module for the PAO method.
Definition pao_main.F:12
subroutine, public pao_post_scf(qs_env, ls_scf_env, pao_is_done)
Calculate PAO forces and store density matrix for future ASPC extrapolations.
Definition pao_main.F:329
subroutine, public pao_update(qs_env, ls_scf_env, pao_is_done)
Called after the SCF optimization, updates the PAO basis.
Definition pao_main.F:193
subroutine, public pao_optimization_end(ls_scf_env)
Finish a PAO optimization run.
Definition pao_main.F:368
subroutine, public pao_optimization_start(qs_env, ls_scf_env)
Start a PAO optimization run.
Definition pao_main.F:112
Methods using the PEXSI library to calculate the density matrix and related quantities using the Kohn...
subroutine, public pexsi_to_qs(ls_scf_env, qs_env, kts, matrix_w)
Pass energy weighted density matrix and entropic energy contribution to QS environment.
subroutine, public density_matrix_pexsi(pexsi_env, matrix_p, matrix_w, kts, matrix_ks, matrix_s, nelectron_exact, mu, iscf, ispin)
Calculate density matrix, energy-weighted density matrix and entropic energy contribution with the DF...
subroutine, public pexsi_finalize_scf(pexsi_env, mu_spin)
Deallocations and post-processing after SCF.
subroutine, public pexsi_init_scf(ks_env, pexsi_env, template_matrix)
Initializations needed before SCF.
subroutine, public pexsi_set_convergence_tolerance(pexsi_env, delta_scf, eps_scf, initialize, check_convergence)
Set PEXSI convergence tolerance (numElectronPEXSITolerance), adapted to the convergence error of the ...
buffer for the diis of the scf
subroutine, public qs_diis_b_release_sparse(diis_buffer)
releases the given diis buffer (see doc/ReferenceCounting.html)
Apply the direct inversion in the iterative subspace (DIIS) of Pulay in the framework of an SCF itera...
Definition qs_diis.F:21
pure subroutine, public qs_diis_b_create_sparse(diis_buffer, nbuffer)
Allocates an SCF DIIS buffer for LS-SCF calculation.
Definition qs_diis.F:849
subroutine, public qs_diis_b_step_4lscf(diis_buffer, qs_env, ls_scf_env, unit_nr, iscf, diis_step, eps_diis, nmixing, s_matrix, threshold)
Update the SCF DIIS buffer in linear scaling SCF (LS-SCF), and if appropriate does a diis step.
Definition qs_diis.F:546
pure subroutine, public qs_diis_b_clear_sparse(diis_buffer)
clears the DIIS buffer in LS-SCF calculation
Definition qs_diis.F:833
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
Routines for Quickstep NON-SCF run.
subroutine, public qs_nonscf_print_summary(qs_env, tdiag, nelectron_total, iounit)
writes a summary of information after diagonalization
Does all kind of post scf calculations for GPW/GAPW.
subroutine, public write_mo_free_results(qs_env)
Write QS results always available (if switched on through the print_keys) Can be called from ls_scf.
subroutine, public qs_scf_post_moments(input, logger, qs_env, output_unit)
Computes and prints electric moments.
Does all kind of post scf calculations for DFTB.
subroutine, public scf_post_calculation_tb(qs_env, tb_type, no_mos)
collects possible post - scf calculations and prints info / computes properties.
CP2K transport environment and related C-interoperable types.
routines for DFT+NEGF calculations (coupling with the quantum transport code OMEN)
Definition transport.F:19
subroutine, public external_scf_method(transport_env, matrix_s, matrix_ks, matrix_p, nelectron_spin, natoms, energy_diff, iscf, extra_scf)
SCF calcualtion with an externally evaluated density matrix.
Definition transport.F:365
subroutine, public transport_initialize(ks_env, transport_env, template_matrix)
initializes the transport environment
Definition transport.F:287
type of a logger, at the moment it contains just a print level starting at which level it should be l...
Contains information on the energy correction functional for KG.
build array of pointers to diis buffers for sparse matrix case
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...