0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Gromacs の機械学習ポテンシャルを利用する(インストール編)

Posted at

概要

Gromacs-2025.1 から機械学習ポテンシャル(NNP)が利用可能になったとのことなので、Fedora40 server に Gromacs-2025.1 をインストールした。本記事は、そのインストール記録。QM/MM 計算に NNP を用いる NNP/MM 計算などについては次回以降の記事で書く。

検証環境

CPU: Ryzen 9 7950x
GPU: RTX A6000
OS: Fedora 40 server edition
RAM: 96GB
nvidia-driver: 570.133.07
cuda-12.8

インストール方法

以下の記事でインストールしたパッケージ・依存関係は全て入っている前提で進める。

su  #root ユーザーになる。
# 必要なパッケージをインストール
sudo dnf -y install cmake3 fftw-devel perl-File-Copy perl-libs cmake ninja-build

#ダウンロード
cd /opt
wget https://ftp.gromacs.org/gromacs/gromacs-2025.1.tar.gz
sudo tar zxvf gromacs-2025.1.tar.gz

GROMACS 2025.1 が直接読み込めるのは PyTorch(libtorch)で学習・保存した NNP のみ。TensorFlow や DeepMD ネイティブ形式はまだサポートされていない。

<注意>

  • ABI は “C++11 ABI” 版を選択する。PyTorch 公式サイトから libtorch‑*cxx11‑abi‑shared‑with‑deps‑.zip をダウンロードする。 (*-pre‑cxx11‑abi-* や conda 版は 不可。)
  • PyPI/conda の Python パッケージ版 PyTorchは
    1. C++ ヘッダー & CMake ファイルを含まない
    2. 既定で pre‑C++11 ABI ビルドという理由で GROMACS からは利用できない。

Fedora 40 の標準コンパイラ gcc 14.2.1 は C++11 ABI (=1) が既定なので、追加の ABI オプションは不要。

詳しい説明は、こちらのページを参照。

curl -LO https://download.pytorch.org/libtorch/cu121/libtorch-cxx11-abi-shared-with-deps-2.2.2%2Bcu121.zip
unzip libtorch-*.zip -d /opt

<注意>
NNP 利用時は、cmake 時に以下のオプションを加える必要がある。
詳しくは公式インストールガイドInstalling with Neural Network potential support を参照。

-DGMX_BUILD_NNPOT=ON            # NNP 機能を有効化
-DCMAKE_PREFIX_PATH=/path/to/libtorch   # libtorch のトップディレクトリ

以下が実際のインストール手順。

cd /opt/gromacs-2025.1/
# 以下のコマンドで configure(以下 14 行全て)
cmake -S /opt/gromacs-2025.1 -B build -G Ninja \
      -DCMAKE_INSTALL_PREFIX=/opt/gromacs-2025.1 \
      -DCMAKE_C_COMPILER=gcc \
      -DCMAKE_CXX_COMPILER=g++ \
      -DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc \
      -DCMAKE_PREFIX_PATH=/opt/libtorch \
      -DGMX_MPI=OFF \
      -DGMX_DOUBLE=OFF \
      -DGMX_OPENMP=ON \
      -DGMX_GPU=CUDA \
      -DGMX_BUILD_DOC=OFF \
      -DGMX_BUILD_MAN=OFF \
      -DGMX_BUILD_HTML=OFF \
      -DGMX_BUILD_NNPOT=ON   

# 以下のコマンドで build
cmake --build build -j16   # -j16 は、CPU のコア数を指定している。

# 以下の 3 行を .bashrc に書き込む
# Gromacs の設定
export PATH=/opt/gromacs-2025.1/build/bin:$PATH
export LD_LIBRARY_PATH=/opt/libtorch/lib:$LD_LIBRARY_PATH

動作確認

libtorch の path が通っていないと、gmx 実行時にエラーが起きるので、動作確認を行う。以下のテストは 1 分程度で終わる。

# ダウンロード
git clone https://github.com/hnishi/testdata_gromacs.git testdata_gromacs
cd testdata_gromacs

# テスト
gmx grompp -f MD1.mdp -c ./replace_po_mg.gro -p ./topol.top -o md1.tpr -maxwarn 1 > grompp.log 2>&1

gmx mdrun -s md1.tpr -deffnm md1 -ntmpi 1 -ntomp 16 -gpu_id 0 > md1.log 2>&1

# 結果を確認
tail md1.log
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?