Hi Geoff,

you can indeed use DrawWavyLine() coupled to some basic 2D geometry as in
the example below:

from rdkit import Chem
from rdkit.Geometry import Point3D, Point2D
from rdkit.Chem.Draw import rdDepictor, rdMolDraw2D
from IPython.display import SVG

mol = Chem.MolFromSmiles("C12=CC=CC=[N]1->[*]<-[N]3=C2C=CC=C3")

rdDepictor.Compute2DCoords(mol)
0

dative_bonds = [b for b in mol.GetBonds() if b.GetBondType() ==
Chem.BondType.DATIVE]

def draw_attachment_line(mol, drawer, bond, wavy_color=(0.0, 0.0, 0.0),
n_segments=12, offset=0.07, wavy_len=0.8):
    bi = bond.GetBeginAtomIdx()
    ei = bond.GetEndAtomIdx()
    bc = mol.GetConformer().GetAtomPosition(bi)
    ec = mol.GetConformer().GetAtomPosition(ei)
    bv = bc - ec
    bv.Normalize()
    midpoint = (bc + ec) * 0.5
    ba = midpoint + Point3D(bv.y, -bv.x, 0.0) * (wavy_len * 0.5)
    ea = midpoint + Point3D(-bv.y, bv.x, 0.0) * (wavy_len * 0.5)
    drawer.DrawWavyLine(Point2D(ba.x, ba.y), Point2D(ea.x, ea.y),
wavy_color, wavy_color, n_segments, offset)

drawer = rdMolDraw2D.MolDraw2DSVG(500, 300)
drawer.DrawMolecule(mol)
for bond in dative_bonds:
    draw_attachment_line(mol, drawer, bond)
drawer.FinishDrawing()
SVG(drawer.GetDrawingText())
[image: image.png]

You can tweak the default offset of waves, the number of waves and the
length of the wavy bond through the relevant parameters in
draw_attachment_line().

Cheers,
p.

On Wed, Aug 10, 2022 at 5:22 PM Geoffrey Hutchison <
geoff.hutchi...@gmail.com> wrote:

> I've been using RDKit for depicting sets of ligands from SMILES, which has
> been great.
>
> I'd like to add some bidentate and tridentate ligands. Let's stick to
> bipyridine at first (see image)
>
>
> I have the appropriate SMILES, leaving * as part of a 5 atom ring
> involving the nitrogen atoms (and sanitize = False)
> C12=CC=CC=[N]1[*][N]3=C2C=CC=C3
>
> The resulting depiction is great .. except I'd like to add the attachment
> "squiggles" across the N-* bonds.
>
> I see there are DrawAttachmentLine and DrawWavyLine methods, but I'd need
> to get the positions of the N and * atoms.
>
> What's the best way to do that and / or automate adding wavy lines across
> arbitrary bonds?
>
> Thanks,
> -Geoff
>
> _______________________________________________
> Rdkit-discuss mailing list
> Rdkit-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to