Line data Source code
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 Localization/Wannier functions for TB
10 : !> \par History
11 : !> \author JHU (03.2019)
12 : ! **************************************************************************************************
13 : MODULE localization_tb
14 : USE atomic_kind_types, ONLY: atomic_kind_type
15 : USE cp_array_utils, ONLY: cp_1d_r_p_type
16 : USE cp_control_types, ONLY: dft_control_type
17 : USE cp_fm_types, ONLY: cp_fm_create,&
18 : cp_fm_release,&
19 : cp_fm_to_fm,&
20 : cp_fm_type
21 : USE cp_log_handling, ONLY: cp_get_default_logger,&
22 : cp_logger_get_default_io_unit,&
23 : cp_logger_type
24 : USE input_section_types, ONLY: section_vals_get,&
25 : section_vals_get_subs_vals,&
26 : section_vals_type,&
27 : section_vals_val_get
28 : USE kinds, ONLY: dp
29 : USE particle_list_types, ONLY: particle_list_type
30 : USE particle_types, ONLY: particle_type
31 : USE pw_env_types, ONLY: pw_env_get,&
32 : pw_env_type
33 : USE pw_pool_types, ONLY: pw_pool_p_type,&
34 : pw_pool_type
35 : USE pw_types, ONLY: pw_c1d_gs_type,&
36 : pw_r3d_rs_type
37 : USE qs_environment_types, ONLY: get_qs_env,&
38 : qs_environment_type,&
39 : set_qs_env
40 : USE qs_kind_types, ONLY: qs_kind_type
41 : USE qs_loc_dipole, ONLY: loc_dipole
42 : USE qs_loc_states, ONLY: get_localization_info
43 : USE qs_loc_types, ONLY: qs_loc_env_create,&
44 : qs_loc_env_release,&
45 : qs_loc_env_type
46 : USE qs_loc_utils, ONLY: loc_write_restart,&
47 : qs_loc_control_init,&
48 : qs_loc_init,&
49 : retain_history
50 : USE qs_mo_types, ONLY: get_mo_set,&
51 : mo_set_type
52 : USE qs_subsys_types, ONLY: qs_subsys_get,&
53 : qs_subsys_type
54 : #include "./base/base_uses.f90"
55 :
56 : IMPLICIT NONE
57 : PRIVATE
58 :
59 : ! Global parameters
60 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'localization_tb'
61 : PUBLIC :: wfn_localization_tb
62 :
63 : CONTAINS
64 :
65 : ! **************************************************************************************************
66 : !> \brief wfn localization
67 : !> \param qs_env ...
68 : !> \param tb_type ...
69 : !> \par History
70 : !> 03.2019 initial version
71 : !> \author JHU
72 : !> \note
73 : ! **************************************************************************************************
74 4596 : SUBROUTINE wfn_localization_tb(qs_env, tb_type)
75 :
76 : TYPE(qs_environment_type), POINTER :: qs_env
77 : CHARACTER(LEN=*) :: tb_type
78 :
79 : CHARACTER(len=*), PARAMETER :: routineN = 'wfn_localization_tb'
80 :
81 : INTEGER :: handle, iounit, ispin, nspins
82 4596 : INTEGER, DIMENSION(:, :, :), POINTER :: marked_states
83 : LOGICAL :: do_homo, do_kpoints, explicit, &
84 : loc_explicit
85 4596 : REAL(KIND=dp), DIMENSION(:), POINTER :: mo_eigenvalues
86 4596 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
87 4596 : TYPE(cp_1d_r_p_type), DIMENSION(:), POINTER :: occupied_evals
88 4596 : TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: homo_localized, occupied_orbs
89 4596 : TYPE(cp_fm_type), DIMENSION(:), POINTER :: mo_loc_history
90 : TYPE(cp_fm_type), POINTER :: mo_coeff
91 : TYPE(cp_logger_type), POINTER :: logger
92 : TYPE(dft_control_type), POINTER :: dft_control
93 4596 : TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
94 : TYPE(particle_list_type), POINTER :: particles
95 4596 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
96 : TYPE(pw_c1d_gs_type) :: wf_g
97 : TYPE(pw_env_type), POINTER :: pw_env
98 4596 : TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
99 : TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
100 : TYPE(pw_r3d_rs_type) :: wf_r
101 4596 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
102 : TYPE(qs_loc_env_type), POINTER :: qs_loc_env_homo
103 : TYPE(qs_subsys_type), POINTER :: subsys
104 : TYPE(section_vals_type), POINTER :: dft_section, loc_print_section, &
105 : localize_section
106 :
107 4596 : CALL timeset(routineN, handle)
108 :
109 4596 : logger => cp_get_default_logger()
110 4596 : iounit = cp_logger_get_default_io_unit(logger)
111 :
112 4596 : CPASSERT(ASSOCIATED(qs_env))
113 4596 : dft_section => section_vals_get_subs_vals(qs_env%input, "DFT")
114 4596 : localize_section => section_vals_get_subs_vals(dft_section, "LOCALIZE")
115 4596 : loc_print_section => section_vals_get_subs_vals(localize_section, "PRINT")
116 4596 : CALL section_vals_get(localize_section, explicit=loc_explicit)
117 : !
118 4596 : IF (TRIM(tb_type) == "xTB") THEN
119 : ! okay
120 : ELSE
121 1934 : IF (loc_explicit) THEN
122 0 : CPWARN("Wfn localization for this TB type not implemented")
123 0 : loc_explicit = .FALSE.
124 : END IF
125 : END IF
126 :
127 4596 : IF (loc_explicit) THEN
128 6 : CALL section_vals_val_get(localize_section, "LIST", explicit=explicit)
129 6 : IF (explicit) THEN
130 2 : CPWARN("Localization using LIST of states not implemented for TB methods")
131 : END IF
132 6 : CALL section_vals_val_get(localize_section, "ENERGY_RANGE", explicit=explicit)
133 6 : IF (explicit) THEN
134 0 : CPWARN("Localization using energy range not implemented for TB methods")
135 : END IF
136 6 : CALL section_vals_val_get(localize_section, "LIST_UNOCCUPIED", explicit=explicit)
137 6 : IF (explicit) THEN
138 0 : CPWARN("Localization of unoccupied states not implemented for TB methods")
139 : END IF
140 : ! localize all occupied states
141 6 : IF (iounit > 0) THEN
142 3 : WRITE (iounit, "(/,T11,A)") " +++++++++++++ Start Localization of Orbitals +++++++++++++"
143 : END IF
144 : !
145 : CALL get_qs_env(qs_env, &
146 : dft_control=dft_control, &
147 : do_kpoints=do_kpoints, &
148 : subsys=subsys, &
149 : particle_set=particle_set, &
150 : atomic_kind_set=atomic_kind_set, &
151 6 : qs_kind_set=qs_kind_set)
152 6 : CALL qs_subsys_get(subsys, particles=particles)
153 :
154 6 : IF (do_kpoints) THEN
155 0 : CPWARN("Localization not implemented for k-point calculations!!")
156 6 : ELSEIF (dft_control%restricted) THEN
157 0 : IF (iounit > 0) WRITE (iounit, *) &
158 0 : " Unclear how we define MOs / localization in the restricted case ... skipping"
159 : ELSE
160 6 : CALL get_qs_env(qs_env, mos=mos)
161 6 : nspins = dft_control%nspins
162 26 : ALLOCATE (occupied_orbs(nspins))
163 26 : ALLOCATE (occupied_evals(nspins))
164 20 : ALLOCATE (homo_localized(nspins))
165 14 : DO ispin = 1, nspins
166 : CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, &
167 8 : eigenvalues=mo_eigenvalues)
168 8 : occupied_orbs(ispin) = mo_coeff
169 8 : occupied_evals(ispin)%array => mo_eigenvalues
170 8 : CALL cp_fm_create(homo_localized(ispin), occupied_orbs(ispin)%matrix_struct)
171 14 : CALL cp_fm_to_fm(occupied_orbs(ispin), homo_localized(ispin))
172 : END DO
173 :
174 6 : CALL get_qs_env(qs_env, mo_loc_history=mo_loc_history)
175 6 : do_homo = .TRUE.
176 :
177 6 : CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
178 6 : CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, pw_pools=pw_pools)
179 6 : CALL auxbas_pw_pool%create_pw(wf_r)
180 6 : CALL auxbas_pw_pool%create_pw(wf_g)
181 :
182 6 : NULLIFY (marked_states, qs_loc_env_homo)
183 42 : ALLOCATE (qs_loc_env_homo)
184 6 : CALL qs_loc_env_create(qs_loc_env_homo)
185 6 : CALL qs_loc_control_init(qs_loc_env_homo, localize_section, do_homo=do_homo)
186 : CALL qs_loc_init(qs_env, qs_loc_env_homo, localize_section, homo_localized, do_homo, &
187 6 : .FALSE., mo_loc_history=mo_loc_history)
188 : CALL get_localization_info(qs_env, qs_loc_env_homo, localize_section, homo_localized, &
189 6 : wf_r, wf_g, particles, occupied_orbs, occupied_evals, marked_states)
190 :
191 : !retain the homo_localized for future use
192 6 : IF (qs_loc_env_homo%localized_wfn_control%use_history) THEN
193 0 : CALL retain_history(mo_loc_history, homo_localized)
194 0 : CALL set_qs_env(qs_env, mo_loc_history=mo_loc_history)
195 : END IF
196 :
197 : !write restart for localization of occupied orbitals
198 : CALL loc_write_restart(qs_loc_env_homo, loc_print_section, mos, &
199 6 : homo_localized, do_homo)
200 6 : CALL cp_fm_release(homo_localized)
201 6 : DEALLOCATE (occupied_orbs)
202 6 : DEALLOCATE (occupied_evals)
203 : ! Print Total Dipole if the localization has been performed
204 6 : IF (qs_loc_env_homo%do_localize) THEN
205 6 : CALL loc_dipole(qs_env%input, dft_control, qs_loc_env_homo, logger, qs_env)
206 : END IF
207 6 : CALL auxbas_pw_pool%give_back_pw(wf_g)
208 6 : CALL auxbas_pw_pool%give_back_pw(wf_r)
209 6 : CALL qs_loc_env_release(qs_loc_env_homo)
210 6 : DEALLOCATE (qs_loc_env_homo)
211 12 : IF (ASSOCIATED(marked_states)) THEN
212 2 : DEALLOCATE (marked_states)
213 : END IF
214 : END IF
215 :
216 : END IF
217 :
218 4596 : CALL timestop(handle)
219 :
220 9192 : END SUBROUTINE wfn_localization_tb
221 :
222 : ! **************************************************************************************************
223 :
224 : END MODULE localization_tb
|