構造とエネルギー
ストレステンソルとセルの最適化
ストレステンソルを取得し、ASE のセルフィルターを使って原子位置と格子を同時に最適化します。
AOFDFTCalculator はエネルギー・力に加えてストレステンソルも計算できます (implemented_properties = ["energy", "free_energy", "forces", "stress"])。ASE のセルフィルターと組み合わせると、原子位置と格子定数を同時に最適化できます。
"""
Advance/OF-DFT example: optimize atomic positions and cell using the stress tensor.
Copyright (C) 2026 AdvanceSoft Corporation, All rights reserved.
"""
from ase.build import bulk
from ase.io import write
from ase.optimize import BFGS
from ase.units import GPa
try:
from ase.filters import FrechetCellFilter as CellFilter # ASE >= 3.23
except ImportError:
from ase.constraints import ExpCellFilter as CellFilter
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"
atoms = bulk("Al", "fcc", a=4.05).repeat((3, 3, 3)) # 3x3x3 primitive cells, 27 atoms
atoms.calc = AOFDFTCalculator(
console = False,
logging_file = "al_cell_opt.log",
kin_type = "AS26",
kin_model = "Crystal26",
vps_dir = VPS_DIR,
pao_dir = PAO_DIR,
max_cell_strain = 0.05, # the FFT grid is rebuilt when the cell deforms more than this
)
# forces and stress are obtained by automatic differentiation
stress = atoms.get_stress() # Voigt order (xx, yy, zz, yz, xz, xy), eV/Angstrom^3
print(f"Initial pressure: {-stress[:3].mean() / GPa:8.3f} GPa")
# relax the cell and the positions at the same time
opt = BFGS(CellFilter(atoms), logfile="al_cell_opt.txt")
opt.run(fmax=0.02, steps=50)
a, b, c, alpha, beta, gamma = atoms.cell.cellpar()
stress = atoms.get_stress()
print(f"Final pressure : {-stress[:3].mean() / GPa:8.3f} GPa")
print(f"Cell lengths : {a:.4f} {b:.4f} {c:.4f} Angstrom")
print(f"Cell angles : {alpha:.2f} {beta:.2f} {gamma:.2f} deg")
volume = atoms.get_volume() / len(atoms)
print(f"Volume : {volume:.3f} Angstrom^3/atom")
print(f"Lattice constant: {(4.0 * volume) ** (1.0 / 3.0):.3f} Angstrom (of the cubic fcc cell)")
write("al_optimized.cif", atoms)
実行結果の例
v1.0.0 (Crystal26) の結果です。
Initial pressure: 2.048 GPa
Final pressure : -0.025 GPa
Cell lengths : 8.6260 8.6260 8.6260 Angstrom
Cell angles : 60.00 60.00 60.00 deg
Volume : 16.809 Angstrom^3/atom
Lattice constant: 4.066 Angstrom (of the cubic fcc cell)
v1.0.0 (AS26) では、ストレスがエネルギーの体積微分と一致しません。そのため、セルの最適化で得られる格子定数 (この例では 4.066 Å) は、エネルギーが最小になる格子定数 (4.034 Å、状態方程式と体積弾性率 を参照) からずれます。格子定数を求めるときは、エネルギーと体積の関係からも確認してください。
ポイント
- セルには、fcc Al の基本単位格子を 3×3×3 に繰り返したもの (27 原子) を使っています。v1.0.0 では、基本単位格子 (1 原子) のように周期の短いセルで計算すると結果が変わるためです。
atoms.get_stress()は Voigt 表記 (xx, yy, zz, yz, xz, xy) の 6 成分を eV/ų 単位で返します。ase.units.GPaで割ると GPa に換算できます。圧力は対角成分の平均の符号を反転したものです。- 力とストレスは、全エネルギーを原子位置と格子ベクトルで自動微分して求めています。
- セルが変形しても、変形が小さいうちは FFT グリッドの点数を保ったまま計算を続けます。変形の大きさが
max_cell_strain(既定値 0.05) を超えると、カットオフエネルギーに基づいてグリッドが再生成されます。 - セルの対称性を保ったまま体積だけを最適化したい場合は、セルフィルターに
hydrostatic_strain=Trueを指定します。 - 体積とエネルギーの関係から平衡体積と体積弾性率を求める方法は、状態方程式と体積弾性率 をご覧ください。