Xmipp  v3.23.11-Nereus
angular_sph_alignment.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Carlos Oscar Sanchez Sorzano (coss@cnb.csic.es)
4  * David Herreros Calero (dherreros@cnb.csic.es)
5  *
6  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21  * 02111-1307 USA
22  *
23  * All comments concerning this program package may be sent to the
24  * e-mail address 'xmipp@cnb.csic.es'
25  ***************************************************************************/
26 
27 #ifndef _PROG_ANGULAR_SPH_ALIGNMENT
28 #define _PROG_ANGULAR_SPH_ALIGNMENT
29 
31 #include "core/rerunable_program.h"
32 #include "core/matrix1d.h"
33 #include "core/xmipp_image.h"
34 #include "data/fourier_filter.h"
36 
40 
43 {
44 public:
52  int L1;
53  int L2;
60  double maxShift;
64  double maxResol;
66  double Ts;
68  int Rmax;
69  // Optimize alignment
71  //Optimize deformation
73  //Optimize defocus
75  // Ignore CTF
76  bool ignoreCTF;
77  //Radius optimization
79  // Phase Flipped
81  // Regularization weight
82  double lambda;
83  // Maximum radius for the deformation
84  int RmaxDef;
85 
88 
89 public:
91  bool resume;
92  // 2D and 3D masks in real space
95  // Volume size
96  size_t Xdim;
97  // Input images
104  // Theoretical projection
106  // Filter
108  // Transformation matrix
110  // Original angles
111  double old_rot;
112  double old_tilt;
113  double old_psi;
114  // Original shift
115  double old_shiftX;
116  double old_shiftY;
117  // Original flip
118  bool old_flip;
119  // CTF Check
120  bool hasCTF;
121  // Original defocus
122  double old_defocusU;
123  double old_defocusV;
125  // Current defoci
128  double currentAngle;
129  // CTF
131  // CTF filter
133  // Vector Size
134  int vecSize;
135  // Vector containing the degree of the spherical harmonics
137  //Copy of Optimizer steps
139  //Total Deformation, sumV, sumVd
141  double sumV;
142  double sumVd;
143  // Show optimization
145  // Correlation
146  double correlation;
147 
148 public:
151 
154 
156  void readParams();
157 
159  void show();
160 
162  void defineParams();
163 
166  void preProcess();
167 
171  void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut);
172 
174  void numCoefficients(int l1, int l2, int &nc) const;
175 
177  void minimizepos(int l2, Matrix1D<double> &steps) const;
178 
180  void fillVectorTerms(int l1, int l2);
181 
183  void deformVol(MultidimArray<double> &mVD, const MultidimArray<double> &mV, double &def,
184  double rot, double tilt, double psi);
185 
186  void applyCTFImage(double const &deltaDefocusU, double const &deltaDefocusV,
187  double const &deltaDefocusAngle);
188 
189  void updateCTFImage(double defocusU, double defocusV, double angle);
190 
191  double tranformImageSph(double *pclnm, double rot, double tilt, double psi,
192  double deltaDefocusU, double deltaDefocusV, double deltaDefocusAngle);
193 
195  virtual void finishProcessing();
196 
198  virtual void writeImageParameters(const FileName &fnImg);
199 
200  protected:
201  virtual void createWorkFiles() {
202  return Rerunable::createWorkFiles(resume, getInputMd());
203  }
204 
205  private:
207 
208  std::vector<MDLabel> getLabelsForEmpty() override {
209  return std::vector<MDLabel>{MDL_IMAGE,
210  MDL_ENABLED,
214  MDL_SHIFT_X,
215  MDL_SHIFT_Y,
216  MDL_FLIP,
219  MDL_COST};
220  }
221 };
223 #endif
Rotation angle of an image (double,degrees)
ProgAngularSphAlignment()
Empty constructor.
MultidimArray< int > mask2D
double tranformImageSph(double *pclnm, double rot, double tilt, double psi, double deltaDefocusU, double deltaDefocusV, double deltaDefocusAngle)
Tilting angle of an image (double,degrees)
void minimizepos(int l2, Matrix1D< double > &steps) const
Determine the positions to be minimize of a vector containing spherical harmonic coefficients.
Shift for the image in the X axis (double)
virtual void writeImageParameters(const FileName &fnImg)
Special label to be used when gathering MDs in MpiMetadataPrograms.
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
Is this image enabled? (int [-1 or 1])
void numCoefficients(int l1, int l2, int &nc) const
Length of coefficients vector.
virtual void createWorkFiles(bool resume, MetaData *md)
Deformation in voxels.
Cost for the image (double)
void applyCTFImage(double const &deltaDefocusU, double const &deltaDefocusV, double const &deltaDefocusAngle)
Flip the image? (bool)
void updateCTFImage(double defocusU, double defocusV, double angle)
void readParams()
Read argument from command line.
FileName fnOutDir
Output directory.
double steps
double psi(const double x)
Deformation coefficients.
MultidimArray< int > V_mask
void deformVol(MultidimArray< double > &mVD, const MultidimArray< double > &mV, double &def, double rot, double tilt, double psi)
Deform a volumen using Zernike-Spherical harmonic basis.
Shift for the image in the Y axis (double)
~ProgAngularSphAlignment()
Destructor.
Name of an image (std::string)
void defineParams()
Define parameters.
void fillVectorTerms(int l1, int l2)
Zernike and SPH coefficients allocation.