rvianello / chemicalite

An SQLite extension for chemoinformatics applications.
https://chemicalite.readthedocs.org/en/latest/
BSD 3-Clause "New" or "Revised" License
55 stars 8 forks source link

mol_from_binary_mol results in NoneType molecule field #12

Open mwinokan opened 8 months ago

mwinokan commented 8 months ago

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!

rvianello commented 8 months ago

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!

mwinokan commented 8 months ago

@rvianello thank you. My details are: