.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/surface/bet/plot_01_bet_isotherm.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_surface_bet_plot_01_bet_isotherm.py: The BET multilayer adsorption isotherm ========================================= :class:`~chemistrykit.surface.systems.bet.BETIsotherm` generalizes Langmuir to multilayer adsorption. As the saturation vapor pressure :math:`P_0 \to \infty` at fixed :math:`K=C/P_0`, multilayer condensation is suppressed and BET reduces exactly to the Langmuir isotherm -- a reduction verified here numerically, not just asserted. .. GENERATED FROM PYTHON SOURCE LINES 13-23 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from chemistrykit.surface.systems.bet import BETIsotherm, fit_bet from chemistrykit.surface.systems.langmuir import langmuir_coverage from chemistrykit.surface.visualizers.surface_plots import plot_isotherm, plot_linearization Vm_true, C_true, P0 = 5.0, 80.0, 10.0 iso = BETIsotherm(Vm=Vm_true, C=C_true, P0=P0) .. GENERATED FROM PYTHON SOURCE LINES 24-26 Fit (Vm, C) from synthetic data restricted to the usual reliable BET range, 0.05 < P/P0 < 0.35. .. GENERATED FROM PYTHON SOURCE LINES 26-35 .. code-block:: Python rng = np.random.default_rng(2) P_data = np.array([0.5, 1.0, 1.5, 2.0, 2.5, 3.0]) V_data = iso.loading(P_data) * (1.0 + rng.normal(scale=0.005, size=P_data.shape)) fit = fit_bet(P_data, V_data, P0=P0) print(f"True (Vm, C) = ({Vm_true}, {C_true})") print(f"Fitted (Vm, C) = ({fit.Vm:.4f}, {fit.C:.4f})") print(f"R^2 of linearized fit: {fit.r_squared:.6f}") .. rst-class:: sphx-glr-script-out .. code-block:: none True (Vm, C) = (5.0, 80.0) Fitted (Vm, C) = (5.0341, 72.2212) R^2 of linearized fit: 0.999704 .. GENERATED FROM PYTHON SOURCE LINES 36-39 The Langmuir-limit check: with P0 pushed far above the working pressure range (multilayer condensation never sets in), the BET curve should collapse onto the Langmuir isotherm with the same K=C/P0. .. GENERATED FROM PYTHON SOURCE LINES 39-49 .. code-block:: Python K = 2.0 P0_large = 1.0e7 C_large = K * P0_large Vm = 1.0 P_scan = np.linspace(0.01, 5.0, 200) V_bet = BETIsotherm(Vm=Vm, C=C_large, P0=P0_large).loading(P_scan) theta_langmuir = langmuir_coverage(K, P_scan) max_relative_error = np.max(np.abs(V_bet - Vm * theta_langmuir) / (Vm * theta_langmuir)) print(f"\nMax relative deviation of BET from Langmuir (P0/K=5e6): {max_relative_error:.2e}") .. rst-class:: sphx-glr-script-out .. code-block:: none Max relative deviation of BET from Langmuir (P0/K=5e6): 5.45e-07 .. GENERATED FROM PYTHON SOURCE LINES 50-67 .. code-block:: Python fig, axes = plt.subplots(1, 3, figsize=(14, 4)) plot_isotherm(iso, P_max=8.0, P_data=P_data, q_data=V_data, ax=axes[0]) x_lin = P_data / P0 y_lin = x_lin / (V_data * (1.0 - x_lin)) slope = (fit.C - 1.0) / (fit.Vm * fit.C) intercept = 1.0 / (fit.Vm * fit.C) plot_linearization(x_lin, y_lin, fit=(slope, intercept), ax=axes[1], xlabel="x = P/P0", ylabel="x / [V(1-x)]") axes[2].plot(P_scan, V_bet, label="BET (P0=1e7)") axes[2].plot(P_scan, Vm * theta_langmuir, "k--", label="Langmuir") axes[2].set_xlabel("P") axes[2].set_ylabel("loading") axes[2].set_title("BET -> Langmuir limit") axes[2].legend() plt.tight_layout() plt.show() .. image-sg:: /api/gallery/surface/bet/images/sphx_glr_plot_01_bet_isotherm_001.png :alt: BETIsotherm isotherm, Isotherm linearization, BET -> Langmuir limit :srcset: /api/gallery/surface/bet/images/sphx_glr_plot_01_bet_isotherm_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.094 seconds) .. _sphx_glr_download_api_gallery_surface_bet_plot_01_bet_isotherm.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_bet_isotherm.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_bet_isotherm.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_bet_isotherm.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_