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,584 @@
|
|
|
1
|
+
"""
|
|
2
|
+
MolSSI utilities for easyROB.
|
|
3
|
+
|
|
4
|
+
This module provides data-processing and background utilities for interacting
|
|
5
|
+
with MolSSI descriptor libraries and preparing datasets for model workflows.
|
|
6
|
+
|
|
7
|
+
Responsibilities:
|
|
8
|
+
- Download MolSSI datasets from remote APIs
|
|
9
|
+
- Resolve descriptor coverage for SMILES datasets
|
|
10
|
+
- Normalize and merge descriptor data into exportable formats
|
|
11
|
+
- Convert Excel-based MolSSI datasets into clean CSV files
|
|
12
|
+
- Run long operations in background threads to keep the GUI responsive
|
|
13
|
+
|
|
14
|
+
Architecture:
|
|
15
|
+
- Uses QThread-based workers for I/O-bound tasks (downloads, conversions)
|
|
16
|
+
- Uses RDKit for SMILES canonicalization and validation
|
|
17
|
+
- Communicates results back to the GUI via Qt signals
|
|
18
|
+
|
|
19
|
+
Notes:
|
|
20
|
+
- Designed to isolate data-processing logic from GUI components
|
|
21
|
+
- Handles partial failures gracefully when querying external services
|
|
22
|
+
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
# ------------------------------------------------------------
|
|
26
|
+
# Standard library
|
|
27
|
+
# ------------------------------------------------------------
|
|
28
|
+
from pathlib import Path
|
|
29
|
+
import os
|
|
30
|
+
import re
|
|
31
|
+
import tempfile
|
|
32
|
+
import urllib.parse
|
|
33
|
+
import zipfile
|
|
34
|
+
|
|
35
|
+
# ------------------------------------------------------------
|
|
36
|
+
# Third-party libraries
|
|
37
|
+
# ------------------------------------------------------------
|
|
38
|
+
import pandas as pd
|
|
39
|
+
import requests
|
|
40
|
+
|
|
41
|
+
from rdkit import Chem
|
|
42
|
+
|
|
43
|
+
from PySide6.QtCore import QThread, Signal
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
MOLSSI_BASE_URL = "https://descriptor-libraries.molssi.org"
|
|
47
|
+
SMILES_EXPORT_LIBRARIES = (
|
|
48
|
+
"acids",
|
|
49
|
+
"primary-amines",
|
|
50
|
+
"secondary-amines",
|
|
51
|
+
"amines",
|
|
52
|
+
"anilines",
|
|
53
|
+
"sulfonimidamides",
|
|
54
|
+
"cyanoarenes",
|
|
55
|
+
"unactivated-primary-alkyl-bromides",
|
|
56
|
+
"sulfonyl-fluorides",
|
|
57
|
+
"sulfonates",
|
|
58
|
+
"sulfides",
|
|
59
|
+
"aryl_bromide",
|
|
60
|
+
"nn-ligands-hydride",
|
|
61
|
+
"nn-ligands-fluoride",
|
|
62
|
+
"nn-ligands-ligand-only",
|
|
63
|
+
"kraken",
|
|
64
|
+
)
|
|
65
|
+
ID_EXPORT_LIBRARIES = ("quinones", "cyclic-olefins")
|
|
66
|
+
ALL_MOLSSI_LIBRARIES = (*SMILES_EXPORT_LIBRARIES, *ID_EXPORT_LIBRARIES)
|
|
67
|
+
COMPATIBLE_TEST_WORKBOOK_LIBRARIES = frozenset({
|
|
68
|
+
"primary-amines",
|
|
69
|
+
"secondary-amines",
|
|
70
|
+
"amines",
|
|
71
|
+
"sulfonimidamides",
|
|
72
|
+
"cyanoarenes",
|
|
73
|
+
"sulfonyl-fluorides",
|
|
74
|
+
"unactivated-primary-alkyl-bromides",
|
|
75
|
+
"sulfonates",
|
|
76
|
+
"kraken",
|
|
77
|
+
"quinones",
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
class MolSSIWorker(QThread):
|
|
81
|
+
"""Background worker responsible for resolving MolSSI descriptors."""
|
|
82
|
+
|
|
83
|
+
finished = Signal(dict)
|
|
84
|
+
|
|
85
|
+
def __init__(self, df, file_path, should_abort, debug=False):
|
|
86
|
+
super().__init__()
|
|
87
|
+
self.df = df
|
|
88
|
+
self.file_path = file_path
|
|
89
|
+
self.should_abort = should_abort
|
|
90
|
+
self.debug = debug
|
|
91
|
+
|
|
92
|
+
def run(self):
|
|
93
|
+
"""Run the MolSSI descriptor resolution process in a background thread."""
|
|
94
|
+
if self.should_abort():
|
|
95
|
+
return
|
|
96
|
+
|
|
97
|
+
result = resolve_molssi_descriptors(self.df)
|
|
98
|
+
if self.should_abort():
|
|
99
|
+
return
|
|
100
|
+
|
|
101
|
+
self.finished.emit(result)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class MolSSIDownloadWorker(QThread):
|
|
105
|
+
"""Background worker responsible for downloading MolSSI datasets."""
|
|
106
|
+
|
|
107
|
+
finished = Signal(str)
|
|
108
|
+
error = Signal(str)
|
|
109
|
+
|
|
110
|
+
def __init__(self, url, target_path, parent=None):
|
|
111
|
+
super().__init__(parent)
|
|
112
|
+
self.url = url
|
|
113
|
+
self.target_path = Path(target_path)
|
|
114
|
+
|
|
115
|
+
def run(self):
|
|
116
|
+
"""Download and validate an XLSX before replacing the target file."""
|
|
117
|
+
temporary_path = None
|
|
118
|
+
try:
|
|
119
|
+
self.target_path.parent.mkdir(parents=True, exist_ok=True)
|
|
120
|
+
with requests.get(self.url, stream=True, timeout=(5, 60)) as response:
|
|
121
|
+
response.raise_for_status()
|
|
122
|
+
with tempfile.NamedTemporaryFile(
|
|
123
|
+
mode="wb", prefix=".molssi-", suffix=".xlsx",
|
|
124
|
+
dir=self.target_path.parent, delete=False,
|
|
125
|
+
) as temporary_file:
|
|
126
|
+
temporary_path = Path(temporary_file.name)
|
|
127
|
+
for chunk in response.iter_content(chunk_size=1024 * 1024):
|
|
128
|
+
if chunk:
|
|
129
|
+
temporary_file.write(chunk)
|
|
130
|
+
with zipfile.ZipFile(temporary_path) as workbook:
|
|
131
|
+
members = set(workbook.namelist())
|
|
132
|
+
if not {"[Content_Types].xml", "xl/workbook.xml"}.issubset(members):
|
|
133
|
+
raise ValueError("The MolSSI download is not an XLSX workbook")
|
|
134
|
+
os.replace(temporary_path, self.target_path)
|
|
135
|
+
temporary_path = None
|
|
136
|
+
self.finished.emit(str(self.target_path))
|
|
137
|
+
except (requests.RequestException, OSError, ValueError, zipfile.BadZipFile) as exc:
|
|
138
|
+
self.error.emit(f"Unable to download a valid MolSSI XLSX dataset: {exc}")
|
|
139
|
+
finally:
|
|
140
|
+
if temporary_path is not None:
|
|
141
|
+
temporary_path.unlink(missing_ok=True)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def resolve_molssi_descriptors(df):
|
|
145
|
+
"""Resolve a full-coverage MolSSI descriptor dataset for a SMILES table."""
|
|
146
|
+
smiles_col = next((col for col in df.columns if str(col).casefold() == "smiles"), None)
|
|
147
|
+
|
|
148
|
+
if smiles_col is None:
|
|
149
|
+
return {
|
|
150
|
+
"available": False,
|
|
151
|
+
"export_df": None,
|
|
152
|
+
"library": None,
|
|
153
|
+
"data_type": None,
|
|
154
|
+
"reason": "No SMILES column found",
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
library_col = next(
|
|
158
|
+
(col for col in df.columns if str(col).casefold() == "molssi_library"), None
|
|
159
|
+
)
|
|
160
|
+
libraries = ALL_MOLSSI_LIBRARIES
|
|
161
|
+
if library_col is not None:
|
|
162
|
+
requested = df[library_col].dropna().astype(str).str.strip().str.casefold().unique()
|
|
163
|
+
if df[library_col].isna().any() or len(requested) != 1 or requested[0] not in libraries:
|
|
164
|
+
return {
|
|
165
|
+
"available": False,
|
|
166
|
+
"export_df": None,
|
|
167
|
+
"library": None,
|
|
168
|
+
"data_type": None,
|
|
169
|
+
"reason": f"Invalid MolSSI library selection: {', '.join(map(str, requested))}",
|
|
170
|
+
}
|
|
171
|
+
libraries = (requested[0],)
|
|
172
|
+
|
|
173
|
+
df_work = df.drop(columns=[library_col]).copy() if library_col is not None else df.copy()
|
|
174
|
+
original_input_columns = list(df_work.columns)
|
|
175
|
+
df_work["_smiles_canonical"] = df_work[smiles_col].apply(_canonical_smiles)
|
|
176
|
+
if df_work.empty or df_work["_smiles_canonical"].isna().any():
|
|
177
|
+
return {
|
|
178
|
+
"available": False,
|
|
179
|
+
"export_df": None,
|
|
180
|
+
"library": None,
|
|
181
|
+
"data_type": None,
|
|
182
|
+
"reason": "At least one SMILES is missing or invalid",
|
|
183
|
+
}
|
|
184
|
+
smiles_list = df_work["_smiles_canonical"].drop_duplicates().tolist()
|
|
185
|
+
|
|
186
|
+
for library in libraries:
|
|
187
|
+
data_types = ("DFT", "ML") if library == "kraken" else ("DFT",)
|
|
188
|
+
for data_type in data_types:
|
|
189
|
+
try:
|
|
190
|
+
if library in ID_EXPORT_LIBRARIES:
|
|
191
|
+
df_api = _query_molssi_by_id(smiles_list, library, data_type)
|
|
192
|
+
else:
|
|
193
|
+
df_api = _query_molssi_batched(smiles_list, library, data_type)
|
|
194
|
+
except (requests.ConnectionError, requests.Timeout):
|
|
195
|
+
return {
|
|
196
|
+
"available": False,
|
|
197
|
+
"export_df": None,
|
|
198
|
+
"library": None,
|
|
199
|
+
"data_type": None,
|
|
200
|
+
"reason": "MolSSI API is unavailable",
|
|
201
|
+
}
|
|
202
|
+
if df_api is None or "smiles" not in df_api.columns:
|
|
203
|
+
continue
|
|
204
|
+
canonical = df_api["smiles"].apply(_canonical_smiles)
|
|
205
|
+
if not set(smiles_list).issubset(set(canonical.dropna())):
|
|
206
|
+
continue
|
|
207
|
+
result = _prepare_export(
|
|
208
|
+
df_work, df_api, smiles_col, library, data_type, original_input_columns
|
|
209
|
+
)
|
|
210
|
+
if result["available"]:
|
|
211
|
+
return result
|
|
212
|
+
|
|
213
|
+
return {
|
|
214
|
+
"available": False,
|
|
215
|
+
"export_df": None,
|
|
216
|
+
"library": None,
|
|
217
|
+
"data_type": None,
|
|
218
|
+
"reason": "MolSSI does not provide full coverage",
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def _canonical_smiles(value):
|
|
223
|
+
"""Return an isomeric canonical SMILES, or None for invalid input."""
|
|
224
|
+
if not isinstance(value, str) or not value.strip():
|
|
225
|
+
return None
|
|
226
|
+
try:
|
|
227
|
+
molecule = Chem.MolFromSmiles(value.strip())
|
|
228
|
+
return Chem.MolToSmiles(molecule, canonical=True) if molecule is not None else None
|
|
229
|
+
except (TypeError, ValueError):
|
|
230
|
+
return None
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def _query_molssi_batched(smiles, library, data_type, query_key="molecule_smiles"):
|
|
234
|
+
"""Fetch descriptor records without exceeding practical GET URL lengths."""
|
|
235
|
+
if query_key not in {"molecule_smiles", "molecule_ids"}:
|
|
236
|
+
raise ValueError(f"Unsupported MolSSI batch query key: {query_key}")
|
|
237
|
+
frames = []
|
|
238
|
+
encoded_smiles = [urllib.parse.quote(value, safe="") for value in smiles]
|
|
239
|
+
batches = []
|
|
240
|
+
batch = []
|
|
241
|
+
for value in encoded_smiles:
|
|
242
|
+
if batch and (len(batch) >= 100 or sum(map(len, batch)) + len(batch) + len(value) > 1600):
|
|
243
|
+
batches.append(batch)
|
|
244
|
+
batch = []
|
|
245
|
+
batch.append(value)
|
|
246
|
+
if batch:
|
|
247
|
+
batches.append(batch)
|
|
248
|
+
|
|
249
|
+
for batch in batches:
|
|
250
|
+
url = (
|
|
251
|
+
f"{MOLSSI_BASE_URL}/api/{library}/molecules/data/export/batch"
|
|
252
|
+
f"?{query_key}={','.join(batch)}&data_type={data_type}&return_type=json"
|
|
253
|
+
)
|
|
254
|
+
try:
|
|
255
|
+
response = requests.get(url, timeout=(5, 30))
|
|
256
|
+
if response.status_code != 200:
|
|
257
|
+
return None
|
|
258
|
+
records = response.json()
|
|
259
|
+
if not isinstance(records, list) or not records:
|
|
260
|
+
return None
|
|
261
|
+
frames.append(pd.DataFrame(records))
|
|
262
|
+
except (requests.ConnectionError, requests.Timeout):
|
|
263
|
+
raise
|
|
264
|
+
except (requests.RequestException, ValueError):
|
|
265
|
+
return None
|
|
266
|
+
return pd.concat(frames, ignore_index=True)
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def _query_molssi_by_id(smiles, library, data_type):
|
|
270
|
+
"""Resolve exact structures through search before ID-based batch export."""
|
|
271
|
+
molecule_ids = []
|
|
272
|
+
for canonical_smiles in smiles:
|
|
273
|
+
exact_ids = set()
|
|
274
|
+
for skip in (0, 100, 200):
|
|
275
|
+
url = (
|
|
276
|
+
f"{MOLSSI_BASE_URL}/api/{library}/molecules/search/"
|
|
277
|
+
f"?substructure={urllib.parse.quote(canonical_smiles, safe='')}"
|
|
278
|
+
f"&skip={skip}&limit=100"
|
|
279
|
+
)
|
|
280
|
+
try:
|
|
281
|
+
response = requests.get(url, timeout=(5, 30))
|
|
282
|
+
if response.status_code != 200:
|
|
283
|
+
return None
|
|
284
|
+
candidates = response.json()
|
|
285
|
+
if not isinstance(candidates, list):
|
|
286
|
+
return None
|
|
287
|
+
except (requests.ConnectionError, requests.Timeout):
|
|
288
|
+
raise
|
|
289
|
+
except (requests.RequestException, ValueError):
|
|
290
|
+
return None
|
|
291
|
+
exact_ids.update(
|
|
292
|
+
str(candidate["molecule_id"])
|
|
293
|
+
for candidate in candidates
|
|
294
|
+
if isinstance(candidate, dict)
|
|
295
|
+
and candidate.get("molecule_id") is not None
|
|
296
|
+
and _canonical_smiles(candidate.get("smiles")) == canonical_smiles
|
|
297
|
+
)
|
|
298
|
+
if len(exact_ids) > 1:
|
|
299
|
+
return None
|
|
300
|
+
if len(candidates) < 100:
|
|
301
|
+
break
|
|
302
|
+
if skip == 200:
|
|
303
|
+
return None
|
|
304
|
+
if len(exact_ids) != 1:
|
|
305
|
+
return None
|
|
306
|
+
molecule_ids.extend(exact_ids)
|
|
307
|
+
return _query_molssi_batched(molecule_ids, library, data_type, query_key="molecule_ids")
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def _molssi_workbook_url(library_slug):
|
|
311
|
+
"""Build the published workbook URL for a known library."""
|
|
312
|
+
return f"{MOLSSI_BASE_URL}/{library_slug}/content/{library_slug}_library.xlsx"
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
def _molssi_test_dataset_available(library_slug, data_type):
|
|
316
|
+
"""Check that a published test workbook begins with an XLSX ZIP header."""
|
|
317
|
+
if library_slug not in COMPATIBLE_TEST_WORKBOOK_LIBRARIES or (
|
|
318
|
+
library_slug == "kraken" and data_type == "ML"
|
|
319
|
+
):
|
|
320
|
+
return False
|
|
321
|
+
try:
|
|
322
|
+
with requests.get(
|
|
323
|
+
_molssi_workbook_url(library_slug),
|
|
324
|
+
headers={"Range": "bytes=0-3"},
|
|
325
|
+
stream=True,
|
|
326
|
+
timeout=(5, 15),
|
|
327
|
+
) as response:
|
|
328
|
+
if response.status_code not in (200, 206):
|
|
329
|
+
return False
|
|
330
|
+
return next(response.iter_content(chunk_size=4), b"").startswith(b"PK\x03\x04")
|
|
331
|
+
except (requests.RequestException, OSError):
|
|
332
|
+
return False
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def validate_molssi_test_csv(csv_path, descriptor_columns):
|
|
336
|
+
"""Reject a test CSV that cannot supply the selected API descriptors."""
|
|
337
|
+
available_columns = set(pd.read_csv(csv_path, nrows=0).columns)
|
|
338
|
+
required_columns = {"SMILES", "code_name", *descriptor_columns}
|
|
339
|
+
missing = sorted(required_columns - available_columns)
|
|
340
|
+
if missing:
|
|
341
|
+
preview = ", ".join(missing[:5])
|
|
342
|
+
raise ValueError(
|
|
343
|
+
f"The MolSSI test CSV is missing {len(missing)} required columns: {preview}"
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
def write_csv_atomic(df, target_path):
|
|
348
|
+
"""Replace a CSV only after its complete contents have been written."""
|
|
349
|
+
target_path = Path(target_path)
|
|
350
|
+
temporary_path = None
|
|
351
|
+
try:
|
|
352
|
+
with tempfile.NamedTemporaryFile(
|
|
353
|
+
mode="w", encoding="utf-8", newline="", prefix=".molssi-",
|
|
354
|
+
suffix=".csv", dir=target_path.parent, delete=False,
|
|
355
|
+
) as temporary_file:
|
|
356
|
+
temporary_path = Path(temporary_file.name)
|
|
357
|
+
df.to_csv(temporary_file, index=False)
|
|
358
|
+
os.replace(temporary_path, target_path)
|
|
359
|
+
temporary_path = None
|
|
360
|
+
finally:
|
|
361
|
+
if temporary_path is not None:
|
|
362
|
+
temporary_path.unlink(missing_ok=True)
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
def _prepare_export(df_work, df_api, smiles_col, library, data_type, original_input_columns):
|
|
366
|
+
"""Prepare the merged MolSSI export DataFrame for use in easyROB."""
|
|
367
|
+
try:
|
|
368
|
+
df_api = df_api.copy()
|
|
369
|
+
descriptor_columns = [
|
|
370
|
+
column for column in df_api.columns if column not in {"molecule_id", "smiles"}
|
|
371
|
+
]
|
|
372
|
+
if not descriptor_columns or df_api[descriptor_columns].isna().all(axis=1).any():
|
|
373
|
+
raise ValueError("MolSSI returned no descriptors for at least one molecule")
|
|
374
|
+
descriptor_export_columns = [
|
|
375
|
+
fix_greek_caps_columns(
|
|
376
|
+
f"{column}_molssi" if column in original_input_columns else column
|
|
377
|
+
)
|
|
378
|
+
for column in descriptor_columns
|
|
379
|
+
]
|
|
380
|
+
df_api["_smiles_canonical"] = df_api["smiles"].apply(_canonical_smiles)
|
|
381
|
+
df_api = df_api.dropna(subset=["_smiles_canonical"])
|
|
382
|
+
if df_api["_smiles_canonical"].duplicated().any():
|
|
383
|
+
raise ValueError("MolSSI returned ambiguous records for the same SMILES")
|
|
384
|
+
|
|
385
|
+
has_name = any(str(column).casefold() in {"name", "code_name"} for column in original_input_columns)
|
|
386
|
+
if not has_name and "molecule_id" in df_api.columns:
|
|
387
|
+
df_api = df_api.rename(columns={"molecule_id": "code_name"})
|
|
388
|
+
else:
|
|
389
|
+
df_api = df_api.drop(columns=["molecule_id"], errors="ignore")
|
|
390
|
+
df_api = df_api.drop(columns=["smiles"])
|
|
391
|
+
export_df = df_work.merge(df_api, on="_smiles_canonical", how="left", sort=False, suffixes=("", "_molssi"))
|
|
392
|
+
export_df = export_df.drop(columns=["_smiles_canonical"])
|
|
393
|
+
cols = [smiles_col] + [column for column in export_df.columns if column != smiles_col]
|
|
394
|
+
export_df = export_df.loc[:, cols].copy()
|
|
395
|
+
export_df.columns = [
|
|
396
|
+
fix_greek_caps_columns(c) if c != smiles_col else c
|
|
397
|
+
for c in export_df.columns
|
|
398
|
+
]
|
|
399
|
+
if library == "kraken" and data_type == "ML":
|
|
400
|
+
test_dataset_status = "kraken_ml"
|
|
401
|
+
elif library not in COMPATIBLE_TEST_WORKBOOK_LIBRARIES:
|
|
402
|
+
test_dataset_status = "incompatible"
|
|
403
|
+
elif _molssi_test_dataset_available(library, data_type):
|
|
404
|
+
test_dataset_status = "available"
|
|
405
|
+
else:
|
|
406
|
+
test_dataset_status = "missing"
|
|
407
|
+
return {
|
|
408
|
+
"available": True,
|
|
409
|
+
"export_available": test_dataset_status == "available",
|
|
410
|
+
"test_dataset_status": test_dataset_status,
|
|
411
|
+
"export_df": export_df,
|
|
412
|
+
"descriptor_columns": descriptor_export_columns,
|
|
413
|
+
"library": library,
|
|
414
|
+
"data_type": data_type,
|
|
415
|
+
"reason": None,
|
|
416
|
+
}
|
|
417
|
+
except Exception as exc:
|
|
418
|
+
return {
|
|
419
|
+
"available": False,
|
|
420
|
+
"export_available": False,
|
|
421
|
+
"export_df": None,
|
|
422
|
+
"library": None,
|
|
423
|
+
"data_type": None,
|
|
424
|
+
"reason": str(exc),
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
def fix_greek_caps_columns(col: str) -> str:
|
|
429
|
+
"""Normalize Greek characters and canonical spelling in MolSSI headers."""
|
|
430
|
+
greek_map = {
|
|
431
|
+
"α": "alpha", "β": "beta", "γ": "gamma", "δ": "delta",
|
|
432
|
+
"ε": "epsilon", "ζ": "zeta", "η": "eta", "θ": "theta",
|
|
433
|
+
"ι": "iota", "κ": "kappa", "λ": "lambda", "μ": "mu",
|
|
434
|
+
"ν": "nu", "ξ": "xi", "ο": "omicron", "π": "pi",
|
|
435
|
+
"ρ": "rho", "σ": "sigma", "τ": "tau", "υ": "upsilon",
|
|
436
|
+
"φ": "phi", "χ": "chi", "ψ": "psi", "ω": "omega",
|
|
437
|
+
"Α": "alpha", "Β": "beta", "Γ": "gamma", "Δ": "delta",
|
|
438
|
+
"Ε": "epsilon", "Ζ": "zeta", "Η": "eta", "Θ": "theta",
|
|
439
|
+
"Ι": "iota", "Κ": "kappa", "Λ": "lambda", "Μ": "mu",
|
|
440
|
+
"Ν": "nu", "Ξ": "xi", "Ο": "omicron", "Π": "pi",
|
|
441
|
+
"Ρ": "rho", "Σ": "sigma", "Τ": "tau", "Υ": "upsilon",
|
|
442
|
+
"Φ": "phi", "Χ": "chi", "Ψ": "psi", "Ω": "omega",
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
for greek_char, latin in greek_map.items():
|
|
446
|
+
col = col.replace(greek_char, latin)
|
|
447
|
+
|
|
448
|
+
col = re.sub(r"(?<![A-Za-z0-9])low[_]?e(?![A-Za-z0-9])", "low_e", col, flags=re.IGNORECASE)
|
|
449
|
+
col = re.sub(r"(?<![A-Za-z0-9])boltz(?![A-Za-z0-9])", "boltz", col, flags=re.IGNORECASE)
|
|
450
|
+
return col
|
|
451
|
+
|
|
452
|
+
class ExcelToCSVWorker(QThread):
|
|
453
|
+
"""Convert MolSSI spreadsheets into normalized CSV files for easyROB."""
|
|
454
|
+
|
|
455
|
+
finished = Signal(str)
|
|
456
|
+
error = Signal(str)
|
|
457
|
+
|
|
458
|
+
def __init__(self, path):
|
|
459
|
+
super().__init__()
|
|
460
|
+
self.path = path
|
|
461
|
+
|
|
462
|
+
def _normalize_columns(self, df):
|
|
463
|
+
"""Normalize column names by stripping whitespace, replacing spaces with underscores, and fixing Greek characters."""
|
|
464
|
+
df = df.copy()
|
|
465
|
+
normalized = []
|
|
466
|
+
|
|
467
|
+
for column in df.columns:
|
|
468
|
+
col = str(column).replace("\xa0", "").strip().replace(" ", "_")
|
|
469
|
+
normalized.append(fix_greek_caps_columns(col))
|
|
470
|
+
|
|
471
|
+
df.columns = normalized
|
|
472
|
+
return df
|
|
473
|
+
|
|
474
|
+
def _force_string_key(self, df, key):
|
|
475
|
+
"""Ensure the join key column is treated as a string and cleaned of non-breaking spaces."""
|
|
476
|
+
if key in df.columns:
|
|
477
|
+
df[key] = df[key].astype(str).replace("\xa0", "", regex=True).str.strip()
|
|
478
|
+
return df
|
|
479
|
+
|
|
480
|
+
def _detect_descriptor_sheet(self, sheets):
|
|
481
|
+
"""Determine which sheet contains the descriptors."""
|
|
482
|
+
for name in ("Descriptors", "all_properties", "DFT"):
|
|
483
|
+
if name in sheets:
|
|
484
|
+
return name
|
|
485
|
+
if len(sheets) == 1:
|
|
486
|
+
return sheets[0]
|
|
487
|
+
return None
|
|
488
|
+
|
|
489
|
+
def _read_descriptors(self, sheet_name):
|
|
490
|
+
"""Read the descriptors from the spreadsheet."""
|
|
491
|
+
raw = pd.read_excel(self.path, sheet_name=sheet_name, header=None, nrows=15)
|
|
492
|
+
|
|
493
|
+
for i in range(min(15, len(raw))):
|
|
494
|
+
row = raw.iloc[i].astype(str).str.lower().tolist()
|
|
495
|
+
if any(key in row for key in ("id", "numerical_id", "compound_name", "smiles")):
|
|
496
|
+
return pd.read_excel(self.path, sheet_name=sheet_name, header=i)
|
|
497
|
+
|
|
498
|
+
return pd.read_excel(self.path, sheet_name=sheet_name)
|
|
499
|
+
|
|
500
|
+
def _find_smiles_column(self, columns):
|
|
501
|
+
"""Find the SMILES column in the spreadsheet."""
|
|
502
|
+
for col in columns:
|
|
503
|
+
if col.lower() in ("smiles", "canonical_smiles"):
|
|
504
|
+
return col
|
|
505
|
+
return None
|
|
506
|
+
|
|
507
|
+
def run(self):
|
|
508
|
+
"""Convert the spreadsheet into a CSV file."""
|
|
509
|
+
try:
|
|
510
|
+
with pd.ExcelFile(self.path) as xls:
|
|
511
|
+
sheets = xls.sheet_names
|
|
512
|
+
|
|
513
|
+
descriptor_sheet = self._detect_descriptor_sheet(sheets)
|
|
514
|
+
if not descriptor_sheet:
|
|
515
|
+
raise ValueError("No descriptor sheet found. Expected one of: Descriptors, all_properties, DFT")
|
|
516
|
+
|
|
517
|
+
df_desc = self._normalize_columns(self._read_descriptors(descriptor_sheet))
|
|
518
|
+
needs_merge = descriptor_sheet == "Descriptors"
|
|
519
|
+
|
|
520
|
+
if not needs_merge:
|
|
521
|
+
smiles_col = self._find_smiles_column(df_desc.columns)
|
|
522
|
+
if not smiles_col:
|
|
523
|
+
raise ValueError(f"No SMILES column found in {descriptor_sheet} sheet")
|
|
524
|
+
|
|
525
|
+
df_final = df_desc.rename(columns={smiles_col: "SMILES"})
|
|
526
|
+
for key in ("Compound_Name", "Kraken_ID", "ID", "id", "Numerical_ID"):
|
|
527
|
+
if key in df_final.columns and "code_name" not in df_final.columns:
|
|
528
|
+
df_final.rename(columns={key: "code_name"}, inplace=True)
|
|
529
|
+
break
|
|
530
|
+
else:
|
|
531
|
+
smiles_col_desc = self._find_smiles_column(df_desc.columns)
|
|
532
|
+
if smiles_col_desc:
|
|
533
|
+
df_final = df_desc.rename(columns={smiles_col_desc: "SMILES"})
|
|
534
|
+
for key in ("Compound_Name", "Kraken_ID", "ID", "id", "Numerical_ID"):
|
|
535
|
+
if key in df_final.columns and "code_name" not in df_final.columns:
|
|
536
|
+
df_final.rename(columns={key: "code_name"}, inplace=True)
|
|
537
|
+
break
|
|
538
|
+
else:
|
|
539
|
+
if "Identifiers" not in sheets:
|
|
540
|
+
raise ValueError("Identifiers sheet not found")
|
|
541
|
+
|
|
542
|
+
df_id = self._normalize_columns(pd.read_excel(self.path, sheet_name="Identifiers"))
|
|
543
|
+
smiles_col_id = self._find_smiles_column(df_id.columns)
|
|
544
|
+
if not smiles_col_id:
|
|
545
|
+
raise ValueError("No SMILES column found in Identifiers")
|
|
546
|
+
|
|
547
|
+
join_key = None
|
|
548
|
+
for key in ("Compound_Name", "ID", "Numerical_ID"):
|
|
549
|
+
if key in df_desc.columns and key in df_id.columns:
|
|
550
|
+
join_key = key
|
|
551
|
+
break
|
|
552
|
+
|
|
553
|
+
if not join_key:
|
|
554
|
+
raise ValueError(
|
|
555
|
+
"No valid join key found between Descriptors and Identifiers "
|
|
556
|
+
"(expected ID, Numerical_ID, or Compound_Name)"
|
|
557
|
+
)
|
|
558
|
+
|
|
559
|
+
df_desc = self._force_string_key(df_desc, join_key)
|
|
560
|
+
df_id = self._force_string_key(df_id, join_key)
|
|
561
|
+
df_final = df_desc.merge(
|
|
562
|
+
df_id[[join_key, smiles_col_id]],
|
|
563
|
+
on=join_key,
|
|
564
|
+
how="left",
|
|
565
|
+
validate="many_to_one",
|
|
566
|
+
)
|
|
567
|
+
|
|
568
|
+
if "code_name" not in df_final.columns:
|
|
569
|
+
df_final.rename(columns={join_key: "code_name"}, inplace=True)
|
|
570
|
+
|
|
571
|
+
df_final.rename(columns={smiles_col_id: "SMILES"}, inplace=True)
|
|
572
|
+
|
|
573
|
+
if df_final.empty or df_final["SMILES"].apply(_canonical_smiles).isna().any():
|
|
574
|
+
raise ValueError("The MolSSI workbook contains missing or invalid SMILES")
|
|
575
|
+
|
|
576
|
+
cols = ["SMILES"] + [c for c in df_final.columns if c != "SMILES"]
|
|
577
|
+
df_final = df_final[cols]
|
|
578
|
+
|
|
579
|
+
csv_path = Path(self.path).with_suffix(".csv")
|
|
580
|
+
write_csv_atomic(df_final, csv_path)
|
|
581
|
+
self.finished.emit(str(csv_path))
|
|
582
|
+
|
|
583
|
+
except Exception as exc:
|
|
584
|
+
self.error.emit(str(exc))
|