Speeding Up Crystallographic Analysis Using Spglib

Written by

in

Getting Started with Spglib: Finding Space Groups in Python Determining the crystal structure and symmetry of a material is a foundational step in materials science and solid-state physics. Spglib is a highly efficient, widely used C library for finding and manipulating crystal symmetries. Thanks to its official Python bindings, you can easily integrate powerful symmetry detection into your data science and simulation workflows.

This guide will show you how to set up Spglib in Python and use it to find the space group of any crystal structure. Prerequisites and Installation

Before you begin, you need to install spglib and numpy. Open your terminal and run: pip install spglib numpy Use code with caution. Step 1: Define the Crystal Structure

Spglib identifies symmetry based on a specific input format: a tuple containing the lattice vectors, the relative atomic positions (fractional coordinates), and the atomic numbers (chemical species).

Let’s define a simple Face-Centered Cubic (FCC) Aluminum cell as an example.

import numpy as np import spglib # 1. Lattice vectors (rows represent vectors a, b, c) lattice = [ [4.05, 0.0, 0.0], [0.0, 4.05, 0.0], [0.0, 0.0, 4.05] ] # 2. Fractional coordinates of atoms positions = [ [0.0, 0.0, 0.0], [0.0, 0.5, 0.5], [0.5, 0.0, 0.5], [0.5, 0.5, 0.0] ] # 3. Atomic numbers (13 is Aluminum) numbers = [13, 13, 13, 13] # Combine into the Spglib cell tuple cell = (lattice, positions, numbers) Use code with caution. Step 2: Get the Space Group Information

Once your cell is defined, finding the space group requires just a single function call: spglib.get_spacegroup().

# Look up the space group spacegroup = spglib.get_spacegroup(cell, symprec=1e-5) print(f”Space Group: {spacegroup}“) Use code with caution. Space Group: Fm-3m (225) Use code with caution. Understanding symprec

The symprec parameter stands for symmetry precision. Because computer simulations and experimental data contain small rounding errors or displacements, atoms might not sit exactly at their ideal mathematical positions. symprec defines the distance tolerance (usually in Angstroms) within which two points are considered symmetrically equivalent. A value between 1e-5 and 1e-3 is standard. Step 3: Extract Advanced Dataset Details

If youget_symmetry_dataset(). This returns a rich dictionary containing the Pearson symbol, Wyckoff positions, international tables, and transformation matrices.

dataset = spglib.get_symmetry_dataset(cell, symprec=1e-5) print(f”International Symbol: {dataset[‘international’]}“) print(f”Hall Symbol: {dataset[‘hall’]}“) print(f”Crystal System: {dataset[‘crystal_system’]}“) print(f”Wyckoff Letters: {dataset[‘wyckoffs’]}“) Use code with caution. Integrating with ASE (Atomic Simulation Environment)

If you already use the Atomic Simulation Environment (ASE) to handle your crystal structures, you do not need to format the tuples manually. Spglib integrates natively with ASE objects.

from ase.build import bulk # Create an ASE Atoms object atoms = bulk(‘Al’, ‘fcc’, a=4.05) # Spglib accepts ASE Atoms objects directly spacegroup = spglib.get_spacegroup(atoms) print(f”ASE Structure Space Group: {spacegroup}“) Use code with caution. Next Steps

Now that you can find space groups, you can use Spglib to find primitive cells (find_primitive), standardize unconventional unit cells (standardize_cell), or find irreducible k-points for quantum mechanical calculations. To help me tailor the next step, please share:

Are your crystal structures ideal (perfect) or do they contain experimental noise/displacements?

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *