Skip to content

Commit

Permalink
[doc] Add 3D visualization of WFs
Browse files Browse the repository at this point in the history
  • Loading branch information
qiaojunfeng committed Sep 6, 2022
1 parent 69ef25e commit 4befb05
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 14 deletions.
28 changes: 27 additions & 1 deletion docs/src/tutorials_src/4-realspace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ The [`disentangle`](@ref) function
will disentangle and maximally localize the spread
functional, and returns the gauge matrices `A`,
=#
A = disentangle(model)
A = disentangle(model);

# The initial spread is
omega(model)
Expand Down Expand Up @@ -99,6 +99,32 @@ visualizer, e.g., `vesta`, to have a look at the WFs!
=#

using JSServe # hide
Page(; exportable=true, offline=true) # hide
#=
We also provide a simple plotting package
[`WannierPlots.jl`](https://github.com/qiaojunfeng/WannierPlots.jl)
for quick Visualization of band structure, real space WFs, etc.
First, load the plotting packages
=#
using WGLMakie
set_theme!(; resolution=(800, 800))
using WannierPlots
#=
!!! tip
Here we want to show the WFs in this web page, so we first load `WGLMakie`.
When you use the `WannierPlots` package in REPL, you can first load `GLMakie`,
then the WFs will be shown in a standalone window.
=#
# Read the 1st WF
xsf = read_xsf("$CUR_DIR/wjl_00001.xsf");
# Visualize with `WannierPlots.jl`,
pos = inv(xsf.primvec) * xsf.atom_positions # to fractional coordinates
atom_numbers = parse.(Int, xsf.atoms) # to integer atomic numbers
plot_wf(xsf.rgrid, xsf.W, xsf.primvec, pos, atom_numbers)

#=
## Compute WF centers in realspace
Expand Down
25 changes: 24 additions & 1 deletion docs/src/tutorials_src/5-parallel_transport.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,32 @@ Also, you can try to plot the WFs, by first truncating the `unk`
Wannier.truncate_unk(CUR_DIR, [7], "$CUR_DIR/truncate")
# the new `unk`s are stored in a subfolder `truncate`,
# now write the realspace WF
write_realspace_wf("$CUR_DIR/wjl", model_top; unkdir="$CUR_DIR/truncate")
write_realspace_wf(
"$CUR_DIR/wjl", model_top; n_supercells=[3, 3, 2], unkdir="$CUR_DIR/truncate"
)
# and visualize with your favorite tool.

# As a reference, here is the real space WFs visualized with [`WannierPlots.jl`].
using JSServe # hide
Page(; exportable=true, offline=true) # hide
# First, load the plotting packages
using WGLMakie
set_theme!(; resolution=(800, 800))
using WannierPlots
#=
!!! tip
Here we want to show the WFs in this web page, so we first load `WGLMakie`.
When you use the `WannierPlots` package in REPL, you can first load `GLMakie`,
then the WFs will be shown in a standalone window.
=#
# Read the 1st WF
xsf = read_xsf("$CUR_DIR/wjl_00001.xsf");
# Visualize with `WannierPlots.jl`,
pos = inv(xsf.primvec) * xsf.atom_positions # to fractional coordinates
atom_numbers = parse.(Int, xsf.atoms) # to integer atomic numbers
plot_wf(xsf.rgrid, xsf.W, xsf.primvec, pos, atom_numbers)

#=
Now we have automated Wannierization of the valence manifold,
and the top valence band of MoS2, without any initial projection!
Expand Down
15 changes: 4 additions & 11 deletions src/io/xsf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,14 @@ function read_xsf(filename::AbstractString)
n_x, n_y, n_z = size(W)
# fractional w.r.t. span_vectors
O = inv(span_vectors) * origin
X = range(0, 1, n_x) .- O[1]
Y = range(0, 1, n_y) .- O[2]
Z = range(0, 1, n_z) .- O[3]
X = range(0, 1, n_x) .+ O[1]
Y = range(0, 1, n_y) .+ O[2]
Z = range(0, 1, n_z) .+ O[3]
Xg, Yg, Zg = ndgrid(X, Y, Z)
rgrid = RGrid(span_vectors, Xg, Yg, Zg)
end

return (
primvec=primvec,
convvec=convvec,
atoms=atoms,
atom_positions=atom_positions,
rgrid=rgrid,
W=W,
)
return (; primvec, convvec, atoms, atom_positions, rgrid, W)
end

"""
Expand Down
2 changes: 1 addition & 1 deletion tutorials

0 comments on commit 4befb05

Please sign in to comment.