{ "cells": [ { "cell_type": "markdown", "id": "007f5b29", "metadata": {}, "source": [ "# SI Figure S4: correlation of implicit (PCM) corrections across solvents and methods\n", "\n", "**S4A** correlation across solvents (both nuclei), **S4B** one solvent vs another (¹H), **S4C**\n", "correlation across methods (both nuclei). Cells show -log10(1-r), so 3 means r=0.999." ] }, { "cell_type": "code", "execution_count": null, "id": "34163231", "metadata": {}, "outputs": [], "source": [ "import os, sys\n", "\n", "# make the in-repo modules importable (not pip-installed)\n", "REPO = os.path.abspath(\"../..\")\n", "for _p in (\"data/delta22\", \"analysis/code\", \"analysis/code/shared\"):\n", " sys.path.insert(0, os.path.join(REPO, _p))" ] }, { "cell_type": "code", "execution_count": null, "id": "d4fced82", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "\n", "import delta22\n", "import delta22_plots\n", "import paths" ] }, { "cell_type": "code", "execution_count": null, "id": "2d316f79", "metadata": {}, "outputs": [], "source": [ "DELTA22_HDF5 = paths.dataset_file(\"delta22\", root=REPO)\n", "XLSX = os.path.join(REPO, \"data\", \"delta22\", \"delta22_experimental.xlsx\")\n", "\n", "def figure_path(name):\n", " os.makedirs(\"figures\", exist_ok=True)\n", " return os.path.join(\"figures\", name)" ] }, { "cell_type": "code", "execution_count": null, "id": "cb9e3ebb", "metadata": {}, "outputs": [], "source": [ "METHOD, BASIS, GEOM = \"b3lyp_d3bj\", \"pcSseg2\", \"pbe0_tz\"\n", "dft = delta22.load_query_df_dft(DELTA22_HDF5, XLSX, verbose=False)\n", "base = dft[(dft[\"sap_nmr_method\"] == METHOD) & (dft[\"sap_basis\"] == BASIS)\n", " & (dft[\"sap_geometry_type\"] == GEOM)]\n", "one = base[base[\"nucleus\"] == \"H\"]\n", "\n", "# solvent order that groups polar-aprotic -> polar-protic -> aromatic (matches the published panel)\n", "ORDERED_SOLVENTS = [\"chloroform\", \"tetrahydrofuran\", \"dichloromethane\", \"acetone\", \"acetonitrile\",\n", " \"dimethylsulfoxide\", \"trifluoroethanol\", \"methanol\", \"TIP4P\",\n", " \"benzene\", \"toluene\", \"chlorobenzene\"]" ] }, { "cell_type": "markdown", "id": "ee2d20ba", "metadata": {}, "source": [ "## S4A: solvent-vs-solvent PCM correlation (¹H and ¹³C)" ] }, { "cell_type": "code", "execution_count": null, "id": "c8664491", "metadata": {}, "outputs": [], "source": [ "for nucleus, label in [(\"H\", \"1H\"), (\"C\", \"13C\")]:\n", " solvent_corr = delta22.correlation_matrix(base[base[\"nucleus\"] == nucleus], \"pcm\", [\"solute\", \"site\"], \"solvent\")\n", " solvent_corr = solvent_corr.reindex(index=ORDERED_SOLVENTS, columns=ORDERED_SOLVENTS)\n", " vals = solvent_corr.values[np.triu_indices_from(solvent_corr.values, k=1)]\n", " print(f\"solvent PCM correlation ({label}): mean r={np.nanmean(vals):.4f} min r={np.nanmin(vals):.4f}\")\n", " caption = (\"Correlation coefficients between solvents across all 22 solutes.\\n\"\n", " f\"PCM corrections computed with {METHOD} with the {BASIS} basis.\\n\"\n", " \"A value of 3 means the coefficient is 0.999.\")\n", " delta22_plots.plot_correlation_matrix(solvent_corr, f\"Solvents are Highly Correlated ({nucleus})\", caption,\n", " colormap=\"Reds\", show_values=True,\n", " save_path=figure_path(f\"si_figure_s04a_{label}.png\"))" ] }, { "cell_type": "markdown", "id": "133ed792", "metadata": {}, "source": [ "## S4B: PCM corrections, chloroform vs acetonitrile (1H) -- one square of S4A" ] }, { "cell_type": "code", "execution_count": null, "id": "21db6810", "metadata": {}, "outputs": [], "source": [ "pair = one.pivot_table(index=[\"solute\", \"site\"], columns=\"solvent\", values=\"pcm\")[\n", " [\"chloroform\", \"acetonitrile\"]].dropna()\n", "delta22_plots.plot_pcm_scatter(pair[\"chloroform\"], pair[\"acetonitrile\"], \"chloroform\", \"acetonitrile\", \"H\",\n", " save_path=figure_path(\"si_figure_s04b_1H.png\"))" ] }, { "cell_type": "markdown", "id": "1f0e76f9", "metadata": {}, "source": [ "## S4C: method-vs-method correlation (chloroform, double hybrids excluded, ¹H and ¹³C)" ] }, { "cell_type": "code", "execution_count": null, "id": "f75897e7", "metadata": {}, "outputs": [], "source": [ "# one solvent, exclude the double hybrids whose PCM is the substituted reference value\n", "for nucleus, label in [(\"H\", \"1H\"), (\"C\", \"13C\")]:\n", " chcl3 = dft[(dft[\"sap_basis\"] == BASIS) & (dft[\"sap_geometry_type\"] == GEOM)\n", " & (dft[\"nucleus\"] == nucleus) & (dft[\"solvent\"] == \"chloroform\")\n", " & (~dft[\"sap_nmr_method\"].isin(delta22.DOUBLE_HYBRID_METHODS))]\n", " method_corr = delta22.correlation_matrix(chcl3, \"pcm\", [\"solute\", \"site\"], \"sap_nmr_method\")\n", " method_order = sorted(method_corr.index) # alphabetical, matches the published panel\n", " method_corr = method_corr.reindex(index=method_order, columns=method_order)\n", " mvals = method_corr.values[np.triu_indices_from(method_corr.values, k=1)]\n", " print(f\"method PCM correlation ({label}): mean r={np.nanmean(mvals):.4f} min r={np.nanmin(mvals):.4f}\")\n", " caption = (\"Correlation coefficients between NMR methods across all 22 solutes.\\n\"\n", " f\"PCM corrections for chloroform with the {BASIS} basis.\")\n", " delta22_plots.plot_correlation_matrix(method_corr, f\"NMR Methods are Highly Correlated ({nucleus})\", caption,\n", " colormap=\"Reds\", show_values=True,\n", " save_path=figure_path(f\"si_figure_s04c_{label}.png\"))" ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }