예제 #1
0
 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] == range(4))
     self.assertTrue(sc.coremap[4] == range(4, 4 + 192))
     return
예제 #2
0
    def updateWidgets(self):
        """Update the widgets."""
        # Update space group
        sgname = self.sgComboBox.GetValue()
        try:
            self.spacegroup = self.structure.getSpaceGroup(sgname)
            error = None
        except ValueError:
            error = "Space group %s does not exist." % sgname
        # This changes list box value to the short_name of the new spacegroup
        # or to the name of previous spacegroup when getSpaceGroup failed.
        self.sgComboBox.SetValue(self.spacegroup.short_name)

        # Update offset
        for i in range(3):
            textctrl = self.textCtrls[i]
            val = textctrl.GetValue()
            # make sure the value is meaningful
            try:
                val = float(eval("1.0*" + val, dict(math.__dict__)))
            except (NameError, TypeError, SyntaxError):
                val = 0.0
            textctrl.SetValue("%s" % val)
            self.offset[i] = val

        # find how many new atoms would be generated
        from diffpy.Structure.SymmetryUtilities import ExpandAsymmetricUnit
        corepos = [self.structure[i].xyz for i in self.indices]
        symposeps = self.structure.symposeps
        eau = ExpandAsymmetricUnit(self.spacegroup,
                                   corepos,
                                   sgoffset=self.offset,
                                   eps=symposeps)
        newsize = sum(eau.multiplicity)
        s = ""
        if len(self.indices) != 1:
            s = "s"
        message = "%i atom%s selected.  Expanding to %i positions." %\
                (len(self.indices), s, newsize)
        self.numConstrainedLabel.SetLabel(message)

        # Raise an error if we had to change the space group
        if error:
            raise ControlValueError(error)
        return
예제 #3
0
 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
예제 #5
0
from diffpy.Structure.SymmetryUtilities import ExpandAsymmetricUnit
positions = [[0.1, 0.2, 0.2]]

from diffpy.Structure.SpaceGroups import GetSpaceGroup
sg225 = GetSpaceGroup('Fm-3m')

eau = ExpandAsymmetricUnit(sg225, positions)

pos_expanded=eau.positions[0]