Obtaining Molecule Description using Open Babel / PyBel
By Güngör Budak
- 2 minutes read - 241 wordsOpen Babel is a great tool to analyze and investigate molecular data (.MOL, .SDF files). Its Python API is particularly very nice if you are familiar with Python already. In this post, I’ll demonstrate how you can obtain molecule description such as molecular weight, HBA, HBD, logP, formula, number of chiral centers using PyBel.
Installation
1$ sudo apt-get install openbabel python-openbabel
Usage for MW, HBA, HBD, logP
After reading .MOL file, we need to use calcdesc
method with descnames
argument for getting the descriptions. Getting formula is different, though.
1gungor@gungors-mint ~/Desktop $ python
2Python 2.7.6 (default, Mar 22 2014, 22:59:56)
3[GCC 4.8.2] on linux2
4Type "help", "copyright", "credits" or "license" for more information.
5>>> from pybel import *
6>>> mol = readfile('mol', 'benzene.mol').next()
7>>> desc = mol.calcdesc(descnames=['MW', 'logP', 'HBA1', 'HBD'])
8>>> desc['formula'] = mol.formula
9>>> print desc<br />{'HBA1': 0.0, 'HBD': 0.0, 'MW': 78.11184, 'logP': 1.6865999999999999, 'formula': 'C6H6'}
Usage for Number of Chiral Centers
This is not included in PyBel, or I couldn’t find it but Open Babel comes with obchiral terminal command which returns the chiral atoms found in the molecules. We can parse this output to get the number of chiral centers.
1>>> from subprocess import Popen, PIPE
2>>> p = Popen(['obchiral', 'brg_flap_1.mol'], stdout=PIPE, stderr=PIPE)
3>>> stdout, stderr = p.communicate()
4>>> chiral_num = stdout.count('Is Chiral')
5>>> print chiral_num
61
So you can use above codes to get molecule description including molecular weight, HBA, HBD, logP, formula, number of chiral centers.