robert 2.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. robert/__init__.py +9 -0
  2. robert/__main__.py +20 -0
  3. robert/_version.py +3 -0
  4. robert/api.py +646 -0
  5. robert/aqme.py +280 -0
  6. robert/argument_parser.py +98 -0
  7. robert/checkml.py +433 -0
  8. robert/checkml_score.py +50 -0
  9. robert/curate.py +217 -0
  10. robert/evaluate_bot_retrieval.py +125 -0
  11. robert/evaluate_bot_support.py +102 -0
  12. robert/evaluate_workflow_summaries.py +87 -0
  13. robert/export_bot_docs_knowledge.py +1632 -0
  14. robert/generate.py +249 -0
  15. robert/generate_utils.py +311 -0
  16. robert/gui_easyrob/__init__.py +0 -0
  17. robert/gui_easyrob/assets/gif_easyrob.gif +0 -0
  18. robert/gui_easyrob/bot/__init__.py +47 -0
  19. robert/gui_easyrob/bot/answer_metadata.py +198 -0
  20. robert/gui_easyrob/bot/bot_context.py +679 -0
  21. robert/gui_easyrob/bot/bot_engine.py +1100 -0
  22. robert/gui_easyrob/bot/bot_panel.py +1231 -0
  23. robert/gui_easyrob/bot/bot_rag.py +1178 -0
  24. robert/gui_easyrob/bot/bot_window.py +39 -0
  25. robert/gui_easyrob/bot/bot_worker.py +149 -0
  26. robert/gui_easyrob/bot/credential_store.py +143 -0
  27. robert/gui_easyrob/bot/error_parser.py +105 -0
  28. robert/gui_easyrob/bot/evidence_policy.py +164 -0
  29. robert/gui_easyrob/bot/heuristics.py +859 -0
  30. robert/gui_easyrob/bot/icons.py +56 -0
  31. robert/gui_easyrob/bot/input_csv_audit.py +212 -0
  32. robert/gui_easyrob/bot/knowledge/aqme_context.json +5907 -0
  33. robert/gui_easyrob/bot/knowledge/robert_context.json +4817 -0
  34. robert/gui_easyrob/bot/knowledge/ui_context.json +8293 -0
  35. robert/gui_easyrob/bot/knowledge_schema.py +1252 -0
  36. robert/gui_easyrob/bot/knowledge_sources/aqme_user_guidance.json +442 -0
  37. robert/gui_easyrob/bot/knowledge_sources/coverage_manifest.json +95 -0
  38. robert/gui_easyrob/bot/knowledge_sources/robert_user_guidance.json +471 -0
  39. robert/gui_easyrob/bot/knowledge_sources/ui_user_guidance.json +1312 -0
  40. robert/gui_easyrob/bot/llm_providers.py +1573 -0
  41. robert/gui_easyrob/bot/online_docs.py +105 -0
  42. robert/gui_easyrob/bot/prompt_policy.py +575 -0
  43. robert/gui_easyrob/bot/question_intent.py +562 -0
  44. robert/gui_easyrob/bot/response_quality.py +104 -0
  45. robert/gui_easyrob/bot/result_insights.py +225 -0
  46. robert/gui_easyrob/bot/token_usage.py +75 -0
  47. robert/gui_easyrob/bot/workflow_results.py +1396 -0
  48. robert/gui_easyrob/checkml_launcher.py +15 -0
  49. robert/gui_easyrob/easyrob.py +29 -0
  50. robert/gui_easyrob/easyrob_launcher.py +113 -0
  51. robert/gui_easyrob/main/__init__.py +9 -0
  52. robert/gui_easyrob/main/window.py +5152 -0
  53. robert/gui_easyrob/result_navigation.py +14 -0
  54. robert/gui_easyrob/tabs/__init__.py +23 -0
  55. robert/gui_easyrob/tabs/advanced_options.py +370 -0
  56. robert/gui_easyrob/tabs/aqme.py +1234 -0
  57. robert/gui_easyrob/tabs/checkml.py +898 -0
  58. robert/gui_easyrob/tabs/images.py +427 -0
  59. robert/gui_easyrob/tabs/interactive_predictions.py +555 -0
  60. robert/gui_easyrob/tabs/molssi.py +447 -0
  61. robert/gui_easyrob/tabs/predictions.py +484 -0
  62. robert/gui_easyrob/tabs/result_catalog.py +170 -0
  63. robert/gui_easyrob/tabs/results.py +490 -0
  64. robert/gui_easyrob/tabs/results_workspace.py +120 -0
  65. robert/gui_easyrob/test_bot_input_csv_audit.py +152 -0
  66. robert/gui_easyrob/test_bot_question_routing.py +383 -0
  67. robert/gui_easyrob/test_bot_result_analysis.py +356 -0
  68. robert/gui_easyrob/test_bot_retrieval_evaluation.py +110 -0
  69. robert/gui_easyrob/test_bot_ui_integration.py +278 -0
  70. robert/gui_easyrob/test_checkml_app_mode.py +124 -0
  71. robert/gui_easyrob/test_checkml_completion.py +57 -0
  72. robert/gui_easyrob/test_checkml_defaults.py +37 -0
  73. robert/gui_easyrob/test_checkml_result_summary.py +113 -0
  74. robert/gui_easyrob/test_checkml_web_mode.py +57 -0
  75. robert/gui_easyrob/test_dialog_layout.py +33 -0
  76. robert/gui_easyrob/test_gui_bot_regressions.py +320 -0
  77. robert/gui_easyrob/test_molssi_auto.py +569 -0
  78. robert/gui_easyrob/test_tutorial_view.py +215 -0
  79. robert/gui_easyrob/tutorials/check_model.md +25 -0
  80. robert/gui_easyrob/tutorials/chemdraw.md +49 -0
  81. robert/gui_easyrob/tutorials/csv.md +53 -0
  82. robert/gui_easyrob/tutorials/descriptors.md +21 -0
  83. robert/gui_easyrob/tutorials/overview.md +65 -0
  84. robert/gui_easyrob/tutorials/predictions.md +25 -0
  85. robert/gui_easyrob/tutorials/robbot.md +29 -0
  86. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_1.png +0 -0
  87. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_2.png +0 -0
  88. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_3.png +0 -0
  89. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_4.png +0 -0
  90. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_5.png +0 -0
  91. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_6.png +0 -0
  92. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_7.png +0 -0
  93. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_1.png +0 -0
  94. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_10.png +0 -0
  95. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_11.png +0 -0
  96. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_12.png +0 -0
  97. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_13.png +0 -0
  98. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_2.png +0 -0
  99. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_3.png +0 -0
  100. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_4.png +0 -0
  101. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_5.png +0 -0
  102. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_6.png +0 -0
  103. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_7.png +0 -0
  104. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_8.png +0 -0
  105. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_9.png +0 -0
  106. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1.png +0 -0
  107. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_1.png +0 -0
  108. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_2.png +0 -0
  109. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_3.png +0 -0
  110. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_4.png +0 -0
  111. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_5.png +0 -0
  112. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_2.png +0 -0
  113. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_3.png +0 -0
  114. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_4.png +0 -0
  115. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_5.png +0 -0
  116. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_6.png +0 -0
  117. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_7.png +0 -0
  118. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_8.png +0 -0
  119. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_9.png +0 -0
  120. robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_1.png +0 -0
  121. robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_2.png +0 -0
  122. robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_3.png +0 -0
  123. robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_4.png +0 -0
  124. robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_5.png +0 -0
  125. robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_6.png +0 -0
  126. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1.png +0 -0
  127. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_1.png +0 -0
  128. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_2.png +0 -0
  129. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_3.png +0 -0
  130. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_4.png +0 -0
  131. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_5.png +0 -0
  132. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_6.png +0 -0
  133. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_7.png +0 -0
  134. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_8.png +0 -0
  135. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_2.png +0 -0
  136. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_3.png +0 -0
  137. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_4.png +0 -0
  138. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5.png +0 -0
  139. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_1.png +0 -0
  140. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_2.png +0 -0
  141. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_3.png +0 -0
  142. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_6.png +0 -0
  143. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_1.png +0 -0
  144. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_1_1.png +0 -0
  145. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_2.png +0 -0
  146. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_3.png +0 -0
  147. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_4.png +0 -0
  148. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_5.png +0 -0
  149. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_6.png +0 -0
  150. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_1.png +0 -0
  151. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_2.png +0 -0
  152. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_3.png +0 -0
  153. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_4.png +0 -0
  154. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_5.png +0 -0
  155. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_6.png +0 -0
  156. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_7.png +0 -0
  157. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_8.png +0 -0
  158. robert/gui_easyrob/utils/__init__.py +0 -0
  159. robert/gui_easyrob/utils/aqme_utils.py +238 -0
  160. robert/gui_easyrob/utils/molssi_utils.py +584 -0
  161. robert/gui_easyrob/utils/predictions_utils.py +985 -0
  162. robert/gui_easyrob/utils/utils_gui.py +738 -0
  163. robert/gui_easyrob/version.py +68 -0
  164. robert/gui_easyrob/web/app.css +484 -0
  165. robert/gui_easyrob/web/app.html +134 -0
  166. robert/gui_easyrob/web/app.js +764 -0
  167. robert/gui_easyrob/web/checkml_brand.png +0 -0
  168. robert/gui_easyrob/web/easyrob_background.gif +0 -0
  169. robert/gui_easyrob/web/easyrob_background.png +0 -0
  170. robert/gui_easyrob/web/images.css +89 -0
  171. robert/gui_easyrob/web/images.html +39 -0
  172. robert/gui_easyrob/web/images.js +101 -0
  173. robert/gui_easyrob/web/results.js +499 -0
  174. robert/gui_easyrob/web/robert_brand.png +0 -0
  175. robert/gui_easyrob/web_dialogs.py +64 -0
  176. robert/gui_easyrob/web_results.py +253 -0
  177. robert/gui_easyrob/web_shell.py +684 -0
  178. robert/gui_easyrob/workflow_progress.py +89 -0
  179. robert/gui_easyrob/workflow_run_lock.py +27 -0
  180. robert/icons/CheckML_icon.png +0 -0
  181. robert/icons/Robert_icon.png +0 -0
  182. robert/icons/Robert_logo.jpg +0 -0
  183. robert/icons/Robert_logo_transparent.png +0 -0
  184. robert/icons/documentation_icon.png +0 -0
  185. robert/icons/info_icon.png +0 -0
  186. robert/icons/pdf_icon.png +0 -0
  187. robert/icons/play_icon.png +0 -0
  188. robert/icons/stop_icon.png +0 -0
  189. robert/icons/youtube_icon.ico +0 -0
  190. robert/predict.py +193 -0
  191. robert/predict_utils.py +410 -0
  192. robert/report/CheckML_logo.jpg +0 -0
  193. robert/report/GENERATE.png +0 -0
  194. robert/report/Robert_icon.ico +0 -0
  195. robert/report/Robert_logo.jpg +0 -0
  196. robert/report/Robert_logo1.jpg +0 -0
  197. robert/report/abbrev.png +0 -0
  198. robert/report/adv_anal.png +0 -0
  199. robert/report/checkml_pass.svg +3 -0
  200. robert/report/checkml_unclear.svg +3 -0
  201. robert/report/checkml_warning.svg +3 -0
  202. robert/report/features.png +0 -0
  203. robert/report/outliers.png +0 -0
  204. robert/report/pred.png +0 -0
  205. robert/report/repro.png +0 -0
  206. robert/report/robust_x.png +0 -0
  207. robert/report/robust_y_high.png +0 -0
  208. robert/report/robust_y_low.png +0 -0
  209. robert/report/score.png +0 -0
  210. robert/report/score_0.jpg +0 -0
  211. robert/report/score_1.jpg +0 -0
  212. robert/report/score_10.jpg +0 -0
  213. robert/report/score_2.jpg +0 -0
  214. robert/report/score_3.jpg +0 -0
  215. robert/report/score_4.jpg +0 -0
  216. robert/report/score_5.jpg +0 -0
  217. robert/report/score_6.jpg +0 -0
  218. robert/report/score_7.jpg +0 -0
  219. robert/report/score_8.jpg +0 -0
  220. robert/report/score_9.jpg +0 -0
  221. robert/report/score_gray_0.jpg +0 -0
  222. robert/report/score_gray_1.jpg +0 -0
  223. robert/report/score_gray_10.jpg +0 -0
  224. robert/report/score_gray_2.jpg +0 -0
  225. robert/report/score_gray_3.jpg +0 -0
  226. robert/report/score_gray_4.jpg +0 -0
  227. robert/report/score_gray_5.jpg +0 -0
  228. robert/report/score_gray_6.jpg +0 -0
  229. robert/report/score_gray_7.jpg +0 -0
  230. robert/report/score_gray_8.jpg +0 -0
  231. robert/report/score_gray_9.jpg +0 -0
  232. robert/report/score_w_1_0.jpg +0 -0
  233. robert/report/score_w_1_1.jpg +0 -0
  234. robert/report/score_w_2_0.jpg +0 -0
  235. robert/report/score_w_2_1.jpg +0 -0
  236. robert/report/score_w_2_2.jpg +0 -0
  237. robert/report/score_w_2_gray_0.jpg +0 -0
  238. robert/report/score_w_2_gray_1.jpg +0 -0
  239. robert/report/score_w_2_gray_2.jpg +0 -0
  240. robert/report/score_w_3_0.jpg +0 -0
  241. robert/report/score_w_3_1.jpg +0 -0
  242. robert/report/score_w_3_2.jpg +0 -0
  243. robert/report/score_w_3_3.jpg +0 -0
  244. robert/report/score_w_4_0.jpg +0 -0
  245. robert/report/score_w_4_1.JPG +0 -0
  246. robert/report/score_w_4_2.jpg +0 -0
  247. robert/report/score_w_4_3.jpg +0 -0
  248. robert/report/score_w_4_4.jpg +0 -0
  249. robert/report/transpa.png +0 -0
  250. robert/report/y_distrib.png +0 -0
  251. robert/report.py +2880 -0
  252. robert/report_utils.py +2270 -0
  253. robert/robert.py +181 -0
  254. robert/utils.py +4763 -0
  255. robert/verify.py +606 -0
  256. robert-2.2.0.dist-info/METADATA +55 -0
  257. robert-2.2.0.dist-info/RECORD +261 -0
  258. robert-2.2.0.dist-info/WHEEL +5 -0
  259. robert-2.2.0.dist-info/entry_points.txt +3 -0
  260. robert-2.2.0.dist-info/licenses/LICENSE +21 -0
  261. robert-2.2.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,484 @@
1
+ """
2
+ Prediction results viewer for easyROB.
3
+
4
+ This module loads prediction CSV files generated by ROBERT and presents them
5
+ in interactive, sortable tables enriched with model diagnostics and validation
6
+ artifacts.
7
+
8
+ Responsibilities:
9
+ - Discover and load prediction CSV files asynchronously
10
+ - Display results in sortable tables with custom models
11
+ - Provide statistical summaries and diagnostic panels
12
+ - Integrate report-derived artifacts (PDF fragments, plots)
13
+
14
+ Import strategy:
15
+ - Supports dual execution modes:
16
+ 1. Local (portable execution)
17
+ 2. Installed package (environment / entry point)
18
+
19
+ - Imports use a try/except fallback for compatibility.
20
+
21
+ Notes:
22
+ - Combines UI (Qt), data processing (pandas), and visualization (matplotlib)
23
+ - Designed to keep heavy logic delegated to utils.predictions_utils
24
+
25
+ """
26
+ # ------------------------------------------------------------
27
+ # Import resolution (local vs installed package)
28
+ # ------------------------------------------------------------
29
+ try:
30
+ from utils.utils_gui import (
31
+ QFrame,
32
+ QHBoxLayout,
33
+ QHeaderView,
34
+ QLabel,
35
+ QLineEdit,
36
+ QMenu,
37
+ QMessageBox,
38
+ QSize,
39
+ QSizePolicy,
40
+ QSplitter,
41
+ QTabWidget,
42
+ QTableView,
43
+ QThreadPool,
44
+ QVBoxLayout,
45
+ QWidget,
46
+ Qt,
47
+ Signal,
48
+ )
49
+
50
+ from utils.predictions_utils import (
51
+ LoadCsvTask,
52
+ NumericSortProxy,
53
+ PandasTableModel,
54
+ PredictionDashboardPanel,
55
+ StatsHeader,
56
+ evaluate_predictions_for_model,
57
+ extract_boundary_fragment,
58
+ extract_boundary_scores,
59
+ extract_robert_fragment_image,
60
+ find_external_test_pixmaps,
61
+ find_prediction_csvs,
62
+ get_robert_report_path,
63
+ )
64
+
65
+ except ImportError as e:
66
+ from robert.gui_easyrob.utils.utils_gui import (
67
+ QFrame,
68
+ QHBoxLayout,
69
+ QHeaderView,
70
+ QLabel,
71
+ QLineEdit,
72
+ QMenu,
73
+ QMessageBox,
74
+ QSize,
75
+ QSizePolicy,
76
+ QSplitter,
77
+ QTabWidget,
78
+ QTableView,
79
+ QThreadPool,
80
+ QVBoxLayout,
81
+ QWidget,
82
+ Qt,
83
+ Signal,
84
+ )
85
+
86
+ from robert.gui_easyrob.utils.predictions_utils import (
87
+ LoadCsvTask,
88
+ NumericSortProxy,
89
+ PandasTableModel,
90
+ PredictionDashboardPanel,
91
+ StatsHeader,
92
+ evaluate_predictions_for_model,
93
+ extract_boundary_fragment,
94
+ extract_boundary_scores,
95
+ extract_robert_fragment_image,
96
+ find_external_test_pixmaps,
97
+ find_prediction_csvs,
98
+ get_robert_report_path,
99
+ )
100
+
101
+ # ------------------------------------------------------------
102
+ # Standard library & third-party (keep explicit)
103
+ # ------------------------------------------------------------
104
+ import os
105
+ import re
106
+ import pandas as pd
107
+ import matplotlib.pyplot as plt
108
+
109
+ class PredictionsTab(QWidget):
110
+ """Tab for displaying prediction results from ROBERT runs."""
111
+ availabilityChanged = Signal(bool)
112
+
113
+ def __init__(self, parent=None):
114
+ super().__init__(parent)
115
+
116
+ self._thread_pool = QThreadPool.globalInstance()
117
+ self._load_generation = 0
118
+ self._pending_csv_signals = {}
119
+ self._catalog = None
120
+ self._selected_model = None
121
+ self.csv_paths = {}
122
+ self._report_paths = {}
123
+
124
+ layout = QVBoxLayout(self)
125
+
126
+ self.placeholder = QLabel("No prediction data available")
127
+ self.placeholder.setAlignment(Qt.AlignCenter)
128
+ layout.addWidget(self.placeholder)
129
+
130
+ self.subtabs = QTabWidget()
131
+ self.subtabs.hide()
132
+ layout.addWidget(self.subtabs)
133
+
134
+ # --------------------------------------------------
135
+ def _extract_names_column_from_predict(self):
136
+ """
137
+ Looks for PREDICT_data.dat inside the PREDICT folder
138
+ under the current run directory and extracts the value
139
+ passed to --names in the command line.
140
+ """
141
+ base_path = self._base_path
142
+
143
+ if os.path.isfile(base_path):
144
+ base_path = os.path.dirname(base_path)
145
+
146
+ predict_dir = os.path.join(base_path, "PREDICT")
147
+ dat_path = os.path.join(predict_dir, "PREDICT_data.dat")
148
+
149
+ if not os.path.exists(dat_path):
150
+ return None
151
+
152
+ with open(dat_path, "r", encoding="utf-8") as f:
153
+ content = f.read()
154
+
155
+ match = re.search(
156
+ r"""(?<!\S)--names(?:\s+|=)(?:"([^"]+)"|'([^']+)'|(\S+))""",
157
+ content,
158
+ )
159
+ if match:
160
+ return next(value for value in match.groups() if value is not None)
161
+
162
+ return None
163
+
164
+ def _filter_prediction_dataframe(self, df: pd.DataFrame) -> pd.DataFrame:
165
+ """
166
+ Prioritize identifying and prediction columns without dropping CSV data.
167
+ """
168
+
169
+ names_col = self._extract_names_column_from_predict()
170
+
171
+ smiles_cols = []
172
+ pred_cols = []
173
+ pred_sd_cols = []
174
+
175
+ for col in df.columns:
176
+ if col.lower() == "smiles":
177
+ smiles_cols.append(col)
178
+ elif col.endswith("_pred"):
179
+ pred_cols.append(col)
180
+ elif col.endswith("_pred_sd"):
181
+ pred_sd_cols.append(col)
182
+
183
+ ordered_columns = []
184
+
185
+ # Add Image column if smiles exists
186
+ if smiles_cols:
187
+ ordered_columns.append("Image")
188
+
189
+ if names_col and names_col in df.columns:
190
+ ordered_columns.append(names_col)
191
+
192
+ ordered_columns.extend(smiles_cols)
193
+ ordered_columns.extend(pred_cols)
194
+ ordered_columns.extend(pred_sd_cols)
195
+
196
+ if not ordered_columns:
197
+ return df
198
+
199
+ df = df.copy()
200
+
201
+ if smiles_cols and "Image" not in df.columns:
202
+ df.insert(0, "Image", df[smiles_cols[0]])
203
+
204
+ ordered_columns.extend(col for col in df.columns if col not in ordered_columns)
205
+ return df[ordered_columns]
206
+
207
+ def refresh_with_new_path(self, selected_file_path: str, catalog=None, model=None):
208
+ """Refreshes the predictions tab with new data from the selected file path."""
209
+ # This is the ONLY base path used by PredictionsTab
210
+ self._base_path = selected_file_path
211
+ self._catalog = catalog
212
+ self._selected_model = model
213
+ self._load_generation += 1
214
+ generation = self._load_generation
215
+ self._pending_csv_signals.clear()
216
+
217
+ csvs = (
218
+ catalog.external_predictions(model)
219
+ if catalog is not None and catalog.is_all_models
220
+ else find_prediction_csvs(selected_file_path)
221
+ )
222
+ self.csv_paths = csvs
223
+ self._report_paths = {}
224
+ if catalog is not None and catalog.is_all_models:
225
+ for variant, name in catalog.selected_variants(model).items():
226
+ self._report_paths[variant] = (
227
+ catalog.root / "REPORT_models"
228
+ / f"ROBERT_report_{name}_{variant}.pdf"
229
+ )
230
+
231
+ while self.subtabs.count():
232
+ page = self.subtabs.widget(0)
233
+ self.subtabs.removeTab(0)
234
+ page.deleteLater()
235
+
236
+ if not csvs:
237
+ self.subtabs.hide()
238
+ self.placeholder.show()
239
+ self.availabilityChanged.emit(False)
240
+ return
241
+
242
+ for key, path in csvs.items():
243
+ container = QLabel("Loading CSV…")
244
+ container.setAlignment(Qt.AlignCenter)
245
+ self.subtabs.addTab(container, key.replace("_", " "))
246
+
247
+ task = LoadCsvTask(key, path)
248
+ task_signals = task.signals
249
+ signal_key = (generation, key)
250
+ self._pending_csv_signals[signal_key] = task_signals
251
+ task_signals.done.connect(
252
+ lambda loaded_key, frame, run=generation, pending=signal_key:
253
+ self._finish_csv_load(loaded_key, frame, run, pending)
254
+ )
255
+ self._thread_pool.start(task)
256
+
257
+ self.placeholder.hide()
258
+ self.subtabs.show()
259
+ self.availabilityChanged.emit(True)
260
+
261
+ def _finish_csv_load(self, key, frame, generation, signal_key):
262
+ """Keep task signals alive until their CSV has reached the GUI thread."""
263
+ self._pending_csv_signals.pop(signal_key, None)
264
+ self._add_loaded_df(key, frame, generation)
265
+
266
+ def _add_loaded_df(self, key: str, df: pd.DataFrame, generation=None):
267
+ """Adds a dataframe to the predictions tab."""
268
+ if generation is not None and generation != self._load_generation:
269
+ return
270
+
271
+ # Filter dataframe columns
272
+ df = self._filter_prediction_dataframe(df)
273
+
274
+ pdf_path = self._report_paths.get(key) or get_robert_report_path(self._base_path, key)
275
+ info = evaluate_predictions_for_model(
276
+ self._base_path,
277
+ df,
278
+ key,
279
+ report_path=pdf_path,
280
+ )
281
+
282
+ # Extract fragment image
283
+ pdf_image = extract_robert_fragment_image(pdf_path)
284
+
285
+ widget = self._create_table_with_stats(df, info, pdf_image)
286
+ tab_name = key.replace("_", " ")
287
+
288
+ for i in range(self.subtabs.count()):
289
+ if self.subtabs.tabText(i) == tab_name:
290
+ old_page = self.subtabs.widget(i)
291
+ self.subtabs.removeTab(i)
292
+ self.subtabs.insertTab(i, widget, tab_name)
293
+ old_page.deleteLater()
294
+ break
295
+
296
+ # --------------------------------------------------
297
+ def _show_histogram_menu_header(self, pos, df: pd.DataFrame, header):
298
+ """Shows a histogram for the clicked column."""
299
+
300
+ column = header.logicalIndexAt(pos)
301
+ if column < 0:
302
+ return
303
+
304
+ col_name = df.columns[column]
305
+ series = df[col_name]
306
+
307
+ if not pd.api.types.is_numeric_dtype(series):
308
+ QMessageBox.information(self, "Histogram", "Column is not numeric")
309
+ return
310
+
311
+ menu = QMenu(header)
312
+ action = menu.addAction(f"Show histogram: {col_name}")
313
+
314
+ if menu.exec(header.mapToGlobal(pos)) == action:
315
+ self._show_histogram(series, col_name)
316
+
317
+ def _create_table_with_stats(self, df, info, pdf_image):
318
+ """Creates the main table view with the predictions and the side dashboard with stats and diagnostics."""
319
+
320
+ container = QWidget()
321
+ container.setStyleSheet("background: palette(window);")
322
+ layout = QVBoxLayout(container)
323
+ layout.setContentsMargins(10, 10, 10, 10)
324
+ layout.setSpacing(10)
325
+
326
+ toolbar = QHBoxLayout()
327
+ summary = QLabel(f"{info['model'].replace('_', ' ')} · {len(df)} predictions · {len(df.columns)} columns")
328
+ summary.setStyleSheet("font-size: 13px; font-weight: 600; padding: 4px;")
329
+ toolbar.addWidget(summary)
330
+ toolbar.addStretch()
331
+
332
+ search_column = self._extract_names_column_from_predict()
333
+ if search_column not in df.columns:
334
+ search_column = None
335
+ search = QLineEdit()
336
+ search.setObjectName("predictionSearch")
337
+ search.setPlaceholderText(f"Search {search_column}" if search_column else "Identifier unavailable")
338
+ search.setClearButtonEnabled(True)
339
+ search.setFixedWidth(220)
340
+ search.setEnabled(search_column is not None)
341
+ toolbar.addWidget(search)
342
+ layout.addLayout(toolbar)
343
+
344
+ table = QTableView()
345
+
346
+ base_model = PandasTableModel(df)
347
+ proxy = NumericSortProxy()
348
+ proxy.setSourceModel(base_model)
349
+ if search_column is not None:
350
+ proxy.setFilterKeyColumn(df.columns.get_loc(search_column))
351
+ proxy.setFilterCaseSensitivity(Qt.CaseInsensitive)
352
+ search.textChanged.connect(proxy.setFilterFixedString)
353
+ table.setModel(proxy)
354
+
355
+ has_images = "Image" in df.columns
356
+ table.verticalHeader().setDefaultSectionSize(130 if has_images else 34)
357
+ if has_images:
358
+ table.setIconSize(QSize(120, 120))
359
+ table.setAlternatingRowColors(True)
360
+ table.setWordWrap(False)
361
+ table.setSortingEnabled(True)
362
+ table.setSelectionBehavior(QTableView.SelectItems)
363
+ table.setSelectionMode(QTableView.ExtendedSelection)
364
+
365
+ header = StatsHeader(df, Qt.Horizontal, table)
366
+ table.setHorizontalHeader(header)
367
+
368
+ header.setSectionResizeMode(QHeaderView.ResizeToContents)
369
+ table.resizeColumnsToContents()
370
+ header.setSectionResizeMode(QHeaderView.Interactive)
371
+
372
+ if "Image" in df.columns:
373
+ image_col = df.columns.get_loc("Image")
374
+ table.setColumnWidth(image_col, 140)
375
+
376
+ header.setContextMenuPolicy(Qt.CustomContextMenu)
377
+ header.customContextMenuRequested.connect(
378
+ lambda pos, d=df, h=header: self._show_header_menu(pos, d, h)
379
+ )
380
+
381
+ # ---- Side Dashboard ----
382
+ pdf_path = info["pdf_path"]
383
+ model_key = info["model"] # "PFI" or "No_PFI"
384
+
385
+ # Boundary robustness data (regression only - None for classification, see
386
+ # extract_boundary_scores())
387
+ bound_score = extract_boundary_scores(pdf_path)
388
+ bound_pixmap = extract_boundary_fragment(pdf_path)
389
+
390
+ # External validation plot
391
+ external_pixmaps = find_external_test_pixmaps(
392
+ self._base_path,
393
+ (lambda path: self._catalog.include_image(path, self._selected_model))
394
+ if self._catalog is not None and self._catalog.is_all_models else None,
395
+ )
396
+ external_pixmap = external_pixmaps.get(model_key)
397
+
398
+ side_panel = PredictionDashboardPanel(
399
+ scenario=info["scenario"],
400
+ pdf_image=pdf_image,
401
+ boundary_score=bound_score,
402
+ boundary_image=bound_pixmap,
403
+ external_plot=external_pixmap
404
+ )
405
+
406
+ splitter = QSplitter(Qt.Horizontal)
407
+ splitter.addWidget(table)
408
+ splitter.addWidget(side_panel)
409
+ splitter.setStretchFactor(0, 3)
410
+ splitter.setStretchFactor(1, 1)
411
+ splitter.setSizes([800, 360])
412
+ layout.addWidget(splitter)
413
+
414
+ return container
415
+
416
+ def _show_header_menu(self, pos, df: pd.DataFrame, header):
417
+ """Shows a context menu for the table header with sorting and histogram options."""
418
+ column = header.logicalIndexAt(pos)
419
+ if column < 0:
420
+ return
421
+
422
+ col_name = df.columns[column]
423
+ series = df[col_name]
424
+
425
+ table = header.parent() # QTableView
426
+
427
+ menu = QMenu(header)
428
+
429
+ # Sorting actions
430
+ action_sort_asc = menu.addAction("Sort ascending")
431
+ action_sort_desc = menu.addAction("Sort descending")
432
+
433
+ menu.addSeparator()
434
+
435
+ # Histogram action (only for numeric columns)
436
+ action_hist = None
437
+ if pd.api.types.is_numeric_dtype(series):
438
+ action_hist = menu.addAction(f"Show histogram: {col_name}")
439
+
440
+ chosen = menu.exec(header.mapToGlobal(pos))
441
+
442
+ if chosen == action_sort_asc:
443
+ table.sortByColumn(column, Qt.AscendingOrder)
444
+
445
+ elif chosen == action_sort_desc:
446
+ table.sortByColumn(column, Qt.DescendingOrder)
447
+
448
+ elif action_hist is not None and chosen == action_hist:
449
+ self._show_histogram(series, col_name)
450
+
451
+ # --------------------------------------------------
452
+
453
+ def _show_histogram_menu(self, pos, df: pd.DataFrame, table: QTableView):
454
+ """Shows a context menu for the table header with sorting and histogram options."""
455
+ index = table.indexAt(pos)
456
+ if not index.isValid():
457
+ return
458
+
459
+ col_name = df.columns[index.column()]
460
+ series = df[col_name]
461
+
462
+ if not pd.api.types.is_numeric_dtype(series):
463
+ QMessageBox.information(self, "Histogram", "Column is not numeric")
464
+ return
465
+
466
+ menu = QMenu(table)
467
+ action = menu.addAction(f"Show histogram: {col_name}")
468
+
469
+ if menu.exec(table.viewport().mapToGlobal(pos)) == action:
470
+ self._show_histogram(series, col_name)
471
+
472
+ # --------------------------------------------------
473
+ def _show_histogram(self, series: pd.Series, col_name: str):
474
+ """Displays a histogram for the given numeric series."""
475
+ clean = series.dropna()
476
+
477
+ plt.figure()
478
+ clean.hist(bins=30)
479
+
480
+ plt.title(col_name)
481
+ plt.xlabel(col_name)
482
+ plt.ylabel("Frequency")
483
+ plt.grid(False)
484
+ plt.show(block=False)
@@ -0,0 +1,170 @@
1
+ """Discover model-specific ROBERT result files for the GUI."""
2
+
3
+ from dataclasses import dataclass
4
+ from pathlib import Path
5
+ import re
6
+
7
+
8
+ VARIANTS = ("No_PFI", "PFI")
9
+
10
+
11
+ def _model_and_variant(stem):
12
+ for variant in VARIANTS:
13
+ suffix = f"_{variant}"
14
+ if stem.endswith(suffix) and len(stem) > len(suffix):
15
+ return stem[:-len(suffix)], variant
16
+ return None
17
+
18
+
19
+ @dataclass(frozen=True)
20
+ class ResultCatalog:
21
+ """Describe the result files for a ROBERT run."""
22
+
23
+ root: Path
24
+ models: tuple[str, ...]
25
+ best_by_variant: dict[str, str]
26
+ is_all_models: bool
27
+
28
+ @classmethod
29
+ def discover(cls, run_dir):
30
+ """Find available model variants and ROBERT's selected best models."""
31
+ root = Path(run_dir)
32
+ model_variants = {}
33
+ for path in (root / "PREDICT").glob("*.csv"):
34
+ if path.name.startswith("Results_boundary_williams_"):
35
+ continue
36
+ parsed = _model_and_variant(path.stem)
37
+ if parsed:
38
+ model, variant = parsed
39
+ model_variants.setdefault(model, set()).add(variant)
40
+ for path in (root / "REPORT_models").glob("ROBERT_report_*.pdf"):
41
+ parsed = _model_and_variant(path.stem.removeprefix("ROBERT_report_"))
42
+ if parsed:
43
+ model, variant = parsed
44
+ model_variants.setdefault(model, set()).add(variant)
45
+
46
+ all_models = (
47
+ any((root / "REPORT_models").glob("ROBERT_report_*.pdf"))
48
+ or (root / "GENERATE" / "All_models").is_dir()
49
+ )
50
+
51
+ best = {}
52
+ if all_models:
53
+ # --all_models: report.py's organize_all_models_pdfs() already picked a single
54
+ # overall-best (model, variant) combining Interpolation and Boundary robustness
55
+ # together, and copied only that one PDF back into the working directory - read
56
+ # that directly instead of re-deriving a pick here. GENERATE/Best_model/{variant}
57
+ # is a DIFFERENT, older selection (RMSE-only, resolved independently per variant),
58
+ # which can disagree with the actual kept PDF and even differ between variants -
59
+ # showing both as "the best" is exactly the confusing, inconsistent result this
60
+ # replaces
61
+ for path in sorted(root.glob("ROBERT_report_*.pdf")):
62
+ parsed = _model_and_variant(path.stem.removeprefix("ROBERT_report_"))
63
+ if parsed:
64
+ model, variant = parsed
65
+ best[variant] = model
66
+ if not best:
67
+ # A partial or imported run can have model reports without the final
68
+ # PDF copied to the root. Use GENERATE's recorded selections then.
69
+ best_root = root / "GENERATE" / "Best_model"
70
+ for variant in VARIANTS:
71
+ candidates = sorted(
72
+ path for path in (best_root / variant).glob("*.csv")
73
+ if not path.stem.endswith("_db")
74
+ )
75
+ if candidates:
76
+ name = candidates[0].stem
77
+ best[variant] = name.removesuffix("_PFI") if variant == "PFI" else name
78
+ else:
79
+ # single-model run (no --all_models): both No_PFI and PFI are the same model,
80
+ # read straight from GENERATE/Best_model/{variant} as before
81
+ best_root = root / "GENERATE" / "Best_model"
82
+ for variant in VARIANTS:
83
+ candidates = sorted(
84
+ path for path in (best_root / variant).glob("*.csv")
85
+ if not path.stem.endswith("_db")
86
+ )
87
+ if candidates:
88
+ name = candidates[0].stem
89
+ best[variant] = name.removesuffix("_PFI") if variant == "PFI" else name
90
+ else:
91
+ for path in sorted(root.glob("ROBERT_report_*.pdf")):
92
+ parsed = _model_and_variant(path.stem.removeprefix("ROBERT_report_"))
93
+ if parsed and parsed[1] == variant:
94
+ best[variant] = parsed[0]
95
+ break
96
+ if variant not in best:
97
+ best[variant] = next(
98
+ (model for model in sorted(model_variants)
99
+ if variant in model_variants[model]),
100
+ "",
101
+ )
102
+ best = {variant: model for variant, model in best.items() if model}
103
+ return cls(root, tuple(sorted(model_variants)), best, all_models)
104
+
105
+ def selected_variants(self, model=None):
106
+ """Map each available PFI variant to its selected model."""
107
+ if model is None:
108
+ return self.best_by_variant
109
+ return {variant: model for variant in VARIANTS if (
110
+ self.root / "PREDICT" / f"{model}_{variant}.csv"
111
+ ).is_file() or (
112
+ self.root / "REPORT_models" / f"ROBERT_report_{model}_{variant}.pdf"
113
+ ).is_file()}
114
+
115
+ def report_paths(self, model=None):
116
+ """Return the default or selected model reports."""
117
+ if not self.is_all_models:
118
+ return sorted(self.root.glob("ROBERT_report*.pdf"))
119
+ if model is None:
120
+ retained = sorted(self.root.glob("ROBERT_report_*.pdf"))
121
+ if retained:
122
+ return retained
123
+ selected = self.selected_variants(model)
124
+ return [
125
+ path for variant in VARIANTS
126
+ if (name := selected.get(variant))
127
+ if (path := self.root / "REPORT_models" / f"ROBERT_report_{name}_{variant}.pdf").is_file()
128
+ ]
129
+
130
+ def internal_predictions(self, model=None):
131
+ """Return prediction CSVs for the selected model variants."""
132
+ selected = self.selected_variants(model)
133
+ return {
134
+ variant: path for variant in VARIANTS
135
+ if (name := selected.get(variant))
136
+ if (path := self.root / "PREDICT" / f"{name}_{variant}.csv").is_file()
137
+ }
138
+
139
+ def external_predictions(self, model=None):
140
+ """Return optional external test CSVs for the selected variants."""
141
+ selected = self.selected_variants(model)
142
+ paths = sorted((self.root / "PREDICT" / "csv_test").glob("*.csv"))
143
+ results = {}
144
+ for variant, name in selected.items():
145
+ match = next(
146
+ (path for path in paths if path.stem.endswith(f"_{name}_{variant}")),
147
+ None,
148
+ )
149
+ if match is not None:
150
+ results[variant] = match
151
+ return results
152
+
153
+ def plot_paths(self, model=None):
154
+ """List internal and optional external CSVs in display order."""
155
+ internal = self.internal_predictions(model)
156
+ external = self.external_predictions(model)
157
+ return [*internal.values(), *external.values()]
158
+
159
+ def include_image(self, path, model=None):
160
+ """Keep shared figures and figures matching the selected model variants."""
161
+ if not self.is_all_models:
162
+ return True
163
+ selected = self.selected_variants(model)
164
+ matched = [
165
+ (name, variant)
166
+ for name in self.models
167
+ for variant in VARIANTS
168
+ if re.search(rf"(?:^|_){re.escape(name)}_{variant}(?:_|$)", path.stem)
169
+ ]
170
+ return not matched or any(selected.get(variant) == name for name, variant in matched)