TypeError:get_properties()缺少1个必需的位置参数:“标识符”

2024-05-16 21:20:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在尝试使用PubChemPy在python上找出这个错误,但我被卡住了。 我正在尝试输入一个化学品列表,并生成一个包含大约200种化学品的列表的规范微笑信息。 这是我正在使用的代码

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

任何帮助都将不胜感激


Tags: of代码namein规范信息列表for
2条回答

第二次编辑:此代码从名称列表到获取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_属性需要cid作为必需参数。你不能输入化学名称。因此,您需要一个中间步骤来获取与pcp.get_cids中的名称对应的标识符列表,我在上面的代码中已经完成了这项工作

看起来您正在将列表传递到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)

相关问题 更多 >