Python Forum
Converting Smiles to Fingerprint with pandas iterrows/apply-function:
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Converting Smiles to Fingerprint with pandas iterrows/apply-function:
#1
Im trying to iterate my function over a column but it doesn't work properly. Could you guys show me where I have to correct my code?

Thats my 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)
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)

Im trying to iterate my function over a column but it doesn't work properly. Could you guys show me where I have to correct my code?

Thank you guys for your help!
Reply


Messages In This Thread
Converting Smiles to Fingerprint with pandas iterrows/apply-function: - by Jompie96 - Jul-04-2019, 01:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to apply function lower() to the list? Toltimtixma 2 756 Feb-10-2023, 05:15 PM
Last Post: Toltimtixma
  Use of groupby in a function with Pandas Paulman 0 928 Dec-03-2021, 04:56 PM
Last Post: Paulman
  IF statement to apply at each date illmattic 2 2,599 Apr-08-2021, 12:31 PM
Last Post: illmattic
  Function won't apply dynamically in timeseries illmattic 1 1,708 Jan-08-2021, 03:15 PM
Last Post: stullis
  Pandas's regular expression function result is so strange cools0607 6 3,097 Jun-15-2020, 07:34 AM
Last Post: cools0607
  How to apply VLookup formula jonzee 2 3,501 Jan-12-2020, 04:16 PM
Last Post: Clunk_Head
  Issue in .apply function fullstop 0 1,472 Dec-17-2019, 01:29 PM
Last Post: fullstop
  Apply a function with pandas Jompie96 2 2,181 Jun-13-2019, 07:04 PM
Last Post: Jompie96
  help with converting C# function to Python korenron 17 11,146 May-19-2019, 10:26 AM
Last Post: Gribouillis
  zklib fingerprint attendance problem daemonsh 1 2,697 Jul-29-2018, 04:30 PM
Last Post: daemonsh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020