Install Cheminformatics Tool RDKit for Python

(2014.02.12 update Added about reinstallation of Boost and installation of PIL) (Updated on February 19, 2014 Added structural formula drawing using Cairo) (Updated on March 11, 2014) Updated structural formula drawing using Cairo)

As a tool for cheminformatics OpenBabel (C ++) and CDK (Java) are famous as open source, RDKit can be used in Python, so you only need to write a relatively simple script It is convenient because you can draw, search, and analyze chemical structural formulas.

Installation (Mac OS X 10.7)

When using Homebrew Python, don't forget to put it in your PATH with .bash_profile etc.

If NumPy is not included, enter it.

pip install numpy

Volunteer Homebrew formura is open to the public, so tap it and install it. https://github.com/edc/homebrew-rdkit

brew tap edc/homebrew-rdkit
brew install rdkit

Dependent modules cmake, wget, swig, boost, and rdkit are installed. It takes some time to install boost and rdkit.

If you are using Homebrew Python, you will get a Fatal Python error due to Boost. Build Boost from source and reinstall it with the following command.

brew uninstall boost
brew install boost --build-from-source

From the command line from rdkit import Chem If you can, the installation is successful.

PIL is required to display structural formula images.

pip install pillow

Try using

For example, the following code draws a chemical structural formula from SMILES and outputs it as PNG.

rdkittest.py


from rdkit import Chem
from rdkit.Chem import Draw
from rdkit.Chem import rdDepictor

mol = Chem.MolFromSmiles('CCC(CC)O[C@@H]1C=C(C[C@@H]([C@H]1NC(=O)C)[NH3+])C(=O)OCC')
rdDepictor.Compute2DCoords(mol)
Draw.MolToFile(mol, 'mol.png')

result:

mol.png

The code is overwhelmingly shorter than the CDK. It seems that functions with a large amount of calculation such as drawing, searching, and analysis are implemented in C ++. I don't think it's too slow.

However, as you can see, the image quality at this stage is very poor compared to CDK. So, in my case, I search and analyze with RDKit, and only draw is thrown to CDK.

(Supplement) Drawing high-quality structural images using Cairo

If Cairo and PyCairo are available (that is, they can be imported cairo), the image quality will be significantly improved because Cairo will be used automatically when drawing the structural formula with Draw.MolToFile ().

mol.png

Both Cairo and PyCairo can be installed with Homebrew.

brew install cairo
brew install py2cairo

(For Python2.7, it's py2cairo instead of pycairo.) When Cairo is installed with Homebrew, it conflicts with the X11 default Cairo, so I think it is probably necessary to set the library path.

(Added on 2014.03.11) Install pango and pygtk.

brew install pango
brew install pygtk

It's OK if you can import pango from Python. This will improve the font and display atomic number subscripts and ion superscripts normally.

mol.png

Recommended Posts

Install Cheminformatics Tool RDKit for Python
Install Python (for Windows)
Install dlib for Python (Windows)
install python
Created AtCoder test tool for Python
Install confluent-kafka for Python on Ubuntu
Python visualization tool for data analysis work
Solution for pip install error [Python] [Mac]
Python environment tool comparison chart for Rubyist
Install Python package management tool pip (Windows)
A tool for easily entering Python code
2016-10-30 else for Python3> for:
python [for myself]
Install Python locally
Install NAOqi python
Install Python Control
CentOS8 --Install --Python3
How to install Python for pharmaceutical company researchers
Install Python and libraries for Python on MacOS Catalina
About Python for loops
Install python on WSL
Tool to make mask image for ETC in Python
Python basics ② for statement
How to install Python
Install Python on Pidora.
Install Scrapy on python3
Install Python on Mac
How to install python
Install Python 3 on Mac
Install python from source
Install Python3.4 on CentOS 6.6
About Python, for ~ (range)
Install Python Jupyter lab
Install python external library
python textbook for beginners
Install python (pyenv, pyenv-virtualenv)
Refactoring tools for Python
Install Voluptuous with Python 2.5
Install python on windows
python for android Toolchain
Compile and install MySQL-python for python2.7 on amazon linux
Python PyTorch install tips
Install Python 2.7.3 on CentOS 5.4
Install python with pyenv
Install Python 3.3 on Ubuntu 12.04
Install Python 3.4 on Mac
OpenCV for Python beginners
Install Python 3.6 on Docker
[Python] for statement error
Python environment for projects
For those who can't install Python on Windows XP
I touched the latest automatic test tool "Playwright for Python"
First Fabric (Python deployment tool)
[2020.8 latest] How to install Python
How to install Python [Windows]
About Fabric's support for Python 3
Install Python 3.8 on RHEL 8 (AppStream)
Python list, for statement, dictionary
Install watchdog on Windows + Python 3.3
Python for Data Analysis Chapter 4
Modern Python for intermediate users