This is just memorandum for my self.
RDKit has ConvertToNumpyArray method for converting rdkit fp to numpy array. But there is not direct method for convert numpy array to rdkit fp.
However, rdkit has CreateFromBitString method.
So, I tried to convert numpy array to rdkit fp with the method.
import numpy as np from rdkit import Chem from rdkit.Chem import AllChem from rdkit.Chem import DataStructs mol = Chem.MolFromSmiles('C1CCCOC1') fp = AllChem.GetMorganFingerprintAsBitVect(mol, 2, nBits=512) arr = np.zeros((0,), dtype=np.int8) arr > array([], dtype=int8)
Then convert fp to numpy array.
DataStructs.ConvertToNumpyArray(fp,arr) arr > array([0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Next convert numpy array to rdkit fp.
bitstring="".join(arr.astype(str)) fp2 = DataStructs.cDataStructs.CreateFromBitString(bitstring)
Finally, check both fingerprint.
list(fp.GetOnBits()) > [2, 4, 11, 28, 144, 225, 381, 414, 438] list(fp2.GetOnBits()) > [2, 4, 11, 28, 144, 225, 381, 414, 438]
RDKit has many functions. I am happy to find new methods that I have not used before. ;)
Thanks man, this helped me out quite a bit. I really needed to get those bit fingerprints into a form I could do some actual operations with and would not have guessed the boost::python::api::object in the signature meant a numpy array