(git:b76ce4e)
Loading...
Searching...
No Matches
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-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief
10! **************************************************************************************************
14 USE cp_dbcsr_api, ONLY: dbcsr_p_type
15 USE cp_fm_types, ONLY: cp_fm_type
19 USE cp_output_handling, ONLY: cp_p_file,&
25 USE kinds, ONLY: dp
32 USE pw_types, ONLY: pw_c1d_gs_type,&
37 USE qs_loc_main, ONLY: qs_loc_driver
42 USE qs_mo_types, ONLY: mo_set_type
45#include "./base/base_uses.f90"
46
47 IMPLICIT NONE
48 PRIVATE
49
50 ! Global parameters
51 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_loc_states'
52 PUBLIC :: get_localization_info
53
54! **************************************************************************************************
55
56CONTAINS
57
58! **************************************************************************************************
59!> \brief Performs localization of the orbitals
60!> \param qs_env ...
61!> \param qs_loc_env ...
62!> \param loc_section ...
63!> \param mo_local ...
64!> \param wf_r ...
65!> \param wf_g ...
66!> \param particles ...
67!> \param coeff ...
68!> \param evals ...
69!> \param marked_states ...
70! **************************************************************************************************
71 SUBROUTINE get_localization_info(qs_env, qs_loc_env, loc_section, mo_local, &
72 wf_r, wf_g, particles, coeff, evals, marked_states)
73
74 TYPE(qs_environment_type), POINTER :: qs_env
75 TYPE(qs_loc_env_type), POINTER :: qs_loc_env
76 TYPE(section_vals_type), POINTER :: loc_section
77 TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: mo_local
78 TYPE(pw_r3d_rs_type), INTENT(INOUT) :: wf_r
79 TYPE(pw_c1d_gs_type), INTENT(INOUT) :: wf_g
80 TYPE(particle_list_type), POINTER :: particles
81 TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: coeff
82 TYPE(cp_1d_r_p_type), DIMENSION(:), POINTER :: evals
83 INTEGER, DIMENSION(:, :, :), POINTER :: marked_states
84
85 CHARACTER(len=*), PARAMETER :: routinen = 'get_localization_info'
86
87 INTEGER :: handle, ispin, max_moment, mystate, ns, &
88 nspins, output_unit
89 INTEGER, DIMENSION(:), POINTER :: lstates, marked_states_spin
90 LOGICAL :: com_nl, do_homo, do_mixed, magnetic, &
91 vel_reprs
92 REAL(kind=dp), DIMENSION(:, :), POINTER :: scenter
93 TYPE(cp_logger_type), POINTER :: logger
94 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: ks_rmpv, matrix_s
95 TYPE(dft_control_type), POINTER :: dft_control
96 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
97 TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
98 TYPE(section_vals_type), POINTER :: loc_print_section
99 TYPE(wannier_centres_type), DIMENSION(:), POINTER :: wc
100
101 CALL timeset(routinen, handle)
102 NULLIFY (mos, ks_rmpv, dft_control, loc_print_section, marked_states_spin, &
103 matrix_s, scenter, wc)
104 CALL get_qs_env(qs_env, mos=mos, matrix_ks=ks_rmpv, molecule_set=molecule_set, &
105 dft_control=dft_control, matrix_s=matrix_s)
106 logger => cp_get_default_logger()
107 output_unit = cp_logger_get_default_io_unit(logger)
108 loc_print_section => section_vals_get_subs_vals(loc_section, "PRINT")
109 do_homo = qs_loc_env%localized_wfn_control%do_homo
110 do_mixed = qs_loc_env%localized_wfn_control%do_mixed
111 IF (btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
112 "WANNIER_STATES"), cp_p_file)) THEN
113 CALL get_qs_env(qs_env=qs_env, wanniercentres=wc)
114 IF (.NOT. ASSOCIATED(wc)) THEN
115 ALLOCATE (wc(dft_control%nspins))
116 END IF
117 END IF
118
119 IF (dft_control%restricted) THEN
120 !For ROKS usefull only first term
121 nspins = 1
122 ELSE
123 nspins = dft_control%nspins
124 END IF
125 !
126 DO ispin = 1, nspins
127 !
128 IF (do_homo) THEN
129 qs_loc_env%tag_mo = "HOMO"
130 ELSE
131 qs_loc_env%tag_mo = "LUMO"
132 END IF
133
134 IF (qs_loc_env%do_localize) THEN
135 ! Do the Real localization..
136 IF (output_unit > 0 .AND. do_homo) WRITE (output_unit, "(/,T2,A,I3)") &
137 "LOCALIZATION| Computing localization properties "// &
138 "for OCCUPIED ORBITALS. Spin:", ispin
139 IF (output_unit > 0 .AND. do_mixed) WRITE (output_unit, "(/,T2,A,/,T16,A,I3)") &
140 "LOCALIZATION| Computing localization properties for OCCUPIED, ", &
141 "PARTIALLY OCCUPIED and UNOCCUPIED ORBITALS. Spin:", ispin
142 IF (output_unit > 0 .AND. (.NOT. do_homo) .AND. (.NOT. do_mixed)) &
143 WRITE (output_unit, "(/,T2,A,I3)") &
144 "LOCALIZATION| Computing localization properties "// &
145 "for UNOCCUPIED ORBITALS. Spin:", ispin
146
147 scenter => qs_loc_env%localized_wfn_control%centers_set(ispin)%array
148
149 CALL qs_loc_driver(qs_env, qs_loc_env, loc_print_section, &
150 myspin=ispin, ext_mo_coeff=mo_local(ispin))
151
152 ! maps wfc to molecules, and compute the molecular dipoles if required
153 IF ((btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
154 "MOLECULAR_DIPOLES"), cp_p_file) .OR. &
155 btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
156 "MOLECULAR_MOMENTS"), cp_p_file) .OR. &
157 btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
158 "MOLECULAR_STATES"), cp_p_file) .OR. &
159 btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
160 "LOCALIZED_MOMENTS"), cp_p_file))) THEN
161 CALL wfc_to_molecule(qs_loc_env, scenter, molecule_set, ispin, dft_control%nspins)
162 END IF
163
164 ! Compute the wannier states
165 IF (btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
166 "WANNIER_STATES"), cp_p_file) .OR. &
167 (btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
168 "LOCALIZED_MOMENTS"), cp_p_file))) THEN
169 ns = SIZE(qs_loc_env%localized_wfn_control%loc_states, 1)
170 IF (.NOT. ASSOCIATED(wc(ispin)%centres)) THEN
171 ALLOCATE (wc(ispin)%WannierHamDiag(ns))
172 ALLOCATE (wc(ispin)%centres(3, ns))
173 END IF
174
175 wc(ispin)%centres(:, :) = scenter(1 + (ispin - 1)*3:ispin*3, :)
176 lstates => qs_loc_env%localized_wfn_control%loc_states(:, ispin)
177 CALL construct_wannier_states(mo_local(ispin), &
178 ks_rmpv(ispin)%matrix, qs_env, loc_print_section=loc_print_section, &
179 wanniercentres=wc(ispin), ns=ns, states=lstates)
180 END IF
181 ! Compute the molecular states
182 IF (btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
183 "MOLECULAR_STATES"), cp_p_file)) THEN
185 molecule_set, mo_local(ispin), coeff(ispin), &
186 evals(ispin)%array, ks_rmpv(ispin)%matrix, matrix_s(1)%matrix, qs_env, wf_r, wf_g, &
187 loc_print_section=loc_print_section, particles=particles, tag=trim(qs_loc_env%tag_mo), &
188 marked_states=marked_states_spin, ispin=ispin)
189 IF (ASSOCIATED(marked_states_spin)) THEN
190 IF (.NOT. ASSOCIATED(marked_states)) THEN
191 ALLOCATE (marked_states(SIZE(marked_states_spin), dft_control%nspins, 2))
192 END IF
193 mystate = 1
194 IF (qs_loc_env%tag_mo == "LUMO") mystate = 2
195 marked_states(:, ispin, mystate) = marked_states_spin(:)
196 DEALLOCATE (marked_states_spin)
197 END IF
198 END IF
199 END IF
200
201 ! Compute all the second moments of the Wannier states
202 IF (section_get_lval(loc_print_section, "WANNIER_SPREADS%SECOND_MOMENTS")) THEN
203 IF (section_get_lval(loc_print_section, "WANNIER_SPREADS%PERIODIC")) THEN
204 IF (dft_control%qs_control%gapw_control%lmax_sphere < 6) THEN
205 cpabort("Periodic second moments require LMAXN1>=6 In QS section")
206 END IF
207 CALL centers_second_moments_berry(qs_env, qs_loc_env, loc_print_section, ispin)
208 ELSE
209 CALL centers_second_moments_loc(qs_env, qs_loc_env, loc_print_section, ispin)
210 END IF
211 END IF
212 END DO
213
214 ! Compute molecular dipoles
215 IF (btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
216 "MOLECULAR_DIPOLES"), cp_p_file)) THEN
217 CALL calculate_molecular_dipole(qs_env, qs_loc_env, loc_print_section, molecule_set)
218 END IF
219
220 ! Compute molecular multipole moments
221 IF (btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
222 "MOLECULAR_MOMENTS"), cp_p_file)) THEN
223 CALL calculate_molecular_moments(qs_env, qs_loc_env, mo_local, loc_print_section, molecule_set)
224 END IF
225 !
226 IF (btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
227 "WANNIER_STATES"), cp_p_file)) THEN
228 CALL set_qs_env(qs_env=qs_env, wanniercentres=wc)
229 END IF
230 !
231 IF (btest(cp_print_key_should_output(logger%iter_info, loc_print_section, &
232 "LOCALIZED_MOMENTS"), cp_p_file)) THEN
233 max_moment = section_get_ival(loc_print_section, "LOCALIZED_MOMENTS%MAX_MOMENT")
234 magnetic = section_get_lval(loc_print_section, "LOCALIZED_MOMENTS%MAGNETIC")
235 vel_reprs = section_get_lval(loc_print_section, "LOCALIZED_MOMENTS%VEL_REPRS")
236 com_nl = section_get_lval(loc_print_section, "LOCALIZED_MOMENTS%COM_NL")
237 CALL calculate_localized_moments(qs_env, qs_loc_env, mo_local, max_moment, magnetic, &
238 vel_reprs, com_nl, loc_print_section)
239 END IF
240
241 CALL timestop(handle)
242
243 END SUBROUTINE get_localization_info
244
245END 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
integer function, public section_get_ival(section_vals, keyword_name)
...
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
Routines for the calculation of moments from Wannier functions.
subroutine, public calculate_localized_moments(qs_env, qs_loc_env, mo_local, max_moment, magnetic, vel_reprs, com_nl, loc_print_section)
Calculates localized multipole moments per molecule in the Wannier MO basis.
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, 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, 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.
subroutine, public set_qs_env(qs_env, super_cell, mos, qmmm, qmmm_periodic, mimic, 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, rhoz_cneo_set, 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, harris_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, eeq, rhs, do_rixs, tb_tblite)
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.
New version of the module for the localization of the molecular orbitals This should be able to use d...
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!
represent a pointer to a 1d array
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...
contains all the info needed by quickstep to calculate the spread of a selected set of orbitals and i...