Skip to content

Commit 34bd213

Browse files
committed
fix copilot finds & add docstring for TightBindingTerm
- also a fix for an error in the docs CI (add a docstring for `TightBindingTerm`)
1 parent 5149714 commit 34bd213

6 files changed

Lines changed: 41 additions & 22 deletions

File tree

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ hopping ranges, the package:
2222
## Key types and API
2323

2424
### Core pipeline
25-
- `tb_hamiltonian(cbr, Rs, Val{hermiticity})` — top-level entry point; returns `TightBindingModel`
25+
- `tb_hamiltonian(cbr, Rs, ::Val{<:Hermiticity})` — top-level entry point; returns `TightBindingModel`
2626
- `obtain_symmetry_related_hoppings(Rs, br_a, br_b)` — enumerates hopping orbits
2727
- `sgrep_induced_by_siteir(br, op)` — site-symmetry induced space group representation
2828

docs/src/band-symmetry.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ To explore these tools, we first re-build the graphene model previously explored
1111
sgnum = 17 # plane group p6mm
1212
brs = calc_bandreps(sgnum, Val(2)) # band representations
1313
cbr = @composite brs[5] # (2b|A₁) EBR
14-
tbm = tb_hamiltonian(cbr) # tight-binding model (nearest neigbors)
14+
tbm = tb_hamiltonian(cbr) # tight-binding model (nearest neighbors)
1515
ptbm = tbm([0, 1]) # zero self-energy, nonzero nearest-neighbor hopping
1616
Rs = directbasis(sgnum, Val(2)) # (conventional) direct lattice basis
1717
kp = irrfbz_path(sgnum, Rs) # high-symmetry k-path

docs/src/nonhermitian.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ By default, the models returned by `tb_hamiltonian` are Hermitian. In addition t
44

55
## Hatano--Nelson model
66

7-
The architypical non-Hermitian model is the 1D Hatano--Nelson model, consisting of a single site and nearest-neigbor hoppings, in a setting with only time-reversal symmetry.
7+
The archetypical non-Hermitian model is the 1D Hatano--Nelson model, consisting of a single site and nearest-neighbor hoppings, in a setting with only time-reversal symmetry.
88
It is simple to build this model with SymmetricTightBinding.jl:
99

1010
```@example hatano-nelson
1111
brs = calc_bandreps(1, 1) # EBRs in plane group 1, with time-reversal symmetry
1212
pin_free!(brs, [1=>[0]]) # the 1a Wyckoff position in plane group 1 has a free parameter: set to 0 for definiteness
1313
cbr = @composite brs[1] # single-site model
14-
tbm = tb_hamiltonian(cbr, [[1]], NONHERMITIAN) # nearest neigbor hoppings
14+
tbm = tb_hamiltonian(cbr, [[1]], NONHERMITIAN) # nearest neighbor hoppings
1515
```
1616

1717
The model is very simple: two different hopping terms, corresponding to right- and left-directed hopping terms. The absence of hermiticity allows the hopping amplitudes in either direction to differ, contrasting the Hermitian case:
@@ -21,7 +21,7 @@ tb_hamiltonian(cbr, [[1]], HERMITIAN)
2121
```
2222
The non-Hermitian model reduces to the Hermitian model when the left- and right-directed hopping amplitudes are equal. When the two are _not_ equal, the Hatano-Nelson model features exceptional points and spontaneous symmetry breaking of the real spectrum, as we can verify by example (using Brillouin.jl and GLMakie.jl for dispersion plotting):
2323

24-
```@example hatano-nelson¨
24+
```@example hatano-nelson
2525
ptbm = tbm([0.9, 1.1]) # a model with 0.9 hopping amplitude to right, 1.1 to the left
2626
2727
using Brillouin, GLMakie
@@ -45,7 +45,7 @@ tbm_notr = tb_hamiltonian((@composite brs_notr[1]), [[0], [1]], NONHERMITIAN) #
4545
## A more complicated example: exceptional surfaces in p4
4646

4747
We can also construct more complicated examples where symmetry plays a role. Consider for example the following simple extension of the Hatano-Nelson model to a 2D lattice with p4 symmetry:
48-
```
48+
```@example hatano-nelson-p4
4949
brs = calc_bandreps(10, Val(2))
5050
cbr = @composite brs[1]
5151
tbm_H = tb_hamiltonian(cbr, [[0,0], [1,0]], Val(HERMITIAN))
@@ -54,7 +54,7 @@ tbm_NH = tb_hamiltonian(cbr, [[0,0], [1,0]], Val(NONHERMITIAN))
5454

5555
It is instructive to visualize both the Hermitian and non-Hermitian models and compare the involved hopping terms:
5656

57-
```
57+
```@example hatano-nelson-p4
5858
plot(tbm_H)
5959
plot(tbm_NH)
6060
```

ext/SymmetricTightBindingMakieExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function Makie.plot!(
5555
t = p.t[]
5656
offdiag = p.offdiag[] # implies that (anti-)hermiticity requires adding reversed hoppings
5757
context = p.context[]
58-
context = merge(context, default_context_attributes) # TODO: remove manual merging once Makie v0.25+ is out
58+
context = merge(default_context_attributes, context) # TODO: remove manual merging once Makie v0.25+ is out
5959

6060
P, V = Point{D, Float32}, Vec{D, Float32}
6161
Rm = stack(Rs)

src/tightbinding.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function obtain_symmetry_related_hoppings(
2929
Rs::AbstractVector{V}, # must be specified in the primitive basis
3030
brₐ::NewBandRep{D},
3131
brᵦ::NewBandRep{D};
32-
diagonal_block::Bool = true, # whether to manually add "reversed" hoppings (if false),
32+
diagonal_block::Bool = true, # whether to manually add "reversed" hoppings (if true),
3333
reverse_hop::Bool = false, # if hopping actually goes from a+R→b rather than a→b+R
3434
# (used in NONHERMITIAN case, for lower-triangular blocks)
3535
# practically just corresponds to flipping signs of `Rs`
@@ -75,7 +75,7 @@ function obtain_symmetry_related_hoppings(
7575
# hermiticity/anti-hermiticity could link orbits that spatial symmetries might not have
7676
# already linked: in particular, if we are in a "diagonal block" of the Hamiltonian,
7777
# then, for every hopping vector `δ`, we must have a "reversed" counterpart `-δ` in the
78-
# presence of hermiticity r anti-hermiticity (always the case in our implementation);
78+
# presence of hermiticity or anti-hermiticity (always the case in our implementation);
7979
# but those two vectors might have fallen in distinct orbits up this point - if so, we
8080
# now merge them
8181
if diagonal_block
@@ -849,16 +849,18 @@ end
849849
tb_hamiltonian(
850850
cbr::CompositeBandRep{D},
851851
Rs::AbstractVector{Vector{Int}}
852-
[Sᵛ::Val{S} = Val(Hermitian)]
852+
[Sᵛ::Val{S} = Val(HERMITIAN)]
853853
) -> TightBindingModel{D, S}
854854
855855
Construct the tight-binding Hamiltonian from a given composite band representation `cbr` and
856856
a set of global translation-representatives `Rs`.
857857
858-
Whether the returned Hamiltonian is Hermitian or anti-Hermitian can be controlled by passing
859-
the optional argument `Sᵛ` as `Val(HERMITIAN)` (default) or `Val(ANTIHERMITIAN)`.
860-
This can also be passed as a plain `HERMITIAN` or `ANTIHERMITIAN` (but is then not type
861-
stable).
858+
Whether the returned Hamiltonian is Hermitian, anti-Hermitian, or non-Hermitian can be
859+
controlled by passing the optional argument `Sᵛ :: Val{S}` where `S` is an value of the enum
860+
type [`Hermiticity`](@ref), i.e., `HERMITIAN`, `ANTIHERMITIAN`, or `NONHERMITIAN` (default,
861+
`HERMITIAN`).
862+
This choice can also be passed a plain `S` (without a `Val` wrapper) but the call is then
863+
not type-stable.
862864
863865
The returned [`TightBindingModel`](@ref) will generally feature several terms (iterating to
864866
[`TightBindingTerm`](@ref)s), each representing a tight-binding term that is closed under
@@ -903,7 +905,7 @@ function tb_hamiltonian(
903905
# upper block-diagonals: we do this to get a more natural sorting of the terms in the
904906
# model, with self-hoppings first, etc. For Hermitian/anti-Hermitian models, we only
905907
# go over the upper triangular part, with the latter following directly; for
906-
# non-Hermitian, we just go over all blocks, going along diagonls 0,1,-1,…,B-1,-(B-1)
908+
# non-Hermitian, we just go over all blocks, going along diagonals 0,1,-1,…,B-1,-(B-1)
907909
for d in _diagonal_indices(B, Sᵛ) # offset from main diagonal (at 0)
908910
for block_i in _row_indices(B, d, Sᵛ)
909911
block_j = block_i + d

src/types.jl

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ from `br2` to `br1` if `diagonal_block = false` and `S` is not `NONHERMITIAN`).
8585
- `br2 :: NewBandRep{D}`: second band representation
8686
- `ordering1 :: OrbitalOrdering{D}`: ordering of the orbitals in `br1`
8787
- `ordering2 :: OrbitalOrdering{D}`: ordering of the orbitals in `br2`
88-
- `h_orbit :: Union{Nothing,HoppingOrbit{D}}`: hopping orbit associated to the block
88+
- `h_orbit :: HoppingOrbit{D}`: hopping orbit associated to the block
8989
- `Mm :: Array{Int,4}`: matrix codifying Hamiltonian
90-
- `t :: Vector{Float64}}`: a basis vector, stored in re/im-doubled format
90+
- `t :: Vector{Float64}`: a basis vector, stored in re/im-doubled format
9191
- `MmtC :: Array{ComplexF64, 3}`: pre-contracted matrix `Mm` with "complexified" `t`.
9292
- `diagonal_block :: Bool`: whether this is a diagonal block in the overall Hamiltonian.
9393
"""
@@ -152,6 +152,26 @@ Hermitian conjugation. Values:
152152
NONHERMITIAN
153153
end
154154

155+
156+
"""
157+
TightBindingTerm{D, S}
158+
159+
A single term a tight-binding Hamiltonian, representing a single block or a
160+
hermiticity-related pair of blocks of the Hamiltonian matrix.
161+
162+
## Fields
163+
- `axis :: BlockedOneTo{Int, Vector{Int}}`: the blocked axis of the term, encoding the
164+
global row/column indices all blocks in the full Hamiltonian matrix.
165+
- `block_ij :: NTuple{2, Int}`: the indices of considered term in the blocked axes; i.e.,
166+
`axis[block_ij...]` gives the global row/column indices of the "key" block represented by
167+
the term. If `S` is `NONHERMITIAN` or the term is diagonal, the key block is the only
168+
block represented by the term; otherwise, the term also represents the hermiticity-related
169+
block, whose global coordinates are `axis[reverse(block_ij)...]`.
170+
- `block :: TightBindingBlock{D, S}`: the `TightBindingBlock` associated to the key block.
171+
- `brs :: Vector{NewBandRep{D}}`: the set of band representations involved in the
172+
Hamiltonian; each element corresponds to a block-index in `axis`, such that `axis[i, j]`
173+
gives the (block of) hopping amplitudes from `brs[j]` to `brs[i]`.
174+
"""
155175
struct TightBindingTerm{D, S} <: AbstractBlockMatrix{TightBindingElementString}
156176
axis::BlockedOneTo{Int, Vector{Int}}
157177
block_ij::NTuple{2, Int}
@@ -191,10 +211,7 @@ function _getindex(
191211
i::Int,
192212
j::Int,
193213
conjugate::Bool = false
194-
) where {D, S}
195-
# if we are actually getting from a block related to the stored one by antihermiticity
196-
antihermitian_get = S === ANTIHERMITIAN && conjugate == true
197-
214+
) where {D, S}
198215
@boundscheck 1 i size(tbb.Mm, 3) && 1 j size(tbb.Mm, 4) ||
199216
error(BoundsError(tbb, (i, j)))
200217

0 commit comments

Comments
 (0)