$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.BufferedReader;
22import java.io.File;
23import java.io.IOException;
24import java.io.InputStreamReader;
25import java.lang.reflect.Field;
26import java.util.ArrayList;
27import java.util.HashMap;
28import java.util.HashSet;
29import java.util.List;
30import java.util.Map;
31import java.util.Set;
32import java.util.logging.Level;
33
34import denoptim.exception.DENOPTIMException;
35import denoptim.files.FileUtils;
36import denoptim.fragmenter.BridgeHeadFindingRule;
37import denoptim.graph.APClass;
38import denoptim.io.DenoptimIO;
39import denoptim.logging.StaticLogger;
40import denoptim.programs.RunTimeParameters;
41
42
50{
54 protected boolean closeRings = false;
55
60 //TODO-V3 make controllable from parameters side.
61 public boolean requireCompleteRingclosure = true;
62
66 protected boolean buildChelatesMode = false;
67
75 protected Set<APClass> metalCoordinatingAPClasses =
76 new HashSet<APClass>();
77
81 protected boolean selectFragsFromCC = false;
82
90 protected int rceMode = -1;
91
96 protected int maxRotBonds = 7;
97
102 protected int maxRingSize = 9;
103
107 protected Map<String,Integer> minRcaPerType = new HashMap<String,Integer>();
108
112 protected Map<String,Integer> maxRcaPerType = new HashMap<String,Integer>();
113
117 protected int minRingClosures = 0;
118
122 protected int maxRingClosures = 50;
123
127 protected double linearityLimit = 178.5;
128
139 protected double rcTolDist = 0.33;
140
152 protected double pathConfSearchExtraTol = 1.1;
153
159 protected double rcMaxDot = -0.75;
160
164 protected double pathConfSearchStep = 12.0;
165
170 protected List<Integer> ringSizeBias = new ArrayList<Integer>()
171 {
175 private static final long serialVersionUID = 1L;
176 {
177 for (int i=0; i<maxRingSize+1; i++)
178 {
179 add(0);
180 }
181 if (maxRingSize>=7)
182 {
183 // WARNING: if the default value of maxRingSize is changed
184 // also the default content of this array has to change
185 set(5,2);
186 set(6,4);
187 set(7,1);
188 }
189 }
190 };
191
195 protected Map<String,String> ringClosabCondAsSMARTS =
196 new HashMap<String,String>();
197
201 protected Set<String> reqElInRings = new HashSet<String>();
202
209 protected String rccIndex = "";
210
215 protected String rccFolder = "";
216
221
228 protected boolean exhaustiveConfSrch = false;
229
235 protected boolean checkInterdepPaths = false;
236
242 protected boolean serializeRCCs = false;
243
248 protected List<BridgeHeadFindingRule> bridgeHeadFindingRules;
249
250//-----------------------------------------------------------------------------
251
257 {
260
261 try
262 {
264 new BufferedReader(new InputStreamReader(
265 this.getClass().getClassLoader().getResourceAsStream(
266 "data/bridge-head_finding_rules.json"))));
267 } catch (IOException e)
268 {
269 // should never happen
270 e.printStackTrace();
271 }
272 }
273
274//----------------------------------------------------------------------------
275
277 {
278 return rceMode;
279 }
280
281//----------------------------------------------------------------------------
282
284 {
285 return maxRotBonds;
286 }
287
288//----------------------------------------------------------------------------
289
290 public int getMaxRingSize()
291 {
292 return maxRingSize;
293 }
294
295//----------------------------------------------------------------------------
296
302 public List<Integer> getRingSizeBias()
303 {
304 return ringSizeBias;
305 }
306
307//----------------------------------------------------------------------------
308
316 public void setRingSizeBias(List<Integer> biases)
317 {
318 ringSizeBias = biases;
319 }
320
321//------------------------------------------------------------------------------
322
327 public int getMinRcaPerType(String type)
328 {
329 if (minRcaPerType.containsKey(type))
330 return minRcaPerType.get(type);
331 else
332 return 0;
333 }
334
335//------------------------------------------------------------------------------
336
341 public int getMaxRcaPerType(String type)
342 {
343 if (maxRcaPerType.containsKey(type))
344 return maxRcaPerType.get(type);
345 else
346 return 10000;
347 }
348
349//------------------------------------------------------------------------------
350
352 {
353 return minRingClosures;
354 }
355
356//------------------------------------------------------------------------------
357
359 {
360 return maxRingClosures;
361 }
362
363//----------------------------------------------------------------------------
364
365 public Map<String,String> getConstitutionalClosabilityConds()
366 {
368 }
369
370//----------------------------------------------------------------------------
371
384 Map<String,String> ringClosabCondAsSMARTS)
385 {
386 this.ringClosabCondAsSMARTS = ringClosabCondAsSMARTS;
387 }
388
389//----------------------------------------------------------------------------
390
391 public int getVerbosity()
392 {
393 return verbosity;
394 }
395
396//-----------------------------------------------------------------------------
397
398 public void allowRingClosures(boolean value)
399 {
400 closeRings = value;
401 }
402
403//-----------------------------------------------------------------------------
404
405 public boolean allowRingClosures()
406 {
407 return closeRings;
408 }
409
410//-----------------------------------------------------------------------------
411
412 public boolean buildChelatesMode()
413 {
414 return buildChelatesMode;
415 }
416
417//----------------------------------------------------------------------------
418
420 {
421 return selectFragsFromCC;
422 }
423
424//----------------------------------------------------------------------------
425
426 public double getRCDistTolerance()
427 {
428 return rcTolDist;
429 }
430
431//----------------------------------------------------------------------------
432
434 {
436 }
437
438//----------------------------------------------------------------------------
439
440 public double getRCDotPrTolerance()
441 {
442 return rcMaxDot;
443 }
444
445//----------------------------------------------------------------------------
446
447 public double getLinearityLimit()
448 {
449 return linearityLimit;
450 }
451
452//----------------------------------------------------------------------------
453
454 public double getPathConfSearchStep()
455 {
456 return pathConfSearchStep;
457 }
458
459//----------------------------------------------------------------------------
460
461 public Set<String> getRequiredRingElements()
462 {
463 return reqElInRings;
464 }
465
466//----------------------------------------------------------------------------
467
468 public List<BridgeHeadFindingRule> getBridgeHeadFindingRules()
469 {
471 }
472
473//----------------------------------------------------------------------------
474
476 {
477 return rccIndex;
478 }
479
480//----------------------------------------------------------------------------
481
482 public String getRCCLibraryFolder()
483 {
484 return rccFolder;
485 }
486
487//----------------------------------------------------------------------------
488
490 {
491 return rcArchive;
492 }
493
494//----------------------------------------------------------------------------
495
496 public boolean doExhaustiveConfSrch()
497 {
498 return exhaustiveConfSrch;
499 }
500
501//----------------------------------------------------------------------------
502
503 public boolean serializeRCCs()
504 {
505 return serializeRCCs;
506 }
507
508//----------------------------------------------------------------------------
509
511 {
512 return checkInterdepPaths;
513 }
514
515//----------------------------------------------------------------------------
516
517 public void interpretKeyword(String key, String value)
518 throws DENOPTIMException
519 {
520 String msg = "";
521 switch (key.toUpperCase())
522 {
523 case "VERBOSITY=":
524 try
525 {
526 verbosity = Integer.parseInt(value);
527 }
528 catch (Throwable t)
529 {
530 msg = "Unable to understand value '" + value + "'";
531 throw new DENOPTIMException(msg);
532 }
533 break;
534 case "CLOSERINGS":
535 closeRings = true;
536 break;
537 case "CLOSERINGS=":
538 closeRings = true;
539 break;
540 case "BUILDCHELATESMODE":
541 buildChelatesMode = true;
542 break;
543 case "ORPHANAPCLASS=":
544 buildChelatesMode = true;
546 break;
547 case "SELECTFRAGMENTSFROMCLOSABLECHAINS":
548 selectFragsFromCC = true;
549 break;
550 case "EVALUATIONCLOSABILITYMODE=":
551 switch (value.toUpperCase())
552 {
553 case "RING_SIZE":
554 rceMode = -1;
555 break;
556
557 case "CONSTITUTION":
558 rceMode = 0;
559 break;
560
561 case "3D-CONFORMATION":
562 rceMode = 1;
563 break;
564
565 case "CONSTITUTION_AND_3D-CONFORMATION":
566 rceMode = 2;
567 break;
568
569 default:
570 msg = "Unable to understand value '" + value + "'";
571 throw new DENOPTIMException(msg);
572 }
573 break;
574 case "MAXROTBONDS=":
575 try
576 {
577 maxRotBonds = Integer.parseInt(value);
578 }
579 catch (Throwable t)
580 {
581 msg = "Unable to understand value '" + value + "'";
582 throw new DENOPTIMException(msg);
583 }
584 break;
585 case "MAXSIZENEWRINGS=":
586 try
587 {
588 maxRingSize = Integer.parseInt(value);
589 }
590 catch (Throwable t)
591 {
592 msg = "Unable to understand value '" + value + "'";
593 throw new DENOPTIMException(msg);
594 }
595 break;
596 case "MINRCAPERTYPEPERGRAPH=":
597 try
598 {
599 String[] words = value.trim().split("\\s+");
600 if (words.length!=2)
601 {
602 msg = "Unable to understand value '" + value + "'";
603 throw new DENOPTIMException(msg);
604 }
605 minRcaPerType.put(words[1],Integer.parseInt(words[0]));
606 }
607 catch (Throwable t)
608 {
609 msg = "Unable to understand value '" + value + "'";
610 throw new DENOPTIMException(msg);
611 }
612 break;
613 case "MAXRCAPERTYPEPERGRAPH=":
614 try
615 {
616 String[] words = value.trim().split("\\s+");
617 if (words.length!=2)
618 {
619 msg = "Unable to understand value '" + value + "'";
620 throw new DENOPTIMException(msg);
621 }
622 maxRcaPerType.put(words[1],Integer.parseInt(words[0]));
623 }
624 catch (Throwable t)
625 {
626 msg = "Unable to understand value '" + value + "'";
627 throw new DENOPTIMException(msg);
628 }
629 break;
630 case "MINNUMBEROFRINGCLOSURES=":
631 try
632 {
633 minRingClosures = Integer.parseInt(value);
634 }
635 catch (Throwable t)
636 {
637 msg = "Unable to understand value '" + value + "'";
638 throw new DENOPTIMException(msg);
639 }
640 break;
641 case "MAXNUMBERRINGCLOSURES=":
642 try
643 {
644 maxRingClosures = Integer.parseInt(value);
645 }
646 catch (Throwable t)
647 {
648 msg = "Unable to understand value '" + value + "'";
649 throw new DENOPTIMException(msg);
650 }
651 break;
652 case "LINEARITYLIMIT=":
653 try
654 {
655 linearityLimit = Double.parseDouble(value);
656 }
657 catch (Throwable t)
658 {
659 msg = "Unable to understand value '" + value + "'";
660 throw new DENOPTIMException(msg);
661 }
662 break;
663 case "DISTANCETOLERANCEFACTOR=":
664 try
665 {
666 rcTolDist = Double.parseDouble(value);
667 }
668 catch (Throwable t)
669 {
670 msg = "Unable to understand value '" + value + "'";
671 throw new DENOPTIMException(msg);
672 }
673 break;
674 case "EXTRADISTANCETOLERANCEFACTOR=":
675 try
676 {
677 pathConfSearchExtraTol = Double.parseDouble(value);
678 }
679 catch (Throwable t)
680 {
681 msg = "Unable to understand value '" + value + "'";
682 throw new DENOPTIMException(msg);
683 }
684 break;
685 case "MAXDOTPROD=":
686 try
687 {
688 rcMaxDot = Double.parseDouble(value);
689 }
690 catch (Throwable t)
691 {
692 msg = "Unable to understand value '" + value + "'";
693 throw new DENOPTIMException(msg);
694 }
695 break;
696 case "CONFSEARCHSTEP=":
697 try
698 {
699 pathConfSearchStep = Double.parseDouble(value);
700 }
701 catch (Throwable t)
702 {
703 msg = "Unable to understand value '" + value + "'";
704 throw new DENOPTIMException(msg);
705 }
706 break;
707 case "RINGSIZEBIAS=":
708 String[] words = value.split("\\s+");
709 if (words.length != 2)
710 {
711 msg = "Unable to read ring size and bias weight from "
712 + "'" + value + "'. Expected syntax is: "
713 + "'5 2' as to specify that 5-member rings "
714 + "are given a weight of 2.";
715 throw new DENOPTIMException(msg);
716 }
717 int size = -1;
718 int weight = 0;
719 try
720 {
721 size = Integer.parseInt(words[0]);
722 } catch (Throwable t)
723 {
724 throw new DENOPTIMException("Ring size must be an integer");
725 }
726 try
727 {
728 weight = Integer.parseInt(words[1]);
729 } catch (Throwable t)
730 {
731 throw new DENOPTIMException("Bias weight must be an integer");
732 }
733 if (size < 0)
734 {
735 msg = "Ring size must be >= 0";
736 throw new DENOPTIMException(msg);
737 }
738 if (weight < 0)
739 {
740 msg = "Bias for ring size must be >= 0";
741 throw new DENOPTIMException(msg);
742 }
743 if (size > maxRingSize)
744 {
745 for (int i=maxRingSize+1; i<size; i++)
746 {
747 ringSizeBias.add(0);
748 }
749 ringSizeBias.add(weight);
750 maxRingSize = size;
751 }
752 else
753 {
754 ringSizeBias.set(size,weight);
755 }
756 break;
757
758 case "CLOSABLERINGSMARTS=":
759 int id = ringClosabCondAsSMARTS.size();
760 ringClosabCondAsSMARTS.put("q"+id,value);
761 break;
762
763 case "REQUIREDELEMENTINRINGS=":
764 reqElInRings.add(value);
765 break;
766
767 case "RCCINDEX=":
768 rccIndex = value;
769 break;
770
771 case "RCCFOLDER=":
772 serializeRCCs = true;
773 rccFolder = value;
774 break;
775
776 case "EXHAUSTIVECONFSEARCH":
777 exhaustiveConfSrch = true;
778 break;
779
780 case "CHECKINTERDEPENDENTCHAINS":
781 checkInterdepPaths = true;
782 break;
783
784 case "BRIDGEHEADFINDINGRULESFILE=":
785 {
787 value);
788 break;
789 }
790
791 default:
792 msg = "Keyword '" + key + "' is not a known ring closure-"
793 + "related keyword. Check input files.";
794 throw new DENOPTIMException(msg);
795 }
796 }
797
798//----------------------------------------------------------------------------
799
801 {
802 String msg = "";
803 if (!closeRings)
804 {
805 msg = "The use of ring-closure related keywords "
806 + "is dependent on the activation of the ring-closing "
807 + "machinery (use "
808 + ParametersType.RC_PARAMS.getKeywordRoot()
809 + "CLOSERINGS keyword).";
810 throw new DENOPTIMException(msg);
811 }
812
813 if (rceMode > 2)
814 {
815 msg = "Unknown ring-closure evaluation mode '" + rceMode + "' "
816 + "Acceptable values are: "
817 + "-1 (only ring size)"
818 + "0 (only contitutional), "
819 + "1 (only 3D chain), "
820 + "2 (both constitutional and 3D chain). ";
821 throw new DENOPTIMException(msg);
822 }
823
825 {
826 File folder = new File(rccFolder);
827 try
828 {
829 folder.mkdir();
830 }
831 catch (Throwable t2)
832 {
833 msg = "CyclicGraphHandler can't make folder " + rccFolder
834 + ". " + t2;
835 throw new DENOPTIMException(msg);
836 }
837 }
838
840 {
841 msg = "To use the BuildChelates mode you need to perform "
842 + "experiments capable of closing/opening and modifying "
843 + "rings. See the "
844 + ParametersType.RC_PARAMS.getKeywordRoot()
845 + "CLOSERINGS keyword "
846 + "and provide the related input (i.e., ring "
847 + "closing attractor fragments).";
848 throw new DENOPTIMException(msg);
849 }
850
851 for (String type : minRcaPerType.keySet())
852 {
853 if (minRcaPerType.get(type) > maxRcaPerType.get(type))
854 {
855 msg = "Check values of max and min number of RCA for type '"
856 + type+"'.";
857 throw new DENOPTIMException(msg);
858 }
859 }
860
862 {
863 msg = "Check values of minRingClosures and maxRingClosures";
864 throw new DENOPTIMException(msg);
865 }
866
868 {
869 exhaustiveConfSrch = true;
870 }
871
873 {
874 msg = "Exhaustive conformational search has been turned ON. "
875 + "This is a very time consuming task!";
876 StaticLogger.appLogger.log(Level.WARNING,msg);
877 }
878
880 {
881 msg = "DENOPTIM can guide the selection of fragments to "
882 + "those leading to known closable chains. This "
883 + "functionality is currently under development "
884 + "and is fully operative only for rings "
885 + "involving the scaffolds. ";
886 StaticLogger.appLogger.log(Level.WARNING,msg);
887 }
889 }
890
891//----------------------------------------------------------------------------
892
894 {
895 rcArchive = new RingClosuresArchive(this);
897 }
898
899//------------------------------------------------------------------------------
900
907 public String getPrintedList()
908 {
909 StringBuilder sb = new StringBuilder(1024);
910 sb.append(" " + paramTypeName() + " ").append(NL);
911 for (Field f : this.getClass().getDeclaredFields())
912 {
913 try
914 {
915 sb.append(f.getName()).append(" = ").append(
916 f.get(this)).append(NL);
917 }
918 catch (Throwable t)
919 {
920 sb.append("ERROR! Unable to print " + paramTypeName()
921 + " parameters. Cause: " + t);
922 break;
923 }
924 }
925 for (RunTimeParameters otherCollector : otherParameters.values())
926 {
927 sb.append(otherCollector.getPrintedList());
928 }
929 return sb.toString();
930 }
931
932//------------------------------------------------------------------------------
933
934}
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:164
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.
List< BridgeHeadFindingRule > getBridgeHeadFindingRules()
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< BridgeHeadFindingRule > bridgeHeadFindingRules
Rules that identify the atoms that can become bridge heads to form fused rings.
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...
Utility methods for input/output.
static List< BridgeHeadFindingRule > readBridgeHesFindingRules(String fileName)
Reads a list of rules for identifying potential bridge-head sites.
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.