$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 int maxHeavyAtom = 100;
81
85 protected int maxRotatableBond = 20;
86
90 protected double maxMW = 500;
91
95 protected boolean enforceSymmetry = false;
96
100 protected boolean symmetryConstraints = false;
101
105 private HashMap<APClass, Double> symmConstraintsMap =
106 new HashMap<APClass, Double>();
107
109
110//------------------------------------------------------------------------------
111
116 {
117 super(paramType);
118 }
119
120//------------------------------------------------------------------------------
121
126 {
128 }
129
130//------------------------------------------------------------------------------
131
138 {
141 }
142
143//------------------------------------------------------------------------------
144
145 public int getMaxHeavyAtom()
146 {
147 return maxHeavyAtom;
148 }
149
150//------------------------------------------------------------------------------
151
153 {
154 return maxRotatableBond;
155 }
156
157//------------------------------------------------------------------------------
158
159 public double getMaxMW()
160 {
161 return maxMW;
162 }
163
164//------------------------------------------------------------------------------
165
166 public boolean enforceSymmetry()
167 {
168 return enforceSymmetry;
169 }
170
171//------------------------------------------------------------------------------
172
173 public boolean symmetryConstraints()
174 {
175 return symmetryConstraints;
176 }
177
178//------------------------------------------------------------------------------
179
180 public String getRotSpaceDefFile()
181 {
182 return rotBndsFile;
183 }
184
185//------------------------------------------------------------------------------
186
188 {
189 File libFile = new File(fragmentLibFile);
190 return libFile.getAbsolutePath() + "_addedFragments.sdf";
191 }
192
193//------------------------------------------------------------------------------
194
196 {
197 File libFile = new File(scaffoldLibFile);
198 return libFile.getAbsolutePath() + "_addedScaffolds.sdf";
199 }
200
201//------------------------------------------------------------------------------
202
204 {
205 return buildingBlocksSpace;
206 }
207
208//------------------------------------------------------------------------------
209
210 public void interpretKeyword(String key, String value)
211 throws DENOPTIMException
212 {
213 String msg = "";
214 switch (key.toUpperCase())
215 {
216 case "SCAFFOLDLIBFILE=":
217 scaffoldLibFile = value;
218 break;
219 case "FRAGMENTLIBFILE=":
220 fragmentLibFile = value;
221 break;
222 case "CAPPINGFRAGMENTLIBFILE=":
223 cappingLibFile = value;
224 break;
225 case "COMPMATRIXFILE=":
226 compMatrixFile = value;
227 break;
228 case "RCCOMPMATRIXFILE=":
229 rcCompMatrixFile = value;
230 break;
231 case "ROTBONDSDEFFILE=":
232 rotBndsFile = value;
233 break;
234 case "MAXHEAVYATOM=":
235 try
236 {
237 if (value.length() > 0)
238 maxHeavyAtom = Integer.parseInt(value);
239 }
240 catch (Throwable t)
241 {
242 msg = "Unable to understand value '" + value + "'";
243 throw new DENOPTIMException(msg);
244 }
245 break;
246 case "MAXROTATABLEBOND=":
247 try
248 {
249 if (value.length() > 0)
250 maxRotatableBond = Integer.parseInt(value);
251 }
252 catch (Throwable t)
253 {
254 msg = "Unable to understand value '" + value + "'";
255 throw new DENOPTIMException(msg);
256 }
257 break;
258 case "MAXMW=":
259 try
260 {
261 if (value.length() > 0)
262 maxMW = Double.parseDouble(value);
263 }
264 catch (Throwable t)
265 {
266 msg = "Unable to understand value '" + value + "'";
267 throw new DENOPTIMException(msg);
268 }
269 break;
270 case "ENFORCESYMMETRY":
271 enforceSymmetry = true;
272 break;
273 case "CONSTRAINSYMMETRY=":
274 symmetryConstraints = true;
275 try
276 {
277 if (value.length() > 0)
278 {
279 String[] words = value.trim().split("\\s+");
280 if (words.length != 2)
281 {
282 msg = "Keyword " + key + " requires two arguments: "
283 + "[APClass (String)] [probability (Double)].";
284 throw new DENOPTIMException(msg);
285 }
286 APClass apClass = APClass.make(words[0]);
287 double prob = 0.0;
288 try
289 {
290 prob = Double.parseDouble(words[1]);
291 }
292 catch (Throwable t2)
293 {
294 msg = "Unable to convert '" + words[1] + "' into a "
295 + "double.";
296 throw new DENOPTIMException(msg);
297 }
298 symmConstraintsMap.put(apClass,prob);
299 }
300 else
301 {
302 msg = "Keyword '" + key + "' requires two arguments: "
303 + "[APClass (String)] [probability (Double)].";
304 throw new DENOPTIMException(msg);
305 }
306 }
307 catch (Throwable t)
308 {
309 if (msg.equals(""))
310 {
311 msg = "Unable to understand value '" + value + "'";
312 }
313 throw new DENOPTIMException(msg);
314 }
315 break;
316 case "VERBOSITY=":
317 try
318 {
319 verbosity = Integer.parseInt(value);
320 }
321 catch (Throwable t)
322 {
323 msg = "Unable to understand value '" + value + "'";
324 throw new DENOPTIMException(msg);
325 }
326 break;
327 default:
328 msg = "Keyword " + key + " is not a known fragment space-"
329 + "related keyword. Check input files.";
330 throw new DENOPTIMException(msg);
331 }
332 }
333
334//------------------------------------------------------------------------------
335
337 {
338 String msg = "";
339 if (scaffoldLibFile.length() == 0)
340 {
341 getLogger().log(Level.WARNING,"No scaffolds library file specified.");
342 } else {
344 {
345 msg = "Cannot find the scaffold library: " + scaffoldLibFile;
346 throw new DENOPTIMException(msg);
347 }
348 }
349
350 if (fragmentLibFile.length() == 0)
351 {
352 getLogger().log(Level.WARNING,"No fragment library file specified.");
353 } else {
355 {
356 msg = "Cannot find the fragment library: " + fragmentLibFile;
357 throw new DENOPTIMException(msg);
358 }
359 }
360
361 if (cappingLibFile.length() > 0)
362 {
364 {
365 msg = "Cannot find the library of capping groups: "
367 throw new DENOPTIMException(msg);
368 }
369 }
370
371 if (compMatrixFile.length() > 0)
372 {
374 {
375 msg = "Cannot find the compatibility matrix file: "
377 throw new DENOPTIMException(msg);
378 }
379 }
380
381 if (rcCompMatrixFile.length() > 0)
382 {
384 {
385 msg = "Cannot find the ring-closures compatibility matrix "
386 + "file: " + rcCompMatrixFile;
387 throw new DENOPTIMException(msg);
388 }
389 }
390
391 if (rotBndsFile.length()>0 && !FileUtils.checkExists(rotBndsFile))
392 {
393 msg = "Cannot find file with definitions of rotatable bonds: "
394 + rotBndsFile;
395 throw new DENOPTIMException(msg);
396 }
397
399 }
400
401//------------------------------------------------------------------------------
402
409 {
415 }
416
417//------------------------------------------------------------------------------
418
425 public String getPrintedList()
426 {
427 StringBuilder sb = new StringBuilder(1024);
428 sb.append(" " + paramTypeName() + " ").append(NL);
429 for (Field f : this.getClass().getDeclaredFields())
430 {
431 try
432 {
433 sb.append(f.getName()).append(" = ").append(
434 f.get(this)).append(NL);
435 }
436 catch (Throwable t)
437 {
438 sb.append("ERROR! Unable to print " + paramTypeName()
439 + " parameters. Cause: " + t);
440 break;
441 }
442 }
443 for (RunTimeParameters otherCollector : otherParameters.values())
444 {
445 sb.append(otherCollector.getPrintedList());
446 }
447 return sb.toString();
448 }
449
450//------------------------------------------------------------------------------
451
458 public void setFragmentSpace(FragmentSpace fragmentSpace)
459 {
460 buildingBlocksSpace = fragmentSpace;
461 }
462
463//------------------------------------------------------------------------------
464
465}
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.
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:136
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.