19package denoptim.programs;
21import java.io.BufferedReader;
22import java.io.FileReader;
23import java.io.IOException;
24import java.lang.reflect.Constructor;
25import java.util.HashMap;
27import java.util.logging.ConsoleHandler;
28import java.util.logging.FileHandler;
29import java.util.logging.Level;
30import java.util.logging.Logger;
31import java.util.logging.SimpleFormatter;
32import java.util.logging.StreamHandler;
34import denoptim.exception.DENOPTIMException;
35import denoptim.files.FileUtils;
36import denoptim.fitness.FitnessParameters;
37import denoptim.fragspace.FragmentSpaceParameters;
38import denoptim.graph.rings.RingClosureParameters;
39import denoptim.main.Main.RunType;
40import denoptim.programs.combinatorial.CEBLParameters;
41import denoptim.programs.denovo.GAParameters;
42import denoptim.programs.fitnessevaluator.FRParameters;
43import denoptim.programs.fragmenter.FragmenterParameters;
44import denoptim.programs.genetweeker.GeneOpsRunnerParameters;
45import denoptim.programs.grapheditor.GraphEdParameters;
46import denoptim.programs.graphlisthandler.GraphListsHandlerParameters;
47import denoptim.programs.isomorphism.IsomorphismParameters;
48import denoptim.programs.moldecularmodelbuilder.MMBuilderParameters;
49import denoptim.utils.Randomizer;
81 protected String
workDir = System.getProperty(
"user.dir");
95 private Logger
logger = Logger.getLogger(
"DummyLogger");
113 new HashMap<ParametersType, RunTimeParameters>();
195 private Class<?> implementation;
198 CEBL_PARAMS.keywordRoot =
"FSE-";
199 GA_PARAMS.keywordRoot =
"GA-";
200 FS_PARAMS.keywordRoot =
"FS-";
201 FRG_PARAMS.keywordRoot =
"FRG-";
202 RC_PARAMS.keywordRoot =
"RC-";
203 FIT_PARAMS.keywordRoot =
"FP-";
204 FR_PARAMS.keywordRoot =
"FR-";
205 MMB_PARAM.keywordRoot =
"3DB-";
206 GO_PARAMS.keywordRoot =
"TESTGENOPS-";
207 GE_PARAMS.keywordRoot =
"GRAPHEDIT-";
208 GLH_PARAMS.keywordRoot =
"GRAPHLISTS-";
209 ISO_PARAMS.keywordRoot =
"ISOMORPHISM-";
230 return implementation;
262 public final String
NL = System.getProperty(
"line.separator");
278 this.logger.setLevel(Level.SEVERE);
311 this.workDir = pathname;
333 this.workDir = pathname;
359 innerParams.setLogger(
logger);
379 throws SecurityException, IOException
402 throws SecurityException, IOException
404 logger = Logger.getLogger(loggerIdentifier);
406 int n =
logger.getHandlers().length;
407 for (
int i=0; i<n; i++)
414 FileHandler fileHdlr =
new FileHandler(
logFile);
415 SimpleFormatter formatterTxt =
new SimpleFormatter();
416 fileHdlr.setFormatter(formatterTxt);
417 logger.setUseParentHandlers(
false);
418 logger.addHandler(fileHdlr);
419 logger.setLevel(Level.INFO);
420 String header =
"Started logging for " + loggerIdentifier;
421 logger.log(Level.INFO,header);
423 logger.addHandler(
new StreamHandler(System.out,
424 new SimpleFormatter()));
430 for (
int iH=0; iH<
logger.getHandlers().length; iH++)
438 innerParams.setLogger(
logger);
453 logger = Logger.getLogger(loggerIdentifier);
455 int n =
logger.getHandlers().length;
456 for (
int i=0; i<n; i++)
460 ConsoleHandler handler =
new ConsoleHandler();
461 handler.setFormatter(
new SimpleFormatter());
462 handler.setLevel(Level.INFO);
463 logger.addHandler(handler);
468 for (
int iH=0; iH<
logger.getHandlers().length; iH++)
476 innerParams.setLogger(
logger);
493 boolean result =
false;
494 String value = s.trim().toUpperCase();
495 if (value.equals(
"YES")
498 || value.equals(
"TRUE"))
501 }
else if (value.equals(
"NO")
504 || value.equals(
"FALSE"))
523 return Level.WARNING;
569 for (
int iH=0; iH<
logger.getHandlers().length; iH++)
577 innerParams.setVerbosity(l);
596 if (innerParams.rng!=
null)
598 rng = innerParams.rng;
599 return innerParams.rng;
606 innerParams.setRandomizer(
rng);
635 innerParams.setRandomizer(
rng);
651 innerParams.setRandomizer(
rng);
668 innerParams.setRandomizer(
rng);
683 BufferedReader br =
null;
686 br =
new BufferedReader(
new FileReader(infile));
687 while ((line = br.readLine()) !=
null)
692 catch (NumberFormatException | IOException nfe)
706 catch (IOException ioe)
722 if ((line.trim()).length() == 0)
725 if (line.startsWith(
"#"))
734 if (line.toUpperCase().startsWith(parType.keywordRoot))
740 otherParams.isMaster =
false;
765 }
catch (Exception e) {
802 otherParams.isMaster =
false;
843 String key = line.trim();
845 if (line.contains(
"="))
848 line.indexOf(
"=") + 1).trim();
849 value = line.substring(line.indexOf(
"=") + 1).trim();
893 otherCollector.checkParameters();
915 otherCollector.processParameters();
967 StringBuilder sb =
new StringBuilder(1024);
969 sb.append(
"-------------------------------------------"
970 +
"----------------------").append(
NL);
971 logger.log(Level.INFO,sb.toString());
984 if (pathname ==
null || pathname.isBlank())
989 String msg =
"ERROR! File '" + pathname +
"' not found!";
990 throw new Error(msg);
1005 String msg =
"ERROR! File '" + pathname +
"' not found!";
1006 throw new Error(msg);
1021 String msg =
"ERROR! Parameter '" + paramName +
"' is null! "
1022 +
"Please, add '" + paramType.keywordRoot + paramKey
1023 +
"' to the input parameters.";
1024 throw new Error(msg);
1039 String msg =
"ERROR! Parameter '" + paramName +
"' not striktly "
1040 +
"positive (" + value +
"). "
1041 +
"Please, use a positive value for '" + paramType.keywordRoot
1043 throw new Error(msg);
1059 String msg =
"ERROR! Parameter '" + paramName +
"' is negative ("
1061 +
"Please, use a positive value for '" + paramType.keywordRoot
1063 throw new Error(msg);
1077 if (max < value || min > value)
1079 String msg =
"ERROR! Parameter '" + paramName +
"' is not in range"
1080 + min +
" < x < " + max +
" (value: " + value +
"). "
1081 +
"Please, correct the value of '" + paramType.keywordRoot
1083 throw new Error(msg);
static boolean checkExists(String fileName)
Settings defining the calculation of fitness.
Parameters defining the fragment space.
Parameters and setting related to handling ring closures.
Collection of parameters controlling the behavior of the software.
Map< ParametersType, RunTimeParameters > otherParameters
Collection of other parameters by type.
void setRandomizer(Randomizer rng)
Sets the randomizer.
Logger startProgramSpecificLogger(String loggerIdentifier)
Starts a logger with the given name.
long getRandomSeed()
Returns the seed.
RunTimeParameters(ParametersType paramType)
Constructor.
boolean isMaster
Flag signaling this is the master collection of parameters.
boolean containsParameters(ParametersType type)
void setLogger(Logger logger)
Set the name of the program specific logger.
abstract void checkParameters()
Evaluate consistency of input parameters.
void setParameters(RunTimeParameters otherParams)
String getWorkDirectory()
Gets the pathname to the working directory.
static RunTimeParameters getInstanceFor(ParametersType paramType)
Builds the implementation of this class suitable to allocate parameters of the given type.
Randomizer startRandomizer(long seed)
Starts a program specific randomizer, i.e., a tool for generating random numbers and taking random de...
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...
abstract String getPrintedList()
Returns the list of parameters in a string with newline characters as delimiters.
void ensureFileExists(String pathname)
Ensures a pathname does lead to an existing file or triggers an error.
void interpretKeyword(String line)
Processes a string looking for keyword and a possibly associated value.
RunTimeParameters getParameters(ParametersType type)
void readParameterFile(String infile)
Read the parameter TXT file line by line and interpret its content.
Logger getLogger()
Get the name of the program specific logger.
Logger startProgramSpecificLogger(String loggerIdentifier, boolean toLogFile)
Starts a logger with the given name.
Logger logger
Program-specific logger.
void ensureIsPositiveOrZero(String paramName, int value, String paramKey)
Ensures that a parameter is a positive number (x>=0) or triggers an error.
String getLogFilePathname()
Gets the pathname to the log file.
void printParameters()
Print all parameters.
void setLogFilePathname(String pathname)
Sets the pathname to the log file.
abstract void processParameters()
Processes all parameters and initialize related objects.
void readParameterLine(String line)
void ensureNotNull(String paramName, String param, String paramKey)
Ensures that a parameter is not null or triggers an error.
String paramTypeName()
Returns a string defining the type the parameters collected here.
void ensureInRange(String paramName, int value, int min, int max, String paramKey)
Ensures that a parameter is within a range or triggers an error.
void ensureIsPositive(String paramName, int value, String paramKey)
Ensures that a parameter is a positive number (x>=0) or triggers an error.
Randomizer rng
Program-specific random numbers and random decisions generator.
void checkOtherParameters()
Checks any of the parameter collections contained in this instance.
abstract void interpretKeyword(String key, String value)
Processes a keyword/value pair and assign the related parameters.
String workDir
Working directory.
Logger startConsoleLogger(String loggerIdentifier)
Starts a program-specific logger that prints to System.err stream.
final String NL
New line character.
Level verbosityTologLevel()
Randomizer startRandomizer()
Starts a program specific randomizer, i.e., a tool for generating random numbers and taking random de...
ParametersType paramType
The type of parameters collected in this instance.
int getVerbosity()
Returns the level of verbosity, i.e., the amount of log that we want to print.
void processOtherParameters()
Processes any of the parameter collections contained in this instance.
int verbosity
Verbosity level for logger.
void setVerbosity(int l)
Set the level of verbosity.
Randomizer getRandomizer()
Returns the current program-specific randomizer.
void setWorkDirectory(String pathname)
Gets the pathname to the working directory.
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 combinatorial algorithm for exploration of a fragment space b...
Parameters for genetic algorithm.
Parameters controlling execution of FitnessRunner.
Parameters controlling execution of the fragmenter.
Parameters controlling execution of TestOperator.
Parameters controlling execution of GraphEditor.
Parameters controlling execution of GraphEditor.
Parameters controlling execution of Isomorphism main class.
Parameters for the conformer generator (3D builder).
Tool to generate random numbers and random decisions.
Identifier of the type of parameters.
GO_PARAMS
Parameters controlling stand-alone run of genetic operators.
FR_PARAMS
Parameters controlling a stand-alone fitness evaluation run.
String keywordRoot
The root of any keyword that is meant to be used to set any of the parameters belonging to this class...
FS_PARAMS
Parameters pertaining the definition of the fragment space.
CEBL_PARAMS
Parameters pertaining the combinatorial exploration by layer.
ISO_PARAMS
Parameters controlling the stand-alone detection of graph isomorphism.
FRG_PARAMS
Parameters controlling the fragmenter.
MMB_PARAM
Parameters pertaining the construction of three-dimensional molecular models using the Tinker-based m...
GLH_PARAMS
Parameters controlling the stand-alone management of list of graphs.
FIT_PARAMS
Parameters pertaining the calculation of fitness (i.e., the fitness provider).
GA_PARAMS
Parameters pertaining the genetic algorithm.
RC_PARAMS
Parameters pertaining to ring closures in graphs.
Class<?> getImplementation()
GE_PARAMS
Parameters controlling the stand-alone editing of graphs.