0

I'm new to Rdkit. I need to generate fingerprint in integer/count form. I have tried many alternatives but always I get the message:

DataStructs.ConvertToNumpyArray(fps2[i], arr[i])
ArgumentError: Python argument types in
rdkit.DataStructs.cDataStructs.ConvertToNumpyArray(UIntSparseIntVect, numpy.ndarray)
did not match C++ signature:
ConvertToNumpyArray(RDKit::DiscreteValueVect bv, boost::python::api::object destArray)
ConvertToNumpyArray(ExplicitBitVect bv, boost::python::api::object destArray)

My Code as below:

import numpy as np
from rdkit.Chem import AllChem as Chem
from rdkit import DataStructs
from rdkit.Chem.AtomPairs import Pairs

suppl = Chem.SDMolSupplier('5ht3ligs.sdf')
fps1 = [Chem.RDKFingerprint(x, fpSize=1024, minPath=1, maxPath=4) for x in suppl]
fps2 = [Chem.GetHashedMorganFingerprint(x, radius=2, nBits=1024) for x in suppl]
fps3 = [Chem.GetMorganFingerprint(x, radius=2, useCounts= True) for x in suppl]
fps4 = [Pairs.GetAtomPairFingerprintAsIntVect(x) for x in suppl]
arr = np.zeros((4,1024), dtype = np.int8)
for i in range(0,len(suppl)):
DataStructs.ConvertToNumpyArray(fps2[i], arr[i])
print(arr)

I am also wondering if there is a way in Rdkit to print the fingerprint directly to the text file similar to Chem.SDwrite but to save fingerprint? However, If I can convert the count fingerprint to an array then I can use Python code to save to text file.

David Buck
  • 3,752
  • 35
  • 31
  • 35
Ammar
  • 1
  • If I see it correctly you have a sdf with 4 compounds and want an array with shape (4, 1024). I tried the script with your fps2 and a sdf with 4548 compounds and got an array with shape (4548,1024) without an error. – rapelpy Mar 03 '20 at 18:33
  • For me its work only for fps1 the others type of fingerprints has the errors. – Ammar Mar 04 '20 at 10:45
  • fps1 works fine. fps3 works when I use Chem.GetMorganFingerprintAsBitVect(x, radius=2, nBits=1024), but you get the same fp as fps2. fps4 works when I use Pairs.GetHashedAtomPairFingerprint(x, nBits=1024). – rapelpy Mar 04 '20 at 17:10

0 Answers0