Depicting Molecular Properties
Problem
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.
Ingredients
|
Difficulty level
Download
Solution
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():
2
3 FILTER_RULES = """
4# This file defines the rules for filtering multi-structure files based on
5# properties and substructure patterns.
6
7MIN_MOLWT 130 "Minimum molecular weight"
8MAX_MOLWT 781 "Maximum molecular weight"
9
10MIN_XLOGP -3.0 "Minimum XLogP"
11MAX_XLOGP 6.85 "Maximum XLogP"
12
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"
16
17# choices are insoluble<poorly<moderately<soluble<very<highly
18MIN_SOLUBILITY insoluble "Minimum solubility"
19
20MIN_LIPINSKI_DONORS 0 "Minimum number of hydrogens on O & N atoms"
21MAX_LIPINSKI_DONORS 6 "Maximum number of hydrogens on O & N atoms"
22
23MIN_LIPINSKI_ACCEPTORS 1 "Minimum number of oxygen & nitrogen atoms"
24MAX_LIPINSKI_ACCEPTORS 14 "Maximum number of oxygen & nitrogen atoms"
25
26MAX_LIPINSKI 3 "Maximum number of Lipinski violations"
27"""
28 return FILTER_RULES
Note
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
Filter Files section of the MolProp TK manual
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
else
# 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):
2
3 ifs = oechem.oeisstream(get_filter_rules())
4 filter = oemolprop.OEFilter(ifs)
5
6 level = oechem.OEThrow.GetLevel()
7 oechem.OEThrow.SetLevel(oechem.OEErrorLevel_Warning)
8
9 ostr = oechem.oeosstream()
10 pwnd = False
11 filter.SetTable(ostr, pwnd)
12
13 headers = ostr.str().split(b'\t')
14 ostr.clear() # remove the header row from the stream
15
16 filter(mol)
17
18 fields = ostr.str().decode("UTF-8").split('\t')
19 ostr.clear() # remove this row from the stream
20
21 filterdict = dict(zip(headers, fields))
22
23 for prop in properties:
24 if prop.GetFilterName() in filterdict:
25 prop.SetValue(filterdict[prop.GetFilterName()])
26
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.
Note
The OEAddSVGHover function should always be called prior to pushing / popping the OESVGGroup objects.
1 bgnangle, endangle = 0.0, incangle
2
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)
8
9 image.PushGroup(area_group)
10 draw_property_pie(pframe, prop, center, bgnangle, bgnangle + incangle, radius)
11 image.PopGroup(area_group)
12
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)
20
Usage
Usage
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 properties2img.py -in input.ism -out property.svg -colorgradient
See also in OEChem TK manual
API
OEColorStop class
OELinearColorGradient class
See also in MolProp TK manual
Theory
Filter Files chapter
API
See also in OEDepict TK manual
Theory
Molecule Depiction chapter
API
OE2DMolDisplay class
OE2DMolDisplayOptions class
OEAddLabel function
OEAddSVGHover function
OEFont class
OEImage class
OEImageFrame class
OEPen class
OEPrepareDepiction function
OERenderMolecule function
OESVGGroup class
See also in GraphemeTM TK manual
API
OEDrawColorGradient function