Spglib

2.7.0 · active · verified Mon Apr 13

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.

Warnings

Install

Imports

Quickstart

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']}")

view raw JSON →