Exemple #1
0
    def _perfectCrystalForPhoton(self, diffraction_setup, polarized_photon):

        energy = polarized_photon.energy()

        # Retrieve bragg angle.
        angle_bragg = diffraction_setup.angleBragg(energy)

        if False:  # this is "commented" by srio to speed it up!
            F_0 = diffraction_setup.F0(energy)
            F_H = diffraction_setup.FH(energy)
            F_H_bar = diffraction_setup.FH_bar(energy)

            # Check if given Bragg/Laue geometry and given miller indices are possible.
            self._checkSetup(diffraction_setup, angle_bragg, F_0, F_H, F_H_bar)

            # Log the structure factors.
            if self.isDebug:
                self.logStructureFactors(F_0, F_H, F_H_bar)
        else:
            # Check if given Bragg/Laue geometry and given miller indices are possible.
            self._checkSetupDiffraction(diffraction_setup, angle_bragg)

            # Log the structure factors.
            if self.isDebug:
                self.logStructureFactorsPsi(F_0, F_H, F_H_bar)

        # Retrieve lattice spacing d.
        d_spacing = diffraction_setup.dSpacing() * 1e-10

        # Calculate the Bragg normal B_H.
        normal_bragg = diffraction_setup.normalBragg()

        # Calculate the surface normal n.
        normal_surface = diffraction_setup.normalSurface()

        # Retrieve unitcell volume from xraylib.
        # unitcell_volume = diffraction_setup.unitcellVolume() * 10 ** -30

        # Calculate psis as defined in Zachariasen [3-95]

        # lumped together by srio
        # psi_0     = diffraction_setup.psi0(energy)     # self._calculatePsiFromStructureFactor(unitcell_volume, polarized_photon, F_0)
        # psi_H     = diffraction_setup.psiH(energy)     # self._calculatePsiFromStructureFactor(unitcell_volume, polarized_photon, F_H)
        # psi_H_bar = diffraction_setup.psiH_bar(energy) # self._calculatePsiFromStructureFactor(unitcell_volume, polarized_photon, F_H_bar)
        psi_0, psi_H, psi_H_bar = diffraction_setup.psiAll(energy)

        # Create PerfectCrystalDiffraction instance.
        perfect_crystal = PerfectCrystalDiffraction(
            geometry_type=diffraction_setup.geometryType(),
            bragg_normal=normal_bragg,
            surface_normal=normal_surface,
            bragg_angle=angle_bragg,
            psi_0=psi_0,
            psi_H=psi_H,
            psi_H_bar=psi_H_bar,
            thickness=diffraction_setup.thickness(),
            d_spacing=d_spacing)

        return perfect_crystal
Exemple #2
0
    def _perfectCrystalForEnergy(self, diffraction_setup, energy):

        # Retrieve bragg angle.
        angle_bragg = diffraction_setup.angleBragg(energy)

        # Get structure factors for all relevant lattice vectors 0,H,H_bar.
        F_0 = diffraction_setup.F0(energy)
        F_H = diffraction_setup.FH(energy)
        F_H_bar = diffraction_setup.FH_bar(energy)

        # Check if given Bragg/Laue geometry and given miller indices are possible.
        self._checkSetup(diffraction_setup, angle_bragg, F_0, F_H, F_H_bar)

        # Log the structure factors.
        if self.isDebug:
            self.logStructureFactors(F_0, F_H, F_H_bar)

        # Retrieve lattice spacing d.
        d_spacing = diffraction_setup.dSpacing() * 1e-10

        # Calculate the Bragg normal B_H.
        normal_bragg = diffraction_setup.normalBragg()

        # Calculate the surface normal n.
        normal_surface = diffraction_setup.normalSurface()

        # Calculate the incoming photon direction (parallel to k_0).
        photon_direction = diffraction_setup.incomingPhotonDirection(
            energy, 0.0)

        # Create photon k_0.
        photon_in = Photon(energy, photon_direction)

        # Retrieve unitcell volume from xraylib.
        unitcell_volume = diffraction_setup.unitcellVolume() * 10**-30

        # Calculate psis as defined in Zachariasen [3-95]
        psi_0 = self._calculatePsiFromStructureFactor(unitcell_volume,
                                                      photon_in, F_0)
        psi_H = self._calculatePsiFromStructureFactor(unitcell_volume,
                                                      photon_in, F_H)
        psi_H_bar = self._calculatePsiFromStructureFactor(
            unitcell_volume, photon_in, F_H_bar)

        # Create PerfectCrystalDiffraction instance.
        perfect_crystal = PerfectCrystalDiffraction(
            geometry_type=diffraction_setup.geometryType(),
            bragg_normal=normal_bragg,
            surface_normal=normal_surface,
            bragg_angle=angle_bragg,
            psi_0=psi_0,
            psi_H=psi_H,
            psi_H_bar=psi_H_bar,
            thickness=diffraction_setup.thickness(),
            d_spacing=d_spacing)

        return perfect_crystal
def generatePerfectCrystalDiffraction():

    # Si(111), E=3124eV
    angle_bragg = 0.685283
    psi_0 = -0.00010047702301 - 0.00001290853605j
    psi_H = -0.00004446850675 + 0.00003155997069j
    psi_H_bar = -0.00003155997069 - 0.00004446850675j
    d_spacing = 3.135416 * 1e-10

    geometry_type = LaueTransmission()
    normal_bragg = Vector(0, 0, 1).scalarMultiplication(2.0 * pi / d_spacing)
    normal_surface = Vector(1.0, 0.0, 0.0)

    thickness = 128 * 1e-6

    perfect_crystal_diffraction = PerfectCrystalDiffraction(
        geometry_type, normal_bragg, normal_surface, angle_bragg, psi_0, psi_H,
        psi_H_bar, thickness, d_spacing)

    return perfect_crystal_diffraction
Exemple #4
0
def calculate_simple_diffraction_angular_scan_accelerated():

    # Create a diffraction setup.

    diffraction_setup_dabax = DiffractionSetupDabax(
        geometry_type=BraggDiffraction(),  # GeometryType object
        crystal_name="YB66",  # string
        thickness=7e-3,  # meters
        miller_h=4,  # int
        miller_k=0,  # int
        miller_l=0,  # int
        asymmetry_angle=
        0,  #10.0*numpy.pi/180.,                              # radians
        azimuthal_angle=0.0,
        dabax=DabaxXraylib())  # radians

    energy = 8040.0  # eV
    angle_deviation_min = 20e-6  # radians
    angle_deviation_max = 80e-6  # radians
    angle_deviation_points = 200

    angle_step = (angle_deviation_max -
                  angle_deviation_min) / angle_deviation_points

    #
    # gets Bragg angle needed to create deviation's scan
    #
    bragg_angle = diffraction_setup_dabax.angleBragg(energy)

    print("Bragg angle for E=%f eV is %f deg" %
          (energy, bragg_angle * 180.0 / numpy.pi))

    # Create a Diffraction object (the calculator)
    diffraction = Diffraction()
    diffraction_dabax = Diffraction()

    # initialize arrays for storing outputs
    deviations = numpy.zeros(angle_deviation_points)
    intensityS = numpy.zeros(angle_deviation_points)
    intensityP = numpy.zeros(angle_deviation_points)
    intensityS_dabax = numpy.zeros(angle_deviation_points)
    intensityP_dabax = numpy.zeros(angle_deviation_points)

    for ia in range(angle_deviation_points):
        deviation = angle_deviation_min + ia * angle_step
        angle = deviation + bragg_angle

        # calculate the components of the unitary vector of the incident photon scan
        # Note that diffraction plane is YZ
        yy = numpy.cos(angle)
        zz = -numpy.abs(numpy.sin(angle))
        photon = Photon(energy_in_ev=energy,
                        direction_vector=Vector(0.0, yy, zz))

        # perform the calculation
        coeffs = diffraction.calculateDiffractedComplexAmplitudes(
            diffraction_setup_dabax, photon)

        # store results
        deviations[ia] = deviation
        intensityS[ia] = coeffs['S'].intensity()
        intensityP[ia] = coeffs['P'].intensity()

    psi_0, psi_H, psi_H_bar = diffraction_setup_dabax.psiAll(energy)

    for ia in range(angle_deviation_points):
        deviation = angle_deviation_min + ia * angle_step
        angle = deviation + bragg_angle

        # calculate the components of the unitary vector of the incident photon scan
        # Note that diffraction plane is YZ
        yy = numpy.cos(angle)
        zz = -numpy.abs(numpy.sin(angle))
        photon = Photon(energy_in_ev=energy,
                        direction_vector=Vector(0.0, yy, zz))

        # perform the calculation
        # coeffs_dabax = diffraction_dabax.calculateDiffractedComplexAmplitudes(diffraction_setup_dabax, photon)
        #
        # # store results
        # deviations[ia] = deviation
        # intensityS_dabax[ia] = coeffs_dabax['S'].intensity()
        # intensityP_dabax[ia] = coeffs_dabax['P'].intensity()

        # Create PerfectCrystalDiffraction instance.
        perfect_crystal = PerfectCrystalDiffraction(
            geometry_type=diffraction_setup_dabax.geometryType(),
            bragg_normal=diffraction_setup_dabax.normalBragg(),
            surface_normal=diffraction_setup_dabax.normalSurface(),
            bragg_angle=diffraction_setup_dabax.angleBragg(energy),
            psi_0=psi_0,
            psi_H=psi_H,
            psi_H_bar=psi_H_bar,
            thickness=diffraction_setup_dabax.thickness(),
            d_spacing=diffraction_setup_dabax.dSpacing() * 1e-10)

        complex_amplitudes = perfect_crystal.calculateDiffraction(photon)

        deviations[ia] = deviation
        intensityS_dabax[ia] = complex_amplitudes['S'].intensity(
        )  # 0.0 # coeffs_dabax['S'].intensity()
        intensityP_dabax[ia] = complex_amplitudes['P'].intensity(
        )  # 0.0 # coeffs_dabax['P'].intensity()

    # plot results
    import matplotlib.pylab as plt
    plt.plot(1e6 * deviations, intensityS_dabax)
    plt.plot(1e6 * deviations, intensityP_dabax)
    plt.xlabel("deviation angle [urad]")
    plt.ylabel("Reflectivity")
    plt.legend(["Sigma-polarization DABAX", "Pi-polarization DABAX"])
    plt.show()
def calculate_simple_diffraction_energy_scan_accelerated():

    # Create a diffraction setup.

    print("\nCreating a diffraction setup...")
    diffraction_setup = DiffractionSetup(
        geometry_type=BraggDiffraction(),  # GeometryType object
        crystal_name="Si",  # string
        thickness=1e-2,  # meters
        miller_h=1,  # int
        miller_k=1,  # int
        miller_l=1,  # int
        asymmetry_angle=
        0,  #10.0*numpy.pi/180.,                              # radians
        azimuthal_angle=0.0)  # radians                            # int

    import socket
    if socket.getfqdn().find("esrf") >= 0:
        dx = DabaxXraylib(
            dabax_repository="http://ftp.esrf.fr/pub/scisoft/DabaxFiles/")
    else:
        dx = DabaxXraylib()

    diffraction_setup_dabax = DiffractionSetupDabax(
        geometry_type=BraggDiffraction(),  # GeometryType object
        crystal_name="Si",  # string
        thickness=1e-2,  # meters
        miller_h=1,  # int
        miller_k=1,  # int
        miller_l=1,  # int
        asymmetry_angle=
        0,  #10.0*numpy.pi/180.,                              # radians
        azimuthal_angle=0.0,
        dabax=dx)  # radians

    energy = 8000.0  # eV

    angle_deviation_min = -100e-6  # radians
    angle_deviation_max = 100e-6  # radians
    angle_deviation_points = 50

    angle_step = (angle_deviation_max -
                  angle_deviation_min) / angle_deviation_points

    #
    # gets Bragg angle needed to create deviation's scan
    #
    bragg_angle_corrected = diffraction_setup.angleBraggCorrected(energy)

    print("Bragg angle corrected for E=%f eV is %f deg" %
          (energy, bragg_angle_corrected * 180.0 / numpy.pi))

    DeltaE = energy * 1e-4

    npoints = 100
    energies = numpy.linspace(energy - 3 * DeltaE, energy + 3 * DeltaE,
                              npoints)

    # Create a Diffraction object (the calculator)
    diffraction = Diffraction()
    diffraction_dabax = Diffraction()

    # initialize arrays for storing outputs
    intensityS = numpy.zeros(npoints)
    intensityP = numpy.zeros(npoints)
    intensityS_dabax = numpy.zeros(npoints)
    intensityP_dabax = numpy.zeros(npoints)

    t0 = time.time()
    for ia in range(npoints):

        # calculate the components of the unitary vector of the incident photon scan
        # Note that diffraction plane is YZ
        yy = numpy.cos(bragg_angle_corrected)
        zz = -numpy.abs(numpy.sin(bragg_angle_corrected))
        photon = Photon(energy_in_ev=energies[ia],
                        direction_vector=Vector(0.0, yy, zz))

        # perform the calculation
        coeffs = diffraction.calculateDiffractedComplexAmplitudes(
            diffraction_setup, photon)

        # store results
        intensityS[ia] = coeffs['S'].intensity()
        intensityP[ia] = coeffs['P'].intensity()

    COOR = []
    ENER = []
    for ia in range(npoints):

        # calculate the components of the unitary vector of the incident photon scan
        # Note that diffraction plane is YZ
        yy = numpy.cos(bragg_angle_corrected)
        zz = -numpy.abs(numpy.sin(bragg_angle_corrected))

        COOR.append([0.0, yy, zz])
        ENER.append(energies[ia])

    t1 = time.time()

    Psi_0, Psi_H, Psi_H_bar = diffraction_setup_dabax.psiAll(ENER)

    for ia in range(npoints):
        # perform the calculation
        incoming_photon = Photon(energy_in_ev=ENER[ia],
                                 direction_vector=Vector(
                                     COOR[ia][0], COOR[ia][1], COOR[ia][2]))
        energy = ENER[ia]

        # psi_0, psi_H, psi_H_bar = diffraction_setup_dabax.psiAll(energy)
        psi_0, psi_H, psi_H_bar = Psi_0[ia], Psi_H[ia], Psi_H_bar[ia]

        # Create PerfectCrystalDiffraction instance.
        perfect_crystal = PerfectCrystalDiffraction(
            geometry_type=diffraction_setup_dabax.geometryType(),
            bragg_normal=diffraction_setup_dabax.normalBragg(),
            surface_normal=diffraction_setup_dabax.normalSurface(),
            bragg_angle=diffraction_setup_dabax.angleBragg(energy),
            psi_0=psi_0,
            psi_H=psi_H,
            psi_H_bar=psi_H_bar,
            thickness=diffraction_setup_dabax.thickness(),
            d_spacing=diffraction_setup_dabax.dSpacing() * 1e-10)

        complex_amplitudes = perfect_crystal.calculateDiffraction(
            incoming_photon)

        intensityS_dabax[ia] = complex_amplitudes['S'].intensity(
        )  # 0.0 # coeffs_dabax['S'].intensity()
        intensityP_dabax[ia] = complex_amplitudes['P'].intensity(
        )  # 0.0 # coeffs_dabax['P'].intensity()

    t2 = time.time()

    # plot results
    import matplotlib.pylab as plt
    plt.plot(energies, intensityS)
    plt.plot(energies, intensityP)
    plt.plot(energies, intensityS_dabax)
    plt.plot(energies, intensityP_dabax)
    plt.xlabel("photon energy [eV]")
    plt.ylabel("Reflectivity")
    plt.legend([
        "Sigma-polarization XRAYLIB", "Pi-polarization XRAYLIB",
        "Sigma-polarization DABAX", "Pi-polarization DABAX"
    ])
    plt.show()

    print("Total time, Time per points XRAYLIB: ", t1 - t0,
          (t1 - t0) / npoints)
    print("Total time, Time per points DABAX: ", t2 - t1, (t2 - t1) / npoints)