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

Fix problems left in #11 #12

Merged
merged 10 commits into from
Jan 12, 2022
8 changes: 8 additions & 0 deletions Artifacts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ lazy = true
sha256 = "64d7713bb9b1e766a4762d52b4828155b5c26f3a8487c516d0a402e7c04797de"
url = "https://github.com/MineralsCloud/PseudopotentialArtifacts/raw/main/pslibrary/al.tar.gz"

[all]
git-tree-sha1 = "0fd60ae0d71a6334be1bd5a5e3e6afe604030b19"
lazy = true

[[all.download]]
sha256 = "6e182fa335f72db0b9131cb7a613e9ab7cd7e584795ea151532e1cb999e83179"
url = "https://github.com/MineralsCloud/PseudopotentialArtifacts/raw/main/pslibrary/all.tar.gz"

[ar]
git-tree-sha1 = "dafcfdbbde59c25e4b80557d2e4bf35353db4eb5"
lazy = true
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ version = "0.1.1-DEV"

[deps]
AcuteML = "6b84a0a3-a11a-41fa-a417-e600528de108"
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
LazyArtifacts = "4af54fe1-eca0-43a8-85a7-787d91b784e3"
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Pseudopotentials = "1b2dc2e6-48aa-4f00-b8f4-19d1a71d7a0e"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

Expand Down
30 changes: 27 additions & 3 deletions scripts/database.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using AcuteML: UN, parsehtml, root, nextelement, nodecontent
using Artifacts:
artifact_hash, artifact_exists, create_artifact, archive_artifact, bind_artifact!
using DataFrames: DataFrame, groupby
using JLD2: jldsave
using Pkg.Artifacts:
artifact_hash, artifact_exists, create_artifact, archive_artifact, bind_artifact!
using Pseudopotentials:
CoreHole, ExchangeCorrelationFunctional, ValenceCoreState, Pseudization

Expand Down Expand Up @@ -32,7 +32,7 @@ end

function makedb(element::String)
database = DataFrame(
element = [],
element = String[],
rel = Bool[],
corehole = UN{CoreHole}[],
xc = UN{ExchangeCorrelationFunctional}[],
Expand All @@ -48,11 +48,19 @@ function makedb(element::String)
return database
end
makedb(i::Integer) = makedb(ELEMENTS[i])
function makedb()
data = mapreduce(makedb, append!, ELEMENTS)
return groupby(data, :element)
end

function savedb(file, element)
database = makedb(element)
return jldsave(file; database)
end
function savedb(file)
database = makedb()
return jldsave(file; database)
end

function makeartifact(element::AbstractString)
element_hash = artifact_hash(element, ARTIFACT_TOML)
Expand All @@ -71,6 +79,22 @@ function makeartifact(element::AbstractString)
end
end
makeartifact(i::Integer) = makeartifact(ELEMENTS[i])
function makeartifact()
dir_hash = artifact_hash("all", ARTIFACT_TOML)
if dir_hash === nothing || !artifact_exists(dir_hash)
dir_hash = create_artifact() do artifact_dir
savedb(joinpath(artifact_dir, "all.jld2"))
end
tar_hash = archive_artifact(dir_hash, "all.tar.gz")
bind_artifact!(
ARTIFACT_TOML,
"all",
dir_hash;
download_info = [(DATABASE_URL_BASE * "all.tar.gz", tar_hash)],
lazy = true,
)
end
end

grepvalues(x::UPFFileName) = (
getfield(x, i) for
Expand Down
19 changes: 10 additions & 9 deletions src/PSlibrary.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module PSlibrary

using Artifacts: @artifact_str
using DataFrames: DataFrame, groupby
using AcuteML: UN, parsehtml, root, nextelement, nodecontent
using JLD2: load
using LazyArtifacts
using MLStyle: @match
using Pseudopotentials:
CoreHole, ExchangeCorrelationFunctional, ValenceCoreState, Pseudization
using Pkg.Artifacts: @artifact_str
using REPL.TerminalMenus: RadioMenu, request

using ..UnifiedPseudopotentialFormat: UPFFileName
Expand Down Expand Up @@ -132,7 +132,7 @@ function list_elements(pt = true)
if pt
println(PERIODIC_TABLE)
end
return groupby(unique!(DATABASE), :element)
return loaddb()
end

"""
Expand All @@ -143,11 +143,7 @@ List all pseudopotentials in `PSlibrary` for a specific element (abbreviation or
function list_potentials(element::Union{AbstractString,AbstractChar})
element = lowercase(string(element))
@assert element in ELEMENTS "element $element is not recognized!"
for meta in _parsehtml(element)
parsed = parse(UPFFileName, meta.name)
push!(DATABASE, [fieldvalues(parsed)..., meta.src, meta.name])
end
return list_elements(false)[(uppercasefirst(element),)]
return loaddb(element)
end
function list_potentials(atomic_number::Integer)
@assert 1 <= atomic_number <= 94
Expand Down Expand Up @@ -191,15 +187,20 @@ function download_potential(name::AbstractString, path)
df = list_potentials(x.element)
if name in df.name
i = findfirst(==(name), df.name)
download(df.src[i], path)
return download(df.src[i], path)
else
throw("potential '$name' is not in the database!")
end
end

function loaddb(element::AbstractString)
artifact_path = joinpath(@artifact_str(element), "$element.jld2")
load(artifact_path)["database"]
return load(artifact_path)["database"]
end
loaddb(i::Integer) = loaddb(ELEMENTS[i])
function loaddb()
artifact_path = joinpath(artifact"all", "all.jld2")
return load(artifact_path)["database"]
end

end