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.
Files changed (219) hide show
  1. main.py +71 -0
  2. molforge/__init__.py +19 -0
  3. molforge/ai/__init__.py +15 -0
  4. molforge/ai/deepseek_harness.py +185 -0
  5. molforge/ai/mcp/desktop_client.py +38 -0
  6. molforge/ai/mcp/desktop_service.py +121 -0
  7. molforge/ai/mcp/mcp_server.py +780 -0
  8. molforge/ai/mcp_bridge.py +945 -0
  9. molforge/ai/observation.py +152 -0
  10. molforge/ai/tools.py +455 -0
  11. molforge/application/__init__.py +22 -0
  12. molforge/application/ai/__init__.py +1 -0
  13. molforge/application/ai/deepseek_client.py +293 -0
  14. molforge/application/ai/observation.py +161 -0
  15. molforge/application/ai/tools.py +200 -0
  16. molforge/application/ai_proposals.py +166 -0
  17. molforge/application/bio_selection.py +143 -0
  18. molforge/application/builtin_commands.py +1445 -0
  19. molforge/application/calculators/__init__.py +10 -0
  20. molforge/application/calculators/base.py +143 -0
  21. molforge/application/calculators/calchem_engine.py +67 -0
  22. molforge/application/calculators/calchem_subprocess_worker.py +109 -0
  23. molforge/application/calculators/gaussian_engine.py +59 -0
  24. molforge/application/calculators/gaussian_job_spec.py +240 -0
  25. molforge/application/calculators/orca_engine.py +92 -0
  26. molforge/application/calculators/qc_input_generator.py +300 -0
  27. molforge/application/calculators/registry.py +29 -0
  28. molforge/application/calculators/rest_engine.py +262 -0
  29. molforge/application/command_bus.py +139 -0
  30. molforge/application/commands.py +55 -0
  31. molforge/application/conformers.py +143 -0
  32. molforge/application/document_session.py +156 -0
  33. molforge/application/events.py +74 -0
  34. molforge/application/fragment_catalog.py +422 -0
  35. molforge/application/fragment_commands.py +268 -0
  36. molforge/application/geometry_commands.py +84 -0
  37. molforge/application/history.py +105 -0
  38. molforge/application/internal_coordinates.py +293 -0
  39. molforge/application/invalidation.py +1174 -0
  40. molforge/application/jobs.py +185 -0
  41. molforge/application/measurement.py +167 -0
  42. molforge/application/measurement_targets.py +264 -0
  43. molforge/application/modeling_commands.py +61 -0
  44. molforge/application/plugins.py +197 -0
  45. molforge/application/ports/editor2d.py +85 -0
  46. molforge/application/reaction.py +75 -0
  47. molforge/application/selection.py +164 -0
  48. molforge/application/selection_commands.py +31 -0
  49. molforge/application/trajectory.py +120 -0
  50. molforge/application/trajectory_analysis.py +231 -0
  51. molforge/application/workspace_registry.py +226 -0
  52. molforge/core/__init__.py +12 -0
  53. molforge/core/conformer.py +45 -0
  54. molforge/core/molecule.py +150 -0
  55. molforge/core/orbital.py +33 -0
  56. molforge/core/properties.py +43 -0
  57. molforge/domain/__init__.py +12 -0
  58. molforge/domain/biomolecule.py +99 -0
  59. molforge/domain/chemical_summary.py +129 -0
  60. molforge/domain/chemistry.py +13 -0
  61. molforge/domain/coordinate_store.py +164 -0
  62. molforge/domain/coordination.py +133 -0
  63. molforge/domain/custom_fragments.py +255 -0
  64. molforge/domain/document.py +469 -0
  65. molforge/domain/element_reference.json +598 -0
  66. molforge/domain/elements.py +188 -0
  67. molforge/domain/ids.py +58 -0
  68. molforge/domain/massive_system.py +246 -0
  69. molforge/domain/periodic.py +116 -0
  70. molforge/domain/provenance.py +115 -0
  71. molforge/domain/topology.py +364 -0
  72. molforge/infrastructure/__init__.py +23 -0
  73. molforge/infrastructure/hpc/cluster_config.py +122 -0
  74. molforge/infrastructure/hpc/remote_executor.py +212 -0
  75. molforge/infrastructure/hpc/slurm_generator.py +93 -0
  76. molforge/io/__init__.py +35 -0
  77. molforge/io/calchem_bridge.py +407 -0
  78. molforge/io/calculators.py +893 -0
  79. molforge/io/cclib_adapter.py +422 -0
  80. molforge/io/conformers.py +183 -0
  81. molforge/io/cube_reader.py +215 -0
  82. molforge/io/custom_fragments.py +79 -0
  83. molforge/io/format_matrix.py +157 -0
  84. molforge/io/gemmi_adapter.py +150 -0
  85. molforge/io/history_skill.py +46 -0
  86. molforge/io/mdanalysis_adapter.py +155 -0
  87. molforge/io/mforge_storage.py +261 -0
  88. molforge/io/multiwfn_driver.py +614 -0
  89. molforge/io/openbabel_adapter.py +265 -0
  90. molforge/io/openbabel_handler.py +33 -0
  91. molforge/io/rdkit_adapter.py +1865 -0
  92. molforge/io/readers/__init__.py +10 -0
  93. molforge/io/readers/cube_reader.py +71 -0
  94. molforge/io/readers/gjf_reader.py +110 -0
  95. molforge/io/readers/glog_reader.py +45 -0
  96. molforge/io/readers/mol2_reader.py +36 -0
  97. molforge/io/readers/mol_reader.py +56 -0
  98. molforge/io/readers/pdb_reader.py +39 -0
  99. molforge/io/readers/smi_reader.py +40 -0
  100. molforge/io/readers/xyz_reader.py +47 -0
  101. molforge/io/registry.py +128 -0
  102. molforge/io/writers/__init__.py +7 -0
  103. molforge/io/writers/gjf_writer.py +68 -0
  104. molforge/io/writers/pdb_writer.py +37 -0
  105. molforge/io/writers/png_writer.py +31 -0
  106. molforge/io/writers/svg_writer.py +111 -0
  107. molforge/io/writers/xyz_writer.py +39 -0
  108. molforge/rendering/__init__.py +21 -0
  109. molforge/rendering/benchmark.py +121 -0
  110. molforge/rendering/bridge.py +60 -0
  111. molforge/rendering/contracts.py +119 -0
  112. molforge/rendering/glyph_scene.py +279 -0
  113. molforge/rendering/ketcher_bridge.py +131 -0
  114. molforge/rendering/ketcher_id_mapping.py +110 -0
  115. molforge/rendering/materials.py +127 -0
  116. molforge/rendering/molstar_backend.py +245 -0
  117. molforge/rendering/native_labels.py +134 -0
  118. molforge/rendering/orbitals.py +139 -0
  119. molforge/rendering/vtk_backend.py +2294 -0
  120. molforge/runtime.py +29 -0
  121. molforge/server/__init__.py +1 -0
  122. molforge/server/api_bridge.py +947 -0
  123. molforge/ui/__init__.py +1 -0
  124. molforge/ui/assets/caffeine_2d.svg +150 -0
  125. molforge/ui/assets/caffeine_3d_preview.svg +209 -0
  126. molforge/ui/assets/caffeine_preview.json +302 -0
  127. molforge/ui/assets/icons/atom.svg +1 -0
  128. molforge/ui/assets/icons/bond.svg +1 -0
  129. molforge/ui/assets/icons/cleanup.svg +1 -0
  130. molforge/ui/assets/icons/export.svg +1 -0
  131. molforge/ui/assets/icons/fragments.svg +1 -0
  132. molforge/ui/assets/icons/history.svg +1 -0
  133. molforge/ui/assets/icons/jobs.svg +1 -0
  134. molforge/ui/assets/icons/measure.svg +1 -0
  135. molforge/ui/assets/icons/molecules.svg +1 -0
  136. molforge/ui/assets/icons/overview.svg +1 -0
  137. molforge/ui/assets/icons/ring.svg +1 -0
  138. molforge/ui/assets/icons/search.svg +1 -0
  139. molforge/ui/assets/icons/select.svg +1 -0
  140. molforge/ui/assets/icons/settings.svg +1 -0
  141. molforge/ui/assets/icons/templates.svg +1 -0
  142. molforge/ui/assets/molforge_logo.ico +0 -0
  143. molforge/ui/assets/molforge_logo.png +0 -0
  144. molforge/ui/atom_labels.py +92 -0
  145. molforge/ui/bio_structure_dialog.py +57 -0
  146. molforge/ui/conformer_dialog.py +151 -0
  147. molforge/ui/dialogs/__init__.py +2 -0
  148. molforge/ui/dialogs/aim_qtaim_dialog.py +533 -0
  149. molforge/ui/dialogs/calchem_orbitals_dialog.py +287 -0
  150. molforge/ui/dialogs/element_fragments.py +130 -0
  151. molforge/ui/dialogs/gaussian_calculation_setup.py +308 -0
  152. molforge/ui/dialogs/hpc_job_dialog.py +427 -0
  153. molforge/ui/dialogs/vibrational_spectrum_dialog.py +381 -0
  154. molforge/ui/editor2d_widget.py +1803 -0
  155. molforge/ui/element_picker.py +218 -0
  156. molforge/ui/gmv_window_manager.py +65 -0
  157. molforge/ui/gromacs_job_dialog.py +47 -0
  158. molforge/ui/hotkeys.py +107 -0
  159. molforge/ui/i18n.py +237 -0
  160. molforge/ui/live_llm_dialog.py +135 -0
  161. molforge/ui/llm_config_dialog.py +103 -0
  162. molforge/ui/modeling_actions.py +176 -0
  163. molforge/ui/molstar_widget.py +98 -0
  164. molforge/ui/molstar_window.py +85 -0
  165. molforge/ui/panels.py +2966 -0
  166. molforge/ui/qc_result_dialog.py +1924 -0
  167. molforge/ui/render3d_widget.py +1579 -0
  168. molforge/ui/scrolling.py +52 -0
  169. molforge/ui/settings_panel.py +330 -0
  170. molforge/ui/shells/__init__.py +4 -0
  171. molforge/ui/shells/base_shell.py +72 -0
  172. molforge/ui/shells/document_tabs.py +715 -0
  173. molforge/ui/shells/studio_2d.py +339 -0
  174. molforge/ui/shells/studio_3d.py +401 -0
  175. molforge/ui/shells/studio_split.py +370 -0
  176. molforge/ui/shells/workflow_inputs.py +698 -0
  177. molforge/ui/theme.py +719 -0
  178. molforge/ui/trajectory_window.py +333 -0
  179. molforge/ui/views.py +892 -0
  180. molforge/ui/vtk_multiview_widget.py +141 -0
  181. molforge/ui/welcome_window.py +223 -0
  182. molforge/ui/window.py +3320 -0
  183. molforge/workflows/__init__.py +25 -0
  184. molforge/workflows/assets/OSC_MD_workflows/templates/01-MD/delete_solvent.py +216 -0
  185. molforge/workflows/assets/OSC_MD_workflows/templates/02-RDF/extract_atoms.py +60 -0
  186. molforge/workflows/assets/OSC_MD_workflows/templates/02-RDF/extract_atoms_example.py +22 -0
  187. 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
  188. 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
  189. 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
  190. 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
  191. molforge/workflows/assets/esp-surface-analysis/scripts/compute_descriptors.py +134 -0
  192. molforge/workflows/assets/esp-surface-analysis/scripts/parse_surfanalysis.py +58 -0
  193. molforge/workflows/assets/esp-surface-analysis/scripts/plot_esp_hist.py +115 -0
  194. molforge/workflows/assets/homo-lumo-plot/extract_orb_energy.py +57 -0
  195. molforge/workflows/assets/homo-lumo-plot/make_level_plot.py +76 -0
  196. molforge/workflows/assets/homo-lumo-plot/run_pipeline.py +84 -0
  197. molforge/workflows/assets/osc-energy-level-diagram/scripts/extract_levels.py +60 -0
  198. molforge/workflows/assets/osc-energy-level-diagram/scripts/make_editable_pptx.py +122 -0
  199. molforge/workflows/assets/osc-energy-level-diagram/scripts/make_energy_table.py +66 -0
  200. molforge/workflows/assets/osc-energy-level-diagram/scripts/make_level_lines_diagram.py +148 -0
  201. molforge/workflows/assets/osc-energy-level-diagram/scripts/make_rectangle_diagram.py +148 -0
  202. molforge/workflows/assets/osc-energy-level-diagram/scripts/verify_from_log.py +45 -0
  203. molforge/workflows/dipole_analysis.py +32 -0
  204. molforge/workflows/esp_surface.py +36 -0
  205. molforge/workflows/gromacs_submit.py +167 -0
  206. molforge/workflows/homo_lumo_plot.py +59 -0
  207. molforge/workflows/igmh_interaction.py +111 -0
  208. molforge/workflows/md_rdf_analysis.py +134 -0
  209. molforge/workflows/md_studio.py +255 -0
  210. molforge/workflows/osc_energy_diagram.py +24 -0
  211. molforge/workflows/planarity_analysis.py +66 -0
  212. molforge/workflows/reorganization_energy.py +166 -0
  213. molforge/workflows/scientific_workflows.py +650 -0
  214. molforge_studio-7.4.3.dist-info/METADATA +215 -0
  215. molforge_studio-7.4.3.dist-info/RECORD +219 -0
  216. molforge_studio-7.4.3.dist-info/WHEEL +5 -0
  217. molforge_studio-7.4.3.dist-info/entry_points.txt +3 -0
  218. molforge_studio-7.4.3.dist-info/licenses/LICENSE +93 -0
  219. molforge_studio-7.4.3.dist-info/top_level.txt +2 -0
@@ -0,0 +1,218 @@
1
+ """
2
+ ui/element_picker.py - 元素周期表选择器
3
+ ==========================================
4
+ 完整 118 种元素,按真实周期表布局(含镧系/锕系),
5
+ 按钮三行信息(原子序数 / 符号 / 原子量),CPK 着色,
6
+ 顶部搜索框按符号/中文名过滤,深色仪器风格。
7
+ """
8
+ from PyQt6.QtCore import Qt, pyqtSignal, QSortFilterProxyModel, QAbstractListModel, QModelIndex
9
+ from PyQt6.QtWidgets import (
10
+ QDialog, QVBoxLayout, QHBoxLayout, QGridLayout, QPushButton, QLabel,
11
+ QWidget, QLineEdit, QScrollArea, QFrame, QLayout
12
+ )
13
+ from ..domain.elements import ELEMENTS, Element
14
+
15
+
16
+ def _cpk_qcolor(elem: Element) -> str:
17
+ """把元素的 CPK 颜色转成十六进制(适当提亮,深色背景下更清楚)。"""
18
+ r, g, b = elem.cpk_color
19
+ r = min(1.0, r * 1.15 + 0.08)
20
+ g = min(1.0, g * 1.15 + 0.08)
21
+ b = min(1.0, b * 1.15 + 0.08)
22
+ return f"#{int(r*255):02X}{int(g*255):02X}{int(b*255):02X}"
23
+
24
+
25
+ def _text_color(elem: Element) -> str:
26
+ """根据元素底色亮度决定文字用黑还是白。"""
27
+ r, g, b = elem.cpk_color
28
+ lum = 0.299 * r + 0.587 * g + 0.114 * b
29
+ return "#101820" if lum > 0.6 else "#FFFFFF"
30
+
31
+
32
+ class ElementPickerDialog(QDialog):
33
+ """完整元素周期表选择器。"""
34
+
35
+ element_selected = pyqtSignal(Element)
36
+
37
+ def __init__(self, parent=None, compact=False):
38
+ super().__init__(parent)
39
+ self.setWindowTitle("元素周期表")
40
+ self.compact = bool(compact)
41
+ self.selected_element: Element | None = None
42
+ self.setMinimumSize(600, 420)
43
+ self.resize(780, 560) if self.compact else self.resize(1100, 700)
44
+
45
+ self.setStyleSheet("""
46
+ QDialog { background: #0F1A29; }
47
+ QLabel { color: #EAF2F6; }
48
+ QLineEdit {
49
+ background: #172B3C; color: #EAF2F6;
50
+ border: 1px solid #365165; border-radius: 8px;
51
+ padding: 8px 12px; font-size: 14px;
52
+ }
53
+ QLineEdit:focus { border: 1px solid #66DEC9; }
54
+ """)
55
+
56
+ outer = QVBoxLayout(self)
57
+ outer.setContentsMargins(16, 16, 16, 16)
58
+ outer.setSpacing(10)
59
+
60
+ # 标题行
61
+ header = QHBoxLayout()
62
+ title = QLabel("元素周期表 · 选择当前元素")
63
+ title.setStyleSheet("font-size:18px; font-weight:bold;")
64
+ header.addWidget(title)
65
+ header.addStretch()
66
+ # 搜索框
67
+ self.search = QLineEdit()
68
+ self.search.setPlaceholderText("搜索符号或中文名(如 C / 碳 / carbon)")
69
+ self.search.setMaximumWidth(320)
70
+ self.search.textChanged.connect(self._filter_elements)
71
+ header.addWidget(self.search)
72
+ outer.addLayout(header)
73
+
74
+ # 周期表滚动区
75
+ scroll = QScrollArea()
76
+ scroll.setWidgetResizable(False)
77
+ self.table_scroll = scroll
78
+ scroll.setFrameShape(QFrame.Shape.NoFrame)
79
+ table_widget = QWidget()
80
+ self.grid = QGridLayout(table_widget)
81
+ self.grid.setSizeConstraint(QLayout.SizeConstraint.SetFixedSize)
82
+ self.grid.setSpacing(4)
83
+ self.grid.setContentsMargins(0, 0, 0, 0)
84
+ scroll.setWidget(table_widget)
85
+ outer.addWidget(scroll, 1)
86
+
87
+ # 信息栏
88
+ self.info_label = QLabel("请选择一个元素;横向/纵向滚动查看完整周期表。半径来自 RDKit 参考表,重元素可能含估计值。")
89
+ self.info_label.setWordWrap(True)
90
+ self.info_label.setStyleSheet(
91
+ "color:#EAF2F6; background:#152435; border:1px solid #2A3B4A;"
92
+ "border-radius:8px; padding:10px; font-size:13px;"
93
+ )
94
+ outer.addWidget(self.info_label)
95
+
96
+ # 存储所有按钮,便于过滤
97
+ self._buttons: list[tuple[QPushButton, Element]] = []
98
+ self._build_table()
99
+
100
+ def _make_button(self, elem: Element) -> QPushButton:
101
+ """生成三行信息的元素按钮。"""
102
+ bg = _cpk_qcolor(elem)
103
+ fg = _text_color(elem)
104
+ # 原子量简写
105
+ aw = f"{elem.atomic_weight:g}"
106
+ btn = QPushButton(f"{elem.symbol}\n{elem.atomic_number}" if self.compact else f"{elem.atomic_number}\n{elem.symbol}\n{aw}")
107
+ btn.setFixedSize(36, 36) if self.compact else btn.setFixedSize(66, 66)
108
+ btn.setStyleSheet(f"""
109
+ QPushButton {{
110
+ background: {bg};
111
+ color: {fg};
112
+ border: 1px solid rgba(255,255,255,0.14);
113
+ border-radius: 6px;
114
+ text-align: center;
115
+ font-weight: bold;
116
+ padding: 2px;
117
+ }}
118
+ QPushButton:hover {{
119
+ border: 2px solid #66DEC9;
120
+ }}
121
+ QPushButton:pressed {{
122
+ background: #2A4A5A;
123
+ }}
124
+ """)
125
+ btn.setToolTip(
126
+ f"{elem.name_cn} ({elem.name})\n"
127
+ f"原子序数: {elem.atomic_number}\n"
128
+ f"原子量: {elem.atomic_weight}\n"
129
+ f"电负性: {elem.electronegativity or 'N/A'}\n"
130
+ f"范德华半径: {elem.vdw_radius} Å\n"
131
+ f"共价半径: {elem.covalent_radius} Å(RDKit 参考值,非唯一实测半径)\n"
132
+ f"分类: {elem.category}\n"
133
+ f"电子构型: {elem.electron_config}"
134
+ )
135
+ btn.clicked.connect(lambda checked=False, e=elem: self._on_clicked(e))
136
+ btn.installEventFilter(self)
137
+ return btn
138
+
139
+ def _build_table(self):
140
+ """按真实周期表布局摆放按钮。"""
141
+ for z, elem in ELEMENTS.items():
142
+ if 57 <= z <= 71 or 89 <= z <= 103:
143
+ continue
144
+ row = elem.period - 1
145
+ col = elem.group - 1
146
+ btn = self._make_button(elem)
147
+ self.grid.addWidget(btn, row, col)
148
+ self._buttons.append((btn, elem))
149
+
150
+ for row, text in ((5, "57–71"), (6, "89–103")):
151
+ self.grid.addWidget(QLabel(text), row, 2)
152
+
153
+ # f 区标签
154
+ f_base_row = 8 # 主表 7 行 + 1 空行
155
+ lan_lbl = QLabel("镧系")
156
+ lan_lbl.setStyleSheet("color:#95A9B8; font-size:11px;")
157
+ self.grid.addWidget(lan_lbl, f_base_row, 0, 1, 2)
158
+ act_lbl = QLabel("锕系")
159
+ act_lbl.setStyleSheet("color:#95A9B8; font-size:11px;")
160
+ self.grid.addWidget(act_lbl, f_base_row + 1, 0, 1, 2)
161
+
162
+ for z in range(57, 72):
163
+ elem = ELEMENTS[z]
164
+ btn = self._make_button(elem)
165
+ self.grid.addWidget(btn, f_base_row, z - 57 + 2)
166
+ self._buttons.append((btn, elem))
167
+ for z in range(89, 104):
168
+ elem = ELEMENTS[z]
169
+ btn = self._make_button(elem)
170
+ self.grid.addWidget(btn, f_base_row + 1, z - 89 + 2)
171
+ self._buttons.append((btn, elem))
172
+
173
+ def _filter_elements(self, text: str):
174
+ """按搜索文本过滤按钮可见性。"""
175
+ text = text.strip().lower()
176
+ if not text:
177
+ for btn, _ in self._buttons:
178
+ btn.setVisible(True)
179
+ return
180
+ for btn, elem in self._buttons:
181
+ match = (text in elem.symbol.lower()
182
+ or text in elem.name_cn
183
+ or text in elem.name.lower()
184
+ or str(elem.atomic_number) == text)
185
+ btn.setVisible(match)
186
+
187
+ def eventFilter(self, obj, event):
188
+ """悬停时显示元素详情;右键点击元素按钮时弹出 ElementFragmentsDialog 基团面板。"""
189
+ if event.type() == event.Type.Enter and isinstance(obj, QPushButton):
190
+ for btn, elem in self._buttons:
191
+ if btn is obj:
192
+ self._show_info(elem)
193
+ break
194
+ elif event.type() == event.Type.MouseButtonPress and isinstance(obj, QPushButton):
195
+ if hasattr(event, "button") and event.button() == Qt.MouseButton.RightButton:
196
+ for btn, elem in self._buttons:
197
+ if btn is obj:
198
+ from .dialogs.element_fragments import ElementFragmentsDialog
199
+ dlg = ElementFragmentsDialog(self, initial_category=elem.symbol)
200
+ if dlg.exec() and dlg.selected_fragment is not None:
201
+ self.selected_fragment = dlg.selected_fragment
202
+ self.selected_element = elem
203
+ self.accept()
204
+ return True
205
+ return super().eventFilter(obj, event)
206
+
207
+ def _show_info(self, elem: Element):
208
+ self.info_label.setText(
209
+ f"{elem.name_cn} ({elem.symbol}) · 序数 {elem.atomic_number} · "
210
+ f"原子量 {elem.atomic_weight} · 电负性 {elem.electronegativity or 'N/A'} · "
211
+ f"vdW半径 {elem.vdw_radius} Å / 共价半径 {elem.covalent_radius} Å(RDKit参考,可能含估计值) · {elem.category} · {elem.electron_config}"
212
+ )
213
+
214
+ def _on_clicked(self, elem: Element):
215
+ self.selected_element = elem
216
+ self._show_info(elem)
217
+ self.element_selected.emit(elem)
218
+ self.accept()
@@ -0,0 +1,65 @@
1
+ """
2
+ ui/gmv_window_manager.py - GaussView 风格 G:M:V 多窗口与视图生命周期管理器
3
+ ===========================================================================
4
+ 统一协调 WorkspaceRegistry 与顶层窗口实例,确保:
5
+ - G1:M1:V1 与克隆视图 G1:M1:V2 共享同一个 DocumentSession (同一 CommandBus 与 UndoHistory)
6
+ - 窗口关闭时安全释放 VTK / Qt 监听器并更新 WorkspaceRegistry,避免悬空回调与 0xC0000409 崩溃
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from typing import Any
12
+
13
+ from ..application.document_session import DocumentSession
14
+ from ..application.workspace_registry import PaneCount, ViewSession, WorkspaceRegistry
15
+ from ..domain.document import MoleculeDocument
16
+
17
+
18
+ class GMVWindowManager:
19
+ """管理 G:M:V 窗口注册、克隆视图与生命周期回收。"""
20
+
21
+ def __init__(self, registry: WorkspaceRegistry | None = None) -> None:
22
+ self.registry: WorkspaceRegistry = registry or WorkspaceRegistry.instance()
23
+ self._window_by_tag: dict[str, Any] = {}
24
+
25
+ def register_new_group_window(
26
+ self,
27
+ document: MoleculeDocument,
28
+ window_obj: Any = None,
29
+ pane_count: PaneCount = 1,
30
+ ) -> tuple[DocumentSession, ViewSession]:
31
+ session, view = self.registry.create_new_group_view(document, pane_count=pane_count)
32
+ if window_obj is not None:
33
+ self._window_by_tag[view.gmv_tag] = window_obj
34
+ return session, view
35
+
36
+ def register_add_molecule_to_group(
37
+ self,
38
+ group_id: int,
39
+ document: MoleculeDocument,
40
+ window_obj: Any = None,
41
+ pane_count: PaneCount = 1,
42
+ ) -> tuple[DocumentSession, ViewSession]:
43
+ session, view = self.registry.add_molecule_to_group(group_id, document, pane_count=pane_count)
44
+ if window_obj is not None:
45
+ self._window_by_tag[view.gmv_tag] = window_obj
46
+ return session, view
47
+
48
+ def register_clone_view(
49
+ self,
50
+ source_gmv_tag: str,
51
+ window_obj: Any = None,
52
+ pane_count: PaneCount = 1,
53
+ ) -> tuple[DocumentSession, ViewSession]:
54
+ session, view = self.registry.clone_view(source_gmv_tag, pane_count=pane_count)
55
+ if window_obj is not None:
56
+ self._window_by_tag[view.gmv_tag] = window_obj
57
+ return session, view
58
+
59
+ def close_window(self, gmv_tag: str) -> None:
60
+ self._window_by_tag.pop(gmv_tag, None)
61
+ self.registry.close_view(gmv_tag)
62
+
63
+ @property
64
+ def open_tags(self) -> list[str]:
65
+ return list(self.registry.active_views.keys())
@@ -0,0 +1,47 @@
1
+ """Explicit job preparation; submission only after reviewing generated files."""
2
+ from pathlib import Path
3
+ from PyQt6.QtCore import QThread,pyqtSignal
4
+ from PyQt6.QtWidgets import QDialog,QVBoxLayout,QFormLayout,QLineEdit,QPushButton,QFileDialog,QTextEdit,QMessageBox,QHBoxLayout
5
+ from ..workflows.gromacs_submit import build_gromacs_job,enqueue_gromacs_job,DEFAULT_GMX
6
+ from ..runtime import data_dir
7
+ class _JobWorker(QThread):
8
+ done=pyqtSignal(object,str)
9
+ def __init__(self,fn,parent):super().__init__(parent);self.fn=fn
10
+ def run(self):
11
+ try:self.done.emit(self.fn(),"")
12
+ except Exception as exc:self.done.emit(None,str(exc))
13
+ class GromacsJobDialog(QDialog):
14
+ def __init__(self,parent=None):
15
+ super().__init__(parent);self.job=None;self.worker=None
16
+ self.setWindowTitle("GROMACS 任务准备与队列提交");self.resize(760,440)
17
+ lay=QVBoxLayout(self);form=QFormLayout();lay.addLayout(form)
18
+ self.fields={}
19
+ for key,label,default in [('structure','结构 GRO/PDB',''),('topology','完整拓扑 TOP',''),('gmx_path','GROMACS执行文件',DEFAULT_GMX),('work_dir','独立任务目录',str(data_dir()/'jobs'))]:
20
+ edit=QLineEdit(default);self.fields[key]=edit
21
+ row=QHBoxLayout();row.addWidget(edit);btn=QPushButton('浏览');row.addWidget(btn)
22
+ btn.clicked.connect(lambda _=False,k=key:self.browse(k));form.addRow(label,row)
23
+ self.log=QTextEdit();self.log.setReadOnly(True);lay.addWidget(self.log)
24
+ self.build=QPushButton('生成任务(不入队)');self.submit=QPushButton('确认后加入Pueue队列');self.submit.setEnabled(False)
25
+ lay.addWidget(self.build);lay.addWidget(self.submit);self.build.clicked.connect(self.prepare);self.submit.clicked.connect(self.enqueue)
26
+ def browse(self,key):
27
+ path=QFileDialog.getExistingDirectory(self,'选择目录') if key=='work_dir' else QFileDialog.getOpenFileName(self,'选择文件')[0]
28
+ if path:self.fields[key].setText(path)
29
+ def start(self,fn):
30
+ self.build.setEnabled(False);self.submit.setEnabled(False);self.worker=_JobWorker(fn,self)
31
+ self.worker.done.connect(self.done);self.worker.start()
32
+ def prepare(self):
33
+ args={k:w.text().strip() for k,w in self.fields.items()}
34
+ root=Path(args['work_dir'])
35
+ if root.exists() and any(root.iterdir()):
36
+ QMessageBox.warning(self,'目录非空','请选择新的空任务目录,避免覆盖已有计算。');return
37
+ self.start(lambda:build_gromacs_job(**args))
38
+ def enqueue(self):
39
+ if not self.job:return
40
+ if QMessageBox.question(self,'确认计算任务','将使用GPU资源运行已生成的minim/nvt/md任务。确认完整拓扑、盒子和参数已审核后入队?',QMessageBox.StandardButton.Yes|QMessageBox.StandardButton.No,QMessageBox.StandardButton.No)!=QMessageBox.StandardButton.Yes:return
41
+ self.start(lambda:enqueue_gromacs_job(self.job))
42
+ def done(self,value,error):
43
+ if isinstance(value,dict):self.job=value
44
+ self.log.append(error or str(value));self.build.setEnabled(True);self.submit.setEnabled(self.job is not None and not error)
45
+ def closeEvent(self,e):
46
+ if self.worker and self.worker.isRunning():e.ignore();return
47
+ super().closeEvent(e)
molforge/ui/hotkeys.py ADDED
@@ -0,0 +1,107 @@
1
+ """
2
+ ui/hotkeys.py - 2D 编辑器快捷键配置
3
+ ====================================
4
+ 专业化学软件的快捷键体系(参考 ChemDraw / MarvinSketch)。
5
+
6
+ 约定:
7
+ - 单字母无修饰 = 元素(C/N/O/S/P/F)或工具(V/B/R/E)
8
+ - 翻转/旋转/视图等用 Ctrl,避免与元素键冲突
9
+ detect_conflicts() 可在启动时检查同一 (key, 修饰键组合) 是否被绑定多次。
10
+ """
11
+ from __future__ import annotations
12
+
13
+ from dataclasses import dataclass, field
14
+
15
+
16
+ @dataclass
17
+ class Hotkey:
18
+ key: str
19
+ modifiers: list[str] = field(default_factory=list)
20
+ action: str = ""
21
+ description: str = ""
22
+
23
+ @property
24
+ def chord(self) -> tuple[str, tuple[str, ...]]:
25
+ return (self.key.lower(), tuple(sorted(self.modifiers)))
26
+
27
+
28
+ # 2D 编辑器快捷键(已消除冲突)
29
+ EDITOR_2D_HOTKEYS: list[Hotkey] = [
30
+ # 工具切换(无修饰,不与元素重叠)
31
+ Hotkey("V", [], "select", "选择工具"),
32
+ Hotkey("B", [], "bond", "键工具"),
33
+ Hotkey("R", [], "ring", "环工具"),
34
+ Hotkey("E", [], "erase", "擦除工具"),
35
+
36
+ # 元素(无修饰单字母)
37
+ Hotkey("C", [], "atom_C", "碳"),
38
+ Hotkey("N", [], "atom_N", "氮"),
39
+ Hotkey("O", [], "atom_O", "氧"),
40
+ Hotkey("S", [], "atom_S", "硫"),
41
+ Hotkey("P", [], "atom_P", "磷"),
42
+ Hotkey("F", [], "atom_F", "氟"),
43
+ Hotkey("I", [], "atom_I", "碘"),
44
+ Hotkey("H", [], "atom_H", "氢"),
45
+
46
+ # 环模板(数字)
47
+ Hotkey("1", [], "ring_benzene", "苯环"),
48
+ Hotkey("2", [], "ring_cyclohexane", "环己烷"),
49
+ Hotkey("3", [], "ring_cyclopentane", "环戊烷"),
50
+ Hotkey("4", [], "ring_thiophene", "噻吩"),
51
+ Hotkey("5", [], "ring_pyridine", "吡啶"),
52
+
53
+ # 编辑操作(Ctrl)
54
+ Hotkey("Z", ["Ctrl"], "undo", "撤销"),
55
+ Hotkey("Y", ["Ctrl"], "redo", "重做"),
56
+ Hotkey("C", ["Ctrl"], "copy", "复制"),
57
+ Hotkey("X", ["Ctrl"], "cut", "剪切"),
58
+ Hotkey("V", ["Ctrl"], "paste", "粘贴"),
59
+ Hotkey("D", ["Ctrl"], "duplicate", "快速复制"),
60
+ Hotkey("Delete", [], "delete", "删除选中"),
61
+
62
+ # 视图 / 翻转 / 旋转(Ctrl,避免与元素 F 冲突)
63
+ Hotkey("+", [], "zoom_in", "放大"),
64
+ Hotkey("-", [], "zoom_out", "缩小"),
65
+ Hotkey("0", [], "zoom_fit", "适应窗口"),
66
+ Hotkey("F", ["Ctrl"], "flip_h", "水平翻转"),
67
+ Hotkey("G", ["Ctrl"], "flip_v", "垂直翻转"),
68
+ Hotkey("R", ["Ctrl"], "rotate", "旋转"),
69
+
70
+ # 文件
71
+ Hotkey("O", ["Ctrl"], "open", "打开文件"),
72
+ Hotkey("S", ["Ctrl"], "save", "保存"),
73
+ Hotkey("E", ["Ctrl", "Shift"], "export", "导出"),
74
+
75
+ Hotkey("Space", [], "pan", "平移(按住)"),
76
+ Hotkey("?", ["Shift"], "help", "快捷键帮助"),
77
+ ]
78
+
79
+
80
+ GLOBAL_HOTKEYS: list[Hotkey] = [
81
+ Hotkey("K", ["Ctrl"], "command_palette", "命令面板"),
82
+ Hotkey("1", ["Ctrl"], "view_2d", "2D 视图"),
83
+ Hotkey("2", ["Ctrl"], "view_3d", "3D 视图"),
84
+ Hotkey("3", ["Ctrl"], "view_split", "分屏视图"),
85
+ Hotkey("Tab", [], "switch_panel", "切换右侧面板"),
86
+ ]
87
+
88
+
89
+ def detect_conflicts(hotkeys: list[Hotkey] | None = None) -> list[tuple]:
90
+ """返回冲突列表:同一 (key, 修饰键) 绑定多个动作。"""
91
+ if hotkeys is None:
92
+ hotkeys = EDITOR_2D_HOTKEYS + GLOBAL_HOTKEYS
93
+ seen: dict[tuple, list[str]] = {}
94
+ for h in hotkeys:
95
+ seen.setdefault(h.chord, []).append(h.action)
96
+ return [(chord, acts) for chord, acts in seen.items() if len(acts) > 1]
97
+
98
+
99
+ def get_hotkey_map() -> dict[str, list[Hotkey]]:
100
+ result: dict[str, list[Hotkey]] = {}
101
+ for h in EDITOR_2D_HOTKEYS + GLOBAL_HOTKEYS:
102
+ result.setdefault(h.action, []).append(h)
103
+ return result
104
+
105
+
106
+ def format_hotkey(h: Hotkey) -> str:
107
+ return "+".join(list(h.modifiers) + [h.key])
molforge/ui/i18n.py ADDED
@@ -0,0 +1,237 @@
1
+ """
2
+ ui/i18n.py - 国际化(中英文切换)
3
+ =====================================
4
+ 支持中英文界面切换。
5
+
6
+ 用法:
7
+ from .i18n import t, set_language
8
+ set_language("zh")
9
+ print(t("file.open")) # 打开文件
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ from typing import Callable
15
+
16
+
17
+ # 翻译字典
18
+ TRANSLATIONS: dict[str, dict[str, str]] = {
19
+ "zh": {
20
+ # 通用
21
+ "app.name": "MolForge",
22
+ "app.tagline": "AI-native 分子科学工作台",
23
+
24
+ # 顶部栏
25
+ "topbar.search": "搜索工具和命令...",
26
+ "topbar.project": "工作区",
27
+ "topbar.export": "导出",
28
+
29
+ # 左侧导航
30
+ "nav.workspace": "工作区",
31
+ "nav.molecules": "分子",
32
+ "nav.fragments": "片段",
33
+ "nav.templates": "模板",
34
+ "nav.jobs": "计算任务",
35
+ "nav.results": "结果",
36
+
37
+ # 分子列表
38
+ "molecules.title": "分子",
39
+ "molecules.quick_insert": "快速插入",
40
+
41
+ # 中央工作区
42
+ "workspace.breadcrumb": "分子工作区",
43
+ "workspace.structure_browser": "结构浏览器",
44
+ "workspace.view_2d": "二维",
45
+ "workspace.view_3d": "三维",
46
+ "workspace.view_split": "分屏",
47
+
48
+ # 工具栏
49
+ "toolbar.select": "选择",
50
+ "toolbar.atom": "原子",
51
+ "toolbar.bond": "键",
52
+ "toolbar.ring": "环",
53
+ "toolbar.measure": "测量",
54
+ "toolbar.cleanup": "清理",
55
+ "toolbar.ball_stick": "球棍",
56
+ "toolbar.cpk": "CPK",
57
+ "toolbar.surface": "表面",
58
+
59
+ # 右侧面板
60
+ "right.panel_title": "助手与属性检查器",
61
+ "right.tab_inspector": "属性检查",
62
+ "right.tab_ai": "AI 助手",
63
+ "right.tab_jobs": "任务",
64
+ "right.tab_history": "历史",
65
+ "right.tab_settings": "设置",
66
+
67
+ # AI 助手
68
+ "ai.current_context": "当前分子上下文",
69
+ "ai.assistant_title": "MolForge 助手",
70
+ "ai.explore_structure": "探索此结构",
71
+ "ai.explore_hint": "询问键合、几何、构象,或准备计算任务。",
72
+ "ai.suggested_actions": "建议操作",
73
+ "ai.check_functional_groups": "检查官能团",
74
+ "ai.generate_conformer": "生成构象",
75
+ "ai.prepare_dft": "准备 DFT 计算",
76
+ "ai.input_placeholder": "询问关于分子的问题...",
77
+
78
+ # 状态栏
79
+ "status.renderer": "渲染器",
80
+ "status.fps": "FPS",
81
+ "status.atoms": "原子",
82
+ "status.bonds": "键",
83
+
84
+ # 对话框
85
+ "dialog.open_file": "打开文件",
86
+ "dialog.save_file": "保存文件",
87
+ "dialog.confirm": "确认",
88
+ "dialog.cancel": "取消",
89
+ "dialog.yes": "是",
90
+ "dialog.no": "否",
91
+
92
+ # 警告/错误
93
+ "warning.stale": "数据已过期",
94
+ "warning.topology_changed": "拓扑已改变,所有构象和计算结果已过期",
95
+ "error.file_not_found": "文件不存在",
96
+ "error.invalid_format": "无效的文件格式",
97
+
98
+ # 设置
99
+ "settings.theme": "主题",
100
+ "settings.theme_dark": "深色",
101
+ "settings.theme_light": "浅色",
102
+ "settings.language": "语言",
103
+ "settings.font_size": "字体大小",
104
+ "settings.atom_scale": "原子大小",
105
+ "settings.bond_radius": "键粗细",
106
+ },
107
+
108
+ "en": {
109
+ # General
110
+ "app.name": "MolForge",
111
+ "app.tagline": "AI-native Molecular Workbench",
112
+
113
+ # Top bar
114
+ "topbar.search": "Search tools and commands...",
115
+ "topbar.project": "Workspace",
116
+ "topbar.export": "Export",
117
+
118
+ # Left nav
119
+ "nav.workspace": "Workspace",
120
+ "nav.molecules": "Molecules",
121
+ "nav.fragments": "Fragments",
122
+ "nav.templates": "Templates",
123
+ "nav.jobs": "Jobs",
124
+ "nav.results": "Results",
125
+
126
+ # Molecule list
127
+ "molecules.title": "Molecules",
128
+ "molecules.quick_insert": "Quick Insert",
129
+
130
+ # Center workspace
131
+ "workspace.breadcrumb": "Molecule Workspace",
132
+ "workspace.structure_browser": "Structure Browser",
133
+ "workspace.view_2d": "2D",
134
+ "workspace.view_3d": "3D",
135
+ "workspace.view_split": "Split",
136
+
137
+ # Toolbar
138
+ "toolbar.select": "Select",
139
+ "toolbar.atom": "Atom",
140
+ "toolbar.bond": "Bond",
141
+ "toolbar.ring": "Ring",
142
+ "toolbar.measure": "Measure",
143
+ "toolbar.cleanup": "Cleanup",
144
+ "toolbar.ball_stick": "Ball & Stick",
145
+ "toolbar.cpk": "CPK",
146
+ "toolbar.surface": "Surface",
147
+
148
+ # Right panel
149
+ "right.panel_title": "Assistant & Inspector",
150
+ "right.tab_inspector": "Inspector",
151
+ "right.tab_ai": "AI Assistant",
152
+ "right.tab_jobs": "Jobs",
153
+ "right.tab_history": "History",
154
+ "right.tab_settings": "Settings",
155
+
156
+ # AI Assistant
157
+ "ai.current_context": "Current Molecule Context",
158
+ "ai.assistant_title": "MolForge Assistant",
159
+ "ai.explore_structure": "Explore Structure",
160
+ "ai.explore_hint": "Ask about bonding, geometry, conformers, or prepare calculations.",
161
+ "ai.suggested_actions": "Suggested Actions",
162
+ "ai.check_functional_groups": "Check Functional Groups",
163
+ "ai.generate_conformer": "Generate Conformer",
164
+ "ai.prepare_dft": "Prepare DFT Calculation",
165
+ "ai.input_placeholder": "Ask a question about the molecule...",
166
+
167
+ # Status bar
168
+ "status.renderer": "Renderer",
169
+ "status.fps": "FPS",
170
+ "status.atoms": "Atoms",
171
+ "status.bonds": "Bonds",
172
+
173
+ # Dialogs
174
+ "dialog.open_file": "Open File",
175
+ "dialog.save_file": "Save File",
176
+ "dialog.confirm": "Confirm",
177
+ "dialog.cancel": "Cancel",
178
+ "dialog.yes": "Yes",
179
+ "dialog.no": "No",
180
+
181
+ # Warnings/Errors
182
+ "warning.stale": "Data is stale",
183
+ "warning.topology_changed": "Topology changed, all conformers and results are stale",
184
+ "error.file_not_found": "File not found",
185
+ "error.invalid_format": "Invalid file format",
186
+
187
+ # Settings
188
+ "settings.theme": "Theme",
189
+ "settings.theme_dark": "Dark",
190
+ "settings.theme_light": "Light",
191
+ "settings.language": "Language",
192
+ "settings.font_size": "Font Size",
193
+ "settings.atom_scale": "Atom Scale",
194
+ "settings.bond_radius": "Bond Radius",
195
+ },
196
+ }
197
+
198
+
199
+ _current_language: str = "zh"
200
+ _listeners: list[Callable[[str], None]] = []
201
+
202
+
203
+ def set_language(lang: str) -> None:
204
+ """设置当前语言。"""
205
+ global _current_language
206
+ if lang in TRANSLATIONS:
207
+ _current_language = lang
208
+ for listener in _listeners:
209
+ listener(lang)
210
+
211
+
212
+ def get_language() -> str:
213
+ """获取当前语言。"""
214
+ return _current_language
215
+
216
+
217
+ def t(key: str, default: str | None = None) -> str:
218
+ """翻译一个键。"""
219
+ lang_dict = TRANSLATIONS.get(_current_language, {})
220
+ if key in lang_dict:
221
+ return lang_dict[key]
222
+ # 回退到英文
223
+ en_dict = TRANSLATIONS.get("en", {})
224
+ if key in en_dict:
225
+ return en_dict[key]
226
+ # 回退到默认值或键本身
227
+ return default if default is not None else key
228
+
229
+
230
+ def add_language_listener(listener: Callable[[str], None]) -> None:
231
+ """添加语言切换监听器。"""
232
+ _listeners.append(listener)
233
+
234
+
235
+ def get_available_languages() -> list[str]:
236
+ """获取可用语言列表。"""
237
+ return list(TRANSLATIONS.keys())