18.3 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 a clique search.

 1 #!/usr/bin/env python
 2
 3 from openeye.oechem import *
 4 import os,sys
 5
 6 pattern = OEGraphMol()
 7 target  = OEGraphMol()
 8 OEParseSmiles(pattern,"c1cc(O)c(O)cc1CCN")
 9 OEParseSmiles(target, "c1c(O)c(O)c(Cl)cc1CCCBr")
10 # create clique earch object
11 cs = OECliqueSearch(pattern,OEExprOpts_DefaultAtoms,OEExprOpts_DefaultBonds)
12 # ignore cliques that differ by more than 5 atoms from MCS
13 cs.SetSaveRange(5)
14
15 count  = 1
16 # loop over matches
17 for match in cs.Match(target):
18     sys.stdout.write("\nMatch %d :" % count)
19     sys.stdout.write("\npattern atoms: ")
20     for ma in match.GetAtoms():
21         sys.stdout.write("%d " %  ma.pattern.GetIdx())
22     sys.stdout.write("\ntarget atoms:  ")
23     for ma in match.GetAtoms():
24         sys.stdout.write("%d " %  ma.target.GetIdx())
25     count += 1

Listing:18.4 Clique search example

The same molecules and expression options are used as in Listing 18.3, however, an iterator over all identified cliques is returned by the OECliqueSearch.Match method. The OECliqueSearch.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.