Skip to content

Commit

Permalink
Merge pull request #149 from MineralsCloud:parser
Browse files Browse the repository at this point in the history
Replace `parse_electrons_energies` & `parsefinal` with `eachconvergedenergy` & `eachcellparameterscard` or `eachatomicpositionscard`
  • Loading branch information
singularitti authored Oct 30, 2023
2 parents 3fa6d98 + ccaf234 commit 66abca6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
11 changes: 4 additions & 7 deletions src/ConvergenceTestWorkflow/actions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using AbInitioSoftwareBase: Setter
using CrystallographyBase: MonkhorstPackGrid
using Dates: format, now
using QuantumESPRESSO.PWscf:
PWInput, KMeshCard, PWInput, VerbositySetter, Preamble, parse_electrons_energies
PWInput, KMeshCard, PWInput, VerbositySetter, Preamble, eachconvergedenergy
using Setfield: @set!
using UnifiedPseudopotentialFormat # To work with `download_potential`
using Unitful: ustrip, @u_str
Expand All @@ -17,12 +17,9 @@ end
function (::ExtractData)(file)
str = read(file, String)
preamble = tryparse(Preamble, str)
e = try
parse_electrons_energies(str, :converged)
catch
end
if preamble !== nothing && !isempty(e)
return preamble.ecutwfc * u"Ry" => e.ε[end] * u"Ry" # volume, energy
energies = collect(eachconvergedenergy(str))
if !isnothing(preamble) && !isempty(energies)
return preamble.ecutwfc * u"Ry" => last(energies) * u"Ry" # volume, energy
else
throw(DataExtractionFailed("no data found in file $file."))
end
Expand Down
33 changes: 14 additions & 19 deletions src/EquationOfStateWorkflow/EquationOfStateWorkflow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ using AtomsIO: Atom, periodic_system, save_system
using CrystallographyBase: Lattice, Cell, basisvectors, cellvolume, eachatom
using ExpressBase: Calculation
using QuantumESPRESSO.PWscf:
CellParametersCard,
AtomicPositionsCard,
Preamble,
parse_electrons_energies,
parsefinal,
isjobdone,
tryparsefinal
Preamble, isjobdone, isoptimized, eachcellparameterscard, eachconvergedenergy
using Unitful: @u_str
using UnitfulAtomic

Expand All @@ -27,12 +21,9 @@ end
function (::ExtractData{SelfConsistentField})(file)
str = read(file, String)
preamble = tryparse(Preamble, str)
e = try
parse_electrons_energies(str, :converged)
catch
end
if preamble !== nothing && !isempty(e)
return preamble.omega * u"bohr^3" => e.ε[end] * u"Ry" # volume, energy
energies = collect(eachconvergedenergy(str))
if !isnothing(preamble) && !isempty(energies)
return preamble.omega * u"bohr^3" => last(energies) * u"Ry" # volume, energy
else
throw(DataExtractionFailed("no data found in file $file."))
end
Expand All @@ -42,19 +33,23 @@ function (::ExtractData{VariableCellOptimization})(file)
if !isjobdone(str)
@warn "Job is not finished!"
end
x = tryparsefinal(CellParametersCard, str)
if x !== nothing
return cellvolume(parsefinal(CellParametersCard, str)) * u"bohr^3" =>
parse_electrons_energies(str, :converged).ε[end] * u"Ry" # volume, energy
if !isoptimized(str)
@warn "Cell is not completely optimized!"
end
cards, energies = collect(eachcellparameterscard(str)),
collect(eachconvergedenergy(str))
if !isempty(cards) && !isempty(energies)
lastcell, lastenergy = last(cards), last(energies)
return cellvolume(lastcell) * u"bohr^3" => lastenergy * u"Ry" # volume, energy
else
throw(DataExtractionFailed("no data found in file $file."))
end
end

function (::ExtractCell)(file)
str = read(file, String)
cell_parameters = parsefinal(CellParametersCard, str)
atomic_positions = parsefinal(AtomicPositionsCard, str)
cell_parameters = last(collect(eachcellparameterscard(str)))
atomic_positions = last(collect(eachatomicpositionscard(str)))
return Cell(cell_parameters, atomic_positions)
end

Expand Down
7 changes: 5 additions & 2 deletions src/PhononWorkflow/actions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ using QuantumESPRESSO.PWscf:
AtomicPositionsCard,
CellParametersCardSetter,
AtomicPositionsCardSetter,
tryparsefinal
eachatomicpositionscard,
eachcellparameterscard
using QuantumESPRESSO.PHonon: PhInput, Q2rInput, MatdynInput, VerbositySetter, relayinfo
using Setfield: @set!
using UnifiedPseudopotentialFormat # To work with `download_potential`

import Express.PhononWorkflow: CreateInput, RunCmd, parsecell

function parsecell(str)
return tryparsefinal(AtomicPositionsCard, str), tryparsefinal(CellParametersCard, str)
cell_parameters = last(collect(eachcellparameterscard(str)))
atomic_positions = last(collect(eachatomicpositionscard(str)))
return atomic_positions, cell_parameters
end

(::CreateInput{SelfConsistentField})(file::AbstractString) =
Expand Down

0 comments on commit 66abca6

Please sign in to comment.