Skip to content

Instantly share code, notes, and snippets.

@mbohun
Forked from jhjensen2/diamin_enumerator.py
Created February 3, 2018 14:14
Show Gist options
  • Save mbohun/9cd8a67bb1aed767f38530d827291b2e to your computer and use it in GitHub Desktop.
Save mbohun/9cd8a67bb1aed767f38530d827291b2e to your computer and use it in GitHub Desktop.
from rdkit import Chem
from rdkit.Chem import AllChem
from itertools import islice
raw_smiles = ['NCCN']
smiles_list = ['NCCN']
rxn_smarts_list = ['[C:1][*:2][C:3]>>[C:1]1[*:2][C:3]1','[C:1][C:2]>>[C:1][C][C:2]']
molecules = []
mol = Chem.MolFromSmiles(smiles_list[0])
molecules.append(mol)
substitutions = 6
for i in range(substitutions):
for smiles in islice(raw_smiles,i,len(raw_smiles)):
mol = Chem.MolFromSmiles(smiles)
for rxn_smarts in rxn_smarts_list:
rxn = AllChem.ReactionFromSmarts(rxn_smarts)
new_mols = rxn.RunReactants((mol,))
for new_mol in new_mols:
new_smiles = Chem.MolToSmiles(new_mol[0])
if new_smiles not in raw_smiles:
raw_smiles.append(new_smiles)
for smiles in raw_smiles:
try:
mol = Chem.MolFromSmiles(smiles)
except:
continue
if mol != None:
smiles = Chem.MolToSmiles(Chem.MolFromSmiles(smiles))
if smiles not in smiles_list:
smiles_list.append(smiles)
molecules.append(mol)
print len(smiles_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment