diff --git a/.gitignore b/.gitignore index 18bfa1e9..ec0a7e93 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ deps/python2/ assets/mpirunflags\.jl deps/mpirunflags\.jl + +deps/wannier90flags\.jl diff --git a/deps/asset_init.jl b/deps/asset_init.jl index 85c83631..a1dbfd5d 100644 --- a/deps/asset_init.jl +++ b/deps/asset_init.jl @@ -1,11 +1,34 @@ +function writefbodyline(f, indent, s) + for i=1:indent + write(f, "\t") + end + write(f, "$s\n") +end -open(joinpath(@__DIR__, "mpirunflags.jl"), "w") do wf - function writefbodyline(indent, s) - for i=1:indent - write(wf, "\t") - end - write(wf, "$s\n") +function fort2julia(f_type) + f_type = lowercase(f_type) + if f_type == "real" + return Float32 + elseif f_type == "real(kind=dp)" + return Float64 + elseif f_type == "complex(kind=dp)" + return Complex{Float64} + elseif occursin("character", f_type) + return String + elseif f_type == "string" + return String + elseif f_type == "integer" + return Int + elseif f_type == "logical" + return Bool + elseif occursin(".D", f_type) + return replace(f_type, "D" => "e") + else + return Nothing end +end + +open(joinpath(@__DIR__, "mpirunflags.jl"), "w") do wf write(wf, "_MPIFLAGS() = ExecFlag[\n") # writefbodyline(1, "flags = ") open(joinpath(@__DIR__, "..", "assets","mpirun_man.txt"), "r") do f @@ -47,11 +70,28 @@ open(joinpath(@__DIR__, "mpirunflags.jl"), "w") do wf symbols = [Symbol(name)] end for symbol in symbols - writefbodyline(1,"""ExecFlag(Symbol("$symbol"), "$name", $type, "$description", nothing),""") + writefbodyline(wf, 1,"""ExecFlag(Symbol("$symbol"), "$name", $type, "$description", nothing),""") end end end end - writefbodyline(1,"""ExecFlag(:dummy, "dummy", Nothing, "dummy", nothing)""") - writefbodyline(0,"]") + writefbodyline(wf, 0,"]") +end + +open(joinpath(@__DIR__, "wannier90flags.jl"), "w") do wf + write(wf, "_WANFLAGS() = Dict{Symbol, Type}(\n") + open(joinpath(@__DIR__, "..", "assets", "inputs", "wannier", "input_flags.txt"), "r") do f + while !eof(f) + line = readline(f) + if isempty(line) || line[1] == '!' + continue + else + s_line = split(line, "::") + flag = Symbol(strip(strip(split(split(split(s_line[end], "=")[1],"(")[1],"!")[1], ':'))) + fl_type = fort2julia(strip(split(s_line[1])[1],',')) + writefbodyline(wf, 1, """Symbol("$flag") => $fl_type,""") + end + end + end + write(wf, ")") end diff --git a/src/DFControl.jl b/src/DFControl.jl index dca8465a..2cd8ea18 100644 --- a/src/DFControl.jl +++ b/src/DFControl.jl @@ -90,7 +90,6 @@ module DFControl # end init_defaults(default_file) init_QEInputInfos() - init_wan_control_flags() end const UNDO_JOBS = DFJob[] diff --git a/src/job.jl b/src/job.jl index 0ebea90f..ec4f74a7 100644 --- a/src/job.jl +++ b/src/job.jl @@ -623,7 +623,7 @@ addwancalc!(job::DFJob, template::String="nscf", args...; kwargs...) = addwancalc!(job, input(job, template), args...; kwargs...) "Automatically calculates and sets the wannier energies. This uses the projections, `Emin` and the bands to infer the other limits.\n`Epad` allows one to specify the padding around the inner and outer energy windows" -function setwanenergies!(job::DFJob, Emin::AbstractFloat, bands; Epad=5.0, print=true) +function setwanenergies!(job::DFJob, bands, Emin::AbstractFloat; Epad=5.0, print=true) wancalcs = filter(x -> package(x) == Wannier90, job.inputs) @assert length(wancalcs) != 0 error("Job ($(job.name)) has no Wannier90 calculations, nothing todo.") nbnd = sum([sum(orbsize.(t)) for t in projections(job)]) diff --git a/src/wannier90/constants.jl b/src/wannier90/constants.jl index 6caaa417..eeed54c0 100644 --- a/src/wannier90/constants.jl +++ b/src/wannier90/constants.jl @@ -1,19 +1,5 @@ -const WannierControlFlags = Dict{Symbol, Type}() -function init_wan_control_flags() - open(joinpath(@__DIR__, "..", "..", "assets", "inputs", "wannier", "input_flags.txt"), "r") do f - while !eof(f) - line = readline(f) - if line == "" || line[1] == '!' - continue - else - s_line = split(line) - flag = Symbol(split(s_line[end],"(")[1]) - fl_type = fort2julia(strip(s_line[1],',')) - WannierControlFlags[flag] = fl_type - end - end - end -end -flagtype(::Type{Wannier90}, flag) = haskey(WannierControlFlags, flag) ? WannierControlFlags[flag] : Nothing +include(joinpath(depsdir, "wannier90flags.jl")) +const WANFLAGS = _WANFLAGS() +flagtype(::Type{Wannier90}, flag) = haskey(WANFLAGS, flag) ? WANFLAGS[flag] : Nothing flagtype(::DFInput{Wannier90}, flag) = flagtype(Wannier90, flag) diff --git a/test/job_control_tests.jl b/test/job_control_tests.jl index aad77ecc..fe6d79b8 100644 --- a/test/job_control_tests.jl +++ b/test/job_control_tests.jl @@ -129,7 +129,7 @@ end testorbs = [:s, :p] setprojections!(job, :Pt => testorbs) @test convert.(Symbol, [p.orb for p in projections(job, :Pt)]) == testorbs -setwanenergies!(job, fermi-7.0, read_qe_bands_file(outpath(nscf)), Epad=3.0, print=false) +setwanenergies!(job, read_qe_bands_file(outpath(nscf)), fermi-7.0, Epad=3.0, print=false) @test flag(job, :dis_froz_max) == 13.2921 @test flag(job, :dis_win_max) == 16.292099999999998