.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/surface/langmuir/plot_01_langmuir_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_langmuir_plot_01_langmuir_isotherm.py: The Langmuir adsorption isotherm =================================== :class:`~chemistrykit.surface.systems.langmuir.LangmuirIsotherm` models monolayer adsorption on a fixed pool of identical surface sites. Its fractional coverage :math:`\theta=KP/(1+KP)` reaches exactly one-half at the half-saturation pressure :math:`P=1/K`, and :func:`~chemistrykit.surface.systems.langmuir.fit_langmuir` recovers `(K, qmax)` from noisy loading-vs-pressure data via the standard 1/q-vs-1/P linearization. .. GENERATED FROM PYTHON SOURCE LINES 14-28 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from chemistrykit.surface.systems.langmuir import LangmuirIsotherm, fit_langmuir from chemistrykit.surface.visualizers.surface_plots import plot_isotherm, plot_linearization K_true, qmax_true = 2.5, 8.0 iso = LangmuirIsotherm(K=K_true, qmax=qmax_true) P_half = iso.half_saturation_pressure() theta_half = iso.fractional_coverage(P_half) print(f"Half-saturation pressure P=1/K = {P_half:.4f}") print(f"Coverage there: {theta_half:.6f} (should be exactly 0.5)") .. rst-class:: sphx-glr-script-out .. code-block:: none Half-saturation pressure P=1/K = 0.4000 Coverage there: 0.500000 (should be exactly 0.5) .. GENERATED FROM PYTHON SOURCE LINES 29-31 Generate synthetic noisy data and recover the parameters by fitting the linearized isotherm. .. GENERATED FROM PYTHON SOURCE LINES 31-40 .. code-block:: Python rng = np.random.default_rng(0) P_data = np.array([0.1, 0.25, 0.5, 1.0, 2.0, 4.0, 8.0, 16.0]) q_data = iso.loading(P_data) * (1.0 + rng.normal(scale=0.01, size=P_data.shape)) fit = fit_langmuir(P_data, q_data) print(f"\nTrue (K, qmax) = ({K_true}, {qmax_true})") print(f"Fitted (K, qmax) = ({fit.K:.4f}, {fit.qmax:.4f})") print(f"R^2 of linearized fit: {fit.r_squared:.6f}") .. rst-class:: sphx-glr-script-out .. code-block:: none True (K, qmax) = (2.5, 8.0) Fitted (K, qmax) = (2.4874, 8.0384) R^2 of linearized fit: 0.999973 .. GENERATED FROM PYTHON SOURCE LINES 41-51 .. code-block:: Python fig, axes = plt.subplots(1, 2, figsize=(10, 4)) plot_isotherm(iso, P_max=20.0, P_data=P_data, q_data=q_data, ax=axes[0]) axes[0].axvline(P_half, color="gray", linestyle="--", linewidth=0.8) axes[0].axhline(iso.qmax * theta_half, color="gray", linestyle="--", linewidth=0.8) x_lin = 1.0 / P_data y_lin = 1.0 / q_data plot_linearization(x_lin, y_lin, fit=(1.0 / (fit.qmax * fit.K), 1.0 / fit.qmax), ax=axes[1], xlabel="1/P", ylabel="1/q") plt.tight_layout() plt.show() .. image-sg:: /api/gallery/surface/langmuir/images/sphx_glr_plot_01_langmuir_isotherm_001.png :alt: LangmuirIsotherm isotherm, Isotherm linearization :srcset: /api/gallery/surface/langmuir/images/sphx_glr_plot_01_langmuir_isotherm_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.064 seconds) .. _sphx_glr_download_api_gallery_surface_langmuir_plot_01_langmuir_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_langmuir_isotherm.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_langmuir_isotherm.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_langmuir_isotherm.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_