Xmipp  v3.23.11-Nereus
forward_zernike_subtomos.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_FORWARD_ZERNIKE_SUBTOMOS
28 #define _PROG_FORWARD_ZERNIKE_SUBTOMOS
29 
31 #include "core/rerunable_program.h"
32 #include "core/matrix1d.h"
33 #include <data/blobs.h>
34 #include "core/xmipp_image.h"
35 #include "data/fourier_filter.h"
37 
41 
44 {
45 public:
53  int L1, L2;
57  double maxShift;
61  double maxResol;
63  double Ts;
65  int Rmax;
66  // Optimize alignment
68  //Optimize deformation
70  //Optimize defocus
72  // Ignore CTF
73  bool ignoreCTF;
74  //Radius optimization
76  // Phase Flipped
78  // Regularization weight
79  double lambda;
80  // Maximum radius for the deformation
81  int RmaxDef;
82  // Number of images (execution mode) (single image == 1, pair == 2, or triplet == 3)
84  // Number alignment parameters to minimize
86  // Number CTF parameters to minimize
90  bool useCTF;
91  // Tilt angles
92  double t1, t2;
93 
94 public:
96  bool resume;
97  // 2D and 3D masks in real space
99  // Volume size
100  size_t Xdim;
101  // Images Filename
103  // Input image
108  // Theoretical subtomos
110  // Filter
113  // Transformation matrix
115  // Original angles
117  // Original shift
119  // Original flip
120  bool old_flip;
121  // CTF Check
122  bool hasCTF;
123  // Original defocus
125  // Current defoci
127  // CTF filter
129  // Vector Size
130  int vecSize;
131  // Vector containing the degree of the spherical harmonics
133  //Copy of Optimizer steps
135  //Total Deformation, sumV, sumVd
137  int sumV;
138  // Show optimization
140  // Correlation
141  double correlation;
142  // Loop step
144  // Blob
145  struct blobtype blob;
146  double blob_r;
147 
148  double sigma4;
149  // Gaussian projection table
151 
152  // Gaussian projection2 table
154 
155  // Deformation field and positions
157  std::vector<size_t> idx_z_clnm;
158  std::vector<double> z_clnm_diff;
160 
161 public:
162  enum class Direction { ROTATE, UNROTATE };
163 
166 
169 
171  void readParams();
172 
174  void show();
175 
177  void defineParams();
178 
181  void preProcess();
182 
186  void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut);
187 
189  void numCoefficients(int l1, int l2, int &vecSize);
190 
192  // void minimizepos(Matrix1D<double> &vectpos);
193  void minimizepos(int L1, int l2, Matrix1D<double> &steps);
194 
196  void fillVectorTerms(int l1, int l2, Matrix1D<int> &vL1, Matrix1D<int> &vN,
197  Matrix1D<int> &vL2, Matrix1D<int> &vM);
198 
200  void deformVol(MultidimArray<double> &mVD, const MultidimArray<double> &mV, double &def,
201  double rot, double tilt, double psi);
202 
203  void updateCTFImage(double defocusU, double defocusV, double angle);
204 
205  double transformImageSph(double *pclnm);
206 
207  template<Direction DIRECTION>
208  void rotateCoefficients();
209 
210  //AJ new
212  virtual void finishProcessing();
213 
215  virtual void writeImageParameters(MDRow &row);
216  //END AJ
217 
218  virtual void checkPoint();
219 
220  // void removePixels();
221 
222  Matrix1D<double> weightsInterpolation3D(double x, double y, double z);
223 
224  void splattingAtPos(std::array<double, 3> r, double weight, MultidimArray<double> &mP, const MultidimArray<double> &mV);
225 
226  void rotatePositions(double rot, double tilt, double psi);
227 
228  void preComputeDF();
229 
230 protected:
232 
233 private:
234  std::vector<MDLabel> getLabelsForEmpty() override
235  {
236  std::vector<MDLabel> labels = getInputMd()->getActiveLabels();
237  labels.push_back(MDL_SPH_DEFORMATION);
238  labels.push_back(MDL_SPH_COEFFICIENTS);
239  if (!(std::find(labels.begin(), labels.end(), MDL_ENABLED) != labels.end()))
240  labels.push_back(MDL_ENABLED);
241  // labels.push_back(MDL_COST);
242  return labels;
243  }
244 };
246 #endif
ProgForwardZernikeSubtomos()
Empty constructor.
~ProgForwardZernikeSubtomos()
Destructor.
void defineParams()
Define parameters.
void rotatePositions(double rot, double tilt, double psi)
std::vector< SelLine >::iterator find(std::vector< SelLine > &text, const std::string &img_name)
Definition: selfile.cpp:553
void updateCTFImage(double defocusU, double defocusV, double angle)
static double * y
void numCoefficients(int l1, int l2, int &vecSize)
Length of coefficients vector.
doublereal * x
Is this image enabled? (int [-1 or 1])
virtual void createWorkFiles(bool resume, MetaData *md)
Deformation in voxels.
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
double z
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.
virtual void checkPoint()
For very long programs, it may be needed to write checkpoints.
Matrix1D< double > gaussianProjectionTable2
FileName fnOutDir
Output directory.
double steps
virtual void writeImageParameters(MDRow &row)
void minimizepos(int L1, int l2, Matrix1D< double > &steps)
Determine the positions to be minimize of a vector containing spherical harmonic coefficients.
double psi(const double x)
Deformation coefficients.
void splattingAtPos(std::array< double, 3 > r, double weight, MultidimArray< double > &mP, const MultidimArray< double > &mV)
virtual std::vector< MDLabel > getActiveLabels() const =0
void fillVectorTerms(int l1, int l2, Matrix1D< int > &vL1, Matrix1D< int > &vN, Matrix1D< int > &vL2, Matrix1D< int > &vM)
Zernike and SPH coefficients allocation.
void readParams()
Read argument from command line.
Matrix1D< double > gaussianProjectionTable
Matrix1D< double > weightsInterpolation3D(double x, double y, double z)