{ "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 }