$darkmode
DENOPTIM
FragmentSpaceParameters.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.fragspace;
20
21import java.io.File;
22import java.lang.reflect.Field;
23import java.util.HashMap;
24import java.util.logging.Level;
25
26import denoptim.exception.DENOPTIMException;
27import denoptim.files.FileUtils;
28import denoptim.graph.APClass;
29import denoptim.programs.RunTimeParameters;
30
31
39{
45 protected String scaffoldLibFile = "";
46
51 protected String fragmentLibFile = "";
52
59 protected String cappingLibFile = "";
60
65 protected String compMatrixFile = "";
66
70 protected String rcCompMatrixFile = "";
71
75 protected String rotBndsFile = "";
76
80 protected String rotConstraintsFile = "";
81
85 protected int maxHeavyAtom = 100;
86
90 protected int maxRotatableBond = 20;
91
95 protected double maxMW = 500;
96
100 protected boolean enforceSymmetry = false;
101
105 protected boolean symmetryConstraints = false;
106
110 private HashMap<APClass, Double> symmConstraintsMap =
111 new HashMap<APClass, Double>();
112
114
115//------------------------------------------------------------------------------
116
121 {
122 super(paramType);
123 }
124
125//------------------------------------------------------------------------------
126
131 {
133 }
134
135//------------------------------------------------------------------------------
136
143 {
146 }
147
148//------------------------------------------------------------------------------
149
150 public int getMaxHeavyAtom()
151 {
152 return maxHeavyAtom;
153 }
154
155//------------------------------------------------------------------------------
156
158 {
159 return maxRotatableBond;
160 }
161
162//------------------------------------------------------------------------------
163
164 public double getMaxMW()
165 {
166 return maxMW;
167 }
168
169//------------------------------------------------------------------------------
170
171 public boolean enforceSymmetry()
172 {
173 return enforceSymmetry;
174 }
175
176//------------------------------------------------------------------------------
177
178 public boolean symmetryConstraints()
179 {
180 return symmetryConstraints;
181 }
182
183//------------------------------------------------------------------------------
184
185 public String getRotSpaceDefFile()
186 {
187 return rotBndsFile;
188 }
189
190//------------------------------------------------------------------------------
191
193 {
194 return rotConstraintsFile;
195 }
196
197//------------------------------------------------------------------------------
198
200 {
201 File libFile = new File(fragmentLibFile);
202 return libFile.getAbsolutePath() + "_addedFragments.sdf";
203 }
204
205//------------------------------------------------------------------------------
206
208 {
209 File libFile = new File(scaffoldLibFile);
210 return libFile.getAbsolutePath() + "_addedScaffolds.sdf";
211 }
212
213//------------------------------------------------------------------------------
214
216 {
217 return buildingBlocksSpace;
218 }
219
220//------------------------------------------------------------------------------
221
222 public void interpretKeyword(String key, String value)
223 throws DENOPTIMException
224 {
225 String msg = "";
226 switch (key.toUpperCase())
227 {
228 case "SCAFFOLDLIBFILE=":
229 scaffoldLibFile = value;
230 break;
231 case "FRAGMENTLIBFILE=":
232 fragmentLibFile = value;
233 break;
234 case "CAPPINGFRAGMENTLIBFILE=":
235 cappingLibFile = value;
236 break;
237 case "COMPMATRIXFILE=":
238 compMatrixFile = value;
239 break;
240 case "RCCOMPMATRIXFILE=":
241 rcCompMatrixFile = value;
242 break;
243 case "ROTBONDSDEFFILE=":
244 rotBndsFile = value;
245 break;
246 case "ROTCONSTRDEFFILE=":
247 rotConstraintsFile = value;
248 break;
249 case "MAXHEAVYATOM=":
250 try
251 {
252 if (value.length() > 0)
253 maxHeavyAtom = Integer.parseInt(value);
254 }
255 catch (Throwable t)
256 {
257 msg = "Unable to understand value '" + value + "'";
258 throw new DENOPTIMException(msg);
259 }
260 break;
261 case "MAXROTATABLEBOND=":
262 try
263 {
264 if (value.length() > 0)
265 maxRotatableBond = Integer.parseInt(value);
266 }
267 catch (Throwable t)
268 {
269 msg = "Unable to understand value '" + value + "'";
270 throw new DENOPTIMException(msg);
271 }
272 break;
273 case "MAXMW=":
274 try
275 {
276 if (value.length() > 0)
277 maxMW = Double.parseDouble(value);
278 }
279 catch (Throwable t)
280 {
281 msg = "Unable to understand value '" + value + "'";
282 throw new DENOPTIMException(msg);
283 }
284 break;
285 case "ENFORCESYMMETRY":
286 enforceSymmetry = true;
287 break;
288 case "CONSTRAINSYMMETRY=":
289 symmetryConstraints = true;
290 try
291 {
292 if (value.length() > 0)
293 {
294 String[] words = value.trim().split("\\s+");
295 if (words.length != 2)
296 {
297 msg = "Keyword " + key + " requires two arguments: "
298 + "[APClass (String)] [probability (Double)].";
299 throw new DENOPTIMException(msg);
300 }
301 APClass apClass = APClass.make(words[0]);
302 double prob = 0.0;
303 try
304 {
305 prob = Double.parseDouble(words[1]);
306 }
307 catch (Throwable t2)
308 {
309 msg = "Unable to convert '" + words[1] + "' into a "
310 + "double.";
311 throw new DENOPTIMException(msg);
312 }
313 symmConstraintsMap.put(apClass,prob);
314 }
315 else
316 {
317 msg = "Keyword '" + key + "' requires two arguments: "
318 + "[APClass (String)] [probability (Double)].";
319 throw new DENOPTIMException(msg);
320 }
321 }
322 catch (Throwable t)
323 {
324 if (msg.equals(""))
325 {
326 msg = "Unable to understand value '" + value + "'";
327 }
328 throw new DENOPTIMException(msg);
329 }
330 break;
331 case "VERBOSITY=":
332 try
333 {
334 verbosity = Integer.parseInt(value);
335 }
336 catch (Throwable t)
337 {
338 msg = "Unable to understand value '" + value + "'";
339 throw new DENOPTIMException(msg);
340 }
341 break;
342 default:
343 msg = "Keyword " + key + " is not a known fragment space-"
344 + "related keyword. Check input files.";
345 throw new DENOPTIMException(msg);
346 }
347 }
348
349//------------------------------------------------------------------------------
350
352 {
353 String msg = "";
354 if (scaffoldLibFile.length() == 0)
355 {
356 getLogger().log(Level.WARNING,"No scaffolds library file specified.");
357 } else {
359 {
360 msg = "Cannot find the scaffold library: " + scaffoldLibFile;
361 throw new DENOPTIMException(msg);
362 }
363 }
364
365 if (fragmentLibFile.length() == 0)
366 {
367 getLogger().log(Level.WARNING,"No fragment library file specified.");
368 } else {
370 {
371 msg = "Cannot find the fragment library: " + fragmentLibFile;
372 throw new DENOPTIMException(msg);
373 }
374 }
375
376 if (cappingLibFile.length() > 0)
377 {
379 {
380 msg = "Cannot find the library of capping groups: "
382 throw new DENOPTIMException(msg);
383 }
384 }
385
386 if (compMatrixFile.length() > 0)
387 {
389 {
390 msg = "Cannot find the compatibility matrix file: "
392 throw new DENOPTIMException(msg);
393 }
394 }
395
396 if (rcCompMatrixFile.length() > 0)
397 {
399 {
400 msg = "Cannot find the ring-closures compatibility matrix "
401 + "file: " + rcCompMatrixFile;
402 throw new DENOPTIMException(msg);
403 }
404 }
405
406 if (rotBndsFile.length()>0 && !FileUtils.checkExists(rotBndsFile))
407 {
408 msg = "Cannot find file with definitions of rotatable bonds: "
409 + rotBndsFile;
410 throw new DENOPTIMException(msg);
411 }
412
414 {
415 msg = "Cannot find file with definitions of constrained rotatable bonds: "
417 throw new DENOPTIMException(msg);
418 }
419
421 }
422
423//------------------------------------------------------------------------------
424
431 {
437 }
438
439//------------------------------------------------------------------------------
440
447 public String getPrintedList()
448 {
449 StringBuilder sb = new StringBuilder(1024);
450 sb.append(" " + paramTypeName() + " ").append(NL);
451 for (Field f : this.getClass().getDeclaredFields())
452 {
453 try
454 {
455 sb.append(f.getName()).append(" = ").append(
456 f.get(this)).append(NL);
457 }
458 catch (Throwable t)
459 {
460 sb.append("ERROR! Unable to print " + paramTypeName()
461 + " parameters. Cause: " + t);
462 break;
463 }
464 }
465 for (RunTimeParameters otherCollector : otherParameters.values())
466 {
467 sb.append(otherCollector.getPrintedList());
468 }
469 return sb.toString();
470 }
471
472//------------------------------------------------------------------------------
473
480 public void setFragmentSpace(FragmentSpace fragmentSpace)
481 {
482 buildingBlocksSpace = fragmentSpace;
483 }
484
485//------------------------------------------------------------------------------
486
487}
static boolean checkExists(String fileName)
Definition: FileUtils.java:241
Class defining a space of building blocks.
Parameters defining the fragment space.
void processParameters()
Read the information collected in the parameters stored in this class and create the fragment space a...
boolean enforceSymmetry
Flag enforcing constitutional symmetry.
double maxMW
Maximum molecular weight accepted.
String fragmentLibFile
PathName of the file containing the molecular representation of building blocks: fragment section - f...
FragmentSpaceParameters(FragmentSpace fs)
Constructor of a default set of parameters coupled with a given fragment space.
int maxRotatableBond
Maximum number of rotatable bonds accepted.
String rotBndsFile
Rotatable bonds definition file.
HashMap< APClass, Double > symmConstraintsMap
List of constitutional symmetry constraints.
String getPrintedList()
Returns the list of parameters in a string with newline characters as delimiters.
boolean symmetryConstraints
Flag for application of selected constitutional symmetry constraints.
void interpretKeyword(String key, String value)
Processes a keyword/value pair and assign the related parameters.
void checkParameters()
Evaluate consistency of input parameters.
String compMatrixFile
Pathname of the file containing the compatibility matrix, bond order to AP-class relation,...
FragmentSpaceParameters(ParametersType paramType)
Constructor.
String cappingLibFile
Pathname of the file containing the molecular representation of building blocks: capping group sectio...
String rcCompMatrixFile
Pathname of the file containing the RC-compatibility matrix.
int maxHeavyAtom
Maximum number of heavy (non-hydrogen) atoms accepted.
String scaffoldLibFile
Pathname of the file containing the molecular representation of building blocks: scaffolds section - ...
void setFragmentSpace(FragmentSpace fragmentSpace)
Sets the fragment space linked to these parameters.
String rotConstraintsFile
Rotatable bonds constraints definition file.
static APClass make(String ruleAndSubclass)
Creates an APClass if it does not exist already, or returns the reference to the existing instance.
Definition: APClass.java:164
Collection of parameters controlling the behavior of the software.
Map< ParametersType, RunTimeParameters > otherParameters
Collection of other parameters by type.
Logger getLogger()
Get the name of the program specific logger.
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.
ParametersType paramType
The type of parameters collected in this instance.
void processOtherParameters()
Processes any of the parameter collections contained in this instance.
int verbosity
Verbosity level for logger.
FS_PARAMS
Parameters pertaining the definition of the fragment space.