File size: 5,312 Bytes
ef53368
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "1127ad90",
   "metadata": {},
   "source": [
    "# SI Figure S13: MagNET-x vs DFT explicit-solvent corrections\n",
    "\n",
    "Four panels, both nuclei: **A** MagNET-x (NN) vs DFT explicit-solvent correction per site/solvent,\n",
    "Desmond and OpenMM overlaid; **B** the NN-minus-DFT error distribution; **C** every site's DFT and NN\n",
    "correction in chloroform, one column per solute; **D** the semi-parsimonious composite model's fit accuracy vs experiment across the four OpenMM solvents, split by engine and\n",
    "DFT-vs-NN source."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "649a6ece",
   "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": "dd166a12",
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "\n",
    "import delta22\n",
    "import delta22_plots\n",
    "import paths"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "da96ff0e",
   "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": "0cc06b06",
   "metadata": {},
   "outputs": [],
   "source": [
    "dft = delta22.load_query_df_dft(DELTA22_HDF5, XLSX, verbose=False)\n",
    "nn = delta22.load_query_df_nn(DELTA22_HDF5, XLSX, verbose=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "af66d177",
   "metadata": {},
   "outputs": [],
   "source": [
    "# openMM/Desmond engine hues (used by the scatter/histogram/site/fitting-accuracy panels below)\n",
    "ENGINE_COLORS = {\"openMM\": \"#2E86AB\", \"desmond\": \"#A23B72\"}\n",
    "ENGINE_LABELS = {\"desmond\": \"Desmond\", \"openMM\": \"OpenMM\"}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8ddc9cdc",
   "metadata": {},
   "source": [
    "## Panels A and B: MagNET-x vs DFT explicit corrections, Desmond and OpenMM overlaid"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "622c1d35",
   "metadata": {},
   "outputs": [],
   "source": [
    "explicit_by_engine = delta22.compare_dft_nn_by_engine(dft, nn, keys=(\"solute\", \"site\", \"nucleus\", \"solvent\"))\n",
    "delta22_plots.plot_dft_nn_scatter_by_engine(explicit_by_engine, ENGINE_COLORS, ENGINE_LABELS,\n",
    "                                            save_path=figure_path(\"si_figure_s13a_scatter.png\"))\n",
    "delta22_plots.plot_dft_nn_error_histogram_by_engine(explicit_by_engine, ENGINE_COLORS, ENGINE_LABELS,\n",
    "                                                    save_path=figure_path(\"si_figure_s13b_hist.png\"))\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2c511445",
   "metadata": {},
   "source": [
    "## Panel C: every proton/carbon site's explicit correction in chloroform"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ca4e7871",
   "metadata": {},
   "outputs": [],
   "source": [
    "for nucleus, label in [(\"H\", \"Proton\"), (\"C\", \"Carbon\")]:\n",
    "    pairs = delta22.explicit_correction_dft_nn_pairs(dft, nn, \"chloroform\", nucleus)\n",
    "    delta22_plots.plot_explicit_correction_by_site(\n",
    "        pairs, f\"All {label} Sites: DFT vs NN Explicit Corrections (chloroform)\", ENGINE_COLORS,\n",
    "        save_path=figure_path(f\"si_figure_s13c_sites_{'1H' if nucleus == 'H' else '13C'}.png\"))\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0813f518",
   "metadata": {},
   "source": [
    "## Panel D: fitting accuracy of the semi-parsimonious composite model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0ebd8702",
   "metadata": {},
   "outputs": [],
   "source": [
    "# the published panels use 250 seeded train/test splits\n",
    "N_SPLITS = 250"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8ce39a57",
   "metadata": {},
   "outputs": [],
   "source": [
    "SOLVENT_ORDER = [\"chloroform\", \"methanol\", \"TIP4P\", \"benzene\"]\n",
    "solutes = sorted(dft[\"solute\"].unique())\n",
    "for nucleus, label in [(\"H\", \"1H\"), (\"C\", \"13C\")]:\n",
    "    fitting = delta22.si_s13d_fitting_accuracy(dft, nn, SOLVENT_ORDER, N_SPLITS, solutes, nucleus=nucleus)\n",
    "    delta22_plots.plot_fitting_accuracy_boxplot(\n",
    "        fitting, SOLVENT_ORDER, label, ENGINE_COLORS,\n",
    "        save_path=figure_path(f\"si_figure_s13d_fitting_{'1H' if nucleus == 'H' else '13C'}.png\"))\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}