ProSHADE  0.7.6.2 (DEC 2021)
Protein Shape Detection
ProSHADE_misc.cpp
Go to the documentation of this file.
1 
22 //==================================================== ProSHADE
23 #include "ProSHADE_misc.hpp"
24 
33 void ProSHADE_internal_misc::addToStringVector ( std::vector < std::string >* vecToAddTo, std::string elementToAdd )
34 {
35  //================================================ Based on the compiler C++11 support, use the correct vector addition function.
36 #if __cplusplus >= 201103L
37  vecToAddTo->emplace_back ( elementToAdd );
38 #else
39  vecToAddTo->push_back ( elementToAdd );
40 #endif
41 
42  //================================================ Done
43  return ;
44 
45 }
46 
55 void ProSHADE_internal_misc::addToSingleVector ( std::vector < proshade_single >* vecToAddTo, proshade_single elementToAdd )
56 {
57  //================================================ Based on the compiler C++11 support, use the correct vector addition function.
58 #if __cplusplus >= 201103L
59  vecToAddTo->emplace_back ( elementToAdd );
60 #else
61  vecToAddTo->push_back ( elementToAdd );
62 #endif
63 
64  //================================================ Done
65  return ;
66 
67 }
68 
77 void ProSHADE_internal_misc::addToDoubleVector ( std::vector < proshade_double >* vecToAddTo, proshade_double elementToAdd )
78 {
79  //================================================ Based on the compiler C++11 support, use the correct vector addition function.
80 #if __cplusplus >= 201103L
81  vecToAddTo->emplace_back ( elementToAdd );
82 #else
83  vecToAddTo->push_back ( elementToAdd );
84 #endif
85 
86  //================================================ Done
87  return ;
88 
89 }
90 
99 void ProSHADE_internal_misc::addToUnsignVector ( std::vector < proshade_unsign >* vecToAddTo, proshade_unsign elementToAdd )
100 {
101  //================================================ Based on the compiler C++11 support, use the correct vector addition function.
102 #if __cplusplus >= 201103L
103  vecToAddTo->emplace_back ( elementToAdd );
104 #else
105  vecToAddTo->push_back ( elementToAdd );
106 #endif
107 
108  //================================================ Done
109  return ;
110 
111 }
112 
121 void ProSHADE_internal_misc::addToSignedVector ( std::vector < proshade_signed >* vecToAddTo, proshade_signed elementToAdd )
122 {
123  //================================================ Based on the compiler C++11 support, use the correct vector addition function.
124 #if __cplusplus >= 201103L
125  vecToAddTo->emplace_back ( elementToAdd );
126 #else
127  vecToAddTo->push_back ( elementToAdd );
128 #endif
129 
130  //================================================ Done
131  return ;
132 
133 }
134 
143 void ProSHADE_internal_misc::addToDblPtrVector ( std::vector < proshade_double* >* vecToAddTo, proshade_double* elementToAdd )
144 {
145  //================================================ Based on the compiler C++11 support, use the correct vector addition function.
146 #if __cplusplus >= 201103L
147  vecToAddTo->emplace_back ( elementToAdd );
148 #else
149  vecToAddTo->push_back ( elementToAdd );
150 #endif
151 
152  //================================================ Done
153  return ;
154 
155 }
156 
166 void ProSHADE_internal_misc::addToSigPtrVector ( std::vector < proshade_signed* >* vecToAddTo, proshade_signed* elementToAdd )
167 {
168  //================================================ Based on the compiler C++11 support, use the correct vector addition function.
169 #if __cplusplus >= 201103L
170  vecToAddTo->emplace_back ( elementToAdd );
171 #else
172  vecToAddTo->push_back ( elementToAdd );
173 #endif
174 
175  //================================================ Done
176  return ;
177 
178 }
179 
189 void ProSHADE_internal_misc::addToUnsPtrVector ( std::vector < proshade_unsign* >* vecToAddTo, proshade_unsign* elementToAdd )
190 {
191  //================================================ Based on the compiler C++11 support, use the correct vector addition function.
192 #if __cplusplus >= 201103L
193  vecToAddTo->emplace_back ( elementToAdd );
194 #else
195  vecToAddTo->push_back ( elementToAdd );
196 #endif
197 
198  //================================================ Done
199  return ;
200 
201 }
202 
211 void ProSHADE_internal_misc::addToUnsignVectorVector ( std::vector < std::vector < proshade_unsign > >* vecToAddTo, std::vector < proshade_unsign > elementToAdd )
212 {
213  //================================================ Based on the compiler C++11 support, use the correct vector addition function.
214 #if __cplusplus >= 201103L
215  vecToAddTo->emplace_back ( elementToAdd );
216 #else
217  vecToAddTo->push_back ( elementToAdd );
218 #endif
219 
220  //================================================ Done
221  return ;
222 
223 }
224 
233 void ProSHADE_internal_misc::addToDoubleVectorVector ( std::vector < std::vector < proshade_double > >* vecToAddTo, std::vector < proshade_double > elementToAdd )
234 {
235  //================================================ Based on the compiler C++11 support, use the correct vector addition function.
236 #if __cplusplus >= 201103L
237  vecToAddTo->emplace_back ( elementToAdd );
238 #else
239  vecToAddTo->push_back ( elementToAdd );
240 #endif
241 
242  //================================================ Done
243  return ;
244 
245 }
246 
253 bool ProSHADE_internal_misc::sortSymHlp ( const proshade_double* a, const proshade_double* b )
254 {
255  //================================================ Compare
256  return ( a[5] < b[5] );
257 
258 }
259 
266 bool ProSHADE_internal_misc::sortSymHlpInv ( const proshade_double* a, const proshade_double* b )
267 {
268  //================================================ Compare
269  return ( a[5] > b[5] );
270 
271 }
272 
279 bool ProSHADE_internal_misc::sortISymByPeak ( const std::vector< proshade_double* > a, const std::vector< proshade_double* > b )
280 {
281  //================================================ If one is less or more than 31, it is wrong
282  if ( a.size() != 31 ) { return ( false ); }
283  if ( b.size() != 31 ) { return ( true ); }
284 
285  //================================================ Find the sums
286  proshade_double aSum = 0.0, bSum = 0.0;
287  for ( size_t it = 0; it < 31; it++ )
288  {
289  aSum += a.at(it)[5];
290  bSum += b.at(it)[5];
291  }
292 
293  //================================================ Decide
294  return ( aSum > bSum );
295 
296 }
297 
304 bool ProSHADE_internal_misc::sortDSymHlpInv ( const proshade_double* a, const proshade_double* b )
305 {
306  //================================================ Get weighted averages
307  proshade_double aScore = ( ( a[0] * a[5] ) + ( a[6] * a[11] ) ) / ( a[0] + a[6] );
308  proshade_double bScore = ( ( b[0] * b[5] ) + ( b[6] * b[11] ) ) / ( b[0] + b[6] );
309 
310  //================================================ Compare
311  return ( aScore > bScore );
312 
313 }
314 
321 bool ProSHADE_internal_misc::sortSymInvFoldHlp ( const proshade_double* a, const proshade_double* b )
322 {
323  //================================================ Compare
324  return ( a[0] > b[0] );
325 
326 }
327 
335 void ProSHADE_internal_misc::deepCopyAxisToDblPtrVector ( std::vector< proshade_double* >* dblPtrVec, proshade_double* axis )
336 {
337  //================================================ Allocate new memory
338  proshade_double* symAx = new proshade_double[7];
339 
340  //================================================ Check memory allocation
341  ProSHADE_internal_misc::checkMemoryAllocation ( symAx, __FILE__, __LINE__, __func__ );
342 
343  //================================================ Copy the 6 values
344  symAx[0] = axis[0];
345  symAx[1] = axis[1];
346  symAx[2] = axis[2];
347  symAx[3] = axis[3];
348  symAx[4] = axis[4];
349  symAx[5] = axis[5];
350  symAx[6] = axis[6];
351 
352  //================================================ Save
353  ProSHADE_internal_misc::addToDblPtrVector ( dblPtrVec, symAx );
354 
355  //================================================ Done
356  return ;
357 
358 }
359 
372 void ProSHADE_internal_misc::deepCopyBoundsSigPtrVector ( std::vector < proshade_signed* >* sigPtrVec, proshade_signed* xFrom, proshade_signed* xTo, proshade_signed* yFrom, proshade_signed* yTo, proshade_signed* zFrom, proshade_signed* zTo )
373 {
374  //================================================ Allocate new memory
375  proshade_signed* bounds = nullptr;
376  bounds = new proshade_signed[6];
377 
378  //================================================ Check memory allocation
379  ProSHADE_internal_misc::checkMemoryAllocation ( bounds, __FILE__, __LINE__, __func__ );
380 
381  //================================================ Copy the 6 values
382  bounds[0] = *xFrom;
383  bounds[1] = *xTo;
384  bounds[2] = *yFrom;
385  bounds[3] = *yTo;
386  bounds[4] = *zFrom;
387  bounds[5] = *zTo;
388 
389  //================================================ Save
390  ProSHADE_internal_misc::addToSigPtrVector ( sigPtrVec, bounds );
391 
392  //================================================ Done
393  return ;
394 
395 }
ProSHADE_internal_misc::sortSymInvFoldHlp
bool sortSymInvFoldHlp(const proshade_double *a, const proshade_double *b)
This function compares two arrays of two based on the first number, sorting highest first.
Definition: ProSHADE_misc.cpp:321
ProSHADE_internal_misc::addToDblPtrVector
void addToDblPtrVector(std::vector< proshade_double * > *vecToAddTo, proshade_double *elementToAdd)
Adds the element to the vector.
Definition: ProSHADE_misc.cpp:143
ProSHADE_internal_misc::sortSymHlp
bool sortSymHlp(const proshade_double *a, const proshade_double *b)
This function compares two arrays of two based on the fifth number, sorting lowest first.
Definition: ProSHADE_misc.cpp:253
ProSHADE_internal_misc::addToUnsignVectorVector
void addToUnsignVectorVector(std::vector< std::vector< proshade_unsign > > *vecToAddTo, std::vector< proshade_unsign > elementToAdd)
Adds the element to the vector of vectors.
Definition: ProSHADE_misc.cpp:211
ProSHADE_misc.hpp
This header file declares all miscellaneous functions.
ProSHADE_internal_misc::addToDoubleVector
void addToDoubleVector(std::vector< proshade_double > *vecToAddTo, proshade_double elementToAdd)
Adds the element to the vector.
Definition: ProSHADE_misc.cpp:77
ProSHADE_internal_misc::addToSigPtrVector
void addToSigPtrVector(std::vector< proshade_signed * > *vecToAddTo, proshade_signed *elementToAdd)
Adds the element to the vector.
Definition: ProSHADE_misc.cpp:166
ProSHADE_internal_misc::addToSignedVector
void addToSignedVector(std::vector< proshade_signed > *vecToAddTo, proshade_signed elementToAdd)
Adds the element to the vector.
Definition: ProSHADE_misc.cpp:121
ProSHADE_internal_misc::sortDSymHlpInv
bool sortDSymHlpInv(const proshade_double *a, const proshade_double *b)
This function compares two arrays of the ProSHADE dihedral symmetry list based on combination of axes...
Definition: ProSHADE_misc.cpp:304
ProSHADE_internal_misc::deepCopyAxisToDblPtrVector
void deepCopyAxisToDblPtrVector(std::vector< proshade_double * > *dblPtrVec, proshade_double *axis)
Does a deep copy of a double array to a vector of double arrays.
Definition: ProSHADE_misc.cpp:335
ProSHADE_internal_misc::sortISymByPeak
bool sortISymByPeak(const std::vector< proshade_double * > a, const std::vector< proshade_double * > b)
This function compares two vectors of arrays based on the sum of the fifth column,...
Definition: ProSHADE_misc.cpp:279
ProSHADE_internal_misc::checkMemoryAllocation
void checkMemoryAllocation(chVar checkVar, std::string fileP, unsigned int lineP, std::string funcP, std::string infoP="This error may occurs when ProSHADE requests memory to be\n : allocated to it and this operation fails. This could\n : happen when not enough memory is available, either due to\n : other processes using a lot of memory, or when the machine\n : does not have sufficient memory available. Re-run to see\n : if this problem persists.")
Checks if memory was allocated properly.
Definition: ProSHADE_misc.hpp:68
ProSHADE_internal_misc::addToDoubleVectorVector
void addToDoubleVectorVector(std::vector< std::vector< proshade_double > > *vecToAddTo, std::vector< proshade_double > elementToAdd)
Adds the element to the vector of vectors.
Definition: ProSHADE_misc.cpp:233
ProSHADE_internal_misc::addToUnsignVector
void addToUnsignVector(std::vector< proshade_unsign > *vecToAddTo, proshade_unsign elementToAdd)
Adds the element to the vector.
Definition: ProSHADE_misc.cpp:99
ProSHADE_internal_misc::addToSingleVector
void addToSingleVector(std::vector< proshade_single > *vecToAddTo, proshade_single elementToAdd)
Adds the element to the vector.
Definition: ProSHADE_misc.cpp:55
ProSHADE_internal_misc::addToUnsPtrVector
void addToUnsPtrVector(std::vector< proshade_unsign * > *vecToAddTo, proshade_unsign *elementToAdd)
Adds the element to the vector.
Definition: ProSHADE_misc.cpp:189
ProSHADE_internal_misc::sortSymHlpInv
bool sortSymHlpInv(const proshade_double *a, const proshade_double *b)
This function compares two arrays of two based on the fifth number, sorting highest first.
Definition: ProSHADE_misc.cpp:266
ProSHADE_internal_misc::addToStringVector
void addToStringVector(std::vector< std::string > *vecToAddTo, std::string elementToAdd)
Adds the element to the vector.
Definition: ProSHADE_misc.cpp:33
ProSHADE_internal_misc::deepCopyBoundsSigPtrVector
void deepCopyBoundsSigPtrVector(std::vector< proshade_signed * > *sigPtrVec, proshade_signed *xFrom, proshade_signed *xTo, proshade_signed *yFrom, proshade_signed *yTo, proshade_signed *zFrom, proshade_signed *zTo)
Does a deep copy of a signed int array to a vector of signed int arrays.
Definition: ProSHADE_misc.cpp:372