本家様 https://github.com/asarnow/pyem
「UCSF PyEM is a collection of Python modules and command-line utilities for electron microscopy of biological samples.」とある。
PyEMはpython3のコードのようで、pyenvとanacondaでpython3によるPyEM実行環境を作ることにした。
インストール対象はCentOS 7です
あと、PyEMにある「recenter.py」(Recenter particles on the center-of-mass of corresponding 2D class-averages.)は、
EMAN2のpythonモジュールを参照します。そのためpython3でEMAN2を作る必要もあるみたい。
まずはpyenvの基点を /apps/pyenv として、その配下に pythonパッケージ管理の anaconda を敷きます。
pyenv/anaconda †
crYOLOと同じように pyenv と anaconda をインストールします
*既に crYOLO とかで構築済みなら不要。その環境を使い回します
(おさらい)
git clone https://github.com/yyuu/pyenv.git /apps/pyenv
export PYENV_ROOT=/apps/pyenv
export PATH=$PYENV_ROOT/bin:$PATH
eval "$(pyenv init - --no-rehash)"
pyenv install anaconda3-5.3.1
pyenv global anaconda3-5.3.1
export PATH=$PYENV_ROOT/versions/anaconda3-5.3.1/bin/:$PATH
conda update conda
PyEM 向けの仮想実行環境を作る †
仮想環境名ですが単純に「PyEM」とします。*pythonは3.6ではEMAN2がコンパイルできなかった
[root@centos7 ~]# conda create -n PyEM python=3.7
PyEMのインストール †
作成した仮想環境 PyEM に移ります。
[root@centos7 ~]# source activate PyEM
(PyEM) [root@centos7 ~]#
次にPyEMに必要なパッケージをこの 仮想環境 PyEM に加えます
(PyEM) [root@centos7 ~]# conda install matplotlib seaborn numba natsort numexpr hdf5
(PyEM) [root@centos7 ~]# conda install -c conda-forge pyfftw healpy pathos
gitからPyEMソースコードを取得します。場所は /apps とかで
(PyEM) [root@centos7 ~]# cd /apps
(PyEM) [root@centos7 apps]# git clone https://github.com/asarnow/pyem ./PyEM
(PyEM) [root@centos7 apps]# cd PyEM
(PyEM) [root@centos7 PyEM]# ls -CF
activate csparc2star.py* map.py* projection_subtraction.py* recenter.py* sort.py subparticles.py*
angdist.py* ctf2star.py* mask.py* project.py* reconstruct.py* stack.py* subset.py*
cfsc.py* emcalc.py* par2star.py* pyem/ requirements.txt star2bild.py* varmap.py*
changelog.md LICENSE pose.py README.md setup.py star.py*
(PyEM) [root@centos7 PyEM]#
そしてPyEMをインストールします
(PyEM) [root@centos7 PyEM]# pip install --no-dependencies -e .
Obtaining file:///apps/PyEM
Installing collected packages: pyem
Running setup.py develop for pyem
Successfully installed pyem
(PyEM) [root@centos7 PyEM]#
なんかスムーズにできたみたい。
実行するには †
ここではEnvironmentModulesで用意していて、その場合のmoduleファイルは下記になる
#%Module1.0
set PyEM /apps/PyEM/
set root /apps/pyenv/versions/anaconda3-5.3.1/envs/PyEM
prepend-path PATH $PyEM:$root/bin
これを「/etc/modulefiles/PyEM」として配置させ、「module load PyEM」でロードすれば使える
他のアプリ/スクリプトは問題ないのだが、
recenter.py †
「recenter.py」スクリプトはちょいと修正する必要があった
| --- a/recenter.py
+++ b/recenter.py
@@ -21,8 +21,8 @@ import glob
import logging
import sys
import numpy as np
-from star import parse_star, write_star
-from EMAN2 import EMData, Vec3f, Transform
+from pyem.star import parse_star, write_star
+from EMAN2 import EMData, Vec3f, Vec2f, Transform
|
っと修正して再度実行するも下記のようなメッセージが表示される
(PyEM) [root@centos7 PyEM]# ./recenter.py
Traceback (most recent call last):
File "./recenter.py", line 25, in <module>
from EMAN2 import EMData, Vec3f, Transform
ModuleNotFoundError: No module named 'EMAN2'
(PyEM) [root@centos7 PyEM]#
まぁーEMAN2のライブラリが必要という事。
EMAN2で使用した「eman2.31_sphire1.3.linux64.sh」はpython2.7で作られたバイナリーで、PyEMが必要とするのはpython3で作ったEMAN2.
なので、
Python3でEMAN2を作る †
下拵え
必要なパッケージをインストールします
(PyEM) [root@centos7 ~]# yum install epel-release
(PyEM) [root@centos7 ~]# yum install cmake3 gsl-devel mesa-libGL-devel freeglut-devel
(PyEM) [root@centos7 ~]# conda install -c cryoem ftgl
(PyEM) [root@centos7 ~]# conda install pyopengl
[実行に必要なライブラリ]
(PyEM) [root@centos7 ~]# conda install future
(PyEM) [root@centos7 ~]# conda install -c conda-forge bsddb3
eman2を取得してコンパイルします
(PyEM) [root@centos7 ~]# cd /apps/src
(PyEM) [root@centos7 src]# git clone https://github.com/cryoem/eman2 eman2-source
(PyEM) [root@centos7 src]# cd eman2-source
(PyEM) [root@centos7 eman2-source]#
留意
CentOS7のGCC-4.8.5は git logの「2020-10-09」時点ならコンパイル可能 「git checkout -b 2020-10-09 e8882c9a0eca9f251a64aefe5cfb826ff76e77b」
それより最新版は GCC-5以上が必要みたい.
*v2.31となる「git checkout -v v2.31 refs/tag/v2.31」も同様にGCC-4.8.5でコンパイルは出ませんでした
ここでは CentOS/devtoolset の devtoolset-9 を使って GCC-9.3.1で最新版(20210117)をコンパイルしてみました.
(PyEM) [root@centos7 eman2-source]# git branch
* master
(PyEM) [root@centos7 eman2-source]# mkdir b && cd b (buildする場所を作ってそこに移ります)
(devtoolset-9へ移行)
(PyEM) [root@centos7 b]# source scl_source enable devtoolset-9
(PyEM) [root@centos7 b]# which gcc
/opt/rh/devtoolset-9/root/usr/bin/gcc
(PyEM) [root@centos7 b]# cmake3 -Wno-dev ..
(PyEM) [root@centos7 b]# make
(PyEM) [root@centos7 b]# make install
(PyEM) [root@centos7 b]# vi /apps/pyenv/versions/anaconda3-5.3.1/envs/PyEM/lib/python3.7/site-packages/EMAN2.py
:
:
# This next line is to initialize the Transform object for threadsafety. Utterly stupid approach, but a functional hack
T=Transform({"type":"2d","alpha":0})
↓
#T=Transform({"type":"2d","alpha":0})
「/apps/pyenv/versions/anaconda3-5.3.1/envs/PyEM/」を起点にインストールされる.
「e2projectmanager.py」は「/apps/pyenv/versions/anaconda3-5.3.1/envs/PyEM/bin/e2projectmanager.py」な感じで
EnvironmentModulesにeman2も加えるなら
#%Module1.0
set PyEM /apps/PyEM/
set root /apps/pyenv/versions/anaconda3-5.3.1/envs/PyEM
prepend-path PATH $PyEM:$root/bin
setenv EMAN2DIR $root/bin
とします
(PyEM) [root@centos7 PyEM]# ./recenter.py
usage: recenter.py [-h] [--class-2d CLASS_2D] [--class-3d CLASS_3D]
[--zero-origin ZERO_ORIGIN]
input output
recenter.py: error: the following arguments are required: input, output
(PyEM) [root@centos7 PyEM]#
(PyEM) [root@centos7 PyEM]#
(PyEM) [root@centos7 PyEM]# ./recenter.py -h
usage: recenter.py [-h] [--class-2d CLASS_2D] [--class-3d CLASS_3D]
[--zero-origin ZERO_ORIGIN]
input output
positional arguments:
input Input .star file
output Output .star file
optional arguments:
-h, --help show this help message and exit
--class-2d CLASS_2D 2D class images for recentering (pass glob in quotes
for multiple files)
--class-3d CLASS_3D 3D class images for recentering (pass glob in quotes
for multiple files)
--zero-origin ZERO_ORIGIN
Subtract particle origin from particle coordinates in
output
(PyEM) [root@centos7 PyEM]#
これでPyEMの「recenter.py」も動きます。
eman2をインストールしたので、「module load PyEM」を行うとeman2のアプリも使えるようになります
ただ、、openmpiのカスタマイズ(dl抜き)が必要なのでバイナリー提供のeman2を使うのが簡便かと思われます