$darkmode
DENOPTIM
RandomCombOfRingsIterator.java
Go to the documentation of this file.
1package denoptim.graph.rings;
2
3import java.util.ArrayList;
4import java.util.Collections;
5import java.util.Iterator;
6import java.util.List;
7import java.util.logging.Level;
8
9import org.openscience.cdk.interfaces.IAtomContainer;
10
11import denoptim.exception.DENOPTIMException;
12import denoptim.fragspace.FragmentSpace;
13import denoptim.graph.DGraph;
14import denoptim.graph.Fragment;
15import denoptim.graph.Ring;
16import denoptim.graph.Vertex;
17import denoptim.graph.Edge.BondType;
18
26public class RandomCombOfRingsIterator implements Iterator<List<Ring>>
27{
31 private IAtomContainer originalMol;
32
37
41 private int maxRingClosures = -1;
42
47
52
53//-----------------------------------------------------------------------------
54
63 public RandomCombOfRingsIterator(IAtomContainer iac,
66 {
67 this.settings = rcParams;
68 this.fragSpace = fragSpace;
69 this.maxRingClosures = maxRingClosures;
70 this.originalMol = iac;
71 this.molGraph = molGraph;
72 }
73
74//-----------------------------------------------------------------------------
75
79 @Override
80 public boolean hasNext()
81 {
82 return true;
83 }
84
85//-----------------------------------------------------------------------------
86
87 @Override
88 public List<Ring> next()
89 {
92
93 List<Vertex> wLstVrtI = rsm.getRSBiasedListOfCandidates();
94
95 // Randomly choose the compatible combinations of RCAs and store them
96 // as rings
97 List<Ring> combOfRings = new ArrayList<Ring>();
98 while (wLstVrtI.size() > 0)
99 {
100 // Termination criterion based on maximum number of rings per graph
101 if (combOfRings.size() >= maxRingClosures)
102 break;
103
104 int vIdI = settings.getRandomizer().nextInt(wLstVrtI.size());
105 Vertex vI = wLstVrtI.get(vIdI);
106 wLstVrtI.removeAll(Collections.singleton(vI));
107
108 // Create vector of possible choices for second RCV
109 List<Vertex> wLstVrtJ = rsm.getRSBiasedListOfCandidates(vI);
110 while (wLstVrtJ.size() > 0)
111 {
112 int vIdJ = settings.getRandomizer().nextInt(wLstVrtJ.size());
113 Vertex vJ = wLstVrtJ.get(vIdJ);
114 wLstVrtJ.removeAll(Collections.singleton(vJ));
115
116 PathSubGraph path = new PathSubGraph(vI, vJ, molGraph);
117 // NB: closability is evaluated on the original
119 {
120 ArrayList<Vertex> arrLst = new ArrayList<Vertex>();
121 arrLst.addAll(path.getVertecesPath());
122 Ring ring = new Ring(arrLst);
123
124 BondType bndTypI = vI.getEdgeToParent().getBondType();
125 BondType bndTypJ = vJ.getEdgeToParent().getBondType();
126 if (bndTypI != bndTypJ)
127 {
128 String s = "Attempt to close rings is not compatible "
129 + "to the different bond type specified by the "
130 + "head and tail APs: (" + bndTypI + "!="
131 + bndTypJ + " for vertices " + vI + " "
132 + vJ + ")";
133 throw new IllegalArgumentException(s);
134 }
135 ring.setBondType(bndTypI);
136
137 combOfRings.add(ring);
138
139 wLstVrtI.removeAll(Collections.singleton(vJ));
140
141 // Update ring sizes according to the newly added bond
142 if (vI instanceof Fragment && vJ instanceof Fragment)
143 {
144 rsm.addRingClosingBond(vI,vJ);
145 }
146 rsm.setVertexAsDone(vJ);
147 break;
148 }
149 }
150 rsm.setVertexAsDone(vI);
151 }
152 return combOfRings;
153 }
154
155//-----------------------------------------------------------------------------
156
157}
Class defining a space of building blocks.
Container for the list of vertices and the edges that connect them.
Definition: DGraph.java:102
BondType getBondType()
Definition: Edge.java:164
Class representing a continuously connected portion of chemical object holding attachment points.
Definition: Fragment.java:61
This class represents the closure of a ring in a spanning tree.
Definition: Ring.java:40
void setBondType(BondType bndType)
Set the bond type (i.e., bond order) of the chord connecting the head and the tail vertices.
Definition: Ring.java:158
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
Definition: Vertex.java:61
Edge getEdgeToParent()
Looks into the edges that use any of the APs that belong to this vertex and returns the edge that has...
Definition: Vertex.java:972
Tool box for determining whether a chain of atoms, i.e., a path, can be folded as to form a ring-clos...
static boolean isCloseable(PathSubGraph subGraph, IAtomContainer mol, RingClosureParameters settings)
Method to evaluate the closability of a single path in a graph.
This object represents a path in a DGraph.
List< Vertex > getVertecesPath()
Returns the list of verteces involved.
A class for iterating over sets of ring combinations generated by considering any constrain and setti...
boolean hasNext()
Always returns true because we allow duplicates.
int maxRingClosures
Max number of ring closures to consider in a valid combination of rings.
FragmentSpace fragSpace
Space of building blocks.
RandomCombOfRingsIterator(IAtomContainer iac, DGraph molGraph, int maxRingClosures, FragmentSpace fragSpace, RingClosureParameters rcParams)
Constructs an iterator.
IAtomContainer originalMol
Chemical representation of the system we work with.
RingClosureParameters settings
Parameters related to rings.
DGraph molGraph
Graph representation of the system we work with.
Parameters and setting related to handling ring closures.
Utility class to calculate and manage the alternative ring sizes achievable by formation of Rings.
void addRingClosingBond(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...
Randomizer getRandomizer()
Returns the current program-specific randomizer.
int nextInt(int i)
Returns a pseudo-random, uniformly distributed int value between 0 (inclusive) and the specified valu...
Possible chemical bond types an edge can represent.
Definition: Edge.java:303