chemicalite icon indicating copy to clipboard operation
chemicalite copied to clipboard

mol_from_binary_mol results in NoneType molecule field

Open mwinokan opened this issue 1 year ago • 2 comments

Related to #11, I have been able to write rdkit.Chem.Mol objects to a table using the mol_from_smiles function provided by the chemicalite extension, however when I write an arbitrary Mol object to the table using the mol_from_binary_mol function, only None is stored.

See the following minimal example returns:

import sqlite3
from rdkit import Chem

connection = sqlite3.connect('test.db')

connection.enable_load_extension(True)
connection.load_extension('chemicalite')
connection.enable_load_extension(False)

connection.execute("CREATE TABLE compounds(id INTEGER PRIMARY KEY, name TEXT, smiles TEXT, molecule MOL)")

# this works fine
connection.cursor().execute("INSERT INTO compounds(name, smiles, molecule) "
                            "VALUES(?1, ?2, mol_from_smiles(?2))", ("acetone","CC(=O)C"))

# here the molecule field contains None
connection.cursor().execute("INSERT INTO compounds(name, smiles, molecule) "
                            "VALUES(?1, ?2, mol_from_binary_mol(?3))", ("acetone","CC(=O)C",Chem.MolFromSmiles("CC(=O)C").ToBinary()))

# see the contents of the table
connection.cursor().execute("SELECT * FROM compounds").fetchall()

The last line returns:

[(b'MOL\x00\xef\xbe\xad\xde\x00\x00\x00\x00\r\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x04\x00\x00\x00\x03\x00\x00\x00\x80\x01\x06\x00`\x00\x00\x00\x01\x03\x06\x00(\x00\x00\x00\x03\x04\x08\x00(\x00\x00\x00\x03\x02\x06\x00`\x00\x00\x00\x01\x03\x0b\x00\x01\x00\x01\x02\x08\x02\x01\x03\x00\x14\x00@\t\x00\x00\x00\x00\x00\x00\x00?\x00\x00\x00\x00\x12f\x00\x00\x00\x03\x00\x00\x00\x0f\x00\x00\x00__computedProps\x06\x02\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00numArom\x0f\x00\x00\x00_StereochemDone\x07\x00\x00\x00numArom\x01\x00\x00\x00\x00\x0f\x00\x00\x00_StereochemDone\x01\x01\x00\x00\x00\x13:\xf4\x00\x00\x00\x02\x00\x00\x00\x0f\x00\x00\x00__computedProps\x06\x01\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00_CIPRank\x08\x00\x00\x00_CIPRank\x02\x00\x00\x00\x00\x02\x00\x00\x00\x0f\x00\x00\x00__computedProps\x06\x01\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00_CIPRank\x08\x00\x00\x00_CIPRank\x02\x01\x00\x00\x00\x02\x00\x00\x00\x0f\x00\x00\x00__computedProps\x06\x01\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00_CIPRank\x08\x00\x00\x00_CIPRank\x02\x02\x00\x00\x00\x02\x00\x00\x00\x0f\x00\x00\x00__computedProps\x06\x01\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00_CIPRank\x08\x00\x00\x00_CIPRank\x02\x00\x00\x00\x00\x13;\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x13\x16',),
 (None,)]

I would like to be able to store the rdkit molecule including conformer, hence the desire not to generate the table entry using mol_from_smiles

Thank you!

mwinokan avatar Jan 16 '24 11:01 mwinokan

Hi @mwinokan thank you for reporting the problem, I hope I'll be able to look into this during the next few days. In the meantime, could you please share some details about your software configuration? Thanks!

rvianello avatar Jan 18 '24 22:01 rvianello

@rvianello thank you. My details are:

  • macOS Ventura 13.6 on Intel
  • SQLite version 3.41.2
  • conda environment: py310.txt

mwinokan avatar Jan 19 '24 09:01 mwinokan