这是一个字典,我必须将它转换为一个列表(我要向每个字符串添加一些内容),每个化学实体都有它自己的InChI键。我想提取所有的InChI键,但似乎无法做到,因为字符串'standardInChIKey‘不是我可以调用的键。
有人知道我是怎么做到这一点的吗?
我是编程的初学者,所以对于任何明显的错误,我很抱歉。
my_list = [{'1': {'oscar': [{'md5Sum': '7b6b48af2461f51e889d5f42d0f3f3fa', 'chemicalData': {}}]}}, {'2': {'oscar': [{'md5Sum': 'd9734945a440de92cc1802c1084b4874', 'chemicalData': {'Aporphinium': {'name': 'Aporphinium', 'standardInChI': 'InChI=1S/C17H17N/c1-18-10-9-12-6-4-8-15-14-7-3-2-5-13(14)11-16(18)17(12)15/h2-8,16H,9-11H2,1H3/p+1', 'standardInChIKey': 'BZKUYNBAFQJRDM-UHFFFAOYSA-O'}, 'DMSO': {'name': 'DMSO', 'standardInChI': 'InChI=1S/C2H6OS/c1-4(2)3/h1-2H3', 'standardInChIKey': 'IAZDPXIOMUYVGZ-UHFFFAOYSA-N'}, 'hydroxide': {'name': 'hydroxide', 'standardInChI': 'InChI=1S/H2O/h1H2/p-1', 'standardInChIKey': 'XLYOFNOQVPJJNP-UHFFFAOYSA-M'}, 'picrate': {'name': 'picrate', 'standardInChI': 'InChI=1S/C6H3N3O7/c10-6-4(8(13)14)1-3(7(11)12)2-5(6)9(15)16/h1-2,10H/p-1', 'standardInChIKey': 'OXNIZHLAWKMVMX-UHFFFAOYSA-M'}, 'Isothebaine': {'name': 'Isothebaine', 'standardInChI': 'InChI=1S/C19H21NO3/c1-20-8-7-12-10-15(23-3)19(21)18-16(12)13(20)9-11-5-4-6-14(22-2)17(11)18/h4-6,10,13,21H,7-9H2,1-3H3/t13-/m0/s1', 'standardInChIKey': 'RQCOQZNIQLKGTN-ZDUSSCGKSA-N'}, 'EtOH': {'name': 'EtOH', 'standardInChI': 'InChI=1S/C2H6O/c1-2-3/h3H,2H2,1H3', 'standardInChIKey': 'LFQSCWFLJHTTHZ-UHFFFAOYSA-N'}, 'oxoaporphine': {'name': 'oxoaporphine', 'standardInChI': 'InChI=1S/C17H15NO/c1-18-10-16(19)14-8-4-7-13-12-6-3-2-5-11(12)9-15(18)17(13)14/h2-8,15H,9-10H2,1H3', 'standardInChIKey': 'QOJUUOXLHHMNMK-UHFFFAOYSA-N'}, 'ethanol': {'name': 'ethanol', 'standardInChI': 'InChI=1S/C2H6O/c1-2-3/h3H,2H2,1H3', 'standardInChIKey': 'LFQSCWFLJHTTHZ-UHFFFAOYSA-N'}, 'Aporphine': {'name': 'Aporphine', 'standardInChI': 'InChI=1S/C17H17N/c1-18-10-9-12-6-4-8-15-14-7-3-2-5-13(14)11-16(18)17(12)15/h2-8,16H,9-11H2,1H3', 'standardInChIKey': 'BZKUYNBAFQJRDM-UHFFFAOYSA-N'}, 'deuteriochloroform': {'name': 'deuteriochloroform', 'standardInChI': 'InChI=1S/CHCl3/c2-1(3)4/h1H/i1D', 'standardInChIKey': 'HEDRZPFGACZZDS-MICDWDOJSA-N'}, 'methoxyphenanthrene': {'name': 'methoxyphenanthrene', 'standardInChI': 'InChI=1S/C15H12O/c1-16-15-8-4-7-13-12-6-3-2-5-11(12)9-10-14(13)15/h2-10H,1H3', 'standardInChIKey': 'ONMKCYMMGBIVPT-UHFFFAOYSA-N'}, 'TETRAMETHOXYPHENANTHRENE': {'name': 'TETRAMETHOXYPHENANTHRENE', 'standardInChI': 'InChI=1S/C18H18O4/c1-19-15-13-10-9-11-7-5-6-8-12(11)14(13)16(20-2)18(22-4)17(15)21-3/h5-10H,1-4H3', 'standardInChIKey': 'PHIDHNJRDMYWKQ-UHFFFAOYSA-N'}, 'CH3OH': {'name': 'CH3OH', 'standardInChI': 'InChI=1S/CH4O/c1-2/h2H,1H3', 'standardInChIKey': 'OKKJLVBELUTLKV-UHFFFAOYSA-N'}, 'APORPHINE': {'name': 'APORPHINE', 'standardInChI': 'InChI=1S/C17H17N/c1-18-10-9-12-6-4-8-15-14-7-3-2-5-13(14)11-16(18)17(12)15/h2-8,16H,9-11H2,1H3', 'standardInChIKey': 'BZKUYNBAFQJRDM-UHFFFAOYSA-N'}, 'DIMETHOXYOXOAPORPHINE': {'name': 'DIMETHOXYOXOAPORPHINE', 'standardInChI': 'InChI=1S/C19H19NO3/c1-20-10-15(21)13-9-16(22-2)19(23-3)18-12-7-5-4-6-11(12)8-14(20)17(13)18/h4-7,9,14H,8,10H2,1-3H3', 'standardInChIKey': 'NOQPPVHNJNQIGF-UHFFFAOYSA-N'}, 'KBr': {'name': 'KBr', 'standardInChI': 'InChI=1S/BrH.K/h1H;/q;+1/p-1', 'standardInChIKey': 'IOLCXVTUBQKXJR-UHFFFAOYSA-M'}, 'aporphine': {'name': 'aporphine', 'standardInChI': 'InChI=1S/C17H17N/c1-18-10-9-12-6-4-8-15-14-7-3-2-5-13(14)11-16(18)17(12)15/h2-8,16H,9-11H2,1H3', 'standardInChIKey': 'BZKUYNBAFQJRDM-UHFFFAOYSA-N'}, 'Actinodaphnine': {'name': 'Actinodaphnine', 'standardInChI': 'InChI=1S/C18H17NO4/c1-21-14-7-11-10(5-13(14)20)4-12-16-9(2-3-19-12)6-15-18(17(11)16)23-8-22-15/h5-7,12,19-20H,2-4,8H2,1H3/t12-/m0/s1', 'standardInChIKey': 'VYJUHRAQPIBWNV-LBPRGKRZSA-N'}}}]}}如果我这样做:
my_list[1]['2']我得到了:
{'oscar': [{'md5Sum': 'b7bab051cbd99f75b61bd76f35c0e372',
'chemicalData': {'Aporphinium': {'name': 'Aporphinium',
'standardInChI': 'InChI=1S/C17H17N/c1-18-10-9-12-6-4-8-15-14-7-3-2-5-13(14)11-16(18)17(12)15/h2-8,16H,9-11H2,1H3/p+1',
'standardInChIKey': 'BZKUYNBAFQJRDM-UHFFFAOYSA-O'},
'DMSO': {'name': 'DMSO',
'standardInChI': 'InChI=1S/C2H6OS/c1-4(2)3/h1-2H3',
'standardInChIKey': 'IAZDPXIOMUYVGZ-UHFFFAOYSA-N'},
'hydroxide': {'name': 'hydroxide',
'standardInChI': 'InChI=1S/H2O/h1H2/p-1',
'standardInChIKey': 'XLYOFNOQVPJJNP-UHFFFAOYSA-M'},
'picrate': {'name': 'picrate',
'standardInChI': 'InChI=1S/C6H3N3O7/c10-6-4(8(13)14)1-3(7(11)12)2-5(6)9(15)16/h1-2,10H/p-1',
'standardInChIKey': 'OXNIZHLAWKMVMX-UHFFFAOYSA-M'},
'Isothebaine': {'name': 'Isothebaine',
'standardInChI': 'InChI=1S/C19H21NO3/c1-20-8-7-12-10-15(23-3)19(21)18-16(12)13(20)9-11-5-4-6-14(22-2)17(11)18/h4-6,10,13,21H,7-9H2,1-3H3/t13-/m0/s1',
'standardInChIKey': 'RQCOQZNIQLKGTN-ZDUSSCGKSA-N'},
'EtOH': {'name': 'EtOH',
'standardInChI': 'InChI=1S/C2H6O/c1-2-3/h3H,2H2,1H3',
'standardInChIKey': 'LFQSCWFLJHTTHZ-UHFFFAOYSA-N'},
'oxoaporphine': {'name': 'oxoaporphine',
'standardInChI': 'InChI=1S/C17H15NO/c1-18-10-16(19)14-8-4-7-13-12-6-3-2-5-11(12)9-15(18)17(13)14/h2-8,15H,9-10H2,1H3',
'standardInChIKey': 'QOJUUOXLHHMNMK-UHFFFAOYSA-N'},
'ethanol': {'name': 'ethanol',
'standardInChI': 'InChI=1S/C2H6O/c1-2-3/h3H,2H2,1H3',
'standardInChIKey': 'LFQSCWFLJHTTHZ-UHFFFAOYSA-N'},
'Aporphine': {'name': 'Aporphine',
'standardInChI': 'InChI=1S/C17H17N/c1-18-10-9-12-6-4-8-15-14-7-3-2-5-13(14)11-16(18)17(12)15/h2-8,16H,9-11H2,1H3',
'standardInChIKey': 'BZKUYNBAFQJRDM-UHFFFAOYSA-N'},
'deuteriochloroform': {'name': 'deuteriochloroform',
'standardInChI': 'InChI=1S/CHCl3/c2-1(3)4/h1H/i1D',
'standardInChIKey': 'HEDRZPFGACZZDS-MICDWDOJSA-N'},
'methoxyphenanthrene': {'name': 'methoxyphenanthrene',
'standardInChI': 'InChI=1S/C15H12O/c1-16-15-8-4-7-13-12-6-3-2-5-11(12)9-10-14(13)15/h2-10H,1H3',
'standardInChIKey': 'ONMKCYMMGBIVPT-UHFFFAOYSA-N'},
'TETRAMETHOXYPHENANTHRENE': {'name': 'TETRAMETHOXYPHENANTHRENE',
'standardInChI': 'InChI=1S/C18H18O4/c1-19-15-13-10-9-11-7-5-6-8-12(11)14(13)16(20-2)18(22-4)17(15)21-3/h5-10H,1-4H3',
'standardInChIKey': 'PHIDHNJRDMYWKQ-UHFFFAOYSA-N'},
'CH3OH': {'name': 'CH3OH',
'standardInChI': 'InChI=1S/CH4O/c1-2/h2H,1H3',
'standardInChIKey': 'OKKJLVBELUTLKV-UHFFFAOYSA-N'},
'APORPHINE': {'name': 'APORPHINE',
'standardInChI': 'InChI=1S/C17H17N/c1-18-10-9-12-6-4-8-15-14-7-3-2-5-13(14)11-16(18)17(12)15/h2-8,16H,9-11H2,1H3',
'standardInChIKey': 'BZKUYNBAFQJRDM-UHFFFAOYSA-N'},
'DIMETHOXYOXOAPORPHINE': {'name': 'DIMETHOXYOXOAPORPHINE',
'standardInChI': 'InChI=1S/C19H19NO3/c1-20-10-15(21)13-9-16(22-2)19(23-3)18-12-7-5-4-6-11(12)8-14(20)17(13)18/h4-7,9,14H,8,10H2,1-3H3',
'standardInChIKey': 'NOQPPVHNJNQIGF-UHFFFAOYSA-N'},
'KBr': {'name': 'KBr',
'standardInChI': 'InChI=1S/BrH.K/h1H;/q;+1/p-1',
'standardInChIKey': 'IOLCXVTUBQKXJR-UHFFFAOYSA-M'},
'aporphine': {'name': 'aporphine',
'standardInChI': 'InChI=1S/C17H17N/c1-18-10-9-12-6-4-8-15-14-7-3-2-5-13(14)11-16(18)17(12)15/h2-8,16H,9-11H2,1H3',
'standardInChIKey': 'BZKUYNBAFQJRDM-UHFFFAOYSA-N'},
'Actinodaphnine': {'name': 'Actinodaphnine',
'standardInChI': 'InChI=1S/C18H17NO4/c1-21-14-7-11-10(5-13(14)20)4-12-16-9(2-3-19-12)6-15-18(17(11)16)23-8-22-15/h5-7,12,19-20H,2-4,8H2,1H3/t12-/m0/s1',
'standardInChIKey': 'VYJUHRAQPIBWNV-LBPRGKRZSA-N'}}}]}提前感谢!
更新:
这是我如何获得这个列表的:
my_list = []
for z in old_list:
subprocess.call(['wget', '-O', 'journal.pdf', z])
os.system('oscarpdf2json journal.pdf > journal.json')
if os.path.isfile('journal.json'):
with open('journal.json') as f:
journal = json.load(f)
os.remove('journal.pdf')
os.remove('journal.json')
my_list.append({z:{'oscar':journal}})发布于 2019-11-20 21:18:06
我也是一个初学者,但我认为你可以使用这个代码来提取字典中每个条目的所有键,但是变量名不合适:
InChlkeys = []
dictionary = my_list[1]['2']
for i in dictionary.values():
for j in i:
for k in j["chemicalData"].values():
InChlkeys.append(k['standardInChIKey'])发布于 2019-11-20 21:38:36
`
#target_data = my_list[1]['2']
dict_1 = target_data['oscar'][0]
chemical_data = dict_1['chemicalData']
target_dict = {}
for item in chemical_data.items():
chemical_dict = item[1]
chemical_name = chemical_dict['name']
chemical_InChIKey = chemical_dict['standardInChIKey']
target_dict.update({chemical_name : chemical_InChIKey})`
你可以试试上面的几行,我希望这是你需要的。干杯!
更新:取消第一行的注释并运行上面的行。希望你能得到你想要的结果。
https://stackoverflow.com/questions/58954636
复制相似问题