Skip to content

Instantly share code, notes, and snippets.

@acruzpr
Forked from leelasd/convert_molecules.py
Created June 10, 2020 19:41
Show Gist options
  • Save acruzpr/98a63d23d58d0da5ae71b7d89ec3ee7f to your computer and use it in GitHub Desktop.
Save acruzpr/98a63d23d58d0da5ae71b7d89ec3ee7f to your computer and use it in GitHub Desktop.
Convert Smiles code to 3D and save to SDF
import pandas as pd
from rdkit import Chem
from rdkit.Chem import AllChem
df = pd.read_csv('SMILES.csv')
mols = [Chem.MolFromSmiles(smi) for smi in df.SMILES]
hmols = [Chem.AddHs(m) for m in mols]
for mol in hmols:
AllChem.EmbedMolecule(mol,AllChem.ETKDG())
print(AllChem.UFFOptimizeMolecule(mol,1000))
smiles = list(df.SMILES)
sid = list(df.SOURCE_ID)
libs = df[df.columns[0]]
writer = Chem.SDWriter('TEST.sdf')
for n in range(len(libs)):
hmols[n].SetProp("_Library","%s"%libs[n])
hmols[n].SetProp("_Name","%s"%sid[n])
hmols[n].SetProp("_SourceID","%s"%sid[n])
hmols[n].SetProp("_SMILES","%s"%smiles[n])
writer.write(hmols[n])
writer.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment