46#include "./base/base_uses.f90"
52 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_tddfpt2_restart'
54 LOGICAL,
PARAMETER,
PRIVATE :: debug_this_module = .false.
56 INTEGER,
PARAMETER,
PRIVATE :: nderivs = 3
57 INTEGER,
PARAMETER,
PRIVATE :: maxspins = 2
77 TYPE(
cp_fm_type),
DIMENSION(:, :),
INTENT(in) :: evects
78 REAL(kind=
dp),
DIMENSION(:),
INTENT(in) :: evals
84 CHARACTER(LEN=*),
PARAMETER :: routinen =
'tddfpt_write_restart'
86 INTEGER :: handle, ispin, istate, nao, nspins, &
88 INTEGER,
DIMENSION(maxspins) :: nmo_occ
91 CALL timeset(routinen, handle)
93 nspins =
SIZE(evects, 1)
94 nstates =
SIZE(evects, 2)
96 IF (debug_this_module)
THEN
97 cpassert(
SIZE(evals) == nstates)
105 nmo_occ(ispin) =
SIZE(gs_mos(ispin)%evals_occ)
109 extension=
".tdwfn", file_status=
"REPLACE", file_action=
"WRITE", &
110 do_backup=.true., file_form=
"UNFORMATTED")
113 WRITE (ounit) nstates, nspins, nao
114 WRITE (ounit) nmo_occ(1:nspins)
118 DO istate = 1, nstates
139 CALL timestop(handle)
161 fm_pool_ao_mo_occ, blacs_env_global)
RESULT(nstates_read)
162 TYPE(
cp_fm_type),
DIMENSION(:, :),
INTENT(inout) :: evects
163 REAL(kind=
dp),
DIMENSION(:),
INTENT(out) :: evals
170 INTEGER :: nstates_read
172 CHARACTER(LEN=*),
PARAMETER :: routinen =
'tddfpt_read_restart'
174 CHARACTER(len=20) :: read_str, ref_str
175 CHARACTER(LEN=default_path_length) :: filename
176 INTEGER :: handle, ispin, istate, iunit, n_rep_val, &
177 nao, nao_read, nspins, nspins_read, &
179 INTEGER,
DIMENSION(maxspins) :: nmo_occ, nmo_occ_read
181 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: evals_read
185 CALL timeset(routinen, handle)
187 cpassert(
ASSOCIATED(tddfpt_section))
191 IF (n_rep_val > 0)
THEN
196 extension=
".tdwfn", my_local=.false.)
199 CALL blacs_env_global%get(para_env=para_env_global)
201 IF (para_env_global%is_source())
THEN
206 CALL para_env_global%bcast(nstates_read)
208 CALL cp_warn(__location__, &
209 "User requested to restart the TDDFPT wave functions from the file '"//trim(filename)// &
210 "' which does not exist. Guess wave functions will be constructed using Kohn-Sham orbitals.")
211 CALL timestop(handle)
215 CALL open_file(file_name=filename, file_action=
"READ", file_form=
"UNFORMATTED", &
216 file_status=
"OLD", unit_number=iunit)
219 nspins =
SIZE(evects, 1)
220 nstates =
SIZE(evects, 2)
224 nmo_occ(ispin) =
SIZE(gs_mos(ispin)%evals_occ)
227 IF (para_env_global%is_source())
THEN
228 READ (iunit) nstates_read, nspins_read, nao_read
230 IF (nspins_read /= nspins)
THEN
233 CALL cp_abort(__location__, &
234 "Restarted TDDFPT wave function contains incompatible number of spin components ("// &
235 trim(read_str)//
" instead of "//trim(ref_str)//
").")
238 IF (nao_read /= nao)
THEN
241 CALL cp_abort(__location__, &
242 "Incompatible number of atomic orbitals ("//trim(read_str)//
" instead of "//trim(ref_str)//
").")
245 READ (iunit) nmo_occ_read(1:nspins)
248 IF (nmo_occ_read(ispin) /= nmo_occ(ispin))
THEN
249 CALL cp_abort(__location__, &
250 "Incompatible number of electrons and/or multiplicity.")
254 IF (nstates_read /= nstates)
THEN
257 CALL cp_warn(__location__, &
258 "TDDFPT restart file contains "//trim(read_str)// &
259 " wave function(s) however "//trim(ref_str)// &
260 " excited states were requested.")
263 CALL para_env_global%bcast(nstates_read)
266 IF (nstates_read <= 0)
THEN
267 CALL timestop(handle)
271 IF (para_env_global%is_source())
THEN
272 ALLOCATE (evals_read(nstates_read))
273 READ (iunit) evals_read
274 IF (nstates_read <= nstates)
THEN
275 evals(1:nstates_read) = evals_read(1:nstates_read)
277 evals(1:nstates) = evals_read(1:nstates)
279 DEALLOCATE (evals_read)
281 CALL para_env_global%bcast(evals)
283 DO istate = 1, nstates_read
285 IF (istate <= nstates)
THEN
295 IF (para_env_global%is_source()) &
298 CALL timestop(handle)
314 matrix_s, S_evects, sub_env)
316 TYPE(
cp_fm_type),
DIMENSION(:, :),
INTENT(in) :: evects
317 REAL(kind=
dp),
DIMENSION(:),
INTENT(in) :: evals
322 TYPE(
dbcsr_type),
INTENT(in),
POINTER :: matrix_s
323 TYPE(
cp_fm_type),
DIMENSION(:, :),
INTENT(INOUT) :: s_evects
326 CHARACTER(LEN=*),
PARAMETER :: routinen =
'tddfpt_write_newtonx_output'
328 INTEGER :: handle, iocc, ispin, istate, ivirt, nao, &
329 nspins, nstates, ounit
330 INTEGER,
DIMENSION(maxspins) :: nmo_occ, nmo_virt
331 LOGICAL :: print_phases, print_virtuals, &
333 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: phase_evects
335 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: evects_mo
338 CALL timeset(routinen, handle)
339 CALL section_vals_val_get(tddfpt_print_section,
"NAMD_PRINT%PRINT_VIRTUALS", l_val=print_virtuals)
341 CALL section_vals_val_get(tddfpt_print_section,
"NAMD_PRINT%SCALE_WITH_PHASES", l_val=scale_with_phases)
343 nspins =
SIZE(evects, 1)
344 nstates =
SIZE(evects, 2)
346 IF (debug_this_module)
THEN
347 cpassert(
SIZE(evals) == nstates)
349 cpassert(nstates > 0)
354 IF (sub_env%is_split)
THEN
355 CALL cp_abort(__location__,
"NEWTONX interface print not possible when states"// &
356 " are distributed to different CPU pools.")
360 extension=
".inp", file_form=
"FORMATTED", file_action=
"WRITE", file_status=
"REPLACE")
364 IF (print_virtuals)
THEN
365 ALLOCATE (evects_mo(nspins, nstates))
366 DO istate = 1, nstates
371 nmo_occ(ispin) =
SIZE(gs_mos(ispin)%evals_occ)
372 nmo_virt(ispin) =
SIZE(gs_mos(ispin)%evals_virt)
374 context=sub_env%blacs_env, &
375 nrow_global=nmo_virt(ispin), ncol_global=nmo_occ(ispin))
379 ncol=nmo_occ(ispin), alpha=1.0_dp, beta=0.0_dp)
382 DO istate = 1, nstates
389 gs_mos(ispin)%mos_virt, &
390 s_evects(ispin, istate), &
392 evects_mo(ispin, istate))
397 DO istate = 1, nstates
400 IF (.NOT. print_virtuals)
THEN
403 WRITE (ounit,
"(/,A)")
"ES EIGENVECTORS SIZE"
410 WRITE (ounit,
"(/,A)")
"ES EIGENVECTORS SIZE"
417 nmo_occ(ispin) =
SIZE(gs_mos(ispin)%evals_occ)
418 ALLOCATE (phase_evects(nmo_occ(ispin)))
419 IF (print_virtuals)
THEN
420 CALL compute_phase_eigenvectors(evects_mo(ispin, istate), phase_evects, sub_env)
422 CALL compute_phase_eigenvectors(evects(ispin, istate), phase_evects, sub_env)
425 WRITE (ounit,
"(/,A,/)")
"PHASES ES EIGENVECTORS"
426 DO iocc = 1, nmo_occ(ispin)
427 WRITE (ounit,
"(F20.14)") phase_evects(iocc)
430 DEALLOCATE (phase_evects)
435 IF (print_virtuals)
THEN
441 WRITE (ounit,
"(/,A)")
"OCCUPIED MOS SIZE"
448 WRITE (ounit,
"(A)")
"OCCUPIED MO EIGENVALUES"
450 nmo_occ(ispin) =
SIZE(gs_mos(ispin)%evals_occ)
451 DO iocc = 1, nmo_occ(ispin)
452 WRITE (ounit,
"(F20.14)") gs_mos(ispin)%evals_occ(iocc)
457 IF (print_virtuals)
THEN
460 WRITE (ounit,
"(/,A)")
"VIRTUAL MOS SIZE"
467 WRITE (ounit,
"(A)")
"VIRTUAL MO EIGENVALUES"
469 nmo_virt(ispin) =
SIZE(gs_mos(ispin)%evals_virt)
470 DO ivirt = 1, nmo_virt(ispin)
471 WRITE (ounit,
"(F20.14)") gs_mos(ispin)%evals_virt(ivirt)
479 IF (print_phases)
THEN
481 WRITE (ounit,
"(A)")
"PHASES OCCUPIED ORBITALS"
483 DO iocc = 1, nmo_occ(ispin)
484 WRITE (ounit,
"(F20.14)") gs_mos(ispin)%phases_occ(iocc)
487 IF (print_virtuals)
THEN
488 WRITE (ounit,
"(A)")
"PHASES VIRTUAL ORBITALS"
490 DO ivirt = 1, nmo_virt(ispin)
491 WRITE (ounit,
"(F20.14)") gs_mos(ispin)%phases_virt(ivirt)
500 CALL timestop(handle)
513 TYPE(
cp_fm_type),
DIMENSION(:, :),
INTENT(in) :: evects
514 INTEGER,
INTENT(in) :: ounit
515 TYPE(
cp_fm_type),
DIMENSION(:, :),
INTENT(INOUT) :: s_evects
516 TYPE(
dbcsr_type),
INTENT(in),
POINTER :: matrix_s
518 CHARACTER(LEN=*),
PARAMETER :: routinen =
'tddfpt_check_orthonormality'
520 INTEGER :: handle, ispin, ivect, jvect, nspins, &
522 INTEGER,
DIMENSION(maxspins) :: nactive
523 REAL(kind=
dp) :: norm
524 REAL(kind=
dp),
DIMENSION(maxspins) :: weights
526 CALL timeset(routinen, handle)
528 nspins =
SIZE(evects, 1)
529 nvects_total =
SIZE(evects, 2)
531 IF (debug_this_module)
THEN
532 cpassert(
SIZE(s_evects, 1) == nspins)
533 cpassert(
SIZE(s_evects, 2) == nvects_total)
537 CALL cp_fm_get_info(matrix=evects(ispin, 1), ncol_global=nactive(ispin))
540 DO jvect = 1, nvects_total
542 DO ivect = 1, jvect - 1
543 CALL cp_fm_trace(evects(:, jvect), s_evects(:, ivect), weights(1:nspins), accurate=.false.)
544 norm = sum(weights(1:nspins))
554 ncol=nactive(ispin), alpha=1.0_dp, beta=0.0_dp)
557 CALL cp_fm_trace(evects(:, jvect), s_evects(:, jvect), weights(1:nspins), accurate=.false.)
559 norm = sum(weights(1:nspins))
560 norm = 1.0_dp/sqrt(norm)
562 IF ((ounit > 0) .AND. debug_this_module)
WRITE (ounit,
'(A,F10.8)')
"norm", norm
566 CALL timestop(handle)
575 SUBROUTINE compute_phase_eigenvectors(evects, phase_evects, sub_env)
580 REAL(kind=
dp),
DIMENSION(:),
INTENT(out) :: phase_evects
583 CHARACTER(len=*),
PARAMETER :: routinen =
'compute_phase_eigenvectors'
584 REAL(kind=
dp),
PARAMETER :: eps_dp = epsilon(0.0_dp)
586 INTEGER :: handle, icol_global, icol_local, irow_global, irow_local, ncol_global, &
587 ncol_local, nrow_global, nrow_local, sign_int
588 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: minrow_neg_array, minrow_pos_array, &
590 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
591 REAL(kind=
dp) :: element
592 REAL(kind=
dp),
CONTIGUOUS,
DIMENSION(:, :), &
595 CALL timeset(routinen, handle)
598 CALL cp_fm_get_info(evects, nrow_global=nrow_global, ncol_global=ncol_global, &
599 nrow_local=nrow_local, ncol_local=ncol_local, local_data=my_block, &
600 row_indices=row_indices, col_indices=col_indices)
602 ALLOCATE (minrow_neg_array(ncol_global), minrow_pos_array(ncol_global), sum_sign_array(ncol_global))
603 minrow_neg_array(:) = nrow_global
604 minrow_pos_array(:) = nrow_global
605 sum_sign_array(:) = 0
607 DO icol_local = 1, ncol_local
608 icol_global = col_indices(icol_local)
610 DO irow_local = 1, nrow_local
611 irow_global = row_indices(irow_local)
613 element = my_block(irow_local, icol_local)
616 IF (element >= eps_dp)
THEN
618 ELSE IF (element <= -eps_dp)
THEN
622 sum_sign_array(icol_global) = sum_sign_array(icol_global) + sign_int
624 IF (sign_int > 0)
THEN
625 IF (minrow_pos_array(icol_global) > irow_global) &
626 minrow_pos_array(icol_global) = irow_global
627 ELSE IF (sign_int < 0)
THEN
628 IF (minrow_neg_array(icol_global) > irow_global) &
629 minrow_neg_array(icol_global) = irow_global
635 CALL sub_env%para_env%sum(sum_sign_array)
636 CALL sub_env%para_env%min(minrow_neg_array)
637 CALL sub_env%para_env%min(minrow_pos_array)
639 DO icol_global = 1, ncol_global
641 IF (sum_sign_array(icol_global) > 0)
THEN
643 phase_evects(icol_global) = 1.0_dp
644 ELSE IF (sum_sign_array(icol_global) < 0)
THEN
646 phase_evects(icol_global) = -1.0_dp
649 IF (minrow_pos_array(icol_global) <= minrow_neg_array(icol_global))
THEN
652 phase_evects(icol_global) = 1.0_dp
655 phase_evects(icol_global) = -1.0_dp
661 DEALLOCATE (minrow_neg_array, minrow_pos_array, sum_sign_array)
663 CALL timestop(handle)
665 END SUBROUTINE compute_phase_eigenvectors
methods related to the blacs parallel environment
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
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.
logical function, public file_exists(file_name)
Checks if file exists, considering also the file discovery mechanism.
basic linear algebra operations for full matrices
subroutine, public cp_fm_column_scale(matrixa, scaling)
scales column i of matrix a with scaling(i)
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....
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
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_write_unformatted(fm, unit)
...
subroutine, public cp_fm_read_unformatted(fm, unit)
...
subroutine, public cp_fm_write_info(matrix, io_unit)
Write nicely formatted info about the FM to the given I/O unit (including the underlying FM struct)
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp)
creates a new full matrix with the given structure
subroutine, public cp_fm_write_formatted(fm, unit, header, value_format)
Write out a full matrix in plain text.
various routines to log and control the output. The idea is that decisions about where to log should ...
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_path_length
Interface to the message passing library MPI.
basic linear algebra operations for full matrixes
integer function, public tddfpt_read_restart(evects, evals, gs_mos, logger, tddfpt_section, tddfpt_print_section, fm_pool_ao_mo_occ, blacs_env_global)
Initialise initial guess vectors by reading (un-normalised) Ritz vectors from a binary restart file.
subroutine, public tddfpt_check_orthonormality(evects, ounit, s_evects, matrix_s)
...
subroutine, public tddfpt_write_newtonx_output(evects, evals, gs_mos, logger, tddfpt_print_section, matrix_s, s_evects, sub_env)
Write Ritz vectors to a binary restart file.
subroutine, public tddfpt_write_restart(evects, evals, gs_mos, logger, tddfpt_print_section)
Write Ritz vectors to a binary restart file.
Utilities for string manipulations.
subroutine, public integer_to_string(inumber, string)
Converts an integer number to a string. The WRITE statement will return an error message,...
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
to create arrays of pools
keeps the information about the structure of 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
Parallel (sub)group environment.
Ground state molecular orbitals.