LoginSignup
0
0

OpenMMとpdbfixerをcondaを用いずに手動インストールする

Last updated at Posted at 2024-06-01

OpenMMpdbfixerは公式ページでもcondaを使ったインストールがおすすめされているが、サードパーティのcondaは邪道と思う方のために、python3公式のvenvを使った方法で管理したい場合は以下のようにする。

仮想環境の作成

Python 3.12で仮想環境venvを起動した状態にする。3.12でなくても良いが、この記事を書いている時点では3.9以上が望ましいだろう。

python3.12 -m venv .venv
source .venv/bin/activate # Python仮想環境の起動を確認する。

which python3.12としてみて、/path/to/your/.venv/bin/python3.12が表示されれば仮想環境が起動している状態である(/path/to/yourの部分は自身のディレクトリに読み替えてください)。

OpenMMのインストール

OpenMMはもともとC++で書かれており、cmakeでビルドすることができる。これに加えてPython APIを追加でインストールすることができる。公式マニュアルのインストール方法では、Python APIをインストールする時にsetuptoolsとCythonが要求されることが書かれていないので、これを先に入れておく必要がある。

python3.12 -m pip install Cython setuptools

次にOpenMMをインストールする。OpenMMのリリースページから最新のバージョンをダウンロードし、解凍する。解凍したディレクトリに移動し、以下のコマンドを実行する。ここではver. 8.1.1をインストールする。

wget https://github.com/openmm/openmm/archive/refs/tags/8.1.1.tar.gz
tar zxvf 8.1.1.tar.gz
cd openmm-8.1.1
mkdir build
cd build
# 先程の/path/to/your/.venv/bin/python3.12を使う
# NVIDIA GPUを使う場合は-DCUDAToolkit_NVCC_EXECUTABLE=/path/to/cuda/bin/nvccを追加すると良いかもしれない。または自動で検出してくれるかもしれない(未確認)
cmake .. -DCMAKE_INSTALL_PREFIX="${HOME}/apps/openmm/8.1.1" -DPYTHON_EXECUTABLE="/path/to/your/.venv/bin/python3.12"
make -j8 install

# インストール開始
# -- Installing: /path/to/your/openmm/8.1.1/examples/NMakefile
# -- Installing: /path/to/your/openmm/8.1.1/examples/MakefileNotes.txt
# -- Installing: /path/to/your/openmm/8.1.1/examples/Empty.cpp
# -- Installing: /path/to/your/openmm/8.1.1/lib/libOpenMM.8.1.dylib
# -- Installing: /path/to/your/openmm/8.1.1/lib/libOpenMM.dylib
# で終了

これでOpenMMのコマンドが使えるようになる。続いて、Python APIをインストールする。

make PythonInstall

# インストール開始
# no previously-included directories found matching 'src/swig_doxygen/doxygen/html'
# no previously-included directories found matching 'src/swig_doxygen/doxygen/xml'
# warning: no previously-included files matching 'CMakeLists.txt' found anywhere in distribution
# writing manifest file 'OpenMM.egg-info/SOURCES.txt'
# Copying OpenMM.egg-info to /path/to/your/.venv/lib/python3.12/site-packages/OpenMM-8.1.1-py3.12.egg-info
# running install_scripts
# [100%] Built target PythonInstall
# で終了

これでOpenMMのPython APIが使えるようになる。以下のコマンドで確認する。

$ python3.12 -m openmm.testInstallation

OpenMM Version: 8.1.1
Git Revision: Unknown

There are 3 Platforms available:

1 Reference - Successfully computed forces
2 CPU - Successfully computed forces
3 OpenCL - Successfully computed forces

Median difference in forces between platforms:

Reference vs. CPU: 6.28658e-06
Reference vs. OpenCL: 6.72889e-06
CPU vs. OpenCL: 7.22461e-07

All differences are within tolerance.

これが表示されればOpenMMが指定した仮想環境のPythonから使えるようになっている。

pdbfixerのインストール

pdbfixerを使うにはOpenMMが必要なので先にそれをインストールしておく。その後は以下のコマンドでpdbfixerをインストールする。ここではver. 1.9をインストールする。

wget https://github.com/openmm/pdbfixer/archive/refs/tags/1.9.tar.gz
tar zxvf 1.9.tar.gz
cd pdbfixer-1.9
python3.12 -m pip install .

こちらはこんな感じですぐにインストールが終わるはず。

Processing /path/to/your/pdbfixer-1.9
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: numpy in /path/to/your/.venv/lib/python3.12/site-packages (from pdbfixer==1.9.0) (1.26.4)
Requirement already satisfied: openmm>=7.1 in /path/to/your/.venv/lib/python3.12/site-packages (from pdbfixer==1.9.0) (8.1.1)
Building wheels for collected packages: pdbfixer
  Building wheel for pdbfixer (pyproject.toml) ... done
  Created wheel for pdbfixer: filename=pdbfixer-1.9.0-py3-none-any.whl size=689353 sha256=05c01479b06bb249d493b3d069611c76ea28f245eb93d47d36d57ecf8a51d2f2
  Stored in directory: /Users/YoshitakaM/Library/Caches/pip/wheels/e2/9b/9a/7a797016b4b4f9ed14b871e7af6b62fd76c1024ca2e0a45e20
Successfully built pdbfixer
Installing collected packages: pdbfixer
Successfully installed pdbfixer-1.9.0

これでpdbfixerが使えるようになる。ターミナルから使えるpdbfixerコマンドと、Pythonから使えるpdbfixerモジュールがインストールされているか確認する。

# ターミナルから使えるか確認
$ which pdbfixer
/path/to/your/.venv/bin/pdbfixer

# Pythonから使えるか確認
$ python3.12 -c "import pdbfixer"
# 何も表示されなければOK

以上でOpenMMとpdbfixerのインストールが完了した。マニュアルはこちらを参照すると良いだろう。

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