19package denoptim.combinatorial;
22import java.util.ArrayList;
23import java.util.HashMap;
25import java.util.logging.Level;
27import org.openscience.cdk.CDKConstants;
28import org.openscience.cdk.interfaces.IAtomContainer;
30import denoptim.constants.DENOPTIMConstants;
31import denoptim.exception.DENOPTIMException;
32import denoptim.fitness.FitnessParameters;
33import denoptim.fragspace.FragmentSpace;
34import denoptim.fragspace.FragmentSpaceParameters;
35import denoptim.fragspace.FragsCombination;
36import denoptim.fragspace.IdFragmentAndAP;
37import denoptim.graph.Candidate;
38import denoptim.graph.DGraph;
39import denoptim.graph.SymmetricVertexes;
40import denoptim.graph.Vertex;
41import denoptim.molecularmodeling.ThreeDimTreeBuilder;
42import denoptim.programs.RunTimeParameters.ParametersType;
43import denoptim.programs.combinatorial.CEBLParameters;
44import denoptim.task.FitnessTask;
45import denoptim.utils.GeneralUtils;
46import denoptim.utils.GraphUtils;
47import denoptim.utils.MoleculeUtils;
118 this.ceblSettings = settings;
129 rootId = molGraph.getGraphId();
131 this.workDir =
new File(
workDir);
203 this.nextIds =
new ArrayList<Integer>();
215 public Object
call() throws Exception
219 String msg =
"Call GraphBuildingTask " +
id
221 + DENOPTIMConstants.EOL +
" - Fragsments to add: ";
224 msg = msg + DENOPTIMConstants.EOL
227 msg = msg + DENOPTIMConstants.EOL +
" - RootGraph: " +
dGraph;
239 Map<Integer, SymmetricVertexes> newSymSets =
240 new HashMap<Integer, SymmetricVertexes>();
243 long sVId = srcAp.getVertexId();
244 int sApId = srcAp.getApId();
265 if (newSymSets.containsKey(tSymSetID))
267 newSymSets.get(tSymSetID).add(trgVrtx);
271 newSymSets.put(tSymSetID, ss);
275 trgVrtx.
getAP(tApId));
279 for (Integer ssId : newSymSets.keySet())
303 boolean needsCaps =
false;
309 ArrayList<DGraph> altCyclicGraphs =
new ArrayList<DGraph>();
315 int sz = altCyclicGraphs.size();
317 if (sz>0 && !needsCaps)
324 + sz +
" cyclic alternatives.";
335 for (
int ig = 0; ig<sz-1; ig++)
337 lst = lst + altCyclicGraphs.get(ig).getGraphId()+
", ";
339 lst = lst + altCyclicGraphs.get(sz-1).getGraphId() +
"]";
342 for (
int ig = 0; ig<altCyclicGraphs.size(); ig++)
344 DGraph g = altCyclicGraphs.get(ig);
350 +
" is cyclic alternative "
351 + (ig+1) +
"/" + altCyclicGraphs.size()
359 Object[] altRes =
new Object[5];
382 smiles =
"FAIL: NO SMILES GENERATED";
390 if (inchiKey ==
null)
392 inchiKey =
"UNDEFINED_INCHI";
394 altRes[0] = inchiKey;
413 msg =
"Exception while working on cyclic graph "+g;
414 throw new Throwable(msg,t);
441 Object[] fseRes =
new Object[5];
458 throw new Exception(t);
474 String molinchi = res[0].toString().trim();
500 String molsmiles = res[1].toString().trim();
502 String parentGraphId = res[3].toString().trim();
503 String
level = res[4].toString().trim();
509 String molName = DENOPTIMConstants.FITFILENAMEPREFIX
512 fitProvMol.setProperty(CDKConstants.TITLE, molName);
Helper methods for the exploration of the fragment space.
static void storeGraphOfLevel(CEBLParameters settings, DGraph graph, int level, int rootId, ArrayList< Integer > nextIds)
Serialize a DENOPTIMGraph to a file.
Task that builds a graph by appending a given combination of fragments onto a given list of attachmen...
ThreeDimTreeBuilder tb3d
Tool for generating 3D models assembling 3D building blocks.
int getNumberOfSubTasks()
Object call()
Calls the task.
GraphBuildingTask(CEBLParameters settings, DGraph molGraph, FragsCombination fragsToAdd, int level, String workDir, int verbosity)
Constructor.
FragsCombination fragsToAdd
Pointer defining the active combination for this task.
FragmentSpace fragSpace
The fragment space.
int rootId
The graph ID of the root graph.
void sendToFitnessProvider(Object[] res)
ArrayList< Integer > getNextIds()
Returns the set of indeces that identify the position of the the (next) combination of fragment in th...
int nSubTasks
Number of subtasks.
int graphId
GraphID: may be from the original graph or from its latest generated cyclic alternative.
ArrayList< Integer > nextIds
Vector of indexes identifying the next combination of fragments.
CEBLParameters ceblSettings
Collection of settings controlling the execution of the task.
int getRootId()
Returns the graphID of the root graph.
void setNextIds(ArrayList< Integer > nextIds)
Set the set of indexes that identify the position of the the (next) combination of fragment in the sp...
int getGraphId()
Returns the graphID of the original graph or of the latest cyclic alternative.
int level
The active level of modification.
General set of constants used in DENOPTIM.
static final int MOLDIGITS
static final String INCHIKEYTAG
SDF tag containing the unique identifier of a candidate.
static final String CANDIDATE2DEXTENSION
Extension of output file with 2D picture of candidate.
static final String PARENTGRAPHTAG
SDF tag defining the ID of a parent graph (used in FSE)
static final String GRAPHLEVELTAG
SDF tag defining the graph generating level in an FSE run.
static final String UNIQUEIDTAG
SDF tag containing the unique identifier of a candidate.
static final String SMILESTAG
SDF tag containing the SMILES of a candidate.
static final String FITFILENAMEEXTOUT
Ending and extension of output file of external fitness provider.
static final String FITFILENAMEEXTIN
Ending and extension of input file of external fitness provider.
Settings defining the calculation of fitness.
Class defining a space of building blocks.
boolean useAPclassBasedApproach()
Check usage of APClass-based approach, i.e., uses attachment points with annotated data (i....
Parameters defining the fragment space.
FragmentSpace getFragmentSpace()
Data structure identifying a combination of one or more pairs of attachment points located on specifi...
Data structure containing information that identifies a single AP of a vertex/fragment.
BBType getVertexMolType()
A candidate is the combination of a denoptim graph with molecular representation and may include also...
void setSmiles(String smiles)
void setGraph(DGraph graph)
void setName(String name)
Container for the list of vertices and the edges that connect them.
Vertex getVertexWithId(long vid)
Searches for a vertex with the given identifier.
boolean graphNeedsCappingGroups(FragmentSpace fragSpace)
Checks the graph for unused APs that need to be capped.
Object[] checkConsistency(RunTimeParameters settings)
Peeks into this graph to derive a preliminary chemical representation with SMILES and InChIKey.
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,...
DGraph clone()
Returns almost "deep-copy" of this graph.
ArrayList< DGraph > makeAllGraphsWithDifferentRingSets(RunTimeParameters settings)
Evaluates the possibility of closing rings in this graph and generates all alternative graphs resulti...
void replaceUnusedRCVsWithCapps(FragmentSpace fragSpace)
Removes unused ring-closing vertices.
void addSymmetricSetOfVertices(SymmetricVertexes symSet)
Adds a symmetric set of vertices to this graph.
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...
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
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.
Tool to build build three-dimensional (3D) tree-like molecular structures from DGraph.
void setAlignBBsIn3D(boolean align)
Sets the flag that controls whether building blocks have to be aligned according to the AP vectors or...
IAtomContainer convertGraphTo3DAtomContainer(DGraph graph)
Created a three-dimensional molecular representation from a given DGraph.
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 the combinatorial algorithm for exploration of a fragment space b...
boolean submitFitnessTask()
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....
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.
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).
File workDir
The file system location where we want to be placed when doing the work.
boolean completed
Flag about completion.
int verbosity
Verbosity level.
boolean hasException
Flag about exception.
final String SEP
System-dependent file separator.
Throwable thrownExc
Exception thrown.
static String getPaddedString(int count, int number)
returns the padded string with zeroes placed to the left of 'number' up to reach the desired number o...
static synchronized int getUniqueMoleculeIndex()
Unique counter for the number of molecules generated.
static synchronized int getUniqueGraphIndex()
Unique counter for the number of graphs generated.
Utilities for molecule conversion.
static String getInChIKeyForMolecule(IAtomContainer mol, Logger logger)
Generates the InChI key for the given atom container.
static String getSMILESForMolecule(IAtomContainer mol, Logger logger)
Returns the SMILES representation of the molecule.
The type of building block.
Identifier of the type of parameters.
FS_PARAMS
Parameters pertaining the definition of the fragment space.
FIT_PARAMS
Parameters pertaining the calculation of fitness (i.e., the fitness provider).