.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/crystal/packing/plot_01_packing_fractions.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_crystal_packing_plot_01_packing_fractions.py: Kepler's conjecture: packing efficiency of SC, BCC, FCC, and HCP ================================================================== Kepler (1611) guessed that no stacking of equal spheres fills space more densely than the layered (face-centered cubic / hexagonal close) packing, with fraction :math:`\pi/\sqrt{18}\approx0.7405`. Comparing the four textbook lattices shows the close-packed pair at exactly that bound. The four lattices implemented here (:mod:`chemistrykit.crystal.systems.packing`) share the :class:`~chemistrykit.crystal.core.base_system.LatticePacking` interface: each derives its atomic packing factor from pure geometry (touching spheres, atoms-per-cell, and a lattice-constant-to-radius relation). FCC and ideal HCP -- both close-packed, differing only in stacking sequence -- turn out to share the same maximum packing fraction. .. GENERATED FROM PYTHON SOURCE LINES 20-42 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from chemistrykit.crystal.systems.packing import ( BodyCenteredCubicPacking, FaceCenteredCubicPacking, HexagonalClosePacking, SimpleCubicPacking, ) from chemistrykit.crystal.visualizers.crystal_plots import plot_packing_fractions lattices = { "SC": SimpleCubicPacking(), "BCC": BodyCenteredCubicPacking(), "FCC": FaceCenteredCubicPacking(), "HCP (ideal)": HexagonalClosePacking(), } for name, lattice in lattices.items(): pf = lattice.packing_fraction() print(f"{name:12s} packing fraction = {pf:.4f} coordination = {lattice.coordination_number:2d} atoms/cell = {lattice.atoms_per_cell}") .. rst-class:: sphx-glr-script-out .. code-block:: none SC packing fraction = 0.5236 coordination = 6 atoms/cell = 1.0 BCC packing fraction = 0.6802 coordination = 8 atoms/cell = 2.0 FCC packing fraction = 0.7405 coordination = 12 atoms/cell = 4.0 HCP (ideal) packing fraction = 0.7405 coordination = 12 atoms/cell = 2.0 .. GENERATED FROM PYTHON SOURCE LINES 43-46 FCC and ideal HCP are both close-packed and share the same packing fraction, even though the underlying models (cubic vs. hexagonal cell, 4 vs. 2 atoms per cell) look nothing alike: .. GENERATED FROM PYTHON SOURCE LINES 46-54 .. code-block:: Python fcc_pf = lattices["FCC"].packing_fraction() hcp_pf = lattices["HCP (ideal)"].packing_fraction() print(f"\nFCC packing fraction: {fcc_pf:.9f}") print(f"HCP packing fraction: {hcp_pf:.9f}") print(f"Match: {abs(fcc_pf - hcp_pf) < 1e-9}") print(f"Kepler's bound pi/sqrt(18) = {np.pi / np.sqrt(18.0):.9f}") assert abs(fcc_pf - np.pi / np.sqrt(18.0)) < 1e-12 .. rst-class:: sphx-glr-script-out .. code-block:: none FCC packing fraction: 0.740480490 HCP packing fraction: 0.740480490 Match: True Kepler's bound pi/sqrt(18) = 0.740480490 .. GENERATED FROM PYTHON SOURCE LINES 55-57 A real HCP metal's actual c/a ratio deviates from the ideal value, which lowers its packing fraction below the FCC/ideal-HCP maximum: .. GENERATED FROM PYTHON SOURCE LINES 57-60 .. code-block:: Python zinc_hcp = HexagonalClosePacking(c_over_a=1.856) # zinc's anomalous c/a print(f"\nZinc-like HCP (c/a=1.856) packing fraction: {zinc_hcp.packing_fraction():.4f} (below the ideal {hcp_pf:.4f})") .. rst-class:: sphx-glr-script-out .. code-block:: none Zinc-like HCP (c/a=1.856) packing fraction: 0.6515 (below the ideal 0.7405) .. GENERATED FROM PYTHON SOURCE LINES 61-68 .. code-block:: Python names = list(lattices.keys()) fractions = [lattices[name].packing_fraction() for name in names] ax = plot_packing_fractions(names, fractions) ax.axhline(np.pi / np.sqrt(18.0), color="k", ls="--", lw=1, label=r"Kepler bound $\pi/\sqrt{18}$") ax.legend() plt.tight_layout() plt.show() .. image-sg:: /api/gallery/crystal/packing/images/sphx_glr_plot_01_packing_fractions_001.png :alt: Atomic packing factor by lattice type :srcset: /api/gallery/crystal/packing/images/sphx_glr_plot_01_packing_fractions_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.031 seconds) .. _sphx_glr_download_api_gallery_crystal_packing_plot_01_packing_fractions.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_packing_fractions.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_packing_fractions.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_packing_fractions.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_