ProSHADE  0.7.5.1 (JAN 2021)
Protein Shape Detection
ProSHADE_wignerMatrices.cpp
Go to the documentation of this file.
1 
22 //==================================================== ProSHADE
24 
30 {
31  //================================================ Sanity check
32  if ( this->maxCompBand == 0 )
33  {
34  throw ProSHADE_exception ( "Attempted allocating Wigner D matrices before\n : allocating E matrices memory.", "EW00024", __FILE__, __LINE__, __func__, "The E matrices and Wigner matrices both require to know\n : the bandwidth of the comparison (which may differ from the\n : object bandwidth). This is set when allocating E matrices\n : and therefore if it is 0 now, E matrices were not yet\n : allocated." );
35  }
36 
37  //================================================ Allocate bands
38  this->wignerMatrices = new proshade_complex** [this->maxCompBand];
39  ProSHADE_internal_misc::checkMemoryAllocation ( this->wignerMatrices, __FILE__, __LINE__, __func__ );
40 
41  //================================================ Allocate the arrays
42  for ( proshade_unsign bandIter = 0; bandIter < this->maxCompBand; bandIter++ )
43  {
44  //============================================ Allocate order 1
45  this->wignerMatrices[bandIter] = new proshade_complex* [(bandIter * 2) + 1];
46  ProSHADE_internal_misc::checkMemoryAllocation ( this->wignerMatrices[bandIter], __FILE__, __LINE__, __func__ );
47 
48  //============================================ Allocate order 2
49  for ( proshade_unsign order1Iter = 0; order1Iter < ( (bandIter * 2) + 1 ); order1Iter++ )
50  {
51  this->wignerMatrices[bandIter][order1Iter] = new proshade_complex [(bandIter * 2) + 1];
52  ProSHADE_internal_misc::checkMemoryAllocation ( this->wignerMatrices[bandIter], __FILE__, __LINE__, __func__ );
53  }
54  }
55 
56  //================================================ Done
57  return ;
58 
59 }
60 
77 void ProSHADE_internal_wigner::allocateWignerWorkspace ( proshade_double*& matIn, proshade_double*& matOut, proshade_double*& sqrts, proshade_double*& workspace, proshade_double*& alphaExponentReal, proshade_double*& alphaExponentImag, proshade_double*& gammaExponentReal, proshade_double*& gammaExponentImag, proshade_double*& trigs, proshade_unsign compBand )
78 {
79  //================================================ Allocate the memory
80  matIn = new proshade_double[static_cast<proshade_unsign> ( 4 * pow( compBand, 2.0 ) - 4 * compBand + 1 )];
81 
82  matOut = new proshade_double[static_cast<proshade_unsign> ( 4 * pow( compBand, 2.0 ) - 4 * compBand + 1 )];
83  sqrts = new proshade_double[static_cast<proshade_unsign> ( 2 * compBand )];
84  workspace = new proshade_double[static_cast<proshade_unsign> ( 4 * pow( compBand, 2.0 ) )];
85  alphaExponentReal = new proshade_double[static_cast<proshade_unsign> ( 2 * compBand - 1 )];
86  alphaExponentImag = new proshade_double[static_cast<proshade_unsign> ( 2 * compBand - 1 )];
87  gammaExponentReal = new proshade_double[static_cast<proshade_unsign> ( 2 * compBand - 1 )];
88  gammaExponentImag = new proshade_double[static_cast<proshade_unsign> ( 2 * compBand - 1 )];
89  trigs = new proshade_double[2];
90 
91  //================================================ Check memory allocation
92  ProSHADE_internal_misc::checkMemoryAllocation ( matIn, __FILE__, __LINE__, __func__ );
93  ProSHADE_internal_misc::checkMemoryAllocation ( matOut, __FILE__, __LINE__, __func__ );
94  ProSHADE_internal_misc::checkMemoryAllocation ( sqrts, __FILE__, __LINE__, __func__ );
95  ProSHADE_internal_misc::checkMemoryAllocation ( workspace, __FILE__, __LINE__, __func__ );
96  ProSHADE_internal_misc::checkMemoryAllocation ( alphaExponentReal, __FILE__, __LINE__, __func__ );
97  ProSHADE_internal_misc::checkMemoryAllocation ( alphaExponentImag, __FILE__, __LINE__, __func__ );
98  ProSHADE_internal_misc::checkMemoryAllocation ( gammaExponentReal, __FILE__, __LINE__, __func__ );
99  ProSHADE_internal_misc::checkMemoryAllocation ( gammaExponentImag, __FILE__, __LINE__, __func__ );
100  ProSHADE_internal_misc::checkMemoryAllocation ( trigs, __FILE__, __LINE__, __func__ );
101 
102  //================================================ Done
103  return ;
104 
105 }
106 
118 void ProSHADE_internal_wigner::releaseWignerWorkspace ( proshade_double*& matIn, proshade_double*& matOut, proshade_double*& sqrts, proshade_double*& workspace, proshade_double*& alphaExponentReal, proshade_double*& alphaExponentImag, proshade_double*& gammaExponentReal, proshade_double*& gammaExponentImag, proshade_double*& trigs )
119 {
120  //================================================ Allocate the memory
121  if ( matIn != NULL ) { delete[] matIn; }
122  if ( matOut != NULL ) { delete[] matOut; }
123  if ( sqrts != NULL ) { delete[] sqrts; }
124  if ( workspace != NULL ) { delete[] workspace; }
125  if ( trigs != NULL ) { delete[] trigs; }
126  if ( alphaExponentReal != NULL ) { delete[] alphaExponentReal; }
127  if ( alphaExponentImag != NULL ) { delete[] alphaExponentImag; }
128  if ( gammaExponentReal != NULL ) { delete[] gammaExponentReal; }
129  if ( gammaExponentImag != NULL ) { delete[] gammaExponentImag; }
130 
131  //================================================ Done
132  return ;
133 
134 }
135 
149 void ProSHADE_internal_wigner::prepareTrigsSqrtsAndExponents ( proshade_double* sqrts, proshade_double* alphaExponentReal, proshade_double* alphaExponentImag, proshade_double* gammaExponentReal, proshade_double* gammaExponentImag, proshade_double* trigs, proshade_unsign compBand, proshade_double angAlpha, proshade_double angBeta, proshade_double angGamma )
150 {
151  //================================================ Compute the square roots
152  for ( proshade_unsign iter = 0; iter < ( 2 * compBand ); iter++ )
153  {
154  sqrts[iter] = static_cast<proshade_double> ( sqrt ( static_cast<proshade_double> ( iter ) ) );
155  }
156 
157  //================================================ Compute the trig values
158  trigs[0] = static_cast<proshade_double> ( cos ( 0.5 * -angBeta ) );
159  trigs[1] = static_cast<proshade_double> ( sin ( 0.5 * -angBeta ) );
160 
161  //================================================ Get alpha and gamma exponents
162  genExp ( compBand, angAlpha, alphaExponentReal, alphaExponentImag );
163  genExp ( compBand, angGamma, gammaExponentReal, gammaExponentImag );
164 
165  //================================================ Done
166  return ;
167 
168 }
169 
189 void ProSHADE_internal_wigner::computeWignerMatrices ( ProSHADE_settings* settings, ProSHADE_internal_data::ProSHADE_data* obj, proshade_double* alphaExponentReal, proshade_double* alphaExponentImag, proshade_double* gammaExponentReal, proshade_double* gammaExponentImag, proshade_double* matIn, proshade_double* matOut, proshade_double* trigs, proshade_double* sqrts, proshade_double* workspace )
190 {
191  //================================================ Report progress
192  ProSHADE_internal_messages::printProgressMessage ( settings->verbose, 2, "Start Wigner D matrix computation." );
193 
194  //================================================ For each band, find the Wigned d matrix
195  proshade_double *expARStart, *expAIStart, *expGRStart, *expGIStart;
196  proshade_double Dij, eARi, eAIi, eGRj, eGIj, iSign, rSign;
197  proshade_complex hlpVal;
198  proshade_unsign noOrders, arrConvIter;
199  for ( proshade_unsign bandIter = 0; bandIter < obj->getComparisonBand(); bandIter++ )
200  {
201  //============================================ Initialise loop
202  noOrders = 2 * bandIter + 1;
203  arrConvIter = 0;
204  expARStart = &alphaExponentReal[ (obj->getComparisonBand() - 1) - bandIter ];
205  expAIStart = &alphaExponentImag[ (obj->getComparisonBand() - 1) - bandIter ];
206  expGRStart = &gammaExponentReal[ (obj->getComparisonBand() - 1) - bandIter ];
207  expGIStart = &gammaExponentImag[ (obj->getComparisonBand() - 1) - bandIter ];
208  iSign = 1.0;
209  rSign = 1.0;
210 
211  //============================================ Get wigner d matrix values using beta angles only
212  wignerdmat ( bandIter, matIn, matOut, trigs, sqrts, workspace );
213 
214  //============================================ Multiply the wigner d matrix by alpha and gamma values and save the wigner D matrix to output array
215  for ( proshade_unsign d1Iter = 0; d1Iter < noOrders; d1Iter++ )
216  {
217  eARi = expARStart[d1Iter];
218  eAIi = expAIStart[d1Iter];
219 
220  for ( proshade_unsign d2Iter = 0; d2Iter < noOrders; d2Iter++ )
221  {
222  Dij = matOut[arrConvIter];
223  eGRj = expGRStart[d2Iter];
224  eGIj = expGIStart[d2Iter];
225 
226  hlpVal[0] = ( Dij * eGRj * eARi - Dij * eGIj * eAIi ) * rSign;
227  hlpVal[1] = ( Dij * eGRj * eAIi + Dij * eGIj * eARi ) * iSign;
228  obj->setWignerMatrixValue ( hlpVal, bandIter, d1Iter, d2Iter );
229 
230  arrConvIter += 1;
231  iSign *= -1.0;
232  rSign *= -1.0;
233  }
234  }
235 
236  //============================================ Get ready for next wigner matrix calculation
237  memcpy ( matIn, matOut, sizeof ( proshade_double ) * ( noOrders * noOrders ) );
238  }
239 
240  //================================================ Report progress
241  ProSHADE_internal_messages::printProgressMessage ( settings->verbose, 3, "Wigner D matrices obtained." );
242 
243  //================================================ Done
244  return ;
245 
246 }
247 
260 void ProSHADE_internal_wigner::computeWignerMatricesForRotation ( ProSHADE_settings* settings, ProSHADE_internal_data::ProSHADE_data* obj, proshade_double eulerAlpha, proshade_double eulerBeta, proshade_double eulerGamma )
261 {
262  //================================================ Initialise local variables
263  proshade_double *matIn, *matOut, *sqrts, *workspace, *alphaExponentReal, *alphaExponentImag, *gammaExponentReal, *gammaExponentImag, *trigs;
264 
265  //================================================ Allocate memory for Wigner matrices
266  obj->allocateWignerMatricesSpace ( settings );
267 
268  //================================================ Allocate the workspace memory
269  allocateWignerWorkspace ( matIn, matOut, sqrts, workspace, alphaExponentReal, alphaExponentImag,
270  gammaExponentReal, gammaExponentImag, trigs, obj->getComparisonBand() );
271 
272  //================================================ Prepare all values for the computation
273  prepareTrigsSqrtsAndExponents ( sqrts, alphaExponentReal, alphaExponentImag, gammaExponentReal, gammaExponentImag,
274  trigs, obj->getComparisonBand(), eulerAlpha, eulerBeta, eulerGamma );
275 
276  //================================================ Compute the values
277  computeWignerMatrices ( settings, obj, alphaExponentReal, alphaExponentImag, gammaExponentReal, gammaExponentImag,
278  matIn, matOut, trigs, sqrts, workspace );
279 
280  //================================================ Release the workspace memory
281  releaseWignerWorkspace ( matIn, matOut, sqrts, workspace, alphaExponentReal, alphaExponentImag,
282  gammaExponentReal, gammaExponentImag, trigs );
283 
284  //================================================ Done
285  return ;
286 
287 }
ProSHADE_internal_wigner::prepareTrigsSqrtsAndExponents
void prepareTrigsSqrtsAndExponents(proshade_double *sqrts, proshade_double *alphaExponentReal, proshade_double *alphaExponentImag, proshade_double *gammaExponentReal, proshade_double *gammaExponentImag, proshade_double *trigs, proshade_unsign compBand, proshade_double angAlpha, proshade_double angBeta, proshade_double angGamma)
This function sets all the values repeatedly required for the computation.
Definition: ProSHADE_wignerMatrices.cpp:149
ProSHADE_internal_data::ProSHADE_data::getComparisonBand
proshade_unsign getComparisonBand(void)
This function allows access to the maximum band for the comparison.
Definition: ProSHADE_data.cpp:3235
ProSHADE_exception
This class is the representation of ProSHADE exception.
Definition: ProSHADE_exceptions.hpp:37
ProSHADE_internal_data::ProSHADE_data::setWignerMatrixValue
void setWignerMatrixValue(proshade_complex val, proshade_unsign band, proshade_unsign order1, proshade_unsign order2)
This function allows setting the Wigner D matrix value by its band, order1 and order2 co-ordinate.
Definition: ProSHADE_data.cpp:3518
ProSHADE_internal_wigner::releaseWignerWorkspace
void releaseWignerWorkspace(proshade_double *&matIn, proshade_double *&matOut, proshade_double *&sqrts, proshade_double *&workspace, proshade_double *&alphaExponentReal, proshade_double *&alphaExponentImag, proshade_double *&gammaExponentReal, proshade_double *&gammaExponentImag, proshade_double *&trigs)
This function releases the memory for the Wigner matrices computation.
Definition: ProSHADE_wignerMatrices.cpp:118
ProSHADE_internal_data::ProSHADE_data
This class contains all inputed and derived data for a single structure.
Definition: ProSHADE_data.hpp:49
ProSHADE_internal_wigner::computeWignerMatrices
void computeWignerMatrices(ProSHADE_settings *settings, ProSHADE_internal_data::ProSHADE_data *obj, proshade_double *alphaExponentReal, proshade_double *alphaExponentImag, proshade_double *gammaExponentReal, proshade_double *gammaExponentImag, proshade_double *matIn, proshade_double *matOut, proshade_double *trigs, proshade_double *sqrts, proshade_double *workspace)
This function does the actual computation of the Wigner D matrices.
Definition: ProSHADE_wignerMatrices.cpp:189
ProSHADE_settings::verbose
proshade_signed verbose
Should the software report on the progress, or just be quiet? Value between -1 (nothing) and 4 (loud)
Definition: ProSHADE_settings.hpp:185
ProSHADE_internal_wigner::computeWignerMatricesForRotation
void computeWignerMatricesForRotation(ProSHADE_settings *settings, ProSHADE_internal_data::ProSHADE_data *obj, proshade_double eulerAlpha, proshade_double eulerBeta, proshade_double eulerGamma)
This function computes the Wigner D matrices for a particular set of Euler angles.
Definition: ProSHADE_wignerMatrices.cpp:260
ProSHADE_internal_data::ProSHADE_data::maxCompBand
proshade_unsign maxCompBand
The largest comparison band - this variable tells how large arrays will be allocated for the comparis...
Definition: ProSHADE_data.hpp:132
ProSHADE_settings
This class stores all the settings and is passed to the executive classes instead of a multitude of p...
Definition: ProSHADE_settings.hpp:86
ProSHADE_internal_data::ProSHADE_data::wignerMatrices
proshade_complex *** wignerMatrices
These matrices are computed for a particular rotation to be done in spherical harmonics.
Definition: ProSHADE_data.hpp:131
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:65
ProSHADE_internal_wigner::allocateWignerWorkspace
void allocateWignerWorkspace(proshade_double *&matIn, proshade_double *&matOut, proshade_double *&sqrts, proshade_double *&workspace, proshade_double *&alphaExponentReal, proshade_double *&alphaExponentImag, proshade_double *&gammaExponentReal, proshade_double *&gammaExponentImag, proshade_double *&trigs, proshade_unsign compBand)
This function allocates the memory for the Wigner matrices computation.
Definition: ProSHADE_wignerMatrices.cpp:77
ProSHADE_wignerMatrices.hpp
This header declares the functions required to compute the Wigner D matrices.
ProSHADE_internal_data::ProSHADE_data::allocateWignerMatricesSpace
void allocateWignerMatricesSpace(ProSHADE_settings *settings)
This function allocates the memory for the Wigner matrices for the calling object.
Definition: ProSHADE_wignerMatrices.cpp:29
ProSHADE_internal_messages::printProgressMessage
void printProgressMessage(proshade_signed verbose, proshade_signed messageLevel, std::string message)
General stdout message printing.
Definition: ProSHADE_messages.cpp:70