Skip to content
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

Add method to get the Pearson symbol to SpaceGroupAnalyzer #4281

Merged
merged 8 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from 6 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
23 changes: 23 additions & 0 deletions src/pymatgen/symmetry/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,29 @@ def get_lattice_type(self) -> LatticeType:
return "rhombohedral"
return "hexagonal" if system == "trigonal" else system

def get_pearson_symbol(self) -> str:
"""Get the Pearson symbol for the structure.

Returns:
str: Pearson symbol for structure.
"""
cry_sys = self.get_crystal_system()
spg_sym = self.get_space_group_symbol()
centering = "C" if spg_sym[0] in ("A", "B", "C", "S") else spg_sym[0]

CRYSTAL_FAMILY_SYMBOLS = {
"triclinic": "a",
"monoclinic": "m",
"orthorhombic": "o",
"tetragonal": "t",
"trigonal": "h",
"hexagonal": "h",
"cubic": "c",
}

num_sites_conventional = len(self._space_group_data["std_types"])
return f"{CRYSTAL_FAMILY_SYMBOLS[cry_sys]}{centering}{num_sites_conventional}"

def get_symmetry_dataset(self) -> SpglibDataset:
"""Get the symmetry dataset as a SpglibDataset.

Expand Down
22 changes: 16 additions & 6 deletions tests/symmetry/test_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,25 @@

class TestSpacegroupAnalyzer(PymatgenTest):
def setUp(self):
# FePO4
self.structure = Structure.from_file(f"{VASP_IN_DIR}/POSCAR")
self.sg = SpacegroupAnalyzer(self.structure, 0.001)

# Li10GeP2S12
self.disordered_structure = self.get_structure("Li10GeP2S12")
self.disordered_sg = SpacegroupAnalyzer(self.disordered_structure, 0.001)

# FePO4 with order of sites changed so the atoms aren't grouped by element.
struct = self.structure.copy()
site = struct[0]
del struct[0]
struct.append(site.species, site.frac_coords)
self.sg3 = SpacegroupAnalyzer(struct, 0.001)
graphite = self.get_structure("Graphite")
graphite.add_site_property("magmom", [0.1] * len(graphite))
self.sg4 = SpacegroupAnalyzer(graphite, 0.001)
self.structure4 = graphite

# Graphite
self.structure4 = self.get_structure("Graphite")
self.structure4.add_site_property("magmom", [0.1] * len(self.structure4))
self.sg4 = SpacegroupAnalyzer(self.structure4, 0.001)

def test_primitive(self):
struct = Structure.from_spacegroup("Fm-3m", np.eye(3) * 3, ["Cu"], [[0, 0, 0]])
Expand All @@ -49,9 +55,7 @@ def test_primitive(self):
def test_is_laue(self):
struct = Structure.from_spacegroup("Fm-3m", np.eye(3) * 3, ["Cu"], [[0, 0, 0]])
assert SpacegroupAnalyzer(struct).is_laue()

assert self.sg.is_laue()

assert self.disordered_sg.is_laue()

def test_magnetic(self):
Expand Down Expand Up @@ -86,6 +90,12 @@ def test_get_pointgroup(self):
assert self.sg.get_point_group_symbol() == "mmm"
assert self.disordered_sg.get_point_group_symbol() == "4/mmm"

def test_get_pearson_symbol(self):
assert self.sg.get_pearson_symbol() == "oP24"
assert self.disordered_sg.get_pearson_symbol() == "tP58"
assert self.sg3.get_pearson_symbol() == "oP24"
assert self.sg4.get_pearson_symbol() == "hP4"

def test_get_point_group_operations(self):
sg: SpacegroupAnalyzer
rng = np.random.default_rng()
Expand Down