def test_old_alt_name(self): "check GetSpaceGroup lookup from deprecated alt_name values" # alt_name values which do not map to short_name or pdb_name altnames_sgnos = (("P M 3", 200), ("P N 3", 201), ("F M 3", 202), ("F D 3", 203), ("I M 3", 204), ("P A 3", 205), ("I A 3", 206), ("P M 3 M", 221), ("P N 3 N", 222), ("P M 3 N", 223), ("P N 3 M", 224), ("F M 3 M", 225), ("F M 3 C", 226), ("F D 3 M", 227), ("F D 3 C", 228), ("I M 3 M", 229), ("I A 3 D", 230)) for name, sgno in altnames_sgnos: self.assertIs(GetSpaceGroup(sgno), GetSpaceGroup(name)) return
def test_UparSymbols(self): """check SymmetryConstraints.UparSymbols() """ sg1 = GetSpaceGroup(1) sg225 = GetSpaceGroup(225) pos = [[0, 0, 0]] Uijs = numpy.zeros((1, 3, 3)) sc1 = SymmetryConstraints(sg1, pos, Uijs) self.assertEqual(6, len(sc1.UparSymbols())) sc225 = SymmetryConstraints(sg225, pos, Uijs) self.assertEqual(['U110'], sc225.UparSymbols()) return
def test_UparValues(self): """check SymmetryConstraints.UparValues() """ places = 12 sg1 = GetSpaceGroup(1) sg225 = GetSpaceGroup(225) pos = [[0, 0, 0]] Uijs = [[[0.1, 0.4, 0.5], [0.4, 0.2, 0.6], [0.5, 0.6, 0.3]]] sc1 = SymmetryConstraints(sg1, pos, Uijs) duv = 0.1 * numpy.arange(1, 7) - sc1.UparValues() self.assertAlmostEqual(0, max(numpy.fabs(duv)), places) sc225 = SymmetryConstraints(sg225, pos, Uijs) self.assertEqual(1, len(sc225.UparValues())) self.assertAlmostEqual(0.2, sc225.UparValues()[0], places) return
def test_FindSpaceGroup(self): "check FindSpaceGroup function" sg123 = GetSpaceGroup(123) ops123 = list(sg123.iter_symops()) self.assertRaises(ValueError, FindSpaceGroup, []) self.assertRaises(ValueError, FindSpaceGroup, 2 * ops123) self.assertIs(sg123, FindSpaceGroup(ops123)) sg123r = FindSpaceGroup(ops123[::-1]) self.assertIsNot(sg123, sg123r) self.assertIsNot(sg123.symop_list, sg123r.symop_list) self.assertEqual(ops123[::-1], sg123r.symop_list) self.assertEqual(_hashSymOpList(sg123.symop_list), _hashSymOpList(sg123r.symop_list)) self.assertIs(sg123, FindSpaceGroup(ops123[::-1], shuffle=True)) return
def get_point_group(space_group_number, proper=False): """Maps a space group number to its (proper) point group. Parameters ---------- space_group_number : int Between 1 and 231. proper : bool, optional Whether to return the point group with proper rotations only (True), or just the point group (False). Default is False. Returns ------- point_group : orix.quaternion.symmetry.Symmetry One of the 11 proper or 32 point groups. Examples -------- >>> from orix.quaternion.symmetry import get_point_group >>> pgOh = get_point_group(225) >>> pgOh.name 'm-3m' >>> pgO = get_point_group(225, proper=True) >>> pgO.name '432' """ spg = GetSpaceGroup(space_group_number) pgn = spg.point_group_name if proper: return spacegroup2pointgroup_dict[pgn]["proper"] else: return spacegroup2pointgroup_dict[pgn]["improper"]
def _parse_space_group_symop_operation_xyz(self, block): """Process symmetry operations from a CifBlock. The method updates spacegroup and eau data according to symmetry operations defined in _space_group_symop_operation_xyz or _symmetry_equiv_pos_as_xyz items in CifBlock. block -- instance of CifBlock No return value. """ from diffpy.structure.spacegroups import IsSpaceGroupIdentifier from diffpy.structure.spacegroups import SpaceGroup, GetSpaceGroup from diffpy.structure.spacegroups import FindSpaceGroup self.asymmetric_unit = list(self.stru) sym_synonyms = ('_space_group_symop_operation_xyz', '_symmetry_equiv_pos_as_xyz') sym_loop_name = [n for n in sym_synonyms if n in block] # recover explicit list of symmetry operations symop_list = [] if sym_loop_name: # sym_loop exists here and we know its cif name sym_loop_name = sym_loop_name[0] sym_loop = block.GetLoop(sym_loop_name) for eqxyz in sym_loop[sym_loop_name]: opcif = getSymOp(eqxyz) symop_list.append(opcif) # determine space group number sg_nameHall = (block.get('_space_group_name_Hall', '') or block.get('_symmetry_space_group_name_Hall', '')) sg_nameHM = (block.get('_space_group_name_H-M_alt', '') or block.get('_symmetry_space_group_name_H-M', '')) self.cif_sgname = (sg_nameHall or sg_nameHM or None) sgid = (block.get('_space_group_IT_number', '') or block.get('_symmetry_Int_Tables_number', '') or sg_nameHM) self.spacegroup = None # try to reuse existing space group from symmetry operations if symop_list: try: self.spacegroup = FindSpaceGroup(symop_list) except ValueError: pass # otherwise lookup the space group from its identifier if self.spacegroup is None and sgid and IsSpaceGroupIdentifier(sgid): self.spacegroup = GetSpaceGroup(sgid) # define new spacegroup when symmetry operations were listed, but # there is no match to an existing definition if symop_list and self.spacegroup is None: new_short_name = "CIF " + (sg_nameHall or 'data') new_crystal_system = (block.get('_space_group_crystal_system') or block.get('_symmetry_cell_setting') or 'TRICLINIC').upper() self.spacegroup = SpaceGroup(short_name=new_short_name, crystal_system=new_crystal_system, symop_list=symop_list) if self.spacegroup is None: emsg = "CIF file has unknown space group identifier {!r}." raise StructureFormatError(emsg.format(sgid)) self._expandAsymmetricUnit(block) return
def test_spacegroup_representation(self): """Verify SpaceGroup.__repr__().""" self.assertEqual( repr(GetSpaceGroup(1)), "SpaceGroup #1 (P1, Triclinic). Symmetry matrices: 1, point sym. matr.: 1" ) self.assertEqual( repr(GetSpaceGroup(3)), "SpaceGroup #3 (P2, Monoclinic). Symmetry matrices: 2, point sym. matr.: 2" ) self.assertEqual(repr(GetSpaceGroup(16)), ( "SpaceGroup #16 (P222, Orthorhombic). Symmetry matrices: 4, point sym. " "matr.: 4")) self.assertEqual( repr(GetSpaceGroup(75)), "SpaceGroup #75 (P4, Tetragonal). Symmetry matrices: 4, point sym. matr.: 4" ) self.assertEqual( repr(GetSpaceGroup(143)), "SpaceGroup #143 (P3, Trigonal). Symmetry matrices: 3, point sym. matr.: 3" ) self.assertEqual( repr(GetSpaceGroup(168)), "SpaceGroup #168 (P6, Hexagonal). Symmetry matrices: 6, point sym. matr.: 6" ) self.assertEqual(repr(GetSpaceGroup(229)), ( "SpaceGroup #229 (Im-3m, Cubic). Symmetry matrices: 96, point sym. " "matr.: 48")) return
def space_group(self, value): """Set space group of phase.""" if isinstance(value, int): value = GetSpaceGroup(value) if not isinstance(value, SpaceGroup) and value is not None: raise ValueError( f"'{value}' must be of type {SpaceGroup}, an integer 1-230, or None." ) self._space_group = value # Overwrites any point group set before
def test_add_list_phases_to_phaselist(self): """Add a list of Phase objects to PhaseList, also ensuring that unique colors are given. """ names = ["a", "b"] sg_no = [10, 20] colors = ["tab:blue", "tab:orange"] pl = PhaseList(names=names, space_groups=sg_no) assert pl.colors == colors new_names = ["c", "d"] new_sg_no = [30, 40] pl.add([Phase(name=n, space_group=i) for n, i in zip(new_names, new_sg_no)]) assert pl.names == names + new_names assert pl.space_groups == ( [GetSpaceGroup(i) for i in sg_no] + [GetSpaceGroup(i) for i in new_sg_no] ) assert pl.colors == colors + ["tab:green", "tab:red"]
def test_add_phaselist_to_phaselist(self): """Add a PhaseList to a PhaseList, also ensuring that new IDs are given. """ names = ["a", "b"] sg_no = [10, 20] pl1 = PhaseList(names=names, space_groups=sg_no) assert pl1.ids == [0, 1] names2 = ["c", "d"] sg_no2 = [30, 40] ids = [4, 5] pl2 = PhaseList(names=names2, space_groups=sg_no2, ids=ids) pl1.add(pl2) assert pl1.names == names + names2 assert pl1.space_groups == ([GetSpaceGroup(i) for i in sg_no] + [GetSpaceGroup(i) for i in sg_no2]) assert pl1.ids == [0, 1, 2, 3]
def test_Uisotropy(self): """check isotropy value for ADP-s at specified sites. """ sg225 = GetSpaceGroup(225) corepos = [[0, 0, 0], [0.1, 0.13, 0.17]] eau = ExpandAsymmetricUnit(sg225, corepos) self.assertEqual([True, False], eau.Uisotropy) sc = SymmetryConstraints(sg225, eau.expandedpos) self.assertEqual(4 * [True] + 192 * [False], sc.Uisotropy) return
def test_add_phase_in_empty_phaselist(self): """Add Phase to empty PhaseList.""" sg_no = 10 name = "a" pl = PhaseList() pl.add(Phase(name, space_group=sg_no)) assert pl.ids == [0] assert pl.names == [name] assert pl.space_groups == [GetSpaceGroup(sg_no)] assert pl.structures == [Structure()]
def test_positionFormula_sg209(self): "check positionFormula at [x, 1-x, -x] site of the F432 space group." sg209 = GetSpaceGroup('F 4 3 2') xyz = [0.05198, 0.94802, -0.05198] g209e = GeneratorSite(sg209, xyz) pfm = g209e.positionFormula(xyz) self.assertEqual('x', pfm['x']) self.assertEqual('-x+1', pfm['y'].replace(' ', '')) self.assertEqual('-x+1', pfm['z'].replace(' ', '')) return
def test_get_point_group(): """Makes sure all the ints from 1 to 230 give answers.""" for sg_number in np.arange(1, 231): proper_pg = get_point_group(sg_number, proper=True) assert proper_pg in [C1, C2, C3, C4, C6, D2, D3, D4, D6, O, T] sg = GetSpaceGroup(sg_number) pg = get_point_group(sg_number, proper=False) assert proper_pg == spacegroup2pointgroup_dict[sg.point_group_name]["proper"] assert pg == spacegroup2pointgroup_dict[sg.point_group_name]["improper"]
def test_expandPosition(self): """check expandPosition() """ # ok again Ni example fcc = GetSpaceGroup(225) pos,pops,pmult = expandPosition(fcc, [0,0,0]) self.assertTrue(numpy.all(pos[0] == 0.0)) self.assertEqual(4, len(pos)) self.assertEqual(192, sum([len(l) for l in pops])) self.assertEqual(4, pmult) return
def test_phase2dict_spacegroup(self): """Space group is written to dict as an int or "None".""" sg100 = 100 phase = Phase(space_group=sg100) phase_dict1 = phase2dict(phase) assert phase_dict1["space_group"] == sg100 sg200 = GetSpaceGroup(200) phase.space_group = sg200 phase_dict2 = phase2dict(phase) assert phase_dict2["space_group"] == sg200.number phase.space_group = None phase_dict3 = phase2dict(phase) assert phase_dict3["space_group"] == "None"
def setUp(self): x, y, z = 0.07, 0.11, 0.13 self.x, self.y, self.z = x, y, z if TestGeneratorSite.generators: self.__dict__.update(TestGeneratorSite.generators) return sg117 = GetSpaceGroup(117) sg143 = GetSpaceGroup(143) sg164 = GetSpaceGroup(164) sg167h = GetSpaceGroup('H-3c') sg167r = GetSpaceGroup('R-3c') sg186 = GetSpaceGroup(186) sg227 = GetSpaceGroup(227) g117c = GeneratorSite(sg117, [0, 0.5, 0]) g117h = GeneratorSite(sg117, [x, x + 0.5, 0.5]) g143a = GeneratorSite(sg143, [0, 0, z]) g143b = GeneratorSite(sg143, [1. / 3, 2. / 3, z]) g143c = GeneratorSite(sg143, [2. / 3, 1. / 3, z]) g143d = GeneratorSite(sg143, [x, y, z]) g164e = GeneratorSite(sg164, (0.5, 0, 0)) g164f = GeneratorSite(sg164, (0.5, 0, 0.5)) g164g = GeneratorSite(sg164, (x, 0, 0)) g164h = GeneratorSite(sg164, (x, 0, 0.5)) gh167e = GeneratorSite(sg167h, (0.30624, 0.0, 0.25)) gr167e = GeneratorSite(sg167r, (0.1, 0.4, 0.25)) g186c = GeneratorSite(sg186, (0.1695, 1.0 - 0.1695, 0.6365)) g227a = GeneratorSite(sg227, [0, 0, 0]) g227c = GeneratorSite(sg227, 3 * [1. / 8]) g227oa = GeneratorSite(sg227, 3 * [1. / 8], sgoffset=3 * [1. / 8]) g227oc = GeneratorSite(sg227, [0, 0, 0], sgoffset=3 * [1. / 8]) TestGeneratorSite.generators = { 'g117c': g117c, 'g117h': g117h, 'g143a': g143a, 'g143b': g143b, 'g143c': g143c, 'g143d': g143d, 'g164e': g164e, 'g164f': g164f, 'g164g': g164g, 'g164h': g164h, 'gh167e': gh167e, 'gr167e': gr167e, 'g186c': g186c, 'g227a': g227a, 'g227c': g227c, 'g227oa': g227oa, 'g227oc': g227oc } self.__dict__.update(TestGeneratorSite.generators) return
def test_corepos(self): """test_corepos - find positions in the asymmetric unit. """ sg225 = GetSpaceGroup(225) corepos = [[0, 0, 0], [0.1, 0.13, 0.17]] eau = ExpandAsymmetricUnit(sg225, corepos) sc = SymmetryConstraints(sg225, eau.expandedpos) self.assertEqual(2, len(sc.corepos)) self.assertTrue(numpy.all(corepos[0] == sc.corepos[0])) self.assertTrue(numpy.all(corepos[1] == sc.corepos[1])) self.assertEqual(2, len(sc.coremap)) mapped_count = sum(len(idcs) for idcs in sc.coremap.values()) self.assertEqual(len(sc.positions), mapped_count) self.assertTrue(sc.coremap[0] == list(range(4))) self.assertTrue(sc.coremap[4] == list(range(4, 4+192))) return
def test__findUParameters(self): """check GeneratorSite._findUParameters() """ # by default all Uparameters equal zero, this would fail for NaNs for gen in TestGeneratorSite.generators.values(): for usym, uval in gen.Uparameters: self.assertEqual(0.0, uval) # special test for g117h Uij = numpy.array([[1, 3, 4], [3, 1, -4], [4, -4, 2]]) sg117 = GetSpaceGroup(117) g117h = GeneratorSite(sg117, self.g117h.xyz, Uij) upd = dict(g117h.Uparameters) self.assertEqual(1, upd['U11']) self.assertEqual(2, upd['U33']) self.assertEqual(3, upd['U12']) self.assertEqual(4, upd['U13']) return
def test_unknown_spacegroup_number(self): "test CIF file with unknown space group symbol" from diffpy.structure.spacegroups import GetSpaceGroup, _hashSymOpList with open(self.pbteciffile) as fp: lines = fp.readlines() self.assertTrue(lines[16].startswith('_symmetry_space_group')) self.assertTrue(lines[17].startswith('_symmetry_space_group')) lines[16:18] = [ '_space_group_IT_number ?\n', '_symmetry_space_group_name_H-M ?\n', '_symmetry_space_group_name_Hall ?\n', ] ciftxt = ''.join(lines) stru = self.ptest.parse(ciftxt) self.assertEqual(8, len(stru)) h225 = _hashSymOpList(GetSpaceGroup(225).iter_symops()) sgcif = self.ptest.spacegroup self.assertEqual(h225, _hashSymOpList(sgcif.iter_symops())) return
def test_GetSpaceGroup(self): "check GetSpaceGroup function" from diffpy.structure.spacegroups import sg125 self.assertRaises(ValueError, GetSpaceGroup, 0) self.assertRaises(ValueError, GetSpaceGroup, 300) self.assertRaises(ValueError, GetSpaceGroup, "300") self.assertIs(sg125, GetSpaceGroup(125)) self.assertIs(sg125, GetSpaceGroup("125")) self.assertIs(sg125, GetSpaceGroup("P4/nbm")) self.assertIs(sg125, GetSpaceGroup("P 4/n 2/b 2/m")) # old alt_name self.assertIs(sg125, GetSpaceGroup("P 4/N B M")) # upper case pdb_name self.assertIs(sg125, GetSpaceGroup("P 4/N 2/B 2/M")) return
def test_UFormula_g186c_eqxyz(self): '''Check rotated U formulas at the symmetry positions of c-site in 186. ''' sg186 = GetSpaceGroup(186) crules = [ {'U11': 'A', 'U22': 'A', 'U33': 'C', 'U12': 'D', 'U13': 'E', 'U23': '-E'}, {'U11': 'A', 'U22': '2*A-2*D', 'U33': 'C', 'U12': 'A-D', 'U13': 'E', 'U23': '2*E'}, {'U11': '2*A-2*D', 'U22': 'A', 'U33': 'C', 'U12': 'A-D', 'U13': '-2*E', 'U23': '-E'}, {'U11': 'A', 'U22': 'A', 'U33': 'C', 'U12': 'D', 'U13': '-E', 'U23': 'E'}, {'U11': 'A', 'U22': '2*A-2*D', 'U33': 'C', 'U12': 'A-D', 'U13': '-E', 'U23': '-2*E'}, {'U11': '2*A-2*D', 'U22': 'A', 'U33': 'C', 'U12': 'A-D', 'U13': '2*E', 'U23': 'E'}, ] self.assertEqual(6, len(self.g186c.eqxyz)) gc = self.g186c for idx in range(6): self.assertEqual(crules[idx], gc.UFormula(gc.eqxyz[idx], 'ABCDEF')) uiso = numpy.array([[2, 1, 0], [1, 2, 0], [0, 0, 2]]) eau = ExpandAsymmetricUnit(sg186, [gc.xyz], [uiso]) for u in eau.expandedUijs: du = numpy.linalg.norm((uiso - u).flatten()) self.assertAlmostEqual(0.0, du, 8) symcon = SymmetryConstraints(sg186, sum(eau.expandedpos, []), sum(eau.expandedUijs, [])) upd = dict(symcon.Upars) self.assertEqual(2.0, upd['U110']) self.assertEqual(2.0, upd['U330']) self.assertEqual(1.0, upd['U120']) self.assertEqual(0.0, upd['U130']) uisod = {'U11' : 2.0, 'U22' : 2.0, 'U33' : 2.0, 'U12' : 1.0, 'U13' : 0.0, 'U23' : 0.0} for ufms in symcon.UFormulas(): for n, fm in ufms.items(): self.assertEqual(uisod[n], eval(fm, upd)) return
def test___init__(self): """check SymmetryConstraints.__init__() """ sg225 = GetSpaceGroup(225) # initialize from nested lists and arrays from ExpandAsymmetricUnit eau = ExpandAsymmetricUnit(sg225, [[0, 0, 0]]) sc0 = SymmetryConstraints(sg225, eau.expandedpos) self.assertEqual(1, len(sc0.coremap)) # initialize from list of arrays of coordinates poslistarrays = [xyz for xyz in sc0.positions] sc1 = SymmetryConstraints(sg225, poslistarrays) self.assertEqual(1, len(sc1.coremap)) # initialize from list of lists of coordinates poslistlist = [list(xyz) for xyz in poslistarrays] sc2 = SymmetryConstraints(sg225, poslistlist) self.assertEqual(1, len(sc2.coremap)) # initialize from nx3 array posarray = numpy.array(poslistlist) sc3 = SymmetryConstraints(sg225, posarray) self.assertEqual(1, len(sc3.coremap)) # finally initialize from a single coordinate sc4 = SymmetryConstraints(sg225, [0, 0, 0]) self.assertEqual(1, len(sc4.coremap)) return
def test_isSpaceGroupLatPar(self): """check isSpaceGroupLatPar() """ triclinic = GetSpaceGroup("P1") monoclinic = GetSpaceGroup("P2") orthorhombic = GetSpaceGroup("P222") tetragonal = GetSpaceGroup("P4") trigonal = GetSpaceGroup("P3") hexagonal = GetSpaceGroup("P6") cubic = GetSpaceGroup("P23") self.assertTrue(isSpaceGroupLatPar(triclinic, 1, 2, 3, 40, 50, 60)) self.assertFalse(isSpaceGroupLatPar(monoclinic, 1, 2, 3, 40, 50, 60)) self.assertTrue(isSpaceGroupLatPar(monoclinic, 1, 2, 3, 90, 50, 90)) self.assertFalse(isSpaceGroupLatPar(orthorhombic, 1, 2, 3, 90, 50, 90)) self.assertTrue(isSpaceGroupLatPar(orthorhombic, 1, 2, 3, 90, 90, 90)) self.assertFalse(isSpaceGroupLatPar(tetragonal, 1, 2, 3, 90, 90, 90)) self.assertTrue(isSpaceGroupLatPar(tetragonal, 2, 2, 3, 90, 90, 90)) self.assertFalse(isSpaceGroupLatPar(trigonal, 2, 2, 3, 90, 90, 90)) self.assertTrue(isSpaceGroupLatPar(trigonal, 2, 2, 2, 80, 80, 80)) self.assertFalse(isSpaceGroupLatPar(hexagonal, 2, 2, 2, 80, 80, 80)) self.assertTrue(isSpaceGroupLatPar(hexagonal, 2, 2, 3, 90, 90, 120)) self.assertFalse(isSpaceGroupLatPar(cubic, 2, 2, 3, 90, 90, 120)) self.assertTrue(isSpaceGroupLatPar(cubic, 3, 3, 3, 90, 90, 90)) return
def _parse_space_group_symop_operation_xyz(self, block): """Process symmetry operations from a CifBlock. The method updates spacegroup and eau data according to symmetry operations defined in _space_group_symop_operation_xyz or _symmetry_equiv_pos_as_xyz items in CifBlock. block -- instance of CifBlock No return value. """ from diffpy.structure.spacegroups import IsSpaceGroupIdentifier from diffpy.structure.spacegroups import SpaceGroup, GetSpaceGroup self.asymmetric_unit = list(self.stru) sym_synonyms = ('_space_group_symop_operation_xyz', '_symmetry_equiv_pos_as_xyz') sym_loop_name = [n for n in sym_synonyms if n in block] # recover explicit list of symmetry operations symop_list = [] if sym_loop_name: # sym_loop exists here and we know its cif name sym_loop_name = sym_loop_name[0] sym_loop = block.GetLoop(sym_loop_name) for eqxyz in sym_loop[sym_loop_name]: opcif = getSymOp(eqxyz) symop_list.append(opcif) # determine space group number sg_nameHall = (block.get('_space_group_name_Hall', '') or block.get('_symmetry_space_group_name_Hall', '')) sg_nameHM = (block.get('_space_group_name_H-M_alt', '') or block.get('_symmetry_space_group_name_H-M', '')) self.cif_sgname = (sg_nameHall or sg_nameHM or None) sgid = (int(block.get('_space_group_IT_number', '0')) or int(block.get('_symmetry_Int_Tables_number', '0')) or sg_nameHM) # try to reuse existing space group self.spacegroup = None if sgid and IsSpaceGroupIdentifier(sgid): sgstd = GetSpaceGroup(sgid) oprep_std = [str(op) for op in sgstd.iter_symops()] oprep_std.sort() oprep_cif = [str(op) for op in symop_list] oprep_cif.sort() # make sure symmetry operations have the same order if oprep_std == oprep_cif: self.spacegroup = copy.copy(sgstd) self.spacegroup.symop_list = symop_list # use standard definition when symmetry operations were not listed elif not symop_list: self.spacegroup = sgstd # define new spacegroup when symmetry operations were listed, but # there is no match to an existing definition if symop_list and self.spacegroup is None: new_short_name = "CIF " + (sg_nameHall or 'data') new_crystal_system = ( block.get('_space_group_crystal_system') or block.get('_symmetry_cell_setting') or 'TRICLINIC' ).upper() self.spacegroup = SpaceGroup( short_name=new_short_name, crystal_system=new_crystal_system, symop_list=symop_list) if self.spacegroup is None: emsg = "CIF file has unknown space group identifier {!r}." raise StructureFormatError(emsg.format(sgid)) self._expandAsymmetricUnit() return
def test_sgtbx_spacegroup_aliases(self): """check GetSpaceGroup for non-standard aliases from sgtbx. """ self.assertIs(GetSpaceGroup('Fm3m'), GetSpaceGroup(225)) self.assertIs(GetSpaceGroup('Ia3d'), GetSpaceGroup('I a -3 d')) return
def test_find_asymmetric_positions(positions, space_group, desired_asymmetric): assert np.allclose( find_asymmetric_positions(positions=positions, space_group=GetSpaceGroup(space_group)), desired_asymmetric, )
def constrainAsSpaceGroup(phase, spacegroup, scatterers = None, sgoffset = [0, 0, 0], constrainlat = True, constrainadps = True, adpsymbols = None, isosymbol = "Uiso"): """Constrain the structure to the space group. This applies space group constraints to a StructureParSet with P1 symmetry. Passed scatterers are explicitly constrained to the specified space group. The ADPs and lattice may be constrained as well. Arguments: phase -- A BaseStructure object. spacegroup -- The space group number, symbol or an instance of SpaceGroup class from diffpy.structure package. sgoffset -- Optional offset for sg origin (default [0, 0, 0]). scatterers -- The scatterer ParameterSets to constrain. If scatterers is None (default), then all scatterers accessible from phase.getScatterers will be constrained. constrainlat -- Flag indicating whether to constrain the lattice (default True). constrainadps -- Flag indicating whether to constrain the ADPs (default True). adpsymbols -- A list of the ADP names. By default this is equal to diffpy.structure.symmetryutilities.stdUsymbols (U11, U22, etc.). The names must be given in the same order as stdUsymbols. isosymbol -- Symbol for isotropic ADP (default "Uiso"). If None, isotropic ADPs will be constrainted via the anisotropic ADPs. New Parameters that are used in constraints are created within a SpaceGroupParameters object, which is returned from this function. Constraints are created in ParameterSet that contains the constrained Parameter. This will erase any constraints or constant flags on the scatterers, lattice or ADPs if they are to be constrained. The lattice constraints are applied as following. Crystal System: Triclinic -- No constraints. Monoclinic -- alpha and beta are fixed to 90 unless alpha != beta and alpha == gamma, in which case alpha and gamma are fixed to 90. Orthorhombic -- alpha, beta and gamma are fixed to 90. Tetragonal -- b is constrained to a and alpha, beta and gamma are fixed to 90. Trigonal -- If gamma == 120, then b is constrained to a, alpha and beta are fixed to 90 and gamma is fixed to 120. Otherwise, b and c are constrained to a, beta and gamma are fixed to alpha. Hexagonal -- b is constrained to a, alpha and beta are fixed to 90 and gamma is fixed to 120. Cubic -- b and c are constrained to a, and alpha, beta and gamma are fixed to 90. """ from diffpy.structure.spacegroups import GetSpaceGroup, SpaceGroup sg = spacegroup if not isinstance(spacegroup, SpaceGroup): sg = GetSpaceGroup(spacegroup) sgp = _constrainAsSpaceGroup(phase, sg, scatterers, sgoffset, constrainlat, constrainadps, adpsymbols, isosymbol) return sgp