Skip to content

Commit 8cfd660

Browse files
committed
added test cases examples for MCS and Substructure searches.
1 parent 3cd0609 commit 8cfd660

File tree

2 files changed

+162
-0
lines changed

2 files changed

+162
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* To change this template, choose Tools | Templates
3+
* and open the template in the editor.
4+
*/
5+
package smsd.algorithm.vflib;
6+
7+
import java.util.Map;
8+
import junit.framework.Assert;
9+
import org.junit.After;
10+
import org.junit.AfterClass;
11+
import org.junit.Before;
12+
import org.junit.BeforeClass;
13+
import org.junit.Test;
14+
import org.openscience.cdk.DefaultChemObjectBuilder;
15+
import org.openscience.cdk.interfaces.IAtom;
16+
import org.openscience.cdk.interfaces.IAtomContainer;
17+
import org.openscience.cdk.smiles.SmilesParser;
18+
import smsd.AtomAtomMapping;
19+
20+
/**
21+
*
22+
* @author Asad
23+
*/
24+
public class VF2MCSHandlerTest {
25+
26+
public VF2MCSHandlerTest() {
27+
}
28+
29+
@BeforeClass
30+
public static void setUpClass() throws Exception {
31+
}
32+
33+
@AfterClass
34+
public static void tearDownClass() throws Exception {
35+
}
36+
37+
@Before
38+
public void setUp() {
39+
}
40+
41+
@After
42+
public void tearDown() {
43+
}
44+
45+
/**
46+
* Test ring match using MCS VF2Plus
47+
* @throws Exception
48+
*/
49+
@Test
50+
public void testVF2MCS() throws Exception {
51+
SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
52+
// Benzene
53+
IAtomContainer query = sp.parseSmiles("C1=CC=CC=C1");
54+
// Napthalene
55+
IAtomContainer target = sp.parseSmiles("C1=CC2=C(C=C1)C=CC=C2");
56+
//Algorithm is VF2MCS
57+
//Bond Sensitive is set True
58+
//Ring Match is set True
59+
60+
VF2MCSHandler comparison = new VF2MCSHandler();
61+
comparison.set(query, target);
62+
comparison.searchMCS(true, true);
63+
64+
Assert.assertEquals(6, comparison.getFirstAtomMapping().getCount());
65+
Assert.assertEquals(24, comparison.getAllAtomMapping().size());
66+
67+
/**
68+
* Print the mapping between molecules
69+
**/
70+
System.out.println(" Mappings: ");
71+
for (AtomAtomMapping atomatomMapping : comparison.getAllAtomMapping()) {
72+
for (Map.Entry<IAtom, IAtom> mapping : atomatomMapping.getMappings().entrySet()) {
73+
IAtom sourceAtom = mapping.getKey();
74+
IAtom targetAtom = mapping.getValue();
75+
System.out.println(sourceAtom.getSymbol() + " " + targetAtom.getSymbol());
76+
System.out.println(atomatomMapping.getQueryIndex(sourceAtom) + " " + atomatomMapping.getTargetIndex(targetAtom));
77+
}
78+
System.out.println("");
79+
}
80+
}
81+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* To change this template, choose Tools | Templates
3+
* and open the template in the editor.
4+
*/
5+
package smsd.algorithm.vflib;
6+
7+
import java.util.Map;
8+
import junit.framework.Assert;
9+
import org.junit.After;
10+
import org.junit.AfterClass;
11+
import org.junit.Before;
12+
import org.junit.BeforeClass;
13+
import org.junit.Test;
14+
import org.openscience.cdk.DefaultChemObjectBuilder;
15+
import org.openscience.cdk.interfaces.IAtom;
16+
import org.openscience.cdk.interfaces.IAtomContainer;
17+
import org.openscience.cdk.smiles.SmilesParser;
18+
import smsd.AtomAtomMapping;
19+
20+
/**
21+
*
22+
* @author Asad
23+
*/
24+
public class VF2SubTest {
25+
26+
public VF2SubTest() {
27+
}
28+
29+
@BeforeClass
30+
public static void setUpClass() throws Exception {
31+
}
32+
33+
@AfterClass
34+
public static void tearDownClass() throws Exception {
35+
}
36+
37+
@Before
38+
public void setUp() {
39+
}
40+
41+
@After
42+
public void tearDown() {
43+
}
44+
45+
/**
46+
* Test ring match using MCS VF2Plus
47+
* @throws Exception
48+
*/
49+
@Test
50+
public void testVF2Substructure() throws Exception {
51+
SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
52+
// Benzene
53+
IAtomContainer query = sp.parseSmiles("C1=CC=CC=C1");
54+
// Napthalene
55+
IAtomContainer target = sp.parseSmiles("C1=CC2=C(C=C1)C=CC=C2");
56+
//Algorithm is VF2MCS
57+
//Bond Sensitive is set True
58+
//Ring Match is set True
59+
60+
VF2Sub comparison = new VF2Sub(true, true);
61+
comparison.set(query, target);
62+
Assert.assertTrue(comparison.isSubgraph());
63+
64+
Assert.assertEquals(6, comparison.getFirstAtomMapping().getCount());
65+
Assert.assertEquals(24, comparison.getAllAtomMapping().size());
66+
67+
/**
68+
* Print the mapping between molecules
69+
**/
70+
System.out.println(" Mappings: ");
71+
for (AtomAtomMapping atomatomMapping : comparison.getAllAtomMapping()) {
72+
for (Map.Entry<IAtom, IAtom> mapping : atomatomMapping.getMappings().entrySet()) {
73+
IAtom sourceAtom = mapping.getKey();
74+
IAtom targetAtom = mapping.getValue();
75+
System.out.println(sourceAtom.getSymbol() + " " + targetAtom.getSymbol());
76+
System.out.println(atomatomMapping.getQueryIndex(sourceAtom) + " " + atomatomMapping.getTargetIndex(targetAtom));
77+
}
78+
System.out.println("");
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)