$darkmode
DENOPTIM
FragmentIsomorphismInspectorTest.java
Go to the documentation of this file.
1package denoptim.graph;
2
3/*
4 * DENOPTIM
5 * Copyright (C) 2019 Vishwesh Venkatraman <vishwesh.venkatraman@ntnu.no>
6 * and Marco Foscato <marco.foscato@uib.no>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published
10 * by the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22import static org.junit.jupiter.api.Assertions.assertFalse;
23import static org.junit.jupiter.api.Assertions.assertTrue;
24
25import javax.vecmath.Point3d;
26
27import org.junit.jupiter.api.Test;
28import org.openscience.cdk.Atom;
29import org.openscience.cdk.interfaces.IBond;
30import org.openscience.cdk.silent.Bond;
31
32import denoptim.exception.DENOPTIMException;
33
41{
42
43//------------------------------------------------------------------------------
44
46 {
47 Fragment v = new Fragment();
48 for (int i=0; i<size; i++)
49 {
50 Atom a = new Atom("C", new Point3d());
51 v.addAtom(a);
52 for (int j=0; j<i; j++)
53 {
54 v.addBond(new Bond(a,v.getAtom(j)));
55 }
56 v.addAPOnAtom(a, APClass.make("apc:1"), new Point3d());
57 }
58 return v;
59 }
60
61//------------------------------------------------------------------------------
62
63 @Test
64 public void testTimeout() throws Exception
65 {
68
70 new FragmentIsomorphismInspector(a, b, 10000, false); // 10 secs
71 inspector.reportTimeoutIncidents = false;
72 assertTrue(inspector.isomorphismExists());
73
74 inspector = new FragmentIsomorphismInspector(a, b, 1, false); // 0.001 s
75 inspector.reportTimeoutIncidents = false;
76 assertFalse(inspector.isomorphismExists());
77 }
78
79//------------------------------------------------------------------------------
80
81 @Test
82 public void testIsomorphismExists() throws Exception
83 {
84 Fragment v = new Fragment();
85 Atom c1 = new Atom("C", new Point3d(1,1,1));
86 Atom c2 = new Atom("C", new Point3d(2,2,2));
87 Atom o = new Atom("O", new Point3d(3,3,3));
88 v.addAtom(c1);
89 v.addAtom(c2);
90 v.addAtom(o);
91 v.addBond(new Bond(c1,c2,IBond.Order.SINGLE));
92 v.addBond(new Bond(c2,o,IBond.Order.DOUBLE));
93 v.addAP(0, APClass.make("a:0"), new Point3d(0,1,2));
94 v.addAP(0, APClass.make("a:0"), new Point3d(0,-1,-2));
95 v.addAP(0, APClass.make("a:0"), new Point3d(-1,1,-2));
96 v.addAP(1, APClass.make("b:0"), new Point3d(3,3,3));
97
98 Fragment v2 = v.clone();
99
101 new FragmentIsomorphismInspector(v, v2, false);
102 assertTrue(inspector.isomorphismExists());
103
104 // 3D of atom does not matter
105 v2 = v.clone();
106 v2.getAtom(0).setPoint3d(new Point3d(6,6,6));
107 inspector = new FragmentIsomorphismInspector(v, v2, false);
108 assertTrue(inspector.isomorphismExists());
109
110 // 3D of AP does not matter
111 v2 = v.clone();
112 v2.getAP(1).setDirectionVector(new Point3d());
113 inspector = new FragmentIsomorphismInspector(v, v2, false);
114 assertTrue(inspector.isomorphismExists());
115
116 // AP class matters depending on flag
117 v2 = v.clone();
118 v2.getAP(1).setAPClass(APClass.make("c:0"));
119 inspector = new FragmentIsomorphismInspector(v, v2, false);
120 assertFalse(inspector.isomorphismExists());
121 inspector = new FragmentIsomorphismInspector(v, v2, true);
122 assertTrue(inspector.isomorphismExists());
123
124 // bonding pattern matters
125 v2 = v.clone();
126 v2.getAtom(0).getBond(v2.getAtom(1)).setOrder(IBond.Order.TRIPLE);
127 inspector = new FragmentIsomorphismInspector(v, v2, false);
128 assertFalse(inspector.isomorphismExists());
129 v2 = v.clone();
130 v2.removeBond(0);
131 inspector = new FragmentIsomorphismInspector(v, v2, false);
132 assertFalse(inspector.isomorphismExists());
133
134 // AP count matters irrespectively on flag
135 v2 = v.clone();
136 v2.removeAP(v2.getAP(1));
137 inspector = new FragmentIsomorphismInspector(v, v2, false);
138 assertFalse(inspector.isomorphismExists());
139 inspector = new FragmentIsomorphismInspector(v, v2, true);
140 assertFalse(inspector.isomorphismExists());
141 }
142
143//------------------------------------------------------------------------------
144
145}
static APClass make(String ruleAndSubclass)
Creates an APClass if it does not exist already, or returns the reference to the existing instance.
Definition: APClass.java:164
void setAPClass(String apClass)
Set the Attachment Point class.
void setDirectionVector(Point3d dirVec)
Sets the end of the 3D vector defining the direction of the AP in 3D.
Class representing a continuously connected portion of chemical object holding attachment points.
Definition: Fragment.java:61
IBond removeBond(int position)
Definition: Fragment.java:878
void addAP(int atomPositionNumber)
Adds an attachment point with a dummy APClass.
Definition: Fragment.java:343
AttachmentPoint addAPOnAtom(IAtom srcAtm, APClass apc, Point3d vector)
Add an attachment point to the specifies atom.
Definition: Fragment.java:424
void addBond(IBond bond)
Definition: Fragment.java:871
Fragment clone()
Returns a deep copy of this fragments.
Definition: Fragment.java:733
void addAtom(IAtom atom)
Definition: Fragment.java:836
IAtom getAtom(int number)
Definition: Fragment.java:843
void removeAP(AttachmentPoint ap)
Definition: Fragment.java:433
boolean isomorphismExists()
Checks if an isomorphism exists between the two fragments.
AttachmentPoint getAP(int i)
Get attachment point i on this vertex.
Definition: Vertex.java:1008