Skip to content

Instantly share code, notes, and snippets.

@andersx
Created August 2, 2018 08:23
Show Gist options
  • Select an option

  • Save andersx/4ef2c423a514197edb18ba3c38ba11e2 to your computer and use it in GitHub Desktop.

Select an option

Save andersx/4ef2c423a514197edb18ba3c38ba11e2 to your computer and use it in GitHub Desktop.
Example that will throw a "ValueError: Bad conformer id" with RDKit
import sys
from rdkit import Chem
from rdkit.Chem import AllChem
if __name__ == "__main__":
# my_smiles = ['C#N', 'C1C(C2C1OC2)O', 'C1C2C3C1C2C3O', 'C1C2COC2C1O', 'C1CC2(C1CC2)O',
# 'C1CC2(C1NC2)O', 'C1CC2(C1OC2)N', 'C1CC2(C1OC2)O', 'C1CC2C1CC2O']
my_smiles = ['C#N', 'C1C(C2C1OC2)O']
for smiles in my_smiles:
mol = Chem.MolFromSmiles(smiles)
mol = Chem.AddHs(mol)
AllChem.EmbedMolecule(mol, useRandomCoords=True)
AllChem.EmbedMultipleConfs(mol,
numConfs=50,
# useExpTorsionAnglePrefs=True,
# useBasicKnowledge=True,
# enforceChirality=True
)
optimization = AllChem.MMFFOptimizeMoleculeConfs(mol, maxIters=100)
for i,conf in enumerate(mol.GetConformers()):
filename = "output_%02i_%s.sdf" % (i, smiles)
tm = Chem.Mol(mol, False, conf.GetId())
writer = Chem.SDWriter(filename)
writer.write(tm)
@grigorievaekateriina
Copy link
Copy Markdown

thank you so much!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment