brainandforce / Electrum.jl

A Julian toolkit for solid-state chemical theory.
MIT License
31 stars 0 forks source link

`lengths()` fails for RealBasis #169

Closed xamberl closed 1 year ago

xamberl commented 1 year ago

Below is the error message.

julia> lengths(xtal.basis)
ERROR: Generator produced too many elements: Expected exactly 3 elements, but generator yields more
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] generator_too_long_error(inds::CartesianIndices{1, Tuple{Base.OneTo{Int64}}})
   @ StaticArrays ~/.julia/packages/StaticArrays/O6dgq/src/SArray.jl:6
 [3] macro expansion
   @ ~/.julia/packages/StaticArrays/O6dgq/src/SArray.jl:15 [inlined]
 [4] sacollect
   @ ~/.julia/packages/StaticArrays/O6dgq/src/SArray.jl:15 [inlined]
 [5] StaticArray
   @ ~/.julia/packages/StaticArrays/O6dgq/src/SArray.jl:54 [inlined]
 [6] lengths(b::RealBasis{3, Float64})
   @ Electrum ~/.julia/packages/Electrum/CLkdf/src/lattices.jl:190
 [7] top-level scope
   @ REPL[1]:1

It seems like the loop here should be fixed. https://github.com/brainandforce/Electrum.jl/blob/aba8aa48044838675e8474490bf88380a2821fd0/src/lattices.jl#L185C13-L205

brainandforce commented 1 year ago

The issue for this arises from how the old RealBasis and ReciprocalBasis types worked. They would iterate through each basis vector. However, the new types are instance of LatticeBasis, which is itself a subtype of StaticMatrix, and iterators through a StaticMatrix yield individual elements. For a 3D set of basis vectors, there are 9 elements, and it's getting those instead of the 3 constituent basis vectors.