41 USE dbcsr_api,
ONLY: dbcsr_checksum,&
71 localized_wfn_control_type,&
85 #include "./base/base_uses.f90"
96 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_linres_methods'
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
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, &
131 NULLIFY (logger, lr_section, loc_section, loc_print_section, localized_wfn_control)
137 extension=
".linresLog")
138 my_centers_only = .false.
139 IF (
PRESENT(centers_only)) my_centers_only = centers_only
141 NULLIFY (mos, mo_coeff, qs_loc_env)
143 ALLOCATE (qs_loc_env)
145 linres_control%qs_loc_env => qs_loc_env
147 CALL get_qs_loc_env(qs_loc_env, localized_wfn_control=localized_wfn_control)
149 ALLOCATE (mos_localized(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))
157 IF (my_centers_only)
THEN
159 localized_wfn_control%localization_method =
do_loc_none
163 CALL qs_loc_init(qs_env, qs_loc_env, loc_section, mos_localized=mos_localized, &
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)
175 mos_localized, do_homo=.true.)
176 CALL cp_fm_release(mos_localized)
181 WRITE (iounit,
"(/,T2,A,I2)") &
182 "WANNIER CENTERS for spin ", ispin
183 WRITE (iounit,
"(/,T18,A,3X,A)") &
184 "--------------- Centers --------------- ", &
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)
215 SUBROUTINE linres_solver(p_env, qs_env, psi1, h1_psi0, psi0_order, iounit, should_stop)
216 TYPE(qs_p_env_type) :: p_env
217 TYPE(qs_environment_type),
POINTER :: qs_env
218 TYPE(cp_fm_type),
DIMENSION(:),
INTENT(IN) :: psi1, h1_psi0, psi0_order
219 INTEGER,
INTENT(IN) :: iounit
220 LOGICAL,
INTENT(OUT) :: should_stop
222 CHARACTER(LEN=*),
PARAMETER :: routinen =
'linres_solver'
224 INTEGER :: handle, ispin, iter, maxnmo, nao, ncol, &
227 REAL(
dp) :: alpha, beta, norm_res, t1, t2
228 REAL(
dp),
DIMENSION(:),
POINTER :: tr_pap, tr_rz0, tr_rz00, tr_rz1
229 TYPE(cp_fm_struct_type),
POINTER :: tmp_fm_struct
230 TYPE(cp_fm_type) :: buf
231 TYPE(cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: ap, chc, mo_coeff_array, p, r, z
232 TYPE(cp_fm_type),
DIMENSION(:),
POINTER :: sc
233 TYPE(cp_fm_type),
POINTER :: mo_coeff
234 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s, matrix_t
235 TYPE(dbcsr_type),
POINTER :: matrix_x
236 TYPE(dft_control_type),
POINTER :: dft_control
237 TYPE(linres_control_type),
POINTER :: linres_control
238 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos
239 TYPE(mp_para_env_type),
POINTER :: para_env
241 CALL timeset(routinen, handle)
243 NULLIFY (dft_control, linres_control, matrix_s, matrix_t, matrix_ks, para_env)
244 NULLIFY (mos, tmp_fm_struct, mo_coeff)
249 matrix_ks=matrix_ks, &
252 dft_control=dft_control, &
253 linres_control=linres_control, &
257 nspins = dft_control%nspins
262 maxnmo = max(maxnmo, ncol)
265 CALL check_p_env_init(p_env, linres_control, nspins)
268 ALLOCATE (tr_pap(nspins), tr_rz0(nspins), tr_rz00(nspins), tr_rz1(nspins), &
269 r(nspins), p(nspins), z(nspins), ap(nspins))
279 ALLOCATE (sc(nspins), mo_coeff_array(nspins))
281 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, homo=nocc)
282 NULLIFY (tmp_fm_struct)
284 ncol_global=nocc, para_env=para_env, &
285 context=mo_coeff%matrix_struct%context)
287 CALL cp_fm_to_fm(mo_coeff, mo_coeff_array(ispin), nocc)
293 ALLOCATE (chc(nspins))
296 NULLIFY (tmp_fm_struct)
298 ncol_global=nmo, para_env=para_env, &
299 context=mo_coeff%matrix_struct%context)
307 associate(mo_coeff => psi0_order(ispin))
311 CALL parallel_gemm(
'T',
'N', ncol, ncol, nao, -1.0_dp, mo_coeff, buf, 0.0_dp, chc(ispin))
312 CALL cp_fm_release(buf)
322 WRITE (iounit,
"(/,T3,A,T16,A,T25,A,T38,A,T52,A,T72,A,/,T3,A)") &
323 "Iteration",
"Method",
"Restart",
"Stepsize",
"Convergence",
"Time", &
328 CALL preortho(psi1, mo_coeff_array, sc)
332 IF (p_env%new_preconditioner)
THEN
334 IF (
ASSOCIATED(matrix_t))
THEN
337 matrix_ks(ispin)%matrix, matrix_s(1)%matrix, matrix_t(1)%matrix, &
338 mos(ispin), linres_control%energy_gap)
343 matrix_ks(ispin)%matrix, matrix_s(1)%matrix, matrix_x, &
344 mos(ispin), linres_control%energy_gap)
347 p_env%new_preconditioner = .false.
354 CALL apply_op(qs_env, p_env, psi0_order, psi1, ap, chc)
359 CALL cp_fm_to_fm(h1_psi0(ispin), r(ispin))
364 CALL postortho(r, mo_coeff_array, sc)
367 linres_control%flag =
""
372 CALL cp_fm_to_fm(r(ispin), z(ispin))
374 linres_control%flag =
"CG"
379 CALL apply_preconditioner(p_env%preconditioner(ispin), r(ispin), &
382 linres_control%flag =
"PCG"
388 CALL cp_fm_to_fm(z(ispin), p(ispin))
391 CALL cp_fm_trace(r(ispin), z(ispin), tr_rz0(ispin))
393 IF (sum(tr_rz0) < 0.0_dp) cpabort(
"tr(r_j*z_j) < 0")
394 norm_res = abs(sum(tr_rz0))/sqrt(real(nspins*nao*maxnmo,
dp))
398 should_stop = .false.
399 iteration:
DO iter = 1, linres_control%max_iter
402 linres_control%converged = .false.
403 IF (norm_res .LT. linres_control%eps)
THEN
404 linres_control%converged = .true.
408 IF (iter .EQ. 1 .OR. mod(iter, 1) .EQ. 0 .OR. linres_control%converged &
409 .OR. restart .OR. should_stop)
THEN
411 WRITE (iounit,
"(T5,I5,T18,A3,T28,L1,T38,1E8.2,T48,F16.10,T68,F8.2)") &
412 iter, linres_control%flag, restart, alpha, norm_res, t2 - t1
417 IF (linres_control%converged)
THEN
419 WRITE (iounit,
"(T3,A,I4,A)")
"The linear solver converged in ", iter,
" iterations."
423 ELSE IF (should_stop)
THEN
425 WRITE (iounit,
"(T3,A,I4,A)")
"The linear solver did NOT converge! External stop"
432 IF (iter == linres_control%max_iter)
THEN
434 CALL cp_warn(__location__, &
435 "The linear solver didn't converge! Maximum number of iterations reached.")
438 linres_control%converged = .false.
442 CALL apply_op(qs_env, p_env, psi0_order, p, ap, chc)
445 CALL postortho(ap, mo_coeff_array, sc)
450 CALL cp_fm_trace(ap(ispin), p(ispin), tr_pap(ispin))
454 IF (sum(tr_pap) < 1.0e-10_dp)
THEN
457 alpha = sum(tr_rz0)/sum(tr_pap)
467 IF (mod(iter, linres_control%restart_every) .EQ. 0)
THEN
470 CALL apply_op(qs_env, p_env, psi0_order, psi1, ap, chc)
473 CALL cp_fm_to_fm(h1_psi0(ispin), r(ispin))
476 CALL postortho(r, mo_coeff_array, sc)
481 CALL postortho(ap, mo_coeff_array, sc)
491 linres_control%flag =
""
496 CALL cp_fm_to_fm(r(ispin), z(ispin))
498 linres_control%flag =
"CG"
503 CALL apply_preconditioner(p_env%preconditioner(ispin), r(ispin), &
506 linres_control%flag =
"PCG"
512 CALL cp_fm_trace(r(ispin), z(ispin), tr_rz1(ispin))
514 IF (sum(tr_rz1) < 0.0_dp) cpabort(
"tr(r_j+1*z_j+1) < 0")
515 norm_res = sum(tr_rz1)/sqrt(real(nspins*nao*maxnmo,
dp))
518 IF (sum(tr_rz0) < 1.0e-10_dp)
THEN
521 beta = sum(tr_rz1)/sum(tr_rz0)
527 tr_rz00(ispin) = tr_rz0(ispin)
528 tr_rz0(ispin) = tr_rz1(ispin)
532 CALL external_control(should_stop,
"LINRES", target_time=qs_env%target_time, &
533 start_time=qs_env%start_time)
538 CALL preortho(psi1, mo_coeff_array, sc)
542 CALL cp_fm_release(r)
543 CALL cp_fm_release(p)
544 CALL cp_fm_release(z)
545 CALL cp_fm_release(ap)
547 CALL cp_fm_release(mo_coeff_array)
548 CALL cp_fm_release(sc)
549 CALL cp_fm_release(chc)
551 DEALLOCATE (tr_pap, tr_rz0, tr_rz00, tr_rz1)
553 CALL timestop(handle)
566 SUBROUTINE apply_op(qs_env, p_env, c0, v, Av, chc)
568 TYPE(qs_environment_type),
INTENT(IN),
POINTER :: qs_env
569 TYPE(qs_p_env_type) :: p_env
570 TYPE(cp_fm_type),
DIMENSION(:),
INTENT(IN) :: c0, v, av, chc
572 CHARACTER(LEN=*),
PARAMETER :: routinen =
'apply_op'
574 INTEGER :: handle, ispin, nc1, nc2, nc3, nc4, nr1, &
575 nr2, nr3, nr4, nspins
577 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s
578 TYPE(dft_control_type),
POINTER :: dft_control
579 TYPE(linres_control_type),
POINTER :: linres_control
580 TYPE(qs_rho_type),
POINTER :: rho
582 CALL timeset(routinen, handle)
584 NULLIFY (dft_control, matrix_ks, matrix_s, linres_control)
585 CALL get_qs_env(qs_env=qs_env, &
586 matrix_ks=matrix_ks, &
588 dft_control=dft_control, &
589 linres_control=linres_control)
591 nspins = dft_control%nspins
595 CALL cp_fm_get_info(c0(ispin), ncol_global=nc1, nrow_global=nr1)
596 CALL cp_fm_get_info(v(ispin), ncol_global=nc2, nrow_global=nr2)
597 CALL cp_fm_get_info(av(ispin), ncol_global=nc3, nrow_global=nr3)
598 CALL cp_fm_get_info(chc(ispin), ncol_global=nc4, nrow_global=nr4)
599 IF (.NOT. (nc1 == nc2 .AND. nr1 == nr2 .AND. nc1 == nc3 .AND. nr1 == nr3 &
600 .AND. nc4 == nr4 .AND. nc1 <= nc4))
THEN
601 CALL cp_abort(__location__, &
602 "Number of vectors inconsistent or CHC matrix too small")
608 CALL apply_op_1(v(ispin), av(ispin), matrix_ks(ispin)%matrix, &
609 matrix_s(1)%matrix, chc(ispin))
612 IF (linres_control%do_kernel)
THEN
616 CALL dbcsr_copy(p_env%p1(ispin)%matrix, matrix_s(1)%matrix)
618 CALL build_dm_response(c0, v, p_env%p1)
622 chksum = chksum + dbcsr_checksum(p_env%p1(ispin)%matrix)
626 IF (chksum .GT. 1.0e-14_dp)
THEN
628 CALL p_env_check_i_alloc(p_env, qs_env)
630 CALL p_env_update_rho(p_env, qs_env)
632 CALL get_qs_env(qs_env, rho=rho)
633 CALL qs_rho_update_rho(rho, qs_env=qs_env)
634 IF (dft_control%qs_control%gapw)
THEN
635 CALL prepare_gapw_den(qs_env)
636 ELSEIF (dft_control%qs_control%gapw_xc)
THEN
637 CALL prepare_gapw_den(qs_env, do_rho0=.false.)
641 CALL dbcsr_set(p_env%kpp1(ispin)%matrix, 0.0_dp)
642 IF (
ASSOCIATED(p_env%kpp1_admm))
CALL dbcsr_set(p_env%kpp1_admm(ispin)%matrix, 0.0_dp)
645 CALL apply_op_2(qs_env, p_env, c0, av)
651 CALL timestop(handle)
653 END SUBROUTINE apply_op
663 SUBROUTINE apply_op_1(v, Av, matrix_ks, matrix_s, chc)
665 TYPE(cp_fm_type),
INTENT(IN) :: v, av
666 TYPE(dbcsr_type),
INTENT(IN) :: matrix_ks, matrix_s
667 TYPE(cp_fm_type),
INTENT(IN) :: chc
669 CHARACTER(LEN=*),
PARAMETER :: routinen =
'apply_op_1'
671 INTEGER :: handle, ncol, nrow
672 TYPE(cp_fm_type) :: buf
674 CALL timeset(routinen, handle)
676 CALL cp_fm_create(buf, v%matrix_struct)
678 CALL cp_fm_get_info(v, ncol_global=ncol, nrow_global=nrow)
680 CALL cp_dbcsr_sm_fm_multiply(matrix_ks, v, av, ncol)
682 CALL parallel_gemm(
'N',
'N', nrow, ncol, ncol, 1.0_dp, v, chc, 0.0_dp, buf)
684 CALL cp_dbcsr_sm_fm_multiply(matrix_s, buf, av, ncol, alpha=1.0_dp, beta=1.0_dp)
687 CALL cp_fm_release(buf)
689 CALL timestop(handle)
691 END SUBROUTINE apply_op_1
700 SUBROUTINE preortho(v, psi0, S_psi0)
703 TYPE(cp_fm_type),
DIMENSION(:),
INTENT(IN) :: v, psi0, s_psi0
705 CHARACTER(LEN=*),
PARAMETER :: routinen =
'preortho'
707 INTEGER :: handle, ispin, mp, mt, mv, np, nspins, &
709 TYPE(cp_fm_struct_type),
POINTER :: tmp_fm_struct
710 TYPE(cp_fm_type) :: buf
712 CALL timeset(routinen, handle)
714 NULLIFY (tmp_fm_struct)
719 CALL cp_fm_get_info(v(ispin), ncol_global=mv, nrow_global=nv)
720 CALL cp_fm_get_info(psi0(ispin), ncol_global=mp, nrow_global=np)
722 CALL cp_fm_struct_create(tmp_fm_struct, nrow_global=nv, ncol_global=mp, &
723 para_env=v(ispin)%matrix_struct%para_env, &
724 context=v(ispin)%matrix_struct%context)
725 CALL cp_fm_create(buf, tmp_fm_struct)
726 CALL cp_fm_struct_release(tmp_fm_struct)
728 CALL cp_fm_get_info(buf, ncol_global=mt, nrow_global=nt)
735 CALL parallel_gemm(
'T',
'N', mv, mp, nv, 1.0_dp, v(ispin), s_psi0(ispin), 0.0_dp, buf)
737 CALL parallel_gemm(
'N',
'T', nv, mv, mp, -1.0_dp, psi0(ispin), buf, 1.0_dp, v(ispin))
739 CALL cp_fm_release(buf)
742 CALL timestop(handle)
744 END SUBROUTINE preortho
752 SUBROUTINE postortho(v, psi0, S_psi0)
755 TYPE(cp_fm_type),
DIMENSION(:),
INTENT(IN) :: v, psi0, s_psi0
757 CHARACTER(LEN=*),
PARAMETER :: routinen =
'postortho'
759 INTEGER :: handle, ispin, mp, mt, mv, np, nspins, &
761 TYPE(cp_fm_struct_type),
POINTER :: tmp_fm_struct
762 TYPE(cp_fm_type) :: buf
764 CALL timeset(routinen, handle)
766 NULLIFY (tmp_fm_struct)
771 CALL cp_fm_get_info(v(ispin), ncol_global=mv, nrow_global=nv)
772 CALL cp_fm_get_info(psi0(ispin), ncol_global=mp, nrow_global=np)
774 CALL cp_fm_struct_create(tmp_fm_struct, nrow_global=nv, ncol_global=mp, &
775 para_env=v(ispin)%matrix_struct%para_env, &
776 context=v(ispin)%matrix_struct%context)
777 CALL cp_fm_create(buf, tmp_fm_struct)
778 CALL cp_fm_struct_release(tmp_fm_struct)
780 CALL cp_fm_get_info(buf, ncol_global=mt, nrow_global=nt)
787 CALL parallel_gemm(
'T',
'N', mv, mp, nv, 1.0_dp, v(ispin), psi0(ispin), 0.0_dp, buf)
789 CALL parallel_gemm(
'N',
'T', nv, mv, mp, -1.0_dp, s_psi0(ispin), buf, 1.0_dp, v(ispin))
791 CALL cp_fm_release(buf)
794 CALL timestop(handle)
796 END SUBROUTINE postortho
808 TYPE(qs_environment_type),
POINTER :: qs_env
809 TYPE(section_vals_type),
POINTER :: linres_section
810 TYPE(cp_fm_type),
DIMENSION(:),
INTENT(IN) :: vec
811 INTEGER,
INTENT(IN) :: ivec
812 CHARACTER(LEN=*) :: tag
813 INTEGER,
INTENT(IN),
OPTIONAL :: ind
815 CHARACTER(LEN=*),
PARAMETER :: routinen =
'linres_write_restart'
817 CHARACTER(LEN=default_path_length) :: filename
818 CHARACTER(LEN=default_string_length) :: my_middle, my_pos, my_status
819 INTEGER :: handle, i, i_block, ia, ie, iounit, &
820 ispin, j, max_block, nao, nmo, nspins, &
822 REAL(kind=dp),
DIMENSION(:, :),
POINTER :: vecbuffer
823 TYPE(cp_fm_type),
POINTER :: mo_coeff
824 TYPE(cp_logger_type),
POINTER :: logger
825 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos
826 TYPE(mp_para_env_type),
POINTER :: para_env
827 TYPE(section_vals_type),
POINTER :: print_key
829 NULLIFY (logger, mo_coeff, mos, para_env, print_key, vecbuffer)
831 CALL timeset(routinen, handle)
833 logger => cp_get_default_logger()
835 IF (btest(cp_print_key_should_output(logger%iter_info, linres_section,
"PRINT%RESTART", &
836 used_print_key=print_key), &
839 iounit = cp_print_key_unit_nr(logger, linres_section, &
840 "PRINT%PROGRAM_RUN_INFO", extension=
".Log")
842 CALL get_qs_env(qs_env=qs_env, &
848 my_status =
"REPLACE"
850 CALL xstring(tag, ia, ie)
851 IF (
PRESENT(ind))
THEN
852 my_middle =
"RESTART-"//tag(ia:ie)//trim(adjustl(cp_to_string(ivec)))
854 my_middle =
"RESTART-"//tag(ia:ie)
860 rst_unit = cp_print_key_unit_nr(logger, linres_section,
"PRINT%RESTART", &
861 extension=
".lr", middle_name=trim(my_middle), file_status=trim(my_status), &
862 file_position=trim(my_pos), file_action=
"WRITE", file_form=
"UNFORMATTED")
864 filename = cp_print_key_generate_filename(logger, print_key, &
865 extension=
".lr", middle_name=trim(my_middle), my_local=.false.)
868 WRITE (unit=iounit, fmt=
"(T2,A)") &
869 "LINRES| Writing response functions to the restart file <"//trim(adjustl(filename))//
">"
875 CALL get_mo_set(mos(1), mo_coeff=mo_coeff)
876 CALL cp_fm_get_info(mo_coeff, nrow_global=nao, ncol_block=max_block)
877 ALLOCATE (vecbuffer(nao, max_block))
879 IF (
PRESENT(ind))
THEN
880 IF (rst_unit > 0)
WRITE (rst_unit) ind, ivec, nspins, nao
882 IF (rst_unit > 0)
WRITE (rst_unit) ivec, nspins, nao
886 CALL cp_fm_get_info(vec(ispin), ncol_global=nmo)
888 IF (rst_unit > 0)
WRITE (rst_unit) nmo
890 DO i = 1, nmo, max(max_block, 1)
891 i_block = min(max_block, nmo - i + 1)
892 CALL cp_fm_get_submatrix(vec(ispin), vecbuffer, 1, i, nao, i_block)
897 IF (rst_unit > 0)
WRITE (rst_unit) vecbuffer(1:nao, j)
902 DEALLOCATE (vecbuffer)
904 CALL cp_print_key_finished_output(rst_unit, logger, linres_section, &
908 CALL timestop(handle)
922 TYPE(qs_environment_type),
POINTER :: qs_env
923 TYPE(section_vals_type),
POINTER :: linres_section
924 TYPE(cp_fm_type),
DIMENSION(:),
INTENT(IN) :: vec
925 INTEGER,
INTENT(IN) :: ivec
926 CHARACTER(LEN=*) :: tag
927 INTEGER,
INTENT(INOUT),
OPTIONAL :: ind
929 CHARACTER(LEN=*),
PARAMETER :: routinen =
'linres_read_restart'
931 CHARACTER(LEN=default_path_length) :: filename
932 CHARACTER(LEN=default_string_length) :: my_middle
933 INTEGER :: handle, i, i_block, ia, ie, iostat, iounit, ispin, iv, iv1, ivec_tmp, j, &
934 max_block, n_rep_val, nao, nao_tmp, nmo, nmo_tmp, nspins, nspins_tmp, rst_unit
935 LOGICAL :: file_exists
936 REAL(kind=dp),
DIMENSION(:, :),
POINTER :: vecbuffer
937 TYPE(cp_fm_type),
POINTER :: mo_coeff
938 TYPE(cp_logger_type),
POINTER :: logger
939 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos
940 TYPE(mp_para_env_type),
POINTER :: para_env
941 TYPE(section_vals_type),
POINTER :: print_key
943 file_exists = .false.
945 CALL timeset(routinen, handle)
947 NULLIFY (mos, para_env, logger, print_key, vecbuffer)
948 logger => cp_get_default_logger()
950 iounit = cp_print_key_unit_nr(logger, linres_section, &
951 "PRINT%PROGRAM_RUN_INFO", extension=
".Log")
953 CALL get_qs_env(qs_env=qs_env, &
960 IF (para_env%is_source())
THEN
961 CALL section_vals_val_get(linres_section,
"WFN_RESTART_FILE_NAME", &
964 CALL xstring(tag, ia, ie)
965 IF (
PRESENT(ind))
THEN
966 my_middle =
"RESTART-"//tag(ia:ie)//trim(adjustl(cp_to_string(ivec)))
968 my_middle =
"RESTART-"//tag(ia:ie)
971 IF (n_rep_val > 0)
THEN
972 CALL section_vals_val_get(linres_section,
"WFN_RESTART_FILE_NAME", c_val=filename)
973 CALL xstring(filename, ia, ie)
974 filename = filename(ia:ie)//trim(my_middle)//
".lr"
977 print_key => section_vals_get_subs_vals(linres_section,
"PRINT%RESTART")
978 filename = cp_print_key_generate_filename(logger, print_key, &
979 extension=
".lr", middle_name=trim(my_middle), my_local=.false.)
981 INQUIRE (file=filename, exist=file_exists)
984 IF (file_exists)
THEN
985 CALL open_file(file_name=trim(filename), &
986 file_action=
"READ", &
987 file_form=
"UNFORMATTED", &
988 file_position=
"REWIND", &
990 unit_number=rst_unit)
992 IF (iounit > 0)
WRITE (iounit,
"(T2,A)") &
993 "LINRES| Reading response wavefunctions from the restart file <"//trim(adjustl(filename))//
">"
995 IF (iounit > 0)
WRITE (iounit,
"(T2,A)") &
996 "LINRES| Restart file <"//trim(adjustl(filename))//
"> not found"
1000 CALL para_env%bcast(file_exists)
1002 IF (file_exists)
THEN
1004 CALL get_mo_set(mos(1), mo_coeff=mo_coeff)
1005 CALL cp_fm_get_info(mo_coeff, nrow_global=nao, ncol_block=max_block)
1007 ALLOCATE (vecbuffer(nao, max_block))
1010 IF (
PRESENT(ind))
THEN
1017 IF (
PRESENT(ind))
THEN
1018 IF (rst_unit > 0)
READ (rst_unit, iostat=iostat) ind, ivec_tmp, nspins_tmp, nao_tmp
1019 CALL para_env%bcast(iostat)
1020 CALL para_env%bcast(ind)
1022 IF (rst_unit > 0)
READ (rst_unit, iostat=iostat) ivec_tmp, nspins_tmp, nao_tmp
1023 CALL para_env%bcast(iostat)
1026 IF (iostat .NE. 0)
EXIT
1027 CALL para_env%bcast(ivec_tmp)
1028 CALL para_env%bcast(nspins_tmp)
1029 CALL para_env%bcast(nao_tmp)
1033 IF (nspins_tmp .NE. nspins) cpabort(
"nspins not consistent")
1034 IF (nao_tmp .NE. nao) cpabort(
"nao not consistent")
1036 DO ispin = 1, nspins
1037 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff)
1038 CALL cp_fm_get_info(mo_coeff, ncol_global=nmo)
1040 IF (rst_unit > 0)
READ (rst_unit) nmo_tmp
1041 CALL para_env%bcast(nmo_tmp)
1042 IF (nmo_tmp .NE. nmo) cpabort(
"nmo not consistent")
1045 DO i = 1, nmo, max(max_block, 1)
1046 i_block = min(max_block, nmo - i + 1)
1048 IF (rst_unit > 0)
READ (rst_unit) vecbuffer(1:nao, j)
1050 IF (iv .EQ. ivec_tmp)
THEN
1051 CALL para_env%bcast(vecbuffer)
1052 CALL cp_fm_set_submatrix(vec(ispin), vecbuffer, 1, i, nao, i_block)
1056 IF (ivec .EQ. ivec_tmp)
EXIT
1059 IF (iostat /= 0)
THEN
1060 IF (iounit > 0)
WRITE (iounit,
"(T2,A)") &
1061 "LINRES| Restart file <"//trim(adjustl(filename))//
"> not found"
1064 DEALLOCATE (vecbuffer)
1068 IF (para_env%is_source())
THEN
1069 IF (file_exists)
CALL close_file(unit_number=rst_unit)
1072 CALL timestop(handle)
1082 SUBROUTINE check_p_env_init(p_env, linres_control, nspins)
1084 TYPE(qs_p_env_type) :: p_env
1085 TYPE(linres_control_type),
INTENT(IN) :: linres_control
1086 INTEGER,
INTENT(IN) :: nspins
1088 INTEGER :: ispin, ncol, nrow
1090 IF (linres_control%preconditioner_type /= ot_precond_none)
THEN
1091 cpassert(
ASSOCIATED(p_env%preconditioner))
1092 DO ispin = 1, nspins
1093 CALL cp_fm_get_info(p_env%PS_psi0(ispin), nrow_global=nrow, ncol_global=ncol)
1094 cpassert(nrow == p_env%n_ao(ispin))
1095 cpassert(ncol == p_env%n_mo(ispin))
1099 END SUBROUTINE check_p_env_init
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
DBCSR operations in CP2K.
subroutine, public cp_dbcsr_sm_fm_multiply(matrix, fm_in, fm_out, ncol, alpha, beta)
multiply a dbcsr with a fm matrix
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.
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.
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.
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
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_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,...
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...
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...
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
integer, parameter, public default_path_length
Machine interface based on Fortran 2003 and POSIX.
subroutine, public m_flush(lunit)
flushes units if the &GLOBAL flag is set accordingly
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
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, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_RI_aux_kp, matrix_s, matrix_s_RI_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, WannierCentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, rhs)
Get the QUICKSTEP environment.
subroutine, public prepare_gapw_den(qs_env, local_rho_set, do_rho0, kind_set_external)
...
subroutine, public apply_op_2(qs_env, p_env, c0, Av)
...
localize wavefunctions linear response scf
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_solver(p_env, qs_env, psi1, h1_psi0, psi0_order, iounit, should_stop)
scf loop to optimize the first order wavefunctions (psi1) given a perturbation as an operator applied...
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...
subroutine, public qs_loc_driver(qs_env, qs_loc_env, print_loc_section, myspin, ext_mo_coeff)
set up the calculation of localized orbitals
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.
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)
...