Registry / data / spglib

spglib

JSON →
library2.7.0pypypi✓ verified 22d ago

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 spglib
INSTALL
IMPORT
SIG · SPGLIB
S
spglib
datapythonv2.7.0
Install
3.9s avg
Import
296ms
Disk
94MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.7.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
build_error
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.9s · import 0.296s · 92MB
94MB installed
● package 94MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

spglib
import spglib
get_spacegroup
spglib.get_spacegroup(cell, symprec=1e-5)
from spglib import get_spacegroup
While functional, direct import is discouraged to keep a clear namespace, as many functions exist within the spglib module.
get_symmetry_dataset
spglib.get_symmetry_dataset(cell, symprec=1e-5)

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`.

import spglib import numpy as np # Define a simple cubic cell # Lattice vectors as rows of a 3x3 matrix lattice = np.array([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]) # Fractional coordinates of atoms positions = np.array([[0.0, 0.0, 0.0]]) # Integer atom types (e.g., atomic number, or arbitrary unique integers) numbers = [1] # Combine into a cell tuple: (lattice, positions, numbers) cell = (lattice, positions, numbers) # Determine the space group using a symmetry precision spacegroup_data = spglib.get_spacegroup(cell, symprec=1e-5) print(f"Spacegroup: {spacegroup_data}") # Get a full dataset of symmetry information dataset = spglib.get_symmetry_dataset(cell, symprec=1e-5) print(f"Spacegroup number: {dataset['number']}") print(f"International short symbol: {dataset['international_short']}")
Debug
Known issues
gotchaThe `symprec` parameter (symmetry precision) is crucial for accurate results. It defines the maximum displacement or distance for atoms to be considered symmetrically equivalent. An incorrect `symprec` (too large or too small) can lead to incorrect symmetry detection, especially for structures with small distortions or specific computational precisions.
fix
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.
affects: All versions
gotchaInput cell format requires strict adherence: `(lattice, positions, numbers)`. `lattice` must be a 3x3 NumPy array where rows are the lattice vectors. `positions` must be an Nx3 NumPy array of *fractional* coordinates. `numbers` must be a list or array of *integer* atom types (not elemental symbols).
fix
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.
affects: All versions
gotchaThe behavior of `spglib.get_primitive` and `spglib.find_primitive` regarding the primitive cell origin changed significantly with v2.0.0 (and C library v1.16). From v2.0.0, these functions accept an optional `cell_origin` parameter. If not provided, a default origin is used, which might differ from the implicit behavior of older versions, potentially affecting consistency for users relying on a specific primitive cell definition.
fix
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.
affects: >=2.0.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'spglib'
The spglib Python package is not installed in the current environment or the Python interpreter cannot find it.
fix
Run `pip install spglib` to install the package.
TypeError: Expected 3x3 array for lattice, got tuple
Spglib functions expect input parameters (like lattice, positions, numbers) to be NumPy arrays of specific shapes and data types (e.g., float64, int), but a Python list, tuple, or incorrectly shaped array was provided.
fix
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')`.
Segmentation fault (core dumped)
This severe error typically occurs when malformed data (e.g., incorrect array shapes, non-contiguous arrays, or invalid dtypes) is passed to the underlying C library, leading to memory access violations.
fix
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.
ERROR: Could not build wheels for spglib which use PEP 517 and cannot be installed directly
The spglib package requires a C compiler (like gcc or MSVC) and NumPy headers to be present and accessible during installation, which are missing or not correctly configured in the environment.
fix
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`.
Upgrade
Version history
2.7.0latest on PyPI · released Dec 29, 2025
Audit
Dependencies
numpyrequiredRequired for array manipulation in the Python interface.
Agent activity
15 hits · last 30 days
node
10
OpenAI (training)
1
Resources
spglib — pip install spglib · libregistry