Hi Greg,

Thank you so much for the help!

Pure RDKit functionality really helpful!

Thanks,
Xuan

________________________________
发件人: Greg Landrum <greg.land...@gmail.com>
发送时间: 2019年1月4日 0:08
收件人: Cao Xuan
抄送: rdkit-discuss@lists.sourceforge.net
主题: Re: [Rdkit-discuss] 转发: Reading the fingerprint

Hi Xuan,

The easiest way to do this, and the one I'd recommend using most of the time, 
is using Python's builtin pickle mechanism:
In [5]: fp = Chem.RDKFingerprint(m)

In [6]: import pickle

In [7]: fp2 = pickle.loads(pickle.dumps(fp))

In [8]: fp == fp2
Out[8]: True

But you can also use pure RDKit functionality if you want. This method uses an 
RDKit-internal format (the same used by pickling):

In [9]: fp2 = DataStructs.ExplicitBitVect(fp.ToBinary())

In [10]: fp == fp2
Out[10]: True

This method uses a binary string directly encoding the contents of the 
fingerprint:

In [12]: fp2 = DataStructs.CreateFromBinaryText( 
DataStructs.BitVectToBinaryText(fp)  )

In [13]: fp == fp2
Out[13]: True

And, finally, the least efficient approach (using a string of 0s and 1s):
In [14]: fp2 = DataStructs.CreateFromBitString(fp.ToBitString())

In [15]: fp == fp2
Out[15]: True

I hope this helps,
-greg



On Thu, Jan 3, 2019 at 4:36 PM Cao Xuan 
<danis....@hotmail.com<mailto:danis....@hotmail.com>> wrote:

________________________________
发件人: Cao Xuan
发送时间: 2019年1月3日 0:25
收件人: 
rdkit-discuss@lists.sourceforge.net<mailto:rdkit-discuss@lists.sourceforge.net>
主题: Reading the fingerprint

Hi All,

Is that possible to store the fingerprint on disk in string or byte format, and 
then read the fingerprint by initialize an empty 
DataStructs.cDataStructs.ExplicitBitVect() (I tried to call SetBit() and 
SetBitFromList() but no success).

I also found the post https://sourceforge.net/p/rdkit/mailman/message/28969251/ 
but it is using C++, while I am using the python.

#
bit_binary_text = DataStructs.cDataStructs.BitVectToBinaryText(fps)
temp_bitvect    = DataStructs.cDataStructs.ExplicitBitVect(bit_binary_text)


ValueError: bad version in BitVect pickle

The reason that I want to read fingerprint from disk is because I want to do 
similarity check with rdkit.DataStructs.FingerprintSimilarity(fp1, fp2, 
metric=<Boost.Python.function object>).

Thank you for help!
Xuan
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net<mailto:Rdkit-discuss@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to