openbabel / openbabel

Open Babel is a chemical toolbox designed to speak the many languages of chemical data.
http://openbabel.org/
GNU General Public License v2.0
1.08k stars 414 forks source link

Pybel: Segmentation fault on obconversion #1618

Closed KeironO closed 7 years ago

KeironO commented 7 years ago

Environment Information

Open Babel version: Operating system and version: Ubuntu Linux 16.04 LTS

Expected Behavior

The correct conversion of an InChI string to SMILES.

Actual Behavior

Segmentation fault.

Steps to Reproduce

import pybel
inchi = "InChI=1S/C21H29NO8/c1-12-10-21(13(2)29-21)19(26)28-16-7-9-22(5)8-6-15(17(16)24)11-27-18(25)20(12,4)30-14(3)23/h6,12-13,16H,7-11H2,1-5H3/b15-6-/t12-,13-,16-,20-,21-/m1/s1"

print pybel.readstring("inchi", inchi).write("smi").rstrip()

It crashes on the following line in pybel.py (186).

    success = obconversion.ReadString(obmol, string)
KeironO commented 7 years ago

Interestingly, the same error occurs if you use openbabel directly.

import openbabel

inchi = "InChI=1S/C21H29NO8/c1-12-10-21(13(2)29-21)19(26)28-16-7-9-22(5)8-6-15(17(16)24)11-27-18(25)20(12,4)30-14(3)23/h6,12-13,16H,7-11H2,1-5H3/b15-6-/t12-,13-,16-,20-,21-/m1/s1"

conv = openbabel.OBConversion()
conv.SetInAndOutFormats("inchi", "smi")
mol = openbabel.OBMol()
ReadString(mol, inchi)
smiles = conv.WriteString(mol).rstrip()
fredrikw commented 7 years ago

I think there is a problem with the installation somehow. At least it's working fine for me. Do you have the same problem in the commandline?

obabel -iinchi -:"InChI=1S/C21H29NO8/c1-12-10-21(13(2)29-21)19(26)28-16-7-9-22(5)8-6-15(17(16) 24)11-27-18(25)20(12,4)30-14(3)23/h6,12-13,16H,7-11H2,1-5H3/b15-6-/t12-,13-,16-,20-,21-/m1/s1" -osmi

KeironO commented 7 years ago
*** Open Babel Error  in InChI code
  Reading InChI failed
0 molecules converted

Error there too. I used the openbabel package found on the standard Ubuntu repository, if that helps?

KeironO commented 7 years ago

Even 2.4.0 used in the openbabel snap package throws an error.

sudo snap install openbabel

openbabel.obabel -iinchi -:"InChI=1S/C21H29NO8/c1-12-10-21(13(2)29-21)19(26)28-16-7-9-22(5)8-6-15(17(16) 24)11-27-18(25)20(12,4)30-14(3)23/h6,12-13,16H,7-11H2,1-5H3/b15-6-/t12-,13-,16-,20-,21-/m1/s1" -osmi
==============================
*** Open Babel Error  in InChI code
  Reading InChI failed
0 molecules converted
KeironO commented 7 years ago

2.4.1 found here throws a similar error:

wget http://ftp.us.debian.org/debian/pool/main/o/openbabel/openbabel_2.4.1-1_amd64.deb
sudo dpkg -i openbabel_2.4.1-1_amd64.deb
obabel -iinchi -:"InChI=1S/C21H29NO8/c1-12-10-21(13(2)29-21)19(26)28-16-7-9-22(5)8-6-15(17(16) 24)11-27-18(25)20(12,4)30-14(3)23/h6,12-13,16H,7-11H2,1-5H3/b15-6-/t12-,13-,16-,20-,21-/m1/s1" -osmi
==============================
*** Open Babel Error  in InChI code
  Reading InChI failed
0 molecules converted
fredrikw commented 7 years ago

I'm sorry, there seems to have sneaked in a copy/paste error, there should be no space between "16)" and "24)" that occurs in the line brake in my comment. So the command should be:

obabel -iinchi -:"InChI=1S/C21H29NO8/c1-12-10-21(13(2)29-21)19(26)28-16-7-9-22(5)8-6-15(17(16)24)11-27-18(25)20(12,4)30-14(3)23/h6,12-13,16H,7-11H2,1-5H3/b15-6-/t12-,13-,16-,20-,21-/m1/s1" -osmi

KeironO commented 7 years ago
obabel -iinchi -:"InChI=1S/C21H29NO8/c1-12-10-21(13(2)29-21)19(26)28-16-7-9-22(5)8-6-15(17(16)24)11-27-18(25)20(12,4)30-14(3)23/h6,12-13,16H,7-11H2,1-5H3/b15-6-/t12-,13-,16-,20-,21-/m1/s1" -osmi
[1]    9798 segmentation fault (core dumped)  obabel -iinchi  -osmi

Segmentation fault error.

fredrikw commented 7 years ago

Or, the same error as in Python...

KeironO commented 7 years ago

Ok, the snap version seems to work - but I'm unable to interface with it using python. Any suggestions @fredrikw?

KeironO commented 7 years ago

Temporary solution.

Install Ubuntu snap package via:

sudo snap install openbabel

And use the following script to retrieve SMILES:

from subprocess import check_output

inchi = "InChI=1S/C21H29NO8/c1-12-10-21(13(2)29-21)19(26)28-16-7-9-22(5)8-6-15(17(16)24)11-27-18(25)20(12,4)30-14(3)23/h6,12-13,16H,7-11H2,1-5H3/b15-6-/t12-,13-,16-,20-,21-/m1/s1"
smiles = check_output('openbabel.obabel -iinchi -:"%s" -osmi' %inchi, shell=True).decode().strip()