Xmipp  v3.23.11-Nereus
angular_sph_alignment.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Carlos Oscar Sanchez Sorzano (coss@cnb.csic.es)
4  * David Herreros Calero (dherreros@cnb.csic.es)
5  *
6  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21  * 02111-1307 USA
22  *
23  * All comments concerning this program package may be sent to the
24  * e-mail address 'xmipp@cnb.csic.es'
25  ***************************************************************************/
26 
27 #include "angular_sph_alignment.h"
28 #include "core/transformations.h"
31 #include "data/projection.h"
32 #include "data/mask.h"
33 
34 // Empty constructor =======================================================
36 {
37  resume = false;
38  produces_a_metadata = true;
40  showOptimization = false;
41 }
42 
44 
45 // Read arguments ==========================================================
47 {
49  fnVolR = getParam("--ref");
50  fnMaskR = getParam("--mask");
51  fnOutDir = getParam("--odir");
52  maxShift = getDoubleParam("--max_shift");
53  maxAngularChange = getDoubleParam("--max_angular_change");
54  maxResol = getDoubleParam("--max_resolution");
55  Ts = getDoubleParam("--sampling");
56  Rmax = getIntParam("--Rmax");
57  RmaxDef = getIntParam("--RDef");
58  optimizeAlignment = checkParam("--optimizeAlignment");
59  optimizeDeformation = checkParam("--optimizeDeformation");
60  optimizeDefocus = checkParam("--optimizeDefocus");
61  phaseFlipped = checkParam("--phaseFlipped");
62  L1 = getIntParam("--l1");
63  L2 = getIntParam("--l2");
64  lambda = getDoubleParam("--regularization");
65  resume = checkParam("--resume");
66  Rerunable::setFileName(fnOutDir + "/sphDone.xmd");
67 }
68 
69 // Show ====================================================================
71 {
72  if (!verbose)
73  return;
75  std::cout
76  << "Output directory: " << fnOutDir << std::endl
77  << "Reference volume: " << fnVolR << std::endl
78  << "Reference mask: " << fnMaskR << std::endl
79  << "Max. Shift: " << maxShift << std::endl
80  << "Max. Angular Change: " << maxAngularChange << std::endl
81  << "Max. Resolution: " << maxResol << std::endl
82  << "Sampling: " << Ts << std::endl
83  << "Max. Radius: " << Rmax << std::endl
84  << "Max. Radius Deform. " << RmaxDef << std::endl
85  << "Zernike Degree: " << L1 << std::endl
86  << "SH Degree: " << L2 << std::endl
87  << "Optimize alignment: " << optimizeAlignment << std::endl
88  << "Optimize deformation:" << optimizeDeformation<< std::endl
89  << "Optimize defocus; " << optimizeDefocus << std::endl
90  << "Phase flipped: " << phaseFlipped << std::endl
91  << "Regularization: " << lambda << std::endl
92  ;
93 }
94 
95 // usage ===================================================================
97 {
98  addUsageLine("Make a continuous angular assignment with deformations");
99  defaultComments["-i"].clear();
100  defaultComments["-i"].addComment("Metadata with initial alignment");
101  defaultComments["-o"].clear();
102  defaultComments["-o"].addComment("Metadata with the angular alignment and deformation parameters");
104  addParamsLine(" --ref <volume> : Reference volume");
105  addParamsLine(" [--mask <m=\"\">] : Reference volume mask");
106  addParamsLine(" [--odir <outputDir=\".\">] : Output directory");
107  addParamsLine(" [--max_shift <s=-1>] : Maximum shift allowed in pixels");
108  addParamsLine(" [--max_angular_change <a=5>] : Maximum angular change allowed (in degrees)");
109  addParamsLine(" [--max_resolution <f=4>] : Maximum resolution (A)");
110  addParamsLine(" [--sampling <Ts=1>] : Sampling rate (A/pixel)");
111  addParamsLine(" [--Rmax <R=-1>] : Maximum radius (px). -1=Half of volume size");
112  addParamsLine(" [--RDef <r=-1>] : Maximum radius of the deformation (px). -1=Half of volume size");
113  addParamsLine(" [--l1 <l1=3>] : Degree Zernike Polynomials=1,2,3,...");
114  addParamsLine(" [--l2 <l2=2>] : Harmonical depth of the deformation=1,2,3,...");
115  addParamsLine(" [--optimizeAlignment] : Optimize alignment");
116  addParamsLine(" [--optimizeDeformation] : Optimize deformation");
117  addParamsLine(" [--optimizeDefocus] : Optimize defocus");
118  addParamsLine(" [--phaseFlipped] : Input images have been phase flipped");
119  addParamsLine(" [--regularization <l=0.01>] : Regularization weight");
120  addParamsLine(" [--resume] : Resume processing");
121  addExampleLine("A typical use is:",false);
122  addExampleLine("xmipp_angular_sph_alignment -i anglesFromContinuousAssignment.xmd --ref reference.vol -o assigned_anglesAndDeformations.xmd --optimizeAlignment --optimizeDeformation --depth 1");
123 }
124 
126 {
127  V.read(fnVolR);
128  V().setXmippOrigin();
129  Xdim=XSIZE(V());
130  Vdeformed().initZeros(V());
131 
132  Ifilteredp().initZeros(Xdim,Xdim);
133  Ifilteredp().setXmippOrigin();
134 
135  if (RmaxDef<0)
136  RmaxDef = Xdim/2;
137 
138  // Read Reference mask if avalaible (otherwise sphere of radius RmaxDef is used)
139  Mask mask;
140  mask.type = BINARY_CIRCULAR_MASK;
141  mask.mode = INNER_MASK;
142  if (fnMaskR != "") {
143  Image<double> aux;
144  aux.read(fnMaskR);
145  typeCast(aux(), V_mask);
147  }
148  else {
149  mask.R1 = RmaxDef;
150  mask.generate_mask(V());
151  V_mask = mask.get_binary_mask();
153  }
154 
155  // Total Volume Mass (Inside Mask)
156  sumV = 0.0;
158  if (DIRECT_MULTIDIM_ELEM(V_mask,n) == 1) {
160  }
161  }
162 
163  // Construct mask
164  if (Rmax<0)
165  Rmax=Xdim/2;
166  mask.R1 = Rmax;
167  mask.generate_mask(Xdim,Xdim);
168  mask2D=mask.get_binary_mask();
169 
170  // Low pass filter
173  filter.raised_w=0.02;
174 
175  // Transformation matrix
176  A.initIdentity(3);
177 
178  // CTF Filter
180  FilterCTF.ctf.enable_CTFnoise = false;
182 
183  vecSize = 0;
186 
187  createWorkFiles();
188 }
189 
192  rename(Rerunable::getFileName().c_str(), fn_out.c_str());
193 }
194 
195 // #define DEBUG
196 double ProgAngularSphAlignment::tranformImageSph(double *pclnm, double rot, double tilt, double psi,
197  double deltaDefocusU, double deltaDefocusV, double deltaDefocusAngle)
198 {
199  const MultidimArray<double> &mV=V();
201  VEC_ELEM(clnm,i)=pclnm[i+1];
202  double deformation=0.0;
203  totalDeformation=0.0;
204  P().initZeros((int)XSIZE(I()),(int)XSIZE(I()));
205  P().setXmippOrigin();
206  deformVol(P(), mV, deformation, rot, tilt, psi);
207  if (hasCTF) {
208  applyCTFImage(deltaDefocusU, deltaDefocusV, deltaDefocusAngle);
209  }
210  double cost=0;
211  if (old_flip)
212  {
213  MAT_ELEM(A,0,0)*=-1;
214  MAT_ELEM(A,0,1)*=-1;
215  MAT_ELEM(A,0,2)*=-1;
216  }
217 
218  applyGeometry(xmipp_transformation::LINEAR,Ifilteredp(),Ifiltered(),A,xmipp_transformation::IS_NOT_INV,xmipp_transformation::DONT_WRAP,0.);
220  const MultidimArray<double> mP=P();
221  const MultidimArray<int> &mMask2D=mask2D;
222  MultidimArray<double> &mIfilteredp=Ifilteredp();
223  double corr=correlationIndex(mIfilteredp,mP,&mMask2D);
224  cost=-corr;
225 
226 #ifdef DEBUG
227  std::cout << "A=" << A << std::endl;
228  Image<double> save;
229  save()=P();
230  save.write("PPPtheo.xmp");
231  save()=Ifilteredp();
232  save.write("PPPfilteredp.xmp");
233  save()=Ifiltered();
234  save.write("PPPfiltered.xmp");
235  // Vdeformed.write("PPPVdeformed.vol");
236  std::cout << "Cost=" << cost << " deformation=" << deformation << std::endl;
237  std::cout << "Press any key" << std::endl;
238  char c; std::cin >> c;
239 #endif
240 
241  if (showOptimization)
242  {
243  std::cout << "A=" << A << std::endl;
244  Image<double> save(P);
245  save.write("PPPtheo.xmp");
246  save()=Ifilteredp();
247  save.write("PPPfilteredp.xmp");
248  save()=Ifiltered();
249  save.write("PPPfiltered.xmp");
250  std::cout << "Cost=" << cost << " corr=" << corr << std::endl;
251  std::cout << "Deformation=" << totalDeformation << std::endl;
252  std::cout << "Press any key" << std::endl;
253  char c; std::cin >> c;
254  }
255 
256  double massDiff=std::abs(sumV-sumVd)/sumV;
257  double retval=cost+lambda*(deformation + massDiff);
258  if (showOptimization)
259  std::cout << cost << " " << deformation << " " << lambda*deformation << " " << sumV << " " << sumVd << " " << massDiff << " " << retval << std::endl;
260  return retval;
261 }
262 
263 double continuousSphCost(double *x, void *_prm)
264 {
265  auto *prm=(ProgAngularSphAlignment *)_prm;
266  int idx = 3*(prm->vecSize);
267  double deltax=x[idx+1];
268  double deltay=x[idx+2];
269  double deltaRot=x[idx+3];
270  double deltaTilt=x[idx+4];
271  double deltaPsi=x[idx+5];
272  double deltaDefocusU=x[idx+6];
273  double deltaDefocusV=x[idx+7];
274  double deltaDefocusAngle=x[idx+8];
275  if (prm->maxShift>0 && deltax*deltax+deltay*deltay>prm->maxShift*prm->maxShift)
276  return 1e38;
277  if (prm->maxAngularChange>0 && (fabs(deltaRot)>prm->maxAngularChange || fabs(deltaTilt)>prm->maxAngularChange || fabs(deltaPsi)>prm->maxAngularChange))
278  return 1e38;
279 
280  MAT_ELEM(prm->A,0,2)=prm->old_shiftX+deltax;
281  MAT_ELEM(prm->A,1,2)=prm->old_shiftY+deltay;
282  MAT_ELEM(prm->A,0,0)=1;
283  MAT_ELEM(prm->A,0,1)=0;
284  MAT_ELEM(prm->A,1,0)=0;
285  MAT_ELEM(prm->A,1,1)=1;
286 
287  return prm->tranformImageSph(x,prm->old_rot+deltaRot, prm->old_tilt+deltaTilt, prm->old_psi+deltaPsi,
288  deltaDefocusU, deltaDefocusV, deltaDefocusAngle);
289 }
290 
291 // Predict =================================================================
292 //#define DEBUG
293 void ProgAngularSphAlignment::processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
294 {
296  int totalSize = 3*vecSize+8;
297  p.initZeros(totalSize);
298  clnm.initZeros(totalSize);
299 
300  rowOut=rowIn;
301 
302  flagEnabled=1;
303 
309  if (rowIn.containsLabel(MDL_FLIP))
310  rowIn.getValue(MDL_FLIP,old_flip);
311  else
312  old_flip = false;
313 
315  {
316  hasCTF=true;
317  ctf.readFromMdRow(rowIn);
318  ctf.Tm = Ts;
323  }
324  else
325  hasCTF=false;
326 
327  if (verbose>=2)
328  std::cout << "Processing " << fnImg << std::endl;
329  I.read(fnImg);
330  I().setXmippOrigin();
331 
332  Ifiltered()=I();
334 
335  for (int h=1;h<=L2;h++)
336  {
337  if (verbose>=2)
338  {
339  std::cout<<std::endl;
340  std::cout<<"------------------------------ Basis Degrees: ("<<L1<<","<<h<<") ----------------------------"<<std::endl;
341  }
342  steps.clear();
343  steps.initZeros(totalSize);
344 
345  // Optimize
346  double cost=-1;
347  try
348  {
349  cost=1e38;
350  int iter;
351  if (optimizeAlignment)
352  steps(totalSize-8)=steps(totalSize-7)=steps(totalSize-6)=steps(totalSize-5)=steps(totalSize-4)=1.;
353  if (optimizeDefocus)
354  steps(totalSize-3)=steps(totalSize-2)=steps(totalSize-1)=1.;
356  {
357  minimizepos(h,steps);
358  }
359  steps_cp = steps;
360  powellOptimizer(p, 1, totalSize, &continuousSphCost, this, 0.01, cost, iter, steps, verbose>=2);
361 
362  if (verbose>=3)
363  {
364  showOptimization = true;
366  showOptimization = false;
367  }
368 
369  if (cost>0)
370  {
371  flagEnabled=-1;
372  p.initZeros();
373  }
374  cost=-cost;
375  correlation=cost;
376  if (verbose>=2)
377  {
378  std::cout<<std::endl;
379  for (int j=1;j<4;j++)
380  {
381  switch (j)
382  {
383  case 1:
384  std::cout << "X Coefficients=(";
385  break;
386  case 2:
387  std::cout << "Y Coefficients=(";
388  break;
389  case 3:
390  std::cout << "Z Coefficients=(";
391  break;
392  }
393  for (int i=(j-1)*vecSize;i<j*vecSize;i++)
394  {
395  std::cout << p(i);
396  if (i<j*vecSize-1)
397  std::cout << ",";
398  }
399  std::cout << ")" << std::endl;
400  }
401  std::cout << "Radius=" << RmaxDef << std::endl;
402  std::cout << " Dshift=(" << p(totalSize-5) << "," << p(totalSize-4) << ") "
403  << "Drot=" << p(totalSize-3) << " Dtilt=" << p(totalSize-2)
404  << " Dpsi=" << p(totalSize-1) << std::endl;
405  std::cout << " Total deformation=" << totalDeformation << std::endl;
406  std::cout<<std::endl;
407  }
408  }
409  catch (XmippError &XE)
410  {
411  std::cerr << XE.what() << std::endl;
412  std::cerr << "Warning: Cannot refine " << fnImg << std::endl;
413  flagEnabled=-1;
414  }
415  }
416 
417  //AJ NEW
418  writeImageParameters(fnImg);
419  //END AJ
420 
421 }
422 #undef DEBUG
423 
425  MetaDataVec md;
426  int pos = 3*vecSize;
427  size_t objId = md.addObject();
428  md.setValue(MDL_IMAGE, fnImg, objId);
429  if (flagEnabled==1) {
430  md.setValue(MDL_ENABLED, 1, objId);
431  }
432  else {
433  md.setValue(MDL_ENABLED, -1, objId);
434  }
435  md.setValue(MDL_ANGLE_ROT, old_rot+p(pos+2), objId);
436  md.setValue(MDL_ANGLE_TILT, old_tilt+p(pos+3), objId);
437  md.setValue(MDL_ANGLE_PSI, old_psi+p(pos+4), objId);
438  md.setValue(MDL_SHIFT_X, old_shiftX+p(pos+0), objId);
439  md.setValue(MDL_SHIFT_Y, old_shiftY+p(pos+1), objId);
440  md.setValue(MDL_FLIP, old_flip, objId);
442  std::vector<double> vectortemp;
443  for (int j = 0; j < VEC_XSIZE(clnm); j++) {
444  vectortemp.push_back(clnm(j));
445  }
446  md.setValue(MDL_SPH_COEFFICIENTS, vectortemp, objId);
447  md.setValue(MDL_COST, correlation, objId);
449 }
450 
451 void ProgAngularSphAlignment::numCoefficients(int l1, int l2, int &nc) const
452 {
453  // l1 -> Degree Zernike
454  // l2 & h --> Degree SPH
455  for (int h=0; h<=l2; h++)
456  {
457  // For the current SPH degree (h), determine the number of SPH components/equations
458  int numSPH = 2*h+1;
459  // Finf the total number of radial components with even degree for a given l1 and h
460  int count=l1-h+1;
461  int numEven=(count>>1)+(count&1 && !(h&1));
462  // Total number of components is the number of SPH as many times as Zernike components
463  if (h%2 == 0) {
464  nc += numSPH*numEven;
465  }
466  else {
467  nc += numSPH*(count-numEven);
468  }
469  }
470 }
471 
473 {
474  int size = 0;
475  numCoefficients(L1,l2,size);
476  auto totalSize = (int)((steps.size()-8)/3);
477  for (int idx=0; idx<size; idx++) {
478  VEC_ELEM(steps,idx) = 1.;
479  VEC_ELEM(steps,idx+totalSize) = 1.;
480  VEC_ELEM(steps,idx+2*totalSize) = 1.;
481  }
482 }
483 
485 {
486  int idx = 0;
491  for (int h=0; h<=l2; h++) {
492  int totalSPH = 2*h+1;
493  auto aux = (int)(std::floor(totalSPH/2));
494  for (int l=h; l<=l1; l+=2) {
495  for (int m=0; m<totalSPH; m++) {
496  VEC_ELEM(vL1,idx) = l;
497  VEC_ELEM(vN,idx) = h;
498  VEC_ELEM(vL2,idx) = h;
499  VEC_ELEM(vM,idx) = m-aux;
500  idx++;
501  }
502  }
503  }
504 }
505 
506 void ProgAngularSphAlignment::applyCTFImage(double const &deltaDefocusU, double const &deltaDefocusV,
507  double const &deltaDefocusAngle) {
508  double defocusU=old_defocusU+deltaDefocusU;
509  double defocusV=old_defocusV+deltaDefocusV;
510  double angle=old_defocusAngle+deltaDefocusAngle;
511  if (defocusU!=currentDefocusU || defocusV!=currentDefocusV || angle!=currentAngle) {
512  updateCTFImage(defocusU,defocusV,angle);
513  }
514  FilterCTF.ctf = ctf;
516  if (phaseFlipped)
519 }
520 
521 void ProgAngularSphAlignment::updateCTFImage(double defocusU, double defocusV, double angle)
522 {
523  ctf.K=1; // get pure CTF with no envelope
524  currentDefocusU=ctf.DeltafU=defocusU;
525  currentDefocusV=ctf.DeltafV=defocusV;
528 }
529 
531  double rot, double tilt, double psi)
532 {
533  size_t idxY0=(VEC_XSIZE(clnm)-8)/3;
534  double Ncount=0.0;
535  double modg=0.0;
536  double diff2=0.0;
537 
538  def=0.0;
539  size_t idxZ0=2*idxY0;
540  sumVd=0.0;
541  double RmaxF=RmaxDef;
542  double RmaxF2=RmaxF*RmaxF;
543  double iRmaxF=1.0/RmaxF;
544  // Rotation Matrix
546  R.initIdentity(3);
547  Euler_angles2matrix(rot, tilt, psi, R, false);
548  R = R.inv();
549  Matrix1D<double> pos;
550  pos.initZeros(3);
551 
552  // TODO: Poner primero i y j en el loop, acumular suma y guardar al final
553  for (int k=STARTINGZ(mV); k<=FINISHINGZ(mV); k++)
554  {
555  for (int i=STARTINGY(mV); i<=FINISHINGY(mV); i++)
556  {
557  for (int j=STARTINGX(mV); j<=FINISHINGX(mV); j++)
558  {
559  ZZ(pos) = k; YY(pos) = i; XX(pos) = j;
560  pos = R * pos;
561  double gx=0.0;
562  double gy=0.0;
563  double gz=0.0;
564  // TODO: Sacar al bucle de z
565  double k2=ZZ(pos)*ZZ(pos);
566  double kr=ZZ(pos)*iRmaxF;
567  double k2i2=k2+YY(pos)*YY(pos);
568  double ir=YY(pos)*iRmaxF;
569  double r2=k2i2+XX(pos)*XX(pos);
570  double jr=XX(pos)*iRmaxF;
571  double rr=sqrt(r2)*iRmaxF;
572  if (r2<RmaxF2) {
573  for (size_t idx=0; idx<idxY0; idx++) {
574  if (VEC_ELEM(steps_cp,idx) == 1) {
575  double zsph=0.0;
576  int l1 = VEC_ELEM(vL1,idx);
577  int n = VEC_ELEM(vN,idx);
578  int l2 = VEC_ELEM(vL2,idx);
579  int m = VEC_ELEM(vM,idx);
580  zsph=ZernikeSphericalHarmonics(l1,n,l2,m,jr,ir,kr,rr);
581  if (rr>0 || l2==0) {
582  gx += VEC_ELEM(clnm,idx) *zsph;
583  gy += VEC_ELEM(clnm,idx+idxY0) *zsph;
584  gz += VEC_ELEM(clnm,idx+idxZ0) *zsph;
585  }
586  }
587  }
588  auto k_mask = (int)(ZZ(pos)+gz);
589  auto i_mask = (int)(YY(pos)+gy);
590  auto j_mask = (int)(XX(pos)+gx);
591  int voxelI_mask = 0;
592  if (!V_mask.outside(k_mask, i_mask, j_mask)) {
593  voxelI_mask = A3D_ELEM(V_mask, k_mask, i_mask, j_mask);
594  }
595  if (voxelI_mask == 1) {
596  double voxelI=mV.interpolatedElement3D(XX(pos)+gx,YY(pos)+gy,ZZ(pos)+gz);
597  A2D_ELEM(mP,i,j) += voxelI;
598  sumVd += voxelI;
599  modg += gx*gx+gy*gy+gz*gz;
600  Ncount++;
601  }
602  }
603  }
604  }
605  }
606 
607  def = sqrt(modg/Ncount);
608  totalDeformation = def;
609 }
610 
Rotation angle of an image (double,degrees)
#define A2D_ELEM(v, i, j)
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
Defocus U (Angstroms)
double getDoubleParam(const char *param, int arg=0)
__host__ __device__ float2 floor(const float2 v)
CTFDescription ctf
void clear()
Definition: matrix1d.cpp:67
ProgAngularSphAlignment()
Empty constructor.
#define FINISHINGX(v)
size_t size() const
Definition: matrix1d.h:508
MultidimArray< int > mask2D
#define VEC_XSIZE(m)
Definition: matrix1d.h:77
void Euler_angles2matrix(T alpha, T beta, T gamma, Matrix2D< T > &A, bool homogeneous)
Definition: geometry.cpp:624
doublereal * c
double tranformImageSph(double *pclnm, double rot, double tilt, double psi, double deltaDefocusU, double deltaDefocusV, double deltaDefocusAngle)
Definition: mask.h:360
void sqrt(Image< double > &op)
Tilting angle of an image (double,degrees)
void minimizepos(int l2, Matrix1D< double > &steps) const
Determine the positions to be minimize of a vector containing spherical harmonic coefficients.
double DeltafV
Defocus in V (in Angstroms). Negative values are underfocused.
Definition: ctf.h:830
Shift for the image in the X axis (double)
void applyGeometry(int SplineDegree, MultidimArray< std::complex< double > > &V2, const MultidimArray< std::complex< double > > &V1, const Matrix2D< double > &A, bool inv, bool wrap, std::complex< double > outside, MultidimArray< double > *BcoeffsPtr)
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
double correlationIndex(const MultidimArray< T > &x, const MultidimArray< T > &y, const MultidimArray< int > *mask=NULL, MultidimArray< double > *Contributions=NULL)
virtual void writeImageParameters(const FileName &fnImg)
void inv(Matrix2D< T > &result) const
Definition: matrix2d.cpp:663
Special label to be used when gathering MDs in MpiMetadataPrograms.
void abs(Image< double > &op)
Name for the CTF Model (std::string)
void powellOptimizer(Matrix1D< double > &p, int i0, int n, double(*f)(double *x, void *), void *prm, double ftol, double &fret, int &iter, const Matrix1D< double > &steps, bool show)
void setFileName(const FileName &fn)
#define FINISHINGZ(v)
glob_prnt iter
#define STARTINGX(v)
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
doublereal * x
#define i
Is this image enabled? (int [-1 or 1])
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
double DeltafU
Global gain. By default, 1.
Definition: ctf.h:828
#define STARTINGY(v)
#define MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
#define A3D_ELEM(V, k, i, j)
double azimuthal_angle
Azimuthal angle (between X and U) in degrees.
Definition: ctf.h:832
double continuousSphCost(double *x, void *_prm)
void numCoefficients(int l1, int l2, int &nc) const
Length of coefficients vector.
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
Definition: matrix1d.h:72
const FileName & getFileName() const
T & getValue(MDLabel label)
const char * getParam(const char *param, int arg=0)
#define XX(v)
Definition: matrix1d.h:85
bool setValue(const MDObject &mdValueIn, size_t id)
size_t addObject() override
Deformation in voxels.
#define CTF
Cost for the image (double)
double R1
Definition: mask.h:413
void applyCTFImage(double const &deltaDefocusU, double const &deltaDefocusV, double const &deltaDefocusAngle)
Flip the image? (bool)
void updateCTFImage(double defocusU, double defocusV, double angle)
#define XSIZE(v)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
double Tm
Sampling rate (A/pixel)
Definition: ctf.h:240
int type
Definition: mask.h:402
#define DIRECT_MULTIDIM_ELEM(v, n)
void addExampleLine(const char *example, bool verbatim=true)
T interpolatedElement3D(double x, double y, double z, T outside_value=(T) 0) const
double maxShift
Maximum shift.
void readFromMdRow(const MDRow &row, bool disable_if_not_K=true)
Definition: ctf.cpp:1172
int verbose
Verbosity level.
void initZeros()
Definition: matrix1d.h:592
void readParams()
Read argument from command line.
#define j
FileName fnOutDir
Output directory.
double steps
#define YY(v)
Definition: matrix1d.h:93
int m
double K
Global gain. By default, 1.
Definition: ctf.h:238
#define FINISHINGY(v)
void show() const override
void generate_mask(bool apply_geo=false)
Definition: mask.cpp:1577
virtual bool containsLabel(MDLabel label) const =0
void typeCast(const Matrix1D< T1 > &v1, Matrix1D< T2 > &v2)
Definition: matrix1d.h:1227
bool outside(int k, int i, int j) const
void append(const FileName &outFile) const
#define BINARY_CIRCULAR_MASK
Definition: mask.h:365
double ZernikeSphericalHarmonics(int n, int m, double xr, double yr, double zr, double r)
void produceSideInfo()
Produce Side information.
Definition: ctf.cpp:1392
double psi(const double x)
Deformation coefficients.
MultidimArray< int > V_mask
bool checkParam(const char *param)
void deformVol(MultidimArray< double > &mVD, const MultidimArray< double > &mV, double &def, double rot, double tilt, double psi)
Deform a volumen using Zernike-Spherical harmonic basis.
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
float r2
ProgClassifyCL2D * prm
bool each_image_produces_an_output
Indicate that an output is produced for each image in the input.
Shift for the image in the Y axis (double)
void addUsageLine(const char *line, bool verbatim=false)
~ProgAngularSphAlignment()
Destructor.
bool enable_CTFnoise
Enable CTFnoise part.
Definition: ctf.h:273
const MultidimArray< int > & get_binary_mask() const
Definition: mask.h:707
T * adaptForNumericalRecipes() const
Definition: matrix1d.h:844
int getIntParam(const char *param, int arg=0)
void generateMask(MultidimArray< double > &v)
#define STARTINGZ(v)
int * n
Name of an image (std::string)
#define ZZ(v)
Definition: matrix1d.h:101
bool produces_a_metadata
Indicate that the unique final output file is a Metadata.
#define LOWPASS
void addParamsLine(const String &line)
int ir
void defineParams()
Define parameters.
void initIdentity()
Definition: matrix2d.h:673
int mode
Definition: mask.h:407
void applyMaskSpace(MultidimArray< double > &v)
void fillVectorTerms(int l1, int l2)
Zernike and SPH coefficients allocation.
std::map< String, CommentList > defaultComments
Definition: xmipp_program.h:83
constexpr int INNER_MASK
Definition: mask.h:47