Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | List of all members

#include <angular_projection_matching.h>

Inheritance diagram for ProgAngularProjectionMatching:
Inheritance graph
[legend]
Collaboration diagram for ProgAngularProjectionMatching:
Collaboration graph
[legend]

Public Member Functions

virtual void readParams ()
 Read arguments from command line. More...
 
virtual void defineParams ()
 Define arguments accepted. More...
 
void show ()
 
void run ()
 
virtual void produceSideInfo ()
 
void rotationallyAlignOneImage (Matrix2D< double > &img, int imgno, int &opt_samplenr, double &opt_psi, bool &opt_flip, double &maxcorr)
 
void translationallyAlignOneImage (MultidimArray< double > &img, const int &samplenr, const double &psi, const bool &opt_flip, double &opt_xoff, double &opt_yoff, double &maxcorr)
 
void scaleAlignOneImage (MultidimArray< double > &img, const int &samplenr, const double &psi, const bool &opt_flip, const double &opt_xoff, const double &opt_yoff, const double &old_scale, double &opt_scale, double &maxcorr)
 
void getCurrentReference (int refno, Polar_fftw_plans &local_plans)
 
virtual void processAllImages ()
 
void processSomeImages (const std::vector< size_t > &imagesToProcess)
 
void getCurrentImage (size_t imgid, Image< double > &img)
 
virtual void writeOutputFiles ()
 
void destroyAndClean ()
 
- Public Member Functions inherited from XmippProgram
const char * getParam (const char *param, int arg=0)
 
const char * getParam (const char *param, const char *subparam, int arg=0)
 
int getIntParam (const char *param, int arg=0)
 
int getIntParam (const char *param, const char *subparam, int arg=0)
 
double getDoubleParam (const char *param, int arg=0)
 
double getDoubleParam (const char *param, const char *subparam, int arg=0)
 
float getFloatParam (const char *param, int arg=0)
 
float getFloatParam (const char *param, const char *subparam, int arg=0)
 
void getListParam (const char *param, StringVector &list)
 
int getCountParam (const char *param)
 
bool checkParam (const char *param)
 
bool existsParam (const char *param)
 
void addParamsLine (const String &line)
 
void addParamsLine (const char *line)
 
ParamDefgetParamDef (const char *param) const
 
virtual void quit (int exit_code=0) const
 
virtual int tryRun ()
 
void initProgress (size_t total, size_t stepBin=60)
 
void setProgress (size_t value=0)
 
void endProgress ()
 
void processDefaultComment (const char *param, const char *left)
 
void setDefaultComment (const char *param, const char *comment)
 
virtual void initComments ()
 
void setProgramName (const char *name)
 
void addUsageLine (const char *line, bool verbatim=false)
 
void clearUsage ()
 
void addExampleLine (const char *example, bool verbatim=true)
 
void addSeeAlsoLine (const char *seeAlso)
 
void addKeywords (const char *keywords)
 
const char * name () const
 
virtual void usage (int verb=0) const
 
virtual void usage (const String &param, int verb=2)
 
int version () const
 
virtual void show () const
 
virtual void read (int argc, const char **argv, bool reportErrors=true)
 
virtual void read (int argc, char **argv, bool reportErrors=true)
 
void read (const String &argumentsLine)
 
 XmippProgram ()
 
 XmippProgram (int argc, const char **argv)
 
virtual ~XmippProgram ()
 

Public Attributes

FileName fn_exp
 
FileName fn_ref
 
FileName fn_out
 
FileName fn_ctf
 
MetaDataDb DFexp
 
MetaDataDb DFo
 
size_t dim
 
size_t paddim
 
double pad
 
double max_shift
 
int Ri
 
int Ro
 
double avail_memory
 
int max_nr_refs_in_memory
 
int max_nr_imgs_in_memory
 
int total_nr_refs
 
int counter_refs_in_memory
 
std::vector< int > pointer_allrefs2refsinmem
 
std::vector< int > pointer_refsinmem2allrefs
 
std::vector< size_t > convert_refno_to_stack_position
 
std::vector< size_t > ids
 
Polar< std::complex< double > > * fP_ref
 
Polar< std::complex< double > > * fP_img
 
Polar< std::complex< double > > * fPm_img
 
MultidimArray< double > * proj_ref
 
Polar_fftw_plans global_plans
 
double * stddev_ref
 
double * stddev_img
 
Sampling mysampling
 
bool loop_forward_refs
 
int search5d_shift
 
int search5d_step
 
std::vector< int > search5d_xoff
 
std::vector< int > search5d_yoff
 
MultidimArray< double > Mctf
 
bool phase_flipped
 
int threads
 
int numOrientations
 
size_t nr_trans
 
barrier_t thread_barrier
 
bool do_scale
 
WriteModeMetaData do_overwrite
 
double scale_step
 
double scale_nsteps
 
int progress_bar_step
 
- Public Attributes inherited from XmippProgram
bool doRun
 
bool runWithoutArgs
 
int verbose
 Verbosity level. More...
 
int debug
 

Additional Inherited Members

- Protected Member Functions inherited from XmippProgram
void defineCommons ()
 
- Protected Attributes inherited from XmippProgram
int errorCode
 
ProgramDefprogDef
 Program definition and arguments parser. More...
 
std::map< String, CommentListdefaultComments
 
int argc
 Original command line arguments. More...
 
const char ** argv
 

Detailed Description

projection_matching parameters.

Definition at line 64 of file angular_projection_matching.h.

Member Function Documentation

◆ defineParams()

void ProgAngularProjectionMatching::defineParams ( )
virtual

Define arguments accepted.

Reimplemented from XmippProgram.

Reimplemented in MpiProgAngularProjectionMatching.

Definition at line 83 of file angular_projection_matching.cpp.

84 {
85  addUsageLine("Perform a discrete angular assignment using projection matching in real space.");
86  addUsageLine("This program is relatively fast, using polar coordinates for the in-plane ");
87  addUsageLine("angular searches and the 5-dimensional search of rotation angles and origin ");
88  addUsageLine("offsets is broken in two: first the angles are search in a 3D-search; then, ");
89  addUsageLine("for the optimal orientation the origin offsets are searched (2D).");
90  addUsageLine(" ");
91  addUsageLine("The output of the program consists of a document file with all assigned angles");
92  addUsageLine("and rotations. This file also contains a column for the maximum cross-correlation ");
93  addUsageLine("coefficient. Note that the program does not alter the image headers. ");
94  addUsageLine("The recommended use of this program is within the python script of the ");
95  addUsageLine("xmipp_protocol_projmatch.py");
96  addSeeAlsoLine("angular_discrete_assign, angular_continuous_assign, angular_project_library");
97  addExampleLine("Example of use: Sample at 2 pixel step size for 5D shift search",false);
98  addExampleLine("xmipp_angular_projection_matching -i experimental.doc -o assigned_angles.doc --ref reference.stk --search5d_step 2");
99  addParamsLine(" -i <doc_file> : Docfile with input images");
100  addParamsLine(" -o <output_filename> : Output filename");
101  addParamsLine(" -r <stackFile> : Reference projections");
102  addParamsLine(" alias --ref;");
103  addParamsLine(" [--search5d_shift <s5dshift=0>]: Search range (in +/- pix) for 5D shift search");
104  addParamsLine(" [--search5d_step <s5dstep=2>] : Step size for 5D shift search (in pix)");
105  addParamsLine(" [--Ri <ri=1>] : Inner radius to limit rotational search");
106  addParamsLine(" [--Ro <ro=-1>] : Outer radius to limit rotational search");
107  addParamsLine(" : ro = -1 -> dim/2-1");
108  addParamsLine(" [-s <step=1> <n_steps=3>] : scale step factor (1 means 0.01 in/de-crements) and number of steps around 1.");
109  addParamsLine(" : with default values: 1 0.01 | 0.02 | 0.03");
110  addParamsLine(" alias --scale;");
111  addParamsLine("==+Extra parameters==");
112  addParamsLine(" [--mem <mem=1>] : Available memory for reference library (Gb)");
113  addParamsLine(" [--max_shift <max_shift=-1>] : Max. change in origin offset (+/- pixels; neg= no limit)");
114  addParamsLine(" [--ctf <filename>] : CTF to apply to the reference projections, either a");
115  addParamsLine(" : CTF parameter file or a 2D image with the CTF amplitudes");
116  addParamsLine(" [--pad <pad=1>] : Padding factor (for CTF correction only)");
117  addParamsLine(" [--phase_flipped] : Use this if the experimental images have been phase flipped");
118  addParamsLine(" [--thr <threads=1>] : Number of concurrent threads");
119  addParamsLine(" [--number_orientations <numOrientations=1>] : Number of possible orientations for each experimental image");
120  addParamsLine(" [--append] : Append (versus overwrite) data to the output file");
121 }
void addSeeAlsoLine(const char *seeAlso)
void addExampleLine(const char *example, bool verbatim=true)
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)

◆ destroyAndClean()

void ProgAngularProjectionMatching::destroyAndClean ( )

destroy and clean

Definition at line 197 of file angular_projection_matching.cpp.

198 {
199  delete [] fP_ref;
200  delete [] proj_ref;
201  delete [] fP_img;
202  delete [] fPm_img;
203  delete [] stddev_ref;
204  delete [] stddev_img;
205 
206 }
Polar< std::complex< double > > * fP_ref
Polar< std::complex< double > > * fPm_img
Polar< std::complex< double > > * fP_img

◆ getCurrentImage()

void ProgAngularProjectionMatching::getCurrentImage ( size_t  imgid,
Image< double > &  img 
)

Read current image into memory and translate according to previous optimal Xoff and Yoff

Definition at line 1194 of file angular_projection_matching.cpp.

1195 {
1196  FileName fn_img;
1197  Matrix2D<double> A;
1198  //init A just in case
1199  A.initIdentity(3);
1200 
1201  // jump to line imgno+1 in DFexp, get data and filename
1202  DFexp.getValue(MDL_IMAGE,fn_img, imgid);
1203 
1204  // Read actual image
1205  img.read(fn_img);
1206  img().setXmippOrigin();
1207 
1208  // Store translation in header and apply it to the actual image
1209  //No need to get initial angles since those came with the reference projection
1210  double shiftX=0., shiftY=0.;
1211  DFexp.getValue(MDL_SHIFT_X,shiftX, imgid);
1212  DFexp.getValue(MDL_SHIFT_Y,shiftY, imgid);
1213 
1214  img.setShifts(shiftX,shiftY);
1215 
1216  //FIXME ROB
1217  //img.setEulerAngles(0.,0.,psi);
1218  img.setEulerAngles(0.,0.,0);
1219  //
1220  img.setFlip(0.);
1221 
1222  double scale;
1223  scale = 1.;
1225  DFexp.getValue(MDL_SCALE, scale, imgid);
1226  img.setScale(scale);
1227 
1228  img.getTransformationMatrix(A,true);
1229  A=A.inv();
1230  //std::cerr << "DEBUG_ROB, A:" << A << std::endl;
1231  //img.write("before.spi");
1232  if (!A.isIdentity())
1233  selfApplyGeometry(xmipp_transformation::BSPLINE3, img(), A, xmipp_transformation::IS_INV, xmipp_transformation::WRAP);
1234  //img.write("after.spi");
1235  //exit(0);
1236 }
void selfApplyGeometry(int Splinedegree, MultidimArray< std::complex< double > > &V1, const Matrix2D< double > &A, bool inv, bool wrap, std::complex< double > outside)
bool isIdentity() const
Definition: matrix2d.cpp:1323
void setScale(double scale, const size_t n=0)
bool getValue(MDObject &mdValueOut, size_t id) const override
Shift for the image in the X axis (double)
void inv(Matrix2D< T > &result) const
Definition: matrix2d.cpp:663
void setShifts(double xoff, double yoff, double zoff=0., const size_t n=0)
void setFlip(bool flip, const size_t n=0)
scaling factor for an image or volume (double)
void setEulerAngles(double rot, double tilt, double psi, const size_t n=0)
void getTransformationMatrix(Matrix2D< double > &A, bool only_apply_shifts=false, const size_t n=0)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
Shift for the image in the Y axis (double)
Name of an image (std::string)
void initIdentity()
Definition: matrix2d.h:673
bool containsLabel(const MDLabel label) const override
Definition: metadata_db.h:305

◆ getCurrentReference()

void ProgAngularProjectionMatching::getCurrentReference ( int  refno,
Polar_fftw_plans local_plans 
)

Get pointer to the current reference image If this image wasn't stored in memory yet, read it from disc and store FT of the polar transform as well as the original image

a delete _DATA_ALL

Definition at line 408 of file angular_projection_matching.cpp.

410 {
411  FileName fnt;
412  Image<double> img;
413  double mean,stddev;
415  Polar<double> P;
417  FourierTransformer local_transformer;
418 
419  // Image was not stored yet: read it from disc and store
420  // std::vector<size_t>::const_iterator found =
421  // std::find((mysampling.no_redundant_sampling_points_index).begin(),
422  // (mysampling.no_redundant_sampling_points_index).end(),
423  // (size_t)refno
424  // );
425  // //found = found - (mysampling.no_redundant_sampling_points_index).begin();
426  // _pointer = found - (mysampling.no_redundant_sampling_points_index).begin();
427  // if (found == (mysampling.no_redundant_sampling_points_index).end())
428  // REPORT_ERROR(ERR_VALUE_INCORRECT, "Wrong reference number");
429  // fnt.compose(_pointer + FIRST_IMAGE, fn_ref);
432  img.read(fnt, _DATA_ALL);
433  img().setXmippOrigin();
434 
435  //#define DEBUG
436 #ifdef DEBUG
437 
438  double rot_tmp,tilt_tmp,psi_tmp;
439  img.getEulerAngles(rot_tmp,tilt_tmp,psi_tmp);
440 
441  {
442  std::cerr << "index_found: " << convert_refno_to_stack_position[refno] << std::endl;
443  std::cerr << "refno: " << refno<<std::endl;
444  std::cerr << "reading image " << fnt << std::endl;
445  std::cerr << "rot_tmp,tilt_tmp,psi_tmp: " << rot_tmp<< " "<< tilt_tmp<< " "<<psi_tmp<< std::endl;
446  // std::cerr << "XXXXno_redundant_sampling_points_indexXXXXXX" <<std::endl;
447  // for (std::vector<size_t>::iterator i =
448  // mysampling.my_neighbors.begin();
449  // i != mysampling.my_neighbors.end();
450  // ++i)
451  // std::cerr << *i << " ";
452  std::cerr << std::endl;
453  }
454 #endif
455 #undef DEBUG
456  // Apply CTF
457  if (fn_ctf!="")
458  {
460  if (paddim > dim)
461  {
462  // pad real-space image
463  int x0 = FIRST_XMIPP_INDEX(paddim);
464  int xF = LAST_XMIPP_INDEX(paddim);
465  img().selfWindow(x0, x0, xF,xF);
466  }
467  local_transformer.FourierTransform(img(),Faux);
469  {
470  dAij(Faux,i,j) *= dAij(Mctf,i,j);
471  }
472  local_transformer.inverseFourierTransform(Faux,img());
473 
474  if (paddim > dim)
475  {
476  // de-pad real-space image
477  int x0 = FIRST_XMIPP_INDEX(dim);
478  int xF = LAST_XMIPP_INDEX(dim);
479  img().selfWindow(x0, x0, xF,xF);
480  }
481  }
482 
483  // Calculate FTs of polar rings and its stddev
486  P.computeAverageAndStddev(mean,stddev);
487  P -= mean;
488  fourierTransformRings(P,fP,local_plans,true);
489 
490  pthread_mutex_lock( &update_refs_in_memory_mutex );
491 
493  pointer_allrefs2refsinmem[refno] = counter;
494  if (pointer_refsinmem2allrefs[counter] != -1)
495  {
496  // This position was in use already
497  // Images will be overwritten, so reset the
498  // pointer_allrefs2refsinmem of the old images to -1
500  }
501  pointer_refsinmem2allrefs[counter] = refno;
502  fP_ref[counter] = fP;
503  stddev_ref[counter] = stddev;
504  proj_ref[counter] = img();
505  //#define DEBUG
506 #ifdef DEBUG
507 
508  std::cerr<<"counter= "<<counter<<"refno= "<<refno<<" stddev = "<<stddev;
509  std::cerr<<" refsinmem2allrefs= "<<pointer_refsinmem2allrefs[counter];
510  std::cerr<<" allrefs2refsinmem= "<<pointer_allrefs2refsinmem[pointer_refsinmem2allrefs[counter]] <<std::endl;
511  std::cerr << "pointer_allrefs2refsinmem" <<std::endl;
512  for (std::vector<int>::iterator i = pointer_allrefs2refsinmem.begin();
513  i != pointer_allrefs2refsinmem.end();
514  ++i)
515  std::cerr << *i << " ";
516  std::cerr <<std::endl;
517  std::cerr << "pointer_refsinmem2allrefs" <<std::endl;
518  for (std::vector<int>::iterator i = pointer_refsinmem2allrefs.begin();
519  i != pointer_refsinmem2allrefs.end();
520  ++i)
521  std::cerr << *i << " ";
522  std::cerr <<std::endl;
523 #endif
524 
526  pthread_mutex_unlock( &update_refs_in_memory_mutex );
527  // local_transformer.cleanup();
528 }
void inverseFourierTransform()
Definition: xmipp_fftw.cpp:329
pthread_mutex_t update_refs_in_memory_mutex
#define FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY2D(m)
#define dAij(M, i, j)
void computeAverageAndStddev(double &avg, double &stddev, int mode=FULL_CIRCLES) const
Definition: polar.h:488
void compose(const String &str, const size_t no, const String &ext="")
Polar< std::complex< double > > * fP_ref
#define i
#define x0
void getPolarFromCartesianBSpline(const MultidimArray< T > &M1, int first_ring, int last_ring, int BsplineOrder=3, double xoff=0., double yoff=0., double oversample1=1., int mode1=FULL_CIRCLES)
Definition: polar.h:625
void produceSplineCoefficients(int SplineDegree, MultidimArray< double > &coeffs, const MultidimArray< T > &V1)
void getEulerAngles(double &rot, double &tilt, double &psi, const size_t n=0) const
#define xF
void FourierTransform(T &v, T1 &V, bool getCopy=true)
Definition: xmipp_fftw.h:166
#define j
void fourierTransformRings(Polar< double > &in, Polar< std::complex< double > > &out, Polar_fftw_plans &plans, bool conjugated)
Definition: polar.cpp:34
#define FIRST_XMIPP_INDEX(size)
Definition: xmipp_macros.h:439
std::vector< size_t > convert_refno_to_stack_position
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
#define FIRST_IMAGE
#define LAST_XMIPP_INDEX(size)
Definition: xmipp_macros.h:448

◆ processAllImages()

void ProgAngularProjectionMatching::processAllImages ( )
virtual

Get images to process. This function will return the id's of images to process. It will be specially useful for MPI case when images will be distributed by the master node. Return false if there aren't more images to process

Reimplemented in MpiProgAngularProjectionMatching.

Definition at line 977 of file angular_projection_matching.cpp.

978 {
979  //Init progress bar
980  size_t total_number_of_images = DFexp.size();
981  if (verbose)
982  {
983  progress_bar_step = XMIPP_MAX(1, total_number_of_images / 80);
984  init_progress_bar(total_number_of_images);
985  }
987  if (verbose)
988  progress_bar(total_number_of_images);
989 }
void init_progress_bar(long total)
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
void processSomeImages(const std::vector< size_t > &imagesToProcess)
void progress_bar(long rlen)
int verbose
Verbosity level.
size_t size() const override

◆ processSomeImages()

void ProgAngularProjectionMatching::processSomeImages ( const std::vector< size_t > &  imagesToProcess)

Loop over all images

a

Definition at line 991 of file angular_projection_matching.cpp.

992 {
993  Image<double> img;
994  //double
995  //opt_rot=0.,
996  //opt_tilt=0.;
997  //opt_psi=0.,
998  //opt_xoff=0.,
999  //opt_yoff=0.,
1000  //opt_scale=0.;
1001  //maxcorr=-99.e99;
1002 
1003  auto opt_flip = std::vector<bool> (numOrientations, false);
1004  auto opt_refno = std::vector<int> (numOrientations, 0);
1005  auto opt_psi = std::vector<double> (numOrientations, 0);
1006  auto maxcorr = std::vector<double> (numOrientations, 0);
1007  auto opt_xoff = std::vector<double> (numOrientations, 0);
1008  auto opt_yoff = std::vector<double> (numOrientations, 0);
1009  auto opt_scale = std::vector<double> (numOrientations, 0);
1010  auto opt_rot = std::vector<double> (numOrientations, 0);
1011  auto opt_tilt = std::vector<double> (numOrientations, 0);
1012 
1013  size_t itemId=0;
1014  size_t nr_images = imagesToProcess.size();
1015  size_t idNew, imgid;
1016  FileName fn;
1017 
1018  // Call threads to calculate the rotational alignment of each image in the selfile
1019  auto * th_ids = (pthread_t *)malloc( threads * sizeof( pthread_t));
1020 
1021  // Allocate threads.
1022  auto * threads_d = (structThreadRotationallyAlignOneImage *)
1023  malloc ( threads * sizeof( structThreadRotationallyAlignOneImage ) );
1024 
1025  // Allocate threads vectors.
1026  for( int c = 0 ; c < threads ; c++ )
1027  {
1028  threads_d[c].opt_refno = (int *)malloc (sizeof(int)*numOrientations);
1029  threads_d[c].opt_psi = (double *)malloc (sizeof(double)*numOrientations);
1030  threads_d[c].opt_flip = (bool *) malloc (sizeof(bool)*numOrientations);
1031  threads_d[c].maxcorr = (double *)malloc (sizeof(double)*numOrientations);
1032  threads_d[c].numOrientations = numOrientations;
1033  }
1034 
1035  for (size_t imgno = 0; imgno < nr_images; imgno++)
1036  {
1037  imgid = imagesToProcess[imgno];
1038 
1039  FileName pp;
1040  DFexp.getValue(MDL_IMAGE,pp, imgid);
1041 
1042  getCurrentImage(imgid, img);
1043  for( int c = 0 ; c < threads ; c++ )
1044  {
1045  threads_d[c].thread_id = c;
1046  threads_d[c].prm = this;
1047  threads_d[c].img = &img();
1048  threads_d[c].this_image = imgid;
1049  for (size_t i=0; i<numOrientations ;i++)
1050  {
1051  threads_d[c].maxcorr[i] = -99.e99;
1052  threads_d[c].opt_refno[i] = -1;
1053  opt_scale[i] = 1;
1054  opt_refno[i] = -1;
1055  }
1056  pthread_create( (th_ids+c), nullptr, threadRotationallyAlignOneImage, (void *)(threads_d+c) );
1057  }
1058  // Wait for threads to finish
1059  for( int c = 0 ; c < threads ; c++ )
1060  pthread_join(*(th_ids+c),nullptr);
1061 
1062  //Get optimal refno, psi, flip and maxcorr
1063  auto * indexThreads = new int[threads](); // init to zero
1064  size_t bestThreadCorr = 0;
1065  double tempCorr;
1066  size_t counterValidCorrs = 0;
1067  bool validCorr = false;
1068  for( int n = 0 ; n < numOrientations ; n++ )
1069  {
1070  tempCorr = -99.e99;
1071  validCorr = false;
1072  for( int c = 0 ; c < threads ; c++ )
1073  {
1074  if (threads_d[c].maxcorr[indexThreads[c]] > tempCorr)
1075  {
1076  if (not validCorr)
1077  {
1078  counterValidCorrs++;
1079  validCorr = true;
1080  }
1081 
1082  bestThreadCorr = c;
1083  tempCorr = threads_d[c].maxcorr[indexThreads[c]];
1084  }
1085 
1086  }
1087 
1088  if (not validCorr)
1089  break;
1090 
1091  opt_refno[n] = threads_d[bestThreadCorr].opt_refno[indexThreads[bestThreadCorr]];
1092  opt_psi[n] = threads_d[bestThreadCorr].opt_psi[indexThreads[bestThreadCorr]];
1093  opt_flip[n] = threads_d[bestThreadCorr].opt_flip[indexThreads[bestThreadCorr]];
1094  maxcorr[n] = threads_d[bestThreadCorr].maxcorr[indexThreads[bestThreadCorr]];
1095  indexThreads[bestThreadCorr]++;
1096 
1097 
1098  if (opt_refno[n]>=0)
1099  {
1102  }
1103  else
1104  {
1105  opt_rot[n]=0;
1106  opt_tilt[n]=0;
1107  }
1108  }
1109 
1110  delete[] indexThreads;
1111  // Flip order to loop through references
1113 
1114  //#define DEBUG
1115 #ifdef DEBUG
1116  std::cerr << "DEBUG_ROB, img.name():" << img.name() << std::endl;
1117 #endif
1118 #undef DEBUG
1119 
1120  for(int n=0; n < counterValidCorrs; n++)
1121  {
1122  //std::cout << " " << std::endl;
1123  //std::cout << maxcorr[n] << std::endl;
1125  opt_refno[n],
1126  opt_psi[n],
1127  opt_flip[n],
1128  opt_xoff[n],
1129  opt_yoff[n],
1130  maxcorr[n]);
1131 
1132  //std::cout << maxcorr[n] << std::endl;
1133  if(do_scale && scale_nsteps > 0)
1134  {
1135  // Compute a better scale (scale_min -> scale_max)
1136  scaleAlignOneImage(img(), opt_refno[n], opt_psi[n], opt_flip[n], opt_xoff[n], opt_yoff[n], img.scale(), opt_scale[n], maxcorr[n]);
1137  }
1138 
1139  //Add the previously applied scale to the newly found one
1140  opt_scale[n] *= img.scale();
1142  // Divide opt_shifts by old_scale
1143 
1144  // Add previously applied translation to the newly found one
1145  opt_xoff[n] += img.Xoff();
1146  opt_yoff[n] += img.Yoff();
1147 
1148  // Output
1149  DFexp.getValue(MDL_IMAGE, fn, imgid);
1150  DFexp.getValue(MDL_ITEM_ID, itemId, imgid);
1151 
1152  idNew = DFo.addObject();
1153  DFo.setValue(MDL_ITEM_ID,itemId,idNew);
1154  DFo.setValue(MDL_IMAGE, fn,idNew);
1155  DFo.setValue(MDL_ANGLE_ROT, opt_rot[n],idNew);
1156  DFo.setValue(MDL_ANGLE_TILT,opt_tilt[n],idNew);
1157  DFo.setValue(MDL_ANGLE_PSI, opt_psi[n],idNew);
1158 
1159  //opt_xoff=0;
1160  DFo.setValue(MDL_SHIFT_X, opt_xoff[n],idNew);
1161  DFo.setValue(MDL_SHIFT_Y, opt_yoff[n],idNew);
1162  DFo.setValue(MDL_REF, opt_refno[n] /*+ FIRST_IMAGE*/,idNew);
1163  DFo.setValue(MDL_FLIP, opt_flip[n],idNew);
1164  DFo.setValue(MDL_SCALE, opt_scale[n],idNew);
1165  DFo.setValue(MDL_MAXCC, maxcorr[n],idNew);
1166 
1167  }
1168 
1169  /* FIXME ROB */
1170  //opt_psi += img.psi();
1171  /* */
1172 
1173  //opt_scale=1.0;
1174 
1175  if (verbose && imgno % progress_bar_step == 0)
1176  progress_bar(imgno);
1177  //#endif
1178  //DFo.write("/dev/stderr");
1179  }//loop over images
1180  free(th_ids);
1181 
1182  for( int c = 0 ; c < threads ; c++ )
1183  {
1184  free(threads_d[c].opt_refno);
1185  free(threads_d[c].opt_psi);
1186  free(threads_d[c].opt_flip);
1187  free(threads_d[c].maxcorr);
1188  }
1189 
1190  free(threads_d);
1191 
1192 }//function processSomeImages
Rotation angle of an image (double,degrees)
void scaleAlignOneImage(MultidimArray< double > &img, const int &samplenr, const double &psi, const bool &opt_flip, const double &opt_xoff, const double &opt_yoff, const double &old_scale, double &opt_scale, double &maxcorr)
doublereal * c
#define pp(s, x)
Definition: ml2d.cpp:473
bool getValue(MDObject &mdValueOut, size_t id) const override
Tilting angle of an image (double,degrees)
Shift for the image in the X axis (double)
Special label to be used when gathering MDs in MpiMetadataPrograms.
const FileName & name() const
#define i
Unique identifier for items inside a list or set (std::size_t)
void * threadRotationallyAlignOneImage(void *data)
#define XX(v)
Definition: matrix1d.h:85
size_t addObject() override
Flip the image? (bool)
double Yoff(const size_t n=0) const
void progress_bar(long rlen)
double scale(const size_t n=0) const
free((char *) ob)
Maximum cross-correlation for the image (double)
scaling factor for an image or volume (double)
int verbose
Verbosity level.
void translationallyAlignOneImage(MultidimArray< double > &img, const int &samplenr, const double &psi, const bool &opt_flip, double &opt_xoff, double &opt_yoff, double &maxcorr)
#define YY(v)
Definition: matrix1d.h:93
void getCurrentImage(size_t imgid, Image< double > &img)
Class to which the image belongs (int)
std::vector< Matrix1D< double > > no_redundant_sampling_points_angles
Definition: sampling.h:121
bool setValue(const MDObject &mdValueIn, size_t id) override
Definition: metadata_db.cpp:90
std::vector< size_t > convert_refno_to_stack_position
double Xoff(const size_t n=0) const
Shift for the image in the Y axis (double)
int * n
Name of an image (std::string)

◆ produceSideInfo()

void ProgAngularProjectionMatching::produceSideInfo ( )
virtual

Make shiftmask and calculate nr_psi

Reimplemented in MpiProgAngularProjectionMatching.

Definition at line 209 of file angular_projection_matching.cpp.

210 {
211 
212  Image<double> img,empty;
213  Projection proj;
214  MetaDataVec DF;
215  MetaDataVec SFr,emptySF;
216  SymList SL;
217  FileName fn_img;
219  MultidimArray<double> dataline(3);
220  Polar<double> P;
222 
223  // Read Selfile and get dimensions
224  MetaDataDb MetaDataLeft;
225  MetaDataDb MetaDataRight;
226  String blockName = "all_exp_images";
227 
228  FileName inputFn = fn_exp.removeBlockName();
229  if (existsBlockInMetaDataFile(inputFn, blockName))
230  {
231  FileName rightFn;
232  rightFn.compose(blockName, inputFn);
233  MetaDataRight.read(rightFn);
234  MetaDataLeft.read(fn_exp);
235  //Join with angles and shifhts
236  DFexp.join1(MetaDataLeft, MetaDataRight, MDL_IMAGE,LEFT);
237  }
238  else
239  DFexp.read(fn_exp);
240  //DFexp.removeDisabled();
241 
242 
244  // Thread barrier
246 
247  // Read one image to get dim
249  img.read(fn_img);
250  dim = XSIZE(img());
251 
252  // Check that the reference and the experimental images are of the same
253  // size
254  FileName fnt;
255  fnt.compose(FIRST_IMAGE, fn_ref);
256  Image<double> imgRef;
257  imgRef.read(fnt,HEADER);
258 
259  if (!imgRef().sameShape(img()))
261  "Check that the reference volume and the experimental images are of the same size");
262 
263  // Set padding dimension
264  paddim=ROUND(pad*dim);
265 
266  // Set max_shift
267  if (max_shift<0)
268  max_shift = dim/2;
269 
270  // Set ring defaults
271  if (Ri<1)
272  Ri=1;
273  if (Ro<0)
274  Ro=(dim/2)-1;
275 
276  // Calculate necessary memory per image
281  double memory_per_ref = 0.;
282  for (int i = 0; i < fP.getRingNo(); i++)
283  {
284  memory_per_ref += (double) fP.getSampleNo(i) * 2 * sizeof(double);
285  }
286  memory_per_ref += dim * dim * sizeof(double);
287  max_nr_imgs_in_memory = ROUND( 1024 * 1024 * 1024 * avail_memory / memory_per_ref);
288 
289  // Set up angular sampling
292 
293  //#define DEBUG
294 #ifdef DEBUG
295 
296  std::cerr << "XXXXmysampling.no_redundant_sampling_points_indexXXXXXX" <<std::endl;
297  for (std::vector<size_t>::iterator i =
300  ++i)
301  std::cerr << *i << " ";
302  std::cerr << std::endl;
303  std::cerr << "exit" <<std::endl;
304 #endif
305 #undef DEBUG
306 
308  for (size_t i = 0; i < mysampling.no_redundant_sampling_points_index.size(); i++)
310 
311  // Don't reserve more memory than necessary
312  max_nr_refs_in_memory = XMIPP_MIN(max_nr_imgs_in_memory, total_nr_refs);
313 
314  // Initialize pointers for reference retrieval
318  loop_forward_refs=true;
319 
320  // Initialize 5D search vectors
321  search5d_xoff.clear();
322  search5d_yoff.clear();
323  // Make sure origin is included
324  if(search5d_step == 0)
325  {
326  printf("***********************************************************\n");
327  printf("* ERROR: search step should be different from 0\n");
328  printf("* search step set to 1 \n");
329  printf("***********************************************************\n");
330 
331  search5d_step = 1;
332  }
334  nr_trans = 0;//number translations in 5D
335  for (int xoff = -myfinal; xoff <= myfinal; xoff+= search5d_step)
336  {
337  for (int yoff = -myfinal; yoff <= myfinal; yoff+= search5d_step)
338  {
339  // Only take a circle (not a square)
340  if ( xoff*xoff + yoff*yoff <= search5d_shift*search5d_shift)
341  {
342  search5d_xoff.push_back(xoff);
343  search5d_yoff.push_back(yoff);
344  nr_trans++;
345  }
346  }
347  }
348 
349  // Initialize all arrays
350  try
351  {
356 
357  stddev_ref = new double[max_nr_refs_in_memory];
358  stddev_img = new double[nr_trans];
359  }
360  catch (std::bad_alloc&)
361  {
362  REPORT_ERROR(ERR_MEM_BADREQUEST,"Error allocating memory in produceSideInfo");
363  }
364 
365  // CTF stuff
366  if (fn_ctf != "")
367  {
368  if (!fn_ctf.isMetaData())
369  {
370  Image<double> img;
371  img.read(fn_ctf);
372  Mctf=img();
373  if (XSIZE(Mctf) != paddim)
374  {
375  std::cerr<<"image size= "<<dim<<" padding factor= "<<pad<<" padded image size= "<<paddim<<" Wiener filter size= "<<XSIZE(Mctf)<<std::endl;
377  "Incompatible padding factor for this CTF filter");
378  }
379  }
380  else
381  {
382  CTFDescription ctf;
384  ctf.read(fn_ctf);
385  if (ABS(ctf.DeltafV - ctf.DeltafU) >1.)
386  {
388  "ERROR!! Only non-astigmatic CTFs are allowed!");
389  }
390  ctf.enable_CTF = true;
391  ctf.produceSideInfo();
392  ctf.generateCTF(paddim, paddim, ctfmask);
395  {
396  if (phase_flipped)
397  dAij(Mctf, i, j) = fabs(dAij(ctfmask, i, j).real());
398  else
399  dAij(Mctf, i, j) = dAij(ctfmask, i, j).real();
400  }
401  }
402  }
403 
404  //Store the id's of each experimental image from metadata
406 }
int barrier_init(barrier_t *barrier, int needed)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY2D(m)
#define dAij(M, i, j)
void findObjects(std::vector< size_t > &objectsOut, const MDQuery &query) const override
bool getValue(MDObject &mdValueOut, size_t id) const override
double DeltafV
Defocus in V (in Angstroms). Negative values are underfocused.
Definition: ctf.h:830
bool existsBlockInMetaDataFile(const FileName &inFileWithBlock)
void compose(const String &str, const size_t no, const String &ext="")
int getSampleNo(int iring) const
Definition: polar.h:373
Polar< std::complex< double > > * fP_ref
FileName removeAllExtensions() const
Incorrect MultidimArray size.
Definition: xmipp_error.h:174
Bad amount of memory requested.
Definition: xmipp_error.h:165
#define i
void read(const FileName &fn, bool disable_if_not_K=true)
Definition: ctf.cpp:1220
double DeltafU
Global gain. By default, 1.
Definition: ctf.h:828
bool enable_CTF
Enable CTF part.
Definition: ctf.h:275
std::vector< size_t > no_redundant_sampling_points_index
Definition: sampling.h:123
size_t numberSamplesAsymmetricUnit
Definition: sampling.h:78
void getPolarFromCartesianBSpline(const MultidimArray< T > &M1, int first_ring, int last_ring, int BsplineOrder=3, double xoff=0., double yoff=0., double oversample1=1., int mode1=FULL_CIRCLES)
Definition: polar.h:625
void produceSplineCoefficients(int SplineDegree, MultidimArray< double > &coeffs, const MultidimArray< T > &V1)
#define XSIZE(v)
#define ABS(x)
Definition: xmipp_macros.h:142
#define ROUND(x)
Definition: xmipp_macros.h:210
Polar< std::complex< double > > * fPm_img
#define XMIPP_MIN(x, y)
Definition: xmipp_macros.h:181
#define j
void fourierTransformRings(Polar< double > &in, Polar< std::complex< double > > &out, Polar_fftw_plans &plans, bool conjugated)
Definition: polar.cpp:34
size_t firstRowId() const override
void generateCTF(const MultidimArray< T1 > &sample_image, MultidimArray< T2 > &CTF, double Ts=-1)
Definition: ctf.h:1194
void readSamplingFile(const FileName &infilename, bool read_vectors=true, bool read_sampling_sphere=false)
Definition: sampling.cpp:1592
std::vector< Matrix1D< double > > no_redundant_sampling_points_angles
Definition: sampling.h:121
bool isMetaData(bool failIfNotExists=true) const
FileName removeBlockName() const
Polar< std::complex< double > > * fP_img
std::vector< size_t > convert_refno_to_stack_position
std::string String
Definition: xmipp_strings.h:34
void produceSideInfo()
Produce Side information.
Definition: ctf.cpp:1392
int getRingNo() const
Definition: polar.h:326
void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=NULL, bool decomposeStack=true) override
void join1(const MetaDataDb &mdInLeft, const MetaDataDb &mdInRight, const MDLabel label, JoinType type=LEFT)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
#define FIRST_IMAGE
void calculateFftwPlans(Polar_fftw_plans &out)
Definition: polar.h:708
Incorrect value received.
Definition: xmipp_error.h:195
Name of an image (std::string)

◆ readParams()

void ProgAngularProjectionMatching::readParams ( )
virtual

Read arguments from command line.

Reimplemented from XmippProgram.

Reimplemented in MpiProgAngularProjectionMatching.

Definition at line 44 of file angular_projection_matching.cpp.

46 {
47  fn_exp = getParam("-i");
48  fn_out = getParam("-o");
49  fn_ref = getParam("--ref");
50 
51  // Additional commands
52  pad=XMIPP_MAX(1.,getDoubleParam("--pad"));
53  Ri=getIntParam("--Ri");
54  Ro=getIntParam("--Ro");
55  search5d_shift = getIntParam("--search5d_shift");
56  search5d_step = getIntParam("--search5d_step");
57  max_shift = getDoubleParam("--max_shift");
58  numOrientations = getIntParam("--number_orientations");
59 
60  avail_memory = getDoubleParam("--mem");
61  if (checkParam("--ctf"))
62  fn_ctf = getParam("--ctf");
63  phase_flipped = checkParam("--phase_flipped");
64  threads = getIntParam("--thr");
65 
66  do_scale = checkParam("--scale");
67  if (checkParam("--append"))
69  else
71 
72  if(do_scale)
73  {
74  scale_step = getDoubleParam("--scale",0);
75  //Scale Step can't be 0
76  if (scale_step == 0)
77  scale_step = 1;
78  scale_nsteps = getDoubleParam("--scale",1);
79  }
80 
81 }
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
double getDoubleParam(const char *param, int arg=0)
const char * getParam(const char *param, int arg=0)
bool checkParam(const char *param)
int getIntParam(const char *param, int arg=0)

◆ rotationallyAlignOneImage()

void ProgAngularProjectionMatching::rotationallyAlignOneImage ( Matrix2D< double > &  img,
int  imgno,
int &  opt_samplenr,
double &  opt_psi,
bool &  opt_flip,
double &  maxcorr 
)

Rotational alignment using polar coordinates The input image is assumed to be in FTs of polar rings

◆ run()

void ProgAngularProjectionMatching::run ( )
virtual

Run.

Reimplemented from XmippProgram.

Definition at line 182 of file angular_projection_matching.cpp.

183 {
184  produceSideInfo();
185 
186  show();
187 
189 
191 
192  destroyAndClean();
193  if (verbose)
194  std::cout << "done!"<<std::endl;
195 }
int verbose
Verbosity level.

◆ scaleAlignOneImage()

void ProgAngularProjectionMatching::scaleAlignOneImage ( MultidimArray< double > &  img,
const int &  samplenr,
const double &  psi,
const bool &  opt_flip,
const double &  opt_xoff,
const double &  opt_yoff,
const double &  old_scale,
double &  opt_scale,
double &  maxcorr 
)

Translational alignment using cartesian coordinates The optimal direction is re-projected from the volume

a

Definition at line 871 of file angular_projection_matching.cpp.

880 {
881  MultidimArray<double> Mscale,Mtrans,Mref,Mimg;
882  int refno;
883 
884  Mscale.setXmippOrigin();
885  Mtrans.setXmippOrigin();
886  Mref.setXmippOrigin();
887  Mimg.setXmippOrigin();
888 
889 #ifdef TIMING
890 
891  TimeStamp t0,t1,t2;
892  time_config();
893  annotate_time(&t0);
894 #endif
895 
896  // ROTATE + SHIFT
897  // Transformation matrix
898  Matrix2D<double> A(3,3);
899  A.initIdentity();
900  double ang, cosine, sine;
901  ang = DEG2RAD(opt_psi);
902  cosine = cos(ang);
903  sine = sin(ang);
904 
905  // Rotation
906  MAT_ELEM(A,0, 0) = cosine;
907  MAT_ELEM(A,0, 1) = sine;
908  MAT_ELEM(A,1, 0) = -sine;
909  MAT_ELEM(A,1, 1) = cosine;
910 
911  // Shift
912  MAT_ELEM(A,0, 2) = -opt_xoff;
913  MAT_ELEM(A,1, 2) = -opt_yoff;
914 
916  // Multiply shifts by old_scale
917 
918  if (opt_flip)
919  {
920  MAT_ELEM(A,0, 2) = opt_xoff;
921  MAT_ELEM(A,0, 0) *= -1.;
922  MAT_ELEM(A,0, 1) *= -1.;
923  }
924 
925  // Get pointer to the correct reference image in memory
926  refno = pointer_allrefs2refsinmem[opt_refno];
927  if (refno == -1)
928  {
929  // Reference is not stored in memory (anymore): (re-)read from disc
931  refno = pointer_allrefs2refsinmem[opt_refno];
932  }
933  applyGeometry(xmipp_transformation::LINEAR, Mref, proj_ref[refno], A, xmipp_transformation::IS_NOT_INV, xmipp_transformation::DONT_WRAP);
934 
935 
936  Mtrans = img;
937 
938  // Scale search
939  double corr;
940  opt_scale = 1;
941  //maxcorr = -999;
942 
943  // 1 (0.01 * scale_step * scale_nsteps)
944  double scale = 1 - 0.01 * scale_step * scale_nsteps;
945  while(scale <= 1 + 0.01 * scale_step * scale_nsteps)
946  {
947  if(scale == 1.)
948  continue;
949 
950  // apply current scale
951  A.initIdentity();
952  A /= scale;
953  applyGeometry(xmipp_transformation::LINEAR, Mscale, Mtrans, A, xmipp_transformation::IS_INV, xmipp_transformation::DONT_WRAP);
954 
955  //Image spread correction (if scale != 1) for scale search
956  Mscale = Mscale / (scale * scale * old_scale * old_scale);
957 
958  corr = correlationIndex(Mref,Mscale);
959 
960  // best scale update
961  if(corr > maxcorr)
962  {
963  opt_scale = scale;
964  maxcorr = corr;
965  }
966  scale += 0.01 * scale_step;
967  }
968 
969 #ifdef TIMING
970 
971  float total_trans = elapsed_time(t0);
972  std::cerr<<" trans%% "<<total_trans <<std::endl;
973 #endif
974 
975 }
void getCurrentReference(int refno, Polar_fftw_plans &local_plans)
#define DEG2RAD(d)
Definition: xmipp_macros.h:312
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)
double correlationIndex(const MultidimArray< T > &x, const MultidimArray< T > &y, const MultidimArray< int > *mask=NULL, MultidimArray< double > *Contributions=NULL)
double elapsed_time(ProcessorTimeStamp &time, bool _IN_SECS)
void time_config()
#define MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
void annotate_time(TimeStamp *time)
size_t TimeStamp
Definition: xmipp_funcs.h:823

◆ show()

void ProgAngularProjectionMatching::show ( )

Show.

Definition at line 124 of file angular_projection_matching.cpp.

125 {
126  if (!verbose)
127  return;
128 
129  std::cout
130  << " Input images : "<< fn_exp << std::endl
131  << " Output file : "<< fn_out << std::endl
132  ;
133  if (Ri>0)
134  std::cout << " Inner radius rot-search : " << Ri<< std::endl;
135  if (Ro>0)
136  std::cout << " Outer radius rot-search : " << Ro << std::endl;
138  {
139  std::cout << " Number of references : " << total_nr_refs << std::endl
140  << " Nr. refs in memory : " << max_nr_refs_in_memory << " (using " << avail_memory <<" Gb)" << std::endl
141  ;
142  }
143  else
144  {
145  std::cout << " Number of references : " << total_nr_refs << " (all stored in memory)" << std::endl;
146  }
147  std::cout << " Max. allowed shift : +/- " <<max_shift<<" pixels"<<std::endl;
148  if (search5d_shift > 0)
149  {
150  std::cout << " 5D-search shift range : "<<search5d_shift<<" pixels (sampled "<<nr_trans<<" times)"<<std::endl;
151  }
152  if (fn_ctf!="")
153  {
154  if (!fn_ctf.isMetaData())
155  {
156  std::cout << " CTF image : " <<fn_ctf<<std::endl;
157  if (pad > 1.)
158  std::cout << " Padding factor : "<< pad << std::endl;
159  }
160  else
161  {
162  std::cout << " CTF parameter file : " <<fn_ctf<<std::endl;
163  if (phase_flipped)
164  std::cout << " + Assuming images have been phase flipped " << std::endl;
165  else
166  std::cout << " + Assuming images have not been phase flipped " << std::endl;
167  }
168  }
169  if (threads>1)
170  {
171  std::cout << " -> Using "<<threads<<" parallel threads"<<std::endl;
172  }
173 
174  if (numOrientations != 1)
175  std::cout << " -> Using "<<numOrientations<<" possible orientations for each particle"<<std::endl;
176 
177 
178  std::cout << " ================================================================="<<std::endl;
179 }
int verbose
Verbosity level.
bool isMetaData(bool failIfNotExists=true) const

◆ translationallyAlignOneImage()

void ProgAngularProjectionMatching::translationallyAlignOneImage ( MultidimArray< double > &  img,
const int &  samplenr,
const double &  psi,
const bool &  opt_flip,
double &  opt_xoff,
double &  opt_yoff,
double &  maxcorr 
)

Translational alignment using cartesian coordinates The optimal direction is re-projected from the volume

Definition at line 776 of file angular_projection_matching.cpp.

783 {
784 
785  MultidimArray<double> Mtrans,Mimg,Mref;
786  int refno;
787  Mtrans.setXmippOrigin();
788  Mimg.setXmippOrigin();
789  Mref.setXmippOrigin();
790 #ifdef TIMING
791 
792  TimeStamp t0,t1,t2;
793  time_config();
794  annotate_time(&t0);
795 #endif
796 
797 #ifdef DEBUG
798 
799  std::cerr<<"start trans: opt_refno= "<<opt_refno<<" pointer= "<<pointer_allrefs2refsinmem[opt_refno]<<" opt_psi= "<<opt_psi<<"opt_flip= "<<opt_flip<<std::endl;
800 #endif
801 
802  // Get pointer to the correct reference image in memory
803  refno = pointer_allrefs2refsinmem[opt_refno];
804  if (refno == -1)
805  {
806  // Reference is not stored in memory (anymore): (re-)read from disc
808  refno = pointer_allrefs2refsinmem[opt_refno];
809  }
810 
811  // Rotate stored reference projection by phi degrees
812  rotate(xmipp_transformation::BSPLINE3,Mref,proj_ref[refno],opt_psi,xmipp_transformation::DONT_WRAP);
813  //rotate(BSPLINE3,Mref,proj_ref[refno],-opt_psi,DONT_WRAP);
814 
815 #ifdef DEBUG
816 
817  std::cerr<<"rotated ref "<<std::endl;
818 #endif
819 
820  if (opt_flip)
821  {
822  // Flip experimental image
823  Matrix2D<double> A(3,3);
824  A.initIdentity();
825  MAT_ELEM(A,0, 0) = -1.;
826  //MAT_ELEM(A,0, 1) *= -1.;
827  applyGeometry(xmipp_transformation::LINEAR, Mimg, img, A, xmipp_transformation::IS_INV, xmipp_transformation::DONT_WRAP);
828  }
829  else
830  Mimg = img;
831 
832 
833  // Perform the actual search for the optimal shift
834  if (max_shift>0)
835  {
836  CorrelationAux aux;
837  bestShift(Mref,Mimg,opt_xoff,opt_yoff,aux);
838  }
839  else
840  opt_xoff = opt_yoff = 0.;
841  if (opt_xoff * opt_xoff + opt_yoff * opt_yoff > max_shift * max_shift)
842  opt_xoff = opt_yoff = 0.;
843  //#define DEBUG
844 #ifdef DEBUG
845 
846  std::cerr<<"optimal shift "<<opt_xoff<<" "<<opt_yoff<<std::endl;
847 #endif
848 
849  // Calculate standard cross-correlation coefficient
850  translate(xmipp_transformation::LINEAR,Mtrans,Mimg,vectorR2(opt_xoff,opt_yoff),true);
851  maxcorr = correlationIndex(Mref,Mtrans);
852 
853 #ifdef DEBUG
854 
855  std::cerr<<"optimal shift corr "<<maxcorr<<std::endl;
856 #endif
857 #undef DEBUG
858  // Correct X-shift for mirrored images
859  if (opt_flip)
860  opt_xoff *= -1.;
861 
862 #ifdef TIMING
863 
864  float total_trans = elapsed_time(t0);
865  std::cerr<<" trans%% "<<total_trans <<std::endl;
866 #endif
867 
868 }
void getCurrentReference(int refno, Polar_fftw_plans &local_plans)
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)
double correlationIndex(const MultidimArray< T > &x, const MultidimArray< T > &y, const MultidimArray< int > *mask=NULL, MultidimArray< double > *Contributions=NULL)
double elapsed_time(ProcessorTimeStamp &time, bool _IN_SECS)
#define rotate(a, i, j, k, l)
void time_config()
#define MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
Matrix1D< double > vectorR2(double x, double y)
Definition: matrix1d.cpp:884
void translate(PDB *pdb_original, PDB *pdb_move, unsigned num_atoms, double x0, double y0, double z0)
Definition: lib_pwk.cpp:125
template float bestShift(MultidimArray< float > &, float &, float &, const MultidimArray< int > *, int)
void annotate_time(TimeStamp *time)
size_t TimeStamp
Definition: xmipp_funcs.h:823

◆ writeOutputFiles()

void ProgAngularProjectionMatching::writeOutputFiles ( )
virtual

Write out results to disk This function should be override in MPI class, only master should write.

Reimplemented in MpiProgAngularProjectionMatching.

Definition at line 1238 of file angular_projection_matching.cpp.

1239 {
1241 }
void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const override

Member Data Documentation

◆ avail_memory

double ProgAngularProjectionMatching::avail_memory

Available memory for storage of all references (in Gb)

Definition at line 84 of file angular_projection_matching.h.

◆ convert_refno_to_stack_position

std::vector<size_t> ProgAngularProjectionMatching::convert_refno_to_stack_position

Vector to assign reference number to stack positions

Definition at line 100 of file angular_projection_matching.h.

◆ counter_refs_in_memory

int ProgAngularProjectionMatching::counter_refs_in_memory

Counter for current filling of memory with references

Definition at line 95 of file angular_projection_matching.h.

◆ DFexp

MetaDataDb ProgAngularProjectionMatching::DFexp

Docfile with experimental images

Definition at line 72 of file angular_projection_matching.h.

◆ DFo

MetaDataDb ProgAngularProjectionMatching::DFo

Docfile with results

Definition at line 74 of file angular_projection_matching.h.

◆ dim

size_t ProgAngularProjectionMatching::dim

dimension of the images and padded images

Definition at line 76 of file angular_projection_matching.h.

◆ do_overwrite

WriteModeMetaData ProgAngularProjectionMatching::do_overwrite

Definition at line 137 of file angular_projection_matching.h.

◆ do_scale

bool ProgAngularProjectionMatching::do_scale

scale params

Definition at line 136 of file angular_projection_matching.h.

◆ fn_ctf

FileName ProgAngularProjectionMatching::fn_ctf

Definition at line 70 of file angular_projection_matching.h.

◆ fn_exp

FileName ProgAngularProjectionMatching::fn_exp

Filenames

Definition at line 70 of file angular_projection_matching.h.

◆ fn_out

FileName ProgAngularProjectionMatching::fn_out

Definition at line 70 of file angular_projection_matching.h.

◆ fn_ref

FileName ProgAngularProjectionMatching::fn_ref

Definition at line 70 of file angular_projection_matching.h.

◆ fP_img

Polar<std::complex<double> > * ProgAngularProjectionMatching::fP_img

Definition at line 104 of file angular_projection_matching.h.

◆ fP_ref

Polar<std::complex<double> >* ProgAngularProjectionMatching::fP_ref

Array with Polars of references and of translated images and their mirrors

Definition at line 104 of file angular_projection_matching.h.

◆ fPm_img

Polar<std::complex<double> > * ProgAngularProjectionMatching::fPm_img

Definition at line 104 of file angular_projection_matching.h.

◆ global_plans

Polar_fftw_plans ProgAngularProjectionMatching::global_plans

Global plans for fftw transformers of all polar rings

Definition at line 108 of file angular_projection_matching.h.

◆ ids

std::vector<size_t> ProgAngularProjectionMatching::ids

Array containing the images ids in metadata

Definition at line 102 of file angular_projection_matching.h.

◆ loop_forward_refs

bool ProgAngularProjectionMatching::loop_forward_refs

Flag whether to loop from low to high or from high to low through the references

Definition at line 115 of file angular_projection_matching.h.

◆ max_nr_imgs_in_memory

int ProgAngularProjectionMatching::max_nr_imgs_in_memory

Maximum number of references that can be stored in memory The difference between this and the previous varible is that the previous one is the MIN(max_nr_refs_in_memory, number of references)

Definition at line 91 of file angular_projection_matching.h.

◆ max_nr_refs_in_memory

int ProgAngularProjectionMatching::max_nr_refs_in_memory

Maximum number of references to store in memory

Definition at line 86 of file angular_projection_matching.h.

◆ max_shift

double ProgAngularProjectionMatching::max_shift

Maximum allowed shift

Definition at line 80 of file angular_projection_matching.h.

◆ Mctf

MultidimArray<double> ProgAngularProjectionMatching::Mctf

CTF image

Definition at line 123 of file angular_projection_matching.h.

◆ mysampling

Sampling ProgAngularProjectionMatching::mysampling

sampling object

Definition at line 112 of file angular_projection_matching.h.

◆ nr_trans

size_t ProgAngularProjectionMatching::nr_trans

Number of translations in 5D search

Definition at line 131 of file angular_projection_matching.h.

◆ numOrientations

int ProgAngularProjectionMatching::numOrientations

Definition at line 129 of file angular_projection_matching.h.

◆ pad

double ProgAngularProjectionMatching::pad

Padding factor (only for applying CTF to references)

Definition at line 78 of file angular_projection_matching.h.

◆ paddim

size_t ProgAngularProjectionMatching::paddim

Definition at line 76 of file angular_projection_matching.h.

◆ phase_flipped

bool ProgAngularProjectionMatching::phase_flipped

Are the experimental images phase flipped?

Definition at line 125 of file angular_projection_matching.h.

◆ pointer_allrefs2refsinmem

std::vector<int> ProgAngularProjectionMatching::pointer_allrefs2refsinmem

Pointers for reference retrieval

Definition at line 97 of file angular_projection_matching.h.

◆ pointer_refsinmem2allrefs

std::vector<int> ProgAngularProjectionMatching::pointer_refsinmem2allrefs

Definition at line 98 of file angular_projection_matching.h.

◆ progress_bar_step

int ProgAngularProjectionMatching::progress_bar_step

Progress bar

Definition at line 142 of file angular_projection_matching.h.

◆ proj_ref

MultidimArray<double>* ProgAngularProjectionMatching::proj_ref

Array with reference images

Definition at line 106 of file angular_projection_matching.h.

◆ Ri

int ProgAngularProjectionMatching::Ri

Inner and outer radii to limit the rotational search

Definition at line 82 of file angular_projection_matching.h.

◆ Ro

int ProgAngularProjectionMatching::Ro

Definition at line 82 of file angular_projection_matching.h.

◆ scale_nsteps

double ProgAngularProjectionMatching::scale_nsteps

Definition at line 139 of file angular_projection_matching.h.

◆ scale_step

double ProgAngularProjectionMatching::scale_step

Definition at line 138 of file angular_projection_matching.h.

◆ search5d_shift

int ProgAngularProjectionMatching::search5d_shift

5D-search: maximum offsets (+/- pixels)

Definition at line 117 of file angular_projection_matching.h.

◆ search5d_step

int ProgAngularProjectionMatching::search5d_step

5D-search: offset step (pixels)

Definition at line 119 of file angular_projection_matching.h.

◆ search5d_xoff

std::vector<int> ProgAngularProjectionMatching::search5d_xoff

5D-search: actual displacement vectors

Definition at line 121 of file angular_projection_matching.h.

◆ search5d_yoff

std::vector<int> ProgAngularProjectionMatching::search5d_yoff

Definition at line 121 of file angular_projection_matching.h.

◆ stddev_img

double * ProgAngularProjectionMatching::stddev_img

Definition at line 110 of file angular_projection_matching.h.

◆ stddev_ref

double* ProgAngularProjectionMatching::stddev_ref

vector with stddevs for all reference projections

Definition at line 110 of file angular_projection_matching.h.

◆ thread_barrier

barrier_t ProgAngularProjectionMatching::thread_barrier

Thread barrier

Definition at line 133 of file angular_projection_matching.h.

◆ threads

int ProgAngularProjectionMatching::threads

Threads

Definition at line 127 of file angular_projection_matching.h.

◆ total_nr_refs

int ProgAngularProjectionMatching::total_nr_refs

Total number of references

Definition at line 93 of file angular_projection_matching.h.


The documentation for this class was generated from the following files: