$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;
7
8import org.openscience.cdk.interfaces.IAtomContainer;
9
10import denoptim.exception.DENOPTIMException;
11import denoptim.fragspace.FragmentSpace;
12import denoptim.graph.DGraph;
13import denoptim.graph.Fragment;
14import denoptim.graph.Ring;
15import denoptim.graph.Vertex;
16import denoptim.graph.Edge.BondType;
17
25public class RandomCombOfRingsIterator implements Iterator<List<Ring>>
26{
30 private IAtomContainer originalMol;
31
36
40 private int maxRingClosures = -1;
41
46
51
52//-----------------------------------------------------------------------------
53
62 public RandomCombOfRingsIterator(IAtomContainer iac,
65 {
66 this.settings = rcParams;
67 this.fragSpace = fragSpace;
68 this.maxRingClosures = maxRingClosures;
69 this.originalMol = iac;
70 this.molGraph = molGraph;
71 }
72
73//-----------------------------------------------------------------------------
74
78 @Override
79 public boolean hasNext()
80 {
81 return true;
82 }
83
84//-----------------------------------------------------------------------------
85
86 @Override
87 public List<Ring> next()
88 {
91
92 List<Vertex> wLstVrtI = rsm.getRSBiasedListOfCandidates();
93
94 // Randomly choose the compatible combinations of RCAs and store them
95 // as rings
96 List<Ring> combOfRings = new ArrayList<Ring>();
97 while (wLstVrtI.size() > 0)
98 {
99 // Termination criterion based on maximum number of rings per graph
100 if (combOfRings.size() >= maxRingClosures)
101 break;
102
103 int vIdI = settings.getRandomizer().nextInt(wLstVrtI.size());
104 Vertex vI = wLstVrtI.get(vIdI);
105 wLstVrtI.removeAll(Collections.singleton(vI));
106
107 // Create vector of possible choices for second RCV
108 List<Vertex> wLstVrtJ = rsm.getRSBiasedListOfCandidates(vI);
109 while (wLstVrtJ.size() > 0)
110 {
111 int vIdJ = settings.getRandomizer().nextInt(wLstVrtJ.size());
112 Vertex vJ = wLstVrtJ.get(vIdJ);
113 wLstVrtJ.removeAll(Collections.singleton(vJ));
114
115 PathSubGraph path = new PathSubGraph(vI, vJ, molGraph);
116 // NB: closability is evaluated on the original
118 {
119 ArrayList<Vertex> arrLst = new ArrayList<Vertex>();
120 arrLst.addAll(path.getVertecesPath());
121 Ring ring = new Ring(arrLst);
122
123 BondType bndTypI = vI.getEdgeToParent().getBondType();
124 BondType bndTypJ = vJ.getEdgeToParent().getBondType();
125 if (bndTypI != bndTypJ)
126 {
127 String s = "Attempt to close rings is not compatible "
128 + "to the different bond type specified by the "
129 + "head and tail APs: (" + bndTypI + "!="
130 + bndTypJ + " for vertices " + vI + " "
131 + vJ + ")";
132 throw new IllegalArgumentException(s);
133 }
134 ring.setBondType(bndTypI);
135
136 combOfRings.add(ring);
137
138 wLstVrtI.removeAll(Collections.singleton(vJ));
139
140 // Update ring sizes according to the newly added bond
141 if (vI instanceof Fragment && vJ instanceof Fragment)
142 {
143 rsm.addRingClosingBond(vI,vJ);
144 }
145 rsm.setVertexAsDone(vJ);
146 break;
147 }
148 }
149 rsm.setVertexAsDone(vI);
150 }
151 return combOfRings;
152 }
153
154//-----------------------------------------------------------------------------
155
156}
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:1059
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