Depicting Fragment Combinations

Problem

You want to depict fragment combinations generated by the algorithm described in the Enumerating Fragment Combinations. See example in Table 1.

Table 1. Example of depicting fragment combinations (The pages are reduced here for visualization convenience)
page 1 page 2
../_images/enumfrags2pdf-11.png ../_images/enumfrags2pdf-21.png

Ingredients

Note

Requires OpenEye toolkits version 2014.Jun or later.

Difficulty Level

../_images/chilly1.png ../_images/chilly1.png

Solution

The DepictMoleculeWithFragmentCombinations shows how to visualize fragment combinations returned by the GetFragmentAtomBondSetCombinations function. First a molecule is fragmented using one of the fragmentation functions described in the Enumerating Fragment Combinations section (see line 5 in the code below). Before enumerating the fragment combinations, an index is assigned to each bond of the molecule that indicates which fragment the bond belongs to (lines 9-13). Then a color list is created that is used by the ColorBondByFragmentIndex class to annotate the bonds based on their fragment index (lines 17-22). A highlighting style is also set up in order to fade part of the molecule that does not belong to a given fragment combination (lines 24-25). Then the GetFragmentAtomBondSetCombinations function is called that generates all adjacent fragment combinations and returns them as a list of OEAtomBondSet objects. Each fragment combination is then depicted in a separate cell of the report, by using highlighting and bond annotation (lines 33-47). Finally, in each page header the original molecule fragmentation is depicted (lines 51-59) .

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
def DepictMoleculeWithFragmentCombinations(report, mol, fragfunc, opts):

    # fragment molecule

    frags = [f for f in fragfunc(mol)]

    # assign fragment indices

    stag = "fragment idx"
    itag = OEGetTag(stag)
    for fidx, frag in enumerate(frags):
        for bond in frag.GetBonds():
            bond.SetData(itag, fidx)

    # setup depiction styles

    nrfrags = len(frags)
    colors = [c for c in OEGetLightColors()]
    if len(colors) < nrfrags:
        colors = [c for c in OEGetColors(OEYellowTint, OEDarkOrange, nrfrags)]

    bondglyph = ColorBondByFragmentIndex(colors, itag)

    lineWidthScale = 0.75
    fadehighlight = OEHighlightByColor(OEGrey, lineWidthScale)

    # generate adjacent fragment combination

    fragcombs = GetFragmentAtomBondSetCombinations(mol, frags)

    # depict each fragment combinations

    for frag in fragcombs:

        cell = report.NewCell()
        disp = OE2DMolDisplay(mol, opts)

        fragatoms = OEIsAtomMember(frag.GetAtoms())
        fragbonds = OEIsBondMember(frag.GetBonds())

        notfragatoms = OENotAtom(fragatoms)
        notfragbonds = OENotBond(fragbonds)

        OEAddHighlighting(disp, fadehighlight, notfragatoms, notfragbonds)
        OEAddGlyph(disp, bondglyph, fragbonds)

        OERenderMolecule(cell, disp)

    # depict original fragmentation in each header

    cellwidth, cellheight = report.GetHeaderWidth(), report.GetHeaderHeight()
    opts.SetDimensions(cellwidth, cellheight, OEScale_AutoScale)
    opts.SetAtomColorStyle(OEAtomColorStyle_WhiteMonochrome)
    disp = OE2DMolDisplay(mol, opts)
    OEAddGlyph(disp, bondglyph, IsTrueBond())

    for header in report.GetHeaders():
        OERenderMolecule(header, disp)
        OEDrawBorder(header, OEPen(OEWhite, OELightGrey, OEFill_Off, 2.0))

The ColorBondByFragmentIndex bond annotation class draws a “stick” underneath each bond (lines 20-24). The color of the “stick” is determined by the index attached to the bond as generic data (lines 17-18).

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class ColorBondByFragmentIndex(OEBondGlyphBase):
    def __init__(self, colorlist, tag):
        OEBondGlyphBase.__init__(self)
        self.colorlist = colorlist
        self.tag = tag

    def RenderGlyph(self, disp, bond):

        bdisp = disp.GetBondDisplay(bond)
        if bdisp is None or not bdisp.IsVisible():
            return False

        if not bond.HasData(self.tag):
            return False

        linewidth = disp.GetScale() / 2.0
        color = self.colorlist[bond.GetData(self.tag)]
        pen = OEPen(color, color, OEFill_Off, linewidth)

        adispB = disp.GetAtomDisplay(bond.GetBgn())
        adispE = disp.GetAtomDisplay(bond.GetEnd())

        layer = disp.GetLayer(OELayerPosition_Below)
        layer.DrawLine(adispB.GetCoords(), adispE.GetCoords(), pen)

        return True

    def ColorBondByFragmentIndex(self):
        return ColorCharge(self.colorlist, self.tag).__disown__()

Download code

enumfrags2pdf.py

The following will generate the multi-page PDF shown in Table 1.

Usage:

prompt > python3 enumfrags2pdf.py -in .ism -out enumfrags.pdf -fragtype funcgroup

CC(C)NCC(COc1ccc(c(c1)Cc2ccccc2)CC(=O)N)O

Discussion

See Also in OEChem TK Manual

Theory

API

See Also in OEMedChem TK Manual

Theory

API

See Also in OEDepict TK Manual

Theory

API

See Also in OEGrapheme TK Manual

Theory

API