1 /* Copyright (C) 2009-2010 Syed Asad Rahman <asad@ebi.ac.uk>
2  *
3  * Contact: cdk-devel@lists.sourceforge.net
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public License
7  * as published by the Free Software Foundation; either version 2.1
8  * of the License, or (at your option) any later version.
9  * All we ask is that proper credit is given for our work, which includes
10  * - but is not limited to - adding the above copyright notice to the beginning
11  * of your source code files, and to any copyright notice that you may distribute
12  * with programs based on this work.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 package org.openscience.cdk.smsd;
24 
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotNull;
27 
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.util.logging.Level;
31 import java.util.logging.Logger;
32 
33 import org.junit.After;
34 import org.junit.AfterClass;
35 import org.junit.Assert;
36 import org.junit.Before;
37 import org.junit.BeforeClass;
38 import org.junit.Test;
39 import org.openscience.cdk.AtomContainer;
40 import org.openscience.cdk.DefaultChemObjectBuilder;
41 import org.openscience.cdk.aromaticity.Aromaticity;
42 import org.openscience.cdk.exception.CDKException;
43 import org.openscience.cdk.exception.InvalidSmilesException;
44 import org.openscience.cdk.interfaces.IAtomContainer;
45 import org.openscience.cdk.io.IChemObjectReader.Mode;
46 import org.openscience.cdk.io.MDLV2000Reader;
47 import org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer;
48 import org.openscience.cdk.isomorphism.matchers.QueryAtomContainerCreator;
49 import org.openscience.cdk.smiles.SmilesParser;
50 import org.openscience.cdk.smsd.algorithm.mcsplus.MCSPlusHandlerTest;
51 import org.openscience.cdk.smsd.interfaces.Algorithm;
52 import org.openscience.cdk.smsd.tools.ExtAtomContainerManipulator;
53 import org.openscience.cdk.smsd.tools.MolHandler;
54 import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;
55 
56 /**
57  * @author Syed Asad Rahman &lt;asad@ebi.ac.uk&gt;
58  *
59  * @cdk.module test-smsd
60  * @cdk.require java1.6+
61  */
62 public class SMSDTest {
63 
SMSDTest()64     public SMSDTest() {}
65 
66     @BeforeClass
setUpClass()67     public static void setUpClass() throws Exception {}
68 
69     @AfterClass
tearDownClass()70     public static void tearDownClass() throws Exception {}
71 
72     @Before
setUp()73     public void setUp() {}
74 
75     @After
tearDown()76     public void tearDown() {}
77 
78     /**
79      * Test of init method, of class Isomorphism.
80      * @throws CDKException
81      */
82     @Test
testInit_3args_1()83     public void testInit_3args_1() throws CDKException {
84         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
85         IAtomContainer target = sp.parseSmiles("C\\C=C/OCC=C");
86         IAtomContainer queryac = sp.parseSmiles("CCCOCC(C)=C");
87 
88         Isomorphism smsd1 = new Isomorphism(Algorithm.DEFAULT, false);
89         smsd1.init(queryac, target, true, true);
90         smsd1.setChemFilters(true, false, false);
91         assertNotNull(smsd1.getReactantMolecule());
92         assertNotNull(smsd1.getProductMolecule());
93     }
94 
95     /**
96      * Test of init method, of class Isomorphism.
97      * @throws CDKException
98      */
99     @Test
testInit_3args_2()100     public void testInit_3args_2() throws CDKException {
101         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
102         IAtomContainer target = sp.parseSmiles("C\\C=C/OCC=C");
103         IAtomContainer queryac = sp.parseSmiles("CCCOCC(C)=C");
104 
105         Isomorphism smsd1 = new Isomorphism(Algorithm.DEFAULT, false);
106         smsd1.init(queryac, target, true, true);
107         smsd1.setChemFilters(true, false, false);
108         assertNotNull(smsd1.getReactantMolecule());
109         assertNotNull(smsd1.getProductMolecule());
110     }
111 
112     /**
113      * Test of searchMCS method, of class Isomorphism.
114      * @throws CDKException
115      */
116     @Test
testSearchMCS()117     public void testSearchMCS() throws CDKException {
118         try {
119             SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
120             sp.kekulise(false);
121             IAtomContainer target = null;
122             target = sp.parseSmiles("C\\C=C/Nc1cccc(c1)N(O)\\C=C\\C\\C=C\\C=C/C");
123             AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(target);
124             IAtomContainer queryac = sp.parseSmiles("Nc1ccccc1");
125             AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(queryac);
126             Aromaticity.cdkLegacy().apply(target);
127             Aromaticity.cdkLegacy().apply(queryac);
128             Isomorphism smsd1 = new Isomorphism(Algorithm.DEFAULT, true);
129             smsd1.init(queryac, target, true, true);
130             smsd1.setChemFilters(true, true, true);
131             Assert.assertEquals(7, smsd1.getFirstAtomMapping().size());
132             Assert.assertEquals(2, smsd1.getAllAtomMapping().size());
133             assertNotNull(smsd1.getFirstMapping());
134         } catch (InvalidSmilesException ex) {
135             Logger.getLogger(MCSPlusHandlerTest.class.getName()).log(Level.SEVERE, null, ex);
136         }
137     }
138 
139     /**
140      * Test of set method, of class Isomorphism.
141      * @throws CDKException
142      */
143     @Test
testSet_IAtomContainer_IAtomContainer()144     public void testSet_IAtomContainer_IAtomContainer() throws CDKException {
145         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
146         IAtomContainer target = sp.parseSmiles("C\\C=C/Nc1cccc(c1)N(O)\\C=C\\C\\C=C\\C=C/C");
147         IAtomContainer queryac = sp.parseSmiles("Nc1ccccc1");
148 
149         Isomorphism smsd1 = new Isomorphism(Algorithm.DEFAULT, true);
150         smsd1.init(queryac, target, true, true);
151         smsd1.setChemFilters(true, true, true);
152         assertNotNull(smsd1.getFirstMapping());
153 
154     }
155 
156     /**
157      * Test of set method, of class Isomorphism.
158      * @throws CDKException
159      * @throws IOException
160      */
161     @Test
testSet_String_String()162     public void testSet_String_String() throws CDKException, IOException {
163         String molfile = "data/mdl/decalin.mol";
164         String queryfile = "data/mdl/decalin.mol";
165         IAtomContainer query = new AtomContainer();
166         IAtomContainer target = new AtomContainer();
167 
168         InputStream ins = this.getClass().getClassLoader().getResourceAsStream(molfile);
169         MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT);
170         reader.read(query);
171         ins = this.getClass().getClassLoader().getResourceAsStream(queryfile);
172         reader = new MDLV2000Reader(ins, Mode.STRICT);
173         reader.read(target);
174 
175         Isomorphism smsd1 = new Isomorphism(Algorithm.DEFAULT, true);
176         smsd1.init(query, target, true, true);
177         smsd1.setChemFilters(true, true, true);
178         double score = 1.0;
179         assertEquals(score, smsd1.getTanimotoSimilarity(), 0.0001);
180     }
181 
182     /**
183      * Test of set method, of class Isomorphism.
184      * @throws CDKException
185      */
186     @Test
testSet_MolHandler_MolHandler()187     public void testSet_MolHandler_MolHandler() throws CDKException {
188         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
189 
190         IAtomContainer target1 = sp.parseSmiles("C\\C=C/Nc1cccc(c1)N(O)\\C=C\\C\\C=C\\C=C/C");
191         IAtomContainer queryac = sp.parseSmiles("Nc1ccccc1");
192         MolHandler source = new MolHandler(queryac, true, true);
193         MolHandler target = new MolHandler(target1, true, true);
194         Isomorphism smsd1 = new Isomorphism(Algorithm.DEFAULT, true);
195         smsd1.init(source.getMolecule(), target.getMolecule(), true, true);
196         smsd1.setChemFilters(true, true, true);
197         assertNotNull(smsd1.getFirstMapping());
198     }
199 
200     /**
201      * Test of getAllAtomMapping method, of class Isomorphism.
202      * @throws CDKException
203      */
204     @Test
testGetAllAtomMapping()205     public void testGetAllAtomMapping() throws CDKException {
206         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
207         sp.kekulise(false);
208         IAtomContainer target = sp.parseSmiles("C\\C=C/Nc1cccc(c1)N(O)\\C=C\\C\\C=C\\C=C/C");
209         IAtomContainer queryac = sp.parseSmiles("Nc1ccccc1");
210         AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(target);
211         AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(queryac);
212         Aromaticity.cdkLegacy().apply(target);
213         Aromaticity.cdkLegacy().apply(queryac);
214 
215         ExtAtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(queryac);
216         ExtAtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(target);
217 
218         //	Calling the main algorithm to perform MCS cearch
219 
220         Aromaticity.cdkLegacy().apply(queryac);
221         Aromaticity.cdkLegacy().apply(target);
222 
223         Isomorphism smsd1 = new Isomorphism(Algorithm.DEFAULT, true);
224         smsd1.init(queryac, target, true, true);
225         smsd1.setChemFilters(true, true, true);
226         assertNotNull(smsd1.getFirstMapping());
227         assertEquals(2, smsd1.getAllAtomMapping().size());
228     }
229 
230     /**
231      * Test of getAllMapping method, of class Isomorphism.
232      * @throws CDKException
233      */
234     @Test
testGetAllMapping()235     public void testGetAllMapping() throws CDKException {
236         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
237         sp.kekulise(false);
238         IAtomContainer target = sp.parseSmiles("C\\C=C/Nc1cccc(c1)N(O)\\C=C\\C\\C=C\\C=C/C");
239         IAtomContainer queryac = sp.parseSmiles("Nc1ccccc1");
240         AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(target);
241         AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(queryac);
242         Aromaticity.cdkLegacy().apply(target);
243         Aromaticity.cdkLegacy().apply(queryac);
244 
245         Isomorphism smsd1 = new Isomorphism(Algorithm.DEFAULT, true);
246         smsd1.init(queryac, target, true, true);
247         smsd1.setChemFilters(true, true, true);
248         assertNotNull(smsd1.getFirstMapping());
249 
250         assertEquals(2, smsd1.getAllMapping().size());
251     }
252 
253     /**
254      * Test of getFirstAtomMapping method, of class Isomorphism.
255      * @throws CDKException
256      */
257     @Test
testGetFirstAtomMapping()258     public void testGetFirstAtomMapping() throws CDKException {
259         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
260         IAtomContainer target = sp.parseSmiles("C\\C=C/Nc1cccc(c1)N(O)\\C=C\\C\\C=C\\C=C/C");
261         IAtomContainer queryac = sp.parseSmiles("Nc1ccccc1");
262 
263         Isomorphism smsd1 = new Isomorphism(Algorithm.DEFAULT, true);
264         smsd1.init(queryac, target, true, true);
265         smsd1.setChemFilters(true, true, true);
266         assertNotNull(smsd1.getFirstMapping());
267 
268         assertEquals(7, smsd1.getFirstAtomMapping().size());
269     }
270 
271     /**
272      * Test of getFirstMapping method, of class Isomorphism.
273      * @throws CDKException
274      */
275     @Test
testGetFirstMapping()276     public void testGetFirstMapping() throws CDKException {
277         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
278         IAtomContainer target = sp.parseSmiles("C\\C=C/Nc1cccc(c1)N(O)\\C=C\\C\\C=C\\C=C/C");
279         IAtomContainer queryac = sp.parseSmiles("Nc1ccccc1");
280 
281         Isomorphism smsd1 = new Isomorphism(Algorithm.DEFAULT, true);
282         smsd1.init(queryac, target, true, true);
283         smsd1.setChemFilters(true, true, true);
284         assertNotNull(smsd1.getFirstMapping());
285 
286         assertEquals(7, smsd1.getFirstMapping().size());
287     }
288 
289     /**
290      * Test of setChemFilters method, of class Isomorphism.
291      * @throws CDKException
292      */
293     @Test
testSetChemFilters()294     public void testSetChemFilters() throws CDKException {
295         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
296         IAtomContainer target = sp.parseSmiles("C\\C=C/OCC=C");
297         IAtomContainer queryac = sp.parseSmiles("CCCOCC(C)=C");
298 
299         Isomorphism smsd1 = new Isomorphism(Algorithm.DEFAULT, false);
300         smsd1.init(queryac, target, true, true);
301         smsd1.setChemFilters(true, true, true);
302         assertEquals(1, smsd1.getAllAtomMapping().size());
303     }
304 
305     /**
306      * Test of getFragmentSize method, of class Isomorphism.
307      * @throws CDKException
308      */
309     @Test
testGetFragmentSize()310     public void testGetFragmentSize() throws CDKException {
311         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
312         IAtomContainer target = sp.parseSmiles("C\\C=C/Nc1cccc(c1)N(O)\\C=C\\C\\C=C\\C=C/C");
313         IAtomContainer queryac = sp.parseSmiles("Nc1ccccc1");
314 
315         Isomorphism smsd1 = new Isomorphism(Algorithm.DEFAULT, true);
316         smsd1.init(queryac, target, true, true);
317         smsd1.setChemFilters(false, true, false);
318         Integer score = 2;
319         assertEquals(score, smsd1.getFragmentSize(0));
320     }
321 
322     /**
323      * Test of getStereoScore method, of class Isomorphism.
324      * @throws CDKException
325      */
326     @Test
testGetStereoScore()327     public void testGetStereoScore() throws CDKException {
328         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
329         IAtomContainer target = sp.parseSmiles("C\\C=C/OCC=C");
330         IAtomContainer queryac = sp.parseSmiles("CCCOCC(C)=C");
331 
332         Isomorphism smsd1 = new Isomorphism(Algorithm.DEFAULT, false);
333         smsd1.init(queryac, target, true, true);
334         smsd1.setChemFilters(true, false, false);
335         Integer score = 1048;
336         assertEquals(score, smsd1.getStereoScore(0));
337     }
338 
339     /**
340      * Test of getEnergyScore method, of class Isomorphism.
341      * @throws CDKException
342      */
343     @Test
testGetEnergyScore()344     public void testGetEnergyScore() throws CDKException {
345         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
346         IAtomContainer target = sp.parseSmiles("C\\C=C/Nc1cccc(c1)N(O)\\C=C\\C\\C=C\\C=C/C");
347         IAtomContainer queryac = sp.parseSmiles("Nc1ccccc1");
348 
349         Isomorphism smsd1 = new Isomorphism(Algorithm.DEFAULT, true);
350         smsd1.init(queryac, target, true, true);
351         smsd1.setChemFilters(false, false, true);
352         Double score = 610.0;
353         assertEquals(score, smsd1.getEnergyScore(0));
354     }
355 
356     /**
357      * Test of getReactantMolecule method, of class Isomorphism.
358      * @throws CDKException
359      */
360     @Test
testGetReactantMolecule()361     public void testGetReactantMolecule() throws CDKException {
362         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
363         IAtomContainer target = sp.parseSmiles("C\\C=C/Nc1cccc(c1)N(O)\\C=C\\C\\C=C\\C=C/C");
364         IAtomContainer queryac = sp.parseSmiles("Nc1ccccc1");
365 
366         Isomorphism smsd1 = new Isomorphism(Algorithm.DEFAULT, true);
367         smsd1.init(queryac, target, true, true);
368         smsd1.setChemFilters(true, true, true);
369 
370         assertEquals(7, smsd1.getReactantMolecule().getAtomCount());
371     }
372 
373     /**
374      * Test of getProductMolecule method, of class Isomorphism.
375      * @throws CDKException
376      */
377     @Test
testGetProductMolecule()378     public void testGetProductMolecule() throws CDKException {
379         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
380         IAtomContainer target = sp.parseSmiles("C\\C=C/Nc1cccc(c1)N(O)\\C=C\\C\\C=C\\C=C/C");
381         IAtomContainer queryac = sp.parseSmiles("Nc1ccccc1");
382 
383         Isomorphism smsd1 = new Isomorphism(Algorithm.DEFAULT, true);
384         smsd1.init(queryac, target, true, true);
385         smsd1.setChemFilters(true, true, true);
386 
387         assertEquals(20, smsd1.getProductMolecule().getAtomCount());
388     }
389 
390     /**
391      * Test of getTanimotoSimilarity method, of class Isomorphism.
392      * @throws Exception
393      */
394     @Test
testGetTanimotoSimilarity()395     public void testGetTanimotoSimilarity() throws Exception {
396         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
397         IAtomContainer target = sp.parseSmiles("C\\C=C/Nc1cccc(c1)N(O)\\C=C\\C\\C=C\\C=C/C");
398         IAtomContainer queryac = sp.parseSmiles("Nc1ccccc1");
399 
400         Isomorphism smsd1 = new Isomorphism(Algorithm.DEFAULT, true);
401         smsd1.init(queryac, target, true, true);
402         smsd1.setChemFilters(true, true, true);
403 
404         double score = 0.35;
405         assertEquals(score, smsd1.getTanimotoSimilarity(), 0);
406     }
407 
408     /**
409      * Test of isStereoMisMatch method, of class Isomorphism.
410      * @throws CDKException
411      */
412     @Test
testIsStereoMisMatch()413     public void testIsStereoMisMatch() throws CDKException {
414         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
415         IAtomContainer target = sp.parseSmiles("C\\C=C/Nc1cccc(c1)N(O)\\C=C\\C\\C=C\\C=C/C");
416         IAtomContainer queryac = sp.parseSmiles("Nc1ccccc1");
417 
418         Isomorphism smsd1 = new Isomorphism(Algorithm.DEFAULT, false);
419         smsd1.init(queryac, target, true, true);
420         smsd1.setChemFilters(true, true, true);
421         assertEquals(false, smsd1.isStereoMisMatch());
422     }
423 
424     /**
425      * Test of isSubgraph method, of class Isomorphism.
426      * @throws CDKException
427      */
428     @Test
testIsSubgraph()429     public void testIsSubgraph() throws CDKException {
430         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
431         IAtomContainer target = sp.parseSmiles("C\\C=C/Nc1cccc(c1)N(O)\\C=C\\C\\C=C\\C=C/C");
432         IAtomContainer queryac = sp.parseSmiles("Nc1ccccc1");
433 
434         Isomorphism smsd1 = new Isomorphism(Algorithm.SubStructure, false);
435         smsd1.init(queryac, target, true, true);
436         smsd1.setChemFilters(true, true, true);
437         assertEquals(true, smsd1.isSubgraph());
438     }
439 
440     /**
441      * Test of getEuclideanDistance method, of class Isomorphism.
442      * @throws Exception
443      */
444     @Test
testGetEuclideanDistance()445     public void testGetEuclideanDistance() throws Exception {
446         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
447         IAtomContainer target = sp.parseSmiles("C\\C=C/Nc1cccc(c1)N(O)\\C=C\\C\\C=C\\C=C/C");
448         IAtomContainer queryac = sp.parseSmiles("Nc1ccccc1");
449 
450         Isomorphism smsd1 = new Isomorphism(Algorithm.SubStructure, true);
451         smsd1.init(queryac, target, true, true);
452         smsd1.setChemFilters(true, true, true);
453 
454         double score = 3.605;
455         assertEquals(score, smsd1.getEuclideanDistance(), 0.005);
456 
457         Isomorphism smsd2 = new Isomorphism(Algorithm.VFLibMCS, true);
458         smsd2.init(queryac, target, true, true);
459         smsd2.setChemFilters(true, true, true);
460 
461         assertEquals(score, smsd2.getEuclideanDistance(), 0.005);
462     }
463 
464     @Test
testQueryAtomContainerDefault()465     public void testQueryAtomContainerDefault() throws CDKException {
466         Isomorphism smsd = new Isomorphism(Algorithm.DEFAULT, true);
467         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
468         IAtomContainer query = sp.parseSmiles("CC");
469         IAtomContainer target = sp.parseSmiles("C1CCC12CCCC2");
470 
471         smsd.init(query, target, false, true);
472         boolean foundMatches = smsd.isSubgraph();
473         Assert.assertTrue(foundMatches);
474 
475         IQueryAtomContainer queryContainer = QueryAtomContainerCreator.createSymbolAndBondOrderQueryContainer(query);
476         smsd.init(queryContainer, target);
477         foundMatches = smsd.isSubgraph();
478         Assert.assertTrue(foundMatches);
479     }
480 
481     @Test
testQueryAtomContainerMCSPLUS()482     public void testQueryAtomContainerMCSPLUS() throws CDKException {
483         Isomorphism smsd = new Isomorphism(Algorithm.MCSPlus, true);
484         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
485         IAtomContainer query = sp.parseSmiles("CC");
486         IAtomContainer target = sp.parseSmiles("C1CCC12CCCC2");
487 
488         smsd.init(query, target, false, true);
489         boolean foundMatches = smsd.isSubgraph();
490         Assert.assertTrue(foundMatches);
491 
492         IQueryAtomContainer queryContainer = QueryAtomContainerCreator.createSymbolAndBondOrderQueryContainer(query);
493         smsd.init(queryContainer, target);
494         foundMatches = smsd.isSubgraph();
495         Assert.assertTrue(foundMatches);
496     }
497 
498     @Test
testQueryAtomContainerSubstructure()499     public void testQueryAtomContainerSubstructure() throws CDKException {
500         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
501         IAtomContainer query = sp.parseSmiles("CC");
502         IAtomContainer target = sp.parseSmiles("C1CCC12CCCC2");
503 
504         ExtAtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(query);
505         ExtAtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(target);
506 
507         //	Calling the main algorithm to perform MCS cearch
508 
509         Aromaticity.cdkLegacy().apply(query);
510         Aromaticity.cdkLegacy().apply(target);
511 
512         Isomorphism smsd = new Isomorphism(Algorithm.SubStructure, true);
513         smsd.init(query, target, false, true);
514         boolean foundMatches = smsd.isSubgraph();
515         Assert.assertTrue(foundMatches);
516 
517         //        IQueryAtomContainer queryContainer = QueryAtomContainerCreator.createSymbolAndBondOrderQueryContainer(query);
518         //
519         //        Isomorphism smsd1 = new Isomorphism(Algorithm.SubStructure, true);
520         //        smsd1.init(queryContainer, target, true, true);
521         //        smsd1.setChemFilters(true, true, true);
522         //        foundMatches = smsd1.isSubgraph();
523         //        Assert.assertFalse(foundMatches);
524     }
525 
testQueryAtomCount()526     public void testQueryAtomCount() throws CDKException {
527         Isomorphism smsd = new Isomorphism(Algorithm.DEFAULT, true);
528         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
529         IAtomContainer query = sp.parseSmiles("CC");
530         IAtomContainer target = sp.parseSmiles("C1CCC12CCCC2");
531 
532         smsd.init(query, target, false, true);
533         boolean foundMatches = smsd.isSubgraph();
534         Assert.assertEquals(18, smsd.getAllAtomMapping().size());
535         Assert.assertTrue(foundMatches);
536 
537         IQueryAtomContainer queryContainer = QueryAtomContainerCreator.createSymbolAndBondOrderQueryContainer(query);
538         smsd.init(queryContainer, target);
539         foundMatches = smsd.isSubgraph();
540         Assert.assertTrue(foundMatches);
541     }
542 
543     @Test
testMatchCount()544     public void testMatchCount() throws CDKException {
545         Isomorphism smsd = new Isomorphism(Algorithm.DEFAULT, true);
546         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
547         IAtomContainer query = sp.parseSmiles("CC");
548         IAtomContainer target = sp.parseSmiles("C1CCC12CCCC2");
549 
550         smsd.init(query, target, false, true);
551         boolean foundMatches = smsd.isSubgraph();
552         Assert.assertEquals(18, smsd.getAllAtomMapping().size());
553         Assert.assertTrue(foundMatches);
554 
555         IQueryAtomContainer queryContainer = QueryAtomContainerCreator.createSymbolAndBondOrderQueryContainer(query);
556         smsd.init(queryContainer, target);
557         foundMatches = smsd.isSubgraph();
558         Assert.assertTrue(foundMatches);
559     }
560 
561     @Test
testMatchCountCDKMCS()562     public void testMatchCountCDKMCS() throws CDKException {
563         Isomorphism smsd = new Isomorphism(Algorithm.CDKMCS, true);
564         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
565         IAtomContainer query = sp.parseSmiles("CC");
566         IAtomContainer target = sp.parseSmiles("C1CCC12CCCC2");
567 
568         smsd.init(query, target, false, true);
569         boolean foundMatches = smsd.isSubgraph();
570         Assert.assertEquals(18, smsd.getAllAtomMapping().size());
571         Assert.assertTrue(foundMatches);
572 
573         IQueryAtomContainer queryContainer = QueryAtomContainerCreator.createSymbolAndBondOrderQueryContainer(query);
574         smsd.init(queryContainer, target);
575         foundMatches = smsd.isSubgraph();
576         Assert.assertTrue(foundMatches);
577     }
578 
579     @Test
testImpossibleQuery()580     public void testImpossibleQuery() throws CDKException {
581         Isomorphism smsd = new Isomorphism(Algorithm.DEFAULT, true);
582         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
583         IAtomContainer query = sp.parseSmiles("CC");
584         IAtomContainer target = sp.parseSmiles("C");
585 
586         smsd.init(query, target, false, true);
587         boolean foundMatches = smsd.isSubgraph();
588         Assert.assertFalse(foundMatches);
589     }
590 }
591