I was also searching for this functionality earlier
For what it’s worth here’s some *very* simple code I hacked together to do
fragmentation. The focus is aromatic heterocycles, but it could be more
general by, for example '[c,n]-[*]’ -> ‘[R]-[*]’ and ring =
Chem.MolFromSmarts(‘[R]’) instead of '[n]'
Advertising
Not pretty, but it worked for me
Bet regards, Jan
import sys, os, re
from rdkit import Chem
from rdkit.Chem import AllChem
from rdkit.Chem import Draw
from rdkit.Chem.Draw import IPythonConsole
rings_mol = []
rings_smiles = []
substituent_mol = []
substituent_smiles = []
smiles_file_name = "/Users/jan/Dropbox/Lundbeck/big.smiles"
smiles_file = open(smiles_file_name, "r")
for line in smiles_file:
words = line.split()
name = words[0]
smiles = words[1]
mol = Chem.MolFromSmiles(smiles)
bis = mol.GetSubstructMatches(Chem.MolFromSmarts('[c,n]-[*]'))
bs = [mol.GetBondBetweenAtoms(x,y).GetIdx() for x,y in bis]
if len(bs) == 0:
if smiles not in rings_smiles:
rings_smiles.append(smiles)
rings_mol.append(Chem.MolFromSmiles(smiles))
continue
fragments_mol = Chem.FragmentOnBonds(mol,bs,addDummies=True)
big_fragment = Chem.MolToSmiles(fragments_mol,True)
big_fragment = re.sub(r'\[\d+\*\]',r'[*]',big_fragment)
fragments = big_fragment.split(".")
ring = Chem.MolFromSmarts('[n]')
for fragment in fragments:
if Chem.MolFromSmiles(fragment).HasSubstructMatch(ring):
if fragment not in rings_smiles:
rings_mol.append(Chem.MolFromSmiles(fragment))
rings_smiles.append(fragment)
else:
if fragment not in substituent_smiles:
substituent_mol.append(Chem.MolFromSmiles(fragment))
substituent_smiles.append(fragment)
img =
Draw.MolsToGridImage(rings_mol,molsPerRow=4,subImgSize=(200,200),useSVG=True)
svg_file_name = "/Users/jan/Dropbox/Lundbeck/rings.svg"
svg_file = open(svg_file_name, 'w')
svg_file.write(img.data)
svg_file.close()
os.system('sed -i "" "s/xmlns:svg/xmlns/" '+svg_file_name)
img
On 06 Jun 2017, at 13:43, Popov, Maxim (Ext)
<maxim.po...@novartis.com<mailto:maxim.po...@novartis.com>> wrote:
Dear All,
I have discovered a very usefule tool in Knime, Molecule Fragmenter by RDKit,
but can’t find a corresponding class or function outside of Knime. Can I use
the Fragmenter without Knime?
Thanks!
Maxim
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org<http://slashdot.org/>!
http://sdm.link/slashdot_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net<mailto:Rdkit-discuss@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss