Skip to content

Commit

Permalink
Merge pull request #11 from MineralsCloud:family
Browse files Browse the repository at this point in the history
Rename `family` to `listfamily`
  • Loading branch information
singularitti authored Oct 8, 2023
2 parents 2a02284 + 1e83461 commit 2c1dd69
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/src/public.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ Miller
MillerBravais
ReciprocalMiller
ReciprocalMillerBravais
family
listfamily
@m_str
```
21 changes: 11 additions & 10 deletions src/miller.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using Combinatorics: permutations
using StaticArrays: SVector

export Miller, MillerBravais, ReciprocalMiller, ReciprocalMillerBravais
export family, @m_str
export listfamily, @m_str

"Represent the Miller indices or Miller–Bravais indices."
abstract type Indices <: AbstractVector{Int64} end
Expand Down Expand Up @@ -124,24 +124,25 @@ macro m_str(s) # See https://github.com/JuliaLang/julia/blob/v1.9.3/base/regex.
end

"""
family(x::Union{Miller,MillerBravais,ReciprocalMiller,ReciprocalMillerBravais})
listfamily(x::Union{Miller,MillerBravais,ReciprocalMiller,ReciprocalMillerBravais})
List the all the directions/planes that are equivalent to `x` by symmetry.
"""
function family(mb::T) where {T<:AbstractMillerBravais}
function listfamily(mb::AbstractMillerBravais)
perm = collect(permutations(mb[1:3])) # Permute the first 3 indices for equivalent basis vectors
negate = -perm # Use negative indices
negate = map(-, perm) # Use negative indices
pool = unique(append!(perm, negate))
allowed = filter(v -> v[3] == -v[1] - v[2], pool)
allowed = filter(_predicate, pool)
return map(allowed) do x
T(x..., mb[4]) # Add the 4th index back
typeof(mb)(x..., mb[4]) # Add the 4th index back
end
end
function family(m::T) where {T<:AbstractMiller}
mb = convert(T <: Miller ? MillerBravais : ReciprocalMillerBravais, m) # Real or reciprocal space
vec = family(mb)
return map(x -> convert(T, x), vec)
function listfamily(m::AbstractMiller)
mb = convert(typeof(m) <: Miller ? MillerBravais : ReciprocalMillerBravais, m) # Real or reciprocal space
vec = listfamily(mb)
return map(Base.Fix1(convert, typeof(m)), vec)
end
_predicate(v) = v[3] == -v[1] - v[2]

Base.parent(x::Indices) = x.data

Expand Down
14 changes: 7 additions & 7 deletions test/miller.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ end
end
@test convert(MillerBravais, Miller([1, 0, 0])) == MillerBravais([2, -1, -1, 0])

@testset "Test `family`" begin
@testset "Test `listfamily`" begin
@testset "Test 1" begin
m = Miller(-1, 0, 1)
@test Set(family(m)) == Set(
@test Set(listfamily(m)) == Set(
Miller.([[1, 1, 1], [-1, 0, 1], [0, -1, 1], [-1, -1, 1], [1, 0, 1], [0, 1, 1]])
)
mb = MillerBravais(-1, -1, 2, 3)
@test Set(family(mb)) == Set(
@test Set(listfamily(mb)) == Set(
MillerBravais.([
[1, 1, -2, 3],
[-2, 1, 1, 3],
Expand All @@ -113,13 +113,13 @@ end
end
@testset "Test 2" begin
m = ReciprocalMiller(0, 1, 0)
@test Set(family(m)) == Set(
@test Set(listfamily(m)) == Set(
ReciprocalMiller.([
[1, 0, 0], [0, 1, 0], [1, -1, 0], [-1, 0, 0], [0, -1, 0], [-1, 1, 0]
]),
)
mb = ReciprocalMillerBravais(0, -1, 1, 0)
@test Set(family(mb)) == Set(
@test Set(listfamily(mb)) == Set(
ReciprocalMillerBravais.([
[1, 0, -1, 0],
[0, 1, -1, 0],
Expand All @@ -132,13 +132,13 @@ end
end
@testset "Test 3" begin
m = ReciprocalMiller(1, 1, 0)
@test Set(family(m)) == Set(
@test Set(listfamily(m)) == Set(
ReciprocalMiller.([
[1, 1, 0], [1, -2, 0], [-2, 1, 0], [-1, -1, 0], [-1, 2, 0], [2, -1, 0]
]),
)
mb = ReciprocalMillerBravais(-2, 1, 1, 0)
@test Set(family(mb)) == Set(
@test Set(listfamily(mb)) == Set(
ReciprocalMillerBravais.([
[1, 1, -2, 0],
[1, -2, 1, 0],
Expand Down

0 comments on commit 2c1dd69

Please sign in to comment.