# 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.

Figure 1. Example of depicting the atom contributions of XLogP

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 OEDepict TK - molecule depiction toolkit Grapheme TK - molecule and property visualization toolkit

## 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 = oechem.OEFloatArray(mol.GetMaxAtomIdx()) logp = oemolprop.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 = oegrapheme.OEGetMoleculeSurfaceScale(mol, opts) opts.SetScale(scale) stag = "XLogP" itag = oechem.OEGetTag(stag) SetAtomProperties(mol, itag) disp = oedepict.OE2DMolDisplay(mol, opts) propmap = oegrapheme.OE2DPropMap(opts.GetBackgroundColor()) propmap.SetNegativeColor(oechem.OEDarkGreen) propmap.SetPositiveColor(oechem.OEDarkPurple) propmap.SetLegendLocation(oegrapheme.OELegendLocation_Left) propmap.Render(disp, stag) oedepict.OERenderMolecule(image, disp) 

Hint

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

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 = oechem.OEFloatArray(mol.GetMaxAtomIdx()) logp = oemolprop.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, oegrapheme.OEGetMoleculeSurfaceScale(mol, opts)) opts.SetScale(molscale) stag = "XLogP" itag = oechem.OEGetTag(stag) minvalue = float("inf") maxvalue = float("-inf") for mol in mollist: minvalue, maxvalue = SetAtomProperties(mol, itag, minvalue, maxvalue) propmap = oegrapheme.OE2DPropMap(opts.GetBackgroundColor()) propmap.SetNegativeColor(oechem.OEDarkGreen) propmap.SetPositiveColor(oechem.OEDarkPurple) propmap.SetLegendLocation(oegrapheme.OELegendLocation_Left) propmap.SetMinValue(minvalue) propmap.SetMaxValue(maxvalue) for mol in mollist: disp = oedepict.OE2DMolDisplay(mol, opts) propmap.Render(disp, stag) cell = report.NewCell() oedepict.OERenderMolecule(cell, disp) 
 page 1 page 2 page 3

Usage:

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


Theory

API

API