Xmipp  v3.23.11-Nereus
angular_sph_alignment_gpu.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 
28 #include "core/transformations.h"
31 #include "data/projection.h"
32 #include "data/mask.h"
34 #include "data/fourier_filter.h"
35 
36 // TODO: Refactor this code to reuse the CPU version when possible
37 
38 // Empty constructor =======================================================
40 {
41  resume = false;
42  produces_a_metadata = true;
44  showOptimization = false;
45 }
46 
48 
49 // Read arguments ==========================================================
51 {
53  fnVolR = getParam("--ref");
54  fnMaskR = getParam("--mask");
55  fnOutDir = getParam("--odir");
56  Rerunable::setFileName(fnOutDir+"/sphDone.xmd");
57  maxShift = getDoubleParam("--max_shift");
58  maxAngularChange = getDoubleParam("--max_angular_change");
59  maxResol = getDoubleParam("--max_resolution");
60  Ts = getDoubleParam("--sampling");
61  Rmax = getIntParam("--Rmax");
62  RmaxDef = getIntParam("--RDef");
63  optimizeAlignment = checkParam("--optimizeAlignment");
64  optimizeDeformation = checkParam("--optimizeDeformation");
65  optimizeDefocus = checkParam("--optimizeDefocus");
66  phaseFlipped = checkParam("--phaseFlipped");
67  L1 = getIntParam("--l1");
68  L2 = getIntParam("--l2");
69  lambda = getDoubleParam("--regularization");
70  resume = checkParam("--resume");
71  useFakeKernel = checkParam("--useCPU");
72  device = getIntParam("--device");
73 }
74 
75 // Show ====================================================================
77 {
78  if (!verbose)
79  return;
81  std::cout
82  << "Output directory: " << fnOutDir << std::endl
83  << "Reference volume: " << fnVolR << std::endl
84  << "Reference mask: " << fnMaskR << std::endl
85  << "Max. Shift: " << maxShift << std::endl
86  << "Max. Angular Change: " << maxAngularChange << std::endl
87  << "Max. Resolution: " << maxResol << std::endl
88  << "Sampling: " << Ts << std::endl
89  << "Max. Radius: " << Rmax << std::endl
90  << "Max. Radius Deform. " << RmaxDef << std::endl
91  << "Zernike Degree: " << L1 << std::endl
92  << "SH Degree: " << L2 << std::endl
93  << "Optimize alignment: " << optimizeAlignment << std::endl
94  << "Optimize deformation:" << optimizeDeformation<< std::endl
95  << "Optimize defocus; " << optimizeDefocus << std::endl
96  << "Phase flipped: " << phaseFlipped << std::endl
97  << "Regularization: " << lambda << std::endl
98  << "Device: " << device << std::endl
99  ;
100 }
101 
102 // usage ===================================================================
104 {
105  addUsageLine("Make a continuous angular assignment with deformations");
106  defaultComments["-i"].clear();
107  defaultComments["-i"].addComment("Metadata with initial alignment");
108  defaultComments["-o"].clear();
109  defaultComments["-o"].addComment("Metadata with the angular alignment and deformation parameters");
111  addParamsLine(" --ref <volume> : Reference volume");
112  addParamsLine(" [--mask <m=\"\">] : Reference volume mask");
113  addParamsLine(" [--odir <outputDir=\".\">] : Output directory");
114  addParamsLine(" [--max_shift <s=-1>] : Maximum shift allowed in pixels");
115  addParamsLine(" [--max_angular_change <a=5>] : Maximum angular change allowed (in degrees)");
116  addParamsLine(" [--max_resolution <f=4>] : Maximum resolution (A)");
117  addParamsLine(" [--sampling <Ts=1>] : Sampling rate (A/pixel)");
118  addParamsLine(" [--Rmax <R=-1>] : Maximum radius (px). -1=Half of volume size");
119  addParamsLine(" [--RDef <r=-1>] : Maximum radius of the deformation (px). -1=Half of volume size");
120  addParamsLine(" [--l1 <l1=3>] : Degree Zernike Polynomials=1,2,3,...");
121  addParamsLine(" [--l2 <l2=2>] : Harmonical depth of the deformation=1,2,3,...");
122  addParamsLine(" [--optimizeAlignment] : Optimize alignment");
123  addParamsLine(" [--optimizeDeformation] : Optimize deformation");
124  addParamsLine(" [--optimizeDefocus] : Optimize defocus");
125  addParamsLine(" [--phaseFlipped] : Input images have been phase flipped");
126  addParamsLine(" [--regularization <l=0.01>] : Regularization weight");
127  addParamsLine(" [--resume] : Resume processing");
128  addParamsLine(" [--useCPU] : Uses fake kernel (CPU) instead of GPU kernel");
129  addParamsLine(" [--device <dev=0>] : GPU device to use. 0th by default");
130  addExampleLine("A typical use is:",false);
131  addExampleLine("xmipp_cuda_angular_sph_alignment -i anglesFromContinuousAssignment.xmd --ref reference.vol -o assigned_anglesAndDeformations.xmd --optimizeAlignment --optimizeDeformation --depth 1");
132 }
133 
134 // Produce side information ================================================
135 
137 {
138  V.read(fnVolR);
139  V().setXmippOrigin();
140  Xdim=XSIZE(V());
141  Vdeformed().initZeros(V());
142  // sumV=V().sum();
143 
144  Ifilteredp().initZeros(Xdim,Xdim);
145  Ifilteredp().setXmippOrigin();
146 
147  if (RmaxDef<0)
148  RmaxDef = Xdim/2;
149 
150  // Read Reference mask if avalaible (otherwise sphere of radius RmaxDef is used)
151  Mask mask;
152  mask.type = BINARY_CIRCULAR_MASK;
153  mask.mode = INNER_MASK;
154  if (fnMaskR != "") {
155  Image<double> aux;
156  aux.read(fnMaskR);
157  typeCast(aux(), V_mask);
159  }
160  else {
161  mask.R1 = RmaxDef;
162  mask.generate_mask(V());
163  V_mask = mask.get_binary_mask();
165  }
166 
167  // Total Volume Mass (Inside Mask)
168  sumV = 0.0;
170  if (DIRECT_MULTIDIM_ELEM(V_mask,n) == 1) {
172  }
173  }
174 
175  // Construct mask
176  if (Rmax<0)
177  Rmax=Xdim/2;
178  mask.R1 = Rmax;
179  mask.generate_mask(Xdim,Xdim);
180  mask2D=mask.get_binary_mask();
181 
182  // Define pointers
183  filter = std::make_unique<FourierFilter>();
184  FilterCTF = std::make_unique<FourierFilter>();
185  ctf = std::make_unique<CTFDescription>();
186 
187  // Low pass filter
188  std::cout << "Preprocess begins" << std::endl;
189  filter->FilterBand=LOWPASS;
190  filter->w1=Ts/maxResol;
191  filter->raised_w=0.02;
192 
193  // Transformation matrix
194  A.initIdentity(3);
195 
196  // CTF Filter
197  FilterCTF->FilterBand = CTF;
198  FilterCTF->ctf.enable_CTFnoise = false;
199  FilterCTF->ctf.produceSideInfo();
200 
201  vecSize = 0;
204 
205  createWorkFiles();
206 
207  // GPU preparation
209 }
210 
213  rename(Rerunable::getFileName().c_str(), fn_out.c_str());
214 }
215 
216 // #define DEBUG
218  double *pclnm, double rot, double tilt, double psi, Matrix2D<double> &A,
219  double deltaDefocusU, double deltaDefocusV, double deltaDefocusAngle)
220 {
221  const MultidimArray<double> &mV=V();
223  VEC_ELEM(clnm,i)=pclnm[i+1];
224  double deformation=0.0;
225  totalDeformation=0.0;
226  P().initZeros((int)XSIZE(I()),(int)XSIZE(I()));
227  P().setXmippOrigin();
228  deformVol(P(), mV, deformation, rot, tilt, psi);
229  if (hasCTF)
230  {
231  double defocusU=old_defocusU+deltaDefocusU;
232  double defocusV=old_defocusV+deltaDefocusV;
233  double angle=old_defocusAngle+deltaDefocusAngle;
234  if (defocusU!=currentDefocusU || defocusV!=currentDefocusV || angle!=currentAngle) {
235  updateCTFImage(defocusU,defocusV,angle);
236  }
237  FilterCTF->ctf = *ctf;
238  FilterCTF->generateMask(P());
239  if (phaseFlipped)
240  FilterCTF->correctPhase();
241  FilterCTF->applyMaskSpace(P());
242  }
243  double cost=0;
244  if (old_flip)
245  {
246  MAT_ELEM(A,0,0)*=-1;
247  MAT_ELEM(A,0,1)*=-1;
248  MAT_ELEM(A,0,2)*=-1;
249  }
250 
251  applyGeometry(xmipp_transformation::LINEAR,Ifilteredp(),Ifiltered(),A,xmipp_transformation::IS_NOT_INV,xmipp_transformation::DONT_WRAP,0.);
252  filter->applyMaskSpace(P());
253  const MultidimArray<double> &mP=P();
254  const MultidimArray<int> &mMask2D=mask2D;
255  MultidimArray<double> &mIfilteredp=Ifilteredp();
256  double corr=correlationIndex(mIfilteredp,mP,&mMask2D);
257  cost=-corr;
258 
259 #ifdef DEBUG
260  std::cout << "A=" << A << std::endl;
261  Image<double> save;
262  save()=P();
263  save.write("PPPtheo.xmp");
264  save()=Ifilteredp();
265  save.write("PPPfilteredp.xmp");
266  save()=Ifiltered();
267  save.write("PPPfiltered.xmp");
268  // Vdeformed.write("PPPVdeformed.vol");
269  std::cout << "Cost=" << cost << " deformation=" << deformation << std::endl;
270  std::cout << "Press any key" << std::endl;
271  char c; std::cin >> c;
272 #endif
273 
274  if (showOptimization)
275  {
276  std::cout << "A=" << A << std::endl;
277  Image<double> save(P);
278  save.write("PPPtheo.xmp");
279  save()=Ifilteredp();
280  save.write("PPPfilteredp.xmp");
281  save()=Ifiltered();
282  save.write("PPPfiltered.xmp");
283  // Vdeformed.write("PPPVdeformed.vol");
284  std::cout << "Cost=" << cost << " corr=" << corr << std::endl;
285  std::cout << "Deformation=" << totalDeformation << std::endl;
286  std::cout << "Press any key" << std::endl;
287  char c; std::cin >> c;
288  }
289 
290  double massDiff=std::abs(sumV-sumVd)/sumV;
291  double retval=cost+lambda*(deformation + massDiff);
292  if (showOptimization)
293  std::cout << cost << " " << deformation << " " << lambda*deformation << " " << sumV << " " << sumVd << " " << massDiff << " " << retval << std::endl;
294  return retval;
295 }
296 
297 double continuousSphCost(double *x, void *_prm)
298 {
299  auto *prm=(ProgAngularSphAlignmentGpu *)_prm;
300  int idx = 3*(prm->vecSize);
301  double deltax=x[idx+1];
302  double deltay=x[idx+2];
303  double deltaRot=x[idx+3];
304  double deltaTilt=x[idx+4];
305  double deltaPsi=x[idx+5];
306  double deltaDefocusU=x[idx+6];
307  double deltaDefocusV=x[idx+7];
308  double deltaDefocusAngle=x[idx+8];
309  if (prm->maxShift>0 && deltax*deltax+deltay*deltay>prm->maxShift*prm->maxShift)
310  return 1e38;
311  if (prm->maxAngularChange>0 && (fabs(deltaRot)>prm->maxAngularChange || fabs(deltaTilt)>prm->maxAngularChange || fabs(deltaPsi)>prm->maxAngularChange))
312  return 1e38;
313 
314  MAT_ELEM(prm->A,0,2)=prm->old_shiftX+deltax;
315  MAT_ELEM(prm->A,1,2)=prm->old_shiftY+deltay;
316  MAT_ELEM(prm->A,0,0)=1;
317  MAT_ELEM(prm->A,0,1)=0;
318  MAT_ELEM(prm->A,1,0)=0;
319  MAT_ELEM(prm->A,1,1)=1;
320 
321  return prm->tranformImageSph(x,prm->old_rot+deltaRot, prm->old_tilt+deltaTilt, prm->old_psi+deltaPsi,
322  prm->A, deltaDefocusU, deltaDefocusV, deltaDefocusAngle);
323 }
324 
325 // Predict =================================================================
326 //#define DEBUG
327 void ProgAngularSphAlignmentGpu::processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
328 {
330  int totalSize = 3*vecSize+8;
331  p.initZeros(totalSize);
332  clnm.initZeros(totalSize);
333 
334  rowOut=rowIn;
335 
336  flagEnabled=1;
337 
338  // Read input image and initial parameters
339 // ApplyGeoParams geoParams;
340 // geoParams.only_apply_shifts=false;
341 // geoParams.wrap=DONT_WRAP;
342 
348  if (rowIn.containsLabel(MDL_FLIP))
349  rowIn.getValue(MDL_FLIP,old_flip);
350  else
351  old_flip = false;
352 
354  {
355  hasCTF=true;
356  ctf->readFromMdRow(rowIn);
357  ctf->Tm = Ts;
358  ctf->produceSideInfo();
359  old_defocusU=ctf->DeltafU;
360  old_defocusV=ctf->DeltafV;
361  old_defocusAngle=ctf->azimuthal_angle;
362  }
363  else
364  hasCTF=false;
365 
366  if (verbose>=2)
367  std::cout << "Processing " << fnImg << std::endl;
368  I.read(fnImg);
369  I().setXmippOrigin();
370 
371  Ifiltered()=I();
372  filter->applyMaskSpace(Ifiltered());
373 
374  // GPU preparation
376 
377  for (int h=1;h<=L2;h++)
378  {
379  if (verbose>=2)
380  {
381  std::cout<<std::endl;
382  std::cout<<"------------------------------ Basis Degrees: ("<<L1<<","<<h<<") ----------------------------"<<std::endl;
383  }
384  steps.clear();
385  steps.initZeros(totalSize);
386 
387  // Optimize
388  double cost=-1;
389  try
390  {
391  cost=1e38;
392  int iter;
393  if (optimizeAlignment)
394  steps(totalSize-8)=steps(totalSize-7)=steps(totalSize-6)=steps(totalSize-5)=steps(totalSize-4)=1.;
395  if (optimizeDefocus)
396  steps(totalSize-3)=steps(totalSize-2)=steps(totalSize-1)=1.;
398  {
399  minimizepos(L1,h,steps);
400  }
401  steps_cp = steps;
402  powellOptimizer(p, 1, totalSize, &continuousSphCost, this, 0.01, cost, iter, steps, verbose>=2);
403 
404  if (verbose>=3)
405  {
406  showOptimization = true;
408  showOptimization = false;
409  }
410 
411  if (cost>0)
412  {
413  flagEnabled=-1;
414  p.initZeros();
415  }
416  cost=-cost;
417  correlation=cost;
418  if (verbose>=2)
419  {
420  std::cout<<std::endl;
421  for (int j=1;j<4;j++)
422  {
423  switch (j)
424  {
425  case 1:
426  std::cout << "X Coefficients=(";
427  break;
428  case 2:
429  std::cout << "Y Coefficients=(";
430  break;
431  case 3:
432  std::cout << "Z Coefficients=(";
433  break;
434  }
435  for (int i=(j-1)*vecSize;i<j*vecSize;i++)
436  {
437  std::cout << p(i);
438  if (i<j*vecSize-1)
439  std::cout << ",";
440  }
441  std::cout << ")" << std::endl;
442  }
443  std::cout << "Radius=" << RmaxDef << std::endl;
444  std::cout << " Dshift=(" << p(totalSize-5) << "," << p(totalSize-4) << ") "
445  << "Drot=" << p(totalSize-3) << " Dtilt=" << p(totalSize-2)
446  << " Dpsi=" << p(totalSize-1) << std::endl;
447  std::cout << " Total deformation=" << totalDeformation << std::endl;
448  std::cout<<std::endl;
449  }
450  }
451  catch (XmippError &XE)
452  {
453  std::cerr << XE.what() << std::endl;
454  std::cerr << "Warning: Cannot refine " << fnImg << std::endl;
455  flagEnabled=-1;
456  }
457  }
458 
459  //AJ NEW
460  writeImageParameters(fnImg);
461  //END AJ
462 
463 }
464 #undef DEBUG
465 
467  MetaDataVec md;
468  int pos = 3*vecSize;
469  size_t objId = md.addObject();
470  md.setValue(MDL_IMAGE, fnImg, objId);
471  if (flagEnabled==1) {
472  md.setValue(MDL_ENABLED, 1, objId);
473  }
474  else {
475  md.setValue(MDL_ENABLED, -1, objId);
476  }
477  md.setValue(MDL_ANGLE_ROT, old_rot+p(pos+2), objId);
478  md.setValue(MDL_ANGLE_TILT, old_tilt+p(pos+3), objId);
479  md.setValue(MDL_ANGLE_PSI, old_psi+p(pos+4), objId);
480  md.setValue(MDL_SHIFT_X, old_shiftX+p(pos+0), objId);
481  md.setValue(MDL_SHIFT_Y, old_shiftY+p(pos+1), objId);
482  md.setValue(MDL_FLIP, old_flip, objId);
484  std::vector<double> vectortemp;
485  for (int j = 0; j < VEC_XSIZE(clnm); j++) {
486  vectortemp.push_back(clnm(j));
487  }
488  md.setValue(MDL_SPH_COEFFICIENTS, vectortemp, objId);
489  md.setValue(MDL_COST, correlation, objId);
491 }
492 
494 {
495  for (int h=0; h<=l2; h++)
496  {
497  int numSPH = 2*h+1;
498  int count=l1-h+1;
499  int numEven=(count>>1)+(count&1 && !(h&1));
500  if (h%2 == 0) {
501  vecSize += numSPH*numEven;
502  }
503  else {
504  vecSize += numSPH*(l1-h+1-numEven);
505  }
506  }
507 }
508 
510 {
511  int size = 0;
512  numCoefficients(L1,l2,size);
513  onesInSteps = size;
514  int totalSize = (steps.size()-8)/3;
515  for (int idx=0; idx<size; idx++) {
516  VEC_ELEM(steps,idx) = 1.;
517  VEC_ELEM(steps,idx+totalSize) = 1.;
518  VEC_ELEM(steps,idx+2*totalSize) = 1.;
519  }
520 }
521 
524 {
525  int idx = 0;
526  vL1.initZeros(vecSize);
527  vN.initZeros(vecSize);
528  vL2.initZeros(vecSize);
529  vM.initZeros(vecSize);
530  for (int h=0; h<=l2; h++) {
531  int totalSPH = 2*h+1;
532  int aux = std::floor(totalSPH/2);
533  for (int l=h; l<=l1; l+=2) {
534  for (int m=0; m<totalSPH; m++) {
535  VEC_ELEM(vL1,idx) = l;
536  VEC_ELEM(vN,idx) = h;
537  VEC_ELEM(vL2,idx) = h;
538  VEC_ELEM(vM,idx) = m-aux;
539  idx++;
540  }
541  }
542  }
543 }
544 
545 void ProgAngularSphAlignmentGpu::updateCTFImage(double defocusU, double defocusV, double angle)
546 {
547  ctf->K=1; // get pure CTF with no envelope
548  currentDefocusU=ctf->DeltafU=defocusU;
549  currentDefocusV=ctf->DeltafV=defocusV;
550  currentAngle=ctf->azimuthal_angle=angle;
551  ctf->produceSideInfo();
552 }
553 
556  const MultidimArray<double> &mV,
557  double &def,
558  double rot,
559  double tilt,
560  double psi)
561 {
562  size_t idxY0=(VEC_XSIZE(clnm)-8)/3;
563 
564  // Rotation Matrix
565  R.initIdentity(3);
566  Euler_angles2matrix(rot, tilt, psi, R, false);
567  R = R.inv();
568 
569  double RmaxF=RmaxDef;
570 
572 
574  //angularAlignGpu.runKernelTest(clnm, idxY0, RmaxF * RmaxF, 1.0/RmaxF, R, mV, steps_cp, vL1, vN, vL2, vM, V_mask, mP);
575 
577  auto outputs = angularAlignGpu.getOutputs();
578 
579  sumVd = outputs.sumVD;
580  def = sqrt(outputs.modg/outputs.count);
581  totalDeformation = def;
582 }
583 
void fillVectorTerms(int l1, int l2, Matrix1D< int > &vL1, Matrix1D< int > &vN, Matrix1D< int > &vL2, Matrix1D< int > &vM)
Zernike and SPH coefficients allocation.
Rotation angle of an image (double,degrees)
#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)
void clear()
Definition: matrix1d.cpp:67
size_t size() const
Definition: matrix1d.h:508
#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
Definition: mask.h:360
void sqrt(Image< double > &op)
Tilting angle of an image (double,degrees)
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)
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)
FileName fnOutDir
Output directory.
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.
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)
glob_prnt iter
doublereal * x
#define i
Is this image enabled? (int [-1 or 1])
~ProgAngularSphAlignmentGpu()
Destructor.
AngularAlignmentGpu::AngularSphAlignment angularAlignGpu
#define MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
Definition: matrix1d.h:72
void updateCTFImage(double defocusU, double defocusV, double angle)
const FileName & getFileName() const
T & getValue(MDLabel label)
const char * getParam(const char *param, int arg=0)
bool setValue(const MDObject &mdValueIn, size_t id)
size_t addObject() override
Deformation in voxels.
#define CTF
Cost for the image (double)
void numCoefficients(int l1, int l2, int &vecSize)
Length of coefficients vector.
double R1
Definition: mask.h:413
void associateWith(ProgAngularSphAlignmentGpu *prog)
Flip the image? (bool)
void show() const override
Show.
#define XSIZE(v)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
int type
Definition: mask.h:402
#define DIRECT_MULTIDIM_ELEM(v, n)
void addExampleLine(const char *example, bool verbatim=true)
double maxShift
Maximum shift.
double tranformImageSph(double *pclnm, double rot, double tilt, double psi, Matrix2D< double > &A, double deltaDefocusU, double deltaDefocusV, double deltaDefocusAngle)
int verbose
Verbosity level.
void readParams()
Read argument from command line.
void initZeros()
Definition: matrix1d.h:592
#define j
double steps
double continuousSphCost(double *x, void *_prm)
int m
void minimizepos(int L1, int l2, Matrix1D< double > &steps)
Determine the positions to be minimize of a vector containing spherical harmonic coefficients.
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
void append(const FileName &outFile) const
#define BINARY_CIRCULAR_MASK
Definition: mask.h:365
double psi(const double x)
Deformation coefficients.
ProgAngularSphAlignmentGpu()
Empty constructor.
std::unique_ptr< CTFDescription > ctf
bool checkParam(const char *param)
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
void defineParams()
Define parameters.
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)
const MultidimArray< int > & get_binary_mask() const
Definition: mask.h:707
std::unique_ptr< FourierFilter > FilterCTF
T * adaptForNumericalRecipes() const
Definition: matrix1d.h:844
int getIntParam(const char *param, int arg=0)
int * n
Name of an image (std::string)
bool produces_a_metadata
Indicate that the unique final output file is a Metadata.
#define LOWPASS
void addParamsLine(const String &line)
void initIdentity()
Definition: matrix2d.h:673
int mode
Definition: mask.h:407
std::unique_ptr< FourierFilter > filter
std::map< String, CommentList > defaultComments
Definition: xmipp_program.h:83
constexpr int INNER_MASK
Definition: mask.h:47
virtual void writeImageParameters(const FileName &fnImg)