diff --git a/src/other.jl b/src/other.jl index 7ec0592..a201c57 100644 --- a/src/other.jl +++ b/src/other.jl @@ -32,26 +32,30 @@ function PeriodicGraphs.make_supercell(cell::Cell{T}, t) where T cell.mat[1,3]*t3, cell.mat[2,3]*t3, cell.mat[3,3]*t3, ) n = length(cell.equivalents) - newequivalents = Vector{EquivalentPosition{T}}(undef, n + (n+1)*(prod(t)-1)) - it1, it2, it3 = 1//t1, 1//t2, 1//t3 - for (i, eq) in enumerate(cell.equivalents) - newequivalents[i] = EquivalentPosition(SMatrix{3,3,T,9}( - eq.mat[1,1], eq.mat[2,1]*t1*it2, eq.mat[3,1]*t1*it3, - eq.mat[1,2]*t2*it1, eq.mat[2,2], eq.mat[3,2]*t2*it3, - eq.mat[1,3]*t3*it1, eq.mat[2,3]*t3*it2, eq.mat[3,3] - ), SVector{3,T}(eq.ofs[1]*it1, eq.ofs[2]*it2, eq.ofs[3]*it3)) - end - for (j, (a, b, c)) in enumerate(PeriodicGraphs.MetaClock(t)) - a == b == c == 0 && continue - ofs = (j-1)*(n+1) - trans = SVector{3,T}(a*it1, b*it2, c*it3) - newequivalents[ofs] = EquivalentPosition(one(SMatrix{3,3,T,9}), trans) - for i in 1:n - ref = newequivalents[i] - newequivalents[ofs+i] = EquivalentPosition(ref.mat, ref.ofs + trans) + if n == 0 + newmat, EquivalentPosition{T}[] + else + newequivalents = Vector{EquivalentPosition{T}}(undef, n + (n+1)*(prod(t)-1)) + it1, it2, it3 = 1//t1, 1//t2, 1//t3 + for (i, eq) in enumerate(cell.equivalents) + newequivalents[i] = EquivalentPosition(SMatrix{3,3,T,9}( + eq.mat[1,1], eq.mat[2,1]*t1*it2, eq.mat[3,1]*t1*it3, + eq.mat[1,2]*t2*it1, eq.mat[2,2], eq.mat[3,2]*t2*it3, + eq.mat[1,3]*t3*it1, eq.mat[2,3]*t3*it2, eq.mat[3,3] + ), SVector{3,T}(eq.ofs[1]*it1, eq.ofs[2]*it2, eq.ofs[3]*it3)) + end + for (j, (a, b, c)) in enumerate(PeriodicGraphs.MetaClock(t)) + a == b == c == 0 && continue + ofs = (j-1)*(n+1) + trans = SVector{3,T}(a*it1, b*it2, c*it3) + newequivalents[ofs] = EquivalentPosition(one(SMatrix{3,3,T,9}), trans) + for i in 1:n + ref = newequivalents[i] + newequivalents[ofs+i] = EquivalentPosition(ref.mat, ref.ofs + trans) + end end + newmat, newequivalents end - newmat, newequivalents end Cell{T}(cell.hall, newmat, newequivalents) end diff --git a/src/types.jl b/src/types.jl index 56b5406..6a65b04 100644 --- a/src/types.jl +++ b/src/types.jl @@ -40,6 +40,14 @@ end (eq::EquivalentPosition)(x) = muladd(eq.mat, x, eq.ofs) EquivalentPosition{T}() where T = EquivalentPosition{T}(one(SMatrix{3,3,T,9}), zero(SVector{3,T})) +function EquivalentPosition(mat::AbstractMatrix{T}, ofs::AbstractVector{U}) where {T,U} + S = promote_type(T,U) + EquivalentPosition{S}(SMatrix{3,3,S,9}(mat), SVector{3,S}(ofs)) +end +function EquivalentPosition{T}(eq::EquivalentPosition{S}) where {S,T} + EquivalentPosition{T}(SMatrix{3,3,T,9}(eq.mat), SVector{3,T}(eq.ofs)) +end + """ find_refid(eqs)