Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,9 @@ nosetests.xml
# version information
setup.cfg
/src/diffpy/*/version.cfg

# PyCharm
.idea

# Coverage report
htmlcov
13 changes: 13 additions & 0 deletions src/diffpy/structure/spacegroupmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,19 @@ def __init__(self,
self.pdb_name = pdb_name
self.symop_list = symop_list

def __repr__(self):
"""Return a string representation of the space group."""
return (
"SpaceGroup #%i (%s, %s). Symmetry matrices: %i, "
"point sym. matr.: %i"
) % (
self.number,
self.short_name,
self.crystal_system[0] + self.crystal_system[1:].lower(),
self.num_sym_equiv,
self.num_primitive_sym_equiv,
)


def iter_symops(self):
"""Iterate over all symmetry operations in the space group.
Expand Down
29 changes: 29 additions & 0 deletions src/diffpy/structure/tests/testspacegroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,35 @@ def test__hashSymOpList(self):
self.assertEqual(len(SpaceGroupList), len(hset))
return

def test_spacegroup_representation(self):
"""Verify SpaceGroup.__repr__()."""
numbers = [1, 3, 16, 75, 143, 168, 229]
short_names = ["P1", "P2", "P222", "P4", "P3", "P6", "Im-3m"]
systems = [
"Triclinic",
"Monoclinic",
"Orthorhombic",
"Tetragonal",
"Trigonal",
"Hexagonal",
"Cubic",
]
n_symmetry_matrices = [1, 2, 4, 4, 3, 6, 96]
n_point_symmetry_matrices = [1, 2, 4, 4, 3, 6, 48]
sg_dict = dict(zip(
numbers,
zip(short_names, systems, n_symmetry_matrices, n_point_symmetry_matrices)
))
for key, value in sg_dict.items():
sg = GetSpaceGroup(key)
expected_str = (
"SpaceGroup #%i (%s, %s). Symmetry matrices: %i, "
"point sym. matr.: %i"
) % ((key,) + value)

self.assertEqual(sg.__repr__(), expected_str)


# End of class TestRoutines

# ----------------------------------------------------------------------------
Expand Down