Depicting Molecular Properties


You want to visualize molecules with their properties in order to identify the ones that can be considered as drug-like. In this example five of such properties are calculated and color coded in a property pie (see example in Table 1):

  • MW – molecular weight

  • XLogP – octanol/water partition coefficient

  • TPSA – topological polar surface area

  • Sol – solubility

  • Rof5 – Lipinski rules [Lipinski-1997]

When hovering over the slices of the property pie, more information can be reveled about the properties (and the color gradients that are used to visualize them). Each property is colored similarly: red color indicates that the property is outside the desired range while green color indicates drug-likeness.

Table 1. Examples of molecule with property pie (Hover mouse over property pies to reveal depiction differences)
../_images/properties2img-01-colorg.svg ../_images/properties2img-01-labels.svg


Difficulty level

../_images/chilly.png ../_images/chilly.png ../_images/chilly.png


Download code

See also Usage subsection.


The five properties that are depicted in this example are calculated using MolProp TK that is designed eliminate inappropriate or undesirable compounds from a large set based on user-defined criteria such as physical properties, functional group content or molecular topology.

While MolProp TK has been designed for filtering molecules, there is a way (even thought it is not straightforward) to access the calculated properties that are used during the filtering process. First the filter rule has to be defined (see get_filter_rules).

 1def get_filter_rules():
 3    FILTER_RULES = """
 4# This file defines the rules for filtering multi-structure files based on
 5# properties and substructure patterns.
 7MIN_MOLWT      130       "Minimum molecular weight"
 8MAX_MOLWT      781       "Maximum molecular weight"
10MIN_XLOGP      -3.0      "Minimum XLogP"
11MAX_XLOGP       6.85     "Maximum XLogP"
13PSA_USE_SandP   false    "Count S and P as polar atoms"
14MIN_2D_PSA      0.0      "Minimum 2-Dimensional (SMILES) Polar Surface Area"
15MAX_2D_PSA      205.0    "Maximum 2-Dimensional (SMILES) Polar Surface Area"
17# choices are insoluble<poorly<moderately<soluble<very<highly
18MIN_SOLUBILITY insoluble "Minimum solubility"
20MIN_LIPINSKI_DONORS  0      "Minimum number of hydrogens on O & N atoms"
21MAX_LIPINSKI_DONORS  6      "Maximum number of hydrogens on O & N atoms"
23MIN_LIPINSKI_ACCEPTORS  1   "Minimum number of oxygen & nitrogen atoms"
24MAX_LIPINSKI_ACCEPTORS  14  "Maximum number of oxygen & nitrogen atoms"
26MAX_LIPINSKI   3         "Maximum number of Lipinski violations"
28    return FILTER_RULES


The minimum and maximum values associated with properties in get_filter_rules are irrelevant in this example since we are not going to use MolProp TK as a filtering tool.

See also

The OEFilter object then can be initialized to calculate the properties defined in the filter rule file (see line 3-4). When passing a molecule into the OEFilter object (see line 16) it returns whether or not the molecule satisfies all the requirements:

if filter(mol):
   # pass
   # reject

In this example we do not use the return value, but rather access the calculated properties that are return in an output stream that are associated with the filter object (see line 9-11). The rest of the code is just parsing the results that are returned in a format similar to this:

SMILES                                        molecular weight XLogP Solubility  2d PSA Lipinski violations Filter
Cc1ccc2c(c1O)NC(C3CC(=CN3C2=O)/C=C/C(=O)N)O   315.32           -1.28 moderately  115.89 0                   Pass
 1def set_properties(mol, properties):
 3    ifs = oechem.oeisstream(get_filter_rules())
 4    filter = oemolprop.OEFilter(ifs)
 6    level = oechem.OEThrow.GetLevel()
 7    oechem.OEThrow.SetLevel(oechem.OEErrorLevel_Warning)
 9    ostr = oechem.oeosstream()
10    pwnd = False
11    filter.SetTable(ostr, pwnd)
13    headers = ostr.str().split(b'\t')
14    ostr.clear()  # remove the header row from the stream
16    filter(mol)
18    fields = ostr.str().decode("UTF-8").split('\t')
19    ostr.clear()  # remove this row from the stream
21    filterdict = dict(zip(headers, fields))
23    for prop in properties:
24        if prop.GetFilterName() in filterdict:
25            prop.SetValue(filterdict[prop.GetFilterName()])
27    oechem.OEThrow.SetLevel(level)

After the properties are calculated the following code snippet illustrates how the properties are visualized with the hover effect in an SVG image file format. In order to add either a hover or a toggle effect to an image SVG group are utilized. You can generate an SVG group for an image by calling the OEImageBase.NewSVGGroup method. In the example below two groups are generated for each property. These two groups are associated by calling the OEAddSVGHover function: while hovering the mouse over objects drawn inside the area_group the objects drawn in the hover_group are displayed. Everything that is rendered between the OEImageBase.PushGroup and the corresponding OEImageBase.PopGroup methods is considered “inside” the group.


The OEAddSVGHover function should always be called prior to pushing / popping the OESVGGroup objects.

 1    bgnangle, endangle = 0.0, incangle
 3    group_prefix = 'property_hover_'
 4    for prop in properties:
 5        area_group = image.NewSVGGroup(prop.GetId())
 6        hover_group = image.NewSVGGroup(group_prefix + prop.GetId())
 7        oedepict.OEAddSVGHover(area_group, hover_group)
 9        image.PushGroup(area_group)
10        draw_property_pie(pframe, prop, center, bgnangle, bgnangle + incangle, radius)
11        image.PopGroup(area_group)
13        image.PushGroup(hover_group)
14        labeltext = '{} = {}'.format(prop.GetLabel(), prop.GetOrigValue())
15        if colorgradient:
16            draw_property_color_gradient(cframe, prop, labeltext)
17        else:
18            draw_property_label(image, prop, labeltext)
19        image.PopGroup(hover_group)



The following commands will generate the image shown on the left shown in Table 1.

prompt > echo "Cc1ccc2c(c1O)NC(C3CC(=CN3C2=O)/C=C/C(=O)N)O" > input.ism
prompt > python3 -in input.ism -out property.svg -colorgradient

See also in OEChem TK manual


See also in MolProp TK manual



See also in OEDepict TK manual



See also in GraphemeTM TK manual