42 addUsageLine(
"Generate 3D reconstructions from projections using random orientations");
44 addParamsLine(
" -i <md_file> : Metadata file with input projections");
45 addParamsLine(
" [--numberOfVolumes <N=1>] : Number of volumes to reconstruct");
46 addParamsLine(
" [--initvolumes <md_file=\"\">] : Set of initial volumes. If none is given, a single volume");
47 addParamsLine(
" : is reconstructed with random angles assigned to the images");
48 addParamsLine(
" [--initgallery <md_file=\"\">] : Gallery of projections from a single volume");
49 addParamsLine(
" [--odir <outputDir=\".\">] : Output directory");
50 addParamsLine(
" [--sym <symfile=c1>] : Enforce symmetry in projections");
54 addParamsLine(
" [--keepIntermediateVolumes] : Keep the volume of each iteration");
55 addParamsLine(
" [--angularSampling <a=5>] : Angular sampling in degrees for generating the projection gallery");
56 addParamsLine(
" [--maxShift <s=-1>] : Maximum shift allowed (+-this amount)");
60 addParamsLine(
" [--strictDirection] : Images not significant for a direction are also discarded");
62 addParamsLine(
" [--dontApplyFisher] : Do not select directions using Fisher");
64 addParamsLine(
" [--useForValidation <numOrientationsPerParticle=10>] : Use the program for validation. This number defines the number of possible orientations per particle");
65 addParamsLine(
" [--dontCheckMirrors] : Don't check mirrors in the alignment process");
98 std::cout <<
"Setting iterations to 1 because of --dontReconstruct\n";
108 std::cout <<
"Input metadata : " <<
fnIn << std::endl;
109 std::cout <<
"Output directory : " <<
fnDir << std::endl;
110 std::cout <<
"Initial significance : " <<
alpha0 << std::endl;
111 std::cout <<
"Final significance : " <<
alphaF << std::endl;
112 std::cout <<
"Number of iterations : " <<
Niter << std::endl;
115 std::cout <<
"Maximum shift : " <<
maxShift << std::endl;
116 std::cout <<
"Minimum tilt : " <<
tilt0 << std::endl;
117 std::cout <<
"Maximum tilt : " <<
tiltF << std::endl;
118 std::cout <<
"Use Imed : " <<
useImed << std::endl;
119 std::cout <<
"Angular distance : " <<
angDistance << std::endl;
120 std::cout <<
"Apply Fisher : " <<
applyFisher << std::endl;
127 std::cout <<
"Symmetry for projections : " <<
fnSym << std::endl;
131 std::cout <<
"Initial volume : " <<
fnInit << std::endl;
133 std::cout <<
"Number of volumes : " <<
Nvolumes << std::endl;
152 std::vector< Matrix2D<double> > allM;
158 for (
size_t nvol=0; nvol<Nvols; ++nvol)
174 std::cout <<
"Current significance: " << one_alpha << std::endl;
175 std::cerr <<
"Aligning images ...\n";
180 for (
auto& row :
mdIn)
184 mdIn.getValue(
MDL_IMAGE,fnImg, row.id());
186 std::cout <<
"Processing: " << fnImg << std::endl;
193 double bestCorr=-2, bestRot, bestTilt, bestImed=1e38, worstImed=-1e38;
198 for (
size_t nVolume=0; nVolume<Nvols; ++nVolume)
201 for (
size_t nDir=0; nDir<Ndirs; ++nDir)
203 mCurrentImageAligned=mCurrentImage;
209 mCurrentImageAligned,M,aux,aux2,aux3,xmipp_transformation::DONT_WRAP);
211 corr =
alignImages(mGalleryProjection, mCurrentImageAligned,
212 M, xmipp_transformation::DONT_WRAP);
217 double scale, shiftX, shiftY, anglePsi;
221 double imed=
imedDistance(mGalleryProjection, mCurrentImageAligned);
244 size_t idx=nVolume*Ndirs+nDir;
253 bestVolume=(int)nVolume;
261 else if (imed>worstImed)
269 double scale, shiftX, shiftY, anglePsi;
277 size_t recId=mdProjectionMatching.
addRow(dynamic_cast<MDRowSql&>(row));
289 double rl=bestCorr*one_alpha;
290 double z=0.5*
log((1+rl)/(1-rl));
295 imgcc.cumlativeDensityFunction(cdfcc);
299 size_t firstVolume=0;
300 size_t lastVolume=Nvols-1;
303 for (
size_t nVolume=firstVolume; nVolume<=lastVolume; ++nVolume)
306 for (
size_t nDir=0; nDir<Ndirs; ++nDir)
308 size_t idx=nVolume*Ndirs+nDir;
321 condition=condition && cdfccthis>=one_alpha;
336 double thisWeight=cdfccthis*(cc/bestCorr);
339 thisWeight*=(1-cdfimedthis)*(bestImed/imed);
341 double angleRot=
mdGallery[nVolume][nDir].rot;
342 double angleTilt=
mdGallery[nVolume][nDir].tilt;
344 std::cout <<
" Getting Gallery: " <<
mdGallery[nVolume][nDir].fnImg
345 <<
" corr=" << cc <<
" imed=" << imed <<
" bestImed=" << bestImed <<
" weight=" << thisWeight <<
" rot=" << angleRot
346 <<
" tilt=" << angleTilt << std::endl
347 <<
" weight by corr=" << cdfccthis*(cc/bestCorr) <<
" weight by imed=" << (1-cdfimedthis)*(bestImed/imed) << std::endl
348 <<
"Matrix=" << allM[nVolume*Ndirs+nDir] << std::endl
349 <<
"shiftX=" << shiftX <<
" shiftY=" << shiftY << std::endl;
352 size_t recId=mdPartial.
addRow(dynamic_cast<MDRowSql&>(row));
371 std::cout <<
"Press any key" << std::endl;
372 char c; std::cin >>
c;
403 std::vector<double> ccdirNeighbourhood;
404 ccdirNeighbourhood.
resize(10*Nimgs);
405 bool emptyVolumes=
false;
410 std::cout <<
"\nIteration " <<
iter << std::endl;
437 std::cerr <<
"Readjusting weights ..." << std::endl;
439 for (
size_t nVolume=0; nVolume<Nvols; ++nVolume)
441 for (
size_t nDir=0; nDir<Ndirs; ++nDir)
445 ccdirNeighbourhood.clear();
446 for (
size_t nImg=0; nImg<Nimgs; ++nImg)
449 ccdirNeighbourhood.push_back(ccimg);
456 for (
size_t nDir2=0; nDir2<Ndirs; ++nDir2)
464 for (
size_t nImg=0; nImg<Nimgs; ++nImg)
467 ccdirNeighbourhood.push_back(ccimg);
475 ccdir=ccdirNeighbourhood;
479 double iBestCorr=1.0/bestCorr;
480 for (
size_t nImg=0; nImg<Nimgs; ++nImg)
498 for (
size_t nVolume=0; nVolume<(size_t)
Nvolumes; ++nVolume)
502 for (
size_t objId : mdReconstruction.
ids())
517 if (mdReconstruction.
size()>0)
522 mdAux.
write(fnAngles);
525 std::cout <<
formatString(
"%s/angles_iter%03d_%02d.xmd is empty. Not written.",
fnDir.c_str(),
iter,nVolume) << std::endl;
533 mdPM.
write(fnImages);
538 String cmd=(
String)
"xmipp_metadata_utilities -i "+fnAngles+
" --operate keep_column image -o "+fnAux;
539 if (system(cmd.c_str())!=0)
542 cmd=(
String)
"xmipp_metadata_utilities -i "+fnAux+
" --operate remove_duplicates image";
543 if (system(cmd.c_str())!=0)
547 cmd=(
String)
"xmipp_metadata_utilities -i "+fnImages+
" --set intersection "+fnAux+
" image image -o "+fnImagesSignificant;
548 if (system(cmd.c_str())!=0)
553 std::cout <<
formatString(
"%s/images_iter%03d_%02d.xmd empty. Not written.",
fnDir.c_str(),
iter,nVolume) << std::endl;
592 std::cerr <<
"Reconstructing volumes ..." << std::endl;
594 for (
size_t nVolume=0; nVolume<(size_t)
Nvolumes; ++nVolume)
603 std::cout <<
"Volume " << nVolume <<
": number of images=" << MD.
size() << std::endl;
605 String args=
formatString(
"-i %s -o %s --sym %s --weight -v 0",fnAngles.c_str(),fnVolume.c_str(),
fnSym.c_str());
607 std::cout << cmd << std::endl;
608 if (system(cmd.c_str())==-1)
614 cmd=(
String)
"xmipp_transform_symmetrize "+args;
615 std::cout << cmd << std::endl;
616 if (system(cmd.c_str())==-1)
620 args=
formatString(
"-i %s --mask circular -%d -v 0",fnVolume.c_str(),
Xdim/2);
621 cmd=(
String)
"xmipp_transform_mask "+args;
622 std::cout << cmd << std::endl;
623 if (system(cmd.c_str())==-1)
630 FileName fnGallery, fnGalleryMetaData;
643 String args=
formatString(
"-i %s -o %s --sampling_rate %f --sym %s --compute_neighbors --angular_distance -1 --experimental_images %s --min_tilt_angle %f --max_tilt_angle %f -v 0",
646 String cmd=(
String)
"xmipp_angular_project_library "+args;
647 if (system(cmd.c_str())==-1)
654 std::vector<GalleryImage> galleryNames;
674 galleryNames.clear();
675 for (
size_t objId : mdAux.
ids())
693 for (
size_t k=0;
k<kmax; ++
k)
699 XSIZE(mGalleryProjection) / 5,
XSIZE(mGalleryProjection) / 2, aux2.
plans, 1);
707 auto number_of_projections = (double)
mdGallery[0].size();
734 std::cout <<
" Changing angular sampling to " <<
angularSampling << std::endl;
735 std::cout <<
" Number of projections taking into account angular sampling and symmetry " << number_of_projections << std::endl;
736 std::cout <<
" changing alpha0 to " <<
alpha0 << std::endl;
754 size_t Ydim,Zdim,Ndim;
765 REPORT_ERROR(
ERR_ARG_INCORRECT,
"Alpha values are too large: reduce the error such that the error times the symmetry number is smaller than 1");
770 bool deleteInit=
false;
782 for (
size_t objId : mdRandom.
ids())
792 mdRandom.
write(fnAngles);
795 if (system(cmd.c_str())==-1)
801 args=
formatString(
"-i %s --sym i1 --spline 1 -v 0",fnVolume.c_str());
802 cmd=(
String)
"xmipp_transform_symmetrize "+args;
803 if (system(cmd.c_str())==-1)
806 args=
formatString(
"-i %s --sym i3 --spline 1 -v 0",fnVolume.c_str());
807 if (system(cmd.c_str())==-1)
810 args=
formatString(
"-i %s --sym i2 --spline 1 -v 0",fnVolume.c_str());
811 if (system(cmd.c_str())==-1)
828 for (
size_t objId : mdInit.
ids())
844 if (deleteInit &&
rank==0)
855 for (
int idx=0; idx<
Nvolumes; ++idx)
862 gallery.push_back(galleryDummy);
Just to locate unclassified errors.
void init_progress_bar(long total)
FourierTransformer transformer1
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
void cumlativeDensityFunction(MultidimArray< double > &cdf)
double getDoubleParam(const char *param, int arg=0)
double alignImages(const MultidimArray< double > &Iref, const AlignmentTransforms &IrefTransforms, MultidimArray< double > &I, Matrix2D< double > &M, bool wrap, AlignmentAux &aux, CorrelationAux &aux2, RotationalCorrelationAux &aux3)
#define REPORT_ERROR(nerr, ErrormMsg)
FileName replaceExtension(const String &newExt) const
std::vector< Image< double > > gallery
bool keepIntermediateVolumes
void sqrt(Image< double > &op)
void aliasImageInStack(const MultidimArray< T > &m, size_t select_image)
int readSymmetryFile(FileName fn_sym, double accuracy=SYM_ACCURACY)
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)
void inv(Matrix2D< T > &result) const
void defineParams()
Read arguments from command line.
size_t numOrientationsPerParticle
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
virtual void synchronize()
Synchronize with other processors.
void alignImagesToGallery()
Align images to gallery projections.
#define DIRECT_A1D_ELEM(v, i)
void produceSideinfo()
Produce side info: fill arrays with relevant transformation matrices.
void log(Image< double > &op)
const char * getParam(const char *param, int arg=0)
void generateProjections()
Generate projections from the current volume.
void reconstructCurrent()
Reconstruct current volume.
Incorrect argument received.
double imedDistance(const MultidimArray< double > &I1, const MultidimArray< double > &I2)
void progress_bar(long rlen)
std::vector< MetaDataDb > mdReconstructionProjectionMatching
T Euler_distanceBetweenAngleSets(T rot1, T tilt1, T psi1, T rot2, T tilt2, T psi2, bool only_projdir)
MultidimArray< double > weight
int verbose
Verbosity level.
virtual void gatherAlignment()
Gather alignment.
#define DIRECT_A3D_ELEM(v, k, i, j)
template void polarFourierTransform< true >(MultidimArray< double > const &, Polar< double > &, Polar< std::complex< double > > &, bool, int, int, Polar_fftw_plans *&, int)
std::vector< AlignmentTransforms *> galleryTransforms
void numberOfProjections()
bool fileExists(const char *filename)
String formatString(const char *format,...)
MultidimArray< double > cc
bool checkParam(const char *param)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
std::vector< std::vector< GalleryImage > > mdGallery
void addUsageLine(const char *line, bool verbatim=false)
void initZeros(const MultidimArray< T1 > &op)
unsigned int randomize_random_generator()
virtual void readParams()
Read arguments from command line.
int getIntParam(const char *param, int arg=0)
double alignImagesConsideringMirrors(const MultidimArray< double > &Iref, const AlignmentTransforms &IrefTransforms, MultidimArray< double > &I, Matrix2D< double > &M, AlignmentAux &aux, CorrelationAux &aux2, RotationalCorrelationAux &aux3, bool wrap, const MultidimArray< int > *mask)
ProgReconstructSignificant()
Empty constructor.
std::vector< MetaDataDb > mdReconstructionPartial
void addParamsLine(const String &line)