singularitti/Spglib.jl

BoundsError on get_dataset

kbarros opened this issue · 1 comments

I would expect the following code to run cleanly, but it throws a BoundsError:

import Spglib
latvecs = [6.42 0 0; 0.0 6.41 0; 0.0 0.0 6.44]
x = 0.79
y = 1-x
positions = [[y, y, x], [y, x, y], [x, y, y], [x, x, x], [x, x, y], [x, y, x], [y, x, x], [y, y, y]]
types = ["Ga", "Ga", "Ga", "Ga", "Ga", "Ga", "Ga", "Ga"]
cell = Spglib.Cell(latvecs, positions, types)
Spglib.get_dataset(cell, 1e-3) # BoundsError

Stacktrace:

ERROR: BoundsError: attempt to access 26-element StepRange{Char, Int64} at index [27]
Stacktrace:
 [1] throw_boundserror(A::StepRange{Char, Int64}, I::Int64)
   @ Base ./abstractarray.jl:734
 [2] getindex
   @ ./range.jl:948 [inlined]
 [3] (::Spglib.var"#7#12")(w::Int32)
   @ Spglib ./none:0
 [4] iterate
   @ ./generator.jl:47 [inlined]
 [5] collect(itr::Base.Generator{Vector{Int32}, Spglib.var"#7#12"})
   @ Base ./array.jl:834
 [6] Spglib.Dataset(dataset::Spglib.SpglibDataset)
   @ Spglib ~/.julia/packages/Spglib/O9RSC/src/core.jl:352
 [7] get_dataset(cell::Spglib.SpglibCell{Float64, Float64, String, Any}, symprec::Float64)
   @ Spglib ~/.julia/packages/Spglib/O9RSC/src/symmetry.jl:175
 [8] top-level scope
   @ REPL[8]:1

The code runs without error when (a) the symmetry precision is reduced to 1e-2 or (b) the unit cell is cubic or (c) any atom is removed.

Versions

Tested on Spglib v0.9.1, with:

julia> versioninfo()
Julia Version 1.10.0-rc3
Commit ed79752b939 (2023-12-18 09:57 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 8 × Apple M1 Pro
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
  Threads: 1 on 6 virtual cores

Thanks for discovering this bug! This is now fixed.