-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
65 additions
and
61 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "PseudoPotentialData" | ||
uuid = "5751a51d-ac76-4487-a056-413ecf6fbe19" | ||
authors = ["Michael F. Herbst <[email protected]> and contributors"] | ||
version = "0.1.0" | ||
version = "0.1.1" | ||
|
||
[deps] | ||
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" | ||
|
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
struct PseudoFamily | ||
identifier::String | ||
# metadata | ||
extension::String # Filename expected as $(symbol).$(extension) | ||
functional::String # DFT functional keyword (or "" if unspecified) | ||
version::VersionNumber | ||
# TODO More things will probably follow | ||
# - Type of pseudisation (norm-conserving, PAW, ...) | ||
# - References to papers describing these pseudopotentials | ||
# - Elements available | ||
end | ||
|
||
""" | ||
Construction of a PseudoFamily from a `identifier` representing | ||
the pseudopotential family to use. | ||
""" | ||
function PseudoFamily(identifier::AbstractString) | ||
artifact_file = find_artifacts_toml(@__FILE__) | ||
@assert !isnothing(artifact_file) | ||
meta = artifact_meta(identifier, artifact_file) | ||
isnothing(meta) && throw(ArgumentError("Invalid pseudo identifier: $identifier")) | ||
PseudoFamily(identifier, | ||
meta["extension"], | ||
meta["functional"], | ||
VersionNumber(meta["version"])) | ||
end | ||
|
||
Base.Broadcast.broadcastable(l::PseudoFamily) = Ref(l) | ||
Base.getindex(family::PseudoFamily, element::Symbol) = pseudofile(family, element) | ||
|
||
|
||
"""Get the list of available pseudopotential family identifiers.""" | ||
function family_identifiers() | ||
artifact_file = find_artifacts_toml(@__FILE__) | ||
@assert !isnothing(artifact_file) | ||
collect(keys(TOML.parsefile(artifact_file))) | ||
end | ||
|
||
"""The list of all known pseudopotential families.""" | ||
const families = map(PseudoFamily, family_identifiers()) | ||
|
||
|
||
""" | ||
Return the directory containing the pseudo files. | ||
This downloads the artifact if necessary. | ||
""" | ||
artifact_directory(family::PseudoFamily) = (@artifact_str "$(family.identifier)") | ||
|
||
""" | ||
Get the full path to the file containing the pseudopotential information | ||
for a particular element and a particular pseudopotential `family`. | ||
The family can be specified as an identifier or an object. | ||
""" | ||
function pseudofile(family::PseudoFamily, element::Symbol) | ||
file = joinpath(artifact_directory(family), "$(element)." * family.extension) | ||
isfile(file) || throw(KeyError(element)) | ||
file | ||
end | ||
function pseudofile(family::AbstractString, element::Symbol) | ||
pseudofile(PseudoFamily(family), element) | ||
end |
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