Skip to content

Commit

Permalink
Update to DFTK 0.7.6 (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n authored Jan 13, 2025
1 parent ffa0d98 commit 78d22ac
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 34 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
UnitfulAtomic = "a7773ee8-282e-5fa2-be4e-bd808c38a91a"

[compat]
AtomsBase = "0.3"
DFTK = "0.6.20"
AtomsBase = "0.5"
DFTK = "0.7.6"
DocStringExtensions = "0.9"
HDF5 = "0.17"
JLD2 = "0.4, 0.5"
Expand Down
9 changes: 5 additions & 4 deletions precompilation_task.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,21 @@
1.282887730510825,
1.282887730510825,
1.282887730510825
],
"pseudopotential": "hgh/lda/si-q4"
]
},
{
"symbol": "Si",
"position": [
-1.282887730510825,
-1.282887730510825,
-1.282887730510825
],
"pseudopotential": "hgh/lda/si-q4"
]
}
]
},
"pseudopotentials": {
"Si": "hgh/lda/si-q4"
},
"model_kwargs": {
"functionals": [
":lda_x",
Expand Down
20 changes: 15 additions & 5 deletions src/AiidaDFTK.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,30 @@ function build_system(data)
atoms = map(data["periodic_system"]["atoms"]) do atom
symbol = Symbol(atom["symbol"])
position = convert(Vector{Float64}, atom["position"]) * u"bohr"
pseudopotential = atom["pseudopotential"]
pseudopotential_kwargs = parse_kwargs(get(atom, "pseudopotential_kwargs", Dict()))
magnetic_moment = convert(Float64, get(atom, "magnetic_moment", 0.0))
Atom(symbol, position; pseudopotential, pseudopotential_kwargs, magnetic_moment)
Atom(symbol, position; magnetic_moment)
end

bounding_box = convert(Vector{Vector{Float64}},
data["periodic_system"]["bounding_box"]) * u"bohr"
periodic_system(atoms, bounding_box)
end

function build_pseudopotentials(pseudo_data, system)
kwargs = parse_kwargs(get(pseudo_data, Symbol("\$kwargs"), Dict()))
family = Dict{Symbol, String}(k => pseudo_data[k]
for k in keys(pseudo_data)
if k != Symbol("\$kwargs"))
load_psp(family, system; kwargs...)
end

function build_basis(data, system)
model = model_DFT(system; parse_kwargs(data["model_kwargs"])...)
PlaneWaveBasis(model; parse_kwargs(data["basis_kwargs"])...)
pseudopotentials = build_pseudopotentials(data["pseudopotentials"], system)
parsed = DFTK.parse_system(system, pseudopotentials)
model = model_DFT(parsed.lattice, parsed.atoms, parsed.positions;
parsed.magnetic_moments,
parse_kwargs(data["model_kwargs"])...)
PlaneWaveBasis(model; parse_kwargs(data["basis_kwargs"])...)
end

function run_geometry_optimisation(data, system, basis)
Expand Down
10 changes: 6 additions & 4 deletions test/iron.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@
0,
0
],
"pseudopotential": "../Fe.upf",
"pseudopotential_kwargs": {
"rcut": 10
},
"magnetic_moment": 4
}
]
},
"pseudopotentials": {
"Fe": "../Fe.upf",
"$kwargs": {
"rcut": 10
}
},
"model_kwargs": {
"functionals": [
":gga_x_pbe",
Expand Down
46 changes: 31 additions & 15 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,15 @@ using UnitfulAtomic
@testset "AiidaDFTK.jl" begin
system_silicon = periodic_system(
[Atom(:Si, [ 1.28, 1.28, 1.28]u"bohr";
pseudopotential="hgh/lda/si-q4",
pseudopotential_kwargs=Dict(),
magnetic_moment=0.0),
Atom(:Si, [-1.28, -1.28, -1.28]u"bohr";
pseudopotential="hgh/lda/si-q4",
pseudopotential_kwargs=Dict(),
magnetic_moment=0.0)],
[[0.0, 5.13, 5.13],
[5.13, 0.0, 5.13],
[5.13, 5.13, 0.0]]u"bohr"
)
system_iron = periodic_system(
[Atom(:Fe, [0, 0, 0]u"bohr";
pseudopotential="Fe.upf",
pseudopotential_kwargs=Dict(:rcut => 10, ),
magnetic_moment=4.0)],
[[-2.711, 2.711, 2.711],
[ 2.711, -2.711, 2.711],
Expand Down Expand Up @@ -61,42 +55,62 @@ using UnitfulAtomic
[5.13, 0.0, 5.13],
[5.13, 5.13, 0.0]],
"atoms" => [Dict("symbol" => "Si",
"position" => [1.28, 1.28, 1.28],
"pseudopotential" => "hgh/lda/si-q4"),
"position" => [1.28, 1.28, 1.28]),
Dict("symbol" => "Si",
"position" => [-1.28, -1.28, -1.28],
"pseudopotential" => "hgh/lda/si-q4")])
"position" => [-1.28, -1.28, -1.28])],)

res = AiidaDFTK.build_system(Dict("periodic_system" => data))
test_approx_eq(res, system_silicon)
end

@testset "build_system iron" begin
pseudo = Dict("rcut" => 10, )
data = Dict("bounding_box" => [[-2.711, 2.711, 2.711],
[ 2.711, -2.711, 2.711],
[ 2.711, 2.711, -2.711]],
"atoms" => [Dict("symbol" => "Fe",
"position" => [0, 0, 0],
"pseudopotential" => "Fe.upf",
"magnetic_moment" => 4.0,
"pseudopotential_kwargs" => pseudo,
)])
res = AiidaDFTK.build_system(Dict("periodic_system" => data))
test_approx_eq(res, system_iron)
end


@testset "build_pseudopotentials silicon" begin
pseudo_data = Dict(:Si => "hgh/lda/si-q4")
pseudos = AiidaDFTK.build_pseudopotentials(pseudo_data, system_silicon)

@test length(pseudos) == 2
@test pseudos[1] == pseudos[2]
@test pseudos[1] isa PspHgh
end

@testset "build_pseudopotentials iron" begin
pseudo_data = Dict(:Fe => "Fe.upf",
Symbol("\$kwargs") => Dict("rcut" => 10))
pseudos = AiidaDFTK.build_pseudopotentials(pseudo_data, system_iron)

@test length(pseudos) == 1
@test pseudos[1] isa PspUpf
@test pseudos[1].rcut == 10
end

@testset "build_basis silicon" begin
smearing = Dict("\$symbol" => "Smearing.MethfesselPaxton", "\$args" => [1])
data = Dict(
"pseudopotentials" => Dict(:Si => "hgh/lda/si-q4"),
"model_kwargs" => Dict("functionals" => [":lda_x", ":lda_c_pw"],
"temperature" => 1e-3,
"smearing" => smearing),
"basis_kwargs" => Dict("kgrid" => [4, 4, 4], "Ecut" => 15),
)
basis = AiidaDFTK.build_basis(data, system_silicon)

ref_model = model_DFT(system_silicon, [:lda_x, :lda_c_pw];
temperature=1e-3, smearing=Smearing.MethfesselPaxton(1))
ref_pseudos = repeat([load_psp("hgh/lda/si-q4")], 2)
ref_model = model_DFT(system_silicon;
functionals=[:lda_x, :lda_c_pw],
temperature=1e-3, smearing=Smearing.MethfesselPaxton(1),
pseudopotentials=ref_pseudos)
ref_basis = PlaneWaveBasis(ref_model; kgrid=[4, 4, 4], Ecut=15)

# TODO Add == implementation for models to DFTK
Expand Down Expand Up @@ -124,6 +138,8 @@ using UnitfulAtomic

smearing = Dict("\$symbol" => "Smearing.MarzariVanderbilt")
data = Dict(
"pseudopotentials" => Dict(:Fe => "Fe.upf",
Symbol("\$kwargs") => Dict("rcut" => 10)),
"model_kwargs" => Dict("functionals" => [":gga_x_pbe", ":gga_c_pbe"],
"temperature" => 1e-2,
"smearing" => smearing),
Expand Down
9 changes: 5 additions & 4 deletions test/silicon_bands.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,21 @@
1.282887730510825,
1.282887730510825,
1.282887730510825
],
"pseudopotential": "hgh/lda/si-q4"
]
},
{
"symbol": "Si",
"position": [
-1.282887730510825,
-1.282887730510825,
-1.282887730510825
],
"pseudopotential": "hgh/lda/si-q4"
]
}
]
},
"pseudopotentials": {
"Si": "hgh/lda/si-q4"
},
"model_kwargs": {
"functionals": [
":lda_x",
Expand Down

6 comments on commit 78d22ac

@Technici4n
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: Changing package repo URL not allowed, please submit a pull request with the URL change to the target registry and retry.

@Technici4n
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/122971

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.0 -m "<description of version>" 78d22ac1495f72cb11e9e2cd46e738cd79ddd624
git push origin v0.2.0

@Technici4n
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

Breaking changes

  • Changes to the input file format wrt. pseudopotentials.
  • Update to DFTK 0.7.6.
  • Exports were removed.

Other changes

  • Logging file with error messages that can be parsed to detect success and failure.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/122971

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.0 -m "<description of version>" 78d22ac1495f72cb11e9e2cd46e738cd79ddd624
git push origin v0.2.0

Please sign in to comment.