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

Bands #12

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.1.6"
[deps]
AtomsBase = "a963bdd2-2df7-4f54-a1ee-49d51e6be12a"
DFTK = "acf6eb54-70d9-11e9-0013-234b7a5f5337"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Expand Down
37 changes: 29 additions & 8 deletions src/AiidaDFTK.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Unitful
using UnitfulAtomic
using Pkg
using Dates

export run_json

Expand Down Expand Up @@ -64,12 +65,14 @@
ρ = guess_density(basis, system)
checkpointfile = data["scf"]["checkpointfile"]
checkpointargs = kwargs_scf_checkpoints(basis; filename=checkpointfile, ρ)
scfres = self_consistent_field(basis; checkpointargs..., kwargs...)
maxtime = get(data["scf"], "maxtime", nothing)
maxtime = maxtime !== nothing ? Second(maxtime) : Year(1)
scfres = self_consistent_field(basis; checkpointargs..., kwargs..., maxtime)

output_files = [checkpointfile, "self_consistent_field.json"]
save_scfres("self_consistent_field.json", scfres; save_ψ=false, save_ρ=false)
save_ψ = get(data["scf"], "save_ψ", false)
save_scfres(checkpointfile, scfres; save_ψ, save_ρ=true)
save_scfres("self_consistent_field.json", scfres; save_ψ=false, save_ρ=false) #output json after jld2, facilitating checking if checkpoint saved correctly
(; scfres, output_files)
end

Expand All @@ -90,10 +93,23 @@
for calc in postscf_calcs
funcname = calc["\$function"]
kwargs = parse_kwargs(get(calc, "\$kwargs", Dict()))
results = getproperty(DFTK, Symbol(funcname))(scfres; kwargs...)

store_hdf5(funcname * ".hdf5", (; funcname, results))
push!(output_files, funcname * ".hdf5")
if funcname == "compute_bands"
kpath = pop!(kwargs, :kpath, nothing)
if kpath !== nothing
kpath = convert(Vector{Vector{Float64}}, kpath)
else
error("kpath is not provided for compute_bands")

Check warning on line 102 in src/AiidaDFTK.jl

View check run for this annotation

Codecov / codecov/patch

src/AiidaDFTK.jl#L102

Added line #L102 was not covered by tests
end
kpath = ExplicitKpoints(kpath)
bands = getproperty(DFTK, Symbol(funcname))(scfres, kpath; kwargs...)
save_bands("compute_bands.json", bands)
push!(output_files, "compute_bands.json")
else
results = getproperty(DFTK, Symbol(funcname))(scfres; kwargs...)
store_hdf5(funcname * ".hdf5", (; funcname, results))
push!(output_files, funcname * ".hdf5")
end
end
(; output_files)
end
Expand Down Expand Up @@ -146,9 +162,14 @@
(; scfres, output_files) = run_scf(data, system, basis)
append!(all_output_files, output_files)

# Run Post SCF routines
(; output_files) = run_postscf(data, scfres)
append!(all_output_files, output_files)
# Run Post SCF routines only after SCF converged
if isfile("self_consistent_field.json")
scf_json = JSON3.read(read("self_consistent_field.json", String))
if get(scf_json, "converged", false)
(; output_files) = run_postscf(data, scfres)
append!(all_output_files, output_files)
end
end

# Dump timings
timingfile = "timings.json"
Expand Down
83 changes: 76 additions & 7 deletions test/iron.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,97 @@
},
"basis_kwargs": {
"kgrid": [
2,
2,
2
6,
6,
6
],
"Ecut": 10
"Ecut": 20
},
"scf": {
"$function": "self_consistent_field",
"checkpointfile": "scfres.jld2",
"save_ψ": true,
"maxtime": 3000,
"$kwargs": {
"mixing": {
"$symbol": "KerkerDosMixing"
"$symbol": "KerkerDosMixing"
},
"is_converged": {
"$symbol": "ScfConvergenceEnergy",
"$args": 1.0e-4
"$symbol": "ScfConvergenceEnergy",
"$args": 1.0e-1
}
}
},
"postscf": [
{
"$function": "compute_forces_cart"
},
{
"$function": "compute_bands",
"$kwargs": {
"kpath": [
[
0.0,
0.0,
0.0
],
[
0.1,
0.0,
0.1
],
[
0.2,
0.0,
0.2
],
[
0.3,
0.0,
0.3
],
[
0.4,
0.0,
0.4
],
[
0.5,
0.0,
0.5
],
[
0.5,
0.0,
0.5
],
[
0.525,
0.05,
0.525
],
[
0.55,
0.1,
0.55
],
[
0.575,
0.15,
0.575
],
[
0.6,
0.2,
0.6
],
[
0.625,
0.25,
0.625
]
]
}
}
]
}
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ using UnitfulAtomic
end
end

run_functionality_test("iron.json", -117.153287)
run_functionality_test("iron.json", -124.1652766)
run_functionality_test("silicon_bands.json", -7.8380925; bands=true)
end
end
Loading