File size: 6,439 Bytes
64c992d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | {
"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
}
|