Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PlotlyJS extension for crystal structure #37

Merged
merged 6 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
repos:
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.2.0
rev: v1.5.4
hooks:
- id: forbid-crlf
- id: remove-crlf
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.5.0
hooks:
- id: check-added-large-files
args: ['--maxkb=5120'] # 5MB
Expand Down
12 changes: 12 additions & 0 deletions ext/WannierPlotlyJSExt/WannierPlotlyJSExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module WannierPlotlyJSExt
using DocStringExtensions
using Wannier
using PlotlyJS
using LinearAlgebra
using Printf: @sprintf

include("band.jl")
include("crystal.jl")
include("dos.jl")

end
39 changes: 23 additions & 16 deletions ext/WannierPlotlyJSExt.jl → ext/WannierPlotlyJSExt/band.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
module WannierPlotlyJSExt
using DocStringExtensions
using Brillouin: KPathInterpolant
using Wannier
using PlotlyJS

"""
$(SIGNATURES)
Expand Down Expand Up @@ -61,7 +57,7 @@ Return a PlotlyJS `Plot` struct for the band structure.
For a full customization, directly manipulate the returned `Plot` struct.
See [PlotlyJS documentation](http://juliaplots.org/PlotlyJS.jl/stable/syncplots/).
"""
function get_band_plot(
function Wannier.get_band_plot(
x::AbstractVector{<:Real},
eigenvalues::AbstractVector;
fermi_energy::Union{Nothing,Real}=nothing,
Expand Down Expand Up @@ -183,10 +179,14 @@ function get_band_plot(
return Plot(traces, layout)
end

function get_band_plot(kpi::KPathInterpolant, eigenvalues::AbstractVector; kwargs...)
function Wannier.get_band_plot(
kpi::KPathInterpolant, eigenvalues::AbstractVector; kwargs...
)
x = Wannier.get_linear_path(kpi)
symm_point_indices, symm_point_labels = Wannier.get_symm_point_indices_labels(kpi)
return get_band_plot(x, eigenvalues; symm_point_indices, symm_point_labels, kwargs...)
return Wannier.get_band_plot(
x, eigenvalues; symm_point_indices, symm_point_labels, kwargs...
)
end

"""
Expand All @@ -202,13 +202,25 @@ Plot band structure.
length-`n_bands` vector

# Keyword Arguments
See also the keyword arguments of [`get_band_plot`](@ref).
See also the keyword arguments of [`Wannier.get_band_plot`](@ref).
"""
function Wannier.plot_band(k, eigenvalues::AbstractVector; kwargs...)
P = get_band_plot(k, eigenvalues; kwargs...)
P = Wannier.get_band_plot(k, eigenvalues; kwargs...)
return PlotlyJS.plot(P)
end

function Wannier.get_band_diff_plot(
k, eigenvalues_1::AbstractArray, eigenvalues_2::AbstractArray; kwargs...
)
P1 = Wannier.get_band_plot(k, eigenvalues_1; color="grey", kwargs...)
# red and slightly thinner
P2 = Wannier.get_band_plot(
k, eigenvalues_2; color="red", dash="dash", width=0.9, kwargs...
)
addtraces!(P1, P2.data...)
return P1
end

"""
$(SIGNATURES)

Expand All @@ -229,11 +241,6 @@ See [`plot_band`](@ref)
function Wannier.plot_band_diff(
k, eigenvalues_1::AbstractArray, eigenvalues_2::AbstractArray; kwargs...
)
P1 = get_band_plot(k, eigenvalues_1; color="grey", kwargs...)
# red and slightly thinner
P2 = get_band_plot(k, eigenvalues_2; color="red", dash="dash", width=0.9, kwargs...)
addtraces!(P1, P2.data...)
return plot(P1)
end

P = Wannier.get_band_diff_plot(k, eigenvalues_1, eigenvalues_2; kwargs...)
return plot(P)
end
Loading
Loading