File size: 4,267 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 | {
"cells": [
{
"cell_type": "markdown",
"id": "6d0c4a9d",
"metadata": {},
"source": [
"# Figure 4C: fit RMSE vs experimental range, implicit vs explicit\n",
"\n",
"Per-solvent fit RMSE vs experimental shift range (¹H), implicit (PCM) vs explicit (Desmond)."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8a3ec572",
"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": "79b3bd64",
"metadata": {},
"outputs": [],
"source": [
"import delta22\n",
"import paths\n",
"import fig4_plots"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "79171fdb",
"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": "fdaaf850",
"metadata": {},
"outputs": [],
"source": [
"# solvent_mean is a synthetic pseudo-solvent representing the average across solvents; it is used below as the reference baseline.\n",
"METHOD, BASIS, GEOM = \"b3lyp_d3bj\", \"pcSseg2\", \"aimnet2\"\n",
"q = delta22.load_query_df_dft(DELTA22_HDF5, XLSX, verbose=False)\n",
"one = q[(q[\"sap_nmr_method\"] == METHOD) & (q[\"sap_basis\"] == BASIS) & (q[\"sap_geometry_type\"] == GEOM)]\n",
"one = delta22.add_solvent_mean(one)\n",
"print(len(one), \"rows for\", METHOD, BASIS, GEOM)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e5527018",
"metadata": {},
"outputs": [],
"source": [
"FIG4C_LABELS = {\n",
" \"chloroform\": \"CDCl3\", \"dichloromethane\": \"DCM\", \"tetrahydrofuran\": \"THF\",\n",
" \"acetonitrile\": \"MeCN\", \"dimethylsulfoxide\": \"DMSO\", \"acetone\": \"acetone\",\n",
" \"methanol\": \"MeOD\", \"TIP4P\": \"TIP4P\", \"trifluoroethanol\": \"trifluoroethanol\",\n",
" \"benzene\": \"benzene\", \"toluene\": \"toluene\", \"chlorobenzene\": \"chlorobenzene\",\n",
"}\n",
"FIG4C_COLORS = {\"Implicit (PCM)\": \"#A72608\", \"Explicit (Desmond)\": \"#61a89a\"} # red diamond / teal circle"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3cdab0a7",
"metadata": {},
"outputs": [],
"source": [
"# differences are taken against the solvent-averaged pseudo-solvent so every real solvent, including chloroform, appears as a point.\n",
"rmse_range_rows = []\n",
"for solvent in delta22.DESMOND_SOLVENTS:\n",
" sp = delta22.solvent_pair_differences(one, solvent, \"solvent_mean\", nucleus=\"H\", explicit=\"desmond\")\n",
" if len(sp) == 0:\n",
" continue\n",
" rmse_range_rows.append({\n",
" \"solvent\": solvent,\n",
" \"range\": float(sp[\"exp_diff\"].max() - sp[\"exp_diff\"].min()),\n",
" \"implicit\": delta22.fit_differences_to_experimental(sp, \"implicit_diff\")[\"rmse\"],\n",
" \"explicit\": delta22.fit_differences_to_experimental(sp, \"explicit_diff\")[\"rmse\"],\n",
" })\n",
"for r in sorted(rmse_range_rows, key=lambda r: r[\"range\"]):\n",
" print(f\"{FIG4C_LABELS[r['solvent']]:16s} range={r['range']:.3f} \"\n",
" f\"implicit={r['implicit']:.3f} explicit={r['explicit']:.3f}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4601c2c7",
"metadata": {},
"outputs": [],
"source": [
"fig4_plots.save_panel(\n",
" lambda ax: fig4_plots.draw_rmse_dumbbell(ax, rmse_range_rows, FIG4C_LABELS, FIG4C_COLORS),\n",
" figure_path(\"fig4c_rmse_range_1H.png\"),\n",
")"
]
}
],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
} |