Skip to content

Commit

Permalink
Unify Collection and IrrepCollection, removing the latter
Browse files Browse the repository at this point in the history
  • Loading branch information
thchr committed Sep 13, 2024
1 parent 5e34c7b commit 7ea038e
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 60 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ SpaceGroup{3} ⋕16 (P222) with 4 operations:
# indexed by their k-point labels; then inspect the small irreps at the A point
julia> lgirs = lgirreps(16, Val(3))
julia> lgirs["A"]
2-element IrrepCollection{LGIrrep{3}} for 16 (P222) at A = [α, 0, 1/2]:
2-element Collection{LGIrrep{3}} for 16 (P222) at A = [α, 0, 1/2]:
A₁ ─┬─────────────────────────────────────────────
├─ 1: ──────────────────────────────── (x,y,z)
1
Expand Down
8 changes: 4 additions & 4 deletions build/ParseIsotropy.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ParseIsotropy

using Crystalline
using Crystalline: AbstractIrrep, IrrepCollection
using Crystalline: AbstractIrrep

export parselittlegroupirreps

Expand Down Expand Up @@ -264,7 +264,7 @@ end

parselittlegroupirreps() = parselittlegroupirreps.(parseisoir(Complex))
function parselittlegroupirreps(irvec::Vector{SGIrrep3D{ComplexF64}})
lgirsd = Dict{String, IrrepCollection{LGIrrep{3}}}()
lgirsd = Dict{String, Collection{LGIrrep{3}}}()
curklab = nothing; accidx = Int[]
for (idx, ir) in enumerate(irvec) # loop over distinct irreps (e.g., Γ1, Γ2, Γ3, Z1, Z2, ..., GP1)
if curklab == klabel(ir)
Expand All @@ -275,7 +275,7 @@ function parselittlegroupirreps(irvec::Vector{SGIrrep3D{ComplexF64}})
for (pos, kidx) in enumerate(accidx) # write all irreps of a specific k-point to a vector (e.g., Z1, Z2, ...)
lgirs[pos] = littlegroupirrep(irvec[kidx])
end
push!(lgirsd, curklab=>IrrepCollection(lgirs))
push!(lgirsd, curklab=>Collection(lgirs))
end

curklab = klabel(ir)
Expand All @@ -292,7 +292,7 @@ function parselittlegroupirreps(irvec::Vector{SGIrrep3D{ComplexF64}})
end
lastklab = klabel(irvec[last(accidx)])
@assert lastklab == "Ω"
push!(lgirsd, lastklab=>IrrepCollection(lgirs))
push!(lgirsd, lastklab=>Collection(lgirs))

return lgirsd
end
Expand Down
4 changes: 2 additions & 2 deletions src/Crystalline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ include("types.jl") # defines useful types for space group symmetry analysis
export SymOperation, # types
DirectBasis, ReciprocalBasis,
Reality, REAL, PSEUDOREAL, COMPLEX,
IrrepCollection,
Collection,
MultTable, LGIrrep, PGIrrep, SiteIrrep,
KVec, RVec,
BandRep, BandRepSet,
Expand All @@ -74,7 +74,7 @@ export SymOperation, # types
isspinful

include("types_symmetry_vectors.jl")
export SymmetryVector, NewBandRep, Collection
export SymmetryVector, NewBandRep
export irreps, multiplicities, occupation

include("notation.jl")
Expand Down
4 changes: 2 additions & 2 deletions src/irreps_reality.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ function realify(lgirs::AbstractVector{LGIrrep{D}}; verbose::Bool=false) where D
end
end

return IrrepCollection(lgirs′)
return Collection(lgirs′)
end

"""
Expand Down Expand Up @@ -320,7 +320,7 @@ function realify(irs::AbstractVector{T}) where T<:AbstractIrrep
# `AbstractIrrep`, which is probably not a great idea, but meh)
ntuple(i->getfield(ir, 5+i), Val(T_extrafields))...))
end
return IrrepCollection(irs′)
return Collection(irs′)
end

# ---------------------------------------------------------------------------------------- #
Expand Down
6 changes: 3 additions & 3 deletions src/littlegroup_irreps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ littlegroups(sgnum::Integer, D::Integer) = littlegroups(sgnum, Val(D))

"""
lgirreps(sgnum::Integer, D::Union{Val{Int}, Integer}=Val(3))
-> Dict{String, IrrepCollection{LGIrrep{D}}}
-> Dict{String, Collection{LGIrrep{D}}}
For given space group number `sgnum` and dimension `D`, return the associated little group
(or "small") irreps (`LGIrrep{D}`s) at high-symmetry k-points, lines, and planes.
Expand Down Expand Up @@ -88,11 +88,11 @@ function lgirreps(sgnum::Integer, Dᵛ::Val{D}=Val(3),

Ps_list, τs_list, realities_list, cdmls_list = _load_lgirreps_data(sgnum, irs_jldfile)

lgirsd = Dict{String, IrrepCollection{LGIrrep{D}}}()
lgirsd = Dict{String, Collection{LGIrrep{D}}}()
for (Ps, τs, realities, cdmls) in zip(Ps_list, τs_list, realities_list, cdmls_list)
klab = klabel(first(cdmls))
lg = lgs[klab]
lgirsd[klab] = IrrepCollection(
lgirsd[klab] = Collection(
[LGIrrep{D}(cdml, lg, P, τ, Reality(reality))
for (P, τ, reality, cdml) in zip(Ps, τs, realities, cdmls)])
end
Expand Down
8 changes: 4 additions & 4 deletions src/pointgroup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function pgirreps(iuclab::String, ::Val{3}=Val(3); mulliken::Bool=false)
matrices, realities, cdmls = _load_pgirreps_data(iuclab)
pgirlabs = !mulliken ? cdmls : _mulliken.(Ref(iuclab), cdmls, false)

return IrrepCollection(PGIrrep{3}.(pgirlabs, Ref(pg), matrices, Reality.(realities)))
return Collection(PGIrrep{3}.(pgirlabs, Ref(pg), matrices, Reality.(realities)))
end
# 2D
function pgirreps(iuclab::String, ::Val{2}; mulliken::Bool=false)
Expand All @@ -152,7 +152,7 @@ function pgirreps(iuclab::String, ::Val{2}; mulliken::Bool=false)
matrices, realities, cdmls = _load_pgirreps_data(iuclab)
pgirlabs = !mulliken ? cdmls : _mulliken.(Ref(iuclab), cdmls, false)

return IrrepCollection(PGIrrep{2}.(pgirlabs, Ref(pg), matrices, Reality.(realities)))
return Collection(PGIrrep{2}.(pgirlabs, Ref(pg), matrices, Reality.(realities)))
end
# 1D
function pgirreps(iuclab::String, ::Val{1}; mulliken::Bool=false)
Expand All @@ -171,7 +171,7 @@ function pgirreps(iuclab::String, ::Val{1}; mulliken::Bool=false)
end
pgirlabs = !mulliken ? cdmls : _mulliken.(Ref(iuclab), cdmls, false)

return IrrepCollection(PGIrrep{1}.(pgirlabs, Ref(pg), matrices, REAL))
return Collection(PGIrrep{1}.(pgirlabs, Ref(pg), matrices, REAL))
end
pgirreps(iuclab::String, ::Val{D}; kws...) where D = _throw_invalid_dim(D) # if D ∉ (1,2,3)
pgirreps(iuclab::String, D::Integer; kws...) = pgirreps(iuclab, Val(D); kws...)
Expand All @@ -181,7 +181,7 @@ function pgirreps(pgnum::Integer, Dᵛ::Val{D}=Val(3);
return pgirreps(iuc, Dᵛ; kws...)
end
function pgirreps(pgnum::Integer, D::Integer; kws...)
return pgirreps(pgnum, Val(D); kws...) :: IrrepCollection{<:PGIrrep}
return pgirreps(pgnum, Val(D); kws...) :: Collection{<:PGIrrep}
end

function (pgir1::PGIrrep{D}, pgir2::PGIrrep{D}) where D
Expand Down
12 changes: 6 additions & 6 deletions src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,12 @@ function prettyprint_header(io::IO, irlab::AbstractString, nboxdelims::Integer=4
end

# ---------------------------------------------------------------------------------------- #
# IrrepCollection
# Collection{<:AbstractIrrep}

function summary(io::IO, c::IrrepCollection{T}) where T
print(io, length(c), "-element IrrepCollection{", T, "}")
function summary(io::IO, c::Collection{T}) where T <: AbstractIrrep
print(io, length(c), "-element Collection{", T, "}")
end
function show(io::IO, ::MIME"text/plain", c::IrrepCollection)
function show(io::IO, ::MIME"text/plain", c::Collection{T}) where T <: AbstractIrrep
summary(io, c)
isassigned(c, firstindex(c)) && _print_group_descriptor(io, group(first(c)); prefix=" for ")
println(io, ":")
Expand All @@ -352,8 +352,8 @@ function show(io::IO, ::MIME"text/plain", c::IrrepCollection)
i length(c) && println(io)
end
end
function show(io::IO, c::IrrepCollection)
show(io, c.irs)
function show(io::IO, c::Collection{T}) where T <: AbstractIrrep
show(io, c.vs)
g = group(first(c))
if position(g) !== nothing
printstyled(io, " (", fullpositionlabel(g), ")"; color=:light_black)
Expand Down
39 changes: 27 additions & 12 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -781,21 +781,36 @@ end
Base.position(siteir::SiteIrrep) = position(group(siteir))

# ---------------------------------------------------------------------------------------- #
# IrrepCollection
# Collection{T}
# ---------------------------------------------------------------------------------------- #

struct IrrepCollection{T<:AbstractIrrep} <: AbstractVector{T}
irs :: Vector{T}
end
Base.size(c::IrrepCollection) = size(c.irs)
Base.IndexStyle(::Type{<:IrrepCollection}) = IndexLinear()
@propagate_inbounds Base.getindex(c::IrrepCollection, i::Int) = c.irs[i]
@propagate_inbounds function Base.setindex!(
c::IrrepCollection{T}, ir::T, i::Int) where T<:AbstractIrrep
c.irs[i] = ir
"""
Collection{T} <: AbstractVector{T}
A wrapper around a `Vector{T}`, that allows custom printing and dispatch rules of custom
`T` (e.g., `AbstractIrrep` & `NewBandRep`).
In Crystalline, it is assumed that all elements of the wrapped vector are associated with
the _same_ space or point group. Accordingly, if `T` implements [`dim`](@ref) or
[`num`](@ref), either must return the same element for each element of the `Collection`
(and is equal to `dim(::Collection)` and `num(::Collection)`).
"""
struct Collection{T} <: AbstractVector{T}
vs :: Vector{T}
end
IrrepCollection(c::IrrepCollection) = c
Base.similar(c::IrrepCollection{T}) where T = IrrepCollection{T}(similar(c.irs))

# ::: AbstractArray interface :::
Base.size(c::Collection) = size(c.vs)
Base.IndexStyle(::Type{<:Collection}) = IndexLinear()
@propagate_inbounds Base.getindex(c::Collection{T}, i::Integer) where T = c.vs[i]::T
@propagate_inbounds Base.setindex!(c::Collection{T}, v::T, i::Integer) where T = (c.vs[i]=v)
Base.similar(c::Collection{T}) where T = Collection{T}(similar(c.vs))
Base.iterate(c::Collection) = iterate(c.vs)
Base.iterate(c::Collection, state) = iterate(c.vs, state)

# ::: Interface :::
dim(vs::Collection) = dim(first(vs))
num(vs::Collection) = num(first(vs))

# ---------------------------------------------------------------------------------------- #
# CharacterTable
Expand Down
29 changes: 9 additions & 20 deletions src/types_symmetry_vectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ abstract type AbstractSymmetryVector{D} <: AbstractVector{Int} end

# ::: API :::
"""
irreps(n::AbstractSymmetryVector) -> AbstractVector{<:IrrepCollection}
irreps(n::AbstractSymmetryVector{D}) -> AbstractVector{<:Collection{<:AbstractIrrep{D}}}
Return the irreps referenced by `n`.
The returned value is an `AbstractVector` of `IrrepCollection`s, with irreps for distinct
groups and **k**-manifolds belonging to the same `IrrepCollection`.
The returned value is an `AbstractVector` of `Collection{<:AbstractIrrep}`s, with irreps for
distinct groups, usually associated with specific **k**-manifolds, belonging to the same
`Collection`.
See also [`multiplicities(::AbstractSymmetryVector)`](@ref).
"""
Expand Down Expand Up @@ -68,7 +69,7 @@ end
# SymmetryVector

mutable struct SymmetryVector{D} <: AbstractSymmetryVector{D}
const lgirsv :: Vector{IrrepCollection{LGIrrep{D}}}
const lgirsv :: Vector{Collection{LGIrrep{D}}}
const multsv :: Vector{Vector{Int}}
occupation :: Int
end
Expand Down Expand Up @@ -151,26 +152,14 @@ function Base.convert(::Type{BandRep}, br::NewBandRep{D}) where D
end

# ---------------------------------------------------------------------------------------- #
# Collection
struct Collection{T} <: AbstractVector{T}
vs :: Vector{T}
end

# ::: AbstractArray interface :::
Base.size(c::Collection) = size(c.vs)
Base.getindex(c::Collection, i::Int) = c.vs[i]
Base.setindex!(c::Collection{T}, v::T, i::Int) where T = (c.vs[i]=v)
Base.similar(c::Collection{T}) where T = Collection{T}(similar(c.vs))
Base.iterate(c::Collection) = iterate(c.vs)
Base.iterate(c::Collection, state) = iterate(c.vs, state)
# Collection{<:NewBandRep}

# ::: Utilities :::
num(brs::Collection{NewBandRep}) = num(first(brs).siteir)
irreplabels(brs::Collection{NewBandRep}) = irreplabels(first(brs).n)
klabels(brs::Collection{NewBandRep}) = klabels(first(brs).n)
irreplabels(brs::Collection{<:NewBandRep}) = irreplabels(first(brs).n)
klabels(brs::Collection{<:NewBandRep}) = klabels(first(brs).n)

# ::: Conversion to BandRepSet :::
function Base.convert(::Type{BandRepSet}, brs::Collection{NewBandRep{D}}) where D
function Base.convert(::Type{BandRepSet}, brs::Collection{<:NewBandRep})
sgnum = num(first(brs))
bandreps = convert.(Ref(BandRep), brs)
kvs = [position(first(lgirs)) for lgirs in irreps(first(brs))]
Expand Down
4 changes: 2 additions & 2 deletions src/wyckoff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ SiteGroup{2} ⋕16 (p6) at 2b = [1/3, 2/3] with 3 operations:
{3⁻|0,1}
julia> siteirs = siteirreps(siteg)
3-element IrrepCollection{SiteIrrep{2}} for ⋕16 (p6) at 2b = [1/3, 2/3]:
3-element Collection{SiteIrrep{2}} for ⋕16 (p6) at 2b = [1/3, 2/3]:
Γ₁ ─┬─────────────────────────────────────────────
├─ 1: ────────────────────────────────── (x,y)
│ 1
Expand Down Expand Up @@ -392,6 +392,6 @@ function siteirreps(siteg::SiteGroup{D}; mulliken::Bool=false) where D
SiteIrrep{D}(label(pgir), siteg, pgir.matrices[Iᵖ²ᵍ], reality(pgir), pgir.iscorep,
pglabel)
end
return IrrepCollection(siteirs)
return Collection(siteirs)
end
mulliken(siteir::SiteIrrep) = _mulliken(siteir.pglabel, label(siteir), iscorep(siteir))
8 changes: 4 additions & 4 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ test_tp_show(sitegroup(sg, wps[end-1]), str)
# LGIrrep
# -------------------------------
str = """
4-element IrrepCollection{LGIrrep{3}} for ⋕16 (P222) at Γ = [0, 0, 0]:
4-element Collection{LGIrrep{3}} for ⋕16 (P222) at Γ = [0, 0, 0]:
Γ₁ ─┬─────────────────────────────────────────────
├─ 1: ──────────────────────────────── (x,y,z)
│ 1
Expand Down Expand Up @@ -252,7 +252,7 @@ str = """
test_tp_show(lgirreps(16)["Γ"], str)

str = """
4-element IrrepCollection{LGIrrep{3}}:
4-element Collection{LGIrrep{3}}:
#undef
#undef
#undef
Expand Down Expand Up @@ -349,8 +349,8 @@ str = """
pgirs = pgirreps("6")
pgirs′ = realify(pgirs)
test_tp_show(pgirs′[end], str)
@test summary(pgirs) == "6-element IrrepCollection{PGIrrep{3}}"
@test summary(pgirs′) == "4-element IrrepCollection{PGIrrep{3}}"
@test summary(pgirs) == "6-element Collection{PGIrrep{3}}"
@test summary(pgirs′) == "4-element Collection{PGIrrep{3}}"

# -------------------------------
# CharacterTable
Expand Down

0 comments on commit 7ea038e

Please sign in to comment.