How to draw sub-structures of a polycyclic aromatic which shows bond angles correctly?

174 Views Asked by At

thank you for reading my question.

Assume that I have a polycyclic aromatic (let's call it "parent molecule") as shown below:

smile = "c1ccc2ocnc2c1"   
mol = Chem.MolFromSmiles(smile)

enter image description here

When I draw sub-structures of the parent molecule, I notice that the bond angles in sub-structures are different from the bond angles in the parent molecule. Following is the code that I use:

from rdkit import Chem
from rdkit.Chem.Draw import rdMolDraw2D
from IPython.display import SVG

smile_1 = 'c(cc)cc'
smile_2 = 'n(co)c(c)c'

m1 = Chem.MolFromSmiles(smile_1,sanitize=False)
Chem.SanitizeMol(m1, sanitizeOps=(Chem.SanitizeFlags.SANITIZE_ALL^Chem.SanitizeFlags.SANITIZE_KEKULIZE^Chem.SanitizeFlags.SANITIZE_SETAROMATICITY))
m2 = Chem.MolFromSmiles(smile_2,sanitize=False)
Chem.SanitizeMol(m2, sanitizeOps=(Chem.SanitizeFlags.SANITIZE_ALL^Chem.SanitizeFlags.SANITIZE_KEKULIZE^Chem.SanitizeFlags.SANITIZE_SETAROMATICITY))

mols = [m1, m2]
smiles = ["smile_1", "smile_2"]

molsPerRow=2
subImgSize=(200, 200)
nRows = len(mols) // molsPerRow
if len(mols) % molsPerRow:
  nRows += 1
  
fullSize = (molsPerRow * subImgSize[0], nRows * subImgSize[1])
d2d = rdMolDraw2D.MolDraw2DSVG(fullSize[0], fullSize[1], subImgSize[0], subImgSize[1])
d2d.drawOptions().prepareMolsBeforeDrawing=False
d2d.DrawMolecules(mols, legends=smiles)
d2d.FinishDrawing()
SVG(d2d.GetDrawingText())

Which results in the following drawing:

enter image description here

As can be seen, the angles between several bonds in sub-structures are different from the parent molecule.
Is there any way to draw sub-structures with the same bond angles as parent molecule? Any help is greatly appreciated.

1

There are 1 best solutions below

0
rapelpy On BEST ANSWER

You can set the original positions of your parent to the substructure.

from rdkit import Chem
from rdkit.Chem.Draw import IPythonConsole
from rdkit.Chem import rdDepictor
rdDepictor.SetPreferCoordGen(True)

def getNiceSub(parent, sub):

    # Get the coordinates of parent (also need to built a conformer)
    mol = Chem.MolFromSmiles(parent)
    rdDepictor.Compute2DCoords(mol)
    
    # Get the coordinates of substructure to built a conformer
    substruct = Chem.MolFromSmiles(sub, sanitize=False)
    rdDepictor.Compute2DCoords(substruct)
    
    # Get the index of the matched atoms
    ms = mol.GetSubstructMatch(substruct)
    
    # Get the positions of the matched atoms
    conf1 = mol.GetConformer()
    p = [list(conf1.GetAtomPosition(x)) for x in ms]
    
    # Set the original positions of parent to substructure
    conf2 = substruct.GetConformer()
    for n in range(len(ms)):
        conf2.SetAtomPosition(n, p[n])
    
    return substruct

parent = 'c1ccc2ocnc2c1'
substructer = 'n(co)c(c)c'
nicesub = getNiceSub(parent, substructer)

parent

parent

substructure

substructure