File size: 5,119 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4b208bf1",
   "metadata": {},
   "source": [
    "# Figure 5D: per-solute explicit-correction RMSE across the test set\n",
    "\n",
    "Per-solute bootstrap RMSE (¹H, solvent-averaged) for the explicit-solvent correction, ordered delta-22 -> olefin/pyridine isomers -> natural products, with a dashed \"scaled to solute\" baseline and a red \"scaled to test set\" line."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "66e2a22e",
   "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/applications\", \"analysis/code\", \"analysis/code/shared\"):\n",
    "    sys.path.insert(0, os.path.join(REPO, _p))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9b70b4ca",
   "metadata": {},
   "outputs": [],
   "source": [
    "from applications_reader import Applications\n",
    "import applications\n",
    "import applications_plots\n",
    "import paths"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2da375fc",
   "metadata": {},
   "outputs": [],
   "source": [
    "APPLICATIONS_HDF5 = paths.dataset_file(\"applications\", root=REPO)\n",
    "XLSX = os.path.join(REPO, \"data\", \"applications\", \"applications_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": "a6acf673",
   "metadata": {},
   "outputs": [],
   "source": [
    "loader = Applications(APPLICATIONS_HDF5, XLSX)\n",
    "query_df_nn = applications.build_query_df_nn(loader)\n",
    "seed = applications.build_bootstrap_seed_coeffs(loader)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "889345fc",
   "metadata": {},
   "outputs": [],
   "source": [
    "site_counts = (query_df_nn.drop_duplicates(subset=[\"solute\", \"nucleus\", \"site\"])\n",
    "               .groupby([\"solute\", \"nucleus\"]).size().unstack(fill_value=0))\n",
    "per_solute = applications.per_solute_fits(query_df_nn)\n",
    "all_solute = applications.per_solvent_fits(query_df_nn)\n",
    "preds_h = applications.apply_bootstrap_params_to_full_dataset(query_df_nn, seed[\"H\"], nucleus=\"H\")\n",
    "bootstrap_rmses_h = applications.compute_solute_rmses(preds_h)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "08869e35",
   "metadata": {},
   "outputs": [],
   "source": [
    "FIG5D_LABELS = {\n",
    "    \"isomer_1E\": \"Olefin 1 (E)\", \"isomer_1Z\": \"Olefin 1 (Z)\",\n",
    "    \"isomer_2E\": \"Olefin 2 (E)\", \"isomer_2Z\": \"Olefin 2 (Z)\",\n",
    "    \"isomer_3E\": \"Olefin 3 (E)\", \"isomer_3Z\": \"Olefin 3 (Z)\",\n",
    "    \"isomer_4N\": \"Pyridone 4\", \"isomer_4O\": \"Pyridine 4\",\n",
    "    \"vomicine\": \"Vomicine\", \"prednisone\": \"Prednisone\",\n",
    "    \"peptide\": \"Acetyl-L-alanyl-L-\\nglutamine\", \"flavone\": \"Flavone\",\n",
    "    \"dihydrotanshinone_I\": \"Dihydrotanshinone I\",\n",
    "}\n",
    "FIG5D_ORDER = [\"isomer_1E\", \"isomer_1Z\", \"isomer_2E\", \"isomer_2Z\", \"isomer_3E\", \"isomer_3Z\",\n",
    "               \"isomer_4N\", \"isomer_4O\", \"vomicine\", \"prednisone\", \"peptide\", \"flavone\",\n",
    "               \"dihydrotanshinone_I\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1ad5844c",
   "metadata": {},
   "outputs": [],
   "source": [
    "applications_plots.plot_nps_on_boxplot_delta22_simplified(\n",
    "    loader.rmse_distribution(\"H\"), bootstrap_rmses_h, per_solute[\"H\"],\n",
    "    nucleus=\"H\", formulas=[\"stationary_plus_qcd + openMM\"], colors=[\"#61a89a\"],\n",
    "    site_counts=site_counts, formula_remap=applications.FORMULA_REMAP,\n",
    "    solute_remap=FIG5D_LABELS, solute_order=FIG5D_ORDER,\n",
    "    title=\"Complex Molecules are Dominated by Additional Physics\",\n",
    "    solute_color_remap=applications.PEPTIDE_HIGHLIGHT_H,\n",
    "    figsize=(14, 8), box_width=0.20, box_gap=0.1,\n",
    "    show_baseline=True, baseline_annotation_text=\"Scaled to solute\",\n",
    "    baseline_annotation_x=0.215, baseline_annotation_y=0.39,\n",
    "    show_full_fit_line=True, full_fit_line_label=\"Scaled to Test Set\", full_fit_line_label_x=0.835,\n",
    "    all_solute_fitting_results=all_solute,\n",
    "    max_bar_height=0.06, site_count_axis_mode=\"inset\", site_count_inset_area_frac=0.1,\n",
    "    site_count_inset_axis_offset=-0.06,\n",
    "    save_path=figure_path(\"fig5d_complex_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
}