19package denoptim.graph;
23import org.openscience.cdk.CDKConstants;
24import org.openscience.cdk.interfaces.IAtomContainer;
25import org.openscience.cdk.interfaces.IChemObjectBuilder;
26import org.openscience.cdk.silent.SilentChemObjectBuilder;
28import denoptim.constants.DENOPTIMConstants;
29import denoptim.exception.DENOPTIMException;
30import denoptim.io.DenoptimIO;
31import denoptim.utils.MoleculeUtils;
39public class Candidate implements Comparable<Candidate>, Cloneable
54 private IAtomContainer
iac;
170 this.sdfFile = molFile;
196 this(
iac, useFragSpace,
false);
220 this.uid =
"UNDEFINED";
221 this.smiles =
"UNDEFINED";
222 this.hasFitness =
false;
226 if (
iac.getProperty(CDKConstants.TITLE) !=
null)
228 this.name =
iac.getProperty(CDKConstants.TITLE).toString();
233 this.error =
iac.getProperty(
239 String fitprp =
iac.getProperty(
241 double fitVal = Double.parseDouble(fitprp);
242 if (Double.isNaN(fitVal))
244 String msg =
"Cannot build Candidate from "
245 +
"IAtomContainer: Fitness value is NaN!";
248 this.fitness = fitVal;
249 this.hasFitness =
true;
254 this.level = Integer.parseInt(
iac.getProperty(
260 this.smiles =
iac.getProperty(
266 this.uid =
iac.getProperty(
268 }
catch (Exception e) {
280 this.comment =
iac.getProperty(
308 if (
iac.getProperty(CDKConstants.TITLE) !=
null)
310 cand.name =
iac.getProperty(CDKConstants.TITLE).toString();
315 cand.error =
iac.getProperty(
321 String fitprp =
iac.getProperty(
323 double fitVal = Double.parseDouble(fitprp);
324 if (Double.isNaN(fitVal))
326 String msg =
"Cannot build Candidate from "
327 +
"IAtomContainer: Fitness value is NaN!";
330 cand.fitness = fitVal;
331 cand.hasFitness =
true;
336 cand.level = Integer.parseInt(
iac.getProperty(
342 cand.smiles =
iac.getProperty(
348 }
catch (Exception e) {
354 +
"Candidate. No property '"
356 +
"' in the atom container.", e);
362 cand.comment =
iac.getProperty(
404 IAtomContainer iacForFitFile =
iac;
405 if (iacForFitFile==
null)
407 IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
408 iacForFitFile = builder.newAtomContainer();
410 iacForFitFile.setProperty(CDKConstants.TITLE,
name);
426 return iacForFitFile;
447 this.sdfFile = molFile;
483 this.hasFitness =
true;
632 if (this.fitness > other.
fitness)
634 else if (this.fitness < other.
fitness)
652 StringBuilder sb =
new StringBuilder(16);
656 sb.append(String.format(
"%-20s",
name));
658 sb.append(String.format(
"%-20s",
this.graph.getGraphId()));
659 sb.append(String.format(
"%-30s",
uid));
660 sb.append(String.format(
"%12.3f",
fitness));
662 return sb.toString();
693 if (this.iac !=
null)
General set of constants used in DENOPTIM.
static final String GRAPHTAG
SDF tag containing graph encoding.
static final String PROVENANCE
SDF tag containing provenance data for a graph.
static final String GRAPHLEVELTAG
SDF tag defining the graph generating level in an FSE run.
static final String GCODETAG
SDF tag containing graph ID.
static final String UNIQUEIDTAG
SDF tag containing the unique identifier of a candidate.
static final String GRAPHJSONTAG
SDF tag containing graph encoding in JSON format.
static final String MOLERRORTAG
SDF tag containing errors during execution of molecule specific tasks.
static final String SMILESTAG
SDF tag containing the SMILES of a candidate.
static final String FITNESSTAG
SDF tag containing the fitness of a candidate.
A candidate is the combination of a denoptim graph with molecular representation and may include also...
String sdfFile
Pathname to SDF file.
void setLevel(int lev)
Sets level that generated this graph in a fragment space exploration experiment.
Candidate(String name, DGraph graph, double fitness, String uid, String smiles)
int getLevel()
Returns the level that generated this graph in a fragment space exploration experiment.
boolean hasFitness
Flag signaling the presence of a fitness value associated.
void setSDFFile(String molFile)
int compareTo(Candidate other)
void cleanup()
Clear the graph describing this candidate.
void setGeneration(int genId)
String uid
Unique identifier of this candidate.
Candidate(IAtomContainer iac, boolean useFragSpace)
Builds a candidate from the SDF representation of an atom container.
int level
Level that generated this graph in fragment space exploration.
Candidate(IAtomContainer iac, boolean useFragSpace, boolean allowNoUID)
Builds a candidate from the SDF representation of an atom container.
void setSmiles(String smiles)
String smiles
SMILES representation.
void setImageFile(String imgFile)
String error
Error that prevented calculation of the fitness.
IAtomContainer iac
Chemical object representation.
String imgFile
Pathname to an image (i.e., PNG file)
DGraph graph
Graph representation.
Candidate(String name, DGraph graph)
void setFitness(double fitness)
void setGraph(DGraph graph)
void setComments(String str)
int generationId
ID of the generation at which this candidate was generated.
static Candidate fromAtomContainerNoGraph(IAtomContainer iac, boolean allowNoUID)
Wraps an atom container as a candidate even if a graph is not available.
int getGeneration()
The generation this candidate belong to is that in which it was generated.
String comment
Any comments.
void setError(String error)
void setName(String name)
IAtomContainer getFitnessProviderOutputRepresentation()
Returns an atom container representing this item in a way that is compatible for writing this item to...
void setChemicalRepresentation(IAtomContainer iac)
Just place the argument in the IAtomContainer field of this object.
String name
Name of this candidate (not guaranteed to be unique)
IAtomContainer getChemicalRepresentation()
Returns the atom container representing this candidate.
Candidate(String name, DGraph graph, String uid, String smiles, String molFile, String imgFile, String comment, int generationId, int level)
double fitness
fitness value
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.
void setCandidateOwner(Candidate candidate)
Sets the reference to the candidate item that is defined by this graph.
DGraph clone()
Returns almost "deep-copy" of this graph.
void cleanup()
Wipes the data in this graph.
Utility methods for input/output.
static DGraph readGraphFromSDFileIAC(IAtomContainer mol)
Converts an atom container read in from an SDF file into a graph, if possible.
Utilities for molecule conversion.
static IAtomContainer makeSameAs(IAtomContainer mol)
Constructs a copy of an atom container, i.e., a molecule that reflects the one given in the input arg...