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++)
1330 HashMap<APClass,ArrayList<APClass>> cpMap =
1331 new HashMap<APClass,ArrayList<APClass>>();
1332 cpMap.put(a0,
new ArrayList<APClass>(Arrays.asList(a0, b0)));
1333 HashMap<APClass,APClass> capMap =
new HashMap<APClass,APClass>();
1335 HashSet<APClass> forbEnds =
new HashSet<APClass>();
1339 IAtom a1 =
new Atom(
"C",
new Point3d(
new double[]{0.0, 0.0, 0.0}));
1340 IAtom a2 =
new Atom(
"C",
new Point3d(
new double[]{1.0, 0.0, 0.0}));
1343 frg1.
addBond(
new Bond(a1, a2));
1344 frg1.
addAP(0, a0,
new Point3d(
new double[]{0.0, 0.0, 1.0}));
1345 frg1.
addAP(1, a0,
new Point3d(
new double[]{1.0, 1.0, 1.0}));
1349 IAtom a3 =
new Atom(
"C",
new Point3d(
new double[]{0.0, 0.0, 0.0}));
1351 frg2.
addAP(0, a0,
new Point3d(
new double[]{0.0, 1.0, 1.0}));
1352 frg2.
addAP(0, b0,
new Point3d(
new double[]{0.0, 1.0, -1.0}));
1356 IAtom a4 =
new PseudoAtom(
"ATP",
new Point3d(
1357 new double[]{0.0, 0.0, 0.0}));
1359 rca1.
addAP(0, ap0,
new Point3d(
new double[]{0.0, 1.0, 1.0}));
1363 IAtom a5 =
new PseudoAtom(
"ATM",
new Point3d(
1364 new double[]{1.0, 0.0, 0.0}));
1366 rca2.
addAP(0, am0,
new Point3d(
new double[]{0.0, 1.0, 1.0}));
1370 IAtom a6 =
new Atom(
"H",
new Point3d(
new double[]{0.0, 0.0, 0.0}));
1372 cap.addAP(0, h0,
new Point3d(
new double[]{0.0, 1.0, 1.0}));
1373 cap.projectAPsToProperties();
1375 ArrayList<Vertex> scaff =
new ArrayList<Vertex>();
1377 ArrayList<Vertex> frags =
new ArrayList<Vertex>();
1381 ArrayList<Vertex> caps =
new ArrayList<Vertex>();
1386 cpMap, capMap, forbEnds, cpMap);
1411 "Number of vertexes after removal of 0 unused RCVs.");
1413 "Number of edges after removal of 0 unused RCVs.");
1435 "Number of RCVs after removal of 2 unused RCVs.");
1437 "Number of vertexes after removal of 2 unused RCVs.");
1439 "Number of edges after removal of 2 unused RCVs.");
1450 List<Template> expected =
new ArrayList<Template>();
1451 DGraph refToThisLayerGraph = gOut;
1452 Template refToThisLayerVrtx =
null;
1453 for (
int embeddingLevel=0; embeddingLevel<10; embeddingLevel++)
1455 refToThisLayerVrtx = (
Template) refToThisLayerGraph
1456 .getVertexList().stream()
1457 .filter(v -> v instanceof
Template)
1460 expected.add(refToThisLayerVrtx);
1465 "Embedding path of graph that is not embedded");
1467 assertEquals(expected, path,
"Path of deepest embedded graph");
1481 List<Template> expectedPathA =
new ArrayList<Template>();
1482 List<Template> expectedPathB =
new ArrayList<Template>();
1483 DGraph refToThisLayerGraphB = gB;
1484 Template refToThisLayerVrtxB =
null;
1485 DGraph refToThisLayerGraphA = gA;
1486 Template refToThisLayerVrtxA =
null;
1487 for (
int embeddingLevel=0; embeddingLevel<9; embeddingLevel++)
1489 refToThisLayerVrtxA = (
Template) refToThisLayerGraphA
1490 .getVertexList().stream()
1491 .filter(v -> v instanceof
Template)
1494 expectedPathA.add(refToThisLayerVrtxA);
1497 refToThisLayerVrtxB = (
Template) refToThisLayerGraphB
1498 .getVertexList().stream()
1499 .filter(v -> v instanceof
Template)
1502 expectedPathB.add(refToThisLayerVrtxB);
1506 DGraph expectedEmbeddedA = expectedPathA.get(8).getInnerGraph();
1507 DGraph expectedEmbeddedB = expectedPathB.get(8).getInnerGraph();
1512 assertEquals(expectedEmbeddedB,embeddedFoundB);
1515 assertEquals(expectedPathB,pathFoundB);
1519 assertEquals(expectedEmbeddedA,embeddedFoundA);
1522 assertEquals(expectedPathA,pathFoundA);
1534 "Inconsistent source vertex");
1539 "Inconsistent source vertex");
1549 int[] expected =
new int[] {2,3,0,1,-1};
1553 "Wrong level for vertex at position "+i);
1557 expected =
new int[] {-1,0,1,2,3,2,0,1,2,3,2};
1561 "Bis: Wrong level for vertex at position "+i);
1575 LinkedHashMap<Integer, Integer> apMap =
1576 new LinkedHashMap<Integer,Integer>();
1585 boolean res = g.
replaceVertex(v1, chosenBBId, choosenBBTyp, apMap, fs);
1587 assertTrue(res,
"ReplaceVertex return value.");
1589 int numVertexesWithGoodBBId = 0;
1590 int numEdgesWithS = 0;
1591 int numEdgesWith2 = 0;
1592 int numEdgesWith3 = 0;
1598 numVertexesWithGoodBBId++;
1602 if (!ap.isAvailable())
1604 Vertex nextVrtx = ap.getLinkedAP().getOwner();
1623 assertEquals(2,numVertexesWithGoodBBId,
"Number of new links.");
1624 assertEquals(2,numEdgesWithS,
"Number of new edges with scaffold.");
1625 assertEquals(4,numEdgesWith2,
"Number of new edges with v2a/b.");
1626 assertEquals(2,numEdgesWith3,
"Number of new edges with v3a/b.");
1640 Set<Long> oldVertexIds =
new HashSet<Long>();
1644 LinkedHashMap<Integer,Integer> apMap2 =
1645 new LinkedHashMap<Integer,Integer>();
1648 int chosenBBId2 = 5;
1651 boolean res2 = g2.
replaceVertex(v2, chosenBBId2, choosenBBTyp2, apMap2,
1654 assertTrue(res2,
"ReplaceVertex return value (2).");
1656 int numVertexesWithGoodBBId2 = 0;
1657 int numEdgesWith1 = 0;
1663 numVertexesWithGoodBBId2++;
1667 if (!ap.isAvailable())
1669 Vertex nextVrtx = ap.getLinkedAP().getOwner();
1676 assertEquals(4,numVertexesWithGoodBBId2,
"Number of new links.");
1677 assertEquals(4,numEdgesWith1,
"Number of new edges with scaffold.");
1679 boolean found =
false;
1680 boolean foundOldVertexId =
false;
1682 while (iterSS.hasNext())
1685 if (ss.size() == origSS.size())
1691 foundOldVertexId =
true;
1695 assertTrue(found,
"could not find old symmetric set");
1696 assertFalse(foundOldVertexId,
"found old vertex id in new symmetric set");
1709 LinkedHashMap<Integer, Integer> apMap =
1710 new LinkedHashMap<Integer,Integer>();
1732 List<Vertex> vrtxsToReplace =
new ArrayList<Vertex>();
1738 LinkedHashMap<AttachmentPoint, AttachmentPoint> apMap =
1739 new LinkedHashMap<AttachmentPoint,AttachmentPoint>();
1760 "graph's surce vertex");
1764 assertEquals(3,pathA.
getEdgesPath().size(),
"path within a ring (A)");
1767 assertEquals(5,pathB.
getEdgesPath().size(),
"path within a ring (B)");
1770 assertEquals(4,pathC.
getEdgesPath().size(),
"path within a ring (C)");
1773 assertTrue(g.
isIsomorphicTo(expected),
"isomforphic to expected");
1787 List<Vertex> vrtxsToReplace =
new ArrayList<Vertex>();
1792 LinkedHashMap<AttachmentPoint, AttachmentPoint> apMap =
1793 new LinkedHashMap<AttachmentPoint,AttachmentPoint>();
1795 apMap.put(vrtxsToReplace.get(0).getAP(3),
1797 apMap.put(vrtxsToReplace.get(0).getAP(4),
1800 apMap.put(vrtxsToReplace.get(0).getAP(0),
1802 apMap.put(vrtxsToReplace.get(0).getAP(1),
1806 incomingSubGraph, apMap);
1810 assertEquals(1,g.
getRingCount(),
"Rings in outer graph");
1814 "Distance Head-Tail in ring of outer graph");
1819 "Vertex in inner graph");
1821 "Rings in inner graph");
1823 "Free APs inner graph");
1826 "Distance Head-Tail in ring of inner graph");
1866 Arrays.asList(v5, v4, v0, v1, v2, v3))));
1869 Arrays.asList(v6, v0, v4, v7))));
1903 assertEquals(numVa, numV - 1);
1904 assertEquals(numEa, numE - 1);
1905 assertEquals(numSa, numS - 1);
1906 assertEquals(numRa, numR - 1);
1915 assertEquals(numVb, numVa - 1);
1916 assertEquals(numEb, numEa - 1);
1917 assertEquals(numSb, numSa);
1918 assertEquals(numRb, numRa);
1927 assertEquals(numVc, numVb - 1);
1928 assertEquals(numEc, numEb - 2);
1929 assertEquals(numSc, numSb);
1930 assertEquals(numRc, numRb - 1);
1965 StringBuilder reason =
new StringBuilder();
1966 assertTrue(graphA.
sameAs(graphB, reason), reason.toString());
2000 StringBuilder reason =
new StringBuilder();
2001 assertFalse(graphA.
sameAs(graphB, reason));
2074 StringBuilder reason =
new StringBuilder();
2075 assertTrue(graphA.
sameAs(graphB, reason));
2142 StringBuilder reason =
new StringBuilder();
2143 assertFalse(graphA.
sameAs(graphB, reason));
2171 ArrayList<Vertex> vrA =
new ArrayList<Vertex>();
2177 ArrayList<Vertex> vrA2 =
new ArrayList<Vertex>();
2207 ArrayList<Vertex> vrB =
new ArrayList<Vertex>();
2213 ArrayList<Vertex> vrB2 =
new ArrayList<Vertex>();
2220 StringBuilder reason =
new StringBuilder();
2221 assertTrue(graphA.
sameAs(graphB, reason));
2249 ArrayList<Vertex> vrA =
new ArrayList<>();
2255 ArrayList<Vertex> vrA2 =
new ArrayList<>();
2285 ArrayList<Vertex> vrB =
new ArrayList<>();
2291 ArrayList<Vertex> vrB2 =
new ArrayList<>();
2298 StringBuilder reason =
new StringBuilder();
2299 assertTrue(graphA.
sameAs(graphB, reason));
2327 ArrayList<Vertex> vrA =
new ArrayList<>();
2333 ArrayList<Vertex> vrA2 =
new ArrayList<>();
2361 ArrayList<Vertex> vrB =
new ArrayList<>();
2367 ArrayList<Vertex> vrB2 =
new ArrayList<>();
2374 StringBuilder reason =
new StringBuilder();
2375 assertFalse(graphA.
sameAs(graphB, reason));
2400 assertEquals(1,lst.size(),
"Size of list");
2401 assertEquals(vertex0.
getVertexId(),lst.get(0).getOwner().getVertexId(),
2402 "ID of the vertex holding the available AP.");
2442 Arrays.asList(v5, v4, v0, v1, v2, v3))));
2445 Arrays.asList(v6, v0, v4, v7))));
2460 "Number of vertices");
2466 "Number of symmetric sets");
2468 "Number of closable chains");
2478 int hashVG = vg.hashCode();
2479 int hashVC = vc.hashCode();
2484 "Reference to vertex owner in ap " + iap +
" vertex "
2487 "Reference to vertex owner in ap " + iap +
" vertex "
2491 "Owner of AP "+iap+
" in vertex "+iv);
2507 "Size of mutation list in case of frozen template");
2514 "Size of mutation list in case of free template");
2518 "No sites if all is ignored");
2585 IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
2586 IAtomContainer iac1 = builder.newAtomContainer();
2587 IAtom ia1 =
new Atom(
"C");
2588 IAtom ia2 =
new Atom(
"C");
2591 iac1.addBond(
new Bond(ia1, ia2, IBond.Order.SINGLE));
2599 IAtomContainer iac2 = builder.newAtomContainer();
2600 iac2.addAtom(
new Atom(
"O"));
2605 IAtomContainer iac3 = builder.newAtomContainer();
2606 iac3.addAtom(
new Atom(
"H"));
2611 IAtomContainer iac4 = builder.newAtomContainer();
2612 iac4.addAtom(
new Atom(
"H"));
2632 }
catch (Throwable t)
2634 t.printStackTrace();
2635 System.err.println(
"FATAL ERROR! Could not make test graph (A). "
2636 +
"Please, report this to the development team.");
2674 IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
2675 IAtomContainer iac1 = builder.newAtomContainer();
2676 IAtom ia1 =
new Atom(
"C");
2677 IAtom ia2 =
new Atom(
"C");
2680 iac1.addBond(
new Bond(ia1, ia2, IBond.Order.SINGLE));
2689 IAtomContainer iac2 = builder.newAtomContainer();
2690 iac2.addAtom(
new Atom(
"O"));
2696 IAtomContainer iac3 = builder.newAtomContainer();
2697 iac3.addAtom(
new Atom(
"H"));
2702 IAtomContainer iac4 = builder.newAtomContainer();
2703 iac4.addAtom(
new Atom(
"H"));
2745 }
catch (Throwable t)
2747 t.printStackTrace();
2748 System.err.println(
"FATAL ERROR! Could not make test graph (A). "
2749 +
"Please, report this to the development team.");
2763 IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
2764 IAtomContainer iac1 = builder.newAtomContainer();
2765 iac1.addAtom(
new Atom(
"C"));
2770 IAtomContainer iac2 = builder.newAtomContainer();
2771 iac2.addAtom(
new Atom(
"O"));
2776 IAtomContainer iac3 = builder.newAtomContainer();
2777 iac3.addAtom(
new Atom(
"H"));
2781 IAtomContainer iac4 = builder.newAtomContainer();
2782 iac4.addAtom(
new Atom(
"H"));
2795 "#vertices in graph before removal");
2801 "#vertices in graph before removal");
2803 "Capping is still contained");
2805 "Owner of removed capping group is null");
2809 IAtomContainer iac12 = builder.newAtomContainer();
2810 iac12.addAtom(
new Atom(
"C"));
2815 IAtomContainer iac22 = builder.newAtomContainer();
2816 iac22.addAtom(
new Atom(
"O"));
2821 IAtomContainer iac23 = builder.newAtomContainer();
2822 iac23.addAtom(
new Atom(
"H"));
2826 IAtomContainer iac24 = builder.newAtomContainer();
2827 iac24.addAtom(
new Atom(
"H"));
2840 "#vertices in graph before removal (B)");
2847 "#vertices in graph before removal (B)");
2849 "Capping is still contained (B)");
2851 "Capping is still contained (C)");
2853 "Owner of removed capping group is null (B)");
2855 "Owner of removed capping group is null (C)");
2863 for (
int atomPos = 0; atomPos < apCount; atomPos++) {
2908 Arrays.asList(v5, v4, v0, v1, v2, v3))));
2911 Arrays.asList(v6, v0, v4, v7))));
2923 String json1 = graph.
toJson();
2926 String json2 = g2.
toJson();
2928 assertTrue(json1.equals(json2),
"Round-trip via JSON is successful");
2942 "self isomorphism on empty graph");
2944 "isomorphism on empty graphs");
2949 "single-vertex graph");
2951 "single-vertex graph vs clone");
2970 "graph with empty vertexes and same properties");
2974 "graph with empty vertexes and different properties");
2984 assertFalse(gD1.
isIsomorphicTo(gAempty),
"graph D vs empty graph");
2985 assertFalse(gAempty.
isIsomorphicTo(gD1),
"empty graph vs graph D");
3008 "Original stays the same");
3017 "SymmetricSets in subGraph1");
3018 assertEquals(1,subGraph1.
getRingCount(),
"Rings in subGraph1");
3020 "Original stays the same");
3029 "SymmetricSets in subGraph2");
3030 assertEquals(0,subGraph2.
getRingCount(),
"Rings in subGraph2");
3032 "Original stays the same");
3043 Set<Vertex> targetVertexes =
new HashSet<>();
3050 for (
Vertex vInTarget : targetVertexes)
3055 Set<Edge> connectionToSubgraph =
new HashSet<Edge>();
3056 Set<Edge> connectionFromSubgraph =
new HashSet<Edge>();
3058 connectionToSubgraph, connectionFromSubgraph);
3060 assertEquals(1, connectionToSubgraph.size());
3061 assertEquals(3, connectionFromSubgraph.size());
3066 boolean found0 =
false;
3067 for (
Edge e : connectionToSubgraph)
3069 Vertex inResults = e.getSrcAP().getOwner();
3075 boolean found2 =
false;
3076 boolean found4 =
false;
3077 boolean found6 =
false;
3078 for (
Edge e : connectionFromSubgraph)
3080 Vertex inResults = e.getTrgAP().getOwner();
3100 List<VertexQuery> allQueries =
new ArrayList<VertexQuery>();
3101 List<List<Vertex>> allExpected =
3102 new ArrayList<List<Vertex>>();
3105 List<Vertex> e0 =
new ArrayList<Vertex>();
3108 allExpected.add(e0);
3112 null,
null,
null,
null,
null,
null);
3113 List<Vertex> e1 =
new ArrayList<Vertex>();
3116 allExpected.add(e1);
3120 null,
null,
null,
null,
null,
null);
3121 List<Vertex> e2 =
new ArrayList<Vertex>();
3124 allExpected.add(e2);
3127 null,
null,
null,
null,
null);
3128 List<Vertex> e3 =
new ArrayList<Vertex>();
3133 allExpected.add(e3);
3136 null,
null,
null,
null);
3137 List<Vertex> e4 =
new ArrayList<Vertex>();
3141 allExpected.add(e4);
3145 List<Vertex> e5 =
new ArrayList<Vertex>();
3148 allExpected.add(e5);
3152 List<Vertex> e6 =
new ArrayList<Vertex>();
3156 allExpected.add(e6);
3165 List<Vertex> e7 =
new ArrayList<Vertex>();
3168 allExpected.add(e7);
3171 null,
null,
null,
null,
null,
null);
3174 List<Vertex> e8 =
new ArrayList<Vertex>();
3177 allExpected.add(e8);
3184 null,
null,
null,
null,
null);
3187 List<Vertex> e9 =
new ArrayList<Vertex>();
3190 allExpected.add(e9);
3195 List<Vertex> e10 =
new ArrayList<Vertex>();
3198 allQueries.add(q10);
3199 allExpected.add(e10);
3204 List<Vertex> e11 =
new ArrayList<Vertex>();
3210 allQueries.add(q11);
3211 allExpected.add(e11);
3217 List<Vertex> e12 =
new ArrayList<Vertex>();
3220 allQueries.add(q12);
3221 allExpected.add(e12);
3227 List<Vertex> e13 =
new ArrayList<Vertex>();
3231 allQueries.add(q13);
3232 allExpected.add(e13);
3238 List<Vertex> e14 =
new ArrayList<Vertex>();
3241 allQueries.add(q14);
3242 allExpected.add(e14);
3252 null,
null,
null,
null,
null,
null);
3255 List<Vertex> e15 =
new ArrayList<Vertex>();
3257 allQueries.add(q15);
3258 allExpected.add(e15);
3262 null,
null,
null,
null,
null);
3265 List<Vertex> e16 =
new ArrayList<Vertex>();
3267 allQueries.add(q16);
3268 allExpected.add(e16);
3273 List<Vertex> e17 =
new ArrayList<Vertex>();
3276 allQueries.add(q17);
3277 allExpected.add(e17);
3282 List<Vertex> e18 =
new ArrayList<Vertex>();
3286 allQueries.add(q18);
3287 allExpected.add(e18);
3293 List<Vertex> e19 =
new ArrayList<Vertex>();
3296 allQueries.add(q19);
3297 allExpected.add(e19);
3303 List<Vertex> e20 =
new ArrayList<Vertex>();
3306 allQueries.add(q20);
3307 allExpected.add(e20);
3313 List<Vertex> e21 =
new ArrayList<Vertex>();
3316 allQueries.add(q21);
3317 allExpected.add(e21);
3327 List<Vertex> e22 =
new ArrayList<Vertex>();
3329 allQueries.add(q22);
3330 allExpected.add(e22);
3335 null,
null,
null, eq23,
null);
3336 List<Vertex> e23 =
new ArrayList<Vertex>();
3338 allQueries.add(q23);
3339 allExpected.add(e23);
3341 for (
int i=0; i<allQueries.size(); i++)
3343 List<Vertex> matches = g.
findVertices(allQueries.get(i),
3344 Logger.getLogger(
"DummyLogger"));
3345 assertEquals(allExpected.get(i).size(),matches.size(),
3346 "Different number of matched vertexes ("+i+
")");
3347 assertTrue(allExpected.get(i).containsAll(matches),
3348 "Inconsistent matches ("+i+
")");
3363 Map<Object,Integer> countsPerLabel =
new HashMap<Object,Integer>();
3367 if (countsPerLabel.containsKey(label))
3368 countsPerLabel.put(label,countsPerLabel.get(label)+1);
3370 countsPerLabel.put(label,1);
3404 boolean foundA =
false;
3405 boolean foundB =
false;
3407 while (iter.hasNext())
3415 assertTrue(foundA,
"Found 2-membered set");
3416 assertTrue(foundB,
"Found 4-membered set");
3428 while (iter2.hasNext())
3431 assertEquals(2,ss.size(),
"side of each symmetric sets.");
3442 List<Vertex> sg =
new ArrayList<Vertex>();
3448 assertEquals(2,symSubGraphs.size(),
"Number of subgraphs");
3450 symSubGraphs.get(0).get(0).getVertexId());
3452 symSubGraphs.get(0).get(1).getVertexId());
3454 symSubGraphs.get(1).get(0).getVertexId());
3456 symSubGraphs.get(1).get(1).getVertexId());
3460 List<Vertex> sg2 =
new ArrayList<Vertex>();
3469 boolean exceptionWhenCappingIsIncluded =
false;
3475 if (e.getMessage().contains(
"Capping groups must not be part of "
3476 +
"symmetric subgraphs"))
3477 exceptionWhenCappingIsIncluded =
true;
3479 assertTrue(exceptionWhenCappingIsIncluded,
3480 "Capping groups trigger exception");
3482 sg2 =
new ArrayList<Vertex>();
3486 assertEquals(2,symSubGraphs.size());
3487 assertEquals(2,symSubGraphs.get(0).size());
3488 assertEquals(2,symSubGraphs.get(1).size());
3499 List<Vertex> childTree =
new ArrayList<Vertex>();
3501 assertEquals(6,childTree.size());
3509 childTree =
new ArrayList<Vertex>();
3511 assertEquals(1,childTree.size());
3514 childTree =
new ArrayList<Vertex>();
3516 assertEquals(4,childTree.size());
3522 childTree =
new ArrayList<Vertex>();
3525 assertEquals(3,childTree.size());
3543 List<Vertex> childTree =
new ArrayList<Vertex>();
3545 new AtomicInteger(0),
new ArrayList<Integer>());
3584 List<Vertex> subGraph =
new ArrayList<Vertex>();
3588 List<AttachmentPoint> expected =
new ArrayList<AttachmentPoint>();
3594 assertEquals(expected,interfaceAPs);
3599 subGraph =
new ArrayList<Vertex>();
3603 expected =
new ArrayList<AttachmentPoint>();
3611 assertEquals(expected,interfaceAPs);
3625 List<Vertex> subGraph =
new ArrayList<Vertex>();
3629 List<AttachmentPoint>expected =
new ArrayList<AttachmentPoint>();
3639 assertEquals(expected,interfaceAPs);
3646 String unqProp =
"UNQPROP";
3772 LinkedHashMap<AttachmentPoint,AttachmentPoint> apMap =
3773 new LinkedHashMap<AttachmentPoint,AttachmentPoint>();
3777 List<Vertex> toReplace =
new ArrayList<Vertex>();
3791 incomingSubGraph =
new DGraph();
3793 apMap =
new LinkedHashMap<AttachmentPoint,AttachmentPoint>();
3796 toReplace =
new ArrayList<Vertex>();
3821 assertEquals(2, egdesFrom.size());
3823 egdesFrom.get(0).getTrgAP().getOwner());
3825 egdesFrom.get(1).getTrgAP().getOwner());
3828 assertEquals(1, egdesTo.size());
3830 egdesTo.get(0).getSrcAP().getOwner());
3849 .filter(v -> v instanceof
Template)
3850 .collect(Collectors.toList());
3851 assertEquals(2, templates.size());
3852 assertEquals(1, templates.stream()
3855 assertEquals(1, templates.stream()
4040 assertEquals(0, symVrtxs.size());
4043 assertEquals(2, symVrtxs.size());
4048 assertEquals(6, symVrtxs.size());
4057 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...