【问题标题】:Converting molecule name to SMILES?将分子名称转换为 SMILES?
【发布时间】:2019-02-28 16:23:26
【问题描述】:

我只是想知道,有没有办法将 IUPAC 或常见的分子名称转换为 SMILES?我想这样做,而不必使用在线系统手动转换每一个。任何意见将不胜感激!

作为背景,我目前正在使用 python 和 RDkit,所以我不确定 RDkit 是否可以做到这一点,我只是不知道。我当前的数据是 csv 格式。

谢谢!

【问题讨论】:

标签: python cheminformatics


【解决方案1】:

RDKit 无法将名称转换为 SMILES。 Chemical Identifier Resolver 可以转换名称和其他标识符(如 CAS No),并且有一个 API,因此您可以使用脚本进行转换。

from urllib.request import urlopen
from urllib.parse import quote

def CIRconvert(ids):
    try:
        url = 'http://cactus.nci.nih.gov/chemical/structure/' + quote(ids) + '/smiles'
        ans = urlopen(url).read().decode('utf8')
        return ans
    except:
        return 'Did not work'

identifiers  = ['3-Methylheptane', 'Aspirin', 'Diethylsulfate', 'Diethyl sulfate', '50-78-2', 'Adamant']

for ids in identifiers :
    print(ids, CIRconvert(ids))

输出

3-Methylheptane CCCCC(C)CC
Aspirin CC(=O)Oc1ccccc1C(O)=O
Diethylsulfate CCO[S](=O)(=O)OCC
Diethyl sulfate CCO[S](=O)(=O)OCC
50-78-2 CC(=O)Oc1ccccc1C(O)=O
Adamant Did not work

【讨论】:

  • 由于某种原因,该网站自 2020 年底以来一直无法正常运行
  • @CodyAldaz 该网站似乎有一些问题,但大多数时候,当我点击Submit 时,它可以工作。但是 API 可以工作。
  • 这主要对我有用,但我必须将空格转换为 URL 格式 (%20),例如: current_id = str(ids.lower()).replace(' ', '% 20') url = 'cactus.nci.nih.gov/chemical/structure' + current_id + '/smiles'
  • @PaulG 感谢您指出空格。我已经编辑了代码。
【解决方案2】:

OPSIN (https://opsin.ch.cam.ac.uk/) 是 name2structure 转换的另一种解决方案。

可以通过安装cli使用,也可以通过https://github.com/gorgitko/molminer使用

(RDKit KNIME 节点也使用 OPSIN)

【讨论】:

    【解决方案3】:

    接受的答案使用Chemical Identifier Resolver,但由于某种原因,该网站对我来说似乎是错误的,API 似乎被搞砸了。

    因此,将微笑转换为 IUPAC 名称的另一种方法是使用 PubChem python API,如果您的微笑在他们的数据库中,它就可以工作

    例如

    #!/usr/bin/env python
    
    import sys    
    import pubchempy as pcp
    
    smiles = str(sys.argv[1])
    print(smiles)
    s= pcp.get_compounds(smiles,'smiles')
    print(s[0].iupac_name)
    

    【讨论】:

    • 问题是关于将名字转换为微笑(而不是其他方式)。也可以使用此 API 来完成:smiles= pcp.get_compounds(ids,'name')[0].canonical_smiles
    • 如果我们没有任何 id 而只有化合物的名称呢?
    【解决方案4】:
    【解决方案5】:

    如果将第一行更改为:

    从 urllib2 导入 url 打开

    它应该适用于 python 2.7

    【讨论】:

      猜你喜欢
      • 2021-01-27
      • 2018-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多