34#include <itertools/itertools.hpp>
35#include <nda/linalg.hpp>
37#include <nda/stdutil/complex.hpp>
45namespace triqs::lattice {
86 std::vector<nda::vector<long>> displ_vec_;
87 std::vector<nda::matrix<dcomplex>> overlap_mat_vec_;
89 void check_hoppings();
143 int n =
static_cast<int>(tb.displ_vec_.size());
144 for (
int i = 0; i < n; ++i) f(tb.displ_vec_[i], tb.overlap_mat_vec_[i]);
161 template <
typename K>
162 requires(nda::ArrayOfRank<K, 1> or nda::ArrayOfRank<K, 2>)
165 auto k_ndim = make_regular(k(nda::ellipsis(), range(
lattice().ndim())));
167 auto vals = [&](
int j) {
168 if constexpr (nda::ArrayOfRank<K, 1>) {
169 return std::exp(2i * M_PI * nda::linalg::dot_generic(k_ndim, displ_vec_[j])) * overlap_mat_vec_[j];
171 auto k_mat = nda::make_matrix_view(k_ndim);
172 auto exp = [](
auto d) {
return std::exp(d); };
173 auto exp_j = make_regular(nda::map(exp)(2i * M_PI * k_mat * displ_vec_[j]));
174 return nda::linalg::outer_product(exp_j, overlap_mat_vec_[j]);
177 auto res = make_regular(vals(0));
178 for (
int i = 1; i < displ_vec_.size(); ++i) res += vals(i);
190 auto kvecs = nda::matrix<double>(k_mesh.
size(), 3);
191 for (
auto [n, k] : itertools::enumerate(k_mesh)) { kvecs(n, range::all) = k.value(); }
192 auto kvecs_rec = make_regular(kvecs * k_mesh.
bz().reciprocal_matrix_inv());
218 template <
typename K>
220 requires(nda::ArrayOfRank<K, 1> or nda::ArrayOfRank<K, 2>)
222 if constexpr (nda::ArrayOfRank<K, 1>) {
223 return nda::linalg::eigvalsh(
fourier(k));
226 auto n_k = h_k.shape()[0];
227 auto res = nda::array<double, 2>(n_k,
n_orbitals());
228 for (
auto l : range(n_k)) res(l, range::all) = nda::linalg::eigvalsh(h_k(l, nda::ellipsis()));
243 for (
auto k : k_mesh) e_k[k] = nda::linalg::eigvalsh(h_k[k]);
262 bool operator==(
tight_binding const &tb)
const {
return bl_ == tb.bl_ && overlap_mat_vec_ == tb.overlap_mat_vec_ && displ_vec_ == tb.displ_vec_; }
277 sout <<
"Tight Binding Hamiltonian on " << tb.
lattice() <<
"\nwith hoppings [";
278 for (
auto const &[displ, overlap_mat] : itertools::zip(tb.
displ_vec(), tb.
overlap_mat_vec())) sout <<
"\n " << displ <<
" : " << overlap_mat;
285 [[nodiscard]]
static std::string
hdf5_format() {
return "tight_binding"; }
295 auto grp = fg.create_group(subgroup_name);
296 write_hdf5_format(grp, tb);
297 h5_write(grp,
"bravais_lattice", tb.bl_);
298 h5_write(grp,
"displ_vec", tb.displ_vec_);
299 h5_write(grp,
"overlap_mat_vec", tb.overlap_mat_vec_);
311 auto grp = g.open_group(subgroup_name);
312 auto bl = h5::h5_read<bravais_lattice>(grp,
"bravais_lattice");
313 auto displ_vec = h5::h5_read<std::vector<nda::vector<long>>>(grp,
"displ_vec");
314 auto overlap_mat_vec = h5::h5_read<std::vector<nda::matrix<dcomplex>>>(grp,
"overlap_mat_vec");
333 std::pair<nda::array<double, 1>, nda::array<double, 2>>
dos(tight_binding
const &TB,
int nkpts,
int neps);
348 std::pair<nda::array<double, 1>, nda::array<double, 1>> dos_patch(
tight_binding const &TB,
const nda::array<double, 2> &triangles,
int neps,
Provides a Brillouin zone class.
Provides a mesh type for Brillouin zones.
The owning Green's function container.
data_t & data() &
Get the data array.
Tight-binding Hamiltonian on a Bravais lattice with fully localised orbitals.
static tight_binding h5_read_construct(h5::group g, std::string subgroup_name)
Construct a tight-binding Hamiltonian by reading it from HDF5.
auto fourier(K const &k) const
Compute the Fourier transform for a given momentum vector (or array of momentum vectors).
friend void h5_write(h5::group fg, std::string subgroup_name, tight_binding const &tb)
Write a tight-binding Hamiltonian to HDF5.
r_t lattice_to_real_coordinates(R const &x) const
Transform a vector from the lattice basis to the standard basis.
long n_orbitals() const
Number of orbitals (also the size of the Bloch Hamiltonian matrix ).
bravais_lattice const & lattice() const
Get the underlying Bravais lattice.
auto dispersion(mesh::brzone const &k_mesh) const
Compute the dispersion on a given Brillouin zone mesh.
auto fourier(mesh::brzone const &k_mesh) const
Compute the Fourier transform on a given Brillouin zone mesh.
auto dispersion(K const &k) const
Compute the dispersion, i.e. the eigenvalue spectrum of , for a given momentum vector (or array of mo...
tight_binding(bravais_lattice bl, std::vector< nda::vector< long > > displ_vec, std::vector< nda::matrix< dcomplex > > overlap_mat_vec)
Construct a tight-binding Hamiltonian on a given Bravais lattice from explicit displacement and overl...
auto const & displ_vec() const
Get the list of displacement vectors, in units of the lattice basis vectors.
auto dispersion(int n_l) const
Compute the dispersion on a regular Brillouin zone mesh with n_l points per dimension.
bool operator!=(tight_binding const &tb) const
Not-equal-to comparison operator (negation of operator==()).
friend std::ostream & operator<<(std::ostream &sout, tight_binding const &tb)
Write a tight-binding Hamiltonian to a std::ostream.
auto const & overlap_mat_vec() const
Get the list of overlap (hopping) matrices, aligned with the displacement vectors.
static std::string hdf5_format()
Get the HDF5 format tag.
bool operator==(tight_binding const &tb) const
Equal-to comparison operator. True if the underlying lattice, displacements and overlap matrices all ...
auto fourier(int n_l) const
Compute the Fourier transform on a regular Brillouin zone mesh with n_l points per dimension.
Brillouin zone mesh type.
long size() const
Get the size of the mesh, i.e. the total number of mesh points in the first BZ.
auto const & bz() const noexcept
Get the underlying Brillouin zone.
Provides the Green's function class.
std::pair< array< double, 1 >, array< double, 2 > > dos(tight_binding const &TB, int nkpts, int neps)
Compute the density of states of a tight-binding Hamiltonian on a regular k-grid.
nda::vector< double > r_t
Real space vector type.
Common macros used in TRIQS.
Ordered dictionary mapping lattice displacements to hopping (overlap) matrices.
std::vector< nda::matrix< dcomplex > > overlap_mat_vec
std::vector of nda::matrix<dcomplex> overlap (hopping) matrices, one per displacement.
std::vector< nda::vector< long > > displ_vec
std::vector of nda::vector<long> displacement vectors, in units of the lattice basis vectors.