本家様 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

既にpyenv環境があるなら

export PYENV_ROOT=/apps/pyenv
export PATH=$PYENV_ROOT/bin:$PATH
eval "$(pyenv init - --no-rehash)"
export PATH=$PYENV_ROOT/versions/anaconda3-5.3.1/bin/:$PATH
 
 
(condaが古いと言われたら)
conda update -n base -c defaults 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 numpy scipy matplotlib seaborn numba pandas natsort
(PyEM) [root@centos7 ~]# conda install -c conda-forge pyfftw healpy pathos
 
(PyEM) [root@centos7 ~]# conda install numexpr       <-- 「emcalc.py」にnumexpr、

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で用意していて、「/etc/modulefiles/PyEM」として下記を用意する

#%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 boost hdf5 tensorflow 
 
[実行に必要なライブラリ]
(PyEM) [root@centos7 ~]# conda install future 
(PyEM) [root@centos7 ~]# conda install -c conda-forge bsddb3
(PyEM) [root@centos7 ~]# conda install scikit-learn nose

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で v2.91 をコンパイルしてみました.

(PyEM) [root@centos7 eman2-source]# git checkout -b v2.91 refs/tags/v2.91
 
 
(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を使うのが簡便かと思われます

cs2star,py

PyEMのcsparc2star.pyを使いやすくしたもの?
https://pypi.org/project/cs2star/
導入には PyEM 実行環境への追加って感じ.
conda環境を準備して、

export PYENV_ROOT=/apps/pyenv
export PATH=$PYENV_ROOT/bin:$PATH
eval "$(pyenv init - --no-rehash)"
export PATH=$PYENV_ROOT/versions/anaconda3-5.3.1/bin/:$PATH

その後にPyEM実行環境へ移る.

[root@centos7 ~]# source activate PyEM
(PyEM) [root@centos7 ~]# which pip
//apps/pyenv/versions/anaconda3-5.3.1/envs/PyEM/bin/pip
 
(PyEM) [root@centos7 ~]#

ここで「pip install cs2star」で完了

もしPyEMをpython-3.6で作っているなら無理みたい.
ERROR: Package 'cs2star' requires a different Python: 3.6.9 not in '>=3.7'」と言われる

その場合はソースから調理します

(PyEM) [root@centos7 ~]# https://files.pythonhosted.org/packages/21/96/e20a4ffaccc0874d341204b5d415ba60168737c51e91ee6dd23b22e7747e/cs2star-0.3.8.tar.gz
(PyEM) [root@centos7 ~]# tar xf cs2star-0.3.8.tar.gz && cd $_
(PyEM) [root@centos7 cs2star-0.3.8]# python setup.py build
(PyEM) [root@centos7 cs2star-0.3.8]# python setup.py install

使用するには「EnvironmentModules」も修正します
PYTHONPATHを追加します

#%Module1.0
set PyEM /apps/PyEM/
set root /apps/pyenv/versions/anaconda3-5.3.1/envs/PyEM
prepend-path PATH $PyEM:$root/bin
setenv PYTHONPATH $PyEM

update

export PYENV_ROOT=/apps/pyenv
export PATH=$PYENV_ROOT/bin:$PATH
eval "$(pyenv init - --no-rehash)"
export PATH=$PYENV_ROOT/versions/anaconda3-5.3.1/bin/:$PATH

とconda環境にして

[root@centos7 ~]# source activate PyEM
(PyEM) [root@centos7 ~]# cd /apps/PyEM
(PyEM) [root@centos7 PyEM]# git pull
(PyEM) [root@centos7 PyEM]# pip install --no-dependencies -e .
(PyEM) [root@centos7 PyEM]# pip install cs2star

とします


トップ   編集 添付 複製 名前変更     ヘルプ   最終更新のRSS
Last-modified: 2022-03-18 (金) 20:07:24 (448d)