17.4 Clique Search

Clique detection is a bounded common structure search. It is a useful search method in cases where common substructure(s) other than the maximum common substructure(s) need to be identified. The following example demonstrates clique search.

# ch17-5.py
mol1=OEGraphMol()
OEParseSmiles(mol1, "c1ccccc1C(=O)C")
OEAssignAromaticFlags(mol1)
OETriposAtomNames(mol1)

# create an OECliqueSearch from this molecule
cs = OECliqueSearch(mol1,
                    OEExprOpts_DefaultAtoms,OEExprOpts_DefaultBonds)
# ignore cliques that differ by more than 5 atoms from MCS
cs.SetSaveRange(5)

ifs = oemolistream("drugs.sdf")
for mol in ifs.GetOEMols():
    OETriposAtomNames(mol)
    print mol.GetTitle()
    matchcount = 0
    for mb in cs.Match(mol):
        print "Match:", matchcount,"Size:",mb.NumAtoms(),"atoms"
        for mp in mb.GetAtoms():
            sys.stdout.write(" %s->%s " %
                        (mp.target.GetName(),mp.pattern.GetName()))
        print
        matchcount += 1

The same molecules and expression options as the prior example are used, however, an iterator over all identified cliques is returned by the Match method. The SetSaveRange method bounds the search. In this case, cliques returned will only differ by five nodes relative to the maximum common substructure. The atom correspondences for each of the returned cliques are printed in the example program.