Utility
Shared utility types and helper functions used across file-format readers, writers, and conversion pipelines.
Constants
Physical constants and package-wide defaults.
WannierIO.Bohr Constant
Bohr radius in Angstrom unit.
This is the default CODATA2006 value in W90 src/constants.F90.
WannierIO.Bohr_QE Constant
Bohr radius in Angstrom unit.
This is the default (Physical constants, SI (NIST 2018)) value in QE Modules/constants.f90.
Helper functions
General helpers for parsing, headers, TOML conversion, and comparisons.
WannierIO.from_toml Method
I store atoms_frac and kpoint_path as Vector of StringVec3. However, TOML.print does not accept Pair (specifically, StringVec3); instead, I convert StringVec3 to Dict in write_win with toml format. On reading I convert it back.
sourceWannierIO.istoml Method
istoml(io)Return true if the input can be parsed as TOML, otherwise false.
This helper catches TOML.ParserError and returns false for invalid TOML content while rethrowing other unexpected errors.
WannierIO.to_toml Method
to_toml(x)Convert types for TOML writing.
Examples
using TOML
x = Dict(:a => (; b=1))
TOML.print(to_toml, x)WannierIO.write_toml Function
Write kwargs into io as a TOML file.
This is more convenient than TOML.print, in that:
Do some type conversion before writing.
Keep the order of kwargs, whereas
TOML.printalways requires aDictwhich will change the order of keys.
Examples
write_toml(stdout; b=2, a=1)WannierIO.format_indices Method
format_indices(indices)Convert a vector of integers to a string of comma-separated indices or range.
E.g., the exclude_bands tag of win file.
Examples
julia> format_indices([1, 2, 5, 8, 9, 10])
"1-2 5 8-10"WannierIO.nextline Method
nextline(io; comment, lower)Read a line from the input stream, ignoring empty lines (containing only whitespace).
Returns the first non-empty line found, or empty string if EOF is reached.
Arguments
io::IO: input stream
Keyword Arguments
comment::Bool=false: if true, keep comments (starting with!or#)lower::Bool=false: if true, convert the returned string to lowercase
Returns
- A string containing the first non-empty line, with leading and trailing whitespace removed, or empty string if EOF is reached.
WannierIO.parse_bool Method
parse_bool(s)Parse a string as bool.
This is capable of parsing Fortran outputs, e.g., .true., .false., true, T.
WannierIO.parse_float Method
parse_float(s)Parse a string as Float64.
The is capable of parsing Fortran outputs, e.g. 1.0D-10, to the ordinary 1e-10.
WannierIO.parse_indices Method
parse_indices(str)Parse a string of comma-separated indices or range into a vector of integers.
E.g., the exclude_bands tag of win file.
Examples
julia> parse_indices("1-2, 5,8 -10")
6-element Vector{Int64}:
1
2
5
8
9
10
julia> parse_indices("1-2 5,8 -10")WannierIO.parse_vector Method
parse_vector(io, T, n_elements)Parse a vector of n_elements elements of type T from io.
Arguments
io: input streamT: type of elementsn_elements::Int: total number of elements
Examples
Suppose a file demo.txt has the following content:
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23Then the following code parses the file and return a vector filled with 1 to 23:
julia> vector = open("demo.txt") do io
parse_vector(io, Int, 23)
endThe number of elements in each line can be different.
sourceWannierIO.strip_comment Method
strip_comment(line; spaces)Strip comments (! or #) from a line.
Arguments
line::AbstractString: input line
Keyword Arguments
spaces::Bool=false: if true, preserve leading and trailing whitespace.
Fortran related
Low-level helpers for formatted/unformatted Fortran IO.
WannierIO.isbinary Method
isbinary(io)Check if the IO is in binary format.
This function preserves the stream position for seekable IO.
sourceFile formats
Format tags used by high-level APIs for dispatch and auto-detection.
WannierIO.AbstractFileFormat Type
Abstract supertype for all explicit file format tags used by WannierIO.
These tags are lightweight dispatch objects. Pass them to functions like read_eig, write_amn, read_win, etc. when you want to choose a format explicitly instead of relying on auto detection.
WannierIO.AbstractFortranFormat Type
Abstract supertype for Fortran-style matrix/data file formats.
sourceWannierIO.AbstractW90InputFormat Type
Abstract supertype for Wannier90 small input-file formats such as win and nnkp.
WannierIO.FortranBinaryStream Type
Fortran unformatted IO with stream access.
For example, file written using these Fortran code:
OPEN(UNIT=11, FILE="ustream.demo", STATUS="NEW", ACCESS="STREAM", FORM="UNFORMATTED")WannierIO.HDF5Format Type
HDF5 storage format for tight-binding data.
Requires loading the HDF5 package.
Note
The matrices written in the HDF5 is row-major (Python/C-style) order, which is different from the column-major (Julia/Fortran-style) order used throughout the rest of WannierIO. If you use the read_w90_tb and write_w90_tb functions to read/write HDF5 files, this is handled automatically. However, if you want to load them in python, be aware of this difference accordingly.
WannierIO.JLD2Format Type
JLD2 storage format for tight-binding data.
Requires loading the JLD2 package.
WannierIO.W90Dat Type
Native Wannier90 tight-binding text format (.dat files written by Wannier90).
WannierIO.W90InputText Type
Plain-text format for Wannier90 win and nnkp files.
The default win and nnkp files are text files, but they are not simple tables that can be parsed with readdlm. This format tag selects the custom Wannier90 text parser used by functions such as read_win and read_nnkp.
Compared with W90InputToml, this format is for the native Wannier90 input syntax. Compared with FortranText, it is for small structured input files rather than large numeric matrix dumps such as amn, mmn, or eig.
WannierIO.W90InputToml Type
TOML format for Wannier90 win and nnkp files.
This allows win or nnkp data to be stored in a standard TOML representation that can be parsed by generic TOML tooling.
WannierIO.ZarrFormat Type
Zarr storage format for tight-binding data.
Requires loading the Zarr package.
Note
Similar to the HDF5 format, the matrices written in Zarr are row-major (Python/C-style) order. If you use the read_w90_tb and write_w90_tb functions to read/write Zarr files, this is handled automatically. However, if you want to load them in python, be aware of this difference accordingly.
WannierIO.ZarrZipFormat Type
Zarr storage format for tight-binding data, zipped into a single file.
Requires loading the Zarr package.
Note
Note the row-major order of the matrices in this format, as described in the documentation of ZarrFormat.
WannierIO.detect_fortran_format Method
detect_fortran_format(file; stream=false)Infer a Fortran-format tag from file using isbinary.
WannierIO.detect_operator_format Method
detect_operator_format(path)Infer an operator storage format tag from the file extension of path:
.h5/.hdf5→HDF5Format.jld2→JLD2Format.zarr→ZarrFormat.zarr.zip→ZarrZipFormat
WannierIO.detect_w90input_format Method
detect_w90input_format(file)Infer a win/nnkp format tag from file using istoml.
WannierIO.format_name Method
format_name(format)Return a short human-readable name for a FileFormat tag.
WannierIO.fortran_format Method
fortran_format(; binary=false, stream=false)Construct a Fortran-format tag.
binary=falsereturnsFortranTextbinary=true, stream=falsereturnsFortranBinarybinary=true, stream=truereturnsFortranBinaryStream
WannierIO.w90input_format Method
w90input_format(; toml=false)Construct a format tag for win/nnkp-style input files.
Package docstring
Top-level package docstring and exported-symbol overview.
WannierIO.WannierIO Module
WannierIO.jl: a package for reading and writing Wannier90 file formats.
WannierIO.jl
A Julia package for reading/writing Wannier90 file formats.
The package is designed to be minimalistic to allow easy reuse in other packages.
Quick examples
using WannierIO
amn = read_amn("silicon.amn")
write_amn("silicon_2.amn", amn.A; amn.header)
chk = read_chk("silicon.chk")
write_chk("silicon_2.chk", chk; binary=true)Related packages
- Wannier.jl: Wannierization and Wannier interpolation. The IO part of
Wannier.jlwas isolated and moved into this package.
Exported functions:
Page index
WannierIO.WannierIOWannierIO.BohrWannierIO.Bohr_QEWannierIO.AbstractFileFormatWannierIO.AbstractFortranFormatWannierIO.AbstractW90InputFormatWannierIO.FortranBinaryWannierIO.FortranBinaryStreamWannierIO.FortranTextWannierIO.HDF5FormatWannierIO.JLD2FormatWannierIO.W90DatWannierIO.W90InputTextWannierIO.W90InputTomlWannierIO.ZarrFormatWannierIO.ZarrZipFormatWannierIO._isapproxWannierIO.default_headerWannierIO.detect_fortran_formatWannierIO.detect_operator_formatWannierIO.detect_w90input_formatWannierIO.format_indicesWannierIO.format_nameWannierIO.fortran_formatWannierIO.from_tomlWannierIO.from_tomlWannierIO.isbinaryWannierIO.isbinaryWannierIO.isbinaryWannierIO.istomlWannierIO.nextlineWannierIO.parse_boolWannierIO.parse_boolWannierIO.parse_floatWannierIO.parse_indicesWannierIO.parse_vectorWannierIO.strip_commentWannierIO.to_tomlWannierIO.w90input_formatWannierIO.write_toml