(git:ed6f26b)
Loading...
Searching...
No Matches
pao_methods.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Methods used by pao_main.F
10!> \author Ole Schuett
11! **************************************************************************************************
13 USE ao_util, ONLY: exp_radius
17 USE bibliography, ONLY: kolafa2004,&
18 kuhne2007,&
19 cite_reference
21 USE cp_dbcsr_api, ONLY: &
29 dbcsr_dot,&
36 USE dm_ls_scf_qs, ONLY: ls_scf_dm_to_ks,&
43 USE kinds, ONLY: default_path_length,&
44 dp
45 USE machine, ONLY: m_walltime
46 USE mathlib, ONLY: binomial,&
49 USE pao_ml, ONLY: pao_ml_forces
50 USE pao_model, ONLY: pao_model_forces,&
52 USE pao_param, ONLY: pao_calc_ab,&
54 USE pao_types, ONLY: pao_env_type
60 USE qs_kind_types, ONLY: get_qs_kind,&
68 USE qs_rho_types, ONLY: qs_rho_get,&
70
71!$ USE OMP_LIB, ONLY: omp_get_level
72#include "./base/base_uses.f90"
73
74 IMPLICIT NONE
75
76 PRIVATE
77
78 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'pao_methods'
79
84 PUBLIC :: pao_test_convergence
87 PUBLIC :: pao_check_grad
88
89CONTAINS
90
91! **************************************************************************************************
92!> \brief Initialize qs kinds
93!> \param pao ...
94!> \param qs_env ...
95! **************************************************************************************************
96 SUBROUTINE pao_init_kinds(pao, qs_env)
97 TYPE(pao_env_type), POINTER :: pao
98 TYPE(qs_environment_type), POINTER :: qs_env
99
100 CHARACTER(len=*), PARAMETER :: routinen = 'pao_init_kinds'
101
102 CHARACTER(LEN=default_path_length) :: pao_model_file
103 INTEGER :: handle, i, ikind, pao_basis_size
104 TYPE(gto_basis_set_type), POINTER :: basis_set
105 TYPE(pao_descriptor_type), DIMENSION(:), POINTER :: pao_descriptors
106 TYPE(pao_potential_type), DIMENSION(:), POINTER :: pao_potentials
107 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
108
109 CALL timeset(routinen, handle)
110 CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set)
111
112 DO ikind = 1, SIZE(qs_kind_set)
113 CALL get_qs_kind(qs_kind_set(ikind), &
114 basis_set=basis_set, &
115 pao_basis_size=pao_basis_size, &
116 pao_model_file=pao_model_file, &
118 pao_descriptors=pao_descriptors)
119
120 IF (pao_basis_size < 1) THEN
121 ! pao disabled for ikind, set pao_basis_size to size of primary basis
122 CALL set_qs_kind(qs_kind_set(ikind), pao_basis_size=basis_set%nsgf)
123 END IF
124
125 ! initialize radii of Gaussians to speedup screeing later on
126 DO i = 1, SIZE(pao_potentials)
127 pao_potentials(i)%beta_radius = exp_radius(0, pao_potentials(i)%beta, pao%eps_pgf, 1.0_dp)
128 END DO
129 DO i = 1, SIZE(pao_descriptors)
130 pao_descriptors(i)%beta_radius = exp_radius(0, pao_descriptors(i)%beta, pao%eps_pgf, 1.0_dp)
131 pao_descriptors(i)%screening_radius = exp_radius(0, pao_descriptors(i)%screening, pao%eps_pgf, 1.0_dp)
132 END DO
133
134 ! Load torch model.
135 IF (len_trim(pao_model_file) > 0) THEN
136 IF (.NOT. ALLOCATED(pao%models)) &
137 ALLOCATE (pao%models(SIZE(qs_kind_set)))
138 CALL pao_model_load(pao, qs_env, ikind, pao_model_file, pao%models(ikind))
139 END IF
140
141 END DO
142 CALL timestop(handle)
143 END SUBROUTINE pao_init_kinds
144
145! **************************************************************************************************
146!> \brief Prints a one line summary for each atom.
147!> \param pao ...
148! **************************************************************************************************
149 SUBROUTINE pao_print_atom_info(pao)
150 TYPE(pao_env_type), POINTER :: pao
151
152 INTEGER :: iatom, natoms
153 INTEGER, DIMENSION(:), POINTER :: pao_basis, param_cols, param_rows, &
154 pri_basis
155
156 CALL dbcsr_get_info(pao%matrix_Y, row_blk_size=pri_basis, col_blk_size=pao_basis)
157 cpassert(SIZE(pao_basis) == SIZE(pri_basis))
158 natoms = SIZE(pao_basis)
159
160 CALL dbcsr_get_info(pao%matrix_X, row_blk_size=param_rows, col_blk_size=param_cols)
161 cpassert(SIZE(param_rows) == natoms .AND. SIZE(param_cols) == natoms)
162
163 IF (pao%iw_atoms > 0) THEN
164 DO iatom = 1, natoms
165 WRITE (pao%iw_atoms, "(A,I7,T20,A,I3,T45,A,I3,T65,A,I3)") &
166 " PAO| atom: ", iatom, &
167 " prim_basis: ", pri_basis(iatom), &
168 " pao_basis: ", pao_basis(iatom), &
169 " pao_params: ", (param_cols(iatom)*param_rows(iatom))
170 END DO
171 END IF
172 END SUBROUTINE pao_print_atom_info
173
174! **************************************************************************************************
175!> \brief Constructs matrix_N and its inverse.
176!> \param pao ...
177!> \param qs_env ...
178! **************************************************************************************************
179 SUBROUTINE pao_build_orthogonalizer(pao, qs_env)
180 TYPE(pao_env_type), POINTER :: pao
181 TYPE(qs_environment_type), POINTER :: qs_env
182
183 CHARACTER(len=*), PARAMETER :: routinen = 'pao_build_orthogonalizer'
184
185 INTEGER :: acol, arow, handle, i, iatom, j, k, n
186 LOGICAL :: found
187 REAL(dp) :: v, w
188 REAL(dp), DIMENSION(:), POINTER :: evals
189 REAL(dp), DIMENSION(:, :), POINTER :: a, block_n, block_n_inv, block_s
190 TYPE(dbcsr_iterator_type) :: iter
191 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
192
193 CALL timeset(routinen, handle)
194
195 CALL get_qs_env(qs_env, matrix_s=matrix_s)
196
197 CALL dbcsr_create(pao%matrix_N, template=matrix_s(1)%matrix, name="PAO matrix_N")
198 CALL dbcsr_reserve_diag_blocks(pao%matrix_N)
199
200 CALL dbcsr_create(pao%matrix_N_inv, template=matrix_s(1)%matrix, name="PAO matrix_N_inv")
201 CALL dbcsr_reserve_diag_blocks(pao%matrix_N_inv)
202
203!$OMP PARALLEL DEFAULT(NONE) SHARED(pao,matrix_s) &
204!$OMP PRIVATE(iter,arow,acol,iatom,block_N,block_N_inv,block_S,found,N,A,evals,k,i,j,w,v)
205 CALL dbcsr_iterator_start(iter, pao%matrix_N)
206 DO WHILE (dbcsr_iterator_blocks_left(iter))
207 CALL dbcsr_iterator_next_block(iter, arow, acol, block_n)
208 iatom = arow; cpassert(arow == acol)
209
210 CALL dbcsr_get_block_p(matrix=pao%matrix_N_inv, row=iatom, col=iatom, block=block_n_inv, found=found)
211 cpassert(ASSOCIATED(block_n_inv))
212
213 CALL dbcsr_get_block_p(matrix=matrix_s(1)%matrix, row=iatom, col=iatom, block=block_s, found=found)
214 cpassert(ASSOCIATED(block_s))
215
216 n = SIZE(block_s, 1); cpassert(SIZE(block_s, 1) == SIZE(block_s, 2)) ! primary basis size
217 ALLOCATE (a(n, n), evals(n))
218
219 ! take square root of atomic overlap matrix
220 a = block_s
221 CALL diamat_all(a, evals) !afterwards A contains the eigenvectors
222 block_n = 0.0_dp
223 block_n_inv = 0.0_dp
224 DO k = 1, n
225 ! NOTE: To maintain a consistent notation with the Berghold paper,
226 ! the "_inv" is swapped: N^{-1}=sqrt(S); N=sqrt(S)^{-1}
227 w = 1.0_dp/sqrt(evals(k))
228 v = sqrt(evals(k))
229 DO i = 1, n
230 DO j = 1, n
231 block_n(i, j) = block_n(i, j) + w*a(i, k)*a(j, k)
232 block_n_inv(i, j) = block_n_inv(i, j) + v*a(i, k)*a(j, k)
233 END DO
234 END DO
235 END DO
236 DEALLOCATE (a, evals)
237 END DO
238 CALL dbcsr_iterator_stop(iter)
239!$OMP END PARALLEL
240
241 ! store a copies of N and N_inv that are distributed according to pao%diag_distribution
242 CALL dbcsr_create(pao%matrix_N_diag, &
243 name="PAO matrix_N_diag", &
244 dist=pao%diag_distribution, &
245 template=matrix_s(1)%matrix)
246 CALL dbcsr_reserve_diag_blocks(pao%matrix_N_diag)
247 CALL dbcsr_complete_redistribute(pao%matrix_N, pao%matrix_N_diag)
248 CALL dbcsr_create(pao%matrix_N_inv_diag, &
249 name="PAO matrix_N_inv_diag", &
250 dist=pao%diag_distribution, &
251 template=matrix_s(1)%matrix)
252 CALL dbcsr_reserve_diag_blocks(pao%matrix_N_inv_diag)
253 CALL dbcsr_complete_redistribute(pao%matrix_N_inv, pao%matrix_N_inv_diag)
254
255 CALL timestop(handle)
256 END SUBROUTINE pao_build_orthogonalizer
257
258! **************************************************************************************************
259!> \brief Build rectangular matrix to converert between primary and PAO basis.
260!> \param pao ...
261!> \param qs_env ...
262! **************************************************************************************************
263 SUBROUTINE pao_build_selector(pao, qs_env)
264 TYPE(pao_env_type), POINTER :: pao
265 TYPE(qs_environment_type), POINTER :: qs_env
266
267 CHARACTER(len=*), PARAMETER :: routinen = 'pao_build_selector'
268
269 INTEGER :: acol, arow, handle, i, iatom, ikind, m, &
270 natoms
271 INTEGER, DIMENSION(:), POINTER :: blk_sizes_aux, blk_sizes_pri
272 REAL(dp), DIMENSION(:, :), POINTER :: block_y
273 TYPE(dbcsr_iterator_type) :: iter
274 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
275 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
276 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
277
278 CALL timeset(routinen, handle)
279
280 CALL get_qs_env(qs_env, &
281 natom=natoms, &
282 matrix_s=matrix_s, &
283 qs_kind_set=qs_kind_set, &
284 particle_set=particle_set)
285
286 CALL dbcsr_get_info(matrix_s(1)%matrix, col_blk_size=blk_sizes_pri)
287
288 ALLOCATE (blk_sizes_aux(natoms))
289 DO iatom = 1, natoms
290 CALL get_atomic_kind(particle_set(iatom)%atomic_kind, kind_number=ikind)
291 CALL get_qs_kind(qs_kind_set(ikind), pao_basis_size=m)
292 cpassert(m > 0)
293 IF (blk_sizes_pri(iatom) < m) &
294 cpabort("PAO basis size exceeds primary basis size.")
295 blk_sizes_aux(iatom) = m
296 END DO
297
298 CALL dbcsr_create(pao%matrix_Y, &
299 template=matrix_s(1)%matrix, &
300 matrix_type="N", &
301 row_blk_size=blk_sizes_pri, &
302 col_blk_size=blk_sizes_aux, &
303 name="PAO matrix_Y")
304 DEALLOCATE (blk_sizes_aux)
305
306 CALL dbcsr_reserve_diag_blocks(pao%matrix_Y)
307
308!$OMP PARALLEL DEFAULT(NONE) SHARED(pao) &
309!$OMP PRIVATE(iter,arow,acol,block_Y,i,M)
310 CALL dbcsr_iterator_start(iter, pao%matrix_Y)
311 DO WHILE (dbcsr_iterator_blocks_left(iter))
312 CALL dbcsr_iterator_next_block(iter, arow, acol, block_y)
313 m = SIZE(block_y, 2) ! size of pao basis
314 block_y = 0.0_dp
315 DO i = 1, m
316 block_y(i, i) = 1.0_dp
317 END DO
318 END DO
319 CALL dbcsr_iterator_stop(iter)
320!$OMP END PARALLEL
321
322 CALL timestop(handle)
323 END SUBROUTINE pao_build_selector
324
325! **************************************************************************************************
326!> \brief Creates new DBCSR distribution which spreads diagonal blocks evenly across ranks
327!> \param pao ...
328!> \param qs_env ...
329! **************************************************************************************************
330 SUBROUTINE pao_build_diag_distribution(pao, qs_env)
331 TYPE(pao_env_type), POINTER :: pao
332 TYPE(qs_environment_type), POINTER :: qs_env
333
334 CHARACTER(len=*), PARAMETER :: routinen = 'pao_build_diag_distribution'
335
336 INTEGER :: handle, iatom, natoms, pgrid_cols, &
337 pgrid_rows
338 INTEGER, DIMENSION(:), POINTER :: diag_col_dist, diag_row_dist
339 TYPE(dbcsr_distribution_type) :: main_dist
340 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
341
342 CALL timeset(routinen, handle)
343
344 CALL get_qs_env(qs_env, natom=natoms, matrix_s=matrix_s)
345
346 ! get processor grid from matrix_s
347 CALL dbcsr_get_info(matrix=matrix_s(1)%matrix, distribution=main_dist)
348 CALL dbcsr_distribution_get(main_dist, nprows=pgrid_rows, npcols=pgrid_cols)
349
350 ! create new mapping of matrix-grid to processor-grid
351 ALLOCATE (diag_row_dist(natoms), diag_col_dist(natoms))
352 DO iatom = 1, natoms
353 diag_row_dist(iatom) = mod(iatom - 1, pgrid_rows)
354 diag_col_dist(iatom) = mod((iatom - 1)/pgrid_rows, pgrid_cols)
355 END DO
356
357 ! instanciate distribution object
358 CALL dbcsr_distribution_new(pao%diag_distribution, template=main_dist, &
359 row_dist=diag_row_dist, col_dist=diag_col_dist)
360
361 DEALLOCATE (diag_row_dist, diag_col_dist)
362
363 CALL timestop(handle)
364 END SUBROUTINE pao_build_diag_distribution
365
366! **************************************************************************************************
367!> \brief Creates the matrix_X
368!> \param pao ...
369!> \param qs_env ...
370! **************************************************************************************************
371 SUBROUTINE pao_build_matrix_x(pao, qs_env)
372 TYPE(pao_env_type), POINTER :: pao
373 TYPE(qs_environment_type), POINTER :: qs_env
374
375 CHARACTER(len=*), PARAMETER :: routinen = 'pao_build_matrix_X'
376
377 INTEGER :: handle, iatom, ikind, natoms
378 INTEGER, DIMENSION(:), POINTER :: col_blk_size, row_blk_size
379 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
380
381 CALL timeset(routinen, handle)
382
383 CALL get_qs_env(qs_env, &
384 natom=natoms, &
385 particle_set=particle_set)
386
387 ! determine block-sizes of matrix_X
388 ALLOCATE (row_blk_size(natoms), col_blk_size(natoms))
389 col_blk_size = 1
390 DO iatom = 1, natoms
391 CALL get_atomic_kind(particle_set(iatom)%atomic_kind, kind_number=ikind)
392 CALL pao_param_count(pao, qs_env, ikind, nparams=row_blk_size(iatom))
393 END DO
394
395 ! build actual matrix_X
396 CALL dbcsr_create(pao%matrix_X, &
397 name="PAO matrix_X", &
398 dist=pao%diag_distribution, &
399 matrix_type="N", &
400 row_blk_size=row_blk_size, &
401 col_blk_size=col_blk_size)
402 DEALLOCATE (row_blk_size, col_blk_size)
403
404 CALL dbcsr_reserve_diag_blocks(pao%matrix_X)
405 CALL dbcsr_set(pao%matrix_X, 0.0_dp)
406
407 CALL timestop(handle)
408 END SUBROUTINE pao_build_matrix_x
409
410! **************************************************************************************************
411!> \brief Creates the matrix_H0 which contains the core hamiltonian
412!> \param pao ...
413!> \param qs_env ...
414! **************************************************************************************************
415 SUBROUTINE pao_build_core_hamiltonian(pao, qs_env)
416 TYPE(pao_env_type), POINTER :: pao
417 TYPE(qs_environment_type), POINTER :: qs_env
418
419 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
420 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
421 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
422
423 CALL get_qs_env(qs_env, &
424 matrix_s=matrix_s, &
425 atomic_kind_set=atomic_kind_set, &
426 qs_kind_set=qs_kind_set)
427
428 ! allocate matrix_H0
429 CALL dbcsr_create(pao%matrix_H0, &
430 name="PAO matrix_H0", &
431 dist=pao%diag_distribution, &
432 template=matrix_s(1)%matrix)
433 CALL dbcsr_reserve_diag_blocks(pao%matrix_H0)
434
435 ! calculate initial atomic fock matrix H0
436 ! Can't use matrix_ks from ls_scf_qs_atomic_guess(), because it's not rotationally invariant.
437 ! getting H0 directly from the atomic code
438 CALL calculate_atomic_fock_matrix(pao%matrix_H0, &
439 atomic_kind_set, &
440 qs_kind_set, &
441 ounit=pao%iw)
442
443 END SUBROUTINE pao_build_core_hamiltonian
444
445! **************************************************************************************************
446!> \brief Test whether the PAO optimization has reached convergence
447!> \param pao ...
448!> \param ls_scf_env ...
449!> \param new_energy ...
450!> \param is_converged ...
451! **************************************************************************************************
452 SUBROUTINE pao_test_convergence(pao, ls_scf_env, new_energy, is_converged)
453 TYPE(pao_env_type), POINTER :: pao
454 TYPE(ls_scf_env_type) :: ls_scf_env
455 REAL(kind=dp), INTENT(IN) :: new_energy
456 LOGICAL, INTENT(OUT) :: is_converged
457
458 REAL(kind=dp) :: energy_diff, loop_eps, now, time_diff
459
460 ! calculate progress
461 energy_diff = new_energy - pao%energy_prev
462 pao%energy_prev = new_energy
463 now = m_walltime()
464 time_diff = now - pao%step_start_time
465 pao%step_start_time = now
466
467 ! convergence criterion
468 loop_eps = pao%norm_G/ls_scf_env%nelectron_total
469 is_converged = loop_eps < pao%eps_pao
470
471 IF (pao%istep > 1) THEN
472 IF (pao%iw > 0) WRITE (pao%iw, *) "PAO| energy improvement:", energy_diff
473 ! CPWARN_IF(energy_diff>0.0_dp, "PAO| energy increased")
474
475 ! print one-liner
476 IF (pao%iw > 0) WRITE (pao%iw, '(A,I6,11X,F20.9,1X,E10.3,1X,E10.3,1X,F9.3)') &
477 " PAO| step ", &
478 pao%istep, &
479 new_energy, &
480 loop_eps, &
481 pao%linesearch%step_size, & !prev step, which let to the current energy
482 time_diff
483 END IF
484 END SUBROUTINE pao_test_convergence
485
486! **************************************************************************************************
487!> \brief Calculate the pao energy
488!> \param pao ...
489!> \param qs_env ...
490!> \param ls_scf_env ...
491!> \param energy ...
492! **************************************************************************************************
493 SUBROUTINE pao_calc_energy(pao, qs_env, ls_scf_env, energy)
494 TYPE(pao_env_type), POINTER :: pao
495 TYPE(qs_environment_type), POINTER :: qs_env
496 TYPE(ls_scf_env_type), TARGET :: ls_scf_env
497 REAL(kind=dp), INTENT(OUT) :: energy
498
499 CHARACTER(len=*), PARAMETER :: routinen = 'pao_calc_energy'
500
501 INTEGER :: handle, ispin
502 REAL(kind=dp) :: penalty, trace_ph
503
504 CALL timeset(routinen, handle)
505
506 ! calculate matrix U, which determines the pao basis
507 CALL pao_calc_ab(pao, qs_env, ls_scf_env, gradient=.false., penalty=penalty)
508
509 ! calculat S, S_inv, S_sqrt, and S_sqrt_inv in the new pao basis
510 CALL pao_rebuild_s(qs_env, ls_scf_env)
511
512 ! calculate the density matrix P in the pao basis
513 CALL pao_dm_trs4(qs_env, ls_scf_env)
514
515 ! calculate the energy from the trace(PH) in the pao basis
516 energy = 0.0_dp
517 DO ispin = 1, ls_scf_env%nspins
518 CALL dbcsr_dot(ls_scf_env%matrix_p(ispin), ls_scf_env%matrix_ks(ispin), trace_ph)
519 energy = energy + trace_ph
520 END DO
521
522 ! add penalty term
523 energy = energy + penalty
524
525 IF (pao%iw > 0) THEN
526 WRITE (pao%iw, *) ""
527 WRITE (pao%iw, *) "PAO| energy:", energy, "penalty:", penalty
528 END IF
529 CALL timestop(handle)
530 END SUBROUTINE pao_calc_energy
531
532! **************************************************************************************************
533!> \brief Ensure that the number of electrons is correct.
534!> \param ls_scf_env ...
535! **************************************************************************************************
536 SUBROUTINE pao_check_trace_ps(ls_scf_env)
537 TYPE(ls_scf_env_type) :: ls_scf_env
538
539 CHARACTER(len=*), PARAMETER :: routinen = 'pao_check_trace_PS'
540
541 INTEGER :: handle, ispin
542 REAL(kind=dp) :: tmp, trace_ps
543 TYPE(dbcsr_type) :: matrix_s_desym
544
545 CALL timeset(routinen, handle)
546 CALL dbcsr_create(matrix_s_desym, template=ls_scf_env%matrix_s, matrix_type="N")
547 CALL dbcsr_desymmetrize(ls_scf_env%matrix_s, matrix_s_desym)
548
549 trace_ps = 0.0_dp
550 DO ispin = 1, ls_scf_env%nspins
551 CALL dbcsr_dot(ls_scf_env%matrix_p(ispin), matrix_s_desym, tmp)
552 trace_ps = trace_ps + tmp
553 END DO
554
555 CALL dbcsr_release(matrix_s_desym)
556
557 IF (abs(ls_scf_env%nelectron_total - trace_ps) > 0.5) &
558 cpabort("Number of electrons wrong. Trace(PS) ="//cp_to_string(trace_ps))
559
560 CALL timestop(handle)
561 END SUBROUTINE pao_check_trace_ps
562
563! **************************************************************************************************
564!> \brief Read primary density matrix from file.
565!> \param pao ...
566!> \param qs_env ...
567! **************************************************************************************************
568 SUBROUTINE pao_read_preopt_dm(pao, qs_env)
569 TYPE(pao_env_type), POINTER :: pao
570 TYPE(qs_environment_type), POINTER :: qs_env
571
572 CHARACTER(len=*), PARAMETER :: routinen = 'pao_read_preopt_dm'
573
574 INTEGER :: handle, ispin
575 REAL(kind=dp) :: cs_pos
576 TYPE(dbcsr_distribution_type) :: dist
577 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s, rho_ao
578 TYPE(dbcsr_type) :: matrix_tmp
579 TYPE(dft_control_type), POINTER :: dft_control
580 TYPE(qs_energy_type), POINTER :: energy
581 TYPE(qs_rho_type), POINTER :: rho
582
583 CALL timeset(routinen, handle)
584
585 CALL get_qs_env(qs_env, &
586 dft_control=dft_control, &
587 matrix_s=matrix_s, &
588 rho=rho, &
589 energy=energy)
590
591 CALL qs_rho_get(rho, rho_ao=rho_ao)
592
593 IF (dft_control%nspins /= 1) cpabort("open shell not yet implemented")
594
595 CALL dbcsr_get_info(matrix_s(1)%matrix, distribution=dist)
596
597 DO ispin = 1, dft_control%nspins
598 CALL dbcsr_binary_read(pao%preopt_dm_file, matrix_new=matrix_tmp, distribution=dist)
599 cs_pos = dbcsr_checksum(matrix_tmp, pos=.true.)
600 IF (pao%iw > 0) WRITE (pao%iw, *) "PAO| Read restart DM "// &
601 trim(pao%preopt_dm_file)//" with checksum: ", cs_pos
602 CALL dbcsr_copy(rho_ao(ispin)%matrix, matrix_tmp, keep_sparsity=.true.)
603 CALL dbcsr_release(matrix_tmp)
604 END DO
605
606 ! calculate corresponding ks matrix
607 CALL qs_rho_update_rho(rho, qs_env=qs_env)
608 CALL qs_ks_did_change(qs_env%ks_env, rho_changed=.true.)
609 CALL qs_ks_update_qs_env(qs_env, calculate_forces=.false., &
610 just_energy=.false., print_active=.true.)
611 IF (pao%iw > 0) WRITE (pao%iw, *) "PAO| Quickstep energy from restart density:", energy%total
612
613 CALL timestop(handle)
614
615 END SUBROUTINE pao_read_preopt_dm
616
617! **************************************************************************************************
618!> \brief Rebuilds S, S_inv, S_sqrt, and S_sqrt_inv in the pao basis
619!> \param qs_env ...
620!> \param ls_scf_env ...
621! **************************************************************************************************
622 SUBROUTINE pao_rebuild_s(qs_env, ls_scf_env)
623 TYPE(qs_environment_type), POINTER :: qs_env
624 TYPE(ls_scf_env_type), TARGET :: ls_scf_env
625
626 CHARACTER(len=*), PARAMETER :: routinen = 'pao_rebuild_S'
627
628 INTEGER :: handle
629 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
630
631 CALL timeset(routinen, handle)
632
633 CALL dbcsr_release(ls_scf_env%matrix_s_inv)
634 CALL dbcsr_release(ls_scf_env%matrix_s_sqrt)
635 CALL dbcsr_release(ls_scf_env%matrix_s_sqrt_inv)
636
637 CALL get_qs_env(qs_env, matrix_s=matrix_s)
638 CALL ls_scf_init_matrix_s(matrix_s(1)%matrix, ls_scf_env)
639
640 CALL timestop(handle)
641 END SUBROUTINE pao_rebuild_s
642
643! **************************************************************************************************
644!> \brief Calculate density matrix using TRS4 purification
645!> \param qs_env ...
646!> \param ls_scf_env ...
647! **************************************************************************************************
648 SUBROUTINE pao_dm_trs4(qs_env, ls_scf_env)
649 TYPE(qs_environment_type), POINTER :: qs_env
650 TYPE(ls_scf_env_type), TARGET :: ls_scf_env
651
652 CHARACTER(len=*), PARAMETER :: routinen = 'pao_dm_trs4'
653
654 CHARACTER(LEN=default_path_length) :: project_name
655 INTEGER :: handle, ispin, nelectron_spin_real, nspin
656 LOGICAL :: converged
657 REAL(kind=dp) :: homo_spin, lumo_spin, mu_spin
658 TYPE(cp_logger_type), POINTER :: logger
659 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks
660
661 CALL timeset(routinen, handle)
662 logger => cp_get_default_logger()
663 project_name = logger%iter_info%project_name
664 nspin = ls_scf_env%nspins
665
666 CALL get_qs_env(qs_env, matrix_ks=matrix_ks)
667 DO ispin = 1, nspin
668 CALL matrix_qs_to_ls(ls_scf_env%matrix_ks(ispin), matrix_ks(ispin)%matrix, &
669 ls_scf_env%ls_mstruct, covariant=.true.)
670
671 nelectron_spin_real = ls_scf_env%nelectron_spin(ispin)
672 IF (ls_scf_env%nspins == 1) nelectron_spin_real = nelectron_spin_real/2
673 CALL density_matrix_trs4(ls_scf_env%matrix_p(ispin), ls_scf_env%matrix_ks(ispin), &
674 ls_scf_env%matrix_s_sqrt_inv, &
675 nelectron_spin_real, ls_scf_env%eps_filter, homo_spin, lumo_spin, mu_spin, &
676 dynamic_threshold=.false., converged=converged, &
677 max_iter_lanczos=ls_scf_env%max_iter_lanczos, &
678 eps_lanczos=ls_scf_env%eps_lanczos)
679 IF (.NOT. converged) cpabort("TRS4 did not converge")
680 END DO
681
682 IF (nspin == 1) CALL dbcsr_scale(ls_scf_env%matrix_p(1), 2.0_dp)
683
684 CALL timestop(handle)
685 END SUBROUTINE pao_dm_trs4
686
687! **************************************************************************************************
688!> \brief Debugging routine for checking the analytic gradient.
689!> \param pao ...
690!> \param qs_env ...
691!> \param ls_scf_env ...
692! **************************************************************************************************
693 SUBROUTINE pao_check_grad(pao, qs_env, ls_scf_env)
694 TYPE(pao_env_type), POINTER :: pao
695 TYPE(qs_environment_type), POINTER :: qs_env
696 TYPE(ls_scf_env_type), TARGET :: ls_scf_env
697
698 CHARACTER(len=*), PARAMETER :: routinen = 'pao_check_grad'
699
700 INTEGER :: handle, i, iatom, j, natoms
701 INTEGER, DIMENSION(:), POINTER :: blk_sizes_col, blk_sizes_row
702 LOGICAL :: found
703 REAL(dp) :: delta, delta_max, eps, gij_num
704 REAL(dp), DIMENSION(:, :), POINTER :: block_g, block_x
705 TYPE(ls_mstruct_type), POINTER :: ls_mstruct
706 TYPE(mp_para_env_type), POINTER :: para_env
707
708 IF (pao%check_grad_tol < 0.0_dp) RETURN ! no checking
709
710 CALL timeset(routinen, handle)
711
712 ls_mstruct => ls_scf_env%ls_mstruct
713
714 CALL get_qs_env(qs_env, para_env=para_env, natom=natoms)
715
716 eps = pao%num_grad_eps
717 delta_max = 0.0_dp
718
719 CALL dbcsr_get_info(pao%matrix_X, col_blk_size=blk_sizes_col, row_blk_size=blk_sizes_row)
720
721 ! can not use an iterator here, because other DBCSR routines are called within loop.
722 DO iatom = 1, natoms
723 IF (pao%iw > 0) WRITE (pao%iw, *) 'PAO| checking gradient of atom ', iatom
724 CALL dbcsr_get_block_p(matrix=pao%matrix_X, row=iatom, col=iatom, block=block_x, found=found)
725
726 IF (ASSOCIATED(block_x)) THEN !only one node actually has the block
727 CALL dbcsr_get_block_p(matrix=pao%matrix_G, row=iatom, col=iatom, block=block_g, found=found)
728 cpassert(ASSOCIATED(block_g))
729 END IF
730
731 DO i = 1, blk_sizes_row(iatom)
732 DO j = 1, blk_sizes_col(iatom)
733 SELECT CASE (pao%num_grad_order)
734 CASE (2) ! calculate derivative to 2th order
735 gij_num = -eval_point(block_x, i, j, -eps, pao, ls_scf_env, qs_env)
736 gij_num = gij_num + eval_point(block_x, i, j, +eps, pao, ls_scf_env, qs_env)
737 gij_num = gij_num/(2.0_dp*eps)
738
739 CASE (4) ! calculate derivative to 4th order
740 gij_num = eval_point(block_x, i, j, -2_dp*eps, pao, ls_scf_env, qs_env)
741 gij_num = gij_num - 8_dp*eval_point(block_x, i, j, -1_dp*eps, pao, ls_scf_env, qs_env)
742 gij_num = gij_num + 8_dp*eval_point(block_x, i, j, +1_dp*eps, pao, ls_scf_env, qs_env)
743 gij_num = gij_num - eval_point(block_x, i, j, +2_dp*eps, pao, ls_scf_env, qs_env)
744 gij_num = gij_num/(12.0_dp*eps)
745
746 CASE (6) ! calculate derivative to 6th order
747 gij_num = -1_dp*eval_point(block_x, i, j, -3_dp*eps, pao, ls_scf_env, qs_env)
748 gij_num = gij_num + 9_dp*eval_point(block_x, i, j, -2_dp*eps, pao, ls_scf_env, qs_env)
749 gij_num = gij_num - 45_dp*eval_point(block_x, i, j, -1_dp*eps, pao, ls_scf_env, qs_env)
750 gij_num = gij_num + 45_dp*eval_point(block_x, i, j, +1_dp*eps, pao, ls_scf_env, qs_env)
751 gij_num = gij_num - 9_dp*eval_point(block_x, i, j, +2_dp*eps, pao, ls_scf_env, qs_env)
752 gij_num = gij_num + 1_dp*eval_point(block_x, i, j, +3_dp*eps, pao, ls_scf_env, qs_env)
753 gij_num = gij_num/(60.0_dp*eps)
754
755 CASE DEFAULT
756 cpabort("Unsupported numerical derivative order: "//cp_to_string(pao%num_grad_order))
757 END SELECT
758
759 IF (ASSOCIATED(block_x)) THEN
760 delta = abs(gij_num - block_g(i, j))
761 delta_max = max(delta_max, delta)
762 !WRITE (*,*) "gradient check", iatom, i, j, Gij_num, block_G(i,j), delta
763 END IF
764 END DO
765 END DO
766 END DO
767
768 CALL para_env%max(delta_max)
769 IF (pao%iw > 0) WRITE (pao%iw, *) 'PAO| checked gradient, max delta:', delta_max
770 IF (delta_max > pao%check_grad_tol) CALL cp_abort(__location__, &
771 "Analytic and numeric gradients differ too much:"//cp_to_string(delta_max))
772
773 CALL timestop(handle)
774 END SUBROUTINE pao_check_grad
775
776! **************************************************************************************************
777!> \brief Helper routine for pao_check_grad()
778!> \param block_X ...
779!> \param i ...
780!> \param j ...
781!> \param eps ...
782!> \param pao ...
783!> \param ls_scf_env ...
784!> \param qs_env ...
785!> \return ...
786! **************************************************************************************************
787 FUNCTION eval_point(block_X, i, j, eps, pao, ls_scf_env, qs_env) RESULT(energy)
788 REAL(dp), DIMENSION(:, :), POINTER :: block_x
789 INTEGER, INTENT(IN) :: i, j
790 REAL(dp), INTENT(IN) :: eps
791 TYPE(pao_env_type), POINTER :: pao
792 TYPE(ls_scf_env_type), TARGET :: ls_scf_env
793 TYPE(qs_environment_type), POINTER :: qs_env
794 REAL(dp) :: energy
795
796 REAL(dp) :: old_xij
797
798 IF (ASSOCIATED(block_x)) THEN
799 old_xij = block_x(i, j) ! backup old block_X
800 block_x(i, j) = block_x(i, j) + eps ! add perturbation
801 END IF
802
803 ! calculate energy
804 CALL pao_calc_energy(pao, qs_env, ls_scf_env, energy)
805
806 ! restore old block_X
807 IF (ASSOCIATED(block_x)) THEN
808 block_x(i, j) = old_xij
809 END IF
810
811 END FUNCTION eval_point
812
813! **************************************************************************************************
814!> \brief Stores density matrix as initial guess for next SCF optimization.
815!> \param qs_env ...
816!> \param ls_scf_env ...
817! **************************************************************************************************
818 SUBROUTINE pao_store_p(qs_env, ls_scf_env)
819 TYPE(qs_environment_type), POINTER :: qs_env
820 TYPE(ls_scf_env_type), TARGET :: ls_scf_env
821
822 CHARACTER(len=*), PARAMETER :: routinen = 'pao_store_P'
823
824 INTEGER :: handle, ispin, istore
825 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
826 TYPE(dft_control_type), POINTER :: dft_control
827 TYPE(ls_mstruct_type), POINTER :: ls_mstruct
828 TYPE(pao_env_type), POINTER :: pao
829
830 IF (ls_scf_env%scf_history%nstore == 0) RETURN
831 CALL timeset(routinen, handle)
832 ls_mstruct => ls_scf_env%ls_mstruct
833 pao => ls_scf_env%pao_env
834 CALL get_qs_env(qs_env, dft_control=dft_control, matrix_s=matrix_s)
835
836 ls_scf_env%scf_history%istore = ls_scf_env%scf_history%istore + 1
837 istore = mod(ls_scf_env%scf_history%istore - 1, ls_scf_env%scf_history%nstore) + 1
838 IF (pao%iw > 0) WRITE (pao%iw, *) "PAO| Storing density matrix for ASPC guess in slot:", istore
839
840 ! initialize storage
841 IF (ls_scf_env%scf_history%istore <= ls_scf_env%scf_history%nstore) THEN
842 DO ispin = 1, dft_control%nspins
843 CALL dbcsr_create(ls_scf_env%scf_history%matrix(ispin, istore), template=matrix_s(1)%matrix)
844 END DO
845 END IF
846
847 ! We are storing the density matrix in the non-orthonormal primary basis.
848 ! While the orthonormal basis would yield better extrapolations,
849 ! we simply can not afford to calculat S_sqrt in the primary basis.
850 DO ispin = 1, dft_control%nspins
851 ! transform into primary basis
852 CALL matrix_ls_to_qs(ls_scf_env%scf_history%matrix(ispin, istore), ls_scf_env%matrix_p(ispin), &
853 ls_scf_env%ls_mstruct, covariant=.false., keep_sparsity=.false.)
854 END DO
855
856 CALL timestop(handle)
857 END SUBROUTINE pao_store_p
858
859! **************************************************************************************************
860!> \brief Provide an initial guess for the density matrix
861!> \param pao ...
862!> \param qs_env ...
863!> \param ls_scf_env ...
864! **************************************************************************************************
865 SUBROUTINE pao_guess_initial_p(pao, qs_env, ls_scf_env)
866 TYPE(pao_env_type), POINTER :: pao
867 TYPE(qs_environment_type), POINTER :: qs_env
868 TYPE(ls_scf_env_type), TARGET :: ls_scf_env
869
870 CHARACTER(len=*), PARAMETER :: routinen = 'pao_guess_initial_P'
871
872 INTEGER :: handle
873
874 CALL timeset(routinen, handle)
875
876 IF (ls_scf_env%scf_history%istore > 0) THEN
877 CALL pao_aspc_guess_p(pao, qs_env, ls_scf_env)
878 pao%need_initial_scf = .true.
879 ELSE
880 IF (len_trim(pao%preopt_dm_file) > 0) THEN
881 CALL pao_read_preopt_dm(pao, qs_env)
882 pao%need_initial_scf = .false.
883 pao%preopt_dm_file = "" ! load only for first MD step
884 ELSE
885 CALL ls_scf_qs_atomic_guess(qs_env, ls_scf_env, ls_scf_env%energy_init)
886 IF (pao%iw > 0) WRITE (pao%iw, '(A,F20.9)') &
887 " PAO| Energy from initial atomic guess:", ls_scf_env%energy_init
888 pao%need_initial_scf = .true.
889 END IF
890 END IF
891
892 CALL timestop(handle)
893
894 END SUBROUTINE pao_guess_initial_p
895
896! **************************************************************************************************
897!> \brief Run the Always Stable Predictor-Corrector to guess an initial density matrix
898!> \param pao ...
899!> \param qs_env ...
900!> \param ls_scf_env ...
901! **************************************************************************************************
902 SUBROUTINE pao_aspc_guess_p(pao, qs_env, ls_scf_env)
903 TYPE(pao_env_type), POINTER :: pao
904 TYPE(qs_environment_type), POINTER :: qs_env
905 TYPE(ls_scf_env_type), TARGET :: ls_scf_env
906
907 CHARACTER(len=*), PARAMETER :: routinen = 'pao_aspc_guess_P'
908
909 INTEGER :: handle, iaspc, ispin, istore, naspc
910 REAL(dp) :: alpha
911 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
912 TYPE(dbcsr_type) :: matrix_p
913 TYPE(dft_control_type), POINTER :: dft_control
914 TYPE(ls_mstruct_type), POINTER :: ls_mstruct
915
916 CALL timeset(routinen, handle)
917 ls_mstruct => ls_scf_env%ls_mstruct
918 cpassert(ls_scf_env%scf_history%istore > 0)
919 CALL cite_reference(kolafa2004)
920 CALL cite_reference(kuhne2007)
921 CALL get_qs_env(qs_env, dft_control=dft_control, matrix_s=matrix_s)
922
923 IF (pao%iw > 0) WRITE (pao%iw, *) "PAO| Calculating initial guess with ASPC"
924
925 CALL dbcsr_create(matrix_p, template=matrix_s(1)%matrix)
926
927 naspc = min(ls_scf_env%scf_history%istore, ls_scf_env%scf_history%nstore)
928 DO ispin = 1, dft_control%nspins
929 ! actual extrapolation
930 CALL dbcsr_set(matrix_p, 0.0_dp)
931 DO iaspc = 1, naspc
932 alpha = (-1.0_dp)**(iaspc + 1)*real(iaspc, kind=dp)* &
933 binomial(2*naspc, naspc - iaspc)/binomial(2*naspc - 2, naspc - 1)
934 istore = mod(ls_scf_env%scf_history%istore - iaspc, ls_scf_env%scf_history%nstore) + 1
935 CALL dbcsr_add(matrix_p, ls_scf_env%scf_history%matrix(ispin, istore), 1.0_dp, alpha)
936 END DO
937
938 ! transform back from primary basis into pao basis
939 CALL matrix_qs_to_ls(ls_scf_env%matrix_p(ispin), matrix_p, ls_scf_env%ls_mstruct, covariant=.false.)
940 END DO
941
942 CALL dbcsr_release(matrix_p)
943
944 ! linear combination of P's is not idempotent. A bit of McWeeny is needed to ensure it is again
945 DO ispin = 1, dft_control%nspins
946 IF (dft_control%nspins == 1) CALL dbcsr_scale(ls_scf_env%matrix_p(ispin), 0.5_dp)
947 ! to ensure that noisy blocks do not build up during MD (in particular with curvy) filter that guess a bit more
948 CALL dbcsr_filter(ls_scf_env%matrix_p(ispin), ls_scf_env%eps_filter**(2.0_dp/3.0_dp))
949 ! we could go to the orthonomal basis, but it seems not worth the trouble
950 ! TODO : 10 iterations is a conservative upper bound, figure out when it fails
951 CALL purify_mcweeny(ls_scf_env%matrix_p(ispin:ispin), ls_scf_env%matrix_s, ls_scf_env%eps_filter, 10)
952 IF (dft_control%nspins == 1) CALL dbcsr_scale(ls_scf_env%matrix_p(ispin), 2.0_dp)
953 END DO
954
955 CALL pao_check_trace_ps(ls_scf_env) ! sanity check
956
957 ! compute corresponding energy and ks matrix
958 CALL ls_scf_dm_to_ks(qs_env, ls_scf_env, ls_scf_env%energy_init, iscf=0)
959
960 CALL timestop(handle)
961 END SUBROUTINE pao_aspc_guess_p
962
963! **************************************************************************************************
964!> \brief Calculate the forces contributed by PAO
965!> \param qs_env ...
966!> \param ls_scf_env ...
967! **************************************************************************************************
968 SUBROUTINE pao_add_forces(qs_env, ls_scf_env)
969 TYPE(qs_environment_type), POINTER :: qs_env
970 TYPE(ls_scf_env_type), TARGET :: ls_scf_env
971
972 CHARACTER(len=*), PARAMETER :: routinen = 'pao_add_forces'
973
974 INTEGER :: handle, iatom, natoms
975 REAL(dp), ALLOCATABLE, DIMENSION(:, :) :: forces
976 TYPE(mp_para_env_type), POINTER :: para_env
977 TYPE(pao_env_type), POINTER :: pao
978 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
979
980 CALL timeset(routinen, handle)
981 pao => ls_scf_env%pao_env
982
983 IF (pao%iw > 0) WRITE (pao%iw, *) "PAO| Adding forces."
984
985 IF (pao%max_pao /= 0) THEN
986 IF (pao%penalty_strength /= 0.0_dp) &
987 cpabort("PAO forces require PENALTY_STRENGTH or MAX_PAO set to zero")
988 IF (pao%linpot_regu_strength /= 0.0_dp) &
989 cpabort("PAO forces require LINPOT_REGULARIZATION_STRENGTH or MAX_PAO set to zero")
990 IF (pao%regularization /= 0.0_dp) &
991 cpabort("PAO forces require REGULARIZATION or MAX_PAO set to zero")
992 END IF
993
994 CALL get_qs_env(qs_env, &
995 para_env=para_env, &
996 particle_set=particle_set, &
997 natom=natoms)
998
999 ALLOCATE (forces(natoms, 3))
1000 CALL pao_calc_ab(pao, qs_env, ls_scf_env, gradient=.true., forces=forces) ! without penalty terms
1001
1002 IF (SIZE(pao%ml_training_set) > 0) &
1003 CALL pao_ml_forces(pao, qs_env, pao%matrix_G, forces)
1004
1005 IF (ALLOCATED(pao%models)) &
1006 CALL pao_model_forces(pao, qs_env, pao%matrix_G, forces)
1007
1008 CALL para_env%sum(forces)
1009 DO iatom = 1, natoms
1010 particle_set(iatom)%f = particle_set(iatom)%f + forces(iatom, :)
1011 END DO
1012
1013 DEALLOCATE (forces)
1014
1015 CALL timestop(handle)
1016
1017 END SUBROUTINE pao_add_forces
1018
1019END MODULE pao_methods
All kind of helpful little routines.
Definition ao_util.F:14
real(kind=dp) function, public exp_radius(l, alpha, threshold, prefactor, epsabs, epsrel, rlow)
The radius of a primitive Gaussian function for a given threshold is calculated. g(r) = prefactor*r**...
Definition ao_util.F:96
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
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_distribution_new(dist, template, group, pgrid, row_dist, col_dist, reuse_arrays)
...
subroutine, public dbcsr_iterator_next_block(iterator, row, column, block, block_number_argument_has_been_removed, row_size, col_size, row_offset, col_offset)
...
logical function, public dbcsr_iterator_blocks_left(iterator)
...
subroutine, public dbcsr_iterator_stop(iterator)
...
subroutine, public dbcsr_desymmetrize(matrix_a, matrix_b)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_get_block_p(matrix, row, col, block, found, row_size, col_size)
...
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_iterator_start(iterator, matrix, shared, dynamic, dynamic_byrows)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_complete_redistribute(matrix, redist)
...
subroutine, public dbcsr_binary_read(filepath, distribution, matrix_new)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
subroutine, public dbcsr_distribution_get(dist, row_dist, col_dist, nrows, ncols, has_threads, group, mynode, numnodes, nprows, npcols, myprow, mypcol, pgrid, subgroups_defined, prow_group, pcol_group)
...
real(kind=dp) function, public dbcsr_checksum(matrix, pos)
Calculates the checksum of a DBCSR matrix.
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.
subroutine, public dbcsr_reserve_diag_blocks(matrix)
Reserves all diagonal blocks.
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
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...
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 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 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 ...
Types needed for a linear scaling quickstep SCF run based on the density matrix.
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_path_length
Definition kinds.F:58
Machine interface based on Fortran 2003 and POSIX.
Definition machine.F:17
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
Definition machine.F:147
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:206
subroutine, public diamat_all(a, eigval, dac)
Diagonalize the symmetric n by n matrix a using the LAPACK library. Only the upper triangle of matrix...
Definition mathlib.F:373
Interface to the message passing library MPI.
Methods used by pao_main.F.
Definition pao_methods.F:12
subroutine, public pao_build_orthogonalizer(pao, qs_env)
Constructs matrix_N and its inverse.
subroutine, public pao_build_core_hamiltonian(pao, qs_env)
Creates the matrix_H0 which contains the core hamiltonian.
subroutine, public pao_guess_initial_p(pao, qs_env, ls_scf_env)
Provide an initial guess for the density matrix.
subroutine, public pao_test_convergence(pao, ls_scf_env, new_energy, is_converged)
Test whether the PAO optimization has reached convergence.
subroutine, public pao_add_forces(qs_env, ls_scf_env)
Calculate the forces contributed by PAO.
subroutine, public pao_check_trace_ps(ls_scf_env)
Ensure that the number of electrons is correct.
subroutine, public pao_init_kinds(pao, qs_env)
Initialize qs kinds.
Definition pao_methods.F:97
subroutine, public pao_build_matrix_x(pao, qs_env)
Creates the matrix_X.
subroutine, public pao_check_grad(pao, qs_env, ls_scf_env)
Debugging routine for checking the analytic gradient.
subroutine, public pao_print_atom_info(pao)
Prints a one line summary for each atom.
subroutine, public pao_store_p(qs_env, ls_scf_env)
Stores density matrix as initial guess for next SCF optimization.
subroutine, public pao_build_selector(pao, qs_env)
Build rectangular matrix to converert between primary and PAO basis.
subroutine, public pao_calc_energy(pao, qs_env, ls_scf_env, energy)
Calculate the pao energy.
subroutine, public pao_build_diag_distribution(pao, qs_env)
Creates new DBCSR distribution which spreads diagonal blocks evenly across ranks.
Main module for PAO Machine Learning.
Definition pao_ml.F:12
subroutine, public pao_ml_forces(pao, qs_env, matrix_g, forces)
Calculate forces contributed by machine learning.
Definition pao_ml.F:623
Module for equivariant PAO-ML based on PyTorch.
Definition pao_model.F:12
subroutine, public pao_model_forces(pao, qs_env, matrix_g, forces)
Calculate forces contributed by machine learning.
Definition pao_model.F:190
subroutine, public pao_model_load(pao, qs_env, ikind, pao_model_file, model)
Loads a PAO-ML model.
Definition pao_model.F:66
Front-End for any PAO parametrization.
Definition pao_param.F:12
subroutine, public pao_calc_ab(pao, qs_env, ls_scf_env, gradient, penalty, forces)
Takes current matrix_X and calculates the matrices A and B.
Definition pao_param.F:70
subroutine, public pao_param_count(pao, qs_env, ikind, nparams)
Returns the number of parameters for given atomic kind.
Definition pao_param.F:173
Factory routines for potentials used e.g. by pao_param_exp and pao_ml.
Types used by the PAO machinery.
Definition pao_types.F:12
Define the data structure for the particle information.
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs)
Get the QUICKSTEP environment.
Routines to somehow generate an 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, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, init_u_ramping_each_scf, reltmat, ghost, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
subroutine, public set_qs_kind(qs_kind, paw_atom, ghost, floating, hard_radius, hard0_radius, covalent_radius, vdw_radius, lmax_rho0, zeff, no_optimize, dispersion, u_minus_j, reltmat, dftb_parameter, xtb_parameter, elec_conf, pao_basis_size)
Set the components of an atomic kind data set.
routines that build the Kohn-Sham matrix (i.e calculate the coulomb and xc parts
subroutine, public qs_ks_update_qs_env(qs_env, calculate_forces, just_energy, print_active)
updates the Kohn Sham matrix of the given qs_env (facility method)
subroutine, public qs_ks_did_change(ks_env, s_mstruct_changed, rho_changed, potential_changed, full_reset)
tells that some of the things relevant to the ks calculation did change. has to be called when change...
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...
Provides all information about an atomic kind.
type of a logger, at the moment it contains just a print level starting at which level it should be l...
stores all the informations relevant to an mpi environment
Holds information about a PAO descriptor.
Holds information about a PAO potential.
Provides all information about a quickstep kind.
keeps the density in various representations, keeping track of which ones are valid.