molforge-studio 7.4.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- main.py +71 -0
- molforge/__init__.py +19 -0
- molforge/ai/__init__.py +15 -0
- molforge/ai/deepseek_harness.py +185 -0
- molforge/ai/mcp/desktop_client.py +38 -0
- molforge/ai/mcp/desktop_service.py +121 -0
- molforge/ai/mcp/mcp_server.py +780 -0
- molforge/ai/mcp_bridge.py +945 -0
- molforge/ai/observation.py +152 -0
- molforge/ai/tools.py +455 -0
- molforge/application/__init__.py +22 -0
- molforge/application/ai/__init__.py +1 -0
- molforge/application/ai/deepseek_client.py +293 -0
- molforge/application/ai/observation.py +161 -0
- molforge/application/ai/tools.py +200 -0
- molforge/application/ai_proposals.py +166 -0
- molforge/application/bio_selection.py +143 -0
- molforge/application/builtin_commands.py +1445 -0
- molforge/application/calculators/__init__.py +10 -0
- molforge/application/calculators/base.py +143 -0
- molforge/application/calculators/calchem_engine.py +67 -0
- molforge/application/calculators/calchem_subprocess_worker.py +109 -0
- molforge/application/calculators/gaussian_engine.py +59 -0
- molforge/application/calculators/gaussian_job_spec.py +240 -0
- molforge/application/calculators/orca_engine.py +92 -0
- molforge/application/calculators/qc_input_generator.py +300 -0
- molforge/application/calculators/registry.py +29 -0
- molforge/application/calculators/rest_engine.py +262 -0
- molforge/application/command_bus.py +139 -0
- molforge/application/commands.py +55 -0
- molforge/application/conformers.py +143 -0
- molforge/application/document_session.py +156 -0
- molforge/application/events.py +74 -0
- molforge/application/fragment_catalog.py +422 -0
- molforge/application/fragment_commands.py +268 -0
- molforge/application/geometry_commands.py +84 -0
- molforge/application/history.py +105 -0
- molforge/application/internal_coordinates.py +293 -0
- molforge/application/invalidation.py +1174 -0
- molforge/application/jobs.py +185 -0
- molforge/application/measurement.py +167 -0
- molforge/application/measurement_targets.py +264 -0
- molforge/application/modeling_commands.py +61 -0
- molforge/application/plugins.py +197 -0
- molforge/application/ports/editor2d.py +85 -0
- molforge/application/reaction.py +75 -0
- molforge/application/selection.py +164 -0
- molforge/application/selection_commands.py +31 -0
- molforge/application/trajectory.py +120 -0
- molforge/application/trajectory_analysis.py +231 -0
- molforge/application/workspace_registry.py +226 -0
- molforge/core/__init__.py +12 -0
- molforge/core/conformer.py +45 -0
- molforge/core/molecule.py +150 -0
- molforge/core/orbital.py +33 -0
- molforge/core/properties.py +43 -0
- molforge/domain/__init__.py +12 -0
- molforge/domain/biomolecule.py +99 -0
- molforge/domain/chemical_summary.py +129 -0
- molforge/domain/chemistry.py +13 -0
- molforge/domain/coordinate_store.py +164 -0
- molforge/domain/coordination.py +133 -0
- molforge/domain/custom_fragments.py +255 -0
- molforge/domain/document.py +469 -0
- molforge/domain/element_reference.json +598 -0
- molforge/domain/elements.py +188 -0
- molforge/domain/ids.py +58 -0
- molforge/domain/massive_system.py +246 -0
- molforge/domain/periodic.py +116 -0
- molforge/domain/provenance.py +115 -0
- molforge/domain/topology.py +364 -0
- molforge/infrastructure/__init__.py +23 -0
- molforge/infrastructure/hpc/cluster_config.py +122 -0
- molforge/infrastructure/hpc/remote_executor.py +212 -0
- molforge/infrastructure/hpc/slurm_generator.py +93 -0
- molforge/io/__init__.py +35 -0
- molforge/io/calchem_bridge.py +407 -0
- molforge/io/calculators.py +893 -0
- molforge/io/cclib_adapter.py +422 -0
- molforge/io/conformers.py +183 -0
- molforge/io/cube_reader.py +215 -0
- molforge/io/custom_fragments.py +79 -0
- molforge/io/format_matrix.py +157 -0
- molforge/io/gemmi_adapter.py +150 -0
- molforge/io/history_skill.py +46 -0
- molforge/io/mdanalysis_adapter.py +155 -0
- molforge/io/mforge_storage.py +261 -0
- molforge/io/multiwfn_driver.py +614 -0
- molforge/io/openbabel_adapter.py +265 -0
- molforge/io/openbabel_handler.py +33 -0
- molforge/io/rdkit_adapter.py +1865 -0
- molforge/io/readers/__init__.py +10 -0
- molforge/io/readers/cube_reader.py +71 -0
- molforge/io/readers/gjf_reader.py +110 -0
- molforge/io/readers/glog_reader.py +45 -0
- molforge/io/readers/mol2_reader.py +36 -0
- molforge/io/readers/mol_reader.py +56 -0
- molforge/io/readers/pdb_reader.py +39 -0
- molforge/io/readers/smi_reader.py +40 -0
- molforge/io/readers/xyz_reader.py +47 -0
- molforge/io/registry.py +128 -0
- molforge/io/writers/__init__.py +7 -0
- molforge/io/writers/gjf_writer.py +68 -0
- molforge/io/writers/pdb_writer.py +37 -0
- molforge/io/writers/png_writer.py +31 -0
- molforge/io/writers/svg_writer.py +111 -0
- molforge/io/writers/xyz_writer.py +39 -0
- molforge/rendering/__init__.py +21 -0
- molforge/rendering/benchmark.py +121 -0
- molforge/rendering/bridge.py +60 -0
- molforge/rendering/contracts.py +119 -0
- molforge/rendering/glyph_scene.py +279 -0
- molforge/rendering/ketcher_bridge.py +131 -0
- molforge/rendering/ketcher_id_mapping.py +110 -0
- molforge/rendering/materials.py +127 -0
- molforge/rendering/molstar_backend.py +245 -0
- molforge/rendering/native_labels.py +134 -0
- molforge/rendering/orbitals.py +139 -0
- molforge/rendering/vtk_backend.py +2294 -0
- molforge/runtime.py +29 -0
- molforge/server/__init__.py +1 -0
- molforge/server/api_bridge.py +947 -0
- molforge/ui/__init__.py +1 -0
- molforge/ui/assets/caffeine_2d.svg +150 -0
- molforge/ui/assets/caffeine_3d_preview.svg +209 -0
- molforge/ui/assets/caffeine_preview.json +302 -0
- molforge/ui/assets/icons/atom.svg +1 -0
- molforge/ui/assets/icons/bond.svg +1 -0
- molforge/ui/assets/icons/cleanup.svg +1 -0
- molforge/ui/assets/icons/export.svg +1 -0
- molforge/ui/assets/icons/fragments.svg +1 -0
- molforge/ui/assets/icons/history.svg +1 -0
- molforge/ui/assets/icons/jobs.svg +1 -0
- molforge/ui/assets/icons/measure.svg +1 -0
- molforge/ui/assets/icons/molecules.svg +1 -0
- molforge/ui/assets/icons/overview.svg +1 -0
- molforge/ui/assets/icons/ring.svg +1 -0
- molforge/ui/assets/icons/search.svg +1 -0
- molforge/ui/assets/icons/select.svg +1 -0
- molforge/ui/assets/icons/settings.svg +1 -0
- molforge/ui/assets/icons/templates.svg +1 -0
- molforge/ui/assets/molforge_logo.ico +0 -0
- molforge/ui/assets/molforge_logo.png +0 -0
- molforge/ui/atom_labels.py +92 -0
- molforge/ui/bio_structure_dialog.py +57 -0
- molforge/ui/conformer_dialog.py +151 -0
- molforge/ui/dialogs/__init__.py +2 -0
- molforge/ui/dialogs/aim_qtaim_dialog.py +533 -0
- molforge/ui/dialogs/calchem_orbitals_dialog.py +287 -0
- molforge/ui/dialogs/element_fragments.py +130 -0
- molforge/ui/dialogs/gaussian_calculation_setup.py +308 -0
- molforge/ui/dialogs/hpc_job_dialog.py +427 -0
- molforge/ui/dialogs/vibrational_spectrum_dialog.py +381 -0
- molforge/ui/editor2d_widget.py +1803 -0
- molforge/ui/element_picker.py +218 -0
- molforge/ui/gmv_window_manager.py +65 -0
- molforge/ui/gromacs_job_dialog.py +47 -0
- molforge/ui/hotkeys.py +107 -0
- molforge/ui/i18n.py +237 -0
- molforge/ui/live_llm_dialog.py +135 -0
- molforge/ui/llm_config_dialog.py +103 -0
- molforge/ui/modeling_actions.py +176 -0
- molforge/ui/molstar_widget.py +98 -0
- molforge/ui/molstar_window.py +85 -0
- molforge/ui/panels.py +2966 -0
- molforge/ui/qc_result_dialog.py +1924 -0
- molforge/ui/render3d_widget.py +1579 -0
- molforge/ui/scrolling.py +52 -0
- molforge/ui/settings_panel.py +330 -0
- molforge/ui/shells/__init__.py +4 -0
- molforge/ui/shells/base_shell.py +72 -0
- molforge/ui/shells/document_tabs.py +715 -0
- molforge/ui/shells/studio_2d.py +339 -0
- molforge/ui/shells/studio_3d.py +401 -0
- molforge/ui/shells/studio_split.py +370 -0
- molforge/ui/shells/workflow_inputs.py +698 -0
- molforge/ui/theme.py +719 -0
- molforge/ui/trajectory_window.py +333 -0
- molforge/ui/views.py +892 -0
- molforge/ui/vtk_multiview_widget.py +141 -0
- molforge/ui/welcome_window.py +223 -0
- molforge/ui/window.py +3320 -0
- molforge/workflows/__init__.py +25 -0
- molforge/workflows/assets/OSC_MD_workflows/templates/01-MD/delete_solvent.py +216 -0
- molforge/workflows/assets/OSC_MD_workflows/templates/02-RDF/extract_atoms.py +60 -0
- molforge/workflows/assets/OSC_MD_workflows/templates/02-RDF/extract_atoms_example.py +22 -0
- molforge/workflows/assets/OSC_MD_workflows/templates/03-/342/225/244/320/225/342/225/250/342/226/221/342/225/250/320/246/342/225/244/320/227/342/225/250/342/225/226/342/225/250/342/224/220/342/225/244/320/225/342/225/250/320/247/342/225/250/342/226/221/342/225/244/320/224/321/202/320/245/320/254/342/225/250/320/265/analysis_mol.py +244 -0
- molforge/workflows/assets/OSC_MD_workflows/templates/04-/342/225/244/320/224/321/202/320/245/320/241/342/225/250/320/254/342/225/244/320/227/321/202/320/245/320/247/321/202/320/244/320/264/342/225/244/320/225/342/225/250/342/224/220/342/225/250/320/246/342/225/244/320/225/321/202/320/245/320/241/342/225/250/342/225/242/rms_roughness.py +33 -0
- molforge/workflows/assets/OSC_MD_workflows/templates/04-/342/225/244/320/224/321/202/320/245/320/241/342/225/250/320/254/342/225/244/320/227/321/202/320/245/320/247/321/202/320/244/320/264/342/225/244/320/225/342/225/250/342/224/220/342/225/250/320/246/342/225/244/320/225/321/202/320/245/320/241/342/225/250/342/225/242/xpm_2.py +117 -0
- molforge/workflows/assets/OSC_MD_workflows/templates/09-/342/225/244/320/231/342/225/250/320/240/342/225/250/320/277/342/225/244/320/227/342/225/250/320/256/342/225/250/320/247/marcus_rate.py +60 -0
- molforge/workflows/assets/esp-surface-analysis/scripts/compute_descriptors.py +134 -0
- molforge/workflows/assets/esp-surface-analysis/scripts/parse_surfanalysis.py +58 -0
- molforge/workflows/assets/esp-surface-analysis/scripts/plot_esp_hist.py +115 -0
- molforge/workflows/assets/homo-lumo-plot/extract_orb_energy.py +57 -0
- molforge/workflows/assets/homo-lumo-plot/make_level_plot.py +76 -0
- molforge/workflows/assets/homo-lumo-plot/run_pipeline.py +84 -0
- molforge/workflows/assets/osc-energy-level-diagram/scripts/extract_levels.py +60 -0
- molforge/workflows/assets/osc-energy-level-diagram/scripts/make_editable_pptx.py +122 -0
- molforge/workflows/assets/osc-energy-level-diagram/scripts/make_energy_table.py +66 -0
- molforge/workflows/assets/osc-energy-level-diagram/scripts/make_level_lines_diagram.py +148 -0
- molforge/workflows/assets/osc-energy-level-diagram/scripts/make_rectangle_diagram.py +148 -0
- molforge/workflows/assets/osc-energy-level-diagram/scripts/verify_from_log.py +45 -0
- molforge/workflows/dipole_analysis.py +32 -0
- molforge/workflows/esp_surface.py +36 -0
- molforge/workflows/gromacs_submit.py +167 -0
- molforge/workflows/homo_lumo_plot.py +59 -0
- molforge/workflows/igmh_interaction.py +111 -0
- molforge/workflows/md_rdf_analysis.py +134 -0
- molforge/workflows/md_studio.py +255 -0
- molforge/workflows/osc_energy_diagram.py +24 -0
- molforge/workflows/planarity_analysis.py +66 -0
- molforge/workflows/reorganization_energy.py +166 -0
- molforge/workflows/scientific_workflows.py +650 -0
- molforge_studio-7.4.3.dist-info/METADATA +215 -0
- molforge_studio-7.4.3.dist-info/RECORD +219 -0
- molforge_studio-7.4.3.dist-info/WHEEL +5 -0
- molforge_studio-7.4.3.dist-info/entry_points.txt +3 -0
- molforge_studio-7.4.3.dist-info/licenses/LICENSE +93 -0
- molforge_studio-7.4.3.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ui/dialogs/hpc_job_dialog.py - Linux 超算集群作业生成、提交与监控一体化工作台
|
|
3
|
+
========================================================================
|
|
4
|
+
功能:
|
|
5
|
+
1. 多集群配置选择(支持远程 SSH 密钥连接与本地 WSL2 零配置仿真)
|
|
6
|
+
2. 自动生成 Gaussian 16 / ORCA 6 / GROMACS / xTB / CalChem 的计算输入与 Slurm 脚本
|
|
7
|
+
3. 一键通过 SSH/SCP 传输并提交至远程 Slurm/PBS 调度系统
|
|
8
|
+
4. 实时轮询 squeue 队列状态,一键将完成的结果日志拉回并加载进 3D 画布
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import os
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from typing import Any, Optional
|
|
16
|
+
from PyQt6.QtCore import Qt, QTimer
|
|
17
|
+
from PyQt6.QtWidgets import (
|
|
18
|
+
QDialog, QWidget, QVBoxLayout, QHBoxLayout, QFormLayout, QLabel,
|
|
19
|
+
QPushButton, QTableWidget, QTableWidgetItem, QHeaderView, QComboBox,
|
|
20
|
+
QSpinBox, QLineEdit, QPlainTextEdit, QTabWidget, QMessageBox, QFileDialog,
|
|
21
|
+
QProgressBar, QGroupBox
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
from ...domain.document import MoleculeDocument
|
|
25
|
+
from ...infrastructure.hpc.cluster_config import ClusterConfigManager, ClusterProfile
|
|
26
|
+
from ...infrastructure.hpc.slurm_generator import SlurmScriptGenerator, JobSpec
|
|
27
|
+
from ...infrastructure.hpc.remote_executor import RemoteHPCExecutor
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class HpcJobDialog(QDialog):
|
|
31
|
+
"""Linux HPC 超算作业提交与任务管理对话框。"""
|
|
32
|
+
|
|
33
|
+
def __init__(self, main_window, document: MoleculeDocument, parent=None):
|
|
34
|
+
super().__init__(parent or main_window)
|
|
35
|
+
self.main_window = main_window
|
|
36
|
+
self.document = document
|
|
37
|
+
self.config_mgr = ClusterConfigManager()
|
|
38
|
+
self.submitted_jobs: list[dict[str, Any]] = []
|
|
39
|
+
|
|
40
|
+
self.setWindowTitle(f"Linux 超算集群任务调度中心 - {document.name}")
|
|
41
|
+
self.resize(820, 620)
|
|
42
|
+
|
|
43
|
+
self._build_ui()
|
|
44
|
+
self._refresh_script_preview()
|
|
45
|
+
|
|
46
|
+
def _build_ui(self) -> None:
|
|
47
|
+
root = QVBoxLayout(self)
|
|
48
|
+
root.setContentsMargins(12, 12, 12, 12)
|
|
49
|
+
root.setSpacing(10)
|
|
50
|
+
|
|
51
|
+
self.tabs = QTabWidget()
|
|
52
|
+
self.tabs.addTab(self._build_submit_tab(), "🚀 1. 新建超算作业 (Submit New Job)")
|
|
53
|
+
self.tabs.addTab(self._build_monitor_tab(), "📋 2. 远程作业队列监控 (Job Monitor)")
|
|
54
|
+
self.tabs.addTab(self._build_cluster_tab(), "⚙️ 3. 集群主机配置 (Cluster Config)")
|
|
55
|
+
root.addWidget(self.tabs, 1)
|
|
56
|
+
|
|
57
|
+
bot = QHBoxLayout()
|
|
58
|
+
bot.addStretch()
|
|
59
|
+
close_btn = QPushButton("关闭")
|
|
60
|
+
close_btn.clicked.connect(self.accept)
|
|
61
|
+
bot.addWidget(close_btn)
|
|
62
|
+
root.addLayout(bot)
|
|
63
|
+
|
|
64
|
+
# ---------- Tab 1: Submit Job ----------
|
|
65
|
+
def _build_submit_tab(self) -> QWidget:
|
|
66
|
+
w = QWidget()
|
|
67
|
+
lay = QVBoxLayout(w)
|
|
68
|
+
|
|
69
|
+
top_grid = QHBoxLayout()
|
|
70
|
+
|
|
71
|
+
# 左侧:参数配置
|
|
72
|
+
left_box = QGroupBox("作业资源配置 (Slurm Directives)")
|
|
73
|
+
l_form = QFormLayout(left_box)
|
|
74
|
+
|
|
75
|
+
self.cluster_combo = QComboBox()
|
|
76
|
+
for name in self.config_mgr.profiles:
|
|
77
|
+
self.cluster_combo.addItem(name)
|
|
78
|
+
self.cluster_combo.currentIndexChanged.connect(self._refresh_script_preview)
|
|
79
|
+
l_form.addRow("目标超算主机:", self.cluster_combo)
|
|
80
|
+
|
|
81
|
+
self.engine_combo = QComboBox()
|
|
82
|
+
self.engine_combo.addItems([
|
|
83
|
+
"Gaussian 16 (DFT/ab initio)",
|
|
84
|
+
"ORCA 6 (DFT/DLPNO-CCSD(T))",
|
|
85
|
+
"xTB (半经验快速预优化)",
|
|
86
|
+
"REST (复旦大学 Rust 原生量子化学/双杂化)",
|
|
87
|
+
"GROMACS (分子动力学)",
|
|
88
|
+
"CalChem-CLI (纯 Rust 高性能内核)",
|
|
89
|
+
])
|
|
90
|
+
self.engine_combo.currentIndexChanged.connect(self._refresh_script_preview)
|
|
91
|
+
l_form.addRow("计算引擎 (Engine):", self.engine_combo)
|
|
92
|
+
|
|
93
|
+
self.job_name_edit = QLineEdit(f"{self.document.name}_calc")
|
|
94
|
+
self.job_name_edit.textChanged.connect(self._refresh_script_preview)
|
|
95
|
+
l_form.addRow("作业名称 (Name):", self.job_name_edit)
|
|
96
|
+
|
|
97
|
+
self.partition_edit = QLineEdit("compute")
|
|
98
|
+
self.partition_edit.textChanged.connect(self._refresh_script_preview)
|
|
99
|
+
l_form.addRow("队列分区 (Partition):", self.partition_edit)
|
|
100
|
+
|
|
101
|
+
self.cores_spin = QSpinBox()
|
|
102
|
+
self.cores_spin.setRange(1, 256)
|
|
103
|
+
self.cores_spin.setValue(16)
|
|
104
|
+
self.cores_spin.valueChanged.connect(self._refresh_script_preview)
|
|
105
|
+
l_form.addRow("计算核心 (Cores):", self.cores_spin)
|
|
106
|
+
|
|
107
|
+
self.mem_spin = QSpinBox()
|
|
108
|
+
self.mem_spin.setRange(1000, 512000)
|
|
109
|
+
self.mem_spin.setSingleStep(4000)
|
|
110
|
+
self.mem_spin.setValue(32000)
|
|
111
|
+
self.mem_spin.setSuffix(" MB")
|
|
112
|
+
self.mem_spin.valueChanged.connect(self._refresh_script_preview)
|
|
113
|
+
l_form.addRow("内存限额 (Memory):", self.mem_spin)
|
|
114
|
+
|
|
115
|
+
self.walltime_edit = QLineEdit("24:00:00")
|
|
116
|
+
self.walltime_edit.textChanged.connect(self._refresh_script_preview)
|
|
117
|
+
l_form.addRow("墙上时钟 (Walltime):", self.walltime_edit)
|
|
118
|
+
|
|
119
|
+
top_grid.addWidget(left_box, 1)
|
|
120
|
+
|
|
121
|
+
# 右侧:脚本实时预览
|
|
122
|
+
right_box = QGroupBox("生成的 slurm.sh 脚本预览")
|
|
123
|
+
r_lay = QVBoxLayout(right_box)
|
|
124
|
+
self.script_preview = QPlainTextEdit()
|
|
125
|
+
self.script_preview.setReadOnly(True)
|
|
126
|
+
self.script_preview.setStyleSheet("font-family: Consolas, monospace; font-size: 11px; background: #0E1A27; color: #66DEC9;")
|
|
127
|
+
r_lay.addWidget(self.script_preview)
|
|
128
|
+
top_grid.addWidget(right_box, 1)
|
|
129
|
+
|
|
130
|
+
lay.addLayout(top_grid, 1)
|
|
131
|
+
|
|
132
|
+
# 提交按钮区
|
|
133
|
+
btn_box = QHBoxLayout()
|
|
134
|
+
self.export_local_btn = QPushButton("💾 导出本地作业包 (Export Package)...")
|
|
135
|
+
self.export_local_btn.clicked.connect(self._on_export_local)
|
|
136
|
+
btn_box.addWidget(self.export_local_btn)
|
|
137
|
+
|
|
138
|
+
self.submit_btn = QPushButton("🚀 一键上传并提交至超算 (Submit to Slurm)")
|
|
139
|
+
self.submit_btn.setProperty("role", "action")
|
|
140
|
+
self.submit_btn.clicked.connect(self._on_submit_remote)
|
|
141
|
+
btn_box.addWidget(self.submit_btn)
|
|
142
|
+
btn_box.addStretch()
|
|
143
|
+
lay.addLayout(btn_box)
|
|
144
|
+
|
|
145
|
+
return w
|
|
146
|
+
|
|
147
|
+
# ---------- Tab 2: Job Monitor ----------
|
|
148
|
+
def _build_monitor_tab(self) -> QWidget:
|
|
149
|
+
w = QWidget()
|
|
150
|
+
lay = QVBoxLayout(w)
|
|
151
|
+
|
|
152
|
+
top_bar = QHBoxLayout()
|
|
153
|
+
self.refresh_queue_btn = QPushButton("🔄 刷新队列状态 (squeue)")
|
|
154
|
+
self.refresh_queue_btn.clicked.connect(self._on_refresh_queue)
|
|
155
|
+
top_bar.addWidget(self.refresh_queue_btn)
|
|
156
|
+
|
|
157
|
+
self.download_log_btn = QPushButton("📥 拉回结果日志 (Download Logs)")
|
|
158
|
+
self.download_log_btn.clicked.connect(self._on_download_logs)
|
|
159
|
+
top_bar.addWidget(self.download_log_btn)
|
|
160
|
+
top_bar.addStretch()
|
|
161
|
+
lay.addLayout(top_bar)
|
|
162
|
+
|
|
163
|
+
self.job_table = QTableWidget()
|
|
164
|
+
self.job_table.setColumnCount(6)
|
|
165
|
+
self.job_table.setHorizontalHeaderLabels([
|
|
166
|
+
"作业编号 (Job ID)", "作业名称", "目标集群", "调度状态", "执行节点/耗时", "提交时间"
|
|
167
|
+
])
|
|
168
|
+
self.job_table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch)
|
|
169
|
+
self.job_table.setSelectionBehavior(QTableWidget.SelectionBehavior.SelectRows)
|
|
170
|
+
lay.addWidget(self.job_table, 1)
|
|
171
|
+
|
|
172
|
+
return w
|
|
173
|
+
|
|
174
|
+
# ---------- Tab 3: Cluster Config ----------
|
|
175
|
+
def _build_cluster_tab(self) -> QWidget:
|
|
176
|
+
w = QWidget()
|
|
177
|
+
lay = QVBoxLayout(w)
|
|
178
|
+
lay.addWidget(QLabel("已保存的主机与超算节点:"))
|
|
179
|
+
self.cluster_list = QPlainTextEdit()
|
|
180
|
+
self.cluster_list.setPlainText(json.dumps(
|
|
181
|
+
{name: p.to_dict() for name, p in self.config_mgr.profiles.items()},
|
|
182
|
+
indent=2, ensure_ascii=False
|
|
183
|
+
))
|
|
184
|
+
lay.addWidget(self.cluster_list, 1)
|
|
185
|
+
save_cfg_btn = QPushButton("保存集群配置修改")
|
|
186
|
+
save_cfg_btn.clicked.connect(self._on_save_cluster_json)
|
|
187
|
+
lay.addWidget(save_cfg_btn)
|
|
188
|
+
return w
|
|
189
|
+
|
|
190
|
+
def _get_current_job_spec_and_profile(self) -> tuple[JobSpec, ClusterProfile]:
|
|
191
|
+
prof_name = self.cluster_combo.currentText()
|
|
192
|
+
prof = self.config_mgr.get(prof_name) or ClusterProfile()
|
|
193
|
+
|
|
194
|
+
eng_raw = self.engine_combo.currentText().lower()
|
|
195
|
+
if "gaussian" in eng_raw:
|
|
196
|
+
eng = "g16"
|
|
197
|
+
in_file = f"{self.job_name_edit.text()}.gjf"
|
|
198
|
+
out_file = f"{self.job_name_edit.text()}.log"
|
|
199
|
+
elif "orca" in eng_raw:
|
|
200
|
+
eng = "orca"
|
|
201
|
+
in_file = f"{self.job_name_edit.text()}.inp"
|
|
202
|
+
out_file = f"{self.job_name_edit.text()}.out"
|
|
203
|
+
elif "gromacs" in eng_raw:
|
|
204
|
+
eng = "gromacs"
|
|
205
|
+
in_file = f"{self.job_name_edit.text()}.tpr"
|
|
206
|
+
out_file = f"{self.job_name_edit.text()}.log"
|
|
207
|
+
elif "xtb" in eng_raw:
|
|
208
|
+
eng = "xtb"
|
|
209
|
+
in_file = f"{self.job_name_edit.text()}.xyz"
|
|
210
|
+
out_file = f"{self.job_name_edit.text()}.log"
|
|
211
|
+
elif "rest" in eng_raw:
|
|
212
|
+
eng = "rest"
|
|
213
|
+
in_file = f"{self.job_name_edit.text()}.toml"
|
|
214
|
+
out_file = f"{self.job_name_edit.text()}.log"
|
|
215
|
+
else:
|
|
216
|
+
eng = "calchem"
|
|
217
|
+
in_file = f"{self.job_name_edit.text()}.json"
|
|
218
|
+
out_file = f"{self.job_name_edit.text()}.out"
|
|
219
|
+
|
|
220
|
+
job = JobSpec(
|
|
221
|
+
job_name=self.job_name_edit.text(),
|
|
222
|
+
engine=eng,
|
|
223
|
+
input_file=in_file,
|
|
224
|
+
output_file=out_file,
|
|
225
|
+
n_cores=int(self.cores_spin.value()),
|
|
226
|
+
memory_mb=int(self.mem_spin.value()),
|
|
227
|
+
walltime=self.walltime_edit.text().strip(),
|
|
228
|
+
partition=self.partition_edit.text().strip(),
|
|
229
|
+
)
|
|
230
|
+
return job, prof
|
|
231
|
+
|
|
232
|
+
def _refresh_script_preview(self) -> None:
|
|
233
|
+
try:
|
|
234
|
+
job, prof = self._get_current_job_spec_and_profile()
|
|
235
|
+
script = SlurmScriptGenerator.generate(job, prof)
|
|
236
|
+
self.script_preview.setPlainText(script)
|
|
237
|
+
except Exception:
|
|
238
|
+
pass
|
|
239
|
+
|
|
240
|
+
def _generate_job_input_file(self, job: JobSpec, target_path: Path) -> None:
|
|
241
|
+
"""根据计算引擎与当前 MoleculeDocument 生成规范的真实计算输入文件。"""
|
|
242
|
+
doc = self.document
|
|
243
|
+
target_path.parent.mkdir(parents=True, exist_ok=True)
|
|
244
|
+
if job.engine == "g16":
|
|
245
|
+
from ...application.calculators.gaussian_job_spec import GaussianJobSpec
|
|
246
|
+
spec = GaussianJobSpec.default_spec(doc)
|
|
247
|
+
spec.job_type = "Opt+Freq"
|
|
248
|
+
spec.nproc_shared = max(1, job.n_cores)
|
|
249
|
+
spec.memory_gb = max(1, job.memory_mb // 1024)
|
|
250
|
+
spec.chk_filename = f"{job.job_name}.chk"
|
|
251
|
+
content = spec.generate_gjf(doc, allow_sample_placeholder=False)
|
|
252
|
+
target_path.write_text(content, encoding="utf-8")
|
|
253
|
+
elif job.engine == "orca":
|
|
254
|
+
from ...application.calculators.qc_input_generator import extract_xyz_lines
|
|
255
|
+
xyz_lines = extract_xyz_lines(doc)
|
|
256
|
+
maxcore = max(1000, job.memory_mb // max(1, job.n_cores))
|
|
257
|
+
charge = int(doc.properties.get("charge", 0))
|
|
258
|
+
z_sum = sum(doc.topology.get_atom(aid).atomic_num for aid in doc.topology.atom_ids)
|
|
259
|
+
mult = 1 if ((z_sum - charge) % 2 == 0) else 2
|
|
260
|
+
lines = [
|
|
261
|
+
f"# ORCA 6 Input generated by MolForge for {doc.name}",
|
|
262
|
+
"! B3LYP D3BJ def2-SVP TightSCF Opt",
|
|
263
|
+
f"%pal nprocs {job.n_cores} end",
|
|
264
|
+
f"%maxcore {maxcore}",
|
|
265
|
+
"",
|
|
266
|
+
f"* xyz {charge} {mult}",
|
|
267
|
+
]
|
|
268
|
+
lines.extend(xyz_lines)
|
|
269
|
+
lines.append("*")
|
|
270
|
+
target_path.write_text("\n".join(lines) + "\n", encoding="utf-8")
|
|
271
|
+
elif job.engine == "xtb":
|
|
272
|
+
from ...application.calculators.qc_input_generator import export_document_to_xyz
|
|
273
|
+
export_document_to_xyz(doc, str(target_path))
|
|
274
|
+
elif job.engine == "rest":
|
|
275
|
+
from ...application.calculators.qc_input_generator import generate_rest_ctrl_in
|
|
276
|
+
charge = float(doc.properties.get("charge", 0.0))
|
|
277
|
+
toml_text = generate_rest_ctrl_in(
|
|
278
|
+
doc,
|
|
279
|
+
xc="b3lyp",
|
|
280
|
+
basis="def2-SVP",
|
|
281
|
+
auxbas="def2-universal-jkfit",
|
|
282
|
+
charge=charge,
|
|
283
|
+
num_threads=max(2, job.n_cores),
|
|
284
|
+
basis_pool="/mnt/e/YDW/REST/knowledge_base/rest_github/basis-set-pool",
|
|
285
|
+
)
|
|
286
|
+
target_path.write_text(toml_text, encoding="utf-8")
|
|
287
|
+
elif job.engine == "calchem":
|
|
288
|
+
import json
|
|
289
|
+
atom_data = []
|
|
290
|
+
coords = doc.coordinates.current.coords if (doc.has_3d and doc.coordinates.current is not None) else None
|
|
291
|
+
idx_to_id, _ = doc.topology.atom_index_map()
|
|
292
|
+
for i, aid in enumerate(idx_to_id):
|
|
293
|
+
atom = doc.topology.get_atom(aid)
|
|
294
|
+
c = coords[i].tolist() if coords is not None and i < len(coords) else [0.0, 0.0, 0.0]
|
|
295
|
+
atom_data.append({"atomic_number": atom.atomic_num, "xyz": c})
|
|
296
|
+
charge = int(doc.properties.get("charge", 0))
|
|
297
|
+
payload = {
|
|
298
|
+
"name": job.job_name,
|
|
299
|
+
"method": "RHF",
|
|
300
|
+
"basis": "sto-3g",
|
|
301
|
+
"charge": charge,
|
|
302
|
+
"atoms": atom_data,
|
|
303
|
+
}
|
|
304
|
+
target_path.write_text(json.dumps(payload, indent=2, ensure_ascii=False), encoding="utf-8")
|
|
305
|
+
elif job.engine == "gromacs":
|
|
306
|
+
from ...ui.shells.workflow_inputs import export_document_to_xyz
|
|
307
|
+
export_document_to_xyz(doc, str(target_path.with_suffix(".xyz")))
|
|
308
|
+
target_path.write_text(f"; GROMACS job placeholder for {doc.name}\n", encoding="utf-8")
|
|
309
|
+
else:
|
|
310
|
+
target_path.write_text(f"# Generic input for {job.engine}\n", encoding="utf-8")
|
|
311
|
+
|
|
312
|
+
def _on_export_local(self) -> None:
|
|
313
|
+
dir_path = QFileDialog.getExistingDirectory(self, "选择本地作业导出目录")
|
|
314
|
+
if not dir_path:
|
|
315
|
+
return
|
|
316
|
+
dest = Path(dir_path) / self.job_name_edit.text()
|
|
317
|
+
dest.mkdir(parents=True, exist_ok=True)
|
|
318
|
+
job, prof = self._get_current_job_spec_and_profile()
|
|
319
|
+
script = SlurmScriptGenerator.generate(job, prof)
|
|
320
|
+
|
|
321
|
+
# 写 slurm.sh
|
|
322
|
+
with open(dest / "slurm.sh", "w", encoding="utf-8") as f:
|
|
323
|
+
f.write(script)
|
|
324
|
+
|
|
325
|
+
# 写规范真实计算输入文件
|
|
326
|
+
self._generate_job_input_file(job, dest / job.input_file)
|
|
327
|
+
|
|
328
|
+
QMessageBox.information(self, "导出成功", f"作业包已完整生成至:\n{dest}")
|
|
329
|
+
|
|
330
|
+
def _on_submit_remote(self) -> None:
|
|
331
|
+
job, prof = self._get_current_job_spec_and_profile()
|
|
332
|
+
from ...runtime import data_dir
|
|
333
|
+
tmp_pkg = data_dir() / "temp" / f"hpc_{job.job_name}"
|
|
334
|
+
tmp_pkg.mkdir(parents=True, exist_ok=True)
|
|
335
|
+
|
|
336
|
+
script = SlurmScriptGenerator.generate(job, prof)
|
|
337
|
+
script_file = tmp_pkg / "slurm.sh"
|
|
338
|
+
with open(script_file, "w", encoding="utf-8") as f:
|
|
339
|
+
f.write(script)
|
|
340
|
+
|
|
341
|
+
input_path = tmp_pkg / job.input_file
|
|
342
|
+
self._generate_job_input_file(job, input_path)
|
|
343
|
+
|
|
344
|
+
executor = RemoteHPCExecutor(prof)
|
|
345
|
+
remote_job_dir = f"{prof.remote_workdir}/{job.job_name}"
|
|
346
|
+
|
|
347
|
+
# 1. 上传文件
|
|
348
|
+
ok_up = executor.upload_files([script_file, input_path], remote_job_dir)
|
|
349
|
+
if not ok_up:
|
|
350
|
+
QMessageBox.warning(self, "上传失败", f"无法连接或上传至 {prof.hostname}:{remote_job_dir}")
|
|
351
|
+
return
|
|
352
|
+
|
|
353
|
+
# 2. 提交作业
|
|
354
|
+
ok_sub, msg = executor.submit_job(remote_job_dir, "slurm.sh")
|
|
355
|
+
if not ok_sub:
|
|
356
|
+
QMessageBox.warning(self, "提交失败", msg)
|
|
357
|
+
return
|
|
358
|
+
|
|
359
|
+
import datetime
|
|
360
|
+
job_info = {
|
|
361
|
+
"id": msg,
|
|
362
|
+
"name": job.job_name,
|
|
363
|
+
"cluster": prof.name,
|
|
364
|
+
"status": "PENDING",
|
|
365
|
+
"info": "刚刚提交",
|
|
366
|
+
"time": datetime.datetime.now().strftime("%H:%M:%S"),
|
|
367
|
+
"remote_dir": remote_job_dir,
|
|
368
|
+
"output_file": job.output_file,
|
|
369
|
+
"profile": prof,
|
|
370
|
+
}
|
|
371
|
+
self.submitted_jobs.append(job_info)
|
|
372
|
+
self._append_job_to_table(job_info)
|
|
373
|
+
self.tabs.setCurrentIndex(1)
|
|
374
|
+
QMessageBox.information(self, "提交成功", f"作业已成功提交至集群!\nJob ID: {msg}")
|
|
375
|
+
|
|
376
|
+
def _append_job_to_table(self, job_info: dict[str, Any]) -> None:
|
|
377
|
+
r = self.job_table.rowCount()
|
|
378
|
+
self.job_table.insertRow(r)
|
|
379
|
+
self.job_table.setItem(r, 0, QTableWidgetItem(str(job_info["id"])))
|
|
380
|
+
self.job_table.setItem(r, 1, QTableWidgetItem(job_info["name"]))
|
|
381
|
+
self.job_table.setItem(r, 2, QTableWidgetItem(job_info["cluster"]))
|
|
382
|
+
self.job_table.setItem(r, 3, QTableWidgetItem(job_info["status"]))
|
|
383
|
+
self.job_table.setItem(r, 4, QTableWidgetItem(job_info["info"]))
|
|
384
|
+
self.job_table.setItem(r, 5, QTableWidgetItem(job_info["time"]))
|
|
385
|
+
|
|
386
|
+
def _on_refresh_queue(self) -> None:
|
|
387
|
+
for i, j in enumerate(self.submitted_jobs):
|
|
388
|
+
executor = RemoteHPCExecutor(j["profile"])
|
|
389
|
+
st = executor.query_job(j["id"])
|
|
390
|
+
j["status"] = st.status
|
|
391
|
+
j["info"] = f"{st.node} {st.elapsed}".strip()
|
|
392
|
+
self.job_table.setItem(i, 3, QTableWidgetItem(st.status))
|
|
393
|
+
self.job_table.setItem(i, 4, QTableWidgetItem(j["info"]))
|
|
394
|
+
|
|
395
|
+
def _on_download_logs(self) -> None:
|
|
396
|
+
sel = self.job_table.selectionModel().selectedRows()
|
|
397
|
+
if not sel:
|
|
398
|
+
return
|
|
399
|
+
r = sel[0].row()
|
|
400
|
+
j = self.submitted_jobs[r]
|
|
401
|
+
executor = RemoteHPCExecutor(j["profile"])
|
|
402
|
+
from ...runtime import data_dir
|
|
403
|
+
dest = data_dir() / "temp" / f"dl_{j['output_file']}"
|
|
404
|
+
rem_file = f"{j['remote_dir']}/{j['output_file']}"
|
|
405
|
+
ok = executor.download_file(rem_file, dest)
|
|
406
|
+
if ok and dest.exists():
|
|
407
|
+
QMessageBox.information(self, "下载完成", f"结果文件已拉回本地:\n{dest}")
|
|
408
|
+
if hasattr(self.main_window, "_open_file_path"):
|
|
409
|
+
self.main_window._open_file_path(str(dest))
|
|
410
|
+
elif hasattr(self.main_window, "_open_qc_log"):
|
|
411
|
+
self.main_window._open_qc_log()
|
|
412
|
+
else:
|
|
413
|
+
QMessageBox.warning(self, "下载失败", f"未能从远程拉回 {rem_file},可能作业仍在运行。")
|
|
414
|
+
|
|
415
|
+
def _on_save_cluster_json(self) -> None:
|
|
416
|
+
try:
|
|
417
|
+
data = json.loads(self.cluster_list.toPlainText())
|
|
418
|
+
self.config_mgr.profiles = {
|
|
419
|
+
name: ClusterProfile.from_dict(prof) for name, prof in data.items()
|
|
420
|
+
}
|
|
421
|
+
self.config_mgr.save()
|
|
422
|
+
self.cluster_combo.clear()
|
|
423
|
+
for name in self.config_mgr.profiles:
|
|
424
|
+
self.cluster_combo.addItem(name)
|
|
425
|
+
QMessageBox.information(self, "保存成功", "集群配置已持久化!")
|
|
426
|
+
except Exception as e:
|
|
427
|
+
QMessageBox.warning(self, "格式错误", f"JSON 格式无效: {e}")
|