跳转到正文
社区

SevenNet 与 ASE 的固定晶胞结构优化

为 ASE 晶体连接核验过的 SevenNet 计算器,计算能量和力,并在明确记录收敛状态的前提下执行有限步数的固定晶胞优化。

难度: 中等 费用: 免费 隐私: 本地 ~45 分钟
开始安装

你将能够

  • 生成可追溯的计算候选产物,并检查文档规定的验收条件。

你将构建什么

基于官方文档的审核稿。本批未执行此工作流,未验证安装、推理、优化或实验结果。

范围与输入

面向原子模拟研究人员。基线使用用户提供的全周期晶体 CIF、SevenNet-0 的 2024 年 7 月权重和 ASE BFGS,保持晶胞固定。这是几何优化,不是已验证分子动力学轨迹、带隙预测或变晶胞优化。明确选择较早的单任务权重用于示例,不宣称其优于新模型。

衔接、单位与产物

ASE 将 CIF 读成带晶格、周期性、原子序数和笛卡尔坐标的 Atoms。SevenNetCalculator 实现 ASE 计算器协议,并按实际 type_map 检查元素。拒绝缺失/不支持元素、无效坐标及非正晶胞体积。此处采用 ASE 单位:能量 eV、位置 Angstrom、力 eV/Angstrom;不能替换成 LAMMPS 单位。保存 initial.extxyz、relaxed.cif、初末力数组、optimization.log、optimization.traj 和 results.json。fmax=0.05 eV/Angstrom 与 100 步是作者选定演示边界,不是通用收敛建议;未收敛要明确记为未满足停止条件。

环境、权利与局限

核验固定 SevenNet 0.13.0 源码,安装与硬件相容的 PyTorch,并记录解析得到的 ASE/依赖版本。CPU 示例不宣称 CUDA 或加速器兼容性。SevenNet 源码为 MIT,ASE 为 LGPL-2.1-or-later;保留模型来源及附带权重/训练数据条款,不能把代码许可自动扩展到全部数据。输入权利单独适用。科学评估需要同分布的参考能量/力或 DFT 比较;收敛本身不能证明物理精度、稳定性或任意化学体系覆盖。基线推理在本地,依赖/模型下载需要联网;配置时间不含优化。

官方参考

原子能量与力计算器

SevenNet

晶体读写与固定晶胞优化器

ASE

组合组件

SevenNet

原子能量与力计算器 · 0.13.0 source 209339d4eb4c1717f906c4cb715629159f00f88c; 7net-0 (July 2024)

基于官方文档的审核稿。本批未执行此工作流,未验证安装、推理、优化或实验结果。

代码开源;算力/存储及外部服务条件由用户另行承担和确认。

查看资源

ASE

晶体读写与固定晶胞优化器 · ASE calculator/BFGS API; record resolved version

基于官方文档的审核稿。本批未执行此工作流,未验证安装、推理、优化或实验结果。

代码开源;算力/存储及外部服务条件由用户另行承担和确认。

查看资源

兼容环境

客户端操作系统架构版本要求
Python Linux不限>= 3.11

安装与测试

1. 准备有权使用的周期晶体

Linux

在新工作目录放置 input.cif,检查单位、原子数、周期晶胞和拟采用的参考计算。确认实际权重元素覆盖及条款,不泛称支持全部材料。

官方来源

预期结果

有效周期晶体及模型/输入来源记录。

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
官方来源

预期结果

记录的环境可导入 sevenn.calculator 和 ASE,不表示已取得数值结果。

3. 保存本审核编写的计算器示例

Linux

将随附 Python 代码保存为 sevennet0_relax.py。它基于官方接口在本次编写,不是上游测试结果。固定源码的 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 一致。

故障排除

  • 不支持元素:选择文档支持的适用权重或拒绝该体系。
  • 权重下载/导入失败:检查软件/模型来源和网络,不默默替换权重。
  • 非有限力:检查晶胞、重叠和模型适用域。
  • 输出目录存在:另选运行名称,不覆盖结果。
  • 未收敛:保留日志、检查几何并单独论证后续策略,不标记成功。
  • 参考不一致:先比较泛函、组成、能量基准和单位。
仍无法运行

替代方案

更新的 SevenNet 权重具有不同适用域/精度任务,需要单独配置;DFT 为独立参考验证,LAMMPS 或 MD 集成不属于此固定晶胞基线。