Skip to content

Commit 092cd63

Browse files
Extend unit tests for get_primitive_cell() (#485)
* Extend unit tests for get_primitive_cell() Added test cases to cover: - Periodic boundary condition validation: ensuring ValueError is raised if structure is not periodic. - Custom arrays warning: ensuring a warning is logged when custom arrays are present in the source structure. Co-authored-by: jan-janssen <3854739+jan-janssen@users.noreply.github.com> * fixes * another fix --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: jan-janssen <3854739+jan-janssen@users.noreply.github.com>
1 parent 012dadd commit 092cd63

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

tests/test_analyse_symmetry.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Distributed under the terms of "New BSD License", see the LICENSE file.
44

55
import unittest
6+
import warnings
67

78
import numpy as np
89
from ase.atoms import Atoms
@@ -425,6 +426,28 @@ def test_arg_equivalent_vectors(self):
425426
dx_round = np.round(np.absolute(dx), decimals=3)
426427
self.assertEqual(len(np.unique(dx_round + arg_v)), len(np.unique(arg_v)))
427428

429+
def test_get_primitive_cell_pbc_error(self):
430+
structure = bulk("Al", cubic=True)
431+
structure.pbc = [True, True, False]
432+
sym = stk.analyse.get_symmetry(structure=structure)
433+
with self.assertRaisesRegex(ValueError, "Can only symmetrize periodic structures."):
434+
sym.get_primitive_cell()
435+
436+
def test_get_primitive_cell_arrays_warning(self):
437+
structure = bulk("Al", cubic=True)
438+
structure.set_array("test_array", np.zeros(len(structure)))
439+
sym = stk.analyse.get_symmetry(structure=structure)
440+
with warnings.catch_warnings(record=True) as w:
441+
warnings.simplefilter("always")
442+
sym.get_primitive_cell()
443+
self.assertTrue(
444+
any(
445+
"Custom arrays {'test_array'} do not carry over to new structure!"
446+
in str(warning.message)
447+
for warning in w
448+
)
449+
)
450+
428451
def test_error(self):
429452
"""spglib errors should be wrapped in a SymmetryError."""
430453

0 commit comments

Comments
 (0)