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).");
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 ");
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");
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");
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");
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");
130 <<
" Input images : "<<
fn_exp << std::endl
131 <<
" Output file : "<<
fn_out << std::endl
134 std::cout <<
" Inner radius rot-search : " <<
Ri<< std::endl;
136 std::cout <<
" Outer radius rot-search : " <<
Ro << std::endl;
139 std::cout <<
" Number of references : " <<
total_nr_refs << std::endl
145 std::cout <<
" Number of references : " <<
total_nr_refs <<
" (all stored in memory)" << std::endl;
147 std::cout <<
" Max. allowed shift : +/- " <<
max_shift<<
" pixels"<<std::endl;
150 std::cout <<
" 5D-search shift range : "<<
search5d_shift<<
" pixels (sampled "<<
nr_trans<<
" times)"<<std::endl;
156 std::cout <<
" CTF image : " <<
fn_ctf<<std::endl;
158 std::cout <<
" Padding factor : "<<
pad << std::endl;
162 std::cout <<
" CTF parameter file : " <<
fn_ctf<<std::endl;
164 std::cout <<
" + Assuming images have been phase flipped " << std::endl;
166 std::cout <<
" + Assuming images have not been phase flipped " << std::endl;
171 std::cout <<
" -> Using "<<
threads<<
" parallel threads"<<std::endl;
175 std::cout <<
" -> Using "<<
numOrientations<<
" possible orientations for each particle"<<std::endl;
178 std::cout <<
" ================================================================="<<std::endl;
194 std::cout <<
"done!"<<std::endl;
226 String blockName =
"all_exp_images";
232 rightFn.
compose(blockName, inputFn);
233 MetaDataRight.
read(rightFn);
259 if (!imgRef().sameShape(img()))
261 "Check that the reference volume and the experimental images are of the same size");
281 double memory_per_ref = 0.;
284 memory_per_ref += (double) fP.
getSampleNo(
i) * 2 *
sizeof(double);
286 memory_per_ref += dim * dim *
sizeof(double);
296 std::cerr <<
"XXXXmysampling.no_redundant_sampling_points_indexXXXXXX" <<std::endl;
297 for (std::vector<size_t>::iterator
i =
301 std::cerr << *
i <<
" ";
302 std::cerr << std::endl;
303 std::cerr <<
"exit" <<std::endl;
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");
335 for (
int xoff = -myfinal; xoff <= myfinal; xoff+=
search5d_step)
337 for (
int yoff = -myfinal; yoff <= myfinal; yoff+=
search5d_step)
360 catch (std::bad_alloc&)
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");
388 "ERROR!! Only non-astigmatic CTFs are allowed!");
433 img().setXmippOrigin();
438 double rot_tmp,tilt_tmp,psi_tmp;
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;
452 std::cerr << std::endl;
465 img().selfWindow(x0, x0, xF,xF);
479 img().selfWindow(x0, x0, xF,xF);
508 std::cerr<<
"counter= "<<counter<<
"refno= "<<refno<<
" stddev = "<<stddev;
511 std::cerr <<
"pointer_allrefs2refsinmem" <<std::endl;
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();
521 std::cerr << *
i <<
" ";
522 std::cerr <<std::endl;
535 size_t thread_id = thread_data->thread_id;
537 size_t thread_num = prm->
threads;
539 size_t &this_image = thread_data->this_image;
542 int *opt_refno = thread_data->opt_refno;
543 double *opt_psi = thread_data->opt_psi;
544 bool *opt_flip = thread_data->opt_flip;
545 double *maxcorr = thread_data->maxcorr;
551 size_t myinit, myfinal, myincr;
553 bool done_once=
false;
574 for (
size_t itrans = myinit; itrans < prm->
nr_trans; itrans+=myincr)
581 if (itrans == myinit)
629 for (
size_t i = myinit;
i != myfinal;
i += myincr)
631 if (
i%thread_num == thread_id)
636 std::cerr<<
" thread_id= "<<thread_id<<
" i= "<<
i<<
" "<<myinit<<
" "<<myfinal<<
" "<<myincr<<std::endl;
649 std::cerr <<
"XXXXpointer_allrefs2refsinmemXXXXXX" <<std::endl;
650 for (std::vector<int>::iterator
i = prm->
654 std::cerr << *
i << std::endl;
655 std::cerr <<
"XXXXpointer_refsinmem2allrefsXXXXXX" <<std::endl;
656 for (std::vector<int>
660 std::cerr << *
i << std::endl;
661 std::cerr <<std::endl;
681 std::cerr <<
"imgno " << imgno <<std::endl;
682 std::cerr<<
"Got refno= "<<refno
687 for (
size_t itrans = 0; itrans < prm->
nr_trans; itrans++)
691 std::cerr<<
"prm->stddev_ref[refno], prm->stddev_img[itrans]: " <<
707 memcpy(&
dAi(allCorr,0),&
dAi(corr,0),
XSIZE(corr)*
sizeof(
double));
708 memcpy(&
dAi(allAng,0),&
dAi(ang,0),
XSIZE(ang)*
sizeof(
double));
716 double bestLastCorr = 99e99;
717 for (
size_t n = 0;
n < nIter;
n++)
719 for (
size_t k = 0;
k <
XSIZE(allCorr);
k++)
734 bestLastCorr = maxcorr[
n];
739 std::cerr<<
"mirror: corr "<<maxcorr;
742 std::cerr<<std::endl;
749 std::cerr <<
"DEBUG_ROB, imgno:" << imgno << std::endl;
750 std::cerr <<
"DEBUG_ROB, i:" <<
i << std::endl;
751 std::cerr <<
"DEBUG_ROB, prm->mysampling.my_neighbors[imgno][i]:" << prm->
mysampling.
my_neighbors[imgno][
i] << std::endl;
752 std::cerr<<
"straight: corr "<<maxcorr<<std::endl;
763 std::cerr<<
" rotal%% "<<total_rot
764 <<
" => prep: "<<prepare_img
765 <<
" all_refs: "<<all_rot_align
766 <<
" (of which "<<get_refs
768 <<
" refs for imgno "<<imgno<<
" )" 777 const int &opt_refno,
778 const double &opt_psi,
779 const bool &opt_flip,
799 std::cerr<<
"start trans: opt_refno= "<<opt_refno<<
" pointer= "<<
pointer_allrefs2refsinmem[opt_refno]<<
" opt_psi= "<<opt_psi<<
"opt_flip= "<<opt_flip<<std::endl;
817 std::cerr<<
"rotated ref "<<std::endl;
837 bestShift(Mref,Mimg,opt_xoff,opt_yoff,aux);
840 opt_xoff = opt_yoff = 0.;
842 opt_xoff = opt_yoff = 0.;
846 std::cerr<<
"optimal shift "<<opt_xoff<<
" "<<opt_yoff<<std::endl;
855 std::cerr<<
"optimal shift corr "<<maxcorr<<std::endl;
865 std::cerr<<
" trans%% "<<total_trans <<std::endl;
872 const int &opt_refno,
873 const double &opt_psi,
874 const bool &opt_flip,
875 const double &opt_xoff,
876 const double &opt_yoff,
877 const double &old_scale,
900 double ang, cosine, sine;
945 while(scale <= 1 + 0.01 *
scale_step * scale_nsteps)
956 Mscale = Mscale / (scale * scale * old_scale * old_scale);
972 std::cerr<<
" trans%% "<<total_trans <<std::endl;
980 size_t total_number_of_images =
DFexp.
size();
1014 size_t nr_images = imagesToProcess.size();
1015 size_t idNew, imgid;
1019 auto * th_ids = (pthread_t *)malloc(
threads *
sizeof( pthread_t));
1035 for (
size_t imgno = 0; imgno < nr_images; imgno++)
1037 imgid = imagesToProcess[imgno];
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;
1051 threads_d[
c].maxcorr[
i] = -99.e99;
1052 threads_d[
c].opt_refno[
i] = -1;
1060 pthread_join(*(th_ids+
c),
nullptr);
1063 auto * indexThreads =
new int[
threads]();
1064 size_t bestThreadCorr = 0;
1066 size_t counterValidCorrs = 0;
1067 bool validCorr =
false;
1074 if (threads_d[
c].maxcorr[indexThreads[
c]] > tempCorr)
1078 counterValidCorrs++;
1083 tempCorr = threads_d[
c].maxcorr[indexThreads[
c]];
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]++;
1098 if (opt_refno[
n]>=0)
1110 delete[] indexThreads;
1116 std::cerr <<
"DEBUG_ROB, img.name():" << img.
name() << std::endl;
1120 for(
int n=0;
n < counterValidCorrs;
n++)
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]);
1140 opt_scale[
n] *= img.
scale();
1145 opt_xoff[
n] += img.
Xoff();
1146 opt_yoff[
n] += img.
Yoff();
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);
1206 img().setXmippOrigin();
1210 double shiftX=0., shiftY=0.;
int barrier_init(barrier_t *barrier, int needed)
void init_progress_bar(long total)
Polar_fftw_plans global_plans
std::vector< int > pointer_allrefs2refsinmem
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
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)
WriteModeMetaData do_overwrite
void setScale(double scale, const size_t n=0)
void getCurrentReference(int refno, Polar_fftw_plans &local_plans)
double getDoubleParam(const char *param, int arg=0)
std::vector< int > search5d_xoff
#define REPORT_ERROR(nerr, ErrormMsg)
pthread_mutex_t update_refs_in_memory_mutex
#define FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY2D(m)
virtual void writeOutputFiles()
void resizeNoCopy(const MultidimArray< T1 > &v)
int getSampleNoOuterRing() const
double DeltafV
Defocus in V (in Angstroms). Negative values are underfocused.
void rotationalCorrelation(const Polar< std::complex< double > > &M1, const Polar< std::complex< double > > &M2, MultidimArray< double > &angles, RotationalCorrelationAux &aux)
virtual void readParams()
Read arguments from command line.
std::vector< size_t > ids
void processSomeImages(const std::vector< size_t > &imagesToProcess)
double correlationIndex(const MultidimArray< T > &x, const MultidimArray< T > &y, const MultidimArray< int > *mask=NULL, MultidimArray< double > *Contributions=NULL)
std::vector< int > search5d_yoff
void computeAverageAndStddev(double &avg, double &stddev, int mode=FULL_CIRCLES) const
virtual void defineParams()
Define arguments accepted.
MultidimArray< double > * proj_ref
void compose(const String &str, const size_t no, const String &ext="")
int getSampleNo(int iring) const
void inv(Matrix2D< T > &result) const
const FileName & name() const
double elapsed_time(ProcessorTimeStamp &time, bool _IN_SECS)
Polar< std::complex< double > > * fP_ref
FileName removeAllExtensions() const
Incorrect MultidimArray size.
virtual void produceSideInfo()
Bad amount of memory requested.
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
#define rotate(a, i, j, k, l)
void addSeeAlsoLine(const char *seeAlso)
void read(const FileName &fn, bool disable_if_not_K=true)
void * threadRotationallyAlignOneImage(void *data)
double DeltafU
Global gain. By default, 1.
bool enable_CTF
Enable CTF part.
#define MAT_ELEM(m, i, j)
void setShifts(double xoff, double yoff, double zoff=0., const size_t n=0)
#define DIRECT_A1D_ELEM(v, i)
std::vector< size_t > no_redundant_sampling_points_index
pthread_mutex_t debug_mutex
const char * getParam(const char *param, int arg=0)
size_t numberSamplesAsymmetricUnit
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)
void setFlip(bool flip, const size_t n=0)
double Yoff(const size_t n=0) const
void progress_bar(long rlen)
void getEulerAngles(double &rot, double &tilt, double &psi, const size_t n=0) const
double scale(const size_t n=0) const
void addExampleLine(const char *example, bool verbatim=true)
Matrix1D< double > vectorR2(double x, double y)
int verbose
Verbosity level.
virtual void processAllImages()
void translationallyAlignOneImage(MultidimArray< double > &img, const int &samplenr, const double &psi, const bool &opt_flip, double &opt_xoff, double &opt_yoff, double &maxcorr)
Polar< std::complex< double > > * fPm_img
int max_nr_refs_in_memory
int max_nr_imgs_in_memory
std::vector< std::vector< size_t > > my_neighbors
void fourierTransformRings(Polar< double > &in, Polar< std::complex< double > > &out, Polar_fftw_plans &plans, bool conjugated)
void generateCTF(const MultidimArray< T1 > &sample_image, MultidimArray< T2 > &CTF, double Ts=-1)
void getCurrentImage(size_t imgid, Image< double > &img)
void setEulerAngles(double rot, double tilt, double psi, const size_t n=0)
void readSamplingFile(const FileName &infilename, bool read_vectors=true, bool read_sampling_sphere=false)
std::vector< Matrix1D< double > > no_redundant_sampling_points_angles
bool isMetaData(bool failIfNotExists=true) const
FileName removeBlockName() const
void translate(PDB *pdb_original, PDB *pdb_move, unsigned num_atoms, double x0, double y0, double z0)
Polar< std::complex< double > > * fP_img
FourierTransformer local_transformer
std::vector< int > pointer_refsinmem2allrefs
#define FIRST_XMIPP_INDEX(size)
std::vector< size_t > convert_refno_to_stack_position
void produceSideInfo()
Produce Side information.
double Xoff(const size_t n=0) const
int counter_refs_in_memory
template float bestShift(MultidimArray< float > &, float &, float &, const MultidimArray< int > *, int)
bool checkParam(const char *param)
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)
void addUsageLine(const char *line, bool verbatim=false)
MultidimArray< double > Mctf
void annotate_time(TimeStamp *time)
#define LAST_XMIPP_INDEX(size)
int barrier_wait(barrier_t *barrier)
int getIntParam(const char *param, int arg=0)
void calculateFftwPlans(Polar_fftw_plans &out)
Incorrect value received.
void addParamsLine(const String &line)