$darkmode
DENOPTIM
EAUtilsTest.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2022 Marco Foscato <marco.foscato@uib.no>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package denoptim.ga;
20
21import static org.junit.jupiter.api.Assertions.assertEquals;
22import static org.junit.jupiter.api.Assertions.assertFalse;
23import static org.junit.jupiter.api.Assertions.assertNotNull;
24import static org.junit.jupiter.api.Assertions.assertTrue;
25
26import java.io.File;
27import java.util.ArrayList;
28import java.util.Arrays;
29import java.util.HashMap;
30import java.util.HashSet;
31import java.util.Iterator;
32import java.util.List;
33import java.util.stream.Collectors;
34
35import org.junit.jupiter.api.Test;
36import org.junit.jupiter.api.io.TempDir;
37import org.openscience.cdk.interfaces.IAtom;
38import org.openscience.cdk.interfaces.IAtomContainer;
39import org.openscience.cdk.interfaces.IChemObjectBuilder;
40import org.openscience.cdk.layout.StructureDiagramGenerator;
41import org.openscience.cdk.silent.SilentChemObjectBuilder;
42import org.openscience.cdk.smiles.SmilesParser;
43
44import denoptim.constants.DENOPTIMConstants;
45import denoptim.exception.DENOPTIMException;
46import denoptim.fragmenter.ScaffoldingPolicy;
47import denoptim.fragspace.FragmentSpace;
48import denoptim.fragspace.FragmentSpaceParameters;
49import denoptim.ga.EAUtils.CandidateSource;
50import denoptim.graph.APClass;
51import denoptim.graph.AttachmentPoint;
52import denoptim.graph.Candidate;
53import denoptim.graph.DGraph;
54import denoptim.graph.DGraphTest;
55import denoptim.graph.Edge.BondType;
56import denoptim.graph.EmptyVertex;
57import denoptim.graph.GraphPattern;
58import denoptim.graph.SymmetricVertexes;
59import denoptim.graph.Template;
60import denoptim.graph.Template.ContractLevel;
61import denoptim.graph.Vertex;
62import denoptim.graph.Vertex.BBType;
63import denoptim.io.DenoptimIO;
64import denoptim.logging.Monitor;
65import denoptim.programs.denovo.GAParameters;
66import denoptim.programs.fragmenter.CuttingRule;
67import denoptim.utils.MoleculeUtils;
68import denoptim.utils.Randomizer;
69
76public class EAUtilsTest
77{
78
79 private static APClass APCA, APCB, APCC;
80 private static String a="A", b="B", c="C";
81
82 private static final String SEP = System.getProperty("file.separator");
83 private static final String NL = System.getProperty("line.separator");
84
88 private IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
89
90 @TempDir
91 static File tempDir;
92
93//------------------------------------------------------------------------------
94
96 {
100
101 HashMap<APClass,ArrayList<APClass>> cpMap =
102 new HashMap<APClass,ArrayList<APClass>>();
103 ArrayList<APClass> lstA = new ArrayList<APClass>();
104 lstA.add(APCA);
105 cpMap.put(APCA, lstA);
106 ArrayList<APClass> lstB = new ArrayList<APClass>();
107 lstB.add(APCB);
108 lstB.add(APCC);
109 cpMap.put(APCB, lstB);
110 ArrayList<APClass> lstC = new ArrayList<APClass>();
111 lstC.add(APCB);
112 lstC.add(APCC);
113 cpMap.put(APCC, lstC);
114
115 /* Compatibility matrix
116 *
117 * | A | B | C |
118 * -------------------------
119 * A | T | | |
120 * -------------------------
121 * B | | T | T |
122 * -------------------------
123 * C | | T | T |
124 * -------------------------
125 */
126
127 HashMap<APClass,APClass> capMap = new HashMap<APClass,APClass>();
128 HashSet<APClass> forbEnds = new HashSet<APClass>();
129
131 FragmentSpace fs = new FragmentSpace(fsp,
132 new ArrayList<Vertex>(),
133 new ArrayList<Vertex>(),
134 new ArrayList<Vertex>(),
135 cpMap, capMap, forbEnds, cpMap);
137
138 EmptyVertex v1 = new EmptyVertex();
140 v1.addAP(APCB);
141 v1.addAP(APCB);
143
144 EmptyVertex v2 = new EmptyVertex();
146 v2.addAP(APCC);
147 v2.addAP(APCC);
149
150 EmptyVertex rcv = new EmptyVertex();
152 rcv.addAP(APCC);
153 rcv.setAsRCV(true);
155
156 DGraph graphForTemplate = new DGraph();
158 BBType.FRAGMENT, fs);
159 graphForTemplate.addVertex(vg1);
160 for (int i=1; i<6; i++)
161 {
163 BBType.FRAGMENT, fs);
164 Vertex vgi_1 = graphForTemplate.getVertexAtPosition(i-1);
165 graphForTemplate.appendVertexOnAP(vgi_1.getAP(1), vgi.getAP(0));
166 }
168 BBType.FRAGMENT, fs);
169 graphForTemplate.appendVertexOnAP(
170 graphForTemplate.getVertexAtPosition(5).getAP(1),rcv1.getAP(0));
172 BBType.FRAGMENT, fs);
173 graphForTemplate.appendVertexOnAP(
174 graphForTemplate.getVertexAtPosition(0).getAP(0),rcv2.getAP(0));
175 graphForTemplate.addRing(rcv1, rcv2);
176
177 Template template = new Template(BBType.SCAFFOLD);
178 template.setInnerGraph(graphForTemplate);
179 template.setContractLevel(ContractLevel.FIXED_STRUCT);
181 fs.getScaffoldLibrary());
182
183 return fsp;
184 }
185
186//------------------------------------------------------------------------------
187
188 @Test
189 public void testBuildGraphFromTemplateScaffold() throws Exception
190 {
192 GAParameters gaParams = new GAParameters();
193 gaParams.setParameters(fsp);
194 DGraph g = EAUtils.buildGraph(gaParams);
195
196 if (g == null)
197 assertTrue(false,"faild construction of graph");
198
200
201 //NB: we want to not allow access to the inner graph from outside the
202 // template, but this means we cannot easily explore the inner graph.
203 // Looking at the mutation sites is a dirty trick to get a look inside
204 // this template, that has contract level "free" (meaning that the
205 // content of the template can change).
206
207 boolean foundChange = false;
208 for (Vertex v : t.getMutationSites())
209 {
210 if (v.getBuildingBlockId() != 0)
211 foundChange = true;
212 }
213 assertTrue(foundChange,"The initial inner graph has changed.");
214 }
215
216//------------------------------------------------------------------------------
217
218 @Test
219 public void testAvoidRedundantXOver() throws Exception
220 {
221 DGraph g1 = new DGraph();
222 EmptyVertex s = new EmptyVertex();
223 s.addAP();
224 s.addAP();
226
227 EmptyVertex v = new EmptyVertex();
228 v.addAP();
230
231 g1.addVertex(s);
232 g1.appendVertexOnAP(s.getAP(0), v.getAP(0));
233
234 Candidate c1 = new Candidate(g1);
235
236 DGraph g2 = g1.clone();
237 Candidate c2 = new Candidate(g2);
238
240 GAParameters gaParams = new GAParameters();
241 gaParams.setParameters(fsp);
242
243 ArrayList<Candidate> eligibleParents = new ArrayList<Candidate>();
244 eligibleParents.add(c1);
245 eligibleParents.add(c2);
246 Population population = new Population(gaParams);
247 population.add(c1);
248 population.add(c2);
249 Monitor mnt = new Monitor();
250
251 Candidate offspring = EAUtils.buildCandidateByXOver(eligibleParents,
252 population, mnt, gaParams);
253
254 assertTrue(offspring==null, "Redundat xover is not done");
255 }
256
257//------------------------------------------------------------------------------
258
259 @Test
260 public void testBuildByXOver_SubGraph() throws Exception
261 {
263 Population population = new Population(gaparams);
264
265 /*
266 * -(A)v0(A)-(A)v1(A)-(A)v2(A)-(A)v3(B)-(B)v4(B)-(B)v5(B)-
267 */
269 Candidate cA = new Candidate("CA",gA);
270 cA.setFitness(1.23);
271 population.add(cA);
272
273 /*
274 * v0(B)-(B)v1(A)-(A)v2(B)-(B)v3(A)-(A)v4(B)-(B)v5
275 */
277 Candidate cE = new Candidate("CE",gE);
278 cE.setFitness(2.34);
279 population.add(cE);
280
281 ArrayList<Candidate> eligibleParents = new ArrayList<Candidate>();
282 eligibleParents.add(cA);
283 eligibleParents.add(cE);
284
285 Monitor mnt = new Monitor();
286
287 Candidate offspring0 = EAUtils.buildCandidateByXOver(eligibleParents,
288 population, mnt, new int[]{0,1}, 3, 0, gaparams);
289
290 Candidate offspring1 = EAUtils.buildCandidateByXOver(eligibleParents,
291 population, mnt, new int[]{0,1}, 3, 1, gaparams);
292
293 DGraph g0 = offspring0.getGraph();
294 assertEquals(4,g0.getVertexCount());
295 assertEquals(3,g0.getEdgeCount());
296 int maxLength = -1;
297 for (Vertex v : g0.getVertexList())
298 {
299 ArrayList<Vertex> childTree = new ArrayList<Vertex>();
300 g0.getChildrenTree(v, childTree);
301 if (childTree.size()>maxLength)
302 {
303 maxLength = childTree.size();
304 }
305 }
306 assertEquals(3,maxLength);
307
308 DGraph g1 = offspring1.getGraph();
309 assertEquals(8,g1.getVertexCount());
310 assertEquals(7,g1.getEdgeCount());
311 maxLength = -1;
312 for (Vertex v : g1.getVertexList())
313 {
314 ArrayList<Vertex> childTree = new ArrayList<Vertex>();
315 g1.getChildrenTree(v, childTree);
316 if (childTree.size()>maxLength)
317 {
318 maxLength = childTree.size();
319 }
320 }
321 assertEquals(7,maxLength);
322 }
323
324//------------------------------------------------------------------------------
325
336 @Test
337 public void testBuildByXOver_Embedded_Free() throws Exception
338 {
340 Population population = new Population(gaparams);
341
343 DGraph gA = pair[0];
344 DGraph gB = pair[1];
345 ((Template)gA.getVertexAtPosition(1)).setContractLevel(
347 ((Template)gB.getVertexAtPosition(1)).setContractLevel(
349
350 Candidate cA = new Candidate("CA",gA);
351 population.add(cA);
352
353 Candidate cB = new Candidate("CB",gB);
354 population.add(cB);
355
356 ArrayList<Candidate> eligibleParents = new ArrayList<Candidate>();
357 eligibleParents.add(cA);
358 eligibleParents.add(cB);
359
360 Monitor mnt = new Monitor();
361
362 Candidate offspring0 = EAUtils.buildCandidateByXOver(eligibleParents,
363 population, mnt, new int[]{0,1}, 8, 0, gaparams);
364
365 Candidate offspring1 = EAUtils.buildCandidateByXOver(eligibleParents,
366 population, mnt, new int[]{0,1}, 8, 1, gaparams);
367
368 DGraph g0xo = offspring0.getGraph();
369 DGraph g1xo = offspring1.getGraph();
370
372 DGraph expected0 = expectedPair[0];
373 DGraph expected1 = expectedPair[1];
374 ((Template)expected0.getVertexAtPosition(1)).setContractLevel(
376 ((Template)expected1.getVertexAtPosition(1)).setContractLevel(
378
379 assertTrue(expected0.sameAs(g0xo, new StringBuilder()));
380 assertTrue(expected1.sameAs(g1xo, new StringBuilder()));
381 }
382
383//------------------------------------------------------------------------------
384
395 @Test
396 public void testBuildByXOver_Embedded_FreeBackwards() throws Exception
397 {
399 Population population = new Population(gaparams);
400
402 DGraph gA = pair[0];
403 DGraph gB = pair[1];
404 ((Template)gA.getVertexAtPosition(1)).setContractLevel(
406 ((Template)gB.getVertexAtPosition(1)).setContractLevel(
408
409 Candidate cA = new Candidate("CA",gA);
410 population.add(cA);
411
412 Candidate cB = new Candidate("CB",gB);
413 population.add(cB);
414
415 ArrayList<Candidate> eligibleParents = new ArrayList<Candidate>();
416 eligibleParents.add(cA);
417 eligibleParents.add(cB);
418
419 Monitor mnt = new Monitor();
420
421 Candidate offspring0 = EAUtils.buildCandidateByXOver(eligibleParents,
422 population, mnt, new int[]{0,1}, 17, 0, gaparams);
423
424 Candidate offspring1 = EAUtils.buildCandidateByXOver(eligibleParents,
425 population, mnt, new int[]{0,1}, 17, 1, gaparams);
426
427 DGraph g0xo = offspring0.getGraph();
428 DGraph g1xo = offspring1.getGraph();
429
431 DGraph expected0 = expectedPair[0];
432 DGraph expected1 = expectedPair[1];
433 ((Template)expected0.getVertexAtPosition(1)).setContractLevel(
435 ((Template)expected1.getVertexAtPosition(1)).setContractLevel(
437
438 assertTrue(expected0.sameAs(g0xo, new StringBuilder()));
439 assertTrue(expected1.sameAs(g1xo, new StringBuilder()));
440 }
441
442//------------------------------------------------------------------------------
443
444 @Test
445 public void testBuildByXOver_Embedded_FixedStructure() throws Exception
446 {
448 Population population = new Population(gaparams);
449
451 DGraph gA = pair[0];
452 DGraph gB = pair[1];
453 Template embeddedTmplA = (Template) gA.getVertexAtPosition(1);
455 DGraph embeddedGraphA = embeddedTmplA.getInnerGraph();
456 Template embeddedTmplB = (Template) gB.getVertexAtPosition(1);
458 DGraph embeddedGraphB = embeddedTmplB.getInnerGraph();
459
460 // Make vertexes unique so, even though they are empty, they will be
461 // seen as non equal and crossover will be seen as non-redundant.
462 String propName = "uniquefier";
463 int i=0;
464 for (Vertex v : embeddedGraphA.getVertexList())
465 {
466 v.setUniquefyingProperty(propName);
467 v.setProperty(propName, i);
468 i++;
469 }
470
471 Candidate cA = new Candidate("CA",gA);
472 population.add(cA);
473 Candidate cB = new Candidate("CB",gB);
474 population.add(cB);
475 ArrayList<Candidate> eligibleParents = new ArrayList<Candidate>();
476 eligibleParents.add(cA);
477 eligibleParents.add(cB);
478
479 Monitor mnt = new Monitor();
480 boolean embeddedGraphHasBeenAlteredA = false;
481 boolean embeddedGraphHasBeenAlteredB = false;
482 for (int ixo=0; ixo<11; ixo++)
483 {
484 Candidate offspring0 = null;
485 Candidate offspring1 = null;
486 try
487 {
488 offspring0 = EAUtils.buildCandidateByXOver(eligibleParents,
489 population, mnt, new int[]{0,1}, ixo, 0, gaparams);
490 offspring1 = EAUtils.buildCandidateByXOver(eligibleParents,
491 population, mnt, new int[]{0,1}, ixo, 1, gaparams);
492 } catch (IndexOutOfBoundsException e)
493 {
494 if (e.getMessage().contains("Index 10 out of bounds"))
495 {
496 // All good! We intentionally triggered this exception to
497 // verify that the list of xover points has the right size.
498 break;
499 }
500 throw e;
501 }
502
503 DGraph g0xo = offspring0.getGraph();
504 DGraph g1xo = offspring1.getGraph();
505 Template t0 = null;
506 Template t1 = null;
507 for (Vertex v : g0xo.getVertexList())
508 {
509 if (v instanceof Template)
510 {
511 t0 = (Template) v;
512 break;
513 }
514 }
515 for (Vertex v : g1xo.getVertexList())
516 {
517 if (v instanceof Template)
518 {
519 t1 = (Template) v;
520 break;
521 }
522 }
523 assertNotNull(t0);
524 assertNotNull(t1);
525
526 DGraph embeddedGraph0 = t0.getInnerGraph();
527 DGraph embeddedGraph1 = t1.getInnerGraph();
528
529 // Ensure there has been a change
530 if (!embeddedGraphA.isIsomorphicTo(embeddedGraph0)
531 && !embeddedGraphA.isIsomorphicTo(embeddedGraph1))
532 {
533 embeddedGraphHasBeenAlteredA = true;
534 }
535 if (!embeddedGraphB.isIsomorphicTo(embeddedGraph0)
536 && !embeddedGraphB.isIsomorphicTo(embeddedGraph1))
537 {
538 embeddedGraphHasBeenAlteredB = true;
539 }
540
541 // Ensure consistency with "fixed-structure" contract
542 assertTrue(embeddedGraphA.isIsostructuralTo(embeddedGraph0)
543 || embeddedGraphB.isIsostructuralTo(embeddedGraph0));
544 assertTrue(embeddedGraphA.isIsostructuralTo(embeddedGraph1)
545 || embeddedGraphB.isIsostructuralTo(embeddedGraph1));
546 }
547 assertTrue(embeddedGraphHasBeenAlteredA);
548 assertTrue(embeddedGraphHasBeenAlteredB);
549 }
550
551//------------------------------------------------------------------------------
552
553 @Test
554 public void testCandidateGenerationMethod() throws Exception
555 {
556 int ix = 0, im=0, ic=0, tot=1000;
557 double wx = 2, wm = 0.6, wc=0.05;
558 double wtot = wx + wm + wc;
559 Randomizer rng = new Randomizer();
560 for (int i=0; i<tot; i++)
561 {
563 wx, wm, wc, rng);
564 switch (mode)
565 {
566 case CROSSOVER:
567 ix++;
568 break;
569 case MUTATION:
570 im++;
571 break;
572 case CONSTRUCTION:
573 ic++;
574 break;
575 default:
576 assertTrue(false,"Unexpected generation mode "+mode);
577 break;
578 }
579 }
580 double x = ((double)ix) / tot;
581 double m = ((double)im) / tot;
582 double c = ((double)ic) / tot;
583
584 double thld = 0.05;
585
586 assertTrue(Math.abs(x-(wx/wtot)) < thld, "#Xover cases are off!");
587 assertTrue(Math.abs(m-(wm/wtot)) < thld, "#Mutation cases are off!");
588 assertTrue(Math.abs(c-(wc/wtot)) < thld, "#Built cases are off!");
589 }
590
591//------------------------------------------------------------------------------
592
593 @Test
594 public void testCandidateGenerationMethodReproducibility() throws Exception
595 {
596 int tot = 100000;
597 long seed = 1234567;
598 long otherSeed = 987654321;
599 double wx = 2, wm = 0.6, wc=0.05;
600
601 Randomizer rng = new Randomizer(seed);
602 List<CandidateSource> resultsA = new ArrayList<CandidateSource>();
603 for (int i=0; i<tot; i++)
604 {
605 resultsA.add(EAUtils.pickNewCandidateGenerationMode(wx,wm,wc,rng));
606 }
607
608 Randomizer rng2 = new Randomizer(otherSeed);
609 List<CandidateSource> resultsB = new ArrayList<CandidateSource>();
610 for (int i=0; i<tot; i++)
611 {
612 resultsB.add(EAUtils.pickNewCandidateGenerationMode(wx,wm,wc,rng2));
613 }
614
615 rng = new Randomizer(seed);
616 List<CandidateSource> resultsC = new ArrayList<CandidateSource>();
617 for (int i=0; i<tot; i++)
618 {
619 resultsC.add(EAUtils.pickNewCandidateGenerationMode(wx,wm,wc,rng));
620 }
621
622 boolean different = false;
623 for (int i=0; i<tot; i++)
624 {
625 if (resultsA.get(i) != resultsB.get(i))
626 {
627 different = true;
628 break;
629 }
630 }
631 assertTrue(different);
632
633 for (int i=0; i<tot; i++)
634 {
635 assertEquals(resultsA.get(i),resultsC.get(i),
636 "Inconsistent sequence of random decisions");
637 }
638 }
639
640//------------------------------------------------------------------------------
641
642 @Test
643 public void testCrowdingProbability() throws Exception
644 {
646 double t = 0.001;
647 double p = 0.0;
649 {
650 p = EAUtils.getCrowdingProbability(ap,3,1.0,1.0,1.0);
651 assertTrue(Math.abs(1.0 - p)<t,
652 "Scheme 3 should return always 1.0 but was "+p);
653 }
655 p = EAUtils.getCrowdingProbability(ap3,0,1.0,10,1.0);
656 assertTrue(Math.abs(1.0 - p)<t, "Scheme 0 on ap3: 1.0 != "+p);
657 p = EAUtils.getCrowdingProbability(ap3,1,1.0,10,1.0);
658 assertTrue(Math.abs(1.0 - p)<t, "Scheme 1 on ap3: 1.0 != "+p);
659 p = EAUtils.getCrowdingProbability(ap3,2,1.0,10,1.0);
660 assertTrue(Math.abs(1.0 - p)<t, "Scheme 2 on ap3: 1.0 != "+p);
661
663 p = EAUtils.getCrowdingProbability(ap2,2,1.0,10,1.0);
664 assertTrue(Math.abs(0.5 - p)<t, "Scheme 2 on ap2");
665 }
666
667//------------------------------------------------------------------------------
668
669 @Test
670 public void testSelectNonScaffoldNonCapVertex() throws Exception
671 {
672 DGraph g = new DGraph();
673 EmptyVertex s = new EmptyVertex();
674 s.addAP();
675 s.addAP();
677
678 EmptyVertex v = new EmptyVertex();
679 v.addAP();
680 v.addAP();
681 v.addAP();
682 v.addAP();
684
685 EmptyVertex c1 = new EmptyVertex();
686 c1.addAP();
688
689 EmptyVertex c2 = new EmptyVertex();
690 c2.addAP();
692
693 EmptyVertex c3 = new EmptyVertex();
694 c3.addAP();
696
697 EmptyVertex c4 = new EmptyVertex();
698 c4.addAP();
700
701 g.addVertex(s);
702 g.appendVertexOnAP(s.getAP(0), v.getAP(0));
703 g.appendVertexOnAP(s.getAP(1), c1.getAP(0));
704 g.appendVertexOnAP(v.getAP(1), c2.getAP(0));
705 g.appendVertexOnAP(v.getAP(2), c3.getAP(0));
706 g.appendVertexOnAP(v.getAP(3), c4.getAP(0));
707
708 Randomizer rng = new Randomizer(1234L);
709 Vertex expected = v;
710 for (int i=0; i<5; i++)
711 {
713 assertEquals(expected, chosen, "Index of the only choosable vertex");
714 }
715 }
716
717//------------------------------------------------------------------------------
718
719 @Test
720 public void testChooseNumberOfSitesToMutate() throws Exception
721 {
722 double[] weights = new double[] {0,0,0,0,1};
723 assertEquals(4,EAUtils.chooseNumberOfSitesToMutate(weights,1.0));
724 assertEquals(4,EAUtils.chooseNumberOfSitesToMutate(weights,0.00000001));
725
726 weights = new double[] {1,0,0,0,1};
727 assertEquals(4,EAUtils.chooseNumberOfSitesToMutate(weights,1.0));
728 assertEquals(0,EAUtils.chooseNumberOfSitesToMutate(weights,0.00000001));
729
730 weights = new double[] {1,1,1,1,1};
731 assertEquals(4,EAUtils.chooseNumberOfSitesToMutate(weights,1.0));
732 assertEquals(4,EAUtils.chooseNumberOfSitesToMutate(weights,0.800001));
733 assertEquals(3,EAUtils.chooseNumberOfSitesToMutate(weights,0.799999));
734 assertEquals(3,EAUtils.chooseNumberOfSitesToMutate(weights,0.600001));
735 assertEquals(2,EAUtils.chooseNumberOfSitesToMutate(weights,0.599999));
736 assertEquals(2,EAUtils.chooseNumberOfSitesToMutate(weights,0.400001));
737 assertEquals(1,EAUtils.chooseNumberOfSitesToMutate(weights,0.399999));
738 assertEquals(1,EAUtils.chooseNumberOfSitesToMutate(weights,0.200001));
739 assertEquals(0,EAUtils.chooseNumberOfSitesToMutate(weights,0.199999));
740 assertEquals(0,EAUtils.chooseNumberOfSitesToMutate(weights,0.000001));
741 }
742
743//------------------------------------------------------------------------------
744
745 @Test
746 public void testMakeGraphFromFragmentationOfMol() throws Exception
747 {
748 // We use a hard-coded molecule to ensure the 3D geometry is fixed
749 assertTrue(tempDir.isDirectory(),"Should be a directory ");
750 String structureFile = tempDir.getAbsolutePath() + SEP + "mol.sdf";
751 DenoptimIO.writeData(structureFile,
752 "" + NL
753 + " OpenBabel03302310043D" + NL
754 + "" + NL
755 + " 33 35 0 0 0 0 0 0 0 0999 V2000" + NL
756 + " -1.5455 1.4965 3.4529 O 0 0 0 0 0 0 0 0 0 0 0 0" + NL
757 + " -1.1783 1.0876 2.3182 C 0 0 0 0 0 0 0 0 0 0 0 0" + NL
758 + " -1.8597 -0.0221 1.6796 N 0 0 0 0 0 0 0 0 0 0 0 0" + NL
759 + " -3.0535 -0.6083 2.2978 C 0 0 0 0 0 0 0 0 0 0 0 0" + NL
760 + " 0.0153 1.7383 1.6547 C 0 0 0 0 0 0 0 0 0 0 0 0" + NL
761 + " -0.1038 1.5947 0.1342 C 0 0 1 0 0 0 0 0 0 0 0 0" + NL
762 + " 0.9646 2.2439 -0.5585 O 0 0 0 0 0 0 0 0 0 0 0 0" + NL
763 + " 2.0315 1.3700 -0.8940 C 0 0 2 0 0 0 0 0 0 0 0 0" + NL
764 + " 3.0842 2.1330 -1.6910 C 0 0 0 0 0 0 0 0 0 0 0 0" + NL
765 + " 3.5659 3.1894 -0.9391 F 0 0 0 0 0 0 0 0 0 0 0 0" + NL
766 + " 4.1344 1.2898 -2.0067 F 0 0 0 0 0 0 0 0 0 0 0 0" + NL
767 + " 2.5295 2.6237 -2.8597 F 0 0 0 0 0 0 0 0 0 0 0 0" + NL
768 + " 1.5529 0.2692 -1.6691 O 0 0 0 0 0 0 0 0 0 0 0 0" + NL
769 + " 0.4699 -0.4528 -1.1881 C 0 0 0 0 0 0 0 0 0 0 0 0" + NL
770 + " -0.3192 0.1414 -0.2151 C 0 0 0 0 0 0 0 0 0 0 0 0" + NL
771 + " -1.2683 -0.6053 0.4932 C 0 0 0 0 0 0 0 0 0 0 0 0" + NL
772 + " -1.5222 -1.9320 0.0906 C 0 0 0 0 0 0 0 0 0 0 0 0" + NL
773 + " -0.8092 -2.5038 -0.9766 C 0 0 0 0 0 0 0 0 0 0 0 0" + NL
774 + " -1.1169 -3.8201 -1.3518 O 0 0 0 0 0 0 0 0 0 0 0 0" + NL
775 + " -0.4725 -4.5263 -2.4070 C 0 0 0 0 0 0 0 0 0 0 0 0" + NL
776 + " 0.2040 -1.7556 -1.6127 C 0 0 0 0 0 0 0 0 0 0 0 0" + NL
777 + " -3.7666 -0.9444 1.5155 H 0 0 0 0 0 0 0 0 0 0 0 0" + NL
778 + " -3.5865 0.1389 2.9228 H 0 0 0 0 0 0 0 0 0 0 0 0" + NL
779 + " -2.7606 -1.4709 2.9321 H 0 0 0 0 0 0 0 0 0 0 0 0" + NL
780 + " 0.9449 1.2474 2.0144 H 0 0 0 0 0 0 0 0 0 0 0 0" + NL
781 + " 0.0550 2.8163 1.9227 H 0 0 0 0 0 0 0 0 0 0 0 0" + NL
782 + " -1.0337 2.1265 -0.1667 H 0 0 0 0 0 0 0 0 0 0 0 0" + NL
783 + " 2.5075 0.9860 0.0372 H 0 0 0 0 0 0 0 0 0 0 0 0" + NL
784 + " -2.2462 -2.5403 0.6157 H 0 0 0 0 0 0 0 0 0 0 0 0" + NL
785 + " -0.6162 -3.9902 -3.3689 H 0 0 0 0 0 0 0 0 0 0 0 0" + NL
786 + " -0.9204 -5.5374 -2.4930 H 0 0 0 0 0 0 0 0 0 0 0 0" + NL
787 + " 0.6107 -4.6349 -2.1878 H 0 0 0 0 0 0 0 0 0 0 0 0" + NL
788 + " 0.8117 -2.1861 -2.3969 H 0 0 0 0 0 0 0 0 0 0 0 0" + NL
789 + " 1 2 2 0 0 0 0" + NL
790 + " 2 3 1 0 0 0 0" + NL
791 + " 2 5 1 0 0 0 0" + NL
792 + " 3 4 1 0 0 0 0" + NL
793 + " 4 22 1 0 0 0 0" + NL
794 + " 4 23 1 0 0 0 0" + NL
795 + " 4 24 1 0 0 0 0" + NL
796 + " 5 6 1 0 0 0 0" + NL
797 + " 5 25 1 0 0 0 0" + NL
798 + " 5 26 1 0 0 0 0" + NL
799 + " 6 7 1 0 0 0 0" + NL
800 + " 6 27 1 6 0 0 0" + NL
801 + " 7 8 1 0 0 0 0" + NL
802 + " 8 9 1 0 0 0 0" + NL
803 + " 8 13 1 0 0 0 0" + NL
804 + " 8 28 1 1 0 0 0" + NL
805 + " 9 10 1 0 0 0 0" + NL
806 + " 9 11 1 0 0 0 0" + NL
807 + " 9 12 1 0 0 0 0" + NL
808 + " 13 14 1 0 0 0 0" + NL
809 + " 14 15 2 0 0 0 0" + NL
810 + " 15 16 1 0 0 0 0" + NL
811 + " 15 6 1 0 0 0 0" + NL
812 + " 16 17 2 0 0 0 0" + NL
813 + " 16 3 1 0 0 0 0" + NL
814 + " 17 18 1 0 0 0 0" + NL
815 + " 17 29 1 0 0 0 0" + NL
816 + " 18 19 1 0 0 0 0" + NL
817 + " 18 21 2 0 0 0 0" + NL
818 + " 19 20 1 0 0 0 0" + NL
819 + " 20 30 1 0 0 0 0" + NL
820 + " 20 31 1 0 0 0 0" + NL
821 + " 20 32 1 0 0 0 0" + NL
822 + " 21 14 1 0 0 0 0" + NL
823 + " 21 33 1 0 0 0 0" + NL
824 + "M END" + NL
825 + "$$$$", false);
826 IAtomContainer mol = DenoptimIO.readSDFFile(structureFile).get(0);
827 GAParameters settings = new GAParameters();
828
829 List<CuttingRule> cuttingRules = new ArrayList<CuttingRule>();
830 cuttingRules.add(new CuttingRule("cC", "[c]", "[C]", "~", 0,
831 new ArrayList<String>()));
832 cuttingRules.add(new CuttingRule("cN", "[c]", "[#7]", "~", 1,
833 new ArrayList<String>()));
834 cuttingRules.add(new CuttingRule("cO", "[c]", "[#8]", "~", 2,
835 new ArrayList<String>()));
836 cuttingRules.add(new CuttingRule("OC", "[O]", "[C]", "-", 3,
837 new ArrayList<String>()));
838 cuttingRules.add(new CuttingRule("CF", "[C]", "[F]", "-", 4,
839 new ArrayList<String>()));
840 cuttingRules.add(new CuttingRule("NC", "[N]", "[C]", "-", 5,
841 new ArrayList<String>()));
842
844 cuttingRules, settings.getLogger(),
846
847 assertEquals(16, graph.getVertexCount());
848 assertEquals(15, graph.getEdgeCount());
849 assertEquals(2, graph.getRingCount());
850 assertEquals(0, graph.getVertexList()
851 .stream()
852 .filter(v -> v instanceof Template)
853 .count());
854
855 DGraph graphWithTemplate = graph.embedPatternsInTemplates(
857
858 assertEquals(7, graphWithTemplate.getVertexCount());
859 assertEquals(6, graphWithTemplate.getEdgeCount());
860 assertEquals(0, graphWithTemplate.getRingCount());
861 List<Vertex> templates = graphWithTemplate.getVertexList()
862 .stream()
863 .filter(v -> v instanceof Template)
864 .collect(Collectors.toList());
865 assertEquals(1, templates.size());
866 Template tmpl = (Template) templates.get(0);
867 assertEquals(BBType.SCAFFOLD, tmpl.getBuildingBlockType());
868 assertEquals(ContractLevel.FIXED, tmpl.getContractLevel());
869 assertEquals(2, tmpl.getInnerGraph().getRingCount());
870 }
871
872//------------------------------------------------------------------------------
873
874 @Test
876 throws Exception
877 {
878 SmilesParser p = new SmilesParser(builder);
879 IAtomContainer mol = p.parseSmiles("c1ccccc1OCN(CC)(C)[Ru](N)(N)C#O");
880
881 // Use this to make the molecule 2D for an easy visual inspection.
882 /*
883 StructureDiagramGenerator sdg = new StructureDiagramGenerator();
884 sdg.generateCoordinates(mol);
885 */
886
887 GAParameters settings = new GAParameters();
888
889 List<CuttingRule> cuttingRules = new ArrayList<CuttingRule>();
890 cuttingRules.add(new CuttingRule("C-O", "[#6]", "[#8]", "-", 2,
891 new ArrayList<String>()));
892 cuttingRules.add(new CuttingRule("N-C", "[#7]", "[#6]", "-", 5,
893 new ArrayList<String>()));
894 cuttingRules.add(new CuttingRule("Ru-Any", "[Ru]", "[$([*])]", "~", 5,
895 new ArrayList<String>()));
896
898 cuttingRules, settings.getLogger(),
900
901 assertEquals(10, graph1.getVertexCount());
902 assertEquals(9, graph1.getEdgeCount());
903 assertEquals(0, graph1.getRingCount());
904 List<Vertex> scaffolds = graph1.getVertexList()
905 .stream()
906 .filter(v -> BBType.SCAFFOLD == v.getBuildingBlockType())
907 .collect(Collectors.toList());
908 assertEquals(1, scaffolds.size());
909 Vertex scaffold = scaffolds.get(0);
910 IAtomContainer iacScaffold = scaffold.getIAtomContainer();
911 assertEquals(6, iacScaffold.getAtomCount());
912
914 policy.label = "Ru";
915
917 cuttingRules, settings.getLogger(), policy);
918
919 assertEquals(10, graph2.getVertexCount());
920 assertEquals(9, graph2.getEdgeCount());
921 assertEquals(0, graph2.getRingCount());
922 scaffolds = graph2.getVertexList()
923 .stream()
924 .filter(v -> BBType.SCAFFOLD == v.getBuildingBlockType())
925 .collect(Collectors.toList());
926 assertEquals(1, scaffolds.size());
927 scaffold = scaffolds.get(0);
928 iacScaffold = scaffold.getIAtomContainer();
929 assertEquals(1, iacScaffold.getAtomCount());
930 assertEquals("Ru", iacScaffold.getAtom(0).getSymbol());
931 }
932
933//------------------------------------------------------------------------------
934
935 @Test
936 public void testMakeGraphFromFragmentationOfMol_Symmetry() throws Exception
937 {
938 SmilesParser p = new SmilesParser(builder);
939 IAtomContainer mol = p.parseSmiles(
940 "Oc1cc(O)cc(O)c1CN(CC)(CC)[Ru](N)(Nc1c(F)cc(F)cc1(Cl))C#O");
941
942 // Use this to make the molecule 2D for an easy visual inspection.
943 /*
944 StructureDiagramGenerator sdg = new StructureDiagramGenerator();
945 sdg.generateCoordinates(mol);
946 */
947
948 GAParameters settings = new GAParameters();
949
950 List<CuttingRule> cuttingRules = new ArrayList<CuttingRule>();
951 cuttingRules.add(new CuttingRule("C-F", "[#6]", "[#9]", "-", 1,
952 new ArrayList<String>()));
953 cuttingRules.add(new CuttingRule("C-O", "[#6]", "[#8]", "-", 2,
954 new ArrayList<String>()));
955 cuttingRules.add(new CuttingRule("N-C", "[#7]", "[#6]", "-", 5,
956 new ArrayList<String>()));
957 cuttingRules.add(new CuttingRule("Ru-Any", "[Ru]", "[$([*])]", "~", 5,
958 new ArrayList<String>()));
959
961 cuttingRules, settings.getLogger(),
963
964 assertEquals(14, graph1.getVertexCount());
965 assertEquals(13, graph1.getEdgeCount());
966 assertEquals(0, graph1.getRingCount());
967 assertEquals(2, graph1.getSymmetricSetCount());
968 boolean foundO = false;
969 boolean foundF = false;
970 Iterator<SymmetricVertexes> iter = graph1.getSymSetsIterator();
971 while (iter.hasNext())
972 {
973 SymmetricVertexes ss = iter.next();
974 String el = ss.get(0).getIAtomContainer().getAtom(0).getSymbol();
975 if ("O".equals(el))
976 foundO = true;
977 else if ("F".equals(el))
978 foundF = true;
979 }
980 assertTrue(foundO);
981 assertTrue(foundF);
982
984 policy.label = "Cl";
985
987 cuttingRules, settings.getLogger(), policy);
988
989 assertEquals(14, graph2.getVertexCount());
990 assertEquals(13, graph2.getEdgeCount());
991 assertEquals(0, graph2.getRingCount());
992 assertEquals(2, graph2.getSymmetricSetCount());
993 foundO = false;
994 foundF = false;
995 iter = graph2.getSymSetsIterator();
996 while (iter.hasNext())
997 {
998 SymmetricVertexes ss = iter.next();
999 String el = ss.get(0).getIAtomContainer().getAtom(0).getSymbol();
1000 if ("O".equals(el))
1001 foundO = true;
1002 else if ("F".equals(el))
1003 foundF = true;
1004 }
1005 assertTrue(foundO);
1006 assertTrue(foundF);
1007
1008
1009 policy = ScaffoldingPolicy.ELEMENT;
1010 policy.label = "F";
1011
1013 cuttingRules, settings.getLogger(), policy);
1014
1015 assertEquals(14, graph3.getVertexCount());
1016 assertEquals(13, graph3.getEdgeCount());
1017 assertEquals(0, graph3.getRingCount());
1018 assertEquals(1, graph3.getSymmetricSetCount());
1019 foundO = false;
1020 foundF = false;
1021 iter = graph3.getSymSetsIterator();
1022 while (iter.hasNext())
1023 {
1024 SymmetricVertexes ss = iter.next();
1025 String el = ss.get(0).getIAtomContainer().getAtom(0).getSymbol();
1026 if ("O".equals(el))
1027 foundO = true;
1028 else if ("F".equals(el))
1029 foundF = true;
1030 }
1031 assertTrue(foundO);
1032 assertFalse(foundF);
1033 }
1034
1035//------------------------------------------------------------------------------
1036
1037 @Test
1039 throws Exception
1040 {
1041 SmilesParser p = new SmilesParser(builder);
1042 IAtomContainer mol = p.parseSmiles("C#C-C#C-C#N");
1043
1044 // 2D is enough to get linearities. No need to wast time getting 3D
1045 StructureDiagramGenerator sdg = new StructureDiagramGenerator();
1046 sdg.generateCoordinates(mol);
1047
1048 GAParameters settings = new GAParameters();
1049
1050 List<CuttingRule> cuttingRules = new ArrayList<CuttingRule>();
1051 cuttingRules.add(new CuttingRule("C-C", "[#6]", "[#6]", "-", 2,
1052 new ArrayList<String>()));
1053 cuttingRules.add(new CuttingRule("C-X", "[#6]", "[#9,#17,#35,#53]", "~",
1054 3, new ArrayList<String>()));
1055
1056 // Must add du on linearities
1058 cuttingRules, settings.getLogger(),
1060
1061 assertEquals(3, graph.getVertexCount());
1062 assertEquals(2, graph.getEdgeCount());
1063 assertEquals(0, graph.getRingCount());
1064 int duAtmCount = 0;
1065 for (Vertex v : graph.getVertexList())
1066 {
1067 for (IAtom a : v.getIAtomContainer().atoms())
1068 {
1071 duAtmCount++;
1072 }
1073
1074 }
1075 assertEquals(4, duAtmCount);
1076
1077 // Without linearities
1078 IAtomContainer molNonLinear = p.parseSmiles("C(Cl)(F)Br");
1079 sdg.generateCoordinates(molNonLinear);
1080
1081 DGraph graph1 = EAUtils.makeGraphFromFragmentationOfMol(molNonLinear,
1082 cuttingRules, settings.getLogger(),
1084
1085 assertEquals(4, graph1.getVertexCount());
1086 assertEquals(3, graph1.getEdgeCount());
1087 assertEquals(0, graph1.getRingCount());
1088 duAtmCount = 0;
1089 for (Vertex v : graph1.getVertexList())
1090 {
1091 for (IAtom a : v.getIAtomContainer().atoms())
1092 {
1095 duAtmCount++;
1096 }
1097
1098 }
1099 assertEquals(0, duAtmCount);
1100
1101 // there are linearities but we do not want Du on linearities
1103 cuttingRules, settings.getLogger(),
1105 // By default we do not add Du on linearities
1106
1107 assertEquals(3, graph2.getVertexCount());
1108 assertEquals(2, graph2.getEdgeCount());
1109 assertEquals(0, graph2.getRingCount());
1110 duAtmCount = 0;
1111 for (Vertex v : graph2.getVertexList())
1112 {
1113 for (IAtom a : v.getIAtomContainer().atoms())
1114 {
1117 duAtmCount++;
1118 }
1119
1120 }
1121 assertEquals(0, duAtmCount);
1122 }
1123
1124//------------------------------------------------------------------------------
1125
1134 @Test
1136 {
1137 SmilesParser p = new SmilesParser(builder);
1138 IAtomContainer mol = p.parseSmiles(
1139 "P123C(OC[SiH2]O1)(OC[SiH2]O2)OC[SiH2]O3");
1140
1141 /*
1142 // In case you need to visualize, but note: two branches overlap in 2D!
1143 StructureDiagramGenerator sdg = new StructureDiagramGenerator();
1144 sdg.generateCoordinates(mol);
1145 */
1146
1147 GAParameters settings = new GAParameters();
1148
1149 List<CuttingRule> cuttingRules = new ArrayList<CuttingRule>();
1150 cuttingRules.add(new CuttingRule("PC-O", "[$(CP)]", "[O]", "-", -1,
1151 new ArrayList<String>()));
1152 cuttingRules.add(new CuttingRule("C-O", "[C]", "[O]", "-", 0,
1153 new ArrayList<String>()));
1154 cuttingRules.add(new CuttingRule("C-Si", "[C]", "[Si]", "-", 1,
1155 new ArrayList<String>()));
1156 cuttingRules.add(new CuttingRule("Si-O", "[Si]", "[O]", "-", 2,
1157 new ArrayList<String>()));
1158 cuttingRules.add(new CuttingRule("P-C", "[P]", "[C]", "-", 3,
1159 new ArrayList<String>()));
1160 cuttingRules.add(new CuttingRule("P-O", "[P]", "[O]", "-", 4,
1161 new ArrayList<String>()));
1162
1164 scaffoldOnP.label = "P";
1166 cuttingRules, settings.getLogger(),
1167 scaffoldOnP, 170);
1168
1169 assertEquals(6, graph.getSymmetricSetCount());
1170 List<List<Integer>> expected = new ArrayList<List<Integer>>();
1171 expected.add(Arrays.asList(2, 8, 14));
1172 expected.add(Arrays.asList(3, 9, 15));
1173 expected.add(Arrays.asList(4, 10, 16));
1174 expected.add(Arrays.asList(5, 11, 17));
1175 expected.add(Arrays.asList(6, 12, 18));
1176 expected.add(Arrays.asList(7, 13, 19));
1177 for (List<Integer> vrtxIDs : expected)
1178 {
1180 graph.getVertexWithId(vrtxIDs.get(0)));
1181 assertFalse(sv0.isEmpty());
1182 for (int i=1; i<vrtxIDs.size(); i++)
1183 {
1185 graph.getVertexWithId(vrtxIDs.get(i)));
1186 assertTrue(sv0 == svI);
1187 }
1188 }
1189 }
1190
1191//------------------------------------------------------------------------------
1192
1193}
General set of constants used in DENOPTIM.
static final String DUMMYATMSYMBOL
Symbol of dummy atom.
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 > getScaffoldLibrary()
ArrayList< Vertex > getFragmentLibrary()
Parameters defining the fragment space.
Helper methods for the genetic algorithm.
Definition: EAUtils.java:93
static CandidateSource pickNewCandidateGenerationMode(double xoverWeight, double mutWeight, double newWeight, Randomizer randomizer)
Takes a decision on which CandidateSource method to use for generating a new Candidate.
Definition: EAUtils.java:249
static int chooseNumberOfSitesToMutate(double[] multiSiteMutationProb, double hit)
Takes a decision on how many sites to mutate on a candidate.
Definition: EAUtils.java:210
static Candidate buildCandidateByXOver(List< Candidate > eligibleParents, Population population, Monitor mnt, GAParameters settings)
Generates a new offspring by performing a crossover operation.
Definition: EAUtils.java:299
static DGraph makeGraphFromFragmentationOfMol(IAtomContainer mol, List< CuttingRule > cuttingRules, Logger logger, ScaffoldingPolicy scaffoldingPolicy)
Converts a molecule into a DGraph by fragmentation and re-assembling of the fragments.
Definition: EAUtils.java:1028
static double getCrowdingProbability(AttachmentPoint ap, GAParameters settings)
Calculated the probability of using and attachment point rooted on an atom that is holding other atta...
Definition: EAUtils.java:2129
static DGraph buildGraph(GAParameters settings)
Graph construction starts with selecting a random core/scaffold.
Definition: EAUtils.java:1678
static Vertex selectNonScaffoldNonCapVertex(DGraph g, Randomizer randomizer)
Chose randomly a vertex that is neither scaffold or capping group.
Definition: EAUtils.java:1371
void testMakeGraphFromFragmentationOfMol()
void testCandidateGenerationMethodReproducibility()
FragmentSpaceParameters prepare()
static final String NL
void testSelectNonScaffoldNonCapVertex()
void testMakeGraphFromFragmentationOfMol_symmetry()
Test the detection of "some" symmetry.
void testMakeGraphFromFragmentationOfMol_linearities()
void testMakeGraphFromFragmentationOfMol_Symmetry()
IChemObjectBuilder builder
Private builder of atom containers.
void testChooseNumberOfSitesToMutate()
void testBuildGraphFromTemplateScaffold()
void testMakeGraphFromFragmentationOfMol_ScaffoldingPolicy()
void testBuildByXOver_Embedded_Free()
NB: the graphs from methods getPairOfTestGraphsB() and getPairOfTestGraphsBxo() and getPairOfTestGr...
static final String SEP
void testBuildByXOver_Embedded_FixedStructure()
void testBuildByXOver_Embedded_FreeBackwards()
NB: the graphs from methods getPairOfTestGraphsB() and getPairOfTestGraphsBxo() and getPairOfTestGr...
A collection of candidates.
Definition: Population.java:48
boolean add(Candidate c)
Definition: Population.java:87
static GAParameters prepare()
static DGraph[] getPairOfTestGraphsBxoxo()
Builds a pair of graphs that contain templates with ContractLevel#FREE contract.
static DGraph makeGraphE()
Produced a graph like this:
static DGraph[] getPairOfTestGraphsB()
Builds a pair of graphs that contain templates with ContractLevel#FREE contract.
static DGraph[] getPairOfTestGraphsBxo()
Builds a pair of graphs that contain templates with ContractLevel#FREE contract.
static DGraph makeGraphA()
Produced a graph like this:
static APClass make(String ruleAndSubclass)
Creates an APClass if it does not exist already, or returns the reference to the existing instance.
Definition: APClass.java:136
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....
A candidate is the combination of a denoptim graph with molecular representation and may include also...
Definition: Candidate.java:40
void setFitness(double fitness)
Definition: Candidate.java:480
Container for the list of vertices and the edges that connect them.
Definition: DGraph.java:102
Vertex getVertexWithId(long vid)
Searches for a vertex with the given identifier.
Definition: DGraph.java:2582
int getSymmetricSetCount()
Returns the number of symmetric sets of vertices.
Definition: DGraph.java:313
ArrayList< AttachmentPoint > getAttachmentPoints()
Returns the list of all attachment points contained in this graph.
Definition: DGraph.java:3970
boolean isIsomorphicTo(DGraph other)
Checks if this graph is "DENOPTIM-isomorphic" to the other one given.
Definition: DGraph.java:3453
void addVertex(Vertex vertex)
Appends a vertex to this graph without creating any edge.
Definition: DGraph.java:1097
DGraph embedPatternsInTemplates(GraphPattern pattern, FragmentSpace fragSpace)
Searches for the given pattern type and generated a new graph where each set of (clones of) vertexes ...
Definition: DGraph.java:4616
void getChildrenTree(Vertex vertex, List< Vertex > children)
Gets all the children of the current vertex recursively.
Definition: DGraph.java:2771
Iterator< SymmetricVertexes > getSymSetsIterator()
Get an iterator for the sets of symmetrically related vertices.
Definition: DGraph.java:324
Vertex getVertexAtPosition(int pos)
Returns the vertex that is in the given position of the list of vertices belonging to this graph.
Definition: DGraph.java:2514
void appendVertexOnAP(AttachmentPoint srcAP, AttachmentPoint trgAP)
Append a vertex to this graph: adds the new vertex to the list of vertices belonging to the graph,...
Definition: DGraph.java:5776
List< Vertex > getVertexList()
Definition: DGraph.java:719
DGraph clone()
Returns almost "deep-copy" of this graph.
Definition: DGraph.java:3186
boolean sameAs(DGraph other, StringBuilder reason)
Compare this and another graph ignoring the vertex IDs.
Definition: DGraph.java:3665
SymmetricVertexes getSymSetForVertex(Vertex v)
Returns the set of vertexes symmetric to the given one.
Definition: DGraph.java:633
void addRing(Ring ring)
Definition: DGraph.java:1030
boolean isIsostructuralTo(DGraph other)
Checks if this graph is "DENOPTIM-isostructural" to the other one given.
Definition: DGraph.java:3580
Unit test for DENOPTIMGraph.
Definition: DGraphTest.java:72
static DGraph makeTestGraphA()
Build a graph meant to be used in unit tests.
An empty vertex has the behaviors of a vertex, but has no molecular structure.
void addAP()
Adds an attachment point with no APClass or other attribute.
A collection of Vertexs that are related by a relation that we call "symmetry", even though this clas...
ContractLevel getContractLevel()
Returns the contract level of this template, i.e., to what extent the content of this template can be...
Definition: Template.java:203
List< Vertex > getMutationSites(List< MutationType > ignoredTypes)
A list of mutation sites from within this vertex.
Definition: Template.java:872
void setContractLevel(ContractLevel contract)
Imposes the given contract to this template.
Definition: Template.java:214
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
Definition: Vertex.java:61
Vertex.BBType getBuildingBlockType()
Definition: Vertex.java:298
void setAsRCV(boolean isRCV)
Definition: Vertex.java:254
void setBuildingBlockType(Vertex.BBType buildingBlockType)
Definition: Vertex.java:305
abstract IAtomContainer getIAtomContainer()
AttachmentPoint getAP(int i)
Get attachment point i on this vertex.
Definition: Vertex.java:920
static Vertex newVertexFromLibrary(int bbId, Vertex.BBType bbt, FragmentSpace fragSpace)
Builds a new molecular fragment kind of vertex.
Definition: Vertex.java:214
Utility methods for input/output.
static ArrayList< IAtomContainer > readSDFFile(String fileName)
Reads a file containing multiple molecules (multiple SD format))
static void writeData(String fileName, String data, boolean append)
Write text-like data file.
A collection of counters user to count actions taken by the evolutionary algorithm.
Definition: Monitor.java:37
void setParameters(RunTimeParameters otherParams)
Logger getLogger()
Get the name of the program specific logger.
Parameters for genetic algorithm.
A cutting rule with three SMARTS queries (atom 1, bond, atom2) and options.
Utilities for molecule conversion.
static String getSymbolOrLabel(IAtom atm)
Gets either the elemental symbol (for standard atoms) of the label (for pseudo-atoms).
Tool to generate random numbers and random decisions.
Definition: Randomizer.java:35
Defines how to define the scaffold vertex of a graph.
A chosen method for generation of new Candidates.
Definition: EAUtils.java:119
Possible chemical bond types an edge can represent.
Definition: Edge.java:303
Enum specifying to what extent the template's inner graph can be changed.
Definition: Template.java:104
FREE
Inner graphs are free to change within the confines of the required AttachmentPoints.
Definition: Template.java:109
FIXED
Inner graphs are effectively equivalent to the Fragment class, as no change in the inner structure is...
Definition: Template.java:116
FIXED_STRUCT
Inner graph keep the same structure, but the identify of vertices can change.
Definition: Template.java:124
The type of building block.
Definition: Vertex.java:86