.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/solutions/acid_base/plot_04_henderson_hasselbalch_buffer.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_solutions_acid_base_plot_04_henderson_hasselbalch_buffer.py: The Henderson-Hasselbalch equation and buffer design ====================================================== Hasselbalch's logarithmic form of Henderson's buffer relationship, .. math:: \mathrm{pH} = pK_a + \log_{10}\frac{[A^-]}{[HA]}, evaluated with :func:`~chemistrykit.solutions.systems.acid_base.henderson_hasselbalch_ph` and inverted by :meth:`~chemistrykit.solutions.systems.acid_base.Buffer.from_target_ph` to design an acetate buffer of fixed total concentration for any target pH. The equation is checked against the exact equilibrium pH of the same mixture. .. GENERATED FROM PYTHON SOURCE LINES 21-40 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from chemistrykit.solutions.systems.acid_base import Buffer, henderson_hasselbalch_ph pKa = 4.76 # acetic acid ratios = np.logspace(-2, 2, 200) pH_hh = [henderson_hasselbalch_ph(pKa, base_conc=r, acid_conc=1.0) for r in ratios] fig, ax = plt.subplots(figsize=(7, 5)) ax.semilogx(ratios, pH_hh, color="steelblue") ax.axhline(pKa, color="gray", linestyle=":", label="pH = pKa at [A-]/[HA] = 1") ax.axvspan(0.1, 10.0, color="steelblue", alpha=0.1, label="useful buffer range, pKa ± 1") ax.set_xlabel("[A-]/[HA]") ax.set_ylabel("pH") ax.set_title("Henderson-Hasselbalch equation, acetate buffer") ax.legend() fig.tight_layout() .. image-sg:: /api/gallery/solutions/acid_base/images/sphx_glr_plot_04_henderson_hasselbalch_buffer_001.png :alt: Henderson-Hasselbalch equation, acetate buffer :srcset: /api/gallery/solutions/acid_base/images/sphx_glr_plot_04_henderson_hasselbalch_buffer_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 41-43 Designing a 0.20 M acetate buffer at pH 5.00, and plotting the required composition for every target pH: .. GENERATED FROM PYTHON SOURCE LINES 43-60 .. code-block:: Python buf = Buffer.from_target_ph(pKa=pKa, target_pH=5.0, total_conc=0.20) print(f"Buffer: [HA] = {buf.acid_conc:.4f} M, [A-] = {buf.base_conc:.4f} M, pH = {buf.pH():.4f}") pH_targets = np.linspace(pKa - 1.0, pKa + 1.0, 100) base_fraction = [Buffer.from_target_ph(pKa=pKa, target_pH=pH, total_conc=0.20).base_conc / 0.20 for pH in pH_targets] fig2, ax2 = plt.subplots(figsize=(7, 5)) ax2.plot(pH_targets, base_fraction, color="darkorange") ax2.axvline(pKa, color="gray", linestyle=":", label="pH = pKa") ax2.set_xlabel("target buffer pH") ax2.set_ylabel("fraction as conjugate base, [A-]/C") ax2.set_title("Buffer composition from Henderson-Hasselbalch") ax2.legend() fig2.tight_layout() plt.show() .. image-sg:: /api/gallery/solutions/acid_base/images/sphx_glr_plot_04_henderson_hasselbalch_buffer_002.png :alt: Buffer composition from Henderson-Hasselbalch :srcset: /api/gallery/solutions/acid_base/images/sphx_glr_plot_04_henderson_hasselbalch_buffer_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Buffer: [HA] = 0.0731 M, [A-] = 0.1269 M, pH = 5.0000 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.103 seconds) .. _sphx_glr_download_api_gallery_solutions_acid_base_plot_04_henderson_hasselbalch_buffer.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_04_henderson_hasselbalch_buffer.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_04_henderson_hasselbalch_buffer.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_04_henderson_hasselbalch_buffer.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_