19package denoptim.programs.fragmenter;
21import java.io.BufferedReader;
23import java.io.IOException;
24import java.io.InputStreamReader;
25import java.lang.reflect.Field;
26import java.text.SimpleDateFormat;
27import java.util.ArrayList;
29import java.util.HashMap;
30import java.util.HashSet;
31import java.util.LinkedHashMap;
35import java.util.concurrent.atomic.AtomicInteger;
36import java.util.logging.Level;
38import denoptim.constants.DENOPTIMConstants;
39import denoptim.exception.DENOPTIMException;
40import denoptim.files.FileFormat;
41import denoptim.files.FileUtils;
42import denoptim.fragmenter.FragmentClusterer;
43import denoptim.fragmenter.ScaffoldingPolicy;
44import denoptim.graph.DGraph;
45import denoptim.graph.Template.ContractLevel;
46import denoptim.graph.Vertex;
47import denoptim.graph.Vertex.BBType;
48import denoptim.io.DenoptimIO;
49import denoptim.logging.StaticLogger;
50import denoptim.programs.RunTimeParameters;
51import denoptim.utils.FormulaUtils;
78 private LinkedHashMap<String, String>
formulae;
162 new HashMap<String,Double>();
170 new HashSet<Map<String,Double>>();
512 this.cutRulesFile = pathname;
557 this.doCheckFormula = checkFormula;
733 Map<String, Double> formulaMax)
735 this.formulaCriteriaLessThan = formulaMax;
1047 this.scaffoldingPolicy = sp;
1096 switch (key.toUpperCase())
1102 case "STRUCTURESFILE=":
1106 case "FORMULATXTFILE=":
1111 case "PREFILTERSMARTS=":
1116 case "CUTTINGRULESFILE=":
1121 case "EXTRACTFROMGRAPHS=":
1126 case "ADDEXPLICITHYDROGEN":
1130 case "UNSETTOSINGLEBO":
1134 case "IGNORABLEFRAGMENTS=":
1139 case "TARGETFRAGMENTS=":
1144 case "ISOMORPHICSAMPLESIZE=":
1147 }
catch (Throwable t)
1149 msg =
"Unable to parse value of " + key +
": '" + value +
"'";
1156 case "REMOVEDUPLICATES":
1163 }
catch (Throwable t)
1165 msg =
"Unable to parse value of " + key +
": '" + value +
"'";
1170 case "REJECTMINORISOTOPES":
1175 case "REJECTELEMENT=":
1180 case "REJFORMULALESSTHAN=":
1183 msg =
"Attempt to specify more than one criterion for "
1184 +
"rejecting fragments based on a lower-limit "
1185 +
"molecular formula. ";
1188 Map<String,Double> elSymbolsCount =
null;
1191 }
catch (Throwable t)
1193 msg =
"Unable to parse value of " + key +
": '" + value +
"'";
1200 case "REJFORMULAMORETHAN=":
1201 Map<String,Double> elSymbolsCount2=
null;
1204 }
catch (Throwable t)
1206 msg =
"Unable to parse value of " + key +
": '" + value +
"'";
1213 case "REJECTAPCLASS=":
1218 case "REJECTAPCLASSCOMBINATION=":
1219 String[] lst = value.split(
"\\s+");
1224 case "MAXFRAGSIZE=":
1227 }
catch (Throwable t)
1229 msg =
"Unable to parse value of " + key +
": '" + value +
"'";
1235 case "MINFRAGSIZE=":
1238 }
catch (Throwable t)
1240 msg =
"Unable to parse value of " + key +
": '" + value +
"'";
1246 case "REJECTSMARTS=":
1251 case "RETAINSMARTS=":
1256 case "CLUSTERIZEANDCOLLECT=":
1259 switch (value.trim().toUpperCase())
1271 + key +
": '" + value +
"'");
1275 case "SAVECLUSTERS":
1280 case "SIZEUNIMODALPOPULATION=":
1284 case "MAXNOISEUNIMODALPOPULATION=":
1288 case "SDWEIGHTUNIMODALPOPULATION=":
1292 case "SCAFFOLDINGPOLICY=":
1293 String[] words = value.split(
"\\s+");
1296 words[0].toUpperCase());
1306 scaffoldingPolicy.label = words[1];
1308 }
catch (Throwable t)
1310 msg =
"Unable to parse value of " + key +
": '" + value +
"'";
1315 case "EMBEDRINGSINTEMPLATES=":
1321 case "RINGEMBEDDINGCONTRACT=":
1323 if (value.length() > 0)
1330 case "FRAGMENTATIONTEMPLATE=":
1337 case "BONDSAROUNDTOPOCRITICATOM=":
1349 case "PARALLELTASKS=":
1356 msg =
"Unable to understand value " + key +
"'" + value +
"'";
1368 msg =
"Unable to understand value " + key +
"'" + value +
"'";
1374 msg =
"Keyword " + key +
" is not a known Fragmenter-"
1375 +
"related keyword. Check input files.";
1397 List<CuttingRule> defaultCuttingRules =
new ArrayList<CuttingRule>();
1398 BufferedReader reader =
null;
1400 reader =
new BufferedReader(
1401 new InputStreamReader(classLoader.getResourceAsStream(
1402 "data/cutting_rules")));
1409 return defaultCuttingRules;
1421 if (!
workDir.equals(System.getProperty(
"user.dir")))
1427 "ISOMORPHICSAMPLESIZE");
1468 }
catch (Throwable e)
1481 }
catch (Throwable e)
1494 }
catch (Throwable e)
1520 +
"Output files associated with the current run are "
1530 String fileSep = System.getProperty(
"file.separator");
1531 boolean success =
false;
1534 SimpleDateFormat sdf =
new SimpleDateFormat(
"yyyyMMddkkmmss");
1535 String str =
"FRG" + sdf.format(
new Date());
1536 workDir = curDir + fileSep + str;
1553 StringBuilder sb =
new StringBuilder(1024);
1555 for (Field f : this.getClass().getDeclaredFields())
1559 sb.append(f.getName()).append(
" = ").append(
1560 f.get(
this)).append(
NL);
1565 +
" parameters. Cause: " + t);
1571 sb.append(otherCollector.getPrintedList());
1573 return sb.toString();
1713 this.useCentroidsAsRepresentativeConformer =
General set of constants used in DENOPTIM.
static final String MWSLOTFRAGSUNQFILENANEEND
Final part of filename used to collect unique fragments in a certain molecular weight slot.
static final String EOL
new line character
static final FileFormat TMPFRAGFILEFORMAT
Format for intermediate files used during fragmentation.
static final String MWSLOTFRAGSFILENAMEROOT
Initial part of filename used to collect fragments belonging to a certain molecular weight slot.
static final String MWSLOTFRAGSALLFILENANEEND
Final part of filename used to collect all samples fragments in a certain molecular weight slot inclu...
static boolean createDirectory(String fileName)
Creates a directory.
static void addToRecentFiles(String fileName, FileFormat ff)
Appends an entry to the list of recent files.
Utility methods for input/output.
static LinkedHashMap< String, String > readCSDFormulae(File file)
Read molecular formula from TXT data representation produced by Cambridge Structural Database tools (...
static void readCuttingRules(BufferedReader reader, List< CuttingRule > cutRules, String source)
Read cutting rules from a stream.
static ArrayList< DGraph > readDENOPTIMGraphsFromFile(File inFile)
Reads a list of DGraphs from file.
static ArrayList< Vertex > readVertexes(File file, Vertex.BBType bbt)
Reads Vertexes from any file that can contain such items.
static final String FS
File separator from system.
Logger class for DENOPTIM.
static final Logger appLogger
Collection of parameters controlling the behavior of the software.
Map< ParametersType, RunTimeParameters > otherParameters
Collection of other parameters by type.
boolean isMaster
Flag signaling this is the master collection of parameters.
String getWorkDirectory()
Gets the pathname to the working directory.
static boolean readYesNoTrueFalse(String s)
Reads a string searching for any common way to say either yes/true (including shorthand t/y) or no/fa...
void ensureFileExists(String pathname)
Ensures a pathname does lead to an existing file or triggers an error.
String paramTypeName()
Returns a string defining the type the parameters collected here.
void ensureIsPositive(String paramName, int value, String paramKey)
Ensures that a parameter is a positive number (x>=0) or triggers an error.
void checkOtherParameters()
Checks any of the parameter collections contained in this instance.
String workDir
Working directory.
final String NL
New line character.
void processOtherParameters()
Processes any of the parameter collections contained in this instance.
int verbosity
Verbosity level for logger.
void ensureFileExistsIfSet(String pathname)
Ensures a pathname is not empty nor null and that it does lead to an existing file or triggers an err...
Parameters controlling execution of the fragmenter.
String structuresFile
Pathname to the file containing the structures of the molecules to fragment or the fragments to proce...
void setEmbeddedRingsContract(ContractLevel embeddedRingsContract)
double getLinearAngleLimit()
void setFragRejectionSMARTS(Map< String, String > fragRejectionSMARTS)
String getCuttingRulesFilePathname()
void setRejectedAPClassCombinations(Set< String[]> rejectedAPClassCombinations)
void setSaveClustersOfConformerToFile(boolean saveClustersOfConformerToFile)
Sets the flag requesting to print clusters of fragments to file upon extraction of the most represent...
void setCuttingRules(List< CuttingRule > cuttingRules)
Assigns the cutting rules loaded from the input.
boolean doFragmentation()
void setStructuresFile(String structuresFile)
Sets the pathname of the file containing input structures.
ArrayList< Vertex > getIgnorableFragments()
void setSizeUnimodalPop(int sizeUnimodalPop)
Sets the size of the population of normally distributed noise-distorted population used to define the...
void setFragmentationTmpls(List< DGraph > fragmentationTmpls)
Sets the list of graph templates for fragmentation.
double factorForSDOnStatsOfUnimodalPop
Factor used to multiply the standard deviation when adding it to the mean of the RMSD for a unimodal ...
void setCheckFormula(boolean checkFormula)
Sets the value of the flag controlling the execution of elemental analysis on the structures.
Set< String > preFilterSMARTS
SMARTS identifying substructures that lead to rejection of a structure before fragmentation.
void setMinFragHeavyAtomCount(int minFragHeavyAtomCount)
Map< String, File > getMWSlotToAllFragsFile()
Map< String, File > mwSlotToUnqFragsFile
Mapping of the molecular weight slot identifier to the file collecting unique fragments belonging to ...
void setFactorForSDOnStatsOfUnimodalPop(double factorForSDOnStatsOfUnimodalPop)
Sets the weight of the standard deviation when calculating the RMSD threshold from the statistics of ...
String cutRulesFile
Pathname to the file containing the cutting rules.
String formulaeFile
Pathname to the file containing the formulae of the molecules to fragment.
ContractLevel embeddedRingsContract
Type of constrain defined for any template generated upon conversion of molecules into DGraph.
void setRejectedFormulaMoreThan(Set< Map< String, Double > > formulaCriteriaMoreThan)
boolean doRejectWeirdIsotopes
Flag requesting to reject fragments with minor isotopes.
boolean isSaveClustersOfConformerToFile()
boolean doManageIsomorphicFamilies
int maxBufferShellSize
Maximum number of buffer shells to consider for fragmentation.
boolean doExtactRepresentativeConformer()
void checkParameters()
Evaluate consistency of input parameters.
void interpretKeyword(String key, String value)
Processes a keyword/value pair and assign the related parameters.
void setFragRetentionSMARTS(Map< String, String > fragRetentionSMARTS)
final Object MANAGEMWSLOTSSLOCK
Synchronization lock for manipulating a) the collections (i.e., MW slots) of fragments produced by mu...
double getFactorForSDOnStatsOfUnimodalPop()
List< DGraph > getFragmentationTmpls()
Map< String, Double > getRejectedFormulaLessThan()
boolean doAddDuOnLinearity
Flag requesting to add dummy atoms on linearities.
boolean doPreFilter
Flag requesting the pre-fragmentation filtering of the structures.
double linearAngleLimit
Upper limit for an angle before it is treated as "flat" ("linear") angle, i.e., close enough to 180 D...
int getMinFragHeavyAtomCount()
Map< String, File > getMWSlotToUnqFragsFile()
int minFragHeavyAtomCount
Lower limit for number of non-H atoms in fragments.
void setAddExplicitH(boolean addExplicitH)
Give true to add explicit H atoms on all atoms.
boolean doFiltering
Flag requesting to do post-fragmentation processing of fragments, i.e., application of all filtration...
void setUseCentroidsAsRepresentativeConformer(boolean useCentroidsAsRepresentativeConformer)
void setRejectedFormulaLessThan(Map< String, Double > formulaMax)
Set< Map< String, Double > > formulaCriteriaMoreThan
Upper limits of formula-based criteria for fragment rejection.
String fragmentationTmplFile
Pathname to file containing a graph to be used as template for fragmentation.
boolean doFragmentation
Flag requesting the fragmentation of the structures.
ScaffoldingPolicy getScaffoldingPolicy()
void setNumTasks(int numParallelTasks)
Sets the number of parallel tasks to run.
Set< String > getRejectedElements()
Set< String > getPreFiltrationSMARTS()
AtomicInteger unqIsomorphicFamilyId
Unique identifier of a family of isomorphic versions of a fragment,.
void setLinearAngleLimit(double linearAngleLimit)
Sets the upper limit for an angle before it is treated as "flat" angle, i.e., close enough to 180 DEG...
boolean doAddDuOnLinearity()
List< CuttingRule > cuttingRules
List of cutting rules sorted by priority.
String getPrintedList()
Returns the list of parameters in a string with newline characters as delimiters.
File getMWSlotFileNameAllFrags(String mwSlotId)
Builds the pathname of the file meant to hold all isomorphic fragments from a given MW slot.
double getMaxNoiseUnimodalPop()
int getIsomorphicSampleSize()
Set< String > rejectedAPClasses
The initial part of APClasses that lead to rejection of a fragment.
Map< String, String > getFragRetentionSMARTS()
int getMaxFragHeavyAtomCount()
boolean doExtactRepresentativeConformer
Flag signaling the request to analyze each isomorphic family to extract the most representative fragm...
ArrayList< Vertex > targetFragments
List of fragment that will be retained, i.e., any isomorphic fragment of any of these will be kept,...
boolean acceptUnsetToSingeBOApprox
Flag requesting to force-accepting the approximation that converts all unset bond orders to single bo...
boolean workingIn3D
Flag activating operations depending on 3D structure.
Map< String, File > mwSlotToAllFragsFile
Mapping of the molecular weight slot identifier to the file collecting all collected fragments belong...
Set< Map< String, Double > > getRejectedFormulaMoreThan()
List< CuttingRule > getDefaultCuttingRules(ClassLoader classLoader)
Get default cutting rules from a given class loader.
boolean doFragExtractionFromGraphs
Flag requesting to extract fragments from graphs.
void setMaxNoiseUnimodalPop(double maxNoiseUnimodalPop)
Sets the maximum noise of the population of normally distributed noise-distorted population used to d...
LinkedHashMap< String, String > getFormulae()
Set< String > rejectedElements
Symbols of elements that lead to rejection of a fragment.
boolean saveClustersOfConformerToFile
Flag requesting to print clusters of fragments to file.
void setMaxFragHeavyAtomCount(int maxFragHeavyAtomCount)
int mwSlotSize
Molecular weight slot width for collecting fragments.
void setRejectWeirdIsotopes(boolean doRejectWeirdIsotopes)
String newIsomorphicFamilyID()
Produced a new unique identifier for a family of isomorphic fragments.
boolean embedRingsInTemplate()
List< CuttingRule > getCuttingRules()
double maxNoiseUnimodalPop
Maximum amount of absolute noise used to generate normally distributed noise-distorted population of ...
Map< String, String > fragRejectionSMARTS
SMARTS leading to rejection of a fragment.
void setFormulaeFile(String formulaeFile)
Sets the pathname of the file containing molecular formula with a format respecting Cambridge Structu...
boolean doFragExtractionFromGraphs()
File getMWSlotFileNameUnqFrags(String mwSlotId)
Builds the pathname of the file meant to hold unique fragments from within a given MW slot,...
Map< String, String > getFragRejectionSMARTS()
ContractLevel getEmbeddedRingsContract()
String getStructuresFile()
boolean useCentroidsAsRepresentativeConformer
Flag requesting to same cluster centroids rather than the actual fragments that are closest to the ce...
boolean isUseCentroidsAsRepresentativeConformer()
Set< String[]> getRejectedAPClassCombinations()
void setCuttingRulesFilePathname(String pathname)
Assigns the pathname to the cutting rules file.
boolean addExplicitH
Flag requesting to add explicit H atoms.
boolean doCheckFormula
Flag requesting the execution of elemental analysis and comparison of the content of the structure fi...
void setEmbedRingsInTemplate(boolean embedRingsInTemplate)
Set< String > getRejectedAPClasses()
int maxFragHeavyAtomCount
Upper limit for number of non-H atoms in fragments.
int numParallelTasks
Number of parallel tasks to run.
Map< String, Double > formulaCriteriaLessThan
Lower limits of formula-based criteria for fragment rejection.
Map< String, String > fragRetentionSMARTS
SMARTS leading to retention of a fragment.
int sizeUnimodalPop
Size of on-the-fly generated, normally distributed noise-distorted population of geometries used to d...
void setRejectedAPClasses(Set< String > rejectedAPClasses)
boolean isStandaloneFragmentClustering
Flag requesting to run fragment clusterer in stand-alone fashion.
boolean acceptUnsetToSingeBO()
int getMaxBufferShellSize()
boolean doRejectWeirdIsotopes()
ScaffoldingPolicy scaffoldingPolicy
The policy for defining the scaffold vertex in a graph that does not have such a BBType.
boolean isStandaloneFragmentClustering()
void setScaffoldingPolicy(ScaffoldingPolicy sp)
String ignorableFragmentsFile
Pathname to file with fragments that can be ignored.
FragmenterParameters()
Constructor.
ArrayList< Vertex > getTargetFragments()
boolean doManageIsomorphicFamilies()
ArrayList< Vertex > ignorableFragments
List of fragment that can be rejected.
void setRejectedElements(Set< String > rejectedElements)
void setIsomorphicSampleSize(int isomorphicSampleSize)
void processParameters()
Processes all parameters and initialize related objects.
void createWorkingDirectory()
List< DGraph > fragmentationTmpls
List of graphs to be used as templates for fragmentation.
LinkedHashMap< String, String > formulae
Molecular formula read-in from CSD file.
void setMWSlotSize(int mwSlotSize)
boolean embedRingsInTemplate
Flag that enables the embedding of rings in templates upon conversion of molecules into DGraph.
int isomorphicSampleSize
Size of the sample of isomorphic fragments to collect.
Map< String, Integer > isomorphsCount
Counts of isomorphic versions of each known fragment generated in a fragmentation process.
void setMWSlotToAllFragsFile(Map< String, File > mwSlotToAllFragsFile)
static final int MAXISOMORPHICSAMPLESIZE
Maximum isomorphic sample size.
List< CuttingRule > getDefaultCuttingRules()
Get default cutting rules from the class loader of the current class.
void setWorkingIn3D(boolean workingIn3D)
Sets boolean variable workingIn3D.
Map< String, Integer > getIsomorphsCount()
String targetFragmentsFile
Pathname to file with fragments that will be retained, i.e., any isomorphic fragment of any of these ...
Set< String[]> rejectedAPClassCombinations
Combination of strings matching the beginning of APClass names that lead to rejection of a fragment.
Defines how to define the scaffold vertex of a graph.
Enum specifying to what extent the template's inner graph can be changed.
FREE
Inner graphs are free to change within the confines of the required AttachmentPoints.
The type of building block.
Identifier of the type of parameters.
FRG_PARAMS
Parameters controlling the fragmenter.