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.
- robert/__init__.py +9 -0
- robert/__main__.py +20 -0
- robert/_version.py +3 -0
- robert/api.py +646 -0
- robert/aqme.py +280 -0
- robert/argument_parser.py +98 -0
- robert/checkml.py +433 -0
- robert/checkml_score.py +50 -0
- robert/curate.py +217 -0
- robert/evaluate_bot_retrieval.py +125 -0
- robert/evaluate_bot_support.py +102 -0
- robert/evaluate_workflow_summaries.py +87 -0
- robert/export_bot_docs_knowledge.py +1632 -0
- robert/generate.py +249 -0
- robert/generate_utils.py +311 -0
- robert/gui_easyrob/__init__.py +0 -0
- robert/gui_easyrob/assets/gif_easyrob.gif +0 -0
- robert/gui_easyrob/bot/__init__.py +47 -0
- robert/gui_easyrob/bot/answer_metadata.py +198 -0
- robert/gui_easyrob/bot/bot_context.py +679 -0
- robert/gui_easyrob/bot/bot_engine.py +1100 -0
- robert/gui_easyrob/bot/bot_panel.py +1231 -0
- robert/gui_easyrob/bot/bot_rag.py +1178 -0
- robert/gui_easyrob/bot/bot_window.py +39 -0
- robert/gui_easyrob/bot/bot_worker.py +149 -0
- robert/gui_easyrob/bot/credential_store.py +143 -0
- robert/gui_easyrob/bot/error_parser.py +105 -0
- robert/gui_easyrob/bot/evidence_policy.py +164 -0
- robert/gui_easyrob/bot/heuristics.py +859 -0
- robert/gui_easyrob/bot/icons.py +56 -0
- robert/gui_easyrob/bot/input_csv_audit.py +212 -0
- robert/gui_easyrob/bot/knowledge/aqme_context.json +5907 -0
- robert/gui_easyrob/bot/knowledge/robert_context.json +4817 -0
- robert/gui_easyrob/bot/knowledge/ui_context.json +8293 -0
- robert/gui_easyrob/bot/knowledge_schema.py +1252 -0
- robert/gui_easyrob/bot/knowledge_sources/aqme_user_guidance.json +442 -0
- robert/gui_easyrob/bot/knowledge_sources/coverage_manifest.json +95 -0
- robert/gui_easyrob/bot/knowledge_sources/robert_user_guidance.json +471 -0
- robert/gui_easyrob/bot/knowledge_sources/ui_user_guidance.json +1312 -0
- robert/gui_easyrob/bot/llm_providers.py +1573 -0
- robert/gui_easyrob/bot/online_docs.py +105 -0
- robert/gui_easyrob/bot/prompt_policy.py +575 -0
- robert/gui_easyrob/bot/question_intent.py +562 -0
- robert/gui_easyrob/bot/response_quality.py +104 -0
- robert/gui_easyrob/bot/result_insights.py +225 -0
- robert/gui_easyrob/bot/token_usage.py +75 -0
- robert/gui_easyrob/bot/workflow_results.py +1396 -0
- robert/gui_easyrob/checkml_launcher.py +15 -0
- robert/gui_easyrob/easyrob.py +29 -0
- robert/gui_easyrob/easyrob_launcher.py +113 -0
- robert/gui_easyrob/main/__init__.py +9 -0
- robert/gui_easyrob/main/window.py +5152 -0
- robert/gui_easyrob/result_navigation.py +14 -0
- robert/gui_easyrob/tabs/__init__.py +23 -0
- robert/gui_easyrob/tabs/advanced_options.py +370 -0
- robert/gui_easyrob/tabs/aqme.py +1234 -0
- robert/gui_easyrob/tabs/checkml.py +898 -0
- robert/gui_easyrob/tabs/images.py +427 -0
- robert/gui_easyrob/tabs/interactive_predictions.py +555 -0
- robert/gui_easyrob/tabs/molssi.py +447 -0
- robert/gui_easyrob/tabs/predictions.py +484 -0
- robert/gui_easyrob/tabs/result_catalog.py +170 -0
- robert/gui_easyrob/tabs/results.py +490 -0
- robert/gui_easyrob/tabs/results_workspace.py +120 -0
- robert/gui_easyrob/test_bot_input_csv_audit.py +152 -0
- robert/gui_easyrob/test_bot_question_routing.py +383 -0
- robert/gui_easyrob/test_bot_result_analysis.py +356 -0
- robert/gui_easyrob/test_bot_retrieval_evaluation.py +110 -0
- robert/gui_easyrob/test_bot_ui_integration.py +278 -0
- robert/gui_easyrob/test_checkml_app_mode.py +124 -0
- robert/gui_easyrob/test_checkml_completion.py +57 -0
- robert/gui_easyrob/test_checkml_defaults.py +37 -0
- robert/gui_easyrob/test_checkml_result_summary.py +113 -0
- robert/gui_easyrob/test_checkml_web_mode.py +57 -0
- robert/gui_easyrob/test_dialog_layout.py +33 -0
- robert/gui_easyrob/test_gui_bot_regressions.py +320 -0
- robert/gui_easyrob/test_molssi_auto.py +569 -0
- robert/gui_easyrob/test_tutorial_view.py +215 -0
- robert/gui_easyrob/tutorials/check_model.md +25 -0
- robert/gui_easyrob/tutorials/chemdraw.md +49 -0
- robert/gui_easyrob/tutorials/csv.md +53 -0
- robert/gui_easyrob/tutorials/descriptors.md +21 -0
- robert/gui_easyrob/tutorials/overview.md +65 -0
- robert/gui_easyrob/tutorials/predictions.md +25 -0
- robert/gui_easyrob/tutorials/robbot.md +29 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_10.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_11.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_12.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_13.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_8.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_9.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_8.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_9.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_8.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_1_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_8.png +0 -0
- robert/gui_easyrob/utils/__init__.py +0 -0
- robert/gui_easyrob/utils/aqme_utils.py +238 -0
- robert/gui_easyrob/utils/molssi_utils.py +584 -0
- robert/gui_easyrob/utils/predictions_utils.py +985 -0
- robert/gui_easyrob/utils/utils_gui.py +738 -0
- robert/gui_easyrob/version.py +68 -0
- robert/gui_easyrob/web/app.css +484 -0
- robert/gui_easyrob/web/app.html +134 -0
- robert/gui_easyrob/web/app.js +764 -0
- robert/gui_easyrob/web/checkml_brand.png +0 -0
- robert/gui_easyrob/web/easyrob_background.gif +0 -0
- robert/gui_easyrob/web/easyrob_background.png +0 -0
- robert/gui_easyrob/web/images.css +89 -0
- robert/gui_easyrob/web/images.html +39 -0
- robert/gui_easyrob/web/images.js +101 -0
- robert/gui_easyrob/web/results.js +499 -0
- robert/gui_easyrob/web/robert_brand.png +0 -0
- robert/gui_easyrob/web_dialogs.py +64 -0
- robert/gui_easyrob/web_results.py +253 -0
- robert/gui_easyrob/web_shell.py +684 -0
- robert/gui_easyrob/workflow_progress.py +89 -0
- robert/gui_easyrob/workflow_run_lock.py +27 -0
- robert/icons/CheckML_icon.png +0 -0
- robert/icons/Robert_icon.png +0 -0
- robert/icons/Robert_logo.jpg +0 -0
- robert/icons/Robert_logo_transparent.png +0 -0
- robert/icons/documentation_icon.png +0 -0
- robert/icons/info_icon.png +0 -0
- robert/icons/pdf_icon.png +0 -0
- robert/icons/play_icon.png +0 -0
- robert/icons/stop_icon.png +0 -0
- robert/icons/youtube_icon.ico +0 -0
- robert/predict.py +193 -0
- robert/predict_utils.py +410 -0
- robert/report/CheckML_logo.jpg +0 -0
- robert/report/GENERATE.png +0 -0
- robert/report/Robert_icon.ico +0 -0
- robert/report/Robert_logo.jpg +0 -0
- robert/report/Robert_logo1.jpg +0 -0
- robert/report/abbrev.png +0 -0
- robert/report/adv_anal.png +0 -0
- robert/report/checkml_pass.svg +3 -0
- robert/report/checkml_unclear.svg +3 -0
- robert/report/checkml_warning.svg +3 -0
- robert/report/features.png +0 -0
- robert/report/outliers.png +0 -0
- robert/report/pred.png +0 -0
- robert/report/repro.png +0 -0
- robert/report/robust_x.png +0 -0
- robert/report/robust_y_high.png +0 -0
- robert/report/robust_y_low.png +0 -0
- robert/report/score.png +0 -0
- robert/report/score_0.jpg +0 -0
- robert/report/score_1.jpg +0 -0
- robert/report/score_10.jpg +0 -0
- robert/report/score_2.jpg +0 -0
- robert/report/score_3.jpg +0 -0
- robert/report/score_4.jpg +0 -0
- robert/report/score_5.jpg +0 -0
- robert/report/score_6.jpg +0 -0
- robert/report/score_7.jpg +0 -0
- robert/report/score_8.jpg +0 -0
- robert/report/score_9.jpg +0 -0
- robert/report/score_gray_0.jpg +0 -0
- robert/report/score_gray_1.jpg +0 -0
- robert/report/score_gray_10.jpg +0 -0
- robert/report/score_gray_2.jpg +0 -0
- robert/report/score_gray_3.jpg +0 -0
- robert/report/score_gray_4.jpg +0 -0
- robert/report/score_gray_5.jpg +0 -0
- robert/report/score_gray_6.jpg +0 -0
- robert/report/score_gray_7.jpg +0 -0
- robert/report/score_gray_8.jpg +0 -0
- robert/report/score_gray_9.jpg +0 -0
- robert/report/score_w_1_0.jpg +0 -0
- robert/report/score_w_1_1.jpg +0 -0
- robert/report/score_w_2_0.jpg +0 -0
- robert/report/score_w_2_1.jpg +0 -0
- robert/report/score_w_2_2.jpg +0 -0
- robert/report/score_w_2_gray_0.jpg +0 -0
- robert/report/score_w_2_gray_1.jpg +0 -0
- robert/report/score_w_2_gray_2.jpg +0 -0
- robert/report/score_w_3_0.jpg +0 -0
- robert/report/score_w_3_1.jpg +0 -0
- robert/report/score_w_3_2.jpg +0 -0
- robert/report/score_w_3_3.jpg +0 -0
- robert/report/score_w_4_0.jpg +0 -0
- robert/report/score_w_4_1.JPG +0 -0
- robert/report/score_w_4_2.jpg +0 -0
- robert/report/score_w_4_3.jpg +0 -0
- robert/report/score_w_4_4.jpg +0 -0
- robert/report/transpa.png +0 -0
- robert/report/y_distrib.png +0 -0
- robert/report.py +2880 -0
- robert/report_utils.py +2270 -0
- robert/robert.py +181 -0
- robert/utils.py +4763 -0
- robert/verify.py +606 -0
- robert-2.2.0.dist-info/METADATA +55 -0
- robert-2.2.0.dist-info/RECORD +261 -0
- robert-2.2.0.dist-info/WHEEL +5 -0
- robert-2.2.0.dist-info/entry_points.txt +3 -0
- robert-2.2.0.dist-info/licenses/LICENSE +21 -0
- 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)
|