ユニバーサル機械学習ポテンシャルMACEを使ってみる:Materi Apps LIVE!での環境構築
Last Update:2025/10/28
ユニバーサル機械学習ポテンシャルMACE( https://github.com/ACEsuit/mace )を試しに使ってみる。
Materi Apps LIVE!は、https://github.com/cmsi/MateriAppsLive/wiki/download からダウンロードできる。
Docker版のMateri Apps LIVE!は、Dockerを起動後、malive.shを実行すれば良い。
※Windows intel cpuで動作確認。macOS apple siliconでは正常動作しないので注意。
(1)Materi Apps LIVE!でのMiniforge仮想環境の構築
参考:MateriApps LIVE! における Python 環境設定( https://github.com/cmsi/MateriAppsLive/wiki/pythonenv )の「Miniforge仮想環境」のページ
Miniforge のインストール
$ cd $HOME $ curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh" $ bash Miniforge3-$(uname)-$(uname -m).sh -b $ rm -f Miniforge3-$(uname)-$(uname -m).sh
Miniforge の有効化
$ source $HOME/miniforge3/bin/activate (base)$
仮想環境mace-envの作成
(base)$ conda create -n mace-env python=3.10 -y
mace-envの有効化
(base)$ conda activate mace-env (mace-env)$
(2)MACEのイントールとポテンシャルの作成
PyTorch 2.5.1(CPU版)をインストールする
(mace-env)$ pip install torch==2.5.1+cpu --index-url https://download.pytorch.org/whl/cpu
MACE v0.3.3をインストールする。
(mace-env)$ pip install mace-torch==0.3.3
MACEモデル + Materials Projectデータセットで学習された 2023-12-03-mace-mp.modelをダウンロードする。2023-12-03-mace-mp.modelは、水素(H)から遷移金属まで、約89元素に対応している。
(mace-env)$ wget https://github.com/ACEsuit/mace/raw/refs/heads/main/mace/calculators/foundations_models/2023-12-03-mace-mp.model
2023-12-03-mace-mp.modelをLAMMPSで用いるモデルファイル(.pt形式)に変換する。
(mace-env)$ python -m mace.cli.create_lammps_model 2023-12-03-mace-mp.model
を実行すると、23-12-03-mace-mp.model-lammps.ptというファイルができる。
(3)ML-MACEが使えるLAMMPSの構築
(mace-env)$ cd $HOME (mace-env)$ wget https://download.pytorch.org/libtorch/cpu/libtorch-shared-with-deps-1.13.0%2Bcpu.zip (mace-env)$ unzip libtorch-shared-with-deps-1.13.0+cpu.zip (mace-env)$ rm libtorch-shared-with-deps-1.13.0+cpu.zip (mace-env)$ git clone --branch mace --depth=1 https://github.com/ACEsuit/lammps (mace-env)$ cd lammps (mace-env)$ mkdir build-mace (mace-env)$ cd build-mace (mace-env)$ cmake \ -D CMAKE_BUILD_TYPE=Release \ -D CMAKE_INSTALL_PREFIX=$(pwd) \ -D CMAKE_CXX_STANDARD=17 \ -D CMAKE_CXX_STANDARD_REQUIRED=ON \ -D BUILD_SHARED_LIBS=ON \ -D BUILD_MPI=ON \ -D PKG_ML-MACE=ON \ -D CMAKE_PREFIX_PATH=$(pwd)/../../libtorch \ -D LAMMPS_MACHINE=mace \ -D MKL_INCLUDE_DIR="" \ ../cmake (mace-env)$ make (mace-env)$ make install (mace-env)$ cp $HOME/2023-12-03-mace-mp.model-lammps.pt ./
(4)実行例
下記のようなin.mace_testファイルを作る。(メタン分子の構造を最適化し、短時間のMDで力やエネルギーを確認する。)
units metal
atom_style atomic
atom_modify map yes
newton on
# Read data file
read_data data.test
# Set atomic masses
mass 1 12.011 # C
mass 2 1.008 # H
# Define MACE pair style and coefficients
pair_style mace no_domain_decomposition
pair_coeff * * 2023-12-03-mace-mp.model-lammps.pt C H
# Neighbor settings
neighbor 2.0 bin
neigh_modify every 1 delay 0 check yes
# Structure optimization
min_style cg
minimize 1e-4 1e-6 100 1000
# Simulation settings
timestep 0.0005
velocity all create 300.0 12345 mom yes rot yes dist gaussian
fix 1 all nvt temp 300.0 300.0 0.1
# Output settings
dump 1 all custom 10 dump.mace id type x y z fx fy fz
thermo 10
# Run simulation
run 100
用いるdata.testは下記になる。
LAMMPS data file for methane molecule
5 atoms
2 atom types
0.0 20.0 xlo xhi
0.0 20.0 ylo yhi
0.0 20.0 zlo zhi
Masses
1 12.011
2 1.008
Atoms
1 1 10.0 10.0 10.0
2 2 10.0 10.0 11.1
3 2 10.0 11.1 10.0
4 2 11.1 10.0 10.0
5 2 10.0 8.9 10.0
LAMMPSの実行
(mace-env)$ export LD_LIBRARY_PATH=$HOME/lammps/build-mace/lib:$HOME/libtorch/lib:$LD_LIBRARY_PATH
(mace-env)$ $HOME/lammps/build-mace/bin/lmp_mace -in in.mace_test
出力されたlog.lammpsファイルを読み込み、下記のpythonスクリプトplot.pyを用いて、各ステップの温度、全エネルギー、圧力をプロットする。
import matplotlib.pyplot as plt
# Thermoデータ(Step, Temp, Total Energy, Pressure)
thermo_data = [
(0, 0.0, -21.848488, 190.6699),
(8, 0.0, -23.91332, 2.5418618),
(10, 259.77785, -23.892222, 143.26104),
(20, 77.536125, -23.797574, -93.921691),
(30, 225.66873, -23.87442, 26.705648),
(40, 246.71762, -23.884463, 20.138729),
(50, 80.233195, -23.797564, -98.368245),
(60, 255.70987, -23.887743, 151.48881),
(70, 138.91505, -23.825134, -199.5855),
(80, 49.564152, -23.777972, 239.21906),
(90, 206.96949, -23.857605, -233.40145),
(100, 88.304981, -23.793695, 217.70879),
(108, 96.487752, -23.797557, -54.724521)
]
# データ分割
steps = [d[0] for d in thermo_data]
temps = [d[1] for d in thermo_data]
energies = [d[2] for d in thermo_data]
pressures = [d[3] for d in thermo_data]
# グラフ作成
fig, axs = plt.subplots(3, 1, figsize=(10, 12))
# 温度 vs ステップ
axs[0].plot(steps, temps, 'r-o')
axs[0].set_title('Temperature vs Step')
axs[0].set_xlabel('Step')
axs[0].set_ylabel('Temperature (K)')
# 全エネルギー vs ステップ
axs[1].plot(steps, energies, 'b-o')
axs[1].set_title('Total Energy vs Step')
axs[1].set_xlabel('Step')
axs[1].set_ylabel('Total Energy (eV)')
# 圧力 vs ステップ
axs[2].plot(steps, pressures, 'g-o')
axs[2].set_title('Pressure vs Step')
axs[2].set_xlabel('Step')
axs[2].set_ylabel('Pressure (bar)')
plt.tight_layout()
plt.show()
(mace-env)$ python plot.py
結果:
