6#include <nda/layout/range.hpp>
7#include <nda/matrix_functions.hpp>
8#include <triqs/gfs.hpp>
9#include <triqs/utility/exceptions.hpp>
12#include <triqs/lattice/wannier_loader.hpp>
24 std::vector<atomic_orbs> atomic_shells) {
26 throw std::runtime_error(
"If performing a spin-polarized calculation, you need to supply two Wannier file paths for up and down channels.\n");
30 auto [R, HR, _] = read_wannier90_tb_data(wannier_file_path);
31 std::vector<tb_hamiltonian> tb_H;
32 tb_H.emplace_back(R, HR);
36 return make_obe_from_tb(std::move(tb_H), spin_kind, std::move(atomic_shells));
40 spin_kind_e spin_kind, std::vector<atomic_orbs> atomic_shells) {
42 throw std::runtime_error(
"For a non-spin polarized calculation, you should specify only one Wannier Hamiltonian.\n");
46 std::vector<tb_hamiltonian> tb_H;
47 for (
auto file : {wannier_file_path_up, wannier_file_path_dn}) {
48 auto [R, HR, _] = read_wannier90_tb_data(file);
49 tb_H.emplace_back(R, HR);
51 if (tb_H[0].n_orbitals() != tb_H[1].n_orbitals()) {
52 throw std::runtime_error(
53 "Cannot construct a one_body_elements "
54 "using up and down H_k that have a different number of orbtials.");
56 return make_obe_from_tb(std::move(tb_H), spin_kind, std::move(atomic_shells));
64 nda::array<nda::matrix<dcomplex>, 2>
Hloc(std::vector<tb_hamiltonian>
const &H_sigma, std::vector<atomic_orbs>
const &atomic_shells) {
71 nda::array<nda::matrix<dcomplex>, 2> Hloc_result(atomic_shells.size(), H_sigma.size());
73 for (
auto [isigma, H] : enumerate(H_sigma)) {
78 for (
auto shell : atomic_shells) { n_orb += shell.dim; }
79 if (H.n_orbitals() != n_orb) {
80 throw std::runtime_error(
"Wannier Hamiltonian does not have the same number of orbitals as the provided atomic shells: HR "
81 + std::to_string(H.n_orbitals()) +
" , atomic_shells total " + std::to_string(n_orb));
85 auto iR0 = H.get_R_idx(std::array<long, 3>{0, 0, 0});
91 for (
auto &&[ishell, shell] : enumerate(atomic_shells)) {
92 auto Hloc0_ab = nda::zeros<dcomplex>(shell.dim, shell.dim);
94 for (
auto iorb : nda::range(shell.dim)) {
95 for (
auto jorb : nda::range(shell.dim)) { Hloc0_ab(iorb, jorb) = H.hoppings()[iR0](start_orb + iorb, start_orb + jorb); }
96 start_orb += shell.dim;
98 Hloc_result(ishell, isigma) = Hloc0_ab;
110 nda::array<nda::matrix<dcomplex>, 2> Hloc_result(n_atoms, n_sigma);
112 for (
auto sigma : range(n_sigma)) {
115 auto iR0 = obe.
H[sigma].get_R_idx({0, 0, 0});
118 Hloc_result(atom, sigma) = obe.
H[sigma].hoppings()[iR0](R_atom, R_atom);
129 nda::array<nda::matrix<dcomplex>, 2> hloc =
Hloc(H_sigma, atomic_shells);
132 double block_threshold = 1e-6;
133 bool diagonalize_hloc =
false;
134 auto [decomposition, U] =
discover_symmetries(hloc, atomic_shells, block_threshold, diagonalize_hloc);
137 auto LS =
local_space(spin_kind, atomic_shells, decomposition, U, {});
146 auto new_H = obe.
H | stdv::transform([&](
auto x) {
return fold(sl, x); }) | tl::to<std::vector>();
148 decltype(sh) new_atomic_shells;
150 nda::array<std::vector<long>, 2> new_dec(dec.extent(0) * sl.n_cluster_sites(), dec.extent(1));
151 for (
auto i : nda::range(sl.n_cluster_sites())) {
152 for (
auto &&[j, shell] : enumerate(sh)) {
153 new_atomic_shells.emplace_back(shell);
154 new_dec(i * sh.size() + j,
r_all) = dec(j,
r_all);
Describe the atomic orbitals within downfolded space.
spin_kind_e spin_kind() const
long n_sigma() const
Dimension of the σ index.
nda::array< std::vector< long >, 2 > const & atoms_block_decomposition() const
List of all blocks spanning 𝓒 space -> atoms_block_decomposition.
auto atomic_decomposition() const
Generates [dimension of the atomic shell].
std::vector< atomic_orbs > const & atomic_shells() const
List of all atomic shells spanning the 𝓒 space.
long n_atoms() const
The number of atoms.
nda::array< nda::matrix< dcomplex >, 2 > impurity_levels(one_body_elements_on_grid const &obe)
Compute the local impurity levels from the single-particle dispersion.
one_body_elements_tb fold(lattice::superlattice const &sl, one_body_elements_tb const &obe)
one_body_elements_tb make_obe_from_tb(std::vector< tb_hamiltonian > H_sigma, spin_kind_e spin_kind, std::vector< atomic_orbs > atomic_shells)
Helper to contruct and return an OBE_tb object given a list of tb_Hamiltonians of length n_sigma.
spin_kind_e
Kind of σ index.
std::pair< nda::array< std::vector< long >, 2 >, nda::array< nda::matrix< dcomplex >, 2 > > discover_symmetries(nda::array< nda::matrix< dcomplex >, 2 > const &Hloc0, std::vector< atomic_orbs > const &atomic_shells, double block_threshold, bool diagonalize_hloc)
Find symmetries of the R = 0 component of a Hamiltonian to determine a GF block structure.
nda::array< nda::matrix< dcomplex >, 2 > Hloc(std::vector< tb_hamiltonian > const &H_sigma, std::vector< atomic_orbs > const &atomic_shells)
Compute Hloc = H(R=0) given n_sigma tight_binding Hamiltonians.
one_body_elements_tb one_body_elements_from_wannier90(std::string const &wannier_file_path, spin_kind_e spin_kind, std::vector< atomic_orbs > atomic_shells)
Construct a obe_tb from Wannier90 in the case of a single spin index.
static constexpr auto r_all
generator< std::pair< long, nda::range > > enumerated_sub_slices(auto sub_div)
std::vector< tb_hamiltonian > H