Xmipp  v3.23.11-Nereus
angular_resolution_alignment.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Jose Luis Vilas (jlvilas@cnb.csic.es)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 #ifndef _PROG_ANGULAR_RESOLUTION_ALIGNMENT
27 #define _PROG_ANGULAR_RESOLUTION_ALIGNMENT
28 
29 #include <core/xmipp_program.h>
30 #include <core/matrix2d.h>
31 #include <core/xmipp_fftw.h>
32 #include <core/xmipp_filename.h>
33 #include <core/metadata_vec.h>
34 
35 
37 {
38 private:
39  // Filenames
40  FileName fnhalf1, fnhalf2, fnmask, fnOut;
41 
42  // Double Params
43  double sampling, ang_con, thrs;
44 
45  // Maximum radius to be analyzed
46  int maxRadius;
47 
48  // Number of threads in the paralellization
49  int Nthreads;
50 
51  // Bool params
52  bool isHelix, limRad, directionalRes;
53 
54  // Matrix2d for the projection angles
55  Matrix2D<float> angles;
56 
57  // Int params
58  size_t xvoldim, yvoldim, zvoldim, fscshellNum;
59 
60  // Frequency vectors and frequency map
61  Matrix1D<double> freq_fourier_x;
62  Matrix1D<double> freq_fourier_y;
63  Matrix1D<double> freq_fourier_z;
64  MultidimArray<float> fx, fy, fz;
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  /* This function determines the frequency map in Fourier space.
77  * The input is the original map inputVol. The output is stored in
78  * the global variable freqMap (defined in the .h)
79  * FreqMap is in Fourier space an each voxel defines the frequency
80  * value associated to that position
81  */
82  void defineFrequenciesSimple(const MultidimArray<double> &inputVol);
83 
84  /* This function tales two half maps and a mask. The half maps
85  * are multiplied by the mask returning two masked half maps half1_aux and half2_aux
86  */
87  void applyShellMask(const MultidimArray<double> &half1, const MultidimArray<double> &half2,
88  const MultidimArray<double> &shellMask,
89  MultidimArray<double> &half1_aux,
90  MultidimArray<double> &half2_aux);
91 
92  /* Estimates the global FSC between two half maps FT1 and FT2 (in Fourier Space)
93  * ARRANGEFSC_AND_FSCGLOBAL: This function estimates the global resolution FSC FSC=real(z1*conj(z2)/(||z1||ยท||z2||)
94  * and precomputes the products z1*conj(z2), ||z1||, ||z2||, to calculate faster the directional FSC. The input are
95  * the Fourier transform of two half maps (FT1, FT2) defined in the .h, the sampling_rate, the used threshold (thrs)
96  * to that define the resolution (FSC-threshold). The output are: 1) The resolution of the map in Angstrom (In the terminal).
97  * 2) three vectors defined in the .h, real_z1z2, absz1_vec, absz2_vec, with z1*conj(z2), ||z1||, ||z2||, defined in
98  * float to speed up the computation and reduce the use of memory. These vector make use of the two half maps FT1, and FT2.
99  */
100  void arrangeFSC_and_fscGlobal();
101 
102  /* This function estiamtes the global FSC between two half maps. The half maps are defined in the .h.
103  */
104  void fscGlobal(double &threshold, double &resol);
105 
106  /* Defines a Matrix2D with coordinates Rot and tilt achieving a uniform coverage of the
107  * projection sphere. Bool alot = True, implies a dense coverage */
108  void generateDirections(Matrix2D<float> &angles, bool alot);
109 
110  /* The half maps are masked with two mask (the one provided by the user and a second one defined by the algorithm)
111  * This function implements the second one. This mask is a radial mask with a Gaussian profile centered at
112  * a specific radius. If the map is a helix the mask will be a gaussian cylinder, if not it will be a gassian shell
113  */
114  void generateShellMask(MultidimArray<double> &shellMask, size_t shellNum, bool ishelix);
115 
116  /* Estimates the directional FSC between two half maps FT1 and FT2 (in Fourier Space)
117  * requires the sampling rate, and the frequency vectors, */
118  void fscDir_fast(MultidimArray<float> &fsc, double rot, double tilt,
119  double &thrs, double &resol);
120 
121  /* PREPAREDATA: Data are prepared to be taken by the algorithm.
122  * The half maps will be read and stored in the multidimarray half1, and half2.
123  * Also de mask (if provided) is read and stored in mask (defined in .h) */
124  void readData(MultidimArray<double> &half1, MultidimArray<double> &half2);
125 
126  /* FSCINTERPOLATION: The exact resolution of the the FSC = thrs is estimated. thrs is a global variable */
127  void fscInterpolation(const MultidimArray<double> &freq, const MultidimArray< double > &frc);
128 
129 public:
130  /* Defining the params and help of the algorithm */
131  void defineParams();
132 
133  /* It reads the input parameters */
134  void readParams();
135 
136  /* Run the program */
137  void run();
138 };
139 
140 #endif
void threshold(double *phi, unsigned long nvox, double limit)
Definition: lib_vwk.cpp:524