ring.cpp
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------------
2 // d-SEAMS is free software: you can redistribute it and/or modify
3 // it under the terms of the GNU General Public License as published by
4 // the Free Software Foundation, either version 3 of the License, or
5 // (at your option) any later version.
6 //
7 // A copy of the GNU General Public License is available at
8 // http://www.gnu.org/licenses/
9 //-----------------------------------------------------------------------------------
10 
11 #include <ring.hpp>
12 
19  //
21 
22  rings.swap(tempEmpty);
23 
24  return 0;
25 }
26 
35  std::vector<int> ring2) {
36  //
37  std::vector<int> common;
38  int iatom; // Index to search for
39 
40  for (int i = 0; i < ring1.size(); i++) {
41  iatom = ring1[i];
42  // Search for iatom in ring2
43 
44  auto it = std::find(ring2.begin(), ring2.end(), iatom);
45 
46  if (it != ring2.end()) {
47  common.push_back(iatom);
48  } // iatom was found!
49  } // end of loop through every element of ring1
50 
51  return common;
52 }
53 
64  std::vector<int> ring2,
65  std::vector<int> ring3) {
67  common1; // Vector containing the common elements of the first two rings
69  common2; // Vector containing the common elements of the three rings
70 
71  // Common elements among the first two rings
72  common1 = ring::findsCommonElements(ring1, ring2);
73  if (common1.size() == 0) {
74  return false;
75  } // no common elements in ring1 and ring2
76 
77  // Common elements among all three rings
78  common2 = ring::findsCommonElements(common1, ring3);
79 
80  // If no common elements were found:
81  if (common2.size() == 0) {
82  return false;
83  } // no common elements between ring1, ring2, and ring3
84 
85  return true; // Common elements found!
86 }
87 
98  //
99  int ringSize = ring.size(); // should be 6
100  std::vector<int> ringTriplet; // triplet from the ring to be searched
101  int kIndex; // Used for making the triplet
102 
103  // Loop through every possible triplet in the ring to be searched
104  for (int i = 0; i < ringSize; i++) {
105  ringTriplet.clear(); // init
106  // Get the first element of the ring triplet
107  ringTriplet.push_back(ring[i]);
108  //
109  // Get the next two elements
110  for (int k = 1; k < 3; k++) {
111  kIndex = i + k;
112  // Wrap-around
113  if (kIndex >= ringSize) {
114  kIndex -= ringSize;
115  } // end of wrap-around
116  ringTriplet.push_back(ring[kIndex]);
117  } // next two elements of ringTriplet
118  //
119  // Obtained ringTriplet!
120  // Check equality
121  if (triplet == ringTriplet) {
122  return true;
123  } // triplet matches!
124  //
125  // Check the reversed triplet too
126  std::reverse(ringTriplet.begin(), ringTriplet.end());
127 
128  // Check for equality
129  if (triplet == ringTriplet) {
130  return true;
131  } // reversed triplet matches
132  } // first element of ringTriplet
133 
134  return false;
135 }
136 
150  //
151  std::vector<std::vector<int>> ringSingleSize; // rings of one size
152 
153  // rings contains primitive rings of all sizes
154  // Only save rings of a given size (ringSize) to the new
155  // vector of vectors, ringSingleSize
156  for (int iring = 0; iring < rings.size(); iring++) {
157  // Check the size of the current ring
158  // If it is the correct size, save it in ringSingleSize
159  if (rings[iring].size() == ringSize) {
160  ringSingleSize.push_back(rings[iring]);
161  } // End of check of the size of iring
162  } // end of loop through all rings in rings
163 
164  return ringSingleSize;
165 }
166 
176  std::vector<int> commonElements; // Vector containing common elements
177 
178  // Sort the vectors before finding common elements
179  sort(ring1.begin(), ring1.end());
180  sort(ring2.begin(), ring2.end());
181 
182  // Find intersection of sorted vectors
183  auto it =
184  std::set_intersection(ring1.begin(), ring1.end(), ring2.begin(),
185  ring2.end(), std::back_inserter(commonElements));
186 
187  // If there are no elements in common, then return false
188  if (commonElements.size() == 0) {
189  return false;
190  }
191  // If there are common elements, return true
192  else {
193  return true;
194  }
195 }
196 
208  // Sort the rings first
209  sort(ring1.begin(), ring1.end()); // Sort ring1 by ID
210  sort(ring2.begin(), ring2.end()); // Sort ring2 by ID
211  bool result;
212 
213  (ring1 == ring2) ? result = true : result = false;
214 
215  return result;
216 }
T back_inserter(T... args)
T begin(T... args)
T clear(T... args)
T end(T... args)
T find(T... args)
bool commonElementsInThreeRings(std::vector< int > ring1, std::vector< int > ring2, std::vector< int > ring3)
Common elements in 3 rings.
Definition: ring.cpp:63
bool findTripletInRing(std::vector< int > ring, std::vector< int > triplet)
Searches a particular ring for a triplet.
Definition: ring.cpp:97
int clearRingList(std::vector< std::vector< int >> &rings)
Erases memory for a vector of vectors for a list of rings.
Definition: ring.cpp:18
bool hasCommonElements(std::vector< int > ring1, std::vector< int > ring2)
Definition: ring.cpp:175
std::vector< std::vector< int > > getSingleRingSize(std::vector< std::vector< int >> rings, int ringSize)
Returns a vector of vectors of rings of a single size.
Definition: ring.cpp:149
std::vector< int > findsCommonElements(std::vector< int > ring1, std::vector< int > ring2)
Returns the common elements of two rings.
Definition: ring.cpp:34
bool compareRings(std::vector< int > ring1, std::vector< int > ring2)
Definition: ring.cpp:207
Topological network criteria functions.
Definition: ring.hpp:60
T push_back(T... args)
T reverse(T... args)
File containing common functions used by bulk and confined topological network critera.
T set_intersection(T... args)
T size(T... args)
T swap(T... args)