.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/catalog/plot_material_by_name.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_gallery_catalog_plot_material_by_name.py: Load optical materials by common name ===================================== Use chemical formulas or familiar names for a first calculation, inspect the documented source choices, and override them when another measurement is needed. Discovery still exposes every dataset and its canonical identity. .. GENERATED FROM PYTHON SOURCE LINES 11-26 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from TypedUnit import ureg from PyOptik import AmbiguousMaterialError, find_materials, material silica = material("SiO2") # main/SiO2/Malitson gold = material("gold") # main/Au/Johnson bk7 = material("N-BK7") # specs/SCHOTT-optical/N-BK7 water = material("water") # main/H2O/Hale for model in (silica, gold, bk7, water): print(model.catalog_id, model.nk(633 * ureg.nm, out_of_range="raise")) .. rst-class:: sphx-glr-script-out .. code-block:: none main/SiO2/Malitson 1.4570121246412515 main/Au/Johnson (0.1834426229508196+3.433241217798595j) specs/SCHOTT-optical/N-BK7 1.5150823520020043 main/H2O/Hale (1.33168+1.4700000000000006e-08j) .. GENERATED FROM PYTHON SOURCE LINES 27-28 Source overrides bypass the documented default. Provenance remains visible. .. GENERATED FROM PYTHON SOURCE LINES 28-38 .. code-block:: Python alternative_gold = material("Au", source="Rakic-LD") print("Selected alternative:", alternative_gold.catalog_id) print("Original reference:", gold.provenance["reference"]) # Discovery always returns every matching page, including the default. candidates = find_materials("Au") print(f"Found {len(candidates)} gold datasets") for page in candidates[:3]: print(page.id.key, "—", page.description) .. rst-class:: sphx-glr-script-out .. code-block:: none Selected alternative: main/Au/Rakic-LD Original reference: P. B. Johnson and R. W. Christy. Optical constants of the noble metals. Phys. Rev. B 6, 4370-4379 (1972) Found 38 gold datasets main/Au/Babar — Babar and Weaver 2015: n,k 0.2066–12.40 µm main/Au/Chen — Chen et al. 2025: n,k 0.210–0.600 µm main/Au/Ciesielski — Ciesielski et al. 2018: Au/SiO2; n,k 0.191–20.9 µm .. GENERATED FROM PYTHON SOURCE LINES 39-40 Disable defaults to require an explicit source for an ambiguous family. .. GENERATED FROM PYTHON SOURCE LINES 40-46 .. code-block:: Python try: material("Au", use_default=False) except AmbiguousMaterialError as error: print(f"Explicit source required: {len(error.candidates)} candidates") print('Select one with material("Au", source="Johnson")') .. rst-class:: sphx-glr-script-out .. code-block:: none Explicit source required: 38 candidates Select one with material("Au", source="Johnson") .. GENERATED FROM PYTHON SOURCE LINES 47-61 .. code-block:: Python wavelengths = np.linspace(400, 1000, 300) * ureg.nm figure, axes = plt.subplots(1, 2, figsize=(10, 4), layout="constrained") for label, model in [("Fused silica", silica), ("SCHOTT N-BK7", bk7)]: axes[0].plot(wavelengths.magnitude, model.n(wavelengths, out_of_range="raise"), label=label) axes[0].set(xlabel="Vacuum wavelength [nm]", ylabel="Refractive index n", title="Dielectrics loaded by name") for label, model in [("Johnson and Christy", gold), ("Rakić Lorentz-Drude", alternative_gold)]: axes[1].plot(wavelengths.magnitude, model.k(wavelengths, out_of_range="raise"), label=label) axes[1].set(xlabel="Vacuum wavelength [nm]", ylabel="Extinction coefficient k", title="Gold: default and explicit source") for axis in axes: axis.grid(alpha=0.25) axis.legend() plt.show() .. image-sg:: /gallery/catalog/images/sphx_glr_plot_material_by_name_001.png :alt: Dielectrics loaded by name, Gold: default and explicit source :srcset: /gallery/catalog/images/sphx_glr_plot_material_by_name_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 8.646 seconds) .. _sphx_glr_download_gallery_catalog_plot_material_by_name.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_material_by_name.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_material_by_name.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_