Depicting Atom Contributions of XLogP

Problem

You want to depict the contribution of each atom to the total XLogP on your molecule diagram. See example in Figure 1.

../_images/xlogp2img1.png

Figure 1. Example of depicting the atom contributions of XLogP

See also

The Depicting Fragment Contributions of XLogP section shows how to depict the fragment contributions of XLogP.

Ingredients

  • OEChem TK - cheminformatics toolkit
  • MolProp TK - molecular property calculation and filtering toolkit

Note

Requires OpenEye toolkits version 2013.Feb or later.

Difficulty Level

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

Solution

The code snippet below shows how to calculate the total XLogP of a molecule along with the atom contributions by calling the OEGetXLogP function. Each atom contribution is then attached to the relevant atom as generic data with the given tag.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
def SetAtomProperties(mol, tag):

    avals = OEFloatArray(mol.GetMaxAtomIdx())
    logp = OEGetXLogP(mol, avals)

    mol.SetTitle(mol.GetTitle() + " -- OEXLogP = %.2f" % logp)

    for atom in mol.GetAtoms():
        val = avals[atom.GetIdx()]
        atom.SetData(tag, val)

The DepictMoleculeWithXLogP function below shows how to project the atom contributions of the total XLogP into a 2D molecular diagram using the OE2DPropMap class. After constructing the OE2DMolDisplay object to depict a molecule, an OE2DPropMap object is initialized and its properties are set that determine how the data is going to be visualized (lines 12-15). For example in this case the negative color xlogp atom contributions are going to be represented by dark green, while the positive values are visualized by using dark purple.

When the OE2DPropMap.Render method is called with same tag that was used in the SetAtomProperties function, the properties that were attached to the atoms as generic data are retrieved and a 2D grid is generated underneath the molecular diagram. The OELinearColorGradient object that is used to assign colors to the cells of the grid is also rendered based on the option set by the OE2DPropMap.SetLegendLocation method . You can see the result in Figure 1.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
def DepictMoleculeWithXLogP(image, mol, opts):

    scale = OEGetMoleculeSurfaceScale(mol, opts)
    opts.SetScale(scale)

    stag = "XLogP"
    itag = OEGetTag(stag)
    SetAtomProperties(mol, itag)

    disp = OE2DMolDisplay(mol, opts)

    propmap = OE2DPropMap(opts.GetBackgroundColor())
    propmap.SetNegativeColor(OEDarkGreen)
    propmap.SetPositiveColor(OEDarkPurple)
    propmap.SetLegendLocation(OELegendLocation_Left)
    propmap.Render(disp, stag)

    OERenderMolecule(image, disp)

Hint

You can easily adapt this example to visualize other atom properties by writing your own SetAtomProperties function.

Download code

xlogp2img.py

Usage:

prompt > python3 xlogp2img.py molecule.ism xlogp.png

Discussion

The example above shows how to visualize the atom contributions for a single molecule, however you might want to visualize the XLogP data for a set of molecules. In this case the SetAtomProperties function not only attaches the XLogP contributions to the relevant atom, but also calculates the minimum and maximum atom contributions for the whole molecule set.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def SetAtomProperties(mol, tag, minvalue, maxvalue):

    avals = OEFloatArray(mol.GetMaxAtomIdx())
    logp = OEGetXLogP(mol, avals)

    mol.SetTitle(mol.GetTitle() + " -- OEXLogP = %.2f" % logp)

    for atom in mol.GetAtoms():
        val = avals[atom.GetIdx()]
        atom.SetData(tag, val)
        minvalue = min(minvalue, val)
        maxvalue = max(maxvalue, val)
    return minvalue, maxvalue

These minimum and maximum values are used to initialize the value range of the linear color gradient of the property map (see lines 20-21 of the DepictMoleculesWithXLogP function below). Each molecule, along with its property map, is then rendered into a cell of an OEReport object. The OEReport class is a layout manager allowing generation of multi-page images in a convenient way. You can see the generated multi-page PDF in Table 1. While the value range of the color gradients depicted alongside the molecules represents the range for the whole set, the black box rendered on each color gradient represents the minimum and maximum XLogP atom contributions for the corresponding molecule.

 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
def DepictMoleculesWithXLogP(report, mollist, opts):

    molscale = float("inf")
    for mol in mollist:
        molscale = min(molscale, OEGetMoleculeSurfaceScale(mol, opts))
    opts.SetScale(molscale)

    stag = "XLogP"
    itag = OEGetTag(stag)

    minvalue = float("inf")
    maxvalue = float("-inf")
    for mol in mollist:
        minvalue, maxvalue = SetAtomProperties(mol, itag, minvalue, maxvalue)

    propmap = OE2DPropMap(opts.GetBackgroundColor())
    propmap.SetNegativeColor(OEDarkGreen)
    propmap.SetPositiveColor(OEDarkPurple)
    propmap.SetLegendLocation(OELegendLocation_Left)
    propmap.SetMinValue(minvalue)
    propmap.SetMaxValue(maxvalue)

    for mol in mollist:

        disp = OE2DMolDisplay(mol, opts)
        propmap.Render(disp, stag)

        cell = report.NewCell()
        OERenderMolecule(cell, disp)
Table 1. Example of depicting atom contributions of XLogP for a set of molecules (The pages are reduced here for visualization convenience)
page 1 page 2 page 3
../_images/xlogp2pdf-1.png ../_images/xlogp2pdf-2.png ../_images/xlogp2pdf-3.png

Download code

xlogp2pdf.py

Usage:

prompt > python3 xlogp2pdf.py molecule.sdf xlogp.pdf

See Also in OEChem TK Manual

Theory

API

See Also in MolProp TK Manual

API

See Also in OEDepict TK Manual

Theory

API

See Also in Grapheme TK Manual

Theory

API