Re: [Rdkit-discuss] Loading mols into postgresql using cartridge
Open-Source Cheminformatics and Machine Learning
Brought to you by:
glandrum
From: Greg L. <gre...@gm...> - 2012-08-25 04:24:40
|
On Wed, Aug 22, 2012 at 5:20 AM, Greg Landrum <gre...@gm...> wrote: > > The current version of the cartridge does not support loading (or > exporting) molecules as RDKit pickles. It should be pretty easy for me > to add this capability though, so I will look into it. The svn version of the cartridge is now capable of sending/receiving molecules and bit-vector fingerprints as binary strings (bytea's in postrgresql). Here's a demonstration from Python. For molecules: In [7]: m = Chem.MolFromSmiles('c1ccccc1') In [8]: mpkl = m.ToBinary() In [9]: curs.execute("select mol_from_pkl(%s)",(buffer(mpkl),)) In [10]: curs.fetchone() Out[10]: ('c1ccccc1',) In [11]: curs.execute("select mol_to_pkl('c1ccccn1'::mol)") In [12]: mpkl = curs.fetchone()[0] In [13]: Chem.MolToSmiles(Chem.Mol(str(mpkl))) Out[13]: 'c1ccncc1' For bit vects: In [14]: fp = AllChem.GetMorganFingerprintAsBitVect(Chem.MolFromSmiles('c1ccccc1'),2,512) In [15]: pkl = DataStructs.BitVectToBinaryText(fp) In [16]: curs.execute("select size(bfp_from_binary_text(%s))",(buffer(pkl),)) In [17]: curs.fetchone() Out[17]: (512,) In [18]: curs.execute("select tanimoto_sml(bfp_from_binary_text(%s),morganbv_fp('c1ccccc1'))",(buffer(pkl),)) In [19]: curs.fetchone() Out[19]: (1.0,) In [20]: curs.execute("select bfp_to_binary_text(morganbv_fp('c1ccccc1'))") In [21]: pkl = curs.fetchone()[0] In [23]: nfp = DataStructs.CreateFromBinaryText(str(pkl)) In [24]: list(nfp.GetOnBits()) Out[24]: [64, 337, 389] In [25]: list(fp.GetOnBits()) Out[25]: [64, 337, 389] The corresponding C++ calls are: - to get a molecule pickle: MolPickler::pickleMol - to construct a molecule from a pickle: ROMol(pkl) - to get a fingerprint as binary text: BitVectToBinaryText - to fill an already constructed fingerprint from binary text (the size of the fp should be 8* the length of the binary text): UpdateBitVectFromBinaryText Best, -greg |