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,84 @@
1
+ # -*- coding: utf-8 -*-
2
+ """一键流水线:fchk → cube → VMD渲染 → 能级图"""
3
+ import os, sys, subprocess, json, argparse
4
+
5
+ MULTIWFN = r"<MULTIWFN_DIR>\Multiwfn_3.8_bin_Win64\Multiwfn.exe"
6
+ VMD = r"<VMD_DIR>\vmd.exe"
7
+ TREND = os.path.dirname(os.path.abspath(__file__))
8
+
9
+ def gen_cube(fchk_path, orb_num, out_dir):
10
+ """用 Multiwfn 生成指定轨道的 cube 文件"""
11
+ inp = os.path.join(out_dir, "_in.txt")
12
+ # Multiwfn 命令序列: 200 (其他功能) -> 3 (生成cube) -> orb_num -> 3 -> 1
13
+ with open(inp, 'w') as f:
14
+ f.write(f"200\n3\n{orb_num}\n3\n1\n")
15
+ os.chdir(out_dir)
16
+ subprocess.run([MULTIWFN, fchk_path], stdin=open(inp), capture_output=True)
17
+ # Multiwfn 输出 orb000XXX.cub
18
+ cub = os.path.join(out_dir, f"orb{orb_num:07d}.cub")
19
+ return cub if os.path.exists(cub) else None
20
+
21
+ def render_cube(cub_path, out_name, out_dir, isoval=0.005):
22
+ """用 VMD + Tachyon 渲染 cube 为 bmp"""
23
+ tcl = os.path.join(TREND, "render_one.tcl")
24
+ out_base = os.path.join(out_dir, out_name)
25
+ cmd = [VMD, "-dispdev", "text", "-e", tcl, "-args", cub_path, out_base, str(isoval)]
26
+ subprocess.run(cmd, capture_output=True)
27
+ bmp = out_base + ".bmp"
28
+ return bmp if os.path.exists(bmp) else None
29
+
30
+ def main():
31
+ parser = argparse.ArgumentParser()
32
+ parser.add_argument('--input-dir', required=True, help='fchk 文件所在目录')
33
+ parser.add_argument('--output-dir', required=True, help='输出目录')
34
+ parser.add_argument('--molecules', required=True, help='逗号分隔的分子名列表')
35
+ parser.add_argument('--homo-orbitals', required=True, help='逗号分隔的 HOMO 轨道号(1-based)')
36
+ args = parser.parse_args()
37
+
38
+ mols = args.molecules.split(',')
39
+ homos = [int(x) for x in args.homo_orbitals.split(',')]
40
+ assert len(mols) == len(homos), "分子数和轨道号数不匹配"
41
+
42
+ os.makedirs(args.output_dir, exist_ok=True)
43
+ data = []
44
+
45
+ from extract_orb_energy import extract_molecule
46
+
47
+ for name, hnum in zip(mols, homos):
48
+ print(f"\n=== Processing {name} ===")
49
+ fchk = os.path.join(args.input_dir, f"{name}.fchk")
50
+ if not os.path.exists(fchk):
51
+ print(f" SKIP: {fchk} not found")
52
+ continue
53
+
54
+ # 1. 提取能量
55
+ d = extract_molecule(name, fchk, hnum)
56
+ data.append(d)
57
+ print(f" HOMO={d['homo_ev']} eV, LUMO={d['lumo_ev']} eV, Gap={d['gap_ev']} eV")
58
+
59
+ # 2. 生成 cube
60
+ mol_dir = os.path.join(args.output_dir, name)
61
+ os.makedirs(mol_dir, exist_ok=True)
62
+ cub_homo = gen_cube(fchk, hnum, mol_dir)
63
+ cub_lumo = gen_cube(fchk, hnum + 1, mol_dir)
64
+ print(f" cube files generated")
65
+
66
+ # 3. VMD 渲染
67
+ if cub_homo:
68
+ render_cube(cub_homo, f"{name}_HOMO", mol_dir)
69
+ print(f" HOMO rendered")
70
+ if cub_lumo:
71
+ render_cube(cub_lumo, f"{name}_LUMO", mol_dir)
72
+ print(f" LUMO rendered")
73
+
74
+ # 4. 拼合能级图
75
+ data_json = os.path.join(args.output_dir, "data.json")
76
+ with open(data_json, 'w') as f:
77
+ json.dump(data, f, indent=2)
78
+
79
+ from make_level_plot import make_plot
80
+ make_plot(data, args.output_dir, os.path.join(args.output_dir, "homo_lumo_levels.png"))
81
+ print(f"\n=== ALL DONE ===")
82
+
83
+ if __name__ == '__main__':
84
+ main()
@@ -0,0 +1,60 @@
1
+ # -*- coding: utf-8 -*-
2
+ # extract_levels.py
3
+ # 从 Gaussian fchk 提取 HOMO/LUMO 轨道能量 (Hartree -> eV)
4
+ # 数据来自 <D_DRIVE_YDW>\OSC\Object_1\Binary_Datas\B3LYP_6-311g(d,p)\
5
+ import re
6
+
7
+ HA2EV = 27.211386245988
8
+ BASE = r"<D_DRIVE_YDW>\OSC\Object_1\Binary_Datas\B3LYP_6-311g(d,p)"
9
+
10
+ # (显示名, fchk文件名, HOMO轨道号 1-based)
11
+ targets = [
12
+ ("BTP-ClFFCl", "ydw-BTP-ClFFCl_B3LYP.fchk", 407),
13
+ ("BTP-FClClF", "ydw-BTP-FClClF_B3LYP.fchk", 407),
14
+ ("BTP-FClFCl", "ydw-BTP-FClFCl_B3LYP.fchk", 407),
15
+ ("BTP-FFClCl", "ydw-BTP-FFClCl_B3LYP.fchk", 407),
16
+ ("HDO-4Cl", "ydw-HDO4Cl_B3LYP.fchk", 463),
17
+ ]
18
+
19
+ def read_orb_energies(path):
20
+ """流式读取 fchk, 返回 Alpha Orbital Energies 列表 (Hartree), 0-based"""
21
+ vals = []
22
+ n = None
23
+ started = False
24
+ with open(path, 'r') as f:
25
+ for ln in f:
26
+ if not started:
27
+ if ln.startswith("Alpha Orbital Energies"):
28
+ m = re.search(r'N=\s*(\d+)', ln)
29
+ n = int(m.group(1))
30
+ started = True
31
+ continue
32
+ for p in ln.split():
33
+ try:
34
+ vals.append(float(p.replace('D', 'E')))
35
+ except ValueError:
36
+ pass
37
+ if n is not None and len(vals) >= n:
38
+ break
39
+ return vals
40
+
41
+ print(f"{'Molecule':<14}{'HOMO#':>6}{'HOMO(eV)':>12}{'LUMO#':>6}{'LUMO(eV)':>12}{'Gap(eV)':>10}")
42
+ print("-" * 60)
43
+ results = {}
44
+ import os
45
+ for name, fname, hi in targets:
46
+ path = os.path.join(BASE, fname)
47
+ e = read_orb_energies(path)
48
+ eh = e[hi - 1] * HA2EV
49
+ el = e[hi] * HA2EV
50
+ gap = el - eh
51
+ results[name] = (eh, el, gap)
52
+ print(f"{name:<14}{hi:>6}{eh:>12.4f}{hi+1:>6}{el:>12.4f}{gap:>10.4f}")
53
+
54
+ # 存成字典供拼图脚本用
55
+ import json
56
+ out = {k: {"homo": round(v[0], 2), "lumo": round(v[1], 2), "gap": round(v[2], 2)}
57
+ for k, v in results.items()}
58
+ with open(os.path.join(os.path.dirname(__file__), "levels.json"), "w") as f:
59
+ json.dump(out, f, indent=2)
60
+ print("\nsaved -> levels.json")
@@ -0,0 +1,122 @@
1
+ # -*- coding: utf-8 -*-
2
+ # make_editable_pptx.py
3
+ # 把 HOMO/LUMO 轨道图 + 能级文本框 + 分子名文本框组装成可编辑 PPT
4
+ import os, json
5
+ from pptx import Presentation
6
+ from pptx.util import Inches, Pt, Emu
7
+ from pptx.dml.color import RGBColor
8
+ from pptx.enum.text import PP_ALIGN
9
+ from PIL import Image
10
+
11
+ LMO = r"<D_DRIVE_YDW>\OSC\Object_1\Binary_Datas\B3LYP_6-311g(d,p)\LMO"
12
+ OUT_DIR = r"<D_DRIVE_YDW>\OSC\Object_1\2610\工作三"
13
+ TMP_PNG = os.path.join(OUT_DIR, "_tmp_png")
14
+ os.makedirs(TMP_PNG, exist_ok=True)
15
+
16
+ with open(os.path.join(OUT_DIR, "levels.json")) as f:
17
+ lv = json.load(f)
18
+
19
+ # 列: (显示名, LMO 子目录名)
20
+ cols = [
21
+ ("BTP-ClFFCl", "ClFFCl"),
22
+ ("BTP-FClClF", "FClClF"),
23
+ ("BTP-FClFCl", "FClFCl"),
24
+ ("BTP-FFClCl", "FFClCl"),
25
+ ("HDO-4Cl", "HDO4Cl"),
26
+ ]
27
+
28
+ # ---------- 幻灯片 16:9 ----------
29
+ prs = Presentation()
30
+ prs.slide_width = Inches(13.333)
31
+ prs.slide_height = Inches(7.5)
32
+ slide = prs.slides.add_slide(prs.slide_layouts[6]) # blank
33
+
34
+ # 白底
35
+ from pptx.oxml.ns import qn
36
+ bg = slide.background
37
+ fill = bg.fill
38
+ fill.solid()
39
+ fill.fore_color.rgb = RGBColor(0xFF, 0xFF, 0xFF)
40
+
41
+ # ---------- 版式参数 (inch) ----------
42
+ MARGIN_X = 0.4
43
+ IMG_W = 2.2 # 每张轨道图边长
44
+ GAP_X = (13.333 - 2*MARGIN_X - 5*IMG_W) / 4 # 列间距
45
+ TOP_Y = 0.3 # 标题 y
46
+ ENERGY_H = 0.38
47
+ IMG_H = IMG_W
48
+ NAME_H = 0.4
49
+ ROW_GAP = 0.45 # 上下排之间的额外间距
50
+
51
+ # 上排 LUMO 起点
52
+ row1_img_y = 1.4
53
+ row1_energy_y = row1_img_y - ENERGY_H - 0.05
54
+ row1_name_y = row1_img_y + IMG_H + 0.05
55
+ # 下排 HOMO 起点
56
+ row2_img_y = row1_name_y + NAME_H + ROW_GAP
57
+ row2_energy_y = row2_img_y - ENERGY_H - 0.05
58
+ row2_name_y = row2_img_y + IMG_H + 0.05
59
+
60
+ def add_text(cx_center, y, w, h, text, size, bold=False):
61
+ """在以 cx_center(Emu) 为中心的文本框里写文字, 水平居中"""
62
+ left = Emu(int(cx_center - Inches(w)/2))
63
+ tb = slide.shapes.add_textbox(left, Inches(y), Inches(w), Inches(h))
64
+ tf = tb.text_frame
65
+ tf.margin_left = tf.margin_right = tf.margin_top = tf.margin_bottom = 0
66
+ tf.word_wrap = False
67
+ p = tf.paragraphs[0]
68
+ p.alignment = PP_ALIGN.CENTER
69
+ r = p.add_run()
70
+ r.text = text
71
+ r.font.name = "Arial"
72
+ r.font.size = Pt(size)
73
+ r.font.bold = bold
74
+ r.font.color.rgb = RGBColor(0, 0, 0)
75
+ return tb
76
+
77
+ def add_png_cell(sub, orb_kind, cx_center, img_y):
78
+ """放一张轨道图 (BMP->PNG), 居中于 cx_center"""
79
+ bmp = os.path.join(LMO, sub, f"{sub}_{orb_kind}.bmp")
80
+ png = os.path.join(TMP_PNG, f"{sub}_{orb_kind}.png")
81
+ if not os.path.exists(png):
82
+ Image.open(bmp).convert("RGB").save(png, "PNG")
83
+ left = Emu(int(cx_center - Inches(IMG_W)/2))
84
+ slide.shapes.add_picture(png, left, Inches(img_y),
85
+ width=Inches(IMG_W), height=Inches(IMG_H))
86
+
87
+ # ---------- 大标题 (左上角, 仿参考图) ----------
88
+ title_tb = slide.shapes.add_textbox(Inches(MARGIN_X), Inches(TOP_Y), Inches(6), Inches(0.6))
89
+ ttf = title_tb.text_frame
90
+ ttf.margin_left = ttf.margin_right = ttf.margin_top = ttf.margin_bottom = 0
91
+ tp = ttf.paragraphs[0]
92
+ tr = tp.add_run()
93
+ tr.text = "B3LYP/6-311g(d,p)"
94
+ tr.font.name = "Arial"
95
+ tr.font.size = Pt(32)
96
+ tr.font.bold = True
97
+ tr.font.color.rgb = RGBColor(0, 0, 0)
98
+
99
+ # ---------- 逐列填充 ----------
100
+ for i, (disp, sub) in enumerate(cols):
101
+ x_left = MARGIN_X + i * (IMG_W + GAP_X)
102
+ cx = Emu(int(Inches(x_left + IMG_W/2)))
103
+
104
+ # 上排: LUMO
105
+ add_png_cell(sub, "LUMO", cx, row1_img_y)
106
+ add_text(cx, row1_energy_y, 2.2, ENERGY_H,
107
+ f"{lv[disp]['lumo']:.2f} eV", 18, bold=False)
108
+ add_text(cx, row1_name_y, 2.4, NAME_H, disp, 20, bold=True)
109
+
110
+ # 下排: HOMO
111
+ add_png_cell(sub, "HOMO", cx, row2_img_y)
112
+ add_text(cx, row2_energy_y, 2.2, ENERGY_H,
113
+ f"{lv[disp]['homo']:.2f} eV", 18, bold=False)
114
+ add_text(cx, row2_name_y, 2.4, NAME_H, disp, 20, bold=True)
115
+
116
+ # 行侧标 (LUMO / HOMO) 参考图没有, 不画
117
+
118
+ out = os.path.join(OUT_DIR, "HOMO_LUMO_B3LYP_6-311gdp.pptx")
119
+ prs.save(out)
120
+ print("saved:", out)
121
+ print(f"row1: energy_y={row1_energy_y:.2f} img_y={row1_img_y:.2f} name_y={row1_name_y:.2f}")
122
+ print(f"row2: energy_y={row2_energy_y:.2f} img_y={row2_img_y:.2f} name_y={row2_name_y:.2f}")
@@ -0,0 +1,66 @@
1
+ # -*- coding: utf-8 -*-
2
+ # make_energy_table.py
3
+ # 生成可编辑 Excel 能级表
4
+ import json, os
5
+ from openpyxl import Workbook
6
+ from openpyxl.styles import Font, Alignment, PatternFill, Border, Side
7
+
8
+ OUT_DIR = r"<D_DRIVE_YDW>\OSC\Object_1\2610\工作三"
9
+ with open(os.path.join(OUT_DIR, "levels.json")) as f:
10
+ lv = json.load(f)
11
+
12
+ order = ["BTP-ClFFCl", "BTP-FClClF", "BTP-FClFCl", "BTP-FFClCl", "HDO-4Cl"]
13
+
14
+ wb = Workbook()
15
+ ws = wb.active
16
+ ws.title = "HOMO_LUMO"
17
+
18
+ thin = Side(border_style="thin", color="000000")
19
+ border = Border(left=thin, right=thin, top=thin, bottom=thin)
20
+ center = Alignment(horizontal="center", vertical="center")
21
+ header_fill = PatternFill("solid", fgColor="D9E1F2")
22
+
23
+ # 表头
24
+ headers = ["Molecule", "HOMO (eV)", "LUMO (eV)", "Gap (eV)"]
25
+ for j, h in enumerate(headers, 1):
26
+ c = ws.cell(row=1, column=j, value=h)
27
+ c.font = Font(bold=True, size=12)
28
+ c.alignment = center
29
+ c.fill = header_fill
30
+ c.border = border
31
+
32
+ # 数据
33
+ for i, name in enumerate(order, 2):
34
+ ws.cell(row=i, column=1, value=name).alignment = center
35
+ ws.cell(row=i, column=2, value=round(lv[name]["homo"], 2)).alignment = center
36
+ ws.cell(row=i, column=3, value=round(lv[name]["lumo"], 2)).alignment = center
37
+ ws.cell(row=i, column=4, value=round(lv[name]["gap"], 2)).alignment = center
38
+ for j in range(1, 5):
39
+ ws.cell(row=i, column=j).border = border
40
+ ws.cell(row=i, column=j).font = Font(size=12)
41
+
42
+ # 列宽
43
+ ws.column_dimensions["A"].width = 18
44
+ ws.column_dimensions["B"].width = 14
45
+ ws.column_dimensions["C"].width = 14
46
+ ws.column_dimensions["D"].width = 12
47
+
48
+ # 第二张 sheet: 换算说明
49
+ ws2 = wb.create_sheet("说明")
50
+ ws2["A1"] = "数据来源"
51
+ ws2["A1"].font = Font(bold=True, size=12)
52
+ notes = [
53
+ "计算级别: B3LYP/6-311g(d,p), 真空, 几何优化最终结构",
54
+ "fchk 路径: D:\\YDW\\OSC\\Object_1\\Binary_Datas\\B3LYP_6-311g(d,p)\\",
55
+ "HOMO 轨道号: BTP 系列 = 407, HDO-4Cl = 463",
56
+ "LUMO 轨道号: BTP 系列 = 408, HDO-4Cl = 464",
57
+ "换算系数: 1 Hartree = 27.211386245988 eV",
58
+ "Gap = LUMO - HOMO",
59
+ ]
60
+ for i, t in enumerate(notes, 2):
61
+ ws2.cell(row=i, column=1, value=t)
62
+ ws2.column_dimensions["A"].width = 80
63
+
64
+ out = os.path.join(OUT_DIR, "HOMO_LUMO_能级表.xlsx")
65
+ wb.save(out)
66
+ print("saved:", out)
@@ -0,0 +1,148 @@
1
+ # -*- coding: utf-8 -*-
2
+ # make_level_lines_diagram.py
3
+ # 水平线 + 轨道小图 + Gap 箭头风格
4
+ import json, os
5
+ from pptx import Presentation
6
+ from pptx.util import Inches, Pt, Emu
7
+ from pptx.dml.color import RGBColor
8
+ from pptx.enum.text import PP_ALIGN, MSO_ANCHOR
9
+ from pptx.enum.shapes import MSO_CONNECTOR, MSO_SHAPE
10
+ from PIL import Image
11
+
12
+ OUT_DIR = r"<D_DRIVE_YDW>\OSC\Object_1\2610\工作三"
13
+ LMO = r"<D_DRIVE_YDW>\OSC\Object_1\Binary_Datas\B3LYP_6-311g(d,p)\LMO"
14
+ TMP = os.path.join(OUT_DIR, "_orb_png")
15
+ os.makedirs(TMP, exist_ok=True)
16
+
17
+ with open(os.path.join(OUT_DIR, "levels.json")) as f:
18
+ lv = json.load(f)
19
+
20
+ order = ["BTP-ClFFCl", "BTP-FClClF", "BTP-FClFCl", "BTP-FFClCl", "HDO-4Cl", "p4PM6"]
21
+ submap = {
22
+ "BTP-ClFFCl": "ClFFCl",
23
+ "BTP-FClClF": "FClClF",
24
+ "BTP-FClFCl": "FClFCl",
25
+ "BTP-FFClCl": "FFClCl",
26
+ "HDO-4Cl": "HDO4Cl",
27
+ "p4PM6": "p4PM6",
28
+ }
29
+
30
+ prs = Presentation()
31
+ prs.slide_width = Inches(13.333)
32
+ prs.slide_height = Inches(7.5)
33
+ slide = prs.slides.add_slide(prs.slide_layouts[6])
34
+ slide.background.fill.solid()
35
+ slide.background.fill.fore_color.rgb = RGBColor(0xFF, 0xFF, 0xFF)
36
+
37
+ # ---------- 绘图区 ----------
38
+ X0, X1 = 1.5, 12.5
39
+ Y_TOP, Y_BOT = 1.0, 6.2
40
+ E_TOP, E_BOT = -2.5, -6.5
41
+
42
+ def e2y(E):
43
+ return Y_TOP + (E_TOP - E) / (E_TOP - E_BOT) * (Y_BOT - Y_TOP)
44
+
45
+ # ---------- 纵轴 ----------
46
+ axis = slide.shapes.add_connector(MSO_CONNECTOR.STRAIGHT,
47
+ Inches(X0), Inches(Y_TOP), Inches(X0), Inches(Y_BOT))
48
+ axis.line.color.rgb = RGBColor(0, 0, 0)
49
+ axis.line.width = Pt(1.5)
50
+
51
+ for E in [round(-2.5 - i*0.5, 1) for i in range(9)]:
52
+ y = e2y(E)
53
+ tick = slide.shapes.add_connector(MSO_CONNECTOR.STRAIGHT,
54
+ Inches(X0-0.08), Inches(y), Inches(X0), Inches(y))
55
+ tick.line.color.rgb = RGBColor(0, 0, 0)
56
+ tick.line.width = Pt(1)
57
+ tb = slide.shapes.add_textbox(Inches(X0-0.85), Inches(y-0.13), Inches(0.75), Inches(0.26))
58
+ tf = tb.text_frame
59
+ tf.margin_left = tf.margin_right = tf.margin_top = tf.margin_bottom = 0
60
+ p = tf.paragraphs[0]; p.alignment = PP_ALIGN.RIGHT
61
+ r = p.add_run(); r.text = f"{E:.1f}"
62
+ r.font.name = "Arial"; r.font.size = Pt(12)
63
+ r.font.color.rgb = RGBColor(0, 0, 0)
64
+
65
+ # 纵轴标题
66
+ tb = slide.shapes.add_textbox(Inches(0.15), Inches(2.3), Inches(0.5), Inches(2.5))
67
+ tf = tb.text_frame
68
+ tf.margin_left = tf.margin_right = tf.margin_top = tf.margin_bottom = 0
69
+ p = tf.paragraphs[0]; p.alignment = PP_ALIGN.CENTER
70
+ r = p.add_run(); r.text = "Energy Level (eV)"
71
+ r.font.name = "Arial"; r.font.size = Pt(16); r.font.bold = True
72
+ r.font.color.rgb = RGBColor(0, 0, 0)
73
+ tb.rotation = 270
74
+
75
+ # ---------- 每列 ----------
76
+ IMG = 1.0 # 轨道小图边长 (从 1.3 缩到 1.0)
77
+ LINE_W = 0.8 # HOMO/LUMO 水平线长度
78
+ n = len(order)
79
+ x_centers = [X0 + 0.6 + (X1 - X0 - 1.2) * i / (n-1) for i in range(n)]
80
+
81
+ def add_text_cx(cx, y, w, h, text, size, bold=False, color=(0,0,0)):
82
+ left = Emu(int(Inches(cx) - Inches(w)/2))
83
+ tb = slide.shapes.add_textbox(left, Inches(y), Inches(w), Inches(h))
84
+ tf = tb.text_frame
85
+ tf.margin_left = tf.margin_right = tf.margin_top = tf.margin_bottom = 0
86
+ p = tf.paragraphs[0]; p.alignment = PP_ALIGN.CENTER
87
+ r = p.add_run(); r.text = text
88
+ r.font.name = "Arial"; r.font.size = Pt(size); r.font.bold = bold
89
+ r.font.color.rgb = RGBColor(*color)
90
+ return tb
91
+
92
+ def bmp2png(bmp_path, png_path):
93
+ if not os.path.exists(png_path):
94
+ Image.open(bmp_path).convert("RGB").save(png_path, "PNG")
95
+ return png_path
96
+
97
+ for i, name in enumerate(order):
98
+ cx = x_centers[i]
99
+ sub = submap[name]
100
+ y_lumo = e2y(lv[name]["lumo"])
101
+ y_homo = e2y(lv[name]["homo"])
102
+
103
+ # LUMO 水平线 (红)
104
+ lumo_line = slide.shapes.add_connector(MSO_CONNECTOR.STRAIGHT,
105
+ Inches(cx - LINE_W/2), Inches(y_lumo),
106
+ Inches(cx + LINE_W/2), Inches(y_lumo))
107
+ lumo_line.line.color.rgb = RGBColor(0xE0, 0x30, 0x30)
108
+ lumo_line.line.width = Pt(3.5)
109
+
110
+ # HOMO 水平线 (黑)
111
+ homo_line = slide.shapes.add_connector(MSO_CONNECTOR.STRAIGHT,
112
+ Inches(cx - LINE_W/2), Inches(y_homo),
113
+ Inches(cx + LINE_W/2), Inches(y_homo))
114
+ homo_line.line.color.rgb = RGBColor(0x20, 0x20, 0x20)
115
+ homo_line.line.width = Pt(3.5)
116
+
117
+ # Gap 竖线 (从 LUMO 到 HOMO)
118
+ gap_line = slide.shapes.add_connector(MSO_CONNECTOR.STRAIGHT,
119
+ Inches(cx), Inches(y_lumo),
120
+ Inches(cx), Inches(y_homo))
121
+ gap_line.line.color.rgb = RGBColor(0x40, 0x60, 0x90)
122
+ gap_line.line.width = Pt(1.5)
123
+
124
+ # Gap 数值 (紧贴竖线右侧)
125
+ add_text_cx(cx + 0.35, (y_lumo+y_homo)/2 - 0.18, 1.0, 0.36,
126
+ f"{lv[name]['gap']:.2f} eV", 14, bold=True, color=(0x40,0x60,0x90))
127
+
128
+ # LUMO 轨道小图 (紧贴 LUMO 线上方)
129
+ lumo_png = bmp2png(os.path.join(LMO, sub, f"{sub}_LUMO.bmp"),
130
+ os.path.join(TMP, f"{sub}_LUMO.png"))
131
+ img_left = Emu(int(Inches(cx) - Inches(IMG)/2))
132
+ slide.shapes.add_picture(lumo_png, img_left, Inches(y_lumo - IMG - 0.05),
133
+ width=Inches(IMG), height=Inches(IMG))
134
+
135
+ # HOMO 轨道小图 (紧贴 HOMO 线下方)
136
+ homo_png = bmp2png(os.path.join(LMO, sub, f"{sub}_HOMO.bmp"),
137
+ os.path.join(TMP, f"{sub}_HOMO.png"))
138
+ slide.shapes.add_picture(homo_png, img_left, Inches(y_homo + 0.05),
139
+ width=Inches(IMG), height=Inches(IMG))
140
+
141
+ # 底部分子名
142
+ add_text_cx(cx, y_homo + IMG + 0.15, 2.0, 0.4, name, 16, bold=True)
143
+
144
+ # 左侧 LUMO/HOMO 标签与纵轴刻度重叠, 直接删掉; 颜色已区分红=LUMO 黑=HOMO
145
+
146
+ out = os.path.join(OUT_DIR, "能级图_水平线轨道_B3LYP.pptx")
147
+ prs.save(out)
148
+ print("saved:", out)
@@ -0,0 +1,148 @@
1
+ # -*- coding: utf-8 -*-
2
+ # make_rectangle_diagram.py
3
+ # 矩形条能级图: 每个分子一个矩形, 上沿=LUMO, 下沿=HOMO, 仿论文图D风格
4
+ import json, os
5
+ from pptx import Presentation
6
+ from pptx.util import Inches, Pt, Emu
7
+ from pptx.dml.color import RGBColor
8
+ from pptx.enum.text import PP_ALIGN, MSO_ANCHOR
9
+ from pptx.enum.shapes import MSO_SHAPE
10
+
11
+ OUT_DIR = r"<D_DRIVE_YDW>\OSC\Object_1\2610\工作三"
12
+ with open(os.path.join(OUT_DIR, "levels.json")) as f:
13
+ lv = json.load(f)
14
+
15
+ order = ["BTP-ClFFCl", "BTP-FClClF", "BTP-FClFCl", "BTP-FFClCl", "HDO-4Cl", "p4PM6"]
16
+ colors = {
17
+ "BTP-ClFFCl": RGBColor(0xFF, 0x8C, 0x00),
18
+ "BTP-FClClF": RGBColor(0x3C, 0xB3, 0x71),
19
+ "BTP-FClFCl": RGBColor(0x46, 0x82, 0xB4),
20
+ "BTP-FFClCl": RGBColor(0x93, 0x70, 0xDB),
21
+ "HDO-4Cl": RGBColor(0xFF, 0x14, 0x93),
22
+ "p4PM6": RGBColor(0x00, 0xBF, 0xBF),
23
+ }
24
+
25
+ prs = Presentation()
26
+ prs.slide_width = Inches(13.333)
27
+ prs.slide_height = Inches(7.5)
28
+ slide = prs.slides.add_slide(prs.slide_layouts[6])
29
+
30
+ # 白底
31
+ slide.background.fill.solid()
32
+ slide.background.fill.fore_color.rgb = RGBColor(0xFF, 0xFF, 0xFF)
33
+
34
+ # ---------- 绘图区参数 (inch) ----------
35
+ X0, X1 = 1.6, 12.6 # 纵轴左右
36
+ Y_TOP, Y_BOT = 0.7, 6.6 # 纵轴上下
37
+ E_TOP, E_BOT = -2.5, -6.0 # 纵轴能量范围 (p4PM6 LUMO=-2.87, 上界放宽)
38
+
39
+ def e2y(E):
40
+ """能量 eV -> y 坐标 (inch)"""
41
+ return Y_TOP + (E_TOP - E) / (E_TOP - E_BOT) * (Y_BOT - Y_TOP)
42
+
43
+ # ---------- 纵轴 ----------
44
+ # 纵轴线
45
+ axis = slide.shapes.add_connector(1, Inches(X0), Inches(Y_TOP), Inches(X0), Inches(Y_BOT))
46
+ axis.line.color.rgb = RGBColor(0, 0, 0)
47
+ axis.line.width = Pt(1.5)
48
+
49
+ # 纵轴刻度 -2.5, -3.0, ..., -6.0
50
+ for E in [round(-2.5 - i*0.5, 1) for i in range(8)]:
51
+ y = e2y(E)
52
+ tick = slide.shapes.add_connector(1, Inches(X0-0.08), Inches(y), Inches(X0), Inches(y))
53
+ tick.line.color.rgb = RGBColor(0, 0, 0)
54
+ tick.line.width = Pt(1)
55
+ tb = slide.shapes.add_textbox(Inches(X0-0.9), Inches(y-0.15), Inches(0.8), Inches(0.3))
56
+ tf = tb.text_frame
57
+ tf.margin_left = tf.margin_right = tf.margin_top = tf.margin_bottom = 0
58
+ p = tf.paragraphs[0]
59
+ p.alignment = PP_ALIGN.RIGHT
60
+ r = p.add_run()
61
+ r.text = f"{E:.1f}"
62
+ r.font.name = "Arial"
63
+ r.font.size = Pt(14)
64
+ r.font.color.rgb = RGBColor(0, 0, 0)
65
+
66
+ # 纵轴标题 "Energy Level (eV)" 竖排
67
+ tb = slide.shapes.add_textbox(Inches(0.2), Inches(2.5), Inches(0.5), Inches(2.5))
68
+ tf = tb.text_frame
69
+ tf.margin_left = tf.margin_right = tf.margin_top = tf.margin_bottom = 0
70
+ p = tf.paragraphs[0]
71
+ p.alignment = PP_ALIGN.CENTER
72
+ r = p.add_run()
73
+ r.text = "Energy Level (eV)"
74
+ r.font.name = "Arial"
75
+ r.font.size = Pt(18)
76
+ r.font.bold = True
77
+ r.font.color.rgb = RGBColor(0, 0, 0)
78
+ # 竖排
79
+ tb.rotation = 270
80
+
81
+ # ---------- 5 个矩形 ----------
82
+ RECT_W = 1.0
83
+ n = len(order)
84
+ x_gap = (X1 - X0 - n * RECT_W) / (n - 1)
85
+
86
+ for i, name in enumerate(order):
87
+ x_left = X0 + 0.4 + i * (RECT_W + x_gap)
88
+ y_lumo = e2y(lv[name]["lumo"])
89
+ y_homo = e2y(lv[name]["homo"])
90
+ h = y_homo - y_lumo
91
+
92
+ # 矩形 (透明填充, 彩色粗边框)
93
+ sh = slide.shapes.add_shape(MSO_SHAPE.RECTANGLE,
94
+ Inches(x_left), Inches(y_lumo),
95
+ Inches(RECT_W), Inches(h))
96
+ sh.fill.background()
97
+ sh.line.color.rgb = colors[name]
98
+ sh.line.width = Pt(3.5)
99
+ # 去掉阴影
100
+ sh.shadow.inherit = False
101
+
102
+ # 矩形中间竖排分子名
103
+ tb = slide.shapes.add_textbox(Inches(x_left), Inches(y_lumo + h/2 - 0.3),
104
+ Inches(RECT_W), Inches(0.6))
105
+ tf = tb.text_frame
106
+ tf.margin_left = tf.margin_right = tf.margin_top = tf.margin_bottom = 0
107
+ tf.vertical_anchor = MSO_ANCHOR.MIDDLE
108
+ p = tf.paragraphs[0]
109
+ p.alignment = PP_ALIGN.CENTER
110
+ r = p.add_run()
111
+ r.text = name
112
+ r.font.name = "Arial"
113
+ r.font.size = Pt(14)
114
+ r.font.bold = True
115
+ r.font.color.rgb = colors[name]
116
+ tb.rotation = 270
117
+
118
+ # 矩形上方 LUMO 数值
119
+ tb = slide.shapes.add_textbox(Inches(x_left-0.3), Inches(y_lumo-0.45),
120
+ Inches(RECT_W+0.6), Inches(0.35))
121
+ tf = tb.text_frame
122
+ tf.margin_left = tf.margin_right = tf.margin_top = tf.margin_bottom = 0
123
+ p = tf.paragraphs[0]
124
+ p.alignment = PP_ALIGN.CENTER
125
+ r = p.add_run()
126
+ r.text = f"{lv[name]['lumo']:.2f}"
127
+ r.font.name = "Arial"
128
+ r.font.size = Pt(16)
129
+ r.font.bold = True
130
+ r.font.color.rgb = RGBColor(0, 0, 0)
131
+
132
+ # 矩形下方 HOMO 数值
133
+ tb = slide.shapes.add_textbox(Inches(x_left-0.3), Inches(y_homo+0.1),
134
+ Inches(RECT_W+0.6), Inches(0.35))
135
+ tf = tb.text_frame
136
+ tf.margin_left = tf.margin_right = tf.margin_top = tf.margin_bottom = 0
137
+ p = tf.paragraphs[0]
138
+ p.alignment = PP_ALIGN.CENTER
139
+ r = p.add_run()
140
+ r.text = f"{lv[name]['homo']:.2f}"
141
+ r.font.name = "Arial"
142
+ r.font.size = Pt(16)
143
+ r.font.bold = True
144
+ r.font.color.rgb = RGBColor(0, 0, 0)
145
+
146
+ out = os.path.join(OUT_DIR, "能级图_矩形条_B3LYP.pptx")
147
+ prs.save(out)
148
+ print("saved:", out)
@@ -0,0 +1,45 @@
1
+ # -*- coding: utf-8 -*-
2
+ # verify_from_log.py
3
+ # 直接从 Gaussian log 抓最后一次 SCF 的 HOMO/LUMO (Hartree) -> eV
4
+ import re, os
5
+
6
+ HA2EV = 27.211386245988
7
+ BASE = r"<D_DRIVE_YDW>\OSC\Object_1\Binary_Datas\B3LYP_6-311g(d,p)"
8
+ files = [
9
+ ("BTP-ClFFCl", "ydw-BTP-ClFFCl_B3LYP.log"),
10
+ ("BTP-FClClF", "ydw-BTP-FClClF_B3LYP.log"),
11
+ ("BTP-FClFCl", "ydw-BTP-FClFCl_B3LYP.log"),
12
+ ("BTP-FFClCl", "ydw-BTP-FFClCl_B3LYP.log"),
13
+ ("HDO-4Cl", "ydw-HDO4Cl_B3LYP.log"),
14
+ ]
15
+
16
+ occ_re = re.compile(r'Alpha\s+occ\.\s+eigenvalues\s*--\s*(.*)')
17
+ virt_re = re.compile(r'Alpha\s+virt\.\s+eigenvalues\s*--\s*(.*)')
18
+
19
+ def parse(path):
20
+ occ_vals, virt_vals = [], []
21
+ last_occ_block, last_virt_block = [], []
22
+ with open(path, 'r', errors='ignore') as f:
23
+ for ln in f:
24
+ mo = occ_re.search(ln)
25
+ mv = virt_re.search(ln)
26
+ if mo:
27
+ raw = mo.group(1)
28
+ raw = re.sub(r'(?<=\d)(?=-)', ' ', raw) # 相邻负数之间补空格
29
+ nums = [float(x) for x in raw.split()]
30
+ # 新的一组 occ 行: 如果上一组 occ 之后已经出现过 virt, 说明是新一轮 SCF, 重置
31
+ if last_virt_block:
32
+ last_occ_block, last_virt_block = [], []
33
+ last_occ_block.extend(nums)
34
+ elif mv:
35
+ raw = re.sub(r'(?<=\d)(?=-)', ' ', mv.group(1))
36
+ nums = [float(x) for x in raw.split()]
37
+ last_virt_block.extend(nums)
38
+ # 最后一轮的 HOMO = occ 块最后一个, LUMO = virt 块第一个
39
+ return last_occ_block[-1], last_virt_block[0]
40
+
41
+ print(f"{'Molecule':<14}{'HOMO(Ha)':>12}{'HOMO(eV)':>10}{'LUMO(Ha)':>12}{'LUMO(eV)':>10}")
42
+ print("-" * 60)
43
+ for name, fn in files:
44
+ eh, el = parse(os.path.join(BASE, fn))
45
+ print(f"{name:<14}{eh:>12.6f}{eh*HA2EV:>10.3f}{el:>12.6f}{el*HA2EV:>10.3f}")