Skip to content

Commit 8fed6ae

Browse files
authored
Refactor bandstructure routines and json results (#895)
1 parent 27ccb1a commit 8fed6ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1065
-616
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Brillouin = "23470ee3-d0df-4052-8b1a-8cbd6363e7f0"
1111
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
1212
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
1313
DftFunctionals = "6bd331d2-b28d-4fd3-880e-1a1c7f37947f"
14+
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
1415
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
1516
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
1617
GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
@@ -34,7 +35,6 @@ PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
3435
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
3536
Primes = "27ebfcd6-29c5-5fa9-bf4b-fb8fc14df3ae"
3637
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
37-
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
3838
PseudoPotentialIO = "cb339c56-07fa-4cb2-923a-142469552264"
3939
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
4040
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
@@ -64,6 +64,7 @@ Brillouin = "0.5.14"
6464
ChainRulesCore = "1.15"
6565
Dates = "1"
6666
DftFunctionals = "0.2"
67+
DocStringExtensions = "0.9"
6768
FFTW = "1.5"
6869
ForwardDiff = "0.10"
6970
GPUArraysCore = "0.1"
@@ -89,7 +90,6 @@ PrecompileTools = "1"
8990
Preferences = "1"
9091
Primes = "0.5"
9192
Printf = "1"
92-
ProgressMeter = "1"
9393
PseudoPotentialIO = "0.1"
9494
Random = "1"
9595
Requires = "1"

docs/src/developer/setup.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ TestEnv.activate() # for tests in a temporary environment.
7474
using TestItemRunner
7575
@run_package_tests filter = ti -> :core ti.tags
7676
```
77+
Or to only run the tests of a particular file `serialisation.jl` use
78+
```julia
79+
@run_package_tests filter = ti -> occursin("serialisation.jl", ti.filename)
80+
```
7781

7882
If you need to write tests, note that you can create modules with `@testsetup`. To use
7983
a function `my_function` of a module `MySetup` in a `@testitem`, you can import it with

docs/src/guide/tutorial.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,15 @@ x = [r[1] for r in rvecs] # only keep the x coordinate
100100
plot(x, scfres.ρ[1, :, 1, 1], label="", xlabel="x", ylabel="ρ", marker=2)
101101

102102
# We can also perform various postprocessing steps:
103-
# for instance compute a band structure
104-
plot_bandstructure(scfres; kline_density=10)
105-
# or get the cartesian forces (in Hartree / Bohr)
103+
# We can get the Cartesian forces (in Hartree / Bohr):
106104
compute_forces_cart(scfres)
107105
# As expected, they are numerically zero in this highly symmetric configuration.
106+
# We could also compute a band structure,
107+
plot_bandstructure(scfres; kline_density=10)
108+
# or plot a density of states, for which we increase the kgrid a bit
109+
# to get smoother plots:
110+
bands = compute_bands(scfres, MonkhorstPack(6, 6, 6))
111+
plot_dos(bands; temperature=1e-3, smearing=Smearing.FermiDirac())
112+
# Note that directly employing the `scfres` also works, but the results
113+
# are much cruder:
114+
plot_dos(scfres; temperature=1e-3, smearing=Smearing.FermiDirac())

docs/src/publications.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ Additionally the following publications describe DFTK or one of its algorithms:
2222

2323
- E. Cancès, M. Hassan and L. Vidal.
2424
[*Modified-Operator Method for the Calculation of Band Diagrams of Crystalline Materials.*](https://arxiv.org/abs/2210.00442)
25-
(Submitted).
25+
Mathematics of Computation (2023).
2626
[ArXiv:2210.00442](https://arxiv.org/abs/2210.00442).
27+
([Supplementary material and computational scripts](https://github.com/LaurentVidal95/ModifiedOp).
2728

2829
- E. Cancès, M. F. Herbst, G. Kemlin, A. Levitt and B. Stamm.
2930
[*Numerical stability and efficiency of response property calculations in density functional theory*](https://arxiv.org/abs/2210.04512)

examples/cohen_bergstresser.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ eigres = diagonalize_all_kblocks(DFTK.lobpcg_hyper, ham, 6)
2929
using Plots
3030
using Unitful
3131

32-
p = plot_bandstructure(basis; n_bands=8, εF, kline_density=10, unit=u"eV")
32+
bands = compute_bands(basis; n_bands=8, εF, kline_density=10)
33+
p = plot_bandstructure(bands; unit=u"eV")
3334
ylims!(p, (-5, 6))

examples/collinear_magnetism.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,14 @@ idown = iup + length(scfres.basis.kpoints) ÷ 2
101101

102102
# We can observe the spin-polarization by looking at the density of states (DOS)
103103
# around the Fermi level, where the spin-up and spin-down DOS differ.
104-
105104
using Plots
106-
plot_dos(scfres)
105+
bands_666 = compute_bands(scfres, MonkhorstPack(6, 6, 6)) # Increase kgrid to get nicer DOS.
106+
plot_dos(bands_666)
107+
# Note that if same k-grid as SCF should be employed, a simple `plot_dos(scfres)`
108+
# is sufficient.
107109

108110
# Similarly the band structure shows clear differences between both spin components.
109111
using Unitful
110112
using UnitfulAtomic
111-
plot_bandstructure(scfres; kline_density=6)
113+
bands_kpath = compute_bands(scfres; kline_density=6)
114+
plot_bandstructure(bands_kpath)

examples/graphene.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ basis = PlaneWaveBasis(model; Ecut, kgrid)
3434
scfres = self_consistent_field(basis)
3535

3636
## Construct 2D path through Brillouin zone
37-
sgnum = 13 # Graphene space group number
38-
kpath = irrfbz_path(model; dim=2, sgnum)
39-
plot_bandstructure(scfres, kpath; kline_density=20)
37+
kpath = irrfbz_path(model; dim=2, space_group_number=13) # graphene space group number
38+
bands = compute_bands(scfres, kpath; kline_density=20)
39+
plot_bandstructure(bands)

examples/input_output.jl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,20 @@ end
7878
println(read("iron_afm_energies.json", String))
7979

8080
# Once JSON3 is loaded, additionally a convenience function for saving
81-
# a parsable summary of `scfres` objects using `save_scfres` is available:
81+
# a summary of `scfres` objects using `save_scfres` is available:
8282

8383
using JSON3
8484
save_scfres("iron_afm.json", scfres)
8585

86+
# Similarly a summary of the band data (occupations, eigenvalues, εF, etc.)
87+
# for post-processing can be dumped using `save_bands`:
88+
save_bands("iron_afm_scfres.json", scfres)
89+
90+
# Notably this function works both for the results obtained
91+
# by `self_consistent_field` as well as `compute_bands`:
92+
bands = compute_bands(scfres, kline_density=10)
93+
save_bands("iron_afm_bands.json", bands)
94+
8695
# ## Writing and reading JLD2 files
8796
# The full state of a DFTK self-consistent field calculation can be
8897
# stored on disk in form of an [JLD2.jl](https://github.com/JuliaIO/JLD2.jl) file.
@@ -99,6 +108,6 @@ save_scfres("iron_afm.jld2", scfres);
99108
# See [Saving SCF results on disk and SCF checkpoints](@ref) for details.
100109

101110
# (Cleanup files generated by this notebook.)
102-
rm("iron_afm.vts")
103-
rm("iron_afm.jld2")
104-
rm("iron_afm_energies.json")
111+
rm.(["iron_afm.vts", "iron_afm.jld2",
112+
"iron_afm.json", "iron_afm_energies.json", "iron_afm_scfres.json",
113+
"iron_afm_bands.json"])

examples/metallic_systems.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ smearing = DFTK.Smearing.FermiDirac() # Smearing method
4141

4242
model = model_DFT(lattice, atoms, positions, [:gga_x_pbe, :gga_c_pbe];
4343
temperature, smearing)
44-
kgrid = kgrid_from_minimal_spacing(lattice, kspacing)
44+
kgrid = kgrid_from_maximal_spacing(lattice, kspacing)
4545
basis = PlaneWaveBasis(model; Ecut, kgrid);
4646

4747
# Finally we run the SCF. Two magnesium atoms in
@@ -60,4 +60,7 @@ scfres.energies
6060

6161
# The fact that magnesium is a metal is confirmed
6262
# by plotting the density of states around the Fermi level.
63-
plot_dos(scfres)
63+
# To get better plots, we decrease the k spacing a bit for this step
64+
kgrid_dos = kgrid_from_maximal_spacing(lattice, 0.7 / u"Å")
65+
bands = compute_bands(scfres, kgrid_dos)
66+
plot_dos(bands)

examples/pseudopotentials.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function run_bands(psp)
9292
basis = PlaneWaveBasis(model; Ecut=12, kgrid=(4, 4, 4))
9393

9494
scfres = self_consistent_field(basis; tol=1e-4)
95-
bandplot = plot_bandstructure(scfres)
95+
bandplot = plot_bandstructure(compute_bands(scfres))
9696
(; scfres, bandplot)
9797
end;
9898

0 commit comments

Comments
 (0)