moyopy
moyopy is a Python binding for the moyo library, a fast and robust crystal symmetry finder written in Rust. It provides functionalities for crystallographic analysis, including space group determination and primitive cell finding. The library is actively maintained, with a current version of 0.7.9, and requires Python 3.10 or newer. New releases appear with an active cadence.
Common errors
-
ModuleNotFoundError: No module named 'moyopy'
cause The moyopy library is not installed in the current Python environment.fixRun `pip install moyopy` to install the package. -
AttributeError: module 'moyopy' has no attribute 'Moyo' (or 'SpaceGroupAnalyzer')
cause Attempting to import a non-existent class or accessing functionality through an incorrect path. `moyopy` directly exposes functions like `get_symmetry_dataset` at its top level, rather than through a main class like `Moyo` or `SpaceGroupAnalyzer` as seen in other libraries.fixImport the relevant function directly, e.g., `from moyopy import get_symmetry_dataset`. -
ValueError: Invalid cell format. The cell must be a tuple of (lattice, positions, numbers).
cause The input structure `cell` passed to `get_symmetry_dataset` (or similar functions) does not adhere to the expected `(lattice, positions, numbers)` tuple format.fixEnsure that `cell` is a tuple where `lattice` is a 3x3 array (float), `positions` is an Nx3 array (float, fractional coordinates), and `numbers` is a list of N integers.
Warnings
- breaking moyopy versions 0.6.1 and later dropped support for Python 3.9. Users on Python 3.9 must upgrade their Python environment to 3.10 or newer.
- breaking The default setting for crystal standardization in moyo-core (which moyopy binds to) changed to International Tables for Crystallography (ITA) standard. This may affect the output of standardized cells compared to previous versions.
- gotcha There can be differences in lattice vector ordering between the underlying Rust moyo-core and its Python bindings (moyopy), which may lead to discrepancies in `prim_std_cell.basis` results compared to other symmetry libraries like spglib. This often necessitates additional explicit ordering constraints for consistent results in downstream applications.
Install
-
pip install moyopy -
pip install moyopy[interface]
Imports
- get_symmetry_dataset
import moyopy.moyo
from moyopy import get_symmetry_dataset
Quickstart
import numpy as np
from moyopy import get_symmetry_dataset
# Define crystal structure (lattice, positions, numbers)
# Example: Diamond cubic silicon
lattice = np.array([
[0, 2.735, 2.735],
[2.735, 0, 2.735],
[2.735, 2.735, 0]
])
positions = np.array([
[0.0, 0.0, 0.0],
[0.25, 0.25, 0.25]
])
numbers = [14, 14] # Atomic numbers for Si
cell = (lattice, positions, numbers)
symprec = 1e-5 # Symmetry precision in Angstrom
angle_tolerance = 1.0 # Angle tolerance in degrees
dataset = get_symmetry_dataset(cell, symprec=symprec, angle_tolerance=angle_tolerance)
print(f"Space group number: {dataset['number']}")
print(f"International symbol: {dataset['international']}")
print(f"Hall symbol: {dataset['hall']}")
# print(f"Rotations: {dataset['rotations']}")
# print(f"Translations: {dataset['translations']}")