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,569 @@
|
|
|
1
|
+
"""Regression checks for automatic MolSSI descriptor detection."""
|
|
2
|
+
|
|
3
|
+
from io import BytesIO
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import tempfile
|
|
6
|
+
from types import SimpleNamespace
|
|
7
|
+
import zipfile
|
|
8
|
+
|
|
9
|
+
import pandas as pd
|
|
10
|
+
import pytest
|
|
11
|
+
import requests
|
|
12
|
+
|
|
13
|
+
from gui_easyrob.utils import molssi_utils
|
|
14
|
+
from scripts.create_molssi_smoke_csvs import KRAKEN_ML_SAMPLE, SAMPLES, TEST_WORKBOOKS
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@pytest.fixture
|
|
18
|
+
def workspace_tmp_path():
|
|
19
|
+
with tempfile.TemporaryDirectory(dir=Path(__file__).parent) as directory:
|
|
20
|
+
yield Path(directory)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class ApiResponse:
|
|
24
|
+
def __init__(self, records, status_code=200):
|
|
25
|
+
self.records = records
|
|
26
|
+
self.status_code = status_code
|
|
27
|
+
|
|
28
|
+
def json(self):
|
|
29
|
+
return self.records
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class DownloadResponse:
|
|
33
|
+
def __init__(self, content, status_code=200):
|
|
34
|
+
self.content = content
|
|
35
|
+
self.status_code = status_code
|
|
36
|
+
|
|
37
|
+
def __enter__(self):
|
|
38
|
+
return self
|
|
39
|
+
|
|
40
|
+
def __exit__(self, *_args):
|
|
41
|
+
return None
|
|
42
|
+
|
|
43
|
+
def raise_for_status(self):
|
|
44
|
+
if self.status_code >= 400:
|
|
45
|
+
raise ValueError(f"HTTP {self.status_code}")
|
|
46
|
+
|
|
47
|
+
def iter_content(self, chunk_size):
|
|
48
|
+
for offset in range(0, len(self.content), chunk_size):
|
|
49
|
+
yield self.content[offset:offset + chunk_size]
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def workbook_bytes():
|
|
53
|
+
buffer = BytesIO()
|
|
54
|
+
with zipfile.ZipFile(buffer, "w") as archive:
|
|
55
|
+
archive.writestr("[Content_Types].xml", "<Types/>")
|
|
56
|
+
archive.writestr("xl/workbook.xml", "<workbook/>")
|
|
57
|
+
return buffer.getvalue()
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_resolution_preserves_names_smiles_and_repeated_input_rows(monkeypatch):
|
|
61
|
+
def fake_get(url, **_kwargs):
|
|
62
|
+
if "/api/acids/" in url:
|
|
63
|
+
return ApiResponse([{"molecule_id": "acid-1", "smiles": "CC(=O)O", "HOMO": -0.2}])
|
|
64
|
+
return ApiResponse([])
|
|
65
|
+
|
|
66
|
+
monkeypatch.setattr(molssi_utils.requests, "get", fake_get)
|
|
67
|
+
monkeypatch.setattr(molssi_utils, "_molssi_test_dataset_available", lambda _slug, _type: False)
|
|
68
|
+
source = pd.DataFrame(
|
|
69
|
+
{"Name": ["first", "second"], "SMILES": ["CC(=O)O", "CC(=O)O"], "target": [1, 2]}
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
result = molssi_utils.resolve_molssi_descriptors(source)
|
|
73
|
+
|
|
74
|
+
assert result["available"] is True
|
|
75
|
+
assert result["export_df"]["Name"].tolist() == ["first", "second"]
|
|
76
|
+
assert result["export_df"]["SMILES"].tolist() == ["CC(=O)O", "CC(=O)O"]
|
|
77
|
+
assert result["export_df"]["target"].tolist() == [1, 2]
|
|
78
|
+
assert result["export_df"]["HOMO"].tolist() == [-0.2, -0.2]
|
|
79
|
+
assert "molecule_id" not in result["export_df"]
|
|
80
|
+
assert result["descriptor_columns"] == ["HOMO"]
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def test_invalid_smiles_cannot_be_reported_as_fully_covered(monkeypatch):
|
|
84
|
+
monkeypatch.setattr(
|
|
85
|
+
molssi_utils.requests, "get", lambda *_args, **_kwargs: ApiResponse(
|
|
86
|
+
[{"molecule_id": "acid-1", "smiles": "CC(=O)O", "HOMO": -0.2}]
|
|
87
|
+
)
|
|
88
|
+
)
|
|
89
|
+
source = pd.DataFrame({"SMILES": ["CC(=O)O", "not a smiles"]})
|
|
90
|
+
|
|
91
|
+
result = molssi_utils.resolve_molssi_descriptors(source)
|
|
92
|
+
|
|
93
|
+
assert result["available"] is False
|
|
94
|
+
assert result["export_df"] is None
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def test_new_aryl_bromide_connection_has_api_name_and_smiles(monkeypatch):
|
|
98
|
+
def fake_get(url, **_kwargs):
|
|
99
|
+
if "/api/aryl_bromide/" in url:
|
|
100
|
+
return ApiResponse(
|
|
101
|
+
[{"molecule_id": "arbr1547", "smiles": "Brc1ccccc1", "HOMO": -0.3}]
|
|
102
|
+
)
|
|
103
|
+
return ApiResponse([])
|
|
104
|
+
|
|
105
|
+
monkeypatch.setattr(molssi_utils.requests, "get", fake_get)
|
|
106
|
+
monkeypatch.setattr(molssi_utils, "_molssi_test_dataset_available", lambda _slug, _type: False)
|
|
107
|
+
|
|
108
|
+
result = molssi_utils.resolve_molssi_descriptors(pd.DataFrame({"SMILES": ["Brc1ccccc1"]}))
|
|
109
|
+
|
|
110
|
+
assert result["library"] == "aryl_bromide"
|
|
111
|
+
assert result["export_df"]["code_name"].tolist() == ["arbr1547"]
|
|
112
|
+
assert result["export_df"]["SMILES"].tolist() == ["Brc1ccccc1"]
|
|
113
|
+
assert result["export_df"]["HOMO"].tolist() == [-0.3]
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def test_kraken_ml_descriptors_do_not_offer_dft_test_workbook(monkeypatch):
|
|
117
|
+
def fake_get(url, **_kwargs):
|
|
118
|
+
if "/api/kraken/" in url and "data_type=ML" in url:
|
|
119
|
+
return ApiResponse(
|
|
120
|
+
[{"molecule_id": 17, "smiles": "c1ccc(P(c2ccccc2)c2ccccc2)cc1", "dipolemoment_max": 1.6}]
|
|
121
|
+
)
|
|
122
|
+
return ApiResponse([])
|
|
123
|
+
|
|
124
|
+
monkeypatch.setattr(molssi_utils.requests, "get", fake_get)
|
|
125
|
+
monkeypatch.setattr(molssi_utils, "_molssi_test_dataset_available", lambda _slug, _type: True)
|
|
126
|
+
source = pd.DataFrame({"SMILES": ["P(c1ccccc1)(c1ccccc1)c1ccccc1"]})
|
|
127
|
+
|
|
128
|
+
result = molssi_utils.resolve_molssi_descriptors(source)
|
|
129
|
+
|
|
130
|
+
assert result["available"] is True
|
|
131
|
+
assert result["library"] == "kraken"
|
|
132
|
+
assert result["data_type"] == "ML"
|
|
133
|
+
assert result["export_available"] is False
|
|
134
|
+
assert result["export_df"]["code_name"].tolist() == [17]
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def test_test_workbook_probe_rejects_html_and_accepts_xlsx(monkeypatch):
|
|
138
|
+
monkeypatch.setattr(
|
|
139
|
+
molssi_utils.requests, "get", lambda *_args, **_kwargs: DownloadResponse(b"<html>not found</html>")
|
|
140
|
+
)
|
|
141
|
+
assert molssi_utils._molssi_test_dataset_available("primary-amines", "DFT") is False
|
|
142
|
+
|
|
143
|
+
monkeypatch.setattr(
|
|
144
|
+
molssi_utils.requests, "get", lambda *_args, **_kwargs: DownloadResponse(workbook_bytes())
|
|
145
|
+
)
|
|
146
|
+
assert molssi_utils._molssi_test_dataset_available("primary-amines", "DFT") is True
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def test_download_worker_rejects_html_without_replacing_existing_workbook(monkeypatch, tmp_path):
|
|
150
|
+
target = tmp_path / "acids_library.xlsx"
|
|
151
|
+
original_workbook = workbook_bytes()
|
|
152
|
+
target.write_bytes(original_workbook)
|
|
153
|
+
monkeypatch.setattr(
|
|
154
|
+
molssi_utils.requests, "get", lambda *_args, **_kwargs: DownloadResponse(b"<html>site home</html>")
|
|
155
|
+
)
|
|
156
|
+
errors = []
|
|
157
|
+
worker = molssi_utils.MolSSIDownloadWorker(
|
|
158
|
+
"https://descriptor-libraries.molssi.org/acids/content/acids_library.xlsx", target
|
|
159
|
+
)
|
|
160
|
+
worker.error.connect(errors.append)
|
|
161
|
+
|
|
162
|
+
worker.run()
|
|
163
|
+
|
|
164
|
+
assert errors
|
|
165
|
+
assert "XLSX" in errors[0]
|
|
166
|
+
assert target.read_bytes() == original_workbook
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def test_download_worker_streams_valid_workbook(monkeypatch):
|
|
170
|
+
monkeypatch.setattr(
|
|
171
|
+
molssi_utils.requests, "get", lambda *_args, **_kwargs: DownloadResponse(workbook_bytes())
|
|
172
|
+
)
|
|
173
|
+
with tempfile.TemporaryDirectory(dir=Path(__file__).parent) as directory:
|
|
174
|
+
target = Path(directory) / "acids_library.xlsx"
|
|
175
|
+
completed = []
|
|
176
|
+
errors = []
|
|
177
|
+
worker = molssi_utils.MolSSIDownloadWorker(
|
|
178
|
+
"https://descriptor-libraries.molssi.org/acids/content/acids_library.xlsx", target
|
|
179
|
+
)
|
|
180
|
+
worker.finished.connect(completed.append)
|
|
181
|
+
worker.error.connect(errors.append)
|
|
182
|
+
|
|
183
|
+
worker.run()
|
|
184
|
+
|
|
185
|
+
assert completed == [str(target)], errors
|
|
186
|
+
assert target.read_bytes() == workbook_bytes()
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def test_conversion_rejects_unmatched_smiles_in_identifier_sheet(tmp_path):
|
|
190
|
+
workbook = tmp_path / "library.xlsx"
|
|
191
|
+
with pd.ExcelWriter(workbook) as writer:
|
|
192
|
+
pd.DataFrame({"Compound Name": ["A", "B"], "HOMO": [-0.2, -0.3]}).to_excel(
|
|
193
|
+
writer, sheet_name="Descriptors", index=False
|
|
194
|
+
)
|
|
195
|
+
pd.DataFrame({"Compound Name": ["A"], "SMILES": ["CCO"]}).to_excel(
|
|
196
|
+
writer, sheet_name="Identifiers", index=False
|
|
197
|
+
)
|
|
198
|
+
worker = molssi_utils.ExcelToCSVWorker(str(workbook))
|
|
199
|
+
errors = []
|
|
200
|
+
worker.error.connect(errors.append)
|
|
201
|
+
|
|
202
|
+
worker.run()
|
|
203
|
+
|
|
204
|
+
assert errors
|
|
205
|
+
assert not workbook.with_suffix(".csv").exists()
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def test_conversion_keeps_corresponding_name_smiles_and_descriptors(workspace_tmp_path):
|
|
209
|
+
workbook = workspace_tmp_path / "library.xlsx"
|
|
210
|
+
with pd.ExcelWriter(workbook) as writer:
|
|
211
|
+
pd.DataFrame({"Compound Name": ["A", "B"], "HOMO": [-0.2, -0.3]}).to_excel(
|
|
212
|
+
writer, sheet_name="Descriptors", index=False
|
|
213
|
+
)
|
|
214
|
+
pd.DataFrame({"Compound Name": ["B", "A"], "SMILES": ["CCC", "CCO"]}).to_excel(
|
|
215
|
+
writer, sheet_name="Identifiers", index=False
|
|
216
|
+
)
|
|
217
|
+
completed = []
|
|
218
|
+
worker = molssi_utils.ExcelToCSVWorker(str(workbook))
|
|
219
|
+
worker.finished.connect(completed.append)
|
|
220
|
+
|
|
221
|
+
worker.run()
|
|
222
|
+
|
|
223
|
+
assert completed == [str(workbook.with_suffix(".csv"))]
|
|
224
|
+
exported = pd.read_csv(completed[0])
|
|
225
|
+
assert exported["code_name"].tolist() == ["A", "B"]
|
|
226
|
+
assert exported["SMILES"].tolist() == ["CCO", "CCC"]
|
|
227
|
+
assert exported["HOMO"].tolist() == [-0.2, -0.3]
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def test_connection_failure_stops_further_library_requests(monkeypatch):
|
|
231
|
+
calls = []
|
|
232
|
+
|
|
233
|
+
def disconnected(url, **_kwargs):
|
|
234
|
+
calls.append(url)
|
|
235
|
+
raise requests.ConnectionError("offline")
|
|
236
|
+
|
|
237
|
+
monkeypatch.setattr(molssi_utils.requests, "get", disconnected)
|
|
238
|
+
|
|
239
|
+
result = molssi_utils.resolve_molssi_descriptors(pd.DataFrame({"SMILES": ["CCO"]}))
|
|
240
|
+
|
|
241
|
+
assert result["available"] is False
|
|
242
|
+
assert "unavailable" in result["reason"].lower()
|
|
243
|
+
assert len(calls) == 1
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def test_response_without_descriptors_is_not_offered(monkeypatch):
|
|
247
|
+
def fake_get(url, **_kwargs):
|
|
248
|
+
if "/api/acids/" in url:
|
|
249
|
+
return ApiResponse([{"molecule_id": "Ac1", "smiles": "CC(=O)O"}])
|
|
250
|
+
return ApiResponse([])
|
|
251
|
+
|
|
252
|
+
monkeypatch.setattr(molssi_utils.requests, "get", fake_get)
|
|
253
|
+
monkeypatch.setattr(molssi_utils, "_molssi_test_dataset_available", lambda _slug, _type: False)
|
|
254
|
+
|
|
255
|
+
result = molssi_utils.resolve_molssi_descriptors(pd.DataFrame({"SMILES": ["CC(=O)O"]}))
|
|
256
|
+
|
|
257
|
+
assert result["available"] is False
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def test_kraken_dft_can_offer_verified_workbook(monkeypatch):
|
|
261
|
+
def fake_get(url, **_kwargs):
|
|
262
|
+
if "/api/kraken/" in url and "data_type=DFT" in url:
|
|
263
|
+
return ApiResponse(
|
|
264
|
+
[{"molecule_id": 17, "smiles": "c1ccc(P(c2ccccc2)c2ccccc2)cc1", "dipolemoment_max": 1.4}]
|
|
265
|
+
)
|
|
266
|
+
return ApiResponse([])
|
|
267
|
+
|
|
268
|
+
monkeypatch.setattr(molssi_utils.requests, "get", fake_get)
|
|
269
|
+
monkeypatch.setattr(molssi_utils, "_molssi_test_dataset_available", lambda _slug, _type: True)
|
|
270
|
+
|
|
271
|
+
result = molssi_utils.resolve_molssi_descriptors(
|
|
272
|
+
pd.DataFrame({"SMILES": ["P(c1ccccc1)(c1ccccc1)c1ccccc1"]})
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
assert result["available"] is True
|
|
276
|
+
assert result["data_type"] == "DFT"
|
|
277
|
+
assert result["export_available"] is True
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def test_conversion_accepts_kraken_dft_sheet_and_identifier(workspace_tmp_path):
|
|
281
|
+
workbook = workspace_tmp_path / "kraken_library.xlsx"
|
|
282
|
+
with pd.ExcelWriter(workbook) as writer:
|
|
283
|
+
pd.DataFrame(
|
|
284
|
+
{"Kraken_ID": [17], "SMILES": ["c1ccc(P(c2ccccc2)c2ccccc2)cc1"], "dipolemoment_max": [1.4]}
|
|
285
|
+
).to_excel(writer, sheet_name="Kraken_descriptors_2025_LATEST-", index=False)
|
|
286
|
+
completed = []
|
|
287
|
+
worker = molssi_utils.ExcelToCSVWorker(str(workbook))
|
|
288
|
+
worker.finished.connect(completed.append)
|
|
289
|
+
|
|
290
|
+
worker.run()
|
|
291
|
+
|
|
292
|
+
assert completed == [str(workbook.with_suffix(".csv"))]
|
|
293
|
+
exported = pd.read_csv(completed[0])
|
|
294
|
+
assert exported["code_name"].tolist() == [17]
|
|
295
|
+
assert exported["SMILES"].tolist() == ["c1ccc(P(c2ccccc2)c2ccccc2)cc1"]
|
|
296
|
+
assert exported["dipolemoment_max"].tolist() == [1.4]
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def test_conversion_maps_lowercase_id_to_code_name(workspace_tmp_path):
|
|
300
|
+
workbook = workspace_tmp_path / "aryl_bromide_library.xlsx"
|
|
301
|
+
with pd.ExcelWriter(workbook) as writer:
|
|
302
|
+
pd.DataFrame({"id": ["arbr6851"], "smiles": ["Brc1ccccc1"], "HOMO_Boltz": [-0.27]}).to_excel(
|
|
303
|
+
writer, sheet_name="Sheet1", index=False
|
|
304
|
+
)
|
|
305
|
+
completed = []
|
|
306
|
+
worker = molssi_utils.ExcelToCSVWorker(str(workbook))
|
|
307
|
+
worker.finished.connect(completed.append)
|
|
308
|
+
|
|
309
|
+
worker.run()
|
|
310
|
+
|
|
311
|
+
exported = pd.read_csv(completed[0])
|
|
312
|
+
assert exported["code_name"].tolist() == ["arbr6851"]
|
|
313
|
+
assert exported["SMILES"].tolist() == ["Brc1ccccc1"]
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
@pytest.mark.parametrize(
|
|
317
|
+
("library", "smiles"),
|
|
318
|
+
[
|
|
319
|
+
("acids", "CC(=O)O"),
|
|
320
|
+
("anilines", "Nc1ccccc1"),
|
|
321
|
+
("sulfides", "CCSC"),
|
|
322
|
+
("aryl_bromide", "Brc1ccccc1"),
|
|
323
|
+
("nn-ligands-hydride", "c1ccc(-c2ccccn2)nc1"),
|
|
324
|
+
("nn-ligands-fluoride", "c1ccc(-c2ccccn2)nc1"),
|
|
325
|
+
("nn-ligands-ligand-only", "c1ccc(-c2ccccn2)nc1"),
|
|
326
|
+
],
|
|
327
|
+
)
|
|
328
|
+
def test_descriptors_do_not_offer_incompatible_workbook(monkeypatch, library, smiles):
|
|
329
|
+
def fake_get(url, **_kwargs):
|
|
330
|
+
if f"/api/{library}/" in url:
|
|
331
|
+
return ApiResponse(
|
|
332
|
+
[{"molecule_id": "sample", "smiles": smiles, "HOMO": -0.2}]
|
|
333
|
+
)
|
|
334
|
+
return ApiResponse([])
|
|
335
|
+
|
|
336
|
+
monkeypatch.setattr(molssi_utils.requests, "get", fake_get)
|
|
337
|
+
monkeypatch.setattr(molssi_utils, "_molssi_test_dataset_available", lambda _slug, _type: True)
|
|
338
|
+
|
|
339
|
+
result = molssi_utils.resolve_molssi_descriptors(
|
|
340
|
+
pd.DataFrame({"SMILES": [smiles]})
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
assert result["available"] is True
|
|
344
|
+
assert result["export_available"] is False
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
def test_external_test_csv_requires_matching_descriptor_columns(tmp_path):
|
|
348
|
+
csv_path = tmp_path / "test.csv"
|
|
349
|
+
pd.DataFrame({"SMILES": ["CCO"], "code_name": ["sample"], "HOMO": [-0.2]}).to_csv(
|
|
350
|
+
csv_path, index=False
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
with pytest.raises(ValueError, match="LUMO"):
|
|
354
|
+
molssi_utils.validate_molssi_test_csv(csv_path, ["HOMO", "LUMO"])
|
|
355
|
+
|
|
356
|
+
molssi_utils.validate_molssi_test_csv(csv_path, ["HOMO"])
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
def test_shutdown_tracks_download_and_conversion_workers():
|
|
360
|
+
from gui_easyrob.main.window import EasyROB
|
|
361
|
+
|
|
362
|
+
class Worker:
|
|
363
|
+
def __init__(self, running):
|
|
364
|
+
self.running = running
|
|
365
|
+
|
|
366
|
+
def isRunning(self):
|
|
367
|
+
return self.running
|
|
368
|
+
|
|
369
|
+
resolver = Worker(True)
|
|
370
|
+
downloader = Worker(True)
|
|
371
|
+
converter = Worker(True)
|
|
372
|
+
inactive = Worker(False)
|
|
373
|
+
window = SimpleNamespace(
|
|
374
|
+
_molssi_workers={resolver, inactive},
|
|
375
|
+
_molssi_download_worker=downloader,
|
|
376
|
+
molssi_tab=SimpleNamespace(_excel_worker=converter),
|
|
377
|
+
)
|
|
378
|
+
|
|
379
|
+
assert set(EasyROB._running_molssi_workers(window)) == {resolver, downloader, converter}
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
def test_rejected_test_csv_does_not_claim_success_or_remove_workbook(tmp_path, monkeypatch):
|
|
383
|
+
from gui_easyrob.tabs import molssi as molssi_tab_module
|
|
384
|
+
|
|
385
|
+
workbook_path = tmp_path / "library.xlsx"
|
|
386
|
+
workbook_path.write_bytes(b"workbook")
|
|
387
|
+
csv_path = tmp_path / "library.csv"
|
|
388
|
+
csv_path.write_text("SMILES,code_name\nCCO,sample\n", encoding="utf-8")
|
|
389
|
+
shown_popups = []
|
|
390
|
+
main_window = SimpleNamespace(csv_test_path=None)
|
|
391
|
+
|
|
392
|
+
class FakeMessageBox:
|
|
393
|
+
Information = 1
|
|
394
|
+
Ok = 2
|
|
395
|
+
|
|
396
|
+
def __init__(self, _parent):
|
|
397
|
+
pass
|
|
398
|
+
|
|
399
|
+
def setIcon(self, _icon):
|
|
400
|
+
pass
|
|
401
|
+
|
|
402
|
+
def setWindowTitle(self, _title):
|
|
403
|
+
pass
|
|
404
|
+
|
|
405
|
+
def setText(self, _text):
|
|
406
|
+
pass
|
|
407
|
+
|
|
408
|
+
def setStandardButtons(self, _buttons):
|
|
409
|
+
pass
|
|
410
|
+
|
|
411
|
+
monkeypatch.setattr(molssi_tab_module, "QMessageBox", FakeMessageBox)
|
|
412
|
+
tab = SimpleNamespace(
|
|
413
|
+
load_test_requested=SimpleNamespace(emit=lambda _path: None),
|
|
414
|
+
window=lambda: main_window,
|
|
415
|
+
_exec_tracked_message_box=lambda *_args, **_kwargs: shown_popups.append("success"),
|
|
416
|
+
)
|
|
417
|
+
|
|
418
|
+
loaded = molssi_tab_module.MolSSIDatabasesTab.load_test_molssi(
|
|
419
|
+
tab, str(csv_path), source=str(workbook_path)
|
|
420
|
+
)
|
|
421
|
+
|
|
422
|
+
assert loaded is False
|
|
423
|
+
assert shown_popups == []
|
|
424
|
+
assert workbook_path.exists()
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
def test_library_hint_selects_overlapping_library_without_exporting_hint(monkeypatch):
|
|
428
|
+
calls = []
|
|
429
|
+
smiles = "C[C@H]1COC(C2=N[C@@H](C)CO2)=N1"
|
|
430
|
+
|
|
431
|
+
def fake_get(url, **_kwargs):
|
|
432
|
+
calls.append(url)
|
|
433
|
+
if "/api/nn-ligands-fluoride/" in url:
|
|
434
|
+
return ApiResponse([{"molecule_id": "Lig1", "smiles": smiles, "F_descriptor": 1.2}])
|
|
435
|
+
return ApiResponse([])
|
|
436
|
+
|
|
437
|
+
monkeypatch.setattr(molssi_utils.requests, "get", fake_get)
|
|
438
|
+
monkeypatch.setattr(molssi_utils, "_molssi_test_dataset_available", lambda *_args: False)
|
|
439
|
+
source = pd.DataFrame({"SMILES": [smiles], "molssi_library": ["nn-ligands-fluoride"]})
|
|
440
|
+
|
|
441
|
+
result = molssi_utils.resolve_molssi_descriptors(source)
|
|
442
|
+
|
|
443
|
+
assert result["library"] == "nn-ligands-fluoride"
|
|
444
|
+
assert result["export_df"]["code_name"].tolist() == ["Lig1"]
|
|
445
|
+
assert "molssi_library" not in result["export_df"].columns
|
|
446
|
+
assert len(calls) == 1
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
def test_unknown_library_hint_is_rejected_without_network_requests(monkeypatch):
|
|
450
|
+
def unexpected_get(*_args, **_kwargs):
|
|
451
|
+
raise AssertionError("The API must not be queried for an unknown library")
|
|
452
|
+
|
|
453
|
+
monkeypatch.setattr(molssi_utils.requests, "get", unexpected_get)
|
|
454
|
+
source = pd.DataFrame({"SMILES": ["CCO"], "molssi_library": ["unknown-library"]})
|
|
455
|
+
|
|
456
|
+
result = molssi_utils.resolve_molssi_descriptors(source)
|
|
457
|
+
|
|
458
|
+
assert result["available"] is False
|
|
459
|
+
assert "unknown-library" in result["reason"]
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
def test_quinone_id_lookup_exports_corresponding_descriptors_and_test_offer(monkeypatch):
|
|
463
|
+
smiles = "O=C1C(S(=O)(O)=O)=CC(C=C1)=O"
|
|
464
|
+
calls = []
|
|
465
|
+
|
|
466
|
+
def fake_get(url, **_kwargs):
|
|
467
|
+
calls.append(url)
|
|
468
|
+
if "/molecules/search/" in url:
|
|
469
|
+
return ApiResponse(
|
|
470
|
+
[
|
|
471
|
+
{"molecule_id": "other", "smiles": "O=C1C=CC(=O)C=C1"},
|
|
472
|
+
{"molecule_id": "q10000", "smiles": smiles},
|
|
473
|
+
]
|
|
474
|
+
)
|
|
475
|
+
if "molecule_ids=q10000" in url:
|
|
476
|
+
return ApiResponse([{"molecule_id": "q10000", "smiles": smiles, "HOMO_boltz": -0.3}])
|
|
477
|
+
return ApiResponse([])
|
|
478
|
+
|
|
479
|
+
monkeypatch.setattr(molssi_utils.requests, "get", fake_get)
|
|
480
|
+
monkeypatch.setattr(molssi_utils, "_molssi_test_dataset_available", lambda *_args: True)
|
|
481
|
+
source = pd.DataFrame({"SMILES": [smiles], "molssi_library": ["quinones"]})
|
|
482
|
+
|
|
483
|
+
result = molssi_utils.resolve_molssi_descriptors(source)
|
|
484
|
+
|
|
485
|
+
assert result["available"] is True
|
|
486
|
+
assert result["library"] == "quinones"
|
|
487
|
+
assert result["export_available"] is True
|
|
488
|
+
assert result["export_df"]["code_name"].tolist() == ["q10000"]
|
|
489
|
+
assert result["export_df"]["HOMO_boltz"].tolist() == [-0.3]
|
|
490
|
+
assert len(calls) == 2
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
def test_id_lookup_rejects_ambiguous_exact_smiles(monkeypatch):
|
|
494
|
+
smiles = "O=C1C(S(=O)(O)=O)=CC(C=C1)=O"
|
|
495
|
+
|
|
496
|
+
def fake_get(url, **_kwargs):
|
|
497
|
+
if "/molecules/search/" in url:
|
|
498
|
+
return ApiResponse([
|
|
499
|
+
{"molecule_id": "q1", "smiles": smiles},
|
|
500
|
+
{"molecule_id": "q2", "smiles": smiles},
|
|
501
|
+
])
|
|
502
|
+
raise AssertionError("Ambiguous IDs must not be exported")
|
|
503
|
+
|
|
504
|
+
monkeypatch.setattr(molssi_utils.requests, "get", fake_get)
|
|
505
|
+
source = pd.DataFrame({"SMILES": [smiles], "molssi_library": ["quinones"]})
|
|
506
|
+
|
|
507
|
+
result = molssi_utils.resolve_molssi_descriptors(source)
|
|
508
|
+
|
|
509
|
+
assert result["available"] is False
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
def test_excel_header_detection_reads_only_initial_rows(tmp_path, monkeypatch):
|
|
513
|
+
workbook = tmp_path / "library.xlsx"
|
|
514
|
+
with pd.ExcelWriter(workbook) as writer:
|
|
515
|
+
pd.DataFrame({"ID": ["sample"], "SMILES": ["CCO"]}).to_excel(
|
|
516
|
+
writer, sheet_name="DFT", index=False
|
|
517
|
+
)
|
|
518
|
+
original_read_excel = molssi_utils.pd.read_excel
|
|
519
|
+
reads = []
|
|
520
|
+
|
|
521
|
+
def tracked_read_excel(*args, **kwargs):
|
|
522
|
+
reads.append(kwargs.copy())
|
|
523
|
+
return original_read_excel(*args, **kwargs)
|
|
524
|
+
|
|
525
|
+
monkeypatch.setattr(molssi_utils.pd, "read_excel", tracked_read_excel)
|
|
526
|
+
worker = molssi_utils.ExcelToCSVWorker(str(workbook))
|
|
527
|
+
|
|
528
|
+
worker._read_descriptors("DFT")
|
|
529
|
+
|
|
530
|
+
assert reads[0]["header"] is None
|
|
531
|
+
assert reads[0]["nrows"] == 15
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
def test_failed_csv_conversion_preserves_existing_csv(tmp_path, monkeypatch):
|
|
535
|
+
workbook = tmp_path / "library.xlsx"
|
|
536
|
+
with pd.ExcelWriter(workbook) as writer:
|
|
537
|
+
pd.DataFrame({"ID": ["sample"], "SMILES": ["CCO"]}).to_excel(
|
|
538
|
+
writer, sheet_name="DFT", index=False
|
|
539
|
+
)
|
|
540
|
+
existing_csv = workbook.with_suffix(".csv")
|
|
541
|
+
existing_csv.write_text("previous export\n", encoding="utf-8")
|
|
542
|
+
|
|
543
|
+
def fail_after_partial_write(_self, handle, **_kwargs):
|
|
544
|
+
handle.write("partial export")
|
|
545
|
+
raise OSError("simulated disk failure")
|
|
546
|
+
|
|
547
|
+
monkeypatch.setattr(molssi_utils.pd.DataFrame, "to_csv", fail_after_partial_write)
|
|
548
|
+
worker = molssi_utils.ExcelToCSVWorker(str(workbook))
|
|
549
|
+
errors = []
|
|
550
|
+
worker.error.connect(errors.append)
|
|
551
|
+
|
|
552
|
+
worker.run()
|
|
553
|
+
|
|
554
|
+
assert errors and "disk failure" in errors[0]
|
|
555
|
+
assert existing_csv.read_text(encoding="utf-8") == "previous export\n"
|
|
556
|
+
assert not list(tmp_path.glob(".molssi-*.csv"))
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
def test_smoke_samples_cover_every_supported_connection():
|
|
560
|
+
assert {sample[0] for sample in SAMPLES} == set(molssi_utils.ALL_MOLSSI_LIBRARIES)
|
|
561
|
+
assert TEST_WORKBOOKS == molssi_utils.COMPATIBLE_TEST_WORKBOOK_LIBRARIES
|
|
562
|
+
for _library, first_id, first_smiles, second_id, second_smiles in SAMPLES:
|
|
563
|
+
assert first_id != second_id
|
|
564
|
+
assert molssi_utils._canonical_smiles(first_smiles)
|
|
565
|
+
assert molssi_utils._canonical_smiles(second_smiles)
|
|
566
|
+
assert molssi_utils._canonical_smiles(first_smiles) != molssi_utils._canonical_smiles(second_smiles)
|
|
567
|
+
assert KRAKEN_ML_SAMPLE[0] == "kraken"
|
|
568
|
+
assert molssi_utils._canonical_smiles(KRAKEN_ML_SAMPLE[2])
|
|
569
|
+
assert molssi_utils._canonical_smiles(KRAKEN_ML_SAMPLE[4])
|