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";
88 HashMap<APClass,ArrayList<APClass>> cpMap =
89 new HashMap<APClass,ArrayList<APClass>>();
90 ArrayList<APClass> lstA =
new ArrayList<APClass>();
92 cpMap.put(
APCA, lstA);
93 ArrayList<APClass> lstB =
new ArrayList<APClass>();
96 cpMap.put(
APCB, lstB);
97 ArrayList<APClass> lstC =
new ArrayList<APClass>();
100 cpMap.put(
APCC, lstC);
101 ArrayList<APClass> lstD =
new ArrayList<APClass>();
103 cpMap.put(
APCD, lstD);
119 HashMap<APClass,APClass> capMap =
new HashMap<APClass,APClass>();
120 HashSet<APClass> forbEnds =
new HashSet<APClass>();
123 new ArrayList<Vertex>(),
124 new ArrayList<Vertex>(),
125 new ArrayList<Vertex>(),
126 cpMap, capMap, forbEnds, cpMap);
272 List<Vertex> symA =
new ArrayList<Vertex>();
277 List<Vertex> symB =
new ArrayList<Vertex>();
347 List<Vertex> sym1 =
new ArrayList<Vertex>();
351 List<Vertex> sym2 =
new ArrayList<Vertex>();
355 List<Vertex> sym3 =
new ArrayList<Vertex>();
359 List<Vertex> sym4 =
new ArrayList<Vertex>();
468 graph.
addRing(v7a_bis, v7a_tris);
470 List<Vertex> symA =
new ArrayList<Vertex>();
475 List<Vertex> symB =
new ArrayList<Vertex>();
533 graph.
addRing(v7a_bis, v7a_tris);
575 List<Vertex> symB =
new ArrayList<Vertex>();
642 List<Vertex> symFirstLayer =
new ArrayList<Vertex>();
643 symFirstLayer.add(v2b);
644 symFirstLayer.add(v2b_bis);
647 List<Vertex> symSecondLayer =
new ArrayList<Vertex>();
648 symSecondLayer.add(v3b_1);
649 symSecondLayer.add(v3b_2);
721 List<Vertex> symA =
new ArrayList<Vertex>();
726 List<Vertex> symB =
new ArrayList<Vertex>();
819 List<Vertex> symA =
new ArrayList<Vertex>();
824 List<Vertex> symB =
new ArrayList<Vertex>();
883 graph.
addRing(v7a_d, v7a_d_quat);
884 graph.
addRing(v7a_d_bis, v7a_d_tris);
886 List<Vertex> symC =
new ArrayList<Vertex>();
937 graph.
addRing(v7a_bis, v7a_tris);
1068 List<Vertex> vToCap =
new ArrayList<Vertex>();
1071 vToCap.add(v1a_2_bis);
1072 vToCap.add(v1a_2_tris);
1077 if (ap.isAvailable())
1093 List<Vertex> symA =
new ArrayList<Vertex>();
1098 List<Vertex> symB =
new ArrayList<Vertex>();
1100 symB.add(v1a_2_bis);
1218 graph.
addRing(v7a_bis, v7a_tris);
1220 List<Vertex> symA =
new ArrayList<Vertex>();
1225 List<Vertex> symB =
new ArrayList<Vertex>();
1289 DGraph refToPrevGraph = gOut;
1290 Vertex refToPRevVrtx = vOut;
1291 for (
int embeddingLevel=0; embeddingLevel<10; embeddingLevel++)
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>();
1334 HashSet<APClass> forbEnds =
new HashSet<APClass>();
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}));
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}));
1348 IAtom a3 =
new Atom(
"C",
new Point3d(
new double[]{0.0, 0.0, 0.0}));
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}));
1355 IAtom a4 =
new PseudoAtom(
"ATP",
new Point3d(
1356 new double[]{0.0, 0.0, 0.0}));
1358 rca1.
addAP(0, ap0,
new Point3d(
new double[]{0.0, 1.0, 1.0}));
1362 IAtom a5 =
new PseudoAtom(
"ATM",
new Point3d(
1363 new double[]{1.0, 0.0, 0.0}));
1365 rca2.
addAP(0, am0,
new Point3d(
new double[]{0.0, 1.0, 1.0}));
1369 IAtom a6 =
new Atom(
"H",
new Point3d(
new double[]{0.0, 0.0, 0.0}));
1371 cap.addAP(0, h0,
new Point3d(
new double[]{0.0, 1.0, 1.0}));
1372 cap.projectAPsToProperties();
1374 ArrayList<Vertex> scaff =
new ArrayList<Vertex>();
1376 ArrayList<Vertex> frags =
new ArrayList<Vertex>();
1380 ArrayList<Vertex> caps =
new ArrayList<Vertex>();
1385 cpMap, capMap, forbEnds, cpMap);
1410 "Number of vertexes after removal of 0 unused RCVs.");
1412 "Number of edges after removal of 0 unused RCVs.");
1434 "Number of RCVs after removal of 2 unused RCVs.");
1436 "Number of vertexes after removal of 2 unused RCVs.");
1438 "Number of edges after removal of 2 unused RCVs.");
1449 List<Template> expected =
new ArrayList<Template>();
1450 DGraph refToThisLayerGraph = gOut;
1451 Template refToThisLayerVrtx =
null;
1452 for (
int embeddingLevel=0; embeddingLevel<10; embeddingLevel++)
1454 refToThisLayerVrtx = (
Template) refToThisLayerGraph
1455 .getVertexList().stream()
1456 .filter(v -> v instanceof
Template)
1459 expected.add(refToThisLayerVrtx);
1464 "Embedding path of graph that is not embedded");
1466 assertEquals(expected, path,
"Path of deepest embedded graph");
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++)
1488 refToThisLayerVrtxA = (
Template) refToThisLayerGraphA
1489 .getVertexList().stream()
1490 .filter(v -> v instanceof
Template)
1493 expectedPathA.add(refToThisLayerVrtxA);
1496 refToThisLayerVrtxB = (
Template) refToThisLayerGraphB
1497 .getVertexList().stream()
1498 .filter(v -> v instanceof
Template)
1501 expectedPathB.add(refToThisLayerVrtxB);
1505 DGraph expectedEmbeddedA = expectedPathA.get(8).getInnerGraph();
1506 DGraph expectedEmbeddedB = expectedPathB.get(8).getInnerGraph();
1511 assertEquals(expectedEmbeddedB,embeddedFoundB);
1514 assertEquals(expectedPathB,pathFoundB);
1518 assertEquals(expectedEmbeddedA,embeddedFoundA);
1521 assertEquals(expectedPathA,pathFoundA);
1533 "Inconsistent source vertex");
1538 "Inconsistent source vertex");
1548 int[] expected =
new int[] {2,3,0,1,-1};
1552 "Wrong level for vertex at position "+i);
1556 expected =
new int[] {-1,0,1,2,3,2,0,1,2,3,2};
1560 "Bis: Wrong level for vertex at position "+i);
1574 LinkedHashMap<Integer, Integer> apMap =
1575 new LinkedHashMap<Integer,Integer>();
1584 boolean res = g.
replaceVertex(v1, chosenBBId, choosenBBTyp, apMap, fs);
1586 assertTrue(res,
"ReplaceVertex return value.");
1588 int numVertexesWithGoodBBId = 0;
1589 int numEdgesWithS = 0;
1590 int numEdgesWith2 = 0;
1591 int numEdgesWith3 = 0;
1597 numVertexesWithGoodBBId++;
1601 if (!ap.isAvailable())
1603 Vertex nextVrtx = ap.getLinkedAP().getOwner();
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.");
1639 Set<Long> oldVertexIds =
new HashSet<Long>();
1643 LinkedHashMap<Integer,Integer> apMap2 =
1644 new LinkedHashMap<Integer,Integer>();
1647 int chosenBBId2 = 5;
1650 boolean res2 = g2.
replaceVertex(v2, chosenBBId2, choosenBBTyp2, apMap2,
1653 assertTrue(res2,
"ReplaceVertex return value (2).");
1655 int numVertexesWithGoodBBId2 = 0;
1656 int numEdgesWith1 = 0;
1662 numVertexesWithGoodBBId2++;
1666 if (!ap.isAvailable())
1668 Vertex nextVrtx = ap.getLinkedAP().getOwner();
1675 assertEquals(4,numVertexesWithGoodBBId2,
"Number of new links.");
1676 assertEquals(4,numEdgesWith1,
"Number of new edges with scaffold.");
1678 boolean found =
false;
1679 boolean foundOldVertexId =
false;
1681 while (iterSS.hasNext())
1684 if (ss.size() == origSS.size())
1690 foundOldVertexId =
true;
1694 assertTrue(found,
"could not find old symmetric set");
1695 assertFalse(foundOldVertexId,
"found old vertex id in new symmetric set");
1708 LinkedHashMap<Integer, Integer> apMap =
1709 new LinkedHashMap<Integer,Integer>();
1731 List<Vertex> vrtxsToReplace =
new ArrayList<Vertex>();
1737 LinkedHashMap<AttachmentPoint, AttachmentPoint> apMap =
1738 new LinkedHashMap<AttachmentPoint,AttachmentPoint>();
1759 "graph's surce vertex");
1763 assertEquals(3,pathA.
getEdgesPath().size(),
"path within a ring (A)");
1766 assertEquals(5,pathB.
getEdgesPath().size(),
"path within a ring (B)");
1769 assertEquals(4,pathC.
getEdgesPath().size(),
"path within a ring (C)");
1772 assertTrue(g.
isIsomorphicTo(expected),
"isomforphic to expected");
1786 List<Vertex> vrtxsToReplace =
new ArrayList<Vertex>();
1791 LinkedHashMap<AttachmentPoint, AttachmentPoint> apMap =
1792 new LinkedHashMap<AttachmentPoint,AttachmentPoint>();
1794 apMap.put(vrtxsToReplace.get(0).getAP(3),
1796 apMap.put(vrtxsToReplace.get(0).getAP(4),
1799 apMap.put(vrtxsToReplace.get(0).getAP(0),
1801 apMap.put(vrtxsToReplace.get(0).getAP(1),
1805 incomingSubGraph, apMap);
1809 assertEquals(1,g.
getRingCount(),
"Rings in outer graph");
1813 "Distance Head-Tail in ring of outer graph");
1818 "Vertex in inner graph");
1820 "Rings in inner graph");
1822 "Free APs inner graph");
1825 "Distance Head-Tail in ring of inner graph");
1865 Arrays.asList(v5, v4, v0, v1, v2, v3))));
1868 Arrays.asList(v6, v0, v4, v7))));
1902 assertEquals(numVa, numV - 1);
1903 assertEquals(numEa, numE - 1);
1904 assertEquals(numSa, numS - 1);
1905 assertEquals(numRa, numR - 1);
1914 assertEquals(numVb, numVa - 1);
1915 assertEquals(numEb, numEa - 1);
1916 assertEquals(numSb, numSa);
1917 assertEquals(numRb, numRa);
1926 assertEquals(numVc, numVb - 1);
1927 assertEquals(numEc, numEb - 2);
1928 assertEquals(numSc, numSb);
1929 assertEquals(numRc, numRb - 1);
1964 StringBuilder reason =
new StringBuilder();
1965 assertTrue(graphA.
sameAs(graphB, reason), reason.toString());
1999 StringBuilder reason =
new StringBuilder();
2000 assertFalse(graphA.
sameAs(graphB, reason));
2073 StringBuilder reason =
new StringBuilder();
2074 assertTrue(graphA.
sameAs(graphB, reason));
2141 StringBuilder reason =
new StringBuilder();
2142 assertFalse(graphA.
sameAs(graphB, reason));
2170 ArrayList<Vertex> vrA =
new ArrayList<Vertex>();
2176 ArrayList<Vertex> vrA2 =
new ArrayList<Vertex>();
2206 ArrayList<Vertex> vrB =
new ArrayList<Vertex>();
2212 ArrayList<Vertex> vrB2 =
new ArrayList<Vertex>();
2219 StringBuilder reason =
new StringBuilder();
2220 assertTrue(graphA.
sameAs(graphB, reason));
2248 ArrayList<Vertex> vrA =
new ArrayList<>();
2254 ArrayList<Vertex> vrA2 =
new ArrayList<>();
2284 ArrayList<Vertex> vrB =
new ArrayList<>();
2290 ArrayList<Vertex> vrB2 =
new ArrayList<>();
2297 StringBuilder reason =
new StringBuilder();
2298 assertTrue(graphA.
sameAs(graphB, reason));
2326 ArrayList<Vertex> vrA =
new ArrayList<>();
2332 ArrayList<Vertex> vrA2 =
new ArrayList<>();
2360 ArrayList<Vertex> vrB =
new ArrayList<>();
2366 ArrayList<Vertex> vrB2 =
new ArrayList<>();
2373 StringBuilder reason =
new StringBuilder();
2374 assertFalse(graphA.
sameAs(graphB, reason));
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.");
2441 Arrays.asList(v5, v4, v0, v1, v2, v3))));
2444 Arrays.asList(v6, v0, v4, v7))));
2459 "Number of vertices");
2465 "Number of symmetric sets");
2467 "Number of closable chains");
2477 int hashVG = vg.hashCode();
2478 int hashVC = vc.hashCode();
2483 "Reference to vertex owner in ap " + iap +
" vertex "
2486 "Reference to vertex owner in ap " + iap +
" vertex "
2490 "Owner of AP "+iap+
" in vertex "+iv);
2506 "Size of mutation list in case of frozen template");
2513 "Size of mutation list in case of free template");
2517 "No sites if all is ignored");
2584 IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
2585 IAtomContainer iac1 = builder.newAtomContainer();
2586 IAtom ia1 =
new Atom(
"C");
2587 IAtom ia2 =
new Atom(
"C");
2590 iac1.addBond(
new Bond(ia1, ia2, IBond.Order.SINGLE));
2598 IAtomContainer iac2 = builder.newAtomContainer();
2599 iac2.addAtom(
new Atom(
"O"));
2604 IAtomContainer iac3 = builder.newAtomContainer();
2605 iac3.addAtom(
new Atom(
"H"));
2610 IAtomContainer iac4 = builder.newAtomContainer();
2611 iac4.addAtom(
new Atom(
"H"));
2631 }
catch (Throwable t)
2633 t.printStackTrace();
2634 System.err.println(
"FATAL ERROR! Could not make test graph (A). "
2635 +
"Please, report this to the development team.");
2673 IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
2674 IAtomContainer iac1 = builder.newAtomContainer();
2675 IAtom ia1 =
new Atom(
"C");
2676 IAtom ia2 =
new Atom(
"C");
2679 iac1.addBond(
new Bond(ia1, ia2, IBond.Order.SINGLE));
2688 IAtomContainer iac2 = builder.newAtomContainer();
2689 iac2.addAtom(
new Atom(
"O"));
2695 IAtomContainer iac3 = builder.newAtomContainer();
2696 iac3.addAtom(
new Atom(
"H"));
2701 IAtomContainer iac4 = builder.newAtomContainer();
2702 iac4.addAtom(
new Atom(
"H"));
2744 }
catch (Throwable t)
2746 t.printStackTrace();
2747 System.err.println(
"FATAL ERROR! Could not make test graph (A). "
2748 +
"Please, report this to the development team.");
2762 IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
2763 IAtomContainer iac1 = builder.newAtomContainer();
2764 iac1.addAtom(
new Atom(
"C"));
2769 IAtomContainer iac2 = builder.newAtomContainer();
2770 iac2.addAtom(
new Atom(
"O"));
2775 IAtomContainer iac3 = builder.newAtomContainer();
2776 iac3.addAtom(
new Atom(
"H"));
2780 IAtomContainer iac4 = builder.newAtomContainer();
2781 iac4.addAtom(
new Atom(
"H"));
2794 "#vertices in graph before removal");
2800 "#vertices in graph before removal");
2802 "Capping is still contained");
2804 "Owner of removed capping group is null");
2808 IAtomContainer iac12 = builder.newAtomContainer();
2809 iac12.addAtom(
new Atom(
"C"));
2814 IAtomContainer iac22 = builder.newAtomContainer();
2815 iac22.addAtom(
new Atom(
"O"));
2820 IAtomContainer iac23 = builder.newAtomContainer();
2821 iac23.addAtom(
new Atom(
"H"));
2825 IAtomContainer iac24 = builder.newAtomContainer();
2826 iac24.addAtom(
new Atom(
"H"));
2839 "#vertices in graph before removal (B)");
2846 "#vertices in graph before removal (B)");
2848 "Capping is still contained (B)");
2850 "Capping is still contained (C)");
2852 "Owner of removed capping group is null (B)");
2854 "Owner of removed capping group is null (C)");
2862 for (
int atomPos = 0; atomPos < apCount; atomPos++) {
2907 Arrays.asList(v5, v4, v0, v1, v2, v3))));
2910 Arrays.asList(v6, v0, v4, v7))));
2922 String json1 = graph.
toJson();
2925 String json2 = g2.
toJson();
2927 assertTrue(json1.equals(json2),
"Round-trip via JSON is successful");
2941 "self isomorphism on empty graph");
2943 "isomorphism on empty graphs");
2948 "single-vertex graph");
2950 "single-vertex graph vs clone");
2969 "graph with empty vertexes and same properties");
2973 "graph with empty vertexes and different properties");
2983 assertFalse(gD1.
isIsomorphicTo(gAempty),
"graph D vs empty graph");
2984 assertFalse(gAempty.
isIsomorphicTo(gD1),
"empty graph vs graph D");
3007 "Original stays the same");
3016 "SymmetricSets in subGraph1");
3017 assertEquals(1,subGraph1.
getRingCount(),
"Rings in subGraph1");
3019 "Original stays the same");
3028 "SymmetricSets in subGraph2");
3029 assertEquals(0,subGraph2.
getRingCount(),
"Rings in subGraph2");
3031 "Original stays the same");
3042 Set<Vertex> targetVertexes =
new HashSet<>();
3049 for (
Vertex vInTarget : targetVertexes)
3054 Set<Edge> connectionToSubgraph =
new HashSet<Edge>();
3055 Set<Edge> connectionFromSubgraph =
new HashSet<Edge>();
3057 connectionToSubgraph, connectionFromSubgraph);
3059 assertEquals(1, connectionToSubgraph.size());
3060 assertEquals(3, connectionFromSubgraph.size());
3065 boolean found0 =
false;
3066 for (
Edge e : connectionToSubgraph)
3068 Vertex inResults = e.getSrcAP().getOwner();
3074 boolean found2 =
false;
3075 boolean found4 =
false;
3076 boolean found6 =
false;
3077 for (
Edge e : connectionFromSubgraph)
3079 Vertex inResults = e.getTrgAP().getOwner();
3099 List<VertexQuery> allQueries =
new ArrayList<VertexQuery>();
3100 List<List<Vertex>> allExpected =
3101 new ArrayList<List<Vertex>>();
3104 List<Vertex> e0 =
new ArrayList<Vertex>();
3107 allExpected.add(e0);
3111 null,
null,
null,
null,
null,
null);
3112 List<Vertex> e1 =
new ArrayList<Vertex>();
3115 allExpected.add(e1);
3119 null,
null,
null,
null,
null,
null);
3120 List<Vertex> e2 =
new ArrayList<Vertex>();
3123 allExpected.add(e2);
3126 null,
null,
null,
null,
null);
3127 List<Vertex> e3 =
new ArrayList<Vertex>();
3132 allExpected.add(e3);
3135 null,
null,
null,
null);
3136 List<Vertex> e4 =
new ArrayList<Vertex>();
3140 allExpected.add(e4);
3144 List<Vertex> e5 =
new ArrayList<Vertex>();
3147 allExpected.add(e5);
3151 List<Vertex> e6 =
new ArrayList<Vertex>();
3155 allExpected.add(e6);
3164 List<Vertex> e7 =
new ArrayList<Vertex>();
3167 allExpected.add(e7);
3170 null,
null,
null,
null,
null,
null);
3173 List<Vertex> e8 =
new ArrayList<Vertex>();
3176 allExpected.add(e8);
3183 null,
null,
null,
null,
null);
3186 List<Vertex> e9 =
new ArrayList<Vertex>();
3189 allExpected.add(e9);
3194 List<Vertex> e10 =
new ArrayList<Vertex>();
3197 allQueries.add(q10);
3198 allExpected.add(e10);
3203 List<Vertex> e11 =
new ArrayList<Vertex>();
3209 allQueries.add(q11);
3210 allExpected.add(e11);
3216 List<Vertex> e12 =
new ArrayList<Vertex>();
3219 allQueries.add(q12);
3220 allExpected.add(e12);
3226 List<Vertex> e13 =
new ArrayList<Vertex>();
3230 allQueries.add(q13);
3231 allExpected.add(e13);
3237 List<Vertex> e14 =
new ArrayList<Vertex>();
3240 allQueries.add(q14);
3241 allExpected.add(e14);
3251 null,
null,
null,
null,
null,
null);
3254 List<Vertex> e15 =
new ArrayList<Vertex>();
3256 allQueries.add(q15);
3257 allExpected.add(e15);
3261 null,
null,
null,
null,
null);
3264 List<Vertex> e16 =
new ArrayList<Vertex>();
3266 allQueries.add(q16);
3267 allExpected.add(e16);
3272 List<Vertex> e17 =
new ArrayList<Vertex>();
3275 allQueries.add(q17);
3276 allExpected.add(e17);
3281 List<Vertex> e18 =
new ArrayList<Vertex>();
3285 allQueries.add(q18);
3286 allExpected.add(e18);
3292 List<Vertex> e19 =
new ArrayList<Vertex>();
3295 allQueries.add(q19);
3296 allExpected.add(e19);
3302 List<Vertex> e20 =
new ArrayList<Vertex>();
3305 allQueries.add(q20);
3306 allExpected.add(e20);
3312 List<Vertex> e21 =
new ArrayList<Vertex>();
3315 allQueries.add(q21);
3316 allExpected.add(e21);
3326 List<Vertex> e22 =
new ArrayList<Vertex>();
3328 allQueries.add(q22);
3329 allExpected.add(e22);
3334 null,
null,
null, eq23,
null);
3335 List<Vertex> e23 =
new ArrayList<Vertex>();
3337 allQueries.add(q23);
3338 allExpected.add(e23);
3340 for (
int i=0; i<allQueries.size(); i++)
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+
")");
3362 Map<Object,Integer> countsPerLabel =
new HashMap<Object,Integer>();
3366 if (countsPerLabel.containsKey(label))
3367 countsPerLabel.put(label,countsPerLabel.get(label)+1);
3369 countsPerLabel.put(label,1);
3403 boolean foundA =
false;
3404 boolean foundB =
false;
3406 while (iter.hasNext())
3414 assertTrue(foundA,
"Found 2-membered set");
3415 assertTrue(foundB,
"Found 4-membered set");
3427 while (iter2.hasNext())
3430 assertEquals(2,ss.size(),
"side of each symmetric sets.");
3441 List<Vertex> sg =
new ArrayList<Vertex>();
3447 assertEquals(2,symSubGraphs.size(),
"Number of subgraphs");
3449 symSubGraphs.get(0).get(0).getVertexId());
3451 symSubGraphs.get(0).get(1).getVertexId());
3453 symSubGraphs.get(1).get(0).getVertexId());
3455 symSubGraphs.get(1).get(1).getVertexId());
3459 List<Vertex> sg2 =
new ArrayList<Vertex>();
3468 boolean exceptionWhenCappingIsIncluded =
false;
3474 if (e.getMessage().contains(
"Capping groups must not be part of "
3475 +
"symmetric subgraphs"))
3476 exceptionWhenCappingIsIncluded =
true;
3478 assertTrue(exceptionWhenCappingIsIncluded,
3479 "Capping groups trigger exception");
3481 sg2 =
new ArrayList<Vertex>();
3485 assertEquals(2,symSubGraphs.size());
3486 assertEquals(2,symSubGraphs.get(0).size());
3487 assertEquals(2,symSubGraphs.get(1).size());
3498 List<Vertex> childTree =
new ArrayList<Vertex>();
3500 assertEquals(6,childTree.size());
3508 childTree =
new ArrayList<Vertex>();
3510 assertEquals(1,childTree.size());
3513 childTree =
new ArrayList<Vertex>();
3515 assertEquals(4,childTree.size());
3521 childTree =
new ArrayList<Vertex>();
3524 assertEquals(3,childTree.size());
3542 List<Vertex> childTree =
new ArrayList<Vertex>();
3544 new AtomicInteger(0),
new ArrayList<Integer>());
3583 List<Vertex> subGraph =
new ArrayList<Vertex>();
3587 List<AttachmentPoint> expected =
new ArrayList<AttachmentPoint>();
3593 assertEquals(expected,interfaceAPs);
3598 subGraph =
new ArrayList<Vertex>();
3602 expected =
new ArrayList<AttachmentPoint>();
3610 assertEquals(expected,interfaceAPs);
3624 List<Vertex> subGraph =
new ArrayList<Vertex>();
3628 List<AttachmentPoint>expected =
new ArrayList<AttachmentPoint>();
3638 assertEquals(expected,interfaceAPs);
3645 String unqProp =
"UNQPROP";
3771 LinkedHashMap<AttachmentPoint,AttachmentPoint> apMap =
3772 new LinkedHashMap<AttachmentPoint,AttachmentPoint>();
3776 List<Vertex> toReplace =
new ArrayList<Vertex>();
3790 incomingSubGraph =
new DGraph();
3792 apMap =
new LinkedHashMap<AttachmentPoint,AttachmentPoint>();
3795 toReplace =
new ArrayList<Vertex>();
3820 assertEquals(2, egdesFrom.size());
3822 egdesFrom.get(0).getTrgAP().getOwner());
3824 egdesFrom.get(1).getTrgAP().getOwner());
3827 assertEquals(1, egdesTo.size());
3829 egdesTo.get(0).getSrcAP().getOwner());
3848 .filter(v -> v instanceof
Template)
3849 .collect(Collectors.toList());
3850 assertEquals(2, templates.size());
3851 assertEquals(1, templates.stream()
3854 assertEquals(1, templates.stream()
3954 Set<Vertex> alreadyAssignedVrtxs =
new HashSet<Vertex>();
3958 Map<SymmetricAPs,List<Vertex>> symChildenSetsOnSymToVrtxs =
3960 alreadyAssignedVrtxs);
3962 Set<SymmetricAPs> keysToRemove =
new HashSet<SymmetricAPs>();
3964 symChildenSetsOnSymToVrtxs.entrySet())
3966 if (e.getValue().size()<2)
3967 keysToRemove.add(e.getKey());
3970 symChildenSetsOnSymToVrtxs.remove(key);
3972 assertEquals(1, symChildenSetsOnSymToVrtxs.size());
3974 List<Vertex> foundVrtxs = symChildenSetsOnSymToVrtxs.get(
3977 assertEquals(3, foundVrtxs.size());
3978 List<Vertex> expected =
new ArrayList<Vertex>();
3982 for (
Vertex foundVrts : foundVrtxs)
3983 assertTrue(expected.contains(foundVrts));
3988 alreadyAssignedVrtxs =
new HashSet<Vertex>();
3990 focusVrtx, alreadyAssignedVrtxs);
3992 keysToRemove =
new HashSet<SymmetricAPs>();
3994 symChildenSetsOnSymToVrtxs.entrySet())
3996 if (e.getValue().size()<2)
3997 keysToRemove.add(e.getKey());
4000 symChildenSetsOnSymToVrtxs.remove(key);
4002 assertEquals(2, symChildenSetsOnSymToVrtxs.size());
4004 foundVrtxs = symChildenSetsOnSymToVrtxs.get(
4007 assertEquals(2, foundVrtxs.size());
4008 expected =
new ArrayList<Vertex>();
4011 for (
Vertex foundVrts : foundVrtxs)
4012 assertTrue(expected.contains(foundVrts));
4014 foundVrtxs = symChildenSetsOnSymToVrtxs.get(
4017 assertEquals(2, foundVrtxs.size());
4018 expected =
new ArrayList<Vertex>();
4021 for (
Vertex foundVrts : foundVrtxs)
4022 assertTrue(expected.contains(foundVrts));
4182 assertEquals(0, symVrtxs.size());
4185 assertEquals(2, symVrtxs.size());
4190 assertEquals(6, symVrtxs.size());
4199 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.
Map< SymmetricAPs, List< Vertex > > findSymmetrySetsOfChildVertexes(Vertex vrtx, Set< Vertex > alreadyAssignedVrtxs)
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()
Tries to determine the set of symmetric vertices in this graph based on finding compatible Vertexes t...
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 testFindSymmetrySetsOfChildVertexes()
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)
abstract List< SymmetricAPs > getSymmetricAPSets()
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...