$darkmode
DENOPTIM
FitnessEvaluationTask.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2019 Vishwesh Venkatraman <vishwesh.venkatraman@ntnu.no> and
4 * Marco Foscato <marco.foscato@uib.no>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20package denoptim.programs.fitnessevaluator;
21
22import java.io.File;
23
24import org.openscience.cdk.interfaces.IAtomContainer;
25
26import denoptim.exception.DENOPTIMException;
27import denoptim.fitness.FitnessParameters;
28import denoptim.fragspace.FragmentSpace;
29import denoptim.fragspace.FragmentSpaceParameters;
30import denoptim.graph.Candidate;
31import denoptim.graph.DGraph;
32import denoptim.molecularmodeling.ThreeDimTreeBuilder;
33import denoptim.programs.RunTimeParameters.ParametersType;
34import denoptim.task.FitnessTask;
35
41{
45 private FRParameters frSettings = null;
46
51
52//------------------------------------------------------------------------------
53
61 DGraph molGraph, IAtomContainer iac,
62 String workDir, String outFileName)
63 {
64 super((FitnessParameters) settings.getParameters(
65 ParametersType.FIT_PARAMS), new Candidate(molGraph));
68 {
69 fsParams = (FragmentSpaceParameters)settings.getParameters(
71 }
72 this.fragSpace = fsParams.getFragmentSpace();
73 this.workDir = new File(workDir);
74 this.frSettings = settings;
75 fitProvMol = iac;
76 fitProvOutFile = outFileName;
77 }
78
79//------------------------------------------------------------------------------
80
81 @Override
82 public Object call() throws DENOPTIMException, Exception
83 {
84 // Optionally improve the molecular representation, which
85 // is otherwise only given by the collection of building
86 // blocks (not aligned, nor roto-translated)
88 {
92 try {
93 DGraph gWithNoRCVs = dGraph.clone();
95
96 // To get a proper molecular representation we need
97 // 1) build a 3d tree
98 // 2) remove RCAs
99 // 3) remove dummy in multi-hapto
100 // 4) remove dummy in linearities
101 // 5) set atom properties that are expected by CDK classes (for
102 // example, the number of implicit atoms).
103 // All this should be done within the TreeBuilder3D and
104 // controlled by flags. Obviously, if we remove all these
105 // functional dummy atoms, then we cannot use them anymore,
106 // So: are there cases where we need to keep them?
107 // We can always rebuild the 3d-tree (with Dummy atoms) if
108 // we need the get it back. Thus, for the moment I do not see
109 // a reason for keeping dummy atoms in the molecular
110 // representation,but potential down-stream effects have to
111 // be evaluated.
112 IAtomContainer mol = tb3d.convertGraphTo3DAtomContainer(
113 gWithNoRCVs,true);
114 fitProvMol = mol;
115 } catch (Throwable t) {
116 //we have it already from before
117 }
118 }
119
120 // Run the fitness provider, whatever that is
121 try
122 {
124 }
125 catch (Throwable ex)
126 {
127 hasException = true;
128 errMsg = "Exception while running fitness provider";
129 thrownExc = ex;
130 ex.printStackTrace();
131 throw new DENOPTIMException(ex);
132 }
133
135 {
137 true, true, fitProvMol);
138 }
139
140 completed = true;
141 return result;
142 }
143
144//------------------------------------------------------------------------------
145
146}
Settings defining the calculation of fitness.
Class defining a space of building blocks.
void addFusedRingsToFragmentLibrary(DGraph graph)
Extracts a system of one or more fused rings and adds them to the fragment space if not already prese...
Parameters defining the fragment space.
A candidate is the combination of a denoptim graph with molecular representation and may include also...
Definition: Candidate.java:40
Container for the list of vertices and the edges that connect them.
Definition: DGraph.java:102
DGraph clone()
Returns almost "deep-copy" of this graph.
Definition: DGraph.java:3186
void replaceUnusedRCVsWithCapps(FragmentSpace fragSpace)
Removes unused ring-closing vertices.
Definition: DGraph.java:1526
Tool to build build three-dimensional (3D) tree-like molecular structures from DGraph.
IAtomContainer convertGraphTo3DAtomContainer(DGraph graph)
Created a three-dimensional molecular representation from a given DGraph.
boolean containsParameters(ParametersType type)
RunTimeParameters getParameters(ParametersType type)
Logger getLogger()
Get the name of the program specific logger.
Randomizer getRandomizer()
Returns the current program-specific randomizer.
Parameters controlling execution of FitnessRunner.
boolean addTemplatesToLibraries
Flag controlling attempt to add templates to building block libraries.
FitnessEvaluationTask(FRParameters settings, DGraph molGraph, IAtomContainer iac, String workDir, String outFileName)
FRParameters frSettings
Collection of settings controlling the execution of the task.
Task that assesses the fitness of a given graph.
DGraph dGraph
The graph representation of the entity to evaluate.
void runFitnessProvider()
This method runs the actual evaluation of the fitness, whether that is run internally (i....
FitnessParameters fitnessSettings
Settings for the calculation of the fitness.
Candidate result
The data structure holding the results of this task.
String fitProvOutFile
The file where we store the final output from the fitness provider.
IAtomContainer fitProvMol
The chemical representation of the entity to evaluate.
File workDir
The file system location where we want to be placed when doing the work.
Definition: Task.java:78
boolean completed
Flag about completion.
Definition: Task.java:41
String errMsg
Error message produced by any subtask.
Definition: Task.java:56
boolean hasException
Flag about exception.
Definition: Task.java:46
Throwable thrownExc
Exception thrown.
Definition: Task.java:61
FS_PARAMS
Parameters pertaining the definition of the fragment space.
FIT_PARAMS
Parameters pertaining the calculation of fitness (i.e., the fitness provider).