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