Skip to content

Commit

Permalink
make eltype of MultTable a SymOperation
Browse files Browse the repository at this point in the history
  • Loading branch information
thchr committed Jul 3, 2021
1 parent 01ff300 commit 56bdaa3
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Crystalline"
uuid = "ae5e2be0-a263-11e9-351e-f94dad1eb351"
authors = ["Thomas Christensen <[email protected]>"]
version = "0.4.1"
version = "0.4.2"

[deps]
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ julia> S"x,-y,-z"
# load the `SymOperation`s of the 3D space group #16 in a conventional setting
julia> sg = spacegroup(16, Val(3))
SpaceGroup{3} #16 (P222) with 4 operations:
1 ──────────────────────────────── (x,y,z)
2₀₀₁ ─────────────────────────── (-x,-y,z)
2₀₁₀ ─────────────────────────── (-x,y,-z)
2₁₀₀ ─────────────────────────── (x,-y,-z)
1
2₀₀₁
2₀₁₀
2₁₀₀

# load a dictionary of small irreps and their little groups for space group #16, indexed by their k-point labels; then inspect the small irreps at the A point
julia> lgirs = get_lgirreps(16, Val(3));
Expand Down
1 change: 0 additions & 1 deletion src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ show(io::IO, op::SymOperation) = print(io, seitz(op))
function show(io::IO, ::MIME"text/plain", mt::MultTable)
summary(io, mt)
println(io, ":")
mt.isgroup || (println(io, " invalid multiplication table"); return nothing)
seitz_ops = seitz.(mt.operations)
pretty_table(io,
getindex.(Ref(seitz_ops), mt.table);
Expand Down
21 changes: 8 additions & 13 deletions src/symops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ end


"""
MultTable(ops::AbstractVector{<:SymOperation{D}}, modτ=true, verbose=false)
MultTable(ops::AbstractVector{<:SymOperation{D}}, modτ=true)
Compute the multiplication (or Cayley) table of `ops`, an `AbstractVector` of
`SymOperation{D}`s.
Expand All @@ -355,7 +355,7 @@ of `row` and `col` operators; the table of indices give the symmetry operators r
the ordering of `ops`.
"""
function MultTable(ops::AbstractVector{SymOperation{D}};
modτ::Bool=true, verbose::Bool=false) where D
modτ::Bool=true) where D
havewarned = false
N = length(ops)
table = Matrix{Int64}(undef, N,N)
Expand All @@ -364,27 +364,22 @@ function MultTable(ops::AbstractVector{SymOperation{D}};
op′ = compose(oprow, opcol, modτ)
match = findfirst(op′′ -> op′op′′, ops)
if isnothing(match)
if !havewarned
if verbose; @warn "The given operations do not form a group!"; end
havewarned = true
end
match = 0
throw(DomainError(ops, "provided operations do not form a group"))
end
@inbounds table[row,col] = match
end
end
isgroup = !havewarned # TODO: ... bit sloppy; could/ought to check more carefully
return MultTable{D}(ops, table, isgroup)
return MultTable{D}(ops, table)
end


function check_multtable_vs_ir(lgir::LGIrrep{D}, αβγ=nothing; verbose::Bool=false) where D
function check_multtable_vs_ir(lgir::LGIrrep{D}, αβγ=nothing) where D
ops = operations(lgir)
sgnum = num(lgir); cntr = centering(sgnum, D)
primitive_ops = primitivize.(ops, cntr) # must do multiplication table in primitive basis, cf. choices in `compose`
check_multtable_vs_ir(MultTable(primitive_ops), lgir, αβγ; verbose=verbose)
check_multtable_vs_ir(MultTable(primitive_ops), lgir, αβγ)
end
function check_multtable_vs_ir(mt::MultTable, ir::AbstractIrrep, αβγ=nothing; verbose::Bool=false)
function check_multtable_vs_ir(mt::MultTable, ir::AbstractIrrep, αβγ=nothing)
havewarned = false
Ds = ir(αβγ)
ops = operations(ir)
Expand All @@ -396,7 +391,7 @@ function check_multtable_vs_ir(mt::MultTable, ir::AbstractIrrep, αβγ=nothing;
checked = trues(N, N)
for (i,Dⁱ) in enumerate(Ds) # rows
for (j,Dʲ) in enumerate(Ds) # cols
@inbounds mtidx = mt[i,j]
@inbounds mtidx = mt.table[i,j]
if iszero(mtidx) && !havewarned
@warn "Provided MultTable is not a group; cannot compare with irreps"
checked[i,j] = false
Expand Down
8 changes: 5 additions & 3 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,14 @@ end
"""
$(TYPEDEF)$(TYPEDFIELDS)
"""
struct MultTable{D} <: AbstractMatrix{Int64}
struct MultTable{D} <: AbstractMatrix{SymOperation{D}}
operations::Vector{SymOperation{D}}
table::Matrix{Int64} # Cayley table: indexes into `operations`
isgroup::Bool
end
@propagate_inbounds getindex(mt::MultTable, i::Int) = mt.table[i]
@propagate_inbounds function getindex(mt::MultTable, i::Int)
mtidx = mt.table[i]
return mt.operations[mtidx]
end
size(mt::MultTable) = size(mt.table)
IndexStyle(::Type{<:MultTable}) = IndexLinear()

Expand Down
22 changes: 11 additions & 11 deletions src/wyckoff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ julia> sg = spacegroup(sgnum, D);
julia> g = SiteGroup(sg, wp)
SiteGroup{2} #16 at 2b = [0.333333, 0.666667] with 3 operations:
1 ────────────────────────────────── (x,y)
{3⁺|1,1} ──────────────────── (-y+1,x-y+1)
{3⁻|0,1} ───────────────────── (-x+y,-x+1)
1
{3⁺|1,1}
{3⁻|0,1}
```
The group structure of a `SiteGroup` can be inspected with `MultTable`:
Expand Down Expand Up @@ -256,9 +256,9 @@ function SiteGroup(sgnum::Integer, wp::WyckPos{D}) where D
return SiteGroup(sg, wp)
end

# `MulTable`s of `SiteGroup`s should be calculated with modτ = false always
function MultTable(g::SiteGroup; verbose::Bool=false)
MultTable(operations(g); modτ=false, verbose=verbose)
# `MulTable`s of `SiteGroup`s should be calculated with `modτ = false` always
function MultTable(g::SiteGroup)
MultTable(operations(g); modτ=false)
end

function orbit(g::SiteGroup{D}, wp::WyckPos{D}) where D
Expand Down Expand Up @@ -299,15 +299,15 @@ julia> sg = spacegroup(sgnum, Val(D));
julia> sitegs = SiteGroup.(Ref(sg), wps)
SiteGroup{2} #5 at 4b = [α, β] with 1 operations:
1 ────────────────────────────────── (x,y)
1
SiteGroup{2} #5 at 2a = [0.0, β] with 2 operations:
1 ────────────────────────────────── (x,y)
m₁₀ ─────────────────────────────── (-x,y)
1
m₁₀
julia> findmaximal(sitegs)
SiteGroup{2} #5 at 2a = [0.0, β] with 2 operations:
1 ────────────────────────────────── (x,y)
m₁₀ ─────────────────────────────── (-x,y)
1
m₁₀
```
"""
function findmaximal(sitegs::AbstractVector{SiteGroup{D}}) where D
Expand Down
30 changes: 18 additions & 12 deletions test/multtable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,40 @@ end # for LGIRS in LGIRSDIM
end # @testset "Space groups (consistent ..."

@testset "Little groups: group property" begin
#numset=Int64[]
for (D, LGIRS) in enumerate(LGIRSDIM)
for lgirsd in LGIRS
for lgirs in values(lgirsd)
sgnum = num(first(lgirs))
cntr = centering(sgnum, D)
ops = operations(first(lgirs)) # ops in conventional basis
primitive_ops = primitivize.(ops, cntr) # ops in primitive basis
mt = MultTable(primitive_ops)
@test mt.isgroup

# for debugging
#mt.isgroup && union!(numset, num(first(lgirs))) # collect info about errors, if any exist
# test that multiplication table can be computed
@test MultTable(primitive_ops) isa MultTable
end
end
end # for LGIRS in LGIRSDIM
# for debugging
#!isempty(numset) && println("The multiplication tables of $(length(numset)) little groups are faulty:\n # = ", numset)
end # @testset "Little groups: ..."

@testset "Broadcasting vs. MultTable indexing" begin
for D in 1:3
for sgnum in 1:MAX_SGNUM[D]
# construct equivalent of MultTable as Matrix{SymOperation{D}} by using
# broadcasting and check that this agrees with MultTable and indexing into it
sg = spacegroup(sgnum, Val(D))
mt = MultTable(sg)
mt′ = sg .* permutedims(sg)
@test mt mt′
end
end
end
for D in 1:3
@testset "Space groups (Bilbao: $(D)D)" begin
for sgnum in 1:MAX_SGNUM[D]
cntr = centering(sgnum, D)
ops = operations(spacegroup(sgnum, Val(D))) # ops in conventional basis
primitive_ops = primitivize.(ops, cntr) # ops in primitive basis
mt = MultTable(primitive_ops)
@test mt.isgroup
@test MultTable(primitive_ops) isa MultTable # test that it doesn't error
end
end
end
Expand All @@ -75,7 +81,7 @@ for (D, LGIRS) in enumerate(LGIRSDIM)

for lgir in lgirs
for αβγ in (nothing, Crystalline.TEST_αβγs[D]) # test finite and zero values of αβγ
checkmt = Crystalline.check_multtable_vs_ir(mt, lgir, αβγ; verbose=false)
checkmt = Crystalline.check_multtable_vs_ir(mt, lgir, αβγ)
@test all(checkmt)
#if !all(checkmt); failcount += 1; end
end
Expand All @@ -93,9 +99,9 @@ end # @testset "Complex LGIrreps"
pg = group(first(pgirs))
for pgir in pgirs
mt = MultTable(operations(pg))
@test mt.isgroup
@test mt isa MultTable

checkmt = Crystalline.check_multtable_vs_ir(mt, pgir, nothing; verbose=false)
checkmt = Crystalline.check_multtable_vs_ir(mt, pgir, nothing)
@test all(checkmt)
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/wyckoff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using Crystalline: constant, free
wps = get_wycks(sgnum, Dᵛ)
for wp in wps
g = SiteGroup(sg, wp)
@test MultTable(g).isgroup
@test g isa SiteGroup

qv = vec(wp)
# test that ops in `g` leave the Wyckoff position `wp` invariant
Expand Down

2 comments on commit 56bdaa3

@thchr
Copy link
Owner Author

@thchr thchr commented on 56bdaa3 Jul 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/40613

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.2 -m "<description of version>" 56bdaa3dccbe9df3594d42d3bd19b40fd5984ab5
git push origin v0.4.2

Please sign in to comment.