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]
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]
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
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 _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()
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
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)
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:
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)