From 190e3a86c8843d7377ad0cbf37b1df89330ee771 Mon Sep 17 00:00:00 2001 From: singularitti Date: Sat, 28 Oct 2023 22:57:04 -0400 Subject: [PATCH 1/6] Add StaticArrays.jl to deps --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index b0527d9..85ed6db 100644 --- a/Project.toml +++ b/Project.toml @@ -10,6 +10,7 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" PyFortran90Namelists = "e44308e6-bd5b-11e9-2850-49daf8f1ec40" QuantumESPRESSOBase = "51b62caa-b28f-11e9-38c2-1f67cb498e05" ReadableRegex = "cbbcb084-453d-4c4c-b292-e315607ba6a4" +StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" VersionParsing = "81def892-9a0e-5fdd-b105-ffc91e053289" [weakdeps] From 12eb0cc3599846bcced903d3d67aa7d692b8a7aa Mon Sep 17 00:00:00 2001 From: singularitti Date: Sat, 28 Oct 2023 22:57:35 -0400 Subject: [PATCH 2/6] Implement `EachTotalForce` block --- src/PWscf/output/each.jl | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/PWscf/output/each.jl b/src/PWscf/output/each.jl index 87f483f..9e62a8f 100644 --- a/src/PWscf/output/each.jl +++ b/src/PWscf/output/each.jl @@ -6,6 +6,7 @@ export eachstep, eachunconvergedenergy, eachconvergedenergy, each_energy_by_step, + eachtotalforce, eachcellparameterscard, eachatomicpositionscard, eachtimeditem @@ -283,6 +284,45 @@ eachconvergedenergy(str::AbstractString) = function each_energy_by_step end +FORCES_ACTING_ON_ATOMS_BLOCK = Regex( + raw"Forces acting on atoms (cartesian axes, Ry/au):" * + capture(lazy_zero_or_more(ANY)) * + rs"Total force =[ \t]*" * + capture(rs"([-+]?[0-9]*\.[0-9]+|[0-9]+\.?[0-9]*)") * + rs"[ \t]+Total SCF correction =[ \t]*" * + capture(rs"([-+]?[0-9]*\.[0-9]+|[0-9]+\.?[0-9]*)"), +) + +struct EachTotalForce <: Each + iterator::Base.RegexMatchIterator +end + +function Base.iterate(iter::EachTotalForce) + iterated = iterate(iter.iterator) + if isnothing(iterated) + return nothing + else + matched, state = iterated + return matched.match, state + end +end +function Base.iterate(iter::EachTotalForce, state) + iterated = iterate(iter.iterator, state) + if isnothing(iterated) + return nothing + else + matched, state = iterated + return matched.match, state + end +end + +Base.eltype(::Type{EachTotalForce}) = String + +Base.IteratorSize(::Type{EachTotalForce}) = Base.SizeUnknown() + +eachtotalforce(str::AbstractString) = + EachTotalForce(eachmatch(FORCES_ACTING_ON_ATOMS_BLOCK, str)) + eachcellparameterscard(str::AbstractString) = EachParsed{CellParametersCard}(CELL_PARAMETERS_BLOCK, str) From daca8a7fbd7180e3042214f86969ecbb0c32c232 Mon Sep 17 00:00:00 2001 From: singularitti Date: Sat, 28 Oct 2023 22:58:09 -0400 Subject: [PATCH 3/6] Implement parses for `AtomicForce` & `eachatomicforce` --- src/PWscf/output/each.jl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/PWscf/output/each.jl b/src/PWscf/output/each.jl index 9e62a8f..17c109b 100644 --- a/src/PWscf/output/each.jl +++ b/src/PWscf/output/each.jl @@ -1,3 +1,5 @@ +using StaticArrays: SVector + export eachstep, eachiteration, eachiterationhead, @@ -7,6 +9,7 @@ export eachstep, eachconvergedenergy, each_energy_by_step, eachtotalforce, + eachatomicforce, eachcellparameterscard, eachatomicpositionscard, eachtimeditem @@ -323,6 +326,33 @@ Base.IteratorSize(::Type{EachTotalForce}) = Base.SizeUnknown() eachtotalforce(str::AbstractString) = EachTotalForce(eachmatch(FORCES_ACTING_ON_ATOMS_BLOCK, str)) +FORCE_ACTING_ON_ATOM = Regex( + rs"atom\s+(\d+)\s+type\s+(\d+)\s+force\s+=\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)" +) + +struct AtomicForce <: PWOutputItem + atom::Int64 + type::Int64 + force::SVector{3,Float64} +end + +function Base.parse(::Type{AtomicForce}, str::AbstractString) + obj = tryparse(AtomicForce, str) + isnothing(obj) ? throw(ParseError("no matched string found!")) : return obj +end +function Base.tryparse(::Type{AtomicForce}, str::AbstractString) + matched = match(FORCE_ACTING_ON_ATOM, str) + if isnothing(matched) + return nothing + else + atom, type = map(Base.Fix1(parse, Int64), matched.captures[1:2]) + force = map(Base.Fix1(parse, Float64), matched.captures[3:5]) + return AtomicForce(atom, type, force) + end +end + +eachatomicforce(str::AbstractString) = EachParsed{AtomicForce}(FORCE_ACTING_ON_ATOM, str) + eachcellparameterscard(str::AbstractString) = EachParsed{CellParametersCard}(CELL_PARAMETERS_BLOCK, str) From 4b0950f4d83574504e3bc36d9d0cde8ad596d081 Mon Sep 17 00:00:00 2001 From: singularitti Date: Sun, 29 Oct 2023 02:48:42 -0400 Subject: [PATCH 4/6] Rename `EachTotalForce` back to `EachAtomicForceBlock` --- src/PWscf/output/each.jl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/PWscf/output/each.jl b/src/PWscf/output/each.jl index 17c109b..48ffe66 100644 --- a/src/PWscf/output/each.jl +++ b/src/PWscf/output/each.jl @@ -8,7 +8,7 @@ export eachstep, eachunconvergedenergy, eachconvergedenergy, each_energy_by_step, - eachtotalforce, + eachatomicforceblock, eachatomicforce, eachcellparameterscard, eachatomicpositionscard, @@ -296,11 +296,11 @@ FORCES_ACTING_ON_ATOMS_BLOCK = Regex( capture(rs"([-+]?[0-9]*\.[0-9]+|[0-9]+\.?[0-9]*)"), ) -struct EachTotalForce <: Each +struct EachAtomicForceBlock <: Each iterator::Base.RegexMatchIterator end -function Base.iterate(iter::EachTotalForce) +function Base.iterate(iter::EachAtomicForceBlock) iterated = iterate(iter.iterator) if isnothing(iterated) return nothing @@ -309,7 +309,7 @@ function Base.iterate(iter::EachTotalForce) return matched.match, state end end -function Base.iterate(iter::EachTotalForce, state) +function Base.iterate(iter::EachAtomicForceBlock, state) iterated = iterate(iter.iterator, state) if isnothing(iterated) return nothing @@ -319,12 +319,12 @@ function Base.iterate(iter::EachTotalForce, state) end end -Base.eltype(::Type{EachTotalForce}) = String +Base.eltype(::Type{EachAtomicForceBlock}) = String -Base.IteratorSize(::Type{EachTotalForce}) = Base.SizeUnknown() +Base.IteratorSize(::Type{EachAtomicForceBlock}) = Base.SizeUnknown() -eachtotalforce(str::AbstractString) = - EachTotalForce(eachmatch(FORCES_ACTING_ON_ATOMS_BLOCK, str)) +eachatomicforceblock(str::AbstractString) = + EachAtomicForceBlock(eachmatch(FORCES_ACTING_ON_ATOMS_BLOCK, str)) FORCE_ACTING_ON_ATOM = Regex( rs"atom\s+(\d+)\s+type\s+(\d+)\s+force\s+=\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)" From 0306010e5dce2967de82c90ec5a8794f094f9e35 Mon Sep 17 00:00:00 2001 From: singularitti Date: Sun, 29 Oct 2023 02:49:46 -0400 Subject: [PATCH 5/6] Implement parses for `TotalForce` & `eachtotalforce` --- src/PWscf/output/each.jl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/PWscf/output/each.jl b/src/PWscf/output/each.jl index 48ffe66..2fcbf85 100644 --- a/src/PWscf/output/each.jl +++ b/src/PWscf/output/each.jl @@ -10,6 +10,7 @@ export eachstep, each_energy_by_step, eachatomicforceblock, eachatomicforce, + eachtotalforce, eachcellparameterscard, eachatomicpositionscard, eachtimeditem @@ -353,6 +354,25 @@ end eachatomicforce(str::AbstractString) = EachParsed{AtomicForce}(FORCE_ACTING_ON_ATOM, str) +TOTAL_FOCE = Regex( + rs"Total force =[ \t]*" * capture(rs"([-+]?[0-9]*\.[0-9]+|[0-9]+\.?[0-9]*)") +) + +struct TotalForce <: PWOutputItem + force::Float64 +end + +function Base.parse(::Type{TotalForce}, str::AbstractString) + obj = tryparse(TotalForce, str) + isnothing(obj) ? throw(ParseError("no matched string found!")) : return obj +end +function Base.tryparse(::Type{TotalForce}, str::AbstractString) + matched = match(TOTAL_FOCE, str) + return isnothing(matched) ? nothing : TotalForce(parse(Float64, matched[1])) +end + +eachtotalforce(str::AbstractString) = EachParsed{TotalForce}(TOTAL_FOCE, str) + eachcellparameterscard(str::AbstractString) = EachParsed{CellParametersCard}(CELL_PARAMETERS_BLOCK, str) From 7893c2d0053ce82e3083e10ea1a37e12049c9544 Mon Sep 17 00:00:00 2001 From: singularitti Date: Sun, 29 Oct 2023 02:50:10 -0400 Subject: [PATCH 6/6] Make new regexes constants --- src/PWscf/output/each.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PWscf/output/each.jl b/src/PWscf/output/each.jl index 2fcbf85..fc108ab 100644 --- a/src/PWscf/output/each.jl +++ b/src/PWscf/output/each.jl @@ -288,7 +288,7 @@ eachconvergedenergy(str::AbstractString) = function each_energy_by_step end -FORCES_ACTING_ON_ATOMS_BLOCK = Regex( +const FORCES_ACTING_ON_ATOMS_BLOCK = Regex( raw"Forces acting on atoms (cartesian axes, Ry/au):" * capture(lazy_zero_or_more(ANY)) * rs"Total force =[ \t]*" * @@ -327,7 +327,7 @@ Base.IteratorSize(::Type{EachAtomicForceBlock}) = Base.SizeUnknown() eachatomicforceblock(str::AbstractString) = EachAtomicForceBlock(eachmatch(FORCES_ACTING_ON_ATOMS_BLOCK, str)) -FORCE_ACTING_ON_ATOM = Regex( +const FORCE_ACTING_ON_ATOM = Regex( rs"atom\s+(\d+)\s+type\s+(\d+)\s+force\s+=\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)" ) @@ -354,7 +354,7 @@ end eachatomicforce(str::AbstractString) = EachParsed{AtomicForce}(FORCE_ACTING_ON_ATOM, str) -TOTAL_FOCE = Regex( +const TOTAL_FOCE = Regex( rs"Total force =[ \t]*" * capture(rs"([-+]?[0-9]*\.[0-9]+|[0-9]+\.?[0-9]*)") )