From 233133c479622fd561a95ec6a16ee6b75e98c200 Mon Sep 17 00:00:00 2001 From: Louis Ponet Date: Wed, 9 Aug 2023 10:41:33 +0200 Subject: [PATCH] some patches and bugfixes --- src/Calculations/qe.jl | 10 +++++++--- src/Client/job.jl | 4 ++-- src/FileIO/qe.jl | 19 ++++++++++++++----- src/FileIO/wannier.jl | 2 +- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/Calculations/qe.jl b/src/Calculations/qe.jl index a94a4140..e2e02680 100644 --- a/src/Calculations/qe.jl +++ b/src/Calculations/qe.jl @@ -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 @@ -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 diff --git a/src/Client/job.jl b/src/Client/job.jl index 5ee38101..d48bc075 100644 --- a/src/Client/job.jl +++ b/src/Client/job.jl @@ -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 @@ -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)) diff --git a/src/FileIO/qe.jl b/src/FileIO/qe.jl index 4772b54c..e2237fff 100644 --- a/src/FileIO/qe.jl +++ b/src/FileIO/qe.jl @@ -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) @@ -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], @@ -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 @@ -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) diff --git a/src/FileIO/wannier.jl b/src/FileIO/wannier.jl index d8f02887..bdcbf2b0 100644 --- a/src/FileIO/wannier.jl +++ b/src/FileIO/wannier.jl @@ -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