(git:ed6f26b)
Loading...
Searching...
No Matches
qs_loc_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 Driver for the localization that should be general
10!> for all the methods available and all the definition of the
11!> spread functional
12!> Write centers, spread and cubes only if required and for the
13!> selected states
14!> The localized functions are copied in the standard mos array
15!> for the next use
16!> \par History
17!> 01.2008 Teodoro Laino [tlaino] - University of Zurich
18!> - Merging the two localization codes and updating to new structures
19!> \author MI (04.2005)
20! **************************************************************************************************
25 USE cell_types, ONLY: cell_type,&
26 pbc
28 USE cp_dbcsr_api, ONLY: dbcsr_copy,&
42 USE cp_fm_types, ONLY: cp_fm_create,&
54 cp_p_file,&
60 USE input_constants, ONLY: &
68 USE kinds, ONLY: default_path_length,&
70 dp,&
71 sp
72 USE machine, ONLY: m_flush
73 USE mathconstants, ONLY: pi,&
74 twopi
77 USE orbital_pointers, ONLY: ncoset
85 USE physcon, ONLY: angstrom
86 USE pw_env_types, ONLY: pw_env_get,&
89 USE pw_types, ONLY: pw_c1d_gs_type,&
95 USE qs_loc_types, ONLY: get_qs_loc_env,&
105 USE qs_matrix_pools, ONLY: mpools_get
107 USE qs_subsys_types, ONLY: qs_subsys_get,&
109 USE string_utilities, ONLY: xstring
110#include "./base/base_uses.f90"
111
112 IMPLICIT NONE
113
114 PRIVATE
115
116! *** Global parameters ***
117
118 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_loc_methods'
119
120! *** Public ***
124
125CONTAINS
126
127! **************************************************************************************************
128!> \brief Calculate and optimize the spread functional as calculated from
129!> the selected mos and by the definition using the berry phase
130!> as given by silvestrelli et al
131!> If required the centers and the spreads for each mos selected
132!> are calculated from z_ij and printed to file.
133!> The centers files is appended if already exists
134!> \param method indicates localization algorithm
135!> \param qs_loc_env new environment for the localization calculations
136!> \param vectors selected mos to be localized
137!> \param op_sm_set sparse matrices containing the integrals of the kind <mi e{iGr} nu>
138!> \param zij_fm_set set of full matrix of size nmoloc x nmoloc, will contain the z_ij numbers
139!> as defined by Silvestrelli et al
140!> \param para_env ...
141!> \param cell ...
142!> \param weights ...
143!> \param ispin ...
144!> \param print_loc_section ...
145!> \param restricted ...
146!> \param nextra ...
147!> \param nmo ...
148!> \param vectors_2 ...
149!> \param guess_mos ...
150!> \par History
151!> 04.2005 created [MI]
152!> \author MI
153!> \note
154!> This definition need the use of complex numbers, therefore the
155!> optimization routines are specific for this case
156!> The file for the centers and the spreads have a xyz format
157! **************************************************************************************************
158 SUBROUTINE optimize_loc_berry(method, qs_loc_env, vectors, op_sm_set, &
159 zij_fm_set, para_env, cell, weights, ispin, print_loc_section, &
160 restricted, nextra, nmo, vectors_2, guess_mos)
161
162 INTEGER, INTENT(IN) :: method
163 TYPE(qs_loc_env_type), POINTER :: qs_loc_env
164 TYPE(cp_fm_type), INTENT(IN) :: vectors
165 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: op_sm_set
166 TYPE(cp_fm_type), DIMENSION(:, :), INTENT(IN) :: zij_fm_set
167 TYPE(mp_para_env_type), POINTER :: para_env
168 TYPE(cell_type), POINTER :: cell
169 REAL(dp), DIMENSION(:) :: weights
170 INTEGER, INTENT(IN) :: ispin
171 TYPE(section_vals_type), POINTER :: print_loc_section
172 INTEGER :: restricted
173 INTEGER, INTENT(IN), OPTIONAL :: nextra, nmo
174 TYPE(cp_fm_type), INTENT(IN), OPTIONAL :: vectors_2, guess_mos
175
176 CHARACTER(len=*), PARAMETER :: routinen = 'optimize_loc_berry'
177
178 INTEGER :: handle, max_iter, nao, nmoloc, out_each, &
179 output_unit, sweeps
180 LOGICAL :: converged, crazy_use_diag, &
181 do_jacobi_refinement, my_do_mixed
182 REAL(dp) :: crazy_scale, eps_localization, &
183 max_crazy_angle, start_time, &
184 target_time
185 TYPE(cp_logger_type), POINTER :: logger
186
187 CALL timeset(routinen, handle)
188 logger => cp_get_default_logger()
189 output_unit = cp_print_key_unit_nr(logger, print_loc_section, "PROGRAM_RUN_INFO", &
190 extension=".locInfo")
191
192 ! get rows and cols of the input
193 CALL cp_fm_get_info(vectors, nrow_global=nao, ncol_global=nmoloc)
194
195 CALL zij_matrix(vectors, op_sm_set, zij_fm_set)
196
197 max_iter = qs_loc_env%localized_wfn_control%max_iter
198 max_crazy_angle = qs_loc_env%localized_wfn_control%max_crazy_angle
199 crazy_use_diag = qs_loc_env%localized_wfn_control%crazy_use_diag
200 crazy_scale = qs_loc_env%localized_wfn_control%crazy_scale
201 eps_localization = qs_loc_env%localized_wfn_control%eps_localization
202 out_each = qs_loc_env%localized_wfn_control%out_each
203 target_time = qs_loc_env%target_time
204 start_time = qs_loc_env%start_time
205 do_jacobi_refinement = qs_loc_env%localized_wfn_control%jacobi_refinement
206 my_do_mixed = qs_loc_env%localized_wfn_control%do_mixed
207
208 CALL centers_spreads_berry(qs_loc_env, zij_fm_set, nmoloc, cell, weights, &
209 ispin, print_loc_section, only_initial_out=.true.)
210
211 sweeps = 0
212
213 SELECT CASE (method)
214 CASE (do_loc_jacobi)
215 CALL jacobi_rotations(weights, zij_fm_set, vectors, para_env, max_iter=max_iter, &
216 eps_localization=eps_localization, sweeps=sweeps, &
217 out_each=out_each, target_time=target_time, start_time=start_time, &
218 restricted=restricted)
219 CASE (do_loc_gapo)
220 IF (my_do_mixed) THEN
221 IF (nextra > 0) THEN
222 IF (PRESENT(guess_mos)) THEN
223 CALL jacobi_cg_edf_ls(para_env, weights, zij_fm_set, vectors, max_iter, &
224 eps_localization, sweeps, out_each, nextra, &
225 qs_loc_env%localized_wfn_control%do_cg_po, &
226 nmo=nmo, vectors_2=vectors_2, mos_guess=guess_mos)
227 ELSE
228 CALL jacobi_cg_edf_ls(para_env, weights, zij_fm_set, vectors, max_iter, &
229 eps_localization, sweeps, out_each, nextra, &
230 qs_loc_env%localized_wfn_control%do_cg_po, &
231 nmo=nmo, vectors_2=vectors_2)
232 END IF
233 ELSE
234 CALL jacobi_cg_edf_ls(para_env, weights, zij_fm_set, vectors, max_iter, &
235 eps_localization, sweeps, out_each, 0, &
236 qs_loc_env%localized_wfn_control%do_cg_po)
237 END IF
238 ELSE
239 cpabort("GAPO works only with STATES MIXED")
240 END IF
241 CASE (do_loc_scdm)
242 ! Decomposition
243 CALL scdm_qrfact(vectors)
244 ! Calculation of Zij
245 CALL zij_matrix(vectors, op_sm_set, zij_fm_set)
246 IF (do_jacobi_refinement) THEN
247 ! Intermediate spread and centers
248 CALL centers_spreads_berry(qs_loc_env, zij_fm_set, nmoloc, cell, weights, &
249 ispin, print_loc_section, only_initial_out=.true.)
250 CALL jacobi_rotations(weights, zij_fm_set, vectors, para_env, max_iter=max_iter, &
251 eps_localization=eps_localization, sweeps=sweeps, &
252 out_each=out_each, target_time=target_time, start_time=start_time, &
253 restricted=restricted)
254 END IF
255 CASE (do_loc_crazy)
256 CALL crazy_rotations(weights, zij_fm_set, vectors, max_iter=max_iter, max_crazy_angle=max_crazy_angle, &
257 crazy_scale=crazy_scale, crazy_use_diag=crazy_use_diag, &
258 eps_localization=eps_localization, iterations=sweeps, converged=converged)
259 ! Possibly fallback to jacobi if the crazy rotation fails
260 IF (.NOT. converged) THEN
261 IF (qs_loc_env%localized_wfn_control%jacobi_fallback) THEN
262 IF (output_unit > 0) WRITE (output_unit, "(T4,A,I6,/,T4,A)") &
263 " Crazy Wannier localization not converged after ", sweeps, &
264 " iterations, switching to jacobi rotations"
265 CALL jacobi_rotations(weights, zij_fm_set, vectors, para_env, max_iter=max_iter, &
266 eps_localization=eps_localization, sweeps=sweeps, &
267 out_each=out_each, target_time=target_time, start_time=start_time, &
268 restricted=restricted)
269 ELSE
270 IF (output_unit > 0) WRITE (output_unit, "(T4,A,I6,/,T4,A)") &
271 " Crazy Wannier localization not converged after ", sweeps, &
272 " iterations, and jacobi_fallback switched off "
273 END IF
274 END IF
275 CASE (do_loc_direct)
276 CALL direct_mini(weights, zij_fm_set, vectors, max_iter=max_iter, &
277 eps_localization=eps_localization, iterations=sweeps)
278 CASE (do_loc_l1_norm_sd)
279 IF (.NOT. cell%orthorhombic) THEN
280 cpabort("Non-orthorhombic cell with the selected method NYI")
281 ELSE
282 CALL approx_l1_norm_sd(vectors, max_iter, eps_localization, converged, sweeps)
283 ! here we need to set zij for the computation of the centers and spreads
284 CALL zij_matrix(vectors, op_sm_set, zij_fm_set)
285 END IF
286 CASE (do_loc_none)
287 IF (output_unit > 0) THEN
288 WRITE (output_unit, '(T4,A,I6,A)') " No MOS localization applied "
289 END IF
290 CASE DEFAULT
291 cpabort("Unknown localization method")
292 END SELECT
293 IF (output_unit > 0) THEN
294 IF (sweeps <= max_iter) WRITE (output_unit, '(T4,A,I3,A,I6,A)') " Localization for spin ", ispin, &
295 " converged in ", sweeps, " iterations"
296 END IF
297
298 CALL centers_spreads_berry(qs_loc_env, zij_fm_set, nmoloc, cell, weights, &
299 ispin, print_loc_section)
300
301 CALL cp_print_key_finished_output(output_unit, logger, print_loc_section, "PROGRAM_RUN_INFO")
302
303 CALL timestop(handle)
304
305 END SUBROUTINE optimize_loc_berry
306
307! **************************************************************************************************
308!> \brief ...
309!> \param qs_env ...
310!> \param method ...
311!> \param qs_loc_env ...
312!> \param vectors ...
313!> \param zij_fm_set ...
314!> \param ispin ...
315!> \param print_loc_section ...
316!> \par History
317!> 04.2005 created [MI]
318!> \author MI
319! **************************************************************************************************
320 SUBROUTINE optimize_loc_pipek(qs_env, method, qs_loc_env, vectors, zij_fm_set, &
321 ispin, print_loc_section)
322 TYPE(qs_environment_type), POINTER :: qs_env
323 INTEGER, INTENT(IN) :: method
324 TYPE(qs_loc_env_type), POINTER :: qs_loc_env
325 TYPE(cp_fm_type), INTENT(IN) :: vectors
326 TYPE(cp_fm_type), DIMENSION(:, :), INTENT(IN) :: zij_fm_set
327 INTEGER, INTENT(IN) :: ispin
328 TYPE(section_vals_type), POINTER :: print_loc_section
329
330 CHARACTER(len=*), PARAMETER :: routinen = 'optimize_loc_pipek'
331
332 INTEGER :: handle, iatom, isgf, ldz, nao, natom, &
333 ncol, nmoloc, output_unit, sweeps
334 INTEGER, ALLOCATABLE, DIMENSION(:) :: first_sgf, last_sgf, nsgf
335 TYPE(cp_fm_pool_p_type), DIMENSION(:), POINTER :: ao_ao_fm_pools
336 TYPE(cp_fm_type) :: opvec
337 TYPE(cp_fm_type), POINTER :: ov_fm
338 TYPE(cp_logger_type), POINTER :: logger
339 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
340 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
341 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
342
343 CALL timeset(routinen, handle)
344 logger => cp_get_default_logger()
345 output_unit = cp_print_key_unit_nr(logger, print_loc_section, "PROGRAM_RUN_INFO", &
346 extension=".locInfo")
347
348 NULLIFY (particle_set)
349 ! get rows and cols of the input
350 CALL cp_fm_get_info(vectors, nrow_global=nao, ncol_global=nmoloc)
351
352 ! replicate the input kind of matrix
353 CALL cp_fm_create(opvec, vectors%matrix_struct)
354 CALL cp_fm_set_all(opvec, 0.0_dp)
355
356 CALL get_qs_env(qs_env=qs_env, matrix_s=matrix_s, &
357 particle_set=particle_set, qs_kind_set=qs_kind_set)
358
359 natom = SIZE(particle_set, 1)
360 ALLOCATE (first_sgf(natom))
361 ALLOCATE (last_sgf(natom))
362 ALLOCATE (nsgf(natom))
363
364 ! construction of
365 CALL get_particle_set(particle_set, qs_kind_set, &
366 first_sgf=first_sgf, last_sgf=last_sgf, nsgf=nsgf)
367
368 ! Copy the overlap sparse matrix in a full matrix
369 CALL mpools_get(qs_env%mpools, ao_ao_fm_pools=ao_ao_fm_pools)
370 ALLOCATE (ov_fm)
371 CALL fm_pool_create_fm(ao_ao_fm_pools(1)%pool, ov_fm, name=" ")
372 CALL copy_dbcsr_to_fm(matrix_s(1)%matrix, ov_fm)
373
374 ! Compute zij here
375 DO iatom = 1, natom
376 CALL cp_fm_set_all(zij_fm_set(iatom, 1), 0.0_dp)
377 CALL cp_fm_get_info(zij_fm_set(iatom, 1), ncol_global=ldz)
378 isgf = first_sgf(iatom)
379 ncol = nsgf(iatom)
380
381 ! multiply fmxfm, using only part of the ao : Ct x S
382 CALL parallel_gemm('N', 'N', nao, nmoloc, nao, 1.0_dp, ov_fm, vectors, 0.0_dp, opvec, &
383 a_first_col=1, a_first_row=1, b_first_col=1, b_first_row=1)
384
385 CALL parallel_gemm('T', 'N', nmoloc, nmoloc, ncol, 0.5_dp, vectors, opvec, &
386 0.0_dp, zij_fm_set(iatom, 1), &
387 a_first_col=1, a_first_row=isgf, b_first_col=1, b_first_row=isgf)
388
389 CALL parallel_gemm('N', 'N', nao, nmoloc, ncol, 1.0_dp, ov_fm, vectors, 0.0_dp, opvec, &
390 a_first_col=isgf, a_first_row=1, b_first_col=1, b_first_row=isgf)
391
392 CALL parallel_gemm('T', 'N', nmoloc, nmoloc, nao, 0.5_dp, vectors, opvec, &
393 1.0_dp, zij_fm_set(iatom, 1), &
394 a_first_col=1, a_first_row=1, b_first_col=1, b_first_row=1)
395
396 END DO ! iatom
397
398 ! And now perform the optimization and rotate the orbitals
399 SELECT CASE (method)
400 CASE (do_loc_jacobi)
401 CALL jacobi_rotation_pipek(zij_fm_set, vectors, sweeps)
402 CASE (do_loc_gapo)
403 cpabort("GAPO and Pipek not implemented.")
404 CASE (do_loc_crazy)
405 cpabort("Crazy and Pipek not implemented.")
406 CASE (do_loc_l1_norm_sd)
407 cpabort("L1 norm and Pipek not implemented.")
408 CASE (do_loc_direct)
409 cpabort("Direct and Pipek not implemented.")
410 CASE (do_loc_none)
411 IF (output_unit > 0) WRITE (output_unit, '(A,I6,A)') " No MOS localization applied "
412 CASE DEFAULT
413 cpabort("Unknown localization method")
414 END SELECT
415
416 IF (output_unit > 0) WRITE (output_unit, '(A,I3,A,I6,A)') " Localization for spin ", ispin, &
417 " converged in ", sweeps, " iterations"
418
419 CALL centers_spreads_pipek(qs_loc_env, zij_fm_set, particle_set, ispin, &
420 print_loc_section)
421
422 DEALLOCATE (first_sgf, last_sgf, nsgf)
423
424 CALL cp_fm_release(opvec)
425 CALL cp_print_key_finished_output(output_unit, logger, print_loc_section, "PROGRAM_RUN_INFO")
426
427 CALL timestop(handle)
428
429 END SUBROUTINE optimize_loc_pipek
430
431! **************************************************************************************************
432!> \brief 2by2 rotation for the pipek operator
433!> in this case the z_ij numbers are reals
434!> \param zij_fm_set ...
435!> \param vectors ...
436!> \param sweeps ...
437!> \par History
438!> 05-2005 created
439!> \author MI
440! **************************************************************************************************
441 SUBROUTINE jacobi_rotation_pipek(zij_fm_set, vectors, sweeps)
442
443 TYPE(cp_fm_type), DIMENSION(:, :), INTENT(IN) :: zij_fm_set
444 TYPE(cp_fm_type), INTENT(IN) :: vectors
445 INTEGER :: sweeps
446
447 INTEGER :: iatom, istate, jstate, natom, nstate
448 REAL(kind=dp) :: aij, bij, ct, mii, mij, mjj, ratio, st, &
449 theta, tolerance
450 TYPE(cp_fm_type) :: rmat
451
452 CALL cp_fm_create(rmat, zij_fm_set(1, 1)%matrix_struct)
453 CALL cp_fm_set_all(rmat, 0.0_dp, 1.0_dp)
454
455 CALL cp_fm_get_info(rmat, nrow_global=nstate)
456 tolerance = 1.0e10_dp
457 sweeps = 0
458 natom = SIZE(zij_fm_set, 1)
459 ! do jacobi sweeps until converged
460 DO WHILE (tolerance >= 1.0e-4_dp)
461 sweeps = sweeps + 1
462 DO istate = 1, nstate
463 DO jstate = istate + 1, nstate
464 aij = 0.0_dp
465 bij = 0.0_dp
466 DO iatom = 1, natom
467 CALL cp_fm_get_element(zij_fm_set(iatom, 1), istate, istate, mii)
468 CALL cp_fm_get_element(zij_fm_set(iatom, 1), istate, jstate, mij)
469 CALL cp_fm_get_element(zij_fm_set(iatom, 1), jstate, jstate, mjj)
470 aij = aij + mij*(mii - mjj)
471 bij = bij + mij*mij - 0.25_dp*(mii - mjj)*(mii - mjj)
472 END DO
473 IF (abs(bij) > 1.e-10_dp) THEN
474 ratio = -aij/bij
475 theta = 0.25_dp*atan(ratio)
476 ELSE
477 bij = 0.0_dp
478 theta = 0.0_dp
479 END IF
480 ! Check max or min
481 ! To minimize the spread
482 IF (theta > pi*0.5_dp) THEN
483 theta = theta - pi*0.25_dp
484 ELSE IF (theta < -pi*0.5_dp) THEN
485 theta = theta + pi*0.25_dp
486 END IF
487
488 ct = cos(theta)
489 st = sin(theta)
490
491 CALL cp_fm_rot_cols(rmat, istate, jstate, ct, st)
492
493 DO iatom = 1, natom
494 CALL cp_fm_rot_cols(zij_fm_set(iatom, 1), istate, jstate, ct, st)
495 CALL cp_fm_rot_rows(zij_fm_set(iatom, 1), istate, jstate, ct, st)
496 END DO
497 END DO
498 END DO
499 CALL check_tolerance_real(zij_fm_set, tolerance)
500 END DO
501
502 CALL rotate_orbitals(rmat, vectors)
503 CALL cp_fm_release(rmat)
504
505 END SUBROUTINE jacobi_rotation_pipek
506
507! **************************************************************************************************
508!> \brief ...
509!> \param zij_fm_set ...
510!> \param tolerance ...
511!> \par History
512!> 04.2005 created [MI]
513!> \author MI
514! **************************************************************************************************
515 SUBROUTINE check_tolerance_real(zij_fm_set, tolerance)
516
517 TYPE(cp_fm_type), DIMENSION(:, :), INTENT(IN) :: zij_fm_set
518 REAL(dp), INTENT(OUT) :: tolerance
519
520 INTEGER :: iatom, istate, jstate, natom, &
521 ncol_local, nrow_global, nrow_local
522 INTEGER, DIMENSION(:), POINTER :: col_indices, row_indices
523 REAL(dp) :: grad_ij, zii, zij, zjj
524 REAL(dp), DIMENSION(:, :), POINTER :: diag
525 TYPE(cp_fm_type) :: force
526
527 CALL cp_fm_create(force, zij_fm_set(1, 1)%matrix_struct)
528 CALL cp_fm_set_all(force, 0._dp)
529
530 NULLIFY (diag, col_indices, row_indices)
531 natom = SIZE(zij_fm_set, 1)
532 CALL cp_fm_get_info(zij_fm_set(1, 1), nrow_local=nrow_local, &
533 ncol_local=ncol_local, nrow_global=nrow_global, &
534 row_indices=row_indices, col_indices=col_indices)
535 ALLOCATE (diag(nrow_global, natom))
536
537 DO iatom = 1, natom
538 DO istate = 1, nrow_global
539 CALL cp_fm_get_element(zij_fm_set(iatom, 1), istate, istate, diag(istate, iatom))
540 END DO
541 END DO
542
543 DO istate = 1, nrow_local
544 DO jstate = 1, ncol_local
545 grad_ij = 0.0_dp
546 DO iatom = 1, natom
547 zii = diag(row_indices(istate), iatom)
548 zjj = diag(col_indices(jstate), iatom)
549 zij = zij_fm_set(iatom, 1)%local_data(istate, jstate)
550 grad_ij = grad_ij + 4.0_dp*zij*(zjj - zii)
551 END DO
552 force%local_data(istate, jstate) = grad_ij
553 END DO
554 END DO
555
556 DEALLOCATE (diag)
557
558 CALL cp_fm_maxabsval(force, tolerance)
559 CALL cp_fm_release(force)
560
561 END SUBROUTINE check_tolerance_real
562! **************************************************************************************************
563!> \brief ...
564!> \param qs_loc_env ...
565!> \param zij ...
566!> \param nmoloc ...
567!> \param cell ...
568!> \param weights ...
569!> \param ispin ...
570!> \param print_loc_section ...
571!> \param only_initial_out ...
572!> \par History
573!> 04.2005 created [MI]
574!> \author MI
575! **************************************************************************************************
576 SUBROUTINE centers_spreads_berry(qs_loc_env, zij, nmoloc, cell, weights, ispin, &
577 print_loc_section, only_initial_out)
578 TYPE(qs_loc_env_type), POINTER :: qs_loc_env
579 TYPE(cp_fm_type), DIMENSION(:, :), INTENT(IN) :: zij
580 INTEGER, INTENT(IN) :: nmoloc
581 TYPE(cell_type), POINTER :: cell
582 REAL(dp), DIMENSION(:) :: weights
583 INTEGER, INTENT(IN) :: ispin
584 TYPE(section_vals_type), POINTER :: print_loc_section
585 LOGICAL, INTENT(IN), OPTIONAL :: only_initial_out
586
587 CHARACTER(len=default_path_length) :: file_tmp, iter
588 COMPLEX(KIND=dp) :: z
589 INTEGER :: idir, istate, jdir, nstates, &
590 output_unit, unit_out_s
591 LOGICAL :: my_only_init
592 REAL(dp) :: avg_spread_ii, spread_i, spread_ii, &
593 sum_spread_i, sum_spread_ii
594 REAL(dp), DIMENSION(3) :: c, c2, cpbc
595 REAL(dp), DIMENSION(:, :), POINTER :: centers
596 REAL(kind=dp) :: imagpart, realpart
597 TYPE(cp_logger_type), POINTER :: logger
598 TYPE(section_vals_type), POINTER :: print_key
599
600 NULLIFY (centers, logger, print_key)
601 logger => cp_get_default_logger()
602 my_only_init = .false.
603 IF (PRESENT(only_initial_out)) my_only_init = only_initial_out
604
605 file_tmp = trim(qs_loc_env%tag_mo)//"_spreads_s"//trim(adjustl(cp_to_string(ispin)))
606 output_unit = cp_print_key_unit_nr(logger, print_loc_section, "PROGRAM_RUN_INFO", &
607 extension=".locInfo")
608 unit_out_s = cp_print_key_unit_nr(logger, print_loc_section, "WANNIER_SPREADS", &
609 middle_name=file_tmp, extension=".data")
610 iter = cp_iter_string(logger%iter_info)
611 IF (unit_out_s > 0 .AND. .NOT. my_only_init) WRITE (unit_out_s, '(i6,/,A)') nmoloc, trim(iter)
612
613 CALL cp_fm_get_info(zij(1, 1), nrow_global=nstates)
614 cpassert(nstates >= nmoloc)
615
616 centers => qs_loc_env%localized_wfn_control%centers_set(ispin)%array
617 cpassert(ASSOCIATED(centers))
618 cpassert(SIZE(centers, 2) == nmoloc)
619 sum_spread_i = 0.0_dp
620 sum_spread_ii = 0.0_dp
621 avg_spread_ii = 0.0_dp
622 DO istate = 1, nmoloc
623 c = 0.0_dp
624 c2 = 0.0_dp
625 spread_i = 0.0_dp
626 spread_ii = 0.0_dp
627 DO jdir = 1, SIZE(zij, 2)
628 CALL cp_fm_get_element(zij(1, jdir), istate, istate, realpart)
629 CALL cp_fm_get_element(zij(2, jdir), istate, istate, imagpart)
630 z = cmplx(realpart, imagpart, dp)
631 spread_i = spread_i - weights(jdir)* &
632 log(realpart*realpart + imagpart*imagpart)/twopi/twopi
633 spread_ii = spread_ii + weights(jdir)* &
634 (1.0_dp - (realpart*realpart + imagpart*imagpart))/twopi/twopi
635 IF (jdir < 4) THEN
636 DO idir = 1, 3
637 c(idir) = c(idir) + &
638 (cell%hmat(idir, jdir)/twopi)*aimag(log(z))
639 END DO
640 END IF
641 END DO
642 cpbc = pbc(c, cell)
643 centers(1:3, istate) = cpbc(1:3)
644 centers(4, istate) = spread_i
645 centers(5, istate) = spread_ii
646 sum_spread_i = sum_spread_i + centers(4, istate)
647 sum_spread_ii = sum_spread_ii + centers(5, istate)
648 IF (unit_out_s > 0 .AND. .NOT. my_only_init) WRITE (unit_out_s, '(I6,2F16.8)') istate, centers(4:5, istate)
649 END DO
650 avg_spread_ii = sum_spread_ii/real(nmoloc, kind=dp)
651
652 ! Print of wannier centers
653 print_key => section_vals_get_subs_vals(print_loc_section, "WANNIER_CENTERS")
654 IF (.NOT. my_only_init) CALL print_wannier_centers(qs_loc_env, print_key, centers, logger, ispin)
655
656 IF (output_unit > 0) THEN
657 WRITE (output_unit, '(T4, A, 2x, 2A26,/,T23, A28)') " Spread Functional ", "sum_in -w_i ln(|z_in|^2)", &
658 "sum_in w_i(1-|z_in|^2)", "sum_in w_i(1-|z_in|^2)/n"
659 IF (my_only_init) THEN
660 WRITE (output_unit, '(T4,A,T38,2F20.10,/,T38,F20.10)') " Initial Spread (Berry) : ", &
661 sum_spread_i, sum_spread_ii, avg_spread_ii
662 ELSE
663 WRITE (output_unit, '(T4,A,T38,2F20.10,/,T38,F20.10)') " Total Spread (Berry) : ", &
664 sum_spread_i, sum_spread_ii, avg_spread_ii
665 END IF
666 END IF
667
668 IF (unit_out_s > 0 .AND. .NOT. my_only_init) WRITE (unit_out_s, '(A,2F16.10)') " Total ", sum_spread_i, sum_spread_ii
669
670 CALL cp_print_key_finished_output(unit_out_s, logger, print_loc_section, "WANNIER_SPREADS")
671 CALL cp_print_key_finished_output(output_unit, logger, print_loc_section, "PROGRAM_RUN_INFO")
672
673 END SUBROUTINE centers_spreads_berry
674
675! **************************************************************************************************
676!> \brief define and print the centers and spread
677!> when the pipek operator is used
678!> \param qs_loc_env ...
679!> \param zij_fm_set matrix elements that define the populations on atoms
680!> \param particle_set ...
681!> \param ispin spin 1 or 2
682!> \param print_loc_section ...
683!> \par History
684!> 05.2005 created [MI]
685! **************************************************************************************************
686 SUBROUTINE centers_spreads_pipek(qs_loc_env, zij_fm_set, particle_set, ispin, &
687 print_loc_section)
688
689 TYPE(qs_loc_env_type), POINTER :: qs_loc_env
690 TYPE(cp_fm_type), DIMENSION(:, :), INTENT(IN) :: zij_fm_set
691 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
692 INTEGER, INTENT(IN) :: ispin
693 TYPE(section_vals_type), POINTER :: print_loc_section
694
695 CHARACTER(len=default_path_length) :: file_tmp, iter
696 INTEGER :: iatom, istate, natom, nstate, unit_out_s
697 INTEGER, DIMENSION(:), POINTER :: atom_of_state
698 REAL(dp) :: r(3)
699 REAL(dp), ALLOCATABLE, DIMENSION(:) :: qii, ziimax
700 REAL(dp), ALLOCATABLE, DIMENSION(:, :) :: diag
701 REAL(dp), DIMENSION(:, :), POINTER :: centers
702 TYPE(cp_logger_type), POINTER :: logger
703 TYPE(section_vals_type), POINTER :: print_key
704
705 NULLIFY (centers, logger, print_key)
706 logger => cp_get_default_logger()
707
708 CALL cp_fm_get_info(zij_fm_set(1, 1), nrow_global=nstate)
709 natom = SIZE(zij_fm_set, 1)
710
711 centers => qs_loc_env%localized_wfn_control%centers_set(ispin)%array
712 cpassert(ASSOCIATED(centers))
713 cpassert(SIZE(centers, 2) == nstate)
714
715 file_tmp = trim(qs_loc_env%tag_mo)//"_spreads_s"//trim(adjustl(cp_to_string(ispin)))
716 unit_out_s = cp_print_key_unit_nr(logger, print_loc_section, "WANNIER_SPREADS", &
717 middle_name=file_tmp, extension=".data", log_filename=.false.)
718 iter = cp_iter_string(logger%iter_info)
719 IF (unit_out_s > 0) WRITE (unit_out_s, '(i6,/,A)') trim(iter)
720
721 ALLOCATE (atom_of_state(nstate))
722 atom_of_state = 0
723
724 ALLOCATE (diag(nstate, natom))
725 diag = 0.0_dp
726
727 DO iatom = 1, natom
728 DO istate = 1, nstate
729 CALL cp_fm_get_element(zij_fm_set(iatom, 1), istate, istate, diag(istate, iatom))
730 END DO
731 END DO
732
733 ALLOCATE (qii(nstate), ziimax(nstate))
734 ziimax = 0.0_dp
735 qii = 0.0_dp
736
737 DO iatom = 1, natom
738 DO istate = 1, nstate
739 qii(istate) = qii(istate) + diag(istate, iatom)*diag(istate, iatom)
740 IF (abs(diag(istate, iatom)) > ziimax(istate)) THEN
741 ziimax(istate) = abs(diag(istate, iatom))
742 atom_of_state(istate) = iatom
743 END IF
744 END DO
745 END DO
746
747 DO istate = 1, nstate
748 iatom = atom_of_state(istate)
749 r(1:3) = particle_set(iatom)%r(1:3)
750 centers(1:3, istate) = r(1:3)
751 centers(4, istate) = 1.0_dp/qii(istate)
752 IF (unit_out_s > 0) WRITE (unit_out_s, '(I6,F16.8)') istate, angstrom*centers(4, istate)
753 END DO
754
755 ! Print the wannier centers
756 print_key => section_vals_get_subs_vals(print_loc_section, "WANNIER_CENTERS")
757 CALL print_wannier_centers(qs_loc_env, print_key, centers, logger, ispin)
758
759 CALL cp_print_key_finished_output(unit_out_s, logger, print_loc_section, "WANNIER_SPREADS")
760
761 DEALLOCATE (qii, ziimax, atom_of_state, diag)
762
763 END SUBROUTINE centers_spreads_pipek
764
765! **************************************************************************************************
766!> \brief write the cube files for a set of selected states
767!> \param qs_env ...
768!> \param mo_coeff set mos from which the states to be printed are extracted
769!> \param nstates number of states to be printed
770!> \param state_list list of the indexes of the states to be printed
771!> \param centers centers and spread, all=0 if they hva not been calculated
772!> \param print_key ...
773!> \param root initial part of the cube file names
774!> \param ispin ...
775!> \param idir ...
776!> \param state0 ...
777!> \param file_position ...
778!> \par History
779!> 08.2005 created [MI]
780!> \author MI
781!> \note
782!> This routine should not be in this module
783! **************************************************************************************************
784 SUBROUTINE qs_print_cubes(qs_env, mo_coeff, nstates, state_list, centers, &
785 print_key, root, ispin, idir, state0, file_position)
786
787 TYPE(qs_environment_type), POINTER :: qs_env
788 TYPE(cp_fm_type), INTENT(IN) :: mo_coeff
789 INTEGER, INTENT(IN) :: nstates
790 INTEGER, DIMENSION(:), POINTER :: state_list
791 REAL(dp), DIMENSION(:, :), POINTER :: centers
792 TYPE(section_vals_type), POINTER :: print_key
793 CHARACTER(LEN=*) :: root
794 INTEGER, INTENT(IN), OPTIONAL :: ispin, idir
795 INTEGER, OPTIONAL :: state0
796 CHARACTER(LEN=default_string_length), OPTIONAL :: file_position
797
798 CHARACTER(len=*), PARAMETER :: routinen = 'qs_print_cubes'
799 CHARACTER, DIMENSION(3), PARAMETER :: labels = (/'x', 'y', 'z'/)
800
801 CHARACTER :: label
802 CHARACTER(LEN=default_path_length) :: file_tmp, filename, my_pos
803 CHARACTER(LEN=default_string_length) :: title
804 INTEGER :: handle, ia, ie, istate, ivector, &
805 my_ispin, my_state0, unit_out_c
806 LOGICAL :: add_idir, add_spin, mpi_io
807 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
808 TYPE(cell_type), POINTER :: cell
809 TYPE(cp_logger_type), POINTER :: logger
810 TYPE(dft_control_type), POINTER :: dft_control
811 TYPE(particle_list_type), POINTER :: particles
812 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
813 TYPE(pw_c1d_gs_type) :: wf_g
814 TYPE(pw_env_type), POINTER :: pw_env
815 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
816 TYPE(pw_r3d_rs_type) :: wf_r
817 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
818 TYPE(qs_subsys_type), POINTER :: subsys
819
820 CALL timeset(routinen, handle)
821 NULLIFY (auxbas_pw_pool, pw_env, logger)
822 logger => cp_get_default_logger()
823
824 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env, subsys=subsys)
825 CALL qs_subsys_get(subsys, particles=particles)
826
827 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
828
829 CALL auxbas_pw_pool%create_pw(wf_r)
830 CALL auxbas_pw_pool%create_pw(wf_g)
831
832 my_state0 = 0
833 IF (PRESENT(state0)) my_state0 = state0
834
835 add_spin = .false.
836 my_ispin = 1
837 IF (PRESENT(ispin)) THEN
838 add_spin = .true.
839 my_ispin = ispin
840 END IF
841 add_idir = .false.
842 IF (PRESENT(idir)) THEN
843 add_idir = .true.
844 label = labels(idir)
845 END IF
846
847 my_pos = "REWIND"
848 IF (PRESENT(file_position)) THEN
849 my_pos = file_position
850 END IF
851
852 DO istate = 1, nstates
853 ivector = state_list(istate) - my_state0
854 CALL get_qs_env(qs_env=qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, cell=cell, &
855 dft_control=dft_control, particle_set=particle_set, pw_env=pw_env)
856
857 CALL calculate_wavefunction(mo_coeff, ivector, wf_r, wf_g, atomic_kind_set, &
858 qs_kind_set, cell, dft_control, particle_set, pw_env)
859
860 ! Formatting the middle part of the name
861 ivector = state_list(istate)
862 CALL xstring(root, ia, ie)
863 IF (add_idir) THEN
864 filename = root(ia:ie)//"_"//label//"_w"//trim(adjustl(cp_to_string(ivector)))
865 ELSE
866 filename = root(ia:ie)//"_w"//trim(adjustl(cp_to_string(ivector)))
867 END IF
868 IF (add_spin) THEN
869 file_tmp = filename
870 CALL xstring(file_tmp, ia, ie)
871 filename = file_tmp(ia:ie)//"_s"//trim(adjustl(cp_to_string(ispin)))
872 END IF
873
874 ! Using the print_key tools to open the file with the proper name
875 mpi_io = .true.
876 unit_out_c = cp_print_key_unit_nr(logger, print_key, "", middle_name=filename, &
877 extension=".cube", file_position=my_pos, log_filename=.false., &
878 mpi_io=mpi_io)
879 IF (SIZE(centers, 1) == 6) THEN
880 WRITE (title, '(A7,I5.5,A2,I1.1,A1,6F10.4)') "WFN ", ivector, "_s", my_ispin, " ", &
881 centers(1:3, istate)*angstrom, centers(4:6, istate)*angstrom
882 ELSE
883 WRITE (title, '(A7,I5.5,A2,I1.1,A1,3F10.4)') "WFN ", ivector, "_s", my_ispin, " ", &
884 centers(1:3, istate)*angstrom
885 END IF
886 CALL cp_pw_to_cube(wf_r, unit_out_c, title, &
887 particles=particles, &
888 stride=section_get_ivals(print_key, "STRIDE"), mpi_io=mpi_io)
889 CALL cp_print_key_finished_output(unit_out_c, logger, print_key, "", mpi_io=mpi_io)
890 END DO
891
892 CALL auxbas_pw_pool%give_back_pw(wf_r)
893 CALL auxbas_pw_pool%give_back_pw(wf_g)
894 CALL timestop(handle)
895 END SUBROUTINE qs_print_cubes
896
897! **************************************************************************************************
898!> \brief Prints wannier centers
899!> \param qs_loc_env ...
900!> \param print_key ...
901!> \param center ...
902!> \param logger ...
903!> \param ispin ...
904! **************************************************************************************************
905 SUBROUTINE print_wannier_centers(qs_loc_env, print_key, center, logger, ispin)
906 TYPE(qs_loc_env_type), POINTER :: qs_loc_env
907 TYPE(section_vals_type), POINTER :: print_key
908 REAL(kind=dp), INTENT(IN) :: center(:, :)
909 TYPE(cp_logger_type), POINTER :: logger
910 INTEGER, INTENT(IN) :: ispin
911
912 CHARACTER(default_string_length) :: iter, unit_str
913 CHARACTER(LEN=default_string_length) :: my_ext, my_form
914 INTEGER :: iunit, l, nstates
915 LOGICAL :: first_time, init_traj
916 REAL(kind=dp) :: unit_conv
917
918 nstates = SIZE(center, 2)
919 my_form = "formatted"
920 my_ext = ".data"
921 IF (btest(cp_print_key_should_output(logger%iter_info, print_key, first_time=first_time) &
922 , cp_p_file)) THEN
923 ! Find out if we want to print IONS+CENTERS or ONLY CENTERS..
924 IF (btest(cp_print_key_should_output(logger%iter_info, print_key, "/IONS+CENTERS") &
925 , cp_p_file)) THEN
926 CALL get_output_format(print_key, my_form=my_form, my_ext=my_ext)
927 END IF
928 IF (first_time .OR. (.NOT. qs_loc_env%first_time)) THEN
929 iunit = cp_print_key_unit_nr(logger, print_key, "", extension=my_ext, file_form=my_form, &
930 middle_name=trim(qs_loc_env%tag_mo)//"_centers_s"//trim(adjustl(cp_to_string(ispin))), &
931 log_filename=.false., on_file=.true., is_new_file=init_traj)
932 IF (iunit > 0) THEN
933 ! Gather units of measure for output (if available)
934 CALL section_vals_val_get(print_key, "UNIT", c_val=unit_str)
935 unit_conv = cp_unit_from_cp2k(1.0_dp, trim(unit_str))
936
937 IF (btest(cp_print_key_should_output(logger%iter_info, print_key, "/IONS+CENTERS"), cp_p_file)) THEN
938 ! Different possible formats
939 CALL print_wannier_traj(qs_loc_env, print_key, center, iunit, init_traj, unit_conv)
940 ELSE
941 ! Default print format
942 iter = cp_iter_string(logger%iter_info)
943 WRITE (iunit, '(i6,/,a)') nstates, trim(iter)
944 DO l = 1, nstates
945 WRITE (iunit, '(A,4F16.8)') "X", unit_conv*center(1:4, l)
946 END DO
947 END IF
948 END IF
949 CALL cp_print_key_finished_output(iunit, logger, print_key, on_file=.true.)
950 END IF
951 END IF
952 END SUBROUTINE print_wannier_centers
953
954! **************************************************************************************************
955!> \brief computes spread and centers
956!> \param qs_loc_env ...
957!> \param print_key ...
958!> \param center ...
959!> \param iunit ...
960!> \param init_traj ...
961!> \param unit_conv ...
962! **************************************************************************************************
963 SUBROUTINE print_wannier_traj(qs_loc_env, print_key, center, iunit, init_traj, unit_conv)
964 TYPE(qs_loc_env_type), POINTER :: qs_loc_env
965 TYPE(section_vals_type), POINTER :: print_key
966 REAL(kind=dp), INTENT(IN) :: center(:, :)
967 INTEGER, INTENT(IN) :: iunit
968 LOGICAL, INTENT(IN) :: init_traj
969 REAL(kind=dp), INTENT(IN) :: unit_conv
970
971 CHARACTER(len=default_string_length) :: iter, remark1, remark2, title
972 INTEGER :: i, iskip, natom, ntot, outformat
973 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
974 TYPE(atomic_kind_type), POINTER :: atomic_kind
975 TYPE(cp_logger_type), POINTER :: logger
976 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
977
978 NULLIFY (particle_set, atomic_kind_set, atomic_kind, logger)
979 logger => cp_get_default_logger()
980 natom = SIZE(qs_loc_env%particle_set)
981 ntot = natom + SIZE(center, 2)
982 CALL allocate_particle_set(particle_set, ntot)
983 ALLOCATE (atomic_kind_set(1))
984 atomic_kind => atomic_kind_set(1)
985 CALL set_atomic_kind(atomic_kind=atomic_kind, kind_number=0, &
986 name="X", element_symbol="X", mass=0.0_dp)
987 ! Particles
988 DO i = 1, natom
989 particle_set(i)%atomic_kind => qs_loc_env%particle_set(i)%atomic_kind
990 particle_set(i)%r = pbc(qs_loc_env%particle_set(i)%r, qs_loc_env%cell)
991 END DO
992 ! Wannier Centers
993 DO i = natom + 1, ntot
994 particle_set(i)%atomic_kind => atomic_kind
995 particle_set(i)%r = pbc(center(1:3, i - natom), qs_loc_env%cell)
996 END DO
997 ! Dump the structure
998 CALL section_vals_val_get(print_key, "FORMAT", i_val=outformat)
999
1000 ! Header file
1001 SELECT CASE (outformat)
1003 IF (init_traj) THEN
1004 !Lets write the header for the coordinate dcd
1005 ! Note (TL) : even the new DCD format is unfortunately too poor
1006 ! for our capabilities.. for example here the printing
1007 ! of the geometry could be nested inside several iteration
1008 ! levels.. this cannot be exactly reproduce with DCD.
1009 ! Just as a compromise let's pick-up the value of the MD iteration
1010 ! level. In any case this is not any sensible information for the standard..
1011 iskip = section_get_ival(print_key, "EACH%MD")
1012 WRITE (iunit) "CORD", 0, -1, iskip, &
1013 0, 0, 0, 0, 0, 0, real(0, kind=sp), 1, 0, 0, 0, 0, 0, 0, 0, 0, 24
1014 remark1 = "REMARK FILETYPE CORD DCD GENERATED BY CP2K"
1015 remark2 = "REMARK Support new DCD format with cell information"
1016 WRITE (iunit) 2, remark1, remark2
1017 WRITE (iunit) ntot
1018 CALL m_flush(iunit)
1019 END IF
1020 CASE (dump_xmol)
1021 iter = cp_iter_string(logger%iter_info)
1022 WRITE (unit=title, fmt="(A)") " Particles+Wannier centers. Iteration:"//trim(iter)
1023 CASE DEFAULT
1024 title = ""
1025 END SELECT
1026 CALL write_particle_coordinates(particle_set, iunit, outformat, "POS", title, qs_loc_env%cell, &
1027 unit_conv=unit_conv)
1028 CALL m_flush(iunit)
1029 CALL deallocate_particle_set(particle_set)
1030 CALL deallocate_atomic_kind_set(atomic_kind_set)
1031 END SUBROUTINE print_wannier_traj
1032
1033! **************************************************************************************************
1034!> \brief Compute the second moments of the centers using the local (non-periodic) pos operators
1035!> \param qs_env ...
1036!> \param qs_loc_env ...
1037!> \param print_loc_section ...
1038!> \param ispin ...
1039!> \par History
1040!> 07.2020 created [H. Elgabarty]
1041!> \author Hossam Elgabarty
1042! **************************************************************************************************
1043 SUBROUTINE centers_second_moments_loc(qs_env, qs_loc_env, print_loc_section, ispin)
1044
1045 ! I might not actually need the qs_env
1046 TYPE(qs_environment_type), POINTER :: qs_env
1047 TYPE(qs_loc_env_type), POINTER :: qs_loc_env
1048 TYPE(section_vals_type), POINTER :: print_loc_section
1049 INTEGER, INTENT(IN) :: ispin
1050
1051 INTEGER, PARAMETER :: norder = 2
1052 LOGICAL, PARAMETER :: debug_this_subroutine = .false.
1053
1054 CHARACTER(len=default_path_length) :: file_tmp
1055 INTEGER :: imoment, istate, ncol_global, nm, &
1056 nmoloc, nrow_global, output_unit, &
1057 output_unit_sm
1058 REAL(dp), DIMENSION(:, :), POINTER :: centers
1059 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: moment_set
1060 REAL(kind=dp), DIMENSION(3) :: rcc
1061 REAL(kind=dp), DIMENSION(6) :: cov
1062 TYPE(cp_fm_struct_type), POINTER :: fm_struct
1063 TYPE(cp_fm_type) :: momv, mvector, omvector
1064 TYPE(cp_fm_type), DIMENSION(:), POINTER :: moloc_coeff
1065 TYPE(cp_fm_type), POINTER :: mo_localized
1066 TYPE(cp_logger_type), POINTER :: logger
1067 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s, moments
1068 TYPE(mp_para_env_type), POINTER :: para_env
1069
1070 logger => cp_get_default_logger()
1071
1072 output_unit = cp_print_key_unit_nr(logger, print_loc_section, "PROGRAM_RUN_INFO", &
1073 extension=".locInfo")
1074
1075 IF (output_unit > 0) THEN
1076 WRITE (output_unit, '(/,T2,A)') &
1077 '!-----------------------------------------------------------------------------!'
1078 WRITE (output_unit, '(T12,A)') "Computing second moments of Wannier functions..."
1079 WRITE (output_unit, '(T2,A)') &
1080 '!-----------------------------------------------------------------------------!'
1081 END IF
1082
1083 file_tmp = "_r_loc_cov_matrix_"//trim(adjustl(cp_to_string(ispin)))
1084 output_unit_sm = cp_print_key_unit_nr(logger, print_loc_section, "WANNIER_SPREADS", &
1085 middle_name=file_tmp, extension=".data")
1086
1087 CALL get_qs_loc_env(qs_loc_env=qs_loc_env, moloc_coeff=moloc_coeff)
1088 centers => qs_loc_env%localized_wfn_control%centers_set(ispin)%array
1089
1090 CALL get_qs_env(qs_env, matrix_s=matrix_s)
1091
1092 nm = ncoset(norder) - 1
1093
1094 !CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set, cell=cell)
1095 !particle_set => qs_loc_env%particle_set
1096 para_env => qs_loc_env%para_env
1097
1098 CALL cp_fm_get_info(moloc_coeff(ispin), ncol_global=nmoloc)
1099 ALLOCATE (moment_set(nm, nmoloc))
1100 moment_set = 0.0_dp
1101
1102 mo_localized => moloc_coeff(ispin)
1103
1104 DO istate = 1, nmoloc
1105 rcc = centers(1:3, istate)
1106 !rcc = 0.0_dp
1107
1108 ALLOCATE (moments(nm))
1109 DO imoment = 1, nm
1110 ALLOCATE (moments(imoment)%matrix)
1111 CALL dbcsr_copy(moments(imoment)%matrix, matrix_s(ispin)%matrix, 'MOM MAT')
1112 CALL dbcsr_set(moments(imoment)%matrix, 0.0_dp)
1113 END DO
1114 !
1115
1116 CALL build_local_moment_matrix(qs_env, moments, norder, rcc)
1117
1118 CALL cp_fm_get_info(mo_localized, ncol_global=ncol_global, nrow_global=nrow_global)
1119 CALL cp_fm_struct_create(fm_struct, nrow_global=nrow_global, ncol_global=1, &
1120 para_env=mo_localized%matrix_struct%para_env, &
1121 context=mo_localized%matrix_struct%context)
1122 CALL cp_fm_create(mvector, fm_struct, name="mvector")
1123 CALL cp_fm_create(omvector, fm_struct, name="omvector")
1124 CALL cp_fm_create(momv, fm_struct, name="omvector")
1125 CALL cp_fm_struct_release(fm_struct)
1126
1127 !cp_fm_to_fm_columns(msource, mtarget, ncol, source_start,target_start)
1128 CALL cp_fm_to_fm(mo_localized, mvector, 1, istate, 1)
1129
1130 DO imoment = 1, nm
1131 CALL cp_dbcsr_sm_fm_multiply(moments(imoment)%matrix, mvector, omvector, 1)
1132 CALL cp_fm_schur_product(mvector, omvector, momv)
1133 !moment_set(imoment, istate) = moment_set(imoment, istate) + SUM(momv%local_data)
1134 moment_set(imoment, istate) = sum(momv%local_data)
1135 END DO
1136 !
1137 CALL cp_fm_release(mvector)
1138 CALL cp_fm_release(omvector)
1139 CALL cp_fm_release(momv)
1140
1141 DO imoment = 1, nm
1142 CALL dbcsr_deallocate_matrix(moments(imoment)%matrix)
1143 END DO
1144 DEALLOCATE (moments)
1145 END DO
1146
1147 CALL para_env%sum(moment_set)
1148
1149 IF (output_unit_sm > 0) THEN
1150 WRITE (unit=output_unit_sm, fmt='(A,T13,A,I1)') "#", &
1151 "SECOND MOMENTS OF WANNIER CENTERS FOR SPIN ", ispin
1152 WRITE (unit=output_unit_sm, fmt='(A,T29,A2,5(14x,A2))') "#", "XX", "XY", "XZ", "YY", "YZ", "ZZ"
1153 DO istate = 1, nmoloc
1154 cov = 0.0_dp
1155 cov(1) = moment_set(4, istate) - moment_set(1, istate)*moment_set(1, istate)
1156 cov(2) = moment_set(5, istate) - moment_set(1, istate)*moment_set(2, istate)
1157 cov(3) = moment_set(6, istate) - moment_set(1, istate)*moment_set(3, istate)
1158 cov(4) = moment_set(7, istate) - moment_set(2, istate)*moment_set(2, istate)
1159 cov(5) = moment_set(8, istate) - moment_set(2, istate)*moment_set(3, istate)
1160 cov(6) = moment_set(9, istate) - moment_set(3, istate)*moment_set(3, istate)
1161 WRITE (unit=output_unit_sm, fmt='(T4,A,I6,6(T20,6F16.8))') "Center:", istate, cov(1:6)
1162 IF (debug_this_subroutine) THEN
1163 WRITE (unit=output_unit_sm, fmt='(T4,A,I5,9(T20,9F12.6))') "Center:", istate, moment_set(1:, istate)
1164 END IF
1165 END DO
1166 END IF
1167 CALL cp_print_key_finished_output(output_unit_sm, logger, print_loc_section, "WANNIER_SPREADS")
1168 CALL cp_print_key_finished_output(output_unit, logger, print_loc_section, "PROGRAM_RUN_INFO")
1169
1170 DEALLOCATE (moment_set)
1171
1172 END SUBROUTINE centers_second_moments_loc
1173
1174! **************************************************************************************************
1175!> \brief Compute the second moments of the centers using a periodic quadrupole operator
1176!> \brief c.f. Wheeler et al. PRB 100 245135 2019, and Kang et al. PRB 100 245134 2019
1177!> \brief The calculation is based on a Taylor expansion of the exp(i k_i r_i r_j k_j) operator to
1178!> \brief to first order in the cosine and the sine parts
1179!> \param qs_env ...
1180!> \param qs_loc_env ...
1181!> \param print_loc_section ...
1182!> \param ispin ...
1183!> \par History
1184!> 08.2020 created [H. Elgabarty]
1185!> \author Hossam Elgabarty
1186! **************************************************************************************************
1187 SUBROUTINE centers_second_moments_berry(qs_env, qs_loc_env, print_loc_section, ispin)
1188
1189 TYPE(qs_environment_type), POINTER :: qs_env
1190 TYPE(qs_loc_env_type), POINTER :: qs_loc_env
1191 TYPE(section_vals_type), POINTER :: print_loc_section
1192 INTEGER, INTENT(IN) :: ispin
1193
1194 INTEGER, PARAMETER :: taylor_order = 1
1195 LOGICAL, PARAMETER :: debug_this_subroutine = .false.
1196
1197 CHARACTER(len=default_path_length) :: file_tmp
1198 COMPLEX(KIND=dp) :: z
1199 INTEGER :: icov, imoment, istate, ncol_global, nm, &
1200 nmoloc, norder, nrow_global, &
1201 output_unit, output_unit_sm
1202 REAL(dp), DIMENSION(:, :), POINTER :: centers
1203 REAL(kind=dp) :: imagpart, lx, ly, lz, realpart
1204 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: moment_set
1205 REAL(kind=dp), DIMENSION(3) :: rcc
1206 REAL(kind=dp), DIMENSION(6) :: cov
1207 TYPE(cell_type), POINTER :: cell
1208 TYPE(cp_fm_struct_type), POINTER :: fm_struct
1209 TYPE(cp_fm_type) :: momv, mvector, omvector
1210 TYPE(cp_fm_type), DIMENSION(:), POINTER :: moloc_coeff
1211 TYPE(cp_fm_type), POINTER :: mo_localized
1212 TYPE(cp_logger_type), POINTER :: logger
1213 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s, moments
1214 TYPE(mp_para_env_type), POINTER :: para_env
1215
1216! two pointers, one to each spin channel's coeff. matrix (nao x nmoloc)
1217
1218 logger => cp_get_default_logger()
1219
1220 output_unit = cp_print_key_unit_nr(logger, print_loc_section, "PROGRAM_RUN_INFO", &
1221 extension=".locInfo")
1222
1223 IF (output_unit > 0) THEN
1224 WRITE (output_unit, '(/,T2,A)') &
1225 '!-----------------------------------------------------------------------------!'
1226 WRITE (output_unit, '(T12,A)') "Computing second moments of Wannier functions..."
1227 WRITE (output_unit, '(T2,A)') &
1228 '!-----------------------------------------------------------------------------!'
1229 END IF
1230
1231 file_tmp = "_r_berry_cov_matrix_"//trim(adjustl(cp_to_string(ispin)))
1232 output_unit_sm = cp_print_key_unit_nr(logger, print_loc_section, "WANNIER_SPREADS", &
1233 middle_name=file_tmp, extension=".data")
1234
1235 norder = 2*(2*taylor_order + 1)
1236 nm = (6 + 11*norder + 6*norder**2 + norder**3)/6 - 1
1237
1238 NULLIFY (cell)
1239 CALL get_qs_loc_env(qs_loc_env=qs_loc_env, moloc_coeff=moloc_coeff, cell=cell)
1240 lx = cell%hmat(1, 1)
1241 ly = cell%hmat(2, 2)
1242 lz = cell%hmat(3, 3)
1243
1244 centers => qs_loc_env%localized_wfn_control%centers_set(ispin)%array
1245
1246 para_env => qs_loc_env%para_env
1247
1248 CALL get_qs_env(qs_env, matrix_s=matrix_s)
1249
1250 CALL cp_fm_get_info(moloc_coeff(ispin), ncol_global=nmoloc)
1251
1252 ALLOCATE (moment_set(nm, nmoloc))
1253 moment_set = 0.0_dp
1254
1255 mo_localized => moloc_coeff(ispin)
1256
1257 DO istate = 1, nmoloc
1258 rcc = centers(1:3, istate)
1259 !rcc = 0.0_dp
1260
1261 ALLOCATE (moments(nm))
1262 DO imoment = 1, nm
1263 ALLOCATE (moments(imoment)%matrix)
1264 CALL dbcsr_copy(moments(imoment)%matrix, matrix_s(ispin)%matrix, 'MOM MAT')
1265 CALL dbcsr_set(moments(imoment)%matrix, 0.0_dp)
1266 END DO
1267 !
1268
1269 CALL build_local_moment_matrix(qs_env, moments, norder, rcc)
1270
1271 CALL cp_fm_get_info(mo_localized, ncol_global=ncol_global, nrow_global=nrow_global)
1272 CALL cp_fm_struct_create(fm_struct, nrow_global=nrow_global, ncol_global=1, &
1273 para_env=mo_localized%matrix_struct%para_env, &
1274 context=mo_localized%matrix_struct%context)
1275 CALL cp_fm_create(mvector, fm_struct, name="mvector")
1276 CALL cp_fm_create(omvector, fm_struct, name="omvector")
1277 CALL cp_fm_create(momv, fm_struct, name="omvector")
1278 CALL cp_fm_struct_release(fm_struct)
1279
1280 ! cp_fm_to_fm_columns(msource, mtarget, ncol, source_start,target_start)
1281 CALL cp_fm_to_fm(mo_localized, mvector, 1, istate, 1)
1282
1283 DO imoment = 1, nm
1284 CALL cp_dbcsr_sm_fm_multiply(moments(imoment)%matrix, mvector, omvector, 1)
1285 CALL cp_fm_schur_product(mvector, omvector, momv)
1286 moment_set(imoment, istate) = sum(momv%local_data)
1287 END DO
1288 !
1289 CALL cp_fm_release(mvector)
1290 CALL cp_fm_release(omvector)
1291 CALL cp_fm_release(momv)
1292
1293 DO imoment = 1, nm
1294 CALL dbcsr_deallocate_matrix(moments(imoment)%matrix)
1295 END DO
1296 DEALLOCATE (moments)
1297 END DO
1298
1299 CALL para_env%sum(moment_set)
1300
1301 IF (output_unit_sm > 0) THEN
1302 WRITE (unit=output_unit_sm, fmt='(A,T13,A,I1)') "#", &
1303 "SECOND MOMENTS OF WANNIER CENTERS FOR SPIN ", ispin
1304 WRITE (unit=output_unit_sm, fmt='(A,T29,A2,5(14x,A2))') "#", "XX", "XY", "XZ", "YY", "YZ", "ZZ"
1305 DO istate = 1, nmoloc
1306 cov = 0.0_dp
1307 DO icov = 1, 6
1308 realpart = 0.0_dp
1309 imagpart = 0.0_dp
1310 z = cmplx(realpart, imagpart, dp)
1311 SELECT CASE (icov)
1312
1313 !! XX
1314 CASE (1)
1315 realpart = 1.0 - 0.5*twopi*twopi/lx/lx/lx/lx &
1316 *moment_set(20, istate)
1317 imagpart = twopi/lx/lx*moment_set(4, istate) &
1318 - twopi*twopi*twopi/lx/lx/lx/lx/lx/lx/6.0*moment_set(56, istate)
1319
1320 ! third order
1321 !realpart = realpart + twopi*twopi*twopi*twopi/Lx/Lx/Lx/Lx/Lx/Lx/Lx/Lx/24.0 * moment_set(120, istate)
1322 !imagpart = imagpart + twopi*twopi*twopi*twopi*twopi/Lx/Lx/Lx/Lx/Lx/Lx/Lx/Lx/Lx/Lx/120 &
1323 ! * moment_set(220, istate)
1324
1325 z = cmplx(realpart, imagpart, dp)
1326 cov(1) = lx*lx/twopi*aimag(log(z)) - lx*lx/twopi/twopi*moment_set(1, istate)*moment_set(1, istate)
1327
1328 !! XY
1329 CASE (2)
1330 realpart = 1.0 - 0.5*twopi*twopi/lx/ly/lx/ly &
1331 *moment_set(23, istate)
1332 imagpart = twopi/lx/ly*moment_set(5, istate) &
1333 - twopi*twopi*twopi/lx/lx/lx/ly/ly/ly/6.0*moment_set(62, istate)
1334
1335 ! third order
1336 !realpart = realpart + twopi*twopi*twopi*twopi/Lx/Lx/Lx/Lx/Ly/Ly/Ly/Ly/24.0 * moment_set(130, istate)
1337 !imagpart = imagpart + twopi*twopi*twopi*twopi*twopi/Lx/Lx/Lx/Lx/Lx/Ly/Ly/Ly/Ly/Ly/120 &
1338 ! * moment_set(235, istate)
1339
1340 z = cmplx(realpart, imagpart, dp)
1341 cov(2) = lx*ly/twopi*aimag(log(z)) - lx*ly/twopi/twopi*moment_set(1, istate)*moment_set(2, istate)
1342
1343 !! XZ
1344 CASE (3)
1345 realpart = 1.0 - 0.5*twopi*twopi/lx/lz/lx/lz &
1346 *moment_set(25, istate)
1347 imagpart = twopi/lx/lz*moment_set(6, istate) &
1348 - twopi*twopi*twopi/lx/lx/lx/lz/lz/lz/6.0*moment_set(65, istate)
1349
1350 ! third order
1351 !realpart = realpart + twopi*twopi*twopi*twopi/Lx/Lx/Lx/Lx/Lz/Lz/Lz/Lz/24.0 * moment_set(134, istate)
1352 !imagpart = imagpart + twopi*twopi*twopi*twopi*twopi/Lx/Lx/Lx/Lx/Lx/Ly/Ly/Ly/Ly/Ly/120 &
1353 ! * moment_set(240, istate)
1354
1355 z = cmplx(realpart, imagpart, dp)
1356 cov(3) = lx*lz/twopi*aimag(log(z)) - lx*lz/twopi/twopi*moment_set(1, istate)*moment_set(3, istate)
1357
1358 !! YY
1359 CASE (4)
1360 realpart = 1.0 - 0.5*twopi*twopi/ly/ly/ly/ly &
1361 *moment_set(30, istate)
1362 imagpart = twopi/ly/ly*moment_set(7, istate) &
1363 - twopi*twopi*twopi/ly/ly/ly/ly/ly/ly/6.0*moment_set(77, istate)
1364
1365 ! third order
1366 !realpart = realpart + twopi*twopi*twopi*twopi/Ly/Ly/Ly/Ly/Ly/Ly/Ly/Ly/24.0 * moment_set(156, istate)
1367 !imagpart = imagpart + twopi*twopi*twopi*twopi*twopi/Ly/Ly/Ly/Ly/Ly/Ly/Ly/Ly/Ly/Ly/120 &
1368 ! * moment_set(275, istate)
1369
1370 z = cmplx(realpart, imagpart, dp)
1371 cov(4) = ly*ly/twopi*aimag(log(z)) - ly*ly/twopi/twopi*moment_set(2, istate)*moment_set(2, istate)
1372
1373 !! YZ
1374 CASE (5)
1375 realpart = 1.0 - 0.5*twopi*twopi/ly/lz/ly/lz &
1376 *moment_set(32, istate)
1377 imagpart = twopi/ly/lz*moment_set(8, istate) &
1378 - twopi*twopi*twopi/ly/ly/ly/lz/lz/lz/6.0*moment_set(80, istate)
1379
1380 ! third order
1381 !realpart = realpart + twopi*twopi*twopi*twopi/Lz/Lz/Lz/Lz/Ly/Ly/Ly/Ly/24.0 * moment_set(160, istate)
1382 !imagpart = imagpart + twopi*twopi*twopi*twopi*twopi/Lz/Lz/Lz/Lz/Lz/Ly/Ly/Ly/Ly/Ly/120 &
1383 ! * moment_set(280, istate)
1384
1385 z = cmplx(realpart, imagpart, dp)
1386 cov(5) = ly*lz/twopi*aimag(log(z)) - ly*lz/twopi/twopi*moment_set(2, istate)*moment_set(3, istate)
1387
1388 !! ZZ
1389 CASE (6)
1390 realpart = 1.0 - 0.5*twopi*twopi/lz/lz/lz/lz &
1391 *moment_set(34, istate)
1392 imagpart = twopi/lz/lz*moment_set(9, istate) &
1393 - twopi*twopi*twopi/lz/lz/lz/lz/lz/lz/6.0*moment_set(83, istate)
1394
1395 ! third order
1396 !realpart = realpart + twopi*twopi*twopi*twopi/Lz/Lz/Lz/Lz/Lz/Lz/Lz/Lz/24.0 * moment_set(164, istate)
1397 !imagpart = imagpart + twopi*twopi*twopi*twopi*twopi/Lz/Lz/Lz/Lz/Lz/Lz/Lz/Lz/Lz/Lz/120 &
1398 ! * moment_set(285, istate)
1399
1400 z = cmplx(realpart, imagpart, dp)
1401 cov(6) = lz*lz/twopi*aimag(log(z)) - lz*lz/twopi/twopi*moment_set(3, istate)*moment_set(3, istate)
1402
1403 END SELECT
1404 END DO
1405 WRITE (unit=output_unit_sm, fmt='(T4,A,I6,6(T20,6F16.8))') "Center:", istate, cov(1:6)
1406 IF (debug_this_subroutine) THEN
1407 WRITE (unit=output_unit_sm, fmt='(T4,A,I5,9(T20,9F12.6))') "Center:", istate, moment_set(1:, istate)
1408 END IF
1409 END DO
1410 END IF
1411 CALL cp_print_key_finished_output(output_unit_sm, logger, print_loc_section, "WANNIER_SPREADS")
1412 CALL cp_print_key_finished_output(output_unit, logger, print_loc_section, "PROGRAM_RUN_INFO")
1413
1414 DEALLOCATE (moment_set)
1415
1416 END SUBROUTINE centers_second_moments_berry
1417
1418END MODULE qs_loc_methods
Define the atomic kind types and their sub types.
subroutine, public set_atomic_kind(atomic_kind, element_symbol, name, mass, kind_number, natom, atom_list, fist_potential, shell, shell_active, damping)
Set the components of an atomic kind data set.
subroutine, public deallocate_atomic_kind_set(atomic_kind_set)
Destructor routine for a set of atomic kinds.
Handles all functions related to the CELL.
Definition cell_types.F:15
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_deallocate_matrix(matrix)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_set(matrix, alpha)
...
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.
basic linear algebra operations for full matrices
subroutine, public cp_fm_rot_rows(matrix, irow, jrow, cs, sn)
Applies a planar rotation defined by cs and sn to the i'th and j'th rows.
subroutine, public cp_fm_rot_cols(matrix, icol, jcol, cs, sn)
Applies a planar rotation defined by cs and sn to the i'th and j'th columnns.
subroutine, public cp_fm_schur_product(matrix_a, matrix_b, matrix_c)
computes the schur product of two matrices c_ij = a_ij * b_ij
pool for for elements that are retained and released
subroutine, public fm_pool_create_fm(pool, element, name)
returns an element, allocating it if none is in the pool
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
subroutine, public cp_fm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
subroutine, public cp_fm_get_element(matrix, irow_global, icol_global, alpha, local)
returns an element of a fm this value is valid on every cpu using this call is expensive
subroutine, public cp_fm_maxabsval(matrix, a_max, ir_max, ic_max)
find the maximum absolute value of the matrix element maxval(abs(matrix))
subroutine, public cp_fm_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp)
creates a new full matrix with the given structure
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...
character(len=default_string_length) function, public cp_iter_string(iter_info, print_key, for_file)
returns the iteration string, a string that is useful to create unique filenames (once you trim it)
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,...
integer, parameter, public cp_p_file
integer function, public cp_print_key_should_output(iteration_info, basis_section, print_key_path, used_print_key, first_time)
returns what should be done with the given property if btest(res,cp_p_store) then the property should...
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)
...
unit conversion facility
Definition cp_units.F:30
real(kind=dp) function, public cp_unit_from_cp2k(value, unit_str, defaults, power)
converts from the internal cp2k units to the given unit
Definition cp_units.F:1179
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_loc_jacobi
integer, parameter, public do_loc_l1_norm_sd
integer, parameter, public do_loc_none
integer, parameter, public dump_xmol
integer, parameter, public do_loc_scdm
integer, parameter, public do_loc_crazy
integer, parameter, public do_loc_gapo
integer, parameter, public dump_dcd_aligned_cell
integer, parameter, public dump_dcd
integer, parameter, public do_loc_direct
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)
...
integer function, public section_get_ival(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_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
integer, parameter, public default_path_length
Definition kinds.F:58
integer, parameter, public sp
Definition kinds.F:33
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:130
Definition of mathematical constants and functions.
real(kind=dp), parameter, public pi
real(kind=dp), parameter, public twopi
Interface to the message passing library MPI.
Output Utilities for MOTION_SECTION.
subroutine, public get_output_format(section, path, my_form, my_ext)
Info on the unit to be opened to dump MD informations.
Provides Cartesian and spherical orbital pointers and indices.
integer, dimension(:), allocatable, public ncoset
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.
subroutine, public write_particle_coordinates(particle_set, iunit, output_format, content, title, cell, array, unit_conv, charge_occup, charge_beta, charge_extended, print_kind)
Should be able to write a few formats e.g. xmol, and some binary format (dcd) some format can be used...
Define the data structure for the particle information.
subroutine, public deallocate_particle_set(particle_set)
Deallocate a particle set.
subroutine, public allocate_particle_set(particle_set, nparticle)
Allocate a particle set.
Definition of physical constants:
Definition physcon.F:68
real(kind=dp), parameter, public angstrom
Definition physcon.F:144
container for various plainwaves related things
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
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
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)
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_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.
Define the quickstep kind type and their sub types.
Driver for the localization that should be general for all the methods available and all the definiti...
subroutine, public optimize_loc_pipek(qs_env, method, qs_loc_env, vectors, zij_fm_set, ispin, print_loc_section)
...
subroutine, public centers_second_moments_berry(qs_env, qs_loc_env, print_loc_section, ispin)
Compute the second moments of the centers using a periodic quadrupole operator.
subroutine, public centers_second_moments_loc(qs_env, qs_loc_env, print_loc_section, ispin)
Compute the second moments of the centers using the local (non-periodic) pos operators.
subroutine, public optimize_loc_berry(method, qs_loc_env, vectors, op_sm_set, zij_fm_set, para_env, cell, weights, ispin, print_loc_section, restricted, nextra, nmo, vectors_2, guess_mos)
Calculate and optimize the spread functional as calculated from the selected mos and by the definitio...
subroutine, public centers_spreads_berry(qs_loc_env, zij, nmoloc, cell, weights, ispin, print_loc_section, only_initial_out)
...
subroutine, public qs_print_cubes(qs_env, mo_coeff, nstates, state_list, centers, print_key, root, ispin, idir, state0, file_position)
write the cube files for a set of selected states
subroutine, public jacobi_rotation_pipek(zij_fm_set, vectors, sweeps)
2by2 rotation for the pipek operator in this case the z_ij numbers are reals
New version of the module for the localization of the molecular orbitals This should be able to use d...
subroutine, public get_qs_loc_env(qs_loc_env, cell, local_molecules, localized_wfn_control, moloc_coeff, op_sm_set, op_fm_set, para_env, particle_set, weights, dim_op)
...
Localization methods such as 2x2 Jacobi rotations Steepest Decents Conjugate Gradient.
subroutine, public approx_l1_norm_sd(c, iterations, eps, converged, sweeps)
...
subroutine, public rotate_orbitals(rmat, vectors)
...
subroutine, public jacobi_rotations(weights, zij, vectors, para_env, max_iter, eps_localization, sweeps, out_each, target_time, start_time, restricted)
wrapper for the jacobi routines, should be removed if jacobi_rot_para can deal with serial para_envs.
subroutine, public zij_matrix(vectors, op_sm_set, zij_fm_set)
...
subroutine, public direct_mini(weights, zij, vectors, max_iter, eps_localization, iterations)
use the exponential parametrization as described in to perform a direct mini Gerd Berghold et al....
subroutine, public crazy_rotations(weights, zij, vectors, max_iter, max_crazy_angle, crazy_scale, crazy_use_diag, eps_localization, iterations, converged)
yet another crazy try, computes the angles needed to rotate the orbitals first and rotates them all a...
subroutine, public scdm_qrfact(vectors)
...
subroutine, public jacobi_cg_edf_ls(para_env, weights, zij, vectors, max_iter, eps_localization, iter, out_each, nextra, do_cg, nmo, vectors_2, mos_guess)
combine jacobi rotations (serial) and conjugate gradient with golden section line search for partiall...
wrapper for the pools of matrixes
subroutine, public mpools_get(mpools, ao_mo_fm_pools, ao_ao_fm_pools, mo_mo_fm_pools, ao_mosub_fm_pools, mosub_mosub_fm_pools, maxao_maxmo_fm_pool, maxao_maxao_fm_pool, maxmo_maxmo_fm_pool)
returns various attributes of the mpools (notably the pools contained in it)
Calculates the moment integrals <a|r^m|b> and <a|r x d/dr|b>
Definition qs_moments.F:14
subroutine, public build_local_moment_matrix(qs_env, moments, nmoments, ref_point, ref_points, basis_type)
...
Definition qs_moments.F:560
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)
...
Utilities for string manipulations.
elemental subroutine, public xstring(string, ia, ib)
...
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Definition cell_types.F:55
keeps the information about the structure of a full matrix
represent a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
stores all the informations relevant to an mpi environment
contained for different pw related things
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Provides all information about a quickstep kind.
contains all the info needed by quickstep to calculate the spread of a selected set of orbitals and i...