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,255 @@
|
|
|
1
|
+
"""
|
|
2
|
+
md_studio.py - MolForge 外接分子动力学统一分析模块
|
|
3
|
+
====================================================
|
|
4
|
+
面向真实 GROMACS 轨迹(gro/tpr + xtc/trr),用 MDAnalysis 成熟分析器做内存安全的计算,
|
|
5
|
+
不构造 N×N 全距离矩阵,可处理 7 万原子级体系:
|
|
6
|
+
|
|
7
|
+
- RMSD:先 Kabsch 最小二乘对齐再算(MDAnalysis.analysis.rms.RMSD,pbc 对齐)
|
|
8
|
+
- Rg :逐帧回旋半径
|
|
9
|
+
- RMSF:逐原子均方波动(rms.RMSF,对齐后)
|
|
10
|
+
- RDF :径向分布函数(rdf.InterRDF,距离分箱,内存安全)
|
|
11
|
+
- 氢键:HydrogenBondAnalysis,占有率统计
|
|
12
|
+
|
|
13
|
+
全部数值来自真实轨迹;输出 CSV/JSON + matplotlib 图,并在 summary 中诚实标注口径与限制。
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import csv
|
|
18
|
+
import json
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
|
|
21
|
+
import numpy as np
|
|
22
|
+
|
|
23
|
+
from .scientific_workflows import new_output_dir
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def run_md_studio(
|
|
27
|
+
topology: str | Path,
|
|
28
|
+
trajectory: str | Path,
|
|
29
|
+
output_parent: str | Path,
|
|
30
|
+
selection: str = "not name H*",
|
|
31
|
+
frame_step: int = 1,
|
|
32
|
+
rdf_range: tuple[str, str] | None = None,
|
|
33
|
+
r_max: float = 12.0,
|
|
34
|
+
n_bins: int = 120,
|
|
35
|
+
progress_callback=None,
|
|
36
|
+
preprocess_pbc: bool = False,
|
|
37
|
+
gmx_path: str | None = None,
|
|
38
|
+
) -> Path:
|
|
39
|
+
"""运行完整 MD 轨迹分析并返回输出目录。
|
|
40
|
+
|
|
41
|
+
参数
|
|
42
|
+
----
|
|
43
|
+
selection: MDAnalysis 选择字符串,默认排除显式氢以控制规模;可传 "all"。
|
|
44
|
+
frame_step: 帧采样步长,1 表示全部帧。
|
|
45
|
+
rdf_range: 两个选择字符串(中心组、参考组),默认用所选原子自身。
|
|
46
|
+
"""
|
|
47
|
+
try:
|
|
48
|
+
import MDAnalysis as mda
|
|
49
|
+
from MDAnalysis.analysis import rms, rdf
|
|
50
|
+
from MDAnalysis.analysis.hydrogenbonds import HydrogenBondAnalysis
|
|
51
|
+
except ImportError as exc: # pragma: no cover
|
|
52
|
+
raise RuntimeError("MD 分析需要 MDAnalysis,请在 molforge-webengine 环境运行。") from exc
|
|
53
|
+
|
|
54
|
+
report = progress_callback or (lambda message: None)
|
|
55
|
+
report("正在读取拓扑与轨迹…")
|
|
56
|
+
top, traj = Path(topology).resolve(), Path(trajectory).resolve()
|
|
57
|
+
if not top.is_file() or not traj.is_file():
|
|
58
|
+
raise ValueError("拓扑或轨迹文件不存在")
|
|
59
|
+
|
|
60
|
+
original_traj = traj
|
|
61
|
+
out = None
|
|
62
|
+
preprocessing = "not applied; input must be made whole/unwrapped as appropriate"
|
|
63
|
+
if preprocess_pbc:
|
|
64
|
+
import subprocess
|
|
65
|
+
from ..io.calculators import EngineToolRegistry
|
|
66
|
+
from .gromacs_submit import DEFAULT_GMX
|
|
67
|
+
detected = EngineToolRegistry.detect_tool("gromacs")
|
|
68
|
+
engine = gmx_path or detected.executable_path or DEFAULT_GMX
|
|
69
|
+
if not Path(engine).is_file():
|
|
70
|
+
raise FileNotFoundError("PBC预处理需要已配置的GROMACS;可取消处理仅输出原始诊断")
|
|
71
|
+
out = new_output_dir(output_parent, f"MDStudio_{top.stem}")
|
|
72
|
+
processed = out / "trajectory_nojump.xtc"
|
|
73
|
+
args = [str(engine), "trjconv", "-f", str(traj), "-s", str(top), "-o", str(processed), "-pbc", "nojump"]
|
|
74
|
+
report("正在使用GROMACS nojump处理周期跳跃(要求初始构型完整)…")
|
|
75
|
+
proc = subprocess.run(args, input="0\n", capture_output=True, text=True, encoding="utf-8", errors="replace", cwd=out, timeout=3600)
|
|
76
|
+
(out / "pbc_preprocessing.log").write_text((proc.stdout or "") + (proc.stderr or ""), encoding="utf-8")
|
|
77
|
+
if proc.returncode != 0 or not processed.is_file():
|
|
78
|
+
raise RuntimeError(f"PBC预处理失败,见{out / 'pbc_preprocessing.log'}")
|
|
79
|
+
traj = processed
|
|
80
|
+
preprocessing = "GROMACS trjconv -pbc nojump; assumes initial conformation is whole"
|
|
81
|
+
u = mda.Universe(str(top), str(traj))
|
|
82
|
+
if len(u.atoms) == 0:
|
|
83
|
+
raise ValueError("轨迹中没有原子")
|
|
84
|
+
ag = u.select_atoms(selection)
|
|
85
|
+
if len(ag) == 0:
|
|
86
|
+
raise ValueError(f"选择 '{selection}' 没有匹配到任何原子")
|
|
87
|
+
|
|
88
|
+
total_frames = len(u.trajectory)
|
|
89
|
+
used_frames = list(range(0, total_frames, max(1, int(frame_step))))
|
|
90
|
+
|
|
91
|
+
report(f"载入{len(u.atoms)}原子/{total_frames}帧;采样{len(used_frames)}帧。正在计算RMSD/Rg…")
|
|
92
|
+
# 1. RMSD(对齐到第一帧)与逐帧 Rg
|
|
93
|
+
rmsd_run = rms.RMSD(ag, ag, select=selection, ref_frame=used_frames[0], verbose=False)
|
|
94
|
+
rmsd_run.run(frames=used_frames)
|
|
95
|
+
rmsd_table = np.asarray(rmsd_run.results.rmsd) # 列: frame, time(ps), rmsd(Å)
|
|
96
|
+
|
|
97
|
+
rg_list = []
|
|
98
|
+
for fidx in used_frames:
|
|
99
|
+
u.trajectory[fidx]
|
|
100
|
+
rg_list.append(float(ag.radius_of_gyration()))
|
|
101
|
+
times = rmsd_table[:, 1]
|
|
102
|
+
rmsd_vals = rmsd_table[:, 2]
|
|
103
|
+
rg_vals = np.asarray(rg_list, dtype=float)
|
|
104
|
+
|
|
105
|
+
report("正在逐帧对齐并累计RMSF…")
|
|
106
|
+
# Align each sampled frame to the first; RMSD.run does not mutate the trajectory.
|
|
107
|
+
u.trajectory[used_frames[0]]
|
|
108
|
+
reference = ag.positions.astype(float).copy()
|
|
109
|
+
reference -= reference.mean(axis=0)
|
|
110
|
+
mean = np.zeros_like(reference)
|
|
111
|
+
m2 = np.zeros_like(reference)
|
|
112
|
+
for count, fidx in enumerate(used_frames, 1):
|
|
113
|
+
u.trajectory[fidx]
|
|
114
|
+
xyz = ag.positions.astype(float).copy()
|
|
115
|
+
xyz -= xyz.mean(axis=0)
|
|
116
|
+
left, _, right = np.linalg.svd(xyz.T @ reference)
|
|
117
|
+
correction = np.eye(3)
|
|
118
|
+
correction[-1, -1] = np.linalg.det(left @ right)
|
|
119
|
+
aligned = xyz @ (left @ correction @ right)
|
|
120
|
+
delta = aligned - mean
|
|
121
|
+
mean += delta / count
|
|
122
|
+
m2 += delta * (aligned - mean)
|
|
123
|
+
rmsf_vals = np.sqrt(np.maximum(0.0, m2.sum(axis=1) / len(used_frames)))
|
|
124
|
+
|
|
125
|
+
# 3. RDF:InterRDF 距离分箱,内存安全(不构造 N×N 矩阵)
|
|
126
|
+
if rdf_range is None:
|
|
127
|
+
# 同组RDF包含分子内对;下面的非零下界排除r=0自身距离。
|
|
128
|
+
center = ag
|
|
129
|
+
around = ag
|
|
130
|
+
else:
|
|
131
|
+
center = u.select_atoms(rdf_range[0])
|
|
132
|
+
around = u.select_atoms(rdf_range[1])
|
|
133
|
+
# 起始 0.5 Å:仅排除r=0自配对;成键距离仍可能在范围内,避免 r→0 伪峰;最近非键接触也 >0.5 Å
|
|
134
|
+
inter = rdf.InterRDF(center, around, nbins=n_bins, range=(0.5, float(r_max)), verbose=False)
|
|
135
|
+
report("正在计算RDF(包含分子内对,大选择可能耗时较长)…")
|
|
136
|
+
inter.run(frames=used_frames)
|
|
137
|
+
r_edges = np.asarray(inter.results.bins)
|
|
138
|
+
g_r = np.asarray(inter.results.rdf)
|
|
139
|
+
r_centers = np.asarray(r_edges)
|
|
140
|
+
|
|
141
|
+
report("RDF完成,正在计算氢键…")
|
|
142
|
+
# 4. 氢键(失败不阻断其余结果,诚实记录)
|
|
143
|
+
hb_status = {"status": "not_run", "unique_count": 0, "occupancy": []}
|
|
144
|
+
try:
|
|
145
|
+
# 该版本用 _sel 选择字符串参数,显式指定以避免无电荷时自动猜测失败
|
|
146
|
+
hba = HydrogenBondAnalysis(
|
|
147
|
+
u, hydrogens_sel="name H*",
|
|
148
|
+
donors_sel="name O* N*", acceptors_sel="name O* N*",
|
|
149
|
+
d_a_cutoff=3.5, d_h_a_angle_cutoff=150.0,
|
|
150
|
+
)
|
|
151
|
+
hba.run(frames=used_frames)
|
|
152
|
+
data = np.asarray(hba.results.hbonds)
|
|
153
|
+
hb_status["status"] = "ok"
|
|
154
|
+
if data.size:
|
|
155
|
+
pairs: dict[tuple[int, int], set[int]] = {}
|
|
156
|
+
for rec in data:
|
|
157
|
+
key = (int(rec[1]), int(rec[3]))
|
|
158
|
+
pairs.setdefault(key, set()).add(int(rec[0]))
|
|
159
|
+
nf = max(1, len(used_frames))
|
|
160
|
+
hb_status["unique_count"] = len(pairs)
|
|
161
|
+
hb_status["occupancy"] = [
|
|
162
|
+
{"donor_index": d, "acceptor_index": a, "fraction": round(len(frames) / nf, 4)}
|
|
163
|
+
for (d, a), frames in sorted(pairs.items(), key=lambda kv: -len(kv[1]))[:50]
|
|
164
|
+
]
|
|
165
|
+
except Exception as exc: # 诚实记录而非伪造
|
|
166
|
+
hb_status = {"status": "unavailable", "unique_count": 0, "occupancy": [], "diagnostic": str(exc)}
|
|
167
|
+
|
|
168
|
+
out = out or new_output_dir(output_parent, f"MDStudio_{top.stem}")
|
|
169
|
+
|
|
170
|
+
# 逐帧表
|
|
171
|
+
with (out / "md_rmsd_rg.csv").open("w", newline="", encoding="utf-8-sig") as fh:
|
|
172
|
+
w = csv.writer(fh)
|
|
173
|
+
w.writerow(["frame", "time_ps", "rmsd_angstrom", "rg_angstrom"])
|
|
174
|
+
for i, fidx in enumerate(used_frames):
|
|
175
|
+
w.writerow([int(fidx), round(float(times[i]), 3), round(float(rmsd_vals[i]), 5), round(float(rg_vals[i]), 5)])
|
|
176
|
+
|
|
177
|
+
# 逐原子 RMSF(带原子 id 与元素名)
|
|
178
|
+
with (out / "md_rmsf.csv").open("w", newline="", encoding="utf-8-sig") as fh:
|
|
179
|
+
w = csv.writer(fh)
|
|
180
|
+
w.writerow(["atom_local_index", "atom_id", "element", "rmsf_angstrom"])
|
|
181
|
+
ids = ag.ids
|
|
182
|
+
names = ag.names
|
|
183
|
+
for i in range(len(ag)):
|
|
184
|
+
w.writerow([i, int(ids[i]), str(names[i]), round(float(rmsf_vals[i]), 5)])
|
|
185
|
+
|
|
186
|
+
# RDF 曲线
|
|
187
|
+
with (out / "md_rdf.csv").open("w", newline="", encoding="utf-8-sig") as fh:
|
|
188
|
+
w = csv.writer(fh)
|
|
189
|
+
w.writerow(["r_angstrom", "g_r"])
|
|
190
|
+
for rv, gv in zip(r_centers, g_r):
|
|
191
|
+
w.writerow([round(float(rv), 4), round(float(gv), 5)])
|
|
192
|
+
|
|
193
|
+
peaks = np.where((g_r[1:-1] > g_r[:-2]) & (g_r[1:-1] >= g_r[2:]))[0] + 1
|
|
194
|
+
peak_i = int(peaks[0]) if len(peaks) else (int(np.argmax(g_r)) if len(g_r) else 0)
|
|
195
|
+
summary = {
|
|
196
|
+
"topology": str(top),
|
|
197
|
+
"trajectory": str(traj),
|
|
198
|
+
"original_trajectory": str(original_traj),
|
|
199
|
+
"selection": selection,
|
|
200
|
+
"total_frames": total_frames,
|
|
201
|
+
"frames_analyzed": len(used_frames),
|
|
202
|
+
"frame_step": int(frame_step),
|
|
203
|
+
"atoms_in_universe": len(u.atoms),
|
|
204
|
+
"atoms_in_selection": len(ag),
|
|
205
|
+
"rmsd_mean_angstrom": round(float(np.mean(rmsd_vals)), 4),
|
|
206
|
+
"rmsd_max_angstrom": round(float(np.max(rmsd_vals)), 4),
|
|
207
|
+
"rg_mean_angstrom": round(float(np.mean(rg_vals)), 4),
|
|
208
|
+
"rmsf_mean_angstrom": round(float(np.mean(rmsf_vals)), 4),
|
|
209
|
+
"rmsf_max_angstrom": round(float(np.max(rmsf_vals)), 4),
|
|
210
|
+
"rdf_first_peak_r_angstrom": round(float(r_centers[peak_i]), 3) if len(g_r) else 0.0,
|
|
211
|
+
"rdf_first_peak_g": round(float(g_r[peak_i]), 4) if len(g_r) else 0.0,
|
|
212
|
+
"hydrogen_bonds": hb_status,
|
|
213
|
+
"rdf_scope": "all selected atom pairs, including intramolecular/bonded pairs; r=0 omitted",
|
|
214
|
+
"pbc_preprocessing": preprocessing,
|
|
215
|
+
"honesty": (
|
|
216
|
+
"全部数值由 MDAnalysis 对真实轨迹计算;RMSD 已 Kabsch 对齐,RDF 走距离分箱(内存安全),"
|
|
217
|
+
"RMSF 为对齐后逐原子波动;PBC处理见pbc_preprocessing,未做自由能聚类,"
|
|
218
|
+
"氢键占有率按采样帧统计。"
|
|
219
|
+
),
|
|
220
|
+
}
|
|
221
|
+
(out / "md_summary.json").write_text(
|
|
222
|
+
json.dumps(summary, indent=2, ensure_ascii=False), encoding="utf-8"
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
report("数值计算完成,正在写表格和图像…")
|
|
226
|
+
_plot_md(out, times, rmsd_vals, rg_vals, rmsf_vals, r_centers, g_r)
|
|
227
|
+
report(f"完成:{out}")
|
|
228
|
+
return out
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def _plot_md(out: Path, times, rmsd, rg, rmsf, r_centers, g_r) -> None:
|
|
232
|
+
import matplotlib
|
|
233
|
+
matplotlib.use("Agg")
|
|
234
|
+
import matplotlib.pyplot as plt
|
|
235
|
+
|
|
236
|
+
fig, axes = plt.subplots(2, 2, figsize=(12, 8))
|
|
237
|
+
axes[0, 0].plot(times, rmsd, color="#1d4ed8")
|
|
238
|
+
axes[0, 0].set_title("RMSD (aligned)")
|
|
239
|
+
axes[0, 0].set_xlabel("Time (ps)"); axes[0, 0].set_ylabel("Å")
|
|
240
|
+
|
|
241
|
+
axes[0, 1].plot(times, rg, color="#66DEC9")
|
|
242
|
+
axes[0, 1].set_title("Radius of Gyration")
|
|
243
|
+
axes[0, 1].set_xlabel("Time (ps)"); axes[0, 1].set_ylabel("Å")
|
|
244
|
+
|
|
245
|
+
axes[1, 0].plot(np.arange(len(rmsf)), rmsf, color="#D8B679")
|
|
246
|
+
axes[1, 0].set_title("RMSF per atom")
|
|
247
|
+
axes[1, 0].set_xlabel("local atom index"); axes[1, 0].set_ylabel("Å")
|
|
248
|
+
|
|
249
|
+
axes[1, 1].plot(r_centers, g_r, color="#7DAEFA")
|
|
250
|
+
axes[1, 1].set_title("RDF g(r)")
|
|
251
|
+
axes[1, 1].set_xlabel("r (Å)"); axes[1, 1].set_ylabel("g(r)")
|
|
252
|
+
|
|
253
|
+
fig.tight_layout()
|
|
254
|
+
fig.savefig(out / "md_overview.png", dpi=130)
|
|
255
|
+
plt.close(fig)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""
|
|
2
|
+
WF-03: OSC 给体/受体能级对齐图工作流 (osc_energy_diagram.py)
|
|
3
|
+
============================================================
|
|
4
|
+
输入文件: 至少 2 个分子的 Gaussian .fchk + 同名 .log/.out(严格执行双源能级一致性校验 |ΔE| <= 0.05 eV)
|
|
5
|
+
调用工具: Python + openpyxl + python-pptx (+ 可选 Multiwfn & VMD)
|
|
6
|
+
输出结果:
|
|
7
|
+
- osc_energy_levels.svg (经典横线阶梯能级对齐图)
|
|
8
|
+
- osc_rectangle_levels.svg (色块矩形带隙对比图)
|
|
9
|
+
- osc_2xN_levels.svg (2xN 网格对比图)
|
|
10
|
+
- osc_energy_levels.xlsx (带格式与注释的 Excel 汇总表)
|
|
11
|
+
- osc_energy_levels.pptx (可直接在 PowerPoint 中编辑的矢量能级幻灯片)
|
|
12
|
+
"""
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Iterable
|
|
17
|
+
from .scientific_workflows import export_osc_levels
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def run_osc_energy_workflow(
|
|
21
|
+
inputs: Iterable[tuple[str | Path, str | Path | None]],
|
|
22
|
+
output_parent: str | Path,
|
|
23
|
+
) -> Path:
|
|
24
|
+
return export_osc_levels(inputs, output_parent)
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""
|
|
2
|
+
WF-06: 分子平面性 (MPP / SDP) 与二聚体堆积几何工作流 (planarity_analysis.py)
|
|
3
|
+
==============================================================================
|
|
4
|
+
严格基于 `planarity-analysis/SKILL.md` 与 `OSC_MD_workflows/03-二面角-质心距分析工作流.md`:
|
|
5
|
+
输入文件: Gaussian .fchk 或 .xyz / .mol / .sdf / .pdb 结构文件
|
|
6
|
+
调用工具: NumPy SVD 最佳拟合平面求解器 (+ 可选 Multiwfn 100->21->mpp 与 VMD render_planarity.tcl)
|
|
7
|
+
输出结果:
|
|
8
|
+
- planarity.json / planarity.csv (重原子数、平面度 RMSD/MPP Å、最大离面距离 Å、跨度 SDP Å、法向量)
|
|
9
|
+
- atom_plane_deviations.pqr (含每个原子离面有向距离 d_s 的 PQR 文件,可直接用于 VMD BWR 蓝-白-红渲染)
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import csv
|
|
14
|
+
import json
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
import numpy as np
|
|
17
|
+
from .scientific_workflows import (
|
|
18
|
+
analyze_fchk_planarity,
|
|
19
|
+
planarity_from_coordinates,
|
|
20
|
+
read_fchk_geometry,
|
|
21
|
+
new_output_dir,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def run_planarity_workflow(input_path: str | Path, output_parent: str | Path) -> Path:
|
|
26
|
+
p = Path(input_path).resolve()
|
|
27
|
+
if not p.is_file():
|
|
28
|
+
raise ValueError(f"输入文件不存在: {p}")
|
|
29
|
+
if p.suffix.lower() == ".fchk":
|
|
30
|
+
out = analyze_fchk_planarity(p, output_parent)
|
|
31
|
+
z, coords = read_fchk_geometry(p)
|
|
32
|
+
else:
|
|
33
|
+
from ..io.rdkit_adapter import load_molecule_document
|
|
34
|
+
loaded = load_molecule_document(p)
|
|
35
|
+
doc = loaded[0] if isinstance(loaded, tuple) else loaded
|
|
36
|
+
if not doc.has_3d or doc.coordinates.current is None:
|
|
37
|
+
doc.relax_3d_geometry(max_iters=80)
|
|
38
|
+
z = np.asarray([doc.topology.get_atom(aid).atomic_num for aid in doc.topology.atom_ids], dtype=int)
|
|
39
|
+
coords = np.asarray(doc.coordinates.current.coords, dtype=float)
|
|
40
|
+
result = planarity_from_coordinates(z, coords)
|
|
41
|
+
result.update(source=str(p), metric="重原子最佳拟合平面 RMSD (MPP)")
|
|
42
|
+
out = new_output_dir(output_parent, f"Planarity_{p.stem}")
|
|
43
|
+
(out / "planarity.json").write_text(json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8")
|
|
44
|
+
with (out / "planarity.csv").open("w", newline="", encoding="utf-8-sig") as fh:
|
|
45
|
+
w = csv.writer(fh)
|
|
46
|
+
w.writerow(["metric", "value", "unit"])
|
|
47
|
+
for k, v in result.items():
|
|
48
|
+
if isinstance(v, (int, float)):
|
|
49
|
+
w.writerow([k, v, "Å" if "angstrom" in k else ""])
|
|
50
|
+
|
|
51
|
+
# 生成每个原子的离面距离表与 VMD BWR 可视化 .pqr 文件
|
|
52
|
+
keep = z != 1
|
|
53
|
+
pts = coords[keep] if np.sum(keep) >= 3 else coords
|
|
54
|
+
center = pts.mean(axis=0)
|
|
55
|
+
_, _, vt = np.linalg.svd(pts - center, full_matrices=False)
|
|
56
|
+
normal = vt[-1]
|
|
57
|
+
signed_d = (coords - center) @ normal
|
|
58
|
+
symbols = {1: "H", 5: "B", 6: "C", 7: "N", 8: "O", 9: "F", 14: "Si", 15: "P", 16: "S", 17: "Cl", 34: "Se", 35: "Br", 53: "I"}
|
|
59
|
+
pqr_lines = []
|
|
60
|
+
for i, (zi, pt, dv) in enumerate(zip(z, coords, signed_d), 1):
|
|
61
|
+
sym = symbols.get(int(zi), "C")
|
|
62
|
+
pqr_lines.append(
|
|
63
|
+
f"ATOM {i:5d} {sym:>2s} MOL A 1 {pt[0]:8.3f}{pt[1]:8.3f}{pt[2]:8.3f} {dv:6.3f} 1.500 {sym:>2s}"
|
|
64
|
+
)
|
|
65
|
+
(out / "atom_plane_deviations.pqr").write_text("\n".join(pqr_lines) + "\nTER\nEND\n", encoding="utf-8")
|
|
66
|
+
return out
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"""
|
|
2
|
+
WF-04: OSC 内球重组能 (λ_h / λ_e) 四点法与 Marcus 电荷转移速率工作流 (reorganization_energy.py)
|
|
3
|
+
==================================================================================================
|
|
4
|
+
严格基于 `OSC_MD_workflows/06-重组能计算工作流.md` 与 `09-电荷转移动力学K工作流.md`:
|
|
5
|
+
支持两种工作模式:
|
|
6
|
+
模式 A(生成 4 点法 Gaussian 输入卡):
|
|
7
|
+
输入分子结构 (.xyz/.mol/.sdf/.pdb/.gjf),一键生成全套 4 个 Gaussian 16 输入文件:
|
|
8
|
+
1. reorg-opt-中性.gjf (0 1, opt, E(N, R_N))
|
|
9
|
+
2. reorg-opt-阴离子.gjf (-1 2, opt, E(A-, R_A-)) 或 阳离子 (+1 2, opt, E(D+, R_D+))
|
|
10
|
+
3. reorg-sp-中性.gjf (0 1, sp at charged geometry, E(N, R_charged))
|
|
11
|
+
4. reorg-sp-阴离子.gjf (±1 2, sp at neutral geometry, E(charged, R_N))
|
|
12
|
+
模式 B(从 4 个 Gaussian .log/.out 解析能量计算四点法重组能 λ 与 Marcus 速率 k_ET):
|
|
13
|
+
λ_1 = E(N, R_charged) - E(N, R_N)
|
|
14
|
+
λ_2 = E(charged, R_N) - E(charged, R_charged)
|
|
15
|
+
λ_total = λ_1 + λ_2 (单位: eV 与 meV)
|
|
16
|
+
并结合电子耦合 V_DA (eV) 与驱动力 ΔG (eV) 计算标准 Marcus 速率:
|
|
17
|
+
k_ET = (2π/ħ) |V_DA|² / sqrt(4π λ k_B T) * exp(-(ΔG + λ)² / (4 λ k_B T))
|
|
18
|
+
"""
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import csv
|
|
22
|
+
import json
|
|
23
|
+
import math
|
|
24
|
+
import re
|
|
25
|
+
from pathlib import Path
|
|
26
|
+
from .scientific_workflows import new_output_dir, HARTREE_TO_EV
|
|
27
|
+
|
|
28
|
+
KB_EV_PER_K = 8.617333262e-5
|
|
29
|
+
HBAR_EV_S = 6.582119569e-16
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def parse_last_scf_energy_hartree(log_path: str | Path) -> float:
|
|
33
|
+
"""从 Gaussian .log/.out 中提取最后一步收敛的 SCF Done 能量 (Hartree)。"""
|
|
34
|
+
p = Path(log_path)
|
|
35
|
+
if not p.is_file():
|
|
36
|
+
raise ValueError(f"日志文件不存在: {p}")
|
|
37
|
+
scf_re = re.compile(r"SCF\s+Done:\s+E\([^\)]+\)\s*=\s*([-+]?\d+\.\d+(?:[DEde][-+]?\d+)?)")
|
|
38
|
+
last_val: float | None = None
|
|
39
|
+
with p.open("r", encoding="utf-8", errors="replace") as fh:
|
|
40
|
+
for line in fh:
|
|
41
|
+
m = scf_re.search(line)
|
|
42
|
+
if m:
|
|
43
|
+
last_val = float(m.group(1).replace("D", "E").replace("d", "e"))
|
|
44
|
+
if last_val is None:
|
|
45
|
+
raise ValueError(f"未在 {p.name} 中找到 'SCF Done:' 能量记录")
|
|
46
|
+
return last_val
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def compute_marcus_rate(v_da_ev: float, lambda_ev: float, dg_ev: float = 0.0, temp_k: float = 298.15) -> dict[str, float]:
|
|
50
|
+
"""根据 `09-速率/marcus_rate.py` 计算非绝热极限下的 Marcus 电荷转移速率 k (s^-1)。"""
|
|
51
|
+
if lambda_ev <= 0.0 or temp_k <= 0.0:
|
|
52
|
+
raise ValueError("重组能 λ 与温度 T 必须大于 0")
|
|
53
|
+
kbt = KB_EV_PER_K * temp_k
|
|
54
|
+
prefactor = (2.0 * math.pi / HBAR_EV_S) * (v_da_ev ** 2) / math.sqrt(4.0 * math.pi * lambda_ev * kbt)
|
|
55
|
+
barrier_ev = ((dg_ev + lambda_ev) ** 2) / (4.0 * lambda_ev)
|
|
56
|
+
rate_s1 = prefactor * math.exp(-barrier_ev / kbt)
|
|
57
|
+
return {
|
|
58
|
+
"v_da_ev": float(v_da_ev),
|
|
59
|
+
"lambda_ev": float(lambda_ev),
|
|
60
|
+
"delta_g_ev": float(dg_ev),
|
|
61
|
+
"temperature_k": float(temp_k),
|
|
62
|
+
"activation_barrier_ev": round(barrier_ev, 6),
|
|
63
|
+
"marcus_rate_s_inv": float(rate_s1),
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def generate_four_point_gjf_bundle(
|
|
68
|
+
structure_path_or_doc,
|
|
69
|
+
output_parent: str | Path,
|
|
70
|
+
carrier_type: str = "electron", # "electron" (-1 2) or "hole" (+1 2)
|
|
71
|
+
functional_basis: str = "wb97xd/6-31g(d,p)",
|
|
72
|
+
solvent: str = "chloroform",
|
|
73
|
+
nproc: int = 24,
|
|
74
|
+
mem_gb: int = 24,
|
|
75
|
+
) -> Path:
|
|
76
|
+
"""根据分子结构生成四点法重组能全套 4 个 Gaussian .gjf 输入文件。"""
|
|
77
|
+
from ..io.rdkit_adapter import load_molecule_document
|
|
78
|
+
from ..application.calculators.qc_input_generator import extract_xyz_lines
|
|
79
|
+
if hasattr(structure_path_or_doc, "topology"):
|
|
80
|
+
doc = structure_path_or_doc
|
|
81
|
+
else:
|
|
82
|
+
loaded = load_molecule_document(structure_path_or_doc)
|
|
83
|
+
doc = loaded[0] if isinstance(loaded, tuple) else loaded
|
|
84
|
+
|
|
85
|
+
xyz_lines = extract_xyz_lines(doc)
|
|
86
|
+
if not xyz_lines:
|
|
87
|
+
raise ValueError("分子结构为空,无法生成重组能 .gjf 输入文件")
|
|
88
|
+
coord_block = "\n".join(xyz_lines)
|
|
89
|
+
stem = doc.name or "molecule"
|
|
90
|
+
chg_ion = -1 if carrier_type == "electron" else 1
|
|
91
|
+
ion_tag = "阴离子" if carrier_type == "electron" else "阳离子"
|
|
92
|
+
out = new_output_dir(output_parent, f"Reorg4Pt_Inputs_{stem}")
|
|
93
|
+
|
|
94
|
+
scrf_str = f" scrf(smd,solvent={solvent})" if solvent and solvent.lower() != "none" else ""
|
|
95
|
+
specs = [
|
|
96
|
+
(f"reorg-opt-中性.gjf", f"{stem}-OPT01.chk", f"#p {functional_basis} opt{scrf_str} SCF=conver=6", "中性态几何优化 E(N,RN)", 0, 1),
|
|
97
|
+
(f"reorg-opt-{ion_tag}.gjf", f"{stem}-OPT12.chk", f"#p {functional_basis} opt{scrf_str} SCF=conver=6", f"{ion_tag}态几何优化 E(Ion,RIon)", chg_ion, 2),
|
|
98
|
+
(f"reorg-sp-中性.gjf", f"{stem}-sp01.chk", f"#p {functional_basis} sp{scrf_str} SCF=conver=6", f"中性单点(在{ion_tag}平衡几何上) E(N,RIon)", 0, 1),
|
|
99
|
+
(f"reorg-sp-{ion_tag}.gjf", f"{stem}-sp12.chk", f"#p {functional_basis} sp{scrf_str} SCF=conver=6", f"{ion_tag}单点(在中性平衡几何上) E(Ion,RN)", chg_ion, 2),
|
|
100
|
+
]
|
|
101
|
+
for fname, chk, route, title, chg, mult in specs:
|
|
102
|
+
content = (
|
|
103
|
+
f"%chk={chk}\n"
|
|
104
|
+
f"%nprocshared={nproc}\n"
|
|
105
|
+
f"%mem={mem_gb}GB\n"
|
|
106
|
+
f"{route}\n\n"
|
|
107
|
+
f"{title}\n\n"
|
|
108
|
+
f"{chg} {mult}\n"
|
|
109
|
+
f"{coord_block}\n\n"
|
|
110
|
+
)
|
|
111
|
+
(out / fname).write_text(content, encoding="utf-8")
|
|
112
|
+
return out
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def run_reorganization_energy_workflow(
|
|
116
|
+
log_files: list[str | Path],
|
|
117
|
+
output_parent: str | Path,
|
|
118
|
+
v_da_ev: float = 0.025,
|
|
119
|
+
dg_ev: float = 0.0,
|
|
120
|
+
temp_k: float = 298.15,
|
|
121
|
+
) -> Path:
|
|
122
|
+
"""
|
|
123
|
+
输入 4 个 Gaussian .log/.out 文件(按 [OPT_neutral, OPT_charged, SP_neutral_at_charged, SP_charged_at_neutral] 顺序),
|
|
124
|
+
计算 Nelson 四点法内球重组能 λ_1, λ_2, λ_total (eV / meV) 与 Marcus 电荷转移速率 k_ET。
|
|
125
|
+
"""
|
|
126
|
+
if len(log_files) != 4:
|
|
127
|
+
raise ValueError("四点法重组能计算需要精确提供 4 个 Gaussian .log/.out 文件:[1]中性优化, [2]带电态优化, [3]中性单点(带电几何), [4]带电单点(中性几何)")
|
|
128
|
+
|
|
129
|
+
e_n_rn = parse_last_scf_energy_hartree(log_files[0])
|
|
130
|
+
e_c_rc = parse_last_scf_energy_hartree(log_files[1])
|
|
131
|
+
e_n_rc = parse_last_scf_energy_hartree(log_files[2])
|
|
132
|
+
e_c_rn = parse_last_scf_energy_hartree(log_files[3])
|
|
133
|
+
|
|
134
|
+
lam1_ev = (e_n_rc - e_n_rn) * HARTREE_TO_EV
|
|
135
|
+
lam2_ev = (e_c_rn - e_c_rc) * HARTREE_TO_EV
|
|
136
|
+
lam_tot_ev = lam1_ev + lam2_ev
|
|
137
|
+
lam_tot_mev = lam_tot_ev * 1000.0
|
|
138
|
+
|
|
139
|
+
marcus = compute_marcus_rate(v_da_ev=v_da_ev, lambda_ev=max(1e-4, abs(lam_tot_ev)), dg_ev=dg_ev, temp_k=temp_k)
|
|
140
|
+
summary = {
|
|
141
|
+
"E_neutral_at_neutral_hartree": e_n_rn,
|
|
142
|
+
"E_charged_at_charged_hartree": e_c_rc,
|
|
143
|
+
"E_neutral_at_charged_hartree": e_n_rc,
|
|
144
|
+
"E_charged_at_neutral_hartree": e_c_rn,
|
|
145
|
+
"lambda_1_ev": round(lam1_ev, 5),
|
|
146
|
+
"lambda_2_ev": round(lam2_ev, 5),
|
|
147
|
+
"lambda_total_ev": round(lam_tot_ev, 5),
|
|
148
|
+
"lambda_total_mev": round(lam_tot_mev, 2),
|
|
149
|
+
"marcus_kinetics": marcus,
|
|
150
|
+
"files": [str(Path(p).resolve()) for p in log_files],
|
|
151
|
+
}
|
|
152
|
+
out = new_output_dir(output_parent, "Reorganization_Energy")
|
|
153
|
+
(out / "reorganization_energy.json").write_text(json.dumps(summary, indent=2, ensure_ascii=False), encoding="utf-8")
|
|
154
|
+
with (out / "reorganization_energy.csv").open("w", newline="", encoding="utf-8-sig") as fh:
|
|
155
|
+
w = csv.writer(fh)
|
|
156
|
+
w.writerow(["metric", "value", "unit"])
|
|
157
|
+
w.writerow(["E(N, R_N)", f"{e_n_rn:.8f}", "Hartree"])
|
|
158
|
+
w.writerow(["E(C, R_C)", f"{e_c_rc:.8f}", "Hartree"])
|
|
159
|
+
w.writerow(["E(N, R_C)", f"{e_n_rc:.8f}", "Hartree"])
|
|
160
|
+
w.writerow(["E(C, R_N)", f"{e_c_rn:.8f}", "Hartree"])
|
|
161
|
+
w.writerow(["lambda_1", f"{lam1_ev:.5f}", "eV"])
|
|
162
|
+
w.writerow(["lambda_2", f"{lam2_ev:.5f}", "eV"])
|
|
163
|
+
w.writerow(["lambda_total", f"{lam_tot_ev:.5f}", "eV"])
|
|
164
|
+
w.writerow(["lambda_total_mev", f"{lam_tot_mev:.2f}", "meV"])
|
|
165
|
+
w.writerow(["Marcus_k_ET", f"{marcus['marcus_rate_s_inv']:.4e}", "s^-1"])
|
|
166
|
+
return out
|