Skip to content

Commit fe4b46b

Browse files
committed
Merge branch 'spacegroup-representation'
Add `repr()` support for the SpaceGroup class (Håkon Wiik Ånes). Close #45.
2 parents 839020a + 2cf1a63 commit fe4b46b

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Release notes
22

3+
## Unreleased - Version 3.0.2
4+
5+
### Added
6+
7+
- A string representation of `SpaceGroup` with key information.
8+
9+
### Changed
10+
11+
### Deprecated
12+
13+
### Removed
14+
15+
### Fixed
16+
17+
318
## Version 3.0.1 – 2019-06-27
419

520
### Added

src/diffpy/structure/spacegroupmod.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,19 @@ def __init__(self,
262262
self.pdb_name = pdb_name
263263
self.symop_list = symop_list
264264

265+
def __repr__(self):
266+
"""Return a string representation of the space group."""
267+
return (
268+
"SpaceGroup #%i (%s, %s). Symmetry matrices: %i, "
269+
"point sym. matr.: %i"
270+
) % (
271+
self.number,
272+
self.short_name,
273+
self.crystal_system[0] + self.crystal_system[1:].lower(),
274+
self.num_sym_equiv,
275+
self.num_primitive_sym_equiv,
276+
)
277+
265278

266279
def iter_symops(self):
267280
"""Iterate over all symmetry operations in the space group.

src/diffpy/structure/tests/testspacegroups.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,44 @@ def test__hashSymOpList(self):
8686
self.assertEqual(len(SpaceGroupList), len(hset))
8787
return
8888

89+
def test_spacegroup_representation(self):
90+
"""Verify SpaceGroup.__repr__()."""
91+
self.assertEqual(
92+
repr(GetSpaceGroup(1)),
93+
"SpaceGroup #1 (P1, Triclinic). Symmetry matrices: 1, point sym. matr.: 1"
94+
)
95+
self.assertEqual(
96+
repr(GetSpaceGroup(3)),
97+
"SpaceGroup #3 (P2, Monoclinic). Symmetry matrices: 2, point sym. matr.: 2"
98+
)
99+
self.assertEqual(
100+
repr(GetSpaceGroup(16)),
101+
(
102+
"SpaceGroup #16 (P222, Orthorhombic). Symmetry matrices: 4, point sym. "
103+
"matr.: 4"
104+
)
105+
)
106+
self.assertEqual(
107+
repr(GetSpaceGroup(75)),
108+
"SpaceGroup #75 (P4, Tetragonal). Symmetry matrices: 4, point sym. matr.: 4"
109+
)
110+
self.assertEqual(
111+
repr(GetSpaceGroup(143)),
112+
"SpaceGroup #143 (P3, Trigonal). Symmetry matrices: 3, point sym. matr.: 3"
113+
)
114+
self.assertEqual(
115+
repr(GetSpaceGroup(168)),
116+
"SpaceGroup #168 (P6, Hexagonal). Symmetry matrices: 6, point sym. matr.: 6"
117+
)
118+
self.assertEqual(
119+
repr(GetSpaceGroup(229)),
120+
(
121+
"SpaceGroup #229 (Im-3m, Cubic). Symmetry matrices: 96, point sym. "
122+
"matr.: 48"
123+
)
124+
)
125+
return
126+
89127
# End of class TestRoutines
90128

91129
# ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)