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,715 @@
1
+ """Bottom document tabs, MDI manager, export suite, and 5-minute auto-save shared by the three independent Studio windows."""
2
+ from __future__ import annotations
3
+
4
+ import copy
5
+ import uuid
6
+ from pathlib import Path
7
+ from PyQt6.QtCore import Qt, QTimer
8
+ from PyQt6.QtGui import QAction, QActionGroup, QGuiApplication
9
+ from PyQt6.QtWidgets import (
10
+ QFileDialog, QInputDialog, QMenu, QMessageBox, QTabWidget, QToolBar, QMdiArea, QMdiSubWindow
11
+ )
12
+
13
+ from ...application.workspace_registry import WorkspaceRegistry
14
+ from ...domain.document import MoleculeDocument
15
+
16
+
17
+ class _DocumentSubWindow(QMdiSubWindow):
18
+ def __init__(self, owner):
19
+ super().__init__()
20
+ self.owner = owner
21
+
22
+ def closeEvent(self, event):
23
+ page = self.widget()
24
+ event.ignore()
25
+ QTimer.singleShot(0, lambda p=page: self.owner._close_mdi_page(p))
26
+
27
+
28
+ class StudioTabs:
29
+ """Shared document tabs, tool synchronization, export actions, and auto-save mixin for Studio windows."""
30
+
31
+ def init_tabs(self, initial_widget):
32
+ self.setAcceptDrops(True)
33
+ self._active_tool: str = "选择"
34
+ self._active_element: int = 6
35
+ self._tool_actions: dict[str, QAction] = {}
36
+ self._saved_revisions: dict[str, int] = {}
37
+
38
+ self.tabs = QTabWidget(self)
39
+ self.tabs.setTabPosition(QTabWidget.TabPosition.South)
40
+ self.tabs.setTabsClosable(True)
41
+ self.tabs.setMovable(True)
42
+ self.tabs.tabCloseRequested.connect(self.close_tab)
43
+ self.tabs.currentChanged.connect(self._activate_tab)
44
+ bar = self.tabs.tabBar()
45
+ bar.tabBarDoubleClicked.connect(self.rename_tab)
46
+ bar.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
47
+ bar.customContextMenuRequested.connect(self._tab_menu)
48
+ self._pages = {}
49
+ self._mdi_area = None
50
+ self._active_mdi_page = None
51
+
52
+ c2_init = getattr(self, "canvas2d", None)
53
+ c3_init = getattr(self, "canvas3d", None)
54
+ self._wire_canvas_signals(c2_init, c3_init)
55
+
56
+ self.tabs.blockSignals(True)
57
+ self._register_page(initial_widget, self.shell, c2_init, c3_init)
58
+ self.tabs.blockSignals(False)
59
+ self._saved_revisions[self.shell.document.document_id] = self.shell.document.revision
60
+ self.setCentralWidget(self.tabs)
61
+
62
+ # 启动每 5 分钟 (300,000 ms) 定时自动保存 (P1 Bug 6)
63
+ self._autosave_timer = QTimer(self)
64
+ self._autosave_timer.setInterval(300_000)
65
+ self._autosave_timer.timeout.connect(self._run_autosave)
66
+ self._autosave_timer.start()
67
+
68
+ def _wire_canvas_signals(self, c2, c3):
69
+ if c2 is not None:
70
+ try:
71
+ c2.tool_changed_signal.connect(self._on_canvas_tool_changed)
72
+ c2.element_changed_signal.connect(self._on_canvas_element_changed)
73
+ except Exception:
74
+ pass
75
+
76
+ def _on_canvas_tool_changed(self, tool_name: str):
77
+ self._active_tool = tool_name
78
+ act = self._tool_actions.get(tool_name)
79
+ if act is not None and not act.isChecked():
80
+ act.setChecked(True)
81
+ c3 = getattr(self, "canvas3d", None)
82
+ if c3 is not None:
83
+ c3.set_current_tool(tool_name)
84
+
85
+ def _on_canvas_element_changed(self, atomic_num: int):
86
+ self._active_element = int(atomic_num)
87
+ c3 = getattr(self, "canvas3d", None)
88
+ if c3 is not None:
89
+ c3.set_current_element(int(atomic_num))
90
+
91
+ def _register_page(self, widget, shell, canvas2d=None, canvas3d=None):
92
+ self._pages[widget] = (shell, canvas2d, canvas3d)
93
+ index = self.tabs.addTab(widget, shell.document.name)
94
+ shell.session.command_bus.add_listener(
95
+ lambda *_args, w=widget: self._refresh_page(w)
96
+ )
97
+ shell.session.selection.add_listener(
98
+ lambda _origin, c=canvas2d: c.update() if c is not None else None
99
+ )
100
+ self.tabs.setCurrentIndex(index)
101
+ # 关键修复 (P0 Bug 1):即使 index 等于原先的 currentIndex,也强制执行 _activate_page,
102
+ # 确保 self.shell / self.document / self.command_bus / self.canvas2d / self.canvas3d 100% 指向新标签页!
103
+ self._activate_page(widget)
104
+ return index
105
+
106
+ def _refresh_page(self, widget):
107
+ if widget not in self._pages:
108
+ return
109
+ shell, c2, c3 = self._pages[widget]
110
+ idx = self.tabs.indexOf(widget)
111
+ if idx >= 0:
112
+ dirty = "*" if self._is_doc_modified(shell.document) else ""
113
+ self.tabs.setTabText(idx, f"{shell.document.name}{dirty}")
114
+ if c2 is not None:
115
+ c2.update()
116
+ active = widget is self.tabs.currentWidget() or (
117
+ self._mdi_area is not None and widget is getattr(self, "_active_mdi_page", None)
118
+ )
119
+ if active:
120
+ self.refresh_views()
121
+
122
+ def _activate_tab(self, index):
123
+ widget = self.tabs.widget(index)
124
+ if widget not in self._pages:
125
+ return
126
+ self._activate_page(widget)
127
+
128
+ def add_document_tab(self, document=None, session=None):
129
+ from .studio_2d import Studio2DShell
130
+ from .studio_3d import Studio3DShell
131
+ from .studio_split import StudioSplitShell
132
+ from ..editor2d_widget import Editor2DWidget
133
+ from ..render3d_widget import Render3DWidget
134
+ from PyQt6.QtWidgets import QSplitter
135
+
136
+ is_blank_new = (document is None)
137
+ doc = document if document is not None else MoleculeDocument(name=f"未命名-{self.tabs.count() + 1}")
138
+ kind = self.shell.shell_kind
139
+ cls = {
140
+ "studio_2d": Studio2DShell,
141
+ "studio_3d": Studio3DShell,
142
+ "studio_split": StudioSplitShell,
143
+ }[kind]
144
+ shell = cls(document=doc, session=session)
145
+ c2 = c3 = None
146
+ if kind == "studio_split":
147
+ widget = QSplitter(Qt.Orientation.Horizontal, self.tabs)
148
+ c2 = Editor2DWidget(widget)
149
+ c3 = Render3DWidget(widget)
150
+ widget.addWidget(c2)
151
+ widget.addWidget(c3)
152
+ widget.setSizes([600, 640])
153
+ elif kind == "studio_2d":
154
+ widget = c2 = Editor2DWidget(self.tabs)
155
+ else:
156
+ widget = c3 = Render3DWidget(self.tabs)
157
+
158
+ # 若是新建空白画布,自动切换到「原子」绘制模式,让用户点击画布即可立即放置原子 (P0 Bug 1)
159
+ if is_blank_new:
160
+ self._active_tool = "原子"
161
+ act = self._tool_actions.get("原子")
162
+ if act is not None:
163
+ act.setChecked(True)
164
+
165
+ for canvas in (c2, c3):
166
+ if canvas is not None:
167
+ canvas.set_selection_service(shell.session.selection)
168
+ canvas.set_command_bus(shell.session.command_bus)
169
+ canvas.set_current_element(self._active_element)
170
+ canvas.set_current_tool(self._active_tool)
171
+ if canvas is c2:
172
+ canvas.set_document(shell.document)
173
+
174
+ self._wire_canvas_signals(c2, c3)
175
+ self._saved_revisions[doc.document_id] = doc.revision
176
+ self._register_page(widget, shell, c2, c3)
177
+
178
+ if c3 is not None:
179
+ QTimer.singleShot(
180
+ 15,
181
+ lambda c=c3, s=shell: c.set_document(s.document) if c.parent() is not None else None,
182
+ )
183
+ if self._mdi_area is not None:
184
+ self.tabs.removeTab(self.tabs.indexOf(widget))
185
+ sub = _DocumentSubWindow(self)
186
+ sub.setWidget(widget)
187
+ self._mdi_area.addSubWindow(sub)
188
+ sub.setWindowTitle(shell.document.name)
189
+ sub.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose, False)
190
+ sub.show()
191
+ self._arrange_mdi("tile")
192
+ self._activate_mdi_window(sub)
193
+ return widget
194
+
195
+ def open_document_tab(self, path):
196
+ from ...io.rdkit_adapter import load_molecule_document
197
+ try:
198
+ loaded = load_molecule_document(path)
199
+ doc = loaded[0] if isinstance(loaded, tuple) else loaded
200
+ self.add_document_tab(doc)
201
+ except Exception as exc:
202
+ QMessageBox.critical(self, "打开失败", f"无法打开文件:\n{exc}")
203
+
204
+ def close_tab(self, index):
205
+ if self._mdi_area is not None:
206
+ self._close_mdi_page(getattr(self, "_active_mdi_page", None))
207
+ return
208
+ if index < 0 or index >= self.tabs.count():
209
+ return
210
+ widget = self.tabs.widget(index)
211
+ if widget in self._pages:
212
+ doc = self._pages[widget][0].document
213
+ if not self._confirm_save_if_modified(doc):
214
+ return
215
+ if self.tabs.count() == 1:
216
+ choice = QMessageBox.question(
217
+ self,
218
+ "关闭最后一个画布",
219
+ "新建空白分子?选择“否”将返回欢迎界面。",
220
+ QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No | QMessageBox.StandardButton.Cancel,
221
+ )
222
+ if choice == QMessageBox.StandardButton.Cancel:
223
+ return
224
+ if choice == QMessageBox.StandardButton.Yes:
225
+ self.add_document_tab()
226
+ else:
227
+ self._open_welcome()
228
+ self.close()
229
+ return
230
+ shell = self._pages.pop(widget)[0]
231
+ self.tabs.removeTab(index)
232
+ shell.close_shell()
233
+ widget.deleteLater()
234
+ if self.tabs.count() > 0:
235
+ cur_w = self.tabs.currentWidget()
236
+ if cur_w in self._pages:
237
+ self._activate_page(cur_w)
238
+
239
+ def rename_tab(self, index):
240
+ if index < 0:
241
+ return
242
+ widget = self.tabs.widget(index)
243
+ name, ok = QInputDialog.getText(self, "重命名分子", "分子名称:", text=self.tabs.tabText(index).rstrip("*"))
244
+ if ok and name.strip():
245
+ self._pages[widget][0].document.name = name.strip()
246
+ self._pages[widget][0].document.bump_revision()
247
+ self._refresh_page(widget)
248
+
249
+ def duplicate_tab(self, index):
250
+ if index >= 0:
251
+ doc = copy.deepcopy(self._pages[self.tabs.widget(index)][0].document)
252
+ doc.document_id = uuid.uuid4().hex
253
+ doc.name += " 副本"
254
+ self.add_document_tab(doc)
255
+
256
+ def _tab_menu(self, pos):
257
+ index = self.tabs.tabBar().tabAt(pos)
258
+ if index < 0:
259
+ return
260
+ menu = QMenu(self)
261
+ menu.addAction("新建画布", lambda: self.add_document_tab())
262
+ menu.addAction("复制画布", lambda: self.duplicate_tab(index))
263
+ menu.addAction("重命名", lambda: self.rename_tab(index))
264
+ menu.addAction("关闭画布", lambda: self.close_tab(index))
265
+ menu.exec(self.tabs.tabBar().mapToGlobal(pos))
266
+
267
+ def install_studio_toolbar(self):
268
+ toolbar = QToolBar("绘图工具", self)
269
+ toolbar.setMovable(True)
270
+ toolbar.setFloatable(True)
271
+ self.addToolBar(toolbar)
272
+ group = QActionGroup(self)
273
+ self._tool_actions = {}
274
+ for label, tool, key in [
275
+ ("选择 V", "选择", "V"),
276
+ ("原子 A", "原子", "A"),
277
+ ("键 B", "键", "B"),
278
+ ("擦除 E", "擦除", "E"),
279
+ ]:
280
+ action = QAction(label, self)
281
+ action.setCheckable(True)
282
+ group.addAction(action)
283
+ toolbar.addAction(action)
284
+ action.triggered.connect(lambda _=False, t=tool: self._set_active_tool(t))
285
+ self._tool_actions[tool] = action
286
+ if tool == self._active_tool:
287
+ action.setChecked(True)
288
+ toolbar.addSeparator()
289
+ toolbar.addAction("🗑️ 删除选中", self.delete_selected_active)
290
+ toolbar.addAction("撤销", lambda: (self.command_bus.undo(), self.refresh_views()))
291
+ toolbar.addAction("重做", lambda: (self.command_bus.redo(), self.refresh_views()))
292
+ toolbar.addSeparator()
293
+ toolbar.addAction("清洁", self._clean_active)
294
+ toolbar.addAction("居中", self._center_active)
295
+ self.studio_toolbar = toolbar
296
+
297
+ def _set_active_tool(self, tool):
298
+ self._active_tool = tool
299
+ act = self._tool_actions.get(tool)
300
+ if act is not None and not act.isChecked():
301
+ act.setChecked(True)
302
+ for canvas in (getattr(self, "canvas2d", None), getattr(self, "canvas3d", None)):
303
+ if canvas is not None:
304
+ canvas.set_current_tool(tool)
305
+
306
+ def delete_selected_active(self):
307
+ """删除当前活动画布选中的原子与化学键 (P0 Bug 4)。"""
308
+ c2 = getattr(self, "canvas2d", None)
309
+ if c2 is not None and hasattr(c2, "delete_selected"):
310
+ c2.delete_selected()
311
+ self.refresh_views()
312
+ return
313
+ if self.selection is not None and self.command_bus is not None:
314
+ from ...application.selection_commands import DeleteSelectionCommand
315
+ self.command_bus.execute(DeleteSelectionCommand(self.selection.selected_atoms, self.selection.selected_bonds))
316
+ self.selection.clear()
317
+ self.refresh_views()
318
+
319
+ def _clean_active(self):
320
+ canvas = getattr(self, "canvas3d", None) or getattr(self, "canvas2d", None)
321
+ if canvas is None:
322
+ return
323
+ if hasattr(canvas, "clean_3d_geometry"):
324
+ canvas.clean_3d_geometry()
325
+ elif hasattr(canvas, "recompute_2d_layout"):
326
+ canvas.recompute_2d_layout()
327
+
328
+ def _center_active(self):
329
+ canvas = getattr(self, "canvas3d", None) or getattr(self, "canvas2d", None)
330
+ if canvas is None:
331
+ return
332
+ if hasattr(canvas, "reset_camera"):
333
+ canvas.reset_camera()
334
+ elif hasattr(canvas, "fit_view"):
335
+ canvas.fit_view()
336
+
337
+ # ---------- P1 Bug 5: Studio 完整导出功能 (SMILES / XYZ / MOL / SDF / PDB / PNG / SVG) ----------
338
+
339
+ def install_export_menu(self, file_menu: QMenu):
340
+ """向 Studio 窗口的「文件」菜单注入完整的结构与图像导出选项 (P1 Bug 5)。"""
341
+ exp_menu = file_menu.addMenu("📤 导出结构与图像 (Export)")
342
+ exp_menu.addAction("复制 SMILES 到剪贴板 (Copy SMILES)", self.export_smiles_to_clipboard)
343
+ exp_menu.addAction("导出 XYZ 坐标文件 (.xyz)...", self.export_xyz_file)
344
+ exp_menu.addAction("导出 MOL / SDF 结构文件 (.mol / .sdf)...", self.export_mol_sdf_file)
345
+ exp_menu.addAction("导出 PDB / MOL2 文件 (.pdb / .mol2)...", self.export_pdb_mol2_file)
346
+ exp_menu.addAction("导出 PNG 高清截图 / SVG 矢量图 (.png / .svg)...", self.export_image_file)
347
+
348
+ def _generate_smiles_string(self) -> str:
349
+ from ...io.rdkit_adapter import doc_to_rdkit, compute_formula_and_weight_fast
350
+ try:
351
+ from rdkit import Chem
352
+ rmol, _, _ = doc_to_rdkit(self.document, sanitize=True)
353
+ rmol_no_h = Chem.RemoveHs(rmol)
354
+ smi = Chem.MolToSmiles(rmol_no_h, canonical=True)
355
+ if smi:
356
+ return smi
357
+ except Exception:
358
+ pass
359
+ raise ValueError("当前结构无法生成有效SMILES;请先检查价态和键型")
360
+
361
+ def export_smiles_to_clipboard(self):
362
+ try:
363
+ smi = self._generate_smiles_string()
364
+ except Exception as exc:
365
+ QMessageBox.warning(self, "无法导出SMILES", str(exc))
366
+ return
367
+ QGuiApplication.clipboard().setText(smi)
368
+ QMessageBox.information(self, "已复制 SMILES", f"当前分子 SMILES 已复制到剪贴板:\n{smi}")
369
+
370
+ def export_xyz_file(self) -> bool:
371
+ path, _ = QFileDialog.getSaveFileName(self, "导出 XYZ 坐标文件", f"{self.document.name}.xyz", "XYZ Coordinates (*.xyz)")
372
+ if not path:
373
+ return False
374
+ from ...application.calculators.qc_input_generator import extract_xyz_lines
375
+ xyz_lines = extract_xyz_lines(self.document)
376
+ txt = f"{len(xyz_lines)}\n{self.document.name}\n" + "\n".join(xyz_lines) + "\n"
377
+ Path(path).write_text(txt, encoding="utf-8")
378
+ QMessageBox.information(self, "导出成功", f"已导出 XYZ 坐标文件:\n{path}")
379
+ return True
380
+
381
+ def export_mol_sdf_file(self) -> bool:
382
+ path, _ = QFileDialog.getSaveFileName(
383
+ self, "导出 MOL / SDF 结构文件", f"{self.document.name}.mol", "MDL MOL V2000 (*.mol);;SDF Structure (*.sdf)"
384
+ )
385
+ if not path:
386
+ return False
387
+ from ...io.rdkit_adapter import export_document_to_mol_v2000
388
+ mol_block = export_document_to_mol_v2000(self.document)
389
+ if path.lower().endswith(".sdf"):
390
+ mol_block = mol_block.rstrip() + "\n$$$$\n"
391
+ Path(path).write_text(mol_block, encoding="utf-8")
392
+ QMessageBox.information(self, "导出成功", f"已导出结构文件:\n{path}")
393
+ return True
394
+
395
+ def export_pdb_mol2_file(self) -> bool:
396
+ path, _ = QFileDialog.getSaveFileName(
397
+ self, "导出 PDB / MOL2 文件", f"{self.document.name}.pdb", "Protein Data Bank (*.pdb);;SYBYL MOL2 (*.mol2)"
398
+ )
399
+ if not path:
400
+ return False
401
+ from ...io.rdkit_adapter import export_document_to_pdb, export_document_to_mol2
402
+ if path.lower().endswith(".mol2"):
403
+ Path(path).write_text(export_document_to_mol2(self.document), encoding="utf-8")
404
+ else:
405
+ Path(path).write_text(export_document_to_pdb(self.document), encoding="utf-8")
406
+ QMessageBox.information(self, "导出成功", f"已导出文件:\n{path}")
407
+ return True
408
+
409
+ def export_image_file(self) -> bool:
410
+ path, _ = QFileDialog.getSaveFileName(
411
+ self, "导出高清图像", f"{self.document.name}.png", "PNG 高清图像 (*.png);;SVG 矢量图 (*.svg)"
412
+ )
413
+ if not path:
414
+ return False
415
+ if path.lower().endswith(".svg") and getattr(self, "canvas2d", None) is not None:
416
+ from ...io.writers.svg_writer import write_svg_2d
417
+ write_svg_2d(self.document, path)
418
+ else:
419
+ target = getattr(self, "canvas3d", None) or getattr(self, "canvas2d", None) or self
420
+ target.grab().save(path)
421
+ QMessageBox.information(self, "导出成功", f"已导出图像文件:\n{path}")
422
+ return True
423
+
424
+ # ---------- P1 Bug 6: 5 分钟定时自动保存与关闭未保存提示 ----------
425
+
426
+ def dragEnterEvent(self, event):
427
+ if event.mimeData().hasUrls() and any(u.isLocalFile() for u in event.mimeData().urls()):
428
+ event.acceptProposedAction()
429
+ else:
430
+ event.ignore()
431
+
432
+ def dropEvent(self, event):
433
+ for url in event.mimeData().urls():
434
+ if url.isLocalFile():
435
+ self.open_document_tab(url.toLocalFile())
436
+ event.acceptProposedAction()
437
+
438
+ def save_project(self, doc=None):
439
+ from ...io.mforge_storage import save_mforge
440
+ from ...runtime import data_dir
441
+ doc = doc if doc is not None else self.document
442
+ path, _ = QFileDialog.getSaveFileName(self, "保存完整分子工程", str(data_dir() / f"{doc.name}.mforge"), "MolForge Project (*.mforge)")
443
+ if not path:
444
+ return False
445
+ try:
446
+ save_mforge(doc, path)
447
+ except Exception as exc:
448
+ QMessageBox.critical(self, "保存失败", str(exc))
449
+ return False
450
+ self._saved_revisions[doc.document_id] = doc.revision
451
+ return True
452
+
453
+ def _is_doc_modified(self, doc: MoleculeDocument | None) -> bool:
454
+ if doc is None:
455
+ return False
456
+ saved_rev = self._saved_revisions.get(doc.document_id, 0)
457
+ return doc.revision > saved_rev
458
+
459
+ def _run_autosave(self):
460
+ """每 5 分钟自动将当前打开的分子工程备份至 ~/.molforge_autosave/。"""
461
+ try:
462
+ from ...io.mforge_storage import save_mforge
463
+ from ...runtime import data_dir
464
+ autosave_dir = data_dir() / "autosave"
465
+ autosave_dir.mkdir(parents=True, exist_ok=True)
466
+ for _w, (shell, _c2, _c3) in list(self._pages.items()):
467
+ doc = shell.document
468
+ if doc is not None:
469
+ safe_name = "".join(ch if ch.isalnum() or ch in ("-", "_") else "_" for ch in doc.name) or "untitled"
470
+ save_mforge(doc, autosave_dir / f"{safe_name}_{doc.document_id[:6]}.mforge")
471
+ except Exception as exc:
472
+ self.statusBar().showMessage(f"自动保存失败:{exc}", 10000)
473
+
474
+ def _confirm_save_if_modified(self, doc: MoleculeDocument | None) -> bool:
475
+ if not self._is_doc_modified(doc):
476
+ return True
477
+ ans = QMessageBox.question(
478
+ self,
479
+ "未保存的修改",
480
+ f"分子「{doc.name}」包含未保存的修改,是否在关闭前保存完整工程?",
481
+ QMessageBox.StandardButton.Save | QMessageBox.StandardButton.Discard | QMessageBox.StandardButton.Cancel,
482
+ QMessageBox.StandardButton.Save,
483
+ )
484
+ if ans == QMessageBox.StandardButton.Cancel:
485
+ return False
486
+ if ans == QMessageBox.StandardButton.Save:
487
+ return self.save_project(doc)
488
+ return True
489
+
490
+ def closeEvent(self, event):
491
+ for _w, (shell, _c2, _c3) in list(getattr(self, "_pages", {}).items()):
492
+ if not self._confirm_save_if_modified(shell.document):
493
+ event.ignore()
494
+ return
495
+ if hasattr(self, "_autosave_timer") and self._autosave_timer is not None:
496
+ self._autosave_timer.stop()
497
+ super().closeEvent(event)
498
+
499
+ def install_window_menu(self):
500
+ menu = next((m for m in self.menuBar().findChildren(QMenu) if m.title().startswith("窗口")), None)
501
+ if menu is None:
502
+ menu = self.menuBar().addMenu("窗口(&W)")
503
+ menu.addSeparator()
504
+ menu.addAction("新建画布", lambda: self.add_document_tab())
505
+ menu.addAction("关闭当前画布", self._close_active_canvas)
506
+ menu.addSeparator()
507
+ menu.addAction("平铺所有画布", lambda: self.show_canvas_mdi("tile"))
508
+ menu.addAction("层叠所有画布", lambda: self.show_canvas_mdi("cascade"))
509
+ menu.addAction("恢复标签页", self.restore_canvas_tabs)
510
+ menu.addSeparator()
511
+ next_act = menu.addAction("切换到下一个画布", lambda: self._cycle_tab(1))
512
+ next_act.setShortcut("Ctrl+Tab")
513
+ prev_act = menu.addAction("切换到上一个画布", lambda: self._cycle_tab(-1))
514
+ prev_act.setShortcut("Ctrl+Shift+Tab")
515
+ menu.addSeparator()
516
+ self.tab_list_menu = menu.addMenu("打开的画布")
517
+ self.tab_list_menu.aboutToShow.connect(self._populate_tab_list)
518
+ file_menu = next((m for m in self.menuBar().findChildren(QMenu) if m.title().startswith("文件")), None)
519
+ if file_menu is not None:
520
+ shortcuts = {a.shortcut().toString() for a in self.findChildren(QAction)}
521
+ if "Ctrl+N" not in shortcuts:
522
+ action = file_menu.addAction("新建空白画布 (Ctrl+N)", lambda: self.add_document_tab())
523
+ action.setShortcut("Ctrl+N")
524
+ if "Ctrl+S" not in shortcuts:
525
+ action = file_menu.addAction("保存完整工程 (Ctrl+S)", lambda: self.save_project())
526
+ action.setShortcut("Ctrl+S")
527
+ self.install_export_menu(file_menu)
528
+ file_menu.addSeparator()
529
+ file_menu.addAction("合并到主系统标签页", self.merge_into_main)
530
+ edit_menu = next((m for m in self.menuBar().findChildren(QMenu) if m.title().startswith("编辑")), None)
531
+ if edit_menu is not None:
532
+ edit_menu.addSeparator()
533
+ del_act = QAction("删除选中原子 / 化学键 (Delete)", self)
534
+ del_act.setShortcut("Delete")
535
+ del_act.triggered.connect(self.delete_selected_active)
536
+ edit_menu.addAction(del_act)
537
+ calc_menu = next((m for m in self.menuBar().findChildren(QMenu) if m.title().startswith("计算")), None)
538
+ if calc_menu is not None:
539
+ calc_menu.addSeparator()
540
+ eng_act = QAction("引擎状态与工具路径配置...", self)
541
+ eng_act.triggered.connect(self._open_engine_status_dialog)
542
+ calc_menu.addAction(eng_act)
543
+
544
+ def _open_engine_status_dialog(self):
545
+ from .workflow_inputs import ToolPathConfigDialog
546
+ ToolPathConfigDialog(self).exec()
547
+
548
+ def merge_into_main(self):
549
+ from ..window import MolForgeWindow
550
+ from ..welcome_window import AppController
551
+ main = next((w for w in MolForgeWindow._open_windows if w.isVisible()), None)
552
+ if main is None:
553
+ main = MolForgeWindow(initial_document=self.document)
554
+ AppController.instance().active_windows.append(main)
555
+ else:
556
+ main._add_document_page(self.document, self.session)
557
+ main.show()
558
+ main.raise_()
559
+
560
+ def show_canvas_mdi(self, arrangement="tile"):
561
+ if getattr(self, "_mdi_area", None) is not None:
562
+ self._arrange_mdi(arrangement)
563
+ return
564
+ old_center = self.tabs
565
+ old_center.setParent(None)
566
+ old_center.hide()
567
+
568
+ area = QMdiArea(self)
569
+ area.setViewMode(QMdiArea.ViewMode.SubWindowView)
570
+ area.subWindowActivated.connect(self._activate_mdi_window)
571
+ self._mdi_area = area
572
+ for widget, (shell, _c2, _c3) in list(self._pages.items()):
573
+ sub = _DocumentSubWindow(self)
574
+ sub.setWidget(widget)
575
+ area.addSubWindow(sub)
576
+ sub.setWindowTitle(shell.document.name)
577
+ sub.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose, False)
578
+ sub.show()
579
+ self.setCentralWidget(area)
580
+ self._arrange_mdi(arrangement)
581
+ if area.activeSubWindow() is not None:
582
+ self._activate_mdi_window(area.activeSubWindow())
583
+
584
+ def _arrange_mdi(self, arrangement):
585
+ if self._mdi_area is None:
586
+ return
587
+ if arrangement == "tile":
588
+ self._mdi_area.tileSubWindows()
589
+ else:
590
+ self._mdi_area.cascadeSubWindows()
591
+
592
+ def _activate_mdi_window(self, subwindow):
593
+ if subwindow is None:
594
+ return
595
+ page = subwindow.widget()
596
+ if page in self._pages:
597
+ self._active_mdi_page = page
598
+ self._pages[page][0].document.name = subwindow.windowTitle()
599
+ self._activate_page(widget=page)
600
+
601
+ def _close_active_canvas(self):
602
+ if self._mdi_area is not None:
603
+ sub = self._mdi_area.activeSubWindow()
604
+ if sub is not None:
605
+ self._close_mdi_page(sub.widget())
606
+ return
607
+ self.close_tab(self.tabs.currentIndex())
608
+
609
+ def _close_mdi_page(self, page):
610
+ if page not in self._pages:
611
+ return
612
+ if not self._confirm_save_if_modified(self._pages[page][0].document):
613
+ return
614
+ if len(self._pages) == 1:
615
+ choice = QMessageBox.question(
616
+ self,
617
+ "关闭最后一个画布",
618
+ "新建空白分子?选择“否”返回欢迎界面。",
619
+ QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No | QMessageBox.StandardButton.Cancel,
620
+ )
621
+ if choice == QMessageBox.StandardButton.Cancel:
622
+ return
623
+ if choice == QMessageBox.StandardButton.No:
624
+ self._open_welcome()
625
+ self.close()
626
+ return
627
+ self.add_document_tab()
628
+ area = self._mdi_area
629
+ shell = self._pages.pop(page)[0]
630
+ sub = next((w for w in area.subWindowList() if w.widget() is page), None)
631
+ if sub is not None:
632
+ area.removeSubWindow(page)
633
+ sub.deleteLater()
634
+ page.deleteLater()
635
+ shell.close_shell()
636
+ if not self._pages:
637
+ self._mdi_area = None
638
+ self.restore_canvas_tabs()
639
+ return
640
+ self._arrange_mdi("tile")
641
+ active = area.activeSubWindow()
642
+ if active is not None:
643
+ self._activate_mdi_window(active)
644
+
645
+ def restore_canvas_tabs(self):
646
+ area = self._mdi_area
647
+ if area is None:
648
+ return
649
+ active = getattr(self, "_active_mdi_page", None)
650
+ self.tabs.blockSignals(True)
651
+ for sub in list(area.subWindowList()):
652
+ page = sub.widget()
653
+ if page is None or page not in self._pages:
654
+ continue
655
+ shell, _c2, _c3 = self._pages[page]
656
+ title = sub.windowTitle() or shell.document.name
657
+ shell.document.name = title
658
+ page.setParent(self.tabs)
659
+ area.removeSubWindow(sub)
660
+ sub.deleteLater()
661
+ page.setParent(self.tabs)
662
+ page.show()
663
+ self.tabs.addTab(page, title)
664
+ self.tabs.blockSignals(False)
665
+ area.setParent(None)
666
+ self._mdi_area = None
667
+ self.setCentralWidget(self.tabs)
668
+ self.tabs.show()
669
+ area.deleteLater()
670
+ if self.tabs.count():
671
+ index = self.tabs.indexOf(active) if active is not None else 0
672
+ self.tabs.setCurrentIndex(max(0, index))
673
+ self._activate_page(self.tabs.currentWidget())
674
+
675
+ def _activate_page(self, widget):
676
+ if widget not in self._pages:
677
+ return
678
+ self.shell, self.canvas2d, self.canvas3d = self._pages[widget]
679
+ self.session = self.shell.session
680
+ self.view_session = self.shell.view_session
681
+ self.document = self.session.document
682
+ self.command_bus = self.session.command_bus
683
+ self.selection = self.session.selection
684
+ self.group_tag = self.shell.gmv_tag
685
+ if hasattr(self, "splitter") and widget is not None:
686
+ self.splitter = widget
687
+ for canvas in (self.canvas2d, self.canvas3d):
688
+ if canvas is not None:
689
+ canvas.set_selection_service(self.selection)
690
+ canvas.set_command_bus(self.command_bus)
691
+ canvas.set_current_element(self._active_element)
692
+ canvas.set_current_tool(self._active_tool)
693
+ canvas.set_document(self.document)
694
+ self.refresh_views()
695
+
696
+ def _cycle_tab(self, direction):
697
+ if self._mdi_area is not None:
698
+ subs = self._mdi_area.subWindowList()
699
+ if subs:
700
+ current = self._mdi_area.activeSubWindow()
701
+ index = subs.index(current) if current in subs else 0
702
+ self._mdi_area.setActiveSubWindow(subs[(index + direction) % len(subs)])
703
+ return
704
+ if self.tabs.count():
705
+ self.tabs.setCurrentIndex((self.tabs.currentIndex() + direction) % self.tabs.count())
706
+
707
+ def _populate_tab_list(self):
708
+ self.tab_list_menu.clear()
709
+ if self._mdi_area is not None:
710
+ for sub in self._mdi_area.subWindowList():
711
+ self.tab_list_menu.addAction(sub.windowTitle(), lambda _=False, w=sub: self._mdi_area.setActiveSubWindow(w))
712
+ else:
713
+ for i in range(self.tabs.count()):
714
+ self.tab_list_menu.addAction(self.tabs.tabText(i), lambda _=False, n=i: self.tabs.setCurrentIndex(n))
715
+