TRIQS/triqs_modest 3.3.0
Modular Electronic Structure Toolkit
Loading...
Searching...
No Matches
obe_tb.hpp
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#pragma once
7#include <triqs/tb/tb_hamiltonian.hpp>
8#include <mpi/mpi.hpp>
9#include <stdexcept>
10#include <triqs/mesh/imfreq.hpp>
11#include "loaders.hpp"
12#include "triqs/lattice/bz_integrators.hpp"
13#include "triqs/lattice/gloc.hpp"
15#include <nda/nda.hpp>
16#include <triqs/gfs/functions/density.hpp>
17#include <triqs/utility/root_finder.hpp>
18#include "triqs/tb/superlattice.hpp"
19
20namespace triqs::modest {
21
22 using namespace triqs::tb;
23 using namespace triqs::lattice;
24
31 std::vector<tb_hamiltonian> H;
32 //downfolding_projector P;
33 //C2PY_IGNORE std::optional<ibz_symmetry_ops> ibz_symm_ops = {}; //< IBZ symmetrizer after a k-sum
34
36 bool operator==(one_body_elements_tb const &) const = default;
37
39 friend void mpi_broadcast(one_body_elements_tb &x, mpi::communicator c = {}, int root = 0) {
40 mpi::broadcast(x.C_space, c, root);
41 mpi::broadcast(x.H, c, root);
42 }
43 };
44
45 one_body_elements_tb one_body_elements_from_model(std::vector<std::array<long, 3>> const &Rs, std::vector<nda::array<dcomplex, 2>> const &HR,
46 spin_kind_e spin_kind, std::vector<atomic_orbs> atomic_shells);
47
63 one_body_elements_tb one_body_elements_from_wannier90(std::string const &wannier_file_path, spin_kind_e spin_kind,
64 std::vector<atomic_orbs> atomic_shells);
65
78 one_body_elements_tb one_body_elements_from_wannier90(std::string const &wannier_file_path_up, std::string const &wannier_file_path_dn,
79 spin_kind_e spin_kind, std::vector<atomic_orbs> atomic_shells);
80
// tb factories
82
84 C2PY_IGNORE one_body_elements_tb make_obe_from_tb(std::vector<tb_hamiltonian> const tb_H_sigma, spin_kind_e spin_kind,
85 std::vector<atomic_orbs> atomic_shells);
86
95 nda::array<nda::matrix<dcomplex>, 2> Hloc(std::vector<tb_hamiltonian> const &H_sigma, std::vector<atomic_orbs> const &atomic_shells);
96
104 nda::array<nda::matrix<dcomplex>, 2> impurity_levels(one_body_elements_tb const &obe);
105
113 one_body_elements_tb fold(superlattice const &sl, one_body_elements_tb const &obe);
114
124 one_body_elements_tb rotate(one_body_elements_tb const &obe, nda::matrix<dcomplex> const &U);
125
126 // -----------------------------------------------------------------------
127
131
148 template <typename Mesh>
149 block2_gf<Mesh, matrix_valued> gloc(one_body_elements_tb const &obe, double mu, block2_gf<Mesh, matrix_valued> const &Sigma_dynamic,
150 nda::array<nda::matrix<dcomplex>, 2> const &Sigma_static, triqs::lattice::bz_int_options const &opt) {
151
152 auto &mesh = Sigma_dynamic(0, 0).mesh();
153 auto n_sigma = obe.C_space.n_sigma();
154 auto gloc_result = make_block2_gf(mesh, obe.C_space.Gc_block_shape());
155 // TODO also check safety of orbital space sizes...
156 if (n_sigma != Sigma_static.shape(1)) { throw std::runtime_error("Mismatch between the spin channels in Sigma_Static and Sigma_Dynamic"); }
157 if (n_sigma != obe.H.size()) { throw std::runtime_error("Mismatch between the spin channels in Sigma and spin channels in Hamiltonian."); }
158
159 // Embedding decomposition from structure of Sigma -- provides a list of block names
160 auto embedding_decomp = get_struct(Sigma_dynamic).dims(r_all, 0) | tl::to<std::vector>();
161
162 for (auto sigma : range(n_sigma)) {
163
164 // spin index
165 auto Sigma_full_space = gfs::gf(mesh, {obe.H[sigma].n_orbitals(), obe.H[sigma].n_orbitals()}); //
166 for (auto &&[block, R] : enumerated_sub_slices(embedding_decomp)) {
167 for (auto [n, w] : enumerate(mesh)) {
168 Sigma_full_space.data()(n, R, R) = Sigma_dynamic(block, sigma).data()(n, r_all, r_all) + Sigma_static(block, sigma);
169 }
170 }
171 // Call the TRIQS version of this function
172 gloc_result(0, sigma) = triqs::lattice::gloc(obe.H[sigma], mu, Sigma_full_space, opt);
173 }
174 return gloc_result;
175 }
176
190 template <typename Mesh>
191 block2_gf<Mesh, matrix_valued> gloc(Mesh const &mesh, one_body_elements_tb const &obe, double mu, triqs::lattice::bz_int_options const &opt) {
192 auto result = make_block2_gf(mesh, obe.C_space.Gc_block_shape());
193 for (auto sigma : range(obe.C_space.n_sigma())) { result(0, sigma) = gloc(mesh, obe.H[sigma], mu, opt); }
194 return result;
195 }
196
198
199 // -----------------------------------------------------------------------
200
213 template <typename Mesh>
214 double density(one_body_elements_tb const &obe, double mu, block2_gf<Mesh, matrix_valued> const &Sigma_dynamic,
215 nda::array<nda::matrix<dcomplex>, 2> const &Sigma_static, triqs::lattice::bz_int_options const &opt) {
216
217 //auto n_blocks = Sigma_dynamic.size1();
218 auto n_sigma = obe.C_space.n_sigma();
219
220 double n = 0;
221 auto Gloc = gloc(obe, mu, Sigma_dynamic, Sigma_static, opt); // returns block2gf (1, nsigma, {norb, norb})
222 // return type of Gloc is a B2GF with dimensions (1, nspin, {norb, norb})
223 for (auto sigma : range(n_sigma)) { // spin index
224 n += real(nda::trace(density(Gloc(0, sigma))));
225 }
226 return n;
227 }
228
229 // -----------------------------------------------------------------------
245 template <typename Mesh>
246 double find_chemical_potential(double const target_density, one_body_elements_tb const &obe, block2_gf<Mesh, matrix_valued> const &Sigma_dynamic,
247 nda::array<nda::matrix<dcomplex>, 2> const &Sigma_static, triqs::lattice::bz_int_options const &opt,
248 std::string method = "dichotomy", double precision = 1.e-5, bool verbosity = true) {
249 std::function<double(double)> f = [&obe, &Sigma_dynamic, &Sigma_static, &opt](double x) {
250 return density(obe, x, Sigma_dynamic, Sigma_static, opt);
251 };
252 return std::get<0>(triqs::utility::root_finder(method, f, 0.0, target_density, precision, 0.5, 1000, "Chemical Potential", "Total Density", verbosity));
253 }
254
269 template <typename Mesh>
270 double find_chemical_potential(double const target_density, one_body_elements_tb const &obe, Mesh const &mesh,
271 triqs::lattice::bz_int_options const &opt, std::string method = "dichotomy", double precision = 1.e-5,
272 bool verbosity = true) {
273
274 auto Sigma_dynamic = make_block2_gf(mesh, obe.C_space.Gc_block_shape());
275 auto Sigma_static = nda::array<nda::matrix<dcomplex>, 2>(1, obe.C_space.n_sigma());
276 for (auto [i, j] : Sigma_static.indices()) { Sigma_static(i, j) = nda::zeros<dcomplex>(obe.C_space.dim(), obe.C_space.dim()); }
277 return find_chemical_potential(target_density, obe, Sigma_dynamic, Sigma_static, opt, method, precision, verbosity);
278 }
279
280 // -------- instantiations --------------
281
283 template block2_gf<mesh::imfreq, matrix_valued> gloc(one_body_elements_tb const &obe, double mu,
284 block2_gf<mesh::imfreq, matrix_valued> const &Sigma_dynamic,
285 nda::array<nda::matrix<dcomplex>, 2> const &Sigma_static,
286 triqs::lattice::bz_int_options const &opt);
287
288 template block2_gf<mesh::imfreq, matrix_valued> gloc(mesh::imfreq const &mesh, one_body_elements_tb const &obe, double mu,
289 triqs::lattice::bz_int_options const &opt);
290
291 template double density(one_body_elements_tb const &obe, double mu, block2_gf<mesh::imfreq, matrix_valued> const &Sigma_dynamic,
292 nda::array<nda::matrix<dcomplex>, 2> const &Sigma_static, triqs::lattice::bz_int_options const &opt);
293
294 template double find_chemical_potential(double const target_density, one_body_elements_tb const &obe,
295 block2_gf<mesh::imfreq, matrix_valued> const &Sigma_dynamic,
296 nda::array<nda::matrix<dcomplex>, 2> const &Sigma_static, triqs::lattice::bz_int_options const &opt,
297 std::string method, double precision, bool verbosity);
298
299 template double find_chemical_potential(double const target_density, one_body_elements_tb const &obe, mesh::imfreq const &mesh,
300 triqs::lattice::bz_int_options const &opt, std::string method, double precision, bool verbosity);
301
304} // namespace triqs::modest
Describe the atomic orbitals within downfolded space.
long n_sigma() const
Dimension of the index.
long dim() const
Dimension of the correlated space.
C2PY_IGNORE gf_struct2_t Gc_block_shape() const
Shape of the Green function in the correlated space, without block decomposition.
#define C2PY_IGNORE
Definition defs.hpp:17
block2_gf< Mesh, matrix_valued > gloc(one_body_elements_on_grid const &obe, double mu, block2_gf< Mesh, matrix_valued > const &Sigma_dynamic, nda::array< nda::matrix< dcomplex >, 2 > const &Sigma_static)
Compute local Green's function on a mesh.
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.
double find_chemical_potential(double const target_density, one_body_elements_on_grid const &obe, double beta, std::string method="dichotomy", double precision=1.e-5, bool verbosity=true)
Find the chemical potenital from the local Green's function given a target density.
Definition density.hpp:199
double density(one_body_elements_on_grid const &obe, double mu, block2_gf< Mesh, matrix_valued > const &Sigma_dynamic, nda::array< nda::matrix< dcomplex >, 2 > const &Sigma_static)
Compute the density of the lattice Green's function with a self-energy using Woodbury.
Definition density.hpp:92
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 one-body elements TB object from Wannier90 in the case of a single spin index.
Definition obe_tb.cpp:23
gf_struct2_t get_struct(block2_gf< Mesh, matrix_valued > const &g)
Definition gf_supp.hpp:52
block2_gf< Mesh, matrix_valued > make_block2_gf(Mesh const &mesh, gf_struct2_t const &gf_s)
Definition gf_supp.hpp:41
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.
Definition obe_tb.cpp:118
one_body_elements_tb rotate(one_body_elements_tb const &obe, nda::matrix< dcomplex > const &U)
Rotate a tight-binding Hamiltonian by a unitary matrix .
Definition obe_tb.cpp:154
one_body_elements_tb fold(tb::superlattice const &sl, one_body_elements_tb const &obe)
Definition obe_tb.cpp:137
spin_kind_e
Kind of σ index.
nda::array< nda::matrix< dcomplex >, 2 > Hloc(std::vector< tb_hamiltonian > const &H_sigma, std::vector< atomic_orbs > const &atomic_shells)
Compute given tight binding Hamiltonians.
Definition obe_tb.cpp:70
one_body_elements_tb one_body_elements_from_model(std::vector< std::array< long, 3 > > const &Rs, std::vector< nda::array< dcomplex, 2 > > const &HR, spin_kind_e spin_kind, std::vector< atomic_orbs > atomic_shells)
Definition obe_tb.cpp:39
static constexpr auto r_all
Definition defs.hpp:40
generator< std::pair< long, nda::range > > enumerated_sub_slices(auto sub_div)
nda::array< long, 2 > dims
Definition gf_supp.hpp:37
A one-body elements using a tight-binding Hamiltonian.
Definition obe_tb.hpp:29
bool operator==(one_body_elements_tb const &) const =default
Equality comparison operator.
friend void mpi_broadcast(one_body_elements_tb &x, mpi::communicator c={}, int root=0)
MPI broadcast.
Definition obe_tb.hpp:39
std::vector< tb_hamiltonian > H
List of TB Hamiltonians.
Definition obe_tb.hpp:31
local_space C_space
Local space.
Definition obe_tb.hpp:30