35 void read(
const std::string& path) {
36 std::ifstream stream(path, std::ios::binary);
38 throw std::runtime_error(
"Cannot read wavefunction file: " + path);
41 const std::vector<char> header = read_record(stream);
42 if (header.size() != kpoint_header_bytes) {
43 throw_corrupt(
"its k-point header is " + std::to_string(header.size()) +
44 " bytes, not the packed " + std::to_string(kpoint_header_bytes) +
45 " (a file from a Q3 build that padded the header is not readable)");
47 std::memcpy(&kpoint_coordinates_.
x, header.data() + 4,
sizeof(
double));
48 std::memcpy(&kpoint_coordinates_.
y, header.data() + 12,
sizeof(
double));
49 std::memcpy(&kpoint_coordinates_.
z, header.data() + 20,
sizeof(
double));
50 std::memcpy(&is_gamma_only_flag_, header.data() + 32,
sizeof(int32_t));
52 const std::vector<char> dimensions = read_record(stream);
53 if (dimensions.size() != 4 *
sizeof(int32_t))
54 throw_corrupt(
"its dimension record is not four integers");
55 const auto* dimension_values =
reinterpret_cast<const int32_t*
>(dimensions.data());
57 number_of_bands_ = dimension_values[3];
60 " plane wave(s) and " + std::to_string(number_of_bands_) +
" band(s)");
63 const std::vector<char> reciprocal = read_record(stream);
64 if (reciprocal.size() != 9 *
sizeof(
double))
65 throw_corrupt(
"its reciprocal-lattice record is not nine reals");
66 const auto* vectors =
reinterpret_cast<const double*
>(reciprocal.data());
67 for (
int row = 0; row < 3; row++)
68 for (
int column = 0; column < 3; column++)
69 reciprocal_lattice_vectors_[row][column] = vectors[row * 3 + column];
71 const std::vector<char> millers = read_record(stream);
73 throw_corrupt(
"its Miller-index record is the wrong length");
74 const auto* miller_values =
reinterpret_cast<const int32_t*
>(millers.data());
77 miller_indices_[index] = {miller_values[3 * index],
78 miller_values[3 * index + 1],
79 miller_values[3 * index + 2]};
82 band_coefficients_.assign(number_of_bands_, {});
83 for (
int band = 0; band < number_of_bands_; band++) {
84 const std::vector<char> coefficients = read_record(stream);
85 if (coefficients.size() !=
87 throw_corrupt(
"the record for band " + std::to_string(band + 1) +
88 " is the wrong length");
90 const auto* values =
reinterpret_cast<const Complex*
>(coefficients.data());