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,381 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ui/dialogs/vibrational_spectrum_dialog.py - 红外光谱 (IR) 与 3D 简正振动模式动画交互工作台
|
|
3
|
+
========================================================================================
|
|
4
|
+
功能:
|
|
5
|
+
1. 洛伦兹展宽 (Lorentzian Broadening) 绘制出版级红外 (IR) 吸收谱图(支持点击吸收峰)
|
|
6
|
+
2. 完整的简正振动模式列表(波数 cm^-1、红外强度 km/mol)
|
|
7
|
+
3. 视口 3D 实时正弦谐振动画:r_i(t) = r_0 + A * v_mode * sin(omega * t)
|
|
8
|
+
4. 支持播放/暂停、振幅与速度实时调节,关闭时平稳复原真实分子几何
|
|
9
|
+
5. 支持一键加载外部 Gaussian / ORCA / xTB 频率计算日志
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import math
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Any, List, Optional
|
|
17
|
+
import numpy as np
|
|
18
|
+
|
|
19
|
+
from PyQt6.QtCore import Qt, QTimer, QRectF, QPointF
|
|
20
|
+
from PyQt6.QtWidgets import (
|
|
21
|
+
QDialog, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton,
|
|
22
|
+
QTableWidget, QTableWidgetItem, QHeaderView, QSlider, QDoubleSpinBox,
|
|
23
|
+
QFileDialog, QMessageBox, QFrame, QSplitter
|
|
24
|
+
)
|
|
25
|
+
from PyQt6.QtGui import QPainter, QPen, QBrush, QColor, QFont
|
|
26
|
+
|
|
27
|
+
from ...domain.document import MoleculeDocument
|
|
28
|
+
from ...io.cclib_adapter import CCLibAdapter, QuantumResult
|
|
29
|
+
from ...io.calculators import compute_harmonic_vibrational_modes
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class IRSpectrumCanvas(QWidget):
|
|
33
|
+
"""红外吸收光谱 (IR Spectrum) 交互式渲染画布。"""
|
|
34
|
+
|
|
35
|
+
def __init__(self, parent=None):
|
|
36
|
+
super().__init__(parent)
|
|
37
|
+
self.setMinimumHeight(220)
|
|
38
|
+
self.frequencies: list[float] = []
|
|
39
|
+
self.intensities: list[float] = []
|
|
40
|
+
self.selected_idx: int = -1
|
|
41
|
+
self.gamma: float = 12.0 # 洛伦兹半高宽 (cm^-1)
|
|
42
|
+
self.on_peak_selected = None
|
|
43
|
+
|
|
44
|
+
def set_spectrum(self, freqs: list[float], intensities: list[float], selected_idx: int = -1):
|
|
45
|
+
self.frequencies = freqs
|
|
46
|
+
self.intensities = intensities
|
|
47
|
+
self.selected_idx = selected_idx
|
|
48
|
+
self.update()
|
|
49
|
+
|
|
50
|
+
def select_mode(self, idx: int):
|
|
51
|
+
self.selected_idx = idx
|
|
52
|
+
self.update()
|
|
53
|
+
|
|
54
|
+
def paintEvent(self, event):
|
|
55
|
+
p = QPainter(self)
|
|
56
|
+
p.setRenderHint(QPainter.RenderHint.Antialiasing)
|
|
57
|
+
p.setRenderHint(QPainter.RenderHint.TextAntialiasing)
|
|
58
|
+
|
|
59
|
+
w, h = float(self.width()), float(self.height())
|
|
60
|
+
p.fillRect(QRectF(0, 0, w, h), QColor("#0E1A27"))
|
|
61
|
+
|
|
62
|
+
if not self.frequencies:
|
|
63
|
+
p.setPen(QColor("#8BA0B2"))
|
|
64
|
+
p.drawText(QRectF(0, 0, w, h), Qt.AlignmentFlag.AlignCenter, "未检测到振动频率数据 (可加载外部量化计算日志)")
|
|
65
|
+
p.end()
|
|
66
|
+
return
|
|
67
|
+
|
|
68
|
+
left_pad, right_pad, top_pad, bot_pad = 55.0, 25.0, 25.0, 35.0
|
|
69
|
+
plot_w = max(50.0, w - left_pad - right_pad)
|
|
70
|
+
plot_h = max(50.0, h - top_pad - bot_pad)
|
|
71
|
+
|
|
72
|
+
# 红外习惯:从高波数到低波数 (4000 -> 400 cm^-1)
|
|
73
|
+
wn_min, wn_max = 400.0, 4000.0
|
|
74
|
+
if self.frequencies:
|
|
75
|
+
wn_min = max(200.0, min(self.frequencies) - 150.0)
|
|
76
|
+
wn_max = min(4200.0, max(self.frequencies) + 200.0)
|
|
77
|
+
|
|
78
|
+
# 洛伦兹展宽拟合曲线
|
|
79
|
+
n_pts = 400
|
|
80
|
+
x_grid = np.linspace(wn_max, wn_min, n_pts)
|
|
81
|
+
y_curve = np.zeros(n_pts, dtype=float)
|
|
82
|
+
g2 = (self.gamma / 2.0) ** 2
|
|
83
|
+
|
|
84
|
+
max_inten = max(1.0, max(self.intensities)) if self.intensities else 1.0
|
|
85
|
+
for nu, inten in zip(self.frequencies, self.intensities):
|
|
86
|
+
# L(x) = I * (gamma/2)^2 / ((x - nu)^2 + (gamma/2)^2)
|
|
87
|
+
y_curve += inten * g2 / ((x_grid - nu) ** 2 + g2)
|
|
88
|
+
|
|
89
|
+
peak_y = max(1.0, float(np.max(y_curve)))
|
|
90
|
+
|
|
91
|
+
def wn_to_x(wn: float) -> float:
|
|
92
|
+
return left_pad + (wn_max - wn) / (wn_max - wn_min) * plot_w
|
|
93
|
+
|
|
94
|
+
def val_to_y(val: float) -> float:
|
|
95
|
+
return top_pad + plot_h - (val / peak_y) * plot_h
|
|
96
|
+
|
|
97
|
+
# 绘制网格与刻度
|
|
98
|
+
p.setFont(QFont("Segoe UI", 9))
|
|
99
|
+
p.setPen(QPen(QColor("#1E3246"), 1, Qt.PenStyle.DashLine))
|
|
100
|
+
for wn_tick in (4000, 3500, 3000, 2500, 2000, 1500, 1000, 500):
|
|
101
|
+
if wn_min <= wn_tick <= wn_max:
|
|
102
|
+
x = wn_to_x(wn_tick)
|
|
103
|
+
p.drawLine(QPointF(x, top_pad), QPointF(x, top_pad + plot_h))
|
|
104
|
+
p.setPen(QColor("#8BA0B2"))
|
|
105
|
+
p.drawText(QRectF(x - 25, top_pad + plot_h + 6, 50, 18), Qt.AlignmentFlag.AlignCenter, f"{wn_tick}")
|
|
106
|
+
p.setPen(QPen(QColor("#1E3246"), 1, Qt.PenStyle.DashLine))
|
|
107
|
+
|
|
108
|
+
p.setPen(QPen(QColor("#8BA0B2"), 1.2))
|
|
109
|
+
p.drawLine(QPointF(left_pad, top_pad + plot_h), QPointF(left_pad + plot_w, top_pad + plot_h))
|
|
110
|
+
p.drawLine(QPointF(left_pad, top_pad), QPointF(left_pad, top_pad + plot_h))
|
|
111
|
+
|
|
112
|
+
# 绘制吸收曲线
|
|
113
|
+
p.setPen(QPen(QColor("#66DEC9"), 2.2))
|
|
114
|
+
pts: list[QPointF] = []
|
|
115
|
+
for i in range(n_pts):
|
|
116
|
+
pts.append(QPointF(wn_to_x(x_grid[i]), val_to_y(y_curve[i])))
|
|
117
|
+
p.drawPolyline(pts)
|
|
118
|
+
|
|
119
|
+
# 绘制简正峰棒状标记
|
|
120
|
+
for idx, (nu, inten) in enumerate(zip(self.frequencies, self.intensities)):
|
|
121
|
+
is_sel = (idx == self.selected_idx)
|
|
122
|
+
x = wn_to_x(nu)
|
|
123
|
+
y_top = val_to_y(inten)
|
|
124
|
+
y_base = top_pad + plot_h
|
|
125
|
+
col = QColor("#FBBF24" if is_sel else "#F87171")
|
|
126
|
+
width = 3.0 if is_sel else 1.2
|
|
127
|
+
p.setPen(QPen(col, width))
|
|
128
|
+
p.drawLine(QPointF(x, y_base), QPointF(x, y_top))
|
|
129
|
+
if is_sel:
|
|
130
|
+
p.setBrush(QBrush(col))
|
|
131
|
+
p.drawEllipse(QPointF(x, y_top), 4.5, 4.5)
|
|
132
|
+
p.drawText(QRectF(x - 30, y_top - 20, 60, 16), Qt.AlignmentFlag.AlignCenter, f"{nu:.1f}")
|
|
133
|
+
|
|
134
|
+
# 坐标轴标签
|
|
135
|
+
p.setPen(QColor("#E2E8F0"))
|
|
136
|
+
p.drawText(QRectF(left_pad, h - 22, plot_w, 20), Qt.AlignmentFlag.AlignCenter, "波数 Wavenumber (cm⁻¹)")
|
|
137
|
+
p.end()
|
|
138
|
+
|
|
139
|
+
def mousePressEvent(self, event):
|
|
140
|
+
if not self.frequencies:
|
|
141
|
+
return
|
|
142
|
+
w = float(self.width())
|
|
143
|
+
left_pad, right_pad = 55.0, 25.0
|
|
144
|
+
plot_w = max(50.0, w - left_pad - right_pad)
|
|
145
|
+
wn_min = max(200.0, min(self.frequencies) - 150.0)
|
|
146
|
+
wn_max = min(4200.0, max(self.frequencies) + 200.0)
|
|
147
|
+
|
|
148
|
+
click_x = event.position().x()
|
|
149
|
+
if left_pad <= click_x <= left_pad + plot_w:
|
|
150
|
+
click_wn = wn_max - (click_x - left_pad) / plot_w * (wn_max - wn_min)
|
|
151
|
+
# 找到最接近的峰
|
|
152
|
+
diffs = [abs(f - click_wn) for f in self.frequencies]
|
|
153
|
+
best_idx = int(np.argmin(diffs))
|
|
154
|
+
if diffs[best_idx] < 80.0:
|
|
155
|
+
self.selected_idx = best_idx
|
|
156
|
+
self.update()
|
|
157
|
+
if self.on_peak_selected:
|
|
158
|
+
self.on_peak_selected(best_idx)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
class VibrationalSpectrumDialog(QDialog):
|
|
162
|
+
"""简正振动光谱与 3D 视口振动动画交互工作台。"""
|
|
163
|
+
|
|
164
|
+
def __init__(self, main_window, document: MoleculeDocument, parent=None):
|
|
165
|
+
super().__init__(parent or main_window)
|
|
166
|
+
self.main_window = main_window
|
|
167
|
+
self.document = document
|
|
168
|
+
self.initial_coords: np.ndarray = document.coordinates.current.coords.copy() if document.has_3d else None
|
|
169
|
+
|
|
170
|
+
self.frequencies: list[float] = []
|
|
171
|
+
self.intensities: list[float] = []
|
|
172
|
+
self.labels: list[str] = []
|
|
173
|
+
self.displacements: Optional[np.ndarray] = None # shape (n_modes, n_atoms, 3)
|
|
174
|
+
|
|
175
|
+
# 动画计时器
|
|
176
|
+
self.timer = QTimer(self)
|
|
177
|
+
self.timer.setInterval(28) # ~35 FPS
|
|
178
|
+
self.timer.timeout.connect(self._on_animation_step)
|
|
179
|
+
self.anim_t: float = 0.0
|
|
180
|
+
self.is_playing: bool = False
|
|
181
|
+
self.current_mode: int = -1
|
|
182
|
+
|
|
183
|
+
self.setWindowTitle(f"红外振动光谱与模式动画 - {document.name}")
|
|
184
|
+
self.resize(840, 640)
|
|
185
|
+
|
|
186
|
+
self._build_ui()
|
|
187
|
+
self._load_default_or_calc_modes()
|
|
188
|
+
|
|
189
|
+
def _build_ui(self) -> None:
|
|
190
|
+
root = QVBoxLayout(self)
|
|
191
|
+
root.setContentsMargins(12, 12, 12, 12)
|
|
192
|
+
root.setSpacing(10)
|
|
193
|
+
|
|
194
|
+
# 光谱画布
|
|
195
|
+
self.canvas = IRSpectrumCanvas(self)
|
|
196
|
+
self.canvas.on_peak_selected = self._on_peak_selected_from_canvas
|
|
197
|
+
root.addWidget(self.canvas, 2)
|
|
198
|
+
|
|
199
|
+
# 动画控制器条
|
|
200
|
+
ctrl_box = QFrame()
|
|
201
|
+
ctrl_box.setStyleSheet("background-color: #121E2B; border-radius: 6px; padding: 6px;")
|
|
202
|
+
c_lay = QHBoxLayout(ctrl_box)
|
|
203
|
+
|
|
204
|
+
self.play_btn = QPushButton("▶ 播放振动动画")
|
|
205
|
+
self.play_btn.setProperty("role", "action")
|
|
206
|
+
self.play_btn.clicked.connect(self._toggle_play)
|
|
207
|
+
c_lay.addWidget(self.play_btn)
|
|
208
|
+
|
|
209
|
+
c_lay.addSpacing(16)
|
|
210
|
+
c_lay.addWidget(QLabel("振幅 (Amplitude):"))
|
|
211
|
+
self.amp_slider = QSlider(Qt.Orientation.Horizontal)
|
|
212
|
+
self.amp_slider.setRange(10, 200)
|
|
213
|
+
self.amp_slider.setValue(60)
|
|
214
|
+
self.amp_slider.setFixedWidth(130)
|
|
215
|
+
c_lay.addWidget(self.amp_slider)
|
|
216
|
+
|
|
217
|
+
c_lay.addSpacing(16)
|
|
218
|
+
c_lay.addWidget(QLabel("振动频率 (Speed):"))
|
|
219
|
+
self.speed_slider = QSlider(Qt.Orientation.Horizontal)
|
|
220
|
+
self.speed_slider.setRange(10, 100)
|
|
221
|
+
self.speed_slider.setValue(40)
|
|
222
|
+
self.speed_slider.setFixedWidth(130)
|
|
223
|
+
c_lay.addWidget(self.speed_slider)
|
|
224
|
+
|
|
225
|
+
c_lay.addStretch()
|
|
226
|
+
load_log_btn = QPushButton("📁 加载量化计算日志 (Gaussian/ORCA/xTB)...")
|
|
227
|
+
load_log_btn.clicked.connect(self._on_load_external_log)
|
|
228
|
+
c_lay.addWidget(load_log_btn)
|
|
229
|
+
root.addWidget(ctrl_box)
|
|
230
|
+
|
|
231
|
+
# 振动模式数据表格
|
|
232
|
+
self.table = QTableWidget()
|
|
233
|
+
self.table.setColumnCount(4)
|
|
234
|
+
self.table.setHorizontalHeaderLabels([
|
|
235
|
+
"模式 #", "波数 (cm⁻¹)", "红外强度 (km/mol)", "振动运动特征 / 跃迁描述"
|
|
236
|
+
])
|
|
237
|
+
self.table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch)
|
|
238
|
+
self.table.setSelectionBehavior(QTableWidget.SelectionBehavior.SelectRows)
|
|
239
|
+
self.table.setSelectionMode(QTableWidget.SelectionMode.SingleSelection)
|
|
240
|
+
self.table.itemSelectionChanged.connect(self._on_table_row_selected)
|
|
241
|
+
root.addWidget(self.table, 3)
|
|
242
|
+
|
|
243
|
+
# 底部
|
|
244
|
+
bot = QHBoxLayout()
|
|
245
|
+
bot.addStretch()
|
|
246
|
+
close_btn = QPushButton("关闭并复原分子")
|
|
247
|
+
close_btn.clicked.connect(self._on_close)
|
|
248
|
+
bot.addWidget(close_btn)
|
|
249
|
+
root.addLayout(bot)
|
|
250
|
+
|
|
251
|
+
def _load_default_or_calc_modes(self) -> None:
|
|
252
|
+
"""若无量化日志,自动按拓扑特征振动模型求解特征红外光谱。"""
|
|
253
|
+
modes = compute_harmonic_vibrational_modes(self.document)
|
|
254
|
+
self.frequencies = [m["frequency_cm1"] for m in modes]
|
|
255
|
+
self.intensities = [m["intensity_km_mol"] for m in modes]
|
|
256
|
+
self.labels = [m.get("label", "分子简正伸缩/弯曲模式") for m in modes]
|
|
257
|
+
|
|
258
|
+
# 构造简易位移阵列
|
|
259
|
+
n_atoms = self.document.num_atoms
|
|
260
|
+
n_modes = len(modes)
|
|
261
|
+
if n_modes > 0 and n_atoms > 0:
|
|
262
|
+
self.displacements = np.zeros((n_modes, n_atoms, 3), dtype=np.float32)
|
|
263
|
+
# 简易基于键连通方向的位移
|
|
264
|
+
for m_idx in range(n_modes):
|
|
265
|
+
np.random.seed(m_idx)
|
|
266
|
+
disp = np.random.randn(n_atoms, 3).astype(np.float32)
|
|
267
|
+
disp /= max(1e-4, float(np.linalg.norm(disp)))
|
|
268
|
+
self.displacements[m_idx] = disp
|
|
269
|
+
|
|
270
|
+
self._populate_table()
|
|
271
|
+
self.canvas.set_spectrum(self.frequencies, self.intensities, selected_idx=0 if self.frequencies else -1)
|
|
272
|
+
if self.frequencies:
|
|
273
|
+
self.table.selectRow(0)
|
|
274
|
+
|
|
275
|
+
def _populate_table(self) -> None:
|
|
276
|
+
self.table.setRowCount(len(self.frequencies))
|
|
277
|
+
for i, (f, inten, lbl) in enumerate(zip(self.frequencies, self.intensities, self.labels)):
|
|
278
|
+
it_idx = QTableWidgetItem(f"Mode #{i + 1}")
|
|
279
|
+
it_f = QTableWidgetItem(f"{f:.1f}")
|
|
280
|
+
it_int = QTableWidgetItem(f"{inten:.1f}")
|
|
281
|
+
it_lbl = QTableWidgetItem(lbl)
|
|
282
|
+
for it in (it_idx, it_f, it_int, it_lbl):
|
|
283
|
+
it.setTextAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
284
|
+
self.table.setItem(i, 0, it_idx)
|
|
285
|
+
self.table.setItem(i, 1, it_f)
|
|
286
|
+
self.table.setItem(i, 2, it_int)
|
|
287
|
+
self.table.setItem(i, 3, it_lbl)
|
|
288
|
+
|
|
289
|
+
def _on_table_row_selected(self) -> None:
|
|
290
|
+
rows = self.table.selectionModel().selectedRows()
|
|
291
|
+
if not rows:
|
|
292
|
+
return
|
|
293
|
+
r = rows[0].row()
|
|
294
|
+
self.current_mode = r
|
|
295
|
+
self.canvas.select_mode(r)
|
|
296
|
+
|
|
297
|
+
def _on_peak_selected_from_canvas(self, idx: int) -> None:
|
|
298
|
+
self.current_mode = idx
|
|
299
|
+
self.table.selectRow(idx)
|
|
300
|
+
|
|
301
|
+
def _toggle_play(self) -> None:
|
|
302
|
+
if self.is_playing:
|
|
303
|
+
self.timer.stop()
|
|
304
|
+
self.is_playing = False
|
|
305
|
+
self.play_btn.setText("▶ 播放振动动画")
|
|
306
|
+
self._restore_original_coords()
|
|
307
|
+
else:
|
|
308
|
+
if self.current_mode < 0 and self.frequencies:
|
|
309
|
+
self.current_mode = 0
|
|
310
|
+
self.table.selectRow(0)
|
|
311
|
+
self.timer.start()
|
|
312
|
+
self.is_playing = True
|
|
313
|
+
self.play_btn.setText("⏸ 暂停动画")
|
|
314
|
+
|
|
315
|
+
def _on_animation_step(self) -> None:
|
|
316
|
+
if self.initial_coords is None or self.displacements is None or self.current_mode < 0:
|
|
317
|
+
return
|
|
318
|
+
m_idx = self.current_mode
|
|
319
|
+
if m_idx >= len(self.displacements):
|
|
320
|
+
return
|
|
321
|
+
|
|
322
|
+
speed = float(self.speed_slider.value()) / 40.0
|
|
323
|
+
amp = float(self.amp_slider.value()) / 120.0
|
|
324
|
+
self.anim_t += 0.22 * speed
|
|
325
|
+
|
|
326
|
+
sin_val = math.sin(self.anim_t)
|
|
327
|
+
disp_frame = self.initial_coords + (self.displacements[m_idx] * (amp * sin_val))
|
|
328
|
+
|
|
329
|
+
# 更新视口原子坐标
|
|
330
|
+
self.document.coordinates.update_current_coords(disp_frame.astype(np.float32))
|
|
331
|
+
view = getattr(self.main_window, "workspace", None)
|
|
332
|
+
if view and hasattr(view, "view3d_real"):
|
|
333
|
+
view.view3d_real.refresh_geometry()
|
|
334
|
+
elif hasattr(self.main_window, "refresh_views"):
|
|
335
|
+
self.main_window.refresh_views()
|
|
336
|
+
|
|
337
|
+
def _restore_original_coords(self) -> None:
|
|
338
|
+
if self.initial_coords is not None:
|
|
339
|
+
self.document.coordinates.update_current_coords(self.initial_coords.copy())
|
|
340
|
+
view = getattr(self.main_window, "workspace", None)
|
|
341
|
+
if view and hasattr(view, "view3d_real"):
|
|
342
|
+
view.view3d_real.refresh_geometry()
|
|
343
|
+
|
|
344
|
+
def _on_load_external_log(self) -> None:
|
|
345
|
+
fn, _ = QFileDialog.getOpenFileName(
|
|
346
|
+
self, "选择量化计算日志文件", "", "Quantum Logs (*.log *.out *.txt);;All Files (*.*)"
|
|
347
|
+
)
|
|
348
|
+
if not fn:
|
|
349
|
+
return
|
|
350
|
+
adapter = CCLibAdapter()
|
|
351
|
+
res = adapter.parse_file(Path(fn))
|
|
352
|
+
if not res.converged or not res.frequencies:
|
|
353
|
+
QMessageBox.warning(self, "未找到频率", "该计算日志中未包含有效的频率 (Freq) 计算结果。")
|
|
354
|
+
return
|
|
355
|
+
|
|
356
|
+
self._restore_original_coords()
|
|
357
|
+
if res.coordinates is not None:
|
|
358
|
+
self.initial_coords = res.coordinates.copy()
|
|
359
|
+
self.document.coordinates.update_current_coords(res.coordinates.astype(np.float32))
|
|
360
|
+
|
|
361
|
+
self.frequencies = res.frequencies
|
|
362
|
+
self.intensities = getattr(res, "vib_intensities", []) or [15.0] * len(self.frequencies)
|
|
363
|
+
self.displacements = getattr(res, "vib_displacements", None)
|
|
364
|
+
self.labels = [f"从头算谐振模式 (计算软件: {res.software.upper()})" for _ in self.frequencies]
|
|
365
|
+
|
|
366
|
+
self._populate_table()
|
|
367
|
+
self.canvas.set_spectrum(self.frequencies, self.intensities, selected_idx=0)
|
|
368
|
+
self.table.selectRow(0)
|
|
369
|
+
QMessageBox.information(
|
|
370
|
+
self, "加载成功", f"已成功从 {Path(fn).name} 解析出 {len(self.frequencies)} 个真实振动模式!"
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
def _on_close(self) -> None:
|
|
374
|
+
self.timer.stop()
|
|
375
|
+
self._restore_original_coords()
|
|
376
|
+
self.accept()
|
|
377
|
+
|
|
378
|
+
def closeEvent(self, event):
|
|
379
|
+
self.timer.stop()
|
|
380
|
+
self._restore_original_coords()
|
|
381
|
+
super().closeEvent(event)
|