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 _set_spaceGroup(self, item): from matter.SpaceGroups import SpaceGroup if isinstance(item, SpaceGroup): self._sg = item self._sgid = item.number else: from matter.SpaceGroups import GetSpaceGroup self._sg = GetSpaceGroup(item) self._sgid = item
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) 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)) 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, 'g227a': g227a, 'g227c': g227c, 'g227oa': g227oa, 'g227oc': g227oc } self.__dict__.update(TestGeneratorSite.generators) return
def test_expandPosition(self): """check expandPosition() """ # ok again Ni example fcc = GetSpaceGroup(225) pos, pops, pmult = expandPosition(fcc, [0, 0, 0]) self.failUnless(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_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.failUnless(numpy.all(corepos[0] == sc.corepos[0])) self.failUnless(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.failUnless(sc.coremap[0] == range(4)) self.failUnless(sc.coremap[4] == 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___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.failUnless(isSpaceGroupLatPar(triclinic, 1, 2, 3, 40, 50, 60)) self.failIf(isSpaceGroupLatPar(monoclinic, 1, 2, 3, 40, 50, 60)) self.failUnless(isSpaceGroupLatPar(monoclinic, 1, 2, 3, 90, 50, 90)) self.failIf(isSpaceGroupLatPar(orthorhombic, 1, 2, 3, 90, 50, 90)) self.failUnless(isSpaceGroupLatPar(orthorhombic, 1, 2, 3, 90, 90, 90)) self.failIf(isSpaceGroupLatPar(tetragonal, 1, 2, 3, 90, 90, 90)) self.failUnless(isSpaceGroupLatPar(tetragonal, 2, 2, 3, 90, 90, 90)) self.failIf(isSpaceGroupLatPar(trigonal, 2, 2, 3, 90, 90, 90)) self.failUnless(isSpaceGroupLatPar(trigonal, 2, 2, 2, 80, 80, 80)) self.failIf(isSpaceGroupLatPar(hexagonal, 2, 2, 2, 80, 80, 80)) self.failUnless(isSpaceGroupLatPar(hexagonal, 2, 2, 3, 90, 90, 120)) self.failIf(isSpaceGroupLatPar(cubic, 2, 2, 3, 90, 90, 120)) self.failUnless(isSpaceGroupLatPar(cubic, 3, 3, 3, 90, 90, 90)) return
def _get_spaceGroup(self): if not self._sg: from matter.SpaceGroups import GetSpaceGroup self._sg = GetSpaceGroup(self._sgid) return self._sg