diff --git a/src/PWscf/output/each.jl b/src/PWscf/output/each.jl index aa54082..1f18ccf 100644 --- a/src/PWscf/output/each.jl +++ b/src/PWscf/output/each.jl @@ -130,9 +130,9 @@ function Base.tryparse(::Type{Diagonalization}, str::AbstractString) end end -struct UnconvergedEnergy <: PWOutputItem +Base.@kwdef struct UnconvergedEnergy <: PWOutputItem total_energy::Float64 - harris_foulkes_estimate::Maybe{Float64} + harris_foulkes_estimate::Maybe{Float64} = nothing estimated_scf_accuracy::Float64 end @@ -145,17 +145,32 @@ function Base.tryparse(::Type{UnconvergedEnergy}, str::AbstractString) if isnothing(matched) return nothing else - ɛ, hf, δ = map(_parser, matched.captures) - return UnconvergedEnergy(ɛ, hf, δ) + total, harris_foulkes_estimate, estimated_scf_accuracy = map( + _parser, matched.captures + ) + return UnconvergedEnergy(total, harris_foulkes_estimate, estimated_scf_accuracy) end end _parser(x) = isnothing(x) ? x : parse(Float64, x) -struct ConvergedEnergy <: PWOutputItem - total_energy::Float64 - harris_foulkes_estimate::Maybe{Float64} +Base.@kwdef struct ConvergedEnergy <: PWOutputItem + total::Float64 + harris_foulkes_estimate::Maybe{Float64} = nothing estimated_scf_accuracy::Float64 + all_electron::Maybe{Float64} = nothing + one_electron::Maybe{Float64} = nothing + hartree::Maybe{Float64} = nothing + xc::Maybe{Float64} = nothing + ewald::Maybe{Float64} = nothing + one_center_paw::Maybe{Float64} = nothing + paw_hartree_ae::Maybe{Float64} = nothing + paw_hartree_ps::Maybe{Float64} = nothing + paw_xc_ae::Maybe{Float64} = nothing + paw_xc_ps::Maybe{Float64} = nothing + total_e_h_paw::Maybe{Float64} = nothing + total_e_xc_paw::Maybe{Float64} = nothing + smearing::Maybe{Float64} = nothing end function Base.parse(::Type{ConvergedEnergy}, str::AbstractString) @@ -167,7 +182,46 @@ function Base.tryparse(::Type{ConvergedEnergy}, str::AbstractString) if isnothing(matched) return nothing else - ɛ, hf, δ = map(_parser, matched.captures[1:3]) - return ConvergedEnergy(ɛ, hf, δ) + total, harris_foulkes_estimate, estimated_scf_accuracy = map( + _parser, matched.captures[1:3] + ) + all_electron = if !isnothing(matched[:ae]) + parse(Float64, only(match(Regex(FIXED_POINT_REAL), matched[:ae]))) + end + one_electron, hartree, xc, ewald = if !isnothing(matched[:decomp]) + map( + Base.Fix1(parse, Float64) ∘ only, + eachmatch(Regex(FIXED_POINT_REAL), matched[:decomp]), + ) + end + # one_center_paw, + # paw_hartree_ae, paw_hartree_ps, paw_xc_ae, paw_xc_ps, total_e_h_paw, + # total_e_xc_paw = if !isnothing(matched[:decomp]) + # map( + # Base.Fix1(parse, Float64) ∘ only, + # eachmatch(Regex(FIXED_POINT_REAL), matched[:decomp]), + # ) + # end + smearing = if !isnothing(matched[:smearing]) + parse(Float64, only(match(Regex(FIXED_POINT_REAL), matched[:smearing]))) + end + return ConvergedEnergy(; + total, + harris_foulkes_estimate, + estimated_scf_accuracy, + all_electron, + one_electron, + hartree, + xc, + ewald, + # one_center_paw, + # paw_hartree_ae, + # paw_hartree_ps, + # paw_xc_ae, + # paw_xc_ps, + # total_e_h_paw, + # total_e_xc_paw, + smearing, + ) end end diff --git a/src/PWscf/output/output.jl b/src/PWscf/output/output.jl index 4ccb3bc..6e596e2 100644 --- a/src/PWscf/output/output.jl +++ b/src/PWscf/output/output.jl @@ -13,10 +13,6 @@ export Preamble, export parse_symmetries, parse_stress, parse_bands, - parse_all_electron_energy, - parse_energy_decomposition, - parse_paw_contribution, - parse_smearing_energy, parse_version, parse_parallel_info, parse_fft_dimensions, @@ -100,73 +96,6 @@ function parse_bands(str::AbstractString) return kpts, bands end # function parse_bands -function parse_all_electron_energy(str::AbstractString) - df = DataFrame(; step=Int[], ae=Maybe{Float64}[]) - for (i, m) in enumerate(eachmatch(CONVERGED_ELECTRONS_ENERGY, str)) - ae = if any(==(nothing), (m, m[:ae])) - nothing - else - parse(Float64, match(Regex(FIXED_POINT_REAL), m[:ae])[1]) - end - push!(df, [i ae]) - end - return df -end # function parse_all_electron_energy - -function parse_energy_decomposition(str::AbstractString) - df = DataFrame(; - step=Int[], - onelectron=Maybe{Float64}[], - hartree=Maybe{Float64}[], - xc=Maybe{Float64}[], - ewald=Maybe{Float64}[], - ) - for (i, m) in enumerate(eachmatch(CONVERGED_ELECTRONS_ENERGY, str)) - data = if any(==(nothing), (m, m[:decomp])) - ntuple(_ -> nothing, 4) - else - map(x -> parse(Float64, x[1]), eachmatch(Regex(FIXED_POINT_REAL), m[:decomp])) - end - push!(df, [i data...]) - end - return df -end # function parse_energy_decomposition - -function parse_paw_contribution(str::AbstractString) - df = DataFrame(; - step=Int[], - one_electron=Maybe{Float64}[], - hartree_ae=Maybe{Float64}[], - hartree_ps=Maybe{Float64}[], - xc_ae=Maybe{Float64}[], - xc_ps=Maybe{Float64}[], - eh=Maybe{Float64}[], - exc=Maybe{Float64}[], - ) - for (i, m) in enumerate(eachmatch(CONVERGED_ELECTRONS_ENERGY, str)) - data = if any(==(nothing), (m, m[:one])) - ntuple(_ -> nothing, 6) - else - map(x -> parse(Float64, x[1]), eachmatch(Regex(FIXED_POINT_REAL), m[:one])) - end - push!(df, [i data...]) - end - return df -end # function parse_paw_contribution - -function parse_smearing_energy(str::AbstractString) - df = DataFrame(; step=Int[], smearing=Maybe{Float64}[]) - for (i, m) in enumerate(eachmatch(CONVERGED_ELECTRONS_ENERGY, str)) - smearing = if any(==(nothing), (m, m[:smearing])) - nothing - else - parse(Float64, match(Regex(FIXED_POINT_REAL), m[:smearing])[1]) - end - push!(df, [i smearing]) - end - return df -end # function parse_smearing_energy - function parse_version(str::AbstractString)::Maybe{VersionNumber} m = match(PWSCF_VERSION, str) m !== nothing ? vparse(m[:version]) : return nothing