$darkmode
DENOPTIM
RingClosureParameters.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.graph.rings;
20
21import java.io.File;
22import java.lang.reflect.Field;
23import java.util.ArrayList;
24import java.util.HashMap;
25import java.util.HashSet;
26import java.util.List;
27import java.util.Map;
28import java.util.Set;
29import java.util.logging.Level;
30
31import denoptim.exception.DENOPTIMException;
32import denoptim.files.FileUtils;
33import denoptim.graph.APClass;
34import denoptim.logging.StaticLogger;
35import denoptim.programs.RunTimeParameters;
36
37
45{
49 protected boolean closeRings = false;
50
55 //TODO-V3 make controllable from parameters side.
56 public boolean requireCompleteRingclosure = true;
57
61 protected boolean buildChelatesMode = false;
62
70 protected Set<APClass> metalCoordinatingAPClasses =
71 new HashSet<APClass>();
72
76 protected boolean selectFragsFromCC = false;
77
85 protected int rceMode = -1;
86
91 protected int maxRotBonds = 7;
92
97 protected int maxRingSize = 9;
98
102 protected Map<String,Integer> minRcaPerType = new HashMap<String,Integer>();
103
107 protected Map<String,Integer> maxRcaPerType = new HashMap<String,Integer>();
108
112 protected int minRingClosures = 0;
113
117 protected int maxRingClosures = 50;
118
122 protected double linearityLimit = 178.5;
123
134 protected double rcTolDist = 0.33;
135
147 protected double pathConfSearchExtraTol = 1.1;
148
154 protected double rcMaxDot = -0.75;
155
159 protected double pathConfSearchStep = 12.0;
160
165 protected List<Integer> ringSizeBias = new ArrayList<Integer>()
166 {
170 private static final long serialVersionUID = 1L;
171 {
172 for (int i=0; i<maxRingSize+1; i++)
173 {
174 add(0);
175 }
176 if (maxRingSize>=7)
177 {
178 // WARNING: if the default value of maxRingSize is changed
179 // also the default content of this array has to change
180 set(5,2);
181 set(6,4);
182 set(7,1);
183 }
184 }
185 };
186
190 protected Map<String,String> ringClosabCondAsSMARTS =
191 new HashMap<String,String>();
192
196 protected Set<String> reqElInRings = new HashSet<String>();
197
204 protected String rccIndex = "";
205
210 protected String rccFolder = "";
211
216
223 protected boolean exhaustiveConfSrch = false;
224
230 protected boolean checkInterdepPaths = false;
231
237 protected boolean serializeRCCs = false;
238
239//-----------------------------------------------------------------------------
240
246 {
249 }
250
251//----------------------------------------------------------------------------
252
254 {
255 return rceMode;
256 }
257
258//----------------------------------------------------------------------------
259
261 {
262 return maxRotBonds;
263 }
264
265//----------------------------------------------------------------------------
266
267 public int getMaxRingSize()
268 {
269 return maxRingSize;
270 }
271
272//----------------------------------------------------------------------------
273
279 public List<Integer> getRingSizeBias()
280 {
281 return ringSizeBias;
282 }
283
284//----------------------------------------------------------------------------
285
293 public void setRingSizeBias(List<Integer> biases)
294 {
295 ringSizeBias = biases;
296 }
297
298//------------------------------------------------------------------------------
299
304 public int getMinRcaPerType(String type)
305 {
306 if (minRcaPerType.containsKey(type))
307 return minRcaPerType.get(type);
308 else
309 return 0;
310 }
311
312//------------------------------------------------------------------------------
313
318 public int getMaxRcaPerType(String type)
319 {
320 if (maxRcaPerType.containsKey(type))
321 return maxRcaPerType.get(type);
322 else
323 return 10000;
324 }
325
326//------------------------------------------------------------------------------
327
329 {
330 return minRingClosures;
331 }
332
333//------------------------------------------------------------------------------
334
336 {
337 return maxRingClosures;
338 }
339
340//----------------------------------------------------------------------------
341
342 public Map<String,String> getConstitutionalClosabilityConds()
343 {
345 }
346
347//----------------------------------------------------------------------------
348
361 Map<String,String> ringClosabCondAsSMARTS)
362 {
363 this.ringClosabCondAsSMARTS = ringClosabCondAsSMARTS;
364 }
365
366//----------------------------------------------------------------------------
367
368 public int getVerbosity()
369 {
370 return verbosity;
371 }
372
373//-----------------------------------------------------------------------------
374
375 public void allowRingClosures(boolean value)
376 {
377 closeRings = value;
378 }
379
380//-----------------------------------------------------------------------------
381
382 public boolean allowRingClosures()
383 {
384 return closeRings;
385 }
386
387//-----------------------------------------------------------------------------
388
389 public boolean buildChelatesMode()
390 {
391 return buildChelatesMode;
392 }
393
394//----------------------------------------------------------------------------
395
397 {
398 return selectFragsFromCC;
399 }
400
401//----------------------------------------------------------------------------
402
403 public double getRCDistTolerance()
404 {
405 return rcTolDist;
406 }
407
408//----------------------------------------------------------------------------
409
411 {
413 }
414
415//----------------------------------------------------------------------------
416
417 public double getRCDotPrTolerance()
418 {
419 return rcMaxDot;
420 }
421
422//----------------------------------------------------------------------------
423
424 public double getLinearityLimit()
425 {
426 return linearityLimit;
427 }
428
429//----------------------------------------------------------------------------
430
431 public double getPathConfSearchStep()
432 {
433 return pathConfSearchStep;
434 }
435
436//----------------------------------------------------------------------------
437
438 public Set<String> getRequiredRingElements()
439 {
440 return reqElInRings;
441 }
442
443//----------------------------------------------------------------------------
444
446 {
447 return rccIndex;
448 }
449
450//----------------------------------------------------------------------------
451
452 public String getRCCLibraryFolder()
453 {
454 return rccFolder;
455 }
456
457//----------------------------------------------------------------------------
458
460 {
461 return rcArchive;
462 }
463
464//----------------------------------------------------------------------------
465
466 public boolean doExhaustiveConfSrch()
467 {
468 return exhaustiveConfSrch;
469 }
470
471//----------------------------------------------------------------------------
472
473 public boolean serializeRCCs()
474 {
475 return serializeRCCs;
476 }
477
478//----------------------------------------------------------------------------
479
481 {
482 return checkInterdepPaths;
483 }
484
485//----------------------------------------------------------------------------
486
487 public void interpretKeyword(String key, String value)
488 throws DENOPTIMException
489 {
490 String msg = "";
491 switch (key.toUpperCase())
492 {
493 case "VERBOSITY=":
494 try
495 {
496 verbosity = Integer.parseInt(value);
497 }
498 catch (Throwable t)
499 {
500 msg = "Unable to understand value '" + value + "'";
501 throw new DENOPTIMException(msg);
502 }
503 break;
504 case "CLOSERINGS":
505 closeRings = true;
506 break;
507 case "CLOSERINGS=":
508 closeRings = true;
509 break;
510 case "BUILDCHELATESMODE":
511 buildChelatesMode = true;
512 break;
513 case "ORPHANAPCLASS=":
514 buildChelatesMode = true;
516 break;
517 case "SELECTFRAGMENTSFROMCLOSABLECHAINS":
518 selectFragsFromCC = true;
519 break;
520 case "EVALUATIONCLOSABILITYMODE=":
521 switch (value.toUpperCase())
522 {
523 case "RING_SIZE":
524 rceMode = -1;
525 break;
526
527 case "CONSTITUTION":
528 rceMode = 0;
529 break;
530
531 case "3D-CONFORMATION":
532 rceMode = 1;
533 break;
534
535 case "CONSTITUTION_AND_3D-CONFORMATION":
536 rceMode = 2;
537 break;
538
539 default:
540 msg = "Unable to understand value '" + value + "'";
541 throw new DENOPTIMException(msg);
542 }
543 break;
544 case "MAXROTBONDS=":
545 try
546 {
547 maxRotBonds = Integer.parseInt(value);
548 }
549 catch (Throwable t)
550 {
551 msg = "Unable to understand value '" + value + "'";
552 throw new DENOPTIMException(msg);
553 }
554 break;
555 case "MAXSIZENEWRINGS=":
556 try
557 {
558 maxRingSize = Integer.parseInt(value);
559 }
560 catch (Throwable t)
561 {
562 msg = "Unable to understand value '" + value + "'";
563 throw new DENOPTIMException(msg);
564 }
565 break;
566 case "MINRCAPERTYPEPERGRAPH=":
567 try
568 {
569 String[] words = value.trim().split("\\s+");
570 if (words.length!=2)
571 {
572 msg = "Unable to understand value '" + value + "'";
573 throw new DENOPTIMException(msg);
574 }
575 minRcaPerType.put(words[1],Integer.parseInt(words[0]));
576 }
577 catch (Throwable t)
578 {
579 msg = "Unable to understand value '" + value + "'";
580 throw new DENOPTIMException(msg);
581 }
582 break;
583 case "MAXRCAPERTYPEPERGRAPH=":
584 try
585 {
586 String[] words = value.trim().split("\\s+");
587 if (words.length!=2)
588 {
589 msg = "Unable to understand value '" + value + "'";
590 throw new DENOPTIMException(msg);
591 }
592 maxRcaPerType.put(words[1],Integer.parseInt(words[0]));
593 }
594 catch (Throwable t)
595 {
596 msg = "Unable to understand value '" + value + "'";
597 throw new DENOPTIMException(msg);
598 }
599 break;
600 case "MINNUMBEROFRINGCLOSURES=":
601 try
602 {
603 minRingClosures = Integer.parseInt(value);
604 }
605 catch (Throwable t)
606 {
607 msg = "Unable to understand value '" + value + "'";
608 throw new DENOPTIMException(msg);
609 }
610 break;
611 case "MAXNUMBERRINGCLOSURES=":
612 try
613 {
614 maxRingClosures = Integer.parseInt(value);
615 }
616 catch (Throwable t)
617 {
618 msg = "Unable to understand value '" + value + "'";
619 throw new DENOPTIMException(msg);
620 }
621 break;
622 case "LINEARITYLIMIT=":
623 try
624 {
625 linearityLimit = Double.parseDouble(value);
626 }
627 catch (Throwable t)
628 {
629 msg = "Unable to understand value '" + value + "'";
630 throw new DENOPTIMException(msg);
631 }
632 break;
633 case "DISTANCETOLERANCEFACTOR=":
634 try
635 {
636 rcTolDist = Double.parseDouble(value);
637 }
638 catch (Throwable t)
639 {
640 msg = "Unable to understand value '" + value + "'";
641 throw new DENOPTIMException(msg);
642 }
643 break;
644 case "EXTRADISTANCETOLERANCEFACTOR=":
645 try
646 {
647 pathConfSearchExtraTol = Double.parseDouble(value);
648 }
649 catch (Throwable t)
650 {
651 msg = "Unable to understand value '" + value + "'";
652 throw new DENOPTIMException(msg);
653 }
654 break;
655 case "MAXDOTPROD=":
656 try
657 {
658 rcMaxDot = Double.parseDouble(value);
659 }
660 catch (Throwable t)
661 {
662 msg = "Unable to understand value '" + value + "'";
663 throw new DENOPTIMException(msg);
664 }
665 break;
666 case "CONFSEARCHSTEP=":
667 try
668 {
669 pathConfSearchStep = Double.parseDouble(value);
670 }
671 catch (Throwable t)
672 {
673 msg = "Unable to understand value '" + value + "'";
674 throw new DENOPTIMException(msg);
675 }
676 break;
677 case "RINGSIZEBIAS=":
678 String[] words = value.split("\\s+");
679 if (words.length != 2)
680 {
681 msg = "Unable to read ring size and bias wevight from "
682 + "'" + value + "'. Expected syntax is: "
683 + "'5 2' as to specify that 5-member rings "
684 + "are given a weight of 2.";
685 throw new DENOPTIMException(msg);
686 }
687 int size = -1;
688 int weight = 0;
689 try
690 {
691 size = Integer.parseInt(words[0]);
692 } catch (Throwable t)
693 {
694 throw new DENOPTIMException("Ring size must be an integer");
695 }
696 try
697 {
698 weight = Integer.parseInt(words[1]);
699 } catch (Throwable t)
700 {
701 throw new DENOPTIMException("Bias weight must be an integer");
702 }
703 if (size < 0)
704 {
705 msg = "Ring size must be >= 0";
706 throw new DENOPTIMException(msg);
707 }
708 if (weight < 0)
709 {
710 msg = "Bias for ring size must be >= 0";
711 throw new DENOPTIMException(msg);
712 }
713 if (size > maxRingSize)
714 {
715 for (int i=maxRingSize+1; i<size; i++)
716 {
717 ringSizeBias.add(0);
718 }
719 ringSizeBias.add(weight);
720 maxRingSize = size;
721 }
722 else
723 {
724 ringSizeBias.set(size,weight);
725 }
726 break;
727 case "CLOSABLERINGSMARTS=":
728 int id = ringClosabCondAsSMARTS.size();
729 ringClosabCondAsSMARTS.put("q"+id,value);
730 break;
731 case "REQUIREDELEMENTINRINGS=":
732 reqElInRings.add(value);
733 break;
734 case "RCCINDEX=":
735 rccIndex = value;
736 break;
737 case "RCCFOLDER=":
738 serializeRCCs = true;
739 rccFolder = value;
740 break;
741 case "EXHAUSTIVECONFSEARCH":
742 exhaustiveConfSrch = true;
743 break;
744 case "CHECKINTERDEPENDENTCHAINS":
745 checkInterdepPaths = true;
746 break;
747 default:
748 msg = "Keyword '" + key + "' is not a known ring closure-"
749 + "related keyword. Check input files.";
750 throw new DENOPTIMException(msg);
751 }
752 }
753
754//----------------------------------------------------------------------------
755
757 {
758 String msg = "";
759 if (!closeRings)
760 {
761 msg = "The use of ring-closure related keywords "
762 + "is dependent on the activation of the ring-closing "
763 + "machinery (use "
764 + ParametersType.RC_PARAMS.getKeywordRoot()
765 + "CLOSERINGS keyword).";
766 throw new DENOPTIMException(msg);
767 }
768
769 if (rceMode > 2)
770 {
771 msg = "Unknown ring-closure evaluation mode '" + rceMode + "' "
772 + "Acceptable values are: "
773 + "-1 (only ring size)"
774 + "0 (only contitutional), "
775 + "1 (only 3D chain), "
776 + "2 (both constitutional and 3D chain). ";
777 throw new DENOPTIMException(msg);
778 }
779
781 {
782 File folder = new File(rccFolder);
783 try
784 {
785 folder.mkdir();
786 }
787 catch (Throwable t2)
788 {
789 msg = "CyclicGraphHandler can't make folder " + rccFolder
790 + ". " + t2;
791 throw new DENOPTIMException(msg);
792 }
793 }
794
796 {
797 msg = "To use the BuildChelates mode you need to perform "
798 + "experiments capable of closing/opening and modifying "
799 + "rings. See the "
800 + ParametersType.RC_PARAMS.getKeywordRoot()
801 + "CLOSERINGS keyword "
802 + "and provide the related input (i.e., ring "
803 + "closing attractor fragments).";
804 throw new DENOPTIMException(msg);
805 }
806
807 for (String type : minRcaPerType.keySet())
808 {
809 if (minRcaPerType.get(type) > maxRcaPerType.get(type))
810 {
811 msg = "Check values of max and min number of RCA for type '"
812 + type+"'.";
813 throw new DENOPTIMException(msg);
814 }
815 }
816
818 {
819 msg = "Check values of minRingClosures and maxRingClosures";
820 throw new DENOPTIMException(msg);
821 }
822
824 {
825 exhaustiveConfSrch = true;
826 }
827
829 {
830 msg = "Exhaustive conformational search has been turned ON. "
831 + "This is a very time consuming task!";
832 StaticLogger.appLogger.log(Level.WARNING,msg);
833 }
834
836 {
837 msg = "DENOPTIM can guide the selection of fragments to "
838 + "those leading to known closable chains. This "
839 + "functionality is currently under development "
840 + "and is fully operative only for rings "
841 + "involving the scaffolds. ";
842 StaticLogger.appLogger.log(Level.WARNING,msg);
843 }
845 }
846
847//----------------------------------------------------------------------------
848
850 {
851 rcArchive = new RingClosuresArchive(this);
853 }
854
855//------------------------------------------------------------------------------
856
863 public String getPrintedList()
864 {
865 StringBuilder sb = new StringBuilder(1024);
866 sb.append(" " + paramTypeName() + " ").append(NL);
867 for (Field f : this.getClass().getDeclaredFields())
868 {
869 try
870 {
871 sb.append(f.getName()).append(" = ").append(
872 f.get(this)).append(NL);
873 }
874 catch (Throwable t)
875 {
876 sb.append("ERROR! Unable to print " + paramTypeName()
877 + " parameters. Cause: " + t);
878 break;
879 }
880 }
881 for (RunTimeParameters otherCollector : otherParameters.values())
882 {
883 sb.append(otherCollector.getPrintedList());
884 }
885 return sb.toString();
886 }
887
888//------------------------------------------------------------------------------
889
890}
static boolean checkExists(String fileName)
Definition: FileUtils.java:241
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
Parameters and setting related to handling ring closures.
int getVerbosity()
Returns the level of verbosity, i.e., the amount of log that we want to print.
int maxRingSize
Maximum size (number of atoms) in ring closing chain.
Map< String, String > ringClosabCondAsSMARTS
SMARTS defining the constitution-based ring closability condition.
void setRingSizeBias(List< Integer > biases)
Sets the preference for certain ring sizes or the prohibition to generate certain rings (i....
int maxRingClosures
Maximum number of RingClosures in a valid graph.
boolean serializeRCCs
FLag controlling the serialization of the RingClosingConformations.
boolean requireCompleteRingclosure
Flag requesting complete ring closure of all pairs of RCAs in at least one combination of RCAs to con...
Set< APClass > metalCoordinatingAPClasses
List of metal-coordinating APClasses.
String getPrintedList()
Returns the list of parameters in a string with newline characters as delimiters.
void processParameters()
Processes all parameters and initialize related objects.
Set< String > reqElInRings
Required elements in closable chains.
double rcMaxDot
Maximum value of dot product between the normalized attachment point vectors at the head and tail of ...
double pathConfSearchStep
Torsion angle step for conformational scan of candidate closable chain.
double pathConfSearchExtraTol
Extra tolerance factor for interatomic distances.
String rccIndex
Pathname of the text file containing the list of visited RingClosingConformations (i....
void checkParameters()
Evaluate consistency of input parameters.
Map< String, Integer > maxRcaPerType
Maximum number of RingClosingAttractors in a valid graph.
boolean selectFragsFromCC
Flag activating the biased selection of closable fragment chains.
boolean exhaustiveConfSrch
Flag controlling conformational search.
String rccFolder
Pathname of the root folder containing the archive of serialized RingClosingConformations.
int maxRotBonds
Maximum number of rotatable bonds for which conformational space is explored.
boolean buildChelatesMode
Flag activating procedures favoring formation of chelates.
int minRingClosures
Minimum number of RingClosures in a valid graph.
void setConstitutionalClosabilityConds(Map< String, String > ringClosabCondAsSMARTS)
Sets the list of constitutions that can be formed by ring closure.
RingClosuresArchive rcArchive
Collection of information about ring-closability of graph substructures.
double linearityLimit
Maximum value for non-flat bond angle (in degree).
void interpretKeyword(String key, String value)
Processes a keyword/value pair and assign the related parameters.
double rcTolDist
Tolerance factor for interatomic distances.
boolean closeRings
Flag activating the ring closing machinery.
Map< String, Integer > minRcaPerType
Minimum number of RingClosingAttractors in a valid graph.
int rceMode
The ring closability evaluation mode: -1= only ring rize bias 0 = only constitution of candidate ring...
boolean checkInterdepPaths
Flag controlling the ring-closing criterion evaluating the simultaneous closability of interdependent...
List< Integer > ringSizeBias
Relative weight of ring sizes to bias the selection of a ring combination among the various alternati...
Data structure to store and handle information about sub-structures (i.e., chains of fragments) and r...
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.
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.
RC_PARAMS
Parameters pertaining to ring closures in graphs.