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,52 @@
1
+ """Natural-size tool strips: controls keep their text; the viewport scrolls."""
2
+ from PyQt6.QtCore import Qt, pyqtSignal
3
+ from PyQt6.QtWidgets import QScrollArea, QFrame, QLayout, QPushButton, QLabel, QSizePolicy
4
+
5
+ class HorizontalWheelScrollArea(QScrollArea):
6
+ height_changed = pyqtSignal(int)
7
+ def __init__(self, content_widget, height=42, parent=None):
8
+ super().__init__(parent)
9
+ if not content_widget.objectName():
10
+ content_widget.setObjectName("ToolbarStrip")
11
+ content_widget.ensurePolished()
12
+ for child in content_widget.findChildren(QPushButton) + content_widget.findChildren(QLabel):
13
+ child.ensurePolished()
14
+ child.setMinimumWidth(min(child.maximumWidth(), max(child.minimumWidth(), child.sizeHint().width())))
15
+ content_widget.setMinimumHeight(max(height, content_widget.sizeHint().height()))
16
+ content_widget.layout().setSizeConstraint(QLayout.SizeConstraint.SetMinimumSize)
17
+ self.setWidget(content_widget)
18
+ self.setWidgetResizable(True)
19
+ self.setFrameShape(QFrame.Shape.NoFrame)
20
+ self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
21
+ self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded)
22
+ self.setMinimumWidth(0)
23
+ self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed)
24
+ self.setFixedHeight(content_widget.minimumHeight() + self.horizontalScrollBar().sizeHint().height())
25
+ self.horizontalScrollBar().rangeChanged.connect(self._fit_height)
26
+
27
+ def _fit_height(self, minimum, maximum):
28
+ content_height = max(self.widget().minimumHeight(), self.widget().sizeHint().height())
29
+ self.setFixedHeight(content_height + (self.horizontalScrollBar().sizeHint().height() if maximum > 0 else 0))
30
+
31
+ def resizeEvent(self, event):
32
+ super().resizeEvent(event)
33
+ self.height_changed.emit(self.height())
34
+
35
+ def wheelEvent(self, event):
36
+ bar = self.horizontalScrollBar()
37
+ # 若水平滚动条存在且有可滚动余量,则响应水平滚轮
38
+ if bar and bar.maximum() > 0:
39
+ delta = event.angleDelta().y() or event.angleDelta().x()
40
+ old_val = bar.value()
41
+ bar.setValue(old_val - int(delta * .6))
42
+ if bar.value() != old_val:
43
+ event.accept()
44
+ return
45
+ event.ignore()
46
+ # 否则将纵向滚轮事件透传给外层父级垂直滚动容器
47
+ parent = self.parent()
48
+ while parent is not None:
49
+ if isinstance(parent, QScrollArea):
50
+ parent.wheelEvent(event)
51
+ break
52
+ parent = parent.parent()
@@ -0,0 +1,330 @@
1
+ """
2
+ ui/settings_panel.py - Blender / DaVinci 风格模块化渲染与主题设置面板
3
+ =====================================================================
4
+ 修复:
5
+ - 移除旧版默认 Windows 95 风格 QGroupBox 与白底看不清字的按钮
6
+ - 每个滑块配备实时百分比/数值读数标签(#66DEC9 等宽字体)
7
+ - 所有滑块与下拉框安装滚轮防误触过滤器(WheelGuard),使面板上下滚动极其顺滑
8
+ """
9
+ from __future__ import annotations
10
+
11
+ from PyQt6.QtCore import Qt, QObject, QEvent, pyqtSignal
12
+ from PyQt6.QtWidgets import (
13
+ QWidget, QVBoxLayout, QHBoxLayout, QFrame, QLabel, QPushButton,
14
+ QColorDialog, QSlider, QComboBox
15
+ )
16
+ from PyQt6.QtGui import QColor
17
+
18
+
19
+ class WheelGuardFilter(QObject):
20
+ """防止在 QScrollArea 中滚动鼠标滚轮时误触未聚焦的控件,同时将滚轮事件无缝转发给外层滚动区域,彻底消除滚轮卡死。"""
21
+
22
+ def eventFilter(self, obj, event) -> bool:
23
+ if event.type() == QEvent.Type.Wheel and not obj.hasFocus():
24
+ event.ignore()
25
+ from PyQt6.QtWidgets import QScrollArea
26
+ parent = obj.parent()
27
+ while parent is not None:
28
+ if isinstance(parent, QScrollArea):
29
+ parent.wheelEvent(event)
30
+ break
31
+ parent = parent.parent()
32
+ return True
33
+ return super().eventFilter(obj, event)
34
+
35
+
36
+ def install_wheel_guard(widget: QWidget, guard: WheelGuardFilter) -> None:
37
+ widget.setFocusPolicy(Qt.FocusPolicy.StrongFocus)
38
+ widget.installEventFilter(guard)
39
+
40
+
41
+ class SettingsCard(QFrame):
42
+ """带精致标题栏的设置模块卡片。"""
43
+
44
+ def __init__(self, title: str, parent=None):
45
+ super().__init__(parent)
46
+ self.setObjectName("CollapsibleCard")
47
+ self._root = QVBoxLayout(self)
48
+ self._root.setContentsMargins(0, 0, 0, 0)
49
+ self._root.setSpacing(0)
50
+
51
+ self.header_btn = QPushButton(f"▾ {title}")
52
+ self.header_btn.setObjectName("CardHeaderBtn")
53
+ self.header_btn.setCheckable(True)
54
+ self.header_btn.setChecked(True)
55
+ self.header_btn.clicked.connect(self._toggle)
56
+ self._root.addWidget(self.header_btn)
57
+ self._title = title
58
+
59
+ self.body = QWidget()
60
+ self.body.setObjectName("ScrollPage")
61
+ self.body_layout = QVBoxLayout(self.body)
62
+ self.body_layout.setContentsMargins(11, 10, 11, 11)
63
+ self.body_layout.setSpacing(8)
64
+ self._root.addWidget(self.body)
65
+
66
+ def _toggle(self, checked: bool):
67
+ self.body.setVisible(checked)
68
+ arrow = "▾" if checked else "▸"
69
+ self.header_btn.setText(f"{arrow} {self._title}")
70
+
71
+
72
+ class SettingsPanel(QWidget):
73
+ """
74
+ 模块化渲染与外观设置面板。
75
+ """
76
+
77
+ canvas_color_changed = pyqtSignal(QColor)
78
+ material_changed = pyqtSignal(str)
79
+ theme_changed = pyqtSignal(str)
80
+ atom_size_changed = pyqtSignal(float)
81
+ bond_width_changed = pyqtSignal(float)
82
+ background_3d_changed = pyqtSignal(QColor)
83
+ roughness_changed = pyqtSignal(float)
84
+ metallic_changed = pyqtSignal(float)
85
+ accent_picked = pyqtSignal(str)
86
+
87
+ def __init__(self, parent=None):
88
+ super().__init__(parent)
89
+ self.setObjectName("ScrollPage")
90
+ self._wheel_guard = WheelGuardFilter(self)
91
+
92
+ layout = QVBoxLayout(self)
93
+ layout.setContentsMargins(4, 4, 6, 12)
94
+ layout.setSpacing(10)
95
+
96
+ # 1. 3D 球棍与几何比例模块
97
+ geom_card = SettingsCard("3D 球棍比例与尺寸 (GEOMETRY SCALE)")
98
+ b_lay = geom_card.body_layout
99
+
100
+ # 原子大小滑块 + 实时读数
101
+ row_a_top = QHBoxLayout()
102
+ row_a_top.addWidget(QLabel("原子球半径缩放"))
103
+ row_a_top.addStretch()
104
+ self.atom_val_label = QLabel("100%")
105
+ self.atom_val_label.setProperty("role", "value")
106
+ row_a_top.addWidget(self.atom_val_label)
107
+ b_lay.addLayout(row_a_top)
108
+
109
+ self.atom_size_slider = QSlider(Qt.Orientation.Horizontal)
110
+ self.atom_size_slider.setRange(40, 220)
111
+ self.atom_size_slider.setValue(100)
112
+ install_wheel_guard(self.atom_size_slider, self._wheel_guard)
113
+ self.atom_size_slider.valueChanged.connect(self._on_atom_slider)
114
+ b_lay.addWidget(self.atom_size_slider)
115
+
116
+ # 键粗细滑块 + 实时读数
117
+ row_b_top = QHBoxLayout()
118
+ row_b_top.addWidget(QLabel("化学键圆柱半径"))
119
+ row_b_top.addStretch()
120
+ self.bond_val_label = QLabel("100%")
121
+ self.bond_val_label.setProperty("role", "value")
122
+ row_b_top.addWidget(self.bond_val_label)
123
+ b_lay.addLayout(row_b_top)
124
+
125
+ self.bond_width_slider = QSlider(Qt.Orientation.Horizontal)
126
+ self.bond_width_slider.setRange(40, 220)
127
+ self.bond_width_slider.setValue(100)
128
+ install_wheel_guard(self.bond_width_slider, self._wheel_guard)
129
+ self.bond_width_slider.valueChanged.connect(self._on_bond_slider)
130
+ b_lay.addWidget(self.bond_width_slider)
131
+
132
+ layout.addWidget(geom_card)
133
+
134
+ # 2. Studio 材质与光照模块
135
+ mat_card = SettingsCard("3D 棚拍材质与高光 (STUDIO SHADING)")
136
+ m_lay = mat_card.body_layout
137
+
138
+ row_preset = QHBoxLayout()
139
+ row_preset.addWidget(QLabel("光学预设"))
140
+ self.material_combo = QComboBox()
141
+ self.material_combo.addItems(["Studio", "Scientific", "Analysis"])
142
+ install_wheel_guard(self.material_combo, self._wheel_guard)
143
+ self.material_combo.currentTextChanged.connect(self.material_changed.emit)
144
+ row_preset.addWidget(self.material_combo, 1)
145
+ m_lay.addLayout(row_preset)
146
+
147
+ row_r_top = QHBoxLayout()
148
+ row_r_top.addWidget(QLabel("表面粗糙度 (Roughness)"))
149
+ row_r_top.addStretch()
150
+ self.rough_val_label = QLabel("0.35")
151
+ self.rough_val_label.setProperty("role", "value")
152
+ row_r_top.addWidget(self.rough_val_label)
153
+ m_lay.addLayout(row_r_top)
154
+
155
+ self.roughness_slider = QSlider(Qt.Orientation.Horizontal)
156
+ self.roughness_slider.setRange(5, 95)
157
+ self.roughness_slider.setValue(35)
158
+ install_wheel_guard(self.roughness_slider, self._wheel_guard)
159
+ self.roughness_slider.valueChanged.connect(self._on_rough_slider)
160
+ m_lay.addWidget(self.roughness_slider)
161
+
162
+ row_m_top = QHBoxLayout()
163
+ row_m_top.addWidget(QLabel("环境反射强度 (Ambient)"))
164
+ row_m_top.addStretch()
165
+ self.metal_val_label = QLabel("0.10")
166
+ self.metal_val_label.setProperty("role", "value")
167
+ row_m_top.addWidget(self.metal_val_label)
168
+ m_lay.addLayout(row_m_top)
169
+
170
+ self.metallic_slider = QSlider(Qt.Orientation.Horizontal)
171
+ self.metallic_slider.setRange(0, 100)
172
+ self.metallic_slider.setValue(10)
173
+ install_wheel_guard(self.metallic_slider, self._wheel_guard)
174
+ self.metallic_slider.valueChanged.connect(self._on_metal_slider)
175
+ m_lay.addWidget(self.metallic_slider)
176
+
177
+ layout.addWidget(mat_card)
178
+
179
+ # 3. 主题与视口背景色模块
180
+ theme_card = SettingsCard("界面主题与视口背景 (THEME & CANVAS)")
181
+ t_lay = theme_card.body_layout
182
+
183
+ row_theme = QHBoxLayout()
184
+ row_theme.addWidget(QLabel("全局主题"))
185
+ self.theme_combo = QComboBox()
186
+ self.theme_combo.addItems(["Dark Professional", "Light Clean", "High Contrast"])
187
+ install_wheel_guard(self.theme_combo, self._wheel_guard)
188
+ self.theme_combo.currentTextChanged.connect(self.theme_changed.emit)
189
+ row_theme.addWidget(self.theme_combo, 1)
190
+ t_lay.addLayout(row_theme)
191
+
192
+ row_colors = QHBoxLayout()
193
+ self.canvas_bg_btn = QPushButton("2D 画布底色...")
194
+ self.canvas_bg_btn.clicked.connect(self._pick_canvas_color)
195
+ row_colors.addWidget(self.canvas_bg_btn)
196
+
197
+ self.canvas_3d_btn = QPushButton("3D 视口底色...")
198
+ self.canvas_3d_btn.clicked.connect(self._pick_3d_color)
199
+ row_colors.addWidget(self.canvas_3d_btn)
200
+ t_lay.addLayout(row_colors)
201
+
202
+ self.accent_btn = QPushButton("自定义主题强调色 (#66DEC9)...")
203
+ self.accent_btn.clicked.connect(self._pick_accent)
204
+ t_lay.addWidget(self.accent_btn)
205
+
206
+ layout.addWidget(theme_card)
207
+
208
+ # 4. 界面字体与排版定制 (UI TYPOGRAPHY)
209
+ font_card = SettingsCard("🔤 界面字体与排版定制 (UI TYPOGRAPHY)")
210
+ f_lay = font_card.body_layout
211
+
212
+ row_f_family = QHBoxLayout()
213
+ row_f_family.addWidget(QLabel("中英文字体系列"))
214
+ self.font_family_combo = QComboBox()
215
+ self.font_family_combo.addItems([
216
+ "Microsoft YaHei UI",
217
+ "PingFang SC",
218
+ "SimHei",
219
+ "Segoe UI",
220
+ "Arial",
221
+ "System Default",
222
+ ])
223
+ install_wheel_guard(self.font_family_combo, self._wheel_guard)
224
+ row_f_family.addWidget(self.font_family_combo, 1)
225
+ f_lay.addLayout(row_f_family)
226
+
227
+ row_f_size = QHBoxLayout()
228
+ row_f_size.addWidget(QLabel("UI 基础字号"))
229
+ self.font_size_combo = QComboBox()
230
+ for sz, lbl in [
231
+ (12, "12px · 紧凑小号"),
232
+ (13, "13px · 标准学术"),
233
+ (14, "14px · 舒适现代 (默认推荐)"),
234
+ (15, "15px · 清晰易读"),
235
+ (16, "16px · 大字号"),
236
+ (18, "18px · 高分屏 4K 宽屏"),
237
+ ]:
238
+ self.font_size_combo.addItem(lbl, sz)
239
+ self.font_size_combo.setCurrentIndex(2)
240
+ install_wheel_guard(self.font_size_combo, self._wheel_guard)
241
+ row_f_size.addWidget(self.font_size_combo, 1)
242
+ f_lay.addLayout(row_f_size)
243
+
244
+ btn_apply_font = QPushButton("💾 保存并应用全局字体设置")
245
+ btn_apply_font.setStyleSheet("QPushButton { font-weight:700; font-size:13px; min-height:30px; background:#0D9488; color:#FFFFFF; border:1px solid #5EEAD4; }")
246
+ btn_apply_font.clicked.connect(self._apply_and_save_fonts)
247
+ f_lay.addWidget(btn_apply_font)
248
+
249
+ layout.addWidget(font_card)
250
+ layout.addStretch(1)
251
+
252
+ # 启动时回显已持久化的主题、强调色与字体排版配置
253
+ self._load_persisted_preferences()
254
+
255
+ def _load_persisted_preferences(self):
256
+ from .theme import load_saved_typography, load_saved_theme
257
+ saved_theme, saved_accent = load_saved_theme()
258
+ self._current_accent = saved_accent
259
+ self.theme_combo.blockSignals(True)
260
+ idx_t = self.theme_combo.findText(saved_theme)
261
+ if idx_t >= 0:
262
+ self.theme_combo.setCurrentIndex(idx_t)
263
+ self.theme_combo.blockSignals(False)
264
+ if saved_accent:
265
+ self.accent_btn.setText(f"强调色: {saved_accent}")
266
+
267
+ family, size = load_saved_typography()
268
+ self.font_family_combo.blockSignals(True)
269
+ idx_f = self.font_family_combo.findText(family)
270
+ if idx_f >= 0:
271
+ self.font_family_combo.setCurrentIndex(idx_f)
272
+ self.font_family_combo.blockSignals(False)
273
+
274
+ self.font_size_combo.blockSignals(True)
275
+ idx_s = self.font_size_combo.findData(int(size))
276
+ if idx_s >= 0:
277
+ self.font_size_combo.setCurrentIndex(idx_s)
278
+ self.font_size_combo.blockSignals(False)
279
+
280
+ def _apply_and_save_fonts(self):
281
+ from PyQt6.QtWidgets import QMessageBox
282
+ from PyQt6.QtCore import QSettings
283
+ from .theme import apply_global_typography
284
+ store = QSettings("MolForge", "Typography")
285
+ family = self.font_family_combo.currentText()
286
+ if family == "System Default":
287
+ family = "Microsoft YaHei UI"
288
+ size = int(self.font_size_combo.currentData() or 14)
289
+
290
+ store.setValue("font_family", family)
291
+ store.setValue("font_size", size)
292
+
293
+ cur_theme = self.theme_combo.currentText() or None
294
+ cur_accent = getattr(self, "_current_accent", None)
295
+ apply_global_typography(family, size, theme_name=cur_theme, accent=cur_accent)
296
+ QMessageBox.information(self, "字体已更新", f"界面字体已更新为:{family},基准字号:{size}px!全界面及左右侧边栏已即时同步生效。")
297
+
298
+ def _on_atom_slider(self, v: int):
299
+ self.atom_val_label.setText(f"{v}%")
300
+ self.atom_size_changed.emit(v / 100.0)
301
+
302
+ def _on_bond_slider(self, v: int):
303
+ self.bond_val_label.setText(f"{v}%")
304
+ self.bond_width_changed.emit(v / 100.0)
305
+
306
+ def _on_rough_slider(self, v: int):
307
+ self.rough_val_label.setText(f"{v / 100.0:.2f}")
308
+ self.roughness_changed.emit(v / 100.0)
309
+
310
+ def _on_metal_slider(self, v: int):
311
+ self.metal_val_label.setText(f"{v / 100.0:.2f}")
312
+ self.metallic_changed.emit(v / 100.0)
313
+
314
+ def _pick_accent(self):
315
+ c = QColorDialog.getColor(QColor("#66DEC9"), self, "选择主题强调色")
316
+ if c.isValid():
317
+ hexc = c.name()
318
+ self._current_accent = hexc
319
+ self.accent_btn.setText(f"强调色: {hexc}")
320
+ self.accent_picked.emit(hexc)
321
+
322
+ def _pick_canvas_color(self):
323
+ color = QColorDialog.getColor(QColor("#F4F3EE"), self, "选择 2D 画布颜色")
324
+ if color.isValid():
325
+ self.canvas_color_changed.emit(color)
326
+
327
+ def _pick_3d_color(self):
328
+ color = QColorDialog.getColor(QColor("#111D2C"), self, "选择 3D 背景颜色")
329
+ if color.isValid():
330
+ self.background_3d_changed.emit(color)
@@ -0,0 +1,4 @@
1
+ from .base_shell import BaseStudioShell
2
+ from .studio_2d import Studio2DShell
3
+ from .studio_3d import Studio3DShell
4
+ from .studio_split import StudioSplitShell
@@ -0,0 +1,72 @@
1
+ """
2
+ ui/shells/base_shell.py - 三大独立系统共享的抽象会话外壳契约
3
+ ============================================================
4
+ 每个独立系统 (Studio2DShell / Studio3DShell / StudioSplitShell) 均消费同一个 DocumentSession,
5
+ 拥有各自独立的菜单体系、状态栏与窗口生命周期,而非简单隐藏旧三栏面板。
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from ..gmv_window_manager import GMVWindowManager
11
+ from ...application.document_session import DocumentSession, DocumentSessionEvent
12
+ from ...application.workspace_registry import PaneCount, ViewSession, WorkspaceRegistry
13
+ from ...domain.document import MoleculeDocument
14
+
15
+
16
+ class BaseStudioShell:
17
+ """三大独立 Studio 系统的公共会话基类(可在无头测试与 PyQt6 主窗口下共用)。"""
18
+
19
+ shell_kind: str = "base"
20
+ menu_titles: tuple[str, ...] = ()
21
+
22
+ def __init__(
23
+ self,
24
+ document: MoleculeDocument | None = None,
25
+ session: DocumentSession | None = None,
26
+ view_session: ViewSession | None = None,
27
+ pane_count: PaneCount = 1,
28
+ ) -> None:
29
+ reg = WorkspaceRegistry.instance()
30
+ if session is not None:
31
+ self.session = session
32
+ doc = session.document
33
+ else:
34
+ doc = document if document is not None else MoleculeDocument(name="untitled")
35
+ self.session = reg.get_or_create_session(doc)
36
+
37
+ if view_session is not None:
38
+ self.view_session = view_session
39
+ else:
40
+ _, self.view_session = reg.create_new_group_view(self.session.document, pane_count=pane_count)
41
+
42
+ self.gmv_manager = GMVWindowManager(reg)
43
+ self.is_closed: bool = False
44
+ self.last_event: DocumentSessionEvent | None = None
45
+ self.session.event_hub.subscribe(self._on_session_event)
46
+
47
+ @property
48
+ def document(self) -> MoleculeDocument:
49
+ return self.session.document
50
+
51
+ @property
52
+ def gmv_tag(self) -> str:
53
+ return self.view_session.gmv_tag
54
+
55
+ def status_summary(self) -> dict[str, int | str]:
56
+ return {
57
+ "gmv_tag": self.gmv_tag,
58
+ "atoms": self.document.topology.num_atoms,
59
+ "bonds": self.document.topology.num_bonds,
60
+ "electrons": self.session.total_electrons(),
61
+ "charge": int(self.document.properties.get("charge", 0)),
62
+ "multiplicity": self.session.spin_multiplicity(),
63
+ }
64
+
65
+ def close_shell(self) -> None:
66
+ if not self.is_closed:
67
+ self.session.event_hub.unsubscribe(self._on_session_event)
68
+ self.gmv_manager.close_window(self.gmv_tag)
69
+ self.is_closed = True
70
+
71
+ def _on_session_event(self, event: DocumentSessionEvent) -> None:
72
+ self.last_event = event