-
Notifications
You must be signed in to change notification settings - Fork 2
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
Possible flag-based interface to reduce duplication #11
Draft
azadoks
wants to merge
19
commits into
main
Choose a base branch
from
flag_interface
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
82ecf37
Possible flag-based interface to reduce duplication
azadoks 4c5f534
Rework info i/o, improve UPF, UPF-PSP8 agreement, reorganize
azadoks 0f9092a
Fix documentation, 1.6 tests
azadoks 6e4a2d3
Some todos
azadoks ae15a89
Fix broken tests
azadoks 81aeff1
Oops
azadoks 9caab57
Typo
azadoks e86b77b
Fix test?
azadoks 94936c5
Typo in docs api
azadoks 868f2c3
Test truncation
azadoks c571045
Fix tests?
azadoks 18784c7
Add useless Hankel test for coverage
azadoks c8705fe
Ugh
azadoks 2f2cbf4
Dunno
azadoks 4d6b119
Fix quadrature, move to CubicSplines, allow interpolation from log to…
azadoks 44e929f
Messy, don't look
azadoks 55c53de
Big rework of integration interface
azadoks 6d2103d
Remove accidental files
azadoks 0d70da7
Lots of changes
azadoks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,53 @@ | ||
# # Tutorial | ||
# | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice docs, super valuable. |
||
# Here, we'll take a look at the basic usage of PseudoPotentialIO.jl: searching for, loading, and investigating the contents of pseudopotentials. | ||
# Here, we'll take a look at the basic usage of PseudoPotentialIO.jl: searching for, | ||
# loading, and investigating the contents of pseudopotentials. | ||
|
||
using PseudoPotentialIO | ||
using CairoMakie | ||
using Colors | ||
|
||
# ## 1. Searching for pseudopotentials | ||
# PseudoPotentialIO provides easy access to a variety of pseudopotential families with zero setup using Julia [Artifacts](https://docs.julialang.org/en/v1/stdlib/Artifacts/), [LazyArtifacts.jl](https://github.com/JuliaPackaging/LazyArtifacts.jl), and [PseudoLibrary](https://github.com/JuliaMolSim/PseudoLibrary). | ||
# PseudoPotentialIO provides easy access to a variety of pseudopotential families with zero | ||
# setup using Julia [Artifacts](https://docs.julialang.org/en/v1/stdlib/Artifacts/), | ||
# [LazyArtifacts.jl](https://github.com/JuliaPackaging/LazyArtifacts.jl), and | ||
# [PseudoLibrary](https://github.com/JuliaMolSim/PseudoLibrary). | ||
# In order to list the available pre-bundled families, use `list_families` | ||
|
||
list_families(with_info=true) | ||
println(list_families()) | ||
|
||
# Because families are downloaded lazily, detailed information on some of the families is missing (they need to be downloaded first). | ||
# Because families are downloaded lazily, detailed information on some of the families is | ||
# missing (they need to be downloaded first). | ||
# In order to download a pseudopotential family, you can load it using `load_family`. | ||
# | ||
# !!! note "Loading pseudopotential families" | ||
# `load_family` can also load all the pseudopotentials in a local directory! | ||
# | ||
# You can then see an overview of which elements the family supports with `show_family_periodic_table`. | ||
# You can then see a summary of the family with`show_family_summary` and which elements it | ||
# supports with `show_family_periodic_table`. | ||
|
||
family = load_family("hgh_lda_upf"); | ||
family = load_family_psp_files("hgh_lda_upf"); | ||
show_family_periodic_table(family) | ||
|
||
# For more detailed information, use `show_family_list`. | ||
# You can restrict the output by providing a list of elements that you're interested in. | ||
|
||
show_family_list(family) # Show all the pseudopotentials | ||
show_family_list(family; elements=["Ba", "Ti", "O"]) # Only show the pseudos for Ba, Ti, and O | ||
show_family_table(family) # Show all the pseudopotentials | ||
show_family_table(family; elements=["Ba", "Ti", "O"]) # Only show the pseudos for Ba, Ti, and O | ||
|
||
# ## 2. Loading pseudopotential files | ||
# To load an individual pseudopotential _file_, use `load_psp_file`, specifying the family name or directory and the filename of the pseudopotential | ||
# To load an individual pseudopotential _file_, use `load_psp_file`, specifying the family | ||
# name or directory and the filename of the pseudopotential | ||
|
||
Ba_psp_file = load_psp_file("hgh_lda_upf", "Ba.pz-sp-hgh.UPF") | ||
|
||
# PseudoPotentialIO distinguishes between pseudopotential _files_ and the pseudopotentials themselves. | ||
# Structures like `HghFile`, `UpfFile`, and `Psp8File` correspond to pseudopotential file formats and make the quantities that these files contain directly available, with no unit conversion or processing. | ||
# For example, we can take a look at the author field from the header in the barium UPF pseudopotential we just loaded | ||
# PseudoPotentialIO distinguishes between pseudopotential _files_ and the pseudopotentials | ||
# themselves. | ||
# Structures like `HghFile`, `UpfFile`, and `Psp8File` correspond to pseudopotential file | ||
# formats and make the quantities that these files contain directly available, with no unit | ||
# conversion or processing. | ||
# For example, we can take a look at the author field from the header in the barium UPF | ||
# pseudopotential we just loaded | ||
|
||
Ba_psp_file.header.author | ||
|
||
|
@@ -45,39 +56,55 @@ Ba_psp_file.header.author | |
propertynames(Ba_psp_file) | ||
|
||
# ## 3. Loading pseudopotentials | ||
# Once you've decided that you would like to use a given pseudopotential for a calculation, either convert its `PsPFile` struct a corresponding pseudopotential structure | ||
# Once you've decided that you would like to use a given pseudopotential for a calculation, | ||
# either convert its `PsPFile` struct a corresponding pseudopotential structure | ||
|
||
Ba_psp_from_File = load_psp(Ba_psp_file) | ||
|
||
# , or load the pseudopotential structure directly from the file using `load_psp` | ||
|
||
Ba_psp_from_disk = load_psp("hgh_lda_upf", "Ba.pz-sp-hgh.UPF") | ||
|
||
# We can confirm that these pseudopotentials are identical | ||
Ba_psp_from_File == Ba_psp_from_disk | ||
|
||
# This procedure has processed the contents of the UPF file (on disk) or the `UpfFile` struct into a common and consistent data representation that PseudoPotentialIO uses for calculations. We can see that the contents have changed by looking at the property names of our new `UpfPsP` struct | ||
# This procedure has processed the contents of the UPF file (on disk) or the `UpfFile` | ||
# struct into a common and consistent data representation that PseudoPotentialIO uses for | ||
# calculations. We can see that the contents have changed by looking at the property names | ||
# of our new `UpfPsP` struct | ||
|
||
propertynames(Ba_psp_from_disk) | ||
|
||
# ## 4. Inspecting pseudopotential quantities | ||
# One thing that we might want to do with a processed pseudopotential is to visualize some of the quantities it contains. | ||
# One thing that we might want to do with a processed pseudopotential is to visualize some | ||
# of the quantities it contains. | ||
# Let's plot the Kleinman-Bylander projectors from a PseudoDojo barium pseudopotential | ||
|
||
Ba_psp = load_psp("pd_nc_sr_pbesol_standard_0.4.1_upf", "Ba.upf"); | ||
let | ||
linestyles = [:solid, :dash, :dot] | ||
colors = Colors.JULIA_LOGO_COLORS | ||
fig = Figure(); ax = Axis(fig[1,1], xlabel="r [a₀]", ylabel="β(r)") | ||
for l in angular_momenta(Ba_psp) # Iterate over each angular momentum 0:lmax | ||
|
||
## Iterate over each angular momentum 0:lmax | ||
for l in angular_momenta(Ba_psp) | ||
color = colors[l+1] | ||
for n in projector_radial_indices(Ba_psp, l) # Iterate over each projector at l 1:nmax | ||
## Iterate over each projector at l 1:nmax | ||
for n in 1:n_radials(NumericProjector(), Ba_psp, l) | ||
linestyle = linestyles[n] | ||
r²βln = Ba_psp.β[l][n] # Projector multiplied by r² | ||
i_rc_ln = lastindex(r²βln) # Cutoff radius index | ||
βln = r²βln ./ Ba_psp.r[1:i_rc_ln].^2 # Remove the r² prefactor | ||
lines!(ax, Ba_psp.r[1:i_rc_ln], βln, label="|β[$l][$n]⟩", | ||
linestyle=linestyle, color=color) | ||
|
||
## Get a callable (interpolator or function) which lets us evaluate the | ||
## pseudopotential quantity in real- or Fourier-space | ||
r²βln = psp_quantity_evaluator( | ||
RealSpace(), # Select real- or Fourier-space using [Real,Fourier]Space() | ||
NumericProjector(), # Select the quantity, here a non-local β-projector | ||
Ba_psp, l, n) | ||
|
||
## Real-space evaluators for numeric pseudos fail outside their cutoff radius, | ||
## which we can find using the `cutoff_radius` function | ||
rgrid = 0:0.01:cutoff_radius(NumericProjector(), Ba_psp, l, n) | ||
|
||
## Remove the r² prefactor | ||
βln = r²βln.(rgrid) ./ rgrid.^2 | ||
|
||
lines!(ax, rgrid, βln, label="|β[$l][$n]⟩", linestyle=linestyle, color=color) | ||
end | ||
end | ||
axislegend() | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels a bit like a too overwhelming method zoo. People will generally not remember all this. Let's brainstorm if we can simplify by show functions on clever types or so.