def testis_diffracting(self):
        #TODO: Test is_diffractiong() with other cases
        plane1 = plane.Plane(1, 1, 1)
        plane2 = plane.Plane(1, 0, 1)

        # FCC
        self.assertTrue(
            calculations.is_diffracting(plane1, self.cubic, self.atomsfcc,
                                        self.scatter))
        self.assertFalse(
            calculations.is_diffracting(plane2, self.cubic, self.atomsfcc,
                                        self.scatter))

        # BCC
        self.assertFalse(
            calculations.is_diffracting(plane1, self.cubic, self.atomsbcc,
                                        self.scatter))
        self.assertTrue(
            calculations.is_diffracting(plane2, self.cubic, self.atomsbcc,
                                        self.scatter))

        # HCP
        self.assertFalse(
            calculations.is_diffracting(plane1, self.hexagonal, self.atomshcp,
                                        self.scatter))
        self.assertTrue(
            calculations.is_diffracting(plane2, self.hexagonal, self.atomshcp,
                                        self.scatter))
 def testinterplanarangle(self):
     # Problem 2.15
     plane1 = plane.Plane(1, 0, 0)
     plane2 = plane.Plane(1, 1, 0)
     angle = calculations.interplanarangle(plane1, plane2, self.L4)
     angle *= 180 / pi
     self.assertAlmostEqual(angle, 44.7387, 3)
    def testzoneaxis(self):
        # Example 2.16
        plane1 = plane.Plane(-0.0963, 0.1243, 0.2018)
        plane2 = plane.Plane(0.1084, -0.0880, 0.2947)
        zone = calculations.zoneaxis(plane1, plane2, self.L3)
        expected_zone = [1.0219, 0.8478, 0.0888]
        self.assertTrue(vectors.almostequal(zone, expected_zone, 3))

        # Problem 2.9
        plane1 = plane.Plane(0.1166, 0.0968, 0.0101)
        plane2 = plane.Plane(-0.0286, 0.0369, 0.0599)
        zone = calculations.zoneaxis(plane1, plane2, self.L3)
        expected_zone = [0.0895, -0.097, -0.0030]
        self.assertTrue(vectors.almostequal(zone, expected_zone, 3))
    def testdiffraction_intensity(self):
        plane1 = plane.Plane(1, 1, 1)
        plane2 = plane.Plane(1, 0, 1)

        # FCC
        intensity = calculations.diffraction_intensity(plane1, self.cubic,
                                                       self.atomsfcc,
                                                       self.scatter)
        expected_intensity = 757.78198507326738
        self.assertAlmostEqual(intensity, expected_intensity)

        intensity = calculations.diffraction_intensity(plane2, self.cubic,
                                                       self.atomsfcc,
                                                       self.scatter)
        expected_intensity = 0
        self.assertAlmostEqual(intensity, expected_intensity)

        # BCC
        intensity = calculations.diffraction_intensity(plane1, self.cubic,
                                                       self.atomsbcc,
                                                       self.scatter)
        expected_intensity = 0
        self.assertAlmostEqual(intensity, expected_intensity)

        intensity = calculations.diffraction_intensity(plane2, self.cubic,
                                                       self.atomsbcc,
                                                       self.scatter)
        expected_intensity = 234.69367215181771
        self.assertAlmostEqual(intensity, expected_intensity)

        # HCP
        intensity = calculations.diffraction_intensity(plane1, self.cubic,
                                                       self.atomshcp,
                                                       self.scatter)
        expected_intensity = 0
        self.assertAlmostEqual(intensity, expected_intensity)

        intensity = calculations.diffraction_intensity(plane2, self.cubic,
                                                       self.atomshcp,
                                                       self.scatter)
        expected_intensity = 176.02025411386322
        self.assertAlmostEqual(intensity, expected_intensity)
    def testformfactor(self):
        plane1 = plane.Plane(1, 1, 1)
        plane2 = plane.Plane(1, 0, 1)

        # FCC
        formfactor = calculations.formfactor(plane1, self.cubic, self.atomsfcc,
                                             self.scatter)
        expected_formfactor = 27.527840181773566
        self.assertAlmostEqual(abs(formfactor), expected_formfactor)

        formfactor = calculations.formfactor(plane2, self.cubic, self.atomsfcc,
                                             self.scatter)
        expected_formfactor = 0
        self.assertAlmostEqual(abs(formfactor), expected_formfactor)

        # BCC
        formfactor = calculations.formfactor(plane1, self.cubic, self.atomsbcc,
                                             self.scatter)
        expected_formfactor = 0
        self.assertAlmostEqual(abs(formfactor), expected_formfactor)

        formfactor = calculations.formfactor(plane2, self.cubic, self.atomsbcc,
                                             self.scatter)
        expected_formfactor = 15.319715145909786
        self.assertAlmostEqual(abs(formfactor), expected_formfactor)

        # HCP
        formfactor = calculations.formfactor(plane1, self.hexagonal,
                                             self.atomshcp, self.scatter)
        expected_formfactor = 0
        self.assertAlmostEqual(abs(formfactor), expected_formfactor)

        formfactor = calculations.formfactor(plane2, self.hexagonal,
                                             self.atomshcp, self.scatter)
        expected_formfactor = complex(11.800945464186695, -6.8132790404402881)
        self.assertAlmostEqual(formfactor.real, expected_formfactor.real)
        self.assertAlmostEqual(formfactor.imag, expected_formfactor.imag)
Exemple #6
0
    def setUp(self):
        unittest.TestCase.setUp(self)

        self.plane1 = plane.Plane(3, 3, 3)
        self.plane2 = plane.Plane(1, -2, 1, 0)
        self.plane3 = plane.Plane(-1, -2, 1, 0)
 def testare_planes_equivalent(self):
     plane1 = plane.Plane(1, 1, 1)
     plane2 = plane.Plane(-1, -1, -1)
     self.assertTrue(
         calculations.are_planes_equivalent(plane1, plane2, self.cubic))
    def setUp(self):
        unittest.TestCase.setUp(self)

        # Manual testing
        self.cubic = unitcell.create_cubic_unitcell(2)
        self.tetragonal = unitcell.create_tetragonal_unitcell(2, 3)
        self.orthorhombic = unitcell.create_orthorhombic_unitcell(1, 2, 3)
        self.trigonal = unitcell.create_trigonal_unitcell(2, 35.0 / 180 * pi)
        self.hexagonal = unitcell.create_hexagonal_unitcell(2, 3)
        self.monoclinic = unitcell.create_monoclinic_unitcell(
            1, 2, 3, 55.0 / 180 * pi)
        self.triclinic = \
            unitcell.create_triclinic_unitcell(1, 2, 3,
                                               75.0 / 180 * pi, 55.0 / 180 * pi, 35.0 / 180 * pi)

        self.planes = [
            plane.Plane(1, 0, 0),
            plane.Plane(1, 1, 0),
            plane.Plane(1, 1, 1),
            plane.Plane(2, 0, 2),
            plane.Plane(1, 2, 3),
            plane.Plane(4, 5, 6),
            plane.Plane(0, 9, 2)
        ]

        # Example 1.13 from Mathematical Crystallography (p.31-33)
        self.L1 = unitcell.create_hexagonal_unitcell(4.914, 5.409)

        self.atom1 = atomsite.AtomSite(8, (0.4141, 0.2681, 0.1188))
        self.atom2 = atomsite.AtomSite(14, (0.4699, 0.0, 0.0))
        self.atom3 = atomsite.AtomSite(14, (0.5301, 0.5301, 0.3333))

        # Problem 1.13 from Mathematical Crystallography (p.34)
        alpha = 93.11 / 180.0 * pi
        beta = 115.91 / 180.0 * pi
        gamma = 91.26 / 180.0 * pi
        self.L2 = unitcell.create_triclinic_unitcell(8.173, 12.869, 14.165,
                                                     alpha, beta, gamma)

        self.atom4 = atomsite.AtomSite(8, (0.3419, 0.3587, 0.1333))
        self.atom5 = atomsite.AtomSite(14, (0.5041, 0.3204, 0.1099))
        self.atom6 = atomsite.AtomSite(13, (0.1852, 0.3775, 0.1816))

        # Example 2.16 and Problem 2.9 from Mathematical Crystallography (p.64-65)
        alpha = 114.27 / 180.0 * pi
        beta = 82.68 / 180.0 * pi
        gamma = 94.58 / 180.0 * pi
        self.L3 = unitcell.create_triclinic_unitcell(6.621, 7.551, 17.381,
                                                     alpha, beta, gamma)

        # Problem 2.15 from Mathematical Crystallography (p.79)
        alpha = 113.97 / 180.0 * pi
        beta = 98.64 / 180.0 * pi
        gamma = 67.25 / 180.0 * pi
        self.L4 = unitcell.create_triclinic_unitcell(5.148, 7.251, 5.060,
                                                     alpha, beta, gamma)

        # Scattering factors
        relativepath = os.path.join('..', 'testdata', 'goodconfiguration.cfg')
        configurationfilepath = Files.getCurrentModulePath(
            __file__, relativepath)

        self.scatter = scatteringfactors.XrayScatteringFactors(
            configurationfilepath)

        # Atom sites
        self.atomsfcc = atomsites.AtomSites([
            atomsite.AtomSite(14, 0.5, 0.5, 0.0),
            atomsite.AtomSite(14, 0.5, 0.0, 0.5),
            atomsite.AtomSite(14, 0.0, 0.5, 0.5),
            atomsite.AtomSite(14, 0.0, 0.0, 0.0)
        ])

        self.atomsbcc = atomsites.AtomSites([
            atomsite.AtomSite(14, 0.5, 0.5, 0.5),
            atomsite.AtomSite(14, 0.0, 0.0, 0.0)
        ])

        self.atomshcp = atomsites.AtomSites([
            atomsite.AtomSite(14, 1 / 3.0, 2 / 3.0, 0.5),
            atomsite.AtomSite(14, 0.0, 0.0, 0.0)
        ])
 def testplanespacing(self):
     # Example 2.3
     hkl = plane.Plane(3, 1, 2)
     self.assertAlmostEqual(calculations.planespacing(hkl, self.L2), 1.964,
                            3)