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, &
50
57 type :: wannier_opts_t
58 integer :: num_bands = 0
59 integer :: num_wann = 0
60 logical :: use_scdm
61 real(real64) :: scdm_mu
62 real(real64) :: scdm_sigma
63 real(real64) :: threshold
64 character(len=80) :: prefix
65 integer :: restart_from
66 logical :: plot
67 logical :: wannierize
68 logical :: calc_overlaps
69 logical :: dump_inputs
70 logical :: spinors = .false.
71 integer, allocatable :: spin_proj_component(:)
72
73 logical, allocatable :: exclude_list(:)
74 integer, allocatable :: band_index(:)
75
76 ! Wigner Seitz grid options
77 ! These are optional, but the values from .win file must be used if present.
78 integer, dimension(3) :: ws_search_size = [2, 2, 2]
79 real(real64) :: ws_distance_tol = 1e-5 * p_ang
80
81 ! TD-related options
82 integer :: td_update_interval
83 integer :: td_method
84 logical :: td_write_hr
87
88 contains
89 procedure :: parse_oct => wannier_opts_parse_oct
90 procedure :: parse_win => wannier_opts_parse_win
91 end type wannier_opts_t
92
93contains
94
96 subroutine wannier_opts_parse_oct(this, namespace)
97 class(wannier_opts_t), intent(inout) :: this
98 type(namespace_t), intent(in) :: namespace
99
100 logical :: read_from_td
101
102 push_sub(wannier_opts_parse_oct)
103
104 !%Variable Wannier90Prefix
105 !%Type string
106 !%Default w90
107 !%Section Utilities::oct-wannier90
108 !%Description
109 !% Prefix for wannier90 files. Used by both oct-wannier90 and oct-wannier90lib
110 !% as well as the time-dependent Wannier workflow.
111 !%End
112 call parse_variable(namespace, 'Wannier90Prefix', 'w90', this%prefix)
113
114 !%Variable Wannier90UseTD
115 !%Type logical
116 !%Default no
117 !%Section Utilities::oct-wannier90
118 !%Description
119 !% This variable controls which states are used as input into the standalone utilities
120 !% oct-wannier90 and oct-wannier90lib.
121 !% By default oct-wannier90 uses the ground-state states.
122 !% By setting this variable to yes, oct-wannier90 will use the TD states instead.
123 !% This parameter does not apply to the time-dependent Wannier workflow.
124 !%End
125 call parse_variable(global_namespace, 'Wannier90UseTD', .false., read_from_td)
126 if (read_from_td) then
127 this%restart_from = restart_td
128 else
129 this%restart_from = restart_gs
130 end if
131
132 !%Variable Wannier90DumpFiles
133 !%Type logical
134 !%Default no
135 !%Section Utilities::oct-wannier90lib
136 !%Description
137 !% Whether or not to dump intermediate files to disk.
138 !% This applies only to the oct-wannierlib utility.
139 !% Files are: .amn, .mmn, .eig and .win with inputs.
140 !%End
141 call parse_variable(global_namespace, 'Wannier90DumpFiles', .false., this%dump_inputs)
142
143 !%Variable Wannier90Wannierize
144 !%Type logical
145 !%Default yes
146 !%Section Utilities::oct-wannier90lib
147 !%Description
148 !% Whether or not to perform the wannierization step (including disentanglement).
149 !% This applies only to the standalone utility oct-wannier90lib.
150 !%End
151 call parse_variable(global_namespace, 'Wannier90Wannierize', .true., this%wannierize)
153 !%Variable Wannier90Plot
154 !%Type logical
155 !%Default no
156 !%Section Utilities::oct-wannier90lib
157 !%Description
158 !% If set to yes, oct-wannier90lib will generate the wannier functions on a real space
159 !% grid and write them to file.
160 !%End
161 call parse_variable(global_namespace, 'Wannier90Plot', .false., this%plot)
163 !%Variable Wannier90CalcOverlaps
164 !%Type logical
165 !%Default no
166 !%Section Utilities::oct-wannier90lib
167 !%Description
168 !% Whether or not to calculate the amn and mmn matrices from octopus states.
169 !% By setting this variable to no, oct-wannier90 will attempt to read them from files.
170 !% This applies only to the standalone utility oct-wannier90lib.
171 !%End
172 call parse_variable(global_namespace, 'Wannier90CalcOverlaps', .false., this%calc_overlaps)
174 !%Variable Wannier90UseSCDM
175 !%Type logical
176 !%Default no
177 !%Section Utilities::oct-wannier90
178 !%Description
179 !% By default oct-wannier90 and oct-wannier90lib use the projection method to generate the .amn file.
180 !% By setting this variable to yes, they will use the SCDM method instead.
181 !%End
182 call parse_variable(namespace, 'Wannier90UseSCDM', .false., this%use_scdm)
183 if (this%use_scdm) then
184 !%Variable SCDMsigma
185 !%Type float
186 !%Default 0.2
187 !%Section Utilities::oct-wannier90
188 !%Description
189 !% Broadening of SCDM smearing function.
190 !%End
191 call parse_variable(namespace, 'SCDMsigma', 0.2_real64, this%scdm_sigma)
192
193 !%Variable SCDMmu
194 !%Type float
195 !%Section Utilities::oct-wannier90
196 !%Description
197 !% Energy range up to which states are considered for SCDM.
198 !%End
199 call parse_variable(namespace, 'SCDMmu', m_huge, this%scdm_mu)
200 end if
201
202 ! We use the variable AOThreshold to deterine the threshold on the radii of the atomic orbitals
203 ! TODO: Have the threshold for wannier functions different than for AO
204 call parse_variable(namespace, 'AOThreshold', 0.001_real64, this%threshold)
205
206 !%Variable TDWannierMethod
207 !%Type integer
208 !%Default 0
209 !%Section Time-Dependent
210 !%Description
211 !% Specifies which method to use for TD Wannier calculations.
212 !%Option none 0
213 !% TD Wannier functionality is disabled.
214 !%Option wannier90 1
215 !% Performs a full wannierization of the time-dependent Kohn-Sham states to update the U matrix.
216 !%Option phase 2
217 !% Updates the time-dependent wannier transformation matrix U by applying the phase a static state would acquire.
218 !%End
219 call parse_variable(namespace, 'TDWannierMethod', 0, this%td_method)
220
221 !%Variable TDWannierUpdateInterval
222 !%Type integer
223 !%Default 1
224 !%Section Time-Dependent::TD Output
225 !%Description
226 !% If TDWannierMethod is enabled, Wannier-related data is updated and written
227 !% every TDWannierUpdateInterval iterations.
228 !%End
229 call parse_variable(namespace, 'TDWannierUpdateInterval', 1, this%td_update_interval)
230
231 !%Variable TDWannierWriteHR
232 !%Type logical
233 !%Default no
234 !%Section Time-Dependent
235 !%Description
236 !% Whether or not TD Wannier writes w90_hr.dat file during TD run.
237 !%End
238 call parse_variable(namespace, 'TDWannierWriteHR', .false., this%td_write_hr)
239 if (this%td_write_hr) then
240 if (this%td_method == td_wannier_method_none) then
241 message(1) = 'TDWannierWriteHR is set to yes, but TDWannierMethod is set to None.'
242 message(2) = 'TDWannierWriteHR will be ignored.'
243 call messages_warning(2)
244 else
245 message(1) = 'TDWannierWriteHR is set to yes. ' // &
246 'Currently the time-dependent lattice models are gauge-dependent and can not be trusted.'
247 call messages_warning(1)
248 end if
249 end if
250
252
253 end subroutine wannier_opts_parse_oct
254
265 subroutine wannier_opts_parse_win(this)
266 class(wannier_opts_t), intent(inout) :: this
267
268 character(len=80) :: filename, line, dummy, dummy1, dummy2
269 integer :: w90_win, io, tmp_int
270 real(real64) :: ws_distance_tol_angstrom
271 logical :: exist
272
273 push_sub(wannier_opts_parse_win)
274
275 filename = trim(adjustl(this%prefix)) //'.win'
276 inquire(file=filename,exist=exist)
277 if (.not. exist) then
278 message(1) = 'Cannot find specified Wannier90 win file.'
279 call messages_fatal(1)
280 else
281 message(1) = 'Reading file '//filename
282 w90_win = io_open(trim(filename), action='read')
283 do
284 read(w90_win, '(A)', iostat=io) line
285 if (is_iostat_end(io)) exit
286
287 if (index(line, '=') > 0) then
288 read(line, *, iostat=io) dummy, dummy2, dummy1
289 else
290 read(line, *, iostat=io) dummy, dummy1
291 end if
292 if (dummy == 'num_bands') then
293 read(dummy1, *, iostat=io) tmp_int
294 this%num_bands = tmp_int
295 else if (dummy == 'num_wann') then
296 read(dummy1, *, iostat=io) tmp_int
297 this%num_wann = tmp_int
298 else if (dummy == 'ws_search_size') then
299 if (index(line, '=') > 0) then
300 read(line, *, iostat=io) dummy, dummy2, this%ws_search_size(:)
301 else
302 read(line, *, iostat=io) dummy, this%ws_search_size(:)
303 end if
304 if (io /= 0) then
305 ! Single integer: apply to all three dimensions
306 read(dummy1, *, iostat=io) tmp_int
307 this%ws_search_size = tmp_int
308 end if
309 else if (dummy == 'ws_distance_tol') then
310 read(dummy1, *, iostat=io) ws_distance_tol_angstrom
311 this%ws_distance_tol = units_to_atomic(unit_angstrom, ws_distance_tol_angstrom)
312 end if
313 end do
314
315 call io_close(w90_win)
316 end if
317
319
320 end subroutine wannier_opts_parse_win
321
322end 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
integer, parameter, public td_wannier_method_phase
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)