$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.io.DenoptimIO;
37import denoptim.programs.RunTimeParameters;
38import denoptim.programs.fragmenter.CuttingRule;
39import denoptim.programs.fragmenter.FragmenterParameters;
40
41
49{
53 private String inFile;
54
58 private List<IAtomContainer> inMols;
59
63 private String outGraphsFile = null;
65
66//-----------------------------------------------------------------------------
67
72 {
74 }
75
76//-----------------------------------------------------------------------------
77
78 public int getInputMolsCount()
79 {
80 return inMols.size();
81 }
82
83//-----------------------------------------------------------------------------
84
85 public IAtomContainer getInputMol(int i)
86 {
87 return inMols.get(i);
88 }
89
90//-----------------------------------------------------------------------------
91
92 public String getOutFile()
93 {
94 return outGraphsFile;
95 }
96
97//-----------------------------------------------------------------------------
98
100 {
101 return outGraphsFormat;
102 }
103
104//-----------------------------------------------------------------------------
105
106 public List<CuttingRule> getCuttingRules()
107 {
111 return frgParams.getCuttingRules();
112 }
113
114//-----------------------------------------------------------------------------
115
117 {
121 return frgParams.getScaffoldingPolicy();
122 }
123
124//-----------------------------------------------------------------------------
125
126 public double getLinearAngleLimit()
127 {
131 return frgParams.getLinearAngleLimit();
132 }
133
134//-----------------------------------------------------------------------------
135
137 {
141 return fsParams.getFragmentSpace();
142 }
143
144//-----------------------------------------------------------------------------
145
147 {
149 {
151 }
152 }
153
154//-----------------------------------------------------------------------------
155
157 {
159 {
161 }
162 }
163
164//-----------------------------------------------------------------------------
165
173 public void interpretKeyword(String key, String value)
174 throws DENOPTIMException
175 {
176 String msg = "";
177 switch (key.toUpperCase())
178 {
179 case "INPUTFILE=":
180 inFile = value;
181 break;
182 case "WORKDIR=":
183 workDir = value;
184 break;
185 case "OUTPUTGRAPHS=":
186 outGraphsFile = value;
187 break;
188 case "OUTPUTGRAPHSFORMAT=":
189 switch (value.toUpperCase())
190 {
191 case "SDF":
193 break;
194 case "JSON":
196 break;
197 default:
198 outGraphsFormat = FileFormat.valueOf(value.toUpperCase());
199 }
200 break;
201 case "LOGFILE=":
202 logFile = value;
203 break;
204 case "VERBOSITY=":
205 try
206 {
207 verbosity = Integer.parseInt(value);
208 }
209 catch (Throwable t)
210 {
211 msg = "Unable to understand value " + key + "'" + value + "'";
212 throw new DENOPTIMException(msg);
213 }
214 break;
215 default:
216 msg = "Keyword " + key + " is not a known GraphEditor-"
217 + "related keyword. Check input files.";
218 throw new DENOPTIMException(msg);
219 }
220 }
221
222//------------------------------------------------------------------------------
223
230 public String getPrintedList()
231 {
232 StringBuilder sb = new StringBuilder(1024);
233 sb.append(" " + paramTypeName() + " ").append(NL);
234 for (Field f : this.getClass().getDeclaredFields())
235 {
236 try
237 {
238 sb.append(f.getName()).append(" = ").append(
239 f.get(this)).append(NL);
240 }
241 catch (Throwable t)
242 {
243 sb.append("ERROR! Unable to print " + paramTypeName()
244 + " parameters. Cause: " + t);
245 break;
246 }
247 }
248 for (RunTimeParameters otherCollector : otherParameters.values())
249 {
250 sb.append(otherCollector.getPrintedList());
251 }
252 return sb.toString();
253 }
254
255//-----------------------------------------------------------------------------
256
263 {
264 String msg = "";
265 if (!workDir.equals(".") && !FileUtils.checkExists(workDir))
266 {
267 msg = "Directory " + workDir + " not found. Please specify an "
268 + "existing directory.";
269 throw new DENOPTIMException(msg);
270 }
271
272 if (inFile == null)
273 {
274 msg = "Input file not defined. Check you input.";
275 throw new DENOPTIMException(msg);
276 }
277 else if (inFile != null && !FileUtils.checkExists(inFile))
278 {
279 msg = "File with input molecules not found. Check " + inFile;
280 throw new DENOPTIMException(msg);
281 }
282
284 {
285 msg = "Ouput file '" + outGraphsFile + "' exists already!";
286 throw new DENOPTIMException(msg);
287 }
288
290 }
291
292//----------------------------------------------------------------------------
293
300 {
301 try {
303 } catch (Exception e) {
304 throw new DENOPTIMException("Cannot import molecules from '"
305 + inFile + "'.", e);
306 }
307
309
312
315
316 if (frgParams.getCuttingRules() == null ||
317 frgParams.getCuttingRules().isEmpty())
318 {
319 List<CuttingRule> defaultCutRules = new ArrayList<CuttingRule>();
320 try {
321 BufferedReader reader = null;
322 try {
323 reader = new BufferedReader(new InputStreamReader(this
324 .getClass().getClassLoader().getResourceAsStream(
325 "data/cutting_rules")));
326 DenoptimIO.readCuttingRules(reader, defaultCutRules,
327 "bundled jar");
328 frgParams.setCuttingRules(defaultCutRules);
329 } finally {
330 if (reader!=null)
331 reader.close();
332 }
333 } catch (Exception e )
334 {
335 throw new DENOPTIMException("Cannot load default cutting "
336 + "rules.", e);
337 }
338 }
339 }
340
341//-----------------------------------------------------------------------------
342
343}
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.
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.
M2G_PARAMS
Parameters controlling molecule-to-graph conversion.
FS_PARAMS
Parameters pertaining the definition of the fragment space.
FRG_PARAMS
Parameters controlling the fragmenter.