Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Jun 23, 2021
1 parent 2e2f3a4 commit b4df227
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 27 deletions.
24 changes: 13 additions & 11 deletions src/display/overloads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function show(io::IO, block::InputData)
"""
dfprintln(io, s)
dfprintln(io, string(block.data) * "\n\n")
return
return
end

show(io::IO, data::Vector{InputData}) = map(x -> show(io, x), data)
Expand All @@ -27,7 +27,7 @@ function show(io::IO, band::DFBand{T}) where {T<:AbstractFloat}
extra: $(band.extra)
"""
dfprintln(io, string)
return
return
end

show(io::IO, bands::Vector{<:DFBand}) = map(x -> show(io, x), bands)
Expand Down Expand Up @@ -87,11 +87,13 @@ function show(io::IO, job::DFJob)
for (si, i) in enumerate(is)
n = name(i)
cr = i.run ? crayon"green" : crayon"red"
dfprint(io, cr, i == last ? (is_running ? "\t$n <- running\n" : "\t$n <- ran last\n") : "\t$n\n")
dfprint(io, cr,
i == last ? (is_running ? "\t$n <- running\n" : "\t$n <- ran last\n") :
"\t$n\n")
end
end
dfprint(io, reset)
return
return
end

function show(io::IO, in::DFCalculation)
Expand All @@ -116,15 +118,15 @@ function show(io::IO, in::DFCalculation)
end
end
dfprint(io, crayon"reset")
return
return
end

function show(io::IO, flag_info::QEFlagInfo{T}) where {T}
df_show_type(io, flag_info)
dfprintln(io, crayon"yellow", "name : $(flag_info.name)")
dfprintln(io, crayon"cyan", "description:", crayon"reset")
dfprint(io, "\t" * replace(flag_info.description, "\n" => "\n\t"))
return
return
end

function show(io::IO, flag_info::ElkFlagInfo{T}) where {T}
Expand All @@ -138,7 +140,7 @@ function show(io::IO, flag_info::ElkFlagInfo{T}) where {T}
end
dfprintln(io, crayon"cyan", "description:", crayon"reset")
dfprintln(io, "\t" * replace(flag_info.description, "\n" => "\n\t"))
return
return
end

function show(io::IO, info::ElkControlBlockInfo)
Expand All @@ -150,14 +152,14 @@ function show(io::IO, info::ElkControlBlockInfo)
dfprintln(io, crayon"cyan", "description:", crayon"reset")
dfprintln(io, "\t" * replace(info.description, "\n" => "\n\t"))
dfprint(io, crayon"reset")
return
return
end

function show(io::IO, el::Element)
for f in fieldnames(typeof(el))
dfprintln(io, crayon"red", "$f: ", crayon"reset", "$(getfield(el, f))")
end
dfprint(io, crayon"reset")
return dfprint(io, crayon"reset")
end

function show(io::IO, str::AbstractStructure)
Expand All @@ -170,7 +172,7 @@ function show(io::IO, str::AbstractStructure)
for a in atoms(str)
show(io, a)
end
dfprintln(io, crayon"reset")
return dfprintln(io, crayon"reset")
end

function show(io::IO, at::AbstractAtom{T,LT}) where {T,LT<:Length{T}}
Expand All @@ -193,5 +195,5 @@ function show(io::IO, at::AbstractAtom{T,LT}) where {T,LT<:Length{T}}
end
end
dfprintln(io, crayon"reset")
return
return
end
38 changes: 25 additions & 13 deletions src/qe/fileio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ end
function parse_Hubbard_block(f)
# Each of these will have n Hubbard typ elements at the end
ids = Int[]
traces = NamedTuple{(:up, :down, :total), NTuple{3, Float64}}[]
traces = NamedTuple{(:up, :down, :total),NTuple{3,Float64}}[]
eigvals = (up = Vector{Float64}[], down = Vector{Float64}[])
eigvec = (up = Matrix{Float64}[], down=Matrix{Float64}[])
occupations = (up = Matrix{Float64}[], down=Matrix{Float64}[])
eigvec = (up = Matrix{Float64}[], down = Matrix{Float64}[])
occupations = (up = Matrix{Float64}[], down = Matrix{Float64}[])
magmoms = Float64[]
line = readline(f)
cur_spin = :up
Expand All @@ -57,28 +57,36 @@ function parse_Hubbard_block(f)
if line[1:4] == "atom"
sline = split(line)
push!(ids, parse(Int, sline[2]))
push!(traces, NamedTuple{(:up, :down, :total)}(parse.(Float64, (sline[end-2], sline[end-1], sline[end]))))
push!(traces,
NamedTuple{(:up, :down, :total)}(parse.(Float64,
(sline[end-2], sline[end-1],
sline[end]))))
for spin in (:up, :down)
readline(f) #should be spin1
readline(f)# should be eigvals
push!(eigvals[spin], parse.(Float64, split(readline(f))))
dim = length(eigvals[spin][1])
readline(f) #eigvectors
tmat = zeros(dim, dim)
for i = 1:dim
for i in 1:dim
tmat[i, :] = parse.(Float64, split(readline(f)))
end
push!(eigvec[spin], tmat)
readline(f) #occupations
for i = 1:dim
for i in 1:dim
tmat[i, :] = parse.(Float64, split(readline(f)))
end
push!(occupations[spin], tmat)
end
push!(magmoms, parse(Float64, split(readline(f))[end]))
end
end
return [(id = i, trace = t, eigvals = (up = val_up, down = val_down), eigvecs = (up = vec_up, down=vec_down), occupations = (up=occ_up, down=occ_down), magmom = m) for (i, t, val_up,val_down, vec_up,vec_down, occ_up,occ_down, m) in zip(ids, traces, eigvals.up,eigvals.down, eigvec.up,eigvec.down, occupations.up,occupations.down, magmoms)]
return [(id = i, trace = t, eigvals = (up = val_up, down = val_down),
eigvecs = (up = vec_up, down = vec_down),
occupations = (up = occ_up, down = occ_down), magmom = m)
for (i, t, val_up, val_down, vec_up, vec_down, occ_up, occ_down, m) in
zip(ids, traces, eigvals.up, eigvals.down, eigvec.up, eigvec.down,
occupations.up, occupations.down, magmoms)]
end

"""
Expand Down Expand Up @@ -268,14 +276,14 @@ function qe_read_pw_output(filename::String, T = Float64; cleanup = true)
end
elseif occursin("iteration #", line)
sline = split(line)
it = length(sline[2]) == 1 ? parse(Int, sline[3]) : parse(Int, sline[2][2:end])
it = length(sline[2]) == 1 ? parse(Int, sline[3]) :
parse(Int, sline[2][2:end])
if !haskey(out, :scf_iteration)
out[:scf_iteration] = [it]
else
push!(out[:scf_iteration], it)
end



elseif occursin("Magnetic moment per site", line)
key = :colin_mag_moments
out[key] = T[]
Expand Down Expand Up @@ -320,7 +328,6 @@ function qe_read_pw_output(filename::String, T = Float64; cleanup = true)
split(readline(f))[3:5])
end
elseif line == "--- enter write_ns ---"

if !haskey(out, :Hubbard)
out[:Hubbard] = [parse_Hubbard_block(f)]
else
Expand Down Expand Up @@ -442,9 +449,14 @@ function qe_read_pw_output(filename::String, T = Float64; cleanup = true)
pop!(out, f, nothing)
end
end
out[:converged] = out[:converged] ? true : haskey(out, :scf_converged) && out[:scf_converged] && !haskey(out, :total_force)
out[:converged] = out[:converged] ? true :
haskey(out, :scf_converged) &&
out[:scf_converged] &&
!haskey(out, :total_force)
if haskey(out, :scf_iteration)
out[:n_scf] = length(findall(i -> out[:scf_iteration][i+1] < out[:scf_iteration][i], 1:length(out[:scf_iteration])-1))
out[:n_scf] = length(findall(i -> out[:scf_iteration][i+1] <
out[:scf_iteration][i],
1:length(out[:scf_iteration])-1))
end
pop!(out, :scf_converged, nothing)
return out
Expand Down
4 changes: 1 addition & 3 deletions src/registry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ function request_job(job_dir::String)
return DateTime(0)
end
end
matching_jobs = sort(registered_jobs(job_dir);
by = timestamp,
rev = true)
matching_jobs = sort(registered_jobs(job_dir); by = timestamp, rev = true)
if length(matching_jobs) == 1
return matching_jobs[1]
else
Expand Down

0 comments on commit b4df227

Please sign in to comment.