Example #1
0
    def test_crystal_structure_handling(self):
        sample = self._ws.sample()

        self.assertEquals(sample.hasCrystalStructure(), False)
        self.assertRaises(RuntimeError, sample.getCrystalStructure)

        cs = CrystalStructure('5.43 5.43 5.43',
                              'F d -3 m',
                              'Si 0 0 0 1.0 0.01')

        sample.setCrystalStructure(cs)

        self.assertEquals(sample.hasCrystalStructure(), True)

        cs_from_sample = sample.getCrystalStructure()

        self.assertEquals(cs.getSpaceGroup().getHMSymbol(), cs_from_sample.getSpaceGroup().getHMSymbol())
        self.assertEquals(cs.getUnitCell().a(), cs_from_sample.getUnitCell().a())
        self.assertEquals(len(cs.getScatterers()), len(cs_from_sample.getScatterers()))
        self.assertEquals(cs.getScatterers()[0], cs_from_sample.getScatterers()[0])


        sample.clearCrystalStructure()

        self.assertEquals(sample.hasCrystalStructure(), False)
        self.assertRaises(RuntimeError, sample.getCrystalStructure)
Example #2
0
    def test_crystal_structure_handling(self):
        sample = self._ws.sample()

        self.assertEquals(sample.hasCrystalStructure(), False)
        self.assertRaises(RuntimeError, sample.getCrystalStructure)

        cs = CrystalStructure('5.43 5.43 5.43',
                              'F d -3 m',
                              'Si 0 0 0 1.0 0.01')

        sample.setCrystalStructure(cs)

        self.assertEquals(sample.hasCrystalStructure(), True)

        cs_from_sample = sample.getCrystalStructure()

        self.assertEquals(cs.getSpaceGroup().getHMSymbol(), cs_from_sample.getSpaceGroup().getHMSymbol())
        self.assertEquals(cs.getUnitCell().a(), cs_from_sample.getUnitCell().a())
        self.assertEquals(len(cs.getScatterers()), len(cs_from_sample.getScatterers()))
        self.assertEquals(cs.getScatterers()[0], cs_from_sample.getScatterers()[0])


        sample.clearCrystalStructure()

        self.assertEquals(sample.hasCrystalStructure(), False)
        self.assertRaises(RuntimeError, sample.getCrystalStructure)
    def _update_distributions_and_weights(self):
        crystal_structure = CrystalStructure(str(self._unit_cell), str(self._space_group), str(self._atoms))
        reflection_generator = ReflectionGenerator(crystal_structure)

        # Calculate all unique reflections within the specified resolution limits, including structure factors
        unique_hkls = reflection_generator.getUniqueHKLs(self.d_min, self.d_max)
        structure_factors = reflection_generator.getFsSquared(unique_hkls)

        # Calculate multiplicities of the reflections
        point_group = crystal_structure.getSpaceGroup().getPointGroup()
        multiplicities = [len(point_group.getEquivalents(hkl)) for hkl in unique_hkls]

        # Calculate weights as F^2 * multiplicity and normalize so that Sum(weights) = 1
        weights = np.array([x * y for x, y in zip(structure_factors, multiplicities)])
        self._parameter_lock.acquire()
        self._peak_weights = weights / sum(weights)

        d_values = reflection_generator.getDValues(unique_hkls)
        self._peak_distributions = [partial(np.random.normal, loc=d, scale=self._relative_sigma * d) for d in d_values]
        self._parameter_lock.release()
Example #4
0
    def test_SpaceGroup(self):
        structure = CrystalStructure("5.43 5.42 5.41", "F d -3 m", "Al 1/3 0.454 1/12 1.0 0.01")
        spaceGroup = structure.getSpaceGroup()

        self.assertEqual(spaceGroup.getHMSymbol(), "F d -3 m")
    def test_SpaceGroup(self):
        structure = CrystalStructure("5.43 5.42 5.41", "F d -3 m",
                                     "Al 1/3 0.454 1/12 1.0 0.01")
        spaceGroup = structure.getSpaceGroup()

        self.assertEqual(spaceGroup.getHMSymbol(), "F d -3 m")