From 892f37458b229377359ca1db0f4b3276daf1b765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jan=C3=9Fen?= Date: Wed, 17 Jul 2024 20:50:31 +0200 Subject: [PATCH 1/4] Fix equivalent atoms and add tests --- structuretoolkit/analyse/phonopy.py | 2 +- tests/test_analyse_phonopy.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/test_analyse_phonopy.py diff --git a/structuretoolkit/analyse/phonopy.py b/structuretoolkit/analyse/phonopy.py index bc587fce5..260cc0912 100644 --- a/structuretoolkit/analyse/phonopy.py +++ b/structuretoolkit/analyse/phonopy.py @@ -41,5 +41,5 @@ def get_equivalent_atoms( positions = np.reshape(np.array(positions), (natom, 3)) cell = np.reshape(np.array(cell), (3, 3)) unitcell = PhonopyAtoms(symbols=types, cell=cell, scaled_positions=positions) - ops = spg.get_symmetry(unitcell, symprec=symprec, angle_tolerance=angle_tolerance) + ops = spg.get_symmetry(cell=unitcell.totuple(), symprec=symprec, angle_tolerance=angle_tolerance) return ops["equivalent_atoms"] diff --git a/tests/test_analyse_phonopy.py b/tests/test_analyse_phonopy.py new file mode 100644 index 000000000..51a333ee9 --- /dev/null +++ b/tests/test_analyse_phonopy.py @@ -0,0 +1,11 @@ +import unittest +from ase.build import bulk +from structuretoolkit.analyse.phonopy import get_equivalent_atoms + + +class TestEquivalentAtoms(unittest.TestCase): + def test_get_equivalent_atoms(self): + equivalent_atoms = get_equivalent_atoms( + structure=bulk("Al", cubic=True), symprec=1e-5, angle_tolerance=-1.0 + ) + self.assertTrue(all(equivalent_atoms == [0, 0, 0, 0])) From 15c5e536bdbed437ac735716289f023b15b721df Mon Sep 17 00:00:00 2001 From: pyiron-runner Date: Wed, 17 Jul 2024 18:52:35 +0000 Subject: [PATCH 2/4] Format black --- structuretoolkit/analyse/phonopy.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/structuretoolkit/analyse/phonopy.py b/structuretoolkit/analyse/phonopy.py index 260cc0912..9bcccabcd 100644 --- a/structuretoolkit/analyse/phonopy.py +++ b/structuretoolkit/analyse/phonopy.py @@ -41,5 +41,7 @@ def get_equivalent_atoms( positions = np.reshape(np.array(positions), (natom, 3)) cell = np.reshape(np.array(cell), (3, 3)) unitcell = PhonopyAtoms(symbols=types, cell=cell, scaled_positions=positions) - ops = spg.get_symmetry(cell=unitcell.totuple(), symprec=symprec, angle_tolerance=angle_tolerance) + ops = spg.get_symmetry( + cell=unitcell.totuple(), symprec=symprec, angle_tolerance=angle_tolerance + ) return ops["equivalent_atoms"] From 272abe282f911c4f95cabd10fe1cd62c1b3a7436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jan=C3=9Fen?= Date: Wed, 17 Jul 2024 20:57:27 +0200 Subject: [PATCH 3/4] Skip spglib tests when spglib is not available --- tests/test_analyse_phonopy.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_analyse_phonopy.py b/tests/test_analyse_phonopy.py index 51a333ee9..744a071e7 100644 --- a/tests/test_analyse_phonopy.py +++ b/tests/test_analyse_phonopy.py @@ -3,6 +3,17 @@ from structuretoolkit.analyse.phonopy import get_equivalent_atoms +try: + import spglib + + spglib_not_available = False +except ImportError: + spglib_not_available = True + + +@unittest.skipIf( + spglib_not_available, "spglib is not installed, so the spglib tests are skipped." +) class TestEquivalentAtoms(unittest.TestCase): def test_get_equivalent_atoms(self): equivalent_atoms = get_equivalent_atoms( From 3d6d312ee2abfbbf2ce00994d642994e0f92d653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jan=C3=9Fen?= Date: Wed, 17 Jul 2024 21:05:48 +0200 Subject: [PATCH 4/4] Add another test --- tests/test_analyse_phonopy.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/test_analyse_phonopy.py b/tests/test_analyse_phonopy.py index 744a071e7..2917fa830 100644 --- a/tests/test_analyse_phonopy.py +++ b/tests/test_analyse_phonopy.py @@ -1,6 +1,8 @@ import unittest from ase.build import bulk +import numpy as np from structuretoolkit.analyse.phonopy import get_equivalent_atoms +from structuretoolkit.common.phonopy import atoms_to_phonopy, phonopy_to_atoms try: @@ -14,9 +16,16 @@ @unittest.skipIf( spglib_not_available, "spglib is not installed, so the spglib tests are skipped." ) -class TestEquivalentAtoms(unittest.TestCase): +class TestPhonopyAtoms(unittest.TestCase): def test_get_equivalent_atoms(self): equivalent_atoms = get_equivalent_atoms( structure=bulk("Al", cubic=True), symprec=1e-5, angle_tolerance=-1.0 ) self.assertTrue(all(equivalent_atoms == [0, 0, 0, 0])) + + def test_convert(self): + structure = bulk("Al", cubic=True) + structure_converted = phonopy_to_atoms(atoms_to_phonopy(structure)) + self.assertTrue(np.all(structure.symbols == structure_converted.symbols)) + self.assertTrue(np.all(structure.positions == structure_converted.positions)) + self.assertTrue(np.all(structure.cell == structure_converted.cell))