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> wrote:

>
> ------------------------------
> *发件人:* Cao Xuan
> *发送时间:* 2019年1月3日 0:25
> *收件人:* 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
> 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