molforge-studio 7.4.3__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.
- main.py +71 -0
- molforge/__init__.py +19 -0
- molforge/ai/__init__.py +15 -0
- molforge/ai/deepseek_harness.py +185 -0
- molforge/ai/mcp/desktop_client.py +38 -0
- molforge/ai/mcp/desktop_service.py +121 -0
- molforge/ai/mcp/mcp_server.py +780 -0
- molforge/ai/mcp_bridge.py +945 -0
- molforge/ai/observation.py +152 -0
- molforge/ai/tools.py +455 -0
- molforge/application/__init__.py +22 -0
- molforge/application/ai/__init__.py +1 -0
- molforge/application/ai/deepseek_client.py +293 -0
- molforge/application/ai/observation.py +161 -0
- molforge/application/ai/tools.py +200 -0
- molforge/application/ai_proposals.py +166 -0
- molforge/application/bio_selection.py +143 -0
- molforge/application/builtin_commands.py +1445 -0
- molforge/application/calculators/__init__.py +10 -0
- molforge/application/calculators/base.py +143 -0
- molforge/application/calculators/calchem_engine.py +67 -0
- molforge/application/calculators/calchem_subprocess_worker.py +109 -0
- molforge/application/calculators/gaussian_engine.py +59 -0
- molforge/application/calculators/gaussian_job_spec.py +240 -0
- molforge/application/calculators/orca_engine.py +92 -0
- molforge/application/calculators/qc_input_generator.py +300 -0
- molforge/application/calculators/registry.py +29 -0
- molforge/application/calculators/rest_engine.py +262 -0
- molforge/application/command_bus.py +139 -0
- molforge/application/commands.py +55 -0
- molforge/application/conformers.py +143 -0
- molforge/application/document_session.py +156 -0
- molforge/application/events.py +74 -0
- molforge/application/fragment_catalog.py +422 -0
- molforge/application/fragment_commands.py +268 -0
- molforge/application/geometry_commands.py +84 -0
- molforge/application/history.py +105 -0
- molforge/application/internal_coordinates.py +293 -0
- molforge/application/invalidation.py +1174 -0
- molforge/application/jobs.py +185 -0
- molforge/application/measurement.py +167 -0
- molforge/application/measurement_targets.py +264 -0
- molforge/application/modeling_commands.py +61 -0
- molforge/application/plugins.py +197 -0
- molforge/application/ports/editor2d.py +85 -0
- molforge/application/reaction.py +75 -0
- molforge/application/selection.py +164 -0
- molforge/application/selection_commands.py +31 -0
- molforge/application/trajectory.py +120 -0
- molforge/application/trajectory_analysis.py +231 -0
- molforge/application/workspace_registry.py +226 -0
- molforge/core/__init__.py +12 -0
- molforge/core/conformer.py +45 -0
- molforge/core/molecule.py +150 -0
- molforge/core/orbital.py +33 -0
- molforge/core/properties.py +43 -0
- molforge/domain/__init__.py +12 -0
- molforge/domain/biomolecule.py +99 -0
- molforge/domain/chemical_summary.py +129 -0
- molforge/domain/chemistry.py +13 -0
- molforge/domain/coordinate_store.py +164 -0
- molforge/domain/coordination.py +133 -0
- molforge/domain/custom_fragments.py +255 -0
- molforge/domain/document.py +469 -0
- molforge/domain/element_reference.json +598 -0
- molforge/domain/elements.py +188 -0
- molforge/domain/ids.py +58 -0
- molforge/domain/massive_system.py +246 -0
- molforge/domain/periodic.py +116 -0
- molforge/domain/provenance.py +115 -0
- molforge/domain/topology.py +364 -0
- molforge/infrastructure/__init__.py +23 -0
- molforge/infrastructure/hpc/cluster_config.py +122 -0
- molforge/infrastructure/hpc/remote_executor.py +212 -0
- molforge/infrastructure/hpc/slurm_generator.py +93 -0
- molforge/io/__init__.py +35 -0
- molforge/io/calchem_bridge.py +407 -0
- molforge/io/calculators.py +893 -0
- molforge/io/cclib_adapter.py +422 -0
- molforge/io/conformers.py +183 -0
- molforge/io/cube_reader.py +215 -0
- molforge/io/custom_fragments.py +79 -0
- molforge/io/format_matrix.py +157 -0
- molforge/io/gemmi_adapter.py +150 -0
- molforge/io/history_skill.py +46 -0
- molforge/io/mdanalysis_adapter.py +155 -0
- molforge/io/mforge_storage.py +261 -0
- molforge/io/multiwfn_driver.py +614 -0
- molforge/io/openbabel_adapter.py +265 -0
- molforge/io/openbabel_handler.py +33 -0
- molforge/io/rdkit_adapter.py +1865 -0
- molforge/io/readers/__init__.py +10 -0
- molforge/io/readers/cube_reader.py +71 -0
- molforge/io/readers/gjf_reader.py +110 -0
- molforge/io/readers/glog_reader.py +45 -0
- molforge/io/readers/mol2_reader.py +36 -0
- molforge/io/readers/mol_reader.py +56 -0
- molforge/io/readers/pdb_reader.py +39 -0
- molforge/io/readers/smi_reader.py +40 -0
- molforge/io/readers/xyz_reader.py +47 -0
- molforge/io/registry.py +128 -0
- molforge/io/writers/__init__.py +7 -0
- molforge/io/writers/gjf_writer.py +68 -0
- molforge/io/writers/pdb_writer.py +37 -0
- molforge/io/writers/png_writer.py +31 -0
- molforge/io/writers/svg_writer.py +111 -0
- molforge/io/writers/xyz_writer.py +39 -0
- molforge/rendering/__init__.py +21 -0
- molforge/rendering/benchmark.py +121 -0
- molforge/rendering/bridge.py +60 -0
- molforge/rendering/contracts.py +119 -0
- molforge/rendering/glyph_scene.py +279 -0
- molforge/rendering/ketcher_bridge.py +131 -0
- molforge/rendering/ketcher_id_mapping.py +110 -0
- molforge/rendering/materials.py +127 -0
- molforge/rendering/molstar_backend.py +245 -0
- molforge/rendering/native_labels.py +134 -0
- molforge/rendering/orbitals.py +139 -0
- molforge/rendering/vtk_backend.py +2294 -0
- molforge/runtime.py +29 -0
- molforge/server/__init__.py +1 -0
- molforge/server/api_bridge.py +947 -0
- molforge/ui/__init__.py +1 -0
- molforge/ui/assets/caffeine_2d.svg +150 -0
- molforge/ui/assets/caffeine_3d_preview.svg +209 -0
- molforge/ui/assets/caffeine_preview.json +302 -0
- molforge/ui/assets/icons/atom.svg +1 -0
- molforge/ui/assets/icons/bond.svg +1 -0
- molforge/ui/assets/icons/cleanup.svg +1 -0
- molforge/ui/assets/icons/export.svg +1 -0
- molforge/ui/assets/icons/fragments.svg +1 -0
- molforge/ui/assets/icons/history.svg +1 -0
- molforge/ui/assets/icons/jobs.svg +1 -0
- molforge/ui/assets/icons/measure.svg +1 -0
- molforge/ui/assets/icons/molecules.svg +1 -0
- molforge/ui/assets/icons/overview.svg +1 -0
- molforge/ui/assets/icons/ring.svg +1 -0
- molforge/ui/assets/icons/search.svg +1 -0
- molforge/ui/assets/icons/select.svg +1 -0
- molforge/ui/assets/icons/settings.svg +1 -0
- molforge/ui/assets/icons/templates.svg +1 -0
- molforge/ui/assets/molforge_logo.ico +0 -0
- molforge/ui/assets/molforge_logo.png +0 -0
- molforge/ui/atom_labels.py +92 -0
- molforge/ui/bio_structure_dialog.py +57 -0
- molforge/ui/conformer_dialog.py +151 -0
- molforge/ui/dialogs/__init__.py +2 -0
- molforge/ui/dialogs/aim_qtaim_dialog.py +533 -0
- molforge/ui/dialogs/calchem_orbitals_dialog.py +287 -0
- molforge/ui/dialogs/element_fragments.py +130 -0
- molforge/ui/dialogs/gaussian_calculation_setup.py +308 -0
- molforge/ui/dialogs/hpc_job_dialog.py +427 -0
- molforge/ui/dialogs/vibrational_spectrum_dialog.py +381 -0
- molforge/ui/editor2d_widget.py +1803 -0
- molforge/ui/element_picker.py +218 -0
- molforge/ui/gmv_window_manager.py +65 -0
- molforge/ui/gromacs_job_dialog.py +47 -0
- molforge/ui/hotkeys.py +107 -0
- molforge/ui/i18n.py +237 -0
- molforge/ui/live_llm_dialog.py +135 -0
- molforge/ui/llm_config_dialog.py +103 -0
- molforge/ui/modeling_actions.py +176 -0
- molforge/ui/molstar_widget.py +98 -0
- molforge/ui/molstar_window.py +85 -0
- molforge/ui/panels.py +2966 -0
- molforge/ui/qc_result_dialog.py +1924 -0
- molforge/ui/render3d_widget.py +1579 -0
- molforge/ui/scrolling.py +52 -0
- molforge/ui/settings_panel.py +330 -0
- molforge/ui/shells/__init__.py +4 -0
- molforge/ui/shells/base_shell.py +72 -0
- molforge/ui/shells/document_tabs.py +715 -0
- molforge/ui/shells/studio_2d.py +339 -0
- molforge/ui/shells/studio_3d.py +401 -0
- molforge/ui/shells/studio_split.py +370 -0
- molforge/ui/shells/workflow_inputs.py +698 -0
- molforge/ui/theme.py +719 -0
- molforge/ui/trajectory_window.py +333 -0
- molforge/ui/views.py +892 -0
- molforge/ui/vtk_multiview_widget.py +141 -0
- molforge/ui/welcome_window.py +223 -0
- molforge/ui/window.py +3320 -0
- molforge/workflows/__init__.py +25 -0
- molforge/workflows/assets/OSC_MD_workflows/templates/01-MD/delete_solvent.py +216 -0
- molforge/workflows/assets/OSC_MD_workflows/templates/02-RDF/extract_atoms.py +60 -0
- molforge/workflows/assets/OSC_MD_workflows/templates/02-RDF/extract_atoms_example.py +22 -0
- molforge/workflows/assets/OSC_MD_workflows/templates/03-/342/225/244/320/225/342/225/250/342/226/221/342/225/250/320/246/342/225/244/320/227/342/225/250/342/225/226/342/225/250/342/224/220/342/225/244/320/225/342/225/250/320/247/342/225/250/342/226/221/342/225/244/320/224/321/202/320/245/320/254/342/225/250/320/265/analysis_mol.py +244 -0
- molforge/workflows/assets/OSC_MD_workflows/templates/04-/342/225/244/320/224/321/202/320/245/320/241/342/225/250/320/254/342/225/244/320/227/321/202/320/245/320/247/321/202/320/244/320/264/342/225/244/320/225/342/225/250/342/224/220/342/225/250/320/246/342/225/244/320/225/321/202/320/245/320/241/342/225/250/342/225/242/rms_roughness.py +33 -0
- molforge/workflows/assets/OSC_MD_workflows/templates/04-/342/225/244/320/224/321/202/320/245/320/241/342/225/250/320/254/342/225/244/320/227/321/202/320/245/320/247/321/202/320/244/320/264/342/225/244/320/225/342/225/250/342/224/220/342/225/250/320/246/342/225/244/320/225/321/202/320/245/320/241/342/225/250/342/225/242/xpm_2.py +117 -0
- molforge/workflows/assets/OSC_MD_workflows/templates/09-/342/225/244/320/231/342/225/250/320/240/342/225/250/320/277/342/225/244/320/227/342/225/250/320/256/342/225/250/320/247/marcus_rate.py +60 -0
- molforge/workflows/assets/esp-surface-analysis/scripts/compute_descriptors.py +134 -0
- molforge/workflows/assets/esp-surface-analysis/scripts/parse_surfanalysis.py +58 -0
- molforge/workflows/assets/esp-surface-analysis/scripts/plot_esp_hist.py +115 -0
- molforge/workflows/assets/homo-lumo-plot/extract_orb_energy.py +57 -0
- molforge/workflows/assets/homo-lumo-plot/make_level_plot.py +76 -0
- molforge/workflows/assets/homo-lumo-plot/run_pipeline.py +84 -0
- molforge/workflows/assets/osc-energy-level-diagram/scripts/extract_levels.py +60 -0
- molforge/workflows/assets/osc-energy-level-diagram/scripts/make_editable_pptx.py +122 -0
- molforge/workflows/assets/osc-energy-level-diagram/scripts/make_energy_table.py +66 -0
- molforge/workflows/assets/osc-energy-level-diagram/scripts/make_level_lines_diagram.py +148 -0
- molforge/workflows/assets/osc-energy-level-diagram/scripts/make_rectangle_diagram.py +148 -0
- molforge/workflows/assets/osc-energy-level-diagram/scripts/verify_from_log.py +45 -0
- molforge/workflows/dipole_analysis.py +32 -0
- molforge/workflows/esp_surface.py +36 -0
- molforge/workflows/gromacs_submit.py +167 -0
- molforge/workflows/homo_lumo_plot.py +59 -0
- molforge/workflows/igmh_interaction.py +111 -0
- molforge/workflows/md_rdf_analysis.py +134 -0
- molforge/workflows/md_studio.py +255 -0
- molforge/workflows/osc_energy_diagram.py +24 -0
- molforge/workflows/planarity_analysis.py +66 -0
- molforge/workflows/reorganization_energy.py +166 -0
- molforge/workflows/scientific_workflows.py +650 -0
- molforge_studio-7.4.3.dist-info/METADATA +215 -0
- molforge_studio-7.4.3.dist-info/RECORD +219 -0
- molforge_studio-7.4.3.dist-info/WHEEL +5 -0
- molforge_studio-7.4.3.dist-info/entry_points.txt +3 -0
- molforge_studio-7.4.3.dist-info/licenses/LICENSE +93 -0
- molforge_studio-7.4.3.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"""Live document tools: network runs in a worker, document commands run on Qt thread."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
import html
|
|
4
|
+
import threading
|
|
5
|
+
from PyQt6.QtCore import QThread, pyqtSignal
|
|
6
|
+
from PyQt6.QtWidgets import QDialog, QVBoxLayout, QHBoxLayout, QTextEdit, QLineEdit, QPushButton, QMessageBox, QLabel
|
|
7
|
+
from ..ai.mcp_bridge import MolForgeMCPBridge, get_llm_config
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class _ChatWorker(QThread):
|
|
11
|
+
tool_requested = pyqtSignal(str, object, object)
|
|
12
|
+
reply = pyqtSignal(str)
|
|
13
|
+
|
|
14
|
+
def __init__(self, bridge, text, parent=None):
|
|
15
|
+
super().__init__(parent)
|
|
16
|
+
self.bridge = bridge
|
|
17
|
+
self.text = text
|
|
18
|
+
|
|
19
|
+
def execute_tool(self, name, args):
|
|
20
|
+
packet = {"event": threading.Event(), "result": None}
|
|
21
|
+
self.tool_requested.emit(name, args, packet)
|
|
22
|
+
if not packet["event"].wait(300):
|
|
23
|
+
return {"ok": False, "error": "等待界面处理工具调用超时"}
|
|
24
|
+
return packet["result"]
|
|
25
|
+
|
|
26
|
+
def run(self):
|
|
27
|
+
try:
|
|
28
|
+
self.reply.emit(self.bridge.chat(self.text, tool_executor=self.execute_tool))
|
|
29
|
+
except Exception as exc:
|
|
30
|
+
self.reply.emit(f"对话失败:{exc}")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class LiveLlmDialog(QDialog):
|
|
34
|
+
def __init__(self, parent, doc_provider):
|
|
35
|
+
super().__init__(parent)
|
|
36
|
+
self.provider = doc_provider
|
|
37
|
+
self.bridge = None
|
|
38
|
+
self.worker = None
|
|
39
|
+
self.setWindowTitle("LLM 当前分子工具对话 (独立窗口)")
|
|
40
|
+
self.resize(740, 560)
|
|
41
|
+
lay = QVBoxLayout(self)
|
|
42
|
+
|
|
43
|
+
cfg = get_llm_config()
|
|
44
|
+
self.info_lbl = QLabel(f"✓ 已自动同步主界面大模型配置 — 端点: {cfg['base_url']} | 模型: {cfg['model']}")
|
|
45
|
+
self.info_lbl.setStyleSheet("color: #66DEC9; font-size: 11px; font-weight: 600; padding: 2px 0;")
|
|
46
|
+
lay.addWidget(self.info_lbl)
|
|
47
|
+
|
|
48
|
+
lay.addWidget(QLabel("网络请求在后台运行;修改结构先显示确认,经命令总线执行,可撤销。"))
|
|
49
|
+
self.history = QTextEdit()
|
|
50
|
+
self.history.setReadOnly(True)
|
|
51
|
+
lay.addWidget(self.history)
|
|
52
|
+
|
|
53
|
+
row = QHBoxLayout()
|
|
54
|
+
self.input = QLineEdit()
|
|
55
|
+
self.input.setPlaceholderText("读取当前分子、列出原子、运行平面性或提出修改指令...")
|
|
56
|
+
self.send = QPushButton("发送")
|
|
57
|
+
self.config = QPushButton("调整独立端点...")
|
|
58
|
+
self.config.setToolTip("此窗口已自动继承右侧面板配置。如需临时为该对话更换其他大模型端点请点击此按钮。")
|
|
59
|
+
row.addWidget(self.input, 1)
|
|
60
|
+
row.addWidget(self.send)
|
|
61
|
+
row.addWidget(self.config)
|
|
62
|
+
lay.addLayout(row)
|
|
63
|
+
|
|
64
|
+
self.send.clicked.connect(self.ask)
|
|
65
|
+
self.input.returnPressed.connect(self.ask)
|
|
66
|
+
self.config.clicked.connect(self.settings)
|
|
67
|
+
|
|
68
|
+
def settings(self):
|
|
69
|
+
from .llm_config_dialog import LlmConfigDialog
|
|
70
|
+
dlg = LlmConfigDialog(self)
|
|
71
|
+
if dlg.exec():
|
|
72
|
+
cfg = get_llm_config()
|
|
73
|
+
self.info_lbl.setText(f"接入端点: {cfg['base_url']} | 模型: {cfg['model']}")
|
|
74
|
+
if self.bridge:
|
|
75
|
+
self.bridge.config = cfg
|
|
76
|
+
|
|
77
|
+
def ask(self):
|
|
78
|
+
text = self.input.text().strip()
|
|
79
|
+
if not text or (self.worker and self.worker.isRunning()):
|
|
80
|
+
return
|
|
81
|
+
doc = self.provider()
|
|
82
|
+
if doc is None:
|
|
83
|
+
QMessageBox.warning(self, "无分子", "当前没有打开的分子文档")
|
|
84
|
+
return
|
|
85
|
+
owner = self.parent()
|
|
86
|
+
bus = getattr(owner, 'command_bus', None)
|
|
87
|
+
if bus is None or bus.document is not doc:
|
|
88
|
+
QMessageBox.warning(self, "未连接", "当前窗口的命令总线与文档不一致")
|
|
89
|
+
return
|
|
90
|
+
if self.bridge is None or self.bridge.document is not doc:
|
|
91
|
+
self.bridge = MolForgeMCPBridge(doc, bus)
|
|
92
|
+
# 始终同步最新大模型配置
|
|
93
|
+
self.bridge.config = get_llm_config()
|
|
94
|
+
|
|
95
|
+
self.input.clear()
|
|
96
|
+
self.history.append("你:" + html.escape(text))
|
|
97
|
+
self.send.setEnabled(False)
|
|
98
|
+
self.config.setEnabled(False)
|
|
99
|
+
|
|
100
|
+
self.worker = _ChatWorker(self.bridge, text, self)
|
|
101
|
+
self.worker.tool_requested.connect(self.tool)
|
|
102
|
+
self.worker.reply.connect(self.answer)
|
|
103
|
+
self.worker.finished.connect(lambda: self.send.setEnabled(True))
|
|
104
|
+
self.worker.finished.connect(lambda: self.config.setEnabled(True))
|
|
105
|
+
self.worker.start()
|
|
106
|
+
|
|
107
|
+
def tool(self, name, args, packet):
|
|
108
|
+
try:
|
|
109
|
+
if name in {'add_atom', 'delete_atom', 'add_bond'}:
|
|
110
|
+
allowed = QMessageBox.question(
|
|
111
|
+
self,
|
|
112
|
+
"确认分子修改",
|
|
113
|
+
f"模型请求 {name}\n参数:{args}\n对当前分子执行?",
|
|
114
|
+
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
|
|
115
|
+
QMessageBox.StandardButton.No,
|
|
116
|
+
)
|
|
117
|
+
if allowed != QMessageBox.StandardButton.Yes:
|
|
118
|
+
packet['result'] = {'ok': False, 'error': '用户拒绝修改'}
|
|
119
|
+
return
|
|
120
|
+
packet['result'] = self.bridge.dispatch(name, args)
|
|
121
|
+
self.history.append("工具 " + html.escape(name) + ":" + html.escape(str(packet['result'])[:140]))
|
|
122
|
+
except Exception as exc:
|
|
123
|
+
packet['result'] = {'ok': False, 'error': str(exc)}
|
|
124
|
+
finally:
|
|
125
|
+
packet['event'].set()
|
|
126
|
+
|
|
127
|
+
def answer(self, text):
|
|
128
|
+
self.history.append("模型:" + html.escape(text))
|
|
129
|
+
|
|
130
|
+
def closeEvent(self, event):
|
|
131
|
+
if self.worker and self.worker.isRunning():
|
|
132
|
+
QMessageBox.information(self, "对话进行中", "请等待当前请求结束后关闭。")
|
|
133
|
+
event.ignore()
|
|
134
|
+
return
|
|
135
|
+
super().closeEvent(event)
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""
|
|
2
|
+
llm_config_dialog.py - LLM(OpenAI 兼容端点)配置对话框
|
|
3
|
+
=====================================================
|
|
4
|
+
让用户配置 base_url / api_key / model,持久化到 QSettings("MolForge","LLM")。
|
|
5
|
+
配置供 MolForgeMCPBridge 的 function-calling 对话循环使用。
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from PyQt6.QtWidgets import (
|
|
10
|
+
QDialog, QVBoxLayout, QHBoxLayout, QFormLayout, QLineEdit, QPushButton, QLabel,
|
|
11
|
+
QDialogButtonBox, QComboBox, QMessageBox
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
from ..ai.mcp_bridge import get_llm_config, set_llm_config, fetch_remote_models
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class LlmConfigDialog(QDialog):
|
|
18
|
+
"""配置任意 OpenAI 兼容端点(本地 vLLM/Ollama/DeepSeek/OpenAI 等)。"""
|
|
19
|
+
|
|
20
|
+
def __init__(self, parent=None):
|
|
21
|
+
super().__init__(parent)
|
|
22
|
+
self.setWindowTitle("LLM 接入设置(OpenAI 兼容端点)")
|
|
23
|
+
self.resize(560, 260)
|
|
24
|
+
cfg = get_llm_config()
|
|
25
|
+
|
|
26
|
+
lay = QVBoxLayout(self)
|
|
27
|
+
tip = QLabel(
|
|
28
|
+
"💡 说明:当前已自动加载主面板中的大模型端点与密钥。在此处调整并保存后将全局同步生效。"
|
|
29
|
+
)
|
|
30
|
+
tip.setStyleSheet("color: #66DEC9; font-weight: 600; padding: 4px 0;")
|
|
31
|
+
tip.setWordWrap(True)
|
|
32
|
+
lay.addWidget(tip)
|
|
33
|
+
|
|
34
|
+
form = QFormLayout()
|
|
35
|
+
self.ed_url = QLineEdit(cfg["base_url"])
|
|
36
|
+
self.ed_url.setPlaceholderText("如 http://127.0.0.1:8000/v1")
|
|
37
|
+
form.addRow("Base URL:", self.ed_url)
|
|
38
|
+
|
|
39
|
+
self.ed_key = QLineEdit(cfg["api_key"])
|
|
40
|
+
self.ed_key.setEchoMode(QLineEdit.EchoMode.Password)
|
|
41
|
+
self.ed_key.setPlaceholderText("本地服务可填 EMPTY")
|
|
42
|
+
form.addRow("API Key:", self.ed_key)
|
|
43
|
+
|
|
44
|
+
row_m = QHBoxLayout()
|
|
45
|
+
self.ed_model = QComboBox()
|
|
46
|
+
self.ed_model.setEditable(True)
|
|
47
|
+
self.ed_model.addItem(cfg["model"])
|
|
48
|
+
self.ed_model.setCurrentText(cfg["model"])
|
|
49
|
+
self.ed_model.lineEdit().setPlaceholderText("如 gemini-3.8-flash / deepseek-chat")
|
|
50
|
+
row_m.addWidget(self.ed_model, 1)
|
|
51
|
+
|
|
52
|
+
self.btn_fetch = QPushButton("🔄 获取模型")
|
|
53
|
+
self.btn_fetch.setToolTip("请求所填 Base URL 的 /v1/models 接口,拉取当前端点所有可用模型")
|
|
54
|
+
self.btn_fetch.clicked.connect(self._fetch_models)
|
|
55
|
+
row_m.addWidget(self.btn_fetch)
|
|
56
|
+
|
|
57
|
+
form.addRow("模型名:", row_m)
|
|
58
|
+
lay.addLayout(form)
|
|
59
|
+
|
|
60
|
+
btns = QDialogButtonBox(QDialogButtonBox.StandardButton.Save | QDialogButtonBox.StandardButton.Cancel)
|
|
61
|
+
btns.accepted.connect(self._save)
|
|
62
|
+
btns.rejected.connect(self.reject)
|
|
63
|
+
lay.addWidget(btns)
|
|
64
|
+
|
|
65
|
+
def _fetch_models(self):
|
|
66
|
+
url = self.ed_url.text().strip()
|
|
67
|
+
key = self.ed_key.text().strip()
|
|
68
|
+
if not url:
|
|
69
|
+
QMessageBox.warning(self, "提示", "请先填写 Base URL")
|
|
70
|
+
return
|
|
71
|
+
try:
|
|
72
|
+
models = fetch_remote_models(url, key)
|
|
73
|
+
if not models:
|
|
74
|
+
QMessageBox.information(self, "提示", f"已连接至端点,但未返回模型列表。")
|
|
75
|
+
return
|
|
76
|
+
self.ed_model.clear()
|
|
77
|
+
for m in models:
|
|
78
|
+
self.ed_model.addItem(m)
|
|
79
|
+
if "gemini-3.8-flash" in models:
|
|
80
|
+
self.ed_model.setCurrentText("gemini-3.8-flash")
|
|
81
|
+
elif "deepseek-chat" in models:
|
|
82
|
+
self.ed_model.setCurrentText("deepseek-chat")
|
|
83
|
+
QMessageBox.information(self, "获取模型成功", f"成功拉取到 {len(models)} 个可用模型!")
|
|
84
|
+
except Exception as e:
|
|
85
|
+
QMessageBox.warning(self, "获取失败", f"无法连接端点获取模型列表:\n{e}")
|
|
86
|
+
|
|
87
|
+
def _save(self):
|
|
88
|
+
url = self.ed_url.text().strip()
|
|
89
|
+
if not url:
|
|
90
|
+
url = "http://127.0.0.1:8045/v1"
|
|
91
|
+
m_txt = self.ed_model.currentText().strip()
|
|
92
|
+
if not m_txt or m_txt in ("default-model", "antigravity"):
|
|
93
|
+
m_txt = "gemini-3.8-flash"
|
|
94
|
+
cfg = get_llm_config()
|
|
95
|
+
set_llm_config(
|
|
96
|
+
url,
|
|
97
|
+
self.ed_key.text().strip() or "EMPTY",
|
|
98
|
+
m_txt,
|
|
99
|
+
temperature=float(cfg.get("temperature", 0.3)),
|
|
100
|
+
max_tokens=int(cfg.get("max_tokens", 4096)),
|
|
101
|
+
reasoning_effort=str(cfg.get("reasoning_effort", "none")),
|
|
102
|
+
)
|
|
103
|
+
self.accept()
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"""Shared 2D/3D selection, fragment and appearance actions."""
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from PyQt6.QtWidgets import QFileDialog, QInputDialog, QMessageBox, QColorDialog
|
|
4
|
+
from ..application.modeling_commands import SetAtomPropertiesCommand, connected_atoms
|
|
5
|
+
from ..application.fragment_commands import InsertFragmentCommand
|
|
6
|
+
from ..runtime import data_dir
|
|
7
|
+
from PyQt6.QtCore import QObject, pyqtSignal
|
|
8
|
+
from PyQt6 import sip
|
|
9
|
+
from threading import Thread
|
|
10
|
+
|
|
11
|
+
_pending_loaders = set()
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class _Loader(QObject):
|
|
15
|
+
succeeded = pyqtSignal(object)
|
|
16
|
+
failed = pyqtSignal(str)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _background(view, work, done):
|
|
20
|
+
loader = _Loader()
|
|
21
|
+
_pending_loaders.add(loader)
|
|
22
|
+
def finish(value, failed=False):
|
|
23
|
+
try:
|
|
24
|
+
if not sip.isdeleted(view):
|
|
25
|
+
if failed: QMessageBox.warning(view,'片段操作失败',str(value))
|
|
26
|
+
else: done(value)
|
|
27
|
+
finally:
|
|
28
|
+
_pending_loaders.discard(loader)
|
|
29
|
+
loader.deleteLater()
|
|
30
|
+
loader.succeeded.connect(finish)
|
|
31
|
+
loader.failed.connect(lambda message:finish(message,True))
|
|
32
|
+
def run():
|
|
33
|
+
try: loader.succeeded.emit(work())
|
|
34
|
+
except Exception as exc: loader.failed.emit(str(exc))
|
|
35
|
+
Thread(target=run,daemon=True).start()
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _targets(view, seed=None):
|
|
39
|
+
ids = set(view._selection.selected_atoms) if view._selection else set()
|
|
40
|
+
if seed is not None and seed not in ids:
|
|
41
|
+
ids = {seed}
|
|
42
|
+
return ids
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _run(view, command):
|
|
46
|
+
if view._command_bus is None:
|
|
47
|
+
return
|
|
48
|
+
result = view._command_bus.execute(command)
|
|
49
|
+
if not result.success:
|
|
50
|
+
QMessageBox.warning(view,'操作未完成',result.message)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _save(view, seed):
|
|
54
|
+
from ..io.custom_fragments import fragment_from_selection, save_fragment
|
|
55
|
+
name, ok = QInputDialog.getText(view,'保存选中片段','片段名称(右击原子作为连接入口):')
|
|
56
|
+
if not ok or not name.strip(): return
|
|
57
|
+
try:
|
|
58
|
+
spec = fragment_from_selection(view._document,_targets(view,seed),name,root=seed)
|
|
59
|
+
path = save_fragment(spec)
|
|
60
|
+
except Exception as exc:
|
|
61
|
+
QMessageBox.warning(view,'保存片段失败',str(exc));return
|
|
62
|
+
QMessageBox.information(view,'片段已保存',f'{spec.name_cn}\n{path}\n插入时检查入口价态;必要时先删除入口端的离去氢。')
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _insert(view, path, seed):
|
|
66
|
+
from ..io.custom_fragments import load_fragment
|
|
67
|
+
original_document=view._document
|
|
68
|
+
def insert(spec):
|
|
69
|
+
if view._document is not original_document:
|
|
70
|
+
QMessageBox.warning(view,'活动分子已改变','片段未插入;请在目标分子上重新操作。');return
|
|
71
|
+
_run(view,InsertFragmentCommand(spec,anchor_atom_id=seed,attach_to_existing=seed is not None))
|
|
72
|
+
_background(view,lambda:load_fragment(path),insert)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _browse(view, seed):
|
|
76
|
+
path,_ = QFileDialog.getOpenFileName(view,'导入自定义片段',str(data_dir()/'fragments'),'MolForge fragment (*.json)')
|
|
77
|
+
if path: _insert(view,path,seed)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _from_structure(view):
|
|
81
|
+
from ..io.rdkit_adapter import load_molecule_document
|
|
82
|
+
from ..io.custom_fragments import fragment_from_selection, save_fragment
|
|
83
|
+
path,_ = QFileDialog.getOpenFileName(view,'将分子文件保存为自定义片段','','Structure (*.xyz *.mol *.sdf *.pdb *.mol2 *.gro)')
|
|
84
|
+
if not path:return
|
|
85
|
+
name,ok=QInputDialog.getText(view,'片段名称','名称:',text=Path(path).stem)
|
|
86
|
+
if not ok:return
|
|
87
|
+
def work():
|
|
88
|
+
doc,_=load_molecule_document(path)
|
|
89
|
+
spec=fragment_from_selection(doc,list(doc.topology.atom_ids),name)
|
|
90
|
+
return save_fragment(spec)
|
|
91
|
+
_background(view,work,lambda result:QMessageBox.information(view,'已存入片段库',str(result)))
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _opacity(view, ids):
|
|
95
|
+
value,ok=QInputDialog.getDouble(view,'选中原子/内部键透明度','不透明度(0完全透明,1不透明):',1.,0.,1.,2)
|
|
96
|
+
if ok:_run(view,SetAtomPropertiesCommand(ids,opacity=value))
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _glow(view, ids):
|
|
100
|
+
color=QColorDialog.getColor(parent=view,title='选择柔光颜色(仅可视化效果)')
|
|
101
|
+
if not color.isValid():return
|
|
102
|
+
strength,ok=QInputDialog.getDouble(view,'柔光强度','强度0–1(不是物理发光模拟):',.45,0.,1.,2)
|
|
103
|
+
if ok:_run(view,SetAtomPropertiesCommand(ids,glow_color=(color.redF(),color.greenF(),color.blueF()),glow=strength))
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _export_scene(view):
|
|
107
|
+
try:view.export_scene_png()
|
|
108
|
+
except Exception as exc:QMessageBox.warning(view,'图像导出失败',str(exc))
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def add_modeling_actions(view, menu, seed=None, bond_id=None):
|
|
112
|
+
if view._document is None:return
|
|
113
|
+
ids=_targets(view,seed)
|
|
114
|
+
if seed is not None:
|
|
115
|
+
menu.addAction('成键 / 配位几何模板…',lambda:_arrange_geometry(view,seed))
|
|
116
|
+
if bond_id is not None:
|
|
117
|
+
torsion=menu.addMenu('绕单键旋转构象')
|
|
118
|
+
bond=view._document.topology.get_bond(bond_id)
|
|
119
|
+
torsion.setEnabled(bond.order==1 and not bond.aromatic)
|
|
120
|
+
for endpoint in (bond.begin,bond.end):
|
|
121
|
+
side=torsion.addMenu(f'旋转 {endpoint.value+1} 号原子一侧')
|
|
122
|
+
for degrees in (-60,60,180):
|
|
123
|
+
side.addAction(f'{degrees:+g}°',lambda checked=False,a=endpoint,d=degrees:_torsion(view,bond_id,a,d))
|
|
124
|
+
side.addAction('自定义角度…',lambda checked=False,a=endpoint:_torsion(view,bond_id,a))
|
|
125
|
+
selection=menu.addMenu('选择与冻结')
|
|
126
|
+
if bond_id is not None and view._selection:
|
|
127
|
+
bond=view._document.topology.get_bond(bond_id)
|
|
128
|
+
for endpoint in (bond.begin,bond.end):
|
|
129
|
+
selection.addAction(f'选中此键 {endpoint.value+1} 号原子一侧片段',
|
|
130
|
+
lambda _=False,a=endpoint:view._selection.select_atoms(connected_atoms(view._document,a,{bond_id}),origin='modeling'))
|
|
131
|
+
if seed is not None and view._selection:
|
|
132
|
+
selection.addAction('只选中此原子',lambda:view._selection.select_atoms([seed],origin='modeling'))
|
|
133
|
+
selection.addAction('选中连通片段',lambda:view._selection.select_atoms(connected_atoms(view._document,seed),origin='modeling'))
|
|
134
|
+
if view._selection:
|
|
135
|
+
selection.addAction('选中全部冻结原子',lambda:view._selection.select_atoms([a for a in view._document.topology.atom_ids if view._document.topology.get_atom(a).properties.get('frozen')],origin='modeling'))
|
|
136
|
+
freeze=selection.addAction(f'冻结选中原子的3D坐标({len(ids)})',lambda:_run(view,SetAtomPropertiesCommand(ids,frozen=True)))
|
|
137
|
+
thaw=selection.addAction('解冻选中原子',lambda:_run(view,SetAtomPropertiesCommand(ids,frozen=False)))
|
|
138
|
+
freeze.setEnabled(bool(ids));thaw.setEnabled(bool(ids))
|
|
139
|
+
fragments=menu.addMenu('自定义片段')
|
|
140
|
+
save=fragments.addAction('将选中原子保存为片段…',lambda:_save(view,seed));save.setEnabled(bool(ids))
|
|
141
|
+
fragments.addAction('从分子文件创建片段…',lambda:_from_structure(view))
|
|
142
|
+
fragments.addAction('导入片段JSON并插入…',lambda:_browse(view,seed))
|
|
143
|
+
folder=data_dir()/'fragments'
|
|
144
|
+
if folder.exists():
|
|
145
|
+
from ..io.custom_fragments import load_fragment
|
|
146
|
+
library=fragments.addMenu('插入已保存片段')
|
|
147
|
+
for path in sorted(folder.glob('*.json')):
|
|
148
|
+
try:spec=load_fragment(path)
|
|
149
|
+
except (ValueError,KeyError,TypeError,OSError):continue
|
|
150
|
+
library.addAction(spec.name_cn,lambda _=False,p=path:_insert(view,p,seed))
|
|
151
|
+
appearance=menu.addMenu('颜色、透明度与柔光')
|
|
152
|
+
appearance.setEnabled(bool(ids))
|
|
153
|
+
appearance.addAction('选中原子/内部键不透明度…',lambda:_opacity(view,ids))
|
|
154
|
+
appearance.addAction('选中原子柔光颜色与强度…',lambda:_glow(view,ids))
|
|
155
|
+
appearance.addAction('关闭柔光',lambda:_run(view,SetAtomPropertiesCommand(ids,glow=0.)))
|
|
156
|
+
appearance.addAction('恢复不透明',lambda:_run(view,SetAtomPropertiesCommand(ids,opacity=1.)))
|
|
157
|
+
if hasattr(view,'export_scene_png'):
|
|
158
|
+
menu.addAction('导出纯3D画面PNG(含编号/柔光)…',lambda:_export_scene(view))
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def _arrange_geometry(view,seed):
|
|
162
|
+
from .dialogs.element_fragments import ElementFragmentsDialog
|
|
163
|
+
from ..domain.elements import get_element
|
|
164
|
+
from ..application.geometry_commands import ArrangeGeometryCommand
|
|
165
|
+
symbol=get_element(view._document.topology.get_atom(seed).atomic_num).symbol
|
|
166
|
+
dialog=ElementFragmentsDialog(view,symbol,geometry_only=True)
|
|
167
|
+
if dialog.exec() and dialog.selected_geometry:
|
|
168
|
+
_run(view,ArrangeGeometryCommand(seed,dialog.selected_geometry))
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def _torsion(view,bond_id,endpoint,degrees=None):
|
|
172
|
+
from ..application.geometry_commands import RotateBondFragmentCommand
|
|
173
|
+
if degrees is None:
|
|
174
|
+
degrees,ok=QInputDialog.getDouble(view,'单键构象旋转','相对转角(度);冻结原子不移动:',60.,-360.,360.,2)
|
|
175
|
+
if not ok:return
|
|
176
|
+
_run(view,RotateBondFragmentCommand(bond_id,endpoint,degrees))
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""Mol* 大分子视图 widget:离线 molstar.js + loadStructureFromData 加载 PDB。"""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from PyQt6.QtCore import QObject, pyqtSlot, QUrl
|
|
7
|
+
from PyQt6.QtWidgets import QWidget, QVBoxLayout
|
|
8
|
+
from PyQt6.QtWebEngineWidgets import QWebEngineView
|
|
9
|
+
from PyQt6.QtWebEngineCore import QWebEngineProfile, QWebEnginePage
|
|
10
|
+
from PyQt6.QtWebChannel import QWebChannel
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class _Bridge(QObject):
|
|
14
|
+
def __init__(self, on_status, on_picked, on_ready):
|
|
15
|
+
super().__init__()
|
|
16
|
+
self._on_status = on_status
|
|
17
|
+
self._on_picked = on_picked
|
|
18
|
+
self._on_ready = on_ready
|
|
19
|
+
|
|
20
|
+
@pyqtSlot(str, bool)
|
|
21
|
+
def onStatus(self, msg, is_error):
|
|
22
|
+
self._on_status(msg, is_error)
|
|
23
|
+
|
|
24
|
+
@pyqtSlot(str)
|
|
25
|
+
def onPicked(self, loc):
|
|
26
|
+
self._on_picked(loc)
|
|
27
|
+
|
|
28
|
+
@pyqtSlot()
|
|
29
|
+
def jsReady(self):
|
|
30
|
+
self._on_ready()
|
|
31
|
+
|
|
32
|
+
@pyqtSlot(str)
|
|
33
|
+
def onLoaded(self, name):
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class MolStarWidget(QWidget):
|
|
38
|
+
def __init__(self, parent=None):
|
|
39
|
+
super().__init__(parent)
|
|
40
|
+
self._ready = False
|
|
41
|
+
self._pending = None
|
|
42
|
+
self.on_picked = None
|
|
43
|
+
|
|
44
|
+
self.view = QWebEngineView(self)
|
|
45
|
+
from ..runtime import data_dir
|
|
46
|
+
root = data_dir()/"webengine"
|
|
47
|
+
root.mkdir(exist_ok=True)
|
|
48
|
+
self._profile = QWebEngineProfile(self)
|
|
49
|
+
self._profile.setCachePath(str(root/"cache"))
|
|
50
|
+
self._profile.setPersistentStoragePath(str(root/"storage"))
|
|
51
|
+
self.view.setPage(QWebEnginePage(self._profile,self.view))
|
|
52
|
+
layout = QVBoxLayout(self)
|
|
53
|
+
layout.setContentsMargins(0, 0, 0, 0)
|
|
54
|
+
layout.addWidget(self.view)
|
|
55
|
+
|
|
56
|
+
self._channel = QWebChannel()
|
|
57
|
+
self._bridge = _Bridge(self._status, self._picked, self._ready_cb)
|
|
58
|
+
self._channel.registerObject("pybridge", self._bridge)
|
|
59
|
+
self.view.page().setWebChannel(self._channel)
|
|
60
|
+
|
|
61
|
+
html = Path(__file__).parent.parent / "rendering" / "molstar_viewer2.html"
|
|
62
|
+
self.view.setUrl(QUrl.fromLocalFile(str(html)))
|
|
63
|
+
|
|
64
|
+
def _status(self, msg, is_error):
|
|
65
|
+
print(f"[Mol*] {'ERR ' if is_error else ''}{msg}")
|
|
66
|
+
|
|
67
|
+
def _picked(self, loc):
|
|
68
|
+
if self.on_picked:
|
|
69
|
+
self.on_picked(loc)
|
|
70
|
+
|
|
71
|
+
def _ready_cb(self):
|
|
72
|
+
self._ready = True
|
|
73
|
+
if self._pending:
|
|
74
|
+
text, name, fmt = self._pending
|
|
75
|
+
self._pending = None
|
|
76
|
+
self.load_pdb(text, name, fmt)
|
|
77
|
+
|
|
78
|
+
def load_pdb(self, text: str, name: str = "structure", fmt: str = "pdb"):
|
|
79
|
+
"""加载 PDB/mmCIF 文本。未就绪时排队。fmt: 'pdb' 或 'mmcif'。"""
|
|
80
|
+
if not self._ready:
|
|
81
|
+
self._pending = (text, name, fmt)
|
|
82
|
+
return
|
|
83
|
+
js = f"loadStructure({_js_str(text)}, {_js_str(fmt)}, {_js_str(name)})"
|
|
84
|
+
self.view.page().runJavaScript(js)
|
|
85
|
+
|
|
86
|
+
def apply_preset(self, preset: str):
|
|
87
|
+
"""应用表示预设:cartoon / ball-and-stick / molecular-surface 等。"""
|
|
88
|
+
if self._ready:
|
|
89
|
+
self.view.page().runJavaScript(f"setPreset({_js_str(preset)})")
|
|
90
|
+
|
|
91
|
+
def reset_camera(self):
|
|
92
|
+
if self._ready:
|
|
93
|
+
self.view.page().runJavaScript("resetCamera()")
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _js_str(s: str) -> str:
|
|
97
|
+
import json
|
|
98
|
+
return json.dumps(s)
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""Mol* 大分子视图窗口:离线渲染蛋白质,链/残基选择,display presets。"""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from PyQt6.QtWidgets import (
|
|
5
|
+
QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QComboBox, QLabel, QPushButton)
|
|
6
|
+
from PyQt6.QtCore import Qt
|
|
7
|
+
|
|
8
|
+
from molforge.ui.molstar_widget import MolStarWidget
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
_PRESETS = [
|
|
12
|
+
("默认(卡通+配体)", "default"),
|
|
13
|
+
("卡通 Cartoon", "cartoon"),
|
|
14
|
+
("球棍 Ball-and-Stick", "ball-and-stick"),
|
|
15
|
+
("分子表面 Surface", "molecular-surface"),
|
|
16
|
+
("聚合物与配体", "polymer-and-ligand"),
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class MolStarWindow(QMainWindow):
|
|
21
|
+
def __init__(self, text: str, fmt: str = "pdb", name: str = "structure", parent=None):
|
|
22
|
+
super().__init__(parent)
|
|
23
|
+
self.setWindowTitle(f"大分子视图 - {name}")
|
|
24
|
+
self.resize(1200, 850)
|
|
25
|
+
|
|
26
|
+
central = QWidget()
|
|
27
|
+
self.setCentralWidget(central)
|
|
28
|
+
self.setStyleSheet("""
|
|
29
|
+
QWidget { background:#0F1A29; color:#EAF2F6; }
|
|
30
|
+
QComboBox { background:#152435; border:1px solid #2A3B4A;
|
|
31
|
+
border-radius:4px; padding:4px 8px; min-width:180px; }
|
|
32
|
+
QComboBox QAbstractItemView { background:#152435;
|
|
33
|
+
selection-background-color:#1A2C40; border:1px solid #2A3B4A; }
|
|
34
|
+
QPushButton { background:#152435; border:1px solid #2A3B4A;
|
|
35
|
+
border-radius:4px; padding:5px 12px; }
|
|
36
|
+
QPushButton:hover { background:#1A2C40; }
|
|
37
|
+
QLabel { background:transparent; }
|
|
38
|
+
""")
|
|
39
|
+
layout = QVBoxLayout(central)
|
|
40
|
+
layout.setContentsMargins(8, 8, 8, 8)
|
|
41
|
+
layout.setSpacing(8)
|
|
42
|
+
|
|
43
|
+
# 工具栏:表示预设 + 重置相机
|
|
44
|
+
bar = QHBoxLayout()
|
|
45
|
+
bar.addWidget(QLabel("表示:"))
|
|
46
|
+
self.preset_box = QComboBox()
|
|
47
|
+
for label, key in _PRESETS:
|
|
48
|
+
self.preset_box.addItem(label, key)
|
|
49
|
+
self.preset_box.currentIndexChanged.connect(self._apply_preset)
|
|
50
|
+
bar.addWidget(self.preset_box)
|
|
51
|
+
bar.addStretch()
|
|
52
|
+
reset_btn = QPushButton("重置相机")
|
|
53
|
+
reset_btn.clicked.connect(self._reset_camera)
|
|
54
|
+
bar.addWidget(reset_btn)
|
|
55
|
+
layout.addLayout(bar)
|
|
56
|
+
|
|
57
|
+
# Mol* 视图
|
|
58
|
+
self.viewer = MolStarWidget()
|
|
59
|
+
self.viewer.on_picked = self._on_picked
|
|
60
|
+
layout.addWidget(self.viewer, 1)
|
|
61
|
+
|
|
62
|
+
# 选中信息
|
|
63
|
+
self.pick_label = QLabel("点击分子可选中链 / 残基 / 原子")
|
|
64
|
+
self.pick_label.setStyleSheet(
|
|
65
|
+
"color:#95A9B8; padding:4px 6px; background:#152435; border-radius:4px;")
|
|
66
|
+
layout.addWidget(self.pick_label)
|
|
67
|
+
|
|
68
|
+
# 加载
|
|
69
|
+
self.viewer.load_pdb(text, name, fmt)
|
|
70
|
+
|
|
71
|
+
def _apply_preset(self):
|
|
72
|
+
key = self.preset_box.currentData()
|
|
73
|
+
self.viewer.apply_preset(key)
|
|
74
|
+
|
|
75
|
+
def _reset_camera(self):
|
|
76
|
+
self.viewer.reset_camera()
|
|
77
|
+
|
|
78
|
+
def _on_picked(self, loc: str):
|
|
79
|
+
parts = loc.split("|")
|
|
80
|
+
if len(parts) == 4:
|
|
81
|
+
chain, seq, res, atom = parts
|
|
82
|
+
text = f"链 {chain} · 残基 {res} {seq} · 原子 {atom}"
|
|
83
|
+
else:
|
|
84
|
+
text = loc
|
|
85
|
+
self.pick_label.setText(text)
|