Skip to content

Commit

Permalink
job tests
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Jul 20, 2021
1 parent dfafb64 commit 49c168a
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 31 deletions.
1 change: 0 additions & 1 deletion src/fileio.jl
Expand Up @@ -332,7 +332,6 @@ function read_job_line(line)
push!(execs, Exec(efile, dir, parse_generic_flags(flags)))
end
end
@show execs
return execs, calculation, output, run
end

Expand Down
26 changes: 2 additions & 24 deletions src/job.jl
Expand Up @@ -11,33 +11,14 @@ iswannierjob(job::DFJob) = any(x -> package(x) == Wannier90, calculations(job))
getnscfcalc(job::DFJob) = getfirst(x -> isnscf(x), calculations(job))
cell(job::DFJob) = cell(structure(job))

calculation(job::DFJob, n::String) = getfirst(x -> occursin(n, name(x)), calculations(job))
calculations(job::DFJob) = job.calculations

"""
calculations(job::DFJob, names::Vector)
Returns an array of the calculations that match the names.
"""
function calculations(job::DFJob, names::Vector, fuzzy = true)
return fuzzy ? filter(x -> any(occursin.(names, name(x))), calculations(job)) :
calculation.(job, names)
end
calculations(job::DFJob, n::String, fuzzy = true) = calculations(job, [n], fuzzy)
function calculations(job::DFJob, ::Type{P}) where {P<:Package}
return filter(x -> package(x) == P, calculations(job))
end
inpath(job::DFJob, n) = inpath(calculation(job, n))
outpath(job::DFJob, n) = outpath(calculation(job, n))
calculations(job::DFJob) = job.calculations

"Runs some checks on the set flags for the calculations in the job, and sets metadata (:prefix, :outdir etc) related flags to the correct ones. It also checks whether flags in the various calculations are allowed and set to the correct types."
function sanitize_flags!(job::DFJob)
set_flags!(job, :prefix => "$(job.name)"; print = false)
if iswannierjob(job)
nscfcalc = getnscfcalc(job)
if package(nscfcalc) == QE && hasflag(nscfcalc, :nbnd)
set_flags!(job, :num_bands => nscfcalc[:nbnd]; print = false)
elseif package(nscfcalc) == Elk
if package(nscfcalc) == Elk
setflags!(job, :num_bands => length(nscfcalc[:wann_bands]))
nscfcalc[:wann_projections] = projections_string.(unique(filter(x -> !isempty(projections(x)), atoms(job))))
nscfcalc[:elk2wan_tasks] = ["602", "604"]
Expand Down Expand Up @@ -160,9 +141,6 @@ function last_running_calculation(job::DFJob)
end
end

"Finds the calculation corresponding to the name and returns the full output path."
outpath(job::DFJob, n::String) = outpath(calculation(job, n))

"""
joinpath(job::DFJob, args...)
Expand Down
3 changes: 2 additions & 1 deletion src/jobAPI.jl
Expand Up @@ -49,8 +49,9 @@ function save(job::DFJob; kwargs...)
sanitize_flags!(job)
timestamp!(job, now())
save_metadata(job)
writejobfiles(job; kwargs...)
rm_tmp_flags!(job)
return writejobfiles(job; kwargs...)
return
end

"""
Expand Down
4 changes: 2 additions & 2 deletions src/qe/calculation.jl
Expand Up @@ -256,7 +256,7 @@ function set_kpoints!(c::DFCalculation{QE}, k_grid::NTuple{6,Int}; print = true)
(@warn "Expected calculation to be scf, vc-relax, relax.\nGot $calc.")
set_data!(c, :k_points, [k_grid...]; option = :automatic, print = print)
prod(k_grid[1:3]) > 100 && set_flags!(c, :verbosity => "high"; print = print)
return calculation
return c
end

function set_kpoints!(c::DFCalculation{QE}, k_grid::Vector{<:NTuple{4}}; print = true,
Expand All @@ -280,7 +280,7 @@ function set_kpoints!(c::DFCalculation{QE}, k_grid::Vector{<:NTuple{4}}; print =
end
end
set_data!(c, :k_points, k_grid; option = k_option, print = print)
return calculation
return c
end

"""
Expand Down
2 changes: 1 addition & 1 deletion src/wannier90/projections.jl
Expand Up @@ -97,7 +97,7 @@ end
function set_projections!(str::Structure, projs::Pair...; soc = false, kwargs...)
projdict = Dict{Symbol, typeof(projs[1][2])}()
for (sym, proj) in projs
ats = atoms(str, sym)
ats = str[sym]
for a in ats
projdict[name(a)] = proj
end
Expand Down
10 changes: 9 additions & 1 deletion test/job_control_tests.jl
Expand Up @@ -79,7 +79,15 @@ end
save(job)
end


@testset "calculations" begin
job = DFJob(testjobpath)
ncalcs = length(job.calculations)
t = pop!(job, "scf")
@test length(job.calculations) == ncalcs - 1
@test job.calculations[2].name == "bands"
insert!(job, 2, t)
@test job.calculations[2].name == "scf"
end

rm(testjobpath, recursive=true)
# function copy_outfiles()
Expand Down
19 changes: 18 additions & 1 deletion test/jobfromcif_tests.jl
Expand Up @@ -58,27 +58,44 @@ testjobpath = joinpath(testdir, "testassets", "test_job")
end
@test job2.structure == job.structure
@test all(values(job[:ecutwfc]) .== 40.0)
@test DFControl.find_cutoffs(job) == (41.0, 236.0)
end

refjobpath =joinpath(testdir, "testassets", "reference_job")

@testset "reference comparison" begin
job = DFJob(testjobpath)
orig_job = deepcopy(job)
job.structure = create_supercell(job, 1, 0, 0, make_afm = true)

job2 = DFJob(refjobpath)
@test job2.structure == job.structure

for f in DFControl.searchdir(job2, ".out")
cp(f, joinpath(job, splitdir(f)[2]), force=true)
end
for f in DFControl.searchdir(job2, "dos")
cp(f, joinpath(job, splitdir(f)[2]), force=true)
end

set_projections!(job, element(:Ni) => ["s", "p", "d"])
wanexec = Exec("wannier90.x", joinpath(homedir(), "Software/wannier90"))
append!(job, gencalc_wan(job, 0.000011, wanexec = wanexec))
for (c1, c2) in zip(job2.calculations, job.calculations)
@test c2 == c1
end
save(job)
@test !ispath(joinpath(job, "scf.out"))
job = DFJob(testjobpath)

for (c1, c2) in zip(job2.calculations, job.calculations)
@test c2 == c1
end
save(orig_job)
for f in DFControl.searchdir(job2, ".out")
cp(f, joinpath(job, splitdir(f)[2]), force=true)
end
for f in DFControl.searchdir(job2, "dos")
cp(f, joinpath(job, splitdir(f)[2]), force=true)
end
end

0 comments on commit 49c168a

Please sign in to comment.