1

I'm trying to iterate my function over a column but it doesn't work properly. I get this error code:

ArgumentError: Python argument types in
    rdkit.Chem.rdmolops.RDKFingerprint(NoneType, int, int, int, int, int, float, int)
did not match C++ signature:
    RDKFingerprint(RDKit::ROMol mol, unsigned int minPath=1, unsigned int maxPath=7, unsigned int fpSize=2048, unsigned int nBitsPerHash=2, bool useHs=True, double tgtDensity=0.0, unsigned int minSize=128, bool branchedPaths=True, bool useBondOrder=True, boost::python::api::object atomInvariants=0, boost::python::api::object fromAtoms=0, boost::python::api::object atomBits=None, boost::python::api::object bitInfo=None)

Code:

def SmilesToFPS(smiles):
    mol = Chem.MolFromSmiles(smiles)
    fps = FingerprintMols.FingerprintMol(mol)
    #fpSize=1024, minPath=1, maxPath=7,
     #    bitsPerHash=2, useHs=True, 
      #    tgtDensity=0.0, minSize=0, 
       #    branchedPaths=True, useBondOrder=True, 
        #      atomInvariants=0, fromAtoms=0, atomBits=None, bitInfo=None)
    return print(fps.ToBitString()) 

for index, row in df_3.iterrows():

#for i, number in df_3['SmilesCode'].iteritems(): 
#this doesn't work.thats why I used .iterrows
    try:
        fingerprints = SmilesToFPS(smiles)
        
    except:
        fingerprints = 'ERROR'
    print('\r', row['SmilesCode'], fingerprints, end='')
    
    smiles_list.append(row['SmilesCode'])
    fingerprint_list.append(fingerprints)
    
df_4 = pd.DataFrame({'SmilesCode' : smiles_list, 'Fingerprints' : fingerprint_list})

I expect a Bitstring for every SmilesCode but I only get Errors for every row/SmilesCode. The defined function does work tho but not if I use it to iterate over my desired column! If I use the apply() function from pandas:

df_modDfObj = df_3.apply(SmilesToFPS)
Vandan Revanur
  • 459
  • 6
  • 17
Mr. Chang
  • 11
  • 4
  • I did not test the whole script, but you tried to return and append the print function instead the bitstring. return print(fps.ToBitString()) should be changed to return fps.ToBitString(). – rapelpy Jul 04 '19 at 14:01
  • Thank you for your input! I changed it. But it doesnt solve my problems. – Mr. Chang Jul 04 '19 at 14:10
  • After I added fingerprint_list and smiles_list to your code I tested it. SmilesToFPS(row['SmilesCode']) instead of SmilesToFPS(smiles) works. – rapelpy Jul 04 '19 at 15:26
  • Thank you for your effort. I found this myself a few hours ago haha. – Mr. Chang Jul 04 '19 at 16:32

0 Answers0