Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | List of all members

#include <angular_continuous_assign.h>

Inheritance diagram for ProgAngularContinuousAssign:
Inheritance graph
[legend]
Collaboration diagram for ProgAngularContinuousAssign:
Collaboration graph
[legend]

Public Member Functions

 ProgAngularContinuousAssign ()
 Empty constructor. More...
 
void readParams ()
 Read argument from command line. More...
 
void show ()
 Show. More...
 
void defineParams ()
 Define parameters. More...
 
void preProcess ()
 
void processImage (const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
 
- Public Member Functions inherited from XmippMetadataProgram
MetaDatagetInputMd ()
 
MetaDataVecgetOutputMd ()
 
 XmippMetadataProgram ()
 Empty constructor. More...
 
virtual int tryRead (int argc, const char **argv, bool reportErrors=true)
 
virtual void init ()
 
virtual void setup (MetaData *md, const FileName &o="", const FileName &oroot="", bool applyGeo=false, MDLabel label=MDL_IMAGE)
 
virtual ~XmippMetadataProgram ()
 
void setMode (WriteModeMetaData _mode)
 
void setupRowOut (const FileName &fnImgIn, const MDRow &rowIn, const FileName &fnImgOut, MDRow &rowOut) const
 Prepare rowout. More...
 
virtual void wait ()
 Wait for the distributor to finish. More...
 
virtual void checkPoint ()
 For very long programs, it may be needed to write checkpoints. More...
 
virtual void run ()
 Run over all images. More...
 
- Public Member Functions inherited from XmippProgram
const char * getParam (const char *param, int arg=0)
 
const char * getParam (const char *param, const char *subparam, int arg=0)
 
int getIntParam (const char *param, int arg=0)
 
int getIntParam (const char *param, const char *subparam, int arg=0)
 
double getDoubleParam (const char *param, int arg=0)
 
double getDoubleParam (const char *param, const char *subparam, int arg=0)
 
float getFloatParam (const char *param, int arg=0)
 
float getFloatParam (const char *param, const char *subparam, int arg=0)
 
void getListParam (const char *param, StringVector &list)
 
int getCountParam (const char *param)
 
bool checkParam (const char *param)
 
bool existsParam (const char *param)
 
void addParamsLine (const String &line)
 
void addParamsLine (const char *line)
 
ParamDefgetParamDef (const char *param) const
 
virtual void quit (int exit_code=0) const
 
virtual int tryRun ()
 
void initProgress (size_t total, size_t stepBin=60)
 
void setProgress (size_t value=0)
 
void endProgress ()
 
void processDefaultComment (const char *param, const char *left)
 
void setDefaultComment (const char *param, const char *comment)
 
void setProgramName (const char *name)
 
void addUsageLine (const char *line, bool verbatim=false)
 
void clearUsage ()
 
void addExampleLine (const char *example, bool verbatim=true)
 
void addSeeAlsoLine (const char *seeAlso)
 
void addKeywords (const char *keywords)
 
const char * name () const
 
virtual void usage (int verb=0) const
 
virtual void usage (const String &param, int verb=2)
 
int version () const
 
virtual void read (int argc, const char **argv, bool reportErrors=true)
 
virtual void read (int argc, char **argv, bool reportErrors=true)
 
void read (const String &argumentsLine)
 
 XmippProgram ()
 
 XmippProgram (int argc, const char **argv)
 
virtual ~XmippProgram ()
 

Public Attributes

FileName fn_ref
 
double gaussian_DFT_sigma
 
double gaussian_Real_sigma
 
double weight_zero_freq
 
int max_no_iter
 
bool quiet
 
double max_shift
 
double max_angular_change
 
MultidimArray< double > reDFTVolume
 
MultidimArray< double > imDFTVolume
 
Mask mask_Fourier
 
Mask mask_Real
 
- Public Attributes inherited from XmippMetadataProgram
FileName fn_in
 Filenames of input and output Metadata. More...
 
FileName fn_out
 
FileName baseName
 
FileName pathBaseName
 
FileName oextBaseName
 
bool apply_geo
 Apply geo. More...
 
size_t ndimOut
 Output dimensions. More...
 
size_t zdimOut
 
size_t ydimOut
 
size_t xdimOut
 
DataType datatypeOut
 
size_t mdInSize
 Number of input elements. More...
 
- Public Attributes inherited from XmippProgram
bool doRun
 
bool runWithoutArgs
 
int verbose
 Verbosity level. More...
 
int debug
 

Additional Inherited Members

- Protected Member Functions inherited from XmippMetadataProgram
virtual void initComments ()
 
virtual void postProcess ()
 
virtual bool getImageToProcess (size_t &objId, size_t &objIndex)
 
void show () const override
 
virtual void startProcessing ()
 
virtual void finishProcessing ()
 
virtual void writeOutput ()
 
virtual void showProgress ()
 
virtual void defineLabelParam ()
 
- Protected Member Functions inherited from XmippProgram
void defineCommons ()
 
- Protected Attributes inherited from XmippMetadataProgram
WriteModeMetaData mode
 Metadata writing mode: OVERWRITE, APPEND. More...
 
FileName oext
 Output extension and root. More...
 
FileName oroot
 
MDLabel image_label
 MDLabel to be used to read/write images, usually will be MDL_IMAGE. More...
 
bool produces_an_output
 Indicate that a unique final output is produced. More...
 
bool produces_a_metadata
 Indicate that the unique final output file is a Metadata. More...
 
bool each_image_produces_an_output
 Indicate that an output is produced for each image in the input. More...
 
bool allow_apply_geo
 
bool decompose_stacks
 Input Metadata will treat a stack file as a set of images instead of a unique file. More...
 
bool delete_output_stack
 Delete previous output stack file prior to process images. More...
 
bool get_image_info
 Get the input image file dimensions to further operations. More...
 
bool save_metadata_stack
 Save the associated output metadata when output file is a stack. More...
 
bool track_origin
 Include the original input image filename in the output stack. More...
 
bool keep_input_columns
 Keep input metadata columns. More...
 
bool remove_disabled
 Remove disabled images from the input selfile. More...
 
bool allow_time_bar
 Show process time bar. More...
 
bool input_is_metadata
 Input is a metadata. More...
 
bool single_image
 Input is a single image. More...
 
bool input_is_stack
 Input is a stack. More...
 
bool output_is_stack
 Output is a stack. More...
 
bool create_empty_stackfile
 
bool delete_mdIn
 
size_t time_bar_step
 Some time bar related counters. More...
 
size_t time_bar_size
 
size_t time_bar_done
 
- Protected Attributes inherited from XmippProgram
int errorCode
 
ProgramDefprogDef
 Program definition and arguments parser. More...
 
std::map< String, CommentListdefaultComments
 
int argc
 Original command line arguments. More...
 
const char ** argv
 

Detailed Description

Predict Continuous Parameters.

Definition at line 39 of file angular_continuous_assign.h.

Constructor & Destructor Documentation

◆ ProgAngularContinuousAssign()

ProgAngularContinuousAssign::ProgAngularContinuousAssign ( )

Empty constructor.

Definition at line 51 of file angular_continuous_assign.cpp.

52 {
53  produces_a_metadata = true;
54 }
bool produces_a_metadata
Indicate that the unique final output file is a Metadata.

Member Function Documentation

◆ defineParams()

void ProgAngularContinuousAssign::defineParams ( )
virtual

Define parameters.

Reimplemented from XmippMetadataProgram.

Reimplemented in BasicMpiMetadataProgram< ProgAngularContinuousAssign >.

Definition at line 86 of file angular_continuous_assign.cpp.

87 {
88  addUsageLine("Make a continuous angular assignment");
89  addUsageLine("+This program assigns Euler angles to experimental projections by ");
90  addUsageLine("+minimizing the difference between the given experimental image and ");
91  addUsageLine("+the central slice of a reference volume in Fourier space. All ");
92  addUsageLine("+interpolations are based on a B-spline model of the images and the ");
93  addUsageLine("+volume. The translations are also optimized. Since an iterative ");
94  addUsageLine("+optimization is performed, it must be initialized with some rough ");
95  addUsageLine("+estimate of the angles. The output of xmipp_angular_predict can be ");
96  addUsageLine("+used as initialization without any transformation.");
97  addUsageLine("+The method is fully described at http://www.ncbi.nlm.nih.gov/pubmed/15885434");
98  defaultComments["-i"].clear();
99  defaultComments["-i"].addComment("Metadata with initial alignment");
100  defaultComments["-o"].clear();
101  defaultComments["-o"].addComment("Metadata with output alignment");
103  addParamsLine(" --ref <volume> : Reference volume");
104  addParamsLine(" [--gaussian_Fourier <s=0.5>] : Weighting sigma in Fourier space");
105  addParamsLine(" :+Small values of this parameter concentrate ");
106  addParamsLine(" :+the optimization on low frequencies. This ");
107  addParamsLine(" :+value should be below 1.");
108  addParamsLine(" [--gaussian_Real <s=0.5>] : Weighting sigma in Real space");
109  addParamsLine(" :+Small values of this parameter concentrate ");
110  addParamsLine(" :+the optimization in the image center. This ");
111  addParamsLine(" :+value should be below 1.");
112  addParamsLine(" [--zerofreq_weight <s=0. >] : Zero-frequency weight");
113  addParamsLine(" [--max_iter <max=60>] : Maximum number of iterations");
114  addParamsLine(" :+Convergence might be reached before this number of iterations");
115  addParamsLine(" [--max_shift <s=-1>] : Maximum shift allowed");
116  addParamsLine(" :+Use this option to limit the maximum shift that the ");
117  addParamsLine(" :+optimization process can find. If the minimum is ");
118  addParamsLine(" :+found beyond this limit (note it is an absolute limit ");
119  addParamsLine(" :+on the shift and it is not relative to the initial shift), ");
120  addParamsLine(" :+then the solution given by the initial guess is kept ");
121  addParamsLine(" :+since the optimized one looks suspicious.");
122  addParamsLine(" [--max_angular_change <a=-1>]: Maximum angular change allowed");
123  addParamsLine(" :+Use this option to limit the maximum angular ");
124  addParamsLine(" :+change with respect to the initial solution ");
125  addParamsLine(" :+that the optimization algorithm can find. If ");
126  addParamsLine(" :+the solution found is beyond this limit, then ");
127  addParamsLine(" :+the initial solution is returned instead of the ");
128  addParamsLine(" :+optimized one since this latter looks suspicious.");
129  addExampleLine("A typical use is:",false);
130  addExampleLine("xmipp_angular_continuous_assign -i anglesFromDiscreteAssignment.doc --ref reference.vol -o assigned_angles.xmd");
131 }
void addExampleLine(const char *example, bool verbatim=true)
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)
std::map< String, CommentList > defaultComments
Definition: xmipp_program.h:83

◆ preProcess()

void ProgAngularContinuousAssign::preProcess ( )
virtual

Produce side info. An exception is thrown if any of the files is not found

Reimplemented from XmippMetadataProgram.

Reimplemented in BasicMpiMetadataProgram< ProgAngularContinuousAssign >.

Definition at line 134 of file angular_continuous_assign.cpp.

135 {
136  // Read the reference volume
137  Image<double> V;
138  V.read(fn_ref);
139  V().setXmippOrigin();
140 
141  // Prepare the masks in real space
142  Mask mask_Real3D;
143  mask_Real3D.type = mask_Real.type = GAUSSIAN_MASK;
144  mask_Real3D.mode = mask_Real.mode = INNER_MASK;
145 
146  mask_Real3D.sigma = mask_Real.sigma = gaussian_Real_sigma * ((double)XSIZE(V()));
147 
148  mask_Real3D.generate_mask(V());
149  mask_Real.generate_mask(YSIZE(V()), XSIZE(V()));
150 
151  double gs2 = 2. * PI * gaussian_Real_sigma * gaussian_Real_sigma * ((double)XSIZE(V()) * (double) XSIZE(V()));
152  double gs3 = gs2 * sqrt(2. * PI) * gaussian_Real_sigma * ((double) XSIZE(V()));
153 
154  mask_Real3D.get_cont_mask() *= gs3;
155  mask_Real.get_cont_mask() *= gs2;
156 
157  //For debugging
158  /*Image<double> mask2D_test;
159  mask2D_test.read("ident2D.spi"); //Identity image
160  mask2D_test().setXmippOrigin();
161  mask_Real.apply_mask(mask2D_test(), mask2D_test());
162  mask2D_test.write("mask_2Dtest.xmp");*/
163 
164  // Prepare the weight function in Fourier space
167 
168  mask_Fourier.sigma = gaussian_DFT_sigma * ((double)XSIZE(V()));
170 
171  double gsf2 = 2. * PI * gaussian_DFT_sigma * gaussian_DFT_sigma * ((double)XSIZE(V()) * (double)XSIZE(V()));
172  mask_Fourier.get_cont_mask() *= gsf2;
174 
175  // Weight the input volume in real space
176  mask_Real3D.apply_mask(V(), V());
177 
178  // Perform the DFT of the reference volume
179  int Status;
180  reDFTVolume = V();
181  imDFTVolume.resize(V());
182  CenterFFT(reDFTVolume, false);
184  MULTIDIM_ARRAY(imDFTVolume), XSIZE(V()), YSIZE(V()), ZSIZE(V()),
185  &Status);
186  CenterFFT(reDFTVolume, true);
187  CenterFFT(imDFTVolume, true);
188 }
#define YSIZE(v)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
Definition: mask.h:360
void sqrt(Image< double > &op)
double sigma
Definition: mask.h:442
#define MULTIDIM_ARRAY(v)
MultidimArray< double > imDFTVolume
void CenterFFT(MultidimArray< T > &v, bool forward)
Definition: xmipp_fft.h:291
void apply_mask(const MultidimArray< T > &I, MultidimArray< T > &result, T subs_val=0, bool apply_geo=false)
Definition: mask.h:635
int VolumeDftRealToRealImaginary(double *Re2Re, double *ImOut, long Nx, long Ny, long Nz, int *Status)
#define XSIZE(v)
int type
Definition: mask.h:402
#define ZSIZE(v)
MultidimArray< double > reDFTVolume
const MultidimArray< double > & get_cont_mask() const
Definition: mask.h:728
void generate_mask(bool apply_geo=false)
Definition: mask.cpp:1577
#define GAUSSIAN_MASK
Definition: mask.h:369
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
#define PI
Definition: tools.h:43
int mode
Definition: mask.h:407
constexpr int INNER_MASK
Definition: mask.h:47

◆ processImage()

void ProgAngularContinuousAssign::processImage ( const FileName fnImg,
const FileName fnImgOut,
const MDRow rowIn,
MDRow rowOut 
)
virtual

Predict angles and shift. At the input the pose parameters must have an initial guess of the parameters. At the output they have the estimated pose.

Implements XmippMetadataProgram.

Definition at line 191 of file angular_continuous_assign.cpp.

192 {
193  // Read the image and take its angles from the Metadata
194  // if they are available. If not, take them from the header.
195  // If not, set them to 0.
196  Image<double> img;
197  img.read(fnImg);
198  img().setXmippOrigin();
199 
200  double old_rot, old_tilt, old_psi, old_shiftX, old_shiftY;
201  rowIn.getValue(MDL_ANGLE_ROT,old_rot);
202  rowIn.getValue(MDL_ANGLE_TILT,old_tilt);
203  rowIn.getValue(MDL_ANGLE_PSI,old_psi);
204  rowIn.getValue(MDL_SHIFT_X,old_shiftX);
205  rowIn.getValue(MDL_SHIFT_Y,old_shiftY);
206 
207  Matrix1D<double> pose(5);
208  pose(0) = old_rot;
209  pose(1) = old_tilt;
210  pose(2) = old_psi;
211  pose(3) = -old_shiftX; // The convention of shifts is different
212  pose(4) = -old_shiftY; // for Slavica
213 
214  mask_Real.apply_mask(img(), img());
215 
217  img(), mask_Fourier.get_cont_mask(), pose, max_no_iter);
218 
219  Matrix2D<double> Eold, Enew;
220  Euler_angles2matrix(old_rot,old_tilt,old_psi,Eold);
221  Euler_angles2matrix(pose(0),pose(1),pose(2),Enew);
222  double angular_change=Euler_distanceBetweenMatrices(Eold,Enew);
223  double shift=sqrt(pose(3)*pose(3)+pose(4)*pose(4));
224  double new_rot=old_rot;
225  double new_tilt=old_tilt;
226  double new_psi=old_psi;
227  double new_shiftX=old_shiftX;
228  double new_shiftY=old_shiftY;
229  if (angular_change<max_angular_change || max_angular_change<0)
230  {
231  new_rot = pose(0);
232  new_tilt = pose(1);
233  new_psi = pose(2);
234  }
235  else
236  cost=-1;
237  if (shift<max_shift || max_shift<0)
238  {
239  new_shiftX = -pose(3);
240  new_shiftY = -pose(4);
241  }
242  else
243  cost=-1;
244 
245  rowOut.setValue(MDL_ANGLE_ROT, new_rot);
246  rowOut.setValue(MDL_ANGLE_TILT, new_tilt);
247  rowOut.setValue(MDL_ANGLE_PSI, new_psi);
248  rowOut.setValue(MDL_SHIFT_X, new_shiftX);
249  rowOut.setValue(MDL_SHIFT_Y, new_shiftY);
250  rowOut.setValue(MDL_COST, cost);
251 }
Rotation angle of an image (double,degrees)
void Euler_angles2matrix(T alpha, T beta, T gamma, Matrix2D< T > &A, bool homogeneous)
Definition: geometry.cpp:624
void sqrt(Image< double > &op)
Tilting angle of an image (double,degrees)
Shift for the image in the X axis (double)
Special label to be used when gathering MDs in MpiMetadataPrograms.
double CSTSplineAssignment(MultidimArray< double > &ReDFTVolume, MultidimArray< double > &ImDFTVolume, MultidimArray< double > &image, MultidimArray< double > &weight, Matrix1D< double > &pose_parameters, int max_no_iter)
MultidimArray< double > imDFTVolume
void apply_mask(const MultidimArray< T > &I, MultidimArray< T > &result, T subs_val=0, bool apply_geo=false)
Definition: mask.h:635
T & getValue(MDLabel label)
Cost for the image (double)
double Euler_distanceBetweenMatrices(const Matrix2D< double > &E1, const Matrix2D< double > &E2)
Definition: geometry.cpp:671
MultidimArray< double > reDFTVolume
const MultidimArray< double > & get_cont_mask() const
Definition: mask.h:728
void setValue(MDLabel label, const T &d, bool addLabel=true)
double cost
Cost, scaled between 0 and 1.
Definition: micrograph.h:66
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
Shift for the image in the Y axis (double)

◆ readParams()

void ProgAngularContinuousAssign::readParams ( )
virtual

Read argument from command line.

Reimplemented from XmippMetadataProgram.

Reimplemented in BasicMpiMetadataProgram< ProgAngularContinuousAssign >.

Definition at line 57 of file angular_continuous_assign.cpp.

58 {
60  fn_ref = getParam("--ref");
61  gaussian_DFT_sigma = getDoubleParam("--gaussian_Fourier");
62  gaussian_Real_sigma = getDoubleParam("--gaussian_Real");
63  weight_zero_freq = getDoubleParam("--zerofreq_weight");
64  max_no_iter = getIntParam("--max_iter");
65  max_shift = getDoubleParam("--max_shift");
66  max_angular_change = getDoubleParam("--max_angular_change");
67 }
double getDoubleParam(const char *param, int arg=0)
const char * getParam(const char *param, int arg=0)
int getIntParam(const char *param, int arg=0)

◆ show()

void ProgAngularContinuousAssign::show ( )

Show.

Definition at line 70 of file angular_continuous_assign.cpp.

71 {
72  if (!verbose)
73  return;
75  std::cout << "Reference volume: " << fn_ref << std::endl
76  << "Gaussian Fourier: " << gaussian_DFT_sigma << std::endl
77  << "Gaussian Real: " << gaussian_Real_sigma << std::endl
78  << "Zero-frequency weight:"<< weight_zero_freq << std::endl
79  << "Max. Iter: " << max_no_iter << std::endl
80  << "Max. Shift: " << max_shift << std::endl
81  << "Max. Angular Change: " << max_angular_change << std::endl
82  ;
83 }
int verbose
Verbosity level.
void show() const override

Member Data Documentation

◆ fn_ref

FileName ProgAngularContinuousAssign::fn_ref

Filename of the reference volume

Definition at line 43 of file angular_continuous_assign.h.

◆ gaussian_DFT_sigma

double ProgAngularContinuousAssign::gaussian_DFT_sigma

Gaussian weight sigma in Fourier space.

Definition at line 45 of file angular_continuous_assign.h.

◆ gaussian_Real_sigma

double ProgAngularContinuousAssign::gaussian_Real_sigma

Gaussian weight sigma in real space.

Definition at line 47 of file angular_continuous_assign.h.

◆ imDFTVolume

MultidimArray<double> ProgAngularContinuousAssign::imDFTVolume

Definition at line 62 of file angular_continuous_assign.h.

◆ mask_Fourier

Mask ProgAngularContinuousAssign::mask_Fourier

Definition at line 64 of file angular_continuous_assign.h.

◆ mask_Real

Mask ProgAngularContinuousAssign::mask_Real

Definition at line 66 of file angular_continuous_assign.h.

◆ max_angular_change

double ProgAngularContinuousAssign::max_angular_change

Maximum angular change allowed

Definition at line 57 of file angular_continuous_assign.h.

◆ max_no_iter

int ProgAngularContinuousAssign::max_no_iter

Maximum number of iterations

Definition at line 51 of file angular_continuous_assign.h.

◆ max_shift

double ProgAngularContinuousAssign::max_shift

Maximum shift allowed

Definition at line 55 of file angular_continuous_assign.h.

◆ quiet

bool ProgAngularContinuousAssign::quiet

Do not produce any output

Definition at line 53 of file angular_continuous_assign.h.

◆ reDFTVolume

MultidimArray<double> ProgAngularContinuousAssign::reDFTVolume

Definition at line 60 of file angular_continuous_assign.h.

◆ weight_zero_freq

double ProgAngularContinuousAssign::weight_zero_freq

Weight for zero frequency.

Definition at line 49 of file angular_continuous_assign.h.


The documentation for this class was generated from the following files: