構造とエネルギー

分子の構造最適化とポテンシャル曲線

孤立メタン分子の構造を ASE のオプティマイザで最適化し、C-H 結合を伸縮させたときのポテンシャル曲線を計算します。

カテゴリ
構造とエネルギー
使用する機能
kin_model="Molecule26"scf_style="molecule"ase.optimize.BFGSget_forces
スクリプト
ch4_relax.py

原子に働く力は自動微分で計算されるため、ASE のオプティマイザ (BFGS など) をそのまま使って構造最適化を行えます。分子の計算では、分子向けの学習済みモデル Molecule26 と SCF プリセット scf_style="molecule" を指定します。

ch4_relax.pyダウンロード
"""
Advance/OF-DFT example: structure optimization and potential energy curve of methane.

Copyright (C) 2026 AdvanceSoft Corporation, All rights reserved.
"""

import matplotlib.pyplot as plt
import numpy as np
from ase.build import molecule
from ase.io import write
from ase.optimize import BFGS

from aofdft.calculator import AOFDFTCalculator

VPS_DIR = "path/to/DFT_DATA19_AS/VPS"  # edit these two paths for your environment
PAO_DIR = "path/to/DFT_DATA19_AS/PAO"

# isolated molecule in a box: 4.0 Angstrom of vacuum on each side
atoms = molecule("CH4")
atoms.center(vacuum=4.0)

c_idx     = [a.index for a in atoms if a.symbol == "C"][0]
h_indices = [a.index for a in atoms if a.symbol == "H"]

atoms.calc = AOFDFTCalculator(
    console      = False,
    logging_file = "methane_scf.log",
    kin_type     = "AS26",
    kin_model    = "Molecule26",  # pre-trained model for molecules
    vps_dir      = VPS_DIR,
    pao_dir      = PAO_DIR,
    scf_style    = "molecule",    # SCF preset for molecules
)

# 1) structure optimization with an ASE optimizer
opt = BFGS(atoms, logfile="methane_opt.log")
opt.run(fmax=0.05)  # eV/Angstrom

eq_dist = atoms.get_distance(c_idx, h_indices[0])
print(f"Optimized C-H distance: {eq_dist:.3f} Angstrom")
write("methane_optimized.xyz", atoms)

# 2) potential energy curve: stretch all C-H bonds uniformly
c_pos     = atoms.positions[c_idx].copy()
units     = [(atoms.positions[i] - c_pos) / np.linalg.norm(atoms.positions[i] - c_pos) for i in h_indices]
distances = np.linspace(0.8, 2.0, 13)
energies  = []

for d in distances:
    for i, unit in zip(h_indices, units):
        atoms.positions[i] = c_pos + unit * d

    energies.append(atoms.get_potential_energy())
    print(f"C-H distance: {d:.2f} Angstrom, total energy: {energies[-1]:.4f} eV")

plt.plot(distances, np.array(energies) - min(energies), marker="o", label="AOF-DFT (Molecule26)")
plt.xlabel("C-H distance (Angstrom)")
plt.ylabel("Relative energy (eV)")
plt.legend()
plt.tight_layout()
plt.savefig("methane_EvsR.png", dpi=150)
print("Saved methane_EvsR.png")

実行結果の例

text
Optimized C-H distance: 1.210 Angstrom
このスクリプトで得られるメタン分子のポテンシャル曲線 (v1.0.0、Molecule26)。
このスクリプトで得られるメタン分子のポテンシャル曲線 (v1.0.0、Molecule26)。

解析事例 メタンの解析 では Kohn-Sham DFT との比較を行っており、C-H 結合距離は AOF-DFT で 1.205 Å、Kohn-Sham DFT で 1.217 Å とよく一致し、ポテンシャル曲線もほとんど一致することが示されています。解析事例の AOF-DFT の値は、この例の出力 (1.210 Å) と少し異なります。真空層の厚さなどの違いによると考えられます。真空層を 2.5 Å にすると、この例でも解析事例に近い値 (1.204 Å) になります。

AOF-DFT (Molecule26) と Kohn-Sham DFT のポテンシャル曲線の比較 (解析事例より)。
AOF-DFT (Molecule26) と Kohn-Sham DFT のポテンシャル曲線の比較 (解析事例より)。

ポイント

  • 孤立分子は、真空層を設けた周期セルの中に置いて計算します。atoms.center(vacuum=4.0) は各方向に 4.0 Å の真空層を追加します (セルの一辺は約 9.3 Å)。
  • 真空層が狭いと結果が変わります。この例では、真空層を 2.5、4.0、6.0 Å にすると、最適化後の C-H 結合距離は 1.204、1.210、1.211 Å、全エネルギーは −223.94、−225.19、−225.33 eV になります。新しく計算する系では、真空層を広げても結果が変わらないことを確認してください。
  • 同じ Calculator オブジェクトで構造を変えながら計算を続けると、直前の密度行列が次の SCF 計算の初期値として使われるため、2 回目以降の SCF は短い反復で収束します。
  • opt.run(fmax=0.05) は、すべての原子に働く力が 0.05 eV/Å 未満になるまで最適化を続けます。
  • Kohn-Sham DFT との比較計算を行う方法は、OpenMX による Kohn-Sham DFT との比較 をご覧ください。