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,253 @@
1
+ """Read-only adapters for presenting existing result data in the web workspace."""
2
+
3
+ import base64
4
+ from functools import lru_cache
5
+ from io import BytesIO
6
+ import math
7
+ from pathlib import Path
8
+
9
+ import pymupdf as fitz
10
+ import pandas as pd
11
+ import numpy as np
12
+ from PySide6.QtCore import QBuffer, QIODevice, QUrl
13
+ from rdkit import Chem
14
+ from rdkit.Chem import Draw
15
+
16
+ try:
17
+ from utils.predictions_utils import (
18
+ evaluate_predictions_for_model, extract_boundary_fragment,
19
+ extract_boundary_scores, extract_robert_fragment_image,
20
+ find_external_test_pixmaps, get_robert_report_path,
21
+ )
22
+ except ImportError:
23
+ from robert.gui_easyrob.utils.predictions_utils import (
24
+ evaluate_predictions_for_model, extract_boundary_fragment,
25
+ extract_boundary_scores, extract_robert_fragment_image,
26
+ find_external_test_pixmaps, get_robert_report_path,
27
+ )
28
+
29
+
30
+ def _number(value):
31
+ """Return finite JSON numbers and map missing measurements to null."""
32
+ try:
33
+ result = float(value)
34
+ except (TypeError, ValueError):
35
+ return None
36
+ return result if math.isfinite(result) else None
37
+
38
+
39
+ def _cell(value):
40
+ if pd.isna(value):
41
+ return ""
42
+ return str(value)
43
+
44
+
45
+ def _prediction_name_column(frame, configured_name):
46
+ """Use the configured identifier or a recognizable column in the displayed CSV."""
47
+ columns = {str(column).casefold(): column for column in frame.columns}
48
+ for candidate in (configured_name, "code_name", "name", "sample_id", "compound_id", "id"):
49
+ if candidate and str(candidate).casefold() in columns:
50
+ return columns[str(candidate).casefold()]
51
+ return ""
52
+
53
+
54
+ @lru_cache(maxsize=512)
55
+ def _molecule_image(smiles, size=96):
56
+ if not smiles or not isinstance(smiles, str):
57
+ return ""
58
+ molecule = Chem.MolFromSmiles(smiles)
59
+ if molecule is None:
60
+ return ""
61
+ stream = BytesIO()
62
+ Draw.MolToImage(molecule, size=(size, size)).save(stream, format="PNG")
63
+ return "data:image/png;base64," + base64.b64encode(stream.getvalue()).decode("ascii")
64
+
65
+
66
+ def _pixmap_image(pixmap):
67
+ if pixmap is None or pixmap.isNull():
68
+ return ""
69
+ buffer = QBuffer()
70
+ buffer.open(QIODevice.OpenModeFlag.WriteOnly)
71
+ if not pixmap.save(buffer, "PNG"):
72
+ return ""
73
+ return "data:image/png;base64," + base64.b64encode(bytes(buffer.data())).decode("ascii")
74
+
75
+
76
+ class WebResultsService:
77
+ """Expose only files and rows already selected by the native result workspace."""
78
+
79
+ def __init__(self, window):
80
+ self.window = window
81
+ self._table_cache = {}
82
+ self._diagnostic_cache = {}
83
+
84
+ def report_page(self, report_index, page_index, zoom):
85
+ paths = list(self.window.results_tab.pdf_tabs)
86
+ if report_index < 0 or report_index >= len(paths):
87
+ return {"error": "Report is unavailable"}
88
+ path = Path(paths[report_index])
89
+ if not path.is_file():
90
+ return {"error": "Report file is unavailable"}
91
+ zoom = min(2.0, max(0.75, zoom))
92
+ try:
93
+ with fitz.open(path) as document:
94
+ count = len(document)
95
+ if count < 1:
96
+ return {"error": "Report has no pages"}
97
+ page_index = min(count - 1, max(0, page_index))
98
+ pixmap = document.load_page(page_index).get_pixmap(
99
+ matrix=fitz.Matrix(zoom, zoom), alpha=False,
100
+ )
101
+ image = base64.b64encode(pixmap.tobytes("png")).decode("ascii")
102
+ except (OSError, ValueError, RuntimeError) as error:
103
+ return {"error": f"Unable to render report: {error}"}
104
+ return {"name": path.name, "page": page_index, "pages": count,
105
+ "zoom": zoom, "image": "data:image/png;base64," + image}
106
+
107
+ def prediction_table(self, key, query, sort_column, descending, page_index):
108
+ tab = self.window.predictions_tab
109
+ path = tab.csv_paths.get(key)
110
+ if path is None or not Path(path).is_file():
111
+ return {"error": "Prediction table is unavailable"}
112
+ path = Path(path)
113
+ report = tab._report_paths.get(key) or get_robert_report_path(tab._base_path, key)
114
+ report_path = Path(report) if report else None
115
+ cache_key = (str(path), path.stat().st_mtime_ns, str(report or ""),
116
+ report_path.stat().st_mtime_ns if report_path and report_path.is_file() else 0)
117
+ if cache_key not in self._table_cache:
118
+ frame = tab._filter_prediction_dataframe(pd.read_csv(path))
119
+ info = evaluate_predictions_for_model(tab._base_path, frame, key, report_path=report)
120
+ numeric = {}
121
+ for column in frame.select_dtypes(include="number").columns:
122
+ series = pd.to_numeric(frame[column], errors="coerce").dropna()
123
+ numeric[column] = {"mean": _number(series.mean()), "min": _number(series.min()),
124
+ "median": _number(series.median()),
125
+ "max": _number(series.max())} if len(series) else {}
126
+ self._table_cache = {cache_key: (frame, info, numeric)}
127
+ frame, info, numeric = self._table_cache[cache_key]
128
+ name_column = _prediction_name_column(frame, tab._extract_names_column_from_predict())
129
+ filtered = frame
130
+ if query and name_column:
131
+ filtered = filtered[filtered[name_column].astype(str).str.contains(query, case=False, regex=False, na=False)]
132
+ if sort_column in filtered:
133
+ filtered = filtered.sort_values(sort_column, ascending=not descending,
134
+ na_position="last", kind="mergesort")
135
+ page_size = 30
136
+ pages = max(1, math.ceil(len(filtered) / page_size))
137
+ page_index = min(pages - 1, max(0, page_index))
138
+ visible = filtered.iloc[page_index * page_size:(page_index + 1) * page_size]
139
+ columns = list(frame.columns)
140
+ rows = []
141
+ for _, row in visible.iterrows():
142
+ values = [_cell(row[column]) for column in columns]
143
+ if "Image" in columns:
144
+ values[columns.index("Image")] = _molecule_image(row["Image"])
145
+ rows.append(values)
146
+ scenario = info.get("scenario") or {}
147
+ return {
148
+ "key": key, "columns": columns, "rows": rows, "total": len(filtered),
149
+ "allRows": len(frame), "page": page_index, "pages": pages,
150
+ "nameColumn": name_column, "numeric": numeric,
151
+ "scenario": {"state": scenario.get("state", "UNKNOWN"),
152
+ "messages": scenario.get("messages", []),
153
+ "recommendations": scenario.get("recommendations", [])},
154
+ }
155
+
156
+ def prediction_histogram(self, key, column):
157
+ path = self.window.predictions_tab.csv_paths.get(key)
158
+ if path is None or not Path(path).is_file():
159
+ return {"error": "Prediction table is unavailable"}
160
+ frame = self.window.predictions_tab._filter_prediction_dataframe(pd.read_csv(path))
161
+ if column not in frame or not pd.api.types.is_numeric_dtype(frame[column]):
162
+ return {"error": "Histogram requires a numeric column"}
163
+ values = pd.to_numeric(frame[column], errors="coerce").dropna().to_numpy(dtype=float)
164
+ values = values[np.isfinite(values)]
165
+ if not len(values):
166
+ return {"error": "No numeric values are available"}
167
+ counts, edges = np.histogram(values, bins=min(18, max(5, int(math.sqrt(len(values))))))
168
+ return {"column": column, "counts": counts.tolist(), "edges": edges.tolist()}
169
+
170
+ def prediction_diagnostics(self, key):
171
+ tab = self.window.predictions_tab
172
+ path = tab.csv_paths.get(key)
173
+ if path is None or not Path(path).is_file():
174
+ return {"error": "Prediction diagnostics are unavailable"}
175
+ path = Path(path)
176
+ report = tab._report_paths.get(key) or get_robert_report_path(tab._base_path, key)
177
+ report = Path(report)
178
+ cache_key = (str(path), path.stat().st_mtime_ns, str(report),
179
+ report.stat().st_mtime_ns if report.is_file() else 0)
180
+ if cache_key not in self._diagnostic_cache:
181
+ catalog = getattr(tab, "_catalog", None)
182
+ selected_model = getattr(tab, "_selected_model", None)
183
+ external = find_external_test_pixmaps(
184
+ tab._base_path,
185
+ (lambda image_path: catalog.include_image(image_path, selected_model))
186
+ if catalog is not None and catalog.is_all_models else None,
187
+ ).get(key)
188
+ result = {
189
+ "scoreImage": _pixmap_image(extract_robert_fragment_image(report)),
190
+ "boundaryScore": extract_boundary_scores(report),
191
+ "boundaryImage": _pixmap_image(extract_boundary_fragment(report)),
192
+ "externalImage": _pixmap_image(external),
193
+ }
194
+ self._diagnostic_cache = {cache_key: result}
195
+ return self._diagnostic_cache[cache_key]
196
+
197
+ def plot_data(self, index):
198
+ viewer = self.window.interactive_plots
199
+ if index < 0 or index >= len(viewer.paths):
200
+ return {"error": "Interactive plot is unavailable"}
201
+ if viewer.selector.currentIndex() != index or viewer.data is None:
202
+ viewer.selector.setCurrentIndex(index)
203
+ if viewer.data is None:
204
+ viewer._load_selected(index)
205
+ data = viewer.data
206
+ if data is None:
207
+ return {"error": viewer.details.text() or "Prediction data is unavailable"}
208
+ frame = data["frame"]
209
+ identifier = data.get("name_column")
210
+ if identifier not in frame:
211
+ identifier = next((column for column in ("code_name", "Name", "name", "ID") if column in frame), None)
212
+ external = viewer.paths[index].parent.name == "csv_test"
213
+ points = []
214
+ for row_index in range(len(frame)):
215
+ row = frame.iloc[row_index]
216
+ group = _cell(row["Set"]) if "Set" in frame else ("External" if external else "Data")
217
+ points.append({
218
+ "index": row_index, "label": _cell(row[identifier]) if identifier else f"Row {row_index + 1}",
219
+ "group": group, "observed": _number(data["observed"][row_index]),
220
+ "predicted": _number(data["predicted"][row_index]),
221
+ "residual": _number(data["residual"][row_index]),
222
+ "outlier": _number(data["outlier_score"][row_index]),
223
+ "sd": _number(row[f"{data['target']}_pred_sd"]) if f"{data['target']}_pred_sd" in frame else None,
224
+ })
225
+ williams = []
226
+ if viewer.williams_data is not None:
227
+ for row_index, row in viewer.williams_data.iterrows():
228
+ williams.append({
229
+ "index": int(row_index), "label": _cell(row["point_id"]),
230
+ "group": _cell(row["group"]), "x": _number(row["leverage"]),
231
+ "y": _number(row["standardized_residual"]),
232
+ "hStar": _number(row["h_star"]),
233
+ "observed": _number(row["observed"]),
234
+ "predicted": _number(row["predicted"]),
235
+ })
236
+ return {
237
+ "name": viewer.paths[index].name, "target": data["target"],
238
+ "cvLabel": viewer.cv_label, "threshold": viewer.outlier_threshold,
239
+ "points": points, "williams": williams,
240
+ "williamsImage": QUrl.fromLocalFile(str(viewer.williams_image)).toString()
241
+ if viewer.williams_image is not None else "",
242
+ }
243
+
244
+ def plot_molecule(self, plot_index, row_index, williams):
245
+ viewer = self.window.interactive_plots
246
+ if viewer.selector.currentIndex() != plot_index or viewer.data is None:
247
+ self.plot_data(plot_index)
248
+ if viewer.data is None:
249
+ return ""
250
+ source = viewer.williams_smiles if williams else viewer.data["smiles"]
251
+ if row_index < 0 or row_index >= len(source):
252
+ return ""
253
+ return _molecule_image(source[row_index], 240)