23import java.io.IOException;
24import java.util.logging.Level;
26import org.apache.commons.io.FileUtils;
27import org.openscience.cdk.Atom;
28import org.openscience.cdk.AtomContainer;
29import org.openscience.cdk.interfaces.IAtomContainer;
30import org.openscience.cdk.interfaces.IChemObjectBuilder;
31import org.openscience.cdk.silent.SilentChemObjectBuilder;
33import denoptim.combinatorial.GraphBuildingTask;
34import denoptim.constants.DENOPTIMConstants;
35import denoptim.exception.DENOPTIMException;
36import denoptim.fitness.FitnessParameters;
37import denoptim.fitness.FitnessProvider;
38import denoptim.graph.Candidate;
39import denoptim.graph.DGraph;
40import denoptim.io.DenoptimIO;
41import denoptim.molecularmodeling.ThreeDimTreeBuilder;
42import denoptim.utils.MoleculeUtils;
43import denoptim.utils.TaskUtils;
112 this.fitnessSettings = settings;
146 boolean status =
false;
182 "Unable to create image. {0}", ex.getMessage());
199 StringBuilder sb =
new StringBuilder();
205 .append(
" ").append(
id);
211 String msg =
"Calling external fitness provider: => " + sb +
NL;
220 msg =
"Failed to execute fitness provider "
233 IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
234 IAtomContainer processedMol = builder.newAtomContainer();
235 boolean unreadable =
false;
240 if (processedMol.isEmpty())
247 String[] parts = o.toString().trim().split(
"\\s+");
248 if (processedMol.getAtomCount() != parts.length)
251 +
"IDs (" + parts.length +
") and atoms ("
252 + processedMol.getAtomCount() +
") in candidate "
253 +
"processed by external fitness provider.");
255 for (
int i=0; i<processedMol.getAtomCount(); i++)
257 processedMol.getAtom(i).setProperty(
259 Integer.parseInt(parts[i]));
275 msg =
"Unreadable file from fitness provider run (Task " +
id
283 }
catch (IOException e) {
286 +
"disappeared (it was there, but not anymore!)");
290 String err =
"#FTask: Unable to retrive data. See " + fileBkp;
291 processedMol =
new AtomContainer();
292 processedMol.addAtom(
new Atom(
"H"));
309 String err = processedMol.getProperty(
321 String fitprp = processedMol.getProperty(
326 fitVal = Double.parseDouble(fitprp);
334 msg =
"Fitness value '" + fitprp +
"' of "
345 if (Double.isNaN(fitVal))
380 msg =
"Could not find '" + DENOPTIMConstants.FITNESSTAG
402 String msg =
"Calling internal fitness provider. "+
NL;
405 double fitVal = Double.NaN;
413 }
catch (Exception e) {
417 if (Double.isNaN(fitVal))
425 "#InternalFitness: NaN value");
Task that builds a graph by appending a given combination of fragments onto a given list of attachmen...
General set of constants used in DENOPTIM.
static final String UNREADABLEFILEPOSTFIX
Postfix used to mark a file that cannot be read.
static final String PROVENANCE
SDF tag containing provenance data for a graph.
static final String CANDIDATE2DEXTENSION
Extension of output file with 2D picture of candidate.
static final String ATMPROPVERTEXID
String tag of Atom property used to store the unique ID of the Vertex corresponding to the molecular ...
static final String UNIQUEIDTAG
SDF tag containing the unique identifier of a candidate.
static final String MOLERRORTAG
SDF tag containing errors during execution of molecule specific tasks.
static final String FITFILENAMEEXTOUT
Ending and extension of output file of external fitness provider.
static final String FITNESSTAG
SDF tag containing the fitness of a candidate.
static final String FITFILENAMEEXTIN
Ending and extension of input file of external fitness provider.
Settings defining the calculation of fitness.
String getExternalFitnessProvider()
Gets the pathname of the external executable file.
String getExternalFitnessProviderInterpreter()
Gets the interpreter used to run the external fitness provider.
boolean useExternalFitness
Flag indication we want to use external fitness provider.
String getFitnessExpression()
List< DescriptorForFitness > getDescriptors()
boolean makePictures
Flag controlling production of png graphics for each candidate.
boolean writeCandidatesOnDisk
Flag requesting to write a file that collects all info on an evaluated candidate, i....
DENOPTIM's (internal) fitness provider calculates the value of Variables that are used in an expressi...
double getFitness(IAtomContainer iac)
Calculated the fitness according to the current configuration.
A candidate is the combination of a denoptim graph with molecular representation and may include also...
void setSDFFile(String molFile)
void setImageFile(String imgFile)
void setFitness(double fitness)
void setError(String error)
void setChemicalRepresentation(IAtomContainer iac)
Just place the argument in the IAtomContainer field of this object.
Container for the list of vertices and the edges that connect them.
void cleanup()
Wipes the data in this graph.
Utility methods for input/output.
static void writeSDFFile(String fileName, IAtomContainer mol)
Writes IAtomContainer to SDF file.
static void writeCandidateToFile(File file, Candidate candidate, boolean append)
Writes one candidate item to file.
static List< IAtomContainer > readAllAtomContainers(File file)
Returns a single collection with all atom containers found in a file of any format.
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.
Logger getLogger()
Get the name of the program specific logger.
Randomizer getRandomizer()
Returns the current program-specific randomizer.
Task that assesses the fitness of a given graph.
DGraph dGraph
The graph representation of the entity to evaluate.
String fitProvInputFile
The file where we store the input to the fitness provider.
void runFitnessProvider()
This method runs the actual evaluation of the fitness, whether that is run internally (i....
boolean runExternalFitness()
FitnessTask(FitnessParameters settings, Candidate c)
String fitProvUIDFile
The file where we store the list of unique identifiers or previously evaluated candidates.
FitnessParameters fitnessSettings
Settings for the calculation of the fitness.
boolean fitnessIsRequired
Flag specifying if a valid fitness value is required to consider the task successfully completed.
boolean runInternalFitness()
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.
String fitProvPNGFile
The file where we store the graphical representation of the candidate (i.e., a picture).
void runProcess()
Run the process associated with the command.
int getExitCode()
Get the exit code returned by the sub-process.
String getErrorOutput()
Get the content of the error output for the process.
A task that can throw exceptions.
File workDir
The file system location where we want to be placed when doing the work.
Object lock
Lock for addressing synchronization issues.
ProcessHandler processHandler
Executor for external bash script.
String errMsg
Error message produced by any subtask.
boolean hasException
Flag about exception.
final String NL
System-dependent line separator (newline)
Throwable thrownExc
Exception thrown.
Utilities for molecule conversion.
static void moleculeToPNG(IAtomContainer mol, String filename, Logger logger)
Generate a PNG image from molecule mol
static synchronized int getUniqueTaskIndex()
Unique counter for tasks.