1 package search.hitdisplay;
2 
3 import resource.ResourceLocator;
4 import util.DisplayUtil;
5 import util.MolImportUtil;
6 import chemaxon.sss.SearchConstants;
7 import chemaxon.sss.search.MolSearchOptions;
8 import chemaxon.struc.Molecule;
9 import chemaxon.util.HitColoringAndAlignmentOptions;
10import chemaxon.util.HitDisplayTool;
11
12/**
13 * Example code for showing how to rotate the target molecule to be aligned with the query.
14 * 
15 * @author JChem Base team, ChemAxon Ltd.
16 */
17public final class RotateExample {
18
19    public static void main(String[] args) {
20        new RotateExample().run();
21    }
22
23    private void run() {
24        try {
25            runExample();
26        } catch (Exception e) {
27            e.printStackTrace();
28        }
29    }
30
31    private void runExample() throws Exception {
32        Molecule query = getQueryMolecule();
33        Molecule target = getTargetMolecule();
34        Molecule display = getDisplayMol(query, target, getDisplayOptions());
35
36        DisplayUtil.showMolecule(query, 0, "Query");
37        DisplayUtil.showMolecule(target, 1, "Target");
38        DisplayUtil.showMolecule(display, 2, "Rotated target");
39    }
40
41    private HitColoringAndAlignmentOptions getDisplayOptions() {
42        HitColoringAndAlignmentOptions displayOpts = DisplayUtil.createColoringOptions();
43        displayOpts.setAlignmentMode(HitColoringAndAlignmentOptions.ALIGNMENT_ROTATE);
44        return displayOpts;
45    }
46
47    private Molecule getQueryMolecule() {
48        return MolImportUtil.importMol(ResourceLocator.getPath("rotateQuery.mrv"));
49    }
50
51    private Molecule getTargetMolecule() {
52        return MolImportUtil.importMol(ResourceLocator.getPath("rotateTarget.mrv"));
53    }
54
55    private Molecule getDisplayMol(Molecule query, Molecule target,
56            HitColoringAndAlignmentOptions displayOpts) throws Exception {
57
58        MolSearchOptions searchOpts = new MolSearchOptions(SearchConstants.DEFAULT_SEARCHTYPE);
59        HitDisplayTool hdt = new HitDisplayTool(displayOpts, searchOpts, query);
60
61        return hdt.getHit(target);
62    }
63
64}
65