Skip to content

Add python interface for space-group type: moyopy.SpaceGroupType #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
uv pip install --system --no-index --find-links dist moyopy
uv pip install --system moyopy[interface]
python moyopy/examples/basic.py
python moyopy/examples/space_group_type.py
python moyopy/examples/pymatgen_structure.py

linux:
Expand Down
12 changes: 7 additions & 5 deletions moyo/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ mod point_group;
mod setting;
mod wyckoff;

pub use arithmetic_crystal_class::ArithmeticNumber;
pub use arithmetic_crystal_class::{
arithmetic_crystal_class_entry, ArithmeticCrystalClassEntry, ArithmeticNumber,
};
pub use centering::Centering;
pub use classification::{
BravaisClass, CrystalFamily, CrystalSystem, GeometricCrystalClass, LatticeSystem,
};
pub use hall_symbol::{HallSymbol, MagneticHallSymbol};
pub use hall_symbol_database::{hall_symbol_entry, HallNumber, HallSymbolEntry, Number};
pub use magnetic_hall_symbol_database::{magnetic_hall_symbol_entry, MagneticHallSymbolEntry};
Expand All @@ -19,10 +24,7 @@ pub use magnetic_space_group::{
};
pub use setting::Setting;

pub(super) use arithmetic_crystal_class::{
arithmetic_crystal_class_entry, iter_arithmetic_crystal_entry,
};
pub(super) use classification::{CrystalSystem, GeometricCrystalClass, LatticeSystem};
pub(super) use arithmetic_crystal_class::iter_arithmetic_crystal_entry;
pub(super) use magnetic_space_group::uni_number_range;
pub(super) use point_group::PointGroupRepresentative;
pub(super) use wyckoff::{iter_wyckoff_positions, WyckoffPosition, WyckoffPositionSpace};
11 changes: 8 additions & 3 deletions moyo/src/data/arithmetic_crystal_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ pub type ArithmeticNumber = i32;

#[derive(Debug, Clone)]
pub struct ArithmeticCrystalClassEntry {
/// Number for arithmetic crystal classes (1 - 73)
pub arithmetic_number: ArithmeticNumber,
#[allow(dead_code)]
/// Symbol for arithmetic crystal class
pub symbol: &'static str,
/// Geometric crystal class
pub geometric_crystal_class: GeometricCrystalClass,
/// Bravais class
pub bravais_class: BravaisClass,
}

Expand All @@ -33,8 +36,10 @@ impl ArithmeticCrystalClassEntry {

pub fn arithmetic_crystal_class_entry(
arithmetic_number: ArithmeticNumber,
) -> ArithmeticCrystalClassEntry {
ARITHMETIC_CRYSTAL_CLASS_DATABASE[arithmetic_number as usize - 1].clone()
) -> Option<ArithmeticCrystalClassEntry> {
ARITHMETIC_CRYSTAL_CLASS_DATABASE
.get(arithmetic_number as usize - 1)
.cloned()
}

pub fn iter_arithmetic_crystal_entry() -> impl Iterator<Item = &'static ArithmeticCrystalClassEntry>
Expand Down
122 changes: 122 additions & 0 deletions moyo/src/data/classification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,52 @@ pub enum GeometricCrystalClass {
Oh, // m-3m
}

impl ToString for GeometricCrystalClass {
fn to_string(&self) -> String {
match self {
// Triclinic
GeometricCrystalClass::C1 => "1".to_string(),
GeometricCrystalClass::Ci => "-1".to_string(),
// Monoclinic
GeometricCrystalClass::C2 => "2".to_string(),
GeometricCrystalClass::C1h => "m".to_string(),
GeometricCrystalClass::C2h => "2/m".to_string(),
// Orthorhombic
GeometricCrystalClass::D2 => "222".to_string(),
GeometricCrystalClass::C2v => "mm2".to_string(),
GeometricCrystalClass::D2h => "mmm".to_string(),
// Tetragonal
GeometricCrystalClass::C4 => "4".to_string(),
GeometricCrystalClass::S4 => "-4".to_string(),
GeometricCrystalClass::C4h => "4/m".to_string(),
GeometricCrystalClass::D4 => "422".to_string(),
GeometricCrystalClass::C4v => "4mm".to_string(),
GeometricCrystalClass::D2d => "-42m".to_string(),
GeometricCrystalClass::D4h => "4/mmm".to_string(),
// Trigonal
GeometricCrystalClass::C3 => "3".to_string(),
GeometricCrystalClass::C3i => "-3".to_string(),
GeometricCrystalClass::D3 => "32".to_string(),
GeometricCrystalClass::C3v => "3m".to_string(),
GeometricCrystalClass::D3d => "-3m".to_string(),
// Hexagonal
GeometricCrystalClass::C6 => "6".to_string(),
GeometricCrystalClass::C3h => "-6".to_string(),
GeometricCrystalClass::C6h => "6/m".to_string(),
GeometricCrystalClass::D6 => "622".to_string(),
GeometricCrystalClass::C6v => "6mm".to_string(),
GeometricCrystalClass::D3h => "-6m2".to_string(),
GeometricCrystalClass::D6h => "6/mmm".to_string(),
// Cubic
GeometricCrystalClass::T => "23".to_string(),
GeometricCrystalClass::Th => "m-3".to_string(),
GeometricCrystalClass::O => "432".to_string(),
GeometricCrystalClass::Td => "-43m".to_string(),
GeometricCrystalClass::Oh => "m-3m".to_string(),
}
}
}

#[derive(Debug, Clone, Copy, PartialEq, EnumIter)]
pub enum LaueClass {
Ci, // -1
Expand Down Expand Up @@ -155,29 +201,78 @@ impl CrystalSystem {
}
}

impl ToString for CrystalSystem {
fn to_string(&self) -> String {
match self {
CrystalSystem::Triclinic => "Triclinic".to_string(),
CrystalSystem::Monoclinic => "Monoclinic".to_string(),
CrystalSystem::Orthorhombic => "Orthorhombic".to_string(),
CrystalSystem::Tetragonal => "Tetragonal".to_string(),
CrystalSystem::Trigonal => "Trigonal".to_string(),
CrystalSystem::Hexagonal => "Hexagonal".to_string(),
CrystalSystem::Cubic => "Cubic".to_string(),
}
}
}

/// ===========================================================================
/// Classification based on lattice
/// ===========================================================================
/// Reuse notations for Bravais type of lattices
#[allow(non_camel_case_types)]
#[derive(Debug, Clone, Copy, PartialEq, EnumIter)]
pub enum BravaisClass {
// Triclinic
aP,
// Monoclinic
mP,
mC,
// Orthorhombic
oP,
oS,
oF,
oI,
// Tetragonal
tP,
tI,
// Rhombohedral
hR,
// Hexagonal
hP,
// Cubic
cP,
cF,
cI,
}

impl ToString for BravaisClass {
fn to_string(&self) -> String {
match self {
// Triclinic
BravaisClass::aP => "aP".to_string(),
// Monoclinic
BravaisClass::mP => "mP".to_string(),
BravaisClass::mC => "mC".to_string(),
// Orthorhombic
BravaisClass::oP => "oP".to_string(),
BravaisClass::oS => "oS".to_string(),
BravaisClass::oF => "oF".to_string(),
BravaisClass::oI => "oI".to_string(),
// Tetragonal
BravaisClass::tP => "tP".to_string(),
BravaisClass::tI => "tI".to_string(),
// Rhombohedral
BravaisClass::hR => "hR".to_string(),
// Hexagonal
BravaisClass::hP => "hP".to_string(),
// Cubic
BravaisClass::cP => "cP".to_string(),
BravaisClass::cF => "cF".to_string(),
BravaisClass::cI => "cI".to_string(),
}
}
}

#[derive(Debug, Clone, Copy, PartialEq, EnumIter)]
pub enum LatticeSystem {
// (lattice system, holohedry)
Expand Down Expand Up @@ -206,6 +301,20 @@ impl LatticeSystem {
}
}

impl ToString for LatticeSystem {
fn to_string(&self) -> String {
match self {
LatticeSystem::Triclinic => "Triclinic".to_string(),
LatticeSystem::Monoclinic => "Monoclinic".to_string(),
LatticeSystem::Orthorhombic => "Orthorhombic".to_string(),
LatticeSystem::Tetragonal => "Tetragonal".to_string(),
LatticeSystem::Rhombohedral => "Rhombohedral".to_string(),
LatticeSystem::Hexagonal => "Hexagonal".to_string(),
LatticeSystem::Cubic => "Cubic".to_string(),
}
}
}

/// ===========================================================================
/// Other classification
/// ===========================================================================
Expand Down Expand Up @@ -245,3 +354,16 @@ impl CrystalFamily {
}
}
}

impl ToString for CrystalFamily {
fn to_string(&self) -> String {
match self {
CrystalFamily::Triclinic => "Triclinic".to_string(),
CrystalFamily::Monoclinic => "Monoclinic".to_string(),
CrystalFamily::Orthorhombic => "Orthorhombic".to_string(),
CrystalFamily::Tetragonal => "Tetragonal".to_string(),
CrystalFamily::Hexagonal => "Hexagonal".to_string(),
CrystalFamily::Cubic => "Cubic".to_string(),
}
}
}
5 changes: 3 additions & 2 deletions moyo/src/identify/space_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ impl SpaceGroup {
fn correction_transformation_matrices(
arithmetic_number: ArithmeticNumber,
) -> Vec<UnimodularLinear> {
let geometric_crystal_class =
arithmetic_crystal_class_entry(arithmetic_number).geometric_crystal_class;
let geometric_crystal_class = arithmetic_crystal_class_entry(arithmetic_number)
.unwrap()
.geometric_crystal_class;

// conventional -> conventional(standard)
let convs = match geometric_crystal_class {
Expand Down
4 changes: 3 additions & 1 deletion moyo/src/symmetrize/standardize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ impl StandardizedCell {

// To standardized primitive cell
let arithmetic_number = entry.arithmetic_number;
let lattice_system = arithmetic_crystal_class_entry(arithmetic_number).lattice_system();
let lattice_system = arithmetic_crystal_class_entry(arithmetic_number)
.unwrap()
.lattice_system();
let prim_transformation = match lattice_system {
LatticeSystem::Triclinic => standardize_triclinic_cell(&prim_cell.lattice),
_ => space_group.transformation.clone(),
Expand Down
2 changes: 1 addition & 1 deletion moyopy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![image](https://img.shields.io/pypi/v/moyopy.svg)](https://pypi.python.org/pypi/moyopy)
[![image](https://img.shields.io/pypi/pyversions/moyopy.svg)](https://pypi.python.org/pypi/moyopy)

Python interface of [moyo](https://github.com/spglib/moyo)
Python interface of [moyo](https://github.com/spglib/moyo), a fast and robust crystal symmetry finder.

- Document: <https://spglib.github.io/moyo/python/>
- PyPI: <https://pypi.org/project/moyopy/>
Expand Down
15 changes: 4 additions & 11 deletions moyopy/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"sphinxcontrib.bibtex",
# "nbsphinx",
"myst_parser",
"autodoc2",
"autoapi.extension",
]

# Add any paths that contain templates here, relative to this directory.
Expand Down Expand Up @@ -70,17 +70,10 @@
myst_heading_anchors = 3

# -----------------------------------------------------------------------------
# autodoc2
# autoapi
# -----------------------------------------------------------------------------
autodoc2_packages = [
{
"path": "../python/moyopy/_moyopy.pyi",
"module": project,
}
]
autodoc2_render_plugin = "myst"
autodoc2_docstring_parser_regexes = [
(r".*", "rst"),
autoapi_dirs = [
"../python/moyopy",
]

# -----------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions moyopy/docs/examples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ When we need a secondary symmetry information such as Hermann-Mauguin symbol for

```{literalinclude} ../../examples/basic.py
```

## Accessing space-group type information

You can access the space-group classification information using {py:class}`moyopy.SpaceGroupType`.

```{literalinclude} ../../examples/space_group_type.py
```
Empty file removed moyopy/docs/genindex.rst
Empty file.
2 changes: 0 additions & 2 deletions moyopy/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ hidden:
---
Introduction <self>
Examples <examples/index>
API Reference <apidocs/index>
Index <genindex>
```

```{include} ../README.md
Expand Down
9 changes: 9 additions & 0 deletions moyopy/examples/space_group_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# ruff: noqa: E501
from moyopy import SpaceGroupType

s = SpaceGroupType(15) # ITA space group number (1 - 230)
assert s.hm_short == "C 2/c"
assert s.crystal_system == "Monoclinic"

print(s)
# -> PySpaceGroupType { number: 15, hm_short: "C 2/c", hm_full: "C 1 2/c 1", arithmetic_number: 8, arithmetic_symbol: "2/mC", geometric_crystal_class: "2/m", crystal_system: "Monoclinic", bravais_class: "mC", lattice_system: "Monoclinic", crystal_family: "Monoclinic" }
2 changes: 1 addition & 1 deletion moyopy/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ docs = [
"sphinx-autobuild",
"sphinxcontrib-bibtex >= 2.5",
"sphinx-book-theme",
"sphinx-autodoc2",
"sphinx-autoapi",
"myst-parser >= 2.0",
"linkify-it-py",
]
Expand Down
61 changes: 61 additions & 0 deletions moyopy/python/moyopy/_data.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,65 @@ class HallSymbolEntry:
def centering(self) -> Centering:
"""Centering."""

class SpaceGroupType:
"""Space-group type information."""
def __init__(self, number: int): ...
# Space group type
@property
def number(self) -> int:
"""ITA number for space group types (1 - 230)."""
@property
def hm_short(self) -> str:
"""Hermann-Mauguin symbol in short notation."""
@property
def hm_full(self) -> str:
"""Hermann-Mauguin symbol in full notation."""
# Arithmetic crystal class
@property
def arithmetic_number(self) -> int:
"""Number for arithmetic crystal classes (1 - 73)."""
@property
def arithmetic_symbol(self) -> str:
"""Symbol for arithmetic crystal class.

See https://github.com/spglib/moyo/blob/main/moyo/src/data/arithmetic_crystal_class.rs
for string values.
"""
# Other classifications
@property
def geometric_crystal_class(self) -> str:
"""Geometric crystal class.

See https://github.com/spglib/moyo/blob/main/moyo/src/data/classification.rs
for string values.
"""
@property
def crystal_system(self) -> str:
"""Crystal system.

See https://github.com/spglib/moyo/blob/main/moyo/src/data/classification.rs
for string values.
"""
@property
def bravais_class(self) -> str:
"""Bravais class.

See https://github.com/spglib/moyo/blob/main/moyo/src/data/classification.rs
for string values.
"""
@property
def lattice_system(self) -> str:
"""Lattice system.

See https://github.com/spglib/moyo/blob/main/moyo/src/data/classification.rs
for string values.
"""
@property
def crystal_family(self) -> str:
"""Crystal family.

See https://github.com/spglib/moyo/blob/main/moyo/src/data/classification.rs
for string values.
"""

def operations_from_number(number: int, setting: Setting) -> Operations: ...
Loading
Loading