IntRoduction to solid state physics
Practice Course
Sheng Yun Wu
Practice Course
Sheng Yun Wu
Week 3: Diffraction of X-rays by Crystals
This example calculates the Bragg angle using Bragg's Law nλ=2dsin(θ)n \lambda = 2d \sin(\theta)nλ=2dsin(θ).
Bragg’s law describes the condition for constructive interference of X-rays scattered by crystal planes. This example helps students calculate the angle of diffraction θ\thetaθ based on the wavelength, interplanar spacing, and diffraction order.
import numpy as np
def bragg_angle(wavelength, d, n):
return np.arcsin(n * wavelength / (2 * d)) * (180 / np.pi)
# Example: Wavelength = 1.54 Å, distance d = 2 Å, order of diffraction n = 1
wavelength = 1.54e-10 # meters
d = 2e-10 # meters
n = 1
theta = bragg_angle(wavelength, d, n)
print(f"Bragg Angle: {theta:.2f} degrees")
This example simulates a plot showing Bragg diffraction peaks at different diffraction angles.
This example demonstrates how to plot Bragg diffraction peaks based on different orders of diffraction. Students visualize how intensity varies with diffraction angle, which helps them understand diffraction patterns observed in X-ray crystallography.
import matplotlib.pyplot as plt
def plot_bragg_peaks(wavelength, d, max_n=3):
angles = []
intensities = []
for n in range(1, max_n + 1):
theta = np.arcsin(n * wavelength / (2 * d)) * (180 / np.pi)
angles.append(theta)
intensities.append(n**2) # Example intensity formula
plt.plot(angles, intensities, 'bo-')
plt.xlabel('Bragg Angle (degrees)')
plt.ylabel('Intensity (a.u.)')
plt.title('Bragg Diffraction Peaks')
plt.show()
# Example: Wavelength = 1.54 Å, lattice spacing d = 2 Å
plot_bragg_peaks(1.54e-10, 2e-10)
This example calculates the reciprocal lattice vector for a simple cubic crystal lattice.
The reciprocal lattice is an important concept in diffraction, as diffraction patterns are often described in reciprocal space. This example shows students how to calculate the reciprocal lattice vector for a cubic lattice using the lattice constant.
def reciprocal_lattice(a):
return 2 * np.pi / a
# Example: Lattice constant a = 0.4 nm
a = 0.4e-9 # meters
reciprocal = reciprocal_lattice(a)
print(f"Reciprocal Lattice Vector: {reciprocal:.2e} meters⁻¹")
This example generates a 2D plot of reciprocal lattice points, helping students visualize the structure of reciprocal space.
Reciprocal lattice visualization helps students understand the arrangement of diffraction spots in X-ray diffraction patterns. This example generates a 2D plot of reciprocal lattice points for a crystal, aiding in the understanding of diffraction patterns and reciprocal space.
def plot_reciprocal_lattice(a, n_points=3):
fig, ax = plt.subplots()
b = 2 * np.pi / a # Reciprocal lattice constant
for x in np.arange(-n_points * b, n_points * b + b, b):
for y in np.arange(-n_points * b, n_points * b + b, b):
ax.scatter(x, y, c='r')
ax.set_xlabel('kx')
ax.set_ylabel('ky')
plt.title("2D Reciprocal Lattice")
plt.grid(True)
plt.show()
# Lattice constant a = 1 unit
plot_reciprocal_lattice(1)
This example calculates the d-spacing of a cubic crystal using Miller indices and the lattice constant.
The d-spacing defines the distance between planes of atoms in a crystal and is a key parameter in Bragg’s law. This example calculates the d-spacing for specific Miller indices in a cubic crystal lattice, helping students understand how X-rays interact with crystal planes.
def d_spacing(a, h, k, l):
return a / np.sqrt(h**2 + k**2 + l**2)
# Example: Lattice constant a = 0.4 nm, Miller indices (1, 1, 1)
a = 0.4e-9 # meters
h, k, l = 1, 1, 1
d = d_spacing(a, h, k, l)
print(f"d-spacing: {d:.2e} meters")
This example simulates the X-ray diffraction intensity for a simple cubic lattice based on the Miller indices.
This example calculates the diffraction intensity based on the Miller indices. For simple cubic lattices, constructive and destructive interference depend on the sum of the indices. The result helps students predict whether a given set of planes will contribute to the diffraction pattern.
def diffraction_intensity(h, k, l):
if (h + k + l) % 2 == 0:
return 1 # Constructive interference
else:
return 0 # Destructive interference
# Example: Miller indices (1, 1, 1)
h, k, l = 1, 1, 1
intensity = diffraction_intensity(h, k, l)
print(f"Diffraction Intensity: {intensity}")
This example visualizes the Ewald sphere, which is used in X-ray diffraction to represent the geometry of wavevectors.
The Ewald sphere is a graphical construction used to visualize diffraction conditions in reciprocal space. This example helps students understand how incident and scattered wavevectors interact with the reciprocal lattice to produce diffraction patterns.
def plot_ewald_sphere(k, r):
fig, ax = plt.subplots()
circle = plt.Circle((0, 0), r, fill=False, color='b', linestyle='--')
ax.add_patch(circle)
# Incident wave vector (k) and scattered wave vector (k')
ax.quiver(0, 0, k[0], k[1], angles='xy', scale_units='xy', scale=1, color='r', label="k (incident)")
ax.quiver(0, 0, -k[0], k[1], angles='xy', scale_units='xy', scale=1, color='g', label="k' (scattered)")
ax.set_xlim([-r - 1, r + 1])
ax.set_ylim([-r - 1, r + 1])
ax.set_xlabel('kx')
ax.set_ylabel('ky')
plt.title("Ewald Sphere")
plt.grid(True)
plt.legend()
plt.show()
# Example: Incident wave vector k = (1, 0), radius r = 5 units
plot_ewald_sphere([1, 0], 5)
This example simulates the X-ray diffraction pattern for a Face-Centered Cubic (FCC) crystal based on the Miller indices.
Face-centered cubic crystals have distinct diffraction patterns that depend on the Miller indices. This example shows how constructive or destructive interference arises in FCC crystals, helping students predict diffraction peak intensities.
def fcc_diffraction_pattern(h, k, l):
if h % 2 == k % 2 == l % 2:
return 1 # Constructive interference
else:
return 0 # Destructive interference
# Example: Miller indices (2, 2, 0)
h, k, l = 2, 2, 0
pattern = fcc_diffraction_pattern(h, k, l)
print(f"FCC Diffraction Pattern: {pattern}")
This example plots X-ray diffraction peaks for a cubic crystal based on the Miller indices and Bragg’s law.
This example shows how to plot X-ray diffraction peaks for a cubic crystal structure. It uses Bragg’s law to calculate the diffraction angles for various Miller indices and plots the corresponding intensities, giving students insight into the diffraction pattern.
def plot_diffraction_peaks(a, wavelength, max_hkl=3):
angles = []
intensities = []
for h in range(1, max_hkl + 1):
for k in range(1, max_hkl + 1):
for l in range(1, max_hkl + 1):
d = d_spacing(a, h, k, l)
theta = np.arcsin(wavelength / (2 * d)) * (180 / np.pi)
angles.append(theta)
intensities.append((h + k + l)**2) # Example intensity formula
plt.plot(angles, intensities, 'bo-')
plt.xlabel('Bragg Angle (degrees)')
plt.ylabel('Intensity (a.u.)')
plt.title('X-ray Diffraction Peaks for Cubic Crystal')
plt.show()
# Example: Lattice constant a = 2 Å, X-ray wavelength = 1.54 Å
plot_diffraction_peaks(2e-10, 1.54e-10)
Given the diffraction angle and interplanar spacing, this example calculates the X-ray wavelength using Bragg’s law.
This example demonstrates how to calculate the wavelength of X-rays given the diffraction angle and the spacing between crystal planes. It helps students connect theory with practical measurement techniques in X-ray diffraction experiments.
def xray_wavelength(theta, d, n=1):
return 2 * d * np.sin(np.deg2rad(theta)) / n
# Example: Bragg angle θ = 30 degrees, d = 2 Å, n = 1
theta = 30 # degrees
d = 2e-10 # meters
wavelength = xray_wavelength(theta, d)
print(f"X-ray Wavelength: {wavelength:.2e} meters")
These 10 Python examples introduce students to key concepts in Week 3: Diffraction of X-rays by Crystals, such as Bragg’s law, reciprocal lattices, d-spacing, and diffraction patterns. Through these examples, students gain hands-on experience with calculating diffraction angles, visualizing reciprocal space, and understanding diffraction peak intensities in cubic and FCC lattices.