3

I'm using the RDKit package to convert some SMILES into a Fingerprint.

My problem is, I use Scikit-learn and I want to do a CV. For the CV, I need the np.array data structure. For one kind of fingerprint, I convert a data structure to a structure of 0's and 1's.

Here is just an arbitrary example

print (x) 
# A vector containing a lot of 
rdkit.DataStructs.cDataStructs.ExplicitBitVect object at 0x05E498F0 
objects will be created

x=np.array(x)
print (x)
# A vector of 1's and 0's will be created.

I don't know why the numpy array converting, changes the type.

For an object like rdkit.DataStructs.cDataStructs.LongSparseIntVect object at 0x05DDF960 Numpy changes the vector to the same structure.

I'm asking because for 2 out of the 4 fingerprints, I get the following error, due to the Numpy conversion:

AttributeError: 'numpy.ndarray' object has no attribute 'GetNumBits'
for fingerprint morgan

Code

from rdkit import DataStructs
from rdkit.Chem.Fingerprints import FingerprintMols
from rdkit.Chem import AllChem
from rdkit import Chem
from rdkit import DataStructs
from rdkit.Chem import MACCSkeys
import numpy as np


ms = [Chem.MolFromSmiles('CCOC'),    Chem.MolFromSmiles('CCO'),Chem.MolFromSmiles('COC')]
fps = [MACCSkeys.GenMACCSKeys(x) for x in ms]
a=DataStructs.FingerprintSimilarity(fps[0],fps[1])


#everything is fine
print fps
print a
# output: [<rdkit.DataStructs.cDataStructs.ExplicitBitVect object at 0x0325CE30>, <rdkit.DataStructs.cDataStructs.ExplicitBitVect object at 0x0325CE68>, <rdkit.DataStructs.cDataStructs.ExplicitBitVect object at 0x0325CEA0>]


#now the error occurs

fps=np.array(fps)
print fps

#output: [[0 0 0 0 1 0 1 .....] [1 0 0 0 1...0 1] [1 0 0 .... 1 1]
a=DataStructs.FingerprintSimilarity(fps[0],fps[1])
#AttributeError: 'numpy.ndarray' object has no attribute 'GetNumBits'
Joooeey
  • 3,394
  • 1
  • 35
  • 49
auronsen
  • 225
  • 1
  • 3
  • 12
  • Could you make a [minimal, complete and verifiable example](https://stackoverflow.com/help/mcve) of what it is you currently have and then show what you're expecting to get? It's difficult for me to understand what you want to do, but from your very last phrase, I gather you're not using the library as intended. – Oliver W. Nov 25 '15 at 00:05
  • I tried it. maybe this will help to understand what i mean – auronsen Nov 25 '15 at 00:24
  • I solved it in a different way, but thank you! next time i will explain it on a better way – auronsen Nov 25 '15 at 01:56
  • perhaps you can add the solution you've found (or alternate route) to tackle your problem as an answer. Then, you can also accept your own answer, thereby marking this issue as resolved, as well as leaving a hint for someone in the future who might be experiencing something similar to what you're experiencing. – Oliver W. Nov 25 '15 at 14:52
  • I actually didnt solved this problem, i just take an another way, to avoid this converting, so it isnt realy a answer for this problem – auronsen Nov 26 '15 at 23:36

0 Answers0