Skip to content

Commit

Permalink
Merge pull request #111 from MineralsCloud/option
Browse files Browse the repository at this point in the history
Change option from strings to symbols
  • Loading branch information
singularitti authored Oct 10, 2023
2 parents 993eb31 + 30d8c52 commit 5c3efab
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 65 deletions.
10 changes: 5 additions & 5 deletions src/PWscf/input.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ function Base.tryparse(::Type{AtomicPositionsCard}, str::AbstractString)
m = match(ATOMIC_POSITIONS_BLOCK, str)
# Function `match` only searches for the first match of the regular expression, so it could be a `nothing`
if m !== nothing
if string(m.captures[1]) === nothing
if m.captures[1] === nothing
@warn "Not specifying units is DEPRECATED and will no longer be allowed in the future!"
@info "No option is specified, 'alat' is assumed."
option = "alat"
option = :alat
else
option = string(m.captures[1])
option = Symbol(m.captures[1])
end
content = m.captures[2]
return AtomicPositionsCard(
Expand Down Expand Up @@ -251,11 +251,11 @@ function Base.tryparse(::Type{CellParametersCard}, str::AbstractString)
m = match(CELL_PARAMETERS_BLOCK, str)
# Function `match` only searches for the first match of the regular expression, so it could be a `nothing`
if m !== nothing
option = string(m[:option])
option = Symbol(m[:option])
if isempty(option)
@warn "Neither unit nor lattice parameter are specified. DEPRECATED, will no longer be allowed!"
@info "'bohr' is assumed."
option = "bohr"
option = :bohr
end
content = m[:data]
data = Matrix{Float64}(undef, 3, 3)
Expand Down
6 changes: 3 additions & 3 deletions src/PWscf/output.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function parse_ibz(str::AbstractString)::Maybe{Tuple}
end
nk = parse(Int, m[:nk])
result = []
kinds = (:cart => "tpiba", :cryst => "crystal")
kinds = (:cart => :tpiba, :cryst => :crystal)
for (k, v) in kinds
if m[k] !== nothing
x = Matrix{Float64}(undef, nk, 4)
Expand Down Expand Up @@ -535,9 +535,9 @@ function tryparse_internal(::Type{CellParametersCard}, str::AbstractString)
for (i, matched) in enumerate(eachmatch(CELL_PARAMETERS_ITEM_OUTPUT, body))
data[i, :] = map(x -> parse(Float64, x), matched.captures)
end
if m[:option] == "alat"
if m[:option] == :alat
alat = parse(Float64, m[:alat])
CellParametersCard(alat * data, "bohr")
CellParametersCard(alat * data, :bohr)
else
CellParametersCard(data, m[:option])
end
Expand Down
4 changes: 2 additions & 2 deletions test/PWscf/input.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ end
])
@test pw.atomic_positions == AtomicPositionsCard(
[AtomicPosition("C", [2.256, 0.0, 0.0]), AtomicPosition("O", [0, 0, 0], [0, 0, 0])],
"bohr",
:bohr,
)
@test pw.k_points == GammaPointCard()
end
Expand Down Expand Up @@ -257,7 +257,7 @@ end
AtomicPosition("Fe1", [0, 0, 0]),
AtomicPosition("Fe2", [0.5, 0.5, 0.5]),
],
"crystal",
:crystal,
)
@test pw.k_points == KMeshCard(MonkhorstPackGrid([2, 2, 2], [0, 0, 0]))
end
Loading

0 comments on commit 5c3efab

Please sign in to comment.