File size: 3,442 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 | {
"cells": [
{
"cell_type": "markdown",
"id": "e8c73ac7",
"metadata": {},
"source": [
"# Figure 2B: inter-method correlation of delta-22 ¹H stationary shieldings\n",
"\n",
"Lower-triangle Pearson correlation matrix of per-site ¹H delta-22 stationary shieldings across methods\n",
"(pcSseg-2 basis). The colorbar is Pearson r; the published panel mislabels it r², a typo, corrected here."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ae047e23",
"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": "3d783476",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"import delta22\n",
"import paths\n",
"import fig2b_plots"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9f91feb0",
"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": "569d9eef",
"metadata": {},
"outputs": [],
"source": [
"# Gas-phase (\"stationary\") shieldings, one value per (solute, geometry, basis, site, nucleus, method).\n",
"# The stationary shielding does not depend on solvent, so keep one solvent (TIP4P) to deduplicate.\n",
"NUCLEUS = \"H\"\n",
"BASIS = \"pcSseg2\"\n",
"\n",
"dft = delta22.load_query_df_dft(DELTA22_HDF5, XLSX, verbose=False)\n",
"corr_df = dft[[\"solute\", \"sap_geometry_type\", \"sap_nmr_method\", \"sap_basis\",\n",
" \"nucleus\", \"site\", \"solvent\", \"stationary\"]].copy()\n",
"corr_df.columns = [c.replace(\"sap_\", \"\") for c in corr_df.columns]\n",
"corr_df = corr_df.query('solvent == \"TIP4P\"').drop(columns=[\"solvent\"])\n",
"\n",
"pivot = corr_df.pivot(index=[\"solute\", \"geometry_type\", \"basis\", \"site\", \"nucleus\"],\n",
" columns=\"nmr_method\", values=\"stationary\")\n",
"sub = pivot.query(\"nucleus == @NUCLEUS and basis == @BASIS\")\n",
"correlations = sub.corr()\n",
"off_diag = correlations.where(~np.eye(len(correlations), dtype=bool))\n",
"print(f\"{correlations.shape[0]} methods; worst pairwise Pearson r = {off_diag.min().min():.5f}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f866aab1",
"metadata": {},
"outputs": [],
"source": [
"fig2b_plots.plot_correlation_matrix(correlations, save_png=figure_path(\"fig2b_correlation_1H.png\"))"
]
}
],
"metadata": {
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|