Skip to content

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.

source
WannierIO.Bohr_QE Constant

Bohr radius in Angstrom unit.

This is the default (Physical constants, SI (NIST 2018)) value in QE Modules/constants.f90.

source

Helper functions

General helpers for parsing, headers, TOML conversion, and comparisons.

WannierIO.default_header Method

Default header for writing wannier90 files.

source
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.

source
WannierIO.from_toml Method

Fallback to doing nothing.

source
WannierIO.istoml Method
julia
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.

source
WannierIO.to_toml Method
julia
to_toml(x)

Convert types for TOML writing.

Examples

julia
using TOML
x = Dict(:a => (; b=1))
TOML.print(to_toml, x)
source
WannierIO.write_toml Function

Write kwargs into io as a TOML file.

This is more convenient than TOML.print, in that:

  1. Do some type conversion before writing.

  2. Keep the order of kwargs, whereas TOML.print always requires a Dict which will change the order of keys.

Examples

julia
write_toml(stdout; b=2, a=1)
source
WannierIO.format_indices Method
julia
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
julia> format_indices([1, 2, 5, 8, 9, 10])
"1-2 5 8-10"
source
WannierIO.nextline Method
julia
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.
source
WannierIO.parse_bool Method
julia
parse_bool(s)

Parse a string as bool.

This is capable of parsing Fortran outputs, e.g., .true., .false., true, T.

source
WannierIO.parse_bool Method
julia
parse_bool(i)

Parse an integer as bool.

  • 0: false

  • 1 or -1: true

source
WannierIO.parse_float Method
julia
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.

source
WannierIO.parse_indices Method
julia
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
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")
source
WannierIO.parse_vector Method
julia
parse_vector(io, T, n_elements)

Parse a vector of n_elements elements of type T from io.

Arguments

  • io: input stream

  • T: type of elements

  • n_elements::Int: total number of elements

Examples

Suppose a file demo.txt has the following content:

julia
1  2  3  4  5  6  7  8  9  10
11 12 13 14 15 16 17 18 19 20
21 22 23

Then the following code parses the file and return a vector filled with 1 to 23:

julia
julia> vector = open("demo.txt") do io
    parse_vector(io, Int, 23)
end

The number of elements in each line can be different.

source
WannierIO.strip_comment Method
julia
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.
source
WannierIO._isapprox Method
julia
_isapprox(a, b)

Compare two (same-type) structs.

source

Low-level helpers for formatted/unformatted Fortran IO.

WannierIO.isbinary Method
julia
isbinary(filename)

Check if the file is in binary format.

source
WannierIO.isbinary Method
julia
isbinary(chars)

Check if a sequence of chars is binary.

source
WannierIO.isbinary Method
julia
isbinary(io)

Check if the IO is in binary format.

This function preserves the stream position for seekable IO.

source

File 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.

source
WannierIO.AbstractFortranFormat Type

Abstract supertype for Fortran-style matrix/data file formats.

source
WannierIO.AbstractW90InputFormat Type

Abstract supertype for Wannier90 small input-file formats such as win and nnkp.

source
WannierIO.FortranBinary Type

Fortran unformatted record-based IO.

source
WannierIO.FortranBinaryStream Type

Fortran unformatted IO with stream access.

For example, file written using these Fortran code:

fortran
OPEN(UNIT=11, FILE="ustream.demo", STATUS="NEW", ACCESS="STREAM", FORM="UNFORMATTED")
source
WannierIO.FortranText Type

Fortran formatted text IO.

source
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.

source
WannierIO.JLD2Format Type

JLD2 storage format for tight-binding data.

Requires loading the JLD2 package.

source
WannierIO.W90Dat Type

Native Wannier90 tight-binding text format (.dat files written by Wannier90).

source
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.

source
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.

source
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.

source
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.

source
WannierIO.detect_fortran_format Method
julia
detect_fortran_format(file; stream=false)

Infer a Fortran-format tag from file using isbinary.

source
WannierIO.detect_operator_format Method
julia
detect_operator_format(path)

Infer an operator storage format tag from the file extension of path:

source
WannierIO.detect_w90input_format Method
julia
detect_w90input_format(file)

Infer a win/nnkp format tag from file using istoml.

source
WannierIO.format_name Method
julia
format_name(format)

Return a short human-readable name for a FileFormat tag.

source
WannierIO.fortran_format Method
julia
fortran_format(; binary=false, stream=false)

Construct a Fortran-format tag.

source
WannierIO.w90input_format Method
julia
w90input_format(; toml=false)

Construct a format tag for win/nnkp-style input files.

source

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

Stable Dev CI codecov code style: runic

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

julia
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.jl was isolated and moved into this package.

Exported functions:

source

Page index