rdkit.Chem.rdmolfiles.MolToMolFile(NoneType, str)

huangapple go评论66阅读模式
英文:

rdkit.Chem.rdmolfiles.MolToMolFile(NoneType, str)

问题

以下是您提供的代码的翻译部分:

我正在尝试使用rdkit Python库将smi格式转换为sdf格式我正在运行以下一行Python代码

def convertir_smi_sdf(file_smi):
    leer = [i for i in open(file_smi)]
    print(f"Total de smi: {len(leer)}")

    cont = 0
    cont_tot = []
    for i in leer:
        nom_mol = i.split()[1]
        smi_mol = i.split()[0]
        mol_smi = Chem.MolFromSmiles(smi_mol)
        Chem.MolToMolFile(mol_smi, f'{nom_mol}.sdf')
        cont += 1
        cont_tot.append(cont)
    print(f"Se ha convertido {cont_tot[-1]} smiles a SDF")

任何帮助都将非常感激

我需要将这些smiles格式分隔成不同的sdf文件

错误

[![Error][1]][1]

输出

[![Output][2]][2]

  [1]: https://i.stack.imgur.com/KBja9.png
  [2]: https://i.stack.imgur.com/rQcXd.png

请注意,我已经保留了代码中的格式和引用部分,而只对代码本身进行了翻译。

英文:

I am trying to convert smi to sdf format using rdkit python library. I am running following line of python code.

def convertir_smi_sdf(file_smi):
    leer = [i for i in open(file_smi)]
    print(f"Total de smi: {len(leer)}")

    cont = 0
    cont_tot = []
    for i in leer:
        nom_mol = i.split()[1]
        smi_mol = i.split()[0]
        mol_smi = Chem.MolFromSmiles(smi_mol)
        Chem.MolToMolFile(mol_smi, f'{nom_mol}.sdf')
        cont += 1
        cont_tot.append(cont)
    print(f"Se ha convertido {cont_tot[-1]} smiles a SDF")

Any help is highly appreciated

I need this to separate this smiles format in distints sdf archives.

Error:

rdkit.Chem.rdmolfiles.MolToMolFile(NoneType, str)

Output:

rdkit.Chem.rdmolfiles.MolToMolFile(NoneType, str)

答案1

得分: 1

这些类型的错误总是意味着一件事:你输入的SMILES字符串是无效的。在你的情况下,你之所以会收到错误信息,是因为SMILES字符串Cl[Pt](Cl)([NH4])[NH4]是无效的。请参见下面的图片。两个氮原子都形成了5个键,而没有任何正电荷。

当你在RdKit中解析它时,会得到如下的警告:

要处理这个问题,要么手动修复这个SMILES,要么完全忽略它。要忽略它,只需像下面这样传递参数sanitize=False

mol_smi = Chem.MolFromSmiles(smi_mol, sanitize=False)

只是一个警告:通过添加sanitize=False,你将忽略所有无效的SMILES。

英文:

These kinds of errors always mean one thing: The SMILES you're inputting is invalid. In your case, you're getting the error because of the SMILES string Cl[Pt](Cl)([NH4])[NH4] which is invalid. See its picture below. Both Nitrogen atoms are forming 5 bonds without any positive charge on them.

rdkit.Chem.rdmolfiles.MolToMolFile(NoneType, str)

When you parse it in RdKit, you'll get a warning like this:

rdkit.Chem.rdmolfiles.MolToMolFile(NoneType, str)

To deal with this, either fix this SMILES manually or ignore it completely. To ignore it, just pass the argument sanitize=False as below:

mol_smi = Chem.MolFromSmiles(smi_mol, sanitize=False)

Just a warning: by adding sanitize=False, you'll be ignoring all the invalid SMILES.

huangapple
  • 本文由 发表于 2023年2月8日 09:26:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75380555.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定