Skip to content

Instantly share code, notes, and snippets.

@jhjensen2
Created March 10, 2018 07:00
Show Gist options
  • Save jhjensen2/55c2aaca1dd4134e8ed51a73a30adc6b to your computer and use it in GitHub Desktop.
Save jhjensen2/55c2aaca1dd4134e8ed51a73a30adc6b to your computer and use it in GitHub Desktop.
from rdkit import Chem
from rdkit.Chem import Draw
from rdkit.Chem.Draw import IPythonConsole
import string
filename_smiles = "/Users/jan/Desktop/diels_alder.smiles"
molecules = []
names = []
with open(filename_smiles, "r") as file:
for line in file:
if len(line.split()) == 4:
name, smiles, energy, filenames = line.split()
name = name + " " + energy
else:
name, smiles = line.split()
smiles = string.replace(smiles,".[H][H]","",3)
mol = Chem.MolFromSmiles(smiles)
names.append(name)
molecules.append(mol)
print len(molecules)
img = Draw.MolsToGridImage(molecules,molsPerRow=5,legends=[x for x in names],subImgSize=(200,200))
img
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment