TRIQS/triqs_modest 3.3.0
Modular Electronic Structure Toolkit
Loading...
Searching...
No Matches
printing.cpp
Go to the documentation of this file.
1// Copyright (c) 2025--present, The Simons Foundation
2// This file is part of TRIQS/modest and is licensed under the terms of GPLv3 or later.
3// SPDX-License-Identifier: GPL-3.0-or-later
4// See LICENSE in the root of this distribution for details.
5
6#include "./downfolding.hpp"
7#include "./embedding.hpp"
8#include <algorithm>
9#include <fmt/base.h>
10#include <triqs/utility/report_stream.hpp>
12#include <fmt/ranges.h>
13#include <ranges>
14namespace triqs::modest {
15
16 // ----------------------------- PRINT FUNCTIONS ---------------------------------------------
17
18 std::ostream &operator<<(std::ostream &out, band_dispersion const &x) {
19 out << "Band dispersion ε^σ(k) on a grid [band_dispersion]:\n";
20 auto out1 = triqs::utility::indented_ostream(out, 2);
21 out1 << fmt::format("Number of bands (max): {}\n", x.H_k.extent(3));
22 out1 << fmt::format("Represented on a fixed grid of {} points.\n", x.n_k());
23 out1 << fmt::format("Shape of H[k_idx, σ, ν, ν'] = {}\n", x.H_k.shape());
24 out1 << fmt::format("ε^σ(k) is matrix valued? = {}\n", x.matrix_valued);
25 return out;
26 }
27
28 // ---------------------------------------------------------------------------------------------
29
30 std::ostream &operator<<(std::ostream &out, downfolding_projector const &x) {
31 out << "Downfolding projector P^σ_mν(k) on a grid [downfolding_projector]:\n";
32 auto out1 = triqs::utility::indented_ostream(out, 2);
33 out1 << fmt::format("Shape of P[k_idx, σ, m, ν] = {}\n", x.P_k.shape());
34 return out;
35 }
36
37 // ---------------------------------------------------------------------------------------------
38
39 std::ostream &operator<<(std::ostream &out, local_space const &x) {
40 out << "Local space [orbital_set]:\n";
41 auto out1 = triqs::utility::indented_ostream(out, 2); // same stream, but shifted by 2 spaces
42 auto out2 = triqs::utility::indented_ostream(out, 4);
43 auto out3 = triqs::utility::indented_ostream(out, 6);
44 out1 << fmt::format("Total dimension [M]: {}\n", x.dim());
45 out1 << fmt::format("Number of correlated atoms: {}\n", x.atomic_shells().size());
46 // auto ineq = 0;
47 // for (auto iatom : range(x.atomic_shells().size())) {
48 // if (x.first_shell_of_its_equiv_cls(iatom) == iatom) ineq++;
49 // }
50 auto ineq = stdr::count_if(range(x.atomic_shells().size()), //
51 [&](auto i) { return x.first_shell_of_its_equiv_cls(i) == i; });
52 out1 << fmt::format("Number of inequivalent correlated atoms = {}\n", ineq);
53
54 out1 << "Atomic decomposition:\n";
55 auto pr_vec = [](auto const &V) {
56 return fmt::format("{}\n", fmt::join(V | stdv::transform([](auto x) { return fmt::format("{:>3}", x); }), " "));
57 };
58 auto dec = x.atomic_decomposition();
59 out2 << " dim_a: " << pr_vec(dec);
60 out2 << " a: " << pr_vec(range(dec.size()));
61 auto sub = x.atoms_block_decomposition()(r_all, 0) | stdv::transform([](auto x) { return fmt::format("{}", x); });
62 out2 << "irreps: " << fmt::format("{}\n", fmt::join(sub, " "));
63 return out;
64 }
65
66 // ---------------------------------------------------------------------------------------------
67 std::ostream &operator<<(std::ostream &out, ibz_symmetry_ops const &ibz) {
68 out << "[I]rreduicible [B]rillouin [Z]one symmetry operations from the DFT code [ibz_symmetry_ops]\n";
69 auto out1 = triqs::utility::indented_ostream(out, 2);
70 out1 << fmt::format("Number of symmetry ops: {}\n", ibz.ops.size());
71 out1 << fmt::format("Number of rotations per op: {}\n", ibz.ops[0].mats.size());
72 return out;
73 }
74
75 // ---------------------------------------------------------------------------------------------
76
77 std::ostream &operator<<(std::ostream &out, one_body_elements_on_grid const &obe) {
78 auto out1 = triqs::utility::indented_ostream(out, 2); // same stream, but shifted by 2 spaces
79 auto out2 = triqs::utility::indented_ostream(out, 4);
80 out << "One body elements representing a downfolding from (restricted) Bloch 𝓑 to Correlated space 𝓒 from DFT code [one_body_elements_on_grid]\n";
81 out1 << "H:\n";
82 out2 << obe.H;
83 out1 << "C_space:\n";
84 out2 << obe.C_space;
85 out1 << "P:\n";
86 out2 << obe.P;
87 out1 << fmt::format("IBZ = {}\n", bool(obe.ibz_symm_ops));
88 if (obe.ibz_symm_ops) { out2 << obe.ibz_symm_ops.value(); };
89 return out;
90 }
91
92 // ------------------------------ PRINTING -------------------------------------------------------------
93
94 auto format_as(embedding::imp_block_t const &p) {
95 //return fmt::format("({},{},{})", p.n_imp, p.gamma, p.tau);
96 return fmt::format("(imp_idx = {}, γ = {}, τ = {})", p.imp_idx, p.gamma, p.tau);
97 }
98
99 // -------------------------------------------------------------------------------------------------------
100
101 std::string embedding::description(bool verbosity) const {
102 auto sigma_embed_shape = this->embed_block_structure();
103 auto impurities_shape_list = this->imp_block_structure();
104
105 std::ostringstream out;
106 auto out1 = utility::indented_ostream(out, 2); // same stream, but shifted by 2 spaces
107 auto out2 = utility::indented_ostream(out, 4);
108 auto out3 = utility::indented_ostream(out, 6);
109
110 // Detect impurities not connected to any alpha block.
111 auto unconnected_imps = std::vector<long>{};
112 auto is_unconnected = std::vector<bool>(n_impurities(), true);
113 for (long n = 0; n < n_impurities(); ++n) {
114 is_unconnected[n] = stdr::all_of(reverse_psi[n], [](auto const &v) { return v.empty(); });
115 if (is_unconnected[n]) unconnected_imps.push_back(n);
116 }
117
118 auto fmt_vec = [](auto const &V) { return fmt::join(V | stdv::transform([](auto x) { return fmt::format("{:>3}", x); }), " "); };
119 auto pr_vec = [&](auto const &V) { return fmt::format("{}\n", fmt_vec(V)); };
120
121 if (!verbosity) {
122 out << "Embedding: ";
123 out << fmt::format("{} impurities\n", this->n_impurities());
124 out1 << "Σ_embed block decomposition:\n";
125 out2 << "dim_α: " << pr_vec(this->sigma_embed_decomp);
126 out2 << " α: " << pr_vec(range(this->sigma_embed_decomp.size()));
127 out1 << "\nImpurities\n";
128 out2 << "Block dimensions, dim_γ for all γ:\n";
129 for (auto &&[n, dec] : enumerate(this->imp_decomps)) {
130 auto head = fmt::format("[n_imp = {}]", n);
131 auto tag = is_unconnected[n] ? " \033[31m(not connected)\033[0m" : "";
132 out3 << fmt::format("{} dim_γ = {}{}\n", head, fmt_vec(dec), tag);
133 out3 << fmt::format("{:>{}} γ = {}", " ", head.size(), pr_vec(range(dec.size())));
134 }
135 if (!unconnected_imps.empty()) out << fmt::format("\nImpurities not connected to any alpha block: {}\n", unconnected_imps);
136 return out.str();
137 }
138
139 out << "Embedding:\n";
140 out1 << fmt::format("Spin index (σ/τ) names: {}\n\n", this->sigma_names());
141 out1 << "Σ_embed block decomposition:\n";
142 out2 << "dim_α: " << pr_vec(this->sigma_embed_decomp);
143 out2 << " α: " << pr_vec(range(this->sigma_embed_decomp.size()));
144 out1 << "\nImpurities\n";
145 out2 << "Block dimensions, dim_γ for all γ:\n";
146 for (auto &&[n, dec] : enumerate(this->imp_decomps)) {
147 auto head = fmt::format("[n_imp = {}]", n);
148 auto tag = is_unconnected[n] ? " \033[31m(not connected)\033[0m" : "";
149 out3 << fmt::format("{} dim_γ = {}{}\n", head, fmt_vec(dec), tag);
150 out3 << fmt::format("{:>{}} γ = {}", " ", head.size(), pr_vec(range(dec.size())));
151 }
152 out2 << "Gf Block structures for solvers as names, [dim]:\n";
153 for (auto &&[n, ish] : enumerate(impurities_shape_list)) {
154 auto formatted_vec = ish | stdv::transform([](auto &&p) { return fmt::format("{} [{}]", p.first, p.second); }) | tl::to<std::vector>();
155 out3 << fmt::format("[imp_idx = {}] {}\n", n, fmt::join(formatted_vec, ", "));
156 }
157 out1 << "\nMapping ψ(α,σ) = (imp_idx, γ, τ) \n";
158 auto row_labels = range(this->n_alpha()) | stdv::transform([](auto x) { return fmt::format("α = {}", x); }) | tl::to<std::vector>();
159 auto col_labels = range(this->n_sigma()) | stdv::transform([&](auto i) { return fmt::format("σ = {} / {}", i, this->sigma_names()[i]); })
160 | tl::to<std::vector>();
161 nda::format_as_table(out3, this->psi, row_labels, col_labels);
162 if (!unconnected_imps.empty()) out << fmt::format("\nImpurities not connected to any alpha block: {}\n", unconnected_imps);
163
164 return out.str();
165 }
166
167 std::ostream &operator<<(std::ostream &out, embedding const &E) {
168 out << E.description(false);
169 return out;
170 }
171
172} // namespace triqs::modest
std::vector< gf_struct_t > imp_block_structure() const
Block structure (names and dimensions) for each impurity solver.
long n_impurities() const
Number of impurities.
long n_sigma() const
Number of blocks in for the .
embedding(std::vector< long > sigma_embed_decomposition, std::vector< std::vector< long > > imp_decompositions, nda::array< imp_block_t, 2 > psi, std::vector< std::string > sigma_names)
Construct an embedding object.
Definition embedding.cpp:17
std::vector< std::string > sigma_names() const
The names of the sigma indices.
long n_alpha() const
Number of blocks in for the .
C2PY_IGNORE gf_struct2_t embed_block_structure() const
Block structure (names and dimensions) for the embedded self-energy .
std::string description(bool verbosity=false) const
Summarize the embedding object.
Definition printing.cpp:101
Describe the atomic orbitals within downfolded space.
nda::array< std::vector< long >, 2 > const & atoms_block_decomposition() const
2-dim array of all blocks spanning space -> atoms_block_decomposition.
long dim() const
Dimension of the correlated space.
std::vector< atomic_orbs > const & atomic_shells() const
List of all atomic shells spanning the space.
std::vector< long > atomic_decomposition() const
Dimensions of each atomic shell, in order.
void format_as_table(std::ostream &out, nda::Matrix auto const &mat, auto const &row_labels, auto const &col_labels)
Format the matrix mat as a table, with row/col_labels.
std::ostream & operator<<(std::ostream &out, one_body_elements_on_grid const &)
Definition printing.cpp:77
auto format_as(embedding::imp_block_t const &p)
Definition printing.cpp:94
static constexpr auto r_all
Definition defs.hpp:33
The one-body dispersion as a function of momentum.
bool matrix_valued
Is the dispersion matrix-valued?
nda::array< dcomplex, 4 > H_k
Hamiltonian .
long n_k() const
Number of k-points in the grid.
The projector that downfolds the energy bands onto a set of localized atomic-like orbitals.
nda::array< dcomplex, 4 > P_k
Projector .
Irreducible Brillouin Zone (IBZ) symmetry operations to symmetrize observables over the entire Brillo...
A one-body elements struct where all of the underlying data exists on a fixed momentum grid.
std::optional< ibz_symmetry_ops > ibz_symm_ops
IBZ symmetrizer after a k-sum.
band_dispersion H
Band dispersion.
downfolding_projector P
Downfolding projector .