File size: 5,547 Bytes
64c992d
 
 
 
90b47cf
64c992d
 
90b47cf
64c992d
90b47cf
 
 
 
 
64c992d
 
 
 
 
90b47cf
64c992d
 
 
 
 
 
 
 
 
 
 
 
 
 
90b47cf
64c992d
 
 
 
 
 
 
 
 
 
 
 
 
 
90b47cf
64c992d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90b47cf
64c992d
 
 
 
 
 
 
 
 
 
90b47cf
64c992d
 
 
 
 
 
 
 
90b47cf
64c992d
 
 
 
 
 
 
 
 
 
 
 
 
90b47cf
64c992d
 
 
 
 
 
 
 
90b47cf
64c992d
 
 
 
 
 
 
 
 
90b47cf
64c992d
 
 
 
 
 
 
 
 
 
 
 
90b47cf
64c992d
 
 
 
90b47cf
64c992d
 
 
 
 
90b47cf
64c992d
 
 
 
 
 
90b47cf
64c992d
 
 
 
 
 
 
90b47cf
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
169
170
171
172
173
174
175
176
177
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "77f6c813",
   "metadata": {},
   "source": [
    "# Composite-formula ablation workbook\n",
    "\n",
    "Rebuilds the composite-formula ablation grid: ~25 composite-formula variants (stationary geometry\n",
    "plus some combination of implicit PCM, explicit Desmond, and rovibrational QCD corrections) across\n",
    "all 12 delta-22 solvents, at two reference levels: DSD-PBEP86/pcSseg-3 (geometry PBE0/tz) and the\n",
    "MagNET-Zero training reference (WP04/pcSseg-2 for ¹H, ωB97X-D/pcSseg-2 for ¹³C). Also reports the\n",
    "solvent-averaged correlations between the composite-model features."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e00f8b39",
   "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": "b3acc33b",
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "\n",
    "import delta22\n",
    "import composite_models\n",
    "import composite_plots\n",
    "import paths"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a909ba74",
   "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)\n",
    "\n",
    "def document_path(name):\n",
    "    os.makedirs(\"documents\", exist_ok=True)\n",
    "    return os.path.join(\"documents\", name)\n",
    "\n",
    "# the shipped ablations.xlsx used 250 seeded train/test splits per (formula, solvent)\n",
    "N_SPLITS = 250"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5df608e9",
   "metadata": {},
   "outputs": [],
   "source": [
    "query_df_dft = delta22.add_composite_columns(delta22.load_query_df_dft(DELTA22_HDF5, XLSX, verbose=False))\n",
    "solutes = delta22.delta22_solutes(DELTA22_HDF5)\n",
    "print(len(query_df_dft), \"rows;\", len(solutes), \"solutes\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b7bc63a7",
   "metadata": {},
   "source": [
    "## Preview: one formula's mean test RMSE at the DSD-PBEP86 reference level"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ad79f75e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# preview before the full build (all ~25 formulas x 12 solvents x 250 splits x 2 nuclei x 2\n",
    "# reference levels)\n",
    "level = composite_models.REFERENCE_LEVELS[\"dsd\"]\n",
    "preview = composite_models.ablation_rmse_table(query_df_dft, \"H\", level[\"method_h\"], level[\"basis_h\"],\n",
    "                                 level[\"geometry_h\"], solutes, n_splits=20)\n",
    "preview[[\"chloroform\", \"benzene\", \"Mean Test RMSE\"]].round(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7ae7d282",
   "metadata": {},
   "source": [
    "## Build the full ablations workbook (both reference levels, both nuclei)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f9acdb9e",
   "metadata": {},
   "outputs": [],
   "source": [
    "output_path = document_path(\"ablations.xlsx\")\n",
    "composite_models.build_ablations_workbook(query_df_dft, solutes, output_path, n_splits=N_SPLITS)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "66102dfb",
   "metadata": {},
   "source": [
    "## Correlations Between Features\n",
    "\n",
    "Solvent-averaged Pearson r correlation matrix between the five composite-model features (stationary\n",
    "shielding, PCM, Desmond, its vibrational analogue, QCD), both nuclei, plus a per-solvent\n",
    "PCM-vs-Desmond table."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "208d343b",
   "metadata": {},
   "outputs": [],
   "source": [
    "for nucleus, label in [(\"H\", \"Proton\"), (\"C\", \"Carbon\")]:\n",
    "    corr = delta22.ablations_feature_correlations(query_df_dft, nucleus)\n",
    "    nuc_label = \"1H\" if nucleus == \"H\" else \"13C\"\n",
    "    nuc_title = \"$^{1}$H\" if nucleus == \"H\" else \"$^{13}$C\"\n",
    "    composite_plots.plot_feature_correlation_heatmap(\n",
    "        corr[\"r\"], vmin=-1, vmax=1, cmap=\"RdBu\",\n",
    "        title=f\"Solvent-Averaged Pearson $r$ Correlation Matrix for {nuc_title}\",\n",
    "        save_path=figure_path(f\"ablations_feature_corr_r_{nuc_label}.png\"))\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4e3701cd",
   "metadata": {},
   "outputs": [],
   "source": [
    "pcm_desmond_corr = delta22.pcm_desmond_correlation_by_solvent(query_df_dft)\n",
    "print(\"PCM vs. Desmond Pearson R by nucleus and solvent:\")\n",
    "display(pcm_desmond_corr.round(3))\n",
    "composite_plots.plot_pcm_desmond_correlation_table(pcm_desmond_corr,\n",
    "                                   save_path=figure_path(\"ablations_pcm_desmond_corr_table.png\"))\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}