Exemple #1
0
    def structf(self):
        sample_ws = CreateSampleWorkspace()
        LoadCIF(sample_ws, self.cif)
        self.sample = sample_ws.sample().getCrystalStructure()
        self.generator = ReflectionGenerator(self.sample)
        if self.unique == True:
            hkls = self.generator.getUniqueHKLsUsingFilter(
                self.qrange[0], self.qrange[1],
                ReflectionConditionFilter.StructureFactor)
        else:
            hkls = self.generator.getHKLsUsingFilter(
                self.qrange[0], self.qrange[1],
                ReflectionConditionFilter.StructureFactor)

        pg = self.sample.getSpaceGroup().getPointGroup()

        df = pd.DataFrame(data=np.array(hkls), columns=list('hkl'))

        df['d(A)'] = self.generator.getDValues(hkls)
        df['F^2'] = self.generator.getFsSquared(hkls)
        df['hkl'] = hkls
        df['M'] = df['hkl'].map(lambda x: len(pg.getEquivalents(x)))
        df['II_powder'] = df['F^2'] * df['M']
        df['q'] = 2 * np.pi / df['d(A)']
        df['qh'] = df['h'].map(lambda x: np.sign(x) * 2 * np.pi / self.
                               generator.getDValues([V3D(x, 0, 0)])[0])
        df['qk'] = df['k'].map(lambda x: np.sign(x) * 2 * np.pi / self.
                               generator.getDValues([V3D(0, x, 0)])[0])
        df['ql'] = df['l'].map(lambda x: np.sign(x) * 2 * np.pi / self.
                               generator.getDValues([V3D(0, 0, x)])[0])
        self.data = df
 def test_computeincoherentdos(self):
     ws = CreateSampleWorkspace()
     # Will fail unless the input workspace has Q and DeltaE axes.
     with self.assertRaises(RuntimeError):
         ws_DOS = ComputeIncoherentDOS(ws)
     ws = CreateSampleWorkspace(XUnit = 'DeltaE')
     with self.assertRaises(RuntimeError):
         ws_DOS = ComputeIncoherentDOS(ws)
     # Creates a workspace with two optic phonon modes at +E and -E with Q^2 dependence and population correct for T=300K
     ws = self.createPhononWS(300, 5, 'DeltaE')
     # This should work!
     ws_DOS = ComputeIncoherentDOS(ws)
     self.assertEqual(ws_DOS.getAxis(0).getUnit().unitID(), 'DeltaE')
     self.assertEqual(ws_DOS.getNumberHistograms(), 1)
     # Checks that it works if the workspace has |Q| along x instead of y, and converts energy to wavenumber
     ws = Transpose(ws)
     ws_DOS = ComputeIncoherentDOS(ws, Temperature = 300, EnergyBinning = '-20, 0.2, 20', Wavenumbers = True)
     self.assertEqual(ws_DOS.getAxis(0).getUnit().unitID(), 'DeltaE_inWavenumber')
     self.assertEqual(ws_DOS.blocksize(), 200)
     # Checks that the Bose factor correction is ok.
     dos_eplus = np.max(ws_DOS.readY(0)[100:200])
     dos_eminus = np.max(ws_DOS.readY(0)[:100])
     self.assertAlmostEqual(dos_eplus / dos_eminus, 1., places=1)
     # Check that unit conversion from cm^-1 to meV works and also that conversion to states/meV is done
     ws = self.convertToWavenumber(ws)
     SetSampleMaterial(ws, 'Al')
     ws_DOSn = ComputeIncoherentDOS(ws, EnergyBinning = '-160, 1.6, 160', StatesPerEnergy = True)
     self.assertTrue('states' in ws_DOSn.YUnitLabel())
     self.assertEqual(ws_DOSn.getAxis(0).getUnit().unitID(), 'DeltaE')
     material = ws.sample().getMaterial()
     factor = material.relativeMolecularMass() / (material.totalScatterXSection() * 1000) * 4 * np.pi
     self.assertAlmostEqual(np.max(ws_DOSn.readY(0)) / (np.max(ws_DOS.readY(0))*factor), 1., places=1)
 def test_computeincoherentdos(self):
     ws = CreateSampleWorkspace()
     # Will fail unless the input workspace has Q and DeltaE axes.
     with self.assertRaises(RuntimeError):
         ws_DOS = ComputeIncoherentDOS(ws)
     ws = CreateSampleWorkspace(XUnit = 'DeltaE')
     with self.assertRaises(RuntimeError):
         ws_DOS = ComputeIncoherentDOS(ws)
     # Creates a workspace with two optic phonon modes at +E and -E with Q^2 dependence and population correct for T=300K
     ws = self.createPhononWS(300, 5, 'DeltaE')
     # This should work!
     ws_DOS = ComputeIncoherentDOS(ws)
     self.assertEquals(ws_DOS.getAxis(0).getUnit().unitID(), 'DeltaE')
     self.assertEquals(ws_DOS.getNumberHistograms(), 1)
     # Checks that it works if the workspace has |Q| along x instead of y, and converts energy to wavenumber
     ws = Transpose(ws)
     ws_DOS = ComputeIncoherentDOS(ws, Temperature = 300, EnergyBinning = '-20, 0.2, 20', Wavenumbers = True)
     self.assertEquals(ws_DOS.getAxis(0).getUnit().unitID(), 'DeltaE_inWavenumber')
     self.assertEquals(ws_DOS.blocksize(), 200)
     # Checks that the Bose factor correction is ok.
     dos_eplus = np.max(ws_DOS.readY(0)[100:200])
     dos_eminus = np.max(ws_DOS.readY(0)[:100])
     self.assertAlmostEqual(dos_eplus / dos_eminus, 1., places=1)
     # Check that unit conversion from cm^-1 to meV works and also that conversion to states/meV is done
     ws = self.convertToWavenumber(ws)
     SetSampleMaterial(ws, 'Al')
     ws_DOSn = ComputeIncoherentDOS(ws, EnergyBinning = '-160, 1.6, 160', StatesPerEnergy = True)
     self.assertTrue('states' in ws_DOSn.YUnitLabel())
     self.assertEquals(ws_DOSn.getAxis(0).getUnit().unitID(), 'DeltaE')
     material = ws.sample().getMaterial()
     factor = material.relativeMolecularMass() / (material.totalScatterXSection() * 1000) * 4 * np.pi
     self.assertAlmostEqual(np.max(ws_DOSn.readY(0)) / (np.max(ws_DOS.readY(0))*factor), 1., places=1)
Exemple #4
0
 def loadUBFiles(self, ubFiles, omegaHand, phiHand, omegaLogName,
                 phiLogName):
     """
     load the ub files and update the
     :param ubFiles: list of paths to saved UB files
     :param omegaHand: handedness of omega rotation (ccw/cw)
     :param phiHand: handedness of phi rotation (ccw/cw)
     :param omegaLogName: name of log entry for omega angle
     :param phiLogName: name of log entry for phi angle
     :return: matUB: list containing the UB for each run
     :return: omega: array of omega values from log of each run
     :return: phiRef: array of nominal phi values from log of each run
     """
     matUB = []  # container to hold UB matrix arrays
     omega = np.zeros(
         len(ubFiles))  # rot around vertical axis (assumed to be correct)
     phiRef = np.zeros(
         len(ubFiles))  # rot around gonio axis (needs to be refined)
     for irun in range(0, len(ubFiles)):
         # get rotation angles from logs (handedness given in input)
         # these rotation matrices are defined in right-handed coordinate system (i.e. omegaHand = 1 etc.)
         _, fname = path.split(ubFiles[irun])
         dataPath = FileFinder.findRuns(fname.split('.mat')[0])[0]
         tmpWS = CreateSampleWorkspace(StoreInADS=False)
         if dataPath[-4:] == ".raw":
             # assume log is kept separately in a .log file with same path
             LoadLog(Workspace=tmpWS,
                     Filename="".join(dataPath[:-4] + '.log'))
         elif dataPath[-4:] == '.nxs':
             # logs are kept with data in nexus file
             LoadNexusLogs(Workspace=tmpWS, Filename=dataPath)
         # read omega and phi (in RH coords)
         omega[irun] = omegaHand * tmpWS.getRun().getLogData(
             omegaLogName).value[0]
         phiRef[irun] = phiHand * tmpWS.getRun().getLogData(
             phiLogName).value[0]
         # load UB
         LoadIsawUB(InputWorkspace=tmpWS,
                    Filename=ubFiles[irun],
                    CheckUMatrix=True)
         tmpUB = tmpWS.sample().getOrientedLattice().getUB()
         # permute axes to use IPNS convention (as in saved .mat file)
         matUB += [tmpUB[[2, 0, 1], :]]
     DeleteWorkspace(tmpWS)
     return matUB, omega, phiRef