Depicting Molecular Graph Symmetry

Problem

You want to easily identify whether there is a graph symmetry in a molecule. See examples in in Table 1.

Table 1. Example of depiction of molecular graph symmetry. Atoms that belong to the same symmetry class colored identically.
../_images/symmetry2img-1.png ../_images/symmetry2img-2.png ../_images/symmetry2img-3.png
../_images/symmetry2img-4.png ../_images/symmetry2img-5.png ../_images/symmetry2img-6.png

Ingredients

Difficulty Level

../_images/chilly.png

Solution

In DepictSymmetry function, the OEPerceiveSymmetry function is called to assign symmetry class for each atom of a given molecule. The symmetry class of each atom then can be retrieved using the OEAtomBase.GetSymmetryClass method.

After perceiving the molecule symmetry, atoms that belong to the same symmetry class are collected in a dictionary (lines 5-11). If a symmetry class only contains one atom, than it is considered unique and removed from the dictionary (lines 13-19). The atoms of the remaining symmetry classes are then highlighted with different colors (lines 24-26).

 1def DepictSymmetry(image, mol, opts):
 2
 3    oechem.OEPerceiveSymmetry(mol)
 4
 5    symdict = dict()
 6
 7    for atom in mol.GetAtoms():
 8        sym = atom.GetSymmetryClass()
 9        if sym not in symdict:
10            symdict[sym] = oechem.OEAtomBondSet()
11        symdict[sym].AddAtom(atom)
12
13    uniquesym = []
14    for sym, atomset in symdict.items():
15        if atomset.NumAtoms() == 1:
16            uniquesym.append(sym)
17
18    for sym in uniquesym:
19        del symdict[sym]
20
21    oedepict.OEPrepareDepiction(mol)
22    disp = oedepict.OE2DMolDisplay(mol, opts)
23
24    colors = [c for c in oechem.OEGetContrastColors()]
25    for (sym, atomset), color in zip(symdict.items(), colors):
26        oedepict.OEAddHighlighting(disp, color, oedepict.OEHighlightStyle_BallAndStick, atomset)
27
28    oedepict.OERenderMolecule(image, disp)

Download code

symmetry2img.py

Usage:

prompt > python3 symmetry2img.py

Discussion

Perceiving graph symmetry plays an important role in cheminformatics. The classification provided by the OEPerceiveSymmetry function can be used to:

Table 2. Example of depiction of molecular graph symmetry. Atoms that belong to the same symmetry class colored identically.
../_images/symmetry2img-complex-1.png ../_images/symmetry2img-complex-2.png ../_images/symmetry2img-complex-3.png ../_images/symmetry2img-complex-4.png

See also in OEChem TK manual

API

See also in OEDepict TK manual

Theory

API