Octopus
wannier_opts.F90
Go to the documentation of this file.
1!! Copyright (C) 2026 A. Buccheri, J. Reimann
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19
20#include "global.h"
21
26 use, intrinsic :: iso_fortran_env
27
28 use debug_oct_m
29 use global_oct_m
30 use io_oct_m
33 use parser_oct_m
35 use unit_oct_m
37
38 implicit none
39 private
40
41 public :: &
45
46 integer, parameter, public :: &
47 TD_WANNIER_METHOD_NONE = 0, &
49
56 type :: wannier_opts_t
57 integer :: num_bands = 0
58 integer :: num_wann = 0
59 logical :: use_scdm
60 real(real64) :: scdm_mu
61 real(real64) :: scdm_sigma
62 real(real64) :: threshold
63 character(len=80) :: prefix
64 integer :: restart_from
65 logical :: plot
66 logical :: wannierize
67 logical :: calc_overlaps
68 logical :: dump_inputs
69 logical :: spinors = .false.
70 integer, allocatable :: spin_proj_component(:)
71
72 logical, allocatable :: exclude_list(:)
73 integer, allocatable :: band_index(:)
74
75 ! Wigner Seitz grid options
76 ! These are optional, but the values from .win file must be used if present.
77 integer, dimension(3) :: ws_search_size = [2, 2, 2]
78 real(real64) :: ws_distance_tol = 1e-5 * p_ang
79
80 ! TD-related options
81 integer :: td_update_interval
82 integer :: td_method
83 logical :: td_write_hr
86
87 contains
88 procedure :: parse_oct => wannier_opts_parse_oct
89 procedure :: parse_win => wannier_opts_parse_win
90 end type wannier_opts_t
91
92contains
93
95 subroutine wannier_opts_parse_oct(this, namespace)
96 class(wannier_opts_t), intent(inout) :: this
97 type(namespace_t), intent(in) :: namespace
98
99 logical :: read_from_td
100
101 push_sub(wannier_opts_parse_oct)
102
103 !%Variable Wannier90Prefix
104 !%Type string
105 !%Default w90
106 !%Section Utilities::oct-wannier90
107 !%Description
108 !% Prefix for wannier90 files. Used by both oct-wannier90 and oct-wannier90lib
109 !% as well as the time-dependent Wannier workflow.
110 !%End
111 call parse_variable(namespace, 'Wannier90Prefix', 'w90', this%prefix)
112
113 !%Variable Wannier90UseTD
114 !%Type logical
115 !%Default no
116 !%Section Utilities::oct-wannier90
117 !%Description
118 !% This variable controls which states are used as input into the standalone utilities
119 !% oct-wannier90 and oct-wannier90lib.
120 !% By default oct-wannier90 uses the ground-state states.
121 !% By setting this variable to yes, oct-wannier90 will use the TD states instead.
122 !% This parameter does not apply to the time-dependent Wannier workflow.
123 !%End
124 call parse_variable(global_namespace, 'Wannier90UseTD', .false., read_from_td)
125 if (read_from_td) then
126 this%restart_from = restart_td
127 else
128 this%restart_from = restart_gs
129 end if
130
131 !%Variable Wannier90DumpFiles
132 !%Type logical
133 !%Default no
134 !%Section Utilities::oct-wannier90lib
135 !%Description
136 !% Whether or not to dump intermediate files to disk.
137 !% This applies only to the oct-wannierlib utility.
138 !% Files are: .amn, .mmn, .eig and .win with inputs.
139 !%End
140 call parse_variable(global_namespace, 'Wannier90DumpFiles', .false., this%dump_inputs)
142 !%Variable Wannier90Wannierize
143 !%Type logical
144 !%Default yes
145 !%Section Utilities::oct-wannier90lib
146 !%Description
147 !% Whether or not to perform the wannierization step (including disentanglement).
148 !% This applies only to the standalone utility oct-wannier90lib.
149 !%End
150 call parse_variable(global_namespace, 'Wannier90Wannierize', .true., this%wannierize)
152 !%Variable Wannier90Plot
153 !%Type logical
154 !%Default no
155 !%Section Utilities::oct-wannier90lib
156 !%Description
157 !% If set to yes, oct-wannier90lib will generate the wannier functions on a real space
158 !% grid and write them to file.
159 !%End
160 call parse_variable(global_namespace, 'Wannier90Plot', .false., this%plot)
162 !%Variable Wannier90CalcOverlaps
163 !%Type logical
164 !%Default no
165 !%Section Utilities::oct-wannier90lib
166 !%Description
167 !% Whether or not to calculate the amn and mmn matrices from octopus states.
168 !% By setting this variable to no, oct-wannier90 will attempt to read them from files.
169 !% This applies only to the standalone utility oct-wannier90lib.
170 !%End
171 call parse_variable(global_namespace, 'Wannier90CalcOverlaps', .false., this%calc_overlaps)
173 !%Variable Wannier90UseSCDM
174 !%Type logical
175 !%Default no
176 !%Section Utilities::oct-wannier90
177 !%Description
178 !% By default oct-wannier90 and oct-wannier90lib use the projection method to generate the .amn file.
179 !% By setting this variable to yes, they will use the SCDM method instead.
180 !%End
181 call parse_variable(namespace, 'Wannier90UseSCDM', .false., this%use_scdm)
182 if (this%use_scdm) then
183 !%Variable SCDMsigma
184 !%Type float
185 !%Default 0.2
186 !%Section Utilities::oct-wannier90
187 !%Description
188 !% Broadening of SCDM smearing function.
189 !%End
190 call parse_variable(namespace, 'SCDMsigma', 0.2_real64, this%scdm_sigma)
191
192 !%Variable SCDMmu
193 !%Type float
194 !%Section Utilities::oct-wannier90
195 !%Description
196 !% Energy range up to which states are considered for SCDM.
197 !%End
198 call parse_variable(namespace, 'SCDMmu', m_huge, this%scdm_mu)
199 end if
200
201 ! We use the variable AOThreshold to deterine the threshold on the radii of the atomic orbitals
202 ! TODO: Have the threshold for wannier functions different than for AO
203 call parse_variable(namespace, 'AOThreshold', 0.001_real64, this%threshold)
204
205 !%Variable TDWannierMethod
206 !%Type integer
207 !%Default 0
208 !%Section Time-Dependent
209 !%Description
210 !% Specifies which method to use for TD Wannier calculations.
211 !%Option none 0
212 !% TD Wannier functionality is disabled.
213 !%Option wannier90 1
214 !% Performs a full wannierization of the time-dependent Kohn-Sham states to update the U matrix.
215 !%End
216 call parse_variable(namespace, 'TDWannierMethod', 0, this%td_method)
217
218 !%Variable TDWannierUpdateInterval
219 !%Type integer
220 !%Default 1
221 !%Section Time-Dependent::TD Output
222 !%Description
223 !% If TDWannierMethod is enabled, Wannier-related data is updated and written
224 !% every TDWannierUpdateInterval iterations.
225 !%End
226 call parse_variable(namespace, 'TDWannierUpdateInterval', 1, this%td_update_interval)
227
228 !%Variable TDWannierWriteHR
229 !%Type logical
230 !%Default no
231 !%Section Time-Dependent
232 !%Description
233 !% Whether or not TD Wannier writes w90_hr.dat file during TD run.
234 !%End
235 call parse_variable(namespace, 'TDWannierWriteHR', .false., this%td_write_hr)
236 if (this%td_write_hr) then
237 if (this%td_method == td_wannier_method_none) then
238 message(1) = 'TDWannierWriteHR is set to yes, but TDWannierMethod is set to None.'
239 message(2) = 'TDWannierWriteHR will be ignored.'
240 call messages_warning(2)
241 else
242 message(1) = 'TDWannierWriteHR is set to yes. ' // &
243 'Currently the time-dependent lattice models are gauge-dependent and can not be trusted.'
244 call messages_warning(1)
245 end if
246 end if
247
249
250 end subroutine wannier_opts_parse_oct
251
262 subroutine wannier_opts_parse_win(this)
263 class(wannier_opts_t), intent(inout) :: this
264
265 character(len=80) :: filename, line, dummy, dummy1, dummy2
266 integer :: w90_win, io, tmp_int
267 real(real64) :: ws_distance_tol_angstrom
268 logical :: exist
269
270 push_sub(wannier_opts_parse_win)
271
272 filename = trim(adjustl(this%prefix)) //'.win'
273 inquire(file=filename,exist=exist)
274 if (.not. exist) then
275 message(1) = 'Cannot find specified Wannier90 win file.'
276 call messages_fatal(1)
277 else
278 message(1) = 'Reading file '//filename
279 w90_win = io_open(trim(filename), action='read')
280 do
281 read(w90_win, '(A)', iostat=io) line
282 if (is_iostat_end(io)) exit
283
284 if (index(line, '=') > 0) then
285 read(line, *, iostat=io) dummy, dummy2, dummy1
286 else
287 read(line, *, iostat=io) dummy, dummy1
288 end if
289 if (dummy == 'num_bands') then
290 read(dummy1, *, iostat=io) tmp_int
291 this%num_bands = tmp_int
292 else if (dummy == 'num_wann') then
293 read(dummy1, *, iostat=io) tmp_int
294 this%num_wann = tmp_int
295 else if (dummy == 'ws_search_size') then
296 if (index(line, '=') > 0) then
297 read(line, *, iostat=io) dummy, dummy2, this%ws_search_size(:)
298 else
299 read(line, *, iostat=io) dummy, this%ws_search_size(:)
300 end if
301 if (io /= 0) then
302 ! Single integer: apply to all three dimensions
303 read(dummy1, *, iostat=io) tmp_int
304 this%ws_search_size = tmp_int
305 end if
306 else if (dummy == 'ws_distance_tol') then
307 read(dummy1, *, iostat=io) ws_distance_tol_angstrom
308 this%ws_distance_tol = units_to_atomic(unit_angstrom, ws_distance_tol_angstrom)
309 end if
310 end do
311
312 call io_close(w90_win)
313 end if
314
316
317 end subroutine wannier_opts_parse_win
318
319end module wannier_opts_oct_m
real(real64), parameter, public m_huge
Definition: global.F90:218
real(real64), parameter, public p_ang
Definition: global.F90:238
Definition: io.F90:116
subroutine, public io_close(iunit, grp)
Definition: io.F90:467
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
Definition: io.F90:402
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:525
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:410
type(namespace_t), public global_namespace
Definition: namespace.F90:135
integer, parameter, public restart_gs
Definition: restart.F90:156
integer, parameter, public restart_td
Definition: restart.F90:156
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:134
This module defines the unit system, used for input and output.
type(unit_t), public unit_angstrom
For XYZ files.
Wannier options module.
integer, parameter, public td_wannier_method_wannier90
subroutine, public wannier_opts_parse_win(this)
Parse required Wannier90 options from wannier90 .win input file.
subroutine, public wannier_opts_parse_oct(this, namespace)
Parse Wannier90 related options from octopus input file.
Wannier related options.
int true(void)