1 package search;
2
3 import java.util.Arrays;
4
5 import util.DisplayUtil;
6 import chemaxon.formats.MolImporter;
7 import chemaxon.sss.search.MolSearch;
8 import chemaxon.sss.search.MolSearchOptions;
9 import chemaxon.sss.search.StandardizedMolSearch;
10import chemaxon.struc.Molecule;
11import chemaxon.util.HitColoringAndAlignmentOptions;
12import chemaxon.util.HitDisplayTool;
13
14
20public final class StandardizedMolSearchExample {
21
22 private static final String QUERY = "Cc1ccccc1";
23 private static final String TARGET = "CC1=C(C)C=CC=C1C";
24
25
32 public static void main(String[] args) {
33 try {
34 new StandardizedMolSearchExample().run();
35 } catch (Exception e) {
36 e.printStackTrace();
37 }
38 }
39
40 private void run() throws Exception {
41 searchWithoutAromatization();
42 searchWithAromatization();
43 searchWithStandardizedMolSearch();
44 }
45
46 private void searchWithoutAromatization() throws Exception {
47 System.out.println("Executing molecule search " + "without aromatizing molecules.");
48 doSearch(new MolSearch(), MolImporter.importMol(QUERY), MolImporter.importMol(TARGET));
49 }
50
51 private void searchWithAromatization() throws Exception {
52 System.out.println("Executing molecule search " + "with aromatized molecules.");
53 Molecule query = MolImporter.importMol(QUERY);
54 Molecule target = MolImporter.importMol(TARGET);
55 query.aromatize();
56 target.aromatize();
57 doSearch(new MolSearch(), query, target);
58 }
59
60 private void searchWithStandardizedMolSearch() throws Exception {
61 System.out.println("Executing standardized molecule search.");
62 doSearch(new StandardizedMolSearch(), MolImporter.importMol(QUERY),
63 MolImporter.importMol(TARGET));
64 }
65
66 private void doSearch(MolSearch searcher, Molecule query, Molecule target)
67 throws Exception {
68 searcher.setQuery(query);
69 searcher.setTarget(target);
70 if (searcher.isMatching()) {
71 System.out.printf("%s is matching %s\n", DisplayUtil.toSmiles(query),
72 DisplayUtil.toSmiles(target));
73 System.out.printf("There are %d different hits\n", searcher.getMatchCount());
74
75 int[] hit = searcher.findFirst();
76 while (hit != null) {
77 System.out.println(Arrays.toString(hit));
78 hit = searcher.findNext();
79 }
80
81 displayHits(query, target, searcher.getSearchOptions());
82
83 } else {
84 System.out.println("No match has been found.");
85 }
86 System.out.println();
87 }
88
89 private static void displayHits(Molecule query, Molecule target,
90 MolSearchOptions searchOpts) throws Exception {
91
92 HitColoringAndAlignmentOptions displayOpts = DisplayUtil.createColoringOptions();
93
94 HitDisplayTool hdt = new HitDisplayTool(displayOpts, searchOpts, query);
95 hdt.setTarget(target);
96
97 int pos = 0;
98 Molecule hitMol = null;
99 while ((hitMol = hdt.getNextHit()) != null) {
00 DisplayUtil.showMolecule(hitMol, pos++, "Rotated target");
01 }
02 }
03
04}
05