$darkmode
DENOPTIM
AttachmentPointTest.java
Go to the documentation of this file.
1package denoptim.graph;
2
3import static org.junit.jupiter.api.Assertions.assertEquals;
4import static org.junit.jupiter.api.Assertions.assertFalse;
5import static org.junit.jupiter.api.Assertions.assertNotEquals;
6import static org.junit.jupiter.api.Assertions.assertNull;
7import static org.junit.jupiter.api.Assertions.assertTrue;
8
9/*
10 * DENOPTIM
11 * Copyright (C) 2019 Vishwesh Venkatraman <vishwesh.venkatraman@ntnu.no>
12 * and Marco Foscato <marco.foscato@uib.no>
13 *
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Affero General Public License as published
16 * by the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Affero General Public License for more details.
23 *
24 * You should have received a copy of the GNU Affero General Public License
25 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 */
27
28import java.util.ArrayList;
29import java.util.List;
30
31import javax.vecmath.Point3d;
32
33import org.junit.jupiter.api.Test;
34import org.openscience.cdk.Atom;
35import org.openscience.cdk.silent.Bond;
36
37import denoptim.constants.DENOPTIMConstants;
38import denoptim.graph.Edge.BondType;
39import denoptim.graph.Vertex.BBType;
40
48{
49 private final String APRULE = "MyRule";
50 private final String APSUBRULE = "1";
51 private final String APCLASS = APRULE
52 + DENOPTIMConstants.SEPARATORAPPROPSCL + APSUBRULE;
53 private final Point3d DIRVEC = new Point3d(1.1, 2.2, 3.3);
54
55//-----------------------------------------------------------------------------
56
57 @Test
58 public void testParsingofSdfAPString() throws Exception
59 {
60 String[] altStrings = {
61 "123#myrule:0:DOUBLE:1.0%2.0%-3.0",
62 "123#myrule:0:1.0%2.0%-3.0",
63 "123#myrule:0:UNDEFINED",
64 "123#myrule:0"};
65
66 //NB: we will be changing the bond type of the static APClass
67 BondType[] expectedBT = {BondType.DOUBLE,
71
72 boolean[] check3d = {true, true, false, false};
73
74 for (int i=0; i< altStrings.length; i++)
75 {
76 Object[] o = AttachmentPoint.processSdfString(altStrings[i]);
77
78 assertTrue(Integer.class.isInstance(o[0]));
79 int atmId = (int) o[0];
80 assertEquals(122, atmId); //NB: 0-based from 1-based in SDF string
81
82 assertTrue(o[1] instanceof APClass);
83 APClass apc = (APClass) o[1];
84 assertEquals(expectedBT[i], apc.getBondType());
85
86
87 if (check3d[i])
88 {
89 assertTrue(o[2] instanceof Point3d);
90 Point3d p3d = (Point3d)o[2];
91 double thrl = 0.0001;
92 assertTrue(Math.abs(p3d.x - 1.0) < thrl);
93 assertTrue(Math.abs(p3d.y - 2.0) < thrl);
94 assertTrue(Math.abs(p3d.z + 3.0) < thrl);
95 } else {
96 assertEquals(null,o[2]);
97 }
98 }
99 }
100
101//-----------------------------------------------------------------------------
102
103 @Test
104 public void testGetEmbeddedAP() throws Exception
105 {
106 EmptyVertex vA1 = new EmptyVertex(0);
107 vA1.addAP();
108 vA1.addAP();
109 vA1.addAP();
110 vA1.addAP();
111 vA1.addAP();
112 vA1.addAP();
113 vA1.addAP();
114 List<AttachmentPoint> deepAPs1 = vA1.getAttachmentPoints();
115 EmptyVertex vB1 = new EmptyVertex(1);
116 vB1.addAP();
117
118 DGraph gL01 = new DGraph();
119 gL01.addVertex(vA1);
120 gL01.appendVertexOnAP(vA1.getAP(0), vB1.getAP(0));
121
122 Template tL01 = new Template(BBType.NONE);
123 tL01.setInnerGraph(gL01);
124
125 Vertex old1 = tL01;
126
127 int[] expected1 = {6,5,4,3,2,1};
128
129 Edge e1 = gL01.getEdgeAtPosition(0); //there is only 1 edge
132 assertTrue(deepAPs1.contains(srcAP1),"srcAP is deep");
133 assertTrue(trgAP1==vB1.getAP(0),"trgAP is on surface");
134 checkIdentityOfEmbeddedAP(expected1[0],deepAPs1,old1);
135
136 List<Vertex> addedVertexes1 = new ArrayList<Vertex>();
137 addedVertexes1.add(vB1);
138 for (int i=1; i<6; i++)
139 {
140 EmptyVertex vNew = new EmptyVertex(1);
141 vNew.addAP();
142 DGraph gNew = new DGraph();
143 gNew.addVertex(old1);
144 gNew.appendVertexOnAP(old1.getAP(0), vNew.getAP(0));
145 addedVertexes1.add(vNew);
146
147 e1 = gNew.getEdgeAtPosition(0); //there is only 1 edge
148 srcAP1 = e1.getSrcAPThroughout();
149 trgAP1 = e1.getTrgAPThroughout();
150 assertTrue(deepAPs1.contains(srcAP1),"srcAP is deep");
151 assertTrue(trgAP1==vNew.getAP(0),"trgAP is on surface");
152
153 Template template = new Template(BBType.NONE);
154 template.setInnerGraph(gNew);
155 old1 = template;
156
157 checkIdentityOfEmbeddedAP(expected1[i],deepAPs1,old1);
158 }
159
160 int nTotAvailAPs1 = 0;
161 int correntLinks1 = 0;
162 for (AttachmentPoint deepAP : vA1.getAttachmentPoints())
163 {
164 if (deepAP.isAvailableThroughout())
165 {
166 nTotAvailAPs1++;
167 } else {
168 Vertex linkedOwner = deepAP.getLinkedAPThroughout().getOwner();
169 if (addedVertexes1.contains(linkedOwner))
170 correntLinks1++;
171 }
172 }
173 assertEquals(1,nTotAvailAPs1,"total number deep available");
174 assertEquals(addedVertexes1.size(),correntLinks1,"number links to layers");
175
176 //
177 // Now we do the same by building the graph in the opposite direction
178 //
179
180 EmptyVertex vA2 = new EmptyVertex();
181 vA2.addAP();
182 vA2.addAP();
183 vA2.addAP();
184 vA2.addAP();
185 vA2.addAP();
186 vA2.addAP();
187 vA2.addAP();
188 List<AttachmentPoint> deepAPs2 = vA2.getAttachmentPoints();
189 EmptyVertex vB2 = new EmptyVertex(1);
190 vB2.addAP();
191
192 DGraph gL02 = new DGraph();
193
194 //NB: here we pick the other vertex as source (w.r.t. gL01)
195 gL02.addVertex(vB2);
196
197 //NB: here is the different direction
198 gL02.appendVertexOnAP(vB2.getAP(0),vA2.getAP(0));
199
200 Template tL02 = new Template(BBType.NONE);
201 tL02.setInnerGraph(gL02);
202
203 Vertex old2 = tL02;
204
205 int[] expected2 = {6,5,4,3,2,1};
206
207 Edge e2 = gL02.getEdgeAtPosition(0); //there is only 1 edge
210 assertTrue(deepAPs2.contains(trgAP2),"trgAP is deep");
211 assertTrue(srcAP2==vB2.getAP(0),"srcAP is on surface");
212 checkIdentityOfEmbeddedAP(expected2[0],deepAPs2,old2);
213
214 List<Vertex> addedVertexes2 = new ArrayList<Vertex>();
215 addedVertexes2.add(vB2);
216 for (int i=1; i<6; i++)
217 {
218 EmptyVertex vNew = new EmptyVertex(1);
219 vNew.addAP();
220 DGraph gNew = new DGraph();
221
222 //NB: here we pick the other vertex as source
223 gNew.addVertex(vNew);
224
225 //NB: here is the different direction
226 gNew.appendVertexOnAP(vNew.getAP(0), old2.getAP(0));
227 addedVertexes2.add(vNew);
228
229 e2 = gNew.getEdgeAtPosition(0); //there is only 1 edge
230 srcAP2 = e2.getSrcAPThroughout();
231 trgAP2 = e2.getTrgAPThroughout();
232 assertTrue(deepAPs2.contains(trgAP2),"trgAP is deep");
233 assertTrue(srcAP2==vNew.getAP(0),"srcAP is on surface");
234
235 Template template = new Template(BBType.NONE);
236 template.setInnerGraph(gNew);
237 old2 = template;
238
239 checkIdentityOfEmbeddedAP(expected2[i],deepAPs2,old2);
240 }
241
242 int nTotAvailAPs = 0;
243 int correntLinks = 0;
244 for (AttachmentPoint deepAP : vA2.getAttachmentPoints())
245 {
246 if (deepAP.isAvailableThroughout())
247 {
248 nTotAvailAPs++;
249 } else {
250 Vertex linkedOwner = deepAP.getLinkedAPThroughout().getOwner();
251 if (addedVertexes2.contains(linkedOwner))
252 correntLinks++;
253 }
254 }
255 assertEquals(1,nTotAvailAPs,"total number deep available");
256 assertEquals(addedVertexes2.size(),correntLinks,"number links to layers");
257 }
258
259//-----------------------------------------------------------------------------
260
261 private void checkIdentityOfEmbeddedAP(int expectedMAtches,
262 List<AttachmentPoint> deepAPs, Vertex v)
263 {
264 int nfound=0;
265 for (AttachmentPoint outAP : v.getAttachmentPoints())
266 {
267 AttachmentPoint ap = outAP.getEmbeddedAP();
268 if (deepAPs.contains(ap))
269 {
270 nfound++;
271 continue;
272 }
273 }
274 assertEquals(expectedMAtches,nfound,"number of deep-traced APs");
275 }
276
277//-----------------------------------------------------------------------------
278
279 @Test
280 public void testAvailableThrougout() throws Exception
281 {
282 EmptyVertex vA = new EmptyVertex(0);
283 vA.addAP();
284 vA.addAP();
285 vA.addAP();
286 vA.addAP();
287 vA.addAP();
288 vA.addAP();
289 vA.addAP();
290 EmptyVertex vB = new EmptyVertex(1);
291 vB.addAP();
292 vB.addAP();
293
294 DGraph gL0 = new DGraph();
295 gL0.addVertex(vA);
296 gL0.appendVertexOnAP(vA.getAP(0), vB.getAP(1));
297
298 Template tL0 = new Template(BBType.NONE);
299 tL0.setInnerGraph(gL0);
300
301 int[] expectedN = {6,6,6,6};
302 int[] expectedNThroughout = {6,5,4,3};
303
304 checkAvailNT(expectedN[0], expectedNThroughout[0], 0, vA);
305
306 Vertex old = tL0;
307 for (int i=1; i<4; i++)
308 {
309 EmptyVertex vNew = new EmptyVertex(1);
310 vNew.addAP();
311 DGraph gNew = new DGraph();
312 gNew.addVertex(old);
313 gNew.appendVertexOnAP(old.getAP(0), vNew.getAP(0));
314 Template template = new Template(BBType.NONE);
315 template.setInnerGraph(gNew);
316 checkAvailNT(expectedN[i], expectedNThroughout[i], i, vA);
317 old = template;
318 }
319 }
320
321//-----------------------------------------------------------------------------
322
323 private void checkAvailNT(int expN, int expNTm, int level, Vertex v)
324 {
325 int n = 0;
326 int nThroughout = 0;
328 {
329 if (apA.isAvailable())
330 n++;
331 if (apA.isAvailableThroughout())
332 nThroughout++;
333 }
334 assertEquals(expN,n,"Number of level-available ("+level+"");
335 assertEquals(expNTm,nThroughout,"Number of throughout-available ("+level+")");
336 }
337
338//-----------------------------------------------------------------------------
339
340 @Test
341 public void testGetEdbeUserThrougout() throws Exception
342 {
343 EmptyVertex vA = new EmptyVertex(0);
344 vA.addAP();
345 vA.addAP();
346 vA.addAP();
347 vA.addAP();
348 vA.addAP();
349
350 DGraph gL0 = new DGraph();
351 gL0.addVertex(vA);
352 Template tL0 = new Template(BBType.NONE);
353 tL0.setInnerGraph(gL0);
354
355 List<Vertex> newVrtxs = new ArrayList<Vertex>();
356
357 Vertex old = tL0;
358 for (int i=0; i<5; i++)
359 {
360 EmptyVertex vNew = new EmptyVertex(1);
361 vNew.addAP();
362 newVrtxs.add(vNew);
363 DGraph gNew = new DGraph();
364 gNew.addVertex(old);
365 gNew.appendVertexOnAP(old.getAP(0), vNew.getAP(0));
366 Template template = new Template(BBType.NONE);
367 template.setInnerGraph(gNew);
368 checkGetEdgeUserThroughput(vA, newVrtxs);
369 old = template;
370 }
371 }
372
373//-----------------------------------------------------------------------------
374
376 List<Vertex> onion)
377 {
378 int i = -1;
380 {
381 i++;
382 assertTrue(apA.isAvailable(), "APs of vA are all free within the "
383 + "graph owning vA.");
384 Edge e = apA.getEdgeUserThroughout();
385 if (e != null)
386 {
387 AttachmentPoint inAP = e.getSrcAP();
388 while (true)
389 {
390 Vertex src = inAP.getOwner();
391 if (src instanceof Template)
392 {
393 inAP = ((Template) src).getInnerAPFromOuterAP(
394 inAP);
395 } else {
396 break;
397 }
398 }
399 assertEquals(apA,inAP,"Src AP identity");
400 assertEquals(onion.get(i).getAP(0),e.getTrgAP(), "Trg AP identity");
401 }
402 }
403 }
404
405//-----------------------------------------------------------------------------
406
407 @Test
408 public void testIsSrcInUser() throws Exception
409 {
410 DGraph g = new DGraph();
411 EmptyVertex v1 = new EmptyVertex();
414 AttachmentPoint ap1A = v1.getAP(0);
415 AttachmentPoint ap1B = v1.getAP(1);
416 EmptyVertex v2 = new EmptyVertex();
419 AttachmentPoint ap2A = v2.getAP(0);
420 AttachmentPoint ap2B = v2.getAP(1);
421 g.addVertex(v1);
422 g.appendVertexOnAP(ap1A, ap2B);
423
424 assertTrue(ap1A.isSrcInUser(), "Check AP used as src.");
425 assertFalse(ap2B.isSrcInUser(), "Check AP used as trg.");
426 assertFalse(ap1B.isSrcInUser(), "Check AP free on src side.");
427 assertFalse(ap2A.isSrcInUser(), "Check AP free on trg side.");
428 }
429
430//-----------------------------------------------------------------------------
431
432 @Test
433 public void testGetLinkedAP() throws Exception
434 {
435 DGraph g = new DGraph();
436 EmptyVertex v1 = new EmptyVertex();
439 AttachmentPoint ap1A = v1.getAP(0);
440 AttachmentPoint ap1B = v1.getAP(1);
441 EmptyVertex v2 = new EmptyVertex();
444 AttachmentPoint ap2A = v2.getAP(0);
445 AttachmentPoint ap2B = v2.getAP(1);
446 g.addVertex(v1);
447 g.appendVertexOnAP(ap1A, ap2B);
448
449 assertTrue(ap1A.getLinkedAP() == ap2B, "Get AP on other side of ap1A");
450 assertTrue(ap2B.getLinkedAP() == ap1A, "Get AP on other dice of ap2");
451 assertNull(ap1B.getLinkedAP(), "Free AP 1B should return null");
452 assertNull(ap2A.getLinkedAP(), "Free AP 2A should return null");
453 }
454
455//-----------------------------------------------------------------------------
456
457 @Test
458 public void testConstructorsAndSDFString() throws Exception
459 {
460 Fragment dummyVertex = new Fragment();
461 dummyVertex.addAtom(new Atom("C"));
462 dummyVertex.addAP(0, DIRVEC, APClass.make(APCLASS));
463 AttachmentPoint ap = dummyVertex.getAP(0);
464
465 String str2 = ap.getSingleAPStringSDF(true);
466 AttachmentPoint ap2 = new AttachmentPoint(dummyVertex
467 , str2);
468
469 assertEquals(ap.getSingleAPStringSDF(true),
470 ap2.getSingleAPStringSDF(true));
471 }
472
473//-----------------------------------------------------------------------------
474
475 @Test
476 public void testConstructorsAndSDFStringNoDirVec() throws Exception
477 {
478 Fragment dummyVertex = new Fragment();
479 dummyVertex.addAtom(new Atom("C"));
480 dummyVertex.addAP(0, DIRVEC, APClass.make(APCLASS));
481 AttachmentPoint ap = dummyVertex.getAP(0);
482
483 String str2 = ap.getSingleAPStringSDF(true);
484 AttachmentPoint ap2 = new AttachmentPoint(dummyVertex
485 , str2);
486
487 String str3 = (0+1) + DENOPTIMConstants.SEPARATORAPPROPAAP
488 + ap.getSingleAPStringSDF(false);
489 AttachmentPoint ap3 = new AttachmentPoint(dummyVertex
490 , str3);
491
492 assertEquals(ap.getSingleAPStringSDF(true),
493 ap2.getSingleAPStringSDF(true));
494 assertEquals(ap2.toStringNoId(),ap3.toStringNoId());
495 }
496
497//-----------------------------------------------------------------------------
498
499 @Test
500 public void testSortAPs() throws Exception
501 {
502 Fragment dummyVertex = new Fragment();
503 dummyVertex.addAtom(new Atom("C"));
504 dummyVertex.addAtom(new Atom("C"));
505 dummyVertex.addAtom(new Atom("C"));
506 dummyVertex.addAtom(new Atom("C"));
507 dummyVertex.addAtom(new Atom("C"));
508 dummyVertex.addAtom(new Atom("C"));
509 dummyVertex.addAtom(new Atom("C"));
510 dummyVertex.addAP(0);
511 dummyVertex.addAP(0);
512 AttachmentPoint ap1 = dummyVertex.getAP(0);
513 AttachmentPoint ap2 = dummyVertex.getAP(1);
514
515 dummyVertex.addAP(4, DIRVEC, APClass.make("AA:0"));
516 AttachmentPoint ap3 = dummyVertex.getAP(2);
517
518 dummyVertex.addAP(4, DIRVEC, APClass.make("AA:1"));
519 AttachmentPoint ap4 = dummyVertex.getAP(3);
520
521 dummyVertex.addAP(5, new Point3d(1.1, 2.2, 3.3),
523 AttachmentPoint ap5 = dummyVertex.getAP(4);
524
525 dummyVertex.addAP(5, new Point3d(2.2, 2.2, 3.3),
527 AttachmentPoint ap6 = dummyVertex.getAP(5);
528
529 List<AttachmentPoint> list = dummyVertex.getAttachmentPoints();
530
531 list.sort(new AttachmentPointComparator());
532
533 assertEquals(list.get(0),ap1);
534 assertEquals(list.get(1),ap2);
535 assertEquals(list.get(2),ap3);
536 assertEquals(list.get(3),ap4);
537 assertEquals(list.get(4),ap5);
538 assertEquals(list.get(5),ap6);
539 }
540
541//-----------------------------------------------------------------------------
542
543 @Test
544 public void testSameAs()
545 {
546 EmptyVertex dummyVertex = new EmptyVertex();
547 dummyVertex.addAP();
548 dummyVertex.addAP();
549 AttachmentPoint apA = dummyVertex.getAP(0);
550 AttachmentPoint apB = dummyVertex.getAP(1);
551
552 Vertex clone = dummyVertex.clone();
553 AttachmentPoint apAc = clone.getAP(0);
554 AttachmentPoint apBc = clone.getAP(1);
555
556 assertEquals(-1,apA.compareTo(apB),"Comparison driven by ID.");
557 assertTrue(apA.sameAs(apAc),"SameAs ignores ID.");
558 assertTrue(apB.sameAs(apBc),"SameAs ignores ID (2).");
559 }
560
561//-----------------------------------------------------------------------------
562
563 @Test
565 {
566 EmptyVertex dummyVertex = new EmptyVertex();
567 dummyVertex.addAP();
568 dummyVertex.addAP();
569 AttachmentPoint apA = dummyVertex.getAP(0);
570 AttachmentPoint apB = dummyVertex.getAP(1);
571
572 assertFalse(apA.sameAs(apB));
573 }
574
575//-----------------------------------------------------------------------------
576
577 @Test
578 public void testSameAs_DiffAPClass() throws Exception
579 {
580 EmptyVertex dummyVertex = new EmptyVertex();
581 dummyVertex.addAP(APClass.make("classA:0"));
582 AttachmentPoint apA = dummyVertex.getAP(0);
583
584 Vertex clone = dummyVertex.clone();
585 AttachmentPoint apAc = clone.getAP(0);
586 apAc.setAPClass(APClass.make("classB:0"));
587
588 assertFalse(apA.sameAs(apAc));
589 }
590
591//-----------------------------------------------------------------------------
592
593 @Test
594 public void testClone() throws Exception
595 {
596 EmptyVertex ev = new EmptyVertex();
598
599
600 EmptyVertex ev2 = new EmptyVertex();
602 AttachmentPoint ev2Ap = ev2.getAP(0);
603
604 AttachmentPoint orig = ev.getAP(0);
605 Point3d p3d = new Point3d(0.1, 0.2, -0.3);
606 orig.setDirectionVector(p3d);
607
608 Edge e = new Edge(ev2Ap, orig);
609
610 AttachmentPoint clone = orig.clone();
611
612 assertEquals(orig.getAPClass(),clone.getAPClass(),"APClass");
613 assertEquals(orig.getAtomPositionNumber(),
614 clone.getAtomPositionNumber(),"AtomPositionNumber");
615 assertEquals(orig.getDirectionVector(),
616 clone.getDirectionVector(),"DirectionVector");
617 assertNotEquals(orig.getID(),clone.getID(),"ID");
618 assertEquals(orig.getOwner(),
619 clone.getOwner(),"Owner");
620 assertEquals(e,orig.getEdgeUser(),"Edge user in original");
621 assertEquals(null,clone.getEdgeUser(),"Edge user in clone");
622
623 }
624
625//------------------------------------------------------------------------------
626
627 @Test
628 public void testHasSameSrcAtom() throws Exception
629 {
630 Fragment v1 = new Fragment();
631 Atom a1 = new Atom("C");
632 Atom a2 = new Atom("C");
633 Atom a3 = new Atom("C");
634 v1.addAtom(a1);
635 v1.addAtom(a2);
636 v1.addAtom(a3);
637 v1.addBond(new Bond(a1, a2));
638 v1.addBond(new Bond(a2, a3));
639 v1.addAPOnAtom(a1, APClass.make(APCLASS), new Point3d());
640 v1.addAPOnAtom(a1, APClass.make(APCLASS), new Point3d());
641 v1.addAPOnAtom(a2, APClass.make(APCLASS), new Point3d());
642 v1.addAPOnAtom(a3, APClass.make(APCLASS), new Point3d());
643
644 AttachmentPoint ap0 = v1.getAP(0);
645 AttachmentPoint ap1 = v1.getAP(1);
646 AttachmentPoint ap2 = v1.getAP(2);
647
648 /*
649 * ap0
650 * \
651 * a1----a2---a3
652 * / \ \
653 * ap1 ap2 ap3
654 */
655
656 assertTrue(ap0.hasSameSrcAtom(ap1),"Intra-fragment (A)");
657 assertTrue(ap1.hasSameSrcAtom(ap0),"Intra-fragment (B)");
658 assertFalse(ap0.hasSameSrcAtom(ap2),"Intra-fragment (C)");
659 assertFalse(ap2.hasSameSrcAtom(ap0),"Intra-fragment (D)");
660
661 Fragment v2 = v1.clone();
662 DGraph g2 = new DGraph();
663 g2.addVertex(v2);
665 t2.setInnerGraph(g2);
666
667 ap0 = t2.getAP(0);
668 ap1 = t2.getAP(1);
669 ap2 = t2.getAP(2);
670
671 assertTrue(ap0.hasSameSrcAtom(ap1),"Intra-Template (A)");
672 assertTrue(ap1.hasSameSrcAtom(ap0),"Intra-Template (B)");
673 assertFalse(ap0.hasSameSrcAtom(ap2),"Intra-Template (C)");
674 assertFalse(ap2.hasSameSrcAtom(ap0),"Intra-Template (D)");
675 }
676
677//------------------------------------------------------------------------------
678
679 @Test
680 public void testHasConnectedSrcAtom() throws Exception
681 {
682 Fragment v1 = new Fragment();
683 Atom a1 = new Atom("C");
684 Atom a2 = new Atom("C");
685 Atom a3 = new Atom("C");
686 v1.addAtom(a1);
687 v1.addAtom(a2);
688 v1.addAtom(a3);
689 v1.addBond(new Bond(a1, a2));
690 v1.addBond(new Bond(a2, a3));
691 v1.addAPOnAtom(a1, APClass.make(APCLASS), new Point3d());
692 v1.addAPOnAtom(a1, APClass.make(APCLASS), new Point3d());
693 v1.addAPOnAtom(a2, APClass.make(APCLASS), new Point3d());
694 v1.addAPOnAtom(a3, APClass.make(APCLASS), new Point3d());
695
696 AttachmentPoint ap0 = v1.getAP(0);
697 AttachmentPoint ap1 = v1.getAP(1);
698 AttachmentPoint ap2 = v1.getAP(2);
699 AttachmentPoint ap3 = v1.getAP(3);
700
701 /*
702 * ap0
703 * \
704 * a1----a2---a3
705 * / \ \
706 * ap1 ap2 ap3
707 */
708
709 assertTrue(ap0.hasConnectedSrcAtom(ap2),"Intra-fragment (E)");
710 assertTrue(ap2.hasConnectedSrcAtom(ap0),"Intra-fragment (F)");
711 assertFalse(ap1.hasConnectedSrcAtom(ap3),"Intra-fragment (G)");
712 assertFalse(ap3.hasConnectedSrcAtom(ap1),"Intra-fragment (H)");
713
714 Fragment v2 = v1.clone();
715 DGraph g2 = new DGraph();
716 g2.addVertex(v2);
718 t2.setInnerGraph(g2);
719
720 ap0 = t2.getAP(0);
721 ap1 = t2.getAP(1);
722 ap2 = t2.getAP(2);
723 ap3 = t2.getAP(3);
724
725 assertTrue(ap0.hasConnectedSrcAtom(ap2),"Intra-Template (E)");
726 assertTrue(ap2.hasConnectedSrcAtom(ap0),"Intra-Template (F)");
727 assertFalse(ap1.hasConnectedSrcAtom(ap3),"Intra-Template (G)");
728 assertFalse(ap3.hasConnectedSrcAtom(ap1),"Intra-Template (H)");
729
730 Fragment v3a = v1.clone();
731 Fragment v3b = v1.clone();
732 v3b.setVertexId(v3a.getVertexId()+1);
733 DGraph g3 = new DGraph();
734 g3.addVertex(v3a);
735 g3.addVertex(v3b);
736 g3.addEdge(new Edge(v3a.getAP(1), v3b.getAP(0)));
737
738 /*
739 * ap0
740 * \
741 * a1---a2---a3 v3a
742 * / \ \
743 * ap1 ap2 ap3
744 * |
745 * ap0
746 * \
747 * a1---a2---a3 v3b
748 * / \ \
749 * ap1 ap2 ap3
750 *
751 */
752
753 assertTrue(v3a.getAP(0).hasConnectedSrcAtom(v3b.getAP(1)),
754 "Through edge (A)"); // The two APs are not in the edge
755 assertFalse(v3a.getAP(1).hasConnectedSrcAtom(v3b.getAP(0)),
756 "Through edge (B)"); //The two APs are those making the edge
757
759 t3.setInnerGraph(g3);
760
761 assertTrue(t3.getAP(0).hasConnectedSrcAtom(t3.getAP(3)),
762 "Through edge intra-template (A)");
763 assertTrue(t3.getAP(0).hasConnectedSrcAtom(t3.getAP(1)),
764 "Through edge intra-template (B)");
765 assertFalse(t3.getAP(0).hasConnectedSrcAtom(t3.getAP(2)),
766 "Through edge intra-template (C)");
767 assertFalse(t3.getAP(0).hasConnectedSrcAtom(t3.getAP(4)),
768 "Through edge intra-template (D)");
769
770 Template t4 = t2.clone();
771 t4.setVertexId(t2.getVertexId()+1);
772 DGraph g5 = new DGraph();
773 g5.addVertex(t2);
774 g5.addVertex(t4);
775 g5.addEdge(new Edge(t2.getAP(1), t4.getAP(0)));
776
777 /*
778 * {
779 * ap0
780 * \
781 * a1---a2---a3 t2
782 * / \ \
783 * ap1 ap2 ap3
784 * }
785 * |
786 * {
787 * ap0
788 * \
789 * a1---a2---a3 t4
790 * / \ \
791 * ap1 ap2 ap3
792 * }
793 */
794
795 assertTrue(t2.getAP(0).hasConnectedSrcAtom(t4.getAP(1)),
796 "Through deep edge (A)"); // The two APs are not in the edge
797 assertFalse(t2.getAP(1).hasConnectedSrcAtom(t4.getAP(0)),
798 "Through deep edge (B)"); //The two APs are those making the edge
799 }
800
801//------------------------------------------------------------------------------
802
803}
General set of constants used in DENOPTIM.
static final String SEPARATORAPPROPAAP
Separator between atom index and APClass in molecular property.
BondType getBondType()
Definition: APClass.java:341
static final BondType DEFAULTBT
Default bond type for all but APClasses of RCVs.
Definition: APClass.java:109
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:136
Comparator for DENOPTIMAttachmentPoints.
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....
AttachmentPoint getLinkedAP()
Gets the attachment point (AP) that is connected to this AP via the edge user.
AttachmentPoint getEmbeddedAP()
For vertices that are templates this method returns the attachment point that is embedded in the temp...
void setAPClass(String apClass)
Set the Attachment Point class.
APClass getAPClass()
Returns the Attachment Point class.
void setDirectionVector(Point3d dirVec)
Sets the end of the 3D vector defining the direction of the AP in 3D.
int getID()
Returns a unique integer that is used to sort list of attachment points.
int getAtomPositionNumber()
The index of the source atom in the atom list of the fragment.
static Object[] processSdfString(String str)
Parses the string format used to record one attachment point in SDF files.
AttachmentPoint clone()
Returns a deep clone of this attachment point.
Point3d getDirectionVector()
Returns the end of the direction vector.
boolean hasConnectedSrcAtom(AttachmentPoint other)
Checks if this and another APs are rooted on atoms that are bonded in any way other than a possible c...
boolean isSrcInUser()
Checks the role of this AP in the user.
boolean sameAs(AttachmentPoint other)
Compares the features of this and another attachment point and decides if the two are same.
boolean hasSameSrcAtom(AttachmentPoint other)
String getSingleAPStringSDF(boolean isFirst, int srcAtmID)
Prepare a string for writing this AP in a fragment SDF file.
int compareTo(AttachmentPoint other)
Compares this and another attachment points based on their unique identifier.
Edge getEdgeUser()
Gets the edge that is using this AP, or null if no edge is using this AP.
String toStringNoId()
Produces a string with the information included in this object.
Unit test for DENOPTIMAttachmentPoint.
void checkGetEdgeUserThroughput(Vertex v, List< Vertex > onion)
void checkIdentityOfEmbeddedAP(int expectedMAtches, List< AttachmentPoint > deepAPs, Vertex v)
void checkAvailNT(int expN, int expNTm, int level, Vertex v)
Container for the list of vertices and the edges that connect them.
Definition: DGraph.java:102
Edge getEdgeAtPosition(int pos)
Definition: DGraph.java:2649
void addVertex(Vertex vertex)
Appends a vertex to this graph without creating any edge.
Definition: DGraph.java:1097
void appendVertexOnAP(AttachmentPoint srcAP, AttachmentPoint trgAP)
Append a vertex to this graph: adds the new vertex to the list of vertices belonging to the graph,...
Definition: DGraph.java:5776
void addEdge(Edge edge)
Adds the edge to the list of edges belonging to this graph.
Definition: DGraph.java:1021
This class represents the edge between two vertices.
Definition: Edge.java:38
AttachmentPoint getSrcAPThroughout()
Definition: Edge.java:101
AttachmentPoint getTrgAP()
Definition: Edge.java:115
AttachmentPoint getSrcAP()
Definition: Edge.java:94
AttachmentPoint getTrgAPThroughout()
Definition: Edge.java:108
An empty vertex has the behaviors of a vertex, but has no molecular structure.
EmptyVertex clone()
Returns a deep-copy of this vertex.
List< AttachmentPoint > getAttachmentPoints()
void addAP()
Adds an attachment point with no APClass or other attribute.
Class representing a continuously connected portion of chemical object holding attachment points.
Definition: Fragment.java:61
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
List< AttachmentPoint > getAttachmentPoints()
Definition: Fragment.java:1120
Fragment clone()
Returns a deep copy of this fragments.
Definition: Fragment.java:733
void addAtom(IAtom atom)
Definition: Fragment.java:836
void setInnerGraph(DGraph innerGraph)
Definition: Template.java:298
Template clone()
Returns a deep copy of this template.
Definition: Template.java:243
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
Definition: Vertex.java:61
void setVertexId(long vertexId2)
Definition: Vertex.java:261
abstract List< AttachmentPoint > getAttachmentPoints()
AttachmentPoint getAP(int i)
Get attachment point i on this vertex.
Definition: Vertex.java:920
Possible chemical bond types an edge can represent.
Definition: Edge.java:303
The type of building block.
Definition: Vertex.java:86