Xmipp  v3.23.11-Nereus
mpi_classify_CLTomo.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Carlos Oscar coss@cnb.csic.es (2009)
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 #ifndef _PROG_VQ_VOLUMES
26 #define _PROG_VQ_VOLUMES
27 
28 #include <interface/frm.h> // must be included first as it defines _POSIX_C_SOURCE
29 
30 #include <parallel/xmipp_mpi.h>
31 #include <core/metadata_db.h>
33 #include <data/filters.h>
34 #include <data/polar.h>
35 #include <core/xmipp_fftw.h>
36 #include <core/histogram.h>
37 #include <data/numerical_tools.h>
38 #include <core/xmipp_program.h>
39 #include <core/symmetries.h>
40 #include <vector>
41 #include "data/mask.h"
42 
48 {
49 public:
50  double score; // Negative corrCodes indicate invalid particles
51  double shiftx;
52  double shifty;
53  double shiftz;
54  double psi;
55  double tilt;
56  double rot;
57  size_t objId;
58 
61 
63  void readAlignment(const Matrix2D<double> &M);
64 
66  void copyAlignment(const CL3DAssignment &alignment);
67 };
68 
70 std::ostream & operator << (std::ostream &out, const CL3DAssignment& assigned);
71 
73 class CL3DClass {
74 public:
75  // Centroid
77 
78  // Centroid in Fourier space
80 
81  // Fourier transformer
83 
84  // Auxiliary Fourier image
86 
87  // Auxiliary Fourier image magnitude
89 
90  // Fourier mask for the experimental image
92 
93  // Mask for experimental image as a python object
94  PyObject *pyIfourierMaskFRM=nullptr;
95 
96  // Update for next iteration
98 
99  // Update for next iteration in real space
100  //MultidimArray<double> PupdateReal;
101 
102  // Sum weights
103  //double weightSum;
104 
105  // Update for next iteration
107 
108  // Auxiliary for alignment
110 
111  // List of images assigned
112  std::vector<CL3DAssignment> currentListImg;
113 
114  // List of images assigned
115  std::vector<CL3DAssignment> nextListImg;
116 
117  // List of neighbour indexes
118  std::vector<int> neighboursIdx;
119 
120 public:
122  CL3DClass();
123 
126 
128  CL3DClass(const CL3DClass &other);
129  CL3DClass(const CL3DClass &&)=delete;
130 
132  CL3DClass & operator=(const CL3DClass &other);
133  CL3DClass & operator=(const CL3DClass &&)=delete;
134 
136  void updateProjection(MultidimArray<double> &I, const CL3DAssignment &assigned, bool force=false);
137 
139  void transferUpdate();
140 
142  void constructFourierMask(MultidimArray<double> &I);
143 
145  void constructFourierMaskFRM();
146 
150  void fitBasic(MultidimArray<double> &I, CL3DAssignment &result);
151 
153  void lookForNeighbours(const std::vector<CL3DClass *> listP, int K);
154 };
155 
157 {
158  bool operator()(CL3DClass* const& rpStart, CL3DClass* const& rpEnd)
159  {
160  return rpStart->currentListImg.size() > rpEnd->currentListImg.size();
161  }
162 };
163 
165 class CL3D {
166 public:
168  size_t Nimgs;
169 
172 
174  std::vector<CL3DClass *> P;
175 
176 public:
178  void readImage(Image<double> &I, size_t objId, bool applyGeo) const;
179 
181  void initialize(MetaDataDb &_SF,
182  std::vector< MultidimArray<double> > &_codes0);
183 
185  void shareAssignments(bool shareAssignment, bool shareUpdates);
186 
188  void shareSplitAssignments(Matrix1D<int> &assignment, CL3DClass *node1, CL3DClass *node2) const;
189 
191  void write(const FileName &fnRoot, int level) const;
192 
196  void lookNode(MultidimArray<double> &I, int oldnode,
197  int &newnode, CL3DAssignment &bestAssignment);
198 
200  void transferUpdates();
201 
203  void run(const FileName &fnOut, int level);
204 
207  int cleanEmptyNodes();
208 
210  void splitNode(CL3DClass *node,
211  CL3DClass *&node1, CL3DClass *&node2,
212  std::vector<size_t> &finalAssignment,
213  bool iterate=true) const;
214 
216  void splitFirstNode();
217 };
218 
221 public:
224 
227 
230 
233 
235  int Niter;
236 
238  int Ncodes0;
239 
241  int Ncodes;
242 
245 
247  double PminSize;
248 
250  double maxFreq;
251 
253  double sparsity;
254 
256  double DWTsparsity;
257 
260 
263 
265  double maxShiftZ;
266 
268  double maxShiftY;
269 
271  double maxShiftX;
272 
273 
275  double maxRot;
276 
278  double maxTilt;
279 
281  double maxPsi;
282 
285 
287  bool dontAlign;
288 
291 
292  // Symmetry List
294 
296  ProgClassifyCL3D(int argc, char** argv);
297  ProgClassifyCL3D(const ProgClassifyCL3D&)=delete;
298  ProgClassifyCL3D(const ProgClassifyCL3D&&)=delete;
299 
301  ~ProgClassifyCL3D();
302 
303  ProgClassifyCL3D & operator=(const ProgClassifyCL3D &)=delete;
304  ProgClassifyCL3D & operator=(const ProgClassifyCL3D &&)=delete;
305 
307  void readParams();
308 
310  void show() const;
311 
313  void defineParams();
314 
316  void produceSideInfo();
317 
319  void run();
320 public:
321  // Selfile with all the input images
323 
324  // Object Ids
325  std::vector<size_t> objId;
326 
327  // Structure for the classes
329 
330  // Mpi node
332 
333  // Gaussian interpolator
335 
336  // Image dimensions
337  size_t Zdim, Ydim, Xdim;
338 
340  PyObject * frmFunc;
341 
343  PyObject * wedgeClass;
344 
346  double maxShift;
347 
350 };
352 #endif
MultidimArray< std::complex< double > > Pfourier
MultidimArray< double > IfourierMagSorted
double maxShift
Max shift.
GaussianInterpolator gaussianInterpolator
double sparsity
Sparsity factor (0<f<1; 1=drop all coefficients, 0=do not drop any coefficient)
std::vector< size_t > objId
std::vector< CL3DClass * > P
List of nodes.
double maxShiftX
Maximum shift X.
void write(std::ostream &os, const datablock &db)
Definition: cif2pdb.cpp:3747
std::vector< CL3DAssignment > currentListImg
PyObject * frmFunc
Pointer to the Python FRM alignment function.
Definition: mask.h:360
int Niter
Number of iterations.
MetaDataDb * SF
Pointer to input metadata.
double maxPsi
Maximum psi.
bool operator()(CL3DClass *const &rpStart, CL3DClass *const &rpEnd)
bool generateAlignedVolumes
Generate aligned subvolumes.
MultidimArray< std::complex< double > > Pupdate
FileName fnSel
Input selfile with the images to quantify.
bool randomizeStartingOrientation
Use this option to avoid aligning at the beginning all the missing wedges.
double maxShiftY
Maximum shift Y.
void copyAlignment(const CL3DAssignment &alignment)
Copy alignment.
size_t Nimgs
Number of images.
int Ncodes
Final number of code vectors.
std::ostream & operator<<(std::ostream &out, const CL3DAssignment &assigned)
Show.
CL3DAssignment()
Empty constructor.
MpiNode * node
double DWTsparsity
DWT Sparsity factor (0<f<1; 1=drop all coefficients, 0=do not drop any coefficient) ...
MultidimArray< double > Iaux
MultidimArray< std::complex< double > > Ifourier
FileName fnOut
int Nneighbours
Number of neighbours.
double maxShiftZ
Maximum shift Z.
bool dontAlign
Don&#39;t align.
MultidimArray< int > IfourierMaskFRM
MultidimArray< double > Paux
MultidimArray< unsigned char > maxFreqMask
MaxFreq mask.
double maxTilt
Maximum tilt.
std::vector< int > neighboursIdx
PyObject * wedgeClass
Pointer to the Python GeneralWedge class.
void readAlignment(const Matrix2D< double > &M)
Read alignment parameters.
MultidimArray< double > PupdateMask
bool classifyAllImages
Clasify all images.
FourierTransformer transformer
FileName fnOut
Output rootname.
constexpr int K
int Ncodes0
Initial number of code vectors.
double maxRot
Maximum rot.
FileName fnCodes0
Input selfile with initial codes.
double PminSize
Minimum size of a node.
FileName fnSym
Symmetry file or code.
std::vector< CL3DAssignment > nextListImg
double maxFreq
Maximum frequency for the alignment.