19package denoptim.graph;
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;
28import java.util.ArrayList;
29import java.util.Arrays;
30import java.util.HashMap;
31import java.util.HashSet;
32import java.util.Iterator;
33import java.util.LinkedHashMap;
37import java.util.concurrent.atomic.AtomicInteger;
38import java.util.logging.Logger;
39import java.util.stream.Collectors;
41import javax.vecmath.Point3d;
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;
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;
75 private static String
a=
"A",
b=
"B",
c=
"C",
d=
"D",
cap=
"cap";
87 HashMap<APClass,ArrayList<APClass>> cpMap =
88 new HashMap<APClass,ArrayList<APClass>>();
89 ArrayList<APClass> lstA =
new ArrayList<APClass>();
91 cpMap.put(
APCA, lstA);
92 ArrayList<APClass> lstB =
new ArrayList<APClass>();
95 cpMap.put(
APCB, lstB);
96 ArrayList<APClass> lstC =
new ArrayList<APClass>();
99 cpMap.put(
APCC, lstC);
100 ArrayList<APClass> lstD =
new ArrayList<APClass>();
102 cpMap.put(
APCD, lstD);
118 HashMap<APClass,APClass> capMap =
new HashMap<APClass,APClass>();
119 HashSet<APClass> forbEnds =
new HashSet<APClass>();
122 new ArrayList<Vertex>(),
123 new ArrayList<Vertex>(),
124 new ArrayList<Vertex>(),
125 cpMap, capMap, forbEnds, cpMap);
279 List<Vertex> symA =
new ArrayList<Vertex>();
284 List<Vertex> symB =
new ArrayList<Vertex>();
356 List<Vertex> sym1 =
new ArrayList<Vertex>();
360 List<Vertex> sym2 =
new ArrayList<Vertex>();
364 List<Vertex> sym3 =
new ArrayList<Vertex>();
368 List<Vertex> sym4 =
new ArrayList<Vertex>();
477 graph.
addRing(v7a_bis, v7a_tris);
479 List<Vertex> symA =
new ArrayList<Vertex>();
484 List<Vertex> symB =
new ArrayList<Vertex>();
542 graph.
addRing(v7a_bis, v7a_tris);
584 List<Vertex> symB =
new ArrayList<Vertex>();
651 List<Vertex> symFirstLayer =
new ArrayList<Vertex>();
652 symFirstLayer.add(v2b);
653 symFirstLayer.add(v2b_bis);
656 List<Vertex> symSecondLayer =
new ArrayList<Vertex>();
657 symSecondLayer.add(v3b_1);
658 symSecondLayer.add(v3b_2);
730 List<Vertex> symA =
new ArrayList<Vertex>();
735 List<Vertex> symB =
new ArrayList<Vertex>();
828 List<Vertex> symA =
new ArrayList<Vertex>();
833 List<Vertex> symB =
new ArrayList<Vertex>();
892 graph.
addRing(v7a_d, v7a_d_quat);
893 graph.
addRing(v7a_d_bis, v7a_d_tris);
895 List<Vertex> symC =
new ArrayList<Vertex>();
946 graph.
addRing(v7a_bis, v7a_tris);
1087 List<Vertex> vToCap =
new ArrayList<Vertex>();
1090 vToCap.add(v1a_2_bis);
1091 vToCap.add(v1a_2_tris);
1096 if (ap.isAvailable())
1112 List<Vertex> symA =
new ArrayList<Vertex>();
1117 List<Vertex> symB =
new ArrayList<Vertex>();
1119 symB.add(v1a_2_bis);
1237 graph.
addRing(v7a_bis, v7a_tris);
1239 List<Vertex> symA =
new ArrayList<Vertex>();
1244 List<Vertex> symB =
new ArrayList<Vertex>();
1308 DGraph refToPrevGraph = gOut;
1309 Vertex refToPRevVrtx = vOut;
1310 for (
int embeddingLevel=0; embeddingLevel<10; embeddingLevel++)
1349 HashMap<APClass,ArrayList<APClass>> cpMap =
1350 new HashMap<APClass,ArrayList<APClass>>();
1351 cpMap.put(a0,
new ArrayList<APClass>(Arrays.asList(a0, b0)));
1352 HashMap<APClass,APClass> capMap =
new HashMap<APClass,APClass>();
1354 HashSet<APClass> forbEnds =
new HashSet<APClass>();
1358 IAtom a1 =
new Atom(
"C",
new Point3d(
new double[]{0.0, 0.0, 0.0}));
1359 IAtom a2 =
new Atom(
"C",
new Point3d(
new double[]{1.0, 0.0, 0.0}));
1362 frg1.
addBond(
new Bond(a1, a2));
1363 frg1.
addAP(0, a0,
new Point3d(
new double[]{0.0, 0.0, 1.0}));
1364 frg1.
addAP(1, a0,
new Point3d(
new double[]{1.0, 1.0, 1.0}));
1368 IAtom a3 =
new Atom(
"C",
new Point3d(
new double[]{0.0, 0.0, 0.0}));
1370 frg2.
addAP(0, a0,
new Point3d(
new double[]{0.0, 1.0, 1.0}));
1371 frg2.
addAP(0, b0,
new Point3d(
new double[]{0.0, 1.0, -1.0}));
1375 IAtom a4 =
new PseudoAtom(
"ATP",
new Point3d(
1376 new double[]{0.0, 0.0, 0.0}));
1378 rca1.
addAP(0, ap0,
new Point3d(
new double[]{0.0, 1.0, 1.0}));
1382 IAtom a5 =
new PseudoAtom(
"ATM",
new Point3d(
1383 new double[]{1.0, 0.0, 0.0}));
1385 rca2.
addAP(0, am0,
new Point3d(
new double[]{0.0, 1.0, 1.0}));
1389 IAtom a6 =
new Atom(
"H",
new Point3d(
new double[]{0.0, 0.0, 0.0}));
1391 cap.addAP(0, h0,
new Point3d(
new double[]{0.0, 1.0, 1.0}));
1392 cap.projectAPsToProperties();
1394 ArrayList<Vertex> scaff =
new ArrayList<Vertex>();
1396 ArrayList<Vertex> frags =
new ArrayList<Vertex>();
1400 ArrayList<Vertex> caps =
new ArrayList<Vertex>();
1405 cpMap, capMap, forbEnds, cpMap);
1430 "Number of vertexes after removal of 0 unused RCVs.");
1432 "Number of edges after removal of 0 unused RCVs.");
1454 "Number of RCVs after removal of 2 unused RCVs.");
1456 "Number of vertexes after removal of 2 unused RCVs.");
1458 "Number of edges after removal of 2 unused RCVs.");
1469 List<Template> expected =
new ArrayList<Template>();
1470 DGraph refToThisLayerGraph = gOut;
1471 Template refToThisLayerVrtx =
null;
1472 for (
int embeddingLevel=0; embeddingLevel<10; embeddingLevel++)
1474 refToThisLayerVrtx = (
Template) refToThisLayerGraph
1475 .getVertexList().stream()
1476 .filter(v -> v instanceof
Template)
1479 expected.add(refToThisLayerVrtx);
1484 "Embedding path of graph that is not embedded");
1486 assertEquals(expected, path,
"Path of deepest embedded graph");
1500 List<Template> expectedPathA =
new ArrayList<Template>();
1501 List<Template> expectedPathB =
new ArrayList<Template>();
1502 DGraph refToThisLayerGraphB = gB;
1503 Template refToThisLayerVrtxB =
null;
1504 DGraph refToThisLayerGraphA = gA;
1505 Template refToThisLayerVrtxA =
null;
1506 for (
int embeddingLevel=0; embeddingLevel<9; embeddingLevel++)
1508 refToThisLayerVrtxA = (
Template) refToThisLayerGraphA
1509 .getVertexList().stream()
1510 .filter(v -> v instanceof
Template)
1513 expectedPathA.add(refToThisLayerVrtxA);
1516 refToThisLayerVrtxB = (
Template) refToThisLayerGraphB
1517 .getVertexList().stream()
1518 .filter(v -> v instanceof
Template)
1521 expectedPathB.add(refToThisLayerVrtxB);
1525 DGraph expectedEmbeddedA = expectedPathA.get(8).getInnerGraph();
1526 DGraph expectedEmbeddedB = expectedPathB.get(8).getInnerGraph();
1531 assertEquals(expectedEmbeddedB,embeddedFoundB);
1534 assertEquals(expectedPathB,pathFoundB);
1538 assertEquals(expectedEmbeddedA,embeddedFoundA);
1541 assertEquals(expectedPathA,pathFoundA);
1553 "Inconsistent source vertex");
1558 "Inconsistent source vertex");
1568 int[] expected =
new int[] {2,3,0,1,-1};
1572 "Wrong level for vertex at position "+i);
1576 expected =
new int[] {-1,0,1,2,3,2,0,1,2,3,2};
1580 "Bis: Wrong level for vertex at position "+i);
1594 LinkedHashMap<Integer, Integer> apMap =
1595 new LinkedHashMap<Integer,Integer>();
1604 boolean res = g.
replaceVertex(v1, chosenBBId, choosenBBTyp, apMap, fs);
1606 assertTrue(res,
"ReplaceVertex return value.");
1608 int numVertexesWithGoodBBId = 0;
1609 int numEdgesWithS = 0;
1610 int numEdgesWith2 = 0;
1611 int numEdgesWith3 = 0;
1617 numVertexesWithGoodBBId++;
1621 if (!ap.isAvailable())
1623 Vertex nextVrtx = ap.getLinkedAP().getOwner();
1642 assertEquals(2,numVertexesWithGoodBBId,
"Number of new links.");
1643 assertEquals(2,numEdgesWithS,
"Number of new edges with scaffold.");
1644 assertEquals(4,numEdgesWith2,
"Number of new edges with v2a/b.");
1645 assertEquals(2,numEdgesWith3,
"Number of new edges with v3a/b.");
1659 Set<Long> oldVertexIds =
new HashSet<Long>();
1663 LinkedHashMap<Integer,Integer> apMap2 =
1664 new LinkedHashMap<Integer,Integer>();
1667 int chosenBBId2 = 5;
1670 boolean res2 = g2.
replaceVertex(v2, chosenBBId2, choosenBBTyp2, apMap2,
1673 assertTrue(res2,
"ReplaceVertex return value (2).");
1675 int numVertexesWithGoodBBId2 = 0;
1676 int numEdgesWith1 = 0;
1682 numVertexesWithGoodBBId2++;
1686 if (!ap.isAvailable())
1688 Vertex nextVrtx = ap.getLinkedAP().getOwner();
1695 assertEquals(4,numVertexesWithGoodBBId2,
"Number of new links.");
1696 assertEquals(4,numEdgesWith1,
"Number of new edges with scaffold.");
1698 boolean found =
false;
1699 boolean foundOldVertexId =
false;
1701 while (iterSS.hasNext())
1704 if (ss.size() == origSS.size())
1710 foundOldVertexId =
true;
1714 assertTrue(found,
"could not find old symmetric set");
1715 assertFalse(foundOldVertexId,
"found old vertex id in new symmetric set");
1728 LinkedHashMap<Integer, Integer> apMap =
1729 new LinkedHashMap<Integer,Integer>();
1774 "graph's surce vertex");
1778 assertEquals(3,pathA.
getEdgesPath().size(),
"path within a ring (A)");
1781 assertEquals(5,pathB.
getEdgesPath().size(),
"path within a ring (B)");
1784 assertEquals(4,pathC.
getEdgesPath().size(),
"path within a ring (C)");
1820 assertEquals(1,g.
getRingCount(),
"Rings in outer graph");
1824 "Distance Head-Tail in ring of outer graph");
1829 "Vertex in inner graph");
1831 "Rings in inner graph");
1833 "Free APs inner graph");
1836 "Distance Head-Tail in ring of inner graph");
1873 apMappingB.put(vOnGraphB.
getAP(0), vOnInGraphB.
getAP(0));
1874 apMappingB.put(vOnGraphB.
getAP(1), vOnInGraphB.
getAP(2));
2039 Arrays.asList(v5, v4, v0, v1, v2, v3))));
2042 Arrays.asList(v6, v0, v4, v7))));
2076 assertEquals(numVa, numV - 1);
2077 assertEquals(numEa, numE - 1);
2078 assertEquals(numSa, numS - 1);
2079 assertEquals(numRa, numR - 1);
2088 assertEquals(numVb, numVa - 1);
2089 assertEquals(numEb, numEa - 1);
2090 assertEquals(numSb, numSa);
2091 assertEquals(numRb, numRa);
2100 assertEquals(numVc, numVb - 1);
2101 assertEquals(numEc, numEb - 2);
2102 assertEquals(numSc, numSb);
2103 assertEquals(numRc, numRb - 1);
2137 StringBuilder reason =
new StringBuilder();
2138 assertTrue(graphA.
sameAs(graphB, reason), reason.toString());
2172 StringBuilder reason =
new StringBuilder();
2173 assertFalse(graphA.
sameAs(graphB, reason));
2240 StringBuilder reason =
new StringBuilder();
2241 assertTrue(graphA.
sameAs(graphB, reason));
2308 StringBuilder reason =
new StringBuilder();
2309 assertFalse(graphA.
sameAs(graphB, reason));
2337 ArrayList<Vertex> vrA =
new ArrayList<Vertex>();
2343 ArrayList<Vertex> vrA2 =
new ArrayList<Vertex>();
2372 ArrayList<Vertex> vrB =
new ArrayList<Vertex>();
2378 ArrayList<Vertex> vrB2 =
new ArrayList<Vertex>();
2385 StringBuilder reason =
new StringBuilder();
2386 assertTrue(graphA.
sameAs(graphB, reason));
2414 ArrayList<Vertex> vrA =
new ArrayList<>();
2420 ArrayList<Vertex> vrA2 =
new ArrayList<>();
2449 ArrayList<Vertex> vrB =
new ArrayList<>();
2455 ArrayList<Vertex> vrB2 =
new ArrayList<>();
2462 StringBuilder reason =
new StringBuilder();
2463 assertTrue(graphA.
sameAs(graphB, reason));
2491 ArrayList<Vertex> vrA =
new ArrayList<>();
2497 ArrayList<Vertex> vrA2 =
new ArrayList<>();
2525 ArrayList<Vertex> vrB =
new ArrayList<>();
2531 ArrayList<Vertex> vrB2 =
new ArrayList<>();
2538 StringBuilder reason =
new StringBuilder();
2539 assertFalse(graphA.
sameAs(graphB, reason));
2564 assertEquals(1,lst.size(),
"Size of list");
2565 assertEquals(vertex0.
getVertexId(),lst.get(0).getOwner().getVertexId(),
2566 "ID of the vertex holding the available AP.");
2606 Arrays.asList(v5, v4, v0, v1, v2, v3))));
2609 Arrays.asList(v6, v0, v4, v7))));
2624 "Number of vertices");
2630 "Number of symmetric sets");
2632 "Number of closable chains");
2642 int hashVG = vg.hashCode();
2643 int hashVC = vc.hashCode();
2648 "Reference to vertex owner in ap " + iap +
" vertex "
2651 "Reference to vertex owner in ap " + iap +
" vertex "
2655 "Owner of AP "+iap+
" in vertex "+iv);
2671 "Size of mutation list in case of frozen template");
2678 "Size of mutation list in case of free template");
2682 "No sites if all is ignored");
2749 IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
2750 IAtomContainer iac1 = builder.newAtomContainer();
2751 IAtom ia1 =
new Atom(
"C");
2752 IAtom ia2 =
new Atom(
"C");
2755 iac1.addBond(
new Bond(ia1, ia2, IBond.Order.SINGLE));
2763 IAtomContainer iac2 = builder.newAtomContainer();
2764 iac2.addAtom(
new Atom(
"O"));
2769 IAtomContainer iac3 = builder.newAtomContainer();
2770 iac3.addAtom(
new Atom(
"H"));
2775 IAtomContainer iac4 = builder.newAtomContainer();
2776 iac4.addAtom(
new Atom(
"H"));
2796 }
catch (Throwable t)
2798 t.printStackTrace();
2799 System.err.println(
"FATAL ERROR! Could not make test graph (A). "
2800 +
"Please, report this to the development team.");
2838 IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
2839 IAtomContainer iac1 = builder.newAtomContainer();
2840 IAtom ia1 =
new Atom(
"C");
2841 IAtom ia2 =
new Atom(
"C");
2844 iac1.addBond(
new Bond(ia1, ia2, IBond.Order.SINGLE));
2853 IAtomContainer iac2 = builder.newAtomContainer();
2854 iac2.addAtom(
new Atom(
"O"));
2860 IAtomContainer iac3 = builder.newAtomContainer();
2861 iac3.addAtom(
new Atom(
"H"));
2866 IAtomContainer iac4 = builder.newAtomContainer();
2867 iac4.addAtom(
new Atom(
"H"));
2909 }
catch (Throwable t)
2911 t.printStackTrace();
2912 System.err.println(
"FATAL ERROR! Could not make test graph (A). "
2913 +
"Please, report this to the development team.");
2927 IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
2928 IAtomContainer iac1 = builder.newAtomContainer();
2929 iac1.addAtom(
new Atom(
"C"));
2934 IAtomContainer iac2 = builder.newAtomContainer();
2935 iac2.addAtom(
new Atom(
"O"));
2940 IAtomContainer iac3 = builder.newAtomContainer();
2941 iac3.addAtom(
new Atom(
"H"));
2945 IAtomContainer iac4 = builder.newAtomContainer();
2946 iac4.addAtom(
new Atom(
"H"));
2959 "#vertices in graph before removal");
2965 "#vertices in graph before removal");
2967 "Capping is still contained");
2969 "Owner of removed capping group is null");
2973 IAtomContainer iac12 = builder.newAtomContainer();
2974 iac12.addAtom(
new Atom(
"C"));
2979 IAtomContainer iac22 = builder.newAtomContainer();
2980 iac22.addAtom(
new Atom(
"O"));
2985 IAtomContainer iac23 = builder.newAtomContainer();
2986 iac23.addAtom(
new Atom(
"H"));
2990 IAtomContainer iac24 = builder.newAtomContainer();
2991 iac24.addAtom(
new Atom(
"H"));
3004 "#vertices in graph before removal (B)");
3011 "#vertices in graph before removal (B)");
3013 "Capping is still contained (B)");
3015 "Capping is still contained (C)");
3017 "Owner of removed capping group is null (B)");
3019 "Owner of removed capping group is null (C)");
3027 for (
int atomPos = 0; atomPos < apCount; atomPos++) {
3072 Arrays.asList(v5, v4, v0, v1, v2, v3))));
3075 Arrays.asList(v6, v0, v4, v7))));
3087 String json1 = graph.
toJson();
3090 String json2 = g2.
toJson();
3092 assertTrue(json1.equals(json2),
"Round-trip via JSON is successful");
3106 "self isomorphism on empty graph");
3108 "isomorphism on empty graphs");
3113 "single-vertex graph");
3115 "single-vertex graph vs clone");
3134 "graph with empty vertexes and same properties");
3138 "graph with empty vertexes and different properties");
3148 assertFalse(gD1.
isIsomorphicTo(gAempty),
"graph D vs empty graph");
3149 assertFalse(gAempty.
isIsomorphicTo(gD1),
"empty graph vs graph D");
3172 "Original stays the same");
3181 "SymmetricSets in subGraph1");
3182 assertEquals(1,subGraph1.
getRingCount(),
"Rings in subGraph1");
3184 "Original stays the same");
3193 "SymmetricSets in subGraph2");
3194 assertEquals(0,subGraph2.
getRingCount(),
"Rings in subGraph2");
3196 "Original stays the same");
3207 Set<Vertex> targetVertexes =
new HashSet<>();
3214 for (
Vertex vInTarget : targetVertexes)
3219 Set<Edge> connectionToSubgraph =
new HashSet<Edge>();
3220 Set<Edge> connectionFromSubgraph =
new HashSet<Edge>();
3222 connectionToSubgraph, connectionFromSubgraph);
3224 assertEquals(1, connectionToSubgraph.size());
3225 assertEquals(3, connectionFromSubgraph.size());
3230 boolean found0 =
false;
3231 for (
Edge e : connectionToSubgraph)
3233 Vertex inResults = e.getSrcAP().getOwner();
3239 boolean found2 =
false;
3240 boolean found4 =
false;
3241 boolean found6 =
false;
3242 for (
Edge e : connectionFromSubgraph)
3244 Vertex inResults = e.getTrgAP().getOwner();
3264 List<VertexQuery> allQueries =
new ArrayList<VertexQuery>();
3265 List<List<Vertex>> allExpected =
3266 new ArrayList<List<Vertex>>();
3269 List<Vertex> e0 =
new ArrayList<Vertex>();
3272 allExpected.add(e0);
3276 null,
null,
null,
null,
null,
null,
null);
3277 List<Vertex> e1 =
new ArrayList<Vertex>();
3280 allExpected.add(e1);
3284 null,
null,
null,
null,
null,
null,
null);
3285 List<Vertex> e2 =
new ArrayList<Vertex>();
3288 allExpected.add(e2);
3291 null,
null,
null,
null,
null,
null);
3292 List<Vertex> e3 =
new ArrayList<Vertex>();
3297 allExpected.add(e3);
3300 null,
null,
null,
null,
null);
3301 List<Vertex> e4 =
new ArrayList<Vertex>();
3305 allExpected.add(e4);
3308 null,
null,
null,
null);
3309 List<Vertex> e5 =
new ArrayList<Vertex>();
3312 allExpected.add(e5);
3316 List<Vertex> e6 =
new ArrayList<Vertex>();
3320 allExpected.add(e6);
3329 List<Vertex> e7 =
new ArrayList<Vertex>();
3333 allExpected.add(e7);
3337 null,
null,
null,
null);
3340 List<Vertex> e8 =
new ArrayList<Vertex>();
3343 allExpected.add(e8);
3350 List<Vertex> e9 =
new ArrayList<Vertex>();
3353 allExpected.add(e9);
3360 List<Vertex> e10 =
new ArrayList<Vertex>();
3363 allQueries.add(q10);
3364 allExpected.add(e10);
3371 List<Vertex> e11 =
new ArrayList<Vertex>();
3377 allQueries.add(q11);
3378 allExpected.add(e11);
3383 List<Vertex> e12 =
new ArrayList<Vertex>();
3386 allQueries.add(q12);
3387 allExpected.add(e12);
3394 List<Vertex> e13 =
new ArrayList<Vertex>();
3398 allQueries.add(q13);
3399 allExpected.add(e13);
3406 List<Vertex> e14 =
new ArrayList<Vertex>();
3409 allQueries.add(q14);
3410 allExpected.add(e14);
3418 null,
null,
null,
null);
3421 List<Vertex> e15 =
new ArrayList<Vertex>();
3423 allQueries.add(q15);
3424 allExpected.add(e15);
3431 List<Vertex> e16 =
new ArrayList<Vertex>();
3433 allQueries.add(q16);
3434 allExpected.add(e16);
3441 List<Vertex> e17 =
new ArrayList<Vertex>();
3444 allQueries.add(q17);
3445 allExpected.add(e17);
3452 List<Vertex> e18 =
new ArrayList<Vertex>();
3456 allQueries.add(q18);
3457 allExpected.add(e18);
3463 List<Vertex> e19 =
new ArrayList<Vertex>();
3466 allQueries.add(q19);
3467 allExpected.add(e19);
3474 List<Vertex> e20 =
new ArrayList<Vertex>();
3477 allQueries.add(q20);
3478 allExpected.add(e20);
3485 List<Vertex> e21 =
new ArrayList<Vertex>();
3488 allQueries.add(q21);
3489 allExpected.add(e21);
3503 List<Vertex> e22 =
new ArrayList<Vertex>();
3505 allQueries.add(q22);
3506 allExpected.add(e22);
3510 null,
null,
null,
null, eq23,
null);
3511 List<Vertex> e23 =
new ArrayList<Vertex>();
3513 allQueries.add(q23);
3514 allExpected.add(e23);
3516 for (
int i=0; i<allQueries.size(); i++)
3518 List<Vertex> matches = g.
findVertices(allQueries.get(i),
3519 Logger.getLogger(
"DummyLogger"));
3520 assertEquals(allExpected.get(i).size(),matches.size(),
3521 "Different number of matched vertexes ("+i+
")");
3522 assertTrue(allExpected.get(i).containsAll(matches),
3523 "Inconsistent matches ("+i+
")");
3538 Map<Object,Integer> countsPerLabel =
new HashMap<Object,Integer>();
3542 if (countsPerLabel.containsKey(label))
3543 countsPerLabel.put(label,countsPerLabel.get(label)+1);
3545 countsPerLabel.put(label,1);
3579 boolean foundA =
false;
3580 boolean foundB =
false;
3582 while (iter.hasNext())
3590 assertTrue(foundA,
"Found 2-membered set");
3591 assertTrue(foundB,
"Found 4-membered set");
3603 while (iter2.hasNext())
3606 assertEquals(2,ss.size(),
"side of each symmetric sets.");
3617 List<Vertex> sg =
new ArrayList<Vertex>();
3623 assertEquals(2,symSubGraphs.size(),
"Number of subgraphs");
3625 symSubGraphs.get(0).get(0).getVertexId());
3627 symSubGraphs.get(0).get(1).getVertexId());
3629 symSubGraphs.get(1).get(0).getVertexId());
3631 symSubGraphs.get(1).get(1).getVertexId());
3634 List<Vertex> sg2 =
new ArrayList<Vertex>();
3643 boolean exceptionWhenCappingIsIncluded =
false;
3649 if (e.getMessage().contains(
"Capping groups must not be part of "
3650 +
"symmetric subgraphs"))
3651 exceptionWhenCappingIsIncluded =
true;
3653 assertTrue(exceptionWhenCappingIsIncluded,
3654 "Capping groups trigger exception");
3656 sg2 =
new ArrayList<Vertex>();
3660 assertEquals(2,symSubGraphs.size());
3661 assertEquals(2,symSubGraphs.get(0).size());
3662 assertEquals(2,symSubGraphs.get(1).size());
3673 List<Vertex> childTree =
new ArrayList<Vertex>();
3675 assertEquals(6,childTree.size());
3683 childTree =
new ArrayList<Vertex>();
3685 assertEquals(1,childTree.size());
3688 childTree =
new ArrayList<Vertex>();
3690 assertEquals(4,childTree.size());
3696 childTree =
new ArrayList<Vertex>();
3699 assertEquals(3,childTree.size());
3717 List<Vertex> childTree =
new ArrayList<Vertex>();
3719 new AtomicInteger(0),
new ArrayList<Integer>());
3758 List<Vertex> subGraph =
new ArrayList<Vertex>();
3762 List<AttachmentPoint> expected =
new ArrayList<AttachmentPoint>();
3768 assertEquals(expected,interfaceAPs);
3773 subGraph =
new ArrayList<Vertex>();
3777 expected =
new ArrayList<AttachmentPoint>();
3785 assertEquals(expected,interfaceAPs);
3799 List<Vertex> subGraph =
new ArrayList<Vertex>();
3803 List<AttachmentPoint>expected =
new ArrayList<AttachmentPoint>();
3813 assertEquals(expected,interfaceAPs);
3820 String unqProp =
"UNQPROP";
3962 incomingSubGraph =
new DGraph();
3992 assertEquals(2, egdesFrom.size());
3994 egdesFrom.get(0).getTrgAP().getOwner());
3996 egdesFrom.get(1).getTrgAP().getOwner());
3999 assertEquals(1, egdesTo.size());
4001 egdesTo.get(0).getSrcAP().getOwner());
4020 .filter(v -> v instanceof
Template)
4021 .collect(Collectors.toList());
4022 assertEquals(2, templates.size());
4023 assertEquals(1, templates.stream()
4026 assertEquals(1, templates.stream()
4211 assertEquals(0, symVrtxs.size());
4214 assertEquals(2, symVrtxs.size());
4219 assertEquals(6, symVrtxs.size());
4228 assertEquals(2, symVrtxs.size());
4288 List<Vertex> symA =
new ArrayList<Vertex>();
4361 List<Vertex> symA =
new ArrayList<Vertex>();
4378 Set<Vertex> limits =
new HashSet<Vertex>();
4380 assertEquals(visited.size(), 1);
4381 assertTrue(visited.contains(v));
4391 Set<Vertex> limits =
new HashSet<Vertex>();
4396 Set<Vertex> expected =
new HashSet<Vertex>();
4404 assertEquals(visited.size(), expected.size());
4405 for (
Vertex v : visited) {
4406 assertTrue(expected.contains(v),
"Vertex "+v.getVertexId()+
" not found in visited");
4420 assertEquals(visited.size(), 2);
4423 .getVertexAtPosition(3)).getInnerGraph().getVertexAtPosition(0);
4426 assertEquals(visited.size(), 4);
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.
static final APClass RCACLASSMINUS
Conventional class of attachment points on ring-closing vertexes.
static APClass make(String ruleAndSubclass)
Creates an APClass if it does not exist already, or returns the reference to the existing instance.
Class representing a mapping between attachment points (APs).
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....
AttachmentPoint getLinkedAP()
Gets the attachment point (AP) that is connected to this AP via the edge user.
Query for searching AttachmentPoints.
Container for the list of vertices and the edges that connect them.
String toJson()
Produces a string that represents this graph and that adheres to the JSON format.
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...
Vertex getVertexWithId(long vid)
Searches for a vertex with the given identifier.
int getSymmetricSetCount()
Returns the number of symmetric sets of vertices.
Vertex getSourceVertex()
Identifies and return the vertex from which the spanning tree originates.
DGraph extractSubgraph(int index)
Creates a new graph that corresponds to the subgraph of this graph when exploring the spanning tree f...
boolean containsVertex(Vertex v)
Check if this graph contains the specified vertex.
List< Vertex > findVertices(VertexQuery vrtxQuery, Logger logger)
Filters a list of vertices according to a query.
boolean isIsomorphicTo(DGraph other)
Checks if this graph is "DENOPTIM-isomorphic" to the other one given.
ArrayList< AttachmentPoint > getAvailableAPs()
Returns the list of available attachment points contained in this graph.
void addVertex(Vertex vertex)
Appends a vertex to this graph without creating any edge.
List< ClosableChain > closableChains
The potentially closable chains of vertices.
DGraph embedPatternsInTemplates(GraphPattern pattern, FragmentSpace fragSpace)
Searches for the given pattern type and generated a new graph where each set of (clones of) vertexes ...
void getChildrenTree(Vertex vertex, List< Vertex > children)
Gets all the children of the current vertex recursively.
void removeVertex(Vertex vertex)
Remove a vertex from this graph.
Iterator< SymmetricVertexes > getSymSetsIterator()
Get an iterator for the sets of symmetrically related vertices.
ArrayList< Vertex > getRCVertices()
Search for ring closing vertices: vertices that contain only a RingClosingAttractor
List< List< Vertex > > getSymmetricSubGraphs(List< Vertex > subGrpVrtxs)
We assume that the subgraph is a continuously connected, directed graph.
List< Vertex > gVertices
The vertices belonging to this graph.
Vertex getVertexAtPosition(int pos)
Returns the vertex that is in the given position of the list of vertices belonging to this graph.
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 ...
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.
List< Ring > gRings
The rings defined in this graph.
static boolean replaceSingleSubGraph(APMapping apMapping, FragmentSpace fragSpace)
Replaced the subgraph defined by a set of Attachment Points that belong to a graph (ie....
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...
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,...
List< Vertex > getVertexList()
void convertSymmetricLabelsToSymmetricSets()
Looks for any symmetric labels, creates symmetric sets that collect the same information,...
List< AttachmentPoint > getInterfaceAPs(List< Vertex > subGraphB)
Searches for all AttachmentPoints that represent the interface between a subgraph,...
DGraph clone()
Returns almost "deep-copy" of this graph.
void removeCappingGroups(List< Vertex > lstVerts)
Remove capping groups that belong to this graph and are in the given list.
void renumberGraphVertices()
Reassign vertex IDs to all vertices of this graph.
void reassignSymmetricLabels()
Marks the vertices of this graph with a string that is consistent for all vertices that belong to sym...
List< Edge > gEdges
The edges belonging to this graph.
void replaceUnusedRCVsWithCapps(FragmentSpace fragSpace)
Removes unused ring-closing vertices.
boolean sameAs(DGraph other, StringBuilder reason)
Compare this and another graph ignoring the vertex IDs.
int getLevel(Vertex v)
Calculates the level of a vertex in this graph.
static void exploreGraph(Vertex seed, Set< Vertex > limits, Set< Vertex > visited)
Depth-first exploration of graphs.
void removeCappingGroupsOn(Vertex vertex)
Remove capping groups on the given vertex of this graph.
static DGraph fromJson(String json)
Reads a JSON string and returns an instance of this class.
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 ...
void addSymmetricSetOfVertices(SymmetricVertexes symSet)
Adds a symmetric set of vertices to this graph.
SymmetricVertexes getSymSetForVertex(Vertex v)
Returns the set of vertexes symmetric to the given one.
List< AttachmentPoint > getSubgraphAPs(List< Vertex > subGraphB)
Searches for all AttachmentPoints that are owned by vertices in a subgraph but either available or us...
boolean isConnected()
Check if this graph is connected, i.e., there is at least one path between any two vertices.
List< Vertex > getMutableSites()
A list of mutation sites from within this graph.
String localMsg
A free-format string used to record simple properties in the graph.
void addEdge(Edge edge)
Adds the edge to the list of edges belonging to this graph.
List< Template > getEmbeddingPath()
Find the path that one has to traverse to reach this graph from any template-embedding structure.
List< Integer > getBranchIdOfVertexAtPosition(int i)
Returns the branch identifier.
boolean isIsostructuralTo(DGraph other)
Checks if this graph is "DENOPTIM-isostructural" to the other one given.
boolean detectSymVertexSets()
Detects and groups symmetric sets of Vertexes in the graph based on unique identification and path en...
Unit test for DENOPTIMGraph.
void testSymmetricSetLabels()
void testGraphIsomorphism()
void testDetectSymVertexSets()
DGraph makeDisorderedGraph(FragmentSpace fs)
Makes a graph with disordered list of vertexes, i.e., the first vertex is not the source.
void testReplaceVertex_inRing()
static DGraph makeTestGraphM()
Returns a graph with definition of symmetric vertexes and symmetric APs meant for testing purposes.
void testExploreGraph_simpleGraph()
DGraph makeTestGraphG(FragmentSpace fs)
Creates a test graph that looks like this:
void testGetEmbeddingPath()
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 testSameAs_SameSymmSet()
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:
void testSameAs_DiffVertex()
void testGetEdgesWithSrcOrTrg()
void testSameAs_DisorderRings()
void testGetMutationSites()
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:
void testGetSourceVertex()
void testRemoveUnusedRCVs()
void testExploreGraph_noCrossingTemplateBoundary()
void testExtractSubgraphFromCollection()
void testGetChildrenTree()
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.
void testSameAs_DiffSymmSet()
DGraph makeTestGraphH(FragmentSpace fs)
Creates a test graph that looks like this:
void testGetInterfaceAPs()
void testExtractSubgraph()
void testReplaceSingleSubGraph()
void testReplaceSingleSubGraph_inTemplate()
DGraph makeTestGraphB(FragmentSpace fs)
Creates a test graph that looks like this:
void testExploreGraph_nothingToExplore()
static DGraph makeTestGraph_treeWithOutScaffold(FragmentSpace fs)
Creates a test graph that intentionally violates APClass compatibility and looks like this:
void testReplaceSingleSubGraph_NonScafToNonScaf_withAPClassViolation()
void testConvertSymmetricLabelsToSymmetricSets()
DGraph makeTestGraphJ(FragmentSpace fs)
Creates a test graph that looks like this:
static FragmentSpace prepare()
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 testEmbedPatternsInTemplates()
void testGetEmbeddedGraphInClone()
void testGetChildrenTreeWithBranchIdentifier()
void testGetSymmetricSubGraphs()
void testSameAs_SameRings()
void testReplaceSingleSubGraph_ringFormation()
DGraph makeTestGraphF(FragmentSpace fs)
Creates a test graph that looks like this:
static DGraph makeTestGraphO_B(FragmentSpace fs)
Creates a test graph that intentionally violates APClass compatibility and looks like this:
static DGraph makeTestGraphN()
Returns a graph with peculiar definition of symmetric vertexes and symmetric APs meant for testing pu...
DGraph[] makeIsostructuralGraphs()
void testIsIsostructuralTo()
void testSameAs_DiffRings()
void testReplaceSingleSubGraph_ScafToScaf_withAPClassViolation()
static DGraph makeTestGraphO_A(FragmentSpace fs)
Creates a test graph that intentionally violates APClass compatibility and looks like this:
void testGetSubgraphAPs()
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.
A query for edges: a list of properties that target edges should possess in order to match this query...
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.
void addAP(int atomPositionNumber)
Adds an attachment point with a dummy APClass.
void projectAPsToProperties()
Finds the DENOPTIMAttachmentPoint objects defined as properties of the atoms in this container,...
This class represents the closure of a ring in a spanning tree.
int getDistance(Vertex v1, Vertex v2)
Measures how many edges there are between two edges along the sequence of vertices that defined this ...
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)
static Template getTestTemplate(ContractLevel contractLevel)
Method meant for devel phase only.
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
int getBuildingBlockId()
Returns the index of the building block that should correspond to the position of the building block ...
void setVertexId(long vertexId2)
Vertex.BBType getBuildingBlockType()
void setAsRCV(boolean isRCV)
DGraph getGraphOwner()
Returns the graph this vertex belongs to or null.
abstract List< AttachmentPoint > getAttachmentPoints()
void setBuildingBlockId(int buildingBlockId)
Object getProperty(Object property)
void setUniquefyingProperty(String key)
Add the given key among the properties that are checked for equality when comparing vertices with the...
void setBuildingBlockType(Vertex.BBType buildingBlockType)
void setProperty(Object key, Object property)
AttachmentPoint getAP(int i)
Get attachment point i on this vertex.
static Vertex newVertexFromLibrary(int bbId, Vertex.BBType bbt, FragmentSpace fragSpace)
Builds a new molecular fragment kind of vertex.
Query for searching vertices.
This object represents a path in a DGraph.
List< Edge > getEdgesPath()
Returns the list of edges involved, if any.
Possible chemical bond types an edge can represent.
Enum specifying to what extent the template's inner graph can be changed.
FREE
Inner graphs are free to change within the confines of the required AttachmentPoints.
FIXED
Inner graphs are effectively equivalent to the Fragment class, as no change in the inner structure is...
The type of building block.
Flag declaring the type of Vertex implementation.
Types of mutation defined in relation to what happens to the target vertex (i.e., the actual mutation...