Skip to content

Commit

Permalink
some patches and bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Aug 9, 2023
1 parent 50a6f4b commit 233133c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
10 changes: 7 additions & 3 deletions src/Calculations/qe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ end

function outfiles(c::Calculation{QE})
files = [c.outfile]
for (is, fuzzies) in zip(("projwfc.x", "hp.x"), (("pdos",), ("Hubbard_parameters",)))
for (is, fuzzies) in zip(("projwfc.x", "hp.x", "pp.x"), (("pdos",), ("Hubbard_parameters",), ("filplot", "fileout")))
if c.exec.exec == is
append!(files, fuzzies)
end
Expand Down Expand Up @@ -337,13 +337,17 @@ function gencalc_projwfc(template::Calculation{QE}, Emin, Emax, DeltaE, extrafla
end
tdegaussflag = get(template, :degauss, nothing)
degauss = tdegaussflag !== nothing ? tdegaussflag : 0.0
exec = Exec(path=joinpath(dirname(template.exec.path), "projwfc.x"), modules = deepcopy(template.exec.modules), flags = deepcopy(template.exec.flags))
empty!(exec.flags)
exec = Exec(path=joinpath(dirname(template.exec), "projwfc.x"), modules = deepcopy(template.exec.modules))

out = Calculation(deepcopy(template); name = name, exec = exec, data = InputData[])

set_name!(out, "projwfc")

empty!(out.flags)

set_flags!(out, :Emin => Emin, :Emax => Emax, :DeltaE => DeltaE, :ngauss => ngauss,
:degauss => degauss; print = false)

set_flags!(out, extraflags...)
return out
end
4 changes: 2 additions & 2 deletions src/Client/job.jl
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ function outputdata(job::Job; calcs=map(x->x.name, job.calculations), extra_pars
end
end
catch e
@warn "Error while reading output of calculation: $(c)\n" e
@warn "Error while reading output of calculation: $(c)\n" showerror(stdout, e,stacktrace(catch_backtrace()))
end
end
end
Expand All @@ -413,7 +413,7 @@ function bandgap(job::Job, nelec = nothing, outdat = outputdata(job))
if isempty(n_calcs)
error("No valid calculation found to extract the number of electrons.\nPlease supply nelec manually.")
end
nelec = maximum(x->get(get(outdat, x.name, Dict()), :fermi, -Inf), n_calcs)
nelec = maximum(x->get(get(outdat, x.name, Dict()), :n_electrons, 0), n_calcs)
end

bands = map(x->outdat[x.name][:bands], filter(x -> haskey(outdat, x.name), band_calcs))
Expand Down
19 changes: 14 additions & 5 deletions src/FileIO/qe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -716,9 +716,10 @@ function qe_parse_projwfc_output(files...)
end

function pdos(files, kresolved=false)

dir = splitdir(files[1])[1]
atsyms = Symbol.(unique(map(x -> x[findfirst("(", x)[1]+1:findfirst(")", x)[1]-1],files)))
atfiles = filter(x -> occursin("atm", x), files)

atsyms = Symbol.(unique(map(x -> x[findfirst("(", x)[1]+1:findfirst(")", x)[1]-1], atfiles)))
magnetic = (x->occursin("ldosup",x) && occursin("ldosdw",x))(readline(files[1]))
soc = occursin(".5", files[1])
files = joinpath.((dir,), files)
Expand Down Expand Up @@ -1287,8 +1288,8 @@ end
Writes a string represenation to `f`.
"""
function Base.write(f::IO, calculation::Calculation{QE}, structure)
cursize = f.size
function Base.write(f::IO, calculation::Calculation{QE}, structure=nothing)
cursize = f isa IOBuffer ? f.size : 0
if Calculations.hasflag(calculation, :calculation)
Calculations.set_flags!(calculation,
:calculation => replace(calculation[:calculation],
Expand All @@ -1312,13 +1313,20 @@ function Base.write(f::IO, calculation::Calculation{QE}, structure)
# write(f," A = $A\n")
write(f, " nat = $nat\n")
write(f, " ntyp = $ntyp\n")
elseif name == :projwfc
prefix = calculation[:prefix]
outdir = calculation[:outdir]
write(f, " prefix = $prefix\n")
write(f, " outdir = $outdir\n")
end

map(writeflag, [(flag, data) for (flag, data) in flags])
write(f, "/\n\n")
end
end

if exec(calculation.exec) == "pw.x"
@assert structure !== nothing "Supply a structure to write pw.x input"
write_structure(f, calculation, structure)
end
for dat in calculation.data
Expand All @@ -1343,8 +1351,9 @@ function Base.write(f::IO, calculation::Calculation{QE}, structure)
delete!.((calculation,),
(:Hubbard_U, :Hubbard_J0, :Hubbard_J, :Hubbard_alpha, :Hubbard_beta,
:starting_magnetization, :angle1, :angle2, :pseudo_dir))
return f.size - cursize
return f isa IOBuffer ? f.size - cursize : 0
end

function Base.write(f::AbstractString, c::Calculation{QE}, structure)
open(f, "w") do file
write(file, c, structure)
Expand Down
2 changes: 1 addition & 1 deletion src/FileIO/wannier.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function wan_parse_calculation(file)
else
m = match(r"\b([\w\d]+):", line)
atom = Symbol(m.captures[1])
projections = map(x->x.captures[1], eachmatch(r"[\s,;]([\w\d]+)", line))
projections = map(x->x.captures[1], eachmatch(r"[:\s,;]([\w\d]+)", line))
push!(proj_dict, (atom, projections))
end
i += 1
Expand Down

0 comments on commit 233133c

Please sign in to comment.