19package denoptim.graph.rings;
21import java.util.ArrayList;
22import java.util.HashMap;
25import java.util.logging.Level;
26import java.util.logging.Logger;
28import org.openscience.cdk.interfaces.IAtomContainer;
29import org.openscience.cdk.interfaces.IBond;
31import denoptim.constants.DENOPTIMConstants;
32import denoptim.exception.DENOPTIMException;
33import denoptim.graph.APClass;
34import denoptim.graph.AttachmentPoint;
35import denoptim.graph.DGraph;
36import denoptim.graph.Edge;
37import denoptim.graph.Edge.BondType;
38import denoptim.graph.Fragment;
39import denoptim.graph.Ring;
40import denoptim.graph.Vertex;
41import denoptim.graph.Vertex.BBType;
42import denoptim.fragspace.FragmentSpace;
43import denoptim.utils.ObjectPair;
44import denoptim.utils.RingClosingUtils;
121 List<Ring> combOfRings = iter.
next();
122 logger.log(Level.FINE,
"Random combOfRings: "+combOfRings);
139 IAtomContainer mol,
DGraph molGraph)
143 Map<ObjectPair,PathSubGraph> allGoodPaths =
144 new HashMap<ObjectPair,PathSubGraph>();
145 ArrayList<Vertex> rcaVertLst = molGraph.getFreeRCVertices();
152 Map<Vertex,ArrayList<Vertex>> compatMap =
153 new HashMap<Vertex,ArrayList<Vertex>>();
154 for (
int i=0; i<rcaVertLst.size(); i++)
156 Vertex vI = rcaVertLst.get(i);
157 for (
int j=i+1; j<rcaVertLst.size(); j++)
159 Vertex vJ = rcaVertLst.get(j);
162 logger.log(Level.FINE,
"Rejecting RC-incompatible pair "
169 logger.log(Level.FINE,
"Evaluating closability of path "
176 logger.log(Level.FINE,
"Rejecting RCA pair");
181 logger.log(Level.FINE,
"All compatibility criteria satisfied: "
182 +
"Storing verified RCA pair");
185 if (compatMap.containsKey(vI))
187 compatMap.get(vI).add(vJ);
191 ArrayList<Vertex> lst =
192 new ArrayList<Vertex>();
194 compatMap.put(vI,lst);
196 if (compatMap.containsKey(vJ))
198 compatMap.get(vJ).add(vI);
202 ArrayList<Vertex> lst =
203 new ArrayList<Vertex>();
205 compatMap.put(vJ,lst);
218 allGoodPaths.put(compatPair,subGraph);
222 logger.log(Level.FINE,
"Compatibility Map for RCAs: "+
NL+compatMap);
225 Map<IBond,List<PathSubGraph>> interdepPaths =
226 new HashMap<IBond,List<PathSubGraph>>();
238 Vertex hA = rpA.getHeadVertex();
239 Vertex tA = rpA.getTailVertex();
240 Vertex hB = rpB.getHeadVertex();
241 Vertex tB = rpB.getTailVertex();
243 if ((hA == hB || hA == tB) || (tA == hB || tA == tB))
248 for (IBond bnd : rpA.getBondPath())
255 if (rotFlg==
null || !Boolean.valueOf(rotFlg.toString()))
260 if (rpB.getBondPath().contains(bnd))
262 if (interdepPaths.containsKey(bnd))
264 interdepPaths.get(bnd).add(rpA);
265 interdepPaths.get(bnd).add(rpB);
269 List<PathSubGraph> paths =
270 new ArrayList<PathSubGraph>();
273 interdepPaths.put(bnd,paths);
279 StringBuilder sb =
new StringBuilder();
280 for (IBond bnd : interdepPaths.keySet())
282 sb.append(
"Interdependent paths for bond " + bnd);
283 List<PathSubGraph> sop = interdepPaths.get(bnd);
286 sb.append(
NL +
" -> vA: "+p.getHeadVertex()
287 +
" vB: "+p.getTailVertex());
290 logger.log(Level.FINE, sb.toString());
294 ArrayList<ObjectPair> lstPairs =
new ArrayList<ObjectPair>();
295 ArrayList<Long> usedId =
new ArrayList<Long>();
296 ArrayList<Vertex> sortedKeys =
new ArrayList<Vertex>();
297 for (
Vertex keyVert : compatMap.keySet())
299 sortedKeys.add(keyVert);
303 ArrayList<List<Ring>> allCombsOfRings =
304 new ArrayList<List<Ring>>();
313 logger.log(Level.FINE,
"All possible combination of rings: " +
315 return allCombsOfRings;
325 ArrayList<Vertex> sortedKeys,
326 Map<
Vertex,ArrayList<Vertex>> compatMap,
327 ArrayList<ObjectPair> lstPairs,
328 ArrayList<Long> usedId,
329 Map<ObjectPair,PathSubGraph> allGoodPaths,
330 Map<IBond,List<PathSubGraph>> interdepPaths,
331 ArrayList<List<Ring>> allCombsOfRings)
334 int objId = this.hashCode();
335 String recLab =
new String(
new char[
recCount]).replace(
"\0",
"-");
337 StringBuilder sb =
new StringBuilder();
338 sb.append(objId+
"-"+recLab+
"> Begin of new recursion: "+
recCount+
NL);
339 sb.append(objId+
"-"+recLab+
"> sortedKeys= "+sortedKeys+
NL);
340 sb.append(objId+
"-"+recLab+
"> usedId= "+usedId+
NL);
341 sb.append(objId+
"-"+recLab+
"> ii0= "+ii0+
NL);
342 sb.append(objId+
"-"+recLab+
"> lstPairs= "+lstPairs+
NL);
343 sb.append(objId+
"-"+recLab+
"> compatMap= "+compatMap+
NL);
344 sb.append(objId+
"-"+recLab+
"> allCombsOfRings"+
NL);
345 for (List<Ring> ringSet : allCombsOfRings)
347 sb.append(
" "+ringSet+
NL);
349 logger.log(Level.FINEST, sb.toString());
351 boolean inFound =
false;
352 boolean addedNew =
false;
353 for (
int ii=ii0; ii<sortedKeys.size(); ii++)
355 Vertex vi = sortedKeys.get(ii);
358 logger.log(Level.FINEST, objId+
"-"+recLab+
"> vIdI= "+vIdI);
360 if (usedId.contains(vIdI))
365 for (
Vertex vj : compatMap.get(vi))
367 long vIdJ = vj.getVertexId();
369 logger.log(Level.FINEST, objId+
"-"+recLab+
"> vIdJ= "+vIdJ);
371 if (usedId.contains(vIdJ) || usedId.contains(vIdI))
389 if (lstPairs.size() >
maxLng)
404 logger.log(Level.FINEST, objId+
"-"+recLab+
"> lstPairs.size() "
405 +
"& maxLng= "+lstPairs.size() +
" " +
maxLng);
407 if (!inFound && lstPairs.size() ==
maxLng)
409 logger.log(Level.FINEST, objId+
"-"+recLab+
"> in A");
411 boolean closable =
true;
422 logger.log(Level.FINEST, objId+
"-"+recLab+
"> in B");
424 List<Ring> ringsComb =
new ArrayList<Ring>();
428 ArrayList<Vertex> arrLst =
429 new ArrayList<Vertex>();
435 BondType btH = es.get(0).getBondType();
436 BondType btT = es.get(es.size()-1).getBondType();
439 String s =
"Attempt to close rings is not "
440 +
"compatible to the different bond type "
441 +
"specified by the head and tail APs: ("
442 + btH +
"!=" + btT +
" for vertices "
451 logger.log(Level.FINEST, objId+
"-"+recLab
452 +
"> added ringComb: "+ring);
455 boolean notNewCmb =
false;
456 for(List<Ring> oldCmb : allCombsOfRings)
458 StringBuilder sb2 =
new StringBuilder();
459 sb2.append(objId+
"-"+recLab
460 +
"> Comparing ring sets: ");
461 sb2.append(
"o> old: "+oldCmb);
462 sb2.append(
"o> new: "+ringsComb);
463 logger.log(Level.FINEST, sb2.toString());
468 logger.log(Level.FINEST,
"o> result: "+notNewCmb);
478 logger.log(Level.FINEST, objId+
"-"+recLab
479 +
"> adding to all combs of ring.");
480 allCombsOfRings.add(ringsComb);
487 logger.log(Level.FINEST, objId+
"-"+recLab+
"> in C");
489 ArrayList<ObjectPair> toDel =
new ArrayList<ObjectPair>();
490 for (
int ir =
recCount; ir<lstPairs.size(); ir++)
495 usedId.remove(usedId.indexOf(delVA.
getVertexId()));
496 usedId.remove(usedId.indexOf(delVB.
getVertexId()));
497 toDel.add(opToRemove);
499 lstPairs.removeAll(toDel);
501 logger.log(Level.FINEST, objId+
"-"+recLab
502 +
"> in C: after removal usedId: "+usedId+
NL
504 +
"> in C: after removal lstPairs: "+lstPairs);
507 if (lstPairs.contains(op))
509 logger.log(Level.FINEST, objId+
"-"+recLab+
"> in D");
512 usedId.remove(usedId.indexOf(vIdI));
513 usedId.remove(usedId.indexOf(vIdJ));
515 logger.log(Level.FINEST, objId+
"-"+recLab
516 +
"> in D: after removal usedId: "+usedId
518 +
"> in D: after removal lstPairs: "+lstPairs);
523 logger.log(Level.FINEST, objId+
"-"+recLab+
"> returning= "+addedNew);
536 Map<IBond,List<PathSubGraph>> interdepPaths)
538 boolean result =
false;
540 for (IBond bnd : interdepPaths.keySet())
542 List<PathSubGraph> psgSet = interdepPaths.get(bnd);
545 Vertex va1 = psg.getHeadVertex();
546 Vertex va2 = psg.getTailVertex();
553 if ((va1 == vb1 && va2 == vb2) ||
554 (va1 == vb2 && va2 == vb1))
578 ArrayList<ObjectPair> lstPairs,
579 Map<IBond,List<PathSubGraph>> interdepPaths,
580 Map<ObjectPair,PathSubGraph> allGoodPaths)
583 List<ArrayList<ObjectPair>> listOfIntrDepPaths =
584 new ArrayList<ArrayList<ObjectPair>>();
585 for (IBond bnd : interdepPaths.keySet())
587 ArrayList<ObjectPair> locSop =
new ArrayList<ObjectPair>();
588 List<PathSubGraph> psgSet = interdepPaths.get(bnd);
591 Vertex va1 = psg.getHeadVertex();
592 Vertex va2 = psg.getTailVertex();
599 if ((va1 == vb1 && va2 == vb2) ||
600 (va1 == vb2 && va2 == vb1))
606 if (locSop.size() > 1)
608 listOfIntrDepPaths.add(locSop);
613 boolean closable =
true;
614 for (ArrayList<ObjectPair> grpIntrdepPaths : listOfIntrDepPaths)
618 Map<ClosableConf,List<ObjectPair>> mapOcPathsWithCC =
619 new HashMap<ClosableConf,List<ObjectPair>>();
623 Map<ClosableConf,List<ClosableConf>> mapOfClosableConfs =
624 new HashMap<ClosableConf,List<ClosableConf>>();
636 List<ClosableConf> scc =
new ArrayList<ClosableConf>();
637 mapOfClosableConfs.put(cc,scc);
639 List<ObjectPair> sop =
new ArrayList<ObjectPair>();
641 mapOcPathsWithCC.put(cc,sop);
646 for (
int iOp=1; iOp<grpIntrdepPaths.size(); iOp++)
653 for (ArrayList<Double> ccAngles :
661 if (frstCC.shareBond(locCC) &&
662 frstCC.canCoexistWith(locCC))
666 if (mapOfClosableConfs.get(frstCC).size() == 0)
671 mapOfClosableConfs.get(frstCC).add(locCC);
673 mapOcPathsWithCC.get(frstCC).add(locOp);
681 boolean canCoexistWithAll =
true;
683 mapOfClosableConfs.get(frstCC))
685 if (lstCC.shareBond(locCC) &&
686 !lstCC.canCoexistWith(locCC))
689 canCoexistWithAll =
false;
693 if (canCoexistWithAll)
695 mapOfClosableConfs.get(frstCC).add(locCC);
697 mapOcPathsWithCC.get(frstCC).add(locOp);
707 if (!mapOcPathsWithCC.get(frstCC).contains(locOp))
722 boolean foundOneSetFullyClosable =
false;
725 int numPathWithSimCC = mapOcPathsWithCC.get(cc).size();
726 int numInterdepPaths = grpIntrdepPaths.size();
727 if (numPathWithSimCC == numInterdepPaths)
729 foundOneSetFullyClosable =
true;
733 if (!foundOneSetFullyClosable)
754 private ArrayList<Double>
angs;
761 this.angs = dihedrals;
768 boolean shareBnd =
false;
769 for (IBond tBnd : this.bonds)
771 if (other.
bonds.contains(tBnd))
783 boolean canCoexist =
true;
785 for (
int i=0; i<this.bonds.size(); i++)
787 IBond tBnd = this.bonds.get(i);
788 for (
int j=0; j<other.
bonds.size(); j++)
790 IBond oBnd = other.
bonds.get(j);
793 double diff = this.angs.get(i) - other.
angs.get(j);
794 diff = Math.abs(diff);
812 String s =
" ClosableConf [nBonds: " +
bonds.size()
814 for (IBond bnd :
bonds)
816 s = s + bnd.getAtom(0).getSymbol() +
"-"
817 + bnd.getAtom(1).getSymbol() +
" ";
820 s = s +
" dihedrals: " +
angs +
"]";
837 logger.log(Level.FINE,
"Checking conditions for chelates");
847 long vId = vert.getVertexId();
856 int levelOfVert = molGraph.
getLevel(vert);
868 boolean isOrphan =
false;
879 logger.log(Level.FINE,
"Found orphan: " + vert
880 +
" RingSet: " + ringsSet);
889 Map<String,ArrayList<Vertex>> rcasOnThisVertex =
890 new HashMap<String,ArrayList<Vertex>>();
896 cVrtx.getAttachmentPoints().get(0);
898 if (rcasOnThisVertex.keySet().contains(apCls))
900 rcasOnThisVertex.get(apCls).add(cVrtx);
904 ArrayList<Vertex> sameClsRCA =
905 new ArrayList<Vertex>();
906 sameClsRCA.add(cVrtx);
907 rcasOnThisVertex.put(apCls,sameClsRCA);
912 for (String apCls : rcasOnThisVertex.keySet())
914 int usedDenticity = 0;
915 for (
Vertex rcaVrtx : rcasOnThisVertex.get(apCls))
923 if (usedDenticity < rcasOnThisVertex.get(apCls).size())
925 logger.log(Level.FINE,
"Full-denticity is not "
926 +
"satisfied for apclas: " + apCls
927 +
"in vertex " + vert
928 +
" with set of rings " + ringsSet
929 +
"check graph: " + molGraph);
General set of constants used in DENOPTIM.
static final String EOL
new line character
static final String BONDPROPROTATABLE
String tag of Bond's property used to store the property of being rotatable.
Class defining a space of building blocks.
String toString()
Do not use this to make SDF representations.
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.
Container for the list of vertices and the edges that connect them.
List< Vertex > getVertexList()
int getLevel(Vertex v)
Calculates the level of a vertex in this graph.
boolean isVertexInRing(Vertex v)
Edge getEdgeWithParent(long l)
Looks for an edge that points to a vertex with the given vertex id.
This class represents the edge between two vertices.
Class representing a continuously connected portion of chemical object holding attachment points.
This class represents the closure of a ring in a spanning tree.
void setBondType(BondType bndType)
Set the bond type (i.e., bond order) of the chord connecting the head and the tail vertices.
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
Vertex.BBType getBuildingBlockType()
ArrayList< Vertex > getChilddren()
Looks into the edges that use any of the APs that belong to this vertex and returns the list of verti...
Object getProperty(Object property)
Utility class to handle the simultaneous closeness condition.
boolean shareBond(ClosableConf other)
ClosableConf(List< IBond > bonds, ArrayList< Double > dihedrals)
boolean canCoexistWith(ClosableConf other)
This is a tool to identify and manage vertices' connections not included in the DGraph,...
boolean hasInterdependentPaths(ArrayList< ObjectPair > lstPairs, Map< IBond, List< PathSubGraph > > interdepPaths)
Checks whether the combination of RCA's pairs leads to interdependent paths, that is,...
List< Ring > getRandomCombinationOfRings(IAtomContainer inMol, DGraph molGraph, int maxRingClosures)
Identifies a random combination of ring closing paths and returns it as list of DENOPTIMRings ready t...
boolean checkChelatesGraph(DGraph molGraph, List< Ring > ringsSet)
Evaluates the combination of a DENOPTIMGraph and a set of DENOPTIMRings and decides whether it's a pr...
RingClosureParameters settings
Parameters.
ArrayList< List< Ring > > getPossibleCombinationOfRings(IAtomContainer mol, DGraph molGraph)
Identifies all possible ring closing paths and returns them as list of DENOPTIMRings ready to be appe...
Logger logger
Logger to use.
CyclicGraphHandler(RingClosureParameters settings, FragmentSpace fragSpace)
Constructor from data structure.
boolean combineCompatPathSubGraphs(int ii0, ArrayList< Vertex > sortedKeys, Map< Vertex, ArrayList< Vertex > > compatMap, ArrayList< ObjectPair > lstPairs, ArrayList< Long > usedId, Map< ObjectPair, PathSubGraph > allGoodPaths, Map< IBond, List< PathSubGraph > > interdepPaths, ArrayList< List< Ring > > allCombsOfRings)
Recursive method to identify all the combination of rings.
int recCount
variables needed by recursive methods
static final String NL
New line character.
boolean checkClosabilityOfInterdependentPaths(ArrayList< ObjectPair > lstPairs, Map< IBond, List< PathSubGraph > > interdepPaths, Map< ObjectPair, PathSubGraph > allGoodPaths)
This method checks whether the interdependent paths are simultaneously closable.
FragmentSpace fragSpace
Fragment space definition.
This object represents a path in a DGraph.
List< IBond > getBondPath()
Returns the list of bonds in the path between the head and the tail.
RingClosingConformations getRCC()
Returns the ring closing conformations.
List< Vertex > getVertecesPath()
Returns the list of verteces involved.
Vertex getHeadVertex()
Returns the vertex representing the head of the chain.
Vertex getTailVertex()
Returns the vertex representing the tail of the chain.
List< Edge > getEdgesPath()
Returns the list of edges involved.
A class for iterating over sets of ring combinations generated by considering any constrain and setti...
Parameters and setting related to handling ring closures.
Set< APClass > metalCoordinatingAPClasses
List of metal-coordinating APClasses.
boolean checkInterdependentChains()
double getPathConfSearchStep()
Utility class to calculate and manage the alternative ring sizes achievable by formation of Rings.
boolean getCompatibilityOfPair(Vertex vI, Vertex vJ)
void initialize(IAtomContainer origMol, DGraph graph)
Makes this ring size manager work on a specific system that has a molecular representation and a DENO...
Logger getLogger()
Get the name of the program specific logger.
This class is the equivalent of the Pair data structure used in C++ Although AbstractMap....
Toolbox useful when dealing with Ring Closing Attractors and ring closures.
static boolean areSameRingsSet(List< Ring > oldCmb, List< Ring > ringsComb)
Compares two combinations of DENOPTIMRingss and evaluates whether these correspond to the same combin...
Possible chemical bond types an edge can represent.
The type of building block.