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/chilly1.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).

 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
def DepictSymmetry(image, mol, opts):

    oechem.OEPerceiveSymmetry(mol)

    symdict = dict()

    for atom in mol.GetAtoms():
        sym = atom.GetSymmetryClass()
        if sym not in symdict:
            symdict[sym] = oechem.OEAtomBondSet()
        symdict[sym].AddAtom(atom)

    uniquesym = []
    for sym, atomset in symdict.items():
        if atomset.NumAtoms() == 1:
            uniquesym.append(sym)

    for sym in uniquesym:
        del symdict[sym]

    oedepict.OEPrepareDepiction(mol)
    disp = oedepict.OE2DMolDisplay(mol, opts)

    colors = [c for c in oechem.OEGetContrastColors()]
    for (sym, atomset), color in zip(symdict.items(), colors):
        oedepict.OEAddHighlighting(disp, color, oedepict.OEHighlightStyle_BallAndStick, atomset)

    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