Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Mar 28, 2020
1 parent 854006b commit d262daa
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/DFControl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ module DFControl
# else
# error("DFControl not properly installed. Please run Pkg.build(\"DFControl\")")
# end
include("precompile.jl")
_precompile_()
# include("precompile.jl")
# _precompile_()
end
13 changes: 7 additions & 6 deletions src/inputAPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,13 @@ runcommand(input::DFInput) = input.execs[1]

"Returns the outputdata for the input."
function outputdata(input::DFInput; print=true, overwrite=true)
if hasoutput(input) && !overwrite
return outdata(input)
end
if hasoutfile(input)
input.outdata = readoutput(input)
return input.outdata
if hasoutput(input)
if !overwrite && !isempty(outdata(input))
return outdata(input)
else
input.outdata = readoutput(input)
return input.outdata
end
end
print && (@warn "No output data or output file found for input: $(name(input)).")
return SymAnyDict()
Expand Down
2 changes: 1 addition & 1 deletion src/job.jl
Original file line number Diff line number Diff line change
Expand Up @@ -292,5 +292,5 @@ function Base.pop!(job::DFJob, name::String)
return out
end

find_files(job::DFJob, str::AbstractString) = joinpath.((job,), searchdir(job.local_dir, str))
searchdir(job::DFJob, str::AbstractString) = joinpath.((job,), searchdir(job.local_dir, str))

14 changes: 7 additions & 7 deletions src/jobAPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ function outputdata(job::DFJob, inputs::Vector{DFInput}; print=true, onlynew=fal
datadict[name(input)] = tout
end
end
datadict
return datadict
end
outputdata(job::DFJob; kwargs...) = outputdata(job, inputs(job); kwargs...)
outputdata(job::DFJob, names::String...; kwargs...) =
Expand Down Expand Up @@ -528,20 +528,20 @@ Calculates the bandgap (possibly indirect) around the fermi level.
Uses the first found bands calculation, if there is none it uses the first found nscf calculation.
"""
function bandgap(job::DFJob, fermi=nothing)
band_calcs = getfirst.((isbandscalc, isnscfcalc, isscfcalc), (inputs(job),))
band_calcs = getfirst.([isbandscalc, isnscfcalc, isscfcalc], (inputs(job),))
if all(x -> x === nothing, band_calcs)
error("No valid calculation found to calculate the bandgap.\nMake sure the job has either a valid bands or nscf calculation.")
end
bands = readbands(getfirst(x -> x!==nothing, band_calcs))
if fermi === nothing
fermi_calcs = getfirst.((isnscfcalc, isscfcalc), (inputs(job),))
fermi_calcs = getfirst.([isnscfcalc, isscfcalc], (inputs(job),))
if all(x -> x === nothing, band_calcs)
error("No valid calculation found to extract the fermi level.\nPlease supply the fermi level manually.")
end
fermi = readfermi(getfirst(x -> x!==nothing, fermi_calcs))
fermi = maximum(readfermi.(filter(x -> x!==nothing, fermi_calcs)))
end

return bandgap(bands, fermi)
bands = readbands.(filter(x -> x!==nothing, band_calcs))
return minimum(bandgap.(bands, fermi))
end

"Searches for the first scf or nscf calculation with output, and reads the fermi level from it."
Expand Down Expand Up @@ -619,7 +619,7 @@ function pdos(job, atsym, filter_word="")
magnetic = ismagneticcalc(scfcalc)

if package(projwfc) == QE
files = filter(x->occursin("($atsym",x) && occursin("#", x) && occursin(filter_word, x), find_files(job, "pdos"))
files = filter(x->occursin("($atsym",x) && occursin("#", x) && occursin(filter_word, x), searchdir(job, "pdos"))
if isempty(files)
@error "No pdos files found in jobdir"
end
Expand Down
3 changes: 2 additions & 1 deletion src/qe/fileio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ function qe_read_output(filename::String, T=Float64)
elseif occursin("Fermi", line)
out[:fermi] = parse(T, split(line)[5])
elseif occursin("lowest unoccupied", line) && occursin("highest occupied", line)
out[:fermi] = parse(T, split(line)[7])
sline = split(line)
out[:fermi] = (parse(T, sline[7]) + parse(T, sline[8]))/2

elseif occursin("total energy", line) && line[1] == '!'
out[:total_energy] = parse(T, split(line)[5])
Expand Down
11 changes: 5 additions & 6 deletions test/job_control_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ using DFControl, Test
testjobpath = joinpath(testdir, "testassets", "test_job")

job = DFJob(testjobpath);
@test deepcopy(job["scf"]) == job["scf"]
job4 = DFJob(testjobpath)

#output stuff
Expand Down Expand Up @@ -245,7 +244,7 @@ scale_bondlength!(at, at2, 0.5, c)
@test isapprox((position_cart(at) + position_cart(at2))/2, mid)
@test isapprox(distance(at, at2), bondlength/2)

@test isapprox(bandgap(job), 3.6522999999999994)
@test isapprox(bandgap(job), 2.6701999999999995)

t = job["nscf"]
curlen = length(job.inputs)
Expand Down Expand Up @@ -281,14 +280,14 @@ orig_projs = projections(atoms(job, :Pt)[1])
job.structure = create_supercell(structure(job), 1, 0, 0, make_afm=true)

DFControl.sanitize_magnetization!(job)
@test length(atoms(job, :Pt)) == prevlen_Pt
@test length(atoms(job, :Pt1)) == prevlen_Pt
@test length(atoms(job, :Pt2)) == prevlen_Pt

@test magnetization(atoms(job, :Pt1)[1]) == [0, 0, 1]
@test magnetization(atoms(job, :Pt2)[1]) == [0, 0, -1]
@test magnetization(atoms(job, :Pt)[1]) == [0, 0, 1]
@test magnetization(atoms(job, :Pt1)[1]) == [0, 0, -1]

DFControl.sanitize_projections!(job)
@test projections(atoms(job, :Pt1)[1]) != projections(atoms(job, :Pt2)[1])
@test projections(atoms(job, :Pt)[1]) != projections(atoms(job, :Pt1)[1])

job4.server_dir = "/tmp"
save(job4)
Expand Down

0 comments on commit d262daa

Please sign in to comment.