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

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

我一直在尝试使用 PubChemPy 在 python 上找出这个错误,但我被卡住了。 我正在尝试输入一份化学品清单,并为大约 200 种化学品的清单生成 Canonical Smiles 信息。 这是我使用的代码

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

任何帮助将不胜感激

看起来您正在将一个列表传递给 get_properties(),但它不接受列表,但可以接受几个不同的参数。以下是当前文档的摘录:

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

你的问题在有用的细节方面缺乏很多,但我想你实际上想要这样的东西:

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

第二次编辑:此代码从名称列表到获取 cid,然后是 属性:

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 需要 cid 作为必需参数。您不能输入化学名称。因此,您需要一个中间步骤来获取与带有 pcp.get_cids 的名称对应的标识符列表,我在上面的代码中已经完成了。