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 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)
     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))
     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,
         'g186c': g186c,
         'g227a': g227a,
         'g227c': g227c,
         'g227oa': g227oa,
         'g227oc': g227oc
     }
     self.__dict__.update(TestGeneratorSite.generators)
     return
 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_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_ConstrainAsSpaceGroup_args(self):
     """Test the arguments processing of constrainAsSpaceGroup function.
     """
     from diffpy.srfit.structure.sgconstraints import constrainAsSpaceGroup
     from diffpy.Structure.SpaceGroups import GetSpaceGroup
     stru = makeLaMnO3_P1()
     parset = DiffpyStructureParSet("LaMnO3", stru)
     sgpars = constrainAsSpaceGroup(parset, "P b n m")
     sg = GetSpaceGroup('P b n m')
     parset2 = DiffpyStructureParSet("LMO", makeLaMnO3_P1())
     sgpars2 = constrainAsSpaceGroup(parset2, sg)
     list(sgpars)
     list(sgpars2)
     self.assertEqual(sgpars.names, sgpars2.names)
     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] == range(4))
     self.assertTrue(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
Ejemplo n.º 9
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
 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
Ejemplo n.º 12
0
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
Ejemplo n.º 13
0
 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
Ejemplo n.º 14
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]