def _generate_UBList(self):
        CreateSingleValuedWorkspace(OutputWorkspace='__ub')
        LoadIsawUB('__ub',self.getProperty("UBMatrix").value)
        ub=mtd['__ub'].sample().getOrientedLattice().getUB().copy()
        DeleteWorkspace(Workspace='__ub')

        symOps = self.getProperty("SymmetryOps").value
        if symOps:
            try:
                symOps = SpaceGroupFactory.subscribedSpaceGroupSymbols(int(symOps))[0]
            except ValueError:
                pass
            if SpaceGroupFactory.isSubscribedSymbol(symOps):
                symOps = SpaceGroupFactory.createSpaceGroup(symOps).getSymmetryOperations()
            else:
                symOps = SymmetryOperationFactory.createSymOps(symOps)
            logger.information('Using symmetries: '+str([sym.getIdentifier() for sym in symOps]))

            ub_list=[]
            for sym in symOps:
                UBtrans = np.zeros((3,3))
                UBtrans[0] = sym.transformHKL([1,0,0])
                UBtrans[1] = sym.transformHKL([0,1,0])
                UBtrans[2] = sym.transformHKL([0,0,1])
                UBtrans=np.matrix(UBtrans.T)
                ub_list.append(ub*UBtrans)
            return ub_list
        else:
            return [ub]
Esempio n. 2
0
    def _generate_UBList(self):
        CreateSingleValuedWorkspace(OutputWorkspace='__ub')
        LoadIsawUB('__ub', self.getProperty("UBMatrix").value)
        ub = mtd['__ub'].sample().getOrientedLattice().getUB().copy()
        DeleteWorkspace(Workspace='__ub')

        symOps = self.getProperty("SymmetryOps").value
        if symOps:
            try:
                symOps = SpaceGroupFactory.subscribedSpaceGroupSymbols(
                    int(symOps))[0]
            except ValueError:
                pass
            if SpaceGroupFactory.isSubscribedSymbol(symOps):
                symOps = SpaceGroupFactory.createSpaceGroup(
                    symOps).getSymmetryOperations()
            else:
                symOps = SymmetryOperationFactory.createSymOps(symOps)
            logger.information('Using symmetries: ' +
                               str([sym.getIdentifier() for sym in symOps]))

            ub_list = []
            for sym in symOps:
                UBtrans = np.zeros((3, 3))
                UBtrans[0] = sym.transformHKL([1, 0, 0])
                UBtrans[1] = sym.transformHKL([0, 1, 0])
                UBtrans[2] = sym.transformHKL([0, 0, 1])
                UBtrans = np.matrix(UBtrans.T)
                ub_list.append(ub * UBtrans)
            return ub_list
        else:
            return [ub]
Esempio n. 3
0
    def _punch_and_fill(self, signal, dimX, dimY, dimZ):  # noqa
        Xmin, Xmax, _, Xwidth = self._get_dim_params(dimX)
        Ymin, Ymax, _, Ywidth = self._get_dim_params(dimY)
        Zmin, Zmax, _, Zwidth = self._get_dim_params(dimZ)
        X, Y, Z = self._get_XYZ_ogrid(dimX, dimY, dimZ)

        size = self.getProperty("Size").value
        if len(size) == 1:
            size = np.repeat(size, 3)
        size /= 2.0  # We want radii or half box width
        cut_shape = self.getProperty("Shape").value
        space_group = self.getProperty("SpaceGroup").value
        if space_group:
            check_space_group = True
            try:
                space_group = SpaceGroupFactory.subscribedSpaceGroupSymbols(
                    int(space_group))[0]
            except ValueError:
                pass
            logger.information('Using space group: ' + space_group)
            sg = SpaceGroupFactory.createSpaceGroup(space_group)
        else:
            check_space_group = False

        if cut_shape == 'cube':
            for h in range(int(np.ceil(Xmin)), int(Xmax) + 1):
                for k in range(int(np.ceil(Ymin)), int(Ymax) + 1):
                    for l in range(int(np.ceil(Zmin)), int(Zmax) + 1):
                        if not check_space_group or sg.isAllowedReflection(
                            [h, k, l]):
                            signal[int((h - size[0] - Xmin) / Xwidth +
                                       1):int((h + size[0] - Xmin) / Xwidth),
                                   int((k - size[1] - Ymin) / Ywidth +
                                       1):int((k + size[1] - Ymin) / Ywidth),
                                   int((l - size[2] - Zmin) / Zwidth +
                                       1):int((l + size[2] - Zmin) /
                                              Zwidth)] = np.nan
        else:  # sphere
            mask = ((X - np.round(X))**2 / size[0]**2 +
                    (Y - np.round(Y))**2 / size[1]**2 +
                    (Z - np.round(Z))**2 / size[2]**2 < 1)

            # Unmask invalid reflections
            if check_space_group:
                for h in range(int(np.ceil(Xmin)), int(Xmax) + 1):
                    for k in range(int(np.ceil(Ymin)), int(Ymax) + 1):
                        for l in range(int(np.ceil(Zmin)), int(Zmax) + 1):
                            if not sg.isAllowedReflection([h, k, l]):
                                mask[int((h - 0.5 - Xmin) / Xwidth +
                                         1):int((h + 0.5 - Xmin) / Xwidth),
                                     int((k - 0.5 - Ymin) / Ywidth +
                                         1):int((k + 0.5 - Ymin) / Ywidth),
                                     int((l - 0.5 - Zmin) / Zwidth +
                                         1):int((l + 0.5 - Zmin) /
                                                Zwidth)] = False

            signal[mask] = np.nan

        return signal
Esempio n. 4
0
    def validateInputs(self):
        issues = dict()

        inWS = self.getProperty("InputWorkspace").value
        dimX = inWS.getXDimension()
        dimY = inWS.getYDimension()
        dimZ = inWS.getZDimension()

        if dimX.name != '[H,0,0]' or dimY.name != '[0,K,0]' or dimZ.name != '[0,0,L]':
            issues[
                'InputWorkspace'] = 'dimensions must be [H,0,0], [0,K,0] and [0,0,L]'

        for d in range(inWS.getNumDims()):
            dim = inWS.getDimension(d)
            if not np.isclose(dim.getMaximum(), -dim.getMinimum(), atol=1e-5):
                issues[
                    'InputWorkspace'] = 'dimensions must be centered on zero'

        if self.getProperty("Convolution").value and self.getProperty(
                "Method").value == 'Punch and fill':
            try:
                import astropy  # noqa
            except ImportError:
                issues[
                    "Convolution"] = 'python-astropy required to do convolution'

        size = self.getProperty("Size").value
        if len(size) != 1 and len(size) != 3:
            issues["Size"] = 'Must provide 1 or 3 sizes'

        if self.getProperty("SpaceGroup").value:
            space_group = self.getProperty("SpaceGroup").value
            try:
                if not SpaceGroupFactory.isSubscribedNumber(int(space_group)):
                    issues["SpaceGroup"] = 'Space group number is not valid'
            except ValueError:
                if not SpaceGroupFactory.isSubscribedSymbol(space_group):
                    issues["SpaceGroup"] = 'Space group name is not valid'

        sphereMin = self.getProperty("SphereMin").value
        if len(sphereMin) != 1 and len(sphereMin) != 3:
            issues["SphereMin"] = 'Must provide 1 or 3 diameters'

        sphereMax = self.getProperty("SphereMax").value
        if len(sphereMax) != 1 and len(sphereMax) != 3:
            issues["SphereMax"] = 'Must provide 1 or 3 diameters'

        if self.getProperty("WindowFunction").value == 'Tukey':
            try:
                ssignal.tukey
            except AttributeError:
                issues[
                    "WindowFunction"] = 'Tukey window requires scipy >= 0.16.0'

        return issues
Esempio n. 5
0
    def validateInputs(self):
        issues = dict()

        inWS = self.getProperty("InputWorkspace").value
        dimX=inWS.getXDimension()
        dimY=inWS.getYDimension()
        dimZ=inWS.getZDimension()

        if dimX.name != '[H,0,0]' or dimY.name != '[0,K,0]' or dimZ.name != '[0,0,L]':
            issues['InputWorkspace'] = 'dimensions must be [H,0,0], [0,K,0] and [0,0,L]'

        for d in range(inWS.getNumDims()):
            dim = inWS.getDimension(d)
            if not np.isclose(dim.getMaximum(), -dim.getMinimum(), atol=1e-5):
                issues['InputWorkspace'] = 'dimensions must be centered on zero'

        if self.getProperty("Convolution").value and self.getProperty("Method").value == 'Punch and fill':
            try:
                import astropy # noqa
            except ImportError:
                issues["Convolution"] = 'python-astropy required to do convolution'

        size = self.getProperty("Size").value
        if len(size) != 1 and len(size) != 3:
            issues["Size"] = 'Must provide 1 or 3 sizes'

        if self.getProperty("SpaceGroup").value:
            space_group=self.getProperty("SpaceGroup").value
            try:
                if not SpaceGroupFactory.isSubscribedNumber(int(space_group)):
                    issues["SpaceGroup"] = 'Space group number is not valid'
            except ValueError:
                if not SpaceGroupFactory.isSubscribedSymbol(space_group):
                    issues["SpaceGroup"] = 'Space group name is not valid'

        sphereMin = self.getProperty("SphereMin").value
        if len(sphereMin) != 1 and len(sphereMin) != 3:
            issues["SphereMin"] = 'Must provide 1 or 3 diameters'

        sphereMax = self.getProperty("SphereMax").value
        if len(sphereMax) != 1 and len(sphereMax) != 3:
            issues["SphereMax"] = 'Must provide 1 or 3 diameters'

        if self.getProperty("WindowFunction").value == 'Tukey':
            try:
                ssignal.tukey
            except AttributeError:
                issues["WindowFunction"] = 'Tukey window requires scipy >= 0.16.0'

        return issues
    def validateInputs(self):
        issues = dict()

        if self.getProperty("SymmetryOps").value:
            syms=self.getProperty("SymmetryOps").value
            try:
                if not SpaceGroupFactory.isSubscribedNumber(int(syms)):
                    issues["SymmetryOps"] = 'Space group number '+syms+' is not valid'
            except ValueError:
                if not SpaceGroupFactory.isSubscribedSymbol(syms):
                    for sym in syms.split(';'):
                        if not SymmetryOperationFactory.exists(sym):
                            issues["SymmetryOps"] = sym+' is not valid symmetry or space group name'

        return issues
Esempio n. 7
0
    def _getSpaceGroupFromNumber(self, cifData):
        spaceGroupNumber = [int(cifData[x]) for x in
                            [u'_space_group_it_number', u'_symmetry_int_tables_number'] if
                            x in cifData.keys()]

        if len(spaceGroupNumber) == 0:
            raise RuntimeError('No space group symbol in CIF.')

        possibleSpaceGroupSymbols = SpaceGroupFactory.subscribedSpaceGroupSymbols(spaceGroupNumber[0])

        if len(possibleSpaceGroupSymbols) != 1:
            raise RuntimeError(
                'Can not use space group number to determine space group for no. {0}'.format(spaceGroupNumber))

        return SpaceGroupFactory.createSpaceGroup(possibleSpaceGroupSymbols[0]).getHMSymbol()
    def validateInputs(self):
        issues = dict()

        if self.getProperty("SymmetryOps").value:
            syms=self.getProperty("SymmetryOps").value
            try:
                if not SpaceGroupFactory.isSubscribedNumber(int(syms)):
                    issues["SymmetryOps"] = 'Space group number '+syms+' is not valid'
            except ValueError:
                if not SpaceGroupFactory.isSubscribedSymbol(syms):
                    for sym in syms.split(';'):
                        if not SymmetryOperationFactory.exists(sym):
                            issues["SymmetryOps"] = sym+' is not valid symmetry or space group name'

        return issues
Esempio n. 9
0
    def _getSpaceGroupFromNumber(self, cifData):
        spaceGroupNumber = [int(cifData[x]) for x in
                            ['_space_group_it_number', '_symmetry_int_tables_number'] if
                            x in cifData.keys()]

        if len(spaceGroupNumber) == 0:
            raise RuntimeError('No space group symbol in CIF.')

        possibleSpaceGroupSymbols = SpaceGroupFactory.subscribedSpaceGroupSymbols(spaceGroupNumber[0])

        if len(possibleSpaceGroupSymbols) != 1:
            raise RuntimeError(
                'Can not use space group number to determine space group for no. {0}'.format(spaceGroupNumber))

        return SpaceGroupFactory.createSpaceGroup(possibleSpaceGroupSymbols[0]).getHMSymbol()
Esempio n. 10
0
    def test_isAllowedUnitCell_cubic(self):
        cubic = UnitCell(6, 6, 6)
        tetragonal = UnitCell(6, 6, 6.01)
        sg = SpaceGroupFactory.createSpaceGroup('P m -3')

        self.assertTrue(sg.isAllowedUnitCell(cubic))
        self.assertFalse(sg.isAllowedUnitCell(tetragonal))
Esempio n. 11
0
    def test_equivalentPositions_Monoclinic(self):
        wyckoffs = [([0.3, 0.4, 0.45], 8), ([0.0, 0.4, 0.25], 4),
                    ([0.25, 0.25, 0.5], 4), ([0.25, 0.25, 0.0], 4),
                    ([0.0, 0.5, 0.0], 4), ([0.0, 0.0, 0.0], 4)]

        spaceGroup = SpaceGroupFactory.createSpaceGroup("C 1 2/c 1")
        self.checkWyckoffPositions(spaceGroup, wyckoffs)
Esempio n. 12
0
    def test_equivalentPositions_Trigonal(self):
        wyckoffs = [([0.3, 0.4, 0.45], 36), ([0.3, 0.0, 0.25], 18),
                    ([0.5, 0.0, 0.0], 18), ([0.0, 0.0, 0.45], 12),
                    ([0.0, 0.0, 0.0], 6), ([0.0, 0.0, 0.25], 6)]

        spaceGroup = SpaceGroupFactory.createSpaceGroup("R -3 c")
        self.checkWyckoffPositions(spaceGroup, wyckoffs)
Esempio n. 13
0
    def test_isAllowedUnitCell_cubic(self):
        cubic = UnitCell(6, 6, 6)
        tetragonal = UnitCell(6, 6, 6.01)
        sg = SpaceGroupFactory.createSpaceGroup('P m -3')

        self.assertTrue(sg.isAllowedUnitCell(cubic))
        self.assertFalse(sg.isAllowedUnitCell(tetragonal))
Esempio n. 14
0
    def _punch_and_fill(self, signal, dimX, dimY, dimZ): # noqa
        Xmin, Xmax, _, Xwidth = self._get_dim_params(dimX)
        Ymin, Ymax, _, Ywidth = self._get_dim_params(dimY)
        Zmin, Zmax, _, Zwidth = self._get_dim_params(dimZ)
        X, Y, Z = self._get_XYZ_ogrid(dimX, dimY, dimZ)

        size = self.getProperty("Size").value
        if len(size)==1:
            size = np.repeat(size, 3)
        size/=2.0 # We want radii or half box width
        cut_shape = self.getProperty("Shape").value
        space_group = self.getProperty("SpaceGroup").value
        if space_group:
            check_space_group = True
            try:
                space_group=SpaceGroupFactory.subscribedSpaceGroupSymbols(int(space_group))[0]
            except ValueError:
                pass
            logger.information('Using space group: '+space_group)
            sg=SpaceGroupFactory.createSpaceGroup(space_group)
        else:
            check_space_group = False

        if cut_shape == 'cube':
            for h in range(int(np.ceil(Xmin)), int(Xmax)+1):
                for k in range(int(np.ceil(Ymin)), int(Ymax)+1):
                    for l in range(int(np.ceil(Zmin)), int(Zmax)+1):
                        if not check_space_group or sg.isAllowedReflection([h,k,l]):
                            signal[int((h-size[0]-Xmin)/Xwidth+1):int((h+size[0]-Xmin)/Xwidth),
                                   int((k-size[1]-Ymin)/Ywidth+1):int((k+size[1]-Ymin)/Ywidth),
                                   int((l-size[2]-Zmin)/Zwidth+1):int((l+size[2]-Zmin)/Zwidth)]=np.nan
        else:  # sphere
            mask=((X-np.round(X))**2/size[0]**2 + (Y-np.round(Y))**2/size[1]**2 + (Z-np.round(Z))**2/size[2]**2 < 1)

            # Unmask invalid reflections
            if check_space_group:
                for h in range(int(np.ceil(Xmin)), int(Xmax)+1):
                    for k in range(int(np.ceil(Ymin)), int(Ymax)+1):
                        for l in range(int(np.ceil(Zmin)), int(Zmax)+1):
                            if not sg.isAllowedReflection([h,k,l]):
                                mask[int((h-0.5-Xmin)/Xwidth+1):int((h+0.5-Xmin)/Xwidth),
                                     int((k-0.5-Ymin)/Ywidth+1):int((k+0.5-Ymin)/Ywidth),
                                     int((l-0.5-Zmin)/Zwidth+1):int((l+0.5-Zmin)/Zwidth)]=False

            signal[mask]=np.nan

        return signal
Esempio n. 15
0
    def test_equivalentPositions_Cubic(self):
        wyckoffs = [([0.3, 0.4, 0.45], 96), ([0.3, 0.25, 0.25], 48),
                    ([0.3, 0.0, 0.0], 48), ([0.3, 0.3, 0.3], 32),
                    ([0.25, 0.0, 0.0], 24), ([0.0, 0.25, 0.25], 24),
                    ([0.25, 0.25, 0.25], 8), ([0.0, 0.0, 0.0], 8)]

        spaceGroup = SpaceGroupFactory.createSpaceGroup("F -4 3 c")
        self.checkWyckoffPositions(spaceGroup, wyckoffs)
Esempio n. 16
0
    def test_equivalentPositions_Tetragonal(self):
        wyckoffs = [([0.3, 0.4, 0.45], 32), ([0.3, 0.3, 0.25], 16),
                    ([0.25, 0.4, 0.125], 16), ([0.0, 0.0, 0.45], 16),
                    ([0.0, 0.25, 0.125], 16), ([0.0, 0.0, 0.25], 8),
                    ([0.0, 0.0, 0.0], 8)]

        spaceGroup = SpaceGroupFactory.createSpaceGroup("I 41/a c d")
        self.checkWyckoffPositions(spaceGroup, wyckoffs)
Esempio n. 17
0
    def test_isAllowedUnitCell_trigonal(self):
        rhombohedral = UnitCell(5, 5, 5, 80, 80, 80)
        hexagonal = UnitCell(5, 5, 4, 90, 90, 120)

        sgRh = SpaceGroupFactory.createSpaceGroup('R -3 c :r')
        sgHex = SpaceGroupFactory.createSpaceGroup('R -3 c')

        sgP6m = SpaceGroupFactory.createSpaceGroup('P 6/m')

        self.assertTrue(sgRh.isAllowedUnitCell(rhombohedral))
        self.assertFalse(sgRh.isAllowedUnitCell(hexagonal))

        self.assertTrue(sgHex.isAllowedUnitCell(hexagonal))
        self.assertFalse(sgHex.isAllowedUnitCell(rhombohedral))

        self.assertTrue(sgP6m.isAllowedUnitCell(hexagonal))
        self.assertFalse(sgP6m.isAllowedUnitCell(rhombohedral))
Esempio n. 18
0
    def test_isAllowedUnitCell_trigonal(self):
        rhombohedral = UnitCell(5, 5, 5, 80, 80, 80)
        hexagonal = UnitCell(5, 5, 4, 90, 90, 120)

        sgRh = SpaceGroupFactory.createSpaceGroup('R -3 c :r')
        sgHex = SpaceGroupFactory.createSpaceGroup('R -3 c')

        sgP6m = SpaceGroupFactory.createSpaceGroup('P 6/m')

        self.assertTrue(sgRh.isAllowedUnitCell(rhombohedral))
        self.assertFalse(sgRh.isAllowedUnitCell(hexagonal))

        self.assertTrue(sgHex.isAllowedUnitCell(hexagonal))
        self.assertFalse(sgHex.isAllowedUnitCell(rhombohedral))

        self.assertTrue(sgP6m.isAllowedUnitCell(hexagonal))
        self.assertFalse(sgP6m.isAllowedUnitCell(rhombohedral))
Esempio n. 19
0
    def test_equivalentPositions_Triclinic(self):
        wyckoffs = [([0.3, 0.4, 0.45], 2), ([0.5, 0.5, 0.5], 1),
                    ([0.0, 0.5, 0.5], 1), ([0.5, 0.0, 0.5], 1),
                    ([0.5, 0.5, 0.0], 1), ([0.5, 0.0, 0.0], 1),
                    ([0.0, 0.5, 0.0], 1), ([0.0, 0.0, 0.5], 1),
                    ([0.0, 0.0, 0.0], 1)]

        spaceGroup = SpaceGroupFactory.createSpaceGroup("P -1")
        self.checkWyckoffPositions(spaceGroup, wyckoffs)
Esempio n. 20
0
    def test_equivalentPositions_Orthorhombic(self):
        wyckoffs = [([0.3, 0.4, 0.45], 16), ([0.3, 0.25, 0.45], 8),
                    ([0.0, 0.4, 0.45], 8), ([0.25, 0.4, 0.25], 8),
                    ([0.3, 0.0, 0.0], 8), ([0.0, 0.25, 0.45], 4),
                    ([0.25, 0.25, 0.75], 4), ([0.25, 0.25, 0.25], 4),
                    ([0.0, 0.0, 0.5], 4), ([0.0, 0.0, 0.0], 4)]

        spaceGroup = SpaceGroupFactory.createSpaceGroup("I m m a")
        self.checkWyckoffPositions(spaceGroup, wyckoffs)
Esempio n. 21
0
    def test_interface(self):
        spaceGroup = SpaceGroupFactory.createSpaceGroup("P -1")
        self.assertEquals(spaceGroup.getHMSymbol(), "P -1")
        self.assertEquals(spaceGroup.getOrder(), 2)

        symOpStrings = spaceGroup.getSymmetryOperationStrings()

        self.assertEqual(len(symOpStrings), 2)
        self.assertTrue("x,y,z" in symOpStrings)
        self.assertTrue("-x,-y,-z" in symOpStrings)
Esempio n. 22
0
    def test_equivalentPositions_Trigonal(self):
        wyckoffs = [([0.3, 0.4, 0.45], 36),
                    ([0.3, 0.0, 0.25], 18),
                    ([0.5, 0.0, 0.0], 18),
                    ([0.0, 0.0, 0.45], 12),
                    ([0.0, 0.0, 0.0], 6),
                    ([0.0, 0.0, 0.25], 6)]

        spaceGroup = SpaceGroupFactory.createSpaceGroup("R -3 c")
        self.checkWyckoffPositions(spaceGroup, wyckoffs)
Esempio n. 23
0
    def test_equivalentPositions_Hexagonal(self):
        wyckoffs = [([0.3, 0.4, 0.45], 24), ([0.3, 0.6, 0.45], 12),
                    ([0.3, 0.4, 0.25], 12), ([0.3, 0.0, 0.0], 12),
                    ([0.3, 0.6, 0.25], 6), ([0.5, 0.0, 0.0], 6),
                    ([1. / 3., 2. / 3., 0.45], 4), ([0.0, 0.0, 0.45], 4),
                    ([1. / 3, 2. / 3., 0.75], 2), ([1. / 3, 2. / 3., 0.25], 2),
                    ([0.0, 0.0, 0.25], 2), ([0.0, 0.0, 0.0], 2)]

        spaceGroup = SpaceGroupFactory.createSpaceGroup("P 63/m m c")
        self.checkWyckoffPositions(spaceGroup, wyckoffs)
Esempio n. 24
0
    def test_interface(self):
        spaceGroup = SpaceGroupFactory.createSpaceGroup("P -1")
        self.assertEquals(spaceGroup.getHMSymbol(), "P -1")
        self.assertEquals(spaceGroup.getOrder(), 2)

        symOpStrings = spaceGroup.getSymmetryOperationStrings()

        self.assertEqual(len(symOpStrings), 2)
        self.assertTrue("x,y,z" in symOpStrings)
        self.assertTrue("-x,-y,-z" in symOpStrings)
Esempio n. 25
0
    def test_equivalentPositions_Monoclinic(self):
        wyckoffs = [([0.3, 0.4, 0.45], 8),
                    ([0.0, 0.4, 0.25], 4),
                    ([0.25, 0.25, 0.5], 4),
                    ([0.25, 0.25, 0.0], 4),
                    ([0.0, 0.5, 0.0], 4),
                    ([0.0, 0.0, 0.0], 4)]

        spaceGroup = SpaceGroupFactory.createSpaceGroup("C 1 2/c 1")
        self.checkWyckoffPositions(spaceGroup, wyckoffs)
Esempio n. 26
0
    def test_creationFromPythonList(self):
        spaceGroup = SpaceGroupFactory.createSpaceGroup("P 63/m m c")

        # Construct python list of only certain symmetry operations
        symOps = [x for x in spaceGroup.getSymmetryOperations() if x.getOrder() == 6]

        group = Group(symOps)
        self.assertEqual(group.getOrder(), len(symOps))

        # But the constructed group is not actually a group
        self.assertFalse(group.isGroup())
Esempio n. 27
0
    def test_creationFromPythonList(self):
        spaceGroup = SpaceGroupFactory.createSpaceGroup("P 63/m m c")

        # Construct python list of only certain symmetry operations
        symOps = [x for x in spaceGroup.getSymmetryOperations() if x.getOrder() == 6]

        group = Group(symOps)
        self.assertEqual(group.getOrder(), len(symOps))

        # But the constructed group is not actually a group
        self.assertFalse(group.isGroup())
Esempio n. 28
0
    def test_equivalentPositions_Tetragonal(self):
        wyckoffs = [([0.3, 0.4, 0.45], 32),
                    ([0.3, 0.3, 0.25], 16),
                    ([0.25, 0.4, 0.125], 16),
                    ([0.0, 0.0, 0.45], 16),
                    ([0.0, 0.25, 0.125], 16),
                    ([0.0, 0.0, 0.25], 8),
                    ([0.0, 0.0, 0.0], 8)]

        spaceGroup = SpaceGroupFactory.createSpaceGroup("I 41/a c d")
        self.checkWyckoffPositions(spaceGroup, wyckoffs)
Esempio n. 29
0
    def test_to_string(self):
        spaceGroup = SpaceGroupFactory.createSpaceGroup("F -4 3 c")

        expected_str = "Space group with Hermann-Mauguin symbol: "\
                       "F -4 3 c"
        expected_repr = "SpaceGroupFactory.createSpaceGroup(\"F -4 3 c\")"

        self.assertEqual(expected_str, str(spaceGroup))
        self.assertEqual(expected_repr, spaceGroup.__repr__())

        newSpaceGroup = eval(spaceGroup.__repr__())
        self.assertEqual(spaceGroup.getHMSymbol(), newSpaceGroup.getHMSymbol())
Esempio n. 30
0
    def test_to_string(self):
        spaceGroup = SpaceGroupFactory.createSpaceGroup("F -4 3 c")

        expected_str = "Space group with Hermann-Mauguin symbol: "\
                       "F -4 3 c"
        expected_repr = "SpaceGroupFactory.createSpaceGroup(\"F -4 3 c\")"

        self.assertEqual(expected_str, str(spaceGroup))
        self.assertEqual(expected_repr, spaceGroup.__repr__())

        newSpaceGroup = eval(spaceGroup.__repr__())
        self.assertEqual(spaceGroup.getHMSymbol(), newSpaceGroup.getHMSymbol())
Esempio n. 31
0
    def test_equivalentPositions_Cubic(self):
        wyckoffs = [([0.3, 0.4, 0.45], 96),
                    ([0.3, 0.25, 0.25], 48),
                    ([0.3, 0.0, 0.0], 48),
                    ([0.3, 0.3, 0.3], 32),
                    ([0.25, 0.0, 0.0], 24),
                    ([0.0, 0.25, 0.25], 24),
                    ([0.25, 0.25, 0.25], 8),
                    ([0.0, 0.0, 0.0], 8)]

        spaceGroup = SpaceGroupFactory.createSpaceGroup("F -4 3 c")
        self.checkWyckoffPositions(spaceGroup, wyckoffs)
Esempio n. 32
0
    def _getSpaceGroupFromString(self, cifData):
        # Try two possibilities for space group symbol. If neither is present, throw a RuntimeError.
        rawSpaceGroupSymbol = [str(cifData[x]) for x in
                               [u'_space_group_name_h-m_alt', u'_symmetry_space_group_name_h-m'] if
                               x in cifData.keys()]

        if len(rawSpaceGroupSymbol) == 0:
            raise RuntimeError('No space group symbol in CIF.')

        cleanSpaceGroupSymbol = self._getCleanSpaceGroupSymbol(rawSpaceGroupSymbol[0])

        # If the symbol is not registered, throw as well.
        return SpaceGroupFactory.createSpaceGroup(cleanSpaceGroupSymbol).getHMSymbol()
Esempio n. 33
0
    def _getSpaceGroupFromString(self, cifData):
        # Try two possibilities for space group symbol. If neither is present, throw a RuntimeError.
        rawSpaceGroupSymbol = [str(cifData[x]) for x in
                               ['_space_group_name_h-m_alt', '_symmetry_space_group_name_h-m'] if
                               x in cifData.keys()]

        if len(rawSpaceGroupSymbol) == 0:
            raise RuntimeError('No space group symbol in CIF.')

        cleanSpaceGroupSymbol = self._getCleanSpaceGroupSymbol(rawSpaceGroupSymbol[0])

        # If the symbol is not registered, throw as well.
        return SpaceGroupFactory.createSpaceGroup(cleanSpaceGroupSymbol).getHMSymbol()
Esempio n. 34
0
    def test_equivalentPositions_Triclinic(self):
        wyckoffs = [([0.3, 0.4, 0.45], 2),
                    ([0.5, 0.5, 0.5], 1),
                    ([0.0, 0.5, 0.5], 1),
                    ([0.5, 0.0, 0.5], 1),
                    ([0.5, 0.5, 0.0], 1),
                    ([0.5, 0.0, 0.0], 1),
                    ([0.0, 0.5, 0.0], 1),
                    ([0.0, 0.0, 0.5], 1),
                    ([0.0, 0.0, 0.0], 1)]

        spaceGroup = SpaceGroupFactory.createSpaceGroup("P -1")
        self.checkWyckoffPositions(spaceGroup, wyckoffs)
Esempio n. 35
0
    def test_equivalentPositions_Orthorhombic(self):
        wyckoffs = [([0.3, 0.4, 0.45], 16),
                    ([0.3, 0.25, 0.45], 8),
                    ([0.0, 0.4, 0.45], 8),
                    ([0.25, 0.4, 0.25], 8),
                    ([0.3, 0.0, 0.0], 8),
                    ([0.0, 0.25, 0.45], 4),
                    ([0.25, 0.25, 0.75], 4),
                    ([0.25, 0.25, 0.25], 4),
                    ([0.0, 0.0, 0.5], 4),
                    ([0.0, 0.0, 0.0], 4)]

        spaceGroup = SpaceGroupFactory.createSpaceGroup("I m m a")
        self.checkWyckoffPositions(spaceGroup, wyckoffs)
Esempio n. 36
0
def getReflectionFamily(row):
    sg = SpaceGroupFactory.createSpaceGroup('P 32 2 1')
    pg = sg.getPointGroup()
    h = float(row['h'])
    k = float(row['k'])
    l = float(row['l'])
    hklPlus = np.array([h, k, l])
    hklMinus = np.array([-h, -k, -l])
    refFamPlus = pg.getReflectionFamily(hklPlus)
    refFamMinus = pg.getReflectionFamily(hklMinus)
    checkIDX = (~np.equal(refFamPlus, refFamMinus)).argmax()
    if refFamPlus[checkIDX] >= refFamMinus[checkIDX]:
        return tuple(np.array(refFamPlus, dtype=int))
    else:  # refFamPlus[checkIDX] < refFamMinus[checkIDX]:
        return tuple(np.array(refFamMinus, dtype=int))
Esempio n. 37
0
    def test_equivalentPositions_Hexagonal(self):
        wyckoffs = [([0.3, 0.4, 0.45], 24),
                    ([0.3, 0.6, 0.45], 12),
                    ([0.3, 0.4, 0.25], 12),
                    ([0.3, 0.0, 0.0], 12),
                    ([0.3, 0.6, 0.25], 6),
                    ([0.5, 0.0, 0.0], 6),
                    ([1. / 3., 2. / 3., 0.45], 4),
                    ([0.0, 0.0, 0.45], 4),
                    ([1. / 3, 2. / 3., 0.75], 2),
                    ([1. / 3, 2. / 3., 0.25], 2),
                    ([0.0, 0.0, 0.25], 2),
                    ([0.0, 0.0, 0.0], 2)]

        spaceGroup = SpaceGroupFactory.createSpaceGroup("P 63/m m c")
        self.checkWyckoffPositions(spaceGroup, wyckoffs)
Esempio n. 38
0
    if dim.getMaximum() != -dim.getMinimum():
        print('Workspace dimensions must be centered on zero')
        exit()
    #dim_list.append((dim.getNBins(), (dim.getMaximum()-dim.getMinimum())/dim.getNBins()))
    fft_dim = np.fft.fftshift(
        np.fft.fftfreq(dim.getNBins(),
                       (dim.getMaximum() - dim.getMinimum()) / dim.getNBins()))
    dim_list.append((fft_dim[0], fft_dim[-1]))

dimX = ws.getXDimension()
dimY = ws.getYDimension()
dimZ = ws.getZDimension()

signal = ws.getSignalArray().copy()

sg = SpaceGroupFactory.createSpaceGroup(space_group)

X = np.linspace(dimX.getMinimum(), dimX.getMaximum(), dimX.getNBins() + 1)
Y = np.linspace(dimY.getMinimum(), dimY.getMaximum(), dimY.getNBins() + 1)
Z = np.linspace(dimZ.getMinimum(), dimZ.getMaximum(), dimZ.getNBins() + 1)

box_width = 0.1  # in hkl dimensions

for h in range(int(np.ceil(dimX.getMinimum())),
               int(np.floor(dimX.getMaximum())) + 1):
    for k in range(int(np.ceil(dimY.getMinimum())),
                   int(np.floor(dimY.getMaximum())) + 1):
        for l in range(int(np.ceil(dimZ.getMinimum())),
                       int(np.floor(dimZ.getMaximum())) + 1):
            if sg.isAllowedReflection([h, k, l]):
                x_min = np.searchsorted(X, h - box_width)
Esempio n. 39
0
    def test_creationFromVector(self):
        spaceGroup = SpaceGroupFactory.createSpaceGroup("P 63/m m c")
        symOps = spaceGroup.getSymmetryOperations()

        group = Group(symOps)
        self.assertEqual(group.getOrder(), spaceGroup.getOrder())
Esempio n. 40
0
from mantid.simpleapi import *
from mantid.geometry import SymmetryOperationFactory, SpaceGroupFactory
import numpy as np

#symOps = SymmetryOperationFactory.createSymOps("x,y,z; -y,x-y,z+1/3; -x+y,-x,z+2/3; y,x,-z; x-y,-y,-z+2/3; -x,-x+y,-z+1/3")

ws=CreateSingleValuedWorkspace()
LoadIsawUB(ws,"/SNS/users/rwp/benzil/benzil_Hexagonal.mat")

sg=SpaceGroupFactory.createSpaceGroup("P 31 2 1")
symOps = sg.getSymmetryOperations()


ub=ws.sample().getOrientedLattice().getUB()
print("Starting UB :")
print(ub)

for sym in symOps:
    symTrans = np.array([sym.transformHKL([1,0,0]),
                         sym.transformHKL([0,1,0]),
                         sym.transformHKL([0,0,1])])
    symTrans=np.matrix(symTrans.T)
    print("Symmetry transform for "+sym.getIdentifier())
    print(symTrans)
    print("New UB:")
    newUB = ub*symTrans
    print(newUB)

print("To use SetUB(ws, UB=newUB)")
Esempio n. 41
0
    def runTest(self):
        # Na Mn Cl3
        # R -3 H (148)
        # 6.592 6.592 18.585177 90 90 120

        # UB/wavelength from /HFIR/HB3A/IPTS-25470/shared/autoreduce/HB3A_exp0769_scan0040.nxs

        ub = np.array([[1.20297e-01, 1.70416e-01, 1.43000e-04],
                       [8.16000e-04, -8.16000e-04, 5.38040e-02],
                       [1.27324e-01, -4.05110e-02, -4.81000e-04]])

        wavelength = 1.553

        # create fake MDEventWorkspace, similar to what is expected from exp769 after loading with HB3AAdjustSampleNorm
        MD_Q_sample = CreateMDWorkspace(
            Dimensions='3',
            Extents='-5,5,-5,5,-5,5',
            Names='Q_sample_x,Q_sample_y,Q_sample_z',
            Units='rlu,rlu,rlu',
            Frames='QSample,QSample,QSample')

        inst = LoadEmptyInstrument(InstrumentName='HB3A')
        AddTimeSeriesLog(inst, 'omega', '2010-01-01T00:00:00', 0.)
        AddTimeSeriesLog(inst, 'phi', '2010-01-01T00:00:00', 0.)
        AddTimeSeriesLog(inst, 'chi', '2010-01-01T00:00:00', 0.)
        MD_Q_sample.addExperimentInfo(inst)
        SetUB(MD_Q_sample, UB=ub)

        ol = OrientedLattice()
        ol.setUB(ub)

        sg = SpaceGroupFactory.createSpaceGroup("R -3")

        hkl = []
        sat_hkl = []

        for h in range(0, 6):
            for k in range(0, 6):
                for l in range(0, 11):
                    if sg.isAllowedReflection([h, k, l]):
                        if h == k == l == 0:
                            continue
                        q = V3D(h, k, l)
                        q_sample = ol.qFromHKL(q)
                        if not np.any(np.array(q_sample) > 5):
                            hkl.append(q)
                            FakeMDEventData(
                                MD_Q_sample,
                                PeakParams='1000,{},{},{},0.05'.format(
                                    *q_sample))
                        # satellite peaks at 0,0,+1.5
                        q = V3D(h, k, l + 1.5)
                        q_sample = ol.qFromHKL(q)
                        if not np.any(np.array(q_sample) > 5):
                            sat_hkl.append(q)
                            FakeMDEventData(
                                MD_Q_sample,
                                PeakParams='100,{},{},{},0.02'.format(
                                    *q_sample))
                        # satellite peaks at 0,0,-1.5
                        q = V3D(h, k, l - 1.5)
                        q_sample = ol.qFromHKL(q)
                        if not np.any(np.array(q_sample) > 5):
                            sat_hkl.append(q)
                            FakeMDEventData(
                                MD_Q_sample,
                                PeakParams='100,{},{},{},0.02'.format(
                                    *q_sample))

        # Check that this fake workpsace gives us the expected UB
        peaks = FindPeaksMD(MD_Q_sample,
                            PeakDistanceThreshold=1,
                            OutputType='LeanElasticPeak')
        FindUBUsingFFT(peaks, MinD=5, MaxD=20)
        ShowPossibleCells(peaks)
        SelectCellOfType(peaks,
                         CellType='Rhombohedral',
                         Centering='R',
                         Apply=True)
        OptimizeLatticeForCellType(peaks, CellType='Hexagonal', Apply=True)
        found_ol = peaks.sample().getOrientedLattice()
        self.assertAlmostEqual(found_ol.a(), 6.592, places=2)
        self.assertAlmostEqual(found_ol.b(), 6.592, places=2)
        self.assertAlmostEqual(found_ol.c(), 18.585177, places=2)
        self.assertAlmostEqual(found_ol.alpha(), 90)
        self.assertAlmostEqual(found_ol.beta(), 90)
        self.assertAlmostEqual(found_ol.gamma(), 120)

        # nuclear peaks
        predict = HB3APredictPeaks(
            MD_Q_sample,
            Wavelength=wavelength,
            ReflectionCondition='Rhombohedrally centred, obverse',
            SatellitePeaks=True,
            IncludeIntegerHKL=True)
        predict = HB3AIntegratePeaks(MD_Q_sample, predict, 0.25)

        self.assertEqual(predict.getNumberPeaks(), 66)
        # check that the found peaks are expected
        for n in range(predict.getNumberPeaks()):
            HKL = predict.getPeak(n).getHKL()
            self.assertTrue(HKL in hkl, msg=f"Peak {n} with HKL={HKL}")

        # magnetic peaks
        satellites = HB3APredictPeaks(
            MD_Q_sample,
            Wavelength=wavelength,
            ReflectionCondition='Rhombohedrally centred, obverse',
            SatellitePeaks=True,
            ModVector1='0,0,1.5',
            MaxOrder=1,
            IncludeIntegerHKL=False)
        satellites = HB3AIntegratePeaks(MD_Q_sample, satellites, 0.1)

        self.assertEqual(satellites.getNumberPeaks(), 80)
        # check that the found peaks are expected
        for n in range(satellites.getNumberPeaks()):
            HKL = satellites.getPeak(n).getHKL()
            self.assertTrue(HKL in sat_hkl, msg=f"Peak {n} with HKL={HKL}")
Esempio n. 42
0
import itertools
import numpy as np
from mantid.geometry import SpaceGroupFactory, CrystalStructure

# Parse command line
parser = argparse.ArgumentParser(
    description='Output VAMPIRE unit cell to file')
parser.add_argument('filename', metavar='f', type=str)
args = parser.parse_args()

# String joins
s = ' '
t = ';'

# Space group taken from literature
sg = SpaceGroupFactory.createSpaceGroup("P b n m")

# Unit cell dimensions a, b, c
unit_dim = [5.3170, 5.8348, 7.4202]

# Atom positions
Tb_position = [0.9973, 0.0772, 0.25]
Mn_position = [0.5, 0.0, 0.0]
O1_position = [0.1108, 0.4685, 0.25]
O2_position = [0.7086, 0.3272, 0.0504]

# Generate fractional positions
Tb_equiv = sg.getEquivalentPositions(Tb_position)
Mn_equiv = sg.getEquivalentPositions(Mn_position)

# Generate all O in 3x3
Esempio n. 43
0
    def test_creationFromVector(self):
        spaceGroup = SpaceGroupFactory.createSpaceGroup("P 63/m m c")
        symOps = spaceGroup.getSymmetryOperations()

        group = Group(symOps)
        self.assertEqual(group.getOrder(), spaceGroup.getOrder())
Esempio n. 44
0
    def test_creation(self):
        self.assertRaises(ValueError, SpaceGroupFactory.createSpaceGroup, "none")

        SpaceGroupFactory.createSpaceGroup("I m -3 m")
Esempio n. 45
0
from mantid.simpleapi import *
from mantid.geometry import SymmetryOperationFactory, SpaceGroupFactory
import numpy as np

#symOps = SymmetryOperationFactory.createSymOps("x,y,z; -y,x-y,z+1/3; -x+y,-x,z+2/3; y,x,-z; x-y,-y,-z+2/3; -x,-x+y,-z+1/3")

sg = SpaceGroupFactory.createSpaceGroup("R 3 m")
symOps = sg.getSymmetryOperations()

for sym in symOps:
    symTrans = np.array([
        sym.transformHKL([1, 0, 0]),
        sym.transformHKL([0, 1, 0]),
        sym.transformHKL([0, 0, 1])
    ])
    symTrans = np.matrix(symTrans.T)
    print "Symmetry transform for " + sym.getIdentifier()
    print symTrans
Esempio n. 46
0
from mantid.geometry import SpaceGroupFactory, SymmetryOperationFactory

# symOp = SymmetryOperationFactory.createSymOp("x,y,-z")
#symOps = SymmetryOperationFactory.createSymOps("x,y,-z; -x,-y,-z; z,x,y")
#print "Number of operations:", len(symOps)
#print "Operations:"
#for op in symOps:
#        print op.getIdentifier()

#  three different symmetry operation expressions
#symOps='206'
#symOps='x,y,z; -y,x-y,z+1/3; -x+y,-x,z+2/3; y,x,-z; x-y,-y,-z+2/3; -x,-x+y,-z+1/3'
symOps = 'I a -3'

try:
    symOps = SpaceGroupFactory.subscribedSpaceGroupSymbols(int(symOps))[0]
except ValueError:
    pass
if SpaceGroupFactory.isSubscribedSymbol(symOps):
    symOps = SpaceGroupFactory.createSpaceGroup(symOps).getSymmetryOperations()
else:
    symOps = SymmetryOperationFactory.createSymOps(symOps)

#print "Number of operations:", len(symOps)
#print "Operations:"
#for op in symOps:
#    print op.getIdentifier()

totcoordinate = []
coordinates = [0, 0, 0]
for op in symOps:
Esempio n. 47
0
    def test_creation(self):
        self.assertRaises(ValueError, SpaceGroupFactory.createSpaceGroup,
                          "none")

        SpaceGroupFactory.createSpaceGroup("I m -3 m")
Esempio n. 48
0
    def PyExec(self):  # noqa
        progress = Progress(self, 0.0, 1.0, 5)
        inWS = self.getProperty("InputWorkspace").value
        signal = inWS.getSignalArray().copy()

        dimX = inWS.getXDimension()
        dimY = inWS.getYDimension()
        dimZ = inWS.getZDimension()

        Xmin = dimX.getMinimum()
        Ymin = dimY.getMinimum()
        Zmin = dimZ.getMinimum()
        Xmax = dimX.getMaximum()
        Ymax = dimY.getMaximum()
        Zmax = dimZ.getMaximum()
        Xbins = dimX.getNBins()
        Ybins = dimY.getNBins()
        Zbins = dimZ.getNBins()
        Xwidth = dimX.getBinWidth()
        Ywidth = dimY.getBinWidth()
        Zwidth = dimZ.getBinWidth()

        X = np.linspace(Xmin, Xmax, Xbins + 1)
        Y = np.linspace(Ymin, Ymax, Ybins + 1)
        Z = np.linspace(Zmin, Zmax, Zbins + 1)

        X, Y, Z = np.ogrid[(dimX.getX(0) + dimX.getX(1)) /
                           2:(dimX.getX(Xbins) + dimX.getX(Xbins - 1)) /
                           2:Xbins * 1j, (dimY.getX(0) + dimY.getX(1)) /
                           2:(dimY.getX(Ybins) + dimY.getX(Ybins - 1)) /
                           2:Ybins * 1j, (dimZ.getX(0) + dimZ.getX(1)) /
                           2:(dimZ.getX(Zbins) + dimZ.getX(Zbins - 1)) /
                           2:Zbins * 1j]

        if self.getProperty("RemoveReflections").value:
            progress.report("Removing Reflections")
            size = self.getProperty("Size").value
            if len(size) == 1:
                size = np.repeat(size, 3)
            size /= 2.0  # We want radii or half box width
            cut_shape = self.getProperty("Shape").value
            space_group = self.getProperty("SpaceGroup").value
            if space_group:
                check_space_group = True
                try:
                    space_group = SpaceGroupFactory.subscribedSpaceGroupSymbols(
                        int(space_group))[0]
                except ValueError:
                    pass
                logger.information('Using space group: ' + space_group)
                sg = SpaceGroupFactory.createSpaceGroup(space_group)
            else:
                check_space_group = False

            if cut_shape == 'cube':
                for h in range(int(np.ceil(Xmin)), int(Xmax) + 1):
                    for k in range(int(np.ceil(Ymin)), int(Ymax) + 1):
                        for l in range(int(np.ceil(Zmin)), int(Zmax) + 1):
                            if not check_space_group or sg.isAllowedReflection(
                                [h, k, l]):
                                signal[int((h - size[0] - Xmin) / Xwidth +
                                           1):int((h + size[0] - Xmin) /
                                                  Xwidth),
                                       int((k - size[1] - Ymin) / Ywidth +
                                           1):int((k + size[1] - Ymin) /
                                                  Ywidth),
                                       int((l - size[2] - Zmin) / Zwidth +
                                           1):int((l + size[2] - Zmin) /
                                                  Zwidth)] = np.nan
            else:  # sphere
                mask = ((X - np.round(X))**2 / size[0]**2 +
                        (Y - np.round(Y))**2 / size[1]**2 +
                        (Z - np.round(Z))**2 / size[2]**2 < 1)

                # Unmask invalid reflections
                if check_space_group:
                    for h in range(int(np.ceil(Xmin)), int(Xmax) + 1):
                        for k in range(int(np.ceil(Ymin)), int(Ymax) + 1):
                            for l in range(int(np.ceil(Zmin)), int(Zmax) + 1):
                                if not sg.isAllowedReflection([h, k, l]):
                                    mask[int((h - 0.5 - Xmin) / Xwidth +
                                             1):int((h + 0.5 - Xmin) / Xwidth),
                                         int((k - 0.5 - Ymin) / Ywidth +
                                             1):int((k + 0.5 - Ymin) / Ywidth),
                                         int((l - 0.5 - Zmin) / Zwidth +
                                             1):int((l + 0.5 - Zmin) /
                                                    Zwidth)] = False

                signal[mask] = np.nan

        if self.getProperty("CropSphere").value:
            progress.report("Cropping to sphere")
            sphereMin = self.getProperty("SphereMin").value

            if sphereMin[0] < Property.EMPTY_DBL:
                if len(sphereMin) == 1:
                    sphereMin = np.repeat(sphereMin, 3)
                signal[X**2 / sphereMin[0]**2 + Y**2 / sphereMin[1]**2 +
                       Z**2 / sphereMin[2]**2 < 1] = np.nan

            sphereMax = self.getProperty("SphereMax").value

            if sphereMax[0] < Property.EMPTY_DBL:
                if len(sphereMax) == 1:
                    sphereMax = np.repeat(sphereMax, 3)
                if self.getProperty("FillValue").value == Property.EMPTY_DBL:
                    fill_value = np.nan
                else:
                    fill_value = self.getProperty("FillValue").value
                signal[X**2 / sphereMax[0]**2 + Y**2 / sphereMax[1]**2 +
                       Z**2 / sphereMax[2]**2 > 1] = fill_value

        if self.getProperty("Convolution").value:
            progress.report("Convoluting signal")
            signal = self._convolution(signal)

        if self.getPropertyValue("IntermediateWorkspace"):
            cloneWS_alg = self.createChildAlgorithm("CloneMDWorkspace",
                                                    enableLogging=False)
            cloneWS_alg.setProperty("InputWorkspace", inWS)
            cloneWS_alg.execute()
            signalOutWS = cloneWS_alg.getProperty("OutputWorkspace").value
            signalOutWS.setSignalArray(signal)
            self.setProperty("IntermediateWorkspace", signalOutWS)

        # Do FFT
        progress.report("Running FFT")
        # Replace any remaining nan's or inf's with 0
        # Otherwise you end up with a lot of nan's
        signal[np.isnan(signal)] = 0
        signal[np.isinf(signal)] = 0

        signal = np.fft.fftshift(np.fft.fftn(np.fft.ifftshift(signal)))
        number_of_bins = signal.shape

        # Do deconvolution
        if self.getProperty("Convolution").value and self.getProperty(
                "Deconvolution").value:
            signal /= self._deconvolution(np.array(signal.shape))

        # CreateMDHistoWorkspace expects Fortan `column-major` ordering
        signal = signal.real.flatten('F')

        createWS_alg = self.createChildAlgorithm("CreateMDHistoWorkspace",
                                                 enableLogging=False)
        createWS_alg.setProperty("SignalInput", signal)
        createWS_alg.setProperty("ErrorInput", signal**2)
        createWS_alg.setProperty("Dimensionality", 3)
        createWS_alg.setProperty("Extents", self._calc_new_extents(inWS))
        createWS_alg.setProperty("NumberOfBins", number_of_bins)
        createWS_alg.setProperty("Names", 'x,y,z')
        createWS_alg.setProperty("Units", 'a,b,c')
        createWS_alg.execute()
        outWS = createWS_alg.getProperty("OutputWorkspace").value

        # Copy first experiment info
        if inWS.getNumExperimentInfo() > 0:
            outWS.copyExperimentInfos(inWS)

        progress.report()

        self.setProperty("OutputWorkspace", outWS)
Esempio n. 49
0
          OutputWorkspace='flux')
LoadNexus(Filename='/SNS/CORELLI/shared/Vanadium/SolidAngle20161123_cc.nxs',
          OutputWorkspace='sa')

# Get UBs
LoadEmptyInstrument(
    Filename=
    '/SNS/CORELLI/shared/Calibration/CORELLI_Definition_cal_20160310.xml',
    OutputWorkspace='ub')
LoadIsawUB(InputWorkspace='ub', Filename=UBfile)
ub = mtd['ub'].sample().getOrientedLattice().getUB()
print "Starting UB :"
print ub

#PMN   pm-3m (227)  general position has 48 symmety operations.
sg = SpaceGroupFactory.createSpaceGroup("P m -3 m")
symOps = sg.getSymmetryOperations()

ub_list = []
for sym in symOps:
    UBtrans = np.zeros((3, 3))
    UBtrans[0] = sym.transformHKL([1, 0, 0])
    UBtrans[1] = sym.transformHKL([0, 1, 0])
    UBtrans[2] = sym.transformHKL([0, 0, 1])
    UBtrans = np.matrix(UBtrans.T)
    new_ub = ub * UBtrans
    print "Symmetry transform for " + sym.getIdentifier()
    print UBtrans
    print "New UB:"
    print new_ub
    ub_list.append(new_ub)
Esempio n. 50
0
    def PyExec(self): # noqa
        progress = Progress(self, 0.0, 1.0, 5)
        inWS = self.getProperty("InputWorkspace").value
        signal = inWS.getSignalArray().copy()

        dimX=inWS.getXDimension()
        dimY=inWS.getYDimension()
        dimZ=inWS.getZDimension()

        Xmin=dimX.getMinimum()
        Ymin=dimY.getMinimum()
        Zmin=dimZ.getMinimum()
        Xmax=dimX.getMaximum()
        Ymax=dimY.getMaximum()
        Zmax=dimZ.getMaximum()
        Xbins=dimX.getNBins()
        Ybins=dimY.getNBins()
        Zbins=dimZ.getNBins()
        Xwidth=dimX.getBinWidth()
        Ywidth=dimY.getBinWidth()
        Zwidth=dimZ.getBinWidth()

        X=np.linspace(Xmin,Xmax,Xbins+1)
        Y=np.linspace(Ymin,Ymax,Ybins+1)
        Z=np.linspace(Zmin,Zmax,Zbins+1)

        X, Y, Z = np.ogrid[(dimX.getX(0)+dimX.getX(1))/2:(dimX.getX(Xbins)+dimX.getX(Xbins-1))/2:Xbins*1j,
                           (dimY.getX(0)+dimY.getX(1))/2:(dimY.getX(Ybins)+dimY.getX(Ybins-1))/2:Ybins*1j,
                           (dimZ.getX(0)+dimZ.getX(1))/2:(dimZ.getX(Zbins)+dimZ.getX(Zbins-1))/2:Zbins*1j]

        if self.getProperty("RemoveReflections").value:
            progress.report("Removing Reflections")
            size = self.getProperty("Size").value
            if len(size)==1:
                size = np.repeat(size, 3)
            size/=2.0 # We want radii or half box width
            cut_shape = self.getProperty("Shape").value
            space_group = self.getProperty("SpaceGroup").value
            if space_group:
                check_space_group = True
                try:
                    space_group=SpaceGroupFactory.subscribedSpaceGroupSymbols(int(space_group))[0]
                except ValueError:
                    pass
                logger.information('Using space group: '+space_group)
                sg=SpaceGroupFactory.createSpaceGroup(space_group)
            else:
                check_space_group = False

            if cut_shape == 'cube':
                for h in range(int(np.ceil(Xmin)), int(Xmax)+1):
                    for k in range(int(np.ceil(Ymin)), int(Ymax)+1):
                        for l in range(int(np.ceil(Zmin)), int(Zmax)+1):
                            if not check_space_group or sg.isAllowedReflection([h,k,l]):
                                signal[int((h-size[0]-Xmin)/Xwidth+1):int((h+size[0]-Xmin)/Xwidth),
                                       int((k-size[1]-Ymin)/Ywidth+1):int((k+size[1]-Ymin)/Ywidth),
                                       int((l-size[2]-Zmin)/Zwidth+1):int((l+size[2]-Zmin)/Zwidth)]=np.nan
            else:  # sphere
                mask=((X-np.round(X))**2/size[0]**2 + (Y-np.round(Y))**2/size[1]**2 + (Z-np.round(Z))**2/size[2]**2 < 1)

                # Unmask invalid reflections
                if check_space_group:
                    for h in range(int(np.ceil(Xmin)), int(Xmax)+1):
                        for k in range(int(np.ceil(Ymin)), int(Ymax)+1):
                            for l in range(int(np.ceil(Zmin)), int(Zmax)+1):
                                if not sg.isAllowedReflection([h,k,l]):
                                    mask[int((h-0.5-Xmin)/Xwidth+1):int((h+0.5-Xmin)/Xwidth),
                                         int((k-0.5-Ymin)/Ywidth+1):int((k+0.5-Ymin)/Ywidth),
                                         int((l-0.5-Zmin)/Zwidth+1):int((l+0.5-Zmin)/Zwidth)]=False

                signal[mask]=np.nan

        if self.getProperty("CropSphere").value:
            progress.report("Cropping to sphere")
            sphereMin = self.getProperty("SphereMin").value

            if sphereMin[0] < Property.EMPTY_DBL:
                if len(sphereMin)==1:
                    sphereMin = np.repeat(sphereMin, 3)
                signal[X**2/sphereMin[0]**2 + Y**2/sphereMin[1]**2 + Z**2/sphereMin[2]**2 < 1]=np.nan

            sphereMax = self.getProperty("SphereMax").value

            if sphereMax[0] < Property.EMPTY_DBL:
                if len(sphereMax)==1:
                    sphereMax = np.repeat(sphereMax, 3)
                if self.getProperty("FillValue").value == Property.EMPTY_DBL:
                    fill_value = np.nan
                else:
                    fill_value = self.getProperty("FillValue").value
                signal[X**2/sphereMax[0]**2 + Y**2/sphereMax[1]**2 + Z**2/sphereMax[2]**2 > 1]=fill_value

        if self.getProperty("Convolution").value:
            progress.report("Convoluting signal")
            signal = self._convolution(signal)

        if self.getPropertyValue("IntermediateWorkspace"):
            cloneWS_alg = self.createChildAlgorithm("CloneMDWorkspace", enableLogging=False)
            cloneWS_alg.setProperty("InputWorkspace",inWS)
            cloneWS_alg.execute()
            signalOutWS = cloneWS_alg.getProperty("OutputWorkspace").value
            signalOutWS.setSignalArray(signal)
            self.setProperty("IntermediateWorkspace", signalOutWS)

        # Do FFT
        progress.report("Running FFT")
        # Replace any remaining nan's or inf's with 0
        # Otherwise you end up with a lot of nan's
        signal[np.isnan(signal)]=0
        signal[np.isinf(signal)]=0

        signal=np.fft.fftshift(np.fft.fftn(np.fft.ifftshift(signal)))
        number_of_bins = signal.shape

        # Do deconvolution
        if self.getProperty("Convolution").value and self.getProperty("Deconvolution").value:
            signal /= self._deconvolution(np.array(signal.shape))

        # CreateMDHistoWorkspace expects Fortan `column-major` ordering
        signal = signal.real.flatten('F')

        createWS_alg = self.createChildAlgorithm("CreateMDHistoWorkspace", enableLogging=False)
        createWS_alg.setProperty("SignalInput", signal)
        createWS_alg.setProperty("ErrorInput", signal**2)
        createWS_alg.setProperty("Dimensionality", 3)
        createWS_alg.setProperty("Extents", self._calc_new_extents(inWS))
        createWS_alg.setProperty("NumberOfBins", number_of_bins)
        createWS_alg.setProperty("Names", 'x,y,z')
        createWS_alg.setProperty("Units", 'a,b,c')
        createWS_alg.execute()
        outWS = createWS_alg.getProperty("OutputWorkspace").value

        # Copy first experiment info
        if inWS.getNumExperimentInfo() > 0:
            outWS.copyExperimentInfos(inWS)

        progress.report()

        self.setProperty("OutputWorkspace", outWS)
Esempio n. 51
0
#peaksFile = '%s%s/peaks_combined_good.integrate'%(workDir,descriptorTOF)
peaksFile = '%s%s/peaks_%i_%s.integrate'%(workDir,descriptorTOF, sampleRuns[-1], descriptorTOF)
ellipseFile = '/SNS/users/ntv/integrate/corelli_beryl/combined_hexagonal_indexedonly.integrate'
pg = PointGroupFactory.createPointGroup("6/mmm")
'''
#Beta lactamase mutant
sampleRuns = range(5921, 5931 + 1)
workDir = '/SNS/users/ntv/dropbox/'
descriptorBVG = 'beta_lac_3D_mbvg_mutant_newppl'
descriptorTOF = 'beta_lac_lab_highres_mut2'
peaksFile = '%s%s/peaks_combined_good.integrate' % (workDir, descriptorTOF)
#peaksFile = '%s%s/peaks_%i_%s.integrate'%(workDir,descriptorTOF, sampleRuns[-1], descriptorTOF)
#ellipseFile = '/SNS/users/ntv/integrate/mandi_betalactamase/MANDI_betalactamase_2.integrate'
#ellipseFile = '/SNS/users/ntv/integrate/mandi_betalactamase/combined_triclinic.integrate'
ellipseFile = '/SNS/users/ntv/integrate/mandi_beta_lactamase3/combined.integrate'
sg = SpaceGroupFactory.createSpaceGroup("P 32 2 1")
pg = PointGroupFactory.createPointGroupFromSpaceGroup(sg)
'''
#pth
sampleRuns = [870,872,873,874,875,876]
workDir = '/SNS/users/ntv/dropbox/'
descriptorBVG = 'pth_3d'
descriptorTOF = 'pth_tof_secondRun'
peaksFile = '%s%s/peaks_combined_good.integrate'%(workDir,descriptorTOF)
#peaksFile = '%s%s/peaks_%i_%s.integrate'%(workDir,descriptorTOF, sampleRuns[-1], descriptorTOF)
ellipseFile = '/SNS/users/ntv/integrate/mandi_pth/peaks_combined.integrate'
sg = SpaceGroupFactory.createSpaceGroup("P 61 2 2")
pg = PointGroupFactory.createPointGroupFromSpaceGroup(sg)
'''
'''
#gfp
          OutputWorkspace='sa')

# Get UBs
LoadEmptyInstrument(
    Filename=
    '/SNS/CORELLI/shared/Calibration/CORELLI_Definition_cal_20160310.xml',
    OutputWorkspace='ub')
LoadIsawUB(InputWorkspace='ub', Filename=outputdir + UBname)
ub = mtd['ub'].sample().getOrientedLattice().getUB()
print "Starting UB :"
print ub

#symOps = SymmetryOperationFactory.createSymOps(" x, y, z;  -x ,-y, z;  -x,y,-z;  x,-y,-z;-x,-y,-z;  x,y,-z; x,-y,z; -x,y,z")
#symOps = SymmetryOperationFactory.createSymOps("x, y, z;x,-y,-z; x,y,-z; x,-y,z")
#symOps = SymmetryOperationFactory.createSymOps("x, y, z")
symOps = SpaceGroupFactory.createSpaceGroup('P 2 3').getSymmetryOperations()

ub_list = []
for sym in symOps:
    UBtrans = np.zeros((3, 3))
    UBtrans[0] = sym.transformHKL([1, 0, 0])
    UBtrans[1] = sym.transformHKL([0, 1, 0])
    UBtrans[2] = sym.transformHKL([0, 0, 1])
    UBtrans = np.matrix(UBtrans.T)
    new_ub = ub * UBtrans
    print "Symmetry transform for " + sym.getIdentifier()
    print UBtrans
    print "New UB:"
    print new_ub
    ub_list.append(new_ub)