Read and write files
WannierIO follows a consistent IO pattern across Wannier90 formats:
read with a
read_*function,if needed, modify the returned Julia data,
write back with the matching
write_*function.
IO conventions
Function pairs are usually named
read_xxxandwrite_xxx.Most readers/writers accept a filename or an
IOstream.For several Wannier90 files, writing supports
binary=trueto emit Fortran unformatted files.Tight-binding files additionally support backend formats (HDF5/JLD2/Zarr) via
read_w90_tbandwrite_w90_tb.
Common workflows
1. Round-trip a plain-text Wannier90 file
using WannierIO
amn = read_amn("silicon.amn")
write_amn("silicon_copy.amn", amn.A; header=amn.header)The same pattern applies to other files such as read_mmn/write_mmn, read_eig/write_eig, and read_nnkp/write_nnkp.
2. Write Fortran binary files
using WannierIO
chk = read_chk("silicon.chk")
write_chk("silicon_binary.chk", chk; binary=true)
spn = read_spn("silicon.spn")
write_spn("silicon_binary.spn", spn; binary=true)This is useful when interoperating with workflows that expect native Fortran unformatted output.
3. Work with win input files
using WannierIO
win = read_win("silicon.win")
win["num_iter"] = 200
write_win("silicon_new.win", win)read_win can parse both text and TOML-style inputs via format detection.
4. Read and write tight-binding files
using WannierIO
# High-level API with automatic wsvec handling when available.
pack = read_w90_tb("silicon_tb.dat")
write_w90_tb("silicon_out_tb.dat", pack)For details on reduction and sparse backends, see Tight-binding operators and Sparse storage.
5. Volumetric data formats
using WannierIO
xsf = read_xsf("charge.xsf")
write_xsf("charge_copy.xsf", xsf)
cube = read_cube("density.cube")
write_cube("density_copy.cube", cube)Supported volumetric formats include XSF, CUBE, and BXSF.
Tips
Preserve metadata fields (for example headers/lattice metadata) when writing modified data.
If you rely on binary files, test round-trip compatibility on your target compiler/platform because unformatted Fortran records are not universally portable.
Prefer high-level helpers like
read_w90_tbunless you explicitly need low-level file-to-file control.
For a deeper API-level reference, see Wannier90 and Tight binding.