diff --git a/Project.toml b/Project.toml index ceb0236a..0fc69194 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Crystalline" uuid = "ae5e2be0-a263-11e9-351e-f94dad1eb351" authors = ["Thomas Christensen "] -version = "0.4.2" +version = "0.4.3" [deps] Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa" diff --git a/src/bravais.jl b/src/bravais.jl index 842918fd..e2b59f0a 100644 --- a/src/bravais.jl +++ b/src/bravais.jl @@ -496,16 +496,16 @@ function conventionalize(Rsโ€ฒ::DirectBasis{D}, cntr::Char) where D end function transform(Gs::ReciprocalBasis{D}, P::AbstractMatrix{<:Real}) where D - # While the direct basis (๐š ๐› ๐œ) transforms like - # (๐šโ€ฒ ๐›โ€ฒ ๐œโ€ฒ) = (๐š ๐› ๐œ)๐ - # under a basis change matrix ๐, the reciprocal basis (๐š* ๐›* ๐œ*) transforms like - # (๐š*โ€ฒ ๐›*โ€ฒ ๐œ*โ€ฒ) = (๐š* ๐›* ๐œ*)(๐โปยน)แต€ - # since (๐š ๐› ๐œ)(๐š* ๐›* ๐œ*)แต€ = 2ฯ€๐ˆ must be conserved after the basis change - - # Gmโ€ฒ = Gm*(Pโปยน)แต€ = Gm*(Pแต€)โปยน (w/ Gm a matrix w/ columns of untransformed reciprocal - # vecs Gแตข) - Gmโ€ฒ = basis2matrix(Gs)/P' - return ReciprocalBasis{D}(ntuple(i->Gmโ€ฒ[:,i], Val(D))) + # While the direct basis (๐š ๐› ๐œ) transforms like + # (๐šโ€ฒ ๐›โ€ฒ ๐œโ€ฒ) = (๐š ๐› ๐œ)๐ + # under a basis change matrix ๐, the reciprocal basis (๐š* ๐›* ๐œ*) transforms like + # (๐š*โ€ฒ ๐›*โ€ฒ ๐œ*โ€ฒ) = (๐š* ๐›* ๐œ*)(๐โปยน)แต€ + # since (๐š ๐› ๐œ)(๐š* ๐›* ๐œ*)แต€ = 2ฯ€๐ˆ must be conserved after the basis change + + # Gmโ€ฒ = Gm*(Pโปยน)แต€ = Gm*(Pแต€)โปยน (w/ Gm a matrix w/ columns of untransformed reciprocal + # vecs Gแตข) + Gmโ€ฒ = basis2matrix(Gs)/P' + return ReciprocalBasis{D}(ntuple(i->Gmโ€ฒ[:,i], Val(D))) end """ diff --git a/src/types.jl b/src/types.jl index ae2d052c..2ee7e7c5 100644 --- a/src/types.jl +++ b/src/types.jl @@ -23,6 +23,10 @@ for T in (:DirectBasis, :ReciprocalBasis) @eval $T(Vs::NTuple{D, SVector{D, Float64}}) where D = $T{D}(Vs) @eval $T{D}(Vs::NTuple{D, NTuple{D,<:Real}}) where D = $T{D}(SVector{D,Float64}.(Vs)) @eval $T(Vs::NTuple{D, NTuple{D,<:Real}}) where D = $T{D}(Vs) + @eval $T{D}(Vs::NTuple{D, <:AbstractVector{<:Real}}) where D = $T{D}(Vs...) + @eval $T(Vs::NTuple{D, <:AbstractVector{<:Real}}) where D = $T{D}(Vs...) + @eval $T{D}(Vs::AbstractVector{<:AbstractVector{<:Real}}) where D = $T{D}(Vs...) + @eval $T(Vs::AbstractVector{<:AbstractVector{<:Real}}) = $T(Vs...) @eval $T{D}(Vs::AbstractVector{<:Real}...) where D = $T{D}(convert(SVector{D, SVector{D, Float64}}, Vs)) @eval $T(Vs::AbstractVector{<:Real}...) = $T{length(Vs)}(Vs...) @eval $T{D}(Vs::StaticVector{D,<:Real}...) where D = $T{D}(Vs) # resolve ambiguities w/ diff --git a/test/basisvecs.jl b/test/basisvecs.jl index b4b047c3..08b5163e 100644 --- a/test/basisvecs.jl +++ b/test/basisvecs.jl @@ -1,4 +1,4 @@ -using Crystalline, Test, LinearAlgebra +using Crystalline, Test, LinearAlgebra, StaticArrays @testset "Basis vectors" begin @testset "Conventional bases" begin @@ -26,4 +26,22 @@ using Crystalline, Test, LinearAlgebra end end end + + @testset "Mixed inputs for constructors" begin + Rs = ([1.0, 0.0, 0.0], [-0.5, sqrt(3)/2, 0.0], [0, 0, 1.25]) + Rsโ€ฒ = DirectBasis{3}(Rs) + @test Rsโ€ฒ == DirectBasis(Rs) # NTuple{3, Vector{3, Float64}} + Rsหขหข = convert(SVector{3,SVector{3,Float64}}, Rs) # SVector{3, SVector{3, Float64}} + @test Rsโ€ฒ == DirectBasis{3}(Rsหขหข) == DirectBasis(Rsหขหข) + Rsแต› = [Rs...] # Vector{Vector{Float64}} + @test Rsโ€ฒ == DirectBasis{3}(Rsแต›) == DirectBasis(Rsแต›) + Rsหข = SVector{3,Float64}.(Rs) # NTuple{3, SVector{3, Float64}} + @test Rsโ€ฒ == DirectBasis{3}(Rsหข) == DirectBasis(Rsหข) + Rsแต— = ntuple(i->ntuple(j->Rs[i][j], Val(3)), Val(3)) # NTuple{3, NTuple{3, Float64}} + @test Rsโ€ฒ == DirectBasis{3}(Rsแต—) == DirectBasis(Rsแต—) + @test Rsโ€ฒ == DirectBasis(Rs[1], Rs[2], Rs[3]) == DirectBasis{3}(Rs[1], Rs[2], Rs[3]) + # โ†‘ Varargs / splatting of Vector{Float64} + @test Rsโ€ฒ == DirectBasis(Rsหข[1], Rsหข[2], Rsหข[3]) == DirectBasis{3}(Rsหข[1], Rsหข[2], Rsหข[3]) + # โ†‘ Varargs / splatting of SVector{3, Float64} + end end \ No newline at end of file