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

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

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

问题

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

  1. 我正在尝试使用rdkit Python库将smi格式转换为sdf格式我正在运行以下一行Python代码
  2. def convertir_smi_sdf(file_smi):
  3. leer = [i for i in open(file_smi)]
  4. print(f"Total de smi: {len(leer)}")
  5. cont = 0
  6. cont_tot = []
  7. for i in leer:
  8. nom_mol = i.split()[1]
  9. smi_mol = i.split()[0]
  10. mol_smi = Chem.MolFromSmiles(smi_mol)
  11. Chem.MolToMolFile(mol_smi, f'{nom_mol}.sdf')
  12. cont += 1
  13. cont_tot.append(cont)
  14. print(f"Se ha convertido {cont_tot[-1]} smiles a SDF")
  15. 任何帮助都将非常感激
  16. 我需要将这些smiles格式分隔成不同的sdf文件
  17. 错误
  18. [![Error][1]][1]
  19. 输出
  20. [![Output][2]][2]
  21. [1]: https://i.stack.imgur.com/KBja9.png
  22. [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.

  1. def convertir_smi_sdf(file_smi):
  2. leer = [i for i in open(file_smi)]
  3. print(f"Total de smi: {len(leer)}")
  4. cont = 0
  5. cont_tot = []
  6. for i in leer:
  7. nom_mol = i.split()[1]
  8. smi_mol = i.split()[0]
  9. mol_smi = Chem.MolFromSmiles(smi_mol)
  10. Chem.MolToMolFile(mol_smi, f'{nom_mol}.sdf')
  11. cont += 1
  12. cont_tot.append(cont)
  13. 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

  1. 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:

  1. 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:

确定