$darkmode
DENOPTIM
Mol2GraphParameters.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.mol2graph;
20
21import java.io.BufferedReader;
22import java.io.File;
23import java.io.InputStreamReader;
24import java.lang.reflect.Field;
25import java.util.ArrayList;
26import java.util.List;
27
28import org.openscience.cdk.interfaces.IAtomContainer;
29
30import denoptim.exception.DENOPTIMException;
31import denoptim.files.FileFormat;
32import denoptim.files.FileUtils;
33import denoptim.fragmenter.ScaffoldingPolicy;
34import denoptim.fragspace.FragmentSpace;
35import denoptim.fragspace.FragmentSpaceParameters;
36import denoptim.graph.Template.ContractLevel;
37import denoptim.io.DenoptimIO;
38import denoptim.programs.RunTimeParameters;
39import denoptim.programs.fragmenter.CuttingRule;
40import denoptim.programs.fragmenter.FragmenterParameters;
41
42
50{
54 private String inFile;
55
59 private List<IAtomContainer> inMols;
60
64 private String outGraphsFile = null;
66
67//-----------------------------------------------------------------------------
68
73 {
75 }
76
77//-----------------------------------------------------------------------------
78
79 public int getInputMolsCount()
80 {
81 return inMols.size();
82 }
83
84//-----------------------------------------------------------------------------
85
86 public IAtomContainer getInputMol(int i)
87 {
88 return inMols.get(i);
89 }
90
91//-----------------------------------------------------------------------------
92
93 public String getOutFile()
94 {
95 return outGraphsFile;
96 }
97
98//-----------------------------------------------------------------------------
99
101 {
102 return outGraphsFormat;
103 }
104
105//-----------------------------------------------------------------------------
106
107 public List<CuttingRule> getCuttingRules()
108 {
112 return frgParams.getCuttingRules();
113 }
114
115//-----------------------------------------------------------------------------
116
118 {
122 return frgParams.getScaffoldingPolicy();
123 }
124
125//-----------------------------------------------------------------------------
126
127 public boolean embedRingsInTemplate()
128 {
132 return frgParams.embedRingsInTemplate();
133 }
134
135//-----------------------------------------------------------------------------
136
138 {
142 return frgParams.getEmbeddedRingsContract();
143 }
144
145//-----------------------------------------------------------------------------
146
147 public double getLinearAngleLimit()
148 {
152 return frgParams.getLinearAngleLimit();
153 }
154
155//-----------------------------------------------------------------------------
156
158 {
162 return fsParams.getFragmentSpace();
163 }
164
165//-----------------------------------------------------------------------------
166
168 {
170 {
172 }
173 }
174
175//-----------------------------------------------------------------------------
176
178 {
180 {
182 }
183 }
184
185//-----------------------------------------------------------------------------
186
194 public void interpretKeyword(String key, String value)
195 throws DENOPTIMException
196 {
197 String msg = "";
198 switch (key.toUpperCase())
199 {
200 case "INPUTFILE=":
201 inFile = value;
202 break;
203 case "WORKDIR=":
204 workDir = value;
205 break;
206 case "OUTPUTGRAPHS=":
207 outGraphsFile = value;
208 break;
209 case "OUTPUTGRAPHSFORMAT=":
210 switch (value.toUpperCase())
211 {
212 case "SDF":
214 break;
215 case "JSON":
217 break;
218 default:
219 outGraphsFormat = FileFormat.valueOf(value.toUpperCase());
220 }
221 break;
222 case "LOGFILE=":
223 logFile = value;
224 break;
225 case "VERBOSITY=":
226 try
227 {
228 verbosity = Integer.parseInt(value);
229 }
230 catch (Throwable t)
231 {
232 msg = "Unable to understand value " + key + "'" + value + "'";
233 throw new DENOPTIMException(msg);
234 }
235 break;
236 default:
237 msg = "Keyword " + key + " is not a known GraphEditor-"
238 + "related keyword. Check input files.";
239 throw new DENOPTIMException(msg);
240 }
241 }
242
243//------------------------------------------------------------------------------
244
251 public String getPrintedList()
252 {
253 StringBuilder sb = new StringBuilder(1024);
254 sb.append(" " + paramTypeName() + " ").append(NL);
255 for (Field f : this.getClass().getDeclaredFields())
256 {
257 try
258 {
259 sb.append(f.getName()).append(" = ").append(
260 f.get(this)).append(NL);
261 }
262 catch (Throwable t)
263 {
264 sb.append("ERROR! Unable to print " + paramTypeName()
265 + " parameters. Cause: " + t);
266 break;
267 }
268 }
269 for (RunTimeParameters otherCollector : otherParameters.values())
270 {
271 sb.append(otherCollector.getPrintedList());
272 }
273 return sb.toString();
274 }
275
276//-----------------------------------------------------------------------------
277
284 {
285 String msg = "";
286 if (!workDir.equals(".") && !FileUtils.checkExists(workDir))
287 {
288 msg = "Directory " + workDir + " not found. Please specify an "
289 + "existing directory.";
290 throw new DENOPTIMException(msg);
291 }
292
293 if (inFile == null)
294 {
295 msg = "Input file not defined. Check you input.";
296 throw new DENOPTIMException(msg);
297 }
298 else if (inFile != null && !FileUtils.checkExists(inFile))
299 {
300 msg = "File with input molecules not found. Check " + inFile;
301 throw new DENOPTIMException(msg);
302 }
303
305 {
306 msg = "Output file '" + outGraphsFile + "' exists already!";
307 throw new DENOPTIMException(msg);
308 }
309
311 }
312
313//----------------------------------------------------------------------------
314
321 {
322 try {
324 } catch (Exception e) {
325 throw new DENOPTIMException("Cannot import molecules from '"
326 + inFile + "'.", e);
327 }
328
330
333
336
337 if (frgParams.getCuttingRules() == null ||
338 frgParams.getCuttingRules().isEmpty())
339 {
340 List<CuttingRule> defaultCutRules = new ArrayList<CuttingRule>();
341 try {
342 BufferedReader reader = null;
343 try {
344 reader = new BufferedReader(new InputStreamReader(this
345 .getClass().getClassLoader().getResourceAsStream(
346 "data/cutting_rules")));
347 DenoptimIO.readCuttingRules(reader, defaultCutRules,
348 "bundled jar");
349 frgParams.setCuttingRules(defaultCutRules);
350 } finally {
351 if (reader!=null)
352 reader.close();
353 }
354 } catch (Exception e )
355 {
356 throw new DENOPTIMException("Cannot load default cutting "
357 + "rules.", e);
358 }
359 }
360 }
361
362//-----------------------------------------------------------------------------
363
364}
static boolean checkExists(String fileName)
Definition: FileUtils.java:241
Class defining a space of building blocks.
Parameters defining the fragment space.
Utility methods for input/output.
static void readCuttingRules(BufferedReader reader, List< CuttingRule > cutRules, String source)
Read cutting rules from a stream.
static List< IAtomContainer > readAllAtomContainers(File file)
Returns a single collection with all atom containers found in a file of any format.
Collection of parameters controlling the behavior of the software.
Map< ParametersType, RunTimeParameters > otherParameters
Collection of other parameters by type.
boolean containsParameters(ParametersType type)
void setParameters(RunTimeParameters otherParams)
RunTimeParameters getParameters(ParametersType 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 the fragmenter.
void setCuttingRules(List< CuttingRule > cuttingRules)
Assigns the cutting rules loaded from the input.
boolean embedRingsInTemplate
Flag that enables the embedding of rings in templates upon conversion of molecules into DGraph.
Parameters controlling execution of GraphEditor.
void interpretKeyword(String key, String value)
Processes a keyword/value pair and assign the related parameters.
void processParameters()
Processes all parameters and initialize related objects.
void checkParameters()
Evaluate consistency of input parameters.
List< IAtomContainer > inMols
Input molecular objects.
String getPrintedList()
Returns the list of parameters in a string with newline characters as delimiters.
File formats identified by DENOPTIM.
Definition: FileFormat.java:32
Defines how to define the scaffold vertex of a graph.
Enum specifying to what extent the template's inner graph can be changed.
Definition: Template.java:104
M2G_PARAMS
Parameters controlling molecule-to-graph conversion.
FS_PARAMS
Parameters pertaining the definition of the fragment space.
FRG_PARAMS
Parameters controlling the fragmenter.