Skip to content

Commit

Permalink
wanflags are parsed on build
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Nov 23, 2018
1 parent 19712c4 commit ed17a8c
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ deps/python2/
assets/mpirunflags\.jl

deps/mpirunflags\.jl

deps/wannier90flags\.jl
58 changes: 49 additions & 9 deletions deps/asset_init.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion src/DFControl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ module DFControl
# end
init_defaults(default_file)
init_QEInputInfos()
init_wan_control_flags()
end

const UNDO_JOBS = DFJob[]
Expand Down
2 changes: 1 addition & 1 deletion src/job.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand Down
20 changes: 3 additions & 17 deletions src/wannier90/constants.jl
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion test/job_control_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ed17a8c

Please sign in to comment.