Skip to content

Commit d017642

Browse files
committed
improved wannier projections regex and standardize_cell! added
1 parent ad2177e commit d017642

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name = "DFControl"
22
uuid = "1e31e15d-4957-550d-a244-318eced754ae"
33
authors = ["Louis Ponet <[email protected]>"]
44
repo = "https://github.com/louisponet/DFControl.jl.git"
5-
version = "0.5.26"
5+
version = "0.5.27"
66

77
[deps]
88
ANSIColoredPrinters = "a4c015fc-c6ff-483c-b24f-f7ea428134e9"

src/Display/printing.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
show_type(io::IO, ::MIME"text/plain", ::Type{T}) where {T} = println(io, crayon"red", "$T:", crayon"reset")
2-
show_type(io::IO, ::MIME"text/plain", x) = show_type(io, typeof(x))
1+
show_type(io::IO, ::Type{T}) where {T} = println(io, crayon"red", "$T:", crayon"reset")
2+
show_type(io::IO, x) = show_type(io, typeof(x))
33

44
function Base.show(io::IO, ::MIME"text/plain", block::InputData)
55
s = """Block name: $(block.name)

src/FileIO/wannier.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ function wan_parse_calculation(file)
114114
if occursin("random", line)
115115
proj_block = InputData(:projections, :random, nothing)
116116
else
117-
split_line = strip_split(line, ':')
118-
atom = Symbol(split_line[1])
119-
projections = [proj for proj in strip_split(split_line[2], ';')]
117+
m = match(r"\b([\w\d]+):", line)
118+
atom = Symbol(m.captures[1])
119+
projections = map(x->x.captures[1], eachmatch(r"[\s,;]([\w\d]+)", line))
120120
push!(proj_dict, (atom, projections))
121121
end
122122
i += 1

src/Structures/structure.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,37 @@ function find_primitive(s::Structure; kwargs...)
414414
return Structure(new_cell, newats)
415415
end
416416

417+
function standardize_cell!(s::SPGStructure; tolerance = DEFAULT_TOLERANCE, to_primitive=false, no_idealize=false)
418+
nat = length(s.species_indices)
419+
if !to_primitive
420+
t_positions = [s.positions zeros(Float64, 3, 3*nat)]
421+
t_species_indices = [s.species_indices; zeros(Int, 3*nat)]
422+
else
423+
t_positions = s.positions
424+
t_species_indices = s.species_indices
425+
end
426+
# @show t_species_indices
427+
numat = ccall((:spg_standardize_cell, SPGLIB), Cint,
428+
(Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cint}, Cint, Cint, Cint, Cdouble),
429+
s.lattice, t_positions, t_species_indices, nat, to_primitive, no_idealize, tolerance)
430+
numat == 0 && error("Could not find the standardized cell of the supplied structure.")
431+
return SPGStructure(s.lattice, t_positions[:, 1:numat], t_species_indices[1:numat])
432+
end
433+
434+
function standardize_cell(s::Structure; kwargs...)
435+
uats = unique(s.atoms)
436+
spg = standardize_cell!(SPGStructure(s); kwargs...)
437+
new_cell = Mat3{Float64}(spg.lattice') * unit(eltype(s.cell))
438+
newats = eltype(uats)[]
439+
for i in 1:length(spg.species_indices)
440+
tat = deepcopy(uats[spg.species_indices[i]])
441+
set_position!(tat, Point3(spg.positions[:, i]), new_cell)
442+
push!(newats, tat)
443+
end
444+
445+
return Structure(new_cell, newats)
446+
end
447+
417448
"""
418449
cell_parameters(cell::Mat3)
419450
cell_parameters(str::Structure)

0 commit comments

Comments
 (0)