(git:ccc2433)
minbas_wfn_analysis.F
Go to the documentation of this file.
1 !--------------------------------------------------------------------------------------------------!
2 ! CP2K: A general program to perform molecular dynamics simulations !
3 ! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4 ! !
5 ! SPDX-License-Identifier: GPL-2.0-or-later !
6 !--------------------------------------------------------------------------------------------------!
7 
8 ! **************************************************************************************************
9 !> \brief Calculate localized minimal basis and analyze wavefunctions
10 !> \par History
11 !> 12.2016 created [JGH]
12 !> \author JGH
13 ! **************************************************************************************************
17  USE atomic_kind_types, ONLY: atomic_kind_type
18  USE bibliography, ONLY: lu2004,&
19  cite_reference
20  USE cell_types, ONLY: cell_type
21  USE cp_blacs_env, ONLY: cp_blacs_env_type
22  USE cp_control_types, ONLY: dft_control_type
31  cp_fm_struct_type
32  USE cp_fm_types, ONLY: cp_fm_create,&
34  cp_fm_release,&
35  cp_fm_to_fm,&
36  cp_fm_type
38  cp_logger_type
42  USE dbcsr_api, ONLY: &
43  dbcsr_copy, dbcsr_create, dbcsr_distribution_type, dbcsr_dot, dbcsr_get_block_p, &
44  dbcsr_get_occupation, dbcsr_iterator_blocks_left, dbcsr_iterator_next_block, &
45  dbcsr_iterator_start, dbcsr_iterator_stop, dbcsr_iterator_type, dbcsr_multiply, &
46  dbcsr_p_type, dbcsr_release, dbcsr_set, dbcsr_type, dbcsr_type_no_symmetry, &
47  dbcsr_type_symmetric
51  section_vals_type,&
54  USE kinds, ONLY: default_path_length,&
55  dp
56  USE message_passing, ONLY: mp_para_env_type
59  USE mulliken, ONLY: compute_bond_order,&
60  mulliken_charges
61  USE parallel_gemm_api, ONLY: parallel_gemm
62  USE particle_list_types, ONLY: particle_list_type
64  USE particle_types, ONLY: particle_type
65  USE pw_env_types, ONLY: pw_env_get,&
66  pw_env_type
67  USE pw_pool_types, ONLY: pw_pool_type
68  USE pw_types, ONLY: pw_c1d_gs_type,&
69  pw_r3d_rs_type
71  USE qs_environment_types, ONLY: get_qs_env,&
72  qs_environment_type
73  USE qs_kind_types, ONLY: qs_kind_type
74  USE qs_ks_types, ONLY: get_ks_env,&
75  qs_ks_env_type
77  USE qs_mo_types, ONLY: allocate_mo_set,&
79  get_mo_set,&
80  mo_set_type,&
82  USE qs_subsys_types, ONLY: qs_subsys_get,&
83  qs_subsys_type
84 #include "./base/base_uses.f90"
85 
86  IMPLICIT NONE
87  PRIVATE
88 
89  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'minbas_wfn_analysis'
90 
91  PUBLIC :: minbas_analysis
92 
93 ! **************************************************************************************************
94 
95 CONTAINS
96 
97 ! **************************************************************************************************
98 !> \brief ...
99 !> \param qs_env ...
100 !> \param input_section ...
101 !> \param unit_nr ...
102 ! **************************************************************************************************
103  SUBROUTINE minbas_analysis(qs_env, input_section, unit_nr)
104  TYPE(qs_environment_type), POINTER :: qs_env
105  TYPE(section_vals_type), POINTER :: input_section
106  INTEGER, INTENT(IN) :: unit_nr
107 
108  CHARACTER(len=*), PARAMETER :: routinen = 'minbas_analysis'
109 
110  INTEGER :: handle, homo, i, ispin, nao, natom, &
111  nimages, nmao, nmo, nspin
112  INTEGER, ALLOCATABLE, DIMENSION(:, :, :) :: ecount
113  INTEGER, DIMENSION(:), POINTER :: col_blk_sizes, row_blk_sizes
114  LOGICAL :: do_bondorder, explicit, full_ortho, occeq
115  REAL(kind=dp) :: alpha, amax, eps_filter, filter_eps, &
116  trace
117  REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: border, fnorm, mcharge, prmao
118  REAL(kind=dp), DIMENSION(:), POINTER :: occupation_numbers
119  TYPE(cp_blacs_env_type), POINTER :: blacs_env
120  TYPE(cp_fm_struct_type), POINTER :: fm_struct_a, fm_struct_b, fm_struct_c
121  TYPE(cp_fm_type) :: fm1, fm2, fm3, fm4
122  TYPE(cp_fm_type), POINTER :: fm_mos
123  TYPE(dbcsr_distribution_type), POINTER :: dbcsr_dist
124  TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: mao_coef, pqmat, quambo, sqmat
125  TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_s
126  TYPE(dbcsr_type) :: psmat, sinv, smao, smaox, spmat
127  TYPE(dbcsr_type), POINTER :: smat
128  TYPE(dft_control_type), POINTER :: dft_control
129  TYPE(mo_set_type), ALLOCATABLE, DIMENSION(:) :: mbas
130  TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
131  TYPE(mp_para_env_type), POINTER :: para_env
132  TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
133  TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
134  TYPE(qs_ks_env_type), POINTER :: ks_env
135  TYPE(section_vals_type), POINTER :: molden_section
136 
137  ! only do MINBAS analysis if explicitly requested
138  CALL section_vals_get(input_section, explicit=explicit)
139  IF (.NOT. explicit) RETURN
140 
141  ! k-points?
142  CALL get_qs_env(qs_env, dft_control=dft_control)
143  nspin = dft_control%nspins
144  nimages = dft_control%nimages
145  IF (nimages > 1) THEN
146  IF (unit_nr > 0) THEN
147  WRITE (unit=unit_nr, fmt="(T2,A)") &
148  "K-Points: Localized Minimal Basis Analysis not available."
149  END IF
150  END IF
151  IF (nimages > 1) RETURN
152 
153  CALL timeset(routinen, handle)
154 
155  IF (unit_nr > 0) THEN
156  WRITE (unit_nr, '(/,T2,A)') '!-----------------------------------------------------------------------------!'
157  WRITE (unit=unit_nr, fmt="(T26,A)") "LOCALIZED MINIMAL BASIS ANALYSIS"
158  WRITE (unit=unit_nr, fmt="(T18,A)") "W.C. Lu et al, J. Chem. Phys. 120, 2629 (2004)"
159  WRITE (unit_nr, '(T2,A)') '!-----------------------------------------------------------------------------!'
160  END IF
161  CALL cite_reference(lu2004)
162 
163  ! input options
164  CALL section_vals_val_get(input_section, "EPS_FILTER", r_val=eps_filter)
165  CALL section_vals_val_get(input_section, "FULL_ORTHOGONALIZATION", l_val=full_ortho)
166  CALL section_vals_val_get(input_section, "BOND_ORDER", l_val=do_bondorder)
167 
168  ! generate MAOs and QUAMBOs
169  CALL get_qs_env(qs_env, mos=mos)
170  NULLIFY (quambo, mao_coef)
171  CALL minbas_calculation(qs_env, mos, quambo, mao=mao_coef, iounit=unit_nr, &
172  full_ortho=full_ortho, eps_filter=eps_filter)
173  IF (ASSOCIATED(quambo)) THEN
174  CALL get_mo_set(mo_set=mos(1), nao=nao, nmo=nmo)
175  CALL get_qs_env(qs_env=qs_env, ks_env=ks_env)
176  CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set, natom=natom)
177  CALL get_ks_env(ks_env=ks_env, particle_set=particle_set, dbcsr_dist=dbcsr_dist)
178  ALLOCATE (row_blk_sizes(natom), col_blk_sizes(natom))
179  CALL get_particle_set(particle_set, qs_kind_set, nsgf=row_blk_sizes)
180  CALL get_particle_set(particle_set, qs_kind_set, nmao=col_blk_sizes)
181  nmao = sum(col_blk_sizes)
182 
183  NULLIFY (pqmat, sqmat)
184  CALL dbcsr_allocate_matrix_set(sqmat, nspin)
185  CALL dbcsr_allocate_matrix_set(pqmat, nspin)
186  DO ispin = 1, nspin
187  ALLOCATE (sqmat(ispin)%matrix)
188  CALL dbcsr_create(matrix=sqmat(ispin)%matrix, &
189  name="SQMAT", dist=dbcsr_dist, matrix_type=dbcsr_type_symmetric, &
190  row_blk_size=col_blk_sizes, col_blk_size=col_blk_sizes, nze=0)
191  ALLOCATE (pqmat(ispin)%matrix)
192  CALL dbcsr_create(matrix=pqmat(ispin)%matrix, &
193  name="PQMAT", dist=dbcsr_dist, matrix_type=dbcsr_type_symmetric, &
194  row_blk_size=col_blk_sizes, col_blk_size=col_blk_sizes, nze=0)
195  END DO
196  DEALLOCATE (row_blk_sizes, col_blk_sizes)
197 
198  ! Start wfn analysis
199  IF (unit_nr > 0) THEN
200  WRITE (unit_nr, '(/,T2,A)') 'Localized Minimal Basis Wavefunction Analysis'
201  END IF
202 
203  ! localization of basis
204  DO ispin = 1, nspin
205  amax = dbcsr_get_occupation(quambo(ispin)%matrix)
206  IF (unit_nr > 0) THEN
207  WRITE (unit_nr, '(/,T2,A,I2,T69,F10.3,A2,/)') &
208  'Occupation of Basis Function Representation (Spin) ', ispin, amax*100._dp, ' %'
209  END IF
210  END DO
211 
212  CALL get_qs_env(qs_env, matrix_s_kp=matrix_s)
213  CALL get_qs_env(qs_env=qs_env, para_env=para_env, blacs_env=blacs_env)
214  CALL cp_fm_struct_create(fm_struct_a, nrow_global=nao, ncol_global=nmao, &
215  para_env=para_env, context=blacs_env)
216  CALL cp_fm_create(fm1, fm_struct_a)
217  CALL cp_fm_struct_create(fm_struct_b, nrow_global=nmao, ncol_global=nmo, &
218  para_env=para_env, context=blacs_env)
219  CALL cp_fm_create(fm2, fm_struct_b)
220  CALL cp_fm_create(fm3, fm_struct_b)
221  CALL cp_fm_struct_create(fm_struct_c, nrow_global=nmo, ncol_global=nmo, &
222  para_env=para_env, context=blacs_env)
223  CALL cp_fm_create(fm4, fm_struct_c)
224  ALLOCATE (fnorm(nmo, nspin), ecount(natom, 3, nspin), prmao(natom, nspin))
225  ecount = 0
226  prmao = 0.0_dp
227  DO ispin = 1, nspin
228  CALL dbcsr_create(smao, name="S*QM", template=mao_coef(1)%matrix)
229  smat => matrix_s(1, 1)%matrix
230  CALL dbcsr_multiply("N", "N", 1.0_dp, smat, quambo(ispin)%matrix, 0.0_dp, smao)
231  ! calculate atomic extend of basis
232  CALL pm_extend(quambo(ispin)%matrix, smao, ecount(:, :, ispin))
233  CALL dbcsr_create(sinv, name="QM*S*QM", template=sqmat(ispin)%matrix)
234  CALL dbcsr_multiply("T", "N", 1.0_dp, quambo(ispin)%matrix, smao, 0.0_dp, sqmat(ispin)%matrix)
235  ! atomic MAO projection
236  CALL project_mao(mao_coef(ispin)%matrix, smao, sqmat(ispin)%matrix, prmao(:, ispin))
237  ! invert overlap
238  CALL invert_hotelling(sinv, sqmat(ispin)%matrix, 1.e-6_dp, silent=.true.)
239  CALL dbcsr_create(smaox, name="S*QM*SINV", template=smao)
240  CALL dbcsr_multiply("N", "N", 1.0_dp, smao, sinv, 0.0_dp, smaox)
241  CALL copy_dbcsr_to_fm(smaox, fm1)
242  CALL get_mo_set(mos(ispin), mo_coeff=fm_mos, homo=homo)
243  CALL parallel_gemm("T", "N", nmao, nmo, nao, 1.0_dp, fm1, fm_mos, 0.0_dp, fm2)
244  CALL cp_dbcsr_sm_fm_multiply(sqmat(ispin)%matrix, fm2, fm3, nmo)
245  CALL parallel_gemm("T", "N", nmo, nmo, nmao, 1.0_dp, fm2, fm3, 0.0_dp, fm4)
246  CALL cp_fm_get_diag(fm4, fnorm(1:nmo, ispin))
247  ! fm2 are the projected MOs (in MAO basis); orthogonalize the occupied subspace
248  CALL make_basis_lowdin(vmatrix=fm2, ncol=homo, matrix_s=sqmat(ispin)%matrix)
249  ! pmat
250  CALL get_mo_set(mos(ispin), occupation_numbers=occupation_numbers, maxocc=alpha)
251  occeq = all(occupation_numbers(1:homo) == alpha)
252  CALL dbcsr_copy(pqmat(ispin)%matrix, sqmat(ispin)%matrix)
253  CALL dbcsr_set(pqmat(ispin)%matrix, 0.0_dp)
254  IF (occeq) THEN
255  CALL cp_dbcsr_plus_fm_fm_t(sparse_matrix=pqmat(ispin)%matrix, matrix_v=fm2, &
256  ncol=homo, alpha=alpha, keep_sparsity=.false.)
257  ELSE
258  CALL cp_fm_to_fm(fm2, fm3)
259  CALL cp_fm_column_scale(fm3, occupation_numbers(1:homo))
260  alpha = 1.0_dp
261  CALL cp_dbcsr_plus_fm_fm_t(sparse_matrix=pqmat(ispin)%matrix, matrix_v=fm2, &
262  matrix_g=fm3, ncol=homo, alpha=alpha, keep_sparsity=.true.)
263  END IF
264 
265  CALL dbcsr_release(smao)
266  CALL dbcsr_release(smaox)
267  CALL dbcsr_release(sinv)
268  END DO
269  ! Basis extension
270  CALL para_env%sum(ecount)
271  IF (unit_nr > 0) THEN
272  IF (nspin == 1) THEN
273  WRITE (unit_nr, '(T2,A,T20,A,T40,A,T60,A)') 'Ref. Atom', ' # > 0.100 ', ' # > 0.010 ', ' # > 0.001 '
274  DO i = 1, natom
275  WRITE (unit_nr, '(T2,I8,T20,I10,T40,I10,T60,I10)') i, ecount(i, 1:3, 1)
276  END DO
277  ELSE
278  WRITE (unit_nr, '(T2,A,T20,A,T40,A,T60,A)') 'Ref. Atom', ' # > 0.100 ', ' # > 0.010 ', ' # > 0.001 '
279  DO i = 1, natom
280  WRITE (unit_nr, '(T2,I8,T20,2I6,T40,2I6,T60,2I6)') &
281  i, ecount(i, 1, 1:2), ecount(i, 2, 1:2), ecount(i, 3, 1:2)
282  END DO
283  END IF
284  END IF
285  ! MAO projection
286  CALL para_env%sum(prmao)
287  IF (unit_nr > 0) THEN
288  DO ispin = 1, nspin
289  WRITE (unit_nr, '(/,T2,A,I2)') 'Projection on same atom MAO orbitals: Spin ', ispin
290  DO i = 1, natom, 2
291  IF (i < natom) THEN
292  WRITE (unit_nr, '(T2,A,I8,T20,A,F10.6,T42,A,I8,T60,A,F10.6)') &
293  " Atom:", i, "Projection:", prmao(i, ispin), " Atom:", i + 1, "Projection:", prmao(i + 1, ispin)
294  ELSE
295  WRITE (unit_nr, '(T2,A,I8,T20,A,F10.6)') " Atom:", i, "Projection:", prmao(i, ispin)
296  END IF
297  END DO
298  END DO
299  END IF
300  ! MO expansion completness
301  DO ispin = 1, nspin
302  CALL get_mo_set(mos(ispin), homo=homo, nmo=nmo)
303  IF (unit_nr > 0) THEN
304  WRITE (unit_nr, '(/,T2,A,I2)') 'MO expansion in Localized Minimal Basis: Spin ', ispin
305  WRITE (unit_nr, '(T64,A)') 'Occupied Orbitals'
306  WRITE (unit_nr, '(8F10.6)') fnorm(1:homo, ispin)
307  WRITE (unit_nr, '(T65,A)') 'Virtual Orbitals'
308  WRITE (unit_nr, '(8F10.6)') fnorm(homo + 1:nmo, ispin)
309  END IF
310  END DO
311  ! Mulliken population
312  IF (unit_nr > 0) THEN
313  WRITE (unit_nr, '(/,T2,A)') 'Mulliken Population Analysis '
314  END IF
315  ALLOCATE (mcharge(natom, nspin))
316  DO ispin = 1, nspin
317  CALL dbcsr_dot(pqmat(ispin)%matrix, sqmat(ispin)%matrix, trace)
318  IF (unit_nr > 0) THEN
319  WRITE (unit_nr, '(T2,A,I2,T66,F15.4)') 'Number of Electrons: Trace(PS) Spin ', ispin, trace
320  END IF
321  CALL mulliken_charges(pqmat(ispin)%matrix, sqmat(ispin)%matrix, para_env, mcharge(:, ispin))
322  END DO
323  CALL print_atomic_charges(particle_set, qs_kind_set, unit_nr, "Minimal Basis Mulliken Charges", &
324  electronic_charges=mcharge)
325  ! Mayer bond orders
326  IF (do_bondorder) THEN
327  ALLOCATE (border(natom, natom))
328  border = 0.0_dp
329  CALL dbcsr_create(psmat, name="PS", template=sqmat(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
330  CALL dbcsr_create(spmat, name="SP", template=sqmat(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
331  filter_eps = 1.e-6_dp
332  DO ispin = 1, nspin
333  CALL dbcsr_multiply("N", "N", 1.0_dp, pqmat(ispin)%matrix, sqmat(ispin)%matrix, 0.0_dp, psmat, &
334  filter_eps=filter_eps)
335  CALL dbcsr_multiply("N", "N", 1.0_dp, sqmat(ispin)%matrix, pqmat(ispin)%matrix, 0.0_dp, spmat, &
336  filter_eps=filter_eps)
337  CALL compute_bond_order(psmat, spmat, border)
338  END DO
339  CALL para_env%sum(border)
340  border = border*real(nspin, kind=dp)
341  CALL dbcsr_release(psmat)
342  CALL dbcsr_release(spmat)
343  CALL print_bond_orders(particle_set, unit_nr, border)
344  DEALLOCATE (border)
345  END IF
346 
347  ! for printing purposes we now copy the QUAMBOs into MO format
348  ALLOCATE (mbas(nspin))
349  DO ispin = 1, nspin
350  CALL allocate_mo_set(mbas(ispin), nao, nmao, nmao, 0.0_dp, 1.0_dp, 0.0_dp)
351  CALL set_mo_set(mbas(ispin), homo=nmao)
352  ALLOCATE (mbas(ispin)%eigenvalues(nmao))
353  mbas(ispin)%eigenvalues = 0.0_dp
354  ALLOCATE (mbas(ispin)%occupation_numbers(nmao))
355  mbas(ispin)%occupation_numbers = 1.0_dp
356  CALL cp_fm_create(mbas(ispin)%mo_coeff, fm_struct_a)
357  CALL copy_dbcsr_to_fm(quambo(ispin)%matrix, mbas(ispin)%mo_coeff)
358  END DO
359 
360  ! Print basis functions: cube files
361  DO ispin = 1, nspin
362  CALL get_mo_set(mbas(ispin), mo_coeff=fm_mos)
363  CALL post_minbas_cubes(qs_env, input_section, fm_mos, ispin)
364  END DO
365  ! Print basis functions: molden format
366  molden_section => section_vals_get_subs_vals(input_section, "MINBAS_MOLDEN")
367  CALL write_mos_molden(mbas, qs_kind_set, particle_set, molden_section)
368  DO ispin = 1, nspin
369  CALL deallocate_mo_set(mbas(ispin))
370  END DO
371  DEALLOCATE (mbas)
372 
373  DEALLOCATE (fnorm, ecount, prmao, mcharge)
374  CALL cp_fm_release(fm1)
375  CALL cp_fm_release(fm2)
376  CALL cp_fm_release(fm3)
377  CALL cp_fm_release(fm4)
378  CALL cp_fm_struct_release(fm_struct_a)
379  CALL cp_fm_struct_release(fm_struct_b)
380  CALL cp_fm_struct_release(fm_struct_c)
381 
382  ! clean up
383  CALL dbcsr_deallocate_matrix_set(sqmat)
384  CALL dbcsr_deallocate_matrix_set(pqmat)
385  CALL dbcsr_deallocate_matrix_set(mao_coef)
386  CALL dbcsr_deallocate_matrix_set(quambo)
387 
388  END IF
389 
390  IF (unit_nr > 0) THEN
391  WRITE (unit_nr, '(/,T2,A)') &
392  '!--------------------------END OF MINBAS ANALYSIS-----------------------------!'
393  END IF
394 
395  CALL timestop(handle)
396 
397  END SUBROUTINE minbas_analysis
398 
399 ! **************************************************************************************************
400 !> \brief ...
401 !> \param quambo ...
402 !> \param smao ...
403 !> \param ecount ...
404 ! **************************************************************************************************
405  SUBROUTINE pm_extend(quambo, smao, ecount)
406  TYPE(dbcsr_type) :: quambo, smao
407  INTEGER, DIMENSION(:, :), INTENT(INOUT) :: ecount
408 
409  INTEGER :: iatom, jatom, n
410  LOGICAL :: found
411  REAL(kind=dp) :: wij
412  REAL(kind=dp), DIMENSION(:, :), POINTER :: qblock, sblock
413  TYPE(dbcsr_iterator_type) :: dbcsr_iter
414 
415  CALL dbcsr_iterator_start(dbcsr_iter, quambo)
416  DO WHILE (dbcsr_iterator_blocks_left(dbcsr_iter))
417  CALL dbcsr_iterator_next_block(dbcsr_iter, iatom, jatom, qblock)
418  CALL dbcsr_get_block_p(matrix=smao, row=iatom, col=jatom, block=sblock, found=found)
419  IF (found) THEN
420  n = SIZE(qblock, 2)
421  wij = abs(sum(qblock*sblock))/real(n, kind=dp)
422  IF (wij > 0.1_dp) THEN
423  ecount(jatom, 1) = ecount(jatom, 1) + 1
424  ELSEIF (wij > 0.01_dp) THEN
425  ecount(jatom, 2) = ecount(jatom, 2) + 1
426  ELSEIF (wij > 0.001_dp) THEN
427  ecount(jatom, 3) = ecount(jatom, 3) + 1
428  END IF
429  END IF
430  END DO
431  CALL dbcsr_iterator_stop(dbcsr_iter)
432 
433  END SUBROUTINE pm_extend
434 
435 ! **************************************************************************************************
436 !> \brief ...
437 !> \param mao ...
438 !> \param smao ...
439 !> \param sovl ...
440 !> \param prmao ...
441 ! **************************************************************************************************
442  SUBROUTINE project_mao(mao, smao, sovl, prmao)
443  TYPE(dbcsr_type) :: mao, smao, sovl
444  REAL(kind=dp), DIMENSION(:), INTENT(INOUT) :: prmao
445 
446  INTEGER :: i, iatom, jatom, n
447  LOGICAL :: found
448  REAL(kind=dp) :: wi
449  REAL(kind=dp), DIMENSION(:, :), POINTER :: qblock, sblock, so
450  TYPE(dbcsr_iterator_type) :: dbcsr_iter
451 
452  CALL dbcsr_iterator_start(dbcsr_iter, mao)
453  DO WHILE (dbcsr_iterator_blocks_left(dbcsr_iter))
454  CALL dbcsr_iterator_next_block(dbcsr_iter, iatom, jatom, qblock)
455  cpassert(iatom == jatom)
456  CALL dbcsr_get_block_p(matrix=smao, row=iatom, col=jatom, block=sblock, found=found)
457  IF (found) THEN
458  CALL dbcsr_get_block_p(matrix=sovl, row=iatom, col=jatom, block=so, found=found)
459  n = SIZE(qblock, 2)
460  DO i = 1, n
461  wi = sum(qblock(:, i)*sblock(:, i))
462  prmao(iatom) = prmao(iatom) + wi/so(i, i)
463  END DO
464  END IF
465  END DO
466  CALL dbcsr_iterator_stop(dbcsr_iter)
467 
468  END SUBROUTINE project_mao
469 
470 ! **************************************************************************************************
471 !> \brief Computes and prints the Cube Files for the minimal basis set
472 !> \param qs_env ...
473 !> \param print_section ...
474 !> \param minbas_coeff ...
475 !> \param ispin ...
476 ! **************************************************************************************************
477  SUBROUTINE post_minbas_cubes(qs_env, print_section, minbas_coeff, ispin)
478  TYPE(qs_environment_type), POINTER :: qs_env
479  TYPE(section_vals_type), POINTER :: print_section
480  TYPE(cp_fm_type), INTENT(IN) :: minbas_coeff
481  INTEGER, INTENT(IN) :: ispin
482 
483  CHARACTER(LEN=default_path_length) :: filename, title
484  INTEGER :: i, i_rep, ivec, iw, j, n_rep, natom
485  INTEGER, DIMENSION(:), POINTER :: blk_sizes, first_bas, ilist, stride
486  LOGICAL :: explicit, mpi_io
487  TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
488  TYPE(cell_type), POINTER :: cell
489  TYPE(cp_logger_type), POINTER :: logger
490  TYPE(dft_control_type), POINTER :: dft_control
491  TYPE(particle_list_type), POINTER :: particles
492  TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
493  TYPE(pw_c1d_gs_type) :: wf_g
494  TYPE(pw_env_type), POINTER :: pw_env
495  TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
496  TYPE(pw_r3d_rs_type) :: wf_r
497  TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
498  TYPE(qs_subsys_type), POINTER :: subsys
499  TYPE(section_vals_type), POINTER :: minbas_section
500 
501  minbas_section => section_vals_get_subs_vals(print_section, "MINBAS_CUBE")
502  CALL section_vals_get(minbas_section, explicit=explicit)
503  IF (.NOT. explicit) RETURN
504 
505  logger => cp_get_default_logger()
506  stride => section_get_ivals(print_section, "MINBAS_CUBE%STRIDE")
507 
508  CALL get_qs_env(qs_env=qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, &
509  subsys=subsys, cell=cell, particle_set=particle_set, pw_env=pw_env, dft_control=dft_control)
510  CALL qs_subsys_get(subsys, particles=particles)
511 
512  CALL get_qs_env(qs_env=qs_env, natom=natom)
513  ALLOCATE (blk_sizes(natom), first_bas(0:natom))
514  CALL get_particle_set(particle_set, qs_kind_set, nmao=blk_sizes)
515  first_bas(0) = 0
516  DO i = 1, natom
517  first_bas(i) = first_bas(i - 1) + blk_sizes(i)
518  END DO
519 
520  CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
521  CALL auxbas_pw_pool%create_pw(wf_r)
522  CALL auxbas_pw_pool%create_pw(wf_g)
523 
524  ! loop over list of atoms
525  CALL section_vals_val_get(minbas_section, "ATOM_LIST", n_rep_val=n_rep)
526  IF (n_rep == 0) THEN
527  DO i = 1, natom
528  DO ivec = first_bas(i - 1) + 1, first_bas(i)
529  WRITE (filename, '(a4,I5.5,a1,I1.1)') "MINBAS_", ivec, "_", ispin
530  WRITE (title, *) "MINIMAL BASIS ", ivec, " atom ", i, " spin ", ispin
531  mpi_io = .true.
532  iw = cp_print_key_unit_nr(logger, print_section, "MINBAS_CUBE", extension=".cube", &
533  middle_name=trim(filename), file_position="REWIND", log_filename=.false., &
534  mpi_io=mpi_io)
535  CALL calculate_wavefunction(minbas_coeff, ivec, wf_r, wf_g, atomic_kind_set, qs_kind_set, &
536  cell, dft_control, particle_set, pw_env)
537  CALL cp_pw_to_cube(wf_r, iw, title, particles=particles, stride=stride, mpi_io=mpi_io)
538  CALL cp_print_key_finished_output(iw, logger, print_section, "MINBAS_CUBE", mpi_io=mpi_io)
539  END DO
540  END DO
541  ELSE
542  DO i_rep = 1, n_rep
543  CALL section_vals_val_get(minbas_section, "ATOM_LIST", i_rep_val=i_rep, i_vals=ilist)
544  DO i = 1, SIZE(ilist, 1)
545  j = ilist(i)
546  DO ivec = first_bas(j - 1) + 1, first_bas(j)
547  WRITE (filename, '(a4,I5.5,a1,I1.1)') "MINBAS_", ivec, "_", ispin
548  WRITE (title, *) "MINIMAL BASIS ", ivec, " atom ", j, " spin ", ispin
549  mpi_io = .true.
550  iw = cp_print_key_unit_nr(logger, print_section, "MINBAS_CUBE", extension=".cube", &
551  middle_name=trim(filename), file_position="REWIND", log_filename=.false., &
552  mpi_io=mpi_io)
553  CALL calculate_wavefunction(minbas_coeff, ivec, wf_r, wf_g, atomic_kind_set, qs_kind_set, &
554  cell, dft_control, particle_set, pw_env)
555  CALL cp_pw_to_cube(wf_r, iw, title, particles=particles, stride=stride, mpi_io=mpi_io)
556  CALL cp_print_key_finished_output(iw, logger, print_section, "MINBAS_CUBE", mpi_io=mpi_io)
557  END DO
558  END DO
559  END DO
560  END IF
561  DEALLOCATE (blk_sizes, first_bas)
562  CALL auxbas_pw_pool%give_back_pw(wf_r)
563  CALL auxbas_pw_pool%give_back_pw(wf_g)
564 
565  END SUBROUTINE post_minbas_cubes
566 
567 END MODULE minbas_wfn_analysis
simple routine to print charges for all atomic charge methods (currently mulliken,...
subroutine, public print_bond_orders(particle_set, scr, bond_orders)
Print Mayer bond orders.
subroutine, public print_atomic_charges(particle_set, qs_kind_set, scr, title, electronic_charges, atomic_charges)
generates a unified output format for atomic charges
Define the atomic kind types and their sub types.
collects all references to literature in CP2K as new algorithms / method are included from literature...
Definition: bibliography.F:28
integer, save, public lu2004
Definition: bibliography.F:43
Handles all functions related to the CELL.
Definition: cell_types.F:15
methods related to the blacs parallel environment
Definition: cp_blacs_env.F:15
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
DBCSR operations in CP2K.
subroutine, public cp_dbcsr_sm_fm_multiply(matrix, fm_in, fm_out, ncol, alpha, beta)
multiply a dbcsr with a fm matrix
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public cp_dbcsr_plus_fm_fm_t(sparse_matrix, matrix_v, matrix_g, ncol, alpha, keep_sparsity, symmetry_mode)
performs the multiplication sparse_matrix+dense_mat*dens_mat^T if matrix_g is not explicitly given,...
basic linear algebra operations for full matrices
subroutine, public cp_fm_column_scale(matrixa, scaling)
scales column i of matrix a with scaling(i)
represent the structure of a full matrix
Definition: cp_fm_struct.F:14
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
Definition: cp_fm_struct.F:125
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
Definition: cp_fm_struct.F:320
represent a full matrix distributed on many processors
Definition: cp_fm_types.F:15
subroutine, public cp_fm_get_diag(matrix, diag)
returns the diagonal elements of a fm
Definition: cp_fm_types.F:570
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp)
creates a new full matrix with the given structure
Definition: cp_fm_types.F:167
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
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
A wrapper around pw_to_cube() which accepts particle_list_type.
subroutine, public cp_pw_to_cube(pw, unit_nr, title, particles, stride, zero_tails, silent, mpi_io)
...
objects that represent the structure of input sections and the data contained in an input section
integer function, dimension(:), pointer, public section_get_ivals(section_vals, keyword_name)
...
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_get(section_vals, ref_count, n_repetition, n_subs_vals_rep, section, explicit)
returns various attributes about the section_vals
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Routines useful for iterative matrix calculations.
subroutine, public invert_hotelling(matrix_inverse, matrix, threshold, use_inv_as_guess, norm_convergence, filter_eps, accelerator_order, max_iter_lanczos, eps_lanczos, silent)
invert a symmetric positive definite matrix by Hotelling's method explicit symmetrization makes this ...
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
Interface to the message passing library MPI.
Calculate localized minimal basis.
subroutine, public minbas_calculation(qs_env, mos, quambo, mao, iounit, full_ortho, eps_filter)
...
Calculate localized minimal basis and analyze wavefunctions.
subroutine, public minbas_analysis(qs_env, input_section, unit_nr)
...
Functions handling the MOLDEN format. Split from mode_selective.
Definition: molden_utils.F:12
subroutine, public write_mos_molden(mos, qs_kind_set, particle_set, print_section)
Write out the MOs in molden format for visualisation.
Definition: molden_utils.F:65
compute mulliken charges we (currently) define them as c_i = 1/2 [ (PS)_{ii} + (SP)_{ii} ]
Definition: mulliken.F:13
subroutine, public compute_bond_order(psmat, spmat, bond_order)
compute Mayer bond orders for a single spin channel for complete result sum up over all spins and mul...
Definition: mulliken.F:657
basic linear algebra operations for full matrixes
represent a simple array based list of the given type
Define methods related to particle_type.
subroutine, public get_particle_set(particle_set, qs_kind_set, first_sgf, last_sgf, nsgf, nmao, basis)
Get the components of a particle set.
Define the data structure for the particle information.
container for various plainwaves related things
Definition: pw_env_types.F:14
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
Definition: pw_env_types.F:113
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Definition: pw_pool_types.F:24
Calculate the plane wave density by collocating the primitive Gaussian functions (pgf).
subroutine, public calculate_wavefunction(mo_vectors, ivector, rho, rho_gspace, atomic_kind_set, qs_kind_set, cell, dft_control, particle_set, pw_env, basis_type, external_vector)
maps a given wavefunction on the grid
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_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, 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, rhs)
Get the QUICKSTEP environment.
Define the quickstep kind type and their sub types.
Definition: qs_kind_types.F:23
subroutine, public get_ks_env(ks_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, complex_ks, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, kinetic, matrix_s, matrix_s_RI_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_RI_aux_kp, matrix_ks_im_kp, rho, rho_xc, vppl, rho_core, rho_nlcc, rho_nlcc_g, vee, neighbor_list_id, sab_orb, sab_all, sac_ae, sac_ppl, sac_lri, sap_ppnl, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_nonbond, sab_vdw, sab_scp, sab_almo, sab_kp, sab_kp_nosym, task_list, task_list_soft, kpoints, do_kpoints, atomic_kind_set, qs_kind_set, cell, cell_ref, use_ref_cell, particle_set, energy, force, local_particles, local_molecules, molecule_kind_set, molecule_set, subsys, cp_subsys, virial, results, atprop, nkind, natom, dft_control, dbcsr_dist, distribution_2d, pw_env, para_env, blacs_env, nelectron_total, nelectron_spin)
...
Definition: qs_ks_types.F:330
collects routines that perform operations directly related to MOs
Definition: qs_mo_methods.F:14
subroutine, public make_basis_lowdin(vmatrix, ncol, matrix_s)
return a set of S orthonormal vectors (C^T S C == 1) where a Loedwin transformation is applied to kee...
Definition and initialisation of the mo data type.
Definition: qs_mo_types.F:22
subroutine, public set_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, uniform_occupation, kTS, mu, flexible_electron_count)
Set the components of a MO set data structure.
Definition: qs_mo_types.F:452
subroutine, public allocate_mo_set(mo_set, nao, nmo, nelectron, n_el_f, maxocc, flexible_electron_count)
Allocates a mo set and partially initializes it (nao,nmo,nelectron, and flexible_electron_count are v...
Definition: qs_mo_types.F:206
subroutine, public deallocate_mo_set(mo_set)
Deallocate a wavefunction data structure.
Definition: qs_mo_types.F:352
subroutine, public get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, uniform_occupation, kTS, mu, flexible_electron_count)
Get the components of a MO set data structure.
Definition: qs_mo_types.F:397
types that represent a quickstep subsys
subroutine, public qs_subsys_get(subsys, atomic_kinds, atomic_kind_set, particles, particle_set, local_particles, molecules, molecule_set, molecule_kinds, molecule_kind_set, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, natom, nparticle, ncore, nshell, nkind, atprop, virial, results, cell, cell_ref, use_ref_cell, energy, force, qs_kind_set, cp_subsys, nelectron_total, nelectron_spin)
...