Worked solutions to the three exercises of Lecture 2. Each solution is computed here and checked with assert statements against an exact identity or an independent calculation. The first code cell sets up the notebook and runs Demonstration 1 of the lecture without showing its output, because some of the solutions use its variables.
try: # use the installed package, or the copy in this repository
import engmaterials
except ImportError:
import pathlib, subprocess, sys
for _root in [pathlib.Path.cwd(), *pathlib.Path.cwd().parents]:
if (_root / "engmaterials" / "__init__.py").exists():
sys.path.insert(0, str(_root))
break
else: # on Google Colab: install from GitHub
subprocess.run([sys.executable, "-m", "pip", "install", "-q",
"git+https://github.com/ktwyw/engmaterials.git"], check=True)
import engmaterials
import inspect
import numpy as np
import matplotlib.pyplot as plt
from engmaterials import (atomistics, constants, diffraction, elasticity, kinetics_selection,
lattices, phase_field, phase_thermodynamics)
from engmaterials.plotting import label_panels, panel_label, use_style
use_style()
def show_source(obj):
"""Return the source code of a library function or class."""
return inspect.getsource(obj)
def heading(text):
print(f"\n{text}\n" + "=" * len(text))
# Demonstration 1 of the lecture, run without output: the solutions use its variables.
import contextlib, io
_show, plt.show = plt.show, lambda *args, **kwargs: None
_stdout = contextlib.redirect_stdout(io.StringIO()); _stdout.__enter__()
heading("Demonstration 1: Biorthogonality A @ B.T = 2*pi*I and Brillouin-Zone Volume Invariant")
two_pi_cubed = (2.0 * np.pi) ** 3
print(f"{'Crystal':10s} | {'V_cell [A^3]':>13s} | {'V_BZ [A^-3]':>13s} | {'V * V_BZ':>12s} | {'||AB^T - 2pi I||':>16s}")
print("-" * 74)
for sym in ["Cu", "Fe", "Si", "Ti", "Mg"]:
meta = constants.ELEMENTS_DB[sym]
cell = lattices.build_unit_cell(meta["structure"], meta["a_A"], meta["c_A"])
mt = lattices.metric_tensor(cell["lattice_vectors"])
rec = lattices.reciprocal_lattice(cell["lattice_vectors"])
biorth_err = float(np.max(np.abs(cell["lattice_vectors"] @ rec["reciprocal_vectors"].T - 2.0 * np.pi * np.eye(3))))
prod_vol = mt["volume_A3"] * rec["brillouin_zone_volume"]
print(f"{sym + ' (' + meta['structure'] + ')':10s} | {mt['volume_A3']:13.5f} | {rec['brillouin_zone_volume']:13.5f} | {prod_vol:12.6f} | {biorth_err:16.2e}")
assert biorth_err < 1e-13
assert np.isclose(prod_vol, two_pi_cubed, rtol=1e-13)
assert np.allclose(rec["reciprocal_metric"], (2.0 * np.pi) ** 2 * mt["G_inv"], rtol=1e-13)
_stdout.__exit__(None, None, None); plt.show = _show; plt.close("all")Exercise 1¶
Problem. Construct the 1-atom primitive FCC and BCC lattice matrices for and show via lattices.reciprocal_lattice that the reciprocal of primitive FCC is primitive BCC (and vice versa), satisfying .
heading("Exercise 1: Exact Duality Between Primitive FCC and Primitive BCC Reciprocal Lattices")
a = 3.6149
a_fcc_p = 0.5 * a * np.array([[0.0, 1.0, 1.0], [1.0, 0.0, 1.0], [1.0, 1.0, 0.0]])
a_bcc_p = 0.5 * a * np.array([[-1.0, 1.0, 1.0], [1.0, -1.0, 1.0], [1.0, 1.0, -1.0]])
rec_fcc = lattices.reciprocal_lattice(a_fcc_p)
rec_bcc = lattices.reciprocal_lattice(a_bcc_p)
b_target_from_fcc = (2.0 * np.pi / a) * np.array([[-1.0, 1.0, 1.0], [1.0, -1.0, 1.0], [1.0, 1.0, -1.0]])
b_target_from_bcc = (2.0 * np.pi / a) * np.array([[0.0, 1.0, 1.0], [1.0, 0.0, 1.0], [1.0, 1.0, 0.0]])
vol_fcc_p = lattices.metric_tensor(a_fcc_p)["volume_A3"]
vol_bcc_p = lattices.metric_tensor(a_bcc_p)["volume_A3"]
print(f"Primitive FCC V = {vol_fcc_p:.5f} A^3 (a^3/4 = {a**3 / 4:.5f}) | V_BZ = {rec_fcc['brillouin_zone_volume']:.5f} A^-3")
print(f"Primitive BCC V = {vol_bcc_p:.5f} A^3 (a^3/2 = {a**3 / 2:.5f}) | V_BZ = {rec_bcc['brillouin_zone_volume']:.5f} A^-3")
assert np.allclose(rec_fcc["reciprocal_vectors"], b_target_from_fcc, atol=1e-14)
assert np.allclose(rec_bcc["reciprocal_vectors"], b_target_from_bcc, atol=1e-14)
assert np.isclose(vol_fcc_p * rec_fcc["brillouin_zone_volume"], (2.0 * np.pi) ** 3, rtol=1e-14)
Exercise 1: Exact Duality Between Primitive FCC and Primitive BCC Reciprocal Lattices
=====================================================================================
Primitive FCC V = 11.80943 A^3 (a^3/4 = 11.80943) | V_BZ = 21.00442 A^-3
Primitive BCC V = 23.61886 A^3 (a^3/2 = 23.61886) | V_BZ = 10.50221 A^-3
Explanation. Because primitive FCC has reciprocal vectors of the form , the first Brillouin zone of an FCC metal (such as Cu or Al) is the truncated octahedron, the Wigner–Seitz cell of a BCC lattice.
Exercise 2¶
Problem. Quantify the exact percentage error when the cubic formula is mistakenly applied to HCP Ti (1,0,0), (1,1,0), and (1,0,1) planes.
heading("Exercise 2: Diagnostic Audit — Cubic Formula Applied to Hexagonal Titanium")
ti_a, ti_c = constants.ELEMENTS_DB["Ti"]["a_A"], constants.ELEMENTS_DB["Ti"]["c_A"]
ti_lat = lattices.hcp_unit_cell(ti_a, ti_c)["lattice_vectors"]
for hkl in [(1, 0, 0), (1, 1, 0), (1, 0, 1)]:
d_true = lattices.interplanar_spacing(hkl, ti_lat)
d_cubic_bug = ti_a / np.sqrt(hkl[0] ** 2 + hkl[1] ** 2 + hkl[2] ** 2)
pct_err = 100.0 * (d_cubic_bug - d_true) / d_true
print(f"Ti {str(hkl):10s} | d_true = {d_true:.5f} A | d_cubic_bug = {d_cubic_bug:.5f} A | Error = {pct_err:+.2f}%")
err_100 = (ti_a - lattices.interplanar_spacing((1, 0, 0), ti_lat)) / lattices.interplanar_spacing((1, 0, 0), ti_lat)
err_110 = ((ti_a / np.sqrt(2.0)) - lattices.interplanar_spacing((1, 1, 0), ti_lat)) / lattices.interplanar_spacing((1, 1, 0), ti_lat)
assert np.isclose(err_100, 2.0 / np.sqrt(3.0) - 1.0, rtol=1e-14)
assert np.isclose(err_110, np.sqrt(2.0) - 1.0, rtol=1e-14)
Exercise 2: Diagnostic Audit — Cubic Formula Applied to Hexagonal Titanium
==========================================================================
Ti (1, 0, 0) | d_true = 2.55547 A | d_cubic_bug = 2.95080 A | Error = +15.47%
Ti (1, 1, 0) | d_true = 1.47540 A | d_cubic_bug = 2.08653 A | Error = +41.42%
Ti (1, 0, 1) | d_true = 2.24349 A | d_cubic_bug = 2.08653 A | Error = -7.00%
Explanation. Ignoring overpredicts by and ( vs. true ) by (omitting the cross-term), while misusing instead of on skews .
Exercise 3¶
Problem. Implement interplanar_angle_deg(hkl1, hkl2, lattice_vectors) via reciprocal dot products and verify between (1,1,1) and (1,1,-1) in Cu and between (0,0,1) and (1,0,1) in HCP Ti.
heading("Exercise 3: Implement It Yourself — Universal Interplanar Dihedral Angle Calculator")
def interplanar_angle_deg(hkl1: tuple, hkl2: tuple, lattice_vectors: np.ndarray) -> float:
"""Compute dihedral angle [deg] between Miller planes (hkl1) and (hkl2) in any crystal system."""
b_mat = lattices.reciprocal_lattice(lattice_vectors)["reciprocal_vectors"]
g1 = np.asarray(hkl1, dtype=float) @ b_mat
g2 = np.asarray(hkl2, dtype=float) @ b_mat
cos_phi = np.clip(np.dot(g1, g2) / (np.linalg.norm(g1) * np.linalg.norm(g2)), -1.0, 1.0)
return float(np.degrees(np.arccos(cos_phi)))
cu_lat = lattices.cubic_unit_cell("fcc", constants.ELEMENTS_DB["Cu"]["a_A"])["lattice_vectors"]
ti_a, ti_c = constants.ELEMENTS_DB["Ti"]["a_A"], constants.ELEMENTS_DB["Ti"]["c_A"]
ti_lat = lattices.hcp_unit_cell(ti_a, ti_c)["lattice_vectors"]
phi_cu = interplanar_angle_deg((1, 1, 1), (1, 1, -1), cu_lat)
phi_ti = interplanar_angle_deg((0, 0, 1), (1, 0, 1), ti_lat)
phi_ti_exact = float(np.degrees(np.arctan(2.0 * ti_c / (np.sqrt(3.0) * ti_a))))
print(f"Cu angle((111), (11-1)) = {phi_cu:.6f} deg vs arccos(1/3) = {np.degrees(np.arccos(1.0 / 3.0)):.6f} deg")
print(f"Ti angle((001), (101)) = {phi_ti:.6f} deg vs arctan(2c/(sqrt(3)a)) = {phi_ti_exact:.6f} deg")
assert np.isclose(phi_cu, np.degrees(np.arccos(1.0 / 3.0)), rtol=1e-14)
assert np.isclose(phi_ti, phi_ti_exact, rtol=1e-14)
Exercise 3: Implement It Yourself — Universal Interplanar Dihedral Angle Calculator
===================================================================================
Cu angle((111), (11-1)) = 70.528779 deg vs arccos(1/3) = 70.528779 deg
Ti angle((001), (101)) = 61.391986 deg vs arctan(2c/(sqrt(3)a)) = 61.391986 deg
Summary. Because is already the outward plane normal in Cartesian space, computing interplanar stereographic angles reduces to a two-line Euclidean dot product, working identically for cubic octahedra () and HCP pyramidal slip planes ( in Ti).