Created
April 29, 2015 14:34
-
-
Save nickvandewiele/e512e4025fe1586e8ac0 to your computer and use it in GitHub Desktop.
Chemoinformatics: Differences between OB and RDKit IDx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import openbabel as ob | |
from rdkit import Chem | |
""" | |
This snippet shows that the IDx getter of OpenBabel and RDKit differ in implementation. | |
Openbabel IDx: starts at 1 | |
RDKit IDx: starts at 0 | |
""" | |
def main(): | |
inchistr = "InChI=1S/CH4/h1H4" | |
print 'OpenBabel:' | |
obConversion = ob.OBConversion() | |
obConversion.SetInAndOutFormats("inchi", "smi") | |
obmol = ob.OBMol() | |
obConversion.ReadString(obmol, inchistr) | |
obmol.AddHydrogens() | |
for obatom in ob.OBMolAtomIter(obmol): | |
print 'Openbabel IDx: ', obatom.GetIdx() | |
print 'RDKit: ' | |
rdkitmol = Chem.inchi.MolFromInchi(inchistr, removeHs=False) | |
rdkitmol = Chem.AddHs(rdkitmol) | |
for rdatom in rdkitmol.GetAtoms(): | |
print 'RDKit IDx: ', rdatom.GetIdx() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment