Loading...
Searching...
No Matches
exchange_correlation_potential.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * BerkeleyGWExchangeCorrelationPotentialFile — writes BerkeleyGW's `VXC` file:
5 * V_xc(G) itself, from which sigma computes its own <nk|V_xc|nk> when told
6 * `dont_use_vxcdat` instead of reading them from `vxc.dat`.
7 *
8 * Layout: BerkeleyGWFieldFile with the title "VXC-Complex" -- the BerkeleyGW
9 * specification's VXC file, in Rydberg, its G = 0 component the cell average.
10 * That is the record's `exchange_correlation_potential_g` unscaled. sigma reads
11 * it for exactly the bands it needs, which is what makes it the route for bands
12 * the NSCF never had -- those parabands adds beyond them.
13 *
14 * SCOPE: spin-unpolarized only. The record carries one Vxc(G), the spin
15 * average, and VXC is per spin; writing the average into both channels would
16 * be wrong for any magnetic system, so a spin-polarized record is refused.
17 */
18
19#include <fstream>
20#include <stdexcept>
21#include <string>
22#include <vector>
23
24#include "io/logger.hpp"
27
28namespace q3 {
29
30/// Writes `VXC` from a mean-field record; see the file comment.
32 public:
34 : record_(record) {}
35 /// See BerkeleyGWChargeDensityFile: this holds a reference.
37
38 /// Writes the file, or throws -- before creating it -- when the record cannot supply it.
39 void write_to_file(const std::string& file_path) const {
40 if (record_.number_of_spin_components > 1) {
41 throw std::runtime_error(
42 "the record carries the spin-averaged Vxc(G) only, and VXC is per spin; "
43 "spin-polarized VXC export is not supported");
44 }
45 if (record_.exchange_correlation_potential_g.empty()) {
46 throw std::runtime_error("the mean-field record carries no exchange-correlation "
47 "potential");
48 }
49
50 std::ofstream output_file(file_path, std::ios::binary);
51 if (!output_file.is_open()) {
52 throw std::runtime_error("cannot open " + file_path + " for writing");
53 }
54 const std::vector<std::vector<Complex>> values_per_spin = {
56 BerkeleyGWFieldFile(record_, "VXC-Complex", values_per_spin, 1.0).write(output_file);
57
58 log::info(" Wrote BerkeleyGW exchange-correlation potential file: {}", file_path);
59 }
60
61 private:
62 const MeanFieldRecord& record_;
63};
64
65} // namespace q3
Writes VXC from a mean-field record; see the file comment.
void write_to_file(const std::string &file_path) const
Writes the file, or throws – before creating it – when the record cannot supply it.
BerkeleyGWExchangeCorrelationPotentialFile(const MeanFieldRecord &&)=delete
See BerkeleyGWChargeDensityFile: this holds a reference.
One per-spin field on the charge-density G-set, in RHO's layout; see the file comment.
Definition field.hpp:32
void write(std::ofstream &output_file) const
Writes header, G-set and field to an open stream; throws if the field is not on the G-set.
Definition field.hpp:55
void info(spdlog::format_string_t< Args... > fmt, Args &&... args)
Definition logger.hpp:183
int number_of_spin_components
Definition init.hpp:127
std::vector< Complex > exchange_correlation_potential_g
Definition init.hpp:154