$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(1+100*embeddingLevel);
1295 v0.addAP(APCA);
1296 v0.addAP(APCB);
1297 v0.addAP(APCC);
1298 EmptyVertex v1 = new EmptyVertex(2+100*embeddingLevel);
1299 v1.addAP(APCB);
1300 v1.addAP(APCA);
1301 v1.addAP(APCD);
1302 EmptyVertex v2 = new EmptyVertex(3+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.setVertexId(5+100*embeddingLevel);
1310 t.setInnerGraph(g);
1311
1312 refToPrevGraph.appendVertexOnAP(refToPRevVrtx.getAP(0), t.getAP(1));
1313
1314 refToPrevGraph = g;
1315 refToPRevVrtx = v0;
1316 }
1317 return gOut;
1318 }
1319
1320//------------------------------------------------------------------------------
1321
1322 @Test
1323 public void testRemoveUnusedRCVs() throws Exception
1324 {
1325 APClass a0 = APClass.make("a",0,BondType.SINGLE);
1326 APClass b0 = APClass.make("b",0,BondType.SINGLE);
1327 APClass h0 = APClass.make("h",0,BondType.SINGLE);
1330
1331 HashMap<APClass,ArrayList<APClass>> cpMap =
1332 new HashMap<APClass,ArrayList<APClass>>();
1333 cpMap.put(a0, new ArrayList<APClass>(Arrays.asList(a0, b0)));
1334 HashMap<APClass,APClass> capMap = new HashMap<APClass,APClass>();
1335 capMap.put(a0, h0);
1336 HashSet<APClass> forbEnds = new HashSet<APClass>();
1337 forbEnds.add(b0);
1338
1339 Fragment frg1 = new Fragment();
1340 IAtom a1 = new Atom("C", new Point3d(new double[]{0.0, 0.0, 0.0}));
1341 IAtom a2 = new Atom("C", new Point3d(new double[]{1.0, 0.0, 0.0}));
1342 frg1.addAtom(a1);
1343 frg1.addAtom(a2);
1344 frg1.addBond(new Bond(a1, a2));
1345 frg1.addAP(0, a0, new Point3d(new double[]{0.0, 0.0, 1.0}));
1346 frg1.addAP(1, a0, new Point3d(new double[]{1.0, 1.0, 1.0}));
1347 frg1.projectAPsToProperties();
1348
1349 Fragment frg2 = new Fragment();
1350 IAtom a3 = new Atom("C", new Point3d(new double[]{0.0, 0.0, 0.0}));
1351 frg2.addAtom(a3);
1352 frg2.addAP(0, a0, new Point3d(new double[]{0.0, 1.0, 1.0}));
1353 frg2.addAP(0, b0, new Point3d(new double[]{0.0, 1.0, -1.0}));
1354 frg2.projectAPsToProperties();
1355
1356 Fragment rca1 = new Fragment();
1357 IAtom a4 = new PseudoAtom("ATP", new Point3d(
1358 new double[]{0.0, 0.0, 0.0}));
1359 rca1.addAtom(a4);
1360 rca1.addAP(0, ap0, new Point3d(new double[]{0.0, 1.0, 1.0}));
1361 rca1.projectAPsToProperties();
1362
1363 Fragment rca2 = new Fragment();
1364 IAtom a5 = new PseudoAtom("ATM", new Point3d(
1365 new double[]{1.0, 0.0, 0.0}));
1366 rca2.addAtom(a5);
1367 rca2.addAP(0, am0, new Point3d(new double[]{0.0, 1.0, 1.0}));
1368 rca2.projectAPsToProperties();
1369
1370 Fragment cap = new Fragment();
1371 IAtom a6 = new Atom("H", new Point3d(new double[]{0.0, 0.0, 0.0}));
1372 cap.addAtom(a6);
1373 cap.addAP(0, h0, new Point3d(new double[]{0.0, 1.0, 1.0}));
1374 cap.projectAPsToProperties();
1375
1376 ArrayList<Vertex> scaff = new ArrayList<Vertex>();
1377 scaff.add(frg1);
1378 ArrayList<Vertex> frags = new ArrayList<Vertex>();
1379 frags.add(frg2);
1380 frags.add(rca1);
1381 frags.add(rca2);
1382 ArrayList<Vertex> caps = new ArrayList<Vertex>();
1383 caps.add(cap);
1384
1386 FragmentSpace fs = new FragmentSpace(fsp, scaff, frags, caps,
1387 cpMap, capMap, forbEnds, cpMap);
1388 fs.setAPclassBasedApproach(true);
1389
1390 DGraph dg = new DGraph();
1395 dg.addVertex(v1);
1396 dg.addVertex(v2);
1397 dg.addVertex(v3);
1398 dg.addVertex(v4);
1399
1400 Edge e1 = new Edge(v1.getAP(1), v2.getAP(0), BondType.SINGLE);
1401 Edge e2 = new Edge(v2.getAP(1), v3.getAP(0), BondType.SINGLE);
1402 Edge e3 = new Edge(v1.getAP(0), v4.getAP(0), BondType.SINGLE);
1403 dg.addEdge(e1);
1404 dg.addEdge(e2);
1405 dg.addEdge(e3);
1406
1407 dg.addRing(v3, v4);
1408
1410
1411 assertEquals(4, dg.getVertexCount(),
1412 "Number of vertexes after removal of 0 unused RCVs.");
1413 assertEquals(3, dg.getEdgeCount(),
1414 "Number of edges after removal of 0 unused RCVs.");
1415
1416 DGraph acyclicGraph = new DGraph();
1421 acyclicGraph.addVertex(v1b);
1422 acyclicGraph.addVertex(v2b);
1423 acyclicGraph.addVertex(v3b);
1424 acyclicGraph.addVertex(v4b);
1425
1426 Edge e1b = new Edge(v1b.getAP(1), v2b.getAP(0), BondType.SINGLE);
1427 Edge e2b = new Edge(v2b.getAP(1), v3b.getAP(0), BondType.SINGLE);
1428 Edge e3b = new Edge(v1b.getAP(0), v4b.getAP(0), BondType.SINGLE);
1429 acyclicGraph.addEdge(e1b);
1430 acyclicGraph.addEdge(e2b);
1431 acyclicGraph.addEdge(e3b);
1432
1433 acyclicGraph.replaceUnusedRCVsWithCapps(fs);
1434
1435 assertEquals(0, acyclicGraph.getRCVertices().size(),
1436 "Number of RCVs after removal of 2 unused RCVs.");
1437 assertEquals(3, acyclicGraph.getVertexCount(),
1438 "Number of vertexes after removal of 2 unused RCVs.");
1439 assertEquals(2, acyclicGraph.getEdgeCount(),
1440 "Number of edges after removal of 2 unused RCVs.");
1441 }
1442
1443//------------------------------------------------------------------------------
1444
1445 @Test
1446 public void testGetEmbeddingPath() throws Exception
1447 {
1448 prepare();
1450
1451 List<Template> expected = new ArrayList<Template>();
1452 DGraph refToThisLayerGraph = gOut;
1453 Template refToThisLayerVrtx = null;
1454 for (int embeddingLevel=0; embeddingLevel<10; embeddingLevel++)
1455 {
1456 refToThisLayerVrtx = (Template) refToThisLayerGraph
1457 .getVertexList().stream()
1458 .filter(v -> v instanceof Template)
1459 .findAny()
1460 .orElse(null);
1461 expected.add(refToThisLayerVrtx);
1462 refToThisLayerGraph = refToThisLayerVrtx.getInnerGraph();
1463 }
1464
1465 assertEquals(new ArrayList<Template>(),gOut.getEmbeddingPath(),
1466 "Embedding path of graph that is not embedded");
1467 List<Template> path = refToThisLayerGraph.getEmbeddingPath();
1468 assertEquals(expected, path, "Path of deepest embedded graph");
1469 }
1470
1471//------------------------------------------------------------------------------
1472
1473 @Test
1474 public void testGetEmbeddedGraphInClone() throws Exception
1475 {
1476 prepare();
1478 DGraph gB = gA.clone();
1479
1480 // This works only because we know that the graphs have only one
1481 // template per level
1482 List<Template> expectedPathA = new ArrayList<Template>();
1483 List<Template> expectedPathB = new ArrayList<Template>();
1484 DGraph refToThisLayerGraphB = gB;
1485 Template refToThisLayerVrtxB = null;
1486 DGraph refToThisLayerGraphA = gA;
1487 Template refToThisLayerVrtxA = null;
1488 for (int embeddingLevel=0; embeddingLevel<9; embeddingLevel++)
1489 {
1490 refToThisLayerVrtxA = (Template) refToThisLayerGraphA
1491 .getVertexList().stream()
1492 .filter(v -> v instanceof Template)
1493 .findAny()
1494 .orElse(null);
1495 expectedPathA.add(refToThisLayerVrtxA);
1496 refToThisLayerGraphA = refToThisLayerVrtxA.getInnerGraph();
1497
1498 refToThisLayerVrtxB = (Template) refToThisLayerGraphB
1499 .getVertexList().stream()
1500 .filter(v -> v instanceof Template)
1501 .findAny()
1502 .orElse(null);
1503 expectedPathB.add(refToThisLayerVrtxB);
1504 refToThisLayerGraphB = refToThisLayerVrtxB.getInnerGraph();
1505 }
1506
1507 DGraph expectedEmbeddedA = expectedPathA.get(8).getInnerGraph();
1508 DGraph expectedEmbeddedB = expectedPathB.get(8).getInnerGraph();
1509
1510 DGraph embeddedFoundB = DGraph.getEmbeddedGraphInClone(gB,
1511 gA, expectedPathA);
1512
1513 assertEquals(expectedEmbeddedB,embeddedFoundB);
1514
1515 List<Template> pathFoundB = embeddedFoundB.getEmbeddingPath();
1516 assertEquals(expectedPathB,pathFoundB);
1517
1518 DGraph embeddedFoundA = DGraph.getEmbeddedGraphInClone(gA,
1519 gB, expectedPathB);
1520 assertEquals(expectedEmbeddedA,embeddedFoundA);
1521
1522 List<Template> pathFoundA = embeddedFoundA.getEmbeddingPath();
1523 assertEquals(expectedPathA,pathFoundA);
1524 }
1525
1526//------------------------------------------------------------------------------
1527
1528 @Test
1529 public void testGetSourceVertex() throws Exception
1530 {
1531 FragmentSpace fs = prepare();
1533 Vertex src = g.getSourceVertex();
1534 assertEquals(g.getVertexAtPosition(4),src,
1535 "Inconsistent source vertex");
1536
1537 DGraph g2 = makeTestGraphC(fs);
1538 Vertex src2 = g2.getSourceVertex();
1539 assertEquals(g2.getVertexAtPosition(0),src2,
1540 "Inconsistent source vertex");
1541 }
1542
1543//------------------------------------------------------------------------------
1544
1545 @Test
1546 public void testGetLevel() throws Exception
1547 {
1548 FragmentSpace fs = prepare();
1550 int[] expected = new int[] {2,3,0,1,-1};
1551 for (int i=0; i<g.getVertexCount(); i++)
1552 {
1553 assertEquals(expected[i],g.getLevel(g.getVertexAtPosition(i)),
1554 "Wrong level for vertex at position "+i);
1555 }
1556
1557 DGraph g2 = makeTestGraphC(fs);
1558 expected = new int[] {-1,0,1,2,3,2,0,1,2,3,2};
1559 for (int i=0; i<g2.getVertexCount(); i++)
1560 {
1561 assertEquals(expected[i],g2.getLevel(g2.getVertexAtPosition(i)),
1562 "Bis: Wrong level for vertex at position "+i);
1563 }
1564 }
1565
1566//------------------------------------------------------------------------------
1567
1568 @Test
1569 public void testReplaceVertex() throws Exception
1570 {
1571 FragmentSpace fs = prepare();
1572 DGraph g = makeTestGraphB(fs);
1573
1574 Vertex v1 = g.getVertexAtPosition(1);
1575
1576 LinkedHashMap<Integer, Integer> apMap =
1577 new LinkedHashMap<Integer,Integer>();
1578 apMap.put(0, 4);
1579 apMap.put(1, 1);
1580 apMap.put(3, 2);
1581 apMap.put(4, 0);
1582
1583 int chosenBBId = 4;
1584 BBType choosenBBTyp = BBType.FRAGMENT;
1585
1586 boolean res = g.replaceVertex(v1, chosenBBId, choosenBBTyp, apMap, fs);
1587
1588 assertTrue(res,"ReplaceVertex return value.");
1589 assertFalse(g.containsVertex(v1),"v1 is still part of graph");
1590 int numVertexesWithGoodBBId = 0;
1591 int numEdgesWithS = 0;
1592 int numEdgesWith2 = 0;
1593 int numEdgesWith3 = 0;
1594 for (Vertex v : g.gVertices)
1595 {
1596 if (v.getBuildingBlockType() == choosenBBTyp
1597 && v.getBuildingBlockId() == chosenBBId)
1598 {
1599 numVertexesWithGoodBBId++;
1600
1602 {
1603 if (!ap.isAvailable())
1604 {
1605 Vertex nextVrtx = ap.getLinkedAP().getOwner();
1606 if (nextVrtx.getBuildingBlockType() == BBType.SCAFFOLD)
1607 {
1608 numEdgesWithS++;
1609 } else {
1610 switch (nextVrtx.getBuildingBlockId())
1611 {
1612 case 2:
1613 numEdgesWith2++;
1614 break;
1615 case 3:
1616 numEdgesWith3++;
1617 break;
1618 }
1619 }
1620 }
1621 }
1622 }
1623 }
1624 assertEquals(2,numVertexesWithGoodBBId,"Number of new links.");
1625 assertEquals(2,numEdgesWithS,"Number of new edges with scaffold.");
1626 assertEquals(4,numEdgesWith2,"Number of new edges with v2a/b.");
1627 assertEquals(2,numEdgesWith3,"Number of new edges with v3a/b.");
1628
1629 //
1630 //
1631 //
1632 DGraph g2 = makeTestGraphB(fs);
1633
1634 Vertex v2 = g2.getVertexAtPosition(2);
1635
1636 SymmetricVertexes origSS = new SymmetricVertexes();
1637 for (Vertex v : g2.getSymSetForVertex(v2))
1638 {
1639 origSS.add(v);
1640 }
1641 Set<Long> oldVertexIds = new HashSet<Long>();
1642 for (Vertex v : g2.getVertexList())
1643 oldVertexIds.add(v.getVertexId());
1644
1645 LinkedHashMap<Integer,Integer> apMap2 =
1646 new LinkedHashMap<Integer,Integer>();
1647 apMap2.put(0, 1);
1648
1649 int chosenBBId2 = 5;
1650 BBType choosenBBTyp2 = BBType.FRAGMENT;
1651
1652 boolean res2 = g2.replaceVertex(v2, chosenBBId2, choosenBBTyp2, apMap2,
1653 fs);
1654
1655 assertTrue(res2,"ReplaceVertex return value (2).");
1656 assertFalse(g2.containsVertex(v2),"v2 is still part of graph");
1657 int numVertexesWithGoodBBId2 = 0;
1658 int numEdgesWith1 = 0;
1659 for (Vertex v : g2.gVertices)
1660 {
1661 if (v.getBuildingBlockType() == choosenBBTyp2
1662 && v.getBuildingBlockId() == chosenBBId2)
1663 {
1664 numVertexesWithGoodBBId2++;
1665
1667 {
1668 if (!ap.isAvailable())
1669 {
1670 Vertex nextVrtx = ap.getLinkedAP().getOwner();
1671 if (nextVrtx.getBuildingBlockId() == 1)
1672 numEdgesWith1++;
1673 }
1674 }
1675 }
1676 }
1677 assertEquals(4,numVertexesWithGoodBBId2,"Number of new links.");
1678 assertEquals(4,numEdgesWith1,"Number of new edges with scaffold.");
1679 assertEquals(2,g2.getSymmetricSetCount(),"Number of symmetric sets.");
1680 boolean found = false;
1681 boolean foundOldVertexId = false;
1682 Iterator<SymmetricVertexes> iterSS = g2.getSymSetsIterator();
1683 while (iterSS.hasNext())
1684 {
1685 SymmetricVertexes ss = iterSS.next();
1686 if (ss.size() == origSS.size())
1687 {
1688 found = true;
1689 for (Vertex v : ss)
1690 {
1691 if (oldVertexIds.contains(v.getVertexId()))
1692 foundOldVertexId = true;
1693 }
1694 }
1695 }
1696 assertTrue(found,"could not find old symmetric set");
1697 assertFalse(foundOldVertexId,"found old vertex id in new symmetric set");
1698 }
1699
1700//------------------------------------------------------------------------------
1701
1702 @Test
1703 public void testReplaceVertex_inRing() throws Exception
1704 {
1705 FragmentSpace fs = prepare();
1706 DGraph g = makeTestGraphD(fs);
1707
1708 Vertex v = g.getVertexAtPosition(1);
1709
1710 LinkedHashMap<Integer, Integer> apMap =
1711 new LinkedHashMap<Integer,Integer>();
1712 apMap.put(0, 0);
1713 apMap.put(1, 1);
1714 apMap.put(2, 2);
1715 apMap.put(3, 3);
1716 apMap.put(4, 4);
1717
1718 boolean res = g.replaceVertex(v, 1, BBType.FRAGMENT, apMap, fs);
1719 assertTrue(res);
1720
1721 DGraph g2 = makeTestGraphD(fs);
1722 assertTrue(g.isIsomorphicTo(g2));
1723 }
1724
1725//------------------------------------------------------------------------------
1726
1727 @Test
1728 public void testReplaceSubGraph() throws Exception
1729 {
1730 FragmentSpace fs = prepare();
1731 DGraph g = makeTestGraphD(fs);
1732
1733 List<Vertex> vrtxsToReplace = new ArrayList<Vertex>();
1734 vrtxsToReplace.add(g.getVertexAtPosition(0));
1735 vrtxsToReplace.add(g.getVertexAtPosition(1));
1736
1737 DGraph incomingSubGraph = makeTestGraphF(fs);
1738
1739 LinkedHashMap<AttachmentPoint, AttachmentPoint> apMap =
1740 new LinkedHashMap<AttachmentPoint,AttachmentPoint>();
1741 apMap.put(g.getVertexAtPosition(0).getAP(1), //A:0
1742 incomingSubGraph.getVertexAtPosition(0).getAP(2)); //A:0
1743 apMap.put(g.getVertexAtPosition(0).getAP(2), //D:0
1744 incomingSubGraph.getVertexAtPosition(7).getAP(1)); //D:0
1745 apMap.put(g.getVertexAtPosition(1).getAP(1), //B:0
1746 incomingSubGraph.getVertexAtPosition(6).getAP(2)); //B:0
1747 apMap.put(g.getVertexAtPosition(1).getAP(4), //C:0
1748 incomingSubGraph.getVertexAtPosition(6).getAP(4)); //C:0
1749 apMap.put(g.getVertexAtPosition(1).getAP(3), //B:0
1750 incomingSubGraph.getVertexAtPosition(5).getAP(3)); //B:0
1751 incomingSubGraph.reassignSymmetricLabels();
1752
1753 boolean res = g.replaceSingleSubGraph(vrtxsToReplace, incomingSubGraph, apMap);
1754 assertTrue(res);
1755
1757
1758 assertEquals(3,g.getRingCount(),"number of rings");
1759 assertEquals(3,g.getSymmetricSetCount(),"number of symmetric sets");
1760 assertEquals(incomingSubGraph.getVertexAtPosition(0),g.getSourceVertex(),
1761 "graph's surce vertex");
1762 //NB: the position of the vertexes has changes by -2. so vertex 3 is now at 1
1764 g.getVertexAtPosition(2), g); // length was 2
1765 assertEquals(3,pathA.getEdgesPath().size(),"path within a ring (A)");
1767 g.getVertexAtPosition(6), g); // length was 4
1768 assertEquals(5,pathB.getEdgesPath().size(),"path within a ring (B)");
1770 g.getVertexAtPosition(6), g); // length was 2
1771 assertEquals(4,pathC.getEdgesPath().size(),"path within a ring (C)");
1772
1773 DGraph expected = makeTestGraphG(fs);
1774 assertTrue(g.isIsomorphicTo(expected),"isomforphic to expected");
1775 }
1776
1777//------------------------------------------------------------------------------
1778
1779 @Test
1780 public void testReplaceSubGraph_inTemplate() throws Exception
1781 {
1782 FragmentSpace fs = prepare();
1783 DGraph g = makeTestGraphI(fs);
1784
1785 DGraph innerGraph = ((Template) g.getVertexAtPosition(0))
1786 .getInnerGraph();
1787
1788 List<Vertex> vrtxsToReplace = new ArrayList<Vertex>();
1789 vrtxsToReplace.add(innerGraph.getVertexAtPosition(0));
1790
1791 DGraph incomingSubGraph = makeTestGraphJ(fs);
1792
1793 LinkedHashMap<AttachmentPoint, AttachmentPoint> apMap =
1794 new LinkedHashMap<AttachmentPoint,AttachmentPoint>();
1795 // first two are those needed within the template
1796 apMap.put(vrtxsToReplace.get(0).getAP(3), //B:0
1797 incomingSubGraph.getVertexAtPosition(0).getAP(1)); //B:0
1798 apMap.put(vrtxsToReplace.get(0).getAP(4), //C:0
1799 incomingSubGraph.getVertexAtPosition(1).getAP(4)); //C:0
1800 // second two are those projected and used outside template
1801 apMap.put(vrtxsToReplace.get(0).getAP(0), //A:0
1802 incomingSubGraph.getVertexAtPosition(0).getAP(2)); //A:0
1803 apMap.put(vrtxsToReplace.get(0).getAP(1), //B:0
1804 incomingSubGraph.getVertexAtPosition(0).getAP(3)); //B:0
1805
1806 boolean res = innerGraph.replaceSingleSubGraph(vrtxsToReplace,
1807 incomingSubGraph, apMap);
1808 assertTrue(res);
1809
1810 assertEquals(5,g.getVertexCount(),"Vertex in outer graph");
1811 assertEquals(1,g.getRingCount(),"Rings in outer graph");
1812 assertEquals(4,g.getAvailableAPs().size(),"Free APs outer graph");
1813 Ring r = g.getRings().get(0);
1814 assertEquals(4,r.getDistance(r.getHeadVertex(),r.getTailVertex()),
1815 "Distance Head-Tail in ring of outer graph");
1816
1817 DGraph innerGraphAfter =
1818 ((Template) g.getVertexAtPosition(0)).getInnerGraph();
1819 assertEquals(6,innerGraphAfter.getVertexCount(),
1820 "Vertex in inner graph");
1821 assertEquals(1,innerGraphAfter.getRingCount(),
1822 "Rings in inner graph");
1823 assertEquals(6,innerGraphAfter.getAvailableAPs().size(),
1824 "Free APs inner graph");
1825 Ring ri = innerGraphAfter.getRings().get(0);
1826 assertEquals(5,ri.getDistance(ri.getHeadVertex(),ri.getTailVertex()),
1827 "Distance Head-Tail in ring of inner graph");
1828 }
1829
1830//------------------------------------------------------------------------------
1831
1832 @Test
1833 public void testRemoveVertex() throws Exception {
1834 DGraph graph = new DGraph();
1835 EmptyVertex v0 = new EmptyVertex(0);
1836 buildVertexAndConnectToGraph(v0, 3, graph);
1837
1838 EmptyVertex v1 = new EmptyVertex(1);
1839 buildVertexAndConnectToGraph(v1, 2, graph);
1840 graph.addEdge(new Edge(v0.getAP(0), v1.getAP(0)));
1841
1842 EmptyVertex v2 = new EmptyVertex(2);
1843 buildVertexAndConnectToGraph(v2, 2, graph);
1844 graph.addEdge(new Edge(v1.getAP(1), v2.getAP(0)));
1845
1846 EmptyVertex v3 = new EmptyVertex(3);
1847 buildVertexAndConnectToGraph(v3, 1, graph);
1848 graph.addEdge(new Edge(v2.getAP(1), v3.getAP(0)));
1849
1850 EmptyVertex v4 = new EmptyVertex(4);
1851 buildVertexAndConnectToGraph(v4, 3, graph);
1852 graph.addEdge(new Edge(v0.getAP(1), v4.getAP(0)));
1853
1854 EmptyVertex v5 = new EmptyVertex(5);
1855 buildVertexAndConnectToGraph(v5, 1, graph);
1856 graph.addEdge(new Edge(v4.getAP(1), v5.getAP(0)));
1857
1858 EmptyVertex v6 = new EmptyVertex(6);
1859 buildVertexAndConnectToGraph(v6, 1, graph);
1860 graph.addEdge(new Edge(v0.getAP(2), v6.getAP(0)));
1861
1862 EmptyVertex v7 = new EmptyVertex(7);
1863 buildVertexAndConnectToGraph(v7, 1, graph);
1864 graph.addEdge(new Edge(v4.getAP(2), v7.getAP(0)));
1865
1866 graph.addRing(new Ring(new ArrayList<>(
1867 Arrays.asList(v5, v4, v0, v1, v2, v3))));
1868
1869 graph.addRing(new Ring(new ArrayList<>(
1870 Arrays.asList(v6, v0, v4, v7))));
1871
1873 ss.add(v3);
1874 ss.add(v5);
1875 graph.addSymmetricSetOfVertices(ss);
1876
1878 ss2.add(v6);
1879 ss2.add(v7);
1880 graph.addSymmetricSetOfVertices(ss2);
1881
1882 // Current string encoding this graph is
1883// "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,"
1884// + "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,"
1885// + "4_1_5_0_1,0_2_6_0_1,4_2_7_0_1, "
1886// + "DENOPTIMRing [verteces=[5_1_1_0, 4_1_1_0, 0_1_0_0, 1_1_1_0,"
1887// + " 2_1_1_0, 3_1_1_0]] DENOPTIMRing [verteces=[6_1_1_0,"
1888// + " 0_1_0_0, 4_1_1_0, 7_1_1_0]] "
1889// + "SymmetricSet [symVrtxIds=[3, 5]] "
1890// + "SymmetricSet [symVrtxIds=[6, 7]]";
1891
1892 int numV = graph.getVertexCount();
1893 int numE = graph.getEdgeCount();
1894 int numS = graph.getSymmetricSetCount();
1895 int numR = graph.getRingCount();
1896
1897 graph.removeVertex(v5);
1898
1899 int numVa = graph.getVertexCount();
1900 int numEa = graph.getEdgeCount();
1901 int numSa = graph.getSymmetricSetCount();
1902 int numRa = graph.getRingCount();
1903
1904 assertEquals(numVa, numV - 1);
1905 assertEquals(numEa, numE - 1);
1906 assertEquals(numSa, numS - 1);
1907 assertEquals(numRa, numR - 1);
1908
1909 graph.removeVertex(v3);
1910
1911 int numVb = graph.getVertexCount();
1912 int numEb = graph.getEdgeCount();
1913 int numSb = graph.getSymmetricSetCount();
1914 int numRb = graph.getRingCount();
1915
1916 assertEquals(numVb, numVa - 1);
1917 assertEquals(numEb, numEa - 1);
1918 assertEquals(numSb, numSa);
1919 assertEquals(numRb, numRa);
1920
1921 graph.removeVertex(v4); // non terminal vertex
1922
1923 int numVc = graph.getVertexCount();
1924 int numEc = graph.getEdgeCount();
1925 int numSc = graph.getSymmetricSetCount();
1926 int numRc = graph.getRingCount();
1927
1928 assertEquals(numVc, numVb - 1);
1929 assertEquals(numEc, numEb - 2);
1930 assertEquals(numSc, numSb);
1931 assertEquals(numRc, numRb - 1);
1932
1933 }
1934
1935//------------------------------------------------------------------------------
1936
1937 @Test
1939 {
1940 DGraph graphA = new DGraph();
1941 EmptyVertex v0 = new EmptyVertex(0);
1942 buildVertexAndConnectToGraph(v0, 3, graphA);
1943
1944 EmptyVertex v1 = new EmptyVertex(1);
1945 buildVertexAndConnectToGraph(v1, 2, graphA);
1946 graphA.addEdge(new Edge(v0.getAP(0), v1.getAP(0)));
1947
1948 EmptyVertex v2 = new EmptyVertex(2);
1949 buildVertexAndConnectToGraph(v2, 2, graphA);
1950 graphA.addEdge(new Edge(v1.getAP(1), v2.getAP(0)));
1951
1952 // Other graph, but is the same graph
1953
1954 DGraph graphB = new DGraph();
1955 EmptyVertex v90 = new EmptyVertex(90);
1956 buildVertexAndConnectToGraph(v90, 3, graphB);
1957
1958 EmptyVertex v91 = new EmptyVertex(91);
1959 buildVertexAndConnectToGraph(v91, 2, graphB);
1960 graphB.addEdge(new Edge(v90.getAP(0), v91.getAP(0)));
1961
1962 EmptyVertex v92 = new EmptyVertex(92);
1963 buildVertexAndConnectToGraph(v92, 2, graphB);
1964 graphB.addEdge(new Edge(v91.getAP(1), v92.getAP(0)));
1965
1966 StringBuilder reason = new StringBuilder();
1967 assertTrue(graphA.sameAs(graphB, reason), reason.toString());
1968 }
1969
1970//------------------------------------------------------------------------------
1971
1972 @Test
1974 {
1975 DGraph graphA = new DGraph();
1976 EmptyVertex v0 = new EmptyVertex(0);
1977 buildVertexAndConnectToGraph(v0, 3, graphA);
1978
1979 EmptyVertex v1 = new EmptyVertex(1);
1980 buildVertexAndConnectToGraph(v1, 2, graphA);
1981 graphA.addEdge(new Edge(v0.getAP(0), v1.getAP(0)));
1982
1983 EmptyVertex v2 = new EmptyVertex(2);
1984 buildVertexAndConnectToGraph(v2, 2, graphA);
1985 graphA.addEdge(new Edge(v1.getAP(1), v2.getAP(0)));
1986
1987 // Other graph
1988
1989 DGraph graphB = new DGraph();
1990 EmptyVertex v90 = new EmptyVertex(90);
1991 buildVertexAndConnectToGraph(v90, 3, graphB);
1992
1993 EmptyVertex v91 = new EmptyVertex(91);
1994 buildVertexAndConnectToGraph(v91, 2, graphB);
1995 graphB.addEdge(new Edge(v90.getAP(0), v91.getAP(0)));
1996
1997 EmptyVertex v92 = new EmptyVertex(92);
1998 buildVertexAndConnectToGraph(v92, 3, graphB);
1999 graphB.addEdge(new Edge(v91.getAP(1), v92.getAP(0)));
2000
2001 StringBuilder reason = new StringBuilder();
2002 assertFalse(graphA.sameAs(graphB, reason));
2003 }
2004
2005//------------------------------------------------------------------------------
2006
2007 @Test
2008 public void testSameAs_SameSymmSet() throws Exception {
2009 DGraph graphA = new DGraph();
2010 EmptyVertex v0 = new EmptyVertex(0);
2011 buildVertexAndConnectToGraph(v0, 4, graphA);
2012
2013 EmptyVertex v1 = new EmptyVertex(1);
2014 buildVertexAndConnectToGraph(v1, 2, graphA);
2015 graphA.addEdge(new Edge(v0.getAP(0), v1.getAP(0)));
2016
2017 EmptyVertex v2 = new EmptyVertex(2);
2018 buildVertexAndConnectToGraph(v2, 2, graphA);
2019 graphA.addEdge(new Edge(v0.getAP(1), v2.getAP(0)));
2020
2021 EmptyVertex v3 = new EmptyVertex(3);
2022 buildVertexAndConnectToGraph(v3, 2, graphA);
2023 graphA.addEdge(new Edge(v0.getAP(2), v3.getAP(0)));
2024
2025 EmptyVertex v4 = new EmptyVertex(4);
2026 buildVertexAndConnectToGraph(v4, 2, graphA);
2027 graphA.addEdge(new Edge(v0.getAP(3), v4.getAP(0)));
2028
2030 ssA.add(v1);
2031 ssA.add(v2);
2032 graphA.addSymmetricSetOfVertices(ssA);
2034 ssA2.add(v3);
2035 ssA2.add(v4);
2036 graphA.addSymmetricSetOfVertices(ssA2);
2037
2038 // Other
2039
2040 DGraph graphB = new DGraph();
2041 EmptyVertex v90 = new EmptyVertex(90);
2042 buildVertexAndConnectToGraph(v90, 4, graphB);
2043
2044 EmptyVertex v91 = new EmptyVertex(91);
2045 buildVertexAndConnectToGraph(v91, 2, graphB);
2046 graphB.addEdge(new Edge(v90.getAP(0), v91.getAP(0)));
2047
2048 EmptyVertex v92 = new EmptyVertex(92);
2049 buildVertexAndConnectToGraph(v92, 2, graphB);
2050 graphB.addEdge(new Edge(v90.getAP(1), v92.getAP(0)));
2051
2052 EmptyVertex v93 = new EmptyVertex(93);
2053 buildVertexAndConnectToGraph(v93, 2, graphB);
2054 graphB.addEdge(new Edge(v90.getAP(2), v93.getAP(0)));
2055
2056 EmptyVertex v94 = new EmptyVertex(94);
2057 buildVertexAndConnectToGraph(v94, 2, graphB);
2058 graphB.addEdge(new Edge(v90.getAP(3), v94.getAP(0)));
2059
2061 ssB2.add(v93);
2062 ssB2.add(v94);
2063 graphB.addSymmetricSetOfVertices(ssB2);
2065 ssB.add(v91);
2066 ssB.add(v92);
2067 graphB.addSymmetricSetOfVertices(ssB);
2068
2069 /*
2070 System.out.println("Graphs Same SS");
2071 System.out.println(graphA);
2072 System.out.println(graphB);
2073 */
2074
2075 StringBuilder reason = new StringBuilder();
2076 assertTrue(graphA.sameAs(graphB, reason));
2077 }
2078
2079//------------------------------------------------------------------------------
2080
2081 @Test
2082 public void testSameAs_DiffSymmSet() throws Exception {
2083 DGraph graphA = new DGraph();
2084 EmptyVertex v0 = new EmptyVertex(0);
2085 buildVertexAndConnectToGraph(v0, 4, graphA);
2086
2087 EmptyVertex v1 = new EmptyVertex(1);
2088 buildVertexAndConnectToGraph(v1, 2, graphA);
2089 graphA.addEdge(new Edge(v0.getAP(0), v1.getAP(0)));
2090
2091 EmptyVertex v2 = new EmptyVertex(2);
2092 buildVertexAndConnectToGraph(v2, 2, graphA);
2093 graphA.addEdge(new Edge(v0.getAP(1), v2.getAP(0)));
2094
2095 EmptyVertex v3 = new EmptyVertex(3);
2096 buildVertexAndConnectToGraph(v3, 2, graphA);
2097 graphA.addEdge(new Edge(v0.getAP(2), v3.getAP(0)));
2098
2099 EmptyVertex v4 = new EmptyVertex(4);
2100 buildVertexAndConnectToGraph(v4, 2, graphA);
2101 graphA.addEdge(new Edge(v0.getAP(3), v4.getAP(0)));
2102
2104 ssA.add(v1); //difference
2105 ssA.add(v2); //difference
2106 graphA.addSymmetricSetOfVertices(ssA);
2108 ssA2.add(v3); //difference
2109 ssA2.add(v4); //difference
2110 graphA.addSymmetricSetOfVertices(ssA2);
2111
2112 // Other
2113
2114 DGraph graphB = new DGraph();
2115 EmptyVertex v90 = new EmptyVertex(90);
2116 buildVertexAndConnectToGraph(v90, 4, graphB);
2117
2118 EmptyVertex v91 = new EmptyVertex(91);
2119 buildVertexAndConnectToGraph(v91, 2, graphB);
2120 graphB.addEdge(new Edge(v90.getAP(0), v1.getAP(0)));
2121
2122 EmptyVertex v92 = new EmptyVertex(92);
2123 buildVertexAndConnectToGraph(v92, 2, graphB);
2124 graphB.addEdge(new Edge(v0.getAP(1), v2.getAP(0)));
2125
2126 EmptyVertex v93 = new EmptyVertex(93);
2127 buildVertexAndConnectToGraph(v93, 2, graphB);
2128 graphB.addEdge(new Edge(v0.getAP(2), v3.getAP(0)));
2129
2130 EmptyVertex v94 = new EmptyVertex(94);
2131 buildVertexAndConnectToGraph(v94, 2, graphB);
2132 graphB.addEdge(new Edge(v0.getAP(3), v4.getAP(0)));
2133
2135 ssB.add(v1); //difference
2136 ssB.add(v3); //difference
2137 graphB.addSymmetricSetOfVertices(ssB);
2139 ssB2.add(v2); //difference
2140 ssB2.add(v4); //difference
2141 graphB.addSymmetricSetOfVertices(ssB2);
2142
2143 StringBuilder reason = new StringBuilder();
2144 assertFalse(graphA.sameAs(graphB, reason));
2145 }
2146
2147//------------------------------------------------------------------------------
2148
2149 @Test
2151 {
2152 DGraph graphA = new DGraph();
2153 EmptyVertex v0 = new EmptyVertex(0);
2154 buildVertexAndConnectToGraph(v0, 4, graphA);
2155
2156 EmptyVertex v1 = new EmptyVertex(1);
2157 buildVertexAndConnectToGraph(v1, 2, graphA);
2158 graphA.addEdge(new Edge(v0.getAP(0), v1.getAP(0)));
2159
2160 EmptyVertex v2 = new EmptyVertex(2);
2161 buildVertexAndConnectToGraph(v2, 2, graphA);
2162 graphA.addEdge(new Edge(v0.getAP(1), v2.getAP(0)));
2163
2164 EmptyVertex v3 = new EmptyVertex(3);
2165 buildVertexAndConnectToGraph(v3, 2, graphA);
2166 graphA.addEdge(new Edge(v0.getAP(2), v3.getAP(0)));
2167
2168 EmptyVertex v4 = new EmptyVertex(4);
2169 buildVertexAndConnectToGraph(v4, 2, graphA);
2170 graphA.addEdge(new Edge(v0.getAP(3), v4.getAP(0)));
2171
2172 ArrayList<Vertex> vrA = new ArrayList<Vertex>();
2173 vrA.add(v1);
2174 vrA.add(v0);
2175 vrA.add(v2);
2176 Ring rA = new Ring(vrA);
2177 graphA.addRing(rA);
2178 ArrayList<Vertex> vrA2 = new ArrayList<Vertex>();
2179 vrA2.add(v3);
2180 vrA2.add(v0);
2181 vrA2.add(v4);
2182 Ring rA2 = new Ring(vrA2);
2183 graphA.addRing(rA2);
2184
2185
2186 // Other
2187
2188 DGraph graphB = new DGraph();
2189 EmptyVertex v90 = new EmptyVertex(90);
2190 buildVertexAndConnectToGraph(v90, 4, graphB);
2191
2192 EmptyVertex v91 = new EmptyVertex(91);
2193 buildVertexAndConnectToGraph(v91, 2, graphB);
2194 graphB.addEdge(new Edge(v90.getAP(0), v91.getAP(0)));
2195
2196 EmptyVertex v92 = new EmptyVertex(92);
2197 buildVertexAndConnectToGraph(v92, 2, graphB);
2198 graphB.addEdge(new Edge(v90.getAP(1), v92.getAP(0)));
2199
2200 EmptyVertex v93 = new EmptyVertex(93);
2201 buildVertexAndConnectToGraph(v93, 2, graphB);
2202 graphB.addEdge(new Edge(v90.getAP(2), v93.getAP(0)));
2203
2204 EmptyVertex v94 = new EmptyVertex(94);
2205 buildVertexAndConnectToGraph(v94, 2, graphB);
2206 graphB.addEdge(new Edge(v90.getAP(3), v94.getAP(0)));
2207
2208 ArrayList<Vertex> vrB = new ArrayList<Vertex>();
2209 vrB.add(v91);
2210 vrB.add(v90);
2211 vrB.add(v92);
2212 Ring rB = new Ring(vrB);
2213 graphB.addRing(rB);
2214 ArrayList<Vertex> vrB2 = new ArrayList<Vertex>();
2215 vrB2.add(v93);
2216 vrB2.add(v90);
2217 vrB2.add(v94);
2218 Ring rB2 = new Ring(vrB2);
2219 graphB.addRing(rB2);
2220
2221 StringBuilder reason = new StringBuilder();
2222 assertTrue(graphA.sameAs(graphB, reason));
2223 }
2224
2225//------------------------------------------------------------------------------
2226
2227 @Test
2228 public void testSameAs_DisorderRings() throws Exception
2229 {
2230 DGraph graphA = new DGraph();
2231 EmptyVertex v0 = new EmptyVertex(0);
2232 buildVertexAndConnectToGraph(v0, 4, graphA);
2233
2234 EmptyVertex v1 = new EmptyVertex(1);
2235 buildVertexAndConnectToGraph(v1, 2, graphA);
2236 graphA.addEdge(new Edge(v0.getAP(0), v1.getAP(0)));
2237
2238 EmptyVertex v2 = new EmptyVertex(2);
2239 buildVertexAndConnectToGraph(v2, 2, graphA);
2240 graphA.addEdge(new Edge(v0.getAP(1), v2.getAP(0)));
2241
2242 EmptyVertex v3 = new EmptyVertex(3);
2243 buildVertexAndConnectToGraph(v3, 2, graphA);
2244 graphA.addEdge(new Edge(v0.getAP(2), v3.getAP(0)));
2245
2246 EmptyVertex v4 = new EmptyVertex(4);
2247 buildVertexAndConnectToGraph(v4, 2, graphA);
2248 graphA.addEdge(new Edge(v0.getAP(3), v4.getAP(0)));
2249
2250 ArrayList<Vertex> vrA = new ArrayList<>();
2251 vrA.add(v1);
2252 vrA.add(v0);
2253 vrA.add(v2);
2254 Ring rA = new Ring(vrA);
2255 graphA.addRing(rA);
2256 ArrayList<Vertex> vrA2 = new ArrayList<>();
2257 vrA2.add(v3);
2258 vrA2.add(v0);
2259 vrA2.add(v4);
2260 Ring rA2 = new Ring(vrA2);
2261 graphA.addRing(rA2);
2262
2263
2264 // Other
2265
2266 DGraph graphB = new DGraph();
2267 EmptyVertex v90 = new EmptyVertex(90);
2268 buildVertexAndConnectToGraph(v90, 4, graphB);
2269
2270 EmptyVertex v91 = new EmptyVertex(91);
2271 buildVertexAndConnectToGraph(v91, 2, graphB);
2272 graphB.addEdge(new Edge(v90.getAP(0), v91.getAP(0)));
2273
2274 EmptyVertex v92 = new EmptyVertex(92);
2275 buildVertexAndConnectToGraph(v92, 2, graphB);
2276 graphB.addEdge(new Edge(v90.getAP(1), v92.getAP(0)));
2277
2278 EmptyVertex v93 = new EmptyVertex(93);
2279 buildVertexAndConnectToGraph(v93, 2, graphB);
2280 graphB.addEdge(new Edge(v90.getAP(2), v93.getAP(0)));
2281
2282 EmptyVertex v94 = new EmptyVertex(94);
2283 buildVertexAndConnectToGraph(v94, 2, graphB);
2284 graphB.addEdge(new Edge(v90.getAP(3), v94.getAP(0)));
2285
2286 ArrayList<Vertex> vrB = new ArrayList<>();
2287 vrB.add(v91);
2288 vrB.add(v90);
2289 vrB.add(v92);
2290 Ring rB = new Ring(vrB);
2291 graphB.addRing(rB);
2292 ArrayList<Vertex> vrB2 = new ArrayList<>();
2293 vrB2.add(v94);
2294 vrB2.add(v90);
2295 vrB2.add(v93);
2296 Ring rB2 = new Ring(vrB2);
2297 graphB.addRing(rB2);
2298
2299 StringBuilder reason = new StringBuilder();
2300 assertTrue(graphA.sameAs(graphB, reason));
2301 }
2302
2303//------------------------------------------------------------------------------
2304
2305 @Test
2307 {
2308 DGraph graphA = new DGraph();
2309 EmptyVertex v0 = new EmptyVertex(0);
2310 buildVertexAndConnectToGraph(v0, 4, graphA);
2311
2312 EmptyVertex v1 = new EmptyVertex(1);
2313 buildVertexAndConnectToGraph(v1, 2, graphA);
2314 graphA.addEdge(new Edge(v0.getAP(0), v1.getAP(0)));
2315
2316 EmptyVertex v2 = new EmptyVertex(2);
2317 buildVertexAndConnectToGraph(v2, 2, graphA);
2318 graphA.addEdge(new Edge(v0.getAP(1), v2.getAP(0)));
2319
2320 EmptyVertex v3 = new EmptyVertex(3);
2321 buildVertexAndConnectToGraph(v3, 2, graphA);
2322 graphA.addEdge(new Edge(v0.getAP(2), v3.getAP(0)));
2323
2324 EmptyVertex v4 = new EmptyVertex(4);
2325 buildVertexAndConnectToGraph(v4, 2, graphA);
2326 graphA.addEdge(new Edge(v0.getAP(3), v4.getAP(0)));
2327
2328 ArrayList<Vertex> vrA = new ArrayList<>();
2329 vrA.add(v1);
2330 vrA.add(v0);
2331 vrA.add(v2);
2332 Ring rA = new Ring(vrA);
2333 graphA.addRing(rA);
2334 ArrayList<Vertex> vrA2 = new ArrayList<>();
2335 vrA2.add(v3);
2336 vrA2.add(v0);
2337 vrA2.add(v4);
2338 Ring rA2 = new Ring(vrA2);
2339 graphA.addRing(rA2);
2340
2341 // Other
2342 DGraph graphB = new DGraph();
2343 EmptyVertex v90 = new EmptyVertex(90);
2344 buildVertexAndConnectToGraph(v90, 4, graphB);
2345
2346 EmptyVertex v91 = new EmptyVertex(91);
2347 buildVertexAndConnectToGraph(v91, 2, graphB);
2348 graphB.addEdge(new Edge(v90.getAP(0), v91.getAP(0)));
2349
2350 EmptyVertex v92 = new EmptyVertex(92);
2351 buildVertexAndConnectToGraph(v92, 2, graphB);
2352 graphB.addEdge(new Edge(v90.getAP(1), v92.getAP(0)));
2353
2354 EmptyVertex v93 = new EmptyVertex(93);
2355 buildVertexAndConnectToGraph(v93, 2, graphB);
2356 graphB.addEdge(new Edge(v90.getAP(2), v93.getAP(0)));
2357
2358 EmptyVertex v94 = new EmptyVertex(94);
2359 buildVertexAndConnectToGraph(v94, 2, graphB);
2360 graphB.addEdge(new Edge(v90.getAP(3), v94.getAP(0)));
2361
2362 ArrayList<Vertex> vrB = new ArrayList<>();
2363 vrB.add(v91);
2364 vrB.add(v90);
2365 vrB.add(v94);
2366 Ring rB = new Ring(vrB);
2367 graphB.addRing(rB);
2368 ArrayList<Vertex> vrB2 = new ArrayList<>();
2369 vrB2.add(v92);
2370 vrB2.add(v90);
2371 vrB2.add(v93);
2372 Ring rB2 = new Ring(vrB2);
2373 graphB.addRing(rB2);
2374
2375 StringBuilder reason = new StringBuilder();
2376 assertFalse(graphA.sameAs(graphB, reason));
2377 }
2378
2379//------------------------------------------------------------------------------
2380
2381 @Test
2383 throws DENOPTIMException
2384 {
2385 EmptyVertex vertex0 = new EmptyVertex(0);
2386 EmptyVertex vertex1 = new EmptyVertex(1);
2387
2388 vertex0.addAP();
2389 vertex0.addAP();
2390 vertex1.addAP();
2391
2392 Edge edge0 = new Edge(vertex0.getAP(0),
2393 vertex1.getAP(0));
2394
2395 DGraph graph = new DGraph();
2396 graph.addVertex(vertex0);
2397 graph.addVertex(vertex1);
2398 graph.addEdge(edge0);
2399
2400 List<AttachmentPoint> lst = graph.getAvailableAPs();
2401 assertEquals(1,lst.size(), "Size of list");
2402 assertEquals(vertex0.getVertexId(),lst.get(0).getOwner().getVertexId(),
2403 "ID of the vertex holding the available AP.");
2404 }
2405
2406//------------------------------------------------------------------------------
2407
2408 @Test
2409 public void testClone() throws DENOPTIMException {
2410 DGraph graph = new DGraph();
2411 EmptyVertex v0 = new EmptyVertex(0);
2412 buildVertexAndConnectToGraph(v0, 3, graph);
2413
2414 EmptyVertex v1 = new EmptyVertex(1);
2415 buildVertexAndConnectToGraph(v1, 2, graph);
2416 graph.addEdge(new Edge(v0.getAP(0), v1.getAP(0)));
2417
2418 EmptyVertex v2 = new EmptyVertex(2);
2419 buildVertexAndConnectToGraph(v2, 2, graph);
2420 graph.addEdge(new Edge(v1.getAP(1), v2.getAP(0)));
2421
2422 EmptyVertex v3 = new EmptyVertex(3);
2423 buildVertexAndConnectToGraph(v3, 1, graph);
2424 graph.addEdge(new Edge(v2.getAP(1), v3.getAP(0)));
2425
2426 EmptyVertex v4 = new EmptyVertex(4);
2427 buildVertexAndConnectToGraph(v4, 3, graph);
2428 graph.addEdge(new Edge(v0.getAP(1), v4.getAP(0)));
2429
2430 EmptyVertex v5 = new EmptyVertex(5);
2431 buildVertexAndConnectToGraph(v5, 1, graph);
2432 graph.addEdge(new Edge(v4.getAP(1), v5.getAP(0)));
2433
2434 EmptyVertex v6 = new EmptyVertex(6);
2435 buildVertexAndConnectToGraph(v6, 1, graph);
2436 graph.addEdge(new Edge(v0.getAP(2), v6.getAP(0)));
2437
2438 EmptyVertex v7 = new EmptyVertex(7);
2439 buildVertexAndConnectToGraph(v7, 1, graph);
2440 graph.addEdge(new Edge(v4.getAP(2), v7.getAP(0)));
2441
2442 graph.addRing(new Ring(new ArrayList<>(
2443 Arrays.asList(v5, v4, v0, v1, v2, v3))));
2444
2445 graph.addRing(new Ring(new ArrayList<>(
2446 Arrays.asList(v6, v0, v4, v7))));
2447
2449 ss1.add(v3);
2450 ss1.add(v5);
2451 graph.addSymmetricSetOfVertices(ss1);
2452
2454 ss2.add(v6);
2455 ss2.add(v7);
2456 graph.addSymmetricSetOfVertices(ss2);
2457
2458 DGraph clone = graph.clone();
2459
2460 assertEquals(graph.gVertices.size(), clone.gVertices.size(),
2461 "Number of vertices");
2462 assertEquals(graph.gEdges.size(), clone.gEdges.size(),
2463 "Number of Edges");
2464 assertEquals(graph.gRings.size(), clone.gRings.size(),
2465 "Number of Rings");
2466 assertEquals(graph.getSymmetricSetCount(), clone.getSymmetricSetCount(),
2467 "Number of symmetric sets");
2468 assertEquals(graph.closableChains.size(), clone.closableChains.size(),
2469 "Number of closable chains");
2470 assertEquals(graph.localMsg, clone.localMsg,
2471 "Local msg");
2472 assertEquals(graph.graphId, clone.graphId,
2473 "Graph ID");
2474
2475 for (int iv=0; iv<graph.getVertexCount(); iv++)
2476 {
2477 Vertex vg = graph.getVertexAtPosition(iv);
2478 Vertex vc = clone.getVertexAtPosition(iv);
2479 int hashVG = vg.hashCode();
2480 int hashVC = vc.hashCode();
2481
2482 for (int iap = 0; iap<vg.getNumberOfAPs(); iap++)
2483 {
2484 assertEquals(vg.getAP(iap).getOwner().hashCode(), hashVG,
2485 "Reference to vertex owner in ap " + iap + " vertex "
2486 + iv + "(G)");
2487 assertEquals(vc.getAP(iap).getOwner().hashCode(), hashVC,
2488 "Reference to vertex owner in ap " + iap + " vertex "
2489 + iv + " (C)");
2490 assertNotEquals(vc.getAP(iap).getOwner().hashCode(),
2491 vg.getAP(iap).getOwner().hashCode(),
2492 "Owner of AP "+iap+" in vertex "+iv);
2493 }
2494 }
2495 }
2496
2497//------------------------------------------------------------------------------
2498
2499 @Test
2501 {
2502 DGraph graph = new DGraph();
2505 graph.addVertex(tmpl);
2506
2507 assertEquals(1, graph.getMutableSites().size(),
2508 "Size of mutation list in case of frozen template");
2509
2510 graph = new DGraph();
2512 graph.addVertex(tmpl);
2513
2514 assertEquals(2, graph.getMutableSites().size(),
2515 "Size of mutation list in case of free template");
2516
2517 assertEquals(0, graph.getMutableSites(new ArrayList<>(
2518 Arrays.asList(MutationType.values()))).size(),
2519 "No sites if all is ignored");
2520 }
2521
2522//------------------------------------------------------------------------------
2523
2530 throws Exception
2531 {
2532 DGraph graph = new DGraph();
2534 BBType.SCAFFOLD, fs);
2535 graph.addVertex(s);
2536 return graph;
2537 }
2538
2539//------------------------------------------------------------------------------
2540
2547 throws Exception
2548 {
2549 DGraph graph = new DGraph();
2551 BBType.SCAFFOLD, fs);
2552 graph.addVertex(s);
2554 BBType.FRAGMENT, fs);
2555 graph.addVertex(v1a);
2556
2557 graph.addEdge(new Edge(s.getAP(0), v1a.getAP(0)));
2558
2559 return graph;
2560 }
2561
2562//------------------------------------------------------------------------------
2563
2579 public static DGraph makeTestGraphA()
2580 {
2581 DGraph graph = new DGraph();
2582
2583 // If we cannot make the test graph, something is deeeeeply wrong and
2584 // a bugfix is needed.
2585 try {
2586 IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
2587 IAtomContainer iac1 = builder.newAtomContainer();
2588 IAtom ia1 = new Atom("C");
2589 IAtom ia2 = new Atom("C");
2590 iac1.addAtom(ia1);
2591 iac1.addAtom(ia2);
2592 iac1.addBond(new Bond(ia1, ia2, IBond.Order.SINGLE));
2593
2594 Fragment v1 = new Fragment(1, iac1, BBType.SCAFFOLD);
2595 v1.addAP(0);
2596 v1.addAP(0);
2597 v1.addAP(0);
2598 v1.addAP(1);
2599
2600 IAtomContainer iac2 = builder.newAtomContainer();
2601 iac2.addAtom(new Atom("O"));
2602 Fragment v2 = new Fragment(2, iac2, BBType.FRAGMENT);
2603 v2.addAP(0);
2604 v2.addAP(0);
2605
2606 IAtomContainer iac3 = builder.newAtomContainer();
2607 iac3.addAtom(new Atom("H"));
2608 Fragment v3 = new Fragment(3, iac3,
2609 BBType.CAP);
2610 v3.addAP(0);
2611
2612 IAtomContainer iac4 = builder.newAtomContainer();
2613 iac4.addAtom(new Atom("H"));
2614 Fragment v4 = new Fragment(4, iac4,
2615 BBType.CAP);
2616 v4.addAP(0);
2617
2618 graph.addVertex(v1);
2619 graph.addVertex(v2);
2620 graph.addVertex(v3);
2621 graph.addVertex(v4);
2622 graph.addEdge(new Edge(v1.getAP(0), v2.getAP(0)));
2623 graph.addEdge(new Edge(v1.getAP(1), v3.getAP(0)));
2624 graph.addEdge(new Edge(v2.getAP(1), v4.getAP(0)));
2625
2626 // Use this just to verify identify of the graph
2627 /*
2628 System.out.println("WRITING TEST GRAPH A");
2629 DenoptimIO.writeGraphsToFile(new File("/tmp/test_graph_A"),
2630 FileFormat.GRAPHJSON,
2631 new ArrayList<DENOPTIMGraph>(Arrays.asList(graph)));
2632 */
2633 } catch (Throwable t)
2634 {
2635 t.printStackTrace();
2636 System.err.println("FATAL ERROR! Could not make test graph (A). "
2637 + "Please, report this to the development team.");
2638 System.exit(-1);
2639 }
2640
2641 return graph;
2642 }
2643
2644//------------------------------------------------------------------------------
2645
2668 public static DGraph makeTestGraphA2()
2669 {
2670 DGraph graph = new DGraph();
2671
2672 // If we cannot make the test graph, something is deeeeeply wrong and
2673 // a bugfix is needed.
2674 try {
2675 IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
2676 IAtomContainer iac1 = builder.newAtomContainer();
2677 IAtom ia1 = new Atom("C");
2678 IAtom ia2 = new Atom("C");
2679 iac1.addAtom(ia1);
2680 iac1.addAtom(ia2);
2681 iac1.addBond(new Bond(ia1, ia2, IBond.Order.SINGLE));
2682
2683 Fragment v1 = new Fragment(1, iac1, BBType.SCAFFOLD);
2684 v1.addAP(0, APClass.make(a,0));
2685 v1.addAP(0, APClass.make(b,1));
2686 v1.addAP(0, APClass.make(b,1));
2687 v1.addAP(1, APClass.make(a,0));
2688 v1.setBuildingBlockId(0);
2689
2690 IAtomContainer iac2 = builder.newAtomContainer();
2691 iac2.addAtom(new Atom("O"));
2692 Fragment v2 = new Fragment(2, iac2, BBType.FRAGMENT);
2693 v2.addAP(0, APClass.make(b,1));
2694 v2.addAP(0, APClass.make(b,1));
2695 v2.setBuildingBlockId(1);
2696
2697 IAtomContainer iac3 = builder.newAtomContainer();
2698 iac3.addAtom(new Atom("H"));
2699 Fragment v3 = new Fragment(3, iac3, BBType.CAP);
2700 v3.addAP(0, APClass.make(c,1));
2701 v3.setBuildingBlockId(2);
2702
2703 IAtomContainer iac4 = builder.newAtomContainer();
2704 iac4.addAtom(new Atom("H"));
2705 Fragment v4 = new Fragment(4, iac4, BBType.CAP);
2706 v4.addAP(0, APClass.make(c,1));
2707 v4.setBuildingBlockId(3);
2708
2709 EmptyVertex ev1 = new EmptyVertex();
2710 ev1.addAP(APClass.make(d,0));
2711 ev1.addAP(APClass.make(d,0));
2712
2713 EmptyVertex ev2 = new EmptyVertex();
2714 ev2.addAP(APClass.make(d,0));
2715 ev2.addAP(APClass.make(d,0));
2716
2717 EmptyVertex ev3 = new EmptyVertex();
2718 ev3.addAP(APClass.make(a,1));
2719 ev3.addAP(APClass.make(a,1));
2720
2721 graph.addVertex(v1);
2722 graph.addVertex(v2);
2723 graph.addVertex(v3);
2724 graph.addVertex(v4);
2725 graph.addVertex(ev3); //These are disordered on purpose
2726 graph.addVertex(ev2);
2727 graph.addVertex(ev1);
2728 graph.addEdge(new Edge(v1.getAP(0), v2.getAP(0),
2729 BondType.TRIPLE));
2730 graph.addEdge(new Edge(v1.getAP(1), v3.getAP(0),
2731 BondType.SINGLE));
2732 graph.addEdge(new Edge(v2.getAP(1), v4.getAP(0)));
2733 graph.addEdge(new Edge(v1.getAP(2), ev1.getAP(1),
2734 BondType.SINGLE));
2735 graph.addEdge(new Edge(v1.getAP(3), ev3.getAP(0),
2736 BondType.NONE));
2737 graph.addEdge(new Edge(ev1.getAP(0), ev2.getAP(0),
2738 BondType.TRIPLE));
2739
2740 // Use this just to verify identify of the graph
2741 /*
2742 System.out.println("WRITING TEST GRAPH A2 in /tmp/test_graph_A2.json");
2743 DenoptimIO.writeGraphToJSON(new File("/tmp/test_graph_A2.json"),
2744 graph);
2745 */
2746 } catch (Throwable t)
2747 {
2748 t.printStackTrace();
2749 System.err.println("FATAL ERROR! Could not make test graph (A). "
2750 + "Please, report this to the development team.");
2751 System.exit(-1);
2752 }
2753
2754 return graph;
2755 }
2756
2757//------------------------------------------------------------------------------
2758
2759 @Test
2760 public void testRemoveCapping() throws Exception
2761 {
2762 DGraph graph = new DGraph();
2763
2764 IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
2765 IAtomContainer iac1 = builder.newAtomContainer();
2766 iac1.addAtom(new Atom("C"));
2767 Fragment v1 = new Fragment(1, iac1, BBType.SCAFFOLD);
2768 v1.addAP(0);
2769 v1.addAP(0);
2770
2771 IAtomContainer iac2 = builder.newAtomContainer();
2772 iac2.addAtom(new Atom("O"));
2773 Fragment v2 = new Fragment(2, iac2, BBType.FRAGMENT);
2774 v2.addAP(0);
2775 v2.addAP(0);
2776
2777 IAtomContainer iac3 = builder.newAtomContainer();
2778 iac3.addAtom(new Atom("H"));
2779 Fragment v3 = new Fragment(3, iac3, BBType.CAP);
2780 v3.addAP(0);
2781
2782 IAtomContainer iac4 = builder.newAtomContainer();
2783 iac4.addAtom(new Atom("H"));
2784 Fragment v4 = new Fragment(4, iac4, BBType.CAP);
2785 v4.addAP(0);
2786
2787 graph.addVertex(v1);
2788 graph.addVertex(v2);
2789 graph.addVertex(v3);
2790 graph.addVertex(v4);
2791 graph.addEdge(new Edge(v1.getAP(0), v2.getAP(0)));
2792 graph.addEdge(new Edge(v1.getAP(1), v3.getAP(0)));
2793 graph.addEdge(new Edge(v2.getAP(1), v4.getAP(0)));
2794
2795 assertEquals(4, graph.getVertexCount(),
2796 "#vertices in graph before removal");
2797 assertTrue(graph == v4.getGraphOwner());
2798
2799 graph.removeCappingGroupsOn(v2);
2800
2801 assertEquals(3, graph.getVertexCount(),
2802 "#vertices in graph before removal");
2803 assertFalse(graph.containsVertex(v4),
2804 "Capping is still contained");
2805 assertTrue(null == v4.getGraphOwner(),
2806 "Owner of removed capping group is null");
2807
2808 DGraph graph2 = new DGraph();
2809
2810 IAtomContainer iac12 = builder.newAtomContainer();
2811 iac12.addAtom(new Atom("C"));
2812 Fragment v21 = new Fragment(21, iac12, BBType.SCAFFOLD);
2813 v21.addAP(0);
2814 v21.addAP(0);
2815
2816 IAtomContainer iac22 = builder.newAtomContainer();
2817 iac22.addAtom(new Atom("O"));
2818 Fragment v22 = new Fragment(22, iac22, BBType.FRAGMENT);
2819 v22.addAP(0);
2820 v22.addAP(0);
2821
2822 IAtomContainer iac23 = builder.newAtomContainer();
2823 iac23.addAtom(new Atom("H"));
2824 Fragment v23 = new Fragment(23, iac23, BBType.CAP);
2825 v23.addAP(0);
2826
2827 IAtomContainer iac24 = builder.newAtomContainer();
2828 iac24.addAtom(new Atom("H"));
2829 Fragment v24 = new Fragment(24, iac24, BBType.CAP);
2830 v24.addAP(0);
2831
2832 graph2.addVertex(v21);
2833 graph2.addVertex(v22);
2834 graph2.addVertex(v23);
2835 graph2.addVertex(v24);
2836 graph2.addEdge(new Edge(v21.getAP(0), v22.getAP(0)));
2837 graph2.addEdge(new Edge(v21.getAP(1), v23.getAP(0)));
2838 graph2.addEdge(new Edge(v22.getAP(1), v24.getAP(0)));
2839
2840 assertEquals(4, graph2.getVertexCount(),
2841 "#vertices in graph before removal (B)");
2842 assertTrue(graph2 == v23.getGraphOwner());
2843 assertTrue(graph2 == v24.getGraphOwner());
2844
2845 graph2.removeCappingGroups();
2846
2847 assertEquals(2, graph2.getVertexCount(),
2848 "#vertices in graph before removal (B)");
2849 assertFalse(graph.containsVertex(v24),
2850 "Capping is still contained (B)");
2851 assertFalse(graph.containsVertex(v23),
2852 "Capping is still contained (C)");
2853 assertTrue(null == v24.getGraphOwner(),
2854 "Owner of removed capping group is null (B)");
2855 assertTrue(null == v23.getGraphOwner(),
2856 "Owner of removed capping group is null (C)");
2857 }
2858
2859//------------------------------------------------------------------------------
2860
2861 private void buildVertexAndConnectToGraph(EmptyVertex v, int apCount,
2862 DGraph graph) throws DENOPTIMException
2863 {
2864 for (int atomPos = 0; atomPos < apCount; atomPos++) {
2865 v.addAP();
2866 }
2867 graph.addVertex(v);
2868 }
2869
2870//------------------------------------------------------------------------------
2871
2872 @Test
2873 public void testFromToJSON() throws Exception
2874 {
2875 DGraph graph = new DGraph();
2876
2877 EmptyVertex v0 = new EmptyVertex(0);
2878 buildVertexAndConnectToGraph(v0, 3, graph);
2879
2880 EmptyVertex v1 = new EmptyVertex(1);
2881 buildVertexAndConnectToGraph(v1, 2, graph);
2882 graph.addEdge(new Edge(v0.getAP(0), v1.getAP(0)));
2883
2884 EmptyVertex v2 = new EmptyVertex(2);
2885 buildVertexAndConnectToGraph(v2, 2, graph);
2886 graph.addEdge(new Edge(v1.getAP(1), v2.getAP(0)));
2887
2888 EmptyVertex v3 = new EmptyVertex(3);
2889 buildVertexAndConnectToGraph(v3, 1, graph);
2890 graph.addEdge(new Edge(v2.getAP(1), v3.getAP(0)));
2891
2892 EmptyVertex v4 = new EmptyVertex(4);
2893 buildVertexAndConnectToGraph(v4, 3, graph);
2894 graph.addEdge(new Edge(v0.getAP(1), v4.getAP(0)));
2895
2896 EmptyVertex v5 = new EmptyVertex(5);
2897 buildVertexAndConnectToGraph(v5, 1, graph);
2898 graph.addEdge(new Edge(v4.getAP(1), v5.getAP(0)));
2899
2900 EmptyVertex v6 = new EmptyVertex(6);
2901 buildVertexAndConnectToGraph(v6, 1, graph);
2902 graph.addEdge(new Edge(v0.getAP(2), v6.getAP(0)));
2903
2904 EmptyVertex v7 = new EmptyVertex(7);
2905 buildVertexAndConnectToGraph(v7, 1, graph);
2906 graph.addEdge(new Edge(v4.getAP(2), v7.getAP(0)));
2907
2908 graph.addRing(new Ring(new ArrayList<>(
2909 Arrays.asList(v5, v4, v0, v1, v2, v3))));
2910
2911 graph.addRing(new Ring(new ArrayList<>(
2912 Arrays.asList(v6, v0, v4, v7))));
2913
2915 ss1.add(v3);
2916 ss1.add(v5);
2917 graph.addSymmetricSetOfVertices(ss1);
2918
2920 ss2.add(v6);
2921 ss2.add(v7);
2922 graph.addSymmetricSetOfVertices(ss2);
2923
2924 String json1 = graph.toJson();
2925
2926 DGraph g2 = DGraph.fromJson(json1);
2927 String json2 = g2.toJson();
2928
2929 assertTrue(json1.equals(json2), "Round-trip via JSON is successful");
2930 }
2931
2932//-----------------------------------------------------------------------------
2933
2934 @Test
2935 public void testGraphIsomorphism() throws Exception
2936 {
2937 FragmentSpace fs = prepare();
2938
2939 DGraph gAempty = new DGraph();
2940 DGraph gBempty = new DGraph();
2941
2942 assertTrue(gAempty.isIsomorphicTo(gAempty),
2943 "self isomorphism on empty graph");
2944 assertTrue(gAempty.isIsomorphicTo(gBempty),
2945 "isomorphism on empty graphs");
2946
2947 DGraph g01 = makeTestGraph0(fs);
2948 DGraph g02 = makeTestGraph0(fs);
2949 assertTrue(g01.isIsomorphicTo(g02),
2950 "single-vertex graph");
2951 assertTrue(g01.isIsomorphicTo(g01.clone()),
2952 "single-vertex graph vs clone");
2953
2954 DGraph g03 = new DGraph();
2955 EmptyVertex v1 = new EmptyVertex();
2956 v1.addAP();
2957 v1.addAP();
2958 String k ="MyKey";
2960 v1.setProperty(k, 123);
2961 g03.addVertex(v1);
2962 EmptyVertex v2 = new EmptyVertex();
2963 v2.addAP();
2964 v2.addAP();
2966 v2.setProperty(k, 456);
2967 g03.appendVertexOnAP(v1.getAP(0), v2.getAP(0));
2968
2969 DGraph g04 = g03.clone();
2970 assertTrue(g03.isIsomorphicTo(g04),
2971 "graph with empty vertexes and same properties");
2972
2973 v2.setProperty(k, 999);
2974 assertFalse(g03.isIsomorphicTo(g04),
2975 "graph with empty vertexes and different properties");
2976
2977 DGraph g11 = makeTestGraph1(fs);
2978 DGraph g12 = makeTestGraph1(fs);
2979 assertTrue(g11.isIsomorphicTo(g12),"two-vertex graph");
2980 assertTrue(g11.isIsomorphicTo(g11.clone()),"two-vertex graph vs clone");
2981
2982 DGraph gD1 = makeTestGraphD(fs);
2983 DGraph gD2 = makeTestGraphD(fs);
2984 assertTrue(gD1.isIsomorphicTo(gD2),"two of same graph D");
2985 assertFalse(gD1.isIsomorphicTo(gAempty),"graph D vs empty graph");
2986 assertFalse(gAempty.isIsomorphicTo(gD1),"empty graph vs graph D");
2987
2988 DGraph gB1 = makeTestGraphB(fs);
2989 assertFalse(gD1.isIsomorphicTo(gB1),"graph D vs graph B");
2990
2991 DGraph gB2 = gB1.clone();
2992 assertTrue(gB1.isIsomorphicTo(gB2),"graph B vs its clone");
2993 }
2994
2995//-----------------------------------------------------------------------------
2996
2997 @Test
2998 public void testExtractSubgraph() throws Exception
2999 {
3000 FragmentSpace fs = prepare();
3001 DGraph graph = makeTestGraphD(fs);
3002 DGraph graphOriginal = makeTestGraphD(fs);
3003
3004 // This takes all graph
3005 DGraph subGraph = graph.extractSubgraph(
3006 graph.getVertexAtPosition(0));
3007 assertTrue(subGraph.isIsomorphicTo(graph), "complete subgraph");
3008 assertTrue(graph.isIsomorphicTo(graphOriginal),
3009 "Original stays the same");
3010
3011 // This takes a subgraph with a ring
3012 DGraph subGraph1 = graph.extractSubgraph(
3013 graph.getVertexAtPosition(1));
3014 DGraph expected1 = makeTestGraphDSub1(fs);
3015
3016 assertTrue(subGraph1.isIsomorphicTo(expected1), "Subgraph1");
3017 assertEquals(0,subGraph1.getSymmetricSetCount(),
3018 "SymmetricSets in subGraph1");
3019 assertEquals(1,subGraph1.getRingCount(),"Rings in subGraph1");
3020 assertTrue(graph.isIsomorphicTo(graphOriginal),
3021 "Original stays the same");
3022
3023 // This takes a subgraph with symmetric set, but no rings
3024 DGraph subGraph2 = graph.extractSubgraph(
3025 graph.getVertexAtPosition(10));
3026 DGraph expected2 = makeTestGraphDSub2(fs);
3027
3028 assertTrue(subGraph2.isIsomorphicTo(expected2), "Subgraph2");
3029 assertEquals(1,subGraph2.getSymmetricSetCount(),
3030 "SymmetricSets in subGraph2");
3031 assertEquals(0,subGraph2.getRingCount(),"Rings in subGraph2");
3032 assertTrue(graph.isIsomorphicTo(graphOriginal),
3033 "Original stays the same");
3034 }
3035
3036//-----------------------------------------------------------------------------
3037
3038 @Test
3039 public void testExtractSubgraphFromCollection() throws Exception
3040 {
3041 FragmentSpace fs = prepare();
3042 DGraph graph = makeTestGraphD(fs);
3043
3044 Set<Vertex> targetVertexes = new HashSet<>();
3045 targetVertexes.add(graph.getVertexAtPosition(1));
3046 targetVertexes.add(graph.getVertexAtPosition(3));
3047
3048 DGraph subGraph = graph.extractSubgraph(targetVertexes);
3049
3050 assertEquals(targetVertexes.size(), subGraph.getVertexCount());
3051 for (Vertex vInTarget : targetVertexes)
3052 {
3053 assertNotNull(subGraph.getVertexWithId(vInTarget.getVertexId()));
3054 }
3055
3056 Set<Edge> connectionToSubgraph = new HashSet<Edge>();
3057 Set<Edge> connectionFromSubgraph = new HashSet<Edge>();
3058 subGraph = graph.extractSubgraph(targetVertexes,
3059 connectionToSubgraph, connectionFromSubgraph);
3060
3061 assertEquals(1, connectionToSubgraph.size());
3062 assertEquals(3, connectionFromSubgraph.size());
3063
3064 // NB: the subgraph contains clones, but the lists of edges contain
3065 // references to the original graph
3066
3067 boolean found0 = false;
3068 for (Edge e : connectionToSubgraph)
3069 {
3070 Vertex inResults = e.getSrcAP().getOwner();
3071 if (graph.getVertexAtPosition(0) == inResults)
3072 found0 = true;
3073 }
3074 assertTrue(found0);
3075
3076 boolean found2 = false;
3077 boolean found4 = false;
3078 boolean found6 = false;
3079 for (Edge e : connectionFromSubgraph)
3080 {
3081 Vertex inResults = e.getTrgAP().getOwner();
3082 if (graph.getVertexAtPosition(2) == inResults)
3083 found2 = true;
3084 if (graph.getVertexAtPosition(4) == inResults)
3085 found4 = true;
3086 if (graph.getVertexAtPosition(6) == inResults)
3087 found6 = true;
3088 }
3089 assertTrue(found2);
3090 assertTrue(found4);
3091 assertTrue(found6);
3092 }
3093
3094//-----------------------------------------------------------------------------
3095
3096 @Test
3097 public void testFindVertex() throws Exception
3098 {
3099 DGraph g = makeTestGraphA2();
3100
3101 List<VertexQuery> allQueries = new ArrayList<VertexQuery>();
3102 List<List<Vertex>> allExpected =
3103 new ArrayList<List<Vertex>>();
3104
3105 VertexQuery q0 = new VertexQuery(null, null, null, null, null, null, null);
3106 List<Vertex> e0 = new ArrayList<Vertex>();
3107 e0.addAll(g.getVertexList());
3108 allQueries.add(q0);
3109 allExpected.add(e0);
3110
3111 VertexQuery q1 = new VertexQuery(
3113 null, null, null, null, null, null);
3114 List<Vertex> e1 = new ArrayList<Vertex>();
3115 e1.add(g.getVertexAtPosition(5));
3116 allQueries.add(q1);
3117 allExpected.add(e1);
3118
3119 VertexQuery q2 = new VertexQuery(
3121 null, null, null, null, null, null);
3122 List<Vertex> e2 = new ArrayList<Vertex>();
3123 e2.add(g.getVertexAtPosition(2));
3124 allQueries.add(q2);
3125 allExpected.add(e2);
3126
3128 null, null, null, null, null);
3129 List<Vertex> e3 = new ArrayList<Vertex>();
3130 e3.add(g.getVertexAtPosition(4));
3131 e3.add(g.getVertexAtPosition(5));
3132 e3.add(g.getVertexAtPosition(6));
3133 allQueries.add(q3);
3134 allExpected.add(e3);
3135
3136 VertexQuery q4 = new VertexQuery(null, null, BBType.CAP,
3137 null, null, null, null);
3138 List<Vertex> e4 = new ArrayList<Vertex>();
3139 e4.add(g.getVertexAtPosition(2));
3140 e4.add(g.getVertexAtPosition(3));
3141 allQueries.add(q4);
3142 allExpected.add(e4);
3143
3144 VertexQuery q5 = new VertexQuery(null, null, null, 2,
3145 null, null, null);
3146 List<Vertex> e5 = new ArrayList<Vertex>();
3147 e5.add(g.getVertexAtPosition(2));
3148 allQueries.add(q5);
3149 allExpected.add(e5);
3150
3151 VertexQuery q6 = new VertexQuery(null, null, null, null, 1,
3152 null, null);
3153 List<Vertex> e6 = new ArrayList<Vertex>();
3154 e6.add(g.getVertexAtPosition(3));
3155 e6.add(g.getVertexAtPosition(5));
3156 allQueries.add(q6);
3157 allExpected.add(e6);
3158
3159 //
3160 // From here: test filters acting on incoming edge
3161 //
3162
3163 EdgeQuery eq7 = new EdgeQuery(null, null, null, null, null, null, null);
3164 VertexQuery q7 = new VertexQuery(null, null, null, null, null,
3165 eq7, eq7);
3166 List<Vertex> e7 = new ArrayList<Vertex>();
3167 e7.addAll(g.getVertexList());
3168 allQueries.add(q7);
3169 allExpected.add(e7);
3170
3172 null, null, null, null, null, null);
3173 VertexQuery q8 = new VertexQuery(null, null, null, null, null,
3174 eq8, null);
3175 List<Vertex> e8 = new ArrayList<Vertex>();
3176 e8.add(g.getVertexAtPosition(3));
3177 allQueries.add(q8);
3178 allExpected.add(e8);
3179
3180 //NB: the trg vertex ID on the incoming vertex is NOT considered
3181 // because it is a redundant condition that should be expressed as
3182 // the VertexQuery vID argument.
3183 EdgeQuery eq9 = new EdgeQuery(null,
3185 null, null, null, null, null);
3186 VertexQuery q9 = new VertexQuery(null, null, null, null, null,
3187 eq9, null);
3188 List<Vertex> e9 = new ArrayList<Vertex>();
3189 e9.addAll(g.getVertexList());
3190 allQueries.add(q9);
3191 allExpected.add(e9);
3192
3193 EdgeQuery eq10 = new EdgeQuery(null, null, 1, null, null, null, null);
3194 VertexQuery q10 = new VertexQuery(null, null, null, null, null,
3195 eq10, null);
3196 List<Vertex> e10 = new ArrayList<Vertex>();
3197 e10.add(g.getVertexAtPosition(2));
3198 e10.add(g.getVertexAtPosition(3));
3199 allQueries.add(q10);
3200 allExpected.add(e10);
3201
3202 EdgeQuery eq11 = new EdgeQuery(null, null, null, 0, null, null, null);
3203 VertexQuery q11 = new VertexQuery(null, null, null, null, null,
3204 eq11, null);
3205 List<Vertex> e11 = new ArrayList<Vertex>();
3206 e11.add(g.getVertexAtPosition(1));
3207 e11.add(g.getVertexAtPosition(2));
3208 e11.add(g.getVertexAtPosition(3));
3209 e11.add(g.getVertexAtPosition(4));
3210 e11.add(g.getVertexAtPosition(5));
3211 allQueries.add(q11);
3212 allExpected.add(e11);
3213
3214 EdgeQuery eq12 = new EdgeQuery(null, null, null, null,
3215 BondType.TRIPLE, null, null);
3216 VertexQuery q12 = new VertexQuery(null, null, null, null, null,
3217 eq12, null);
3218 List<Vertex> e12 = new ArrayList<Vertex>();
3219 e12.add(g.getVertexAtPosition(1));
3220 e12.add(g.getVertexAtPosition(5));
3221 allQueries.add(q12);
3222 allExpected.add(e12);
3223
3224 EdgeQuery eq13 = new EdgeQuery(null, null, null, null, null,
3225 APClass.make(b,1), null);
3226 VertexQuery q13 = new VertexQuery(null, null, null, null, null,
3227 eq13, null);
3228 List<Vertex> e13 = new ArrayList<Vertex>();
3229 e13.add(g.getVertexAtPosition(2));
3230 e13.add(g.getVertexAtPosition(3));
3231 e13.add(g.getVertexAtPosition(6));
3232 allQueries.add(q13);
3233 allExpected.add(e13);
3234
3235 EdgeQuery eq14 = new EdgeQuery(null, null, null, null, null, null,
3236 APClass.make(c,1));
3237 VertexQuery q14 = new VertexQuery(null, null, null, null, null,
3238 eq14, null);
3239 List<Vertex> e14 = new ArrayList<Vertex>();
3240 e14.add(g.getVertexAtPosition(2));
3241 e14.add(g.getVertexAtPosition(3));
3242 allQueries.add(q14);
3243 allExpected.add(e14);
3244
3245 //
3246 // From here: test filters acting on outgoing edge
3247 //
3248
3249 //NB: the src vertex ID on the outging vertex is NOT considered
3250 // because it is a redundant condition that should be expressed as
3251 // the VertexQuery vID argument.
3253 null, null, null, null, null, null);
3254 VertexQuery q15 = new VertexQuery(null, null, null, null, null, null,
3255 eq15);
3256 List<Vertex> e15 = new ArrayList<Vertex>();
3257 e15.addAll(g.getVertexList());
3258 allQueries.add(q15);
3259 allExpected.add(e15);
3260
3261 EdgeQuery eq16 = new EdgeQuery(null,
3263 null, null, null, null, null);
3264 VertexQuery q16 = new VertexQuery(null, null, null, null, null, null,
3265 eq16);
3266 List<Vertex> e16 = new ArrayList<Vertex>();
3267 e16.add(g.getVertexAtPosition(1));
3268 allQueries.add(q16);
3269 allExpected.add(e16);
3270
3271 EdgeQuery eq17 = new EdgeQuery(null, null, 1, null, null, null, null);
3272 VertexQuery q17 = new VertexQuery(null, null, null, null, null, null,
3273 eq17);
3274 List<Vertex> e17 = new ArrayList<Vertex>();
3275 e17.add(g.getVertexAtPosition(0));
3276 e17.add(g.getVertexAtPosition(1));
3277 allQueries.add(q17);
3278 allExpected.add(e17);
3279
3280 EdgeQuery eq18 = new EdgeQuery(null, null, null, 0, null, null, null);
3281 VertexQuery q18 = new VertexQuery(null, null, null, null, null, null,
3282 eq18);
3283 List<Vertex> e18 = new ArrayList<Vertex>();
3284 e18.add(g.getVertexAtPosition(0));
3285 e18.add(g.getVertexAtPosition(1));
3286 e18.add(g.getVertexAtPosition(6));
3287 allQueries.add(q18);
3288 allExpected.add(e18);
3289
3290 EdgeQuery eq19 = new EdgeQuery(null, null, null, null,
3291 BondType.TRIPLE, null, null);
3292 VertexQuery q19 = new VertexQuery(null, null, null, null, null, null,
3293 eq19);
3294 List<Vertex> e19 = new ArrayList<Vertex>();
3295 e19.add(g.getVertexAtPosition(0));
3296 e19.add(g.getVertexAtPosition(6));
3297 allQueries.add(q19);
3298 allExpected.add(e19);
3299
3300 EdgeQuery eq20 = new EdgeQuery(null, null, null, null, null,
3301 APClass.make(b,1), null);
3302 VertexQuery q20 = new VertexQuery(null, null, null, null, null, null,
3303 eq20);
3304 List<Vertex> e20 = new ArrayList<Vertex>();
3305 e20.add(g.getVertexAtPosition(0));
3306 e20.add(g.getVertexAtPosition(1));
3307 allQueries.add(q20);
3308 allExpected.add(e20);
3309
3310 EdgeQuery eq21 = new EdgeQuery(null, null, null, null, null, null,
3311 APClass.make(d,0));
3312 VertexQuery q21 = new VertexQuery(null, null, null, null, null, null,
3313 eq21);
3314 List<Vertex> e21 = new ArrayList<Vertex>();
3315 e21.add(g.getVertexAtPosition(0));
3316 e21.add(g.getVertexAtPosition(6));
3317 allQueries.add(q21);
3318 allExpected.add(e21);
3319
3320 //
3321 // From here: test combinations
3322 //
3323
3324 EdgeQuery eq22in = new EdgeQuery(null, null, null, 0, null, null, null);
3325 EdgeQuery eq22out = new EdgeQuery(null, null, 1,null, null, null, null);
3326 VertexQuery q22 = new VertexQuery(null, null, null, null, null,
3327 eq22in, eq22out);
3328 List<Vertex> e22 = new ArrayList<Vertex>();
3329 e22.add(g.getVertexAtPosition(1));
3330 allQueries.add(q22);
3331 allExpected.add(e22);
3332
3333 EdgeQuery eq23 = new EdgeQuery(null, null, null, null, BondType.TRIPLE,
3334 null, null);
3336 null, null, null, eq23, null);
3337 List<Vertex> e23 = new ArrayList<Vertex>();
3338 e23.add(g.getVertexAtPosition(1));
3339 allQueries.add(q23);
3340 allExpected.add(e23);
3341
3342 for (int i=0; i<allQueries.size(); i++)
3343 {
3344 List<Vertex> matches = g.findVertices(allQueries.get(i),
3345 Logger.getLogger("DummyLogger"));
3346 assertEquals(allExpected.get(i).size(),matches.size(),
3347 "Different number of matched vertexes ("+i+")");
3348 assertTrue(allExpected.get(i).containsAll(matches),
3349 "Inconsistent matches ("+i+")");
3350 }
3351 }
3352
3353//------------------------------------------------------------------------------
3354
3355
3356 @Test
3357 public void testSymmetricSetLabels() throws Exception
3358 {
3359 FragmentSpace fs = prepare();
3360 DGraph g = makeTestGraphB(fs);
3361
3363
3364 Map<Object,Integer> countsPerLabel = new HashMap<Object,Integer>();
3365 for (Vertex v : g.getVertexList())
3366 {
3367 Object label = v.getProperty(DENOPTIMConstants.VRTSYMMSETID);
3368 if (countsPerLabel.containsKey(label))
3369 countsPerLabel.put(label,countsPerLabel.get(label)+1);
3370 else
3371 countsPerLabel.put(label,1);
3372 }
3373
3374 assertEquals(1,countsPerLabel.get(g.getVertexAtPosition(0).getProperty(
3376 assertEquals(2,countsPerLabel.get(g.getVertexAtPosition(1).getProperty(
3378 assertEquals(4,countsPerLabel.get(g.getVertexAtPosition(2).getProperty(
3380 assertEquals(4,countsPerLabel.get(g.getVertexAtPosition(3).getProperty(
3382 assertEquals(1,countsPerLabel.get(g.getVertexAtPosition(4).getProperty(
3384 assertEquals(1,countsPerLabel.get(g.getVertexAtPosition(8).getProperty(
3386 }
3387
3388//------------------------------------------------------------------------------
3389
3390 @Test
3391 public void testConvertSymmetricLabelsToSymmetricSets() throws Exception
3392 {
3393 FragmentSpace fs = prepare();
3394 DGraph g = makeTestGraphE(fs);
3396 "1234-ABC");
3398 "1234-ABC");
3400 "1234-ABC");
3401
3403
3404 assertEquals(2,g.getSymmetricSetCount(),"number of sets");
3405 boolean foundA = false;
3406 boolean foundB = false;
3407 Iterator<SymmetricVertexes> iter = g.getSymSetsIterator();
3408 while (iter.hasNext())
3409 {
3410 SymmetricVertexes ss = iter.next();
3411 if (ss.size() == 2)
3412 foundA = true;
3413 if (ss.size() == 4)
3414 foundB = true;
3415 }
3416 assertTrue(foundA,"Found 2-membered set");
3417 assertTrue(foundB,"Found 4-membered set");
3418
3419 DGraph g2 = makeTestGraphE(fs);
3421 "1234-ABC");
3423 "1234-ABC");
3424
3426
3427 assertEquals(3,g2.getSymmetricSetCount(),"number of sets");
3428 Iterator<SymmetricVertexes> iter2 = g2.getSymSetsIterator();
3429 while (iter2.hasNext())
3430 {
3431 SymmetricVertexes ss = iter2.next();
3432 assertEquals(2,ss.size(),"side of each symmetric sets.");
3433 }
3434 }
3435
3436//------------------------------------------------------------------------------
3437
3438 @Test
3439 public void testGetSymmetricSubGraphs() throws Exception
3440 {
3441 FragmentSpace fs = prepare();
3442 DGraph g = makeTestGraphF(fs);
3443 List<Vertex> sg = new ArrayList<Vertex>();
3444 sg.add(g.getVertexAtPosition(1));
3445 sg.add(g.getVertexAtPosition(3));
3446
3447 List<List<Vertex>> symSubGraphs = g.getSymmetricSubGraphs(sg);
3448
3449 assertEquals(2,symSubGraphs.size(),"Number of subgraphs");
3450 assertEquals(g.getVertexAtPosition(1).getVertexId(),
3451 symSubGraphs.get(0).get(0).getVertexId());
3452 assertEquals(g.getVertexAtPosition(3).getVertexId(),
3453 symSubGraphs.get(0).get(1).getVertexId());
3454 assertEquals(g.getVertexAtPosition(2).getVertexId(),
3455 symSubGraphs.get(1).get(0).getVertexId());
3456 assertEquals(g.getVertexAtPosition(4).getVertexId(),
3457 symSubGraphs.get(1).get(1).getVertexId());
3458
3459
3460 DGraph g2 = makeTestGraphK(fs);
3461 List<Vertex> sg2 = new ArrayList<Vertex>();
3462 sg2.add(g2.getVertexAtPosition(1));
3463 sg2.add(g2.getVertexAtPosition(4));
3464 sg2.add(g2.getVertexAtPosition(12));
3465
3466 /*
3467 * In the second part we check that capping groups are not included.
3468 */
3469
3470 boolean exceptionWhenCappingIsIncluded = false;
3471 try
3472 {
3473 symSubGraphs = g2.getSymmetricSubGraphs(sg2);
3474 } catch (DENOPTIMException e)
3475 {
3476 if (e.getMessage().contains("Capping groups must not be part of "
3477 + "symmetric subgraphs"))
3478 exceptionWhenCappingIsIncluded = true;
3479 }
3480 assertTrue(exceptionWhenCappingIsIncluded,
3481 "Capping groups trigger exception");
3482
3483 sg2 = new ArrayList<Vertex>();
3484 sg2.add(g2.getVertexAtPosition(1));
3485 sg2.add(g2.getVertexAtPosition(4));
3486 symSubGraphs = g2.getSymmetricSubGraphs(sg2);
3487 assertEquals(2,symSubGraphs.size());
3488 assertEquals(2,symSubGraphs.get(0).size());
3489 assertEquals(2,symSubGraphs.get(1).size());
3490 }
3491
3492//------------------------------------------------------------------------------
3493
3494 @Test
3495 public void testGetChildrenTree() throws Exception
3496 {
3497 FragmentSpace fs = prepare();
3498 DGraph g = makeTestGraphD(fs);
3499
3500 List<Vertex> childTree = new ArrayList<Vertex>();
3501 g.getChildrenTree(g.getVertexAtPosition(1), childTree);
3502 assertEquals(6,childTree.size());
3503 assertTrue(childTree.contains(g.getVertexAtPosition(2)));
3504 assertTrue(childTree.contains(g.getVertexAtPosition(3)));
3505 assertTrue(childTree.contains(g.getVertexAtPosition(4)));
3506 assertTrue(childTree.contains(g.getVertexAtPosition(5)));
3507 assertTrue(childTree.contains(g.getVertexAtPosition(6)));
3508 assertTrue(childTree.contains(g.getVertexAtPosition(7)));
3509
3510 childTree = new ArrayList<Vertex>();
3511 g.getChildrenTree(g.getVertexAtPosition(9), childTree, 1, false);
3512 assertEquals(1,childTree.size());
3513 assertTrue(childTree.contains(g.getVertexAtPosition(10)));
3514
3515 childTree = new ArrayList<Vertex>();
3516 g.getChildrenTree(g.getVertexAtPosition(9), childTree, 2, false);
3517 assertEquals(4,childTree.size());
3518 assertTrue(childTree.contains(g.getVertexAtPosition(10)));
3519 assertTrue(childTree.contains(g.getVertexAtPosition(11)));
3520 assertTrue(childTree.contains(g.getVertexAtPosition(12)));
3521 assertTrue(childTree.contains(g.getVertexAtPosition(13)));
3522
3523 childTree = new ArrayList<Vertex>();
3524 g.getChildrenTree(g.getVertexAtPosition(1), childTree, Integer.MAX_VALUE,
3525 true);
3526 assertEquals(3,childTree.size());
3527 assertTrue(childTree.contains(g.getVertexAtPosition(2)));
3528 assertTrue(childTree.contains(g.getVertexAtPosition(3)));
3529 assertTrue(childTree.contains(g.getVertexAtPosition(4)));
3530 }
3531
3532//------------------------------------------------------------------------------
3533
3534 @Test
3535 public void testGetChildrenTreeWithBranchIdentifier() throws Exception
3536 {
3537 FragmentSpace fs = prepare();
3538 DGraph g = makeTestGraphD(fs);
3539
3540 assertNull(g.getBranchIdOfVertexAtPosition(0));
3541 assertNull(g.getBranchIdOfVertexAtPosition(1));
3542 assertNull(g.getBranchIdOfVertexAtPosition(3));
3543
3544 List<Vertex> childTree = new ArrayList<Vertex>();
3545 g.getChildrenTree(g.getVertexAtPosition(0), childTree,
3546 new AtomicInteger(0), new ArrayList<Integer>());
3547
3548 assertEquals(g.getBranchIdOfVertexAtPosition(3),
3550 assertEquals(g.getBranchIdOfVertexAtPosition(2),
3552 assertEquals(g.getBranchIdOfVertexAtPosition(3),
3554 assertEquals(g.getBranchIdOfVertexAtPosition(4),
3556 assertNotEquals(g.getBranchIdOfVertexAtPosition(2),
3558 assertNotEquals(g.getBranchIdOfVertexAtPosition(2),
3560 assertNotEquals(g.getBranchIdOfVertexAtPosition(3),
3562
3563 assertTrue(g.directedPathExists(g.getVertexAtPosition(1),
3564 g.getVertexAtPosition(5)));
3565 assertTrue(g.directedPathExists(g.getVertexAtPosition(9),
3566 g.getVertexAtPosition(13)));
3567 assertFalse(g.directedPathExists(g.getVertexAtPosition(8),
3568 g.getVertexAtPosition(9)));
3569 assertFalse(g.directedPathExists(g.getVertexAtPosition(9),
3570 g.getVertexAtPosition(8)));
3571 assertFalse(g.directedPathExists(g.getVertexAtPosition(5),
3572 g.getVertexAtPosition(1)));
3573 assertFalse(g.directedPathExists(g.getVertexAtPosition(13),
3574 g.getVertexAtPosition(9)));
3575 }
3576
3577//------------------------------------------------------------------------------
3578
3579 @Test
3580 public void testGetInterfaceAPs() throws Exception
3581 {
3582 FragmentSpace fs = prepare();
3583 DGraph g = makeTestGraphI(fs);
3584
3585 List<Vertex> subGraph = new ArrayList<Vertex>();
3586 subGraph.add(g.getVertexAtPosition(0));
3587 subGraph.add(g.getVertexAtPosition(1));
3588
3589 List<AttachmentPoint> expected = new ArrayList<AttachmentPoint>();
3590 expected.add(g.getVertexAtPosition(0).getAP(1));
3591 expected.add(g.getVertexAtPosition(1).getAP(1));
3592
3593 List<AttachmentPoint> interfaceAPs = g.getInterfaceAPs(subGraph);
3594
3595 assertEquals(expected,interfaceAPs);
3596
3597 DGraph innerGraph = ((Template) g.getVertexAtPosition(0))
3598 .getInnerGraph();
3599
3600 subGraph = new ArrayList<Vertex>();
3601 subGraph.add(innerGraph.getVertexAtPosition(0));
3602 subGraph.add(innerGraph.getVertexAtPosition(1));
3603
3604 expected = new ArrayList<AttachmentPoint>();
3605 expected.add(innerGraph.getVertexAtPosition(0).getAP(0));
3606 expected.add(innerGraph.getVertexAtPosition(0).getAP(1));
3607 expected.add(innerGraph.getVertexAtPosition(0).getAP(4));
3608 expected.add(innerGraph.getVertexAtPosition(1).getAP(1));
3609
3610 interfaceAPs = innerGraph.getInterfaceAPs(subGraph);
3611
3612 assertEquals(expected,interfaceAPs);
3613 }
3614
3615//------------------------------------------------------------------------------
3616
3617 @Test
3618 public void testGetSubgraphAPs() throws Exception
3619 {
3620 FragmentSpace fs = prepare();
3621 DGraph g = makeTestGraphI(fs);
3622
3623 DGraph innerGraph = ((Template) g.getVertexAtPosition(0))
3624 .getInnerGraph();
3625
3626 List<Vertex> subGraph = new ArrayList<Vertex>();
3627 subGraph.add(innerGraph.getVertexAtPosition(0));
3628 subGraph.add(innerGraph.getVertexAtPosition(1));
3629
3630 List<AttachmentPoint>expected = new ArrayList<AttachmentPoint>();
3631 expected.add(innerGraph.getVertexAtPosition(0).getAP(0));
3632 expected.add(innerGraph.getVertexAtPosition(0).getAP(1));
3633 expected.add(innerGraph.getVertexAtPosition(0).getAP(2));
3634 expected.add(innerGraph.getVertexAtPosition(0).getAP(4));
3635 expected.add(innerGraph.getVertexAtPosition(1).getAP(1));
3636
3637 List<AttachmentPoint> interfaceAPs = innerGraph.getSubgraphAPs(
3638 subGraph);
3639
3640 assertEquals(expected,interfaceAPs);
3641 }
3642
3643//------------------------------------------------------------------------------
3644
3645 public DGraph[] makeIsostructuralGraphs() throws Exception
3646 {
3647 String unqProp = "UNQPROP";
3648 EmptyVertex rcvA1 = new EmptyVertex(11002);
3649 rcvA1.addAP(APCA);
3650 rcvA1.setAsRCV(true);
3651 EmptyVertex rcvA2 = new EmptyVertex(11003);
3652 rcvA2.addAP(APCA);
3653 rcvA2.setAsRCV(true);
3654 EmptyVertex vA0 = new EmptyVertex(10000);
3655 vA0.addAP(APCA);
3656 vA0.addAP(APCA);
3657 vA0.addAP(APCB);
3658 vA0.setUniquefyingProperty(unqProp);
3659 vA0.setProperty(unqProp, 111);
3660 EmptyVertex vA1 = new EmptyVertex(10001);
3661 vA1.addAP(APCA);
3662 vA1.addAP(APCA);
3663 vA1.setUniquefyingProperty(unqProp);
3664 vA1.setProperty(unqProp, 222);
3665 EmptyVertex vA2= new EmptyVertex(10002);
3666 vA2.addAP(APCA);
3667 vA2.addAP(APCA);
3668 EmptyVertex vA3 = new EmptyVertex(10003);
3669 vA3.addAP(APCA);
3670 vA3.addAP(APCA);
3671 vA3.addAP(APCB);
3672 DGraph g3A = new DGraph();
3673 g3A.addVertex(vA0);
3674 g3A.appendVertexOnAP(vA0.getAP(0), vA1.getAP(0));
3675 g3A.appendVertexOnAP(vA1.getAP(1), vA2.getAP(0));
3676 g3A.appendVertexOnAP(vA2.getAP(1), vA3.getAP(0));
3677 g3A.appendVertexOnAP(vA3.getAP(1), rcvA1.getAP(0));
3678 g3A.appendVertexOnAP(vA0.getAP(1), rcvA2.getAP(0));
3679 g3A.addRing(rcvA1, rcvA2);
3680
3681 // now build second
3682 EmptyVertex rcvB1 = new EmptyVertex(21002);
3683 rcvB1.addAP(APCA);
3684 rcvB1.setAsRCV(true);
3685 EmptyVertex rcvB2 = new EmptyVertex(21003);
3686 rcvB2.addAP(APCA);
3687 rcvB2.setAsRCV(true);
3688 EmptyVertex vB0 = new EmptyVertex(20000);
3689 vB0.addAP(APCA);
3690 vB0.addAP(APCA);
3691 vB0.addAP(APCB);
3692 vA0.setUniquefyingProperty(unqProp);
3693 vA0.setProperty(unqProp, 333);
3694 EmptyVertex vB1 = new EmptyVertex(20001);
3695 vB1.addAP(APCA);
3696 vB1.addAP(APCA);
3697 vA0.setUniquefyingProperty(unqProp);
3698 vA0.setProperty(unqProp, 444);
3699 EmptyVertex vB2= new EmptyVertex(20002);
3700 vB2.addAP(APCA);
3701 vB2.addAP(APCA);
3702 EmptyVertex vB3 = new EmptyVertex(20003);
3703 vB3.addAP(APCA);
3704 vB3.addAP(APCA);
3705 vB3.addAP(APCB);
3706 DGraph g3B = new DGraph();
3707 g3B.addVertex(vB1);
3708 g3B.appendVertexOnAP(vB1.getAP(1), vB2.getAP(0));
3709 g3B.appendVertexOnAP(vB2.getAP(1), vB3.getAP(0));
3710 g3B.appendVertexOnAP(vB3.getAP(1), vB0.getAP(1));
3711 g3B.appendVertexOnAP(vB0.getAP(0), rcvB1.getAP(0));
3712 g3B.appendVertexOnAP(vB1.getAP(0), rcvB2.getAP(0));
3713 g3B.addRing(rcvB1, rcvB2);
3714
3715 DGraph[] pair = new DGraph[2];
3716 pair[0] = g3A;
3717 pair[1] = g3B;
3718 return pair;
3719 }
3720
3721//------------------------------------------------------------------------------
3722
3723 @Test
3724 public void testIsIsostructuralTo() throws Exception
3725 {
3726 FragmentSpace fs = prepare();
3727
3728 DGraph gAempty = new DGraph();
3729 DGraph gBempty = new DGraph();
3730
3731 assertTrue(gAempty.isIsostructuralTo(gAempty));
3732 assertTrue(gAempty.isIsostructuralTo(gBempty));
3733
3734 DGraph g01 = makeTestGraph0(fs);
3735 DGraph g02 = makeTestGraph0(fs);
3736 assertTrue(g01.isIsostructuralTo(g02));
3737 assertTrue(g01.isIsostructuralTo(g01.clone()));
3738
3739 DGraph g11 = makeTestGraph1(fs);
3740 DGraph g12 = makeTestGraph1(fs);
3741 assertTrue(g11.isIsostructuralTo(g12));
3742 assertFalse(g11.isIsostructuralTo(g01));
3743 assertFalse(g11.isIsostructuralTo(g02));
3744 assertTrue(g11.isIsostructuralTo(g11.clone()));
3745
3746 DGraph gD1 = makeTestGraphD(fs);
3747 DGraph gD2 = makeTestGraphD(fs);
3748 assertTrue(gD1.isIsostructuralTo(gD2));
3749 assertFalse(gD1.isIsostructuralTo(gAempty));
3750 assertFalse(gAempty.isIsostructuralTo(gD1));
3751
3752 DGraph gB1 = makeTestGraphB(fs);
3753 assertFalse(gD1.isIsostructuralTo(gB1));
3754
3755 DGraph gB2 = gB1.clone();
3756 assertTrue(gB1.isIsostructuralTo(gB2));
3757
3758 // Up to here we checked consistency with isIsomorficTo().
3759 // Now, make a pair of graphs that are not isomorphic by replacing one
3760 // of the vertexes with a new vertex that does not satisfy sameAs()
3761 DGraph g1 = makeTestGraphDSub1(fs);
3762 DGraph g2 = makeTestGraphDSub1(fs);
3763
3764 EmptyVertex v1 = new EmptyVertex(10001);
3765 v1.addAP(APCD);
3766 v1.addAP(APCC);
3767 v1.setUniquefyingProperty("blabla123");
3768 v1.setProperty("blabla123", 123);
3769
3770 DGraph incomingSubGraph = new DGraph();
3771 incomingSubGraph.addVertex(v1);
3772
3773 LinkedHashMap<AttachmentPoint,AttachmentPoint> apMap =
3774 new LinkedHashMap<AttachmentPoint,AttachmentPoint>();
3775 apMap.put(g2.getVertexAtPosition(1).getAP(0), v1.getAP(1));
3776 apMap.put(g2.getVertexAtPosition(1).getAP(1), v1.getAP(0));
3777
3778 List<Vertex> toReplace = new ArrayList<Vertex>();
3779 toReplace.add(g2.getVertexAtPosition(1));
3780 g2.replaceSingleSubGraph(toReplace, incomingSubGraph, apMap);
3781
3782 assertFalse(g1.isIsomorphicTo(g2));
3783 assertTrue(g1.isIsostructuralTo(g2));
3784
3785 // Change structure by adding a bifurcation
3786 EmptyVertex v2 = new EmptyVertex(100002);
3787 v2.addAP(APCD);
3788 v2.addAP(APCC);
3789 v2.addAP(APCC);
3790 v2.setUniquefyingProperty("blabla456");
3791 v2.setProperty("blabla456", 456);
3792 incomingSubGraph = new DGraph();
3793 incomingSubGraph.addVertex(v2);
3794 apMap = new LinkedHashMap<AttachmentPoint,AttachmentPoint>();
3795 apMap.put(g2.getVertexAtPosition(2).getAP(0), v1.getAP(1));
3796 apMap.put(g2.getVertexAtPosition(2).getAP(1), v1.getAP(0));
3797 toReplace = new ArrayList<Vertex>();
3798 toReplace.add(g2.getVertexAtPosition(2));
3799 g2.replaceSingleSubGraph(toReplace, incomingSubGraph, apMap);
3800
3801 assertFalse(g1.isIsomorphicTo(g2));
3802 assertFalse(g1.isIsostructuralTo(g2));
3803
3804 // Change graph retaining structure: move ring closure along ring.
3806 DGraph gisA = pair[0];
3807 DGraph gisB = pair[1];
3808 assertFalse(gisA.isIsomorphicTo(gisB));
3809 assertTrue(gisA.isIsostructuralTo(gisB));
3810 }
3811
3812//------------------------------------------------------------------------------
3813
3814 @Test
3815 public void testGetEdgesWithSrcOrTrg() throws Exception
3816 {
3817 FragmentSpace fs = prepare();
3818 DGraph graph = makeTestGraphF(fs);
3819 Vertex v = graph.getVertexAtPosition(5);
3820
3821 List<Edge> egdesFrom = graph.getEdgesWithSrc(v);
3822 assertEquals(2, egdesFrom.size());
3823 assertTrue(graph.getVertexAtPosition(6) ==
3824 egdesFrom.get(0).getTrgAP().getOwner());
3825 assertTrue(graph.getVertexAtPosition(7) ==
3826 egdesFrom.get(1).getTrgAP().getOwner());
3827
3828 List<Edge> egdesTo = graph.getEdgesWithTrg(v);
3829 assertEquals(1, egdesTo.size());
3830 assertTrue(graph.getVertexAtPosition(0) ==
3831 egdesTo.get(0).getSrcAP().getOwner());
3832 }
3833
3834//------------------------------------------------------------------------------
3835
3836 @Test
3837 public void testEmbedPatternsInTemplates() throws Exception
3838 {
3839 FragmentSpace fs = prepare();
3840 DGraph graph = makeTestGraphL(fs);
3841
3842 DGraph graphWithTmpls = graph.embedPatternsInTemplates(
3843 GraphPattern.RING, fs);
3844
3845 assertEquals(7, graphWithTmpls.getVertexCount());
3846 assertEquals(6, graphWithTmpls.getEdgeCount());
3847 assertEquals(0, graphWithTmpls.getRingCount());
3848 List<Vertex> templates = graphWithTmpls.getVertexList()
3849 .stream()
3850 .filter(v -> v instanceof Template)
3851 .collect(Collectors.toList());
3852 assertEquals(2, templates.size());
3853 assertEquals(1, templates.stream()
3854 .filter(t -> t.getBuildingBlockType() == BBType.SCAFFOLD)
3855 .count());
3856 assertEquals(1, templates.stream()
3857 .filter(t -> t.getBuildingBlockType() == BBType.FRAGMENT)
3858 .count());
3859 }
3860
3861//------------------------------------------------------------------------------
3862
3892 {
3893 EmptyVertex v0 = new EmptyVertex(0);
3894 v0.addAP(APCA);
3895 v0.addAP(APCB);
3896 v0.addAP(APCA);
3897 v0.addAP(APCB);
3899 Arrays.asList(v0.getAP(0), v0.getAP(2))));
3901 Arrays.asList(v0.getAP(1), v0.getAP(3))));
3903
3904 EmptyVertex v1 = new EmptyVertex(1);
3905 v1.addAP(APCB);
3906 v1.addAP(APCA);
3907 v1.addAP(APCB);
3908 v1.addAP(APCB);
3910 Arrays.asList(v1.getAP(0), v1.getAP(2), v1.getAP(3))));
3911
3912 EmptyVertex v2 = v1.clone();
3913 v2.setVertexId(2);
3914
3915 EmptyVertex v3 = new EmptyVertex(3);
3916 v3.addAP(APCB);
3917
3918 EmptyVertex v4 = v3.clone();
3919 EmptyVertex v5 = v3.clone();
3920 EmptyVertex v6 = v3.clone();
3921 EmptyVertex v7 = v3.clone();
3922 EmptyVertex v8 = v3.clone();
3923 EmptyVertex v9 = v3.clone();
3924 EmptyVertex v10 = v3.clone();
3925 v4.setVertexId(4);
3926 v5.setVertexId(5);
3927 v6.setVertexId(6);
3928 v7.setVertexId(7);
3929 v8.setVertexId(8);
3930 v9.setVertexId(9);
3931 v10.setVertexId(10);
3932
3933 DGraph g = new DGraph();
3934 g.addVertex(v0);
3935 g.appendVertexOnAP(v0.getAP(0), v1.getAP(1));
3936 g.appendVertexOnAP(v0.getAP(2), v2.getAP(1));
3937 g.appendVertexOnAP(v1.getAP(0), v3.getAP(0));
3938 g.appendVertexOnAP(v1.getAP(2), v4.getAP(0));
3939 g.appendVertexOnAP(v1.getAP(3), v5.getAP(0));
3940 g.appendVertexOnAP(v2.getAP(0), v6.getAP(0));
3941 g.appendVertexOnAP(v2.getAP(2), v7.getAP(0));
3942 g.appendVertexOnAP(v2.getAP(3), v8.getAP(0));
3943 g.appendVertexOnAP(v0.getAP(1), v9.getAP(0));
3944 g.appendVertexOnAP(v0.getAP(3), v10.getAP(0));
3945
3946 return g;
3947 }
3948
3949//------------------------------------------------------------------------------
3950
3980 {
3981 EmptyVertex v0 = new EmptyVertex(0);
3982 v0.addAP(APCB);
3983 v0.addAP(APCB);
3984 v0.addAP(APCB);
3985 v0.addAP(APCB);
3986 v0.addSymmetricAPSet(new SymmetricAPs(Arrays.asList(
3987 v0.getAP(0), v0.getAP(1), v0.getAP(2), v0.getAP(3))));
3988
3989 EmptyVertex v1 = v0.clone();
3990 EmptyVertex v2 = v0.clone();
3991 EmptyVertex v9 = v0.clone();
3992 v1.setVertexId(1);
3993 v2.setVertexId(2);
3994 v9.setVertexId(9);
3995
4000
4001 EmptyVertex v3 = new EmptyVertex(3);
4002 v3.addAP(APCB);
4003
4004 EmptyVertex v4 = v3.clone();
4005 EmptyVertex v5 = v3.clone();
4006 EmptyVertex v6 = v3.clone();
4007 EmptyVertex v7 = v3.clone();
4008 v4.setVertexId(4);
4009 v5.setVertexId(5);
4010 v6.setVertexId(6);
4011 v7.setVertexId(7);;
4012
4013 DGraph g = new DGraph();
4014 g.addVertex(v0);
4015 g.appendVertexOnAP(v0.getAP(0), v1.getAP(1));
4016 g.appendVertexOnAP(v0.getAP(2), v2.getAP(1));
4017 g.appendVertexOnAP(v1.getAP(0), v3.getAP(0));
4018 g.appendVertexOnAP(v1.getAP(2), v4.getAP(0));
4019 g.appendVertexOnAP(v1.getAP(3), v5.getAP(0));
4020 g.appendVertexOnAP(v2.getAP(0), v6.getAP(0));
4021 g.appendVertexOnAP(v2.getAP(2), v7.getAP(0));
4022 // Warning added here just to avoid messing the order of vertexes
4023 g.appendVertexOnAP(v0.getAP(1), v9.getAP(1));
4024
4025 return g;
4026 }
4027
4028//------------------------------------------------------------------------------
4029
4030 @Test
4031 public void testDetectSymVertexSets() throws Exception
4032 {
4033 prepare();
4034 DGraph graph = makeTestGraphM();
4035
4036 assertTrue(graph.detectSymVertexSets());
4037 assertEquals(3, graph.getSymmetricSetCount());
4038
4039 SymmetricVertexes symVrtxs = graph.getSymSetForVertex(
4040 graph.getVertexAtPosition(0));
4041 assertEquals(0, symVrtxs.size());
4042
4043 symVrtxs = graph.getSymSetForVertex(graph.getVertexAtPosition(1));
4044 assertEquals(2, symVrtxs.size());
4045 assertTrue(symVrtxs.contains(graph.getVertexAtPosition(1)));
4046 assertTrue(symVrtxs.contains(graph.getVertexAtPosition(2)));
4047
4048 symVrtxs = graph.getSymSetForVertex(graph.getVertexAtPosition(3));
4049 assertEquals(6, symVrtxs.size());
4050 assertTrue(symVrtxs.contains(graph.getVertexAtPosition(3)));
4051 assertTrue(symVrtxs.contains(graph.getVertexAtPosition(4)));
4052 assertTrue(symVrtxs.contains(graph.getVertexAtPosition(5)));
4053 assertTrue(symVrtxs.contains(graph.getVertexAtPosition(6)));
4054 assertTrue(symVrtxs.contains(graph.getVertexAtPosition(7)));
4055 assertTrue(symVrtxs.contains(graph.getVertexAtPosition(8)));
4056
4057 symVrtxs = graph.getSymSetForVertex(graph.getVertexAtPosition(9));
4058 assertEquals(2, symVrtxs.size());
4059 assertTrue(symVrtxs.contains(graph.getVertexAtPosition(9)));
4060 assertTrue(symVrtxs.contains(graph.getVertexAtPosition(10)));
4061 }
4062
4063//------------------------------------------------------------------------------
4064
4065
4066}
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:6923
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:7348
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:7376
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:6948
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:7411
void addRing(Ring ring)
Definition: DGraph.java:1258
List< Vertex > getMutableSites()
A list of mutation sites from within this graph.
Definition: DGraph.java:6855
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:7228
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:6291
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...