$darkmode
DENOPTIM
FragmentSpace.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2019 Vishwesh Venkatraman <vishwesh.venkatraman@ntnu.no> and
4 * Marco Foscato <marco.foscato@uib.no>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20package denoptim.fragspace;
21
22import java.io.File;
23import java.io.IOException;
24import java.util.ArrayList;
25import java.util.HashMap;
26import java.util.HashSet;
27import java.util.List;
28import java.util.Map;
29import java.util.Set;
30import java.util.logging.Level;
31
32import javax.vecmath.Point3d;
33
34import org.openscience.cdk.Atom;
35import org.openscience.cdk.PseudoAtom;
36import org.openscience.cdk.interfaces.IAtomContainer;
37
38import denoptim.constants.DENOPTIMConstants;
39import denoptim.exception.DENOPTIMException;
40import denoptim.files.UndetectedFileFormatException;
41import denoptim.graph.APClass;
42import denoptim.graph.APMapping;
43import denoptim.graph.AttachmentPoint;
44import denoptim.graph.Candidate;
45import denoptim.graph.DGraph;
46import denoptim.graph.Fragment;
47import denoptim.graph.GraphPattern;
48import denoptim.graph.Template;
49import denoptim.graph.Vertex;
50import denoptim.graph.Vertex.BBType;
51import denoptim.graph.rings.RingClosingAttractor;
52import denoptim.io.DenoptimIO;
53import denoptim.utils.GraphUtils;
54import denoptim.utils.MoleculeUtils;
55import denoptim.utils.Randomizer;
56
66public class FragmentSpace
67{
75 private ArrayList<Vertex> scaffoldLib = null;
76
84 private ArrayList<Vertex> fragmentLib = null;
85
94 private ArrayList<Vertex> cappingLib = null;
95
100 private HashMap<APClass, ArrayList<APClass>> apClassCompatibilityMatrix;
101
106 private ArrayList<Vertex> rcvs = new ArrayList<Vertex>();
107
112 private HashMap<APClass, ArrayList<APClass>> rcCompatMap;
113
118 private HashMap<APClass, APClass> cappingMap;
119
123 private Set<APClass> forbiddenEndList;
124
128 private HashMap<Integer, ArrayList<Integer>> fragPoolPerNumAP;
129
133 private HashMap<Integer, ArrayList<APClass>> apClassesPerFrag;
134
138 private HashMap<APClass, ArrayList<ArrayList<Integer>>> fragsApsPerApClass;
139
143 private final Object LOCK = new Object();
144
148 private HashMap<APClass, Double> symmConstraints;
149
153 private boolean apClassBasedApproch = false;
154
158 private boolean isValid = false;
159
165
166//------------------------------------------------------------------------------
167
175 {
176 fragmentLib = new ArrayList<Vertex>();
177 scaffoldLib = new ArrayList<Vertex>();
178 cappingLib = new ArrayList<Vertex>();
180 }
181
182//------------------------------------------------------------------------------
183
200 String fragFile, String capFile, String cpmFile)
201 throws DENOPTIMException
202 {
203 this(settings, scaffFile, fragFile, capFile, cpmFile, "",
204 new HashMap<APClass, Double>());
205 }
206
207//------------------------------------------------------------------------------
208
231 ArrayList<Vertex> scaffLib,
232 ArrayList<Vertex> fragLib,
233 ArrayList<Vertex> cappLib,
234 HashMap<APClass, ArrayList<APClass>> cpMap,
235 HashMap<APClass, APClass> capMap,
236 HashSet<APClass> forbEnds,
237 HashMap<APClass, ArrayList<APClass>> rcCpMap)
238 throws DENOPTIMException
239 {
240 define(settings, scaffLib, fragLib, cappLib, cpMap, capMap, forbEnds,
241 rcCpMap, null);
242 }
243
244//------------------------------------------------------------------------------
245
269 ArrayList<Vertex> scaffLib,
270 ArrayList<Vertex> fragLib,
271 ArrayList<Vertex> cappLib,
272 HashMap<APClass, ArrayList<APClass>> cpMap,
273 HashMap<APClass, APClass> capMap,
274 HashSet<APClass> forbEnds,
275 HashMap<APClass, ArrayList<APClass>> rcCpMap,
276 HashMap<APClass, Double> symCntrMap)
277 throws DENOPTIMException
278 {
279 define(settings, scaffLib, fragLib, cappLib, cpMap, capMap, forbEnds,
280 rcCpMap, symCntrMap);
281 }
282
283//------------------------------------------------------------------------------
284
305 String fragFile, String capFile, String cpmFile, String rcpmFile,
306 HashMap<APClass, Double> symCntrMap) throws DENOPTIMException
307 {
308 HashMap<APClass, ArrayList<APClass>> cpMap =
309 new HashMap<APClass, ArrayList<APClass>>();
310 HashMap<APClass, APClass> capMap = new HashMap<APClass, APClass>();
311 HashSet<APClass> forbEnds = new HashSet<APClass>();
312 if (cpmFile.length() > 0)
313 {
314 DenoptimIO.readCompatibilityMatrix(cpmFile, cpMap, capMap,
315 forbEnds);
316 }
317
318 HashMap<APClass, ArrayList<APClass>> rcCpMap =
319 new HashMap<APClass, ArrayList<APClass>>();
320 if (rcpmFile != null && rcpmFile.length() > 0)
321 {
322 DenoptimIO.readRCCompatibilityMatrix(rcpmFile, rcCpMap);
323 }
324
325 ArrayList<Vertex> cappLib = new ArrayList<Vertex>();
326 if (capFile.length() > 0)
327 {
328 try
329 {
330 cappLib = DenoptimIO.readVertexes(new File(capFile),
331 BBType.CAP);
332 for (int i=0; i<cappLib.size(); i++)
333 {
334 cappLib.get(i).setBuildingBlockId(i);
335 }
336 } catch (IllegalArgumentException | UndetectedFileFormatException
337 | IOException | DENOPTIMException e)
338 {
339 throw new DENOPTIMException("Cound not read library of capping "
340 + "groups from file '" + capFile + "'.", e);
341 }
342 }
343
344 ArrayList<Vertex> fragLib = new ArrayList<Vertex>();
345 if (fragFile != null && fragFile.length() > 0)
346 {
347 try
348 {
349 fragLib = DenoptimIO.readVertexes(new File(fragFile),
351 for (int i=0; i<fragLib.size(); i++)
352 {
353 fragLib.get(i).setBuildingBlockId(i);
354 }
355 } catch (IllegalArgumentException | UndetectedFileFormatException
356 | IOException | DENOPTIMException e)
357 {
358 throw new DENOPTIMException("Cound not read library of fragments "
359 + "from file '" + fragFile + "'.", e);
360 }
361 }
362
363 ArrayList<Vertex> scaffLib = new ArrayList<Vertex>();
364 if (scaffFile != null && scaffFile.length() > 0)
365 {
366 try
367 {
368 scaffLib = DenoptimIO.readVertexes(new File(scaffFile),
370 for (int i=0; i<scaffLib.size(); i++)
371 {
372 scaffLib.get(i).setBuildingBlockId(i);
373 }
374 } catch (IllegalArgumentException | UndetectedFileFormatException
375 | IOException | DENOPTIMException e)
376 {
377 throw new DENOPTIMException("Cound not read library of scaffolds "
378 + "from file '" + fragFile + "'.", e);
379 }
380 }
381
382 define(settings, scaffLib, fragLib, cappLib, cpMap, capMap, forbEnds,
383 rcCpMap, symCntrMap);
384 }
385
386//------------------------------------------------------------------------------
387
410 ArrayList<Vertex> scaffLib,
411 ArrayList<Vertex> fragLib,
412 ArrayList<Vertex> cappLib,
413 HashMap<APClass, ArrayList<APClass>> cpMap,
414 HashMap<APClass, APClass> capMap,
415 HashSet<APClass> forbEnds,
416 HashMap<APClass, ArrayList<APClass>> rcCpMap,
417 HashMap<APClass, Double> symCntrMap)
418 throws DENOPTIMException
419 {
420 this.settings = settings;
422
423 setScaffoldLibrary(scaffLib);
424 setFragmentLibrary(fragLib);
425 setCappingLibrary(cappLib);
427 apClassBasedApproch = cpMap.size()>0;
428 setCappingMap(capMap);
429 setForbiddenEndList(forbEnds);
431 setSymmConstraints(symCntrMap);
432
434
435 isValid = true;
436 }
437
438//------------------------------------------------------------------------------
439
444 public boolean isDefined()
445 {
446 return isValid;
447 }
448
449//------------------------------------------------------------------------------
450
457 {
458 return settings.getRandomizer();
459 }
460
461//------------------------------------------------------------------------------
462
466 public void setAPclassBasedApproach(boolean useAPC)
467 {
468 apClassBasedApproch = useAPC;
469 }
470
471//------------------------------------------------------------------------------
472
481 public boolean useAPclassBasedApproach()
482 {
483 return apClassBasedApproch;
484 }
485
486//------------------------------------------------------------------------------
487
496 {
497 APClass cls = null;
498 try
499 {
500 Vertex frg = this.getVertexFromLibrary(
501 apId.getVertexMolType(), apId.getVertexMolId());
502 cls = frg.getAttachmentPoints().get(apId.getApId()).getAPClass();
503 } catch (Throwable t)
504 {
505 cls = null;
506 }
507
508 return cls;
509 }
510
511//------------------------------------------------------------------------------
512
532 public Vertex getVertexFromLibrary(Vertex.BBType bbType, int bbIdx)
533 throws DENOPTIMException
534 {
535 String msg = "";
536 switch (bbType)
537 {
538 case SCAFFOLD:
539 if (scaffoldLib == null)
540 {
541 msg = "Cannot retrieve scaffolds before initialising the "
542 + "scaffold library.";
543 throw new DENOPTIMException(msg);
544 }
545 break;
546 case FRAGMENT:
547 if (fragmentLib == null)
548 {
549 msg = "Cannot retrieve fragments before initialising the "
550 + "fragment library.";
551 throw new DENOPTIMException(msg);
552 }
553 break;
554 case CAP:
555 if (cappingLib == null)
556 {
557 msg = "Cannot retrieve capping groups before initialising"
558 + "the library of capping groups.";
559 throw new DENOPTIMException(msg);
560 }
561 break;
562
563 default:
564 throw new DENOPTIMException("Cannot find building block of "
565 + "type '" + bbType + "' in the fragment space.");
566 }
567
568 Vertex originalVrtx = null;
569 switch (bbType)
570 {
571 case SCAFFOLD:
572 if (bbIdx >-1 && bbIdx < scaffoldLib.size())
573 {
574 originalVrtx = scaffoldLib.get(bbIdx);
575 }
576 else
577 {
578 msg = "Mismatch between scaffold bbIdx (" + bbIdx
579 + ") and size of the library (" + scaffoldLib.size()
580 + "). FragType: " + bbType;
581 settings.getLogger().log(Level.SEVERE, msg);
582 throw new DENOPTIMException(msg);
583 }
584 break;
585
586 case FRAGMENT:
587 if (bbIdx >-1 && bbIdx < fragmentLib.size())
588 {
589 originalVrtx = fragmentLib.get(bbIdx);
590 }
591 else
592 {
593 msg = "Mismatch between fragment bbIdx (" + bbIdx
594 + ") and size of the library (" + fragmentLib.size()
595 + "). FragType: " + bbType;
596 settings.getLogger().log(Level.SEVERE, msg);
597 throw new DENOPTIMException(msg);
598 }
599 break;
600
601 case CAP:
602 if (bbIdx >-1 && bbIdx < cappingLib.size())
603 {
604 originalVrtx = cappingLib.get(bbIdx);
605 }
606 else
607 {
608 msg = "Mismatch between capping group bbIdx " + bbIdx
609 + ") and size of the library (" + cappingLib.size()
610 + "). FragType: " + bbType;
611 settings.getLogger().log(Level.SEVERE, msg);
612 throw new DENOPTIMException(msg);
613 }
614 break;
615
616 case UNDEFINED:
617 msg = "Attempting to take UNDEFINED type of building block from "
618 + "fragment library.";
619 settings.getLogger().log(Level.WARNING, msg);
620 if (bbIdx < fragmentLib.size())
621 {
622 originalVrtx = fragmentLib.get(bbIdx);
623 }
624 else
625 {
626 msg = "Mismatch between fragment bbIdx (" + bbIdx
627 + ") and size of the library (" + fragmentLib.size()
628 + "). FragType: " + bbType;
629 settings.getLogger().log(Level.SEVERE, msg);
630 throw new DENOPTIMException(msg);
631 }
632 break;
633
634 default:
635 msg = "Unknown type of fragment '" + bbType + "'.";
636 settings.getLogger().log(Level.SEVERE, msg);
637 throw new DENOPTIMException(msg);
638 }
639 Vertex clone = originalVrtx.clone();
640
642
643 clone.setBuildingBlockId(bbIdx);
644 if (originalVrtx.getBuildingBlockId() != bbIdx)
645 {
646 settings.getLogger().log(Level.WARNING, "Mismatch between building "
647 + "block ID ("
648 + originalVrtx.getBuildingBlockId() + ") and position in "
649 + "the list of building blocks (" + bbIdx + ") for type "
650 + bbType + ".");
651 }
652 return clone;
653 }
654
655//------------------------------------------------------------------------------
656
663 public int getCappingFragment(APClass rcnCap)
664 {
665 if (rcnCap == null)
666 return -1;
667
668 ArrayList<Integer> reacFrags = getCompatibleCappingFragments(rcnCap);
669
670 int fapidx = -1;
671 if (reacFrags.size() > 0)
672 {
673 fapidx = settings.getRandomizer().randomlyChooseOne(reacFrags);
674 }
675
676 return fapidx;
677 }
678
679//------------------------------------------------------------------------------
680
687 public ArrayList<Integer> getCompatibleCappingFragments(
688 APClass cmpReac)
689 {
690 ArrayList<Integer> lstFragIdx = new ArrayList<>();
691 for (int i=0; i<cappingLib.size(); i++)
692 {
693 Vertex mol = getCappingLibrary().get(i);
694 ArrayList<APClass> lstRcn = mol.getAllAPClasses();
695 if (lstRcn.contains(cmpReac))
696 lstFragIdx.add(i);
697 }
698 return lstFragIdx;
699 }
700
701//------------------------------------------------------------------------------
702
709 {
710 int chosenIdx = settings.getRandomizer().nextInt(scaffoldLib.size());
711 Vertex scaffold = null;
712 try
713 {
714 scaffold = Vertex.newVertexFromLibrary(
715 GraphUtils.getUniqueVertexIndex(),chosenIdx,
716 BBType.SCAFFOLD, this);
717 } catch (DENOPTIMException e)
718 {
719 //This cannot happen!
720 }
721 return scaffold;
722 }
723
724//------------------------------------------------------------------------------
725
726 public ArrayList<Vertex> getScaffoldLibrary()
727 {
728 return scaffoldLib;
729 }
730
731//------------------------------------------------------------------------------
732
733 public ArrayList<Vertex> getFragmentLibrary()
734 {
735 return fragmentLib;
736 }
737
738//------------------------------------------------------------------------------
739
740 public ArrayList<Vertex> getCappingLibrary()
741 {
742 return cappingLib;
743 }
744
745//------------------------------------------------------------------------------
746
752 public ArrayList<Integer> getCappingGroupsWithAPClass(APClass capApCls)
753 {
754 ArrayList<Integer> selected = new ArrayList<>();
755 for (int i = 0; i < cappingLib.size(); i++)
756 {
757 APClass apc = cappingLib.get(i).getAP(0).getAPClass();
758 if (apc.equals(capApCls))
759 {
760 selected.add(i);
761 }
762 }
763 return selected;
764 }
765
766//------------------------------------------------------------------------------
767
776 {
777 for (int i = 0; i < cappingLib.size(); i++)
778 {
779 APClass apc = cappingLib.get(i).getAP(0).getAPClass();
780 if (apc.equals(capApCls))
781 {
782 try
783 {
785 } catch (DENOPTIMException e)
786 {
787 //This cannot happen
788 }
789 }
790 }
791 return null;
792 }
793
794//------------------------------------------------------------------------------
795
806 public void importCompatibilityMatrixFromFile(String inFile)
807 throws DENOPTIMException
808 {
809 setCompatibilityMatrix(new HashMap<APClass, ArrayList<APClass>>());
810 setCappingMap(new HashMap<APClass, APClass>());
811 setForbiddenEndList(new HashSet<APClass>());
814 }
815
816//------------------------------------------------------------------------------
817
825 public void importRCCompatibilityMatrixFromFile(String inFile)
826 throws DENOPTIMException
827 {
828 setRCCompatibilityMatrix(new HashMap<APClass, ArrayList<APClass>>());
830 }
831
832//------------------------------------------------------------------------------
833
834 public HashMap<APClass, ArrayList<APClass>> getCompatibilityMatrix()
835 {
837 }
838
839//------------------------------------------------------------------------------
840
847 public ArrayList<APClass> getCompatibleAPClasses(APClass apc)
848 {
849 if (apClassCompatibilityMatrix!= null && apClassCompatibilityMatrix.containsKey(apc))
850 {
851 return apClassCompatibilityMatrix.get(apc);
852 }
853 return new ArrayList<APClass>();
854 }
855
856//------------------------------------------------------------------------------
857
865 public HashMap<APClass, ArrayList<APClass>> getRCCompatibilityMatrix()
866 {
867 return rcCompatMap;
868 }
869
870//------------------------------------------------------------------------------
871
872 public HashMap<APClass, APClass> getCappingMap()
873 {
874 return cappingMap;
875 }
876
877//------------------------------------------------------------------------------
878
886 {
887 return cappingMap.get(srcApClass);
888 }
889
890//------------------------------------------------------------------------------
891
892 public Set<APClass> getForbiddenEndList()
893 {
894 return forbiddenEndList;
895 }
896
897//------------------------------------------------------------------------------
898
908 public Set<APClass> getAllAPClassesFromCPMap()
909 {
910 return apClassCompatibilityMatrix.keySet();
911 }
912
913//------------------------------------------------------------------------------
914
915 public HashMap<Integer, ArrayList<Integer>> getMapOfFragsPerNumAps()
916 {
917 return fragPoolPerNumAP;
918 }
919
920//------------------------------------------------------------------------------
921
929 public ArrayList<Integer> getFragsWithNumAps(int nAps)
930 {
931 ArrayList<Integer> lst = new ArrayList<>();
932 if (fragPoolPerNumAP.containsKey(nAps))
933 {
934 lst = fragPoolPerNumAP.get(nAps);
935 }
936 return lst;
937 }
938
939//------------------------------------------------------------------------------
940
948 public ArrayList<APClass> getAPClassesPerFragment(int fragId)
949 {
950 synchronized (LOCK)
951 {
952 return apClassesPerFrag.get(fragId);
953 }
954 }
955
956//------------------------------------------------------------------------------
957
968 public ArrayList<IdFragmentAndAP> getFragsWithAPClass(APClass apc)
969 {
970 ArrayList<IdFragmentAndAP> lst = new ArrayList<IdFragmentAndAP>();
971
972 synchronized (LOCK)
973 {
974 if (fragsApsPerApClass.containsKey(apc))
975 {
976 for (ArrayList<Integer> idxs : fragsApsPerApClass.get(apc))
977 {
978 IdFragmentAndAP apId = new IdFragmentAndAP(-1, // vertexId
979 idxs.get(0), // MolId,
980 BBType.FRAGMENT, idxs.get(1), // ApId
981 -1, // noVSym
982 -1);// noAPSym
983 lst.add(apId);
984 }
985 }
986 }
987 return lst;
988 }
989
990//------------------------------------------------------------------------------
991
998 public ArrayList<Vertex> getVerticesWithAPClass(APClass apc)
999 {
1000 ArrayList<Vertex> lst = new ArrayList<Vertex>();
1001
1002 synchronized (LOCK)
1003 {
1004 if (fragsApsPerApClass.containsKey(apc))
1005 {
1006 for (ArrayList<Integer> idxs : fragsApsPerApClass.get(apc))
1007 {
1008 Vertex v = fragmentLib.get(idxs.get(0));
1009 lst.add(v);
1010 }
1011 }
1012 }
1013 return lst;
1014 }
1015
1016//------------------------------------------------------------------------------
1017
1026 public ArrayList<Vertex> getFragmentsCompatibleWithTheseAPs(
1027 ArrayList<IdFragmentAndAP> srcAPs)
1028 {
1029 // First we get all possible APs on any fragment
1030 ArrayList<IdFragmentAndAP> compatFragAps =
1032
1033 // then keep unique fragment identifiers, and store unique
1034 Set<Integer> compatFragIds = new HashSet<Integer>();
1035 for (IdFragmentAndAP apId : compatFragAps)
1036 {
1037 compatFragIds.add(apId.getVertexMolId());
1038 }
1039
1040 // Then we pack-up the selected list of fragments
1041 ArrayList<Vertex> compatFrags = new ArrayList<Vertex>();
1042 for (Integer fid : compatFragIds)
1043 {
1044 try {
1045 compatFrags.add(getVertexFromLibrary(BBType.FRAGMENT, fid));
1046 } catch (DENOPTIMException e) {
1047 settings.getLogger().log(Level.WARNING, "Exception while trying "
1048 + "to get fragment '" + fid + "'!");
1049 e.printStackTrace();
1050 }
1051 }
1052 return compatFrags;
1053 }
1054
1055//------------------------------------------------------------------------------
1056
1065 public List<Vertex> getRCVsWithAPClass(APClass apc)
1066 {
1067 List<Vertex> chosenRCVs = new ArrayList<Vertex>();
1068 for (Vertex rcv : getRCVs())
1069 {
1070 // NB: RCVs must have only one attachment point
1071 if (apc.equals(rcv.getAP(0).getAPClass()))
1072 {
1073 Vertex copyOfRCV = null;
1074 try
1075 {
1076 copyOfRCV = getVertexFromLibrary(rcv.getBuildingBlockType(),
1077 rcv.getBuildingBlockId());
1078 chosenRCVs.add(copyOfRCV);
1079 } catch (DENOPTIMException e)
1080 {
1081 // This should never happen because we have already taken
1082 // the BB from BBSpace.
1083 e.printStackTrace();
1084 }
1085 }
1086 }
1087 return chosenRCVs;
1088 }
1089
1090//------------------------------------------------------------------------------
1091
1100 public List<Vertex> getRCVsForAPClass(APClass apc)
1101 {
1102 List<Vertex> chosenRCVs = new ArrayList<Vertex>();
1103 if (!getCompatibilityMatrix().containsKey(apc))
1104 {
1105 return chosenRCVs;
1106 }
1107 List<APClass> apcsCompatWithSrcAP = getCompatibilityMatrix().get(apc);
1108 for (Vertex rcv : getRCVs())
1109 {
1110 // NB: RCVs must have only one attachment point
1111 if (apcsCompatWithSrcAP.contains(rcv.getAP(0).getAPClass()))
1112 {
1113 Vertex copyOfRCV = null;
1114 try
1115 {
1116 copyOfRCV = getVertexFromLibrary(rcv.getBuildingBlockType(),
1117 rcv.getBuildingBlockId());
1118 chosenRCVs.add(copyOfRCV);
1119 } catch (DENOPTIMException e)
1120 {
1121 // This should never happen because we have already taken
1122 // the BB from BBSpace.
1123 e.printStackTrace();
1124 }
1125 }
1126 }
1127 return chosenRCVs;
1128 }
1129
1130//------------------------------------------------------------------------------
1131
1140 public ArrayList<AttachmentPoint> getAPsCompatibleWithThese(
1141 ArrayList<AttachmentPoint> srcAPs)
1142 {
1143 ArrayList<AttachmentPoint> compAps =
1144 new ArrayList<AttachmentPoint>();
1145 boolean first = true;
1146 for (AttachmentPoint ap : srcAPs)
1147 {
1148 ArrayList<AttachmentPoint> compForOne =
1149 getAPsCompatibleWithClass(ap.getAPClass());
1150
1151 if (first)
1152 {
1153 compAps.addAll(compForOne);
1154 first = false;
1155 continue;
1156 }
1157
1158 ArrayList<AttachmentPoint> toKeep =
1159 new ArrayList<AttachmentPoint>();
1160 for (AttachmentPoint candAp : compAps)
1161 {
1162 for (AttachmentPoint newCand : compForOne)
1163 {
1164 if (newCand == candAp)
1165 {
1166 toKeep.add(candAp);
1167 break;
1168 }
1169 }
1170 }
1171
1172 compAps = toKeep;
1173
1174 if (compAps.size()==0)
1175 {
1176 break;
1177 }
1178 }
1179 return compAps;
1180 }
1181
1182//------------------------------------------------------------------------------
1183
1191 public ArrayList<IdFragmentAndAP> getFragAPsCompatibleWithTheseAPs(
1192 ArrayList<IdFragmentAndAP> srcAPs)
1193 {
1194 ArrayList<IdFragmentAndAP> compFrAps = new ArrayList<IdFragmentAndAP>();
1195 boolean first = true;
1196 for (IdFragmentAndAP apId : srcAPs)
1197 {
1198 APClass srcApCls = getAPClassForFragment(apId);
1199 ArrayList<IdFragmentAndAP> compForOne =
1201
1202 if (first)
1203 {
1204 compFrAps.addAll(compForOne);
1205 first = false;
1206 continue;
1207 }
1208
1209 ArrayList<IdFragmentAndAP> toKeep =
1210 new ArrayList<IdFragmentAndAP>();
1211 for (IdFragmentAndAP candAp : compFrAps)
1212 {
1213 for (IdFragmentAndAP newId : compForOne)
1214 {
1215 if (newId.sameFragAndAp(candAp))
1216 {
1217 toKeep.add(candAp);
1218 break;
1219 }
1220 }
1221 }
1222
1223 compFrAps = toKeep;
1224
1225 if (compFrAps.size() == 0)
1226 {
1227 break;
1228 }
1229 }
1230
1231 return compFrAps;
1232 }
1233
1234//------------------------------------------------------------------------------
1235
1244 public ArrayList<AttachmentPoint> getAPsCompatibleWithClass(
1245 APClass aPC1)
1246 {
1247 ArrayList<AttachmentPoint> compatAps =
1248 new ArrayList<AttachmentPoint>();
1249
1250 // Take the compatible AP classes
1251 ArrayList<APClass> compatApClasses = getCompatibleAPClasses(aPC1);
1252
1253 // Find all APs with a compatible class
1254 if (compatApClasses != null)
1255 {
1256 for (APClass klass : compatApClasses)
1257 {
1258 ArrayList<Vertex> vrtxs = getVerticesWithAPClass(klass);
1259 for (Vertex v : vrtxs)
1260 {
1261 for (AttachmentPoint ap : v.getAttachmentPoints())
1262 {
1263 if (ap.getAPClass() == klass)
1264 {
1265 compatAps.add(ap);
1266 }
1267 }
1268 }
1269 }
1270 }
1271
1272 if (compatAps.size()==0)
1273 {
1274 settings.getLogger().log(Level.WARNING,"No compatible "
1275 + "AP found in the fragment space for APClass '"
1276 + aPC1 + "'.");
1277 }
1278
1279 return compatAps;
1280 }
1281
1282//------------------------------------------------------------------------------
1283
1291 public ArrayList<IdFragmentAndAP> getFragAPsCompatibleWithClass(
1292 APClass aPC1)
1293 {
1294 ArrayList<IdFragmentAndAP> compatFragAps =
1295 new ArrayList<IdFragmentAndAP>();
1296
1297 // Take the compatible AP classes
1298 ArrayList<APClass> compatApClasses = getCompatibleAPClasses(aPC1);
1299
1300 // Find all APs with any compatible class
1301 if (compatApClasses != null)
1302 {
1303 for (APClass compClass : compatApClasses)
1304 {
1305 compatFragAps.addAll(getFragsWithAPClass(compClass));
1306 }
1307 }
1308 return compatFragAps;
1309 }
1310
1311//------------------------------------------------------------------------------
1312
1324 public boolean imposeSymmetryOnAPsOfClass(APClass apClass)
1325 {
1326 boolean res = true;
1327 if (hasSymmetryConstrain(apClass))
1328 {
1329 if (getSymmetryConstrain(apClass) < (1.0
1331 {
1332 res = false;
1333 }
1334 } else
1335 {
1337 {
1338 res = false;
1339 }
1340 }
1341 return res;
1342 }
1343
1344//------------------------------------------------------------------------------
1345
1355 public boolean hasSymmetryConstrain(APClass apClass)
1356 {
1357 if (symmConstraints==null)
1358 return false;
1359 return symmConstraints.containsKey(apClass);
1360 }
1361
1362//------------------------------------------------------------------------------
1363
1374 public double getSymmetryConstrain(APClass apClass)
1375 {
1376 return symmConstraints.get(apClass);
1377 }
1378
1379//------------------------------------------------------------------------------
1380
1381 public void setScaffoldLibrary(ArrayList<Vertex> lib)
1382 {
1383 scaffoldLib = new ArrayList<Vertex>();
1385 }
1386
1387 public void setFragmentLibrary(ArrayList<Vertex> lib)
1388 {
1389 fragmentLib = new ArrayList<Vertex>();
1391 }
1392
1393//------------------------------------------------------------------------------
1394
1395 public void setCappingLibrary(ArrayList<Vertex> lib)
1396 {
1397 cappingLib = new ArrayList<Vertex>();
1399 }
1400
1401//------------------------------------------------------------------------------
1402
1403 public void setCompatibilityMatrix(HashMap<APClass, ArrayList<APClass>> map)
1404 {
1406 }
1407
1408//------------------------------------------------------------------------------
1409
1410 public void setRCCompatibilityMatrix(HashMap<APClass,
1411 ArrayList<APClass>> map)
1412 {
1413 rcCompatMap = map;
1414 }
1415
1416//------------------------------------------------------------------------------
1417
1418 public void setCappingMap(HashMap<APClass, APClass> map)
1419 {
1420 cappingMap = map;
1421 }
1422
1423//------------------------------------------------------------------------------
1424
1425 public void setForbiddenEndList(Set<APClass> lst)
1426 {
1427 forbiddenEndList = lst;
1428 }
1429
1430//------------------------------------------------------------------------------
1431
1433 HashMap<Integer, ArrayList<Integer>> map)
1434 {
1435 fragPoolPerNumAP = map;
1436 }
1437
1438//------------------------------------------------------------------------------
1439
1440 public void setSymmConstraints(HashMap<APClass, Double> map)
1441 {
1442 symmConstraints = map;
1443 }
1444
1445//------------------------------------------------------------------------------
1446
1451 public void clearAll()
1452 {
1453 scaffoldLib = null;
1454 fragmentLib = null;
1455 cappingLib = null;
1457 rcCompatMap = null;
1458 cappingMap = null;
1459 forbiddenEndList = null;
1460 fragPoolPerNumAP = null;
1461 apClassesPerFrag = null;
1462 fragsApsPerApClass = null;
1463 symmConstraints = null;
1464 isValid = false;
1465 }
1466
1467//------------------------------------------------------------------------------
1468
1478 public void appendVerticesToLibrary(ArrayList<Vertex> list,
1479 Vertex.BBType bbt, ArrayList<Vertex> library)
1480 {
1481 for (Vertex v : list)
1482 {
1483 appendVertexToLibrary(v,bbt,library);
1484 }
1485 }
1486
1487//------------------------------------------------------------------------------
1488
1499 Vertex.BBType bbt, ArrayList<Vertex> library)
1500 {
1501 v.setBuildingBlockId(library.size());
1502 v.setBuildingBlockType(bbt);
1503 library.add(v);
1504 }
1505
1506//------------------------------------------------------------------------------
1507
1519 //TODO: need something to prevent memory overload:
1520 // -> keep only some templates?
1521 // -> remove those who did not lead to good population members?
1522 // -> remove redundant? The highest-simmetry principle (i.e., rather than
1523 // keeping a template as it is, we'd like to keep its highest symmetry
1524 // isomorphic) would be the first thing to do.
1525
1527 {
1528 addFusedRingsToFragmentLibrary(graph,true,true);
1529 }
1530
1531//------------------------------------------------------------------------------
1532
1546 boolean addIfScaffold, boolean addIfFragment)
1547 {
1548 addFusedRingsToFragmentLibrary(graph, addIfScaffold, addIfFragment, null);
1549 }
1550
1551//------------------------------------------------------------------------------
1552
1571 //TODO: need something to prevent memory overload:
1572 // -> keep only some templates?
1573 // -> remove those who did not lead to good population members?
1574 // -> remove redundant? The highest-symmetry principle (i.e., rather than
1575 // keeping a template as it is, we'd like to keep its highest symmetry
1576 // isomorphic) would be the first thing to do.
1577
1579 boolean addIfScaffold, boolean addIfFragment,
1580 IAtomContainer wholeMol)
1581 {
1582 List<DGraph> subgraphs = null;
1583 try
1584 {
1585 subgraphs = graph.extractPattern(GraphPattern.RING);
1586 } catch (DENOPTIMException e1)
1587 {
1588 settings.getLogger().log(Level.WARNING,"Failed to extract "
1589 + "fused ring patters.");
1590 e1.printStackTrace();
1591 }
1592
1593 for (DGraph g : subgraphs)
1594 {
1595 BBType type = g.hasScaffoldTypeVertex() ?
1596 BBType.SCAFFOLD :
1598
1599 if (!addIfFragment && type == BBType.FRAGMENT)
1600 {
1601 continue;
1602 }
1603 if (!addIfScaffold && type == BBType.SCAFFOLD)
1604 {
1605 continue;
1606 }
1607
1608 ArrayList<Vertex> library = type == BBType.FRAGMENT ?
1610
1611 synchronized (LOCK)
1612 {
1613 if (!hasIsomorph(g, type))
1614 {
1615 //TODO: try to transform the template into its isomorphic
1616 // with highest symmetry, and define the symmetric sets.
1617 // Such enhancement would facilitate the creation of
1618 // symmetric graphs from templates generated on the fly.
1619
1620 Template t = new Template(type);
1621 t.setInnerGraph(g);
1622
1623 boolean has3Dgeometry = false;
1624 IAtomContainer subIAC = null;
1625 if (wholeMol!=null)
1626 {
1627 try
1628 {
1630 wholeMol, g, graph, settings.getLogger(),
1632 t.setIAtomContainer(subIAC,true);
1633 has3Dgeometry = true;
1634 } catch (DENOPTIMException e1)
1635 {
1636 e1.printStackTrace();
1637 ArrayList<DGraph> lst = new ArrayList<>();
1638 lst.add(graph);
1639 lst.add(g);
1640 String forDebugFile = "failedExtractIAC_"
1641 + graph.getGraphId() + ".json";
1642 try
1643 {
1645 new File(forDebugFile), lst);
1646 settings.getLogger().log(Level.WARNING,
1647 "WARNING: failed to extract "
1648 + "molecular representation of graph. "
1649 + "See file '" + forDebugFile + "'.");
1650 } catch (DENOPTIMException e)
1651 {
1652 settings.getLogger().log(Level.WARNING,
1653 "WARNING: failed to extract "
1654 + "molecular representation of graph, "
1655 + "and failed to write graph to file.");
1656 }
1657 }
1658 }
1659
1660 String msg = "Adding new template (Inner Graph id: "
1661 + t.getInnerGraph().getGraphId() + ") to the "
1662 + "library of " + type + "s. The template is "
1663 + "generated from graph " + graph.getGraphId();
1664 Candidate source = graph.getCandidateOwner();
1665 if (source != null)
1666 msg = msg + " candidate " + source.getName();
1667 else
1668 msg = msg + ".";
1669 settings.getLogger().log(Level.INFO, msg);
1670
1671 appendVertexToLibrary(t, type, library);
1672 if (type == BBType.FRAGMENT)
1673 {
1674 classifyFragment(t,library.size()-1);
1675 }
1676
1677 String destFileName = type == BBType.FRAGMENT ?
1680 try
1681 {
1682 if (has3Dgeometry)
1683 {
1684 DenoptimIO.writeSDFFile(destFileName,subIAC,true);
1685 } else {
1686 DenoptimIO.writeGraphToSDF(new File(destFileName),
1687 g, true, false, settings.getLogger(),
1689 }
1690 } catch (DENOPTIMException e)
1691 {
1692 e.printStackTrace();
1693 settings.getLogger().log(Level.WARNING, "WARNING: "
1694 + "failed to write newly "
1695 + "generated " + type + " to file '"
1696 + destFileName + "'.");
1697 }
1698 }
1699 }
1700 }
1701 }
1702
1703//------------------------------------------------------------------------------
1704
1714 public boolean hasIsomorph(DGraph graph, BBType type) {
1715 return (type == BBType.SCAFFOLD ? scaffoldLib : fragmentLib)
1716 .stream()
1717 .filter(v -> v instanceof Template)
1718 .map(t -> (Template) t)
1720 .anyMatch(graph::isIsomorphicTo);
1721 }
1722
1723//------------------------------------------------------------------------------
1724
1730 public void registerRCV(Vertex v)
1731 {
1732 rcvs.add(v);
1733 }
1734
1735//------------------------------------------------------------------------------
1736
1741 public ArrayList<Vertex> getRCVs()
1742 {
1743 return rcvs;
1744 }
1745
1746//------------------------------------------------------------------------------
1747
1758 public List<APMapping> mapAPClassCompatibilities(
1759 List<AttachmentPoint> listA,
1760 List<AttachmentPoint> listB, int maxCombinations)
1761 {
1762 Map<AttachmentPoint,List<AttachmentPoint>> apCompatilities =
1763 new HashMap<AttachmentPoint,List<AttachmentPoint>>();
1764
1765 for (AttachmentPoint apA : listA)
1766 {
1767 for (AttachmentPoint apB : listB)
1768 {
1769 boolean compatible = false;
1771 {
1772 if (apA.getAPClass().isCPMapCompatibleWith(apB.getAPClass(),
1773 this))
1774 {
1775 compatible = true;
1776 }
1777 } else {
1778 compatible = true;
1779 }
1780 if (compatible)
1781 {
1782 if (apCompatilities.containsKey(apA))
1783 {
1784 apCompatilities.get(apA).add(apB);
1785 } else {
1786 List<AttachmentPoint> lst =
1787 new ArrayList<AttachmentPoint>();
1788 lst.add(apB);
1789 apCompatilities.put(apA,lst);
1790 }
1791 }
1792 }
1793 }
1794
1795 // This is used only to keep a sorted list of the map keys
1796 List<AttachmentPoint> keys =
1797 new ArrayList<AttachmentPoint>(
1798 apCompatilities.keySet());
1799
1800 // Get all possible combinations of compatible AP pairs
1801 List<APMapping> apMappings = new ArrayList<APMapping>();
1802 if (keys.size() > 0)
1803 {
1804 int currentKey = 0;
1805 APMapping currentMapping = new APMapping();
1806 FragmentSpaceUtils.recursiveCombiner(keys, currentKey,
1807 apCompatilities, currentMapping, apMappings, true,
1808 maxCombinations);
1809 }
1810
1811 return apMappings;
1812 }
1813
1814//------------------------------------------------------------------------------
1815
1824 public void classifyFragment(Vertex frg, int fragId)
1825 {
1826 // Classify according to number of APs
1827 int nAps = frg.getFreeAPCount();
1828 if (nAps != 0)
1829 {
1830 if (getMapOfFragsPerNumAps().containsKey(nAps))
1831 {
1832 getFragsWithNumAps(nAps).add(fragId);
1833 }
1834 else
1835 {
1836 ArrayList<Integer> lst = new ArrayList<>();
1837 lst.add(fragId);
1838 getMapOfFragsPerNumAps().put(nAps,lst);
1839 }
1840 }
1841
1843 {
1844 // Collect classes per fragment
1845 ArrayList<APClass> lstAPC = frg.getAllAPClasses();
1846 synchronized (LOCK)
1847 {
1848 apClassesPerFrag.put(fragId,lstAPC);
1849 }
1850
1851 // Classify according to AP-Classes
1852 List<AttachmentPoint> lstAPs = frg.getAttachmentPoints();
1853
1854 for (int j=0; j<lstAPs.size(); j++)
1855 {
1856 AttachmentPoint ap = lstAPs.get(j);
1857 ArrayList<Integer> apId = new ArrayList<Integer>();
1858 apId.add(fragId);
1859 apId.add(j);
1860 APClass cls = ap.getAPClass();
1861
1862 if (!ap.isAvailable())
1863 {
1864 continue;
1865 }
1866
1867 synchronized (LOCK)
1868 {
1869 if (fragsApsPerApClass.containsKey(cls))
1870 {
1871 fragsApsPerApClass.get(cls).add(apId);
1872 } else {
1873 ArrayList<ArrayList<Integer>> outLst =
1874 new ArrayList<ArrayList<Integer>>();
1875 outLst.add(apId);
1876 fragsApsPerApClass.put(cls,outLst);
1877 }
1878 }
1879 }
1880
1881 if (frg.isRCV())
1882 registerRCV(frg);
1883 }
1884 }
1885
1886//------------------------------------------------------------------------------
1887
1895 throws DENOPTIMException
1896 {
1897 setFragPoolPerNumAP(new HashMap<Integer,ArrayList<Integer>>());
1899 {
1900 synchronized (LOCK)
1901 {
1902 fragsApsPerApClass = new HashMap<APClass,ArrayList<
1903 ArrayList<Integer>>>();
1904 }
1905 synchronized (LOCK)
1906 {
1907 apClassesPerFrag = new HashMap<Integer,ArrayList<APClass>>();
1908 }
1909 }
1910 for (int j=0; j<getFragmentLibrary().size(); j++)
1911 {
1912 Vertex frag = getFragmentLibrary().get(j);
1913 classifyFragment(frag,j);
1914 }
1915 }
1916
1917//------------------------------------------------------------------------------
1918
1927 public Vertex getPolarizedRCV(boolean polarity)
1928 {
1930 if (!polarity)
1931 apc = APClass.RCACLASSMINUS;
1932
1933 Fragment rcv = new Fragment();
1934 Atom atom = new PseudoAtom(RingClosingAttractor.RCALABELPERAPCLASS.get(apc),
1935 new Point3d());
1936 rcv.addAtom(atom);
1937 rcv.addAP(0, new Point3d(1.5, 0.0, 0.0), apc);
1938 rcv.setAsRCV(true);
1939 return rcv;
1940 }
1941
1942//------------------------------------------------------------------------------
1943
1944}
General set of constants used in DENOPTIM.
static final double FLOATCOMPARISONTOLERANCE
Smallest difference for comparison of double and float numbers.
Exception thrown when the format of a file is not recognized.
Class defining a space of building blocks.
HashMap< APClass, ArrayList< APClass > > getCompatibilityMatrix()
ArrayList< Vertex > getFragmentsCompatibleWithTheseAPs(ArrayList< IdFragmentAndAP > srcAPs)
Searches for all building blocks that are compatible with the given list of APs.
boolean hasSymmetryConstrain(APClass apClass)
Checks if there is a constraint on the constitutional symmetry probability for the given AP class.
ArrayList< APClass > getAPClassesPerFragment(int fragId)
Returns the APclasses associated with a given fragment.
List< APMapping > mapAPClassCompatibilities(List< AttachmentPoint > listA, List< AttachmentPoint > listB, int maxCombinations)
Given two lists of APs this method maps the APClass-compatibilities from between the two lists consid...
void addFusedRingsToFragmentLibrary(DGraph graph, boolean addIfScaffold, boolean addIfFragment)
Extracts a system of one or more fused rings and adds them to the fragment space if not already prese...
void classifyFragment(Vertex frg, int fragId)
Classify a fragment in terms of the number of APs and possibly their type (AP-Class).
void registerRCV(Vertex v)
Adds the reference to a ring-closing vertex (RCV) to the quick-access list of RCVs known in this buil...
HashMap< APClass, APClass > cappingMap
Data structure that stores the AP-classes to be used to cap unused APS on the growing molecule.
boolean apClassBasedApproch
Flag defining use of AP class-based approach.
double getSymmetryConstrain(APClass apClass)
Return the constitutional symmetry constrain for the given APclass, or null.
FragmentSpace(FragmentSpaceParameters settings, ArrayList< Vertex > scaffLib, ArrayList< Vertex > fragLib, ArrayList< Vertex > cappLib, HashMap< APClass, ArrayList< APClass > > cpMap, HashMap< APClass, APClass > capMap, HashSet< APClass > forbEnds, HashMap< APClass, ArrayList< APClass > > rcCpMap, HashMap< APClass, Double > symCntrMap)
Define all components of a fragment space that implements the attachment point class-approach.
void setScaffoldLibrary(ArrayList< Vertex > lib)
void appendVertexToLibrary(Vertex v, Vertex.BBType bbt, ArrayList< Vertex > library)
Takes a vertex and add it to a given library.
ArrayList< IdFragmentAndAP > getFragAPsCompatibleWithTheseAPs(ArrayList< IdFragmentAndAP > srcAPs)
Searches for all APs that are compatible with the given list of APs.
void setCompatibilityMatrix(HashMap< APClass, ArrayList< APClass > > map)
Vertex getPolarizedRCV(boolean polarity)
Returns a newly-built vertex that can play the role of a ring-closing vertex even when working with 3...
FragmentSpaceParameters settings
Settings used to configure this fragment space.
void addFusedRingsToFragmentLibrary(DGraph graph, boolean addIfScaffold, boolean addIfFragment, IAtomContainer wholeMol)
Extracts a system of one or more fused rings and adds them to the fragment space if not already prese...
HashMap< APClass, ArrayList< APClass > > rcCompatMap
Data structure that stores compatible APclasses for joining APs in ring-closing bonds.
boolean isValid
Flag signaling that this fragment space was built and validated.
HashMap< Integer, ArrayList< Integer > > getMapOfFragsPerNumAps()
Randomizer getRandomizer()
Returns the program-specific randomizer that is associated with this program-specific fragment space.
void importRCCompatibilityMatrixFromFile(String inFile)
Load info for ring closures compatibilities from a compatibility matrix file.
ArrayList< AttachmentPoint > getAPsCompatibleWithClass(APClass aPC1)
Returns the list of attachment points found in the fragment space and that are compatible with a give...
FragmentSpace(FragmentSpaceParameters settings, String scaffFile, String fragFile, String capFile, String cpmFile, String rcpmFile, HashMap< APClass, Double > symCntrMap)
Define all components of a fragment space that implements the attachment point class-approach.
APClass getAPClassForFragment(IdFragmentAndAP apId)
Search for a specific AP on a specific fragment and finds out its class.
void define(FragmentSpaceParameters settings, ArrayList< Vertex > scaffLib, ArrayList< Vertex > fragLib, ArrayList< Vertex > cappLib, HashMap< APClass, ArrayList< APClass > > cpMap, HashMap< APClass, APClass > capMap, HashSet< APClass > forbEnds, HashMap< APClass, ArrayList< APClass > > rcCpMap, HashMap< APClass, Double > symCntrMap)
Define all components of this fragment space.
boolean useAPclassBasedApproach()
Check usage of APClass-based approach, i.e., uses attachment points with annotated data (i....
boolean isDefined()
Checks for valid definition of this fragment space.
Vertex getVertexFromLibrary(Vertex.BBType bbType, int bbIdx)
Returns a clone of the requested building block.
void importCompatibilityMatrixFromFile(String inFile)
Load info from a compatibility matrix file.
ArrayList< Vertex > cappingLib
Data structure containing the molecular representation of building blocks: capping group section - fr...
void setAPclassBasedApproach(boolean useAPC)
Set the fragment space to behave according to APClass-based approach.
ArrayList< IdFragmentAndAP > getFragsWithAPClass(APClass apc)
Returns the list of attachment points with the given class.
ArrayList< Integer > getCappingGroupsWithAPClass(APClass capApCls)
ArrayList< AttachmentPoint > getAPsCompatibleWithThese(ArrayList< AttachmentPoint > srcAPs)
Searches for all attachment points that are compatible with the given list of attachment points.
final Object LOCK
Lock for synchronizing tasks.
void groupAndClassifyFragments(boolean apClassBasedApproch)
Performs grouping and classification operations on the library of building blocks of BBType#FRAGMENT.
void appendVerticesToLibrary(ArrayList< Vertex > list, Vertex.BBType bbt, ArrayList< Vertex > library)
Takes a list of vertices and add them to a given library.
void clearAll()
Clears all settings of this fragment space.
HashMap< APClass, ArrayList< ArrayList< Integer > > > fragsApsPerApClass
Clusters of fragments'AP based on AP classes.
void setForbiddenEndList(Set< APClass > lst)
void setFragmentLibrary(ArrayList< Vertex > lib)
APClass getAPClassOfCappingVertex(APClass srcApClass)
ArrayList< Vertex > scaffoldLib
Data structure containing the molecular representation of building blocks: scaffolds section - fragme...
HashMap< APClass, ArrayList< APClass > > getRCCompatibilityMatrix()
Returns the compatibility matrix for ring closing fragment-fragment connections or null if not provid...
HashMap< APClass, ArrayList< APClass > > apClassCompatibilityMatrix
Data structure that stored the true entries of the attachment point classes compatibility matrix.
HashMap< Integer, ArrayList< APClass > > apClassesPerFrag
List of APClasses per each fragment.
HashMap< APClass, Double > symmConstraints
APclass-specific constraints to constitutional symmetry.
ArrayList< Integer > getCompatibleCappingFragments(APClass cmpReac)
Retrieve a list of compatible capping groups.
void setCappingMap(HashMap< APClass, APClass > map)
Vertex makeRandomScaffold()
Randomly select a scaffold and return a fully configured clone of it.
ArrayList< Vertex > getRCVs()
Returns the list of registered ring-closing vertexes (RCVs).
boolean imposeSymmetryOnAPsOfClass(APClass apClass)
Checks if the symmetry settings impose use of symmetry on attachment points of the given AP class.
List< Vertex > getRCVsWithAPClass(APClass apc)
Searches for all building blocks that are ring-closing vertexes and hold an AP with the given class.
Set< APClass > getAllAPClassesFromCPMap()
Return the set of APClasses that used in the compatibility matrix for the growing graph APs.
boolean hasIsomorph(DGraph graph, BBType type)
Checks if a graph is isomorphic to another template's inner graph in its appropriate fragment space l...
Set< APClass > forbiddenEndList
Data structure that stores AP classes that cannot be held unused.
FragmentSpace(FragmentSpaceParameters settings, String scaffFile, String fragFile, String capFile, String cpmFile)
Define all components of a fragment space that implements the attachment point class-approach.
ArrayList< IdFragmentAndAP > getFragAPsCompatibleWithClass(APClass aPC1)
Returns the list of attachment points found in the fragment space and that are compatible with a give...
Vertex getCappingVertexWithAPClass(APClass capApCls)
void setCappingLibrary(ArrayList< Vertex > lib)
HashMap< Integer, ArrayList< Integer > > fragPoolPerNumAP
Clusters of fragments based on the number of APs.
ArrayList< Vertex > getCappingLibrary()
ArrayList< Vertex > rcvs
Store references to the Ring-Closing Vertexes found in the library of fragments.
ArrayList< Vertex > fragmentLib
Data structure containing the molecular representation of building blocks: fragment section - fragmen...
FragmentSpace(FragmentSpaceParameters settings, ArrayList< Vertex > scaffLib, ArrayList< Vertex > fragLib, ArrayList< Vertex > cappLib, HashMap< APClass, ArrayList< APClass > > cpMap, HashMap< APClass, APClass > capMap, HashSet< APClass > forbEnds, HashMap< APClass, ArrayList< APClass > > rcCpMap)
Define all components of a fragment space that implements the attachment point class-approach.
void addFusedRingsToFragmentLibrary(DGraph graph)
Extracts a system of one or more fused rings and adds them to the fragment space if not already prese...
ArrayList< Vertex > getVerticesWithAPClass(APClass apc)
Returns the list of attachment points with the given class.
HashMap< APClass, APClass > getCappingMap()
ArrayList< APClass > getCompatibleAPClasses(APClass apc)
Returns a list of APClasses compatible with the given APClass.
void setSymmConstraints(HashMap< APClass, Double > map)
ArrayList< Vertex > getScaffoldLibrary()
FragmentSpace()
Creates an empty fragment space, which is marked as invalid.
ArrayList< Integer > getFragsWithNumAps(int nAps)
Returns the list of fragments with given number of APs.
void setRCCompatibilityMatrix(HashMap< APClass, ArrayList< APClass > > map)
ArrayList< Vertex > getFragmentLibrary()
List< Vertex > getRCVsForAPClass(APClass apc)
Searches for all building blocks that are ring-closing vertexes and are compatible with the given AP.
int getCappingFragment(APClass rcnCap)
Select a compatible capping group for the given APClass.
void setFragPoolPerNumAP(HashMap< Integer, ArrayList< Integer > > map)
Parameters defining the fragment space.
boolean enforceSymmetry
Flag enforcing constitutional symmetry.
void setFragmentSpace(FragmentSpace fragmentSpace)
Sets the fragment space linked to these parameters.
Utility class for the fragment space.
static boolean recursiveCombiner(List< AttachmentPoint > keys, int currentKey, Map< AttachmentPoint, List< AttachmentPoint > > possibilities, APMapping combination, List< APMapping > completeCombinations, boolean screenAll, int maxCombs)
Search for all possible combinations of compatible APs.
Data structure containing information that identifies a single AP of a vertex/fragment.
static final APClass RCACLASSPLUS
Conventional class of attachment points on ring-closing vertexes.
Definition: APClass.java:84
boolean equals(Object o)
Definition: APClass.java:488
static final APClass RCACLASSMINUS
Conventional class of attachment points on ring-closing vertexes.
Definition: APClass.java:91
Class representing a mapping between attachment points (APs).
Definition: APMapping.java:42
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....
APClass getAPClass()
Returns the Attachment Point class.
boolean isAvailable()
Check availability of this attachment point.
A candidate is the combination of a denoptim graph with molecular representation and may include also...
Definition: Candidate.java:40
Container for the list of vertices and the edges that connect them.
Definition: DGraph.java:102
List< DGraph > extractPattern(GraphPattern pattern)
Extracts subgraphs that match the provided pattern.
Definition: DGraph.java:4457
Candidate getCandidateOwner()
Returns the reference of the candidate item that is defined by this graph.
Definition: DGraph.java:251
Class representing a continuously connected portion of chemical object holding attachment points.
Definition: Fragment.java:61
void addAP(int atomPositionNumber)
Adds an attachment point with a dummy APClass.
Definition: Fragment.java:343
void addAtom(IAtom atom)
Definition: Fragment.java:836
void setInnerGraph(DGraph innerGraph)
Definition: Template.java:298
void setIAtomContainer(IAtomContainer mol, boolean updateAPsAccordingToIAC)
Attaches a molecular representation to this template.
Definition: Template.java:621
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
Definition: Vertex.java:61
abstract Vertex clone()
Returns a deep-copy of this vertex.
int getBuildingBlockId()
Returns the index of the building block that should correspond to the position of the building block ...
Definition: Vertex.java:284
ArrayList< APClass > getAllAPClasses()
Returns the list of all APClasses present on this vertex.
Definition: Vertex.java:720
void setVertexId(long vertexId2)
Definition: Vertex.java:261
void setAsRCV(boolean isRCV)
Definition: Vertex.java:254
abstract List< AttachmentPoint > getAttachmentPoints()
void setBuildingBlockId(int buildingBlockId)
Definition: Vertex.java:291
void setBuildingBlockType(Vertex.BBType buildingBlockType)
Definition: Vertex.java:305
static Vertex newVertexFromLibrary(int bbId, Vertex.BBType bbt, FragmentSpace fragSpace)
Builds a new molecular fragment kind of vertex.
Definition: Vertex.java:214
The RingClosingAttractor represent the available valence/connection that allows to close a ring.
static final HashMap< APClass, String > RCALABELPERAPCLASS
Conventional labels for attractor pseudoatom.
Utility methods for input/output.
static void readRCCompatibilityMatrix(String fileName, HashMap< APClass, ArrayList< APClass > > rcCompatMap)
Reads the APclass compatibility matrix for ring-closing connections (the RC-CPMap).
static void writeGraphsToJSON(File file, List< DGraph > modGraphs)
Writes the graphs to JSON file.
static void writeSDFFile(String fileName, IAtomContainer mol)
Writes IAtomContainer to SDF file.
static void writeGraphToSDF(File file, DGraph graph, boolean append, boolean make3D, Logger logger, Randomizer randomizer)
Writes the graph to SDF file.
static void readCompatibilityMatrix(String fileName, HashMap< APClass, ArrayList< APClass > > compatMap, HashMap< APClass, APClass > cappingMap, Set< APClass > forbiddenEndList)
Read the APclass compatibility matrix data from file.
static ArrayList< Vertex > readVertexes(File file, Vertex.BBType bbt)
Reads Vertexes from any file that can contain such items.
Logger getLogger()
Get the name of the program specific logger.
Randomizer getRandomizer()
Returns the current program-specific randomizer.
Utilities for graphs.
Definition: GraphUtils.java:40
static synchronized long getUniqueVertexIndex()
Unique counter for the number of graph vertices generated.
Definition: GraphUtils.java:97
Utilities for molecule conversion.
static IAtomContainer extractIACForSubgraph(IAtomContainer wholeIAC, DGraph subGraph, DGraph wholeGraph, Logger logger, Randomizer randomizer)
Selects only the atoms that originate from a subgraph of a whole graph that originated the whole mole...
Tool to generate random numbers and random decisions.
Definition: Randomizer.java:35
public< T > T randomlyChooseOne(Collection< T > c)
Chooses one member among the given collection.
int nextInt(int i)
Returns a pseudo-random, uniformly distributed int value between 0 (inclusive) and the specified valu...
The type of building block.
Definition: Vertex.java:86