(git:1f1a7a2)
Loading...
Searching...
No Matches
qs_linres_methods.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief localize wavefunctions
10!> linear response scf
11!> \par History
12!> created 07-2005 [MI]
13!> \author MI
14! **************************************************************************************************
17 USE cp_dbcsr_api, ONLY: dbcsr_copy,&
19 dbcsr_set,&
24 USE cp_files, ONLY: close_file,&
31 USE cp_fm_types, ONLY: cp_fm_create,&
41 USE cp_output_handling, ONLY: cp_p_file,&
46 USE input_constants, ONLY: do_loc_none,&
54 USE kinds, ONLY: default_path_length,&
56 dp
57 USE machine, ONLY: m_flush,&
69 USE qs_loc_main, ONLY: qs_loc_driver
70 USE qs_loc_types, ONLY: get_qs_loc_env,&
77 USE qs_mo_types, ONLY: get_mo_set,&
83 USE qs_rho_types, ONLY: qs_rho_type
84 USE string_utilities, ONLY: xstring
85#include "./base/base_uses.f90"
86
87 IMPLICIT NONE
88
89 PRIVATE
90
91 ! *** Public subroutines ***
94 PUBLIC :: build_dm_response
95
96 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_linres_methods'
97
98! **************************************************************************************************
99
100CONTAINS
101
102! **************************************************************************************************
103!> \brief Find the centers and spreads of the wfn,
104!> if required apply a localization algorithm
105!> \param qs_env ...
106!> \param linres_control ...
107!> \param nspins ...
108!> \param centers_only ...
109!> \par History
110!> 07.2005 created [MI]
111!> \author MI
112! **************************************************************************************************
113 SUBROUTINE linres_localize(qs_env, linres_control, nspins, centers_only)
114
115 TYPE(qs_environment_type), POINTER :: qs_env
116 TYPE(linres_control_type), POINTER :: linres_control
117 INTEGER, INTENT(IN) :: nspins
118 LOGICAL, INTENT(IN), OPTIONAL :: centers_only
119
120 INTEGER :: iounit, ispin, istate, nmoloc(2)
121 LOGICAL :: my_centers_only
122 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: mos_localized
123 TYPE(cp_fm_type), POINTER :: mo_coeff
124 TYPE(cp_logger_type), POINTER :: logger
125 TYPE(localized_wfn_control_type), POINTER :: localized_wfn_control
126 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
127 TYPE(qs_loc_env_type), POINTER :: qs_loc_env
128 TYPE(section_vals_type), POINTER :: loc_print_section, loc_section, &
129 lr_section
130
131 NULLIFY (logger, lr_section, loc_section, loc_print_section, localized_wfn_control)
132 logger => cp_get_default_logger()
133 lr_section => section_vals_get_subs_vals(qs_env%input, "PROPERTIES%LINRES")
134 loc_section => section_vals_get_subs_vals(lr_section, "LOCALIZE")
135 loc_print_section => section_vals_get_subs_vals(lr_section, "LOCALIZE%PRINT")
136 iounit = cp_print_key_unit_nr(logger, lr_section, "PRINT%PROGRAM_RUN_INFO", &
137 extension=".linresLog")
138 my_centers_only = .false.
139 IF (PRESENT(centers_only)) my_centers_only = centers_only
140
141 NULLIFY (mos, mo_coeff, qs_loc_env)
142 CALL get_qs_env(qs_env=qs_env, mos=mos)
143 ALLOCATE (qs_loc_env)
144 CALL qs_loc_env_create(qs_loc_env)
145 linres_control%qs_loc_env => qs_loc_env
146 CALL qs_loc_control_init(qs_loc_env, loc_section, do_homo=.true.)
147 CALL get_qs_loc_env(qs_loc_env, localized_wfn_control=localized_wfn_control)
148
149 ALLOCATE (mos_localized(nspins))
150 DO ispin = 1, nspins
151 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff)
152 CALL cp_fm_create(mos_localized(ispin), mo_coeff%matrix_struct)
153 CALL cp_fm_to_fm(mo_coeff, mos_localized(ispin))
154 END DO
155
156 nmoloc(1:2) = 0
157 IF (my_centers_only) THEN
158 localized_wfn_control%set_of_states = state_loc_all
159 localized_wfn_control%localization_method = do_loc_none
160 localized_wfn_control%operator_type = op_loc_berry
161 END IF
162
163 CALL qs_loc_init(qs_env, qs_loc_env, loc_section, mos_localized=mos_localized, &
164 do_homo=.true.)
165
166 ! The orbital centers are stored in linres_control%localized_wfn_control
167 DO ispin = 1, nspins
168 CALL qs_loc_driver(qs_env, qs_loc_env, loc_print_section, myspin=ispin, &
169 ext_mo_coeff=mos_localized(ispin))
170 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff)
171 CALL cp_fm_to_fm(mos_localized(ispin), mo_coeff)
172 END DO
173
174 CALL loc_write_restart(qs_loc_env, loc_print_section, mos, &
175 mos_localized, do_homo=.true.)
176 CALL cp_fm_release(mos_localized)
177
178 ! Write Centers and Spreads on std out
179 IF (iounit > 0) THEN
180 DO ispin = 1, nspins
181 WRITE (iounit, "(/,T2,A,I2)") &
182 "WANNIER CENTERS for spin ", ispin
183 WRITE (iounit, "(/,T18,A,3X,A)") &
184 "--------------- Centers --------------- ", &
185 "--- Spreads ---"
186 DO istate = 1, SIZE(localized_wfn_control%centers_set(ispin)%array, 2)
187 WRITE (iounit, "(T5,A6,I6,2X,3f12.6,5X,f12.6)") &
188 'state ', istate, localized_wfn_control%centers_set(ispin)%array(1:3, istate), &
189 localized_wfn_control%centers_set(ispin)%array(4, istate)
190 END DO
191 END DO
192 CALL m_flush(iounit)
193 END IF
194
195 END SUBROUTINE linres_localize
196
197! **************************************************************************************************
198!> \brief scf loop to optimize the first order wavefunctions (psi1)
199!> given a perturbation as an operator applied to the ground
200!> state orbitals (h1_psi0)
201!> psi1 is defined wrt psi0_order (can be a subset of the occupied space)
202!> The reference ground state is defined through qs_env (density and ground state MOs)
203!> psi1 is orthogonal to the occupied orbitals in the ground state MO set (qs_env%mos)
204!> \param p_env ...
205!> \param qs_env ...
206!> \param psi1 ...
207!> \param h1_psi0 ...
208!> \param psi0_order ...
209!> \param iounit ...
210!> \param should_stop ...
211!> \param silent ...
212!> \par History
213!> 07.2005 created [MI]
214!> \author MI
215! **************************************************************************************************
216 SUBROUTINE linres_solver(p_env, qs_env, psi1, h1_psi0, psi0_order, iounit, &
217 should_stop, silent)
218 TYPE(qs_p_env_type) :: p_env
219 TYPE(qs_environment_type), POINTER :: qs_env
220 TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: psi1, h1_psi0, psi0_order
221 INTEGER, INTENT(IN) :: iounit
222 LOGICAL, INTENT(OUT) :: should_stop
223 LOGICAL, INTENT(IN), OPTIONAL :: silent
224
225 CHARACTER(LEN=*), PARAMETER :: routinen = 'linres_solver'
226
227 INTEGER :: handle, ispin, iter, maxnmo, nao, ncol, &
228 nmo, nocc, nspins
229 LOGICAL :: my_silent, restart
230 REAL(dp) :: alpha, beta, norm_res, t1, t2
231 REAL(dp), DIMENSION(:), POINTER :: tr_pap, tr_rz0, tr_rz00, tr_rz1
232 TYPE(cp_fm_struct_type), POINTER :: tmp_fm_struct
233 TYPE(cp_fm_type) :: buf
234 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: ap, chc, mo_coeff_array, p, r, z
235 TYPE(cp_fm_type), DIMENSION(:), POINTER :: sc
236 TYPE(cp_fm_type), POINTER :: mo_coeff
237 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks, matrix_s, matrix_t
238 TYPE(dbcsr_type), POINTER :: matrix_x
239 TYPE(dft_control_type), POINTER :: dft_control
240 TYPE(linres_control_type), POINTER :: linres_control
241 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
242 TYPE(mp_para_env_type), POINTER :: para_env
243
244 CALL timeset(routinen, handle)
245
246 my_silent = .false.
247 IF (PRESENT(silent)) my_silent = silent
248
249 NULLIFY (dft_control, linres_control, matrix_s, matrix_t, matrix_ks, para_env)
250 NULLIFY (mos, tmp_fm_struct, mo_coeff)
251
252 t1 = m_walltime()
253
254 CALL get_qs_env(qs_env=qs_env, &
255 matrix_ks=matrix_ks, &
256 matrix_s=matrix_s, &
257 kinetic=matrix_t, &
258 dft_control=dft_control, &
259 linres_control=linres_control, &
260 para_env=para_env, &
261 mos=mos)
262
263 nspins = dft_control%nspins
264 CALL cp_fm_get_info(psi1(1), nrow_global=nao)
265 maxnmo = 0
266 DO ispin = 1, nspins
267 CALL cp_fm_get_info(psi1(ispin), ncol_global=ncol)
268 maxnmo = max(maxnmo, ncol)
269 END DO
270 !
271 CALL check_p_env_init(p_env, linres_control, nspins)
272 !
273 ! allocate the vectors
274 ALLOCATE (tr_pap(nspins), tr_rz0(nspins), tr_rz00(nspins), tr_rz1(nspins), &
275 r(nspins), p(nspins), z(nspins), ap(nspins))
276 !
277 DO ispin = 1, nspins
278 CALL cp_fm_create(r(ispin), psi1(ispin)%matrix_struct)
279 CALL cp_fm_create(p(ispin), psi1(ispin)%matrix_struct)
280 CALL cp_fm_create(z(ispin), psi1(ispin)%matrix_struct)
281 CALL cp_fm_create(ap(ispin), psi1(ispin)%matrix_struct)
282 END DO
283 !
284 ! build C0 occupied vectors and S*C0 matrix
285 ALLOCATE (sc(nspins), mo_coeff_array(nspins))
286 DO ispin = 1, nspins
287 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, homo=nocc)
288 NULLIFY (tmp_fm_struct)
289 CALL cp_fm_struct_create(tmp_fm_struct, nrow_global=nao, &
290 ncol_global=nocc, para_env=para_env, &
291 context=mo_coeff%matrix_struct%context)
292 CALL cp_fm_create(mo_coeff_array(ispin), tmp_fm_struct)
293 CALL cp_fm_to_fm(mo_coeff, mo_coeff_array(ispin), nocc)
294 CALL cp_fm_create(sc(ispin), tmp_fm_struct)
295 CALL cp_fm_struct_release(tmp_fm_struct)
296 END DO
297 !
298 ! Allocate C0_order'*H*C0_order
299 ALLOCATE (chc(nspins))
300 DO ispin = 1, nspins
301 CALL cp_fm_get_info(psi1(ispin), ncol_global=nmo)
302 NULLIFY (tmp_fm_struct)
303 CALL cp_fm_struct_create(tmp_fm_struct, nrow_global=nmo, &
304 ncol_global=nmo, para_env=para_env, &
305 context=mo_coeff%matrix_struct%context)
306 CALL cp_fm_create(chc(ispin), tmp_fm_struct, set_zero=.true.)
307 CALL cp_fm_struct_release(tmp_fm_struct)
308 END DO
309 !
310 DO ispin = 1, nspins
311 !
312 ! C0_order' * H * C0_order
313 associate(mo_coeff => psi0_order(ispin))
314 CALL cp_fm_create(buf, mo_coeff%matrix_struct)
315 CALL cp_fm_get_info(mo_coeff, ncol_global=ncol)
316 CALL cp_dbcsr_sm_fm_multiply(matrix_ks(ispin)%matrix, mo_coeff, buf, ncol)
317 CALL parallel_gemm('T', 'N', ncol, ncol, nao, -1.0_dp, mo_coeff, buf, 0.0_dp, chc(ispin))
318 CALL cp_fm_release(buf)
319 END associate
320 !
321 ! S * C0
322 CALL cp_fm_get_info(mo_coeff_array(ispin), ncol_global=ncol)
323 CALL cp_dbcsr_sm_fm_multiply(matrix_s(1)%matrix, mo_coeff_array(ispin), sc(ispin), ncol)
324 END DO
325 !
326 ! header
327 IF (iounit > 0 .AND. .NOT. my_silent) THEN
328 WRITE (iounit, "(/,T3,A,T16,A,T25,A,T38,A,T52,A,T72,A,/,T3,A)") &
329 "Iteration", "Method", "Restart", "Stepsize", "Convergence", "Time", &
330 repeat("-", 78)
331 END IF
332 !
333 ! orthogonalize x with respect to the psi0
334 CALL preortho(psi1, mo_coeff_array, sc)
335 !
336 ! build the preconditioner
337 IF (linres_control%preconditioner_type /= ot_precond_none) THEN
338 IF (p_env%new_preconditioner) THEN
339 DO ispin = 1, nspins
340 IF (ASSOCIATED(matrix_t)) THEN
341 CALL make_preconditioner(p_env%preconditioner(ispin), &
342 linres_control%preconditioner_type, ot_precond_solver_default, &
343 matrix_ks(ispin)%matrix, matrix_s(1)%matrix, matrix_t(1)%matrix, &
344 mos(ispin), linres_control%energy_gap)
345 ELSE
346 NULLIFY (matrix_x)
347 CALL make_preconditioner(p_env%preconditioner(ispin), &
348 linres_control%preconditioner_type, ot_precond_solver_default, &
349 matrix_ks(ispin)%matrix, matrix_s(1)%matrix, matrix_x, &
350 mos(ispin), linres_control%energy_gap)
351 END IF
352 END DO
353 p_env%new_preconditioner = .false.
354 END IF
355 END IF
356 !
357 ! initialization of the linear solver
358 !
359 ! A * x0
360 CALL apply_op(qs_env, p_env, psi0_order, psi1, ap, chc)
361 !
362 !
363 ! r_0 = b - Ax0
364 DO ispin = 1, nspins
365 CALL cp_fm_to_fm(h1_psi0(ispin), r(ispin))
366 CALL cp_fm_scale_and_add(-1.0_dp, r(ispin), -1.0_dp, ap(ispin))
367 END DO
368 !
369 ! proj r
370 CALL postortho(r, mo_coeff_array, sc)
371 !
372 ! preconditioner
373 linres_control%flag = ""
374 IF (linres_control%preconditioner_type == ot_precond_none) THEN
375 !
376 ! z_0 = r_0
377 DO ispin = 1, nspins
378 CALL cp_fm_to_fm(r(ispin), z(ispin))
379 END DO
380 linres_control%flag = "CG"
381 ELSE
382 !
383 ! z_0 = M * r_0
384 DO ispin = 1, nspins
385 CALL apply_preconditioner(p_env%preconditioner(ispin), r(ispin), &
386 z(ispin))
387 END DO
388 linres_control%flag = "PCG"
389 END IF
390 !
391 DO ispin = 1, nspins
392 !
393 ! p_0 = z_0
394 CALL cp_fm_to_fm(z(ispin), p(ispin))
395 !
396 ! trace(r_0 * z_0)
397 CALL cp_fm_trace(r(ispin), z(ispin), tr_rz0(ispin))
398 END DO
399 IF (sum(tr_rz0) < 0.0_dp) cpabort("tr(r_j*z_j) < 0")
400 norm_res = abs(sum(tr_rz0))/sqrt(real(nspins*nao*maxnmo, dp))
401 !
402 alpha = 0.0_dp
403 restart = .false.
404 should_stop = .false.
405 iteration: DO iter = 1, linres_control%max_iter
406 !
407 ! check convergence
408 linres_control%converged = .false.
409 IF (norm_res < linres_control%eps) THEN
410 linres_control%converged = .true.
411 END IF
412 !
413 t2 = m_walltime()
414 IF (iter == 1 .OR. mod(iter, 1) == 0 .OR. linres_control%converged &
415 .OR. restart .OR. should_stop) THEN
416 IF (iounit > 0 .AND. .NOT. my_silent) THEN
417 WRITE (iounit, "(T5,I5,T18,A3,T28,L1,T38,1E8.2,T48,F16.10,T68,F8.2)") &
418 iter, linres_control%flag, restart, alpha, norm_res, t2 - t1
419 CALL m_flush(iounit)
420 END IF
421 END IF
422 !
423 IF (linres_control%converged) THEN
424 IF (iounit > 0) THEN
425 WRITE (iounit, "(T3,A,I4,A,T73,F8.2)") "The linear solver converged in ", &
426 iter, " iterations.", t2 - t1
427 CALL m_flush(iounit)
428 END IF
429 EXIT iteration
430 ELSE IF (should_stop) THEN
431 IF (iounit > 0) THEN
432 WRITE (iounit, "(T3,A,I4,A)") "The linear solver did NOT converge! External stop"
433 CALL m_flush(iounit)
434 END IF
435 EXIT iteration
436 END IF
437 !
438 ! Max number of iteration reached
439 IF (iter == linres_control%max_iter) THEN
440 IF (iounit > 0) THEN
441 CALL cp_warn(__location__, &
442 "The linear solver didn't converge! Maximum number of iterations reached.")
443 CALL m_flush(iounit)
444 END IF
445 linres_control%converged = .false.
446 END IF
447 !
448 ! Apply the operators that do not depend on the perturbation
449 CALL apply_op(qs_env, p_env, psi0_order, p, ap, chc)
450 !
451 ! proj Ap onto the virtual subspace
452 CALL postortho(ap, mo_coeff_array, sc)
453 !
454 DO ispin = 1, nspins
455 !
456 ! tr(Ap_j*p_j)
457 CALL cp_fm_trace(ap(ispin), p(ispin), tr_pap(ispin))
458 END DO
459 !
460 ! alpha = tr(r_j*z_j) / tr(Ap_j*p_j)
461 IF (sum(tr_pap) < 1.0e-10_dp) THEN
462 alpha = 1.0_dp
463 ELSE
464 alpha = sum(tr_rz0)/sum(tr_pap)
465 END IF
466 DO ispin = 1, nspins
467 !
468 ! x_j+1 = x_j + alpha * p_j
469 CALL cp_fm_scale_and_add(1.0_dp, psi1(ispin), alpha, p(ispin))
470 END DO
471 !
472 ! need to recompute the residue
473 restart = .false.
474 IF (mod(iter, linres_control%restart_every) == 0) THEN
475 !
476 ! r_j+1 = b - A * x_j+1
477 CALL apply_op(qs_env, p_env, psi0_order, psi1, ap, chc)
478 !
479 DO ispin = 1, nspins
480 CALL cp_fm_to_fm(h1_psi0(ispin), r(ispin))
481 CALL cp_fm_scale_and_add(-1.0_dp, r(ispin), -1.0_dp, ap(ispin))
482 END DO
483 CALL postortho(r, mo_coeff_array, sc)
484 !
485 restart = .true.
486 ELSE
487 ! proj Ap onto the virtual subspace
488 CALL postortho(ap, mo_coeff_array, sc)
489 !
490 ! r_j+1 = r_j - alpha * Ap_j
491 DO ispin = 1, nspins
492 CALL cp_fm_scale_and_add(1.0_dp, r(ispin), -alpha, ap(ispin))
493 END DO
494 restart = .false.
495 END IF
496 !
497 ! preconditioner
498 linres_control%flag = ""
499 IF (linres_control%preconditioner_type == ot_precond_none) THEN
500 !
501 ! z_j+1 = r_j+1
502 DO ispin = 1, nspins
503 CALL cp_fm_to_fm(r(ispin), z(ispin))
504 END DO
505 linres_control%flag = "CG"
506 ELSE
507 !
508 ! z_j+1 = M * r_j+1
509 DO ispin = 1, nspins
510 CALL apply_preconditioner(p_env%preconditioner(ispin), r(ispin), &
511 z(ispin))
512 END DO
513 linres_control%flag = "PCG"
514 END IF
515 !
516 DO ispin = 1, nspins
517 !
518 ! tr(r_j+1*z_j+1)
519 CALL cp_fm_trace(r(ispin), z(ispin), tr_rz1(ispin))
520 END DO
521 IF (sum(tr_rz1) < 0.0_dp) cpabort("tr(r_j+1*z_j+1) < 0")
522 norm_res = sum(tr_rz1)/sqrt(real(nspins*nao*maxnmo, dp))
523 !
524 ! beta = tr(r_j+1*z_j+1) / tr(r_j*z_j)
525 IF (sum(tr_rz0) < 1.0e-10_dp) THEN
526 beta = 0.0_dp
527 ELSE
528 beta = sum(tr_rz1)/sum(tr_rz0)
529 END IF
530 DO ispin = 1, nspins
531 !
532 ! p_j+1 = z_j+1 + beta * p_j
533 CALL cp_fm_scale_and_add(beta, p(ispin), 1.0_dp, z(ispin))
534 tr_rz00(ispin) = tr_rz0(ispin)
535 tr_rz0(ispin) = tr_rz1(ispin)
536 END DO
537 !
538 ! Can we exit the SCF loop?
539 CALL external_control(should_stop, "LINRES", target_time=qs_env%target_time, &
540 start_time=qs_env%start_time)
541
542 END DO iteration
543 !
544 ! proj psi1
545 CALL preortho(psi1, mo_coeff_array, sc)
546 !
547 !
548 ! clean up
549 CALL cp_fm_release(r)
550 CALL cp_fm_release(p)
551 CALL cp_fm_release(z)
552 CALL cp_fm_release(ap)
553 !
554 CALL cp_fm_release(mo_coeff_array)
555 CALL cp_fm_release(sc)
556 CALL cp_fm_release(chc)
557 !
558 DEALLOCATE (tr_pap, tr_rz0, tr_rz00, tr_rz1)
559 !
560 CALL timestop(handle)
561 !
562 END SUBROUTINE linres_solver
563
564! **************************************************************************************************
565!> \brief ...
566!> \param qs_env ...
567!> \param p_env ...
568!> \param c0 ...
569!> \param v ...
570!> \param Av ...
571!> \param chc ...
572! **************************************************************************************************
573 SUBROUTINE apply_op(qs_env, p_env, c0, v, Av, chc)
574 !
575 TYPE(qs_environment_type), INTENT(IN), POINTER :: qs_env
576 TYPE(qs_p_env_type) :: p_env
577 TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: c0, v
578 TYPE(cp_fm_type), DIMENSION(:), INTENT(INOUT) :: av
579 TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: chc
580
581 CHARACTER(LEN=*), PARAMETER :: routinen = 'apply_op'
582
583 INTEGER :: handle, ispin, nc1, nc2, nc3, nc4, nr1, &
584 nr2, nr3, nr4, nspins
585 REAL(dp) :: chksum
586 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks, matrix_s
587 TYPE(dft_control_type), POINTER :: dft_control
588 TYPE(linres_control_type), POINTER :: linres_control
589 TYPE(qs_rho_type), POINTER :: rho
590
591 CALL timeset(routinen, handle)
592
593 NULLIFY (dft_control, matrix_ks, matrix_s, linres_control)
594 CALL get_qs_env(qs_env=qs_env, &
595 matrix_ks=matrix_ks, &
596 matrix_s=matrix_s, &
597 dft_control=dft_control, &
598 linres_control=linres_control)
599
600 nspins = dft_control%nspins
601
602 DO ispin = 1, nspins
603 !c0, v, Av, chc
604 CALL cp_fm_get_info(c0(ispin), ncol_global=nc1, nrow_global=nr1)
605 CALL cp_fm_get_info(v(ispin), ncol_global=nc2, nrow_global=nr2)
606 CALL cp_fm_get_info(av(ispin), ncol_global=nc3, nrow_global=nr3)
607 CALL cp_fm_get_info(chc(ispin), ncol_global=nc4, nrow_global=nr4)
608 IF (.NOT. (nc1 == nc2 .AND. nr1 == nr2 .AND. nc1 == nc3 .AND. nr1 == nr3 &
609 .AND. nc4 == nr4 .AND. nc1 <= nc4)) THEN
610 CALL cp_abort(__location__, &
611 "Number of vectors inconsistent or CHC matrix too small")
612 END IF
613 END DO
614
615 ! apply the uncoupled operator
616 DO ispin = 1, nspins
617 CALL apply_op_1(v(ispin), av(ispin), matrix_ks(ispin)%matrix, &
618 matrix_s(1)%matrix, chc(ispin))
619 END DO
620
621 IF (linres_control%do_kernel) THEN
622
623 ! build DM, refill p1, build_dm_response keeps sparse structure
624 DO ispin = 1, nspins
625 CALL dbcsr_copy(p_env%p1(ispin)%matrix, matrix_s(1)%matrix)
626 END DO
627 CALL build_dm_response(c0, v, p_env%p1)
628
629 chksum = 0.0_dp
630 DO ispin = 1, nspins
631 chksum = chksum + dbcsr_checksum(p_env%p1(ispin)%matrix)
632 END DO
633
634 ! skip the kernel if the DM is very small
635 IF (chksum > 1.0e-14_dp) THEN
636
637 CALL p_env_check_i_alloc(p_env, qs_env)
638
639 CALL p_env_update_rho(p_env, qs_env)
640
641 CALL get_qs_env(qs_env, rho=rho) ! that could be called before
642 CALL qs_rho_update_rho(rho, qs_env=qs_env) ! that could be called before
643 IF (dft_control%qs_control%gapw) THEN
644 CALL prepare_gapw_den(qs_env)
645 ELSEIF (dft_control%qs_control%gapw_xc) THEN
646 CALL prepare_gapw_den(qs_env, do_rho0=.false.)
647 END IF
648
649 DO ispin = 1, nspins
650 CALL dbcsr_set(p_env%kpp1(ispin)%matrix, 0.0_dp)
651 IF (ASSOCIATED(p_env%kpp1_admm)) CALL dbcsr_set(p_env%kpp1_admm(ispin)%matrix, 0.0_dp)
652 END DO
653
654 CALL apply_op_2(qs_env, p_env, c0, av)
655
656 END IF
657
658 END IF
659
660 CALL timestop(handle)
661
662 END SUBROUTINE apply_op
663
664! **************************************************************************************************
665!> \brief ...
666!> \param v ...
667!> \param Av ...
668!> \param matrix_ks ...
669!> \param matrix_s ...
670!> \param chc ...
671! **************************************************************************************************
672 SUBROUTINE apply_op_1(v, Av, matrix_ks, matrix_s, chc)
673 !
674 TYPE(cp_fm_type), INTENT(IN) :: v
675 TYPE(cp_fm_type), INTENT(INOUT) :: av
676 TYPE(dbcsr_type), INTENT(IN) :: matrix_ks, matrix_s
677 TYPE(cp_fm_type), INTENT(IN) :: chc
678
679 CHARACTER(LEN=*), PARAMETER :: routinen = 'apply_op_1'
680
681 INTEGER :: handle, ncol, nrow
682 TYPE(cp_fm_type) :: buf
683
684 CALL timeset(routinen, handle)
685 !
686 CALL cp_fm_create(buf, v%matrix_struct)
687 !
688 CALL cp_fm_get_info(v, ncol_global=ncol, nrow_global=nrow)
689 ! H * v
690 CALL cp_dbcsr_sm_fm_multiply(matrix_ks, v, av, ncol)
691 ! v * e (chc already multiplied by -1)
692 CALL parallel_gemm('N', 'N', nrow, ncol, ncol, 1.0_dp, v, chc, 0.0_dp, buf)
693 ! S * ve
694 CALL cp_dbcsr_sm_fm_multiply(matrix_s, buf, av, ncol, alpha=1.0_dp, beta=1.0_dp)
695 !Results is H*C1 - S*<iHj>*C1
696 !
697 CALL cp_fm_release(buf)
698 !
699 CALL timestop(handle)
700 !
701 END SUBROUTINE apply_op_1
702
703!MERGE
704! **************************************************************************************************
705!> \brief ...
706!> \param v ...
707!> \param psi0 ...
708!> \param S_psi0 ...
709! **************************************************************************************************
710 SUBROUTINE preortho(v, psi0, S_psi0)
711 !v = (I-PS)v
712 !
713 TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: v, psi0, s_psi0
714
715 CHARACTER(LEN=*), PARAMETER :: routinen = 'preortho'
716
717 INTEGER :: handle, ispin, mp, mt, mv, np, nspins, &
718 nt, nv
719 TYPE(cp_fm_struct_type), POINTER :: tmp_fm_struct
720 TYPE(cp_fm_type) :: buf
721
722 CALL timeset(routinen, handle)
723 !
724 NULLIFY (tmp_fm_struct)
725 !
726 nspins = SIZE(v, 1)
727 !
728 DO ispin = 1, nspins
729 CALL cp_fm_get_info(v(ispin), ncol_global=mv, nrow_global=nv)
730 CALL cp_fm_get_info(psi0(ispin), ncol_global=mp, nrow_global=np)
731 !
732 CALL cp_fm_struct_create(tmp_fm_struct, nrow_global=nv, ncol_global=mp, &
733 para_env=v(ispin)%matrix_struct%para_env, &
734 context=v(ispin)%matrix_struct%context)
735 CALL cp_fm_create(buf, tmp_fm_struct)
736 CALL cp_fm_struct_release(tmp_fm_struct)
737 !
738 CALL cp_fm_get_info(buf, ncol_global=mt, nrow_global=nt)
739 cpassert(nv == np)
740 cpassert(mt >= mv)
741 cpassert(mt >= mp)
742 cpassert(nt == nv)
743 !
744 ! buf = v' * S_psi0
745 CALL parallel_gemm('T', 'N', mv, mp, nv, 1.0_dp, v(ispin), s_psi0(ispin), 0.0_dp, buf)
746 ! v = v - psi0 * buf'
747 CALL parallel_gemm('N', 'T', nv, mv, mp, -1.0_dp, psi0(ispin), buf, 1.0_dp, v(ispin))
748 !
749 CALL cp_fm_release(buf)
750 END DO
751 !
752 CALL timestop(handle)
753 !
754 END SUBROUTINE preortho
755
756! **************************************************************************************************
757!> \brief projects first index of v onto the virtual subspace
758!> \param v matrix to be projected
759!> \param psi0 matrix with occupied orbitals
760!> \param S_psi0 matrix containing product of metric and occupied orbitals
761! **************************************************************************************************
762 SUBROUTINE postortho(v, psi0, S_psi0)
763 !v = (I-SP)v
764 !
765 TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: v, psi0, s_psi0
766
767 CHARACTER(LEN=*), PARAMETER :: routinen = 'postortho'
768
769 INTEGER :: handle, ispin, mp, mt, mv, np, nspins, &
770 nt, nv
771 TYPE(cp_fm_struct_type), POINTER :: tmp_fm_struct
772 TYPE(cp_fm_type) :: buf
773
774 CALL timeset(routinen, handle)
775 !
776 NULLIFY (tmp_fm_struct)
777 !
778 nspins = SIZE(v, 1)
779 !
780 DO ispin = 1, nspins
781 CALL cp_fm_get_info(v(ispin), ncol_global=mv, nrow_global=nv)
782 CALL cp_fm_get_info(psi0(ispin), ncol_global=mp, nrow_global=np)
783 !
784 CALL cp_fm_struct_create(tmp_fm_struct, nrow_global=nv, ncol_global=mp, &
785 para_env=v(ispin)%matrix_struct%para_env, &
786 context=v(ispin)%matrix_struct%context)
787 CALL cp_fm_create(buf, tmp_fm_struct)
788 CALL cp_fm_struct_release(tmp_fm_struct)
789 !
790 CALL cp_fm_get_info(buf, ncol_global=mt, nrow_global=nt)
791 cpassert(nv == np)
792 cpassert(mt >= mv)
793 cpassert(mt >= mp)
794 cpassert(nt == nv)
795 !
796 ! buf = v' * psi0
797 CALL parallel_gemm('T', 'N', mv, mp, nv, 1.0_dp, v(ispin), psi0(ispin), 0.0_dp, buf)
798 ! v = v - S_psi0 * buf'
799 CALL parallel_gemm('N', 'T', nv, mv, mp, -1.0_dp, s_psi0(ispin), buf, 1.0_dp, v(ispin))
800 !
801 CALL cp_fm_release(buf)
802 END DO
803 !
804 CALL timestop(handle)
805 !
806 END SUBROUTINE postortho
807
808! **************************************************************************************************
809!> \brief ...
810!> \param qs_env ...
811!> \param linres_section ...
812!> \param vec ...
813!> \param ivec ...
814!> \param tag ...
815!> \param ind ...
816! **************************************************************************************************
817 SUBROUTINE linres_write_restart(qs_env, linres_section, vec, ivec, tag, ind)
818 TYPE(qs_environment_type), POINTER :: qs_env
819 TYPE(section_vals_type), POINTER :: linres_section
820 TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: vec
821 INTEGER, INTENT(IN) :: ivec
822 CHARACTER(LEN=*) :: tag
823 INTEGER, INTENT(IN), OPTIONAL :: ind
824
825 CHARACTER(LEN=*), PARAMETER :: routinen = 'linres_write_restart'
826
827 CHARACTER(LEN=default_path_length) :: filename
828 CHARACTER(LEN=default_string_length) :: my_middle, my_pos, my_status
829 INTEGER :: handle, i, i_block, ia, ie, iounit, &
830 ispin, j, max_block, nao, nmo, nspins, &
831 rst_unit
832 REAL(kind=dp), DIMENSION(:, :), POINTER :: vecbuffer
833 TYPE(cp_fm_type), POINTER :: mo_coeff
834 TYPE(cp_logger_type), POINTER :: logger
835 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
836 TYPE(mp_para_env_type), POINTER :: para_env
837 TYPE(section_vals_type), POINTER :: print_key
838
839 NULLIFY (logger, mo_coeff, mos, para_env, print_key, vecbuffer)
840
841 CALL timeset(routinen, handle)
842
843 logger => cp_get_default_logger()
844
845 IF (btest(cp_print_key_should_output(logger%iter_info, linres_section, "PRINT%RESTART", &
846 used_print_key=print_key), &
847 cp_p_file)) THEN
848
849 iounit = cp_print_key_unit_nr(logger, linres_section, &
850 "PRINT%PROGRAM_RUN_INFO", extension=".Log")
851
852 CALL get_qs_env(qs_env=qs_env, &
853 mos=mos, &
854 para_env=para_env)
855
856 nspins = SIZE(mos)
857
858 my_status = "REPLACE"
859 my_pos = "REWIND"
860 CALL xstring(tag, ia, ie)
861 IF (PRESENT(ind)) THEN
862 my_middle = "RESTART-"//tag(ia:ie)//trim(adjustl(cp_to_string(ivec)))
863 ELSE
864 my_middle = "RESTART-"//tag(ia:ie)
865 IF (ivec > 1) THEN
866 my_status = "OLD"
867 my_pos = "APPEND"
868 END IF
869 END IF
870 rst_unit = cp_print_key_unit_nr(logger, linres_section, "PRINT%RESTART", &
871 extension=".lr", middle_name=trim(my_middle), file_status=trim(my_status), &
872 file_position=trim(my_pos), file_action="WRITE", file_form="UNFORMATTED")
873
874 filename = cp_print_key_generate_filename(logger, print_key, &
875 extension=".lr", middle_name=trim(my_middle), my_local=.false.)
876
877 IF (iounit > 0) THEN
878 WRITE (unit=iounit, fmt="(T2,A)") &
879 "LINRES| Writing response functions to the restart file <"//trim(adjustl(filename))//">"
880 END IF
881
882 !
883 ! write data to file
884 ! use the scalapack block size as a default for buffering columns
885 CALL get_mo_set(mos(1), mo_coeff=mo_coeff)
886 CALL cp_fm_get_info(mo_coeff, nrow_global=nao, ncol_block=max_block)
887 ALLOCATE (vecbuffer(nao, max_block))
888
889 IF (PRESENT(ind)) THEN
890 IF (rst_unit > 0) WRITE (rst_unit) ind, ivec, nspins, nao
891 ELSE
892 IF (rst_unit > 0) WRITE (rst_unit) ivec, nspins, nao
893 END IF
894
895 DO ispin = 1, nspins
896 CALL cp_fm_get_info(vec(ispin), ncol_global=nmo)
897
898 IF (rst_unit > 0) WRITE (rst_unit) nmo
899
900 DO i = 1, nmo, max(max_block, 1)
901 i_block = min(max_block, nmo - i + 1)
902 CALL cp_fm_get_submatrix(vec(ispin), vecbuffer, 1, i, nao, i_block)
903 ! doing this in one write would increase efficiency, but breaks RESTART compatibility.
904 ! to old ones, and in cases where max_block is different between runs, as might happen during
905 ! restarts with a different number of CPUs
906 DO j = 1, i_block
907 IF (rst_unit > 0) WRITE (rst_unit) vecbuffer(1:nao, j)
908 END DO
909 END DO
910 END DO
911
912 DEALLOCATE (vecbuffer)
913
914 CALL cp_print_key_finished_output(rst_unit, logger, linres_section, &
915 "PRINT%RESTART")
916 END IF
917
918 CALL timestop(handle)
919
920 END SUBROUTINE linres_write_restart
921
922! **************************************************************************************************
923!> \brief ...
924!> \param qs_env ...
925!> \param linres_section ...
926!> \param vec ...
927!> \param ivec ...
928!> \param tag ...
929!> \param ind ...
930! **************************************************************************************************
931 SUBROUTINE linres_read_restart(qs_env, linres_section, vec, ivec, tag, ind)
932 TYPE(qs_environment_type), POINTER :: qs_env
933 TYPE(section_vals_type), POINTER :: linres_section
934 TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: vec
935 INTEGER, INTENT(IN) :: ivec
936 CHARACTER(LEN=*) :: tag
937 INTEGER, INTENT(INOUT), OPTIONAL :: ind
938
939 CHARACTER(LEN=*), PARAMETER :: routinen = 'linres_read_restart'
940
941 CHARACTER(LEN=default_path_length) :: filename
942 CHARACTER(LEN=default_string_length) :: my_middle
943 INTEGER :: handle, i, i_block, ia, ie, iostat, iounit, ispin, iv, iv1, ivec_tmp, j, &
944 max_block, n_rep_val, nao, nao_tmp, nmo, nmo_tmp, nspins, nspins_tmp, rst_unit
945 LOGICAL :: file_exists
946 REAL(kind=dp), DIMENSION(:, :), POINTER :: vecbuffer
947 TYPE(cp_fm_type), POINTER :: mo_coeff
948 TYPE(cp_logger_type), POINTER :: logger
949 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
950 TYPE(mp_para_env_type), POINTER :: para_env
951 TYPE(section_vals_type), POINTER :: print_key
952
953 file_exists = .false.
954
955 CALL timeset(routinen, handle)
956
957 NULLIFY (mos, para_env, logger, print_key, vecbuffer)
958 logger => cp_get_default_logger()
959
960 iounit = cp_print_key_unit_nr(logger, linres_section, &
961 "PRINT%PROGRAM_RUN_INFO", extension=".Log")
962
963 CALL get_qs_env(qs_env=qs_env, &
964 para_env=para_env, &
965 mos=mos)
966
967 nspins = SIZE(mos)
968
969 rst_unit = -1
970 IF (para_env%is_source()) THEN
971 CALL section_vals_val_get(linres_section, "WFN_RESTART_FILE_NAME", &
972 n_rep_val=n_rep_val)
973
974 CALL xstring(tag, ia, ie)
975 IF (PRESENT(ind)) THEN
976 my_middle = "RESTART-"//tag(ia:ie)//trim(adjustl(cp_to_string(ivec)))
977 ELSE
978 my_middle = "RESTART-"//tag(ia:ie)
979 END IF
980
981 IF (n_rep_val > 0) THEN
982 CALL section_vals_val_get(linres_section, "WFN_RESTART_FILE_NAME", c_val=filename)
983 CALL xstring(filename, ia, ie)
984 filename = filename(ia:ie)//trim(my_middle)//".lr"
985 ELSE
986 ! try to read from the filename that is generated automatically from the printkey
987 print_key => section_vals_get_subs_vals(linres_section, "PRINT%RESTART")
988 filename = cp_print_key_generate_filename(logger, print_key, &
989 extension=".lr", middle_name=trim(my_middle), my_local=.false.)
990 END IF
991 INQUIRE (file=filename, exist=file_exists)
992 !
993 ! open file
994 IF (file_exists) THEN
995 CALL open_file(file_name=trim(filename), &
996 file_action="READ", &
997 file_form="UNFORMATTED", &
998 file_position="REWIND", &
999 file_status="OLD", &
1000 unit_number=rst_unit)
1001
1002 IF (iounit > 0) WRITE (iounit, "(T2,A)") &
1003 "LINRES| Reading response wavefunctions from the restart file <"//trim(adjustl(filename))//">"
1004 ELSE
1005 IF (iounit > 0) WRITE (iounit, "(T2,A)") &
1006 "LINRES| Restart file <"//trim(adjustl(filename))//"> not found"
1007 END IF
1008 END IF
1009
1010 CALL para_env%bcast(file_exists)
1011
1012 IF (file_exists) THEN
1013
1014 CALL get_mo_set(mos(1), mo_coeff=mo_coeff)
1015 CALL cp_fm_get_info(mo_coeff, nrow_global=nao, ncol_block=max_block)
1016
1017 ALLOCATE (vecbuffer(nao, max_block))
1018 !
1019 ! read headers
1020 IF (PRESENT(ind)) THEN
1021 iv1 = ivec
1022 ELSE
1023 iv1 = 1
1024 END IF
1025 DO iv = iv1, ivec
1026
1027 IF (PRESENT(ind)) THEN
1028 IF (rst_unit > 0) READ (rst_unit, iostat=iostat) ind, ivec_tmp, nspins_tmp, nao_tmp
1029 CALL para_env%bcast(iostat)
1030 CALL para_env%bcast(ind)
1031 ELSE
1032 IF (rst_unit > 0) READ (rst_unit, iostat=iostat) ivec_tmp, nspins_tmp, nao_tmp
1033 CALL para_env%bcast(iostat)
1034 END IF
1035
1036 IF (iostat /= 0) EXIT
1037 CALL para_env%bcast(ivec_tmp)
1038 CALL para_env%bcast(nspins_tmp)
1039 CALL para_env%bcast(nao_tmp)
1040
1041 ! check that the number nao, nmo and nspins are
1042 ! the same as in the current mos
1043 IF (nspins_tmp /= nspins) cpabort("nspins not consistent")
1044 IF (nao_tmp /= nao) cpabort("nao not consistent")
1045 !
1046 DO ispin = 1, nspins
1047 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff)
1048 CALL cp_fm_get_info(mo_coeff, ncol_global=nmo)
1049 !
1050 IF (rst_unit > 0) READ (rst_unit) nmo_tmp
1051 CALL para_env%bcast(nmo_tmp)
1052 IF (nmo_tmp /= nmo) cpabort("nmo not consistent")
1053 !
1054 ! read the response
1055 DO i = 1, nmo, max(max_block, 1)
1056 i_block = min(max_block, nmo - i + 1)
1057 DO j = 1, i_block
1058 IF (rst_unit > 0) READ (rst_unit) vecbuffer(1:nao, j)
1059 END DO
1060 IF (iv == ivec_tmp) THEN
1061 CALL para_env%bcast(vecbuffer)
1062 CALL cp_fm_set_submatrix(vec(ispin), vecbuffer, 1, i, nao, i_block)
1063 END IF
1064 END DO
1065 END DO
1066 IF (ivec == ivec_tmp) EXIT
1067 END DO
1068
1069 IF (iostat /= 0) THEN
1070 IF (iounit > 0) WRITE (iounit, "(T2,A)") &
1071 "LINRES| Restart file <"//trim(adjustl(filename))//"> not found"
1072 END IF
1073
1074 DEALLOCATE (vecbuffer)
1075
1076 END IF
1077
1078 IF (para_env%is_source()) THEN
1079 IF (file_exists) CALL close_file(unit_number=rst_unit)
1080 END IF
1081
1082 CALL timestop(handle)
1083
1084 END SUBROUTINE linres_read_restart
1085
1086! **************************************************************************************************
1087!> \brief ...
1088!> \param p_env ...
1089!> \param linres_control ...
1090!> \param nspins ...
1091! **************************************************************************************************
1092 SUBROUTINE check_p_env_init(p_env, linres_control, nspins)
1093 !
1094 TYPE(qs_p_env_type) :: p_env
1095 TYPE(linres_control_type), INTENT(IN) :: linres_control
1096 INTEGER, INTENT(IN) :: nspins
1097
1098 INTEGER :: ispin, ncol, nrow
1099
1100 IF (linres_control%preconditioner_type /= ot_precond_none) THEN
1101 cpassert(ASSOCIATED(p_env%preconditioner))
1102 DO ispin = 1, nspins
1103 CALL cp_fm_get_info(p_env%PS_psi0(ispin), nrow_global=nrow, ncol_global=ncol)
1104 cpassert(nrow == p_env%n_ao(ispin))
1105 cpassert(ncol == p_env%n_mo(ispin))
1106 END DO
1107 END IF
1108
1109 END SUBROUTINE check_p_env_init
1110
1111END MODULE qs_linres_methods
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_set(matrix, alpha)
...
real(kind=dp) function, public dbcsr_checksum(matrix, pos)
Calculates the checksum of a DBCSR matrix.
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
Routines to handle the external control of CP2K.
subroutine, public external_control(should_stop, flag, globenv, target_time, start_time, force_check)
External manipulations during a run : when the <PROJECT_NAME>.EXIT_$runtype command is sent the progr...
Utility routines to open and close files. Tracking of preconnections.
Definition cp_files.F:16
subroutine, public open_file(file_name, file_status, file_form, file_action, file_position, file_pad, unit_number, debug, skip_get_unit_number, file_access)
Opens the requested file using a free unit number.
Definition cp_files.F:311
subroutine, public close_file(unit_number, file_status, keep_preconnection)
Close an open file given by its logical unit number. Optionally, keep the file and unit preconnected.
Definition cp_files.F:122
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_scale_and_add(alpha, matrix_a, beta, matrix_b)
calc A <- alpha*A + beta*B optimized for alpha == 1.0 (just add beta*B) and beta == 0....
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_create(matrix, matrix_struct, name, use_sp, nrow, ncol, set_zero)
creates a new full matrix with the given structure
subroutine, public cp_fm_set_submatrix(fm, new_values, start_row, start_col, n_rows, n_cols, alpha, beta, transpose)
sets a submatrix of a full matrix fm(start_row:start_row+n_rows,start_col:start_col+n_cols) = alpha*o...
subroutine, public cp_fm_get_submatrix(fm, target_m, start_row, start_col, n_rows, n_cols, transpose)
gets a submatrix of a full matrix op(target_m)(1:n_rows,1:n_cols) =fm(start_row:start_row+n_rows,...
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)
...
character(len=default_path_length) function, public cp_print_key_generate_filename(logger, print_key, middle_name, extension, my_local)
Utility function that returns a unit number to write the print key. Might open a file with a unique f...
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...
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public state_loc_all
integer, parameter, public do_loc_none
integer, parameter, public op_loc_berry
integer, parameter, public ot_precond_solver_default
integer, parameter, public ot_precond_none
objects that represent the structure of input sections and the data contained in an input section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
integer, parameter, public default_path_length
Definition kinds.F:58
Machine interface based on Fortran 2003 and POSIX.
Definition machine.F:17
subroutine, public m_flush(lunit)
flushes units if the &GLOBAL flag is set accordingly
Definition machine.F:136
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
Definition machine.F:153
Interface to the message passing library MPI.
basic linear algebra operations for full matrixes
computes preconditioners, and implements methods to apply them currently used in qs_ot
subroutine, public make_preconditioner(preconditioner_env, precon_type, solver_type, matrix_h, matrix_s, matrix_t, mo_set, energy_gap, convert_precond_to_dbcsr, chol_type)
...
Routines to calculate 2nd order kernels from a given response density in ao basis linear response scf...
subroutine, public build_dm_response(c0, c1, dm)
This routine builds response density in dbcsr format.
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
subroutine, public prepare_gapw_den(qs_env, local_rho_set, do_rho0, kind_set_external, pw_env_sub)
...
linres kernel functions
subroutine, public apply_op_2(qs_env, p_env, c0, av)
...
localize wavefunctions linear response scf
subroutine, public linres_solver(p_env, qs_env, psi1, h1_psi0, psi0_order, iounit, should_stop, silent)
scf loop to optimize the first order wavefunctions (psi1) given a perturbation as an operator applied...
subroutine, public linres_write_restart(qs_env, linres_section, vec, ivec, tag, ind)
...
subroutine, public linres_read_restart(qs_env, linres_section, vec, ivec, tag, ind)
...
subroutine, public linres_localize(qs_env, linres_control, nspins, centers_only)
Find the centers and spreads of the wfn, if required apply a localization algorithm.
Type definitiona for linear response calculations.
Driver for the localization that should be general for all the methods available and all the definiti...
Definition qs_loc_main.F:22
subroutine, public qs_loc_driver(qs_env, qs_loc_env, print_loc_section, myspin, ext_mo_coeff)
set up the calculation of localized orbitals
Definition qs_loc_main.F:96
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)
...
subroutine, public qs_loc_env_create(qs_loc_env)
...
Some utilities for the construction of the localization environment.
subroutine, public loc_write_restart(qs_loc_env, section, mo_array, coeff_localized, do_homo, evals, do_mixed)
...
subroutine, public qs_loc_control_init(qs_loc_env, loc_section, do_homo, do_mixed, do_xas, nloc_xas, spin_xas)
initializes everything needed for localization of the HOMOs
subroutine, public qs_loc_init(qs_env, qs_loc_env, localize_section, mos_localized, do_homo, do_mo_cubes, mo_loc_history, evals, tot_zeff_corr, do_mixed)
initializes everything needed for localization of the molecular orbitals
Definition and initialisation of the mo data type.
Definition qs_mo_types.F:22
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.
Utility functions for the perturbation calculations.
subroutine, public p_env_update_rho(p_env, qs_env)
...
subroutine, public p_env_check_i_alloc(p_env, qs_env)
checks that the intenal storage is allocated, and allocs it if needed
basis types for the calculation of the perturbation of density theory.
methods of the rho structure (defined in qs_rho_types)
subroutine, public qs_rho_update_rho(rho_struct, qs_env, rho_xc_external, local_rho_set, task_list_external, task_list_external_soft, pw_env_external, para_env_external)
updates rho_r and rho_g to the rhorho_ao. if use_kinetic_energy_density also computes tau_r and tau_g...
superstucture that hold various representations of the density and keeps track of which ones are vali...
Utilities for string manipulations.
elemental subroutine, public xstring(string, ia, ib)
...
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
General settings for linear response calculations.
A type that holds controlling information for the calculation of the spread of wfn and the optimizati...
contains all the info needed by quickstep to calculate the spread of a selected set of orbitals and i...
Represent a qs system that is perturbed. Can calculate the linear operator and the rhs of the system ...
keeps the density in various representations, keeping track of which ones are valid.