Spglib is a C library for finding and handling crystal symmetries, exposed as a Python module. It is widely used in materials science and solid-state physics for tasks such as space group determination, primitive cell reduction, and irreducible k-point generation. The current stable version is 2.7.0, with regular updates and maintenance.
pip install spglibVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to define a simple cubic unit cell and use `spglib.get_spacegroup` to identify its space group symmetry, as well as `spglib.get_symmetry_dataset` for more detailed information. Note the specific input format for the cell and the use of `symprec`.
Adjust `symprec` based on the precision of your input structure data. Common values range from 1e-1 to 1e-8. For structures from DFT, 1e-3 to 1e-5 is often suitable. Experiment with different values if unexpected results occur.
Ensure lattice vectors are rows, positions are fractional, and atom types are integers. Many common errors arise from incorrect coordinate systems (e.g., Cartesian instead of fractional for positions) or misinterpreting lattice matrix orientation.
When using `get_primitive` or `find_primitive` with spglib >= 2.0.0, explicitly set the `cell_origin` (e.g., `(0, 0, 0)`) if you require a specific origin, especially when comparing results with those obtained from older spglib versions.
Run `pip install spglib` to install the package.
Convert input data to the correct NumPy array format and ensure the expected shape and dtype, for example: `lattice = np.array(lattice_list, dtype='float64')`.
Carefully check the shapes, dtypes (`float64`, `int32`), and C-contiguity of all NumPy arrays passed to spglib functions, ensuring they strictly match the expected input specifications.
Ensure a C compiler is installed and configured on your system (e.g., `sudo apt-get install build-essential` on Linux) and that `numpy` is installed first (`pip install numpy`) before attempting to install `spglib`.