2. 依存関係を隔離して導入
Linux
新しい Python 環境と適切な PyTorch を用います。ソースの宣言は Python >=3.8 ですが依存関係が上位版を要求する場合があり、例は実行確認前の Python 3.11 を対象とします。pip freeze と重みのハッシュを保存します。
python -m pip install torch
python -m pip install 'sevenn @ git+https://github.com/MDIL-SNU/SevenNet.git@209339d4eb4c1717f906c4cb715629159f00f88c' ase
python -m pip freeze
公式出典期待される結果
記録した環境で計算器と ASE を import でき、数値結果はまだ主張しません。
3. レビュー用に作成した計算器例を保存
Linux
付属コードを sevennet0_relax.py として保存します。公式 API に基づく本レビューの作成例で、上流の試験結果ではありません。固定ソースの 7net-0 は2024年7月の重みを選び、CPU と固定セルを明示し、出力先の既存ディレクトリを拒否します。
"""Authored review example using documented SevenNet/ASE APIs; NOT executed.
Sources: sevenn.calculator.SevenNetCalculator, ASE IO and BFGS documentation.
Fixed-cell geometry optimization only. No MD, reference DFT, or accuracy claim.
"""
import argparse
import json
from pathlib import Path
import numpy as np
from ase.io import read, write
from ase.optimize import BFGS
from sevenn.calculator import SevenNetCalculator
parser = argparse.ArgumentParser()
parser.add_argument("input_cif")
parser.add_argument("output_directory")
args = parser.parse_args()
atoms = read(args.input_cif)
if len(atoms) == 0 or not np.isfinite(atoms.positions).all():
raise ValueError("Empty structure or nonfinite coordinates")
if not atoms.pbc.all() or atoms.get_volume() <= 0:
raise ValueError("This example requires a fully periodic crystal with positive cell volume")
# The pinned SevenNet implementation resolves 7net-0 to its July 2024 checkpoint.
# The calculator checks each atomic number against the loaded model type_map.
atoms.calc = SevenNetCalculator(model="7net-0", device="cpu")
energy_initial = float(atoms.get_potential_energy())
forces_initial = atoms.get_forces()
if not np.isfinite(energy_initial) or not np.isfinite(forces_initial).all():
raise ValueError("Nonfinite initial energy or forces")
out = Path(args.output_directory)
out.mkdir(parents=True, exist_ok=False)
write(out / "initial.extxyz", atoms)
optimizer = BFGS(atoms, logfile=str(out / "optimization.log"), trajectory=str(out / "optimization.traj"))
# These are illustrative stopping settings, not upstream recommendations for all systems.
converged = bool(optimizer.run(fmax=0.05, steps=100))
energy_final = float(atoms.get_potential_energy())
forces_final = atoms.get_forces()
if not np.isfinite(energy_final) or not np.isfinite(forces_final).all():
raise ValueError("Nonfinite final energy or forces; inspect the partial output")
write(out / "relaxed.cif", atoms)
np.savez(out / "forces.npz", initial=forces_initial, final=forces_final)
record = {"model": "7net-0", "device": "cpu", "atom_count": len(atoms),
"elements": sorted(set(atoms.get_chemical_symbols())), "fixed_cell": True,
"energy_initial_eV": energy_initial, "energy_final_eV": energy_final,
"force_unit": "eV/Angstrom", "fmax_threshold_eV_per_Angstrom": 0.05,
"max_steps": 100, "converged": converged,
"final_max_force_eV_per_Angstrom": float(np.linalg.norm(forces_final, axis=1).max())}
(out / "results.json").write_text(json.dumps(record, indent=2) + "\n", encoding="utf-8")
print(json.dumps(record, indent=2))
if not converged:
raise SystemExit("Optimization reached its step limit; do not describe it as converged")
公式出典期待される結果
限定した BFGS の前に原子種、座標、周期セルを確認します。
4. エネルギー・力と限定最適化を計算
Linux
確認済み結晶と新しい出力先で実行します。入力と有限なエネルギー・力を保存し、100ステップで選択した力閾値に達しなければ明示的に停止します。
python sevennet0_relax.py input.cif sevennet_review
公式出典期待される結果
初期・最終構造、forces.npz、ログ・軌跡、converged を含む results.json を期待します。有限エネルギーは DFT との一致を意味しません。