Skip to content

Commit

Permalink
wannier output is parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Nov 25, 2018
1 parent ed6c1c5 commit 90c1482
Show file tree
Hide file tree
Showing 6 changed files with 9,155 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/DFControl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ module DFControl
export read_qe_input
export read_qe_output
export read_wannier_input
export read_wannier_output
export readbands

include("plotting.jl")

Expand Down
28 changes: 28 additions & 0 deletions src/fileio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,34 @@ function write_data(f, data)
end
end
end

Base.length(::Type{<:Number}) = 1

function Base.parse(::Type{NamedTuple{names, types}}, spl::Vector{<:AbstractString}) where {names, types}
@assert sum(length.(types.parameters)) == length(spl)
tbuf = Vector{Union{types.parameters...}}(undef, length(types.parameters))
counter = 1
for (i, typ) in enumerate(types.parameters)
if typ <: AbstractVector
l = length(typ)
tbuf[i] = parse(typ, spl[counter:counter+l-1])
counter += l
else
tbuf[i] = parse(typ, spl[counter])
counter += 1
end
end
pstring = (tbuf...,)
return NamedTuple{names}(pstring)
end
Base.parse(::Type{T}, s::AbstractString) where {T <: NamedTuple} = parse(T, split(s))

function Base.parse(::Type{Point{N, T}}, spl::Vector{<:AbstractString}) where {N, T}
@assert N == length(spl)
return Point{N, T}(parse.(T, spl))
end
Base.parse(::Type{T}, s::AbstractString) where {T <: Point} = parse(T, split(s))

#---------------------------BEGINNING GENERAL SECTION-------------------#
#Incomplete: only works with SBATCH right now
function write_job_name(f, job::DFJob)
Expand Down
7 changes: 6 additions & 1 deletion src/input.jl
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,13 @@ function outputdata(input::DFInput; print=true, overwrite=true)
end

readoutput(input::DFInput{QE}) = read_qe_output(outpath(input))
readoutput(input::DFInput{Wannier90}) = SymAnyDict()
readoutput(input::DFInput{Wannier90}) = read_wannier_output(outpath(input))

"""
readbands(input::DFInput)
Will try to read bands from the outputfile of the input. Errors when no bands are found
"""
function readbands(input::DFInput)
to = readoutput(input)
if haskey(to, :bands)
Expand Down
49 changes: 49 additions & 0 deletions src/wannier90/fileio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,52 @@ function save(input::DFInput{Wannier90}, structure, filename::String=inpath(inpu
end
end
end

"""
read_wannier_output(filename)
Reads an outputfile for wannier.
Parsed info:
:disentanglement,
:wannierise,
:final_state,
"""
function read_wannier_output(filename)
DisTuple = NamedTuple{(:Iter, :Ω_i_1, :Ω_i, , :Time), Tuple{Int, Float64, Float64, Float64, Float64}}
WanTuple = NamedTuple{(:Iter, :δ_spread, :∇RMS, :Spread, :Time), Tuple{Int, Float64, Float64, Float64, Float64}}
WfcTuple = NamedTuple{(:index, :center, :Spread), Tuple{Int, Point3{Float64}, Float64}}
data = Dict{Symbol, Any}()
open(filename, "r") do f
sreadline() = readline(f) |> strip
line = sreadline()
while !eof(f)
if line == "Extraction of optimally-connected subspace"
data[:disentanglement] = DisTuple[]
for i = 1:4 readline(f) end
line = sreadline()
while !isempty(line)
push!(data[:disentanglement], parse(DisTuple, split(line)[1:end-2]))
line = sreadline()
end
elseif line == "Initial State"
data[:wannierise] = WanTuple[]
line = sreadline()
while !occursin("Final State", line)
if occursin("CONV", line)
push!(data[:wannierise], parse(WanTuple, split(line)[1:end-2]))
end
line = sreadline()
end
data[:final_state] = WfcTuple[]
line = sreadline()
while !occursin("Sum", line)
line = replace(replace(replace(line, "(" => ""), ")" => ""), "," => "")
push!(data[:final_state], parse(WfcTuple, split(line)[5:end]))
line = sreadline()
end
end
line = sreadline()
end
end
return data
end
4 changes: 3 additions & 1 deletion test/job_control_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ wanflags = [:write_hr => true, :wannier_plot => true]
addwancalc!(job, "nscf",:Pt => [:s, :p, :d], Emin=fermi-7.0, Epad=5.0, wanflags=wanflags, print=false)
@test flag(job, "wan", :write_hr) == flag(job, "wan", :wannier_plot) == true


wanout = outputdata(job, "wan")
@test length(wanout[:final_state]) == 20
@test length(wanout[:wannierise]) == 203
job.inputs = job.inputs[1:4]

setflags!(job, :nspin => 2, print=false)
Expand Down
Loading

0 comments on commit 90c1482

Please sign in to comment.