Quantum 3xplorer (Q3)
An AI-native quantum simulation engine
Loading...
Searching...
No Matches
exporter.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * Wannier90Exporter — an InterpolationRecord's Wannier payload as the four
5 * Wannier90-format files (`<prefix>.mmn`, `.amn`, `.eig`, `.nnkp`).
6 *
7 * The one place that knows both the record's units and the formats'. The
8 * `.nnkp` lattice blocks are Angstrom and inverse Angstrom while the record
9 * carries bohr; the `.eig` is eV while the record holds Rydberg. The record
10 * stays in Q3's units, the format writer stays ignorant of Q3's conventions,
11 * and the conversion lives here.
12 *
13 * A record imported from Wannier90 files carries neither a neighbour table
14 * nor overlaps (see importer.hpp); exporting it writes the `.amn`
15 * and `.eig` that can be written and says so, rather than a `.nnkp` with an
16 * empty nnkpts block or an empty `.mmn` that a consumer would take for real.
17 */
18
19#include <filesystem>
20#include <stdexcept>
21#include <string>
22
25#include "io/logger.hpp"
28
29namespace q3 {
30
32 public:
34 const std::string& directory,
35 const std::string& prefix) const override {
36 if (record.method != "wannier") {
37 throw std::invalid_argument("Wannier90Exporter: the record was built by the '" +
38 record.method +
39 "' method and carries no Wannier interface matrices");
40 }
41 Matrix3x3 real_lattice_angstrom;
42 Matrix3x3 reciprocal_lattice_inverse_angstrom;
43 for (int row = 0; row < 3; row++) {
44 real_lattice_angstrom[row] =
46 reciprocal_lattice_inverse_angstrom[row] =
48 }
49 std::filesystem::create_directories(directory);
50 const std::string seedname = directory + "/" + prefix;
51 const WannierInputs& wannier = record.wannier;
52 Wannier90FormatWriter::write_projections(seedname + ".amn", wannier);
53 Wannier90FormatWriter::write_eigenvalues(seedname + ".eig", wannier);
54 if (wannier.neighbor_directions.empty() || wannier.overlap_matrices.empty()) {
55 log::warn("wrote {}.amn and .eig only: this record carries no neighbour table or "
56 "overlaps (it was imported from projections and eigenvalues), so no .nnkp "
57 "or .mmn is written -- the files it was imported from are those",
58 seedname);
59 return;
60 }
62 wannier,
63 real_lattice_angstrom,
64 reciprocal_lattice_inverse_angstrom);
65 Wannier90FormatWriter::write_overlaps(seedname + ".mmn", wannier);
66 log::info("wrote {}.mmn, .amn, .eig and .nnkp", seedname);
67 }
68
69 [[nodiscard]] std::string name() const override {
70 return "wannier90";
71 }
72};
73
74} // namespace q3
std::string name() const override
Format name as accepted by the input ("none", "wannier90", ...).
Definition exporter.hpp:69
void export_to_directory(const InterpolationRecord &record, const std::string &directory, const std::string &prefix) const override
Definition exporter.hpp:33
static void write_projections(const std::string &file_path, const WannierInputs &record)
Definition writer.hpp:109
static void write_eigenvalues(const std::string &file_path, const WannierInputs &record)
Definition writer.hpp:137
static void write_neighbor_list(const std::string &file_path, const WannierInputs &record, const Matrix3x3 &real_lattice, const Matrix3x3 &reciprocal_lattice)
Definition writer.hpp:160
static void write_overlaps(const std::string &file_path, const WannierInputs &record)
Definition writer.hpp:76
constexpr Real ANGSTROM_TO_BOHR
Ångström → Bohr (ANGSTROM_AU)
constexpr Real BOHR_RADIUS_ANGSTROM
Bohr radius in Ångströms (BOHR_RADIUS_SI * 1e10; BOHR_RADIUS_ANGSTROM)
void warn(spdlog::format_string_t< Args... > fmt, Args &&... args)
Definition logger.hpp:187
void info(spdlog::format_string_t< Args... > fmt, Args &&... args)
Definition logger.hpp:183
WannierInputs wannier
Payload for method == "wannier": interface matrices on the full k-grid.
Definition record.hpp:46
Matrix3x3 real_lattice_bohr
Rows a1, a2, a3, Cartesian, in bohr.
Definition record.hpp:34
std::string method
The method that built the payload: "wannier".
Definition record.hpp:31
Matrix3x3 reciprocal_lattice_inverse_bohr
Rows b1, b2, b3, Cartesian, in inverse bohr, with the 2 pi included.
Definition record.hpp:36
3×3 matrix stored row-major: row i = mat[i]
std::vector< KPointNeighborDirection > neighbor_directions
Definition inputs.hpp:49
std::vector< std::vector< std::vector< Complex > > > overlap_matrices
Definition inputs.hpp:60