19package denoptim.fragmenter;
22import java.io.FileInputStream;
23import java.io.FileNotFoundException;
24import java.io.IOException;
25import java.util.ArrayList;
26import java.util.Iterator;
28import java.util.logging.FileHandler;
29import java.util.logging.Handler;
30import java.util.logging.Level;
31import java.util.logging.Logger;
32import java.util.logging.SimpleFormatter;
34import org.openscience.cdk.DefaultChemObjectBuilder;
35import org.openscience.cdk.interfaces.IAtomContainer;
36import org.openscience.cdk.io.iterator.IteratingSDFReader;
38import denoptim.constants.DENOPTIMConstants;
39import denoptim.exception.DENOPTIMException;
40import denoptim.files.FileFormat;
41import denoptim.graph.FragIsomorphNode;
42import denoptim.graph.Fragment;
43import denoptim.graph.Vertex;
44import denoptim.graph.Vertex.BBType;
45import denoptim.io.DenoptimIO;
46import denoptim.programs.fragmenter.FragmenterParameters;
47import denoptim.task.Task;
48import denoptim.utils.TaskUtils;
73 private List<ClusterableFragment>
sample;
110 if (isomorphicFamily.size()==0)
112 throw new Error(
"Attempt to create a "
113 + this.getClass().getSimpleName() +
" from empty list of "
116 this.isomorphicFamilyId =
"undefinedIsoFamID";
120 List<ClusterableFragment>
sample =
new ArrayList<ClusterableFragment>();
121 for (
int i=0; i<isomorphicFamily.size(); i++)
147 Object isoFamIdObj = oldChampions.getProperty(
149 if (isoFamIdObj==
null)
151 throw new Error(
"Attempt to run analysis of isomorphic family for "
152 +
"a fragment that does not declare the identity of its "
156 this.isomorphicFamilyId = isoFamIdObj.toString();
157 String taskAndFamId = this.getClass().getSimpleName() +
"-" +
id +
"_"
162 this.logger = Logger.
getLogger(taskAndFamId);
163 int n =
logger.getHandlers().length;
164 for (
int i=0; i<n; i++)
169 + taskAndFamId +
".log";
171 SimpleFormatter formatterTxt =
new SimpleFormatter();
172 fileHdlr.setFormatter(formatterTxt);
173 logger.setUseParentHandlers(
false);
174 logger.addHandler(fileHdlr);
176 String header =
"Started logging for " + taskAndFamId;
177 logger.log(Level.INFO,header);
182 if (!this.isoFamMembersFile.exists())
184 throw new Error(
"Expected file '"
202 public Object
call() throws Exception
211 List<Fragment> representativeFragments =
null;
212 String pathname =
"";
226 List<Vertex> representativeVertexes =
new ArrayList<Vertex>();
227 representativeVertexes.addAll(representativeFragments);
229 representativeVertexes);
235 for (
int iCluster=0; iCluster<clusters.size(); iCluster++)
237 List<Vertex> clusterMembers =
new ArrayList<Vertex>();
238 clusterMembers.addAll(clusters.get(iCluster));
246 logger.log(Level.INFO,
"Analysis of isomorphic family completed.");
249 for (Handler h :
logger.getHandlers())
251 if (h instanceof FileHandler) {
274 IteratingSDFReader reader;
275 List<ClusterableFragment> result;
278 reader =
new IteratingSDFReader(
280 DefaultChemObjectBuilder.getInstance());
281 }
catch (FileNotFoundException e1)
286 +
"not be found anymore.");
296 }
catch (IOException e)
322 List<ClusterableFragment>
sample =
new ArrayList<ClusterableFragment>();
324 while (reader.hasNext())
329 logger.log(Level.INFO,
"Sample reached the maximum size: "
331 +
". Ignoring any further fragment.");
337 IAtomContainer mol = reader.next();
345 if (mol.getTitle()!=
null && !mol.getTitle().isBlank())
346 molName =
"'" + mol.getTitle() +
"' ";
354 logger.log(Level.FINE,
"Adding fragment " + molId
355 +
" " + molName +
"to the sample of isomorphic "
361 logger.log(Level.WARNING,
"Skipping fragment " + molId
362 +
" " + molName +
"because it could not "
363 +
"be converted into a fragment.");
368 logger.log(Level.FINE,
"Skipping fragment " + molId
369 +
" " + molName +
"because it does not "
376 molId +
" " + molName);
380 +
" contains " +
sample.size() +
" fragments.");
422 logger.log(Level.WARNING,
"Skipping fragment " + fragId
424 +
"isomorphism could be found with the first "
425 +
"fragment in the sample.");
429 List<FragIsomorphNode> orderedNodes =
430 new ArrayList<FragIsomorphNode>();
General set of constants used in DENOPTIM.
static final Object ISOMORPHICFAMILYID
Property used to store the identifier of the family of isomorphic fragments that owns a fragment.
Represents a fragment that can be clustered based on the 3*N coordinate of atoms and attachment point...
void setOrderOfNodes(Collection< FragIsomorphNode > c)
Sets the order of nodes (i.e., atoms/APs) to use for geometric comparison with other fragments,...
DefaultUndirectedGraph< FragIsomorphNode, FragIsomorphEdge > getJGraphFragIsomorphism()
Class performing the alignment of Fragments.
GraphMapping< FragIsomorphNode, FragIsomorphEdge > getLowestRMSDMapping()
Returns the mapping leading to the lowest RMSD that could be found among all isomorphic mappings.
List< Fragment > getClusterCentroids()
Once the clustering is done, this method return the list of cluster centroids.
void cluster()
Runs the clustering algorithm:
List< Fragment > getNearestToClusterCentroids()
Once the clustering is done, this method return the list of fragments that are nearest to the respect...
List< List< Fragment > > getTransformedClusters()
Once the clustering is done, this method return the list of clusters.
Task that performs the various steps in the process that prepares chemical structured to be chopped,...
static String getResultsFileName(FragmenterParameters settings)
Builds the pathname of the structure file meant to hold results that are not necessarily fragments.
Class representing a continuously connected portion of chemical object holding attachment points.
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
Utility methods for input/output.
static File writeVertexesToFile(File file, FileFormat format, List< Vertex > vertexes)
Writes vertexes to file.
String getWorkDirectory()
Gets the pathname to the working directory.
Logger getLogger()
Get the name of the program specific logger.
Parameters controlling execution of the fragmenter.
boolean isSaveClustersOfConformerToFile()
File getMWSlotFileNameAllFrags(String mwSlotId)
Builds the pathname of the file meant to hold all isomorphic fragments from a given MW slot.
boolean isUseCentroidsAsRepresentativeConformer()
boolean isStandaloneFragmentClustering
Flag requesting to run fragment clusterer in stand-alone fashion.
static final int MAXISOMORPHICSAMPLESIZE
Maximum isomorphic sample size.
A task that can throw exceptions.
boolean completed
Flag about completion.
static synchronized int getUniqueTaskIndex()
Unique counter for tasks.
The type of building block.