Xmipp  v3.23.11-Nereus
resolution_fso.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Jose Luis Vilas (joseluis.vilas-prieto@yale.edu)
4  * or (jlvilas@cnb.csic.es)
5  * Hemant. D. Tagare (hemant.tagare@yale.edu)
6  *
7  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22  * 02111-1307 USA
23  *
24  * All comments concerning this program package may be sent to the
25  * e-mail address 'xmipp@cnb.csic.es'
26  ***************************************************************************/
27 
28 #ifndef _PROG_RES_FSO
29 #define _PROG_RES_FSO
30 
31 #include <core/xmipp_program.h>
32 #include <core/matrix2d.h>
33 #include <core/xmipp_fftw.h>
34 #include <core/xmipp_filename.h>
35 #include <core/metadata_vec.h>
36 
37 
38 class ProgFSO : public XmippProgram
39 {
40 private:
41  // Filenames
42  FileName fnhalf1, fnhalf2, fnmask, fnOut;
43 
44  // Double Params
45  double sampling, ang_con, thrs;
46 
47  // Int params
48  int Nthreads;
49 
50  // Bool params
51  bool do_3dfsc_filter;
52 
53  // Matrix2d for the projection angles
54  Matrix2D<float> angles;
55 
56  // Int params
57  size_t xvoldim, yvoldim, zvoldim, fscshellNum;
58 
59  // Frequency vectors and frequency map
60  Matrix1D<double> freq_fourier_x;
61  Matrix1D<double> freq_fourier_y;
62  Matrix1D<double> freq_fourier_z;
63  MultidimArray<float> fx, fy, fz;
64  MultidimArray<float> threeD_FSC, normalizationMap, aniFilter;
66 
67  // Half maps
69  MultidimArray<float> real_z1z2, absz1_vec, absz2_vec;
70 
71  //Access indices
72  MultidimArray<long> freqElems, cumpos, freqidx, arr2indx;
73 
74 
75 private:
76  /* Once done, the result of the computation is stored in freqMap (class field)
77  * freqMap is a multidim array that define INVERSE of the value of the frequency in Fourier Space
78  * To do that, it makes use of myfftV to detemine the size of the output map (mapfftV and
79  * the output will have the same size), and the vectors freq_fourier_x, freq_fourier_y,
80  * and freq_fourier_z that defines the frequencies along the 3 axis. The output will be
81  * sqrt(freq_fourier_x^2+freq_fourier_y^2+freq_fourier_x^2) */
82  void defineFrequencies(const MultidimArray< std::complex<double> > &mapfftV,
83  const MultidimArray<double> &inputVol);
84 
85  /* Estimates the global FSC between two half maps FT1 and FT2 (in Fourier Space)
86  * ARRANGEFSC_AND_FSCGLOBAL: This function estimates the global resolution FSC FSC=real(z1*conj(z2)/(||z1||ยท||z2||)
87  * and precomputes the products z1*conj(z2), ||z1||, ||z2||, to calculate faster the directional FSC. The input are
88  * the Fourier transform of two half maps (FT1, FT2) defined in the .h, the sampling_rate, the used threshold (thrs)
89  * to that define the resolution (FSC-threshold). The output are: 1) The resolution of the map in Angstrom (In the terminal).
90  * 2) three vectors defined in the .h, real_z1z2, absz1_vec, absz2_vec, with z1*conj(z2), ||z1||, ||z2||, defined in
91  * float to speed up the computation and reduce the use of memory. These vector make use of the two half maps FT1, and FT2.
92  */
93  void arrangeFSC_and_fscGlobal(double sampling_rate,
94  double &thrs, MultidimArray<double> &freq);
95 
96  /*
97  * */
98  double incompleteGammaFunction(double &x);
99 
100  /* Defines a Matrix2D with coordinates Rot and tilt achieving a uniform coverage of the
101  * projection sphere. Bool alot = True, implies a dense coverage */
102  void generateDirections(Matrix2D<float> &angles, bool alot);
103 
104  /* ANISOTROPYPARAMETER: Given a directional FSC it is determined how many
105  * frequencies/points of the FSC has a greater fsc than the fsc threshold, thrs,
106  * This is carried out in aniParam, . */
107  void anistropyParameter(const MultidimArray<float> &FSC,
108  MultidimArray<float> &aniParam, double thrs);
109 
110  /* Estimates the directional FSC between two half maps FT1 and FT2 (in Fourier Space)
111  * requires the sampling rate, and the frequency vectors, */
112  void fscDir_fast(MultidimArray<float> &fsc, double rot, double tilt,
113  MultidimArray<float> &threeD_FSC,
114  MultidimArray<float> &normalizationMap,
115  double &thrs, double &resol, std::vector<Matrix2D<double>> &freqMat, size_t dirnum);
116 
117  /* PREPAREDATA: Data are prepared to be taken by the algorithm.
118  * The half maps will be read and stored in the multidimarray half1, and half2.
119  * Also de mask (if provided) is read and stored in mask (defined in .h) */
120  void prepareData(MultidimArray<double> &half1, MultidimArray<double> &half2);
121 
122  /* SAVEANISOTROPYTOMETADATA - The FSO is stored in metadata file. The FSO comes from
123  * anisotropy and the frequencies from freq. */
124  void saveAnisotropyToMetadata(MetaDataVec &mdAnisotropy,
125  const MultidimArray<double> &freq,
126  const MultidimArray<float> &anisotropy, const MultidimArray<double> &isotropyMatrix);
127 
128  /* DIRECTIONALFILTER: The half maps are summed to get the full map, and are filtered
129  * by an anisotropic filter with cutoff the isosurface of the fsc at the given threshold
130  * introduced by the user. */
131  void directionalFilter(MultidimArray<std::complex<double>> &FThalf1,
132  MultidimArray<double> &threeDfsc, MultidimArray<double> &filteredMap,
133  int m1sizeX, int m1sizeY, int m1sizeZ);
134 
135  void directionalFilterHalves(MultidimArray<std::complex<double>> &FThalf1,
136  MultidimArray<double> &threeDfsc);
137 
138  /* RESOLUTIONDISTRIBUTION: This function stores in a metadata the resolution distribution on the
139  * projection sphere. Thus the metadata contains the resolution of each direction.
140  * To do that, a matrix with rows the rot angle and columns the tilt angle is created.
141  * the rot angle goes from from 0-360 and tilt from 0-90 both in steps of 1 degree. */
142  void resolutionDistribution(MultidimArray<double> &resDirFSC, FileName &fn);
143 
144  /* GETCOMPLETEFOURIER: Because of the hermitician symmetry of the Fourier space, xmipp works with the half
145  * of the space. This function recover the whole Fourier space (both halfs). */
146  void getCompleteFourier(MultidimArray<double> &V, MultidimArray<double> &newV,
147  int m1sizeX, int m1sizeY, int m1sizeZ);
148 
149  /* CREATEFULLFOURIER: The inpur is a Fourier Transform, the function will compute the full Fourier
150  * and will save it in disc, with the name of fnMap m1sizeX, m1sizeY, m1sizeZ, define the size. */
151  void createFullFourier(MultidimArray<double> &fourierHalf, FileName &fnMap,
152  int m1sizeX, int m1sizeY, int m1sizeZ);
153 
154  /* FSCINTERPOLATION: The exact resolution of the the FSC = thrs is estimated. thrs is a global variable */
155  void fscInterpolation(const MultidimArray<double> &freq, const MultidimArray< double > &frc);
156 
157 public:
158  /* Defining the params and help of the algorithm */
159  void defineParams();
160 
161  /* It reads the input parameters */
162  void readParams();
163 
164  /* Run the program */
165  void run();
166 };
167 
168 #endif
doublereal * x
void readParams()
void defineParams()