0ut0fcontrol / sharing

sharing files.
MIT License
0 stars 0 forks source link

在conda环境中从源码编译rdkit (linux) #5

Open 0ut0fcontrol opened 3 years ago

0ut0fcontrol commented 3 years ago

1. 安装miniconda

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh

2. 安装依赖

参考:https://www.rdkit.org/docs/Install.html#linux-x86-64-python-3-environment

conda create -n rdkit_dev -c conda-forge -y cmake cairo pillow eigen pkg-config boost-cpp boost py-boost gxx_linux-64 numpy
conda activate rdkit_dev

3. 编译

参考:https://github.com/conda-forge/rdkit-feedstock/blob/master/recipe/build.sh

git clone https://github.com/rdkit/rdkit.git
cd rdkit
git checkout -b Release_2020_09_3 Release_2020_09_3

mkdir build && cd build
cmake \
    -D CMAKE_BUILD_TYPE=Release \
    -D CMAKE_INSTALL_PREFIX="$CONDA_PREFIX" \
    -D PYTHON_NUMPY_INCLUDE_PATH="$(python -c 'import numpy ; print(numpy.get_include())')" \
    -D BOOST_ROOT="$CONDA_PREFIX" \
    -D Boost_NO_SYSTEM_PATHS=ON \
    -D Boost_NO_BOOST_CMAKE=ON \
    -D RDK_BUILD_AVALON_SUPPORT=ON \
    -D RDK_BUILD_CAIRO_SUPPORT=ON \
    -D RDK_BUILD_CPP_TESTS=OFF \
    -D RDK_BUILD_INCHI_SUPPORT=ON \
    -D RDK_BUILD_FREESASA_SUPPORT=ON \
    -D RDK_BUILD_YAEHMOP_SUPPORT=ON \
    -D RDK_INSTALL_INTREE=OFF \
    -D RDK_INSTALL_STATIC_LIBS=OFF \
    -D RDK_OPTIMIZE_POPCNT=ON \
    ..
make -j 8
make install

如果机器太老不支持POPCNT, 请使用 -D RDK_OPTIMIZE_POPCNT=OFF

Check if the machine supports popcnt

lscpu | grep popcnt
# output nothing if not support.
# if support: Flags: ... popcnt ...

4. 测试

(rdkit_dev) [jcyang@k168:build]$ cd /tmp/
(rdkit_dev) [jcyang@k168:tmp]$ python
Python 3.7.9 | packaged by conda-forge | (default, Dec  9 2020, 21:08:20) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from rdkit import Chem
>>> from rdkit import DataStructs
>>> from rdkit.Chem import AllChem
>>> 
>>> m = Chem.MolFromSmiles('CC')
>>> fp = AllChem.GetMorganFingerprintAsBitVect(m, 2)
>>> 
>>> # This function will fail with "Illegal instruction" if not support `popcnt`.
>>> DataStructs.TanimotoSimilarity(fp,fp)
1.0
>>> print("Okay, this machine supports TanimotoSimilarity.")
Okay, this machine supports TanimotoSimilarity.
>>> exit()
(rdkit_dev) [jcyang@k168:tmp]$