Skip to content

Commit 0a25eb8

Browse files
committed
Merge branch 'cif-handle-unknown-spacegroup'
Resolve #21 on master.
2 parents 90be636 + 74a5ff3 commit 0a25eb8

File tree

5 files changed

+91
-0
lines changed

5 files changed

+91
-0
lines changed

src/diffpy/Structure/Parsers/P_cif.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,9 @@ def _parse_space_group_symop_operation_xyz(self, block):
479479
short_name=new_short_name,
480480
crystal_system=new_crystal_system,
481481
symop_list=symop_list)
482+
if self.spacegroup is None:
483+
emsg = "CIF file has unknown space group identifier {!r}."
484+
raise StructureFormatError(emsg.format(sgid))
482485
self._expandAsymmetricUnit()
483486
return
484487

src/diffpy/Structure/SpaceGroups.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,30 @@ def _buildSGLookupTable():
8484
_sg_lookup_table.setdefault(sg.short_name, sg)
8585
_sg_lookup_table.setdefault(sg.pdb_name, sg)
8686
_sg_lookup_table.setdefault(sg.alt_name, sg)
87+
# extra aliases obtained from matching code in
88+
# cctbx::sgtbx::symbols::find_main_symbol_dict_entry
89+
alias_hmname = [
90+
('Pm3', 'P m -3'),
91+
('Pn3', 'P n -3'),
92+
('Fm3', 'F m -3'),
93+
('Fd3', 'F d -3'),
94+
('Im3', 'I m -3'),
95+
('Pa3', 'P a -3'),
96+
('Ia3', 'I a -3'),
97+
('Pm3m', 'P m -3 m'),
98+
('Pn3n', 'P n -3 n'),
99+
('Pm3n', 'P m -3 n'),
100+
('Pn3m', 'P n -3 m'),
101+
('Fm3m', 'F m -3 m'),
102+
('Fm3c', 'F m -3 c'),
103+
('Fd3m', 'F d -3 m'),
104+
('Fd3c', 'F d -3 c'),
105+
('Im3m', 'I m -3 m'),
106+
('Ia3d', 'I a -3 d'),
107+
]
108+
for a, hm in alias_hmname:
109+
hmbare = hm.replace(' ', '')
110+
_sg_lookup_table.setdefault(a, _sg_lookup_table[hmbare])
87111
# make sure None does not sneak into the dictionary
88112
if None in _sg_lookup_table:
89113
del _sg_lookup_table[None]

src/diffpy/Structure/tests/TestP_cif.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,14 @@ def test_nosites_cif(self):
249249
self.assertEqual(10.413, stru.lattice.c)
250250
return
251251

252+
def test_badspacegroup_cif(self):
253+
"""Test reading of CIF file with unrecognized space group.
254+
"""
255+
ptest = self.ptest
256+
filename = datafile('badspacegroup.cif')
257+
self.assertRaises(StructureFormatError, ptest.parseFile, filename)
258+
return
259+
252260
def test_getParser(self):
253261
"""Test passing of eps keyword argument by getParser function.
254262
"""

src/diffpy/Structure/tests/TestSymmetryUtilities.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ def test_isSpaceGroupLatPar(self):
6161
self.assertTrue(isSpaceGroupLatPar(cubic, 3, 3, 3, 90, 90, 90))
6262
return
6363

64+
def test_sgtbx_spacegroup_aliases(self):
65+
"""check GetSpaceGroup for non-standard aliases from sgtbx.
66+
"""
67+
self.assertIs(GetSpaceGroup('Fm3m'), GetSpaceGroup(225))
68+
self.assertIs(GetSpaceGroup('Ia3d'), GetSpaceGroup('I a -3 d'))
69+
return
70+
6471
def test_expandPosition(self):
6572
"""check expandPosition()
6673
"""
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#------------------------------------------------------------------------------
2+
#$Date: 2015-01-27 21:58:39 +0200 (Tue, 27 Jan 2015) $
3+
#$Revision: 130149 $
4+
#$URL: svn://www.crystallography.net/cod/cif/1/10/01/1100106.cif $
5+
#------------------------------------------------------------------------------
6+
#
7+
# This file is available in the Crystallography Open Database (COD),
8+
# http://www.crystallography.net/
9+
#
10+
# All data on this site have been placed in the public domain by the
11+
# contributors.
12+
#
13+
data_1100106
14+
_publ_section_title 'Clay Montmorillonite'
15+
_chemical_name_common Montmorillonite
16+
_symmetry_cell_setting monoclinic
17+
_symmetry_space_group_name_H-M C2:b1
18+
_audit_update_record 'Last update Thu Dec 18 14:12:16 CET 2003'
19+
_cell_angle_alpha 90
20+
_cell_angle_beta 100.3(1)
21+
_cell_angle_gamma 90
22+
_cell_formula_units_Z 1
23+
_cell_length_a 5.411(4)
24+
_cell_length_b 9.0(5)
25+
_cell_length_c 10.25(2)
26+
_refine_ls_goodness_of_fit_all 1.1109964
27+
_refine_ls_R_factor_all 0.04240644
28+
_refine_ls_wR_factor_all 0.06303699
29+
_cod_database_code 1100106
30+
loop_
31+
_atom_site_label
32+
_atom_site_type_symbol
33+
_atom_site_occupancy
34+
_atom_site_fract_x
35+
_atom_site_fract_y
36+
_atom_site_fract_z
37+
_atom_site_B_iso_or_equiv
38+
Al1 Al3+ 1.00000 0 0 0 0.5
39+
Al2 Al3+ 1.00000 0 0.321 0 0.5
40+
Mg1 Mg2+ 1.00000 0 0.654 0 0.5
41+
Si1 Si4+ 1.00000 0.432 0.333 0.27 0.5
42+
Si2 Si4+ 1.00000 0.432 0.662 0.27 0.5
43+
K1 K1+ 1.00000 0.5 0 0.5 0.5
44+
O1 O2- 1.00000 0.489 0.496 0.335 0.8
45+
O2 O2- 1.00000 0.173 0.725 0.335 0.8
46+
O3 O2- 1.00000 0.17 0.268 0.32 0.8
47+
O4 O2- 1.00000 0.334 -0.024 0.105 0.8
48+
O5 O2- 1.00000 0.417 0.656 0.109 0.8
49+
O6 O2- 1.00000 0.343 0.347 0.109 0.8

0 commit comments

Comments
 (0)