$darkmode
DENOPTIM
DGraphTest.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2022 Marco Foscato <marco.foscato@uib.no>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package denoptim.graph;
20
21import static org.junit.Assert.assertNotNull;
22import static org.junit.jupiter.api.Assertions.assertEquals;
23import static org.junit.jupiter.api.Assertions.assertFalse;
24import static org.junit.jupiter.api.Assertions.assertNotEquals;
25import static org.junit.jupiter.api.Assertions.assertNull;
26import static org.junit.jupiter.api.Assertions.assertTrue;
27
28import java.util.ArrayList;
29import java.util.Arrays;
30import java.util.HashMap;
31import java.util.HashSet;
32import java.util.Iterator;
33import java.util.LinkedHashMap;
34import java.util.List;
35import java.util.Map;
36import java.util.Set;
37import java.util.concurrent.atomic.AtomicInteger;
38import java.util.logging.Logger;
39import java.util.stream.Collectors;
40
41import javax.vecmath.Point3d;
42
43import org.junit.jupiter.api.Test;
44import org.openscience.cdk.Atom;
45import org.openscience.cdk.Bond;
46import org.openscience.cdk.PseudoAtom;
47import org.openscience.cdk.interfaces.IAtom;
48import org.openscience.cdk.interfaces.IAtomContainer;
49import org.openscience.cdk.interfaces.IBond;
50import org.openscience.cdk.interfaces.IChemObjectBuilder;
51import org.openscience.cdk.silent.SilentChemObjectBuilder;
52import org.openscience.cdk.smiles.SmilesParser;
53
54import denoptim.constants.DENOPTIMConstants;
55import denoptim.exception.DENOPTIMException;
56import denoptim.fragspace.FragmentSpace;
57import denoptim.fragspace.FragmentSpaceParameters;
58import denoptim.graph.Edge.BondType;
59import denoptim.graph.Template.ContractLevel;
60import denoptim.graph.Vertex.BBType;
61import denoptim.graph.Vertex.VertexType;
62import denoptim.graph.rings.PathSubGraph;
63import denoptim.utils.MutationType;
64
65
72public class DGraphTest
73{
74
75 private static APClass APCA, APCB, APCC, APCD, CAPP;
76 private static String a="A", b="B", c="C", d="D", cap="cap";
77
78
79//------------------------------------------------------------------------------
80
82 {
83 APCA = APClass.make(a, 0);
84 APCB = APClass.make(b, 0);
85 APCC = APClass.make(c, 0);
86 APCD = APClass.make(d, 99);
87 CAPP = APClass.make(cap, 1);
88
89 HashMap<APClass,ArrayList<APClass>> cpMap =
90 new HashMap<APClass,ArrayList<APClass>>();
91 ArrayList<APClass> lstA = new ArrayList<APClass>();
92 lstA.add(APCA);
93 cpMap.put(APCA, lstA);
94 ArrayList<APClass> lstB = new ArrayList<APClass>();
95 lstB.add(APCB);
96 lstB.add(APCC);
97 cpMap.put(APCB, lstB);
98 ArrayList<APClass> lstC = new ArrayList<APClass>();
99 lstC.add(APCB);
100 lstC.add(APCC);
101 cpMap.put(APCC, lstC);
102 ArrayList<APClass> lstD = new ArrayList<APClass>();
103 lstD.add(APCD);
104 cpMap.put(APCD, lstD);
105
106
107 /* Compatibility matrix
108 *
109 * | A | B | C | D |
110 * -------------------------
111 * A | T | | | |
112 * -------------------------
113 * B | | T | T | |
114 * -------------------------
115 * C | | T | T | |
116 * -------------------------
117 * D | | | | T |
118 */
119
120 HashMap<APClass,APClass> capMap = new HashMap<APClass,APClass>();
121 HashSet<APClass> forbEnds = new HashSet<APClass>();
123 FragmentSpace fs = new FragmentSpace(fsp,
124 new ArrayList<Vertex>(),
125 new ArrayList<Vertex>(),
126 new ArrayList<Vertex>(),
127 cpMap, capMap, forbEnds, cpMap);
129
130 EmptyVertex s0 = new EmptyVertex();
132 s0.addAP(APCA);
133 s0.addAP(APCA);
135
136 EmptyVertex s1 = new EmptyVertex();
138 s1.addAP(APCA);
139 s1.addAP(APCA);
140 s1.addAP(APCD);
142
143 EmptyVertex v0 = new EmptyVertex();
145 v0.addAP(APCA);
146 v0.addAP(APCB);
147 v0.addAP(APCA);
149
150 EmptyVertex v1 = new EmptyVertex();
152 v1.addAP(APCA);
153 v1.addAP(APCB);
154 v1.addAP(APCA);
155 v1.addAP(APCB);
156 v1.addAP(APCC);
158
159 EmptyVertex v2 = new EmptyVertex();
161 v2.addAP(APCB);
163
164 EmptyVertex v3 = new EmptyVertex();
166 v3.addAP(APCD);
167 v3.addAP(APCD);
169
170 EmptyVertex v4 = new EmptyVertex();
172 v4.addAP(APCC);
173 v4.addAP(APCB);
174 v4.addAP(APCB);
175 v4.addAP(APCA);
176 v4.addAP(APCA);
178
179 EmptyVertex v5 = new EmptyVertex();
181 v5.addAP(APCB);
182 v5.addAP(APCD);
184
185 EmptyVertex v6 = new EmptyVertex();
187 v6.addAP(APCC);
188 v6.addAP(APCD);
190
191 EmptyVertex v7 = new EmptyVertex();
193 v7.setAsRCV(true);
194 v7.addAP(APClass.make("ATneutral:0", BondType.ANY));
196
197 EmptyVertex c0 = new EmptyVertex();
199 c0.addAP(CAPP);
201
202 return fs;
203 }
204
205//------------------------------------------------------------------------------
206
234 throws DENOPTIMException
235 {
236 DGraph graph = new DGraph();
238 BBType.SCAFFOLD, fs);
239 graph.addVertex(s);
241 BBType.FRAGMENT, fs);
242 graph.addVertex(v1a);
244 BBType.FRAGMENT, fs);
245 graph.addVertex(v2a);
247 BBType.FRAGMENT, fs);
248 graph.addVertex(v2a_bis);
250 BBType.FRAGMENT, fs);
251 graph.addVertex(v3a);
253 BBType.FRAGMENT, fs);
254 graph.addVertex(v1b);
256 BBType.FRAGMENT, fs);
257 graph.addVertex(v2b);
259 BBType.FRAGMENT, fs);
260 graph.addVertex(v2b_bis);
262 BBType.FRAGMENT, fs);
263 graph.addVertex(v3b);
264 graph.addEdge(new Edge(s.getAP(0), v1a.getAP(0)));
265 graph.addEdge(new Edge(v1a.getAP(1), v2a.getAP(0)));
266 graph.addEdge(new Edge(v1a.getAP(3), v2a_bis.getAP(0)));
267 graph.addEdge(new Edge(v1a.getAP(4), v3a.getAP(0)));
268 graph.addEdge(new Edge(s.getAP(1), v1b.getAP(0)));
269 graph.addEdge(new Edge(v1b.getAP(1), v2b.getAP(0)));
270 graph.addEdge(new Edge(v1b.getAP(3), v2b_bis.getAP(0)));
271 graph.addEdge(new Edge(v1b.getAP(4), v3b.getAP(0)));
272
273 List<Vertex> symA = new ArrayList<Vertex>();
274 symA.add(v1a);
275 symA.add(v1b);
277
278 List<Vertex> symB = new ArrayList<Vertex>();
279 symB.add(v2a);
280 symB.add(v2a_bis);
281 symB.add(v2b);
282 symB.add(v2b_bis);
284
285 graph.renumberGraphVertices();
286 return graph;
287 }
288
289//------------------------------------------------------------------------------
290
310 throws DENOPTIMException
311 {
312 DGraph graph = new DGraph();
314 BBType.SCAFFOLD, fs);
315 graph.addVertex(s);
317 BBType.FRAGMENT, fs);
318 graph.appendVertexOnAP(s.getAP(0), v1a.getAP(2));
320 BBType.FRAGMENT, fs);
321 graph.appendVertexOnAP(v1a.getAP(3), v2a.getAP(1));
323 BBType.FRAGMENT, fs);
324 graph.appendVertexOnAP(v2a.getAP(3), v3a.getAP(1));
326 BBType.FRAGMENT, fs);
327 graph.appendVertexOnAP(v3a.getAP(3), v4a.getAP(1));
329 BBType.FRAGMENT, fs);
330 graph.appendVertexOnAP(v2a.getAP(2), v5a.getAP(0));
331
333 BBType.FRAGMENT, fs);
334 graph.appendVertexOnAP(s.getAP(1), v1b.getAP(2));
336 BBType.FRAGMENT, fs);
337 graph.appendVertexOnAP(v1b.getAP(3), v2b.getAP(1));
339 BBType.FRAGMENT, fs);
340 graph.appendVertexOnAP(v2b.getAP(3), v3b.getAP(1));
342 BBType.FRAGMENT, fs);
343 graph.appendVertexOnAP(v3b.getAP(3), v4b.getAP(1));
345 BBType.FRAGMENT, fs);
346 graph.appendVertexOnAP(v2b.getAP(2), v5b.getAP(0));
347
348 List<Vertex> sym1 = new ArrayList<Vertex>();
349 sym1.add(v1a);
350 sym1.add(v1b);
352 List<Vertex> sym2 = new ArrayList<Vertex>();
353 sym2.add(v2a);
354 sym2.add(v2b);
356 List<Vertex> sym3 = new ArrayList<Vertex>();
357 sym3.add(v3a);
358 sym3.add(v3b);
360 List<Vertex> sym4 = new ArrayList<Vertex>();
361 sym4.add(v4a);
362 sym4.add(v4b);
364
365 graph.renumberGraphVertices();
366 return graph;
367 }
368
369//------------------------------------------------------------------------------
370
406 throws DENOPTIMException
407 {
408 DGraph graph = new DGraph();
410 BBType.SCAFFOLD, fs);
411 graph.addVertex(s);
413 BBType.FRAGMENT, fs);
414 graph.addVertex(v1a);
416 BBType.FRAGMENT, fs);
417 graph.addVertex(v6a);
419 BBType.FRAGMENT, fs);
420 graph.addVertex(v6a_bis);
422 BBType.FRAGMENT, fs);
423 graph.addVertex(v6a_tris);
425 BBType.FRAGMENT, fs);
426 graph.addVertex(v7a);
428 BBType.FRAGMENT, fs);
429 graph.addVertex(v7a_bis);
431 BBType.FRAGMENT, fs);
432 graph.addVertex(v7a_tris);
433
435 BBType.FRAGMENT, fs);
436 graph.addVertex(v7a_quat);
437
439 BBType.FRAGMENT, fs);
440 graph.addVertex(v1c);
441
443 BBType.FRAGMENT, fs);
444 graph.addVertex(v1b);
446 BBType.FRAGMENT, fs);
447 graph.addVertex(v2b);
449 BBType.FRAGMENT, fs);
450 graph.addVertex(v2b_bis);
452 BBType.FRAGMENT, fs);
453 graph.addVertex(v3b);
454 graph.addEdge(new Edge(s.getAP(0), v1a.getAP(0)));
455 graph.addEdge(new Edge(v1a.getAP(1), v6a.getAP(0)));
456 graph.addEdge(new Edge(v1a.getAP(3), v6a_bis.getAP(0)));
457 graph.addEdge(new Edge(v1a.getAP(4), v6a_tris.getAP(0)));
458 graph.addEdge(new Edge(v6a.getAP(1), v7a.getAP(0)));
459 graph.addEdge(new Edge(v6a_bis.getAP(1), v7a_bis.getAP(0)));
460 graph.addEdge(new Edge(v6a_tris.getAP(1), v7a_tris.getAP(0)));
461 graph.addEdge(new Edge(s.getAP(2), v7a_quat.getAP(0)));
462 graph.addEdge(new Edge(s.getAP(1), v1c.getAP(0)));
463 graph.addEdge(new Edge(v1c.getAP(2), v1b.getAP(0)));
464 graph.addEdge(new Edge(v1b.getAP(1), v2b.getAP(0)));
465 graph.addEdge(new Edge(v1b.getAP(3), v2b_bis.getAP(0)));
466 graph.addEdge(new Edge(v1b.getAP(4), v3b.getAP(0)));
467
468 graph.addRing(v7a, v7a_quat);
469 graph.addRing(v7a_bis, v7a_tris);
470
471 List<Vertex> symA = new ArrayList<Vertex>();
472 symA.add(v1a);
473 symA.add(v1c);
475
476 List<Vertex> symB = new ArrayList<Vertex>();
477 symB.add(v2b);
478 symB.add(v2b_bis);
480
481 graph.renumberGraphVertices();
482 return graph;
483 }
484
485//------------------------------------------------------------------------------
486
502 throws DENOPTIMException
503 {
504 DGraph graph = new DGraph();
506 BBType.FRAGMENT, fs);
507 graph.addVertex(v1a);
509 BBType.FRAGMENT, fs);
510 graph.addVertex(v6a);
512 BBType.FRAGMENT, fs);
513 graph.addVertex(v6a_bis);
515 BBType.FRAGMENT, fs);
516 graph.addVertex(v6a_tris);
518 BBType.FRAGMENT, fs);
519 graph.addVertex(v7a);
521 BBType.FRAGMENT, fs);
522 graph.addVertex(v7a_bis);
524 BBType.FRAGMENT, fs);
525 graph.addVertex(v7a_tris);
526
527 graph.addEdge(new Edge(v1a.getAP(1), v6a.getAP(0)));
528 graph.addEdge(new Edge(v1a.getAP(3), v6a_bis.getAP(0)));
529 graph.addEdge(new Edge(v1a.getAP(4), v6a_tris.getAP(0)));
530 graph.addEdge(new Edge(v6a.getAP(1), v7a.getAP(0)));
531 graph.addEdge(new Edge(v6a_bis.getAP(1), v7a_bis.getAP(0)));
532 graph.addEdge(new Edge(v6a_tris.getAP(1), v7a_tris.getAP(0)));
533
534 graph.addRing(v7a_bis, v7a_tris);
535
536 graph.renumberGraphVertices();
537 return graph;
538 }
539
540//------------------------------------------------------------------------------
541
557 throws DENOPTIMException
558 {
559 DGraph graph = new DGraph();
561 BBType.FRAGMENT, fs);
562 graph.addVertex(v1b);
564 BBType.FRAGMENT, fs);
565 graph.addVertex(v2b);
567 BBType.FRAGMENT, fs);
568 graph.addVertex(v2b_bis);
570 BBType.FRAGMENT, fs);
571 graph.addVertex(v3b);
572 graph.addEdge(new Edge(v1b.getAP(1), v2b.getAP(0)));
573 graph.addEdge(new Edge(v1b.getAP(3), v2b_bis.getAP(0)));
574 graph.addEdge(new Edge(v1b.getAP(4), v3b.getAP(0)));
575
576 List<Vertex> symB = new ArrayList<Vertex>();
577 symB.add(v2b);
578 symB.add(v2b_bis);
580
581 graph.renumberGraphVertices();
582 return graph;
583 }
584
585//------------------------------------------------------------------------------
586
606 throws DENOPTIMException
607 {
608 DGraph graph = new DGraph();
610 BBType.FRAGMENT, fs);
611 graph.addVertex(v1b);
612 //First layer
614 BBType.FRAGMENT, fs);
615 graph.addVertex(v2b);
617 BBType.FRAGMENT, fs);
618 graph.addVertex(v2b_bis);
620 BBType.FRAGMENT, fs);
621 graph.addVertex(v2b_tris);
622 graph.addEdge(new Edge(v1b.getAP(1), v2b.getAP(2)));
623 graph.addEdge(new Edge(v1b.getAP(3), v2b_bis.getAP(2)));
624 graph.addEdge(new Edge(v1b.getAP(4), v2b_tris.getAP(2)));
625 //Second layer
627 BBType.FRAGMENT, fs);
628 graph.addVertex(v3b_1);
630 BBType.FRAGMENT, fs);
631 graph.addVertex(v3b_2);
633 BBType.FRAGMENT, fs);
634 graph.addVertex(v3b_3);
636 BBType.FRAGMENT, fs);
637 graph.addVertex(v3b_4);
638 graph.addEdge(new Edge(v2b.getAP(1), v3b_1.getAP(2)));
639 graph.addEdge(new Edge(v2b.getAP(3), v3b_2.getAP(2)));
640 graph.addEdge(new Edge(v2b_bis.getAP(1), v3b_3.getAP(2)));
641 graph.addEdge(new Edge(v2b_bis.getAP(3), v3b_4.getAP(2)));
642
643 List<Vertex> symFirstLayer = new ArrayList<Vertex>();
644 symFirstLayer.add(v2b);
645 symFirstLayer.add(v2b_bis);
646 graph.addSymmetricSetOfVertices(new SymmetricVertexes(symFirstLayer));
647
648 List<Vertex> symSecondLayer = new ArrayList<Vertex>();
649 symSecondLayer.add(v3b_1);
650 symSecondLayer.add(v3b_2);
651 graph.addSymmetricSetOfVertices(new SymmetricVertexes(symSecondLayer));
652
653 graph.renumberGraphVertices();
654 return graph;
655 }
656
657//------------------------------------------------------------------------------
658
684 throws DENOPTIMException
685 {
686 DGraph graph = new DGraph();
688 BBType.FRAGMENT, fs);
689 graph.addVertex(v1a);
691 BBType.FRAGMENT, fs);
692 graph.addVertex(v6a);
694 BBType.FRAGMENT, fs);
695 graph.addVertex(v6a_bis);
697 BBType.FRAGMENT, fs);
698 graph.addVertex(v7a);
700 BBType.FRAGMENT, fs);
701 graph.addVertex(v7a_bis);
702
704 BBType.FRAGMENT, fs);
705 graph.addVertex(v1b);
707 BBType.FRAGMENT, fs);
708 graph.addVertex(v1c);
710 BBType.FRAGMENT, fs);
711 graph.addVertex(v6a_tris);
712 graph.addEdge(new Edge(v1a.getAP(1), v6a.getAP(0)));
713 graph.addEdge(new Edge(v1a.getAP(4), v6a_bis.getAP(0)));
714 graph.addEdge(new Edge(v6a.getAP(1), v7a.getAP(0)));
715 graph.addEdge(new Edge(v6a_bis.getAP(1), v7a_bis.getAP(0)));
716 graph.addEdge(new Edge(v1a.getAP(3), v1b.getAP(1)));
717 graph.addEdge(new Edge(v1b.getAP(2), v1c.getAP(0)));
718 graph.addEdge(new Edge(v1b.getAP(4), v6a_tris.getAP(0)));
719
720 graph.addRing(v7a, v7a_bis);
721
722 List<Vertex> symA = new ArrayList<Vertex>();
723 symA.add(v6a);
724 symA.add(v6a_bis);
726
727 List<Vertex> symB = new ArrayList<Vertex>();
728 symB.add(v7a);
729 symB.add(v7a_bis);
731
732 graph.renumberGraphVertices();
733 return graph;
734 }
735
736//------------------------------------------------------------------------------
737
781 throws DENOPTIMException
782 {
783 DGraph graph = new DGraph();
785 BBType.FRAGMENT, fs);
786 graph.addVertex(v1a);
788 BBType.FRAGMENT, fs);
789 graph.addVertex(v6a);
791 BBType.FRAGMENT, fs);
792 graph.addVertex(v6a_bis);
794 BBType.FRAGMENT, fs);
795 graph.addVertex(v7a);
797 BBType.FRAGMENT, fs);
798 graph.addVertex(v7a_bis);
799
801 BBType.FRAGMENT, fs);
802 graph.addVertex(v1b);
804 BBType.FRAGMENT, fs);
805 graph.addVertex(v1c);
807 BBType.FRAGMENT, fs);
808 graph.addVertex(v6a_tris);
809
810 graph.addEdge(new Edge(v1a.getAP(1), v6a.getAP(0)));
811 graph.addEdge(new Edge(v1a.getAP(4), v6a_bis.getAP(0)));
812 graph.addEdge(new Edge(v6a.getAP(1), v7a.getAP(0)));
813 graph.addEdge(new Edge(v6a_bis.getAP(1), v7a_bis.getAP(0)));
814 graph.addEdge(new Edge(v1a.getAP(3), v1b.getAP(1)));
815 graph.addEdge(new Edge(v1b.getAP(2), v1c.getAP(0)));
816 graph.addEdge(new Edge(v1b.getAP(4), v6a_tris.getAP(0)));
817
818 graph.addRing(v7a, v7a_bis);
819
820 List<Vertex> symA = new ArrayList<Vertex>();
821 symA.add(v6a);
822 symA.add(v6a_bis);
824
825 List<Vertex> symB = new ArrayList<Vertex>();
826 symB.add(v7a);
827 symB.add(v7a_bis);
829
830 // up to here it is graph F. Now come the pieces of graph D
831
833 BBType.FRAGMENT, fs);
834 graph.addVertex(v6a_d);
835 Vertex v6a_d_bis = Vertex.newVertexFromLibrary(6,
836 BBType.FRAGMENT, fs);
837 graph.addVertex(v6a_d_bis);
838 Vertex v6a_d_tris = Vertex.newVertexFromLibrary(6,
839 BBType.FRAGMENT, fs);
840 graph.addVertex(v6a_d_tris);
842 BBType.FRAGMENT, fs);
843 graph.addVertex(v7a_d);
844 Vertex v7a_d_bis = Vertex.newVertexFromLibrary(7,
845 BBType.FRAGMENT, fs);
846 graph.addVertex(v7a_d_bis);
847 Vertex v7a_d_tris = Vertex.newVertexFromLibrary(7,
848 BBType.FRAGMENT, fs);
849 graph.addVertex(v7a_d_tris);
850
851 Vertex v7a_d_quat = Vertex.newVertexFromLibrary(7,
852 BBType.FRAGMENT, fs);
853 graph.addVertex(v7a_d_quat);
854
856 BBType.FRAGMENT, fs);
857 graph.addVertex(v1c_d);
858
860 BBType.FRAGMENT, fs);
861 graph.addVertex(v1b_d);
863 BBType.FRAGMENT, fs);
864 graph.addVertex(v2b_d);
865 Vertex v2b_d_bis = Vertex.newVertexFromLibrary(2,
866 BBType.FRAGMENT, fs);
867 graph.addVertex(v2b_d_bis);
869 BBType.FRAGMENT, fs);
870 graph.addVertex(v3b_d);
871 graph.addEdge(new Edge(v1c.getAP(2), v6a_d.getAP(0)));
872 graph.addEdge(new Edge(v1b.getAP(3), v6a_d_bis.getAP(0)));
873 graph.addEdge(new Edge(v1c.getAP(4), v6a_d_tris.getAP(0)));
874 graph.addEdge(new Edge(v6a_d.getAP(1), v7a_d.getAP(0)));
875 graph.addEdge(new Edge(v6a_d_bis.getAP(1), v7a_d_bis.getAP(0)));
876 graph.addEdge(new Edge(v6a_d_tris.getAP(1), v7a_d_tris.getAP(0)));
877 graph.addEdge(new Edge(v6a_tris.getAP(1), v7a_d_quat.getAP(0)));
878 graph.addEdge(new Edge(v1a.getAP(2), v1c_d.getAP(0)));
879 graph.addEdge(new Edge(v1c_d.getAP(2), v1b_d.getAP(0)));
880 graph.addEdge(new Edge(v1b_d.getAP(1), v2b_d.getAP(0)));
881 graph.addEdge(new Edge(v1b_d.getAP(3), v2b_d_bis.getAP(0)));
882 graph.addEdge(new Edge(v1b_d.getAP(4), v3b_d.getAP(0)));
883
884 graph.addRing(v7a_d, v7a_d_quat);
885 graph.addRing(v7a_d_bis, v7a_d_tris);
886
887 List<Vertex> symC = new ArrayList<Vertex>();
888 symC.add(v2b_d);
889 symC.add(v2b_d_bis);
890
892 return graph;
893 }
894
895//------------------------------------------------------------------------------
896
914 throws DENOPTIMException
915 {
916 DGraph graph = new DGraph();
918 BBType.FRAGMENT, fs);
919 graph.addVertex(v1a);
921 BBType.FRAGMENT, fs);
922 graph.addVertex(v6a_bis);
924 BBType.FRAGMENT, fs);
925 graph.addVertex(v6a_tris);
927 BBType.FRAGMENT, fs);
928 graph.addVertex(v7a_bis);
930 BBType.FRAGMENT, fs);
931 graph.addVertex(v7a_tris);
932
933 graph.addEdge(new Edge(v1a.getAP(3), v6a_bis.getAP(0)));
934 graph.addEdge(new Edge(v1a.getAP(4), v6a_tris.getAP(0)));
935 graph.addEdge(new Edge(v6a_bis.getAP(1), v7a_bis.getAP(0)));
936 graph.addEdge(new Edge(v6a_tris.getAP(1), v7a_tris.getAP(0)));
937
938 graph.addRing(v7a_bis, v7a_tris);
939
940 graph.renumberGraphVertices();
941 return graph;
942 }
943
944//------------------------------------------------------------------------------
945
961 throws Exception
962 {
963 DGraph innerGraph = makeTestGraphH(fs);
964 Template tmpl = new Template(BBType.FRAGMENT);
965 tmpl.setInnerGraph(innerGraph);
966
967 DGraph graph = new DGraph();
968 graph.addVertex(tmpl);
970 BBType.FRAGMENT, fs);
971 graph.addVertex(v6);
973 BBType.FRAGMENT, fs);
974 graph.addVertex(v7);
976 BBType.FRAGMENT, fs);
977 graph.addVertex(v6a);
979 BBType.FRAGMENT, fs);
980 graph.addVertex(v7a);
981
982 graph.addEdge(new Edge(tmpl.getAP(0), v6.getAP(0)));
983 graph.addEdge(new Edge(v6.getAP(1), v7.getAP(0)));
984 graph.addEdge(new Edge(tmpl.getAP(1), v6a.getAP(0)));
985 graph.addEdge(new Edge(v6a.getAP(1), v7a.getAP(0)));
986
987 graph.addRing(v7, v7a);
988
989 graph.renumberGraphVertices();
990 return graph;
991 }
992
993//------------------------------------------------------------------------------
994
1012 throws DENOPTIMException
1013 {
1014 DGraph graph = new DGraph();
1016 BBType.FRAGMENT, fs);
1017 graph.addVertex(v1);
1019 BBType.FRAGMENT, fs);
1020 graph.addVertex(v1b);
1021 graph.addEdge(new Edge(v1.getAP(0), v1b.getAP(2)));
1022 graph.renumberGraphVertices();
1023 return graph;
1024 }
1025
1026//------------------------------------------------------------------------------
1027
1043 throws DENOPTIMException
1044 {
1045 DGraph graph = new DGraph();
1047 BBType.FRAGMENT, fs);
1048 graph.addVertex(v1a);
1050 BBType.FRAGMENT, fs);
1051 graph.addVertex(v6a);
1053 BBType.FRAGMENT, fs);
1054 graph.addVertex(v6a_bis);
1055 Vertex v6a_tris = Vertex.newVertexFromLibrary(6,
1056 BBType.FRAGMENT, fs);
1057 graph.addVertex(v6a_tris);
1058
1060 BBType.FRAGMENT, fs);
1061 graph.addVertex(v1a_2);
1062 Vertex v1a_2_bis = Vertex.newVertexFromLibrary(1,
1063 BBType.FRAGMENT, fs);
1064 graph.addVertex(v1a_2_bis);
1065 Vertex v1a_2_tris = Vertex.newVertexFromLibrary(1,
1066 BBType.FRAGMENT, fs);
1067 graph.addVertex(v1a_2_tris);
1068
1069 List<Vertex> vToCap = new ArrayList<Vertex>();
1070 vToCap.add(v1a);
1071 vToCap.add(v1a_2);
1072 vToCap.add(v1a_2_bis);
1073 vToCap.add(v1a_2_tris);
1074 for (Vertex v : vToCap)
1075 {
1076 for (AttachmentPoint ap : v.getAttachmentPoints())
1077 {
1078 if (ap.isAvailable())
1079 {
1081 BBType.CAP, fs);
1082 graph.appendVertexOnAP(ap, cap.getAP(0));
1083 }
1084 }
1085 }
1086
1087 graph.addEdge(new Edge(v1a.getAP(1), v6a.getAP(0)));
1088 graph.addEdge(new Edge(v1a.getAP(3), v6a_bis.getAP(0)));
1089 graph.addEdge(new Edge(v1a.getAP(4), v6a_tris.getAP(0)));
1090 graph.addEdge(new Edge(v6a.getAP(1), v1a_2.getAP(1)));
1091 graph.addEdge(new Edge(v6a_bis.getAP(1), v1a_2_bis.getAP(1)));
1092 graph.addEdge(new Edge(v6a_tris.getAP(1), v1a_2_tris.getAP(1)));
1093
1094 List<Vertex> symA = new ArrayList<Vertex>();
1095 symA.add(v6a);
1096 symA.add(v6a_bis);
1098
1099 List<Vertex> symB = new ArrayList<Vertex>();
1100 symB.add(v1a_2);
1101 symB.add(v1a_2_bis);
1103
1104 graph.renumberGraphVertices();
1105 return graph;
1106 }
1107
1108//------------------------------------------------------------------------------
1109
1151 throws DENOPTIMException
1152 {
1153 DGraph graph = new DGraph();
1155 BBType.SCAFFOLD, fs);
1156 graph.addVertex(s);
1158 BBType.FRAGMENT, fs);
1159 graph.addVertex(v1a);
1161 BBType.FRAGMENT, fs);
1162 graph.addVertex(v6a);
1164 BBType.FRAGMENT, fs);
1165 graph.addVertex(v6a_bis);
1166 Vertex v6a_tris = Vertex.newVertexFromLibrary(6,
1167 BBType.FRAGMENT, fs);
1168 graph.addVertex(v6a_tris);
1170 BBType.FRAGMENT, fs);
1171 graph.addVertex(v7a);
1173 BBType.FRAGMENT, fs);
1174 graph.addVertex(v7a_bis);
1175 Vertex v7a_tris = Vertex.newVertexFromLibrary(7,
1176 BBType.FRAGMENT, fs);
1177 graph.addVertex(v7a_tris);
1178
1179 Vertex v7a_quat = Vertex.newVertexFromLibrary(7,
1180 BBType.FRAGMENT, fs);
1181 graph.addVertex(v7a_quat);
1182
1184 BBType.FRAGMENT, fs);
1185 graph.addVertex(v1d);
1186
1188 BBType.FRAGMENT, fs);
1189 graph.addVertex(v1c);
1190
1192 BBType.FRAGMENT, fs);
1193 graph.addVertex(v1b);
1195 BBType.FRAGMENT, fs);
1196 graph.addVertex(v2b);
1198 BBType.FRAGMENT, fs);
1199 graph.addVertex(v2b_bis);
1201 BBType.FRAGMENT, fs);
1202 graph.addVertex(v3b);
1203 graph.addEdge(new Edge(s.getAP(0), v1d.getAP(0)));
1204 graph.addEdge(new Edge(v1d.getAP(2), v1a.getAP(0)));
1205 graph.addEdge(new Edge(v1d.getAP(1), v6a.getAP(0)));
1206 graph.addEdge(new Edge(v1a.getAP(3), v6a_bis.getAP(0)));
1207 graph.addEdge(new Edge(v1a.getAP(4), v6a_tris.getAP(0)));
1208 graph.addEdge(new Edge(v6a.getAP(1), v7a.getAP(0)));
1209 graph.addEdge(new Edge(v6a_bis.getAP(1), v7a_bis.getAP(0)));
1210 graph.addEdge(new Edge(v6a_tris.getAP(1), v7a_tris.getAP(0)));
1211 graph.addEdge(new Edge(s.getAP(2), v7a_quat.getAP(0)));
1212 graph.addEdge(new Edge(s.getAP(1), v1c.getAP(0)));
1213 graph.addEdge(new Edge(v1c.getAP(2), v1b.getAP(0)));
1214 graph.addEdge(new Edge(v1b.getAP(1), v2b.getAP(0)));
1215 graph.addEdge(new Edge(v1b.getAP(3), v2b_bis.getAP(0)));
1216 graph.addEdge(new Edge(v1b.getAP(4), v3b.getAP(0)));
1217
1218 graph.addRing(v7a, v7a_quat);
1219 graph.addRing(v7a_bis, v7a_tris);
1220
1221 List<Vertex> symA = new ArrayList<Vertex>();
1222 symA.add(v6a_bis);
1223 symA.add(v6a_tris);
1225
1226 List<Vertex> symB = new ArrayList<Vertex>();
1227 symB.add(v7a_bis);
1228 symB.add(v7a_tris);
1230
1231 graph.renumberGraphVertices();
1232 return graph;
1233 }
1234
1235//------------------------------------------------------------------------------
1236
1249 throws DENOPTIMException
1250 {
1251 DGraph graph = new DGraph();
1253 BBType.FRAGMENT, fs);
1254 graph.addVertex(v1);
1256 BBType.FRAGMENT, fs);
1257 graph.addVertex(v2);
1259 BBType.FRAGMENT, fs);
1260 graph.addVertex(v3);
1262 BBType.FRAGMENT, fs);
1263 graph.addVertex(v4);
1265 BBType.FRAGMENT, fs);
1266 graph.addVertex(v5);
1267
1268 graph.addEdge(new Edge(v4.getAP(0), v1.getAP(0)));
1269 graph.addEdge(new Edge(v3.getAP(1), v4.getAP(1)));
1270 graph.addEdge(new Edge(v5.getAP(0), v3.getAP(0)));
1271 graph.addEdge(new Edge(v1.getAP(1), v2.getAP(0)));
1272 return graph;
1273 }
1274
1275//------------------------------------------------------------------------------
1276
1283 {
1284 EmptyVertex vOut = new EmptyVertex(0);
1285 vOut.addAP(APCA);
1286
1287 DGraph gOut = new DGraph();
1288 gOut.addVertex(vOut);
1289
1290 DGraph refToPrevGraph = gOut;
1291 Vertex refToPRevVrtx = vOut;
1292 for (int embeddingLevel=0; embeddingLevel<10; embeddingLevel++)
1293 {
1294 EmptyVertex v0 = new EmptyVertex(0+100*embeddingLevel);
1295 v0.addAP(APCA);
1296 v0.addAP(APCB);
1297 v0.addAP(APCC);
1298 EmptyVertex v1 = new EmptyVertex(1+100*embeddingLevel);
1299 v1.addAP(APCB);
1300 v1.addAP(APCA);
1301 v1.addAP(APCD);
1302 EmptyVertex v2 = new EmptyVertex(2+100*embeddingLevel);
1303 v2.addAP(APCB);
1304 DGraph g = new DGraph();
1305 g.addVertex(v0);
1306 g.appendVertexOnAP(v0.getAP(1), v1.getAP(0));
1307 g.appendVertexOnAP(v1.getAP(1), v2.getAP(0));
1309 t.setInnerGraph(g);
1310
1311 refToPrevGraph.appendVertexOnAP(refToPRevVrtx.getAP(0), t.getAP(1));
1312
1313 refToPrevGraph = g;
1314 refToPRevVrtx = v0;
1315 }
1316 return gOut;
1317 }
1318
1319//------------------------------------------------------------------------------
1320
1321 @Test
1322 public void testRemoveUnusedRCVs() throws Exception
1323 {
1324 APClass a0 = APClass.make("a",0,BondType.SINGLE);
1325 APClass b0 = APClass.make("b",0,BondType.SINGLE);
1326 APClass h0 = APClass.make("h",0,BondType.SINGLE);
1329
1330 HashMap<APClass,ArrayList<APClass>> cpMap =
1331 new HashMap<APClass,ArrayList<APClass>>();
1332 cpMap.put(a0, new ArrayList<APClass>(Arrays.asList(a0, b0)));
1333 HashMap<APClass,APClass> capMap = new HashMap<APClass,APClass>();
1334 capMap.put(a0, h0);
1335 HashSet<APClass> forbEnds = new HashSet<APClass>();
1336 forbEnds.add(b0);
1337
1338 Fragment frg1 = new Fragment();
1339 IAtom a1 = new Atom("C", new Point3d(new double[]{0.0, 0.0, 0.0}));
1340 IAtom a2 = new Atom("C", new Point3d(new double[]{1.0, 0.0, 0.0}));
1341 frg1.addAtom(a1);
1342 frg1.addAtom(a2);
1343 frg1.addBond(new Bond(a1, a2));
1344 frg1.addAP(0, a0, new Point3d(new double[]{0.0, 0.0, 1.0}));
1345 frg1.addAP(1, a0, new Point3d(new double[]{1.0, 1.0, 1.0}));
1346 frg1.projectAPsToProperties();
1347
1348 Fragment frg2 = new Fragment();
1349 IAtom a3 = new Atom("C", new Point3d(new double[]{0.0, 0.0, 0.0}));
1350 frg2.addAtom(a3);
1351 frg2.addAP(0, a0, new Point3d(new double[]{0.0, 1.0, 1.0}));
1352 frg2.addAP(0, b0, new Point3d(new double[]{0.0, 1.0, -1.0}));
1353 frg2.projectAPsToProperties();
1354
1355 Fragment rca1 = new Fragment();
1356 IAtom a4 = new PseudoAtom("ATP", new Point3d(
1357 new double[]{0.0, 0.0, 0.0}));
1358 rca1.addAtom(a4);
1359 rca1.addAP(0, ap0, new Point3d(new double[]{0.0, 1.0, 1.0}));
1360 rca1.projectAPsToProperties();
1361
1362 Fragment rca2 = new Fragment();
1363 IAtom a5 = new PseudoAtom("ATM", new Point3d(
1364 new double[]{1.0, 0.0, 0.0}));
1365 rca2.addAtom(a5);
1366 rca2.addAP(0, am0, new Point3d(new double[]{0.0, 1.0, 1.0}));
1367 rca2.projectAPsToProperties();
1368
1369 Fragment cap = new Fragment();
1370 IAtom a6 = new Atom("H", new Point3d(new double[]{0.0, 0.0, 0.0}));
1371 cap.addAtom(a6);
1372 cap.addAP(0, h0, new Point3d(new double[]{0.0, 1.0, 1.0}));
1373 cap.projectAPsToProperties();
1374
1375 ArrayList<Vertex> scaff = new ArrayList<Vertex>();
1376 scaff.add(frg1);
1377 ArrayList<Vertex> frags = new ArrayList<Vertex>();
1378 frags.add(frg2);
1379 frags.add(rca1);
1380 frags.add(rca2);
1381 ArrayList<Vertex> caps = new ArrayList<Vertex>();
1382 caps.add(cap);
1383
1385 FragmentSpace fs = new FragmentSpace(fsp, scaff, frags, caps,
1386 cpMap, capMap, forbEnds, cpMap);
1387 fs.setAPclassBasedApproach(true);
1388
1389 DGraph dg = new DGraph();
1394 dg.addVertex(v1);
1395 dg.addVertex(v2);
1396 dg.addVertex(v3);
1397 dg.addVertex(v4);
1398
1399 Edge e1 = new Edge(v1.getAP(1), v2.getAP(0), BondType.SINGLE);
1400 Edge e2 = new Edge(v2.getAP(1), v3.getAP(0), BondType.SINGLE);
1401 Edge e3 = new Edge(v1.getAP(0), v4.getAP(0), BondType.SINGLE);
1402 dg.addEdge(e1);
1403 dg.addEdge(e2);
1404 dg.addEdge(e3);
1405
1406 dg.addRing(v3, v4);
1407
1409
1410 assertEquals(4, dg.getVertexCount(),
1411 "Number of vertexes after removal of 0 unused RCVs.");
1412 assertEquals(3, dg.getEdgeCount(),
1413 "Number of edges after removal of 0 unused RCVs.");
1414
1415 DGraph acyclicGraph = new DGraph();
1420 acyclicGraph.addVertex(v1b);
1421 acyclicGraph.addVertex(v2b);
1422 acyclicGraph.addVertex(v3b);
1423 acyclicGraph.addVertex(v4b);
1424
1425 Edge e1b = new Edge(v1b.getAP(1), v2b.getAP(0), BondType.SINGLE);
1426 Edge e2b = new Edge(v2b.getAP(1), v3b.getAP(0), BondType.SINGLE);
1427 Edge e3b = new Edge(v1b.getAP(0), v4b.getAP(0), BondType.SINGLE);
1428 acyclicGraph.addEdge(e1b);
1429 acyclicGraph.addEdge(e2b);
1430 acyclicGraph.addEdge(e3b);
1431
1432 acyclicGraph.replaceUnusedRCVsWithCapps(fs);
1433
1434 assertEquals(0, acyclicGraph.getRCVertices().size(),
1435 "Number of RCVs after removal of 2 unused RCVs.");
1436 assertEquals(3, acyclicGraph.getVertexCount(),
1437 "Number of vertexes after removal of 2 unused RCVs.");
1438 assertEquals(2, acyclicGraph.getEdgeCount(),
1439 "Number of edges after removal of 2 unused RCVs.");
1440 }
1441
1442//------------------------------------------------------------------------------
1443
1444 @Test
1445 public void testGetEmbeddingPath() throws Exception
1446 {
1447 prepare();
1449
1450 List<Template> expected = new ArrayList<Template>();
1451 DGraph refToThisLayerGraph = gOut;
1452 Template refToThisLayerVrtx = null;
1453 for (int embeddingLevel=0; embeddingLevel<10; embeddingLevel++)
1454 {
1455 refToThisLayerVrtx = (Template) refToThisLayerGraph
1456 .getVertexList().stream()
1457 .filter(v -> v instanceof Template)
1458 .findAny()
1459 .orElse(null);
1460 expected.add(refToThisLayerVrtx);
1461 refToThisLayerGraph = refToThisLayerVrtx.getInnerGraph();
1462 }
1463
1464 assertEquals(new ArrayList<Template>(),gOut.getEmbeddingPath(),
1465 "Embedding path of graph that is not embedded");
1466 List<Template> path = refToThisLayerGraph.getEmbeddingPath();
1467 assertEquals(expected, path, "Path of deepest embedded graph");
1468 }
1469
1470//------------------------------------------------------------------------------
1471
1472 @Test
1473 public void testGetEmbeddedGraphInClone() throws Exception
1474 {
1475 prepare();
1477 DGraph gB = gA.clone();
1478
1479 // This works only because we know that the graphs have only one
1480 // template per level
1481 List<Template> expectedPathA = new ArrayList<Template>();
1482 List<Template> expectedPathB = new ArrayList<Template>();
1483 DGraph refToThisLayerGraphB = gB;
1484 Template refToThisLayerVrtxB = null;
1485 DGraph refToThisLayerGraphA = gA;
1486 Template refToThisLayerVrtxA = null;
1487 for (int embeddingLevel=0; embeddingLevel<9; embeddingLevel++)
1488 {
1489 refToThisLayerVrtxA = (Template) refToThisLayerGraphA
1490 .getVertexList().stream()
1491 .filter(v -> v instanceof Template)
1492 .findAny()
1493 .orElse(null);
1494 expectedPathA.add(refToThisLayerVrtxA);
1495 refToThisLayerGraphA = refToThisLayerVrtxA.getInnerGraph();
1496
1497 refToThisLayerVrtxB = (Template) refToThisLayerGraphB
1498 .getVertexList().stream()
1499 .filter(v -> v instanceof Template)
1500 .findAny()
1501 .orElse(null);
1502 expectedPathB.add(refToThisLayerVrtxB);
1503 refToThisLayerGraphB = refToThisLayerVrtxB.getInnerGraph();
1504 }
1505
1506 DGraph expectedEmbeddedA = expectedPathA.get(8).getInnerGraph();
1507 DGraph expectedEmbeddedB = expectedPathB.get(8).getInnerGraph();
1508
1509 DGraph embeddedFoundB = DGraph.getEmbeddedGraphInClone(gB,
1510 gA, expectedPathA);
1511
1512 assertEquals(expectedEmbeddedB,embeddedFoundB);
1513
1514 List<Template> pathFoundB = embeddedFoundB.getEmbeddingPath();
1515 assertEquals(expectedPathB,pathFoundB);
1516
1517 DGraph embeddedFoundA = DGraph.getEmbeddedGraphInClone(gA,
1518 gB, expectedPathB);
1519 assertEquals(expectedEmbeddedA,embeddedFoundA);
1520
1521 List<Template> pathFoundA = embeddedFoundA.getEmbeddingPath();
1522 assertEquals(expectedPathA,pathFoundA);
1523 }
1524
1525//------------------------------------------------------------------------------
1526
1527 @Test
1528 public void testGetSourceVertex() throws Exception
1529 {
1530 FragmentSpace fs = prepare();
1532 Vertex src = g.getSourceVertex();
1533 assertEquals(g.getVertexAtPosition(4),src,
1534 "Inconsistent source vertex");
1535
1536 DGraph g2 = makeTestGraphC(fs);
1537 Vertex src2 = g2.getSourceVertex();
1538 assertEquals(g2.getVertexAtPosition(0),src2,
1539 "Inconsistent source vertex");
1540 }
1541
1542//------------------------------------------------------------------------------
1543
1544 @Test
1545 public void testGetLevel() throws Exception
1546 {
1547 FragmentSpace fs = prepare();
1549 int[] expected = new int[] {2,3,0,1,-1};
1550 for (int i=0; i<g.getVertexCount(); i++)
1551 {
1552 assertEquals(expected[i],g.getLevel(g.getVertexAtPosition(i)),
1553 "Wrong level for vertex at position "+i);
1554 }
1555
1556 DGraph g2 = makeTestGraphC(fs);
1557 expected = new int[] {-1,0,1,2,3,2,0,1,2,3,2};
1558 for (int i=0; i<g2.getVertexCount(); i++)
1559 {
1560 assertEquals(expected[i],g2.getLevel(g2.getVertexAtPosition(i)),
1561 "Bis: Wrong level for vertex at position "+i);
1562 }
1563 }
1564
1565//------------------------------------------------------------------------------
1566
1567 @Test
1568 public void testReplaceVertex() throws Exception
1569 {
1570 FragmentSpace fs = prepare();
1571 DGraph g = makeTestGraphB(fs);
1572
1573 Vertex v1 = g.getVertexAtPosition(1);
1574
1575 LinkedHashMap<Integer, Integer> apMap =
1576 new LinkedHashMap<Integer,Integer>();
1577 apMap.put(0, 4);
1578 apMap.put(1, 1);
1579 apMap.put(3, 2);
1580 apMap.put(4, 0);
1581
1582 int chosenBBId = 4;
1583 BBType choosenBBTyp = BBType.FRAGMENT;
1584
1585 boolean res = g.replaceVertex(v1, chosenBBId, choosenBBTyp, apMap, fs);
1586
1587 assertTrue(res,"ReplaceVertex return value.");
1588 assertFalse(g.containsVertex(v1),"v1 is still part of graph");
1589 int numVertexesWithGoodBBId = 0;
1590 int numEdgesWithS = 0;
1591 int numEdgesWith2 = 0;
1592 int numEdgesWith3 = 0;
1593 for (Vertex v : g.gVertices)
1594 {
1595 if (v.getBuildingBlockType() == choosenBBTyp
1596 && v.getBuildingBlockId() == chosenBBId)
1597 {
1598 numVertexesWithGoodBBId++;
1599
1601 {
1602 if (!ap.isAvailable())
1603 {
1604 Vertex nextVrtx = ap.getLinkedAP().getOwner();
1605 if (nextVrtx.getBuildingBlockType() == BBType.SCAFFOLD)
1606 {
1607 numEdgesWithS++;
1608 } else {
1609 switch (nextVrtx.getBuildingBlockId())
1610 {
1611 case 2:
1612 numEdgesWith2++;
1613 break;
1614 case 3:
1615 numEdgesWith3++;
1616 break;
1617 }
1618 }
1619 }
1620 }
1621 }
1622 }
1623 assertEquals(2,numVertexesWithGoodBBId,"Number of new links.");
1624 assertEquals(2,numEdgesWithS,"Number of new edges with scaffold.");
1625 assertEquals(4,numEdgesWith2,"Number of new edges with v2a/b.");
1626 assertEquals(2,numEdgesWith3,"Number of new edges with v3a/b.");
1627
1628 //
1629 //
1630 //
1631 DGraph g2 = makeTestGraphB(fs);
1632
1633 Vertex v2 = g2.getVertexAtPosition(2);
1634
1635 SymmetricVertexes origSS = new SymmetricVertexes();
1636 for (Vertex v : g2.getSymSetForVertex(v2))
1637 {
1638 origSS.add(v);
1639 }
1640 Set<Long> oldVertexIds = new HashSet<Long>();
1641 for (Vertex v : g2.getVertexList())
1642 oldVertexIds.add(v.getVertexId());
1643
1644 LinkedHashMap<Integer,Integer> apMap2 =
1645 new LinkedHashMap<Integer,Integer>();
1646 apMap2.put(0, 1);
1647
1648 int chosenBBId2 = 5;
1649 BBType choosenBBTyp2 = BBType.FRAGMENT;
1650
1651 boolean res2 = g2.replaceVertex(v2, chosenBBId2, choosenBBTyp2, apMap2,
1652 fs);
1653
1654 assertTrue(res2,"ReplaceVertex return value (2).");
1655 assertFalse(g2.containsVertex(v2),"v2 is still part of graph");
1656 int numVertexesWithGoodBBId2 = 0;
1657 int numEdgesWith1 = 0;
1658 for (Vertex v : g2.gVertices)
1659 {
1660 if (v.getBuildingBlockType() == choosenBBTyp2
1661 && v.getBuildingBlockId() == chosenBBId2)
1662 {
1663 numVertexesWithGoodBBId2++;
1664
1666 {
1667 if (!ap.isAvailable())
1668 {
1669 Vertex nextVrtx = ap.getLinkedAP().getOwner();
1670 if (nextVrtx.getBuildingBlockId() == 1)
1671 numEdgesWith1++;
1672 }
1673 }
1674 }
1675 }
1676 assertEquals(4,numVertexesWithGoodBBId2,"Number of new links.");
1677 assertEquals(4,numEdgesWith1,"Number of new edges with scaffold.");
1678 assertEquals(2,g2.getSymmetricSetCount(),"Number of symmetric sets.");
1679 boolean found = false;
1680 boolean foundOldVertexId = false;
1681 Iterator<SymmetricVertexes> iterSS = g2.getSymSetsIterator();
1682 while (iterSS.hasNext())
1683 {
1684 SymmetricVertexes ss = iterSS.next();
1685 if (ss.size() == origSS.size())
1686 {
1687 found = true;
1688 for (Vertex v : ss)
1689 {
1690 if (oldVertexIds.contains(v.getVertexId()))
1691 foundOldVertexId = true;
1692 }
1693 }
1694 }
1695 assertTrue(found,"could not find old symmetric set");
1696 assertFalse(foundOldVertexId,"found old vertex id in new symmetric set");
1697 }
1698
1699//------------------------------------------------------------------------------
1700
1701 @Test
1702 public void testReplaceVertex_inRing() throws Exception
1703 {
1704 FragmentSpace fs = prepare();
1705 DGraph g = makeTestGraphD(fs);
1706
1707 Vertex v = g.getVertexAtPosition(1);
1708
1709 LinkedHashMap<Integer, Integer> apMap =
1710 new LinkedHashMap<Integer,Integer>();
1711 apMap.put(0, 0);
1712 apMap.put(1, 1);
1713 apMap.put(2, 2);
1714 apMap.put(3, 3);
1715 apMap.put(4, 4);
1716
1717 boolean res = g.replaceVertex(v, 1, BBType.FRAGMENT, apMap, fs);
1718 assertTrue(res);
1719
1720 DGraph g2 = makeTestGraphD(fs);
1721 assertTrue(g.isIsomorphicTo(g2));
1722 }
1723
1724//------------------------------------------------------------------------------
1725
1726 @Test
1727 public void testReplaceSubGraph() throws Exception
1728 {
1729 FragmentSpace fs = prepare();
1730 DGraph g = makeTestGraphD(fs);
1731
1732 List<Vertex> vrtxsToReplace = new ArrayList<Vertex>();
1733 vrtxsToReplace.add(g.getVertexAtPosition(0));
1734 vrtxsToReplace.add(g.getVertexAtPosition(1));
1735
1736 DGraph incomingSubGraph = makeTestGraphF(fs);
1737
1738 LinkedHashMap<AttachmentPoint, AttachmentPoint> apMap =
1739 new LinkedHashMap<AttachmentPoint,AttachmentPoint>();
1740 apMap.put(g.getVertexAtPosition(0).getAP(1), //A:0
1741 incomingSubGraph.getVertexAtPosition(0).getAP(2)); //A:0
1742 apMap.put(g.getVertexAtPosition(0).getAP(2), //D:0
1743 incomingSubGraph.getVertexAtPosition(7).getAP(1)); //D:0
1744 apMap.put(g.getVertexAtPosition(1).getAP(1), //B:0
1745 incomingSubGraph.getVertexAtPosition(6).getAP(2)); //B:0
1746 apMap.put(g.getVertexAtPosition(1).getAP(4), //C:0
1747 incomingSubGraph.getVertexAtPosition(6).getAP(4)); //C:0
1748 apMap.put(g.getVertexAtPosition(1).getAP(3), //B:0
1749 incomingSubGraph.getVertexAtPosition(5).getAP(3)); //B:0
1750 incomingSubGraph.reassignSymmetricLabels();
1751
1752 boolean res = g.replaceSingleSubGraph(vrtxsToReplace, incomingSubGraph, apMap);
1753 assertTrue(res);
1754
1756
1757 assertEquals(3,g.getRingCount(),"number of rings");
1758 assertEquals(3,g.getSymmetricSetCount(),"number of symmetric sets");
1759 assertEquals(incomingSubGraph.getVertexAtPosition(0),g.getSourceVertex(),
1760 "graph's surce vertex");
1761 //NB: the position of the vertexes has changes by -2. so vertex 3 is now at 1
1763 g.getVertexAtPosition(2), g); // length was 2
1764 assertEquals(3,pathA.getEdgesPath().size(),"path within a ring (A)");
1766 g.getVertexAtPosition(6), g); // length was 4
1767 assertEquals(5,pathB.getEdgesPath().size(),"path within a ring (B)");
1769 g.getVertexAtPosition(6), g); // length was 2
1770 assertEquals(4,pathC.getEdgesPath().size(),"path within a ring (C)");
1771
1772 DGraph expected = makeTestGraphG(fs);
1773 assertTrue(g.isIsomorphicTo(expected),"isomforphic to expected");
1774 }
1775
1776//------------------------------------------------------------------------------
1777
1778 @Test
1779 public void testReplaceSubGraph_inTemplate() throws Exception
1780 {
1781 FragmentSpace fs = prepare();
1782 DGraph g = makeTestGraphI(fs);
1783
1784 DGraph innerGraph = ((Template) g.getVertexAtPosition(0))
1785 .getInnerGraph();
1786
1787 List<Vertex> vrtxsToReplace = new ArrayList<Vertex>();
1788 vrtxsToReplace.add(innerGraph.getVertexAtPosition(0));
1789
1790 DGraph incomingSubGraph = makeTestGraphJ(fs);
1791
1792 LinkedHashMap<AttachmentPoint, AttachmentPoint> apMap =
1793 new LinkedHashMap<AttachmentPoint,AttachmentPoint>();
1794 // first two are those needed within the template
1795 apMap.put(vrtxsToReplace.get(0).getAP(3), //B:0
1796 incomingSubGraph.getVertexAtPosition(0).getAP(1)); //B:0
1797 apMap.put(vrtxsToReplace.get(0).getAP(4), //C:0
1798 incomingSubGraph.getVertexAtPosition(1).getAP(4)); //C:0
1799 // second two are those projected and used outside template
1800 apMap.put(vrtxsToReplace.get(0).getAP(0), //A:0
1801 incomingSubGraph.getVertexAtPosition(0).getAP(2)); //A:0
1802 apMap.put(vrtxsToReplace.get(0).getAP(1), //B:0
1803 incomingSubGraph.getVertexAtPosition(0).getAP(3)); //B:0
1804
1805 boolean res = innerGraph.replaceSingleSubGraph(vrtxsToReplace,
1806 incomingSubGraph, apMap);
1807 assertTrue(res);
1808
1809 assertEquals(5,g.getVertexCount(),"Vertex in outer graph");
1810 assertEquals(1,g.getRingCount(),"Rings in outer graph");
1811 assertEquals(4,g.getAvailableAPs().size(),"Free APs outer graph");
1812 Ring r = g.getRings().get(0);
1813 assertEquals(4,r.getDistance(r.getHeadVertex(),r.getTailVertex()),
1814 "Distance Head-Tail in ring of outer graph");
1815
1816 DGraph innerGraphAfter =
1817 ((Template) g.getVertexAtPosition(0)).getInnerGraph();
1818 assertEquals(6,innerGraphAfter.getVertexCount(),
1819 "Vertex in inner graph");
1820 assertEquals(1,innerGraphAfter.getRingCount(),
1821 "Rings in inner graph");
1822 assertEquals(6,innerGraphAfter.getAvailableAPs().size(),
1823 "Free APs inner graph");
1824 Ring ri = innerGraphAfter.getRings().get(0);
1825 assertEquals(5,ri.getDistance(ri.getHeadVertex(),ri.getTailVertex()),
1826 "Distance Head-Tail in ring of inner graph");
1827 }
1828
1829//------------------------------------------------------------------------------
1830
1831 @Test
1832 public void testRemoveVertex() throws Exception {
1833 DGraph graph = new DGraph();
1834 EmptyVertex v0 = new EmptyVertex(0);
1835 buildVertexAndConnectToGraph(v0, 3, graph);
1836
1837 EmptyVertex v1 = new EmptyVertex(1);
1838 buildVertexAndConnectToGraph(v1, 2, graph);
1839 graph.addEdge(new Edge(v0.getAP(0), v1.getAP(0)));
1840
1841 EmptyVertex v2 = new EmptyVertex(2);
1842 buildVertexAndConnectToGraph(v2, 2, graph);
1843 graph.addEdge(new Edge(v1.getAP(1), v2.getAP(0)));
1844
1845 EmptyVertex v3 = new EmptyVertex(3);
1846 buildVertexAndConnectToGraph(v3, 1, graph);
1847 graph.addEdge(new Edge(v2.getAP(1), v3.getAP(0)));
1848
1849 EmptyVertex v4 = new EmptyVertex(4);
1850 buildVertexAndConnectToGraph(v4, 3, graph);
1851 graph.addEdge(new Edge(v0.getAP(1), v4.getAP(0)));
1852
1853 EmptyVertex v5 = new EmptyVertex(5);
1854 buildVertexAndConnectToGraph(v5, 1, graph);
1855 graph.addEdge(new Edge(v4.getAP(1), v5.getAP(0)));
1856
1857 EmptyVertex v6 = new EmptyVertex(6);
1858 buildVertexAndConnectToGraph(v6, 1, graph);
1859 graph.addEdge(new Edge(v0.getAP(2), v6.getAP(0)));
1860
1861 EmptyVertex v7 = new EmptyVertex(7);
1862 buildVertexAndConnectToGraph(v7, 1, graph);
1863 graph.addEdge(new Edge(v4.getAP(2), v7.getAP(0)));
1864
1865 graph.addRing(new Ring(new ArrayList<>(
1866 Arrays.asList(v5, v4, v0, v1, v2, v3))));
1867
1868 graph.addRing(new Ring(new ArrayList<>(
1869 Arrays.asList(v6, v0, v4, v7))));
1870
1872 ss.add(v3);
1873 ss.add(v5);
1874 graph.addSymmetricSetOfVertices(ss);
1875
1877 ss2.add(v6);
1878 ss2.add(v7);
1879 graph.addSymmetricSetOfVertices(ss2);
1880
1881 // Current string encoding this graph is
1882// "0 0_1_0_0,1_1_1_0,2_1_1_0,3_1_1_0,4_1_1_0,5_1_1_0,"
1883// + "6_1_1_0,7_1_1_0, 0_0_1_0_1,1_1_2_0_1,2_1_3_0_1,0_1_4_0_1,"
1884// + "4_1_5_0_1,0_2_6_0_1,4_2_7_0_1, "
1885// + "DENOPTIMRing [verteces=[5_1_1_0, 4_1_1_0, 0_1_0_0, 1_1_1_0,"
1886// + " 2_1_1_0, 3_1_1_0]] DENOPTIMRing [verteces=[6_1_1_0,"
1887// + " 0_1_0_0, 4_1_1_0, 7_1_1_0]] "
1888// + "SymmetricSet [symVrtxIds=[3, 5]] "
1889// + "SymmetricSet [symVrtxIds=[6, 7]]";
1890
1891 int numV = graph.getVertexCount();
1892 int numE = graph.getEdgeCount();
1893 int numS = graph.getSymmetricSetCount();
1894 int numR = graph.getRingCount();
1895
1896 graph.removeVertex(v5);
1897
1898 int numVa = graph.getVertexCount();
1899 int numEa = graph.getEdgeCount();
1900 int numSa = graph.getSymmetricSetCount();
1901 int numRa = graph.getRingCount();
1902
1903 assertEquals(numVa, numV - 1);
1904 assertEquals(numEa, numE - 1);
1905 assertEquals(numSa, numS - 1);
1906 assertEquals(numRa, numR - 1);
1907
1908 graph.removeVertex(v3);
1909
1910 int numVb = graph.getVertexCount();
1911 int numEb = graph.getEdgeCount();
1912 int numSb = graph.getSymmetricSetCount();
1913 int numRb = graph.getRingCount();
1914
1915 assertEquals(numVb, numVa - 1);
1916 assertEquals(numEb, numEa - 1);
1917 assertEquals(numSb, numSa);
1918 assertEquals(numRb, numRa);
1919
1920 graph.removeVertex(v4); // non terminal vertex
1921
1922 int numVc = graph.getVertexCount();
1923 int numEc = graph.getEdgeCount();
1924 int numSc = graph.getSymmetricSetCount();
1925 int numRc = graph.getRingCount();
1926
1927 assertEquals(numVc, numVb - 1);
1928 assertEquals(numEc, numEb - 2);
1929 assertEquals(numSc, numSb);
1930 assertEquals(numRc, numRb - 1);
1931
1932 }
1933
1934//------------------------------------------------------------------------------
1935
1936 @Test
1938 {
1939 DGraph graphA = new DGraph();
1940 EmptyVertex v0 = new EmptyVertex(0);
1941 buildVertexAndConnectToGraph(v0, 3, graphA);
1942
1943 EmptyVertex v1 = new EmptyVertex(1);
1944 buildVertexAndConnectToGraph(v1, 2, graphA);
1945 graphA.addEdge(new Edge(v0.getAP(0), v1.getAP(0)));
1946
1947 EmptyVertex v2 = new EmptyVertex(2);
1948 buildVertexAndConnectToGraph(v2, 2, graphA);
1949 graphA.addEdge(new Edge(v1.getAP(1), v2.getAP(0)));
1950
1951 // Other graph, but is the same graph
1952
1953 DGraph graphB = new DGraph();
1954 EmptyVertex v90 = new EmptyVertex(90);
1955 buildVertexAndConnectToGraph(v90, 3, graphB);
1956
1957 EmptyVertex v91 = new EmptyVertex(91);
1958 buildVertexAndConnectToGraph(v91, 2, graphB);
1959 graphB.addEdge(new Edge(v90.getAP(0), v91.getAP(0)));
1960
1961 EmptyVertex v92 = new EmptyVertex(92);
1962 buildVertexAndConnectToGraph(v92, 2, graphB);
1963 graphB.addEdge(new Edge(v91.getAP(1), v92.getAP(0)));
1964
1965 StringBuilder reason = new StringBuilder();
1966 assertTrue(graphA.sameAs(graphB, reason), reason.toString());
1967 }
1968
1969//------------------------------------------------------------------------------
1970
1971 @Test
1973 {
1974 DGraph graphA = new DGraph();
1975 EmptyVertex v0 = new EmptyVertex(0);
1976 buildVertexAndConnectToGraph(v0, 3, graphA);
1977
1978 EmptyVertex v1 = new EmptyVertex(1);
1979 buildVertexAndConnectToGraph(v1, 2, graphA);
1980 graphA.addEdge(new Edge(v0.getAP(0), v1.getAP(0)));
1981
1982 EmptyVertex v2 = new EmptyVertex(2);
1983 buildVertexAndConnectToGraph(v2, 2, graphA);
1984 graphA.addEdge(new Edge(v1.getAP(1), v2.getAP(0)));
1985
1986 // Other graph
1987
1988 DGraph graphB = new DGraph();
1989 EmptyVertex v90 = new EmptyVertex(90);
1990 buildVertexAndConnectToGraph(v90, 3, graphB);
1991
1992 EmptyVertex v91 = new EmptyVertex(91);
1993 buildVertexAndConnectToGraph(v91, 2, graphB);
1994 graphB.addEdge(new Edge(v90.getAP(0), v91.getAP(0)));
1995
1996 EmptyVertex v92 = new EmptyVertex(92);
1997 buildVertexAndConnectToGraph(v92, 3, graphB);
1998 graphB.addEdge(new Edge(v91.getAP(1), v92.getAP(0)));
1999
2000 StringBuilder reason = new StringBuilder();
2001 assertFalse(graphA.sameAs(graphB, reason));
2002 }
2003
2004//------------------------------------------------------------------------------
2005
2006 @Test
2007 public void testSameAs_SameSymmSet() throws Exception {
2008 DGraph graphA = new DGraph();
2009 EmptyVertex v0 = new EmptyVertex(0);
2010 buildVertexAndConnectToGraph(v0, 4, graphA);
2011
2012 EmptyVertex v1 = new EmptyVertex(1);
2013 buildVertexAndConnectToGraph(v1, 2, graphA);
2014 graphA.addEdge(new Edge(v0.getAP(0), v1.getAP(0)));
2015
2016 EmptyVertex v2 = new EmptyVertex(2);
2017 buildVertexAndConnectToGraph(v2, 2, graphA);
2018 graphA.addEdge(new Edge(v0.getAP(1), v2.getAP(0)));
2019
2020 EmptyVertex v3 = new EmptyVertex(3);
2021 buildVertexAndConnectToGraph(v3, 2, graphA);
2022 graphA.addEdge(new Edge(v0.getAP(2), v3.getAP(0)));
2023
2024 EmptyVertex v4 = new EmptyVertex(4);
2025 buildVertexAndConnectToGraph(v4, 2, graphA);
2026 graphA.addEdge(new Edge(v0.getAP(3), v4.getAP(0)));
2027
2029 ssA.add(v1);
2030 ssA.add(v2);
2031 graphA.addSymmetricSetOfVertices(ssA);
2033 ssA2.add(v3);
2034 ssA2.add(v4);
2035 graphA.addSymmetricSetOfVertices(ssA2);
2036
2037 // Other
2038
2039 DGraph graphB = new DGraph();
2040 EmptyVertex v90 = new EmptyVertex(90);
2041 buildVertexAndConnectToGraph(v90, 4, graphB);
2042
2043 EmptyVertex v91 = new EmptyVertex(91);
2044 buildVertexAndConnectToGraph(v91, 2, graphB);
2045 graphB.addEdge(new Edge(v90.getAP(0), v91.getAP(0)));
2046
2047 EmptyVertex v92 = new EmptyVertex(92);
2048 buildVertexAndConnectToGraph(v92, 2, graphB);
2049 graphB.addEdge(new Edge(v90.getAP(1), v92.getAP(0)));
2050
2051 EmptyVertex v93 = new EmptyVertex(93);
2052 buildVertexAndConnectToGraph(v93, 2, graphB);
2053 graphB.addEdge(new Edge(v90.getAP(2), v93.getAP(0)));
2054
2055 EmptyVertex v94 = new EmptyVertex(94);
2056 buildVertexAndConnectToGraph(v94, 2, graphB);
2057 graphB.addEdge(new Edge(v90.getAP(3), v94.getAP(0)));
2058
2060 ssB2.add(v93);
2061 ssB2.add(v94);
2062 graphB.addSymmetricSetOfVertices(ssB2);
2064 ssB.add(v91);
2065 ssB.add(v92);
2066 graphB.addSymmetricSetOfVertices(ssB);
2067
2068 /*
2069 System.out.println("Graphs Same SS");
2070 System.out.println(graphA);
2071 System.out.println(graphB);
2072 */
2073
2074 StringBuilder reason = new StringBuilder();
2075 assertTrue(graphA.sameAs(graphB, reason));
2076 }
2077
2078//------------------------------------------------------------------------------
2079
2080 @Test
2081 public void testSameAs_DiffSymmSet() throws Exception {
2082 DGraph graphA = new DGraph();
2083 EmptyVertex v0 = new EmptyVertex(0);
2084 buildVertexAndConnectToGraph(v0, 4, graphA);
2085
2086 EmptyVertex v1 = new EmptyVertex(1);
2087 buildVertexAndConnectToGraph(v1, 2, graphA);
2088 graphA.addEdge(new Edge(v0.getAP(0), v1.getAP(0)));
2089
2090 EmptyVertex v2 = new EmptyVertex(2);
2091 buildVertexAndConnectToGraph(v2, 2, graphA);
2092 graphA.addEdge(new Edge(v0.getAP(1), v2.getAP(0)));
2093
2094 EmptyVertex v3 = new EmptyVertex(3);
2095 buildVertexAndConnectToGraph(v3, 2, graphA);
2096 graphA.addEdge(new Edge(v0.getAP(2), v3.getAP(0)));
2097
2098 EmptyVertex v4 = new EmptyVertex(4);
2099 buildVertexAndConnectToGraph(v4, 2, graphA);
2100 graphA.addEdge(new Edge(v0.getAP(3), v4.getAP(0)));
2101
2103 ssA.add(v1); //difference
2104 ssA.add(v2); //difference
2105 graphA.addSymmetricSetOfVertices(ssA);
2107 ssA2.add(v3); //difference
2108 ssA2.add(v4); //difference
2109 graphA.addSymmetricSetOfVertices(ssA2);
2110
2111 // Other
2112
2113 DGraph graphB = new DGraph();
2114 EmptyVertex v90 = new EmptyVertex(90);
2115 buildVertexAndConnectToGraph(v90, 4, graphB);
2116
2117 EmptyVertex v91 = new EmptyVertex(91);
2118 buildVertexAndConnectToGraph(v91, 2, graphB);
2119 graphB.addEdge(new Edge(v90.getAP(0), v1.getAP(0)));
2120
2121 EmptyVertex v92 = new EmptyVertex(92);
2122 buildVertexAndConnectToGraph(v92, 2, graphB);
2123 graphB.addEdge(new Edge(v0.getAP(1), v2.getAP(0)));
2124
2125 EmptyVertex v93 = new EmptyVertex(93);
2126 buildVertexAndConnectToGraph(v93, 2, graphB);
2127 graphB.addEdge(new Edge(v0.getAP(2), v3.getAP(0)));
2128
2129 EmptyVertex v94 = new EmptyVertex(94);
2130 buildVertexAndConnectToGraph(v94, 2, graphB);
2131 graphB.addEdge(new Edge(v0.getAP(3), v4.getAP(0)));
2132
2134 ssB.add(v1); //difference
2135 ssB.add(v3); //difference
2136 graphB.addSymmetricSetOfVertices(ssB);
2138 ssB2.add(v2); //difference
2139 ssB2.add(v4); //difference
2140 graphB.addSymmetricSetOfVertices(ssB2);
2141
2142 StringBuilder reason = new StringBuilder();
2143 assertFalse(graphA.sameAs(graphB, reason));
2144 }
2145
2146//------------------------------------------------------------------------------
2147
2148 @Test
2150 {
2151 DGraph graphA = new DGraph();
2152 EmptyVertex v0 = new EmptyVertex(0);
2153 buildVertexAndConnectToGraph(v0, 4, graphA);
2154
2155 EmptyVertex v1 = new EmptyVertex(1);
2156 buildVertexAndConnectToGraph(v1, 2, graphA);
2157 graphA.addEdge(new Edge(v0.getAP(0), v1.getAP(0)));
2158
2159 EmptyVertex v2 = new EmptyVertex(2);
2160 buildVertexAndConnectToGraph(v2, 2, graphA);
2161 graphA.addEdge(new Edge(v0.getAP(1), v2.getAP(0)));
2162
2163 EmptyVertex v3 = new EmptyVertex(3);
2164 buildVertexAndConnectToGraph(v3, 2, graphA);
2165 graphA.addEdge(new Edge(v0.getAP(2), v3.getAP(0)));
2166
2167 EmptyVertex v4 = new EmptyVertex(4);
2168 buildVertexAndConnectToGraph(v4, 2, graphA);
2169 graphA.addEdge(new Edge(v0.getAP(3), v4.getAP(0)));
2170
2171 ArrayList<Vertex> vrA = new ArrayList<Vertex>();
2172 vrA.add(v1);
2173 vrA.add(v0);
2174 vrA.add(v2);
2175 Ring rA = new Ring(vrA);
2176 graphA.addRing(rA);
2177 ArrayList<Vertex> vrA2 = new ArrayList<Vertex>();
2178 vrA2.add(v3);
2179 vrA2.add(v0);
2180 vrA2.add(v4);
2181 Ring rA2 = new Ring(vrA2);
2182 graphA.addRing(rA2);
2183
2184
2185 // Other
2186
2187 DGraph graphB = new DGraph();
2188 EmptyVertex v90 = new EmptyVertex(90);
2189 buildVertexAndConnectToGraph(v90, 4, graphB);
2190
2191 EmptyVertex v91 = new EmptyVertex(91);
2192 buildVertexAndConnectToGraph(v91, 2, graphB);
2193 graphB.addEdge(new Edge(v90.getAP(0), v91.getAP(0)));
2194
2195 EmptyVertex v92 = new EmptyVertex(92);
2196 buildVertexAndConnectToGraph(v92, 2, graphB);
2197 graphB.addEdge(new Edge(v90.getAP(1), v92.getAP(0)));
2198
2199 EmptyVertex v93 = new EmptyVertex(93);
2200 buildVertexAndConnectToGraph(v93, 2, graphB);
2201 graphB.addEdge(new Edge(v90.getAP(2), v93.getAP(0)));
2202
2203 EmptyVertex v94 = new EmptyVertex(94);
2204 buildVertexAndConnectToGraph(v94, 2, graphB);
2205 graphB.addEdge(new Edge(v90.getAP(3), v94.getAP(0)));
2206
2207 ArrayList<Vertex> vrB = new ArrayList<Vertex>();
2208 vrB.add(v91);
2209 vrB.add(v90);
2210 vrB.add(v92);
2211 Ring rB = new Ring(vrB);
2212 graphB.addRing(rB);
2213 ArrayList<Vertex> vrB2 = new ArrayList<Vertex>();
2214 vrB2.add(v93);
2215 vrB2.add(v90);
2216 vrB2.add(v94);
2217 Ring rB2 = new Ring(vrB2);
2218 graphB.addRing(rB2);
2219
2220 StringBuilder reason = new StringBuilder();
2221 assertTrue(graphA.sameAs(graphB, reason));
2222 }
2223
2224//------------------------------------------------------------------------------
2225
2226 @Test
2227 public void testSameAs_DisorderRings() throws Exception
2228 {
2229 DGraph graphA = new DGraph();
2230 EmptyVertex v0 = new EmptyVertex(0);
2231 buildVertexAndConnectToGraph(v0, 4, graphA);
2232
2233 EmptyVertex v1 = new EmptyVertex(1);
2234 buildVertexAndConnectToGraph(v1, 2, graphA);
2235 graphA.addEdge(new Edge(v0.getAP(0), v1.getAP(0)));
2236
2237 EmptyVertex v2 = new EmptyVertex(2);
2238 buildVertexAndConnectToGraph(v2, 2, graphA);
2239 graphA.addEdge(new Edge(v0.getAP(1), v2.getAP(0)));
2240
2241 EmptyVertex v3 = new EmptyVertex(3);
2242 buildVertexAndConnectToGraph(v3, 2, graphA);
2243 graphA.addEdge(new Edge(v0.getAP(2), v3.getAP(0)));
2244
2245 EmptyVertex v4 = new EmptyVertex(4);
2246 buildVertexAndConnectToGraph(v4, 2, graphA);
2247 graphA.addEdge(new Edge(v0.getAP(3), v4.getAP(0)));
2248
2249 ArrayList<Vertex> vrA = new ArrayList<>();
2250 vrA.add(v1);
2251 vrA.add(v0);
2252 vrA.add(v2);
2253 Ring rA = new Ring(vrA);
2254 graphA.addRing(rA);
2255 ArrayList<Vertex> vrA2 = new ArrayList<>();
2256 vrA2.add(v3);
2257 vrA2.add(v0);
2258 vrA2.add(v4);
2259 Ring rA2 = new Ring(vrA2);
2260 graphA.addRing(rA2);
2261
2262
2263 // Other
2264
2265 DGraph graphB = new DGraph();
2266 EmptyVertex v90 = new EmptyVertex(90);
2267 buildVertexAndConnectToGraph(v90, 4, graphB);
2268
2269 EmptyVertex v91 = new EmptyVertex(91);
2270 buildVertexAndConnectToGraph(v91, 2, graphB);
2271 graphB.addEdge(new Edge(v90.getAP(0), v91.getAP(0)));
2272
2273 EmptyVertex v92 = new EmptyVertex(92);
2274 buildVertexAndConnectToGraph(v92, 2, graphB);
2275 graphB.addEdge(new Edge(v90.getAP(1), v92.getAP(0)));
2276
2277 EmptyVertex v93 = new EmptyVertex(93);
2278 buildVertexAndConnectToGraph(v93, 2, graphB);
2279 graphB.addEdge(new Edge(v90.getAP(2), v93.getAP(0)));
2280
2281 EmptyVertex v94 = new EmptyVertex(94);
2282 buildVertexAndConnectToGraph(v94, 2, graphB);
2283 graphB.addEdge(new Edge(v90.getAP(3), v94.getAP(0)));
2284
2285 ArrayList<Vertex> vrB = new ArrayList<>();
2286 vrB.add(v91);
2287 vrB.add(v90);
2288 vrB.add(v92);
2289 Ring rB = new Ring(vrB);
2290 graphB.addRing(rB);
2291 ArrayList<Vertex> vrB2 = new ArrayList<>();
2292 vrB2.add(v94);
2293 vrB2.add(v90);
2294 vrB2.add(v93);
2295 Ring rB2 = new Ring(vrB2);
2296 graphB.addRing(rB2);
2297
2298 StringBuilder reason = new StringBuilder();
2299 assertTrue(graphA.sameAs(graphB, reason));
2300 }
2301
2302//------------------------------------------------------------------------------
2303
2304 @Test
2306 {
2307 DGraph graphA = new DGraph();
2308 EmptyVertex v0 = new EmptyVertex(0);
2309 buildVertexAndConnectToGraph(v0, 4, graphA);
2310
2311 EmptyVertex v1 = new EmptyVertex(1);
2312 buildVertexAndConnectToGraph(v1, 2, graphA);
2313 graphA.addEdge(new Edge(v0.getAP(0), v1.getAP(0)));
2314
2315 EmptyVertex v2 = new EmptyVertex(2);
2316 buildVertexAndConnectToGraph(v2, 2, graphA);
2317 graphA.addEdge(new Edge(v0.getAP(1), v2.getAP(0)));
2318
2319 EmptyVertex v3 = new EmptyVertex(3);
2320 buildVertexAndConnectToGraph(v3, 2, graphA);
2321 graphA.addEdge(new Edge(v0.getAP(2), v3.getAP(0)));
2322
2323 EmptyVertex v4 = new EmptyVertex(4);
2324 buildVertexAndConnectToGraph(v4, 2, graphA);
2325 graphA.addEdge(new Edge(v0.getAP(3), v4.getAP(0)));
2326
2327 ArrayList<Vertex> vrA = new ArrayList<>();
2328 vrA.add(v1);
2329 vrA.add(v0);
2330 vrA.add(v2);
2331 Ring rA = new Ring(vrA);
2332 graphA.addRing(rA);
2333 ArrayList<Vertex> vrA2 = new ArrayList<>();
2334 vrA2.add(v3);
2335 vrA2.add(v0);
2336 vrA2.add(v4);
2337 Ring rA2 = new Ring(vrA2);
2338 graphA.addRing(rA2);
2339
2340 // Other
2341 DGraph graphB = new DGraph();
2342 EmptyVertex v90 = new EmptyVertex(90);
2343 buildVertexAndConnectToGraph(v90, 4, graphB);
2344
2345 EmptyVertex v91 = new EmptyVertex(91);
2346 buildVertexAndConnectToGraph(v91, 2, graphB);
2347 graphB.addEdge(new Edge(v90.getAP(0), v91.getAP(0)));
2348
2349 EmptyVertex v92 = new EmptyVertex(92);
2350 buildVertexAndConnectToGraph(v92, 2, graphB);
2351 graphB.addEdge(new Edge(v90.getAP(1), v92.getAP(0)));
2352
2353 EmptyVertex v93 = new EmptyVertex(93);
2354 buildVertexAndConnectToGraph(v93, 2, graphB);
2355 graphB.addEdge(new Edge(v90.getAP(2), v93.getAP(0)));
2356
2357 EmptyVertex v94 = new EmptyVertex(94);
2358 buildVertexAndConnectToGraph(v94, 2, graphB);
2359 graphB.addEdge(new Edge(v90.getAP(3), v94.getAP(0)));
2360
2361 ArrayList<Vertex> vrB = new ArrayList<>();
2362 vrB.add(v91);
2363 vrB.add(v90);
2364 vrB.add(v94);
2365 Ring rB = new Ring(vrB);
2366 graphB.addRing(rB);
2367 ArrayList<Vertex> vrB2 = new ArrayList<>();
2368 vrB2.add(v92);
2369 vrB2.add(v90);
2370 vrB2.add(v93);
2371 Ring rB2 = new Ring(vrB2);
2372 graphB.addRing(rB2);
2373
2374 StringBuilder reason = new StringBuilder();
2375 assertFalse(graphA.sameAs(graphB, reason));
2376 }
2377
2378//------------------------------------------------------------------------------
2379
2380 @Test
2382 throws DENOPTIMException
2383 {
2384 EmptyVertex vertex0 = new EmptyVertex(0);
2385 EmptyVertex vertex1 = new EmptyVertex(1);
2386
2387 vertex0.addAP();
2388 vertex0.addAP();
2389 vertex1.addAP();
2390
2391 Edge edge0 = new Edge(vertex0.getAP(0),
2392 vertex1.getAP(0));
2393
2394 DGraph graph = new DGraph();
2395 graph.addVertex(vertex0);
2396 graph.addVertex(vertex1);
2397 graph.addEdge(edge0);
2398
2399 List<AttachmentPoint> lst = graph.getAvailableAPs();
2400 assertEquals(1,lst.size(), "Size of list");
2401 assertEquals(vertex0.getVertexId(),lst.get(0).getOwner().getVertexId(),
2402 "ID of the vertex holding the available AP.");
2403 }
2404
2405//------------------------------------------------------------------------------
2406
2407 @Test
2408 public void testClone() throws DENOPTIMException {
2409 DGraph graph = new DGraph();
2410 EmptyVertex v0 = new EmptyVertex(0);
2411 buildVertexAndConnectToGraph(v0, 3, graph);
2412
2413 EmptyVertex v1 = new EmptyVertex(1);
2414 buildVertexAndConnectToGraph(v1, 2, graph);
2415 graph.addEdge(new Edge(v0.getAP(0), v1.getAP(0)));
2416
2417 EmptyVertex v2 = new EmptyVertex(2);
2418 buildVertexAndConnectToGraph(v2, 2, graph);
2419 graph.addEdge(new Edge(v1.getAP(1), v2.getAP(0)));
2420
2421 EmptyVertex v3 = new EmptyVertex(3);
2422 buildVertexAndConnectToGraph(v3, 1, graph);
2423 graph.addEdge(new Edge(v2.getAP(1), v3.getAP(0)));
2424
2425 EmptyVertex v4 = new EmptyVertex(4);
2426 buildVertexAndConnectToGraph(v4, 3, graph);
2427 graph.addEdge(new Edge(v0.getAP(1), v4.getAP(0)));
2428
2429 EmptyVertex v5 = new EmptyVertex(5);
2430 buildVertexAndConnectToGraph(v5, 1, graph);
2431 graph.addEdge(new Edge(v4.getAP(1), v5.getAP(0)));
2432
2433 EmptyVertex v6 = new EmptyVertex(6);
2434 buildVertexAndConnectToGraph(v6, 1, graph);
2435 graph.addEdge(new Edge(v0.getAP(2), v6.getAP(0)));
2436
2437 EmptyVertex v7 = new EmptyVertex(7);
2438 buildVertexAndConnectToGraph(v7, 1, graph);
2439 graph.addEdge(new Edge(v4.getAP(2), v7.getAP(0)));
2440
2441 graph.addRing(new Ring(new ArrayList<>(
2442 Arrays.asList(v5, v4, v0, v1, v2, v3))));
2443
2444 graph.addRing(new Ring(new ArrayList<>(
2445 Arrays.asList(v6, v0, v4, v7))));
2446
2448 ss1.add(v3);
2449 ss1.add(v5);
2450 graph.addSymmetricSetOfVertices(ss1);
2451
2453 ss2.add(v6);
2454 ss2.add(v7);
2455 graph.addSymmetricSetOfVertices(ss2);
2456
2457 DGraph clone = graph.clone();
2458
2459 assertEquals(graph.gVertices.size(), clone.gVertices.size(),
2460 "Number of vertices");
2461 assertEquals(graph.gEdges.size(), clone.gEdges.size(),
2462 "Number of Edges");
2463 assertEquals(graph.gRings.size(), clone.gRings.size(),
2464 "Number of Rings");
2465 assertEquals(graph.getSymmetricSetCount(), clone.getSymmetricSetCount(),
2466 "Number of symmetric sets");
2467 assertEquals(graph.closableChains.size(), clone.closableChains.size(),
2468 "Number of closable chains");
2469 assertEquals(graph.localMsg, clone.localMsg,
2470 "Local msg");
2471 assertEquals(graph.graphId, clone.graphId,
2472 "Graph ID");
2473
2474 for (int iv=0; iv<graph.getVertexCount(); iv++)
2475 {
2476 Vertex vg = graph.getVertexAtPosition(iv);
2477 Vertex vc = clone.getVertexAtPosition(iv);
2478 int hashVG = vg.hashCode();
2479 int hashVC = vc.hashCode();
2480
2481 for (int iap = 0; iap<vg.getNumberOfAPs(); iap++)
2482 {
2483 assertEquals(vg.getAP(iap).getOwner().hashCode(), hashVG,
2484 "Reference to vertex owner in ap " + iap + " vertex "
2485 + iv + "(G)");
2486 assertEquals(vc.getAP(iap).getOwner().hashCode(), hashVC,
2487 "Reference to vertex owner in ap " + iap + " vertex "
2488 + iv + " (C)");
2489 assertNotEquals(vc.getAP(iap).getOwner().hashCode(),
2490 vg.getAP(iap).getOwner().hashCode(),
2491 "Owner of AP "+iap+" in vertex "+iv);
2492 }
2493 }
2494 }
2495
2496//------------------------------------------------------------------------------
2497
2498 @Test
2500 {
2501 DGraph graph = new DGraph();
2504 graph.addVertex(tmpl);
2505
2506 assertEquals(1, graph.getMutableSites().size(),
2507 "Size of mutation list in case of frozen template");
2508
2509 graph = new DGraph();
2511 graph.addVertex(tmpl);
2512
2513 assertEquals(2, graph.getMutableSites().size(),
2514 "Size of mutation list in case of free template");
2515
2516 assertEquals(0, graph.getMutableSites(new ArrayList<>(
2517 Arrays.asList(MutationType.values()))).size(),
2518 "No sites if all is ignored");
2519 }
2520
2521//------------------------------------------------------------------------------
2522
2529 throws Exception
2530 {
2531 DGraph graph = new DGraph();
2533 BBType.SCAFFOLD, fs);
2534 graph.addVertex(s);
2535 return graph;
2536 }
2537
2538//------------------------------------------------------------------------------
2539
2546 throws Exception
2547 {
2548 DGraph graph = new DGraph();
2550 BBType.SCAFFOLD, fs);
2551 graph.addVertex(s);
2553 BBType.FRAGMENT, fs);
2554 graph.addVertex(v1a);
2555
2556 graph.addEdge(new Edge(s.getAP(0), v1a.getAP(0)));
2557
2558 return graph;
2559 }
2560
2561//------------------------------------------------------------------------------
2562
2578 public static DGraph makeTestGraphA()
2579 {
2580 DGraph graph = new DGraph();
2581
2582 // If we cannot make the test graph, something is deeeeeply wrong and
2583 // a bugfix is needed.
2584 try {
2585 IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
2586 IAtomContainer iac1 = builder.newAtomContainer();
2587 IAtom ia1 = new Atom("C");
2588 IAtom ia2 = new Atom("C");
2589 iac1.addAtom(ia1);
2590 iac1.addAtom(ia2);
2591 iac1.addBond(new Bond(ia1, ia2, IBond.Order.SINGLE));
2592
2593 Fragment v1 = new Fragment(1, iac1, BBType.SCAFFOLD);
2594 v1.addAP(0);
2595 v1.addAP(0);
2596 v1.addAP(0);
2597 v1.addAP(1);
2598
2599 IAtomContainer iac2 = builder.newAtomContainer();
2600 iac2.addAtom(new Atom("O"));
2601 Fragment v2 = new Fragment(2, iac2, BBType.FRAGMENT);
2602 v2.addAP(0);
2603 v2.addAP(0);
2604
2605 IAtomContainer iac3 = builder.newAtomContainer();
2606 iac3.addAtom(new Atom("H"));
2607 Fragment v3 = new Fragment(3, iac3,
2608 BBType.CAP);
2609 v3.addAP(0);
2610
2611 IAtomContainer iac4 = builder.newAtomContainer();
2612 iac4.addAtom(new Atom("H"));
2613 Fragment v4 = new Fragment(4, iac4,
2614 BBType.CAP);
2615 v4.addAP(0);
2616
2617 graph.addVertex(v1);
2618 graph.addVertex(v2);
2619 graph.addVertex(v3);
2620 graph.addVertex(v4);
2621 graph.addEdge(new Edge(v1.getAP(0), v2.getAP(0)));
2622 graph.addEdge(new Edge(v1.getAP(1), v3.getAP(0)));
2623 graph.addEdge(new Edge(v2.getAP(1), v4.getAP(0)));
2624
2625 // Use this just to verify identify of the graph
2626 /*
2627 System.out.println("WRITING TEST GRAPH A");
2628 DenoptimIO.writeGraphsToFile(new File("/tmp/test_graph_A"),
2629 FileFormat.GRAPHJSON,
2630 new ArrayList<DENOPTIMGraph>(Arrays.asList(graph)));
2631 */
2632 } catch (Throwable t)
2633 {
2634 t.printStackTrace();
2635 System.err.println("FATAL ERROR! Could not make test graph (A). "
2636 + "Please, report this to the development team.");
2637 System.exit(-1);
2638 }
2639
2640 return graph;
2641 }
2642
2643//------------------------------------------------------------------------------
2644
2667 public static DGraph makeTestGraphA2()
2668 {
2669 DGraph graph = new DGraph();
2670
2671 // If we cannot make the test graph, something is deeeeeply wrong and
2672 // a bugfix is needed.
2673 try {
2674 IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
2675 IAtomContainer iac1 = builder.newAtomContainer();
2676 IAtom ia1 = new Atom("C");
2677 IAtom ia2 = new Atom("C");
2678 iac1.addAtom(ia1);
2679 iac1.addAtom(ia2);
2680 iac1.addBond(new Bond(ia1, ia2, IBond.Order.SINGLE));
2681
2682 Fragment v1 = new Fragment(1, iac1, BBType.SCAFFOLD);
2683 v1.addAP(0, APClass.make(a,0));
2684 v1.addAP(0, APClass.make(b,1));
2685 v1.addAP(0, APClass.make(b,1));
2686 v1.addAP(1, APClass.make(a,0));
2687 v1.setBuildingBlockId(0);
2688
2689 IAtomContainer iac2 = builder.newAtomContainer();
2690 iac2.addAtom(new Atom("O"));
2691 Fragment v2 = new Fragment(2, iac2, BBType.FRAGMENT);
2692 v2.addAP(0, APClass.make(b,1));
2693 v2.addAP(0, APClass.make(b,1));
2694 v2.setBuildingBlockId(1);
2695
2696 IAtomContainer iac3 = builder.newAtomContainer();
2697 iac3.addAtom(new Atom("H"));
2698 Fragment v3 = new Fragment(3, iac3, BBType.CAP);
2699 v3.addAP(0, APClass.make(c,1));
2700 v3.setBuildingBlockId(2);
2701
2702 IAtomContainer iac4 = builder.newAtomContainer();
2703 iac4.addAtom(new Atom("H"));
2704 Fragment v4 = new Fragment(4, iac4, BBType.CAP);
2705 v4.addAP(0, APClass.make(c,1));
2706 v4.setBuildingBlockId(3);
2707
2708 EmptyVertex ev1 = new EmptyVertex();
2709 ev1.addAP(APClass.make(d,0));
2710 ev1.addAP(APClass.make(d,0));
2711
2712 EmptyVertex ev2 = new EmptyVertex();
2713 ev2.addAP(APClass.make(d,0));
2714 ev2.addAP(APClass.make(d,0));
2715
2716 EmptyVertex ev3 = new EmptyVertex();
2717 ev3.addAP(APClass.make(a,1));
2718 ev3.addAP(APClass.make(a,1));
2719
2720 graph.addVertex(v1);
2721 graph.addVertex(v2);
2722 graph.addVertex(v3);
2723 graph.addVertex(v4);
2724 graph.addVertex(ev3); //These are disordered on purpose
2725 graph.addVertex(ev2);
2726 graph.addVertex(ev1);
2727 graph.addEdge(new Edge(v1.getAP(0), v2.getAP(0),
2728 BondType.TRIPLE));
2729 graph.addEdge(new Edge(v1.getAP(1), v3.getAP(0),
2730 BondType.SINGLE));
2731 graph.addEdge(new Edge(v2.getAP(1), v4.getAP(0)));
2732 graph.addEdge(new Edge(v1.getAP(2), ev1.getAP(1),
2733 BondType.SINGLE));
2734 graph.addEdge(new Edge(v1.getAP(3), ev3.getAP(0),
2735 BondType.NONE));
2736 graph.addEdge(new Edge(ev1.getAP(0), ev2.getAP(0),
2737 BondType.TRIPLE));
2738
2739 // Use this just to verify identify of the graph
2740 /*
2741 System.out.println("WRITING TEST GRAPH A2 in /tmp/test_graph_A2.json");
2742 DenoptimIO.writeGraphToJSON(new File("/tmp/test_graph_A2.json"),
2743 graph);
2744 */
2745 } catch (Throwable t)
2746 {
2747 t.printStackTrace();
2748 System.err.println("FATAL ERROR! Could not make test graph (A). "
2749 + "Please, report this to the development team.");
2750 System.exit(-1);
2751 }
2752
2753 return graph;
2754 }
2755
2756//------------------------------------------------------------------------------
2757
2758 @Test
2759 public void testRemoveCapping() throws Exception
2760 {
2761 DGraph graph = new DGraph();
2762
2763 IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
2764 IAtomContainer iac1 = builder.newAtomContainer();
2765 iac1.addAtom(new Atom("C"));
2766 Fragment v1 = new Fragment(1, iac1, BBType.SCAFFOLD);
2767 v1.addAP(0);
2768 v1.addAP(0);
2769
2770 IAtomContainer iac2 = builder.newAtomContainer();
2771 iac2.addAtom(new Atom("O"));
2772 Fragment v2 = new Fragment(2, iac2, BBType.FRAGMENT);
2773 v2.addAP(0);
2774 v2.addAP(0);
2775
2776 IAtomContainer iac3 = builder.newAtomContainer();
2777 iac3.addAtom(new Atom("H"));
2778 Fragment v3 = new Fragment(3, iac3, BBType.CAP);
2779 v3.addAP(0);
2780
2781 IAtomContainer iac4 = builder.newAtomContainer();
2782 iac4.addAtom(new Atom("H"));
2783 Fragment v4 = new Fragment(4, iac4, BBType.CAP);
2784 v4.addAP(0);
2785
2786 graph.addVertex(v1);
2787 graph.addVertex(v2);
2788 graph.addVertex(v3);
2789 graph.addVertex(v4);
2790 graph.addEdge(new Edge(v1.getAP(0), v2.getAP(0)));
2791 graph.addEdge(new Edge(v1.getAP(1), v3.getAP(0)));
2792 graph.addEdge(new Edge(v2.getAP(1), v4.getAP(0)));
2793
2794 assertEquals(4, graph.getVertexCount(),
2795 "#vertices in graph before removal");
2796 assertTrue(graph == v4.getGraphOwner());
2797
2798 graph.removeCappingGroupsOn(v2);
2799
2800 assertEquals(3, graph.getVertexCount(),
2801 "#vertices in graph before removal");
2802 assertFalse(graph.containsVertex(v4),
2803 "Capping is still contained");
2804 assertTrue(null == v4.getGraphOwner(),
2805 "Owner of removed capping group is null");
2806
2807 DGraph graph2 = new DGraph();
2808
2809 IAtomContainer iac12 = builder.newAtomContainer();
2810 iac12.addAtom(new Atom("C"));
2811 Fragment v21 = new Fragment(21, iac12, BBType.SCAFFOLD);
2812 v21.addAP(0);
2813 v21.addAP(0);
2814
2815 IAtomContainer iac22 = builder.newAtomContainer();
2816 iac22.addAtom(new Atom("O"));
2817 Fragment v22 = new Fragment(22, iac22, BBType.FRAGMENT);
2818 v22.addAP(0);
2819 v22.addAP(0);
2820
2821 IAtomContainer iac23 = builder.newAtomContainer();
2822 iac23.addAtom(new Atom("H"));
2823 Fragment v23 = new Fragment(23, iac23, BBType.CAP);
2824 v23.addAP(0);
2825
2826 IAtomContainer iac24 = builder.newAtomContainer();
2827 iac24.addAtom(new Atom("H"));
2828 Fragment v24 = new Fragment(24, iac24, BBType.CAP);
2829 v24.addAP(0);
2830
2831 graph2.addVertex(v21);
2832 graph2.addVertex(v22);
2833 graph2.addVertex(v23);
2834 graph2.addVertex(v24);
2835 graph2.addEdge(new Edge(v21.getAP(0), v22.getAP(0)));
2836 graph2.addEdge(new Edge(v21.getAP(1), v23.getAP(0)));
2837 graph2.addEdge(new Edge(v22.getAP(1), v24.getAP(0)));
2838
2839 assertEquals(4, graph2.getVertexCount(),
2840 "#vertices in graph before removal (B)");
2841 assertTrue(graph2 == v23.getGraphOwner());
2842 assertTrue(graph2 == v24.getGraphOwner());
2843
2844 graph2.removeCappingGroups();
2845
2846 assertEquals(2, graph2.getVertexCount(),
2847 "#vertices in graph before removal (B)");
2848 assertFalse(graph.containsVertex(v24),
2849 "Capping is still contained (B)");
2850 assertFalse(graph.containsVertex(v23),
2851 "Capping is still contained (C)");
2852 assertTrue(null == v24.getGraphOwner(),
2853 "Owner of removed capping group is null (B)");
2854 assertTrue(null == v23.getGraphOwner(),
2855 "Owner of removed capping group is null (C)");
2856 }
2857
2858//------------------------------------------------------------------------------
2859
2860 private void buildVertexAndConnectToGraph(EmptyVertex v, int apCount,
2861 DGraph graph) throws DENOPTIMException
2862 {
2863 for (int atomPos = 0; atomPos < apCount; atomPos++) {
2864 v.addAP();
2865 }
2866 graph.addVertex(v);
2867 }
2868
2869//------------------------------------------------------------------------------
2870
2871 @Test
2872 public void testFromToJSON() throws Exception
2873 {
2874 DGraph graph = new DGraph();
2875
2876 EmptyVertex v0 = new EmptyVertex(0);
2877 buildVertexAndConnectToGraph(v0, 3, graph);
2878
2879 EmptyVertex v1 = new EmptyVertex(1);
2880 buildVertexAndConnectToGraph(v1, 2, graph);
2881 graph.addEdge(new Edge(v0.getAP(0), v1.getAP(0)));
2882
2883 EmptyVertex v2 = new EmptyVertex(2);
2884 buildVertexAndConnectToGraph(v2, 2, graph);
2885 graph.addEdge(new Edge(v1.getAP(1), v2.getAP(0)));
2886
2887 EmptyVertex v3 = new EmptyVertex(3);
2888 buildVertexAndConnectToGraph(v3, 1, graph);
2889 graph.addEdge(new Edge(v2.getAP(1), v3.getAP(0)));
2890
2891 EmptyVertex v4 = new EmptyVertex(4);
2892 buildVertexAndConnectToGraph(v4, 3, graph);
2893 graph.addEdge(new Edge(v0.getAP(1), v4.getAP(0)));
2894
2895 EmptyVertex v5 = new EmptyVertex(5);
2896 buildVertexAndConnectToGraph(v5, 1, graph);
2897 graph.addEdge(new Edge(v4.getAP(1), v5.getAP(0)));
2898
2899 EmptyVertex v6 = new EmptyVertex(6);
2900 buildVertexAndConnectToGraph(v6, 1, graph);
2901 graph.addEdge(new Edge(v0.getAP(2), v6.getAP(0)));
2902
2903 EmptyVertex v7 = new EmptyVertex(7);
2904 buildVertexAndConnectToGraph(v7, 1, graph);
2905 graph.addEdge(new Edge(v4.getAP(2), v7.getAP(0)));
2906
2907 graph.addRing(new Ring(new ArrayList<>(
2908 Arrays.asList(v5, v4, v0, v1, v2, v3))));
2909
2910 graph.addRing(new Ring(new ArrayList<>(
2911 Arrays.asList(v6, v0, v4, v7))));
2912
2914 ss1.add(v3);
2915 ss1.add(v5);
2916 graph.addSymmetricSetOfVertices(ss1);
2917
2919 ss2.add(v6);
2920 ss2.add(v7);
2921 graph.addSymmetricSetOfVertices(ss2);
2922
2923 String json1 = graph.toJson();
2924
2925 DGraph g2 = DGraph.fromJson(json1);
2926 String json2 = g2.toJson();
2927
2928 assertTrue(json1.equals(json2), "Round-trip via JSON is successful");
2929 }
2930
2931//-----------------------------------------------------------------------------
2932
2933 @Test
2934 public void testGraphIsomorphism() throws Exception
2935 {
2936 FragmentSpace fs = prepare();
2937
2938 DGraph gAempty = new DGraph();
2939 DGraph gBempty = new DGraph();
2940
2941 assertTrue(gAempty.isIsomorphicTo(gAempty),
2942 "self isomorphism on empty graph");
2943 assertTrue(gAempty.isIsomorphicTo(gBempty),
2944 "isomorphism on empty graphs");
2945
2946 DGraph g01 = makeTestGraph0(fs);
2947 DGraph g02 = makeTestGraph0(fs);
2948 assertTrue(g01.isIsomorphicTo(g02),
2949 "single-vertex graph");
2950 assertTrue(g01.isIsomorphicTo(g01.clone()),
2951 "single-vertex graph vs clone");
2952
2953 DGraph g03 = new DGraph();
2954 EmptyVertex v1 = new EmptyVertex();
2955 v1.addAP();
2956 v1.addAP();
2957 String k ="MyKey";
2959 v1.setProperty(k, 123);
2960 g03.addVertex(v1);
2961 EmptyVertex v2 = new EmptyVertex();
2962 v2.addAP();
2963 v2.addAP();
2965 v2.setProperty(k, 456);
2966 g03.appendVertexOnAP(v1.getAP(0), v2.getAP(0));
2967
2968 DGraph g04 = g03.clone();
2969 assertTrue(g03.isIsomorphicTo(g04),
2970 "graph with empty vertexes and same properties");
2971
2972 v2.setProperty(k, 999);
2973 assertFalse(g03.isIsomorphicTo(g04),
2974 "graph with empty vertexes and different properties");
2975
2976 DGraph g11 = makeTestGraph1(fs);
2977 DGraph g12 = makeTestGraph1(fs);
2978 assertTrue(g11.isIsomorphicTo(g12),"two-vertex graph");
2979 assertTrue(g11.isIsomorphicTo(g11.clone()),"two-vertex graph vs clone");
2980
2981 DGraph gD1 = makeTestGraphD(fs);
2982 DGraph gD2 = makeTestGraphD(fs);
2983 assertTrue(gD1.isIsomorphicTo(gD2),"two of same graph D");
2984 assertFalse(gD1.isIsomorphicTo(gAempty),"graph D vs empty graph");
2985 assertFalse(gAempty.isIsomorphicTo(gD1),"empty graph vs graph D");
2986
2987 DGraph gB1 = makeTestGraphB(fs);
2988 assertFalse(gD1.isIsomorphicTo(gB1),"graph D vs graph B");
2989
2990 DGraph gB2 = gB1.clone();
2991 assertTrue(gB1.isIsomorphicTo(gB2),"graph B vs its clone");
2992 }
2993
2994//-----------------------------------------------------------------------------
2995
2996 @Test
2997 public void testExtractSubgraph() throws Exception
2998 {
2999 FragmentSpace fs = prepare();
3000 DGraph graph = makeTestGraphD(fs);
3001 DGraph graphOriginal = makeTestGraphD(fs);
3002
3003 // This takes all graph
3004 DGraph subGraph = graph.extractSubgraph(
3005 graph.getVertexAtPosition(0));
3006 assertTrue(subGraph.isIsomorphicTo(graph), "complete subgraph");
3007 assertTrue(graph.isIsomorphicTo(graphOriginal),
3008 "Original stays the same");
3009
3010 // This takes a subgraph with a ring
3011 DGraph subGraph1 = graph.extractSubgraph(
3012 graph.getVertexAtPosition(1));
3013 DGraph expected1 = makeTestGraphDSub1(fs);
3014
3015 assertTrue(subGraph1.isIsomorphicTo(expected1), "Subgraph1");
3016 assertEquals(0,subGraph1.getSymmetricSetCount(),
3017 "SymmetricSets in subGraph1");
3018 assertEquals(1,subGraph1.getRingCount(),"Rings in subGraph1");
3019 assertTrue(graph.isIsomorphicTo(graphOriginal),
3020 "Original stays the same");
3021
3022 // This takes a subgraph with symmetric set, but no rings
3023 DGraph subGraph2 = graph.extractSubgraph(
3024 graph.getVertexAtPosition(10));
3025 DGraph expected2 = makeTestGraphDSub2(fs);
3026
3027 assertTrue(subGraph2.isIsomorphicTo(expected2), "Subgraph2");
3028 assertEquals(1,subGraph2.getSymmetricSetCount(),
3029 "SymmetricSets in subGraph2");
3030 assertEquals(0,subGraph2.getRingCount(),"Rings in subGraph2");
3031 assertTrue(graph.isIsomorphicTo(graphOriginal),
3032 "Original stays the same");
3033 }
3034
3035//-----------------------------------------------------------------------------
3036
3037 @Test
3038 public void testExtractSubgraphFromCollection() throws Exception
3039 {
3040 FragmentSpace fs = prepare();
3041 DGraph graph = makeTestGraphD(fs);
3042
3043 Set<Vertex> targetVertexes = new HashSet<>();
3044 targetVertexes.add(graph.getVertexAtPosition(1));
3045 targetVertexes.add(graph.getVertexAtPosition(3));
3046
3047 DGraph subGraph = graph.extractSubgraph(targetVertexes);
3048
3049 assertEquals(targetVertexes.size(), subGraph.getVertexCount());
3050 for (Vertex vInTarget : targetVertexes)
3051 {
3052 assertNotNull(subGraph.getVertexWithId(vInTarget.getVertexId()));
3053 }
3054
3055 Set<Edge> connectionToSubgraph = new HashSet<Edge>();
3056 Set<Edge> connectionFromSubgraph = new HashSet<Edge>();
3057 subGraph = graph.extractSubgraph(targetVertexes,
3058 connectionToSubgraph, connectionFromSubgraph);
3059
3060 assertEquals(1, connectionToSubgraph.size());
3061 assertEquals(3, connectionFromSubgraph.size());
3062
3063 // NB: the subgraph contains clones, but the lists of edges contain
3064 // references to the original graph
3065
3066 boolean found0 = false;
3067 for (Edge e : connectionToSubgraph)
3068 {
3069 Vertex inResults = e.getSrcAP().getOwner();
3070 if (graph.getVertexAtPosition(0) == inResults)
3071 found0 = true;
3072 }
3073 assertTrue(found0);
3074
3075 boolean found2 = false;
3076 boolean found4 = false;
3077 boolean found6 = false;
3078 for (Edge e : connectionFromSubgraph)
3079 {
3080 Vertex inResults = e.getTrgAP().getOwner();
3081 if (graph.getVertexAtPosition(2) == inResults)
3082 found2 = true;
3083 if (graph.getVertexAtPosition(4) == inResults)
3084 found4 = true;
3085 if (graph.getVertexAtPosition(6) == inResults)
3086 found6 = true;
3087 }
3088 assertTrue(found2);
3089 assertTrue(found4);
3090 assertTrue(found6);
3091 }
3092
3093//-----------------------------------------------------------------------------
3094
3095 @Test
3096 public void testFindVertex() throws Exception
3097 {
3098 DGraph g = makeTestGraphA2();
3099
3100 List<VertexQuery> allQueries = new ArrayList<VertexQuery>();
3101 List<List<Vertex>> allExpected =
3102 new ArrayList<List<Vertex>>();
3103
3104 VertexQuery q0 = new VertexQuery(null, null, null, null, null, null, null);
3105 List<Vertex> e0 = new ArrayList<Vertex>();
3106 e0.addAll(g.getVertexList());
3107 allQueries.add(q0);
3108 allExpected.add(e0);
3109
3110 VertexQuery q1 = new VertexQuery(
3112 null, null, null, null, null, null);
3113 List<Vertex> e1 = new ArrayList<Vertex>();
3114 e1.add(g.getVertexAtPosition(5));
3115 allQueries.add(q1);
3116 allExpected.add(e1);
3117
3118 VertexQuery q2 = new VertexQuery(
3120 null, null, null, null, null, null);
3121 List<Vertex> e2 = new ArrayList<Vertex>();
3122 e2.add(g.getVertexAtPosition(2));
3123 allQueries.add(q2);
3124 allExpected.add(e2);
3125
3127 null, null, null, null, null);
3128 List<Vertex> e3 = new ArrayList<Vertex>();
3129 e3.add(g.getVertexAtPosition(4));
3130 e3.add(g.getVertexAtPosition(5));
3131 e3.add(g.getVertexAtPosition(6));
3132 allQueries.add(q3);
3133 allExpected.add(e3);
3134
3135 VertexQuery q4 = new VertexQuery(null, null, BBType.CAP,
3136 null, null, null, null);
3137 List<Vertex> e4 = new ArrayList<Vertex>();
3138 e4.add(g.getVertexAtPosition(2));
3139 e4.add(g.getVertexAtPosition(3));
3140 allQueries.add(q4);
3141 allExpected.add(e4);
3142
3143 VertexQuery q5 = new VertexQuery(null, null, null, 2,
3144 null, null, null);
3145 List<Vertex> e5 = new ArrayList<Vertex>();
3146 e5.add(g.getVertexAtPosition(2));
3147 allQueries.add(q5);
3148 allExpected.add(e5);
3149
3150 VertexQuery q6 = new VertexQuery(null, null, null, null, 1,
3151 null, null);
3152 List<Vertex> e6 = new ArrayList<Vertex>();
3153 e6.add(g.getVertexAtPosition(3));
3154 e6.add(g.getVertexAtPosition(5));
3155 allQueries.add(q6);
3156 allExpected.add(e6);
3157
3158 //
3159 // From here: test filters acting on incoming edge
3160 //
3161
3162 EdgeQuery eq7 = new EdgeQuery(null, null, null, null, null, null, null);
3163 VertexQuery q7 = new VertexQuery(null, null, null, null, null,
3164 eq7, eq7);
3165 List<Vertex> e7 = new ArrayList<Vertex>();
3166 e7.addAll(g.getVertexList());
3167 allQueries.add(q7);
3168 allExpected.add(e7);
3169
3171 null, null, null, null, null, null);
3172 VertexQuery q8 = new VertexQuery(null, null, null, null, null,
3173 eq8, null);
3174 List<Vertex> e8 = new ArrayList<Vertex>();
3175 e8.add(g.getVertexAtPosition(3));
3176 allQueries.add(q8);
3177 allExpected.add(e8);
3178
3179 //NB: the trg vertex ID on the incoming vertex is NOT considered
3180 // because it is a redundant condition that should be expressed as
3181 // the VertexQuery vID argument.
3182 EdgeQuery eq9 = new EdgeQuery(null,
3184 null, null, null, null, null);
3185 VertexQuery q9 = new VertexQuery(null, null, null, null, null,
3186 eq9, null);
3187 List<Vertex> e9 = new ArrayList<Vertex>();
3188 e9.addAll(g.getVertexList());
3189 allQueries.add(q9);
3190 allExpected.add(e9);
3191
3192 EdgeQuery eq10 = new EdgeQuery(null, null, 1, null, null, null, null);
3193 VertexQuery q10 = new VertexQuery(null, null, null, null, null,
3194 eq10, null);
3195 List<Vertex> e10 = new ArrayList<Vertex>();
3196 e10.add(g.getVertexAtPosition(2));
3197 e10.add(g.getVertexAtPosition(3));
3198 allQueries.add(q10);
3199 allExpected.add(e10);
3200
3201 EdgeQuery eq11 = new EdgeQuery(null, null, null, 0, null, null, null);
3202 VertexQuery q11 = new VertexQuery(null, null, null, null, null,
3203 eq11, null);
3204 List<Vertex> e11 = new ArrayList<Vertex>();
3205 e11.add(g.getVertexAtPosition(1));
3206 e11.add(g.getVertexAtPosition(2));
3207 e11.add(g.getVertexAtPosition(3));
3208 e11.add(g.getVertexAtPosition(4));
3209 e11.add(g.getVertexAtPosition(5));
3210 allQueries.add(q11);
3211 allExpected.add(e11);
3212
3213 EdgeQuery eq12 = new EdgeQuery(null, null, null, null,
3214 BondType.TRIPLE, null, null);
3215 VertexQuery q12 = new VertexQuery(null, null, null, null, null,
3216 eq12, null);
3217 List<Vertex> e12 = new ArrayList<Vertex>();
3218 e12.add(g.getVertexAtPosition(1));
3219 e12.add(g.getVertexAtPosition(5));
3220 allQueries.add(q12);
3221 allExpected.add(e12);
3222
3223 EdgeQuery eq13 = new EdgeQuery(null, null, null, null, null,
3224 APClass.make(b,1), null);
3225 VertexQuery q13 = new VertexQuery(null, null, null, null, null,
3226 eq13, null);
3227 List<Vertex> e13 = new ArrayList<Vertex>();
3228 e13.add(g.getVertexAtPosition(2));
3229 e13.add(g.getVertexAtPosition(3));
3230 e13.add(g.getVertexAtPosition(6));
3231 allQueries.add(q13);
3232 allExpected.add(e13);
3233
3234 EdgeQuery eq14 = new EdgeQuery(null, null, null, null, null, null,
3235 APClass.make(c,1));
3236 VertexQuery q14 = new VertexQuery(null, null, null, null, null,
3237 eq14, null);
3238 List<Vertex> e14 = new ArrayList<Vertex>();
3239 e14.add(g.getVertexAtPosition(2));
3240 e14.add(g.getVertexAtPosition(3));
3241 allQueries.add(q14);
3242 allExpected.add(e14);
3243
3244 //
3245 // From here: test filters acting on outgoing edge
3246 //
3247
3248 //NB: the src vertex ID on the outging vertex is NOT considered
3249 // because it is a redundant condition that should be expressed as
3250 // the VertexQuery vID argument.
3252 null, null, null, null, null, null);
3253 VertexQuery q15 = new VertexQuery(null, null, null, null, null, null,
3254 eq15);
3255 List<Vertex> e15 = new ArrayList<Vertex>();
3256 e15.addAll(g.getVertexList());
3257 allQueries.add(q15);
3258 allExpected.add(e15);
3259
3260 EdgeQuery eq16 = new EdgeQuery(null,
3262 null, null, null, null, null);
3263 VertexQuery q16 = new VertexQuery(null, null, null, null, null, null,
3264 eq16);
3265 List<Vertex> e16 = new ArrayList<Vertex>();
3266 e16.add(g.getVertexAtPosition(1));
3267 allQueries.add(q16);
3268 allExpected.add(e16);
3269
3270 EdgeQuery eq17 = new EdgeQuery(null, null, 1, null, null, null, null);
3271 VertexQuery q17 = new VertexQuery(null, null, null, null, null, null,
3272 eq17);
3273 List<Vertex> e17 = new ArrayList<Vertex>();
3274 e17.add(g.getVertexAtPosition(0));
3275 e17.add(g.getVertexAtPosition(1));
3276 allQueries.add(q17);
3277 allExpected.add(e17);
3278
3279 EdgeQuery eq18 = new EdgeQuery(null, null, null, 0, null, null, null);
3280 VertexQuery q18 = new VertexQuery(null, null, null, null, null, null,
3281 eq18);
3282 List<Vertex> e18 = new ArrayList<Vertex>();
3283 e18.add(g.getVertexAtPosition(0));
3284 e18.add(g.getVertexAtPosition(1));
3285 e18.add(g.getVertexAtPosition(6));
3286 allQueries.add(q18);
3287 allExpected.add(e18);
3288
3289 EdgeQuery eq19 = new EdgeQuery(null, null, null, null,
3290 BondType.TRIPLE, null, null);
3291 VertexQuery q19 = new VertexQuery(null, null, null, null, null, null,
3292 eq19);
3293 List<Vertex> e19 = new ArrayList<Vertex>();
3294 e19.add(g.getVertexAtPosition(0));
3295 e19.add(g.getVertexAtPosition(6));
3296 allQueries.add(q19);
3297 allExpected.add(e19);
3298
3299 EdgeQuery eq20 = new EdgeQuery(null, null, null, null, null,
3300 APClass.make(b,1), null);
3301 VertexQuery q20 = new VertexQuery(null, null, null, null, null, null,
3302 eq20);
3303 List<Vertex> e20 = new ArrayList<Vertex>();
3304 e20.add(g.getVertexAtPosition(0));
3305 e20.add(g.getVertexAtPosition(1));
3306 allQueries.add(q20);
3307 allExpected.add(e20);
3308
3309 EdgeQuery eq21 = new EdgeQuery(null, null, null, null, null, null,
3310 APClass.make(d,0));
3311 VertexQuery q21 = new VertexQuery(null, null, null, null, null, null,
3312 eq21);
3313 List<Vertex> e21 = new ArrayList<Vertex>();
3314 e21.add(g.getVertexAtPosition(0));
3315 e21.add(g.getVertexAtPosition(6));
3316 allQueries.add(q21);
3317 allExpected.add(e21);
3318
3319 //
3320 // From here: test combinations
3321 //
3322
3323 EdgeQuery eq22in = new EdgeQuery(null, null, null, 0, null, null, null);
3324 EdgeQuery eq22out = new EdgeQuery(null, null, 1,null, null, null, null);
3325 VertexQuery q22 = new VertexQuery(null, null, null, null, null,
3326 eq22in, eq22out);
3327 List<Vertex> e22 = new ArrayList<Vertex>();
3328 e22.add(g.getVertexAtPosition(1));
3329 allQueries.add(q22);
3330 allExpected.add(e22);
3331
3332 EdgeQuery eq23 = new EdgeQuery(null, null, null, null, BondType.TRIPLE,
3333 null, null);
3335 null, null, null, eq23, null);
3336 List<Vertex> e23 = new ArrayList<Vertex>();
3337 e23.add(g.getVertexAtPosition(1));
3338 allQueries.add(q23);
3339 allExpected.add(e23);
3340
3341 for (int i=0; i<allQueries.size(); i++)
3342 {
3343 List<Vertex> matches = g.findVertices(allQueries.get(i),
3344 Logger.getLogger("DummyLogger"));
3345 assertEquals(allExpected.get(i).size(),matches.size(),
3346 "Different number of matched vertexes ("+i+")");
3347 assertTrue(allExpected.get(i).containsAll(matches),
3348 "Inconsistent matches ("+i+")");
3349 }
3350 }
3351
3352//------------------------------------------------------------------------------
3353
3354
3355 @Test
3356 public void testSymmetricSetLabels() throws Exception
3357 {
3358 FragmentSpace fs = prepare();
3359 DGraph g = makeTestGraphB(fs);
3360
3362
3363 Map<Object,Integer> countsPerLabel = new HashMap<Object,Integer>();
3364 for (Vertex v : g.getVertexList())
3365 {
3366 Object label = v.getProperty(DENOPTIMConstants.VRTSYMMSETID);
3367 if (countsPerLabel.containsKey(label))
3368 countsPerLabel.put(label,countsPerLabel.get(label)+1);
3369 else
3370 countsPerLabel.put(label,1);
3371 }
3372
3373 assertEquals(1,countsPerLabel.get(g.getVertexAtPosition(0).getProperty(
3375 assertEquals(2,countsPerLabel.get(g.getVertexAtPosition(1).getProperty(
3377 assertEquals(4,countsPerLabel.get(g.getVertexAtPosition(2).getProperty(
3379 assertEquals(4,countsPerLabel.get(g.getVertexAtPosition(3).getProperty(
3381 assertEquals(1,countsPerLabel.get(g.getVertexAtPosition(4).getProperty(
3383 assertEquals(1,countsPerLabel.get(g.getVertexAtPosition(8).getProperty(
3385 }
3386
3387//------------------------------------------------------------------------------
3388
3389 @Test
3390 public void testConvertSymmetricLabelsToSymmetricSets() throws Exception
3391 {
3392 FragmentSpace fs = prepare();
3393 DGraph g = makeTestGraphE(fs);
3395 "1234-ABC");
3397 "1234-ABC");
3399 "1234-ABC");
3400
3402
3403 assertEquals(2,g.getSymmetricSetCount(),"number of sets");
3404 boolean foundA = false;
3405 boolean foundB = false;
3406 Iterator<SymmetricVertexes> iter = g.getSymSetsIterator();
3407 while (iter.hasNext())
3408 {
3409 SymmetricVertexes ss = iter.next();
3410 if (ss.size() == 2)
3411 foundA = true;
3412 if (ss.size() == 4)
3413 foundB = true;
3414 }
3415 assertTrue(foundA,"Found 2-membered set");
3416 assertTrue(foundB,"Found 4-membered set");
3417
3418 DGraph g2 = makeTestGraphE(fs);
3420 "1234-ABC");
3422 "1234-ABC");
3423
3425
3426 assertEquals(3,g2.getSymmetricSetCount(),"number of sets");
3427 Iterator<SymmetricVertexes> iter2 = g2.getSymSetsIterator();
3428 while (iter2.hasNext())
3429 {
3430 SymmetricVertexes ss = iter2.next();
3431 assertEquals(2,ss.size(),"side of each symmetric sets.");
3432 }
3433 }
3434
3435//------------------------------------------------------------------------------
3436
3437 @Test
3438 public void testGetSymmetricSubGraphs() throws Exception
3439 {
3440 FragmentSpace fs = prepare();
3441 DGraph g = makeTestGraphF(fs);
3442 List<Vertex> sg = new ArrayList<Vertex>();
3443 sg.add(g.getVertexAtPosition(1));
3444 sg.add(g.getVertexAtPosition(3));
3445
3446 List<List<Vertex>> symSubGraphs = g.getSymmetricSubGraphs(sg);
3447
3448 assertEquals(2,symSubGraphs.size(),"Number of subgraphs");
3449 assertEquals(g.getVertexAtPosition(1).getVertexId(),
3450 symSubGraphs.get(0).get(0).getVertexId());
3451 assertEquals(g.getVertexAtPosition(3).getVertexId(),
3452 symSubGraphs.get(0).get(1).getVertexId());
3453 assertEquals(g.getVertexAtPosition(2).getVertexId(),
3454 symSubGraphs.get(1).get(0).getVertexId());
3455 assertEquals(g.getVertexAtPosition(4).getVertexId(),
3456 symSubGraphs.get(1).get(1).getVertexId());
3457
3458
3459 DGraph g2 = makeTestGraphK(fs);
3460 List<Vertex> sg2 = new ArrayList<Vertex>();
3461 sg2.add(g2.getVertexAtPosition(1));
3462 sg2.add(g2.getVertexAtPosition(4));
3463 sg2.add(g2.getVertexAtPosition(12));
3464
3465 /*
3466 * In the second part we check that capping groups are not included.
3467 */
3468
3469 boolean exceptionWhenCappingIsIncluded = false;
3470 try
3471 {
3472 symSubGraphs = g2.getSymmetricSubGraphs(sg2);
3473 } catch (DENOPTIMException e)
3474 {
3475 if (e.getMessage().contains("Capping groups must not be part of "
3476 + "symmetric subgraphs"))
3477 exceptionWhenCappingIsIncluded = true;
3478 }
3479 assertTrue(exceptionWhenCappingIsIncluded,
3480 "Capping groups trigger exception");
3481
3482 sg2 = new ArrayList<Vertex>();
3483 sg2.add(g2.getVertexAtPosition(1));
3484 sg2.add(g2.getVertexAtPosition(4));
3485 symSubGraphs = g2.getSymmetricSubGraphs(sg2);
3486 assertEquals(2,symSubGraphs.size());
3487 assertEquals(2,symSubGraphs.get(0).size());
3488 assertEquals(2,symSubGraphs.get(1).size());
3489 }
3490
3491//------------------------------------------------------------------------------
3492
3493 @Test
3494 public void testGetChildrenTree() throws Exception
3495 {
3496 FragmentSpace fs = prepare();
3497 DGraph g = makeTestGraphD(fs);
3498
3499 List<Vertex> childTree = new ArrayList<Vertex>();
3500 g.getChildrenTree(g.getVertexAtPosition(1), childTree);
3501 assertEquals(6,childTree.size());
3502 assertTrue(childTree.contains(g.getVertexAtPosition(2)));
3503 assertTrue(childTree.contains(g.getVertexAtPosition(3)));
3504 assertTrue(childTree.contains(g.getVertexAtPosition(4)));
3505 assertTrue(childTree.contains(g.getVertexAtPosition(5)));
3506 assertTrue(childTree.contains(g.getVertexAtPosition(6)));
3507 assertTrue(childTree.contains(g.getVertexAtPosition(7)));
3508
3509 childTree = new ArrayList<Vertex>();
3510 g.getChildrenTree(g.getVertexAtPosition(9), childTree, 1, false);
3511 assertEquals(1,childTree.size());
3512 assertTrue(childTree.contains(g.getVertexAtPosition(10)));
3513
3514 childTree = new ArrayList<Vertex>();
3515 g.getChildrenTree(g.getVertexAtPosition(9), childTree, 2, false);
3516 assertEquals(4,childTree.size());
3517 assertTrue(childTree.contains(g.getVertexAtPosition(10)));
3518 assertTrue(childTree.contains(g.getVertexAtPosition(11)));
3519 assertTrue(childTree.contains(g.getVertexAtPosition(12)));
3520 assertTrue(childTree.contains(g.getVertexAtPosition(13)));
3521
3522 childTree = new ArrayList<Vertex>();
3523 g.getChildrenTree(g.getVertexAtPosition(1), childTree, Integer.MAX_VALUE,
3524 true);
3525 assertEquals(3,childTree.size());
3526 assertTrue(childTree.contains(g.getVertexAtPosition(2)));
3527 assertTrue(childTree.contains(g.getVertexAtPosition(3)));
3528 assertTrue(childTree.contains(g.getVertexAtPosition(4)));
3529 }
3530
3531//------------------------------------------------------------------------------
3532
3533 @Test
3534 public void testGetChildrenTreeWithBranchIdentifier() throws Exception
3535 {
3536 FragmentSpace fs = prepare();
3537 DGraph g = makeTestGraphD(fs);
3538
3539 assertNull(g.getBranchIdOfVertexAtPosition(0));
3540 assertNull(g.getBranchIdOfVertexAtPosition(1));
3541 assertNull(g.getBranchIdOfVertexAtPosition(3));
3542
3543 List<Vertex> childTree = new ArrayList<Vertex>();
3544 g.getChildrenTree(g.getVertexAtPosition(0), childTree,
3545 new AtomicInteger(0), new ArrayList<Integer>());
3546
3547 assertEquals(g.getBranchIdOfVertexAtPosition(3),
3549 assertEquals(g.getBranchIdOfVertexAtPosition(2),
3551 assertEquals(g.getBranchIdOfVertexAtPosition(3),
3553 assertEquals(g.getBranchIdOfVertexAtPosition(4),
3555 assertNotEquals(g.getBranchIdOfVertexAtPosition(2),
3557 assertNotEquals(g.getBranchIdOfVertexAtPosition(2),
3559 assertNotEquals(g.getBranchIdOfVertexAtPosition(3),
3561
3562 assertTrue(g.directedPathExists(g.getVertexAtPosition(1),
3563 g.getVertexAtPosition(5)));
3564 assertTrue(g.directedPathExists(g.getVertexAtPosition(9),
3565 g.getVertexAtPosition(13)));
3566 assertFalse(g.directedPathExists(g.getVertexAtPosition(8),
3567 g.getVertexAtPosition(9)));
3568 assertFalse(g.directedPathExists(g.getVertexAtPosition(9),
3569 g.getVertexAtPosition(8)));
3570 assertFalse(g.directedPathExists(g.getVertexAtPosition(5),
3571 g.getVertexAtPosition(1)));
3572 assertFalse(g.directedPathExists(g.getVertexAtPosition(13),
3573 g.getVertexAtPosition(9)));
3574 }
3575
3576//------------------------------------------------------------------------------
3577
3578 @Test
3579 public void testGetInterfaceAPs() throws Exception
3580 {
3581 FragmentSpace fs = prepare();
3582 DGraph g = makeTestGraphI(fs);
3583
3584 List<Vertex> subGraph = new ArrayList<Vertex>();
3585 subGraph.add(g.getVertexAtPosition(0));
3586 subGraph.add(g.getVertexAtPosition(1));
3587
3588 List<AttachmentPoint> expected = new ArrayList<AttachmentPoint>();
3589 expected.add(g.getVertexAtPosition(0).getAP(1));
3590 expected.add(g.getVertexAtPosition(1).getAP(1));
3591
3592 List<AttachmentPoint> interfaceAPs = g.getInterfaceAPs(subGraph);
3593
3594 assertEquals(expected,interfaceAPs);
3595
3596 DGraph innerGraph = ((Template) g.getVertexAtPosition(0))
3597 .getInnerGraph();
3598
3599 subGraph = new ArrayList<Vertex>();
3600 subGraph.add(innerGraph.getVertexAtPosition(0));
3601 subGraph.add(innerGraph.getVertexAtPosition(1));
3602
3603 expected = new ArrayList<AttachmentPoint>();
3604 expected.add(innerGraph.getVertexAtPosition(0).getAP(0));
3605 expected.add(innerGraph.getVertexAtPosition(0).getAP(1));
3606 expected.add(innerGraph.getVertexAtPosition(0).getAP(4));
3607 expected.add(innerGraph.getVertexAtPosition(1).getAP(1));
3608
3609 interfaceAPs = innerGraph.getInterfaceAPs(subGraph);
3610
3611 assertEquals(expected,interfaceAPs);
3612 }
3613
3614//------------------------------------------------------------------------------
3615
3616 @Test
3617 public void testGetSubgraphAPs() throws Exception
3618 {
3619 FragmentSpace fs = prepare();
3620 DGraph g = makeTestGraphI(fs);
3621
3622 DGraph innerGraph = ((Template) g.getVertexAtPosition(0))
3623 .getInnerGraph();
3624
3625 List<Vertex> subGraph = new ArrayList<Vertex>();
3626 subGraph.add(innerGraph.getVertexAtPosition(0));
3627 subGraph.add(innerGraph.getVertexAtPosition(1));
3628
3629 List<AttachmentPoint>expected = new ArrayList<AttachmentPoint>();
3630 expected.add(innerGraph.getVertexAtPosition(0).getAP(0));
3631 expected.add(innerGraph.getVertexAtPosition(0).getAP(1));
3632 expected.add(innerGraph.getVertexAtPosition(0).getAP(2));
3633 expected.add(innerGraph.getVertexAtPosition(0).getAP(4));
3634 expected.add(innerGraph.getVertexAtPosition(1).getAP(1));
3635
3636 List<AttachmentPoint> interfaceAPs = innerGraph.getSubgraphAPs(
3637 subGraph);
3638
3639 assertEquals(expected,interfaceAPs);
3640 }
3641
3642//------------------------------------------------------------------------------
3643
3644 public DGraph[] makeIsostructuralGraphs() throws Exception
3645 {
3646 String unqProp = "UNQPROP";
3647 EmptyVertex rcvA1 = new EmptyVertex(11002);
3648 rcvA1.addAP(APCA);
3649 rcvA1.setAsRCV(true);
3650 EmptyVertex rcvA2 = new EmptyVertex(11003);
3651 rcvA2.addAP(APCA);
3652 rcvA2.setAsRCV(true);
3653 EmptyVertex vA0 = new EmptyVertex(10000);
3654 vA0.addAP(APCA);
3655 vA0.addAP(APCA);
3656 vA0.addAP(APCB);
3657 vA0.setUniquefyingProperty(unqProp);
3658 vA0.setProperty(unqProp, 111);
3659 EmptyVertex vA1 = new EmptyVertex(10001);
3660 vA1.addAP(APCA);
3661 vA1.addAP(APCA);
3662 vA1.setUniquefyingProperty(unqProp);
3663 vA1.setProperty(unqProp, 222);
3664 EmptyVertex vA2= new EmptyVertex(10002);
3665 vA2.addAP(APCA);
3666 vA2.addAP(APCA);
3667 EmptyVertex vA3 = new EmptyVertex(10003);
3668 vA3.addAP(APCA);
3669 vA3.addAP(APCA);
3670 vA3.addAP(APCB);
3671 DGraph g3A = new DGraph();
3672 g3A.addVertex(vA0);
3673 g3A.appendVertexOnAP(vA0.getAP(0), vA1.getAP(0));
3674 g3A.appendVertexOnAP(vA1.getAP(1), vA2.getAP(0));
3675 g3A.appendVertexOnAP(vA2.getAP(1), vA3.getAP(0));
3676 g3A.appendVertexOnAP(vA3.getAP(1), rcvA1.getAP(0));
3677 g3A.appendVertexOnAP(vA0.getAP(1), rcvA2.getAP(0));
3678 g3A.addRing(rcvA1, rcvA2);
3679
3680 // now build second
3681 EmptyVertex rcvB1 = new EmptyVertex(21002);
3682 rcvB1.addAP(APCA);
3683 rcvB1.setAsRCV(true);
3684 EmptyVertex rcvB2 = new EmptyVertex(21003);
3685 rcvB2.addAP(APCA);
3686 rcvB2.setAsRCV(true);
3687 EmptyVertex vB0 = new EmptyVertex(20000);
3688 vB0.addAP(APCA);
3689 vB0.addAP(APCA);
3690 vB0.addAP(APCB);
3691 vA0.setUniquefyingProperty(unqProp);
3692 vA0.setProperty(unqProp, 333);
3693 EmptyVertex vB1 = new EmptyVertex(20001);
3694 vB1.addAP(APCA);
3695 vB1.addAP(APCA);
3696 vA0.setUniquefyingProperty(unqProp);
3697 vA0.setProperty(unqProp, 444);
3698 EmptyVertex vB2= new EmptyVertex(20002);
3699 vB2.addAP(APCA);
3700 vB2.addAP(APCA);
3701 EmptyVertex vB3 = new EmptyVertex(20003);
3702 vB3.addAP(APCA);
3703 vB3.addAP(APCA);
3704 vB3.addAP(APCB);
3705 DGraph g3B = new DGraph();
3706 g3B.addVertex(vB1);
3707 g3B.appendVertexOnAP(vB1.getAP(1), vB2.getAP(0));
3708 g3B.appendVertexOnAP(vB2.getAP(1), vB3.getAP(0));
3709 g3B.appendVertexOnAP(vB3.getAP(1), vB0.getAP(1));
3710 g3B.appendVertexOnAP(vB0.getAP(0), rcvB1.getAP(0));
3711 g3B.appendVertexOnAP(vB1.getAP(0), rcvB2.getAP(0));
3712 g3B.addRing(rcvB1, rcvB2);
3713
3714 DGraph[] pair = new DGraph[2];
3715 pair[0] = g3A;
3716 pair[1] = g3B;
3717 return pair;
3718 }
3719
3720//------------------------------------------------------------------------------
3721
3722 @Test
3723 public void testIsIsostructuralTo() throws Exception
3724 {
3725 FragmentSpace fs = prepare();
3726
3727 DGraph gAempty = new DGraph();
3728 DGraph gBempty = new DGraph();
3729
3730 assertTrue(gAempty.isIsostructuralTo(gAempty));
3731 assertTrue(gAempty.isIsostructuralTo(gBempty));
3732
3733 DGraph g01 = makeTestGraph0(fs);
3734 DGraph g02 = makeTestGraph0(fs);
3735 assertTrue(g01.isIsostructuralTo(g02));
3736 assertTrue(g01.isIsostructuralTo(g01.clone()));
3737
3738 DGraph g11 = makeTestGraph1(fs);
3739 DGraph g12 = makeTestGraph1(fs);
3740 assertTrue(g11.isIsostructuralTo(g12));
3741 assertFalse(g11.isIsostructuralTo(g01));
3742 assertFalse(g11.isIsostructuralTo(g02));
3743 assertTrue(g11.isIsostructuralTo(g11.clone()));
3744
3745 DGraph gD1 = makeTestGraphD(fs);
3746 DGraph gD2 = makeTestGraphD(fs);
3747 assertTrue(gD1.isIsostructuralTo(gD2));
3748 assertFalse(gD1.isIsostructuralTo(gAempty));
3749 assertFalse(gAempty.isIsostructuralTo(gD1));
3750
3751 DGraph gB1 = makeTestGraphB(fs);
3752 assertFalse(gD1.isIsostructuralTo(gB1));
3753
3754 DGraph gB2 = gB1.clone();
3755 assertTrue(gB1.isIsostructuralTo(gB2));
3756
3757 // Up to here we checked consistency with isIsomorficTo().
3758 // Now, make a pair of graphs that are not isomorphic by replacing one
3759 // of the vertexes with a new vertex that does not satisfy sameAs()
3760 DGraph g1 = makeTestGraphDSub1(fs);
3761 DGraph g2 = makeTestGraphDSub1(fs);
3762
3763 EmptyVertex v1 = new EmptyVertex(10001);
3764 v1.addAP(APCD);
3765 v1.addAP(APCC);
3766 v1.setUniquefyingProperty("blabla123");
3767 v1.setProperty("blabla123", 123);
3768
3769 DGraph incomingSubGraph = new DGraph();
3770 incomingSubGraph.addVertex(v1);
3771
3772 LinkedHashMap<AttachmentPoint,AttachmentPoint> apMap =
3773 new LinkedHashMap<AttachmentPoint,AttachmentPoint>();
3774 apMap.put(g2.getVertexAtPosition(1).getAP(0), v1.getAP(1));
3775 apMap.put(g2.getVertexAtPosition(1).getAP(1), v1.getAP(0));
3776
3777 List<Vertex> toReplace = new ArrayList<Vertex>();
3778 toReplace.add(g2.getVertexAtPosition(1));
3779 g2.replaceSingleSubGraph(toReplace, incomingSubGraph, apMap);
3780
3781 assertFalse(g1.isIsomorphicTo(g2));
3782 assertTrue(g1.isIsostructuralTo(g2));
3783
3784 // Change structure by adding a bifurcation
3785 EmptyVertex v2 = new EmptyVertex(100002);
3786 v2.addAP(APCD);
3787 v2.addAP(APCC);
3788 v2.addAP(APCC);
3789 v2.setUniquefyingProperty("blabla456");
3790 v2.setProperty("blabla456", 456);
3791 incomingSubGraph = new DGraph();
3792 incomingSubGraph.addVertex(v2);
3793 apMap = new LinkedHashMap<AttachmentPoint,AttachmentPoint>();
3794 apMap.put(g2.getVertexAtPosition(2).getAP(0), v1.getAP(1));
3795 apMap.put(g2.getVertexAtPosition(2).getAP(1), v1.getAP(0));
3796 toReplace = new ArrayList<Vertex>();
3797 toReplace.add(g2.getVertexAtPosition(2));
3798 g2.replaceSingleSubGraph(toReplace, incomingSubGraph, apMap);
3799
3800 assertFalse(g1.isIsomorphicTo(g2));
3801 assertFalse(g1.isIsostructuralTo(g2));
3802
3803 // Change graph retaining structure: move ring closure along ring.
3805 DGraph gisA = pair[0];
3806 DGraph gisB = pair[1];
3807 assertFalse(gisA.isIsomorphicTo(gisB));
3808 assertTrue(gisA.isIsostructuralTo(gisB));
3809 }
3810
3811//------------------------------------------------------------------------------
3812
3813 @Test
3814 public void testGetEdgesWithSrcOrTrg() throws Exception
3815 {
3816 FragmentSpace fs = prepare();
3817 DGraph graph = makeTestGraphF(fs);
3818 Vertex v = graph.getVertexAtPosition(5);
3819
3820 List<Edge> egdesFrom = graph.getEdgesWithSrc(v);
3821 assertEquals(2, egdesFrom.size());
3822 assertTrue(graph.getVertexAtPosition(6) ==
3823 egdesFrom.get(0).getTrgAP().getOwner());
3824 assertTrue(graph.getVertexAtPosition(7) ==
3825 egdesFrom.get(1).getTrgAP().getOwner());
3826
3827 List<Edge> egdesTo = graph.getEdgesWithTrg(v);
3828 assertEquals(1, egdesTo.size());
3829 assertTrue(graph.getVertexAtPosition(0) ==
3830 egdesTo.get(0).getSrcAP().getOwner());
3831 }
3832
3833//------------------------------------------------------------------------------
3834
3835 @Test
3836 public void testEmbedPatternsInTemplates() throws Exception
3837 {
3838 FragmentSpace fs = prepare();
3839 DGraph graph = makeTestGraphL(fs);
3840
3841 DGraph graphWithTmpls = graph.embedPatternsInTemplates(
3842 GraphPattern.RING, fs);
3843
3844 assertEquals(7, graphWithTmpls.getVertexCount());
3845 assertEquals(6, graphWithTmpls.getEdgeCount());
3846 assertEquals(0, graphWithTmpls.getRingCount());
3847 List<Vertex> templates = graphWithTmpls.getVertexList()
3848 .stream()
3849 .filter(v -> v instanceof Template)
3850 .collect(Collectors.toList());
3851 assertEquals(2, templates.size());
3852 assertEquals(1, templates.stream()
3853 .filter(t -> t.getBuildingBlockType() == BBType.SCAFFOLD)
3854 .count());
3855 assertEquals(1, templates.stream()
3856 .filter(t -> t.getBuildingBlockType() == BBType.FRAGMENT)
3857 .count());
3858 }
3859
3860//------------------------------------------------------------------------------
3861
3891 {
3892 EmptyVertex v0 = new EmptyVertex(0);
3893 v0.addAP(APCA);
3894 v0.addAP(APCB);
3895 v0.addAP(APCA);
3896 v0.addAP(APCB);
3898 Arrays.asList(v0.getAP(0), v0.getAP(2))));
3900 Arrays.asList(v0.getAP(1), v0.getAP(3))));
3902
3903 EmptyVertex v1 = new EmptyVertex(1);
3904 v1.addAP(APCB);
3905 v1.addAP(APCA);
3906 v1.addAP(APCB);
3907 v1.addAP(APCB);
3909 Arrays.asList(v1.getAP(0), v1.getAP(2), v1.getAP(3))));
3910
3911 EmptyVertex v2 = v1.clone();
3912 v2.setVertexId(2);
3913
3914 EmptyVertex v3 = new EmptyVertex(3);
3915 v3.addAP(APCB);
3916
3917 EmptyVertex v4 = v3.clone();
3918 EmptyVertex v5 = v3.clone();
3919 EmptyVertex v6 = v3.clone();
3920 EmptyVertex v7 = v3.clone();
3921 EmptyVertex v8 = v3.clone();
3922 EmptyVertex v9 = v3.clone();
3923 EmptyVertex v10 = v3.clone();
3924 v4.setVertexId(4);
3925 v5.setVertexId(5);
3926 v6.setVertexId(6);
3927 v7.setVertexId(7);
3928 v8.setVertexId(8);
3929 v9.setVertexId(9);
3930 v10.setVertexId(10);
3931
3932 DGraph g = new DGraph();
3933 g.addVertex(v0);
3934 g.appendVertexOnAP(v0.getAP(0), v1.getAP(1));
3935 g.appendVertexOnAP(v0.getAP(2), v2.getAP(1));
3936 g.appendVertexOnAP(v1.getAP(0), v3.getAP(0));
3937 g.appendVertexOnAP(v1.getAP(2), v4.getAP(0));
3938 g.appendVertexOnAP(v1.getAP(3), v5.getAP(0));
3939 g.appendVertexOnAP(v2.getAP(0), v6.getAP(0));
3940 g.appendVertexOnAP(v2.getAP(2), v7.getAP(0));
3941 g.appendVertexOnAP(v2.getAP(3), v8.getAP(0));
3942 g.appendVertexOnAP(v0.getAP(1), v9.getAP(0));
3943 g.appendVertexOnAP(v0.getAP(3), v10.getAP(0));
3944
3945 return g;
3946 }
3947
3948//------------------------------------------------------------------------------
3949
3979 {
3980 EmptyVertex v0 = new EmptyVertex(0);
3981 v0.addAP(APCB);
3982 v0.addAP(APCB);
3983 v0.addAP(APCB);
3984 v0.addAP(APCB);
3985 v0.addSymmetricAPSet(new SymmetricAPs(Arrays.asList(
3986 v0.getAP(0), v0.getAP(1), v0.getAP(2), v0.getAP(3))));
3987
3988 EmptyVertex v1 = v0.clone();
3989 EmptyVertex v2 = v0.clone();
3990 EmptyVertex v9 = v0.clone();
3991 v1.setVertexId(1);
3992 v2.setVertexId(2);
3993 v9.setVertexId(9);
3994
3999
4000 EmptyVertex v3 = new EmptyVertex(3);
4001 v3.addAP(APCB);
4002
4003 EmptyVertex v4 = v3.clone();
4004 EmptyVertex v5 = v3.clone();
4005 EmptyVertex v6 = v3.clone();
4006 EmptyVertex v7 = v3.clone();
4007 v4.setVertexId(4);
4008 v5.setVertexId(5);
4009 v6.setVertexId(6);
4010 v7.setVertexId(7);;
4011
4012 DGraph g = new DGraph();
4013 g.addVertex(v0);
4014 g.appendVertexOnAP(v0.getAP(0), v1.getAP(1));
4015 g.appendVertexOnAP(v0.getAP(2), v2.getAP(1));
4016 g.appendVertexOnAP(v1.getAP(0), v3.getAP(0));
4017 g.appendVertexOnAP(v1.getAP(2), v4.getAP(0));
4018 g.appendVertexOnAP(v1.getAP(3), v5.getAP(0));
4019 g.appendVertexOnAP(v2.getAP(0), v6.getAP(0));
4020 g.appendVertexOnAP(v2.getAP(2), v7.getAP(0));
4021 // Warning added here just to avoid messing the order of vertexes
4022 g.appendVertexOnAP(v0.getAP(1), v9.getAP(1));
4023
4024 return g;
4025 }
4026
4027//------------------------------------------------------------------------------
4028
4029 @Test
4030 public void testDetectSymVertexSets() throws Exception
4031 {
4032 prepare();
4033 DGraph graph = makeTestGraphM();
4034
4035 assertTrue(graph.detectSymVertexSets());
4036 assertEquals(3, graph.getSymmetricSetCount());
4037
4038 SymmetricVertexes symVrtxs = graph.getSymSetForVertex(
4039 graph.getVertexAtPosition(0));
4040 assertEquals(0, symVrtxs.size());
4041
4042 symVrtxs = graph.getSymSetForVertex(graph.getVertexAtPosition(1));
4043 assertEquals(2, symVrtxs.size());
4044 assertTrue(symVrtxs.contains(graph.getVertexAtPosition(1)));
4045 assertTrue(symVrtxs.contains(graph.getVertexAtPosition(2)));
4046
4047 symVrtxs = graph.getSymSetForVertex(graph.getVertexAtPosition(3));
4048 assertEquals(6, symVrtxs.size());
4049 assertTrue(symVrtxs.contains(graph.getVertexAtPosition(3)));
4050 assertTrue(symVrtxs.contains(graph.getVertexAtPosition(4)));
4051 assertTrue(symVrtxs.contains(graph.getVertexAtPosition(5)));
4052 assertTrue(symVrtxs.contains(graph.getVertexAtPosition(6)));
4053 assertTrue(symVrtxs.contains(graph.getVertexAtPosition(7)));
4054 assertTrue(symVrtxs.contains(graph.getVertexAtPosition(8)));
4055
4056 symVrtxs = graph.getSymSetForVertex(graph.getVertexAtPosition(9));
4057 assertEquals(2, symVrtxs.size());
4058 assertTrue(symVrtxs.contains(graph.getVertexAtPosition(9)));
4059 assertTrue(symVrtxs.contains(graph.getVertexAtPosition(10)));
4060 }
4061
4062//------------------------------------------------------------------------------
4063
4064
4065}
General set of constants used in DENOPTIM.
static final Object VRTSYMMSETID
Property of Vertex used to keep mark symmetric vertexes during graph operations and before defining t...
Class defining a space of building blocks.
void appendVertexToLibrary(Vertex v, Vertex.BBType bbt, ArrayList< Vertex > library)
Takes a vertex and add it to a given library.
void setAPclassBasedApproach(boolean useAPC)
Set the fragment space to behave according to APClass-based approach.
ArrayList< Vertex > getCappingLibrary()
ArrayList< Vertex > getScaffoldLibrary()
ArrayList< Vertex > getFragmentLibrary()
Parameters defining the fragment space.
static final APClass RCACLASSPLUS
Conventional class of attachment points on ring-closing vertexes.
Definition: APClass.java:85
static final APClass RCACLASSMINUS
Conventional class of attachment points on ring-closing vertexes.
Definition: APClass.java:92
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
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....
Container for the list of vertices and the edges that connect them.
Definition: DGraph.java:102
String toJson()
Produces a string that represents this graph and that adheres to the JSON format.
Definition: DGraph.java:6926
boolean replaceVertex(Vertex vertex, int bbId, BBType bbt, LinkedHashMap< Integer, Integer > apIdMap, FragmentSpace fragSpace)
Replaced a given vertex belonging to this graph with a new vertex generated specifically for this pur...
Definition: DGraph.java:2487
Vertex getVertexWithId(long vid)
Searches for a vertex with the given identifier.
Definition: DGraph.java:2811
int getSymmetricSetCount()
Returns the number of symmetric sets of vertices.
Definition: DGraph.java:321
Vertex getSourceVertex()
Identifies and return the vertex from which the spanning tree originates.
Definition: DGraph.java:968
DGraph extractSubgraph(int index)
Creates a new graph that corresponds to the subgraph of this graph when exploring the spanning tree f...
Definition: DGraph.java:4487
boolean containsVertex(Vertex v)
Check if this graph contains the specified vertex.
Definition: DGraph.java:2786
boolean isIsomorphicTo(DGraph other)
Checks if this graph is "DENOPTIM-isomorphic" to the other one given.
Definition: DGraph.java:3682
ArrayList< AttachmentPoint > getAvailableAPs()
Returns the list of available attachment points contained in this graph.
Definition: DGraph.java:4217
void addVertex(Vertex vertex)
Appends a vertex to this graph without creating any edge.
Definition: DGraph.java:1325
List< ClosableChain > closableChains
The potentially closable chains of vertices.
Definition: DGraph.java:121
DGraph embedPatternsInTemplates(GraphPattern pattern, FragmentSpace fragSpace)
Searches for the given pattern type and generated a new graph where each set of (clones of) vertexes ...
Definition: DGraph.java:4845
void getChildrenTree(Vertex vertex, List< Vertex > children)
Gets all the children of the current vertex recursively.
Definition: DGraph.java:3000
void removeVertex(Vertex vertex)
Remove a vertex from this graph.
Definition: DGraph.java:1347
Iterator< SymmetricVertexes > getSymSetsIterator()
Get an iterator for the sets of symmetrically related vertices.
Definition: DGraph.java:332
ArrayList< Vertex > getRCVertices()
Search for ring closing vertices: vertices that contain only a RingClosingAttractor
Definition: DGraph.java:1190
List< List< Vertex > > getSymmetricSubGraphs(List< Vertex > subGrpVrtxs)
We assume that the subgraph is a continuously connected, directed graph.
Definition: DGraph.java:2045
List< Vertex > gVertices
The vertices belonging to this graph.
Definition: DGraph.java:106
Vertex getVertexAtPosition(int pos)
Returns the vertex that is in the given position of the list of vertices belonging to this graph.
Definition: DGraph.java:2743
List< Edge > getEdgesWithTrg(Vertex v)
Returns the list of edges that arrive from the given vertex, i.e., edges where the trgAP is owned by ...
Definition: DGraph.java:1033
static DGraph getEmbeddedGraphInClone(DGraph graphY, DGraph graphB, List< Template > path)
Searches for a graphs (X) embedded at any level in a graph (Y) by knowing.
Definition: DGraph.java:7351
List< Ring > gRings
The rings defined in this graph.
Definition: DGraph.java:116
boolean directedPathExists(Vertex src, Vertex trg)
Uses branch identifiers to define is two vertices are in such a relation that allows the drawing of a...
Definition: DGraph.java:3229
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:6005
List< Vertex > getVertexList()
Definition: DGraph.java:947
void convertSymmetricLabelsToSymmetricSets()
Looks for any symmetric labels, creates symmetric sets that collect the same information,...
Definition: DGraph.java:1828
List< AttachmentPoint > getInterfaceAPs(List< Vertex > subGraphB)
Searches for all AttachmentPoints that represent the interface between a subgraph,...
Definition: DGraph.java:7379
DGraph clone()
Returns almost "deep-copy" of this graph.
Definition: DGraph.java:3415
void removeCappingGroups(List< Vertex > lstVerts)
Remove capping groups that belong to this graph and are in the given list.
Definition: DGraph.java:4343
void renumberGraphVertices()
Reassign vertex IDs to all vertices of this graph.
Definition: DGraph.java:5512
void reassignSymmetricLabels()
Marks the vertices of this graph with a string that is consistent for all vertices that belong to sym...
Definition: DGraph.java:1796
List< Edge > gEdges
The edges belonging to this graph.
Definition: DGraph.java:111
void replaceUnusedRCVsWithCapps(FragmentSpace fragSpace)
Removes unused ring-closing vertices.
Definition: DGraph.java:1754
boolean sameAs(DGraph other, StringBuilder reason)
Compare this and another graph ignoring the vertex IDs.
Definition: DGraph.java:3894
int getLevel(Vertex v)
Calculates the level of a vertex in this graph.
Definition: DGraph.java:5555
void removeCappingGroupsOn(Vertex vertex)
Remove capping groups on the given vertex of this graph.
Definition: DGraph.java:4313
static DGraph fromJson(String json)
Reads a JSON string and returns an instance of this class.
Definition: DGraph.java:6951
List< Edge > getEdgesWithSrc(Vertex v)
Returns the list of edges that depart from the given vertex, i.e., edges where the srcAP is owned by ...
Definition: DGraph.java:1012
List< Ring > getRings()
Definition: DGraph.java:999
void addSymmetricSetOfVertices(SymmetricVertexes symSet)
Adds a symmetric set of vertices to this graph.
Definition: DGraph.java:889
SymmetricVertexes getSymSetForVertex(Vertex v)
Returns the set of vertexes symmetric to the given one.
Definition: DGraph.java:861
List< AttachmentPoint > getSubgraphAPs(List< Vertex > subGraphB)
Searches for all AttachmentPoints that are owned by vertices in a subgraph but either available or us...
Definition: DGraph.java:7414
void addRing(Ring ring)
Definition: DGraph.java:1258
List< Vertex > getMutableSites()
A list of mutation sites from within this graph.
Definition: DGraph.java:6858
String localMsg
A free-format string used to record simple properties in the graph.
Definition: DGraph.java:140
void addEdge(Edge edge)
Adds the edge to the list of edges belonging to this graph.
Definition: DGraph.java:1249
boolean replaceSingleSubGraph(List< Vertex > subGrpVrtxs, DGraph newSubGraph, LinkedHashMap< AttachmentPoint, AttachmentPoint > apMap)
Replaced the subgraph represented by a given collection of vertices that belong to this graph.
Definition: DGraph.java:2183
List< Template > getEmbeddingPath()
Find the path that one has to traverse to reach this graph from any template-embedding structure.
Definition: DGraph.java:7231
List< Integer > getBranchIdOfVertexAtPosition(int i)
Returns the branch identifier.
Definition: DGraph.java:3170
boolean isIsostructuralTo(DGraph other)
Checks if this graph is "DENOPTIM-isostructural" to the other one given.
Definition: DGraph.java:3809
boolean detectSymVertexSets()
Detects and groups symmetric sets of Vertexes in the graph based on unique identification and path en...
Definition: DGraph.java:368
ArrayList< Vertex > findVertices(VertexQuery vrtxQuery, Logger logger)
Filters a list of vertices according to a query.
Definition: DGraph.java:6294
Unit test for DENOPTIMGraph.
Definition: DGraphTest.java:73
DGraph makeDisorderedGraph(FragmentSpace fs)
Makes a graph with disordered list of vertexes, i.e., the first vertex is not the source.
static DGraph makeTestGraphM()
Returns a graph with definition of symmetric vertexes and symmetric APs meant for testing purposes.
DGraph makeTestGraphG(FragmentSpace fs)
Creates a test graph that looks like this:
static DGraph makeDeeplyEmbeddedGraph()
Returns a graph that contains a 10-layered recursive structure.
static DGraph makeTestGraphA2()
Build a graph meant to be used in unit tests.
DGraph makeTestGraphDSub2(FragmentSpace fs)
Creates a test graph that looks like this:
void buildVertexAndConnectToGraph(EmptyVertex v, int apCount, DGraph graph)
void testGetAvailableAPs_returnsListOfAvailableAPs()
DGraph makeTestGraphD(FragmentSpace fs)
Creates a test graph that looks like this:
DGraph makeTestGraphE(FragmentSpace fs)
Creates a test graph that looks like this:
static DGraph makeTestGraph0(FragmentSpace fs)
Build a graph meant to be used in unit tests.
DGraph makeTestGraphL(FragmentSpace fs)
Creates a test graph that looks like this:
DGraph makeTestGraphI(FragmentSpace fs)
Creates a test graph that looks like this:
static DGraph makeTestGraphA()
Build a graph meant to be used in unit tests.
DGraph makeTestGraphH(FragmentSpace fs)
Creates a test graph that looks like this:
DGraph makeTestGraphB(FragmentSpace fs)
Creates a test graph that looks like this:
void testConvertSymmetricLabelsToSymmetricSets()
DGraph makeTestGraphJ(FragmentSpace fs)
Creates a test graph that looks like this:
static FragmentSpace prepare()
Definition: DGraphTest.java:81
DGraph makeTestGraphK(FragmentSpace fs)
Creates a test graph that looks like this:
DGraph makeTestGraphDSub1(FragmentSpace fs)
Creates a test graph that looks like this:
void testGetChildrenTreeWithBranchIdentifier()
DGraph makeTestGraphF(FragmentSpace fs)
Creates a test graph that looks like this:
static DGraph makeTestGraphN()
Returns a graph with peculiar definition of symmetric vertexes and symmetric APs meant for testing pu...
DGraph[] makeIsostructuralGraphs()
DGraph makeTestGraphC(FragmentSpace fs)
Creates a test graph that looks like this:
static DGraph makeTestGraph1(FragmentSpace fs)
Build a graph meant to be used in unit tests.
This class represents the edge between two vertices.
Definition: Edge.java:38
A query for edges: a list of properties that target edges should possess in order to match this query...
Definition: EdgeQuery.java:28
An empty vertex has the behaviors of a vertex, but has no molecular structure.
void addSymmetricAPSet(SymmetricAPs symAPs)
EmptyVertex clone()
Returns a deep-copy of this vertex.
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
void addBond(IBond bond)
Definition: Fragment.java:871
void addAtom(IAtom atom)
Definition: Fragment.java:836
void projectAPsToProperties()
Finds the DENOPTIMAttachmentPoint objects defined as properties of the atoms in this container,...
Definition: Fragment.java:693
This class represents the closure of a ring in a spanning tree.
Definition: Ring.java:40
Vertex getTailVertex()
Definition: Ring.java:95
int getDistance(Vertex v1, Vertex v2)
Measures how many edges there are between two edges along the sequence of vertices that defined this ...
Definition: Ring.java:325
Vertex getHeadVertex()
Definition: Ring.java:83
A collection of AttachmentPoints that are related by a relation that we call "symmetry",...
boolean add(T item)
Adds an item to this list, if not already present.
A collection of Vertexs that are related by a relation that we call "symmetry", even though this clas...
void setInnerGraph(DGraph innerGraph)
Definition: Template.java:298
static Template getTestTemplate(ContractLevel contractLevel)
Method meant for devel phase only.
Definition: Template.java:172
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
Definition: Vertex.java:62
int getBuildingBlockId()
Returns the index of the building block that should correspond to the position of the building block ...
Definition: Vertex.java:305
void setVertexId(long vertexId2)
Definition: Vertex.java:282
Vertex.BBType getBuildingBlockType()
Definition: Vertex.java:319
void setAsRCV(boolean isRCV)
Definition: Vertex.java:275
DGraph getGraphOwner()
Returns the graph this vertex belongs to or null.
Definition: Vertex.java:852
abstract List< AttachmentPoint > getAttachmentPoints()
void setBuildingBlockId(int buildingBlockId)
Definition: Vertex.java:312
Object getProperty(Object property)
Definition: Vertex.java:1224
void setUniquefyingProperty(String key)
Add the given key among the properties that are checked for equality when comparing vertices with the...
Definition: Vertex.java:1200
void setBuildingBlockType(Vertex.BBType buildingBlockType)
Definition: Vertex.java:326
void setProperty(Object key, Object property)
Definition: Vertex.java:1236
AttachmentPoint getAP(int i)
Get attachment point i on this vertex.
Definition: Vertex.java:1008
static Vertex newVertexFromLibrary(int bbId, Vertex.BBType bbt, FragmentSpace fragSpace)
Builds a new molecular fragment kind of vertex.
Definition: Vertex.java:215
Query for searching vertices.
This object represents a path in a DGraph.
List< Edge > getEdgesPath()
Returns the list of edges involved.
Possible chemical bond types an edge can represent.
Definition: Edge.java:303
Enum specifying to what extent the template's inner graph can be changed.
Definition: Template.java:104
FREE
Inner graphs are free to change within the confines of the required AttachmentPoints.
Definition: Template.java:109
FIXED
Inner graphs are effectively equivalent to the Fragment class, as no change in the inner structure is...
Definition: Template.java:116
The type of building block.
Definition: Vertex.java:87
Flag declaring the type of Vertex implementation.
Definition: Vertex.java:173
Types of mutation defined in relation to what happens to the target vertex (i.e., the actual mutation...