Skip to content

Commit

Permalink
More general Quantica.gaps
Browse files Browse the repository at this point in the history
  • Loading branch information
pablosanjose committed Nov 28, 2024
1 parent 75fd834 commit ec7993e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/observables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ end
# gap(::Hamiltonian, µ = 0, ...) -> minimum gap in the bands around µ
#region

function gaps(h::Hamiltonian{T,<:Any,1}, µ = 0, ϕstore = missing; atol = eps(T)) where {T}
function gaps(h::Hamiltonian{T,<:Any,1}, µ = 0, ϕstore = missing; atol = eps(T), nev = 1, kw...) where {T}
g = greenfunction(h, GS.Schur())
λs = schur_eigvals(g, µ)
cϕs = λs .= -im .* log.(λs) # saves one allocation
Expand All @@ -771,9 +771,11 @@ function gaps(h::Hamiltonian{T,<:Any,1}, µ = 0, ϕstore = missing; atol = eps(T
rϕs = real.(cϕs)
iϕs = chopsmall.(abs.(imag.(cϕs)), atol)
ϕstore === missing || copy!(ϕstore, cϕs)
solver = ES.ShiftInvert(ES.ArnoldiMethod(nev = 1), µ)
solver = ES.ShiftInvert(ES.ArnoldiMethod(; nev, kw...), µ)
n = flatsize(h)
Δs = [iszero(iϕ) || rank(h(rϕ)-µ*I; tol=atol) < n ? zero(T) : abs(first(energies(spectrum(h, rϕ; solver)))-µ) for (rϕ, iϕ) in zip(rϕs, iϕs)]
Δs = [iszero(iϕ) || rank(h(rϕ)-µ*I; tol=atol) < n ?
zero(T) :
abs(minimum(x->abs(x-µ), energies(spectrum(h, rϕ; solver)))-µ) for (rϕ, iϕ) in zip(rϕs, iϕs)]
return Δs
end

Expand Down

0 comments on commit ec7993e

Please sign in to comment.