54#include "./../base/base_uses.f90"
59 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'rt_projection_mo_utils'
75 INTEGER :: i_rep, j_td, n_rep_val, nbr_mo_td_max, &
77 INTEGER,
DIMENSION(:),
POINTER :: tmp_ints
83 NULLIFY (rtp_control%proj_mo_list, tmp_ints, proj_mo, logger, &
84 input, proj_mo_section, print_key, mos)
92 ALLOCATE (rtp_control%proj_mo_list(nrep))
95 NULLIFY (rtp_control%proj_mo_list(i_rep)%proj_mo)
96 ALLOCATE (rtp_control%proj_mo_list(i_rep)%proj_mo)
97 proj_mo => rtp_control%proj_mo_list(i_rep)%proj_mo
100 c_val=proj_mo%ref_mo_file_name)
103 i_val=proj_mo%ref_nlumo)
106 IF (.NOT. rtp_control%fixed_ions)
THEN
108 l_val=proj_mo%propagate_ref)
112 IF (proj_mo%ref_mo_file_name ==
"DEFAULT")
THEN
114 IF (n_rep_val > 0)
THEN
121 extension=
".wfn", my_local=.false.)
127 ALLOCATE (proj_mo%ref_mo_index, source=tmp_ints(:))
129 i_val=proj_mo%ref_mo_spin)
132 CALL read_reference_mo_from_wfn(qs_env, proj_mo)
136 l_val=proj_mo%sum_on_all_ref)
139 i_val=proj_mo%td_mo_spin)
140 IF (proj_mo%td_mo_spin >
SIZE(mos))
THEN
141 CALL cp_abort(__location__, &
142 "You asked to project the time dependent BETA spin while the "// &
143 "real time DFT run has only one spin defined. "// &
144 "Please set TD_MO_SPIN to 1 or use UKS.")
150 nbr_mo_td_max = mos(proj_mo%td_mo_spin)%mo_coeff%matrix_struct%ncol_global
152 ALLOCATE (proj_mo%td_mo_index, source=tmp_ints(:))
153 IF (proj_mo%td_mo_index(1) == -1)
THEN
154 DEALLOCATE (proj_mo%td_mo_index)
155 ALLOCATE (proj_mo%td_mo_index(nbr_mo_td_max))
156 ALLOCATE (proj_mo%td_mo_occ(nbr_mo_td_max))
157 DO j_td = 1, nbr_mo_td_max
158 proj_mo%td_mo_index(j_td) = j_td
159 proj_mo%td_mo_occ(j_td) = mos(proj_mo%td_mo_spin)%occupation_numbers(proj_mo%td_mo_index(j_td))
162 ALLOCATE (proj_mo%td_mo_occ(
SIZE(proj_mo%td_mo_index)))
163 proj_mo%td_mo_occ(:) = 0.0_dp
164 DO j_td = 1,
SIZE(proj_mo%td_mo_index)
165 IF (proj_mo%td_mo_index(j_td) > nbr_mo_td_max)
THEN
166 CALL cp_abort(__location__, &
167 "The MO number available in the Time Dependent run "// &
168 "is smaller than the MO number you have required in TD_MO_INDEX.")
170 proj_mo%td_mo_occ(j_td) = mos(proj_mo%td_mo_spin)%occupation_numbers(proj_mo%td_mo_index(j_td))
175 l_val=proj_mo%sum_on_all_td)
187 SUBROUTINE read_reference_mo_from_wfn(qs_env, proj_mo)
191 INTEGER :: i_ref, ispin, mo_index, natom, &
192 nbr_mo_max, nbr_ref_mo, nspins, &
193 real_mo_index, restart_unit
197 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s
199 TYPE(
mo_set_type),
DIMENSION(:),
POINTER :: mo_qs, mo_ref_temp
203 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
205 NULLIFY (mo_qs, mo_ref_temp, mo_set, qs_kind_set, particle_set, para_env, dft_control, &
206 mo_ref_fmstruct, matrix_s)
209 qs_kind_set=qs_kind_set, &
210 particle_set=particle_set, &
211 dft_control=dft_control, &
212 matrix_s_kp=matrix_s, &
216 natom =
SIZE(particle_set, 1)
220 ALLOCATE (mo_ref_temp(nspins))
223 mo_set => mo_qs(ispin)
224 mo_ref_temp(ispin)%nmo = mo_set%nmo + proj_mo%ref_nlumo
225 NULLIFY (mo_ref_fmstruct)
227 ncol_global=mo_ref_temp(ispin)%nmo, para_env=para_env, context=mo_set%mo_coeff%matrix_struct%context)
228 NULLIFY (mo_ref_temp(ispin)%mo_coeff)
229 ALLOCATE (mo_ref_temp(ispin)%mo_coeff)
230 CALL cp_fm_create(mo_ref_temp(ispin)%mo_coeff, mo_ref_fmstruct)
233 mo_ref_temp(ispin)%nao = mo_set%nao
234 mo_ref_temp(ispin)%homo = mo_set%homo
235 mo_ref_temp(ispin)%nelectron = mo_set%nelectron
236 ALLOCATE (mo_ref_temp(ispin)%eigenvalues(mo_ref_temp(ispin)%nmo))
237 ALLOCATE (mo_ref_temp(ispin)%occupation_numbers(mo_ref_temp(ispin)%nmo))
241 IF (para_env%is_source())
THEN
242 INQUIRE (file=trim(proj_mo%ref_mo_file_name), exist=is_file)
243 IF (.NOT. is_file)
THEN
244 CALL cp_abort(__location__, &
245 "Reference file not found! Name of the file CP2K looked for: "//trim(proj_mo%ref_mo_file_name))
248 CALL open_file(file_name=proj_mo%ref_mo_file_name, &
249 file_action=
"READ", &
250 file_form=
"UNFORMATTED", &
252 unit_number=restart_unit)
256 particle_set=particle_set, natom=natom, &
257 rst_unit=restart_unit)
259 IF (para_env%is_source())
CALL close_file(unit_number=restart_unit)
261 IF (proj_mo%ref_mo_spin >
SIZE(mo_ref_temp))
THEN
262 CALL cp_abort(__location__, &
263 "Projection on spin BETA is not possible as the reference wavefunction "// &
264 "only has one spin channel. Use a reference .wfn calculated with UKS/LSD, or set REF_MO_SPIN to 1")
268 nbr_mo_max = mo_ref_temp(proj_mo%ref_mo_spin)%mo_coeff%matrix_struct%ncol_global
269 IF (proj_mo%ref_mo_index(1) == -1)
THEN
270 DEALLOCATE (proj_mo%ref_mo_index)
271 ALLOCATE (proj_mo%ref_mo_index(nbr_mo_max))
272 DO i_ref = 1, nbr_mo_max
273 proj_mo%ref_mo_index(i_ref) = i_ref
276 DO i_ref = 1,
SIZE(proj_mo%ref_mo_index)
277 IF (proj_mo%ref_mo_index(i_ref) > nbr_mo_max)
THEN
278 CALL cp_abort(__location__, &
279 "The number of MOs available in the reference wavefunction "// &
280 "is smaller than the MO number you have requested in REF_MO_INDEX.")
284 nbr_ref_mo =
SIZE(proj_mo%ref_mo_index)
286 IF (nbr_ref_mo > nbr_mo_max)
THEN
287 CALL cp_abort(__location__, &
288 "The total number of requested MOs is larger than what is available in the reference wavefunction. "// &
289 "If you are trying to project onto virtual states, make sure they are included in the .wfn file "// &
290 "e.g., by the ADDED_MOS keyword in the SCF section of the input when calculating your reference.")
294 ALLOCATE (proj_mo%mo_ref(nbr_ref_mo))
296 context=mo_ref_temp(proj_mo%ref_mo_spin)%mo_coeff%matrix_struct%context, &
297 nrow_global=mo_ref_temp(proj_mo%ref_mo_spin)%mo_coeff%matrix_struct%nrow_global, &
300 IF (dft_control%rtp_control%fixed_ions)
THEN
301 CALL cp_fm_create(mo_coeff_temp, mo_ref_fmstruct,
'mo_ref')
304 DO mo_index = 1, nbr_ref_mo
305 real_mo_index = proj_mo%ref_mo_index(mo_index)
306 IF (real_mo_index > nbr_mo_max)
THEN
307 CALL cp_abort(__location__, &
308 "One of reference mo index is larger then the total number of available mo in the .wfn file.")
312 CALL cp_fm_create(proj_mo%mo_ref(mo_index), mo_ref_fmstruct,
'mo_ref')
313 IF (dft_control%rtp_control%fixed_ions)
THEN
315 CALL cp_fm_to_fm(mo_ref_temp(proj_mo%ref_mo_spin)%mo_coeff, mo_coeff_temp, &
317 source_start=real_mo_index, &
322 CALL cp_fm_to_fm(mo_ref_temp(proj_mo%ref_mo_spin)%mo_coeff, proj_mo%mo_ref(mo_index), &
324 source_start=real_mo_index, &
333 DEALLOCATE (mo_ref_temp)
336 IF (dft_control%rtp_control%fixed_ions)
THEN
340 END SUBROUTINE read_reference_mo_from_wfn
353 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: mos_new
357 INTEGER :: i_ref, nbr_ref_mo, nbr_ref_td
358 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: phase, popu, sum_popu_ref
362 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s
366 NULLIFY (dft_control, input, proj_mo_section, print_mo_section, logger)
371 dft_control=dft_control, &
380 IF (proj_mo%propagate_ref)
CALL propagate_ref_mo(qs_env, proj_mo)
384 print_mo_section,
""), &
389 IF (.NOT. dft_control%rtp_control%fixed_ions)
THEN
391 matrix_s_kp=matrix_s)
393 context=proj_mo%mo_ref(1)%matrix_struct%context, &
394 nrow_global=proj_mo%mo_ref(1)%matrix_struct%nrow_global, &
396 CALL cp_fm_create(s_mo_ref, mo_ref_fmstruct,
'S_mo_ref')
399 nbr_ref_mo =
SIZE(proj_mo%ref_mo_index)
400 nbr_ref_td =
SIZE(proj_mo%td_mo_index)
401 ALLOCATE (popu(nbr_ref_td))
402 ALLOCATE (phase(nbr_ref_td))
404 IF (proj_mo%sum_on_all_ref)
THEN
405 ALLOCATE (sum_popu_ref(nbr_ref_td))
406 sum_popu_ref(:) = 0.0_dp
407 DO i_ref = 1, nbr_ref_mo
409 IF (.NOT. dft_control%rtp_control%fixed_ions)
THEN
411 CALL compute_proj_mo(popu, phase, mos_new, proj_mo, i_ref, s_mo_ref=s_mo_ref)
413 CALL compute_proj_mo(popu, phase, mos_new, proj_mo, i_ref)
415 sum_popu_ref(:) = sum_popu_ref(:) + popu(:)
417 IF (proj_mo%sum_on_all_td)
THEN
418 CALL write_proj_mo(qs_env, print_mo_section, proj_mo, popu_tot=sum(sum_popu_ref), n_proj=n_proj)
420 CALL write_proj_mo(qs_env, print_mo_section, proj_mo, popu=sum_popu_ref, n_proj=n_proj)
422 DEALLOCATE (sum_popu_ref)
424 DO i_ref = 1, nbr_ref_mo
425 IF (.NOT. dft_control%rtp_control%fixed_ions)
THEN
427 CALL compute_proj_mo(popu, phase, mos_new, proj_mo, i_ref, s_mo_ref=s_mo_ref)
429 CALL compute_proj_mo(popu, phase, mos_new, proj_mo, i_ref)
431 IF (proj_mo%sum_on_all_td)
THEN
432 CALL write_proj_mo(qs_env, print_mo_section, proj_mo, i_ref=i_ref, popu_tot=sum(popu), n_proj=n_proj)
435 CALL write_proj_mo(qs_env, print_mo_section, proj_mo, i_ref=i_ref, popu=popu, phase=phase, n_proj=n_proj)
440 IF (.NOT. dft_control%rtp_control%fixed_ions)
THEN
459 SUBROUTINE compute_proj_mo(popu, phase, mos_new, proj_mo, i_ref, S_mo_ref)
460 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: popu, phase
461 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: mos_new
466 CHARACTER(len=*),
PARAMETER :: routinen =
'compute_proj_mo'
468 INTEGER :: handle, j_td, nbr_ref_td, spin_td
470 REAL(kind=
dp) :: imag_proj, real_proj
474 CALL timeset(routinen, handle)
477 IF (
PRESENT(s_mo_ref)) is_emd = .true.
479 nbr_ref_td =
SIZE(popu)
480 spin_td = proj_mo%td_mo_spin
483 context=mos_new(1)%matrix_struct%context, &
484 nrow_global=mos_new(1)%matrix_struct%nrow_global, &
486 CALL cp_fm_create(mo_coeff_temp, mo_ref_fmstruct,
'mo_temp')
488 DO j_td = 1, nbr_ref_td
491 CALL cp_fm_to_fm(mos_new(2*spin_td - 1), mo_coeff_temp, &
493 source_start=proj_mo%td_mo_index(j_td), &
497 CALL cp_fm_trace(mo_coeff_temp, s_mo_ref, real_proj)
500 CALL cp_fm_trace(mo_coeff_temp, proj_mo%mo_ref(i_ref), real_proj)
505 CALL cp_fm_to_fm(mos_new(2*spin_td), mo_coeff_temp, &
507 source_start=proj_mo%td_mo_index(j_td), &
511 CALL cp_fm_trace(mo_coeff_temp, s_mo_ref, imag_proj)
513 CALL cp_fm_trace(mo_coeff_temp, proj_mo%mo_ref(i_ref), imag_proj)
517 phase(j_td) = atan2(imag_proj, real_proj)
518 popu(j_td) = proj_mo%td_mo_occ(j_td)*(real_proj**2 + imag_proj**2)
524 CALL timestop(handle)
526 END SUBROUTINE compute_proj_mo
541 SUBROUTINE write_proj_mo(qs_env, print_mo_section, proj_mo, i_ref, popu, phase, popu_tot, n_proj)
545 INTEGER,
OPTIONAL :: i_ref
546 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL :: popu, phase
547 REAL(kind=
dp),
OPTIONAL :: popu_tot
548 INTEGER,
OPTIONAL :: n_proj
550 CHARACTER(LEN=default_string_length) :: ext, filename
551 INTEGER :: j_td, output_unit, print_unit
559 IF (.NOT. (output_unit > 0))
RETURN
561 IF (proj_mo%sum_on_all_ref)
THEN
562 ext =
"-"//trim(adjustl(
cp_to_string(n_proj)))//
"-ALL_REF.dat"
567 trim(adjustl(
cp_to_string(proj_mo%ref_mo_index(i_ref))))// &
574 IF (print_unit /= output_unit)
THEN
575 INQUIRE (unit=print_unit, name=filename)
576 WRITE (unit=print_unit, fmt=
"(/,(T2,A,T40,I6))") &
577 "Real time propagation step:", qs_env%sim_step
579 WRITE (unit=output_unit, fmt=
"(/,T2,A)")
"PROJECTION MO"
582 IF (proj_mo%sum_on_all_ref)
THEN
583 WRITE (print_unit,
"(T3,A)") &
584 "Projection on all the required MO number from the reference file "// &
585 trim(proj_mo%ref_mo_file_name)
586 IF (proj_mo%sum_on_all_td)
THEN
587 WRITE (print_unit,
"(T3, A, E20.12)") &
588 "The sum over all the TD MOs population:", popu_tot
590 WRITE (print_unit,
"(T3,A)") &
591 "For each TD MOs required is printed: Population "
592 DO j_td = 1,
SIZE(popu)
593 WRITE (print_unit,
"(T5,1(E20.12, 1X))") popu(j_td)
597 WRITE (print_unit,
"(T3,A)") &
598 "Projection on the MO number "// &
599 trim(adjustl(
cp_to_string(proj_mo%ref_mo_index(i_ref))))// &
600 " from the reference file "// &
601 trim(proj_mo%ref_mo_file_name)
603 IF (proj_mo%sum_on_all_td)
THEN
604 WRITE (print_unit,
"(T3, A, E20.12)") &
605 "The sum over all the TD MOs population:", popu_tot
607 WRITE (print_unit,
"(T3,A)") &
608 "For each TD MOs required is printed: Population & Phase [rad] "
609 DO j_td = 1,
SIZE(popu)
610 WRITE (print_unit,
"(T5,2(E20.12, E16.8, 1X))") popu(j_td), phase(j_td)
617 END SUBROUTINE write_proj_mo
629 SUBROUTINE propagate_ref_mo(qs_env, proj_mo)
641 CALL get_rtp(rtp=rtp, sinvb=sinvb, dt=dt)
644 context=proj_mo%mo_ref(1)%matrix_struct%context, &
645 nrow_global=proj_mo%mo_ref(1)%matrix_struct%nrow_global, &
649 DO i_ref = 1,
SIZE(proj_mo%ref_mo_index)
658 END SUBROUTINE propagate_ref_mo
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
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_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
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 ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
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
Interface to the message passing library MPI.
Define the data structure for the particle information.
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, matrix_vhxc, 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, xcint_weights, 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.
Define the quickstep kind type and their sub types.
Definition and initialisation of the mo data type.
subroutine, public read_mos_restart_low(mos, para_env, qs_kind_set, particle_set, natom, rst_unit, multiplicity, rt_mos, natom_mismatch)
Reading the mos from apreviously defined restart file.
Definition and initialisation of the mo data type.
subroutine, public deallocate_mo_set(mo_set)
Deallocate a wavefunction data structure.
Function related to MO projection in RTP calculations.
subroutine, public init_mo_projection(qs_env, rtp_control)
Initialize the mo projection objects for time dependent run.
subroutine, public compute_and_write_proj_mo(qs_env, mos_new, proj_mo, n_proj)
Compute the projection of the current MO coefficients on reference ones and write the results.
Types and set_get for real time propagation depending on runtype and diagonalization method different...
subroutine, public get_rtp(rtp, exp_h_old, exp_h_new, h_last_iter, rho_old, rho_next, rho_new, mos, mos_new, mos_old, mos_next, s_inv, s_half, s_minus_half, b_mat, c_mat, propagator_matrix, mixing, mixing_factor, s_der, dt, nsteps, sinvh, sinvh_imag, sinvb, admm_mos)
...
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
Provides all information about a quickstep kind.