molforge-studio 7.4.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. main.py +71 -0
  2. molforge/__init__.py +19 -0
  3. molforge/ai/__init__.py +15 -0
  4. molforge/ai/deepseek_harness.py +185 -0
  5. molforge/ai/mcp/desktop_client.py +38 -0
  6. molforge/ai/mcp/desktop_service.py +121 -0
  7. molforge/ai/mcp/mcp_server.py +780 -0
  8. molforge/ai/mcp_bridge.py +945 -0
  9. molforge/ai/observation.py +152 -0
  10. molforge/ai/tools.py +455 -0
  11. molforge/application/__init__.py +22 -0
  12. molforge/application/ai/__init__.py +1 -0
  13. molforge/application/ai/deepseek_client.py +293 -0
  14. molforge/application/ai/observation.py +161 -0
  15. molforge/application/ai/tools.py +200 -0
  16. molforge/application/ai_proposals.py +166 -0
  17. molforge/application/bio_selection.py +143 -0
  18. molforge/application/builtin_commands.py +1445 -0
  19. molforge/application/calculators/__init__.py +10 -0
  20. molforge/application/calculators/base.py +143 -0
  21. molforge/application/calculators/calchem_engine.py +67 -0
  22. molforge/application/calculators/calchem_subprocess_worker.py +109 -0
  23. molforge/application/calculators/gaussian_engine.py +59 -0
  24. molforge/application/calculators/gaussian_job_spec.py +240 -0
  25. molforge/application/calculators/orca_engine.py +92 -0
  26. molforge/application/calculators/qc_input_generator.py +300 -0
  27. molforge/application/calculators/registry.py +29 -0
  28. molforge/application/calculators/rest_engine.py +262 -0
  29. molforge/application/command_bus.py +139 -0
  30. molforge/application/commands.py +55 -0
  31. molforge/application/conformers.py +143 -0
  32. molforge/application/document_session.py +156 -0
  33. molforge/application/events.py +74 -0
  34. molforge/application/fragment_catalog.py +422 -0
  35. molforge/application/fragment_commands.py +268 -0
  36. molforge/application/geometry_commands.py +84 -0
  37. molforge/application/history.py +105 -0
  38. molforge/application/internal_coordinates.py +293 -0
  39. molforge/application/invalidation.py +1174 -0
  40. molforge/application/jobs.py +185 -0
  41. molforge/application/measurement.py +167 -0
  42. molforge/application/measurement_targets.py +264 -0
  43. molforge/application/modeling_commands.py +61 -0
  44. molforge/application/plugins.py +197 -0
  45. molforge/application/ports/editor2d.py +85 -0
  46. molforge/application/reaction.py +75 -0
  47. molforge/application/selection.py +164 -0
  48. molforge/application/selection_commands.py +31 -0
  49. molforge/application/trajectory.py +120 -0
  50. molforge/application/trajectory_analysis.py +231 -0
  51. molforge/application/workspace_registry.py +226 -0
  52. molforge/core/__init__.py +12 -0
  53. molforge/core/conformer.py +45 -0
  54. molforge/core/molecule.py +150 -0
  55. molforge/core/orbital.py +33 -0
  56. molforge/core/properties.py +43 -0
  57. molforge/domain/__init__.py +12 -0
  58. molforge/domain/biomolecule.py +99 -0
  59. molforge/domain/chemical_summary.py +129 -0
  60. molforge/domain/chemistry.py +13 -0
  61. molforge/domain/coordinate_store.py +164 -0
  62. molforge/domain/coordination.py +133 -0
  63. molforge/domain/custom_fragments.py +255 -0
  64. molforge/domain/document.py +469 -0
  65. molforge/domain/element_reference.json +598 -0
  66. molforge/domain/elements.py +188 -0
  67. molforge/domain/ids.py +58 -0
  68. molforge/domain/massive_system.py +246 -0
  69. molforge/domain/periodic.py +116 -0
  70. molforge/domain/provenance.py +115 -0
  71. molforge/domain/topology.py +364 -0
  72. molforge/infrastructure/__init__.py +23 -0
  73. molforge/infrastructure/hpc/cluster_config.py +122 -0
  74. molforge/infrastructure/hpc/remote_executor.py +212 -0
  75. molforge/infrastructure/hpc/slurm_generator.py +93 -0
  76. molforge/io/__init__.py +35 -0
  77. molforge/io/calchem_bridge.py +407 -0
  78. molforge/io/calculators.py +893 -0
  79. molforge/io/cclib_adapter.py +422 -0
  80. molforge/io/conformers.py +183 -0
  81. molforge/io/cube_reader.py +215 -0
  82. molforge/io/custom_fragments.py +79 -0
  83. molforge/io/format_matrix.py +157 -0
  84. molforge/io/gemmi_adapter.py +150 -0
  85. molforge/io/history_skill.py +46 -0
  86. molforge/io/mdanalysis_adapter.py +155 -0
  87. molforge/io/mforge_storage.py +261 -0
  88. molforge/io/multiwfn_driver.py +614 -0
  89. molforge/io/openbabel_adapter.py +265 -0
  90. molforge/io/openbabel_handler.py +33 -0
  91. molforge/io/rdkit_adapter.py +1865 -0
  92. molforge/io/readers/__init__.py +10 -0
  93. molforge/io/readers/cube_reader.py +71 -0
  94. molforge/io/readers/gjf_reader.py +110 -0
  95. molforge/io/readers/glog_reader.py +45 -0
  96. molforge/io/readers/mol2_reader.py +36 -0
  97. molforge/io/readers/mol_reader.py +56 -0
  98. molforge/io/readers/pdb_reader.py +39 -0
  99. molforge/io/readers/smi_reader.py +40 -0
  100. molforge/io/readers/xyz_reader.py +47 -0
  101. molforge/io/registry.py +128 -0
  102. molforge/io/writers/__init__.py +7 -0
  103. molforge/io/writers/gjf_writer.py +68 -0
  104. molforge/io/writers/pdb_writer.py +37 -0
  105. molforge/io/writers/png_writer.py +31 -0
  106. molforge/io/writers/svg_writer.py +111 -0
  107. molforge/io/writers/xyz_writer.py +39 -0
  108. molforge/rendering/__init__.py +21 -0
  109. molforge/rendering/benchmark.py +121 -0
  110. molforge/rendering/bridge.py +60 -0
  111. molforge/rendering/contracts.py +119 -0
  112. molforge/rendering/glyph_scene.py +279 -0
  113. molforge/rendering/ketcher_bridge.py +131 -0
  114. molforge/rendering/ketcher_id_mapping.py +110 -0
  115. molforge/rendering/materials.py +127 -0
  116. molforge/rendering/molstar_backend.py +245 -0
  117. molforge/rendering/native_labels.py +134 -0
  118. molforge/rendering/orbitals.py +139 -0
  119. molforge/rendering/vtk_backend.py +2294 -0
  120. molforge/runtime.py +29 -0
  121. molforge/server/__init__.py +1 -0
  122. molforge/server/api_bridge.py +947 -0
  123. molforge/ui/__init__.py +1 -0
  124. molforge/ui/assets/caffeine_2d.svg +150 -0
  125. molforge/ui/assets/caffeine_3d_preview.svg +209 -0
  126. molforge/ui/assets/caffeine_preview.json +302 -0
  127. molforge/ui/assets/icons/atom.svg +1 -0
  128. molforge/ui/assets/icons/bond.svg +1 -0
  129. molforge/ui/assets/icons/cleanup.svg +1 -0
  130. molforge/ui/assets/icons/export.svg +1 -0
  131. molforge/ui/assets/icons/fragments.svg +1 -0
  132. molforge/ui/assets/icons/history.svg +1 -0
  133. molforge/ui/assets/icons/jobs.svg +1 -0
  134. molforge/ui/assets/icons/measure.svg +1 -0
  135. molforge/ui/assets/icons/molecules.svg +1 -0
  136. molforge/ui/assets/icons/overview.svg +1 -0
  137. molforge/ui/assets/icons/ring.svg +1 -0
  138. molforge/ui/assets/icons/search.svg +1 -0
  139. molforge/ui/assets/icons/select.svg +1 -0
  140. molforge/ui/assets/icons/settings.svg +1 -0
  141. molforge/ui/assets/icons/templates.svg +1 -0
  142. molforge/ui/assets/molforge_logo.ico +0 -0
  143. molforge/ui/assets/molforge_logo.png +0 -0
  144. molforge/ui/atom_labels.py +92 -0
  145. molforge/ui/bio_structure_dialog.py +57 -0
  146. molforge/ui/conformer_dialog.py +151 -0
  147. molforge/ui/dialogs/__init__.py +2 -0
  148. molforge/ui/dialogs/aim_qtaim_dialog.py +533 -0
  149. molforge/ui/dialogs/calchem_orbitals_dialog.py +287 -0
  150. molforge/ui/dialogs/element_fragments.py +130 -0
  151. molforge/ui/dialogs/gaussian_calculation_setup.py +308 -0
  152. molforge/ui/dialogs/hpc_job_dialog.py +427 -0
  153. molforge/ui/dialogs/vibrational_spectrum_dialog.py +381 -0
  154. molforge/ui/editor2d_widget.py +1803 -0
  155. molforge/ui/element_picker.py +218 -0
  156. molforge/ui/gmv_window_manager.py +65 -0
  157. molforge/ui/gromacs_job_dialog.py +47 -0
  158. molforge/ui/hotkeys.py +107 -0
  159. molforge/ui/i18n.py +237 -0
  160. molforge/ui/live_llm_dialog.py +135 -0
  161. molforge/ui/llm_config_dialog.py +103 -0
  162. molforge/ui/modeling_actions.py +176 -0
  163. molforge/ui/molstar_widget.py +98 -0
  164. molforge/ui/molstar_window.py +85 -0
  165. molforge/ui/panels.py +2966 -0
  166. molforge/ui/qc_result_dialog.py +1924 -0
  167. molforge/ui/render3d_widget.py +1579 -0
  168. molforge/ui/scrolling.py +52 -0
  169. molforge/ui/settings_panel.py +330 -0
  170. molforge/ui/shells/__init__.py +4 -0
  171. molforge/ui/shells/base_shell.py +72 -0
  172. molforge/ui/shells/document_tabs.py +715 -0
  173. molforge/ui/shells/studio_2d.py +339 -0
  174. molforge/ui/shells/studio_3d.py +401 -0
  175. molforge/ui/shells/studio_split.py +370 -0
  176. molforge/ui/shells/workflow_inputs.py +698 -0
  177. molforge/ui/theme.py +719 -0
  178. molforge/ui/trajectory_window.py +333 -0
  179. molforge/ui/views.py +892 -0
  180. molforge/ui/vtk_multiview_widget.py +141 -0
  181. molforge/ui/welcome_window.py +223 -0
  182. molforge/ui/window.py +3320 -0
  183. molforge/workflows/__init__.py +25 -0
  184. molforge/workflows/assets/OSC_MD_workflows/templates/01-MD/delete_solvent.py +216 -0
  185. molforge/workflows/assets/OSC_MD_workflows/templates/02-RDF/extract_atoms.py +60 -0
  186. molforge/workflows/assets/OSC_MD_workflows/templates/02-RDF/extract_atoms_example.py +22 -0
  187. molforge/workflows/assets/OSC_MD_workflows/templates/03-/342/225/244/320/225/342/225/250/342/226/221/342/225/250/320/246/342/225/244/320/227/342/225/250/342/225/226/342/225/250/342/224/220/342/225/244/320/225/342/225/250/320/247/342/225/250/342/226/221/342/225/244/320/224/321/202/320/245/320/254/342/225/250/320/265/analysis_mol.py +244 -0
  188. molforge/workflows/assets/OSC_MD_workflows/templates/04-/342/225/244/320/224/321/202/320/245/320/241/342/225/250/320/254/342/225/244/320/227/321/202/320/245/320/247/321/202/320/244/320/264/342/225/244/320/225/342/225/250/342/224/220/342/225/250/320/246/342/225/244/320/225/321/202/320/245/320/241/342/225/250/342/225/242/rms_roughness.py +33 -0
  189. molforge/workflows/assets/OSC_MD_workflows/templates/04-/342/225/244/320/224/321/202/320/245/320/241/342/225/250/320/254/342/225/244/320/227/321/202/320/245/320/247/321/202/320/244/320/264/342/225/244/320/225/342/225/250/342/224/220/342/225/250/320/246/342/225/244/320/225/321/202/320/245/320/241/342/225/250/342/225/242/xpm_2.py +117 -0
  190. molforge/workflows/assets/OSC_MD_workflows/templates/09-/342/225/244/320/231/342/225/250/320/240/342/225/250/320/277/342/225/244/320/227/342/225/250/320/256/342/225/250/320/247/marcus_rate.py +60 -0
  191. molforge/workflows/assets/esp-surface-analysis/scripts/compute_descriptors.py +134 -0
  192. molforge/workflows/assets/esp-surface-analysis/scripts/parse_surfanalysis.py +58 -0
  193. molforge/workflows/assets/esp-surface-analysis/scripts/plot_esp_hist.py +115 -0
  194. molforge/workflows/assets/homo-lumo-plot/extract_orb_energy.py +57 -0
  195. molforge/workflows/assets/homo-lumo-plot/make_level_plot.py +76 -0
  196. molforge/workflows/assets/homo-lumo-plot/run_pipeline.py +84 -0
  197. molforge/workflows/assets/osc-energy-level-diagram/scripts/extract_levels.py +60 -0
  198. molforge/workflows/assets/osc-energy-level-diagram/scripts/make_editable_pptx.py +122 -0
  199. molforge/workflows/assets/osc-energy-level-diagram/scripts/make_energy_table.py +66 -0
  200. molforge/workflows/assets/osc-energy-level-diagram/scripts/make_level_lines_diagram.py +148 -0
  201. molforge/workflows/assets/osc-energy-level-diagram/scripts/make_rectangle_diagram.py +148 -0
  202. molforge/workflows/assets/osc-energy-level-diagram/scripts/verify_from_log.py +45 -0
  203. molforge/workflows/dipole_analysis.py +32 -0
  204. molforge/workflows/esp_surface.py +36 -0
  205. molforge/workflows/gromacs_submit.py +167 -0
  206. molforge/workflows/homo_lumo_plot.py +59 -0
  207. molforge/workflows/igmh_interaction.py +111 -0
  208. molforge/workflows/md_rdf_analysis.py +134 -0
  209. molforge/workflows/md_studio.py +255 -0
  210. molforge/workflows/osc_energy_diagram.py +24 -0
  211. molforge/workflows/planarity_analysis.py +66 -0
  212. molforge/workflows/reorganization_energy.py +166 -0
  213. molforge/workflows/scientific_workflows.py +650 -0
  214. molforge_studio-7.4.3.dist-info/METADATA +215 -0
  215. molforge_studio-7.4.3.dist-info/RECORD +219 -0
  216. molforge_studio-7.4.3.dist-info/WHEEL +5 -0
  217. molforge_studio-7.4.3.dist-info/entry_points.txt +3 -0
  218. molforge_studio-7.4.3.dist-info/licenses/LICENSE +93 -0
  219. molforge_studio-7.4.3.dist-info/top_level.txt +2 -0
@@ -0,0 +1,92 @@
1
+ """
2
+ calculators/orca_engine.py - ORCA 受控引擎
3
+ ==========================================
4
+ 把 ORCA 作为本机实际可安装引擎:
5
+ probe 检测 orca.exe
6
+ prepare 写 .inp 输入、构造 argv(orca.exe input.inp)、算输入哈希
7
+ parse 从输出日志提取最终能量、收敛状态
8
+ """
9
+ from __future__ import annotations
10
+
11
+ import os
12
+ import re
13
+ import shutil
14
+ from pathlib import Path
15
+
16
+ from .base import CalculationEngine, JobRequest, PreparedJob, EngineNotFound
17
+
18
+ _DEFAULT_ORCA = r"E:\ORCA\software\ORCA6.1.1\orca.exe"
19
+ _DEFAULT_MSMPI_BIN = r"D:\Microsoft_MPI\Bin"
20
+
21
+
22
+ def find_mpiexec() -> str | None:
23
+ """探测本机可用的 MS-MPI / OpenMPI mpiexec 可执行文件。"""
24
+ found = shutil.which("mpiexec") or shutil.which("mpiexec.exe")
25
+ if found:
26
+ return found
27
+ cand = Path(_DEFAULT_MSMPI_BIN) / "mpiexec.exe"
28
+ return str(cand) if cand.is_file() else None
29
+
30
+
31
+ class OrcaEngine(CalculationEngine):
32
+ name = "ORCA"
33
+
34
+ def __init__(self, executable: str | None = None) -> None:
35
+ super().__init__(executable or _DEFAULT_ORCA)
36
+
37
+ def probe(self) -> bool:
38
+ return bool(self._executable) and Path(self._executable).is_file()
39
+
40
+ def has_mpi(self) -> bool:
41
+ return find_mpiexec() is not None
42
+
43
+ def mpi_env(self) -> dict[str, str]:
44
+ """返回包含 mpiexec 所在目录的环境变量副本,供并行 ORCA 子进程使用。"""
45
+ env = os.environ.copy()
46
+ mpi = find_mpiexec()
47
+ if mpi:
48
+ mpi_dir = str(Path(mpi).parent)
49
+ cur_path = env.get("PATH", "")
50
+ if mpi_dir.lower() not in cur_path.lower():
51
+ env["PATH"] = f"{mpi_dir}{os.pathsep}{cur_path}" if cur_path else mpi_dir
52
+ return env
53
+
54
+ def version(self) -> str:
55
+ # ORCA 版本从目录名推断;实际版本可在运行输出里取
56
+ return Path(self._executable).parent.name or "unknown"
57
+
58
+ def prepare(self, request: JobRequest, workdir: Path) -> PreparedJob:
59
+ if not self.probe():
60
+ raise EngineNotFound(
61
+ "未找到 ORCA(orca.exe)。请安装 ORCA 或在设置中指定路径。")
62
+ workdir.mkdir(parents=True, exist_ok=True)
63
+ input_path = workdir / f"{request.name}.inp"
64
+ input_path.write_text(request.input_text, encoding="utf-8")
65
+
66
+ input_hash = self.hash_text(request.input_text)
67
+ # 记录参数与版本,便于复现
68
+ (workdir / "job.meta").write_text(
69
+ f"engine={self.name}\nversion={self.version()}\n"
70
+ f"input_hash={input_hash}\nmethod={request.method}\n",
71
+ encoding="utf-8")
72
+
73
+ argv = [self._executable, str(input_path), *request.extra_args]
74
+ return PreparedJob(
75
+ workdir=workdir, input_path=input_path, argv=argv,
76
+ input_hash=input_hash, engine_version=self.version())
77
+
78
+ def parse(self, prepared: PreparedJob) -> dict:
79
+ log = prepared.workdir / "run.log"
80
+ if not log.exists():
81
+ return {"ok": False, "reason": "无输出日志"}
82
+ text = log.read_text(encoding="utf-8", errors="replace")
83
+
84
+ energies = re.findall(
85
+ r"FINAL SINGLE POINT ENERGY\s+(-?\d+\.\d+)", text)
86
+ converged = "ORCA TERMINATED NORMALLY" in text
87
+ return {
88
+ "ok": converged,
89
+ "final_energy_hartree": float(energies[-1]) if energies else None,
90
+ "converged": converged,
91
+ "input_hash": prepared.input_hash,
92
+ }
@@ -0,0 +1,300 @@
1
+ """
2
+ application/calculators/qc_input_generator.py - Gaussian (.gjf) 与 REST (ctrl.in) 输入卡生成器
3
+ ==================================================================================================
4
+ 专为有机光伏 (OSC) 给体/受体分子计算工作流打造:
5
+ 1. Gaussian 16 / 09 输入卡 (.gjf):
6
+ - 内置 OSC 常用预设(B3LYP-D3(BJ)/6-31G(d) 预优化、wB97XD/def2SVP、CAM-B3LYP TD-DFT 激发态、ESP 静电势)
7
+ - 支持 PCM/SMD 溶剂模型(氯仿 Chloroform、氯苯 Chlorobenzene、甲苯 Toluene 等)
8
+ 2. 复旦大学张颖/徐昕团队 REST (Rust-based Electronic Structure Toolkit) 输入卡 (ctrl.in):
9
+ - 严格遵循官方 TOML 规范,仅包含 [ctrl] 与 [geom] 两个控制区
10
+ - 支持杂化泛函 (b3lyp, pbe0, cam-b3lyp, wb97xd) 与旗舰第五阶双杂化泛函 (xyg3, xygjos, r-xdh7 + scc15, scsrpa)
11
+ - 自动拆分经验色散 (empirical_dispersion = "d3bj")、自动匹配 basis_path 与 auxbas_path、
12
+ 自动设置 spin_polarization 与 outputs (["fchk", "cube_orb", "molden", "dipole"])
13
+ """
14
+ from __future__ import annotations
15
+
16
+ from dataclasses import dataclass, field
17
+ from ..selection import SelectionService
18
+ from ...domain.document import MoleculeDocument
19
+ from ...domain.elements import get_element
20
+
21
+
22
+ @dataclass
23
+ class GaussianPreset:
24
+ label: str
25
+ route: str
26
+ description: str
27
+
28
+
29
+ OSC_GAUSSIAN_PRESETS: list[GaussianPreset] = [
30
+ GaussianPreset(
31
+ label="OSC 基态几何优化 · B3LYP-D3(BJ)/6-31G(d)",
32
+ route="#p B3LYP/6-31G(d) EmpiricalDispersion=GD3BJ opt freq",
33
+ description="有机光伏给体/受体骨架标准基态构型优化与无虚频验证",
34
+ ),
35
+ GaussianPreset(
36
+ label="OSC 前线轨道与偶极 · B3LYP-D3(BJ)/6-311G(d,p)",
37
+ route="#p B3LYP/6-311G(d,p) EmpiricalDispersion=GD3BJ opt pop=full gfinput",
38
+ description="计算精确 HOMO/LUMO 能级、偶极矩并输出轨道系数用于 Cube 渲染",
39
+ ),
40
+ GaussianPreset(
41
+ label="OSC 长程校正几何与轨道 · wB97XD/def2SVP",
42
+ route="#p wB97XD/def2SVP opt pop=full",
43
+ description="适合 A-D-A 型非富勒烯受体(如 Y6/ITIC)的长程校正泛函优化",
44
+ ),
45
+ GaussianPreset(
46
+ label="OSC 激发态吸收光谱 (TD-DFT) · CAM-B3LYP/6-311+G(d,p)",
47
+ route="#p CAM-B3LYP/6-311+G(d,p) TD=(NStates=10) pop=full",
48
+ description="计算前 10 个激发态 (S1~S10) 激发能、振子强度 f 与电荷转移特征",
49
+ ),
50
+ GaussianPreset(
51
+ label="OSC 激发态吸收光谱 (TD-DFT) · wB97XD/def2SVP",
52
+ route="#p wB97XD/def2SVP TD=(NStates=10) pop=full",
53
+ description="大体系给体/受体寡聚物快速 TD-DFT 激发态计算",
54
+ ),
55
+ GaussianPreset(
56
+ label="OSC 分子表面静电势 (ESP) · B3LYP/def2TZVP",
57
+ route="#p B3LYP/def2TZVP pop=chelpg out=wfn",
58
+ description="计算静电势电荷并输出 .wfn 波函数文件供 Multiwfn / MolForge 绘制 ESP",
59
+ ),
60
+ ]
61
+
62
+
63
+ @dataclass
64
+ class RestPreset:
65
+ label: str
66
+ xc: str
67
+ basis: str
68
+ auxbas: str = "def2-SV(P)-JKFIT"
69
+ empirical_dispersion: str = ""
70
+ post_ai_correction: str = ""
71
+ job_type: str = "energy"
72
+ eri_type: str = "ri-v"
73
+ description: str = ""
74
+
75
+
76
+ OSC_REST_PRESETS: list[RestPreset] = [
77
+ RestPreset(
78
+ label="REST 杂化泛函单点与轨道 · B3LYP-D3BJ / def2-TZVPP",
79
+ xc="b3lyp",
80
+ basis="def2-TZVPP",
81
+ empirical_dispersion="d3bj",
82
+ job_type="energy",
83
+ description="RI-V 加速 B3LYP-D3BJ 单点能与前线分子轨道输出",
84
+ ),
85
+ RestPreset(
86
+ label="REST 几何结构优化 · PBE0-D3BJ / def2-SVP (opt)",
87
+ xc="pbe0",
88
+ basis="def2-SVP",
89
+ empirical_dispersion="d3bj",
90
+ job_type="opt",
91
+ description="使用 LBFGS / geometric-pyo3 引擎做快速 DFT 结构优化",
92
+ ),
93
+ RestPreset(
94
+ label="REST 旗舰双杂化泛函 · XYG3 / def2-QZVPP",
95
+ xc="xyg3",
96
+ basis="def2-QZVPP",
97
+ empirical_dispersion="",
98
+ job_type="energy",
99
+ description="徐昕/张颖团队 XYG3 第五阶双杂化泛函高精度电子结构计算(无需额外色散校正)",
100
+ ),
101
+ RestPreset(
102
+ label="REST 高效双杂化泛函 · XYGJOS / def2-TZVPP",
103
+ xc="xygjos",
104
+ basis="def2-TZVPP",
105
+ empirical_dispersion="",
106
+ job_type="energy",
107
+ description="OS 异自旋标度双杂化泛函,兼顾大分子计算效率与高精度",
108
+ ),
109
+ RestPreset(
110
+ label="REST AI 增强重整化双杂化 · R-xDH7-SCC15 / def2-QZVPP",
111
+ xc="r-xdh7",
112
+ basis="def2-QZVPP",
113
+ post_ai_correction="scc15",
114
+ job_type="energy",
115
+ description="结合 SCC15 机器学习强关联校正的 R-xDH7 重整化双杂化泛函",
116
+ ),
117
+ RestPreset(
118
+ label="REST 随机相位近似 · scsRPA / def2-QZVPP",
119
+ xc="scsrpa",
120
+ basis="def2-QZVPP",
121
+ job_type="energy",
122
+ description="自旋分量标度随机相位近似 (scs-RPA),适合非共价相互作用与受体堆积体系",
123
+ ),
124
+ ]
125
+
126
+
127
+ def extract_xyz_lines(doc: MoleculeDocument) -> list[str]:
128
+ """从 MoleculeDocument 提取标准元素符号与 3D 坐标行。"""
129
+ doc.ensure_coordinates()
130
+ atom_ids = list(doc.topology.atom_ids)
131
+ n = len(atom_ids)
132
+ if n == 0:
133
+ return ["C 0.000000 0.000000 0.000000"]
134
+
135
+ coords = doc.coordinates.current.coords if (doc.has_3d and doc.coordinates.current is not None) else None
136
+ lines = []
137
+ for i, aid in enumerate(atom_ids):
138
+ atom = doc.topology.get_atom(aid)
139
+ elem = get_element(atom.atomic_num)
140
+ sym = elem.symbol if elem else "C"
141
+ if coords is not None and i < len(coords):
142
+ x, y, z = float(coords[i, 0]), float(coords[i, 1]), float(coords[i, 2])
143
+ else:
144
+ x2, y2 = doc.coords_2d.get(aid, (float(i * 1.4), 0.0))
145
+ x, y, z = float(x2), float(y2), 0.0
146
+ lines.append(f"{sym:<3s} {x:>14.8f} {y:>14.8f} {z:>14.8f}")
147
+ return lines
148
+
149
+
150
+ def export_document_to_xyz(doc: MoleculeDocument, path: str | Any) -> str:
151
+ """把当前 MoleculeDocument 导出为标准 XYZ 文件(纯计算/数据层,零 GUI 依赖)。"""
152
+ from pathlib import Path
153
+ p = Path(path)
154
+ p.parent.mkdir(parents=True, exist_ok=True)
155
+ atom_ids = list(doc.topology.atom_ids)
156
+ lines = extract_xyz_lines(doc)
157
+ text = f"{len(atom_ids)}\nMolForge canvas export · {doc.name}\n" + "\n".join(lines) + "\n"
158
+ with open(p, "w", encoding="utf-8", newline="\n") as fh:
159
+ fh.write(text)
160
+ return str(p)
161
+
162
+
163
+ def generate_gaussian_gjf(
164
+ doc: MoleculeDocument,
165
+ route: str = "#p B3LYP/6-31G(d) EmpiricalDispersion=GD3BJ opt freq",
166
+ charge: int = 0,
167
+ multiplicity: int = 1,
168
+ nproc: int = 16,
169
+ mem_gb: int = 16,
170
+ solvent: str = "",
171
+ chk_name: str = "",
172
+ ) -> str:
173
+ """生成可直接提交给 Gaussian 09/16 的 .gjf 输入文件文本。"""
174
+ stem = (doc.name or "molecule").replace(" ", "_")
175
+ chk = chk_name.strip() or f"{stem}.chk"
176
+ full_route = route.strip()
177
+ if not full_route.startswith("#"):
178
+ full_route = "#p " + full_route
179
+ if solvent and solvent.lower() not in ("none", "gas", "气相", "") and "scrf" not in full_route.lower():
180
+ full_route += f" SCRF=(PCM,Solvent={solvent})"
181
+
182
+ xyz_lines = extract_xyz_lines(doc)
183
+ lines = [
184
+ f"%chk={chk}",
185
+ f"%nprocshared={max(1, int(nproc))}",
186
+ f"%mem={max(1, int(mem_gb))}GB",
187
+ full_route,
188
+ "",
189
+ f"{doc.name or 'MolForge Structure'} | Generated by MolForge OSC Workbench",
190
+ "",
191
+ f"{int(charge)} {int(multiplicity)}",
192
+ *xyz_lines,
193
+ "",
194
+ ]
195
+ if "out=wfn" in full_route.lower():
196
+ lines.append(f"{stem}.wfn")
197
+ lines.append("")
198
+ lines.append("")
199
+ return "\n".join(lines)
200
+
201
+
202
+ def generate_rest_ctrl_in(
203
+ doc: MoleculeDocument,
204
+ xc: str = "b3lyp",
205
+ basis: str = "def2-TZVPP",
206
+ auxbas: str = "def2-SV(P)-JKFIT",
207
+ empirical_dispersion: str = "d3bj",
208
+ post_ai_correction: str = "",
209
+ job_type: str = "energy",
210
+ opt_engine: str = "lbfgs",
211
+ eri_type: str = "ri-v",
212
+ charge: float = 0.0,
213
+ spin: int = 1,
214
+ num_threads: int = 16,
215
+ print_level: int = 1,
216
+ basis_pool: str = "/mnt/e/YDW/REST/knowledge_base/rest_github/basis-set-pool",
217
+ outputs: list[str] | None = None,
218
+ ) -> str:
219
+ """
220
+ 生成符合复旦大学 REST (Rust-based Electronic Structure Toolkit) 规范的 TOML 输入卡 (ctrl.in)。
221
+ 严格满足:
222
+ - 仅含 [ctrl] 与 [geom] 两个 TOML 区块
223
+ - 方法关键词使用 xc,色散校正单独使用 empirical_dispersion
224
+ - 基组路径使用 basis_path 与 auxbas_path(根目录默认 /opt/rest_workspace/rest/basis-set-pool)
225
+ - charge 与 spin 位于 [ctrl] 区,分子结构位于 [geom] 区的 position 多行双引号字符串
226
+ """
227
+ xc_clean = xc.strip().lower()
228
+ disp_clean = empirical_dispersion.strip().lower()
229
+
230
+ # 若用户传入了如 "b3lyp-d3bj",自动拆分为 xc 与 empirical_dispersion
231
+ for suffix in ("-d3bj", "-d3", "-d4"):
232
+ if xc_clean.endswith(suffix):
233
+ xc_clean = xc_clean[: -len(suffix)]
234
+ disp_clean = suffix[1:]
235
+ break
236
+
237
+ # XYG3 型双杂化/RPA 泛函不额外加经验色散
238
+ no_disp_methods = {"xyg3", "xyg7", "xygjos", "scsrpa", "r-xdh7", "rpa", "zrps", "sbge2"}
239
+ if xc_clean in no_disp_methods:
240
+ disp_clean = ""
241
+
242
+ threads = max(10, int(num_threads))
243
+ spin_int = max(1, int(spin))
244
+ spin_pol = "true" if spin_int > 1 else "false"
245
+ pool = basis_pool.rstrip("/")
246
+ basis_path = f"{pool}/{basis.strip()}"
247
+ auxbas_path = f"{pool}/{auxbas.strip()}"
248
+ out_list = outputs if outputs is not None else ["fchk", "dipole"]
249
+ out_toml = "[" + ", ".join(f'"{o}"' for o in out_list) + "]"
250
+
251
+ ctrl_lines = [
252
+ "[ctrl]",
253
+ f'print_level = {int(print_level)}',
254
+ f'num_threads = {threads}',
255
+ f'job_type = "{job_type.strip()}"',
256
+ f'xc = "{xc_clean}"',
257
+ ]
258
+ if disp_clean:
259
+ ctrl_lines.append(f'empirical_dispersion = "{disp_clean}"')
260
+ if post_ai_correction.strip():
261
+ ctrl_lines.append(f'post_ai_correction = "{post_ai_correction.strip().lower()}"')
262
+ if job_type.strip() == "opt":
263
+ ctrl_lines.append(f'opt_engine = "{opt_engine.strip()}"')
264
+
265
+ ctrl_lines.extend([
266
+ f'eri_type = "{eri_type.strip()}"',
267
+ f'basis_path = "{basis_path}"',
268
+ ])
269
+ if eri_type.strip().lower() != "analytic":
270
+ ctrl_lines.append(f'auxbas_path = "{auxbas_path}"')
271
+
272
+ ctrl_lines.extend([
273
+ 'basis_type = "spheric"',
274
+ f'charge = {float(charge):.1f}',
275
+ f'spin = {float(spin_int):.1f}',
276
+ f'spin_polarization = {spin_pol}',
277
+ 'initial_guess = "sad"',
278
+ 'mixer = "diis"',
279
+ 'max_scf_cycle = 100',
280
+ f'outputs = {out_toml}',
281
+ ])
282
+ if xc_clean in ("rpa", "scsrpa", "r-xdh7"):
283
+ ctrl_lines.append("frequency_points = 20")
284
+
285
+ xyz_lines = extract_xyz_lines(doc)
286
+ xyz_block = "\n".join(xyz_lines)
287
+ safe_name = "".join(c if (c.isalnum() or c in "_-") and ord(c) < 128 else "_" for c in (doc.name or "molforge"))
288
+ clean_name = safe_name.strip("_") or "molforge_mol"
289
+
290
+ geom_lines = [
291
+ "",
292
+ "[geom]",
293
+ f'name = "{clean_name}"',
294
+ 'unit = "angstrom"',
295
+ 'position = """',
296
+ xyz_block,
297
+ '"""',
298
+ "",
299
+ ]
300
+ return "\n".join(ctrl_lines + geom_lines)
@@ -0,0 +1,29 @@
1
+ """引擎注册表:统一管理 ORCA / Gaussian / REST (Rust-based Electronic Structure Toolkit) 引擎。"""
2
+ from __future__ import annotations
3
+
4
+ from .base import CalculationEngine, EngineNotFound
5
+ from .orca_engine import OrcaEngine
6
+ from .gaussian_engine import GaussianEngine
7
+ from .rest_engine import RestEngine
8
+ from .calchem_engine import CalChemEngine
9
+
10
+
11
+ def _all_engines() -> list[CalculationEngine]:
12
+ return [CalChemEngine(), OrcaEngine(), GaussianEngine(), RestEngine()]
13
+
14
+
15
+ def available_engines() -> list[CalculationEngine]:
16
+ """返回本机 probe 成功的引擎。"""
17
+ return [e for e in _all_engines() if e.probe()]
18
+
19
+
20
+ def get_engine(name: str) -> CalculationEngine:
21
+ """按名称获取引擎;未安装时抛 EngineNotFound 并给出明确提示。"""
22
+ for e in _all_engines():
23
+ if e.name.lower() == name.lower():
24
+ if e.probe():
25
+ return e
26
+ raise EngineNotFound(
27
+ f"{name} 未安装或不可执行。请安装 {name} 或在计算面板生成输入卡文件。"
28
+ )
29
+ raise EngineNotFound(f"不支持的引擎:{name}")
@@ -0,0 +1,262 @@
1
+ """
2
+ calculators/rest_engine.py - 复旦大学 REST (Rust-based Electronic Structure Toolkit) 受控计算引擎
3
+ =================================================================================================
4
+ 支持:
5
+ - probe 检测本机或本地 WSL2 虚拟环境中的 rest 可执行程序
6
+ - prepare 生成 ctrl.in (TOML 格式) 并记录 SHA-256 哈希
7
+ - run_wsl 在本地 WSL2 中原生执行真实量子化学计算并秒级回传结果
8
+ - parse 解析 REST 输出日志与结果文件中的 SCF 能量、双杂化 (XYG3/XYGJOS/R-xDH7) 总能量、HOMO/LUMO、Mulliken 电荷及收敛状态
9
+ """
10
+ from __future__ import annotations
11
+
12
+ import json
13
+ import os
14
+ import re
15
+ import shutil
16
+ import subprocess
17
+ from pathlib import Path
18
+ from typing import Any, Callable, Dict, Optional
19
+
20
+ from .base import CalculationEngine, JobRequest, PreparedJob, EngineNotFound
21
+
22
+
23
+ WSL_REST_BIN = "/home/administrator/miniforge3/envs/rest-py311/bin/rest"
24
+ WSL_BASIS_POOL = "/mnt/e/YDW/REST/knowledge_base/rest_github/basis-set-pool"
25
+ HARTREE_TO_EV = 27.211386245988
26
+
27
+
28
+ def to_wsl_path(path: str | Path) -> str:
29
+ """将 Windows 本地路径转换为 WSL2 /mnt 路径。"""
30
+ p = Path(path).resolve()
31
+ drive = p.drive.replace(":", "").lower()
32
+ return f"/mnt/{drive}" + p.as_posix()[2:]
33
+
34
+
35
+ def parse_fchk_orbitals(fchk_path: Path) -> tuple[float | None, float | None]:
36
+ """从 formatted checkpoint (fchk) 文件提取真实 HOMO 与 LUMO 能级 (单位: eV)。"""
37
+ if not fchk_path.exists():
38
+ return None, None
39
+ try:
40
+ text = fchk_path.read_text(encoding="utf-8", errors="replace")
41
+ m_alpha = re.search(r"Number of alpha electrons\s+I\s+(\d+)", text)
42
+ if not m_alpha:
43
+ return None, None
44
+ n_alpha = int(m_alpha.group(1))
45
+
46
+ m_orb = re.search(r"Alpha Orbital Energies\s+R\s+N=\s+(\d+)\s*\n((?:\s*-?\d+\.\d+E[+-]\d+\s*)+)", text)
47
+ if not m_orb:
48
+ return None, None
49
+
50
+ raw_vals = m_orb.group(2).split()
51
+ energies_hartree = [float(v) for v in raw_vals]
52
+
53
+ homo_idx = n_alpha - 1
54
+ lumo_idx = n_alpha
55
+ homo_ev = round(energies_hartree[homo_idx] * HARTREE_TO_EV, 4) if 0 <= homo_idx < len(energies_hartree) else None
56
+ lumo_ev = round(energies_hartree[lumo_idx] * HARTREE_TO_EV, 4) if 0 <= lumo_idx < len(energies_hartree) else None
57
+ return homo_ev, lumo_ev
58
+ except Exception:
59
+ return None, None
60
+
61
+
62
+ class RestEngine(CalculationEngine):
63
+ name = "REST"
64
+
65
+ def __init__(self, executable: str | None = None) -> None:
66
+ exe = (
67
+ executable
68
+ or shutil.which("rest")
69
+ or "/opt/rest_workspace/rest/target/release/rest"
70
+ )
71
+ super().__init__(exe)
72
+
73
+ def probe(self) -> bool:
74
+ if bool(self._executable) and Path(self._executable).is_file():
75
+ return True
76
+ # 在 Windows 上检测本地 WSL2 rest 安装
77
+ if os.name == "nt":
78
+ try:
79
+ res = subprocess.run(
80
+ ["wsl.exe", "-d", "Ubuntu", "-e", "test", "-f", WSL_REST_BIN],
81
+ capture_output=True,
82
+ timeout=5,
83
+ )
84
+ return res.returncode == 0
85
+ except Exception:
86
+ return False
87
+ return False
88
+
89
+ def version(self) -> str:
90
+ return "REST-2026.1.1 (Fudan University Rust Electronic Structure Toolkit)"
91
+
92
+ def prepare(self, request: JobRequest, workdir: Path) -> PreparedJob:
93
+ if not self.probe():
94
+ raise EngineNotFound("未在系统或 WSL2 中找到 REST 可执行文件 (rest)。")
95
+ workdir.mkdir(parents=True, exist_ok=True)
96
+ input_path = workdir / "ctrl.in"
97
+ input_path.write_text(request.input_text, encoding="utf-8")
98
+ input_hash = self.hash_text(request.input_text)
99
+ (workdir / "job.meta").write_text(
100
+ f"engine={self.name}\nversion={self.version()}\ninput_hash={input_hash}\nmethod={request.method}\n",
101
+ encoding="utf-8",
102
+ )
103
+ argv = [self._executable, "-i", str(input_path), *request.extra_args]
104
+ return PreparedJob(
105
+ workdir=workdir, input_path=input_path, argv=argv,
106
+ input_hash=input_hash, engine_version=self.version()
107
+ )
108
+
109
+ def parse(self, prepared: PreparedJob) -> dict:
110
+ log = prepared.workdir / "run.log"
111
+ if not log.exists():
112
+ return {"ok": False, "reason": "无 REST 输出日志"}
113
+ text = log.read_text(encoding="utf-8", errors="replace")
114
+ return parse_rest_log_text(text, input_hash=prepared.input_hash, workdir=prepared.workdir)
115
+
116
+ def run_calculation(
117
+ self,
118
+ doc,
119
+ xc: str = "b3lyp",
120
+ basis: str = "def2-SVP",
121
+ num_threads: int = 4,
122
+ workdir: Optional[Path] = None,
123
+ log_callback: Optional[Callable[[str], None]] = None,
124
+ ) -> Dict[str, Any]:
125
+ """在本地 WSL2 中真实运行 REST 计算并直接返回解析结果(绝不伪造数据)。"""
126
+ from .qc_input_generator import generate_rest_ctrl_in
127
+ safe_name = "".join(c if (c.isalnum() or c in "_-") and ord(c) < 128 else "_" for c in (doc.name or "mol"))
128
+ clean_name = safe_name.strip("_") or "mol"
129
+ if workdir is None:
130
+ # 优先使用 E:\YDW\REST\run_<name> 以保证与 WSL 路径映射与写权限畅通
131
+ rest_root = Path(r"E:\YDW\REST")
132
+ if rest_root.exists():
133
+ workdir = rest_root / f"run_{clean_name}"
134
+ else:
135
+ from ...runtime import data_dir
136
+ workdir = data_dir() / "temp" / f"rest_{clean_name}"
137
+ workdir.mkdir(parents=True, exist_ok=True)
138
+
139
+ charge = float(doc.properties.get("charge", 0.0))
140
+ toml_content = generate_rest_ctrl_in(
141
+ doc,
142
+ xc=xc,
143
+ basis=basis,
144
+ auxbas="def2-universal-jkfit",
145
+ charge=charge,
146
+ num_threads=num_threads,
147
+ basis_pool=WSL_BASIS_POOL,
148
+ )
149
+ input_file = workdir / "ctrl.in"
150
+ input_file.write_text(toml_content, encoding="utf-8")
151
+
152
+ wsl_workdir = to_wsl_path(workdir)
153
+ cmd = [
154
+ "wsl.exe", "-d", "Ubuntu", "-e", "bash", "-c",
155
+ f"cd '{wsl_workdir}' && export REST_BASIS_DIR={WSL_BASIS_POOL} && {WSL_REST_BIN} -i ctrl.in",
156
+ ]
157
+ if log_callback:
158
+ log_callback(f"[WSL2 REST] 正在工作目录执行计算: {wsl_workdir}\n")
159
+ log_callback(f"[WSL2 REST] 运行指令: {' '.join(cmd)}\n")
160
+
161
+ res = subprocess.run(cmd, capture_output=True, timeout=180)
162
+ stdout_str = res.stdout.decode("utf-8", errors="replace")
163
+ stderr_str = res.stderr.decode("utf-8", errors="replace")
164
+ output_text = stdout_str + ("\n" + stderr_str if stderr_str else "")
165
+ (workdir / "run.log").write_text(output_text, encoding="utf-8")
166
+
167
+ if log_callback and output_text:
168
+ log_callback(output_text)
169
+
170
+ parsed = parse_rest_log_text(output_text, workdir=workdir)
171
+ parsed["exit_code"] = res.returncode
172
+ parsed["engine"] = self.version()
173
+ parsed["workdir"] = str(workdir)
174
+ return parsed
175
+
176
+
177
+ def parse_rest_log_text(text: str, input_hash: str = "", workdir: Optional[Path] = None) -> dict:
178
+ """解析 REST 量子化学程序输出文本及衍生结果文件,提取能量(Hartree/eV)、Mulliken电荷与轨道信息。"""
179
+ # 1. 匹配总能量 (The SCF energy / Total SCF energy / Total energy)
180
+ scf_matches = re.findall(
181
+ r"(?:The\s+SCF\s+energy|Total\s+SCF\s+energy|SCF\s+energy|Total\s+energy|Final\s+energy|E\((?:SCF|tot|XYG3|XYGJOS|R-xDH7[^)]*)\))\s*[:=]?\s*(-?\d+\.\d+)",
182
+ text,
183
+ flags=re.IGNORECASE,
184
+ )
185
+ homo_matches = re.findall(r"HOMO\s*(?:energy)?\s*[:=]?\s*(-?\d+\.\d+)\s*(?:a\.u\.|Hartree|eV)?", text, flags=re.IGNORECASE)
186
+ lumo_matches = re.findall(r"LUMO\s*(?:energy)?\s*[:=]?\s*(-?\d+\.\d+)\s*(?:a\.u\.|Hartree|eV)?", text, flags=re.IGNORECASE)
187
+
188
+ energy_au = float(scf_matches[-1]) if scf_matches else None
189
+ homo_val = float(homo_matches[-1]) if homo_matches else None
190
+ lumo_val = float(lumo_matches[-1]) if lumo_matches else None
191
+
192
+ if homo_val is not None and abs(homo_val) < 1.5:
193
+ homo_val *= HARTREE_TO_EV
194
+ if lumo_val is not None and abs(lumo_val) < 1.5:
195
+ lumo_val *= HARTREE_TO_EV
196
+
197
+ # 2. 迭代收敛与用时
198
+ converged = ("scf is converged" in text.lower()) or ("mission accomplished" in text.lower())
199
+ iter_match = re.search(r"SCF is converged after\s+(\d+)\s+iterations", text, re.IGNORECASE)
200
+ iterations = int(iter_match.group(1)) if iter_match else None
201
+
202
+ time_match = re.search(r"Overall\s*\|\s*:\s*([\d\.]+)\s*s", text)
203
+ elapsed_sec = float(time_match.group(1)) if time_match else None
204
+
205
+ # 3. 提取 Mulliken 电荷
206
+ mulliken_charges: dict[int, float] = {}
207
+ mull_block = re.search(r"Mulliken population analysis:\s*\n((?:\s*\d+-[A-Za-z]+\s*:\s*-?\d+\.\d+\s*\n)+)", text)
208
+ if mull_block:
209
+ for line in mull_block.group(1).splitlines():
210
+ m = re.match(r"\s*(\d+)-([A-Za-z]+)\s*:\s*(-?\d+\.\d+)", line)
211
+ if m:
212
+ idx = int(m.group(1))
213
+ val = float(m.group(3))
214
+ mulliken_charges[idx] = val
215
+
216
+ # 4. 若提供了工作目录,读取 rest_results.json 与 fchk 文件进行高精度数值校准
217
+ dipole_debye = None
218
+ if workdir and Path(workdir).is_dir():
219
+ wdir = Path(workdir)
220
+ json_file = wdir / "rest_results.json"
221
+ if json_file.exists():
222
+ try:
223
+ jdata = json.loads(json_file.read_text(encoding="utf-8"))
224
+ if "total_energy" in jdata and energy_au is None:
225
+ energy_au = float(jdata["total_energy"])
226
+ if "dipole_debye" in jdata:
227
+ dipole_debye = jdata["dipole_debye"]
228
+ except Exception:
229
+ pass
230
+
231
+ # 检查所有 *.fchk
232
+ for fchk in wdir.glob("*.fchk"):
233
+ h_fchk, l_fchk = parse_fchk_orbitals(fchk)
234
+ if h_fchk is not None and l_fchk is not None:
235
+ homo_val = h_fchk
236
+ lumo_val = l_fchk
237
+ break
238
+
239
+ gap_ev = round(lumo_val - homo_val, 4) if (homo_val is not None and lumo_val is not None) else None
240
+
241
+ return {
242
+ "ok": converged,
243
+ "software": "REST (Rust-based Electronic Structure Toolkit)",
244
+ "method": "DFT",
245
+ "basis": "def2-SVP",
246
+ "energy": round(energy_au * HARTREE_TO_EV, 4) if energy_au is not None else 0.0,
247
+ "energy_hartree": energy_au,
248
+ "final_energy_hartree": energy_au,
249
+ "final_energy_ev": round(energy_au * HARTREE_TO_EV, 6) if energy_au is not None else None,
250
+ "homo": homo_val if homo_val is not None else 0.0,
251
+ "lumo": lumo_val if lumo_val is not None else 0.0,
252
+ "homo_ev": homo_val,
253
+ "lumo_ev": lumo_val,
254
+ "gap": gap_ev if gap_ev is not None else 0.0,
255
+ "gap_ev": gap_ev,
256
+ "iterations": iterations,
257
+ "elapsed_seconds": elapsed_sec,
258
+ "mulliken_charges": mulliken_charges,
259
+ "dipole_debye": dipole_debye,
260
+ "converged": converged,
261
+ "input_hash": input_hash,
262
+ }