19package denoptim.graph.rings;
21import java.util.ArrayList;
22import java.util.Arrays;
23import java.util.Collections;
24import java.util.HashMap;
25import java.util.Iterator;
29import java.util.logging.Level;
30import java.util.logging.Logger;
32import javax.vecmath.Point3d;
34import org.openscience.cdk.Bond;
35import org.openscience.cdk.graph.ShortestPaths;
36import org.openscience.cdk.graph.matrix.TopologicalMatrix;
37import org.openscience.cdk.interfaces.IAtom;
38import org.openscience.cdk.interfaces.IAtomContainer;
39import org.openscience.cdk.interfaces.IBond;
40import org.openscience.cdk.interfaces.IChemObjectBuilder;
41import org.openscience.cdk.silent.SilentChemObjectBuilder;
43import denoptim.constants.DENOPTIMConstants;
44import denoptim.exception.DENOPTIMException;
45import denoptim.fragspace.FragmentSpace;
46import denoptim.graph.APClass;
47import denoptim.graph.AttachmentPoint;
48import denoptim.graph.DGraph;
49import denoptim.graph.Edge;
50import denoptim.graph.Edge.BondType;
51import denoptim.graph.EmptyVertex;
52import denoptim.graph.Fragment;
53import denoptim.graph.Ring;
54import denoptim.graph.Vertex;
55import denoptim.graph.Vertex.BBType;
56import denoptim.utils.ManySMARTSQuery;
57import denoptim.utils.MoleculeUtils;
58import denoptim.utils.ObjectPair;
59import denoptim.utils.RingClosingUtils;
136 List<Ring> combOfRings = iter.
next();
137 logger.log(Level.FINE,
"Random combOfRings: "+combOfRings);
154 IAtomContainer mol,
DGraph molGraph)
158 Map<ObjectPair,PathSubGraph> allGoodPaths =
159 new HashMap<ObjectPair,PathSubGraph>();
160 ArrayList<Vertex> rcaVertLst = molGraph.getFreeRCVertices();
167 Map<Vertex,ArrayList<Vertex>> compatMap =
168 new HashMap<Vertex,ArrayList<Vertex>>();
169 for (
int i=0; i<rcaVertLst.size(); i++)
171 Vertex vI = rcaVertLst.get(i);
172 for (
int j=i+1; j<rcaVertLst.size(); j++)
174 Vertex vJ = rcaVertLst.get(j);
177 logger.log(Level.FINE,
"Rejecting RC-incompatible pair "
184 logger.log(Level.FINE,
"Evaluating closability of path "
191 logger.log(Level.FINE,
"Rejecting RCA pair");
196 logger.log(Level.FINE,
"All compatibility criteria satisfied: "
197 +
"Storing verified RCA pair");
200 if (compatMap.containsKey(vI))
202 compatMap.get(vI).add(vJ);
206 ArrayList<Vertex> lst =
207 new ArrayList<Vertex>();
209 compatMap.put(vI,lst);
211 if (compatMap.containsKey(vJ))
213 compatMap.get(vJ).add(vI);
217 ArrayList<Vertex> lst =
218 new ArrayList<Vertex>();
220 compatMap.put(vJ,lst);
233 allGoodPaths.put(compatPair,subGraph);
237 logger.log(Level.FINE,
"Compatibility Map for RCAs: "+
NL+compatMap);
240 Map<IBond,List<PathSubGraph>> interdepPaths =
241 new HashMap<IBond,List<PathSubGraph>>();
253 Vertex hA = rpA.getHeadVertex();
254 Vertex tA = rpA.getTailVertex();
255 Vertex hB = rpB.getHeadVertex();
256 Vertex tB = rpB.getTailVertex();
258 if ((hA == hB || hA == tB) || (tA == hB || tA == tB))
263 for (IBond bnd : rpA.getBondPath())
270 if (rotFlg==
null || !Boolean.valueOf(rotFlg.toString()))
275 if (rpB.getBondPath().contains(bnd))
277 if (interdepPaths.containsKey(bnd))
279 interdepPaths.get(bnd).add(rpA);
280 interdepPaths.get(bnd).add(rpB);
284 List<PathSubGraph> paths =
285 new ArrayList<PathSubGraph>();
288 interdepPaths.put(bnd,paths);
294 StringBuilder sb =
new StringBuilder();
295 for (IBond bnd : interdepPaths.keySet())
297 sb.append(
"Interdependent paths for bond " + bnd);
298 List<PathSubGraph> sop = interdepPaths.get(bnd);
301 sb.append(
NL +
" -> vA: "+p.getHeadVertex()
302 +
" vB: "+p.getTailVertex());
305 logger.log(Level.FINE, sb.toString());
309 ArrayList<ObjectPair> lstPairs =
new ArrayList<ObjectPair>();
310 ArrayList<Long> usedId =
new ArrayList<Long>();
311 ArrayList<Vertex> sortedKeys =
new ArrayList<Vertex>();
312 for (
Vertex keyVert : compatMap.keySet())
314 sortedKeys.add(keyVert);
318 ArrayList<List<Ring>> allCombsOfRings =
319 new ArrayList<List<Ring>>();
328 logger.log(Level.FINE,
"All possible combination of rings: " +
330 return allCombsOfRings;
340 ArrayList<Vertex> sortedKeys,
341 Map<
Vertex,ArrayList<Vertex>> compatMap,
342 ArrayList<ObjectPair> lstPairs,
343 ArrayList<Long> usedId,
344 Map<ObjectPair,PathSubGraph> allGoodPaths,
345 Map<IBond,List<PathSubGraph>> interdepPaths,
346 ArrayList<List<Ring>> allCombsOfRings)
349 int objId = this.hashCode();
350 String recLab =
new String(
new char[
recCount]).replace(
"\0",
"-");
352 StringBuilder sb =
new StringBuilder();
353 sb.append(objId+
"-"+recLab+
"> Begin of new recursion: "+
recCount+
NL);
354 sb.append(objId+
"-"+recLab+
"> sortedKeys= "+sortedKeys+
NL);
355 sb.append(objId+
"-"+recLab+
"> usedId= "+usedId+
NL);
356 sb.append(objId+
"-"+recLab+
"> ii0= "+ii0+
NL);
357 sb.append(objId+
"-"+recLab+
"> lstPairs= "+lstPairs+
NL);
358 sb.append(objId+
"-"+recLab+
"> compatMap= "+compatMap+
NL);
359 sb.append(objId+
"-"+recLab+
"> allCombsOfRings"+
NL);
360 for (List<Ring> ringSet : allCombsOfRings)
362 sb.append(
" "+ringSet+
NL);
364 logger.log(Level.FINEST, sb.toString());
366 boolean inFound =
false;
367 boolean addedNew =
false;
368 for (
int ii=ii0; ii<sortedKeys.size(); ii++)
370 Vertex vi = sortedKeys.get(ii);
373 logger.log(Level.FINEST, objId+
"-"+recLab+
"> vIdI= "+vIdI);
375 if (usedId.contains(vIdI))
380 for (
Vertex vj : compatMap.get(vi))
382 long vIdJ = vj.getVertexId();
384 logger.log(Level.FINEST, objId+
"-"+recLab+
"> vIdJ= "+vIdJ);
386 if (usedId.contains(vIdJ) || usedId.contains(vIdI))
404 if (lstPairs.size() >
maxLng)
419 logger.log(Level.FINEST, objId+
"-"+recLab+
"> lstPairs.size() "
420 +
"& maxLng= "+lstPairs.size() +
" " +
maxLng);
422 if (!inFound && lstPairs.size() ==
maxLng)
424 logger.log(Level.FINEST, objId+
"-"+recLab+
"> in A");
426 boolean closable =
true;
437 logger.log(Level.FINEST, objId+
"-"+recLab+
"> in B");
439 List<Ring> ringsComb =
new ArrayList<Ring>();
443 ArrayList<Vertex> arrLst =
444 new ArrayList<Vertex>();
450 BondType btH = es.get(0).getBondType();
451 BondType btT = es.get(es.size()-1).getBondType();
454 String s =
"Attempt to close rings is not "
455 +
"compatible to the different bond type "
456 +
"specified by the head and tail APs: ("
457 + btH +
"!=" + btT +
" for vertices "
466 logger.log(Level.FINEST, objId+
"-"+recLab
467 +
"> added ringComb: "+ring);
470 boolean notNewCmb =
false;
471 for(List<Ring> oldCmb : allCombsOfRings)
473 StringBuilder sb2 =
new StringBuilder();
474 sb2.append(objId+
"-"+recLab
475 +
"> Comparing ring sets: ");
476 sb2.append(
"o> old: "+oldCmb);
477 sb2.append(
"o> new: "+ringsComb);
478 logger.log(Level.FINEST, sb2.toString());
483 logger.log(Level.FINEST,
"o> result: "+notNewCmb);
493 logger.log(Level.FINEST, objId+
"-"+recLab
494 +
"> adding to all combs of ring.");
495 allCombsOfRings.add(ringsComb);
502 logger.log(Level.FINEST, objId+
"-"+recLab+
"> in C");
504 ArrayList<ObjectPair> toDel =
new ArrayList<ObjectPair>();
505 for (
int ir =
recCount; ir<lstPairs.size(); ir++)
510 usedId.remove(usedId.indexOf(delVA.
getVertexId()));
511 usedId.remove(usedId.indexOf(delVB.
getVertexId()));
512 toDel.add(opToRemove);
514 lstPairs.removeAll(toDel);
516 logger.log(Level.FINEST, objId+
"-"+recLab
517 +
"> in C: after removal usedId: "+usedId+
NL
519 +
"> in C: after removal lstPairs: "+lstPairs);
522 if (lstPairs.contains(op))
524 logger.log(Level.FINEST, objId+
"-"+recLab+
"> in D");
527 usedId.remove(usedId.indexOf(vIdI));
528 usedId.remove(usedId.indexOf(vIdJ));
530 logger.log(Level.FINEST, objId+
"-"+recLab
531 +
"> in D: after removal usedId: "+usedId
533 +
"> in D: after removal lstPairs: "+lstPairs);
538 logger.log(Level.FINEST, objId+
"-"+recLab+
"> returning= "+addedNew);
551 Map<IBond,List<PathSubGraph>> interdepPaths)
553 boolean result =
false;
555 for (IBond bnd : interdepPaths.keySet())
557 List<PathSubGraph> psgSet = interdepPaths.get(bnd);
560 Vertex va1 = psg.getHeadVertex();
561 Vertex va2 = psg.getTailVertex();
568 if ((va1 == vb1 && va2 == vb2) ||
569 (va1 == vb2 && va2 == vb1))
593 ArrayList<ObjectPair> lstPairs,
594 Map<IBond,List<PathSubGraph>> interdepPaths,
595 Map<ObjectPair,PathSubGraph> allGoodPaths)
598 List<ArrayList<ObjectPair>> listOfIntrDepPaths =
599 new ArrayList<ArrayList<ObjectPair>>();
600 for (IBond bnd : interdepPaths.keySet())
602 ArrayList<ObjectPair> locSop =
new ArrayList<ObjectPair>();
603 List<PathSubGraph> psgSet = interdepPaths.get(bnd);
606 Vertex va1 = psg.getHeadVertex();
607 Vertex va2 = psg.getTailVertex();
614 if ((va1 == vb1 && va2 == vb2) ||
615 (va1 == vb2 && va2 == vb1))
621 if (locSop.size() > 1)
623 listOfIntrDepPaths.add(locSop);
628 boolean closable =
true;
629 for (ArrayList<ObjectPair> grpIntrdepPaths : listOfIntrDepPaths)
633 Map<ClosableConf,List<ObjectPair>> mapOcPathsWithCC =
634 new HashMap<ClosableConf,List<ObjectPair>>();
638 Map<ClosableConf,List<ClosableConf>> mapOfClosableConfs =
639 new HashMap<ClosableConf,List<ClosableConf>>();
651 List<ClosableConf> scc =
new ArrayList<ClosableConf>();
652 mapOfClosableConfs.put(cc,scc);
654 List<ObjectPair> sop =
new ArrayList<ObjectPair>();
656 mapOcPathsWithCC.put(cc,sop);
661 for (
int iOp=1; iOp<grpIntrdepPaths.size(); iOp++)
668 for (ArrayList<Double> ccAngles :
676 if (frstCC.shareBond(locCC) &&
677 frstCC.canCoexistWith(locCC))
681 if (mapOfClosableConfs.get(frstCC).size() == 0)
686 mapOfClosableConfs.get(frstCC).add(locCC);
688 mapOcPathsWithCC.get(frstCC).add(locOp);
696 boolean canCoexistWithAll =
true;
698 mapOfClosableConfs.get(frstCC))
700 if (lstCC.shareBond(locCC) &&
701 !lstCC.canCoexistWith(locCC))
704 canCoexistWithAll =
false;
708 if (canCoexistWithAll)
710 mapOfClosableConfs.get(frstCC).add(locCC);
712 mapOcPathsWithCC.get(frstCC).add(locOp);
722 if (!mapOcPathsWithCC.get(frstCC).contains(locOp))
737 boolean foundOneSetFullyClosable =
false;
740 int numPathWithSimCC = mapOcPathsWithCC.get(cc).size();
741 int numInterdepPaths = grpIntrdepPaths.size();
742 if (numPathWithSimCC == numInterdepPaths)
744 foundOneSetFullyClosable =
true;
748 if (!foundOneSetFullyClosable)
769 private ArrayList<Double>
angs;
776 this.angs = dihedrals;
783 boolean shareBnd =
false;
784 for (IBond tBnd : this.bonds)
786 if (other.
bonds.contains(tBnd))
798 boolean canCoexist =
true;
800 for (
int i=0; i<this.bonds.size(); i++)
802 IBond tBnd = this.bonds.get(i);
803 for (
int j=0; j<other.
bonds.size(); j++)
805 IBond oBnd = other.
bonds.get(j);
808 double diff = this.angs.get(i) - other.
angs.get(j);
809 diff = Math.abs(diff);
827 String s =
" ClosableConf [nBonds: " +
bonds.size()
829 for (IBond bnd :
bonds)
831 s = s + bnd.getAtom(0).getSymbol() +
"-"
832 + bnd.getAtom(1).getSymbol() +
" ";
835 s = s +
" dihedrals: " +
angs +
"]";
852 logger.log(Level.FINE,
"Checking conditions for chelates");
862 long vId = vert.getVertexId();
871 int levelOfVert = molGraph.
getLevel(vert);
883 boolean isOrphan =
false;
894 logger.log(Level.FINE,
"Found orphan: " + vert
895 +
" RingSet: " + ringsSet);
904 Map<String,ArrayList<Vertex>> rcasOnThisVertex =
905 new HashMap<String,ArrayList<Vertex>>();
911 cVrtx.getAttachmentPoints().get(0);
913 if (rcasOnThisVertex.keySet().contains(apCls))
915 rcasOnThisVertex.get(apCls).add(cVrtx);
919 ArrayList<Vertex> sameClsRCA =
920 new ArrayList<Vertex>();
921 sameClsRCA.add(cVrtx);
922 rcasOnThisVertex.put(apCls,sameClsRCA);
927 for (String apCls : rcasOnThisVertex.keySet())
929 int usedDenticity = 0;
930 for (
Vertex rcaVrtx : rcasOnThisVertex.get(apCls))
938 if (usedDenticity < rcasOnThisVertex.get(apCls).size())
940 logger.log(Level.FINE,
"Full-denticity is not "
941 +
"satisfied for apclas: " + apCls
942 +
"in vertex " + vert
943 +
" with set of rings " + ringsSet
944 +
"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.