60 addUsageLine(
"This function takes a volume and a set of projections with orientations. The volume is projected into the set of projection directions defining the " 61 "the reference projections. Thus, using the projections and references, calculation of the particle alignment precision and accuracy is carried out");
62 addParamsLine(
" [ -i <md_file> ] : Input metadata with images and their angles to be validated against the volume");
63 addParamsLine(
" [ -i2 <md_file> ] : Input metadata of reference particles obtained projecting the volume at the same orientations that the input particles");
64 addParamsLine(
" [--volume <md_file=\"\">] : Input volume to be validated");
65 addParamsLine(
" [--angles_file <file=\".\">] : Input metadata with particle projections at several orientations from (usually) Significant");
66 addParamsLine(
" [--angles_file_ref <file=\".\">] : Input reference metadata with projections and orientations obtained projecting the volume at the several orientations from (usually) Significant");
67 addParamsLine(
" [--gallery <file=\".\">] : Reference Gallery of projections ");
68 addParamsLine(
" [--sym <symfile=c1>] : Enforce symmetry in projections");
69 addParamsLine(
" [--odir <outputDir=\".\">] : Output directory");
70 addParamsLine(
" [--check_mirrors] : Correct for mirrors in the alignment precision and accuracy estimation. In this case the precision of the projection axis without direction is computed");
71 addParamsLine(
" [--dontUseWeights] : Do not use the particle weigths in the clusterability calculation ");
81 MetaDataDb mdExp, mdExpSort, mdProj, mdGallery, mdInputParticles, mdInputParticlesRef;
84 fnOutCL =
fnDir+
"/pruned_particles_alignability.xmd";
85 fnOutQ =
fnDir+
"/validationAlignability.xmd";
96 size_t sz = mdExp.
size();
102 double validationAlignabilityPrecision, validationAlignabilityAccuracy, validationAlignability, validationMirror;
103 validationAlignabilityPrecision = 0;
104 validationAlignabilityAccuracy = 0;
105 validationAlignability = 0;
106 validationMirror = 0;
115 double error_mirror_exp;
116 double error_mirror_proj;
121 error_mirror_exp = 0;
122 error_mirror_proj = 0;
126 size_t numProjs = tempMdExp.
size();
130 calc_sumw2(numProjs, sum_noise, mdGallery);
132 double rankPrec = 0.;
133 double rankAccNoMirror = 0.;
134 double rankAccMirror = 0.;
136 double accuracy = 0.;
137 double accuracyRef = 0.;
138 double accuracyMirror = 0.;
139 double accuracyMirrorRef = 0.;
143 for (
size_t i=0;
i<=maxNImg;
i++)
150 mdInputParticles.
getRow(rowInput,
i+1);
151 mdInputParticles.
getRow(rowInputRef,
i+1);
154 if ( (tempMdExp.
size()==0) || (tempMdProj.
size()==0))
157 calc_sumu(tempMdExp, sum_w_exp, error_mirror_exp);
158 calc_sumu(tempMdProj, sum_w_proj, error_mirror_proj);
160 obtainAngularAccuracy(tempMdExp, rowInput, accuracy, accuracyMirror);
161 obtainAngularAccuracy(tempMdProj, rowInputRef, accuracyRef, accuracyMirrorRef);
165 std::cout <<
" " << std::endl;
166 std::cout <<
"accuracy " << accuracy << std::endl;
167 std::cout <<
"accuracyRef " << accuracyRef << std::endl;
168 std::cout <<
"accuracy2f " << accuracyRef/accuracy << std::endl;
175 rankPrec = 1/(sum_w_proj-sum_noise)*(sum_w_exp-sum_noise);
176 rankAccMirror = 1/(accuracyRef-sum_noise)*(accuracy-sum_noise);
177 rankAccNoMirror = 1/(accuracyMirrorRef-sum_noise)*(accuracyMirror-sum_noise);
218 validationAlignabilityPrecision += (rankPrec>0.5);
219 validationAlignabilityAccuracy += (rankAccMirror > 0.5);
220 validationAlignability += ( (rankAccMirror > 0.5) && (rankPrec>0.5));
221 validationMirror += (rankAccNoMirror> 0.5);
225 validationAlignabilityPrecision /= (maxNImg+1);
226 validationAlignabilityAccuracy /= (maxNImg+1);
227 validationAlignability /= (maxNImg+1);
228 validationMirror /= (maxNImg+1);
237 mdOutQ.
write(fnOutQ);
244 void MultireferenceAligneability::write_projection_file()
250 std::ofstream myfile;
251 myfile.open(filnam.c_str());
252 myfile <<
"# XMIPP_STAR_1 *\n";
254 myfile <<
"data_block1 \n";
255 myfile <<
"_dimensions2D '"+xdim+
" "+ydim+
"' \n";
256 myfile <<
"_projAngleFile "+
fin+
" \n";
257 myfile <<
"_noisePixelLevel '0 0' \n";
261 void MultireferenceAligneability::calc_sumu(
const MetaData & tempMd,
double & sum_W,
double & mirrorProb)
264 double rotRef,tiltRef,psiRef, wRef;
275 for (
size_t objId : tempMd.
ids())
282 for (
size_t objId2 : tempMd.
ids())
293 std::cout << xx <<
" " << yy <<
" " << zz <<
" " << mirror << std::endl;
320 std::cout << sum_W << std::endl;
329 void MultireferenceAligneability::calc_sumw(
const size_t num,
double & sumw)
332 double xRan,yRan,zRan;
334 auto * xRanArray =
new double[num];
335 auto * yRanArray =
new double[num];
336 auto * zRanArray =
new double[num];
340 for (
size_t n=0;
n < trials;
n++)
342 for (
size_t nS=0; nS<num; nS++)
351 x = 2*(double(std::rand())-RAND_MAX/2)/RAND_MAX;
352 y = 2*(double(std::rand())-RAND_MAX/2)/RAND_MAX;
354 while (x*x+y*y >= 1 )
356 x = 2*(std::rand()-RAND_MAX/2)/RAND_MAX;
357 y = 2*(std::rand()-RAND_MAX/2)/RAND_MAX;
364 xRanArray[nS] = xRan;
365 yRanArray[nS] = yRan;
366 zRanArray[nS] = zRan;
370 for (
size_t nS1=0; nS1<num; nS1++)
373 for (
size_t nS2=0; nS2<num; nS2++)
375 a =
std::abs(std::acos(xRanArray[nS1]*xRanArray[nS2]+yRanArray[nS1]*yRanArray[nS2]+zRanArray[nS1]*zRanArray[nS2]));
392 void MultireferenceAligneability::calc_sumw2(
const size_t num,
double & sumw,
const MetaData & mdGallery)
395 const size_t numGallery= mdGallery.
size()+1;
396 const double trials = 500;
398 auto * indxArray =
new size_t[numGallery];
400 auto * rotArray =
new double[num];
401 auto * tiltArray =
new double[num];
402 auto * psiArray =
new double[num];
406 if (numGallery < num)
407 REPORT_ERROR(
ERR_ARG_INCORRECT,
"The gallery size is smaller than the number of orientations per particle. Increase the angular sampling of the gallery");
409 for (
size_t n=0;
n<trials;
n++)
411 size_t currentIndx = 0;
413 for (
size_t i=1;
i<numGallery;
i++)
416 while ( currentIndx < num )
418 indx = (size_t) (
double( std::rand())*(numGallery-1))/RAND_MAX+1;
420 while ( (indx == 0) || (indxArray[indx] == -1) )
421 indx = (size_t) (
double( std::rand())*(numGallery-1))/RAND_MAX;
423 indxArray[indx] = -1;
429 rotArray[currentIndx] = rot;
430 tiltArray[currentIndx] = tilt;
431 psiArray[currentIndx] =
psi;
438 for (
int var = 0; var < num; var++)
440 std::cout << rotArray[var] <<
" " << tiltArray[var] <<
" " << psiArray[var] << std::endl;
450 for (
size_t nS1=0; nS1<num; nS1++)
452 for (
size_t nS2=0; nS2<num; nS2++)
462 sumw = ( sumWRan / (trials*(num-1)*(num-1)) );
466 std::cout <<
" " << std::endl;
467 std::cout <<
" sumw : " << sumw << std::endl;
468 std::cout <<
" " << std::endl;
481 void MultireferenceAligneability::obtainAngularAccuracy(
const MetaData & tempMd,
const MDRow & row,
double & accuracy,
double & accuracyMirror)
483 double rot, tilt,
psi,
w;
484 double rotAux, tiltAux, psiAux;
485 double rotRef, tiltRef, psiRef, wRef;
488 double tempAccuracy, tempAccuracyMirror;
502 for (
size_t objId : tempMd.
ids())
526 rot, tilt, psi,
true,
true,
false);
528 accuracy += tempAccuracy*
w;
529 accuracyMirror += tempAccuracyMirror*
w;
533 std::cout <<
" tempAccuracy : " <<
" " << tempAccuracy <<
" " << std::endl;
534 std::cout <<
" tempAccuracyMirror: " << tempAccuracyMirror << std::endl;
541 std::cout << tilt <<
" " << rot <<
" " << std::endl;
542 std::cout <<
"weight: " << w <<
" " <<
"arco: " << tempAccuracy/(
w) <<
" " << std::endl;
549 accuracyMirror /= sumOfW;
552 std::cout <<
" accuracy : " <<
" " << accuracy <<
" " << std::endl;
553 std::cout <<
" accuracyMirror: " << accuracyMirror << std::endl;
554 std::cout <<
"-------------" << std::endl;
563 std::cout <<
" " << std::endl;
564 std::cout << accuracy << std::endl;
565 std::cout <<
"-----------" << std::endl;
void init_progress_bar(long total)
#define REPORT_ERROR(nerr, ErrormMsg)
void sqrt(Image< double > &op)
MultireferenceAligneability()
int readSymmetryFile(FileName fn_sym, double accuracy=SYM_ACCURACY)
void abs(Image< double > &op)
String integerToString(int I, int _width, char fill_with)
double computeDistance(double rot1, double tilt1, double psi1, double &rot2, double &tilt2, double &psi2, bool projdir_mode, bool check_mirrors, bool object_rotation=false, bool write_mirrors=true)
T & getValue(MDLabel label)
const char * getParam(const char *param, int arg=0)
void setValue(const MDObject &object) override
Incorrect argument received.
void progress_bar(long rlen)
MetaDataDb mdPartialParticles
double psi(const double x)
String formatString(const char *format,...)
bool checkParam(const char *param)
void addUsageLine(const char *line, bool verbatim=false)
unsigned int randomize_random_generator()
void addParamsLine(const String &line)