$darkmode
DENOPTIM
FragmenterParameters.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.fragmenter;
20
21import java.io.BufferedReader;
22import java.io.File;
23import java.io.IOException;
24import java.io.InputStreamReader;
25import java.lang.reflect.Field;
26import java.text.SimpleDateFormat;
27import java.util.ArrayList;
28import java.util.Date;
29import java.util.HashMap;
30import java.util.HashSet;
31import java.util.LinkedHashMap;
32import java.util.List;
33import java.util.Map;
34import java.util.Set;
35import java.util.concurrent.atomic.AtomicInteger;
36import java.util.logging.Level;
37
38import denoptim.constants.DENOPTIMConstants;
39import denoptim.exception.DENOPTIMException;
40import denoptim.files.FileFormat;
41import denoptim.files.FileUtils;
42import denoptim.fragmenter.FragmentClusterer;
43import denoptim.fragmenter.ScaffoldingPolicy;
44import denoptim.graph.DGraph;
45import denoptim.graph.Template.ContractLevel;
46import denoptim.graph.Vertex;
47import denoptim.graph.Vertex.BBType;
48import denoptim.io.DenoptimIO;
49import denoptim.logging.StaticLogger;
50import denoptim.programs.RunTimeParameters;
51import denoptim.utils.FormulaUtils;
52
53
61{
66 private String structuresFile;
67
72 private String formulaeFile;
73
78 private LinkedHashMap<String, String> formulae;
79
83 private String cutRulesFile;
84
88 List<CuttingRule> cuttingRules;
89
93 private int numParallelTasks = 1;
94
100 private boolean doCheckFormula = false;
101
108 private boolean acceptUnsetToSingeBOApprox = false;
109
113 private boolean addExplicitH = false;
114
118 private boolean doPreFilter = false;
119
125 private Set<String> preFilterSMARTS = new HashSet<String>();
126
130 private boolean doFragmentation = false;
131
139 private boolean doFiltering = false;
140
144 private boolean doFragExtractionFromGraphs = false;
145
149 private boolean doRejectWeirdIsotopes = true;
150
154 private Set<String> rejectedElements = new HashSet<String>();
155
161 private Map<String,Double> formulaCriteriaLessThan =
162 new HashMap<String,Double>();
163
169 private Set<Map<String,Double>> formulaCriteriaMoreThan =
170 new HashSet<Map<String,Double>>();
171
175 private Set<String> rejectedAPClasses = new HashSet<String>();
176
181 private Set<String[]> rejectedAPClassCombinations = new HashSet<String[]>();
182
187 private int maxFragHeavyAtomCount = -1;
188
193 private int minFragHeavyAtomCount = -1;
194
198 private Map<String, String> fragRejectionSMARTS = new HashMap<String, String>();
199
204 private Map<String, String> fragRetentionSMARTS = new HashMap<String, String>();
205
210 private boolean doAddDuOnLinearity = true;
211
216 private double linearAngleLimit = 170.0;
217
221 private String ignorableFragmentsFile = "";
222
226 private ArrayList<Vertex> ignorableFragments = new ArrayList<Vertex>();
227
232 private String targetFragmentsFile = "";
233
238 private ArrayList<Vertex> targetFragments = new ArrayList<Vertex>();
239
266 // NB: javadoc reproduced also in the getter method. See below
267 private boolean doManageIsomorphicFamilies = false;
268
275 private int isomorphicSampleSize = 1;
276
280 public static final int MAXISOMORPHICSAMPLESIZE = 50;
281
285 private int mwSlotSize = 10;
286
291 private Map<String,File> mwSlotToAllFragsFile = new HashMap<String,File>();
292
297 private Map<String,File> mwSlotToUnqFragsFile = new HashMap<String,File>();
298
304 private Map<String,Integer> isomorphsCount = new HashMap<String,Integer>();
305
306 //TODO: We could use something like the SizeControlledSet used in the EA to
307 // collect unique identifiers.
308
312 private AtomicInteger unqIsomorphicFamilyId = new AtomicInteger(0);
313
319 public final Object MANAGEMWSLOTSSLOCK = new Object();
320
326 private boolean doExtactRepresentativeConformer = false;
327
334 private int sizeUnimodalPop = 20;
335
341 private double maxNoiseUnimodalPop = 0.2;
342
352
358
362 private boolean saveClustersOfConformerToFile = false;
363
367 private boolean isStandaloneFragmentClustering = false;
368
372 private boolean workingIn3D = true;
373
380
385 protected boolean embedRingsInTemplate = false;
386
392
397 private String fragmentationTmplFile = "";
398
403 private List<DGraph> fragmentationTmpls = new ArrayList<DGraph>();
404
408 private int maxBufferShellSize = 2;
409
410//------------------------------------------------------------------------------
411
416 {
418 }
419
420//------------------------------------------------------------------------------
421
425 public int getNumTasks()
426 {
427 return numParallelTasks;
428 }
429
430//------------------------------------------------------------------------------
431
437 {
438 this.numParallelTasks = numParallelTasks;
439 }
440
441//------------------------------------------------------------------------------
442
446 public String getStructuresFile()
447 {
448 return structuresFile;
449 }
450
451//------------------------------------------------------------------------------
452
458 {
459 this.structuresFile = structuresFile;
460 }
461
462//------------------------------------------------------------------------------
463
469 public void setFormulaeFile(String formulaeFile)
470 {
471 this.formulaeFile = formulaeFile;
472 }
473
474//------------------------------------------------------------------------------
475
480 public String getFormulaeFile()
481 {
482 return formulaeFile;
483 }
484
485//------------------------------------------------------------------------------
486
490 public List<CuttingRule> getCuttingRules()
491 {
492 return cuttingRules;
493 }
494
495//------------------------------------------------------------------------------
496
500 public void setCuttingRules(List<CuttingRule> cuttingRules)
501 {
502 this.cuttingRules = cuttingRules;
503 }
504
505//------------------------------------------------------------------------------
506
510 public void setCuttingRulesFilePathname(String pathname)
511 {
512 this.cutRulesFile = pathname;
513 }
514
515//------------------------------------------------------------------------------
516
521 {
522 return cutRulesFile;
523 }
524
525//------------------------------------------------------------------------------
526
530 public LinkedHashMap<String, String> getFormulae()
531 {
532 return formulae;
533 }
534
535//------------------------------------------------------------------------------
536
543 public boolean doCheckFormula()
544 {
545 return doCheckFormula;
546 }
547
548//------------------------------------------------------------------------------
549
555 public void setCheckFormula(boolean checkFormula)
556 {
557 this.doCheckFormula = checkFormula;
558 }
559
560
561//------------------------------------------------------------------------------
562
566 public boolean doPreFilter()
567 {
568 return doPreFilter;
569 }
570
571//------------------------------------------------------------------------------
572
577 public Set<String> getPreFiltrationSMARTS()
578 {
579 return preFilterSMARTS;
580 }
581
582//------------------------------------------------------------------------------
583
587 public boolean doFragmentation()
588 {
589 return doFragmentation;
590 }
591
592//------------------------------------------------------------------------------
593
598 {
600 }
601
602//------------------------------------------------------------------------------
603
608 public boolean doRejectWeirdIsotopes()
609 {
611 }
612
613//------------------------------------------------------------------------------
614
619 public boolean doAddDuOnLinearity()
620 {
621 return doAddDuOnLinearity;
622 }
623
624//------------------------------------------------------------------------------
625
629 public Set<String> getRejectedElements()
630 {
631 return rejectedElements;
632 }
633
634//------------------------------------------------------------------------------
635
640 public Map<String, Double> getRejectedFormulaLessThan()
641 {
643 }
644
645//------------------------------------------------------------------------------
646
651 public Set<Map<String, Double>> getRejectedFormulaMoreThan()
652 {
654 }
655
656//------------------------------------------------------------------------------
657
661 public Set<String> getRejectedAPClasses()
662 {
663 return rejectedAPClasses;
664 }
665
666//------------------------------------------------------------------------------
667
671 public Set<String[]> getRejectedAPClassCombinations()
672 {
674 }
675
676//------------------------------------------------------------------------------
677
682 {
684 }
685
686//------------------------------------------------------------------------------
687
692 {
694 }
695
696//------------------------------------------------------------------------------
697
701 public Map<String, String> getFragRejectionSMARTS()
702 {
703 return fragRejectionSMARTS;
704 }
705
706//------------------------------------------------------------------------------
707
711 public Map<String, String> getFragRetentionSMARTS()
712 {
713 return fragRetentionSMARTS;
714 }
715
716//------------------------------------------------------------------------------
717
719 {
720 this.doRejectWeirdIsotopes = doRejectWeirdIsotopes;
721 }
722
723//------------------------------------------------------------------------------
724
725 public void setRejectedElements(Set<String> rejectedElements)
726 {
727 this.rejectedElements = rejectedElements;
728 }
729
730//------------------------------------------------------------------------------
731
733 Map<String, Double> formulaMax)
734 {
735 this.formulaCriteriaLessThan = formulaMax;
736 }
737
738//------------------------------------------------------------------------------
739
741 Set<Map<String, Double>> formulaCriteriaMoreThan)
742 {
743 this.formulaCriteriaMoreThan = formulaCriteriaMoreThan;
744 }
745
746//------------------------------------------------------------------------------
747
749 {
750 this.rejectedAPClasses = rejectedAPClasses;
751 }
752
753//------------------------------------------------------------------------------
754
756 Set<String[]> rejectedAPClassCombinations)
757 {
758 this.rejectedAPClassCombinations = rejectedAPClassCombinations;
759 }
760
761//------------------------------------------------------------------------------
762
764 {
765 this.maxFragHeavyAtomCount = maxFragHeavyAtomCount;
766 }
767
768//------------------------------------------------------------------------------
769
771 {
772 this.minFragHeavyAtomCount = minFragHeavyAtomCount;
773 }
774
775//------------------------------------------------------------------------------
776
777 public void setFragRejectionSMARTS(Map<String, String> fragRejectionSMARTS)
778 {
779 this.fragRejectionSMARTS = fragRejectionSMARTS;
780 }
781
782//------------------------------------------------------------------------------
783
784 public void setFragRetentionSMARTS(Map<String, String> fragRetentionSMARTS)
785 {
786 this.fragRetentionSMARTS = fragRetentionSMARTS;
787 }
788
789//------------------------------------------------------------------------------
790
794 public ArrayList<Vertex> getIgnorableFragments()
795 {
796 return ignorableFragments;
797 }
798
799//------------------------------------------------------------------------------
800
805 public ArrayList<Vertex> getTargetFragments()
806 {
807 return targetFragments;
808 }
809
810//------------------------------------------------------------------------------
811
841 {
843 }
844
845//------------------------------------------------------------------------------
846
848 {
850 }
851
852//------------------------------------------------------------------------------
853
855 {
856 this.isomorphicSampleSize = isomorphicSampleSize;
857 }
858
859//------------------------------------------------------------------------------
860
861 public int getMWSlotSize()
862 {
863 return mwSlotSize;
864 }
865
866//------------------------------------------------------------------------------
867
868 public void setMWSlotSize(int mwSlotSize)
869 {
870 this.mwSlotSize = mwSlotSize;
871 }
872
873//------------------------------------------------------------------------------
874
875 public Map<String, File> getMWSlotToAllFragsFile()
876 {
878 }
879
880//------------------------------------------------------------------------------
881
882 public void setMWSlotToAllFragsFile(Map<String, File> mwSlotToAllFragsFile)
883 {
884 this.mwSlotToAllFragsFile = mwSlotToAllFragsFile;
885 }
886
887//------------------------------------------------------------------------------
888
889 public Map<String, File> getMWSlotToUnqFragsFile()
890 {
892 }
893
894//------------------------------------------------------------------------------
895
904 public File getMWSlotFileNameUnqFrags(String mwSlotId)
905 {
906 return new File(getWorkDirectory() + DenoptimIO.FS
910 }
911
912//------------------------------------------------------------------------------
913
921 public File getMWSlotFileNameAllFrags(String mwSlotId)
922 {
923 return new File(getWorkDirectory() + DenoptimIO.FS
927 }
928
929//------------------------------------------------------------------------------
930
934 public Map<String,Integer> getIsomorphsCount()
935 {
936 return isomorphsCount;
937 }
938
939//------------------------------------------------------------------------------
940
945 public String newIsomorphicFamilyID()
946 {
947 return "IsomorphicFamily_" + unqIsomorphicFamilyId.getAndIncrement();
948 }
949
950//------------------------------------------------------------------------------
951
957 public boolean doFiltering()
958 {
959 return doFiltering;
960 }
961
962//------------------------------------------------------------------------------
963
967 public boolean addExplicitH()
968 {
969 return addExplicitH;
970 }
971
972//------------------------------------------------------------------------------
973
978 public void setAddExplicitH(boolean addExplicitH)
979 {
980 this.addExplicitH = addExplicitH;
981 }
982
983//------------------------------------------------------------------------------
984
989 public boolean acceptUnsetToSingeBO()
990 {
992 }
993
994//-----------------------------------------------------------------------------
995
1001 {
1002 this.embedRingsInTemplate = embedRingsInTemplate;
1003 }
1004
1005//-----------------------------------------------------------------------------
1006
1011 public boolean embedRingsInTemplate()
1012 {
1013 return embedRingsInTemplate;
1014 }
1015
1016//------------------------------------------------------------------------------
1017
1024 {
1025 this.embeddedRingsContract = embeddedRingsContract;
1026 }
1027
1028//------------------------------------------------------------------------------
1029
1035 {
1036 return embeddedRingsContract;
1037 }
1038
1039//------------------------------------------------------------------------------
1040
1046 {
1047 this.scaffoldingPolicy = sp;
1048 }
1049
1050//------------------------------------------------------------------------------
1051
1057 {
1058 return scaffoldingPolicy;
1059 }
1060
1061//------------------------------------------------------------------------------
1062
1067 public List<DGraph> getFragmentationTmpls()
1068 {
1069 return fragmentationTmpls;
1070 }
1071
1072//------------------------------------------------------------------------------
1073
1080 {
1081 return maxBufferShellSize;
1082 }
1083
1084//------------------------------------------------------------------------------
1085
1092 public void interpretKeyword(String key, String value)
1093 throws DENOPTIMException
1094 {
1095 String msg = "";
1096 switch (key.toUpperCase())
1097 {
1098 case "WORKDIR=":
1099 workDir = value;
1100 break;
1101
1102 case "STRUCTURESFILE=":
1103 structuresFile = value;
1104 break;
1105
1106 case "FORMULATXTFILE=":
1107 doCheckFormula = true;
1108 formulaeFile = value;
1109 break;
1110
1111 case "PREFILTERSMARTS=":
1112 doPreFilter = true;
1113 preFilterSMARTS.add(value);
1114 break;
1115
1116 case "CUTTINGRULESFILE=":
1117 doFragmentation = true;
1118 cutRulesFile = value;
1119 break;
1120
1121 case "EXTRACTFROMGRAPHS=":
1122 structuresFile = value;
1124 break;
1125
1126 case "ADDEXPLICITHYDROGEN":
1127 addExplicitH = true;
1128 break;
1129
1130 case "UNSETTOSINGLEBO":
1132 break;
1133
1134 case "IGNORABLEFRAGMENTS=":
1135 ignorableFragmentsFile = value;
1136 doFiltering = true;
1137 break;
1138
1139 case "TARGETFRAGMENTS=":
1140 targetFragmentsFile = value;
1141 doFiltering = true;
1142 break;
1143
1144 case "ISOMORPHICSAMPLESIZE=":
1145 try {
1146 isomorphicSampleSize = Integer.parseInt(value);
1147 } catch (Throwable t)
1148 {
1149 msg = "Unable to parse value of " + key + ": '" + value + "'";
1150 throw new DENOPTIMException(msg);
1151 }
1154 break;
1155
1156 case "REMOVEDUPLICATES":
1158 break;
1159
1160 case "MWSLOTSIZE=":
1161 try {
1162 mwSlotSize = Integer.parseInt(value);
1163 } catch (Throwable t)
1164 {
1165 msg = "Unable to parse value of " + key + ": '" + value + "'";
1166 throw new DENOPTIMException(msg);
1167 }
1168 break;
1169
1170 case "REJECTMINORISOTOPES":
1171 doRejectWeirdIsotopes = true;
1172 doFiltering = true;
1173 break;
1174
1175 case "REJECTELEMENT=":
1176 rejectedElements.add(value);
1177 doFiltering = true;
1178 break;
1179
1180 case "REJFORMULALESSTHAN=":
1181 if (formulaCriteriaLessThan.size()>0)
1182 {
1183 msg = "Attempt to specify more than one criterion for "
1184 + "rejecting fragments based on a lower-limit "
1185 + "molecular formula. ";
1186 throw new DENOPTIMException(msg);
1187 }
1188 Map<String,Double> elSymbolsCount = null;
1189 try {
1190 elSymbolsCount = FormulaUtils.parseFormula(value);
1191 } catch (Throwable t)
1192 {
1193 msg = "Unable to parse value of " + key + ": '" + value + "'";
1194 throw new DENOPTIMException(msg);
1195 }
1196 formulaCriteriaLessThan = elSymbolsCount;
1197 doFiltering = true;
1198 break;
1199
1200 case "REJFORMULAMORETHAN=":
1201 Map<String,Double> elSymbolsCount2= null;
1202 try {
1203 elSymbolsCount2 = FormulaUtils.parseFormula(value);
1204 } catch (Throwable t)
1205 {
1206 msg = "Unable to parse value of " + key + ": '" + value + "'";
1207 throw new DENOPTIMException(msg);
1208 }
1209 formulaCriteriaMoreThan.add(elSymbolsCount2);
1210 doFiltering = true;
1211 break;
1212
1213 case "REJECTAPCLASS=":
1214 rejectedAPClasses.add(value);
1215 doFiltering = true;
1216 break;
1217
1218 case "REJECTAPCLASSCOMBINATION=":
1219 String[] lst = value.split("\\s+");
1221 doFiltering = true;
1222 break;
1223
1224 case "MAXFRAGSIZE=":
1225 try {
1226 maxFragHeavyAtomCount = Integer.parseInt(value);
1227 } catch (Throwable t)
1228 {
1229 msg = "Unable to parse value of " + key + ": '" + value + "'";
1230 throw new DENOPTIMException(msg);
1231 }
1232 doFiltering = true;
1233 break;
1234
1235 case "MINFRAGSIZE=":
1236 try {
1237 minFragHeavyAtomCount = Integer.parseInt(value);
1238 } catch (Throwable t)
1239 {
1240 msg = "Unable to parse value of " + key + ": '" + value + "'";
1241 throw new DENOPTIMException(msg);
1242 }
1243 doFiltering = true;
1244 break;
1245
1246 case "REJECTSMARTS=":
1247 fragRejectionSMARTS.put(value, value);
1248 doFiltering = true;
1249 break;
1250
1251 case "RETAINSMARTS=":
1252 fragRetentionSMARTS.put(value, value);
1253 doFiltering = true;
1254 break;
1255
1256 case "CLUSTERIZEANDCOLLECT=":
1259 switch (value.trim().toUpperCase())
1260 {
1261 case "CENTROIDS":
1263 break;
1264
1265 case "MOSTCENTRAL":
1267 break;
1268
1269 default:
1270 throw new DENOPTIMException("Unable to parse value of "
1271 + key + ": '" + value + "'");
1272 }
1273 break;
1274
1275 case "SAVECLUSTERS":
1278 break;
1279
1280 case "SIZEUNIMODALPOPULATION=":
1281 sizeUnimodalPop = Integer.parseInt(value);
1282 break;
1283
1284 case "MAXNOISEUNIMODALPOPULATION=":
1285 maxNoiseUnimodalPop = Double.parseDouble(value);
1286 break;
1287
1288 case "SDWEIGHTUNIMODALPOPULATION=":
1289 factorForSDOnStatsOfUnimodalPop = Double.parseDouble(value);
1290 break;
1291
1292 case "SCAFFOLDINGPOLICY=":
1293 String[] words = value.split("\\s+");
1294 try {
1296 words[0].toUpperCase());
1298 {
1299 if (words.length<2)
1300 {
1301 throw new DENOPTIMException("Expected elemental "
1302 + "symbol after '"
1303 + ScaffoldingPolicy.ELEMENT+ "', but none "
1304 + "found");
1305 }
1306 scaffoldingPolicy.label = words[1];
1307 }
1308 } catch (Throwable t)
1309 {
1310 msg = "Unable to parse value of " + key + ": '" + value + "'";
1311 throw new DENOPTIMException(msg, t);
1312 }
1313 break;
1314
1315 case "EMBEDRINGSINTEMPLATES=":
1316 {
1318 break;
1319 }
1320
1321 case "RINGEMBEDDINGCONTRACT=":
1322 {
1323 if (value.length() > 0)
1324 {
1325 embeddedRingsContract = ContractLevel.valueOf(value);
1326 }
1327 break;
1328 }
1329
1330 case "FRAGMENTATIONTEMPLATE=":
1331 {
1332 doFragmentation = true;
1333 fragmentationTmplFile = value;
1334 break;
1335 }
1336
1337 case "BONDSAROUNDTOPOCRITICATOM=":
1338 {
1339 maxBufferShellSize = Integer.parseInt(value);
1340 }
1341
1342/*
1343 case "=":
1344 = value;
1345 doFiltering = true;
1346 break;
1347 */
1348
1349 case "PARALLELTASKS=":
1350 try
1351 {
1352 numParallelTasks = Integer.parseInt(value);
1353 }
1354 catch (Throwable t)
1355 {
1356 msg = "Unable to understand value " + key + "'" + value + "'";
1357 throw new DENOPTIMException(msg);
1358 }
1359 break;
1360
1361 case "VERBOSITY=":
1362 try
1363 {
1364 verbosity = Integer.parseInt(value);
1365 }
1366 catch (Throwable t)
1367 {
1368 msg = "Unable to understand value " + key + "'" + value + "'";
1369 throw new DENOPTIMException(msg);
1370 }
1371 break;
1372
1373 default:
1374 msg = "Keyword " + key + " is not a known Fragmenter-"
1375 + "related keyword. Check input files.";
1376 throw new DENOPTIMException(msg);
1377 }
1378 }
1379
1380//------------------------------------------------------------------------------
1381
1385 public List<CuttingRule> getDefaultCuttingRules() throws IOException, DENOPTIMException
1386 {
1387 return getDefaultCuttingRules(this.getClass().getClassLoader());
1388 }
1389
1390//------------------------------------------------------------------------------
1391
1395 public List<CuttingRule> getDefaultCuttingRules(ClassLoader classLoader) throws IOException, DENOPTIMException
1396 {
1397 List<CuttingRule> defaultCuttingRules = new ArrayList<CuttingRule>();
1398 BufferedReader reader = null;
1399 try {
1400 reader = new BufferedReader(
1401 new InputStreamReader(classLoader.getResourceAsStream(
1402 "data/cutting_rules")));
1403 DenoptimIO.readCuttingRules(reader, defaultCuttingRules,
1404 "bundled jar");
1405 } finally {
1406 if (reader!=null)
1407 reader.close();
1408 }
1409 return defaultCuttingRules;
1410 }
1411
1412//------------------------------------------------------------------------------
1413
1420 {
1421 if (!workDir.equals(System.getProperty("user.dir")))
1422 {
1424 }
1425 ensureIsPositive("numParallelTasks", numParallelTasks, "PARALLELTASKS");
1426 ensureIsPositive("isomorphicSampleSize", isomorphicSampleSize,
1427 "ISOMORPHICSAMPLESIZE");
1428 ensureIsPositive("mwSlotSize", mwSlotSize, "MWSLOTSIZE");
1435
1437 }
1438
1439//------------------------------------------------------------------------------
1440
1447 {
1448 if (isMaster)
1450
1451 cuttingRules = new ArrayList<CuttingRule>();
1452 if (cutRulesFile!=null && !cutRulesFile.isBlank())
1453 {
1455 }
1456 if (formulaeFile!=null && !formulaeFile.isBlank())
1457 {
1459 }
1461
1462 if (ignorableFragmentsFile!=null && !ignorableFragmentsFile.isBlank())
1463 {
1464 try
1465 {
1468 } catch (Throwable e)
1469 {
1470 throw new DENOPTIMException("Problems reading file '"
1471 + ignorableFragmentsFile + "'", e);
1472 }
1473 }
1474
1475 if (targetFragmentsFile!=null && !targetFragmentsFile.isBlank())
1476 {
1477 try
1478 {
1481 } catch (Throwable e)
1482 {
1483 throw new DENOPTIMException("Problems reading file '"
1484 + targetFragmentsFile + "'", e);
1485 }
1486 }
1487
1488 if (fragmentationTmplFile!=null && !fragmentationTmplFile.isBlank())
1489 {
1490 try
1491 {
1493 new File(fragmentationTmplFile));
1494 } catch (Throwable e)
1495 {
1496 throw new DENOPTIMException("Problems reading file '"
1497 + fragmentationTmplFile + "'", e);
1498 }
1499 }
1500
1502 {
1504 }
1505
1507 {
1508 doFragmentation = true;
1509 try {
1511 } catch (IOException | DENOPTIMException e) {
1512 throw new DENOPTIMException("Problems reading default cutting rules", e);
1513 }
1514 }
1515
1516 if (isMaster)
1517 {
1518 StaticLogger.appLogger.log(Level.INFO, "Program log file: "
1520 + "Output files associated with the current run are "
1521 + "located in " + workDir);
1522 }
1523 }
1524
1525//------------------------------------------------------------------------------
1526
1528 {
1529 String curDir = workDir;
1530 String fileSep = System.getProperty("file.separator");
1531 boolean success = false;
1532 while (!success)
1533 {
1534 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddkkmmss");
1535 String str = "FRG" + sdf.format(new Date());
1536 workDir = curDir + fileSep + str;
1538 }
1540 logFile = workDir + ".log";
1541 }
1542
1543//------------------------------------------------------------------------------
1544
1551 public String getPrintedList()
1552 {
1553 StringBuilder sb = new StringBuilder(1024);
1554 sb.append(" " + paramTypeName() + " ").append(NL);
1555 for (Field f : this.getClass().getDeclaredFields())
1556 {
1557 try
1558 {
1559 sb.append(f.getName()).append(" = ").append(
1560 f.get(this)).append(NL);
1561 }
1562 catch (Throwable t)
1563 {
1564 sb.append("ERROR! Unable to print " + paramTypeName()
1565 + " parameters. Cause: " + t);
1566 break;
1567 }
1568 }
1569 for (RunTimeParameters otherCollector : otherParameters.values())
1570 {
1571 sb.append(otherCollector.getPrintedList());
1572 }
1573 return sb.toString();
1574 }
1575
1576//------------------------------------------------------------------------------
1577
1582 public double getLinearAngleLimit()
1583 {
1584 return linearAngleLimit;
1585 }
1586
1587//------------------------------------------------------------------------------
1588
1595 {
1596 this.linearAngleLimit = linearAngleLimit;
1597 }
1598
1599//------------------------------------------------------------------------------
1600
1606 {
1608 }
1609
1610//------------------------------------------------------------------------------
1611
1618 {
1619 return sizeUnimodalPop;
1620 }
1621
1622//------------------------------------------------------------------------------
1623
1630 {
1631 this.sizeUnimodalPop = sizeUnimodalPop;
1632 }
1633
1634//------------------------------------------------------------------------------
1635
1643 {
1644 return maxNoiseUnimodalPop;
1645 }
1646
1647//------------------------------------------------------------------------------
1648
1656 {
1657 this.maxNoiseUnimodalPop = maxNoiseUnimodalPop;
1658 }
1659
1660//------------------------------------------------------------------------------
1661
1669 {
1671 }
1672
1673
1674//------------------------------------------------------------------------------
1675
1684 {
1685 this.factorForSDOnStatsOfUnimodalPop = factorForSDOnStatsOfUnimodalPop;
1686 }
1687
1688//------------------------------------------------------------------------------
1689
1697 {
1699 }
1700
1701//------------------------------------------------------------------------------
1702
1712 {
1713 this.useCentroidsAsRepresentativeConformer =
1715 }
1716
1717//------------------------------------------------------------------------------
1718
1725 {
1727 }
1728
1729//------------------------------------------------------------------------------
1730
1739 {
1740 this.saveClustersOfConformerToFile = saveClustersOfConformerToFile;
1741 }
1742
1743//------------------------------------------------------------------------------
1744
1750 {
1752 }
1753
1754//------------------------------------------------------------------------------
1755
1760 public boolean isWorkingIn3D()
1761 {
1762 return workingIn3D;
1763 }
1764
1765//------------------------------------------------------------------------------
1766
1771 public void setWorkingIn3D(boolean workingIn3D)
1772 {
1773 this.workingIn3D = workingIn3D;
1774 }
1775
1776//------------------------------------------------------------------------------
1777
1782 public void setFragmentationTmpls(List<DGraph> fragmentationTmpls) {
1783 this.fragmentationTmpls = fragmentationTmpls;
1784 }
1785
1786//------------------------------------------------------------------------------
1787
1788}
General set of constants used in DENOPTIM.
static final String MWSLOTFRAGSUNQFILENANEEND
Final part of filename used to collect unique fragments in a certain molecular weight slot.
static final String EOL
new line character
static final FileFormat TMPFRAGFILEFORMAT
Format for intermediate files used during fragmentation.
static final String MWSLOTFRAGSFILENAMEROOT
Initial part of filename used to collect fragments belonging to a certain molecular weight slot.
static final String MWSLOTFRAGSALLFILENANEEND
Final part of filename used to collect all samples fragments in a certain molecular weight slot inclu...
static boolean createDirectory(String fileName)
Creates a directory.
Definition: FileUtils.java:231
static void addToRecentFiles(String fileName, FileFormat ff)
Appends an entry to the list of recent files.
Definition: FileUtils.java:67
Utility methods for input/output.
static LinkedHashMap< String, String > readCSDFormulae(File file)
Read molecular formula from TXT data representation produced by Cambridge Structural Database tools (...
static void readCuttingRules(BufferedReader reader, List< CuttingRule > cutRules, String source)
Read cutting rules from a stream.
static ArrayList< DGraph > readDENOPTIMGraphsFromFile(File inFile)
Reads a list of DGraphs from file.
static ArrayList< Vertex > readVertexes(File file, Vertex.BBType bbt)
Reads Vertexes from any file that can contain such items.
static final String FS
File separator from system.
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.
boolean isMaster
Flag signaling this is the master collection of parameters.
String getWorkDirectory()
Gets the pathname to the working directory.
static boolean readYesNoTrueFalse(String s)
Reads a string searching for any common way to say either yes/true (including shorthand t/y) or no/fa...
void ensureFileExists(String pathname)
Ensures a pathname does lead to an existing file or triggers an error.
String paramTypeName()
Returns a string defining the type the parameters collected here.
void ensureIsPositive(String paramName, int value, String paramKey)
Ensures that a parameter is a positive number (x>=0) or triggers an error.
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.
void ensureFileExistsIfSet(String pathname)
Ensures a pathname is not empty nor null and that it does lead to an existing file or triggers an err...
Parameters controlling execution of the fragmenter.
String structuresFile
Pathname to the file containing the structures of the molecules to fragment or the fragments to proce...
void setEmbeddedRingsContract(ContractLevel embeddedRingsContract)
void setFragRejectionSMARTS(Map< String, String > fragRejectionSMARTS)
void setRejectedAPClassCombinations(Set< String[]> rejectedAPClassCombinations)
void setSaveClustersOfConformerToFile(boolean saveClustersOfConformerToFile)
Sets the flag requesting to print clusters of fragments to file upon extraction of the most represent...
void setCuttingRules(List< CuttingRule > cuttingRules)
Assigns the cutting rules loaded from the input.
void setStructuresFile(String structuresFile)
Sets the pathname of the file containing input structures.
void setSizeUnimodalPop(int sizeUnimodalPop)
Sets the size of the population of normally distributed noise-distorted population used to define the...
void setFragmentationTmpls(List< DGraph > fragmentationTmpls)
Sets the list of graph templates for fragmentation.
double factorForSDOnStatsOfUnimodalPop
Factor used to multiply the standard deviation when adding it to the mean of the RMSD for a unimodal ...
void setCheckFormula(boolean checkFormula)
Sets the value of the flag controlling the execution of elemental analysis on the structures.
Set< String > preFilterSMARTS
SMARTS identifying substructures that lead to rejection of a structure before fragmentation.
Map< String, File > mwSlotToUnqFragsFile
Mapping of the molecular weight slot identifier to the file collecting unique fragments belonging to ...
void setFactorForSDOnStatsOfUnimodalPop(double factorForSDOnStatsOfUnimodalPop)
Sets the weight of the standard deviation when calculating the RMSD threshold from the statistics of ...
String cutRulesFile
Pathname to the file containing the cutting rules.
String formulaeFile
Pathname to the file containing the formulae of the molecules to fragment.
ContractLevel embeddedRingsContract
Type of constrain defined for any template generated upon conversion of molecules into DGraph.
void setRejectedFormulaMoreThan(Set< Map< String, Double > > formulaCriteriaMoreThan)
boolean doRejectWeirdIsotopes
Flag requesting to reject fragments with minor isotopes.
int maxBufferShellSize
Maximum number of buffer shells to consider for fragmentation.
void checkParameters()
Evaluate consistency of input parameters.
void interpretKeyword(String key, String value)
Processes a keyword/value pair and assign the related parameters.
void setFragRetentionSMARTS(Map< String, String > fragRetentionSMARTS)
final Object MANAGEMWSLOTSSLOCK
Synchronization lock for manipulating a) the collections (i.e., MW slots) of fragments produced by mu...
boolean doAddDuOnLinearity
Flag requesting to add dummy atoms on linearities.
boolean doPreFilter
Flag requesting the pre-fragmentation filtering of the structures.
double linearAngleLimit
Upper limit for an angle before it is treated as "flat" ("linear") angle, i.e., close enough to 180 D...
int minFragHeavyAtomCount
Lower limit for number of non-H atoms in fragments.
void setAddExplicitH(boolean addExplicitH)
Give true to add explicit H atoms on all atoms.
boolean doFiltering
Flag requesting to do post-fragmentation processing of fragments, i.e., application of all filtration...
void setUseCentroidsAsRepresentativeConformer(boolean useCentroidsAsRepresentativeConformer)
void setRejectedFormulaLessThan(Map< String, Double > formulaMax)
Set< Map< String, Double > > formulaCriteriaMoreThan
Upper limits of formula-based criteria for fragment rejection.
String fragmentationTmplFile
Pathname to file containing a graph to be used as template for fragmentation.
boolean doFragmentation
Flag requesting the fragmentation of the structures.
void setNumTasks(int numParallelTasks)
Sets the number of parallel tasks to run.
AtomicInteger unqIsomorphicFamilyId
Unique identifier of a family of isomorphic versions of a fragment,.
void setLinearAngleLimit(double linearAngleLimit)
Sets the upper limit for an angle before it is treated as "flat" angle, i.e., close enough to 180 DEG...
List< CuttingRule > cuttingRules
List of cutting rules sorted by priority.
String getPrintedList()
Returns the list of parameters in a string with newline characters as delimiters.
File getMWSlotFileNameAllFrags(String mwSlotId)
Builds the pathname of the file meant to hold all isomorphic fragments from a given MW slot.
Set< String > rejectedAPClasses
The initial part of APClasses that lead to rejection of a fragment.
boolean doExtactRepresentativeConformer
Flag signaling the request to analyze each isomorphic family to extract the most representative fragm...
ArrayList< Vertex > targetFragments
List of fragment that will be retained, i.e., any isomorphic fragment of any of these will be kept,...
boolean acceptUnsetToSingeBOApprox
Flag requesting to force-accepting the approximation that converts all unset bond orders to single bo...
boolean workingIn3D
Flag activating operations depending on 3D structure.
Map< String, File > mwSlotToAllFragsFile
Mapping of the molecular weight slot identifier to the file collecting all collected fragments belong...
List< CuttingRule > getDefaultCuttingRules(ClassLoader classLoader)
Get default cutting rules from a given class loader.
boolean doFragExtractionFromGraphs
Flag requesting to extract fragments from graphs.
void setMaxNoiseUnimodalPop(double maxNoiseUnimodalPop)
Sets the maximum noise of the population of normally distributed noise-distorted population used to d...
Set< String > rejectedElements
Symbols of elements that lead to rejection of a fragment.
boolean saveClustersOfConformerToFile
Flag requesting to print clusters of fragments to file.
int mwSlotSize
Molecular weight slot width for collecting fragments.
void setRejectWeirdIsotopes(boolean doRejectWeirdIsotopes)
String newIsomorphicFamilyID()
Produced a new unique identifier for a family of isomorphic fragments.
double maxNoiseUnimodalPop
Maximum amount of absolute noise used to generate normally distributed noise-distorted population of ...
Map< String, String > fragRejectionSMARTS
SMARTS leading to rejection of a fragment.
void setFormulaeFile(String formulaeFile)
Sets the pathname of the file containing molecular formula with a format respecting Cambridge Structu...
File getMWSlotFileNameUnqFrags(String mwSlotId)
Builds the pathname of the file meant to hold unique fragments from within a given MW slot,...
boolean useCentroidsAsRepresentativeConformer
Flag requesting to same cluster centroids rather than the actual fragments that are closest to the ce...
void setCuttingRulesFilePathname(String pathname)
Assigns the pathname to the cutting rules file.
boolean addExplicitH
Flag requesting to add explicit H atoms.
boolean doCheckFormula
Flag requesting the execution of elemental analysis and comparison of the content of the structure fi...
void setEmbedRingsInTemplate(boolean embedRingsInTemplate)
int maxFragHeavyAtomCount
Upper limit for number of non-H atoms in fragments.
int numParallelTasks
Number of parallel tasks to run.
Map< String, Double > formulaCriteriaLessThan
Lower limits of formula-based criteria for fragment rejection.
Map< String, String > fragRetentionSMARTS
SMARTS leading to retention of a fragment.
int sizeUnimodalPop
Size of on-the-fly generated, normally distributed noise-distorted population of geometries used to d...
void setRejectedAPClasses(Set< String > rejectedAPClasses)
boolean isStandaloneFragmentClustering
Flag requesting to run fragment clusterer in stand-alone fashion.
ScaffoldingPolicy scaffoldingPolicy
The policy for defining the scaffold vertex in a graph that does not have such a BBType.
String ignorableFragmentsFile
Pathname to file with fragments that can be ignored.
ArrayList< Vertex > ignorableFragments
List of fragment that can be rejected.
void setRejectedElements(Set< String > rejectedElements)
void processParameters()
Processes all parameters and initialize related objects.
List< DGraph > fragmentationTmpls
List of graphs to be used as templates for fragmentation.
LinkedHashMap< String, String > formulae
Molecular formula read-in from CSD file.
boolean embedRingsInTemplate
Flag that enables the embedding of rings in templates upon conversion of molecules into DGraph.
int isomorphicSampleSize
Size of the sample of isomorphic fragments to collect.
Map< String, Integer > isomorphsCount
Counts of isomorphic versions of each known fragment generated in a fragmentation process.
void setMWSlotToAllFragsFile(Map< String, File > mwSlotToAllFragsFile)
static final int MAXISOMORPHICSAMPLESIZE
Maximum isomorphic sample size.
List< CuttingRule > getDefaultCuttingRules()
Get default cutting rules from the class loader of the current class.
void setWorkingIn3D(boolean workingIn3D)
Sets boolean variable workingIn3D.
String targetFragmentsFile
Pathname to file with fragments that will be retained, i.e., any isomorphic fragment of any of these ...
Set< String[]> rejectedAPClassCombinations
Combination of strings matching the beginning of APClass names that lead to rejection of a fragment.
Utilities for manipulating molecular formulas.
static Map< String, Double > parseFormula(String formula)
Reads a molecular formula written as "H2 O" or "C6 H12 O6".
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
FREE
Inner graphs are free to change within the confines of the required AttachmentPoints.
Definition: Template.java:109
The type of building block.
Definition: Vertex.java:86
FRG_PARAMS
Parameters controlling the fragmenter.