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;
52import org.openscience.cdk.smiles.SmilesParser;
54import denoptim.constants.DENOPTIMConstants;
55import denoptim.exception.DENOPTIMException;
56import denoptim.fragspace.FragmentSpace;
57import denoptim.fragspace.FragmentSpaceParameters;
58import denoptim.graph.Edge.BondType;
59import denoptim.graph.Template.ContractLevel;
60import denoptim.graph.Vertex.BBType;
61import denoptim.graph.Vertex.VertexType;
62import denoptim.graph.rings.PathSubGraph;
63import denoptim.utils.MutationType;
76 private static String
a=
"A",
b=
"B",
c=
"C",
d=
"D",
cap=
"cap";
89 HashMap<APClass,ArrayList<APClass>> cpMap =
90 new HashMap<APClass,ArrayList<APClass>>();
91 ArrayList<APClass> lstA =
new ArrayList<APClass>();
93 cpMap.put(
APCA, lstA);
94 ArrayList<APClass> lstB =
new ArrayList<APClass>();
97 cpMap.put(
APCB, lstB);
98 ArrayList<APClass> lstC =
new ArrayList<APClass>();
101 cpMap.put(
APCC, lstC);
102 ArrayList<APClass> lstD =
new ArrayList<APClass>();
104 cpMap.put(
APCD, lstD);
120 HashMap<APClass,APClass> capMap =
new HashMap<APClass,APClass>();
121 HashSet<APClass> forbEnds =
new HashSet<APClass>();
124 new ArrayList<Vertex>(),
125 new ArrayList<Vertex>(),
126 new ArrayList<Vertex>(),
127 cpMap, capMap, forbEnds, cpMap);
273 List<Vertex> symA =
new ArrayList<Vertex>();
278 List<Vertex> symB =
new ArrayList<Vertex>();
348 List<Vertex> sym1 =
new ArrayList<Vertex>();
352 List<Vertex> sym2 =
new ArrayList<Vertex>();
356 List<Vertex> sym3 =
new ArrayList<Vertex>();
360 List<Vertex> sym4 =
new ArrayList<Vertex>();
469 graph.
addRing(v7a_bis, v7a_tris);
471 List<Vertex> symA =
new ArrayList<Vertex>();
476 List<Vertex> symB =
new ArrayList<Vertex>();
534 graph.
addRing(v7a_bis, v7a_tris);
576 List<Vertex> symB =
new ArrayList<Vertex>();
643 List<Vertex> symFirstLayer =
new ArrayList<Vertex>();
644 symFirstLayer.add(v2b);
645 symFirstLayer.add(v2b_bis);
648 List<Vertex> symSecondLayer =
new ArrayList<Vertex>();
649 symSecondLayer.add(v3b_1);
650 symSecondLayer.add(v3b_2);
722 List<Vertex> symA =
new ArrayList<Vertex>();
727 List<Vertex> symB =
new ArrayList<Vertex>();
820 List<Vertex> symA =
new ArrayList<Vertex>();
825 List<Vertex> symB =
new ArrayList<Vertex>();
884 graph.
addRing(v7a_d, v7a_d_quat);
885 graph.
addRing(v7a_d_bis, v7a_d_tris);
887 List<Vertex> symC =
new ArrayList<Vertex>();
938 graph.
addRing(v7a_bis, v7a_tris);
1069 List<Vertex> vToCap =
new ArrayList<Vertex>();
1072 vToCap.add(v1a_2_bis);
1073 vToCap.add(v1a_2_tris);
1078 if (ap.isAvailable())
1094 List<Vertex> symA =
new ArrayList<Vertex>();
1099 List<Vertex> symB =
new ArrayList<Vertex>();
1101 symB.add(v1a_2_bis);
1219 graph.
addRing(v7a_bis, v7a_tris);
1221 List<Vertex> symA =
new ArrayList<Vertex>();
1226 List<Vertex> symB =
new ArrayList<Vertex>();
1290 DGraph refToPrevGraph = gOut;
1291 Vertex refToPRevVrtx = vOut;
1292 for (
int embeddingLevel=0; embeddingLevel<10; embeddingLevel++)
1331 HashMap<APClass,ArrayList<APClass>> cpMap =
1332 new HashMap<APClass,ArrayList<APClass>>();
1333 cpMap.put(a0,
new ArrayList<APClass>(Arrays.asList(a0, b0)));
1334 HashMap<APClass,APClass> capMap =
new HashMap<APClass,APClass>();
1336 HashSet<APClass> forbEnds =
new HashSet<APClass>();
1340 IAtom a1 =
new Atom(
"C",
new Point3d(
new double[]{0.0, 0.0, 0.0}));
1341 IAtom a2 =
new Atom(
"C",
new Point3d(
new double[]{1.0, 0.0, 0.0}));
1344 frg1.
addBond(
new Bond(a1, a2));
1345 frg1.
addAP(0, a0,
new Point3d(
new double[]{0.0, 0.0, 1.0}));
1346 frg1.
addAP(1, a0,
new Point3d(
new double[]{1.0, 1.0, 1.0}));
1350 IAtom a3 =
new Atom(
"C",
new Point3d(
new double[]{0.0, 0.0, 0.0}));
1352 frg2.
addAP(0, a0,
new Point3d(
new double[]{0.0, 1.0, 1.0}));
1353 frg2.
addAP(0, b0,
new Point3d(
new double[]{0.0, 1.0, -1.0}));
1357 IAtom a4 =
new PseudoAtom(
"ATP",
new Point3d(
1358 new double[]{0.0, 0.0, 0.0}));
1360 rca1.
addAP(0, ap0,
new Point3d(
new double[]{0.0, 1.0, 1.0}));
1364 IAtom a5 =
new PseudoAtom(
"ATM",
new Point3d(
1365 new double[]{1.0, 0.0, 0.0}));
1367 rca2.
addAP(0, am0,
new Point3d(
new double[]{0.0, 1.0, 1.0}));
1371 IAtom a6 =
new Atom(
"H",
new Point3d(
new double[]{0.0, 0.0, 0.0}));
1373 cap.addAP(0, h0,
new Point3d(
new double[]{0.0, 1.0, 1.0}));
1374 cap.projectAPsToProperties();
1376 ArrayList<Vertex> scaff =
new ArrayList<Vertex>();
1378 ArrayList<Vertex> frags =
new ArrayList<Vertex>();
1382 ArrayList<Vertex> caps =
new ArrayList<Vertex>();
1387 cpMap, capMap, forbEnds, cpMap);
1412 "Number of vertexes after removal of 0 unused RCVs.");
1414 "Number of edges after removal of 0 unused RCVs.");
1436 "Number of RCVs after removal of 2 unused RCVs.");
1438 "Number of vertexes after removal of 2 unused RCVs.");
1440 "Number of edges after removal of 2 unused RCVs.");
1451 List<Template> expected =
new ArrayList<Template>();
1452 DGraph refToThisLayerGraph = gOut;
1453 Template refToThisLayerVrtx =
null;
1454 for (
int embeddingLevel=0; embeddingLevel<10; embeddingLevel++)
1456 refToThisLayerVrtx = (
Template) refToThisLayerGraph
1457 .getVertexList().stream()
1458 .filter(v -> v instanceof
Template)
1461 expected.add(refToThisLayerVrtx);
1466 "Embedding path of graph that is not embedded");
1468 assertEquals(expected, path,
"Path of deepest embedded graph");
1482 List<Template> expectedPathA =
new ArrayList<Template>();
1483 List<Template> expectedPathB =
new ArrayList<Template>();
1484 DGraph refToThisLayerGraphB = gB;
1485 Template refToThisLayerVrtxB =
null;
1486 DGraph refToThisLayerGraphA = gA;
1487 Template refToThisLayerVrtxA =
null;
1488 for (
int embeddingLevel=0; embeddingLevel<9; embeddingLevel++)
1490 refToThisLayerVrtxA = (
Template) refToThisLayerGraphA
1491 .getVertexList().stream()
1492 .filter(v -> v instanceof
Template)
1495 expectedPathA.add(refToThisLayerVrtxA);
1498 refToThisLayerVrtxB = (
Template) refToThisLayerGraphB
1499 .getVertexList().stream()
1500 .filter(v -> v instanceof
Template)
1503 expectedPathB.add(refToThisLayerVrtxB);
1507 DGraph expectedEmbeddedA = expectedPathA.get(8).getInnerGraph();
1508 DGraph expectedEmbeddedB = expectedPathB.get(8).getInnerGraph();
1513 assertEquals(expectedEmbeddedB,embeddedFoundB);
1516 assertEquals(expectedPathB,pathFoundB);
1520 assertEquals(expectedEmbeddedA,embeddedFoundA);
1523 assertEquals(expectedPathA,pathFoundA);
1535 "Inconsistent source vertex");
1540 "Inconsistent source vertex");
1550 int[] expected =
new int[] {2,3,0,1,-1};
1554 "Wrong level for vertex at position "+i);
1558 expected =
new int[] {-1,0,1,2,3,2,0,1,2,3,2};
1562 "Bis: Wrong level for vertex at position "+i);
1576 LinkedHashMap<Integer, Integer> apMap =
1577 new LinkedHashMap<Integer,Integer>();
1586 boolean res = g.
replaceVertex(v1, chosenBBId, choosenBBTyp, apMap, fs);
1588 assertTrue(res,
"ReplaceVertex return value.");
1590 int numVertexesWithGoodBBId = 0;
1591 int numEdgesWithS = 0;
1592 int numEdgesWith2 = 0;
1593 int numEdgesWith3 = 0;
1599 numVertexesWithGoodBBId++;
1603 if (!ap.isAvailable())
1605 Vertex nextVrtx = ap.getLinkedAP().getOwner();
1624 assertEquals(2,numVertexesWithGoodBBId,
"Number of new links.");
1625 assertEquals(2,numEdgesWithS,
"Number of new edges with scaffold.");
1626 assertEquals(4,numEdgesWith2,
"Number of new edges with v2a/b.");
1627 assertEquals(2,numEdgesWith3,
"Number of new edges with v3a/b.");
1641 Set<Long> oldVertexIds =
new HashSet<Long>();
1645 LinkedHashMap<Integer,Integer> apMap2 =
1646 new LinkedHashMap<Integer,Integer>();
1649 int chosenBBId2 = 5;
1652 boolean res2 = g2.
replaceVertex(v2, chosenBBId2, choosenBBTyp2, apMap2,
1655 assertTrue(res2,
"ReplaceVertex return value (2).");
1657 int numVertexesWithGoodBBId2 = 0;
1658 int numEdgesWith1 = 0;
1664 numVertexesWithGoodBBId2++;
1668 if (!ap.isAvailable())
1670 Vertex nextVrtx = ap.getLinkedAP().getOwner();
1677 assertEquals(4,numVertexesWithGoodBBId2,
"Number of new links.");
1678 assertEquals(4,numEdgesWith1,
"Number of new edges with scaffold.");
1680 boolean found =
false;
1681 boolean foundOldVertexId =
false;
1683 while (iterSS.hasNext())
1686 if (ss.size() == origSS.size())
1692 foundOldVertexId =
true;
1696 assertTrue(found,
"could not find old symmetric set");
1697 assertFalse(foundOldVertexId,
"found old vertex id in new symmetric set");
1710 LinkedHashMap<Integer, Integer> apMap =
1711 new LinkedHashMap<Integer,Integer>();
1733 List<Vertex> vrtxsToReplace =
new ArrayList<Vertex>();
1739 LinkedHashMap<AttachmentPoint, AttachmentPoint> apMap =
1740 new LinkedHashMap<AttachmentPoint,AttachmentPoint>();
1761 "graph's surce vertex");
1765 assertEquals(3,pathA.
getEdgesPath().size(),
"path within a ring (A)");
1768 assertEquals(5,pathB.
getEdgesPath().size(),
"path within a ring (B)");
1771 assertEquals(4,pathC.
getEdgesPath().size(),
"path within a ring (C)");
1774 assertTrue(g.
isIsomorphicTo(expected),
"isomforphic to expected");
1788 List<Vertex> vrtxsToReplace =
new ArrayList<Vertex>();
1793 LinkedHashMap<AttachmentPoint, AttachmentPoint> apMap =
1794 new LinkedHashMap<AttachmentPoint,AttachmentPoint>();
1796 apMap.put(vrtxsToReplace.get(0).getAP(3),
1798 apMap.put(vrtxsToReplace.get(0).getAP(4),
1801 apMap.put(vrtxsToReplace.get(0).getAP(0),
1803 apMap.put(vrtxsToReplace.get(0).getAP(1),
1807 incomingSubGraph, apMap);
1811 assertEquals(1,g.
getRingCount(),
"Rings in outer graph");
1815 "Distance Head-Tail in ring of outer graph");
1820 "Vertex in inner graph");
1822 "Rings in inner graph");
1824 "Free APs inner graph");
1827 "Distance Head-Tail in ring of inner graph");
1867 Arrays.asList(v5, v4, v0, v1, v2, v3))));
1870 Arrays.asList(v6, v0, v4, v7))));
1904 assertEquals(numVa, numV - 1);
1905 assertEquals(numEa, numE - 1);
1906 assertEquals(numSa, numS - 1);
1907 assertEquals(numRa, numR - 1);
1916 assertEquals(numVb, numVa - 1);
1917 assertEquals(numEb, numEa - 1);
1918 assertEquals(numSb, numSa);
1919 assertEquals(numRb, numRa);
1928 assertEquals(numVc, numVb - 1);
1929 assertEquals(numEc, numEb - 2);
1930 assertEquals(numSc, numSb);
1931 assertEquals(numRc, numRb - 1);
1966 StringBuilder reason =
new StringBuilder();
1967 assertTrue(graphA.
sameAs(graphB, reason), reason.toString());
2001 StringBuilder reason =
new StringBuilder();
2002 assertFalse(graphA.
sameAs(graphB, reason));
2075 StringBuilder reason =
new StringBuilder();
2076 assertTrue(graphA.
sameAs(graphB, reason));
2143 StringBuilder reason =
new StringBuilder();
2144 assertFalse(graphA.
sameAs(graphB, reason));
2172 ArrayList<Vertex> vrA =
new ArrayList<Vertex>();
2178 ArrayList<Vertex> vrA2 =
new ArrayList<Vertex>();
2208 ArrayList<Vertex> vrB =
new ArrayList<Vertex>();
2214 ArrayList<Vertex> vrB2 =
new ArrayList<Vertex>();
2221 StringBuilder reason =
new StringBuilder();
2222 assertTrue(graphA.
sameAs(graphB, reason));
2250 ArrayList<Vertex> vrA =
new ArrayList<>();
2256 ArrayList<Vertex> vrA2 =
new ArrayList<>();
2286 ArrayList<Vertex> vrB =
new ArrayList<>();
2292 ArrayList<Vertex> vrB2 =
new ArrayList<>();
2299 StringBuilder reason =
new StringBuilder();
2300 assertTrue(graphA.
sameAs(graphB, reason));
2328 ArrayList<Vertex> vrA =
new ArrayList<>();
2334 ArrayList<Vertex> vrA2 =
new ArrayList<>();
2362 ArrayList<Vertex> vrB =
new ArrayList<>();
2368 ArrayList<Vertex> vrB2 =
new ArrayList<>();
2375 StringBuilder reason =
new StringBuilder();
2376 assertFalse(graphA.
sameAs(graphB, reason));
2401 assertEquals(1,lst.size(),
"Size of list");
2402 assertEquals(vertex0.
getVertexId(),lst.get(0).getOwner().getVertexId(),
2403 "ID of the vertex holding the available AP.");
2443 Arrays.asList(v5, v4, v0, v1, v2, v3))));
2446 Arrays.asList(v6, v0, v4, v7))));
2461 "Number of vertices");
2467 "Number of symmetric sets");
2469 "Number of closable chains");
2479 int hashVG = vg.hashCode();
2480 int hashVC = vc.hashCode();
2485 "Reference to vertex owner in ap " + iap +
" vertex "
2488 "Reference to vertex owner in ap " + iap +
" vertex "
2492 "Owner of AP "+iap+
" in vertex "+iv);
2508 "Size of mutation list in case of frozen template");
2515 "Size of mutation list in case of free template");
2519 "No sites if all is ignored");
2586 IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
2587 IAtomContainer iac1 = builder.newAtomContainer();
2588 IAtom ia1 =
new Atom(
"C");
2589 IAtom ia2 =
new Atom(
"C");
2592 iac1.addBond(
new Bond(ia1, ia2, IBond.Order.SINGLE));
2600 IAtomContainer iac2 = builder.newAtomContainer();
2601 iac2.addAtom(
new Atom(
"O"));
2606 IAtomContainer iac3 = builder.newAtomContainer();
2607 iac3.addAtom(
new Atom(
"H"));
2612 IAtomContainer iac4 = builder.newAtomContainer();
2613 iac4.addAtom(
new Atom(
"H"));
2633 }
catch (Throwable t)
2635 t.printStackTrace();
2636 System.err.println(
"FATAL ERROR! Could not make test graph (A). "
2637 +
"Please, report this to the development team.");
2675 IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
2676 IAtomContainer iac1 = builder.newAtomContainer();
2677 IAtom ia1 =
new Atom(
"C");
2678 IAtom ia2 =
new Atom(
"C");
2681 iac1.addBond(
new Bond(ia1, ia2, IBond.Order.SINGLE));
2690 IAtomContainer iac2 = builder.newAtomContainer();
2691 iac2.addAtom(
new Atom(
"O"));
2697 IAtomContainer iac3 = builder.newAtomContainer();
2698 iac3.addAtom(
new Atom(
"H"));
2703 IAtomContainer iac4 = builder.newAtomContainer();
2704 iac4.addAtom(
new Atom(
"H"));
2746 }
catch (Throwable t)
2748 t.printStackTrace();
2749 System.err.println(
"FATAL ERROR! Could not make test graph (A). "
2750 +
"Please, report this to the development team.");
2764 IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
2765 IAtomContainer iac1 = builder.newAtomContainer();
2766 iac1.addAtom(
new Atom(
"C"));
2771 IAtomContainer iac2 = builder.newAtomContainer();
2772 iac2.addAtom(
new Atom(
"O"));
2777 IAtomContainer iac3 = builder.newAtomContainer();
2778 iac3.addAtom(
new Atom(
"H"));
2782 IAtomContainer iac4 = builder.newAtomContainer();
2783 iac4.addAtom(
new Atom(
"H"));
2796 "#vertices in graph before removal");
2802 "#vertices in graph before removal");
2804 "Capping is still contained");
2806 "Owner of removed capping group is null");
2810 IAtomContainer iac12 = builder.newAtomContainer();
2811 iac12.addAtom(
new Atom(
"C"));
2816 IAtomContainer iac22 = builder.newAtomContainer();
2817 iac22.addAtom(
new Atom(
"O"));
2822 IAtomContainer iac23 = builder.newAtomContainer();
2823 iac23.addAtom(
new Atom(
"H"));
2827 IAtomContainer iac24 = builder.newAtomContainer();
2828 iac24.addAtom(
new Atom(
"H"));
2841 "#vertices in graph before removal (B)");
2848 "#vertices in graph before removal (B)");
2850 "Capping is still contained (B)");
2852 "Capping is still contained (C)");
2854 "Owner of removed capping group is null (B)");
2856 "Owner of removed capping group is null (C)");
2864 for (
int atomPos = 0; atomPos < apCount; atomPos++) {
2909 Arrays.asList(v5, v4, v0, v1, v2, v3))));
2912 Arrays.asList(v6, v0, v4, v7))));
2924 String json1 = graph.
toJson();
2927 String json2 = g2.
toJson();
2929 assertTrue(json1.equals(json2),
"Round-trip via JSON is successful");
2943 "self isomorphism on empty graph");
2945 "isomorphism on empty graphs");
2950 "single-vertex graph");
2952 "single-vertex graph vs clone");
2971 "graph with empty vertexes and same properties");
2975 "graph with empty vertexes and different properties");
2985 assertFalse(gD1.
isIsomorphicTo(gAempty),
"graph D vs empty graph");
2986 assertFalse(gAempty.
isIsomorphicTo(gD1),
"empty graph vs graph D");
3009 "Original stays the same");
3018 "SymmetricSets in subGraph1");
3019 assertEquals(1,subGraph1.
getRingCount(),
"Rings in subGraph1");
3021 "Original stays the same");
3030 "SymmetricSets in subGraph2");
3031 assertEquals(0,subGraph2.
getRingCount(),
"Rings in subGraph2");
3033 "Original stays the same");
3044 Set<Vertex> targetVertexes =
new HashSet<>();
3051 for (
Vertex vInTarget : targetVertexes)
3056 Set<Edge> connectionToSubgraph =
new HashSet<Edge>();
3057 Set<Edge> connectionFromSubgraph =
new HashSet<Edge>();
3059 connectionToSubgraph, connectionFromSubgraph);
3061 assertEquals(1, connectionToSubgraph.size());
3062 assertEquals(3, connectionFromSubgraph.size());
3067 boolean found0 =
false;
3068 for (
Edge e : connectionToSubgraph)
3070 Vertex inResults = e.getSrcAP().getOwner();
3076 boolean found2 =
false;
3077 boolean found4 =
false;
3078 boolean found6 =
false;
3079 for (
Edge e : connectionFromSubgraph)
3081 Vertex inResults = e.getTrgAP().getOwner();
3101 List<VertexQuery> allQueries =
new ArrayList<VertexQuery>();
3102 List<List<Vertex>> allExpected =
3103 new ArrayList<List<Vertex>>();
3106 List<Vertex> e0 =
new ArrayList<Vertex>();
3109 allExpected.add(e0);
3113 null,
null,
null,
null,
null,
null);
3114 List<Vertex> e1 =
new ArrayList<Vertex>();
3117 allExpected.add(e1);
3121 null,
null,
null,
null,
null,
null);
3122 List<Vertex> e2 =
new ArrayList<Vertex>();
3125 allExpected.add(e2);
3128 null,
null,
null,
null,
null);
3129 List<Vertex> e3 =
new ArrayList<Vertex>();
3134 allExpected.add(e3);
3137 null,
null,
null,
null);
3138 List<Vertex> e4 =
new ArrayList<Vertex>();
3142 allExpected.add(e4);
3146 List<Vertex> e5 =
new ArrayList<Vertex>();
3149 allExpected.add(e5);
3153 List<Vertex> e6 =
new ArrayList<Vertex>();
3157 allExpected.add(e6);
3166 List<Vertex> e7 =
new ArrayList<Vertex>();
3169 allExpected.add(e7);
3172 null,
null,
null,
null,
null,
null);
3175 List<Vertex> e8 =
new ArrayList<Vertex>();
3178 allExpected.add(e8);
3185 null,
null,
null,
null,
null);
3188 List<Vertex> e9 =
new ArrayList<Vertex>();
3191 allExpected.add(e9);
3196 List<Vertex> e10 =
new ArrayList<Vertex>();
3199 allQueries.add(q10);
3200 allExpected.add(e10);
3205 List<Vertex> e11 =
new ArrayList<Vertex>();
3211 allQueries.add(q11);
3212 allExpected.add(e11);
3218 List<Vertex> e12 =
new ArrayList<Vertex>();
3221 allQueries.add(q12);
3222 allExpected.add(e12);
3228 List<Vertex> e13 =
new ArrayList<Vertex>();
3232 allQueries.add(q13);
3233 allExpected.add(e13);
3239 List<Vertex> e14 =
new ArrayList<Vertex>();
3242 allQueries.add(q14);
3243 allExpected.add(e14);
3253 null,
null,
null,
null,
null,
null);
3256 List<Vertex> e15 =
new ArrayList<Vertex>();
3258 allQueries.add(q15);
3259 allExpected.add(e15);
3263 null,
null,
null,
null,
null);
3266 List<Vertex> e16 =
new ArrayList<Vertex>();
3268 allQueries.add(q16);
3269 allExpected.add(e16);
3274 List<Vertex> e17 =
new ArrayList<Vertex>();
3277 allQueries.add(q17);
3278 allExpected.add(e17);
3283 List<Vertex> e18 =
new ArrayList<Vertex>();
3287 allQueries.add(q18);
3288 allExpected.add(e18);
3294 List<Vertex> e19 =
new ArrayList<Vertex>();
3297 allQueries.add(q19);
3298 allExpected.add(e19);
3304 List<Vertex> e20 =
new ArrayList<Vertex>();
3307 allQueries.add(q20);
3308 allExpected.add(e20);
3314 List<Vertex> e21 =
new ArrayList<Vertex>();
3317 allQueries.add(q21);
3318 allExpected.add(e21);
3328 List<Vertex> e22 =
new ArrayList<Vertex>();
3330 allQueries.add(q22);
3331 allExpected.add(e22);
3336 null,
null,
null, eq23,
null);
3337 List<Vertex> e23 =
new ArrayList<Vertex>();
3339 allQueries.add(q23);
3340 allExpected.add(e23);
3342 for (
int i=0; i<allQueries.size(); i++)
3344 List<Vertex> matches = g.
findVertices(allQueries.get(i),
3345 Logger.getLogger(
"DummyLogger"));
3346 assertEquals(allExpected.get(i).size(),matches.size(),
3347 "Different number of matched vertexes ("+i+
")");
3348 assertTrue(allExpected.get(i).containsAll(matches),
3349 "Inconsistent matches ("+i+
")");
3364 Map<Object,Integer> countsPerLabel =
new HashMap<Object,Integer>();
3368 if (countsPerLabel.containsKey(label))
3369 countsPerLabel.put(label,countsPerLabel.get(label)+1);
3371 countsPerLabel.put(label,1);
3405 boolean foundA =
false;
3406 boolean foundB =
false;
3408 while (iter.hasNext())
3416 assertTrue(foundA,
"Found 2-membered set");
3417 assertTrue(foundB,
"Found 4-membered set");
3429 while (iter2.hasNext())
3432 assertEquals(2,ss.size(),
"side of each symmetric sets.");
3443 List<Vertex> sg =
new ArrayList<Vertex>();
3449 assertEquals(2,symSubGraphs.size(),
"Number of subgraphs");
3451 symSubGraphs.get(0).get(0).getVertexId());
3453 symSubGraphs.get(0).get(1).getVertexId());
3455 symSubGraphs.get(1).get(0).getVertexId());
3457 symSubGraphs.get(1).get(1).getVertexId());
3461 List<Vertex> sg2 =
new ArrayList<Vertex>();
3470 boolean exceptionWhenCappingIsIncluded =
false;
3476 if (e.getMessage().contains(
"Capping groups must not be part of "
3477 +
"symmetric subgraphs"))
3478 exceptionWhenCappingIsIncluded =
true;
3480 assertTrue(exceptionWhenCappingIsIncluded,
3481 "Capping groups trigger exception");
3483 sg2 =
new ArrayList<Vertex>();
3487 assertEquals(2,symSubGraphs.size());
3488 assertEquals(2,symSubGraphs.get(0).size());
3489 assertEquals(2,symSubGraphs.get(1).size());
3500 List<Vertex> childTree =
new ArrayList<Vertex>();
3502 assertEquals(6,childTree.size());
3510 childTree =
new ArrayList<Vertex>();
3512 assertEquals(1,childTree.size());
3515 childTree =
new ArrayList<Vertex>();
3517 assertEquals(4,childTree.size());
3523 childTree =
new ArrayList<Vertex>();
3526 assertEquals(3,childTree.size());
3544 List<Vertex> childTree =
new ArrayList<Vertex>();
3546 new AtomicInteger(0),
new ArrayList<Integer>());
3585 List<Vertex> subGraph =
new ArrayList<Vertex>();
3589 List<AttachmentPoint> expected =
new ArrayList<AttachmentPoint>();
3595 assertEquals(expected,interfaceAPs);
3600 subGraph =
new ArrayList<Vertex>();
3604 expected =
new ArrayList<AttachmentPoint>();
3612 assertEquals(expected,interfaceAPs);
3626 List<Vertex> subGraph =
new ArrayList<Vertex>();
3630 List<AttachmentPoint>expected =
new ArrayList<AttachmentPoint>();
3640 assertEquals(expected,interfaceAPs);
3647 String unqProp =
"UNQPROP";
3773 LinkedHashMap<AttachmentPoint,AttachmentPoint> apMap =
3774 new LinkedHashMap<AttachmentPoint,AttachmentPoint>();
3778 List<Vertex> toReplace =
new ArrayList<Vertex>();
3792 incomingSubGraph =
new DGraph();
3794 apMap =
new LinkedHashMap<AttachmentPoint,AttachmentPoint>();
3797 toReplace =
new ArrayList<Vertex>();
3822 assertEquals(2, egdesFrom.size());
3824 egdesFrom.get(0).getTrgAP().getOwner());
3826 egdesFrom.get(1).getTrgAP().getOwner());
3829 assertEquals(1, egdesTo.size());
3831 egdesTo.get(0).getSrcAP().getOwner());
3850 .filter(v -> v instanceof
Template)
3851 .collect(Collectors.toList());
3852 assertEquals(2, templates.size());
3853 assertEquals(1, templates.stream()
3856 assertEquals(1, templates.stream()
4041 assertEquals(0, symVrtxs.size());
4044 assertEquals(2, symVrtxs.size());
4049 assertEquals(6, symVrtxs.size());
4058 assertEquals(2, symVrtxs.size());
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.
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.
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.
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.
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.
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...
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.
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.
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...
ArrayList< Vertex > findVertices(VertexQuery vrtxQuery, Logger logger)
Filters a list of vertices according to a query.
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()
void testReplaceSubGraph_inTemplate()
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:
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 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()
DGraph makeTestGraphB(FragmentSpace fs)
Creates a test graph that looks like this:
void testReplaceSubGraph()
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()
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()
void testIsIsostructuralTo()
void testSameAs_DiffRings()
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.
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...