$darkmode
DENOPTIM
GraphEdParameters.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2019 Marco Foscato <marco.foscato@uib.no>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package denoptim.programs.grapheditor;
20
21import java.io.File;
22import java.lang.reflect.Field;
23import java.util.ArrayList;
24import java.util.logging.Level;
25
26import org.openscience.cdk.interfaces.IAtomContainer;
27
28import denoptim.exception.DENOPTIMException;
29import denoptim.files.FileFormat;
30import denoptim.files.FileUtils;
31import denoptim.graph.DGraph;
32import denoptim.io.DenoptimIO;
33import denoptim.logging.StaticLogger;
34import denoptim.programs.RunTimeParameters;
35import denoptim.utils.GraphEdit;
36
37
45{
49 private String inGraphsFile = null;
50
54 private ArrayList<DGraph> inGraphs = new ArrayList<DGraph>();
55
59 private ArrayList<IAtomContainer> inMols;
60
64 private String graphEditsFile = null;
65
69 private ArrayList<GraphEdit> graphEdits;
70
74 private String outGraphsFile = null;
76
80 private boolean symmetry = false;
81
82//-----------------------------------------------------------------------------
83
88 {
90 }
91
92//-----------------------------------------------------------------------------
93
94 public ArrayList<GraphEdit> getGraphEditTasks()
95 {
96 return graphEdits;
97 }
98
99//-----------------------------------------------------------------------------
100
101 public ArrayList<DGraph> getInputGraphs()
102 {
103 return inGraphs;
104 }
105
106//-----------------------------------------------------------------------------
107
108 public IAtomContainer getInpMol(int i)
109 {
110 return inMols.get(i);
111 }
112
113//-----------------------------------------------------------------------------
114
115 public String getOutFile()
116 {
117 return outGraphsFile;
118 }
119
120//-----------------------------------------------------------------------------
121
122 public boolean symmetryFlag()
123 {
124 return symmetry;
125 }
126
127//-----------------------------------------------------------------------------
128
130 {
131 return outGraphsFormat;
132 }
133
134//-----------------------------------------------------------------------------
135
143 public void interpretKeyword(String key, String value)
144 throws DENOPTIMException
145 {
146 String msg = "";
147 switch (key.toUpperCase())
148 {
149 case "WORKDIR=":
150 workDir = value;
151 break;
152 case "INPUTGRAPHS=":
153 inGraphsFile = value;
154 break;
155 case "ENFORCESYMMETRY=":
156 if (value.toUpperCase().equals("YES")
157 || value.toUpperCase().equals("Y"))
158 {
159 symmetry = true;
160 }
161 break;
162 case "GRAPHSEDITSFILE=":
163 graphEditsFile = value;
164 break;
165 case "OUTPUTGRAPHS=":
166 outGraphsFile = value;
167 break;
168 case "OUTPUTGRAPHSFORMAT=":
169 switch (value.toUpperCase())
170 {
171 case "SDF":
173 break;
174 case "JSON":
176 break;
177 default:
178 outGraphsFormat = FileFormat.valueOf(value.toUpperCase());
179 }
180 break;
181 case "LOGFILE=":
182 logFile = value;
183 break;
184 case "VERBOSITY=":
185 try
186 {
187 verbosity = Integer.parseInt(value);
188 }
189 catch (Throwable t)
190 {
191 msg = "Unable to understand value " + key + "'" + value + "'";
192 throw new DENOPTIMException(msg);
193 }
194 break;
195 default:
196 msg = "Keyword " + key + " is not a known GraphEditor-"
197 + "related keyword. Check input files.";
198 throw new DENOPTIMException(msg);
199 }
200 }
201
202//------------------------------------------------------------------------------
203
210 public String getPrintedList()
211 {
212 StringBuilder sb = new StringBuilder(1024);
213 sb.append(" " + paramTypeName() + " ").append(NL);
214 for (Field f : this.getClass().getDeclaredFields())
215 {
216 try
217 {
218 sb.append(f.getName()).append(" = ").append(
219 f.get(this)).append(NL);
220 }
221 catch (Throwable t)
222 {
223 sb.append("ERROR! Unable to print " + paramTypeName()
224 + " parameters. Cause: " + t);
225 break;
226 }
227 }
228 for (RunTimeParameters otherCollector : otherParameters.values())
229 {
230 sb.append(otherCollector.getPrintedList());
231 }
232 return sb.toString();
233 }
234
235//-----------------------------------------------------------------------------
236
243 {
244 String msg = "";
245 if (!workDir.equals(".") && !FileUtils.checkExists(workDir))
246 {
247 msg = "Directory " + workDir + " not found. Please specify an "
248 + "existing directory.";
249 throw new DENOPTIMException(msg);
250 }
251
252 if (inGraphsFile == null)
253 {
254 msg = "Input file with graphs to edit not defined. Check you input.";
255 throw new DENOPTIMException(msg);
256 }
257 else if (inGraphsFile != null && !FileUtils.checkExists(inGraphsFile))
258 {
259 msg = "File with input graphs not found. Check " + inGraphsFile;
260 throw new DENOPTIMException(msg);
261 }
262
264 {
265 msg = "File with graph editing tasks not found. Check " +
267 throw new DENOPTIMException(msg);
268 }
269
271 {
272 msg = "Ouput file '" + outGraphsFile + "' exists already!";
273 throw new DENOPTIMException(msg);
274 }
275
277 }
278
279//----------------------------------------------------------------------------
280
287 {
289
290 if (outGraphsFile == null)
291 {
292 outGraphsFile = inGraphsFile + ".mod" ;
294 {
295 String msg = "Ouput file '" + outGraphsFile + "' exists already!";
296 throw new DENOPTIMException(msg);
297 }
298 }
299
300 if (graphEditsFile != null)
301 {
302 try
303 {
306 }
307 catch (Throwable t)
308 {
309 throw new Error("Cannot read in graph editing tasks from "
311 }
312 }
313 }
314
315//-----------------------------------------------------------------------------
316
317 protected void readInputGraphs() throws DENOPTIMException
318 {
319 try
320 {
322 inGraphsFile));
323 }
324 catch (Throwable t)
325 {
326 String msg = "Cannot read in graphs from " + inGraphsFile;
327 StaticLogger.appLogger.log(Level.INFO,msg);
328 throw new DENOPTIMException(msg,t);
329 }
330 }
331
332//-----------------------------------------------------------------------------
333
334}
static boolean checkExists(String fileName)
Definition: FileUtils.java:241
Utility methods for input/output.
static ArrayList< DGraph > readDENOPTIMGraphsFromFile(File inFile)
Reads a list of <DGraphs from file.
static ArrayList< GraphEdit > readDENOPTIMGraphEditFromFile(String fileName)
Reads a list of graph editing tasks from a JSON file.
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.
String paramTypeName()
Returns a string defining the type the parameters collected here.
void checkOtherParameters()
Checks any of the parameter collections contained in this instance.
final String NL
New line character.
void processOtherParameters()
Processes any of the parameter collections contained in this instance.
int verbosity
Verbosity level for logger.
Parameters controlling execution of GraphEditor.
void checkParameters()
Evaluate consistency of input parameters.
void processParameters()
Processes all parameters and initialize related objects.
ArrayList< GraphEdit > graphEdits
Graph's editing tasks.
ArrayList< IAtomContainer > inMols
Input molecular objects.
void interpretKeyword(String key, String value)
Processes a keyword/value pair and assign the related parameters.
String graphEditsFile
File with list of edit tasks.
boolean symmetry
Flag controlling strategy with respect to symmetry.
String getPrintedList()
Returns the list of parameters in a string with newline characters as delimiters.
File formats identified by DENOPTIM.
Definition: FileFormat.java:32
GE_PARAMS
Parameters controlling the stand-alone editing of graphs.