TypeError: get_properties() missing 1 required positional argument: 'identifier'

330 Views Asked by At

I have been trying to figure out this error on python using PubChemPy but I'm stuck. I am trying to input a list of chemicals and gen the Canonical Smiles information for a list of about 200 chemicals. This is the code I am using

for i in List_of_Chemicals['Chemical name']:
    prop = pcp.get_properties(['CanonicalSMILES'])

any help would be appreciated

2

There are 2 best solutions below

10
H. McClelland On BEST ANSWER

2nd edit: This code goes from a list of names to getting the cid and then the property:

import pubchempy as pcp

# list of chemical names
List_of_Chemicals = ['benzene', 'toluene', '2-nonenal']

for chemical_name in List_of_Chemicals:

    cid=pcp.get_cids(chemical_name)
    prop = pcp.get_properties('CanonicalSMILES', cid)
    print (chemical_name + ' ' + str(prop))

get_properties needs cid as a required argument. You cannot pass in chemical names. So you need an intermediate step to get a list of identifiers corresponding to the names with pcp.get_cids, which I've done in the code above.

0
dylanjm On

Looks like you are passing a list into get_properties() but it doesn't take a list, but can take several different parameters. Here is an excerpt from the current documentation:

The get_properties function allows the retrieval of specific properties without having to deal with entire compound records. This is especially useful for retrieving the properties of a large number of compounds at once:

p = pcp.get_properties('IsomericSMILES', 'CC', 'smiles', searchtype='superstructure')

https://pubchempy.readthedocs.io/en/latest/guide/properties.html

Your question is lacking quite a bit in terms of useful details but I'd imagine you'd actually want something like:

for i in List_of_Chemicals['Chemical name']:
    prop = pcp.get_properties(i)