(git:ccc2433)
qs_loc_states.F
Go to the documentation of this file.
1 !--------------------------------------------------------------------------------------------------!
2 ! CP2K: A general program to perform molecular dynamics simulations !
3 ! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4 ! !
5 ! SPDX-License-Identifier: GPL-2.0-or-later !
6 !--------------------------------------------------------------------------------------------------!
7 
8 ! **************************************************************************************************
9 !> \brief
10 ! **************************************************************************************************
12  USE cp_array_utils, ONLY: cp_1d_r_p_type
13  USE cp_control_types, ONLY: dft_control_type
14  USE cp_fm_types, ONLY: cp_fm_type
17  cp_logger_type
18  USE cp_output_handling, ONLY: cp_p_file,&
20  USE dbcsr_api, ONLY: dbcsr_p_type
23  section_vals_type
24  USE kinds, ONLY: dp
28  USE molecule_types, ONLY: molecule_type
29  USE particle_list_types, ONLY: particle_list_type
30  USE pw_types, ONLY: pw_c1d_gs_type,&
31  pw_r3d_rs_type
32  USE qs_environment_types, ONLY: get_qs_env,&
33  qs_environment_type,&
35  USE qs_loc_main, ONLY: qs_loc_driver
39  USE qs_loc_types, ONLY: qs_loc_env_type
40  USE qs_mo_types, ONLY: mo_set_type
42  USE wannier_states_types, ONLY: wannier_centres_type
43 #include "./base/base_uses.f90"
44 
45  IMPLICIT NONE
46  PRIVATE
47 
48  ! Global parameters
49  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_loc_states'
50  PUBLIC :: get_localization_info
51 
52 ! **************************************************************************************************
53 
54 CONTAINS
55 
56 ! **************************************************************************************************
57 !> \brief Performs localization of the orbitals
58 !> \param qs_env ...
59 !> \param qs_loc_env ...
60 !> \param loc_section ...
61 !> \param mo_local ...
62 !> \param wf_r ...
63 !> \param wf_g ...
64 !> \param particles ...
65 !> \param coeff ...
66 !> \param evals ...
67 !> \param marked_states ...
68 ! **************************************************************************************************
69  SUBROUTINE get_localization_info(qs_env, qs_loc_env, loc_section, mo_local, &
70  wf_r, wf_g, particles, coeff, evals, marked_states)
71 
72  TYPE(qs_environment_type), POINTER :: qs_env
73  TYPE(qs_loc_env_type), POINTER :: qs_loc_env
74  TYPE(section_vals_type), POINTER :: loc_section
75  TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: mo_local
76  TYPE(pw_r3d_rs_type), INTENT(INOUT) :: wf_r
77  TYPE(pw_c1d_gs_type), INTENT(INOUT) :: wf_g
78  TYPE(particle_list_type), POINTER :: particles
79  TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: coeff
80  TYPE(cp_1d_r_p_type), DIMENSION(:), POINTER :: evals
81  INTEGER, DIMENSION(:, :, :), POINTER :: marked_states
82 
83  CHARACTER(len=*), PARAMETER :: routinen = 'get_localization_info'
84 
85  INTEGER :: handle, ispin, mystate, ns, nspins, &
86  output_unit
87  INTEGER, DIMENSION(:), POINTER :: lstates, marked_states_spin
88  LOGICAL :: do_homo, do_mixed
89  REAL(kind=dp), DIMENSION(:, :), POINTER :: scenter
90  TYPE(cp_logger_type), POINTER :: logger
91  TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: ks_rmpv, matrix_s
92  TYPE(dft_control_type), POINTER :: dft_control
93  TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
94  TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
95  TYPE(section_vals_type), POINTER :: loc_print_section
96  TYPE(wannier_centres_type), DIMENSION(:), POINTER :: wc
97 
98  CALL timeset(routinen, handle)
99  NULLIFY (mos, ks_rmpv, dft_control, loc_print_section, marked_states_spin, &
100  matrix_s, scenter, wc)
101  CALL get_qs_env(qs_env, mos=mos, matrix_ks=ks_rmpv, molecule_set=molecule_set, &
102  dft_control=dft_control, matrix_s=matrix_s)
103  logger => cp_get_default_logger()
104  output_unit = cp_logger_get_default_io_unit(logger)
105  loc_print_section => section_vals_get_subs_vals(loc_section, "PRINT")
106  do_homo = qs_loc_env%localized_wfn_control%do_homo
107  do_mixed = qs_loc_env%localized_wfn_control%do_mixed
108  IF (btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
109  "WANNIER_STATES"), cp_p_file)) THEN
110  CALL get_qs_env(qs_env=qs_env, wanniercentres=wc)
111  IF (.NOT. ASSOCIATED(wc)) THEN
112  ALLOCATE (wc(dft_control%nspins))
113  END IF
114  END IF
115 
116  IF (dft_control%restricted) THEN
117  !For ROKS usefull only first term
118  nspins = 1
119  ELSE
120  nspins = dft_control%nspins
121  END IF
122  !
123  DO ispin = 1, nspins
124  !
125  IF (do_homo) THEN
126  qs_loc_env%tag_mo = "HOMO"
127  ELSE
128  qs_loc_env%tag_mo = "LUMO"
129  END IF
130 
131  IF (qs_loc_env%do_localize) THEN
132  ! Do the Real localization..
133  IF (output_unit > 0 .AND. do_homo) WRITE (output_unit, "(/,T2,A,I3)") &
134  "LOCALIZATION| Computing localization properties "// &
135  "for OCCUPIED ORBITALS. Spin:", ispin
136  IF (output_unit > 0 .AND. do_mixed) WRITE (output_unit, "(/,T2,A,/,T16,A,I3)") &
137  "LOCALIZATION| Computing localization properties for OCCUPIED, ", &
138  "PARTIALLY OCCUPIED and UNOCCUPIED ORBITALS. Spin:", ispin
139  IF (output_unit > 0 .AND. (.NOT. do_homo) .AND. (.NOT. do_mixed)) &
140  WRITE (output_unit, "(/,T2,A,I3)") &
141  "LOCALIZATION| Computing localization properties "// &
142  "for UNOCCUPIED ORBITALS. Spin:", ispin
143 
144  scenter => qs_loc_env%localized_wfn_control%centers_set(ispin)%array
145 
146  CALL qs_loc_driver(qs_env, qs_loc_env, loc_print_section, &
147  myspin=ispin, ext_mo_coeff=mo_local(ispin))
148 
149  ! maps wfc to molecules, and compute the molecular dipoles if required
150  IF ((btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
151  "MOLECULAR_DIPOLES"), cp_p_file) .OR. &
152  btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
153  "MOLECULAR_MOMENTS"), cp_p_file) .OR. &
154  btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
155  "MOLECULAR_STATES"), cp_p_file))) THEN
156  CALL wfc_to_molecule(qs_loc_env, scenter, molecule_set, ispin, dft_control%nspins)
157  END IF
158 
159  ! Compute the wannier states
160  IF (btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
161  "WANNIER_STATES"), cp_p_file)) THEN
162  ns = SIZE(qs_loc_env%localized_wfn_control%loc_states, 1)
163  IF (.NOT. ASSOCIATED(wc(ispin)%centres)) THEN
164  ALLOCATE (wc(ispin)%WannierHamDiag(ns))
165  ALLOCATE (wc(ispin)%centres(3, ns))
166  END IF
167 
168  wc(ispin)%centres(:, :) = scenter(1 + (ispin - 1)*3:ispin*3, :)
169  lstates => qs_loc_env%localized_wfn_control%loc_states(:, ispin)
170  CALL construct_wannier_states(mo_local(ispin), &
171  ks_rmpv(ispin)%matrix, qs_env, loc_print_section=loc_print_section, &
172  wanniercentres=wc(ispin), ns=ns, states=lstates)
173  END IF
174  ! Compute the molecular states
175  IF (btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
176  "MOLECULAR_STATES"), cp_p_file)) THEN
178  molecule_set, mo_local(ispin), coeff(ispin), &
179  evals(ispin)%array, ks_rmpv(ispin)%matrix, matrix_s(1)%matrix, qs_env, wf_r, wf_g, &
180  loc_print_section=loc_print_section, particles=particles, tag=trim(qs_loc_env%tag_mo), &
181  marked_states=marked_states_spin, ispin=ispin)
182  IF (ASSOCIATED(marked_states_spin)) THEN
183  IF (.NOT. ASSOCIATED(marked_states)) THEN
184  ALLOCATE (marked_states(SIZE(marked_states_spin), dft_control%nspins, 2))
185  END IF
186  mystate = 1
187  IF (qs_loc_env%tag_mo == "LUMO") mystate = 2
188  marked_states(:, ispin, mystate) = marked_states_spin(:)
189  DEALLOCATE (marked_states_spin)
190  END IF
191  END IF
192  END IF
193 
194  ! Compute all the second moments of the Wannier states
195  IF (section_get_lval(loc_print_section, "WANNIER_SPREADS%SECOND_MOMENTS")) THEN
196  IF (section_get_lval(loc_print_section, "WANNIER_SPREADS%PERIODIC")) THEN
197  IF (dft_control%qs_control%gapw_control%lmax_sphere .LT. 6) THEN
198  cpabort("Periodic second moments require LMAXN1>=6 In QS section")
199  END IF
200  CALL centers_second_moments_berry(qs_env, qs_loc_env, loc_print_section, ispin)
201  ELSE
202  CALL centers_second_moments_loc(qs_env, qs_loc_env, loc_print_section, ispin)
203  END IF
204  END IF
205  END DO
206 
207  ! Compute molecular dipoles
208  IF (btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
209  "MOLECULAR_DIPOLES"), cp_p_file)) THEN
210  CALL calculate_molecular_dipole(qs_env, qs_loc_env, loc_print_section, molecule_set)
211  END IF
212 
213  ! Compute molecular multipole moments
214  IF (btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
215  "MOLECULAR_MOMENTS"), cp_p_file)) THEN
216  CALL calculate_molecular_moments(qs_env, qs_loc_env, mo_local, loc_print_section, molecule_set)
217  END IF
218  !
219  IF (btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
220  "WANNIER_STATES"), cp_p_file)) THEN
221  CALL set_qs_env(qs_env=qs_env, wanniercentres=wc)
222  END IF
223 
224  CALL timestop(handle)
225 
226  END SUBROUTINE get_localization_info
227 
228 END MODULE qs_loc_states
various utilities that regard array of different kinds: output, allocation,... maybe it is not a good...
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
represent a full matrix distributed on many processors
Definition: cp_fm_types.F:15
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, 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...
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
logical function, public section_get_lval(section_vals, keyword_name)
...
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public dp
Definition: kinds.F:34
Set of routines handling the localization for molecular properties.
subroutine, public calculate_molecular_dipole(qs_env, qs_loc_env, loc_print_key, molecule_set)
maps wfc's to molecules and also prints molecular dipoles
Set of routines handling the localization for molecular properties.
subroutine, public calculate_molecular_moments(qs_env, qs_loc_env, mo_local, loc_print_key, molecule_set)
Calculates electrical molecular moments using local operators r-r_ref r_ref: center of mass of the mo...
Routines for the calculation of molecular states.
subroutine, public construct_molecular_states(molecule_set, mo_localized, mo_coeff, mo_eigenvalues, Hks, matrix_S, qs_env, wf_r, wf_g, loc_print_section, particles, tag, marked_states, ispin)
constructs molecular states. mo_localized gets overwritten!
Define the data structure for the molecule information.
represent a simple array based list of the given type
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 set_qs_env(qs_env, super_cell, mos, qmmm, qmmm_periodic, ewald_env, ewald_pw, mpools, rho_external, external_vxc, mask, scf_control, rel_control, qs_charges, ks_env, ks_qmmm_env, wf_history, scf_env, active_space, input, oce, rho_atom_set, rho0_atom_set, rho0_mpole, run_rtp, rtp, rhoz_set, rhoz_tot, ecoul_1c, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, efield, linres_control, xas_env, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, ls_scf_env, do_transport, transport_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, gcp_env, mp2_env, bs_env, kg_env, force, kpoints, WannierCentres, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, rhs)
Set the QUICKSTEP environment.
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
Driver for the localization that should be general for all the methods available and all the definiti...
subroutine, public centers_second_moments_berry(qs_env, qs_loc_env, print_loc_section, ispin)
Compute the second moments of the centers using a periodic quadrupole operator.
subroutine, public centers_second_moments_loc(qs_env, qs_loc_env, print_loc_section, ispin)
Compute the second moments of the centers using the local (non-periodic) pos operators.
Set of routines handling the localization for molecular properties.
subroutine, public wfc_to_molecule(qs_loc_env, center, molecule_set, ispin, nspins)
maps wfc's to molecules and also prints molecular dipoles
subroutine, public get_localization_info(qs_env, qs_loc_env, loc_section, mo_local, wf_r, wf_g, particles, coeff, evals, marked_states)
Performs localization of the orbitals.
Definition: qs_loc_states.F:71
New version of the module for the localization of the molecular orbitals This should be able to use d...
Definition: qs_loc_types.F:25
Definition and initialisation of the mo data type.
Definition: qs_mo_types.F:22
defines the type needed for computing wannier states expectations
Routines for the calculation of wannier states.
subroutine, public construct_wannier_states(mo_localized, Hks, qs_env, loc_print_section, WannierCentres, ns, states)
constructs wannier states. mo_localized should not be overwritten!