21import java.awt.EventQueue;
23import java.io.PrintWriter;
24import java.io.StringWriter;
25import java.lang.reflect.Constructor;
27import java.util.concurrent.ExecutionException;
29import org.apache.commons.cli.CommandLine;
30import org.apache.commons.cli.CommandLineParser;
31import org.apache.commons.cli.DefaultParser;
32import org.apache.commons.cli.HelpFormatter;
33import org.apache.commons.cli.ParseException;
35import denoptim.constants.DENOPTIMConstants;
36import denoptim.exception.ExceptionUtils;
37import denoptim.files.FileFormat;
38import denoptim.files.FileUtils;
39import denoptim.gui.GUI;
40import denoptim.integration.python.Py4JGetawayServer;
41import denoptim.logging.Version;
42import denoptim.programs.combinatorial.FragSpaceExplorer;
43import denoptim.programs.denovo.GARunner;
44import denoptim.programs.fitnessevaluator.FitnessRunner;
45import denoptim.programs.fragmenter.Fragmenter;
46import denoptim.programs.genetweeker.GeneOpsRunner;
47import denoptim.programs.grapheditor.GraphEditor;
48import denoptim.programs.graphlisthandler.GraphListsHandler;
49import denoptim.programs.isomorphism.Isomorphism;
50import denoptim.programs.moldecularmodelbuilder.MolecularModelBuilder;
51import denoptim.task.ProgramTask;
52import denoptim.task.StaticTaskManager;
142 private String description =
"";
147 private boolean isCLIEnabled =
true;
153 private boolean needsInputFile =
false;
156 DRY.description =
"Dry run";
157 FSE.description =
"Combinatorial Fragment Space Exploration";
158 FIT.description =
"Stand-alone FITness evaluation";
159 GA.description =
"Genetic Algorithm";
160 GE.description =
"Stand-alone Graph Editing task";
161 GI.description =
"Stand-alone Graph Isomorphism analysis";
162 GO.description =
"Stand-alone Genetic Operation";
163 GUI.description =
"Graphycal User Interface";
164 CLG.description =
"Comparison of Lists of Graphs";
165 B3D.description =
"Stand-alone build a 3D molecular model from a "
167 FRG.description =
"Fragmentation and managment of fragments";
168 PY4J.description =
"Starts a server listening to Python";
170 DRY.isCLIEnabled =
false;
171 FSE.isCLIEnabled =
true;
172 FIT.isCLIEnabled =
true;
173 GA.isCLIEnabled =
true;
174 GE.isCLIEnabled =
true;
175 GI.isCLIEnabled =
true;
176 GO.isCLIEnabled =
true;
177 GUI.isCLIEnabled =
false;
178 CLG.isCLIEnabled =
true;
179 B3D.isCLIEnabled =
true;
180 FRG.isCLIEnabled =
true;
181 PY4J.isCLIEnabled =
true;
183 DRY.needsInputFile =
false;
184 FSE.needsInputFile =
true;
185 FIT.needsInputFile =
true;
186 GA.needsInputFile =
true;
187 GE.needsInputFile =
true;
188 GI.needsInputFile =
true;
189 GO.needsInputFile =
true;
190 GUI.needsInputFile =
false;
191 CLG.needsInputFile =
true;
192 B3D.needsInputFile =
true;
193 FRG.needsInputFile =
true;
194 PY4J.needsInputFile =
false;
196 DRY.programTaskImpl =
null;
199 GA.programTaskImpl =
GARunner.class;
203 GUI.programTaskImpl =
GUI.class;
207 PY4J.programTaskImpl =
null;
216 return programTaskImpl;
229 for (
int i=0; i<
RunType.values().length; i++)
234 if (i>0 && i <
RunType.values().length-2)
235 s = s +
" '" + rt.toString() +
"' for "+rt.
description+
",";
237 s =
"'" + rt.toString() +
"' for "+rt.
description+
",";
239 s = s + last+
"'"+rt.toString()+
"' for "+rt.
description+
".";
264 return needsInputFile;
276 public static void main(String[] args)
288 System.out.println(behavior.
helpMsg);
298 }
catch (Throwable e)
301 reportError(
"Could not start J2PyServer. Hint on problem: "
302 + e.getMessage(), 1);
307 List<String> inputFiles = behavior.
cmd.getArgList();
320 if (inputFiles.size()>1)
322 reportError(
"Only one input file allowed when requesting run "
323 + behavior.
runType +
". Found " + inputFiles.size()
324 +
" files: " + inputFiles, 1);
328 if (inputFiles.size()<1)
330 reportError(
"Need an input file when requesting run "
331 + behavior.
runType +
". Found " + inputFiles.size(), 1);
332 }
else if (inputFiles.size()==1) {
333 inpFile =
new File(inputFiles.get(0));
334 wDir = inpFile.getParentFile();
337 wDir =
new File(System.getProperty(
"user.dir"));
344 EventQueue.invokeLater(
new GUI(behavior.
cmd));
347 +
"', but I found no such implementation. "
348 +
"Please, report this to the authors.", 1);
365 if (!
ProgramTask.class.isAssignableFrom(taskClass))
367 reportError(
"Attempt to create a program task for class '"
368 + taskClass.getSimpleName() +
"', but such class is not a "
369 +
"extension of '" +
ProgramTask.class.getSimpleName()
376 Constructor<?> taskBuilder = taskClass.getConstructor(File.class,
378 task = (
ProgramTask) taskBuilder.newInstance(inputFile,workDir);
379 }
catch (Exception e)
390 }
catch (InterruptedException e)
393 }
catch (ExecutionException e)
412 "File '"+ file.getAbsolutePath() +
"' not found.");
417 }
catch (Throwable t) {
424 "Could not open file '" + file.getAbsolutePath()
425 +
"' because its format is not recognized.");
441 CommandLineParser parser =
new DefaultParser();
442 CommandLine cmd =
null;
446 }
catch (ParseException e) {
448 String errMsg =
"Unable to parse command-line arguments. "
449 +
"Please, check your input! " + DENOPTIMConstants.EOL
450 +
"Details: " + e.getMessage();
451 return new Behavior(
null,
null, 1, helpMsg, errMsg);
466 if (cmd.getOptions().length==0)
475 rt =
RunType.valueOf(rts.toUpperCase());
476 }
catch (Exception e)
478 String errMsg =
"Unacceptable value for "
480 +
"'" + rts +
"'. Please, modify "
482 return new Behavior(
null,
null, 1,
null, errMsg);
489 result =
new Behavior(
null,
null, 1,
null,
490 "RunType '"+rt+
"' is not enabled from CLI. "
491 +
"Please, contacts the developers.");
495 +
"but more than zero options. Please, contact the "
500 List<String> inputFiles = cmd.getArgList();
501 for (String pathname : inputFiles)
515 HelpFormatter formatter =
new HelpFormatter();
516 StringWriter out =
new StringWriter();
517 PrintWriter pw =
new PrintWriter(out);
521 formatter.getLeftPadding(), formatter.getDescPadding(),
523 "Run without arguments to launch the graphical user "
524 +
"interface (GUI) without opening any file. ",
true);
526 return out.toString();
543 System.exit(exitCode);
555 System.out.println(behavior.
helpMsg);
568 }
catch (Exception e) {
570 System.out.println(
"StaticTaskManager had problems stopping. "
571 +
"Forcing termination.");
573 Runtime.getRuntime().halt(0);
General set of constants used in DENOPTIM.
static final String EOL
new line character
static String getStackTraceAsString(Throwable t)
Prints the stack trace of an exception into a string.
static FileFormat detectFileFormat(File inFile)
Inspects a file/folder and tries to detect if there is one of the data sources that is recognized by ...
Graphical User Interface of the DENOPTIM package.
A tool that start a Py4J gateway server that can listens to calls from Python and translate JAVA obje...
static void launch()
Starts a gateway server using this class as entry point, which then becomes the interpreter of any da...
Class handling DENOPTIM's version identifier for headers.
static final String VERSION
Version identifier (from pom.xml via Maven properties)
Represents the behavior of the program at start-up.
RunType runType
The type of run that is requested.
String errorMsg
The error message.
CommandLine cmd
The parsed command line arguments.
int exitStatus
A non-zero value means some error has occurred and the program will terminate.
String helpMsg
The help message.
static Option help
Option requesting the printing of the help message.
static CLIOptions getInstance()
Gets the singleton instance of this class.
static Option version
Option requesting only the printing of the version.
static Option run
Option controlling the type of run.
Entry point of any kind of run of the DENOPTIM program.
static void reportError(Behavior behavior)
Prints an error message on standard output, possibly after the help message, and then stops the Virtu...
static Behavior ensureFileExistsAndIsReadable(File file, Behavior behavior)
Checks the file exists and format is recognized.
static String getHelpString()
Prints the help message on a string.
static void main(String[] args)
Launches the appropriate program according to the arguments given.
static void terminate()
Stops services and halts the Virtual Machine.
static void runProgramTask(Class<?> taskClass, File inputFile, File workDir)
Creates a task for the given class.
static void reportError(String msg, int exitCode)
Prints an error message on standard output and then stops the Virtual Machine with an exit code.
static Behavior defineProgramBehavior(String[] args)
Does the processing of the application arguments and decides what the program should do.
Combinatorial exploration of the fragment space.
Programs that runs de novo design by a genetic algorithm.
Stand-alone fitness provider.
Tool to create fragments by chopping 2D/3D chemical structures.
Tool to run genetic operations in a stand-alone fashion, i.e., outside of a genetic algorithm run.
Tool for editing DGraphs.
Tool for handling lists of graphs.
Tool to perform isomorphism analysis on DGraphs.
Builder of molecular models.
Task structure for any of the main programs in the denoptim project, such as genetic algorithm and co...
Manager for tasks submitted by the GUI.
static void submitAndWait(Task task)
Submits a task and waits for completion.
static StaticTaskManager getInstance()
Gets the singleton instance of this class.
Types of runs that can be requested to the DENOPTIM Main class.
String description
A short description of the run type.
Class<?> programTaskImpl
The implementation of ProgramTask capable of this run type.
CLG
Run a comparison of lists of graphs.
GI
Run a stand-alone test for graph isomorphism.
B3D
Run the stand-alone conversion of graph into a three-dimensional molecular model.
GO
Run a stand-alone genetic operation.
GE
Run a stand-alone graph editing task.
GA
Run the genetic algorithm with DenoptimGA.
GUI
Launch the graphical user interface denoptim.gui.GUI.
FIT
stand-alone fitness evaluation
boolean needsInputFile
Flag indicating if this run type needs any input file when called from CLI.
boolean isCLIEnabled()
Returns true if this run type can be requested from the CLI.
PY4J
Starts a listener to Python;.
Class<?> getProgramTaskImpl()
Returns the class that implements the program with this type of run.
FRG
Run a fragmentation task.
static String getRunTypesForUser()
Returns a string that contains a textual list (e.g., "A, B, and C") of the possible types that can be...
DRY
Only prints help or version and close program.
FSE
Run a combinatorial generation of candidates with FragSpaceExplorer.
boolean needsInputFile()
Returns true if this run type needs an input file when requested from CLI.
boolean isCLIEnabled
Flag indicating if this run type can be called from CLI.