deepmd-python-inference
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "deepmd-python-inference":https://skillpi.com/zh/skills/deepskill-dee5e126f72b1da23206a88c67c60e9cff44a60de50fb0b936d1a6a6e99dd86e。安装前核对上游来源和版本:https://github.com/jinzhezenggroup/computational-chemistry-agent-skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
在 Python 中使用 DeePMD-kit 模型的 DeepPot API 运行推理。适用于在 Python 中加载已训练或已冻结的 DeePMD 模型(.pth 或 .pb)或内置预训练模型(例如 DPA-3.2-5M),用于预测能量/力/维里张量、评估描述符或计算多模型之间的模型偏差,同时也涵盖使用 `dp test` 命令行工具对带标签数据进行批量评估。
介绍来源: third_party · jinzhezenggroup · 1.0 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: deepmd-python-inference
description: Run Python inference with DeePMD-kit models using the DeepPot API. Use when the user wants to load a trained/frozen DeePMD model (.pth or .pb) or a built-in pretrained model (e.g., DPA-3.2-5M) in Python, predict energy/force/virial for atomic configurations, evaluate descriptors, or calculate model deviation between multiple models. Also covers using `dp test` CLI for batch evaluation against labeled data.
compatibility: Requires deepmd-kit Python package installed. PyTorch backend for .pth models, TensorFlow for .pb models.
license: LGPL-3.0-or-later
metadata:
author: iProzd
version: '1.0'
repository: https://github.com/deepmodeling/deepmd-kitDeePMD-kit Python Inference
Load a trained DeePMD-kit model in Python and predict energy, forces, and virial for atomic configurations. Also covers CLI-based testing with dp test.
Quick Start
from deepmd.infer import DeepPot
import numpy as np
dp = DeepPot("model.pth")
coord = np.array([[1, 0, 0], [0, 0, 1.5], [1, 0, 3]]).reshape([1, -1])
cell = np.diag(10 * np.ones(3)).reshape([1, -1])
atype = [1, 0, 1]
e, f, v = dp.eval(coord, cell, atype)
Agent Responsibilities
- Determine the model source:
- Frozen model file (
.pthfor PyTorch,.pbfor TensorFlow) - Built-in pretrained model name (e.g.,
DPA-3.2-5M) - Checkpoint file (requires freezing first)
- Frozen model file (
- Determine the inference task:
- Single-frame prediction (energy, force, virial)
- Batch prediction over multiple frames
- Descriptor evaluation
- Model deviation calculation
- CLI-based testing against labeled data
- Help the user prepare input arrays in the correct format.
- Run inference and report results.
Python API: DeepPot
Load a Model
from deepmd.infer import DeepPot
# From a frozen PyTorch model
dp = DeepPot("model.pth")
# From a frozen TensorFlow model
dp = DeepPot("graph.pb")
# From a built-in pretrained model (auto-downloads if not cached)
dp = DeepPot("DPA-3.2-5M")
Built-in pretrained model names include DPA-3.3-1M, DPA-3.2-5M, DPA-3.1-3M, DPA3-Omol-Large, etc. DeePMD-kit will automatically download and cache the model on first use.
Predict Energy, Forces, and Virial
import numpy as np
from deepmd.infer import DeepPot
dp = DeepPot("model.pth")
# Prepare inputs
# coord: (nframes, natoms * 3) in Angstrom
# cell: (nframes, 9) cell vectors in Angstrom, row-major
# atype: list of atom type indices (length natoms)
coord = np.array(
[
[
0.0,
0.0,
0.0, # atom 0 (O)
0.0,
0.0,
1.0, # atom 1 (H)
0.0,
1.0,
0.0,
] # atom 2 (H)
]
).reshape([1, -1])
cell = np.diag([10.0, 10.0, 10.0]).reshape([1, -1])
# atype indices correspond to type_map order in the model
# e.g., if type_map = ["O", "H"], then O=0, H=1
atype = [0, 1, 1]
e, f, v = dp.eval(coord, cell, atype)
print(f"Energy (eV): {e}") # shape: (nframes, 1)
print(f"Forces (eV/A): {f}") # shape: (nframes, natoms, 3)
print(f"Virial (eV): {v}") # shape: (nframes, 9)
Non-periodic Systems
For non-periodic (isolated) systems, pass cell=None:
e, f, v = dp.eval(coord, None, atype)
Batch Prediction
Process multiple frames at once:
nframes = 10
natoms = 3
coords = np.random.rand(nframes, natoms * 3)
cells = np.tile(np.diag([10.0, 10.0, 10.0]).reshape([1, -1]), (nframes, 1))
atype = [0, 1, 1]
e, f, v = dp.eval(coords, cells, atype)
# e: (nframes, 1)
# f: (nframes, natoms, 3)
# v: (nframes, 9)
Evaluate Descriptors
Extract the descriptor (atomic environment representation) from the model:
descriptors = dp.eval_descriptor(coord, cell, atype)
# shape: (nframes, natoms, ndesc)
This can also be done via CLI:
dp eval-desc -m model.pth -s /path/to/system -o desc_output
Calculate Model Deviation
Compare predictions from multiple models to estimate uncertainty:
from deepmd.infer import calc_model_devi, DeepPot
coord = np.array([[1, 0, 0], [0, 0, 1.5], [1, 0, 3]]).reshape([1, -1])
cell = np.diag(10 * np.ones(3)).reshape([1, -1])
atype = [1, 0, 1]
graphs = [DeepPot("model_0.pth"), DeepPot("model_1.pth")]
model_devi = calc_model_devi(coord, cell, atype, graphs)
Important: avoid loading the same model multiple times in a loop, as this can cause memory leaks.
CLI Testing: dp test
Test a frozen model against labeled data:
# Basic test
dp --pt test -m model.pth -s /path/to/test_system -n 30
# Test with detailed output
dp --pt test -m model.pth -s /path/to/test_system -n 30 -d test_detail
dp test Options
| Option | Description |
|---|---|
-m MODEL |
Path to the frozen model file |
-s SYSTEM |
Path to the test data system |
-n NUMB |
Number of test frames |
-d DETAIL |
Output prefix for detailed results |
--shuffle-test |
Shuffle test frames |
Output
dp test prints RMSE values for energy, force, and virial:
Energy RMSE : 1.234e-03 eV
Energy RMSE/Natoms : 6.427e-06 eV
Force RMSE : 2.345e-02 eV/A
Virial RMSE : 5.678e-02 eV
Virial RMSE/Natoms : 2.957e-04 eV
With -d test_detail, per-frame predictions are saved to files for further analysis.
Complete Example: Train, Freeze, and Inference
import subprocess
import numpy as np
from deepmd.infer import DeepPot
# Step 1: Train (run in shell)
# dp --pt train input.json
# Step 2: Freeze (run in shell)
# dp --pt freeze -o model.pth
# Step 3: Python inference
dp = DeepPot("model.pth")
# Load test data from deepmd format
coord = np.load("test_system/set.000/coord.npy") # (nframes, natoms*3)
cell = np.load("test_system/set.000/box.npy") # (nframes, 9)
atype_raw = np.loadtxt("test_system/type.raw", dtype=int).tolist()
# Predict
e, f, v = dp.eval(coord, cell, atype_raw)
# Compare with reference
ref_energy = np.load("test_system/set.000/energy.npy")
ref_force = np.load("test_system/set.000/force.npy")
natoms = len(atype_raw)
energy_rmse = np.sqrt(np.mean((e.flatten() - ref_energy.flatten()) ** 2)) / natoms
force_rmse = np.sqrt(np.mean((f.reshape(-1) - ref_force.reshape(-1)) ** 2))
print(f"Energy RMSE/atom: {energy_rmse:.6f} eV")
print(f"Force RMSE: {force_rmse:.6f} eV/A")
Using Pretrained Models Directly
Built-in pretrained models can be used without any training:
from deepmd.infer import DeepPot
import numpy as np
# Auto-downloads DPA-3.2-5M on first use
dp = DeepPot("DPA-3.2-5M")
# Water molecule example
coord = np.array(
[
[0.000, 0.000, 0.117], # O
[0.000, 0.757, -0.469], # H
[0.000, -0.757, -0.469], # H
]
).reshape([1, -1])
cell = np.diag([10.0, 10.0, 10.0]).reshape([1, -1])
atype = [0, 1, 1] # Check model's type_map for correct indices
e, f, v = dp.eval(coord, cell, atype)
print(f"Energy: {e[0][0]:.6f} eV")
print(f"Forces:\n{f[0]}")
To download pretrained models explicitly:
dp pretrained download DPA-3.3-1M
dp pretrained download DPA-3.2-5M
dp pretrained download DPA-3.1-3M
dp pretrained download DPA-3.2-5M --cache-dir ./models
Input Array Format Reference
| Array | Shape | Unit | Description |
|---|---|---|---|
coord |
(nframes, natoms*3) | Angstrom | Atomic coordinates, flattened |
cell |
(nframes, 9) | Angstrom | Cell vectors, row-major (a1x,a1y,a1z,a2x,...) |
atype |
(natoms,) | - | Atom type indices matching model's type_map |
| Output | Shape | Unit | Description |
|---|---|---|---|
e |
(nframes, 1) | eV | Total energy per frame |
f |
(nframes, natoms, 3) | eV/A | Forces on each atom |
v |
(nframes, 9) | eV | Virial tensor per frame |
Agent Checklist
- [ ] Model file exists and is accessible (
.pth,.pb, or valid pretrained name) - [ ]
coordarray is shaped (nframes, natoms*3) and in Angstrom - [ ]
cellarray is shaped (nframes, 9) orNonefor non-periodic systems - [ ]
atypeindices match the model'stype_mapordering - [ ] For model deviation, multiple models are loaded only once (not in a loop)
- [ ] Results are reported with correct units (eV, eV/A)
References
当前收录版本
1.0
安全与评测信息
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供完整的 DeePMD-kit Python 推理工作流,支持多种模型格式和任务类型
- 面向计算化学和材料科学研究人员的高价值科研工具
- 涵盖从单帧预测到批量评估的完整功能集
亮点
- 触发词精准覆盖 DeePMD 模型推理的各种场景
- 明确区分不同模型格式(.pth/.pb/预训练)和任务类型
- 边界清晰,不易与其他 Skill 混淆
亮点
- 文档结构清晰,从快速入门到完整示例层次分明
- frontmatter 完整,包含兼容性、许可证和元数据信息
- 提供详细的输入输出格式参考和 Agent 检查清单
亮点
- 工具来源明确,参数格式详细说明
- 覆盖主要异常场景(非周期性系统、模型兼容性)
- 包含内存泄漏警告和最佳实践建议
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
文档引用的域名或地址
这些地址可能用于文档链接或示例,不是已批准的联网清单。使用前核对实际目的地及发送的数据。
- docs.deepmodeling.com
- github.com
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。