Xmipp  v3.23.11-Nereus
basic_art.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Carlos Oscar S. Sorzano (coss@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 
27 /* Here are all basic functions which are not extra_parameter dependent for
28  the ART process. The extra parameter dependent functions are implemented
29  in the Basic_art.inc file and must be included in each specific
30  implementation (single particles, crystals, ...) */
31 
32 #include "basic_art.h"
33 #include "data/projection.h"
34 #include "core/metadata_sql.h"
36 #include "recons_misc.h"
37 
38 /* Desctructor */
40 {
41  delete fh_hist;
42  delete[] IMG_Inf;
43  delete D;
44  delete Dinv;
45  delete GVNeq;
46  delete surface_mask;
47 }
48 
49 /* Default values ========================================================== */
51 {
52  fh_hist = nullptr;
53  fn_start = "";
54  fn_sym = "";
55  force_sym = 0;
57  do_not_use_symproj = false;
58  fn_surface_mask = "";
60  block_size = 1;
61  eq_mode = ARTK;
62  random_sort = false;
63  dont_sort = false;
64  sort_last_N = 2;
65  WLS = false;
66  no_it = 1;
71  stop_at = 0;
72  basis.setDefault();
73  grid_relative_size = 1.41;
74  grid_type = BCC;
75  proj_ext = 0;
79  R = -1;
80  print_system_matrix = false;
81  tell = 0;
83  is_crystal = false;
84  variability_analysis = false;
85  refine = false;
86  noisy_reconstruction = false;
87 
88  IMG_Inf = nullptr;
89  D = nullptr;
90  Dinv = nullptr;
91  GVNeq = nullptr;
92 
93  surface_mask = nullptr;
94  POCS_freq = 1;
95 
96  known_volume = -1;
97  positivity = false;
98  unmatched = false;
99  ray_length = -1;
100  apply_shifts = true;
101 
102  sampling = 1.;
103  sym_each = 0;
104  ref_trans_after = -1;
105  ref_trans_step = -1;
106  sparseEps = -1;
107  diffusionWeight = -1;
108  max_tilt = 10.e6;
109  grid_relative_size = 1.41;
110  fn_control = "";
111 
112  threads = 1;
113 }
114 
115 void BasicARTParameters::defineParams(XmippProgram * program, bool mpiMode)
116 {
117 
118  program->addParamsLine(" == I/O Parameters == ");
119  program->addParamsLine(" -i <md_file> : Metadata file with input projections");
120  program->addParamsLine(" [-o <volume_file=\"rec_art.vol\">] : Filename for output volume.");
121  program->addParamsLine(" : Rootname for rest of output files is taken from volume filename");
122  program->addParamsLine(" :+++The created files are as follows: %BR%");
123  program->addParamsLine(" :+++ =outputname.vol= 3D reconstruction in voxels %BR%");
124  program->addParamsLine(" :+++ =outputname.basis= 3D reconstruction in basis if the =--save_basis= option is enabled). The grid parameters are also stored in the same file %BR%");
125  program->addParamsLine(" :+++ =outputname.hist= History and information about the 3D reconstruction process %BR%");
126  program->addParamsLine(" [--ctf <ctf_file=\"\">] : Metadata file with CTFs");
127  program->addParamsLine(" [--unmatched] : Apply unmatched forward/backward projectors");
128  program->addParamsLine(" [--start <basisvolume_file=\"\">] : Start from this basis volume. The reconstruction is performed in the same grid as the one ");
129  program->addParamsLine(" : in which the basis volume was stored (any -FCC or -CC or grid size value are useless)");
130  program->addParamsLine(" [--max_tilt <alpha=10.e+6>] : Skip projections with absolute tilt angle greater than alpha.");
131  program->addParamsLine(" : It means that if alpha=40, then only images with tilt angle ");
132  program->addParamsLine(" : within the ranges 0+/-40 and 180+/-40 will be processed. (Projection");
133  program->addParamsLine(" : tilt angles are forced to be in the range 0-360)");
134  program->addParamsLine(" [--ref_trans_after <n=-1>] : Refine the translation alignment after n projections. (Integer type)");
135  program->addParamsLine(" [--ref_trans_step <v=-1>] : Maximum displacement in translation alignment. (Double type)");
136  program->addParamsLine(" [--sparse <eps=-1>] : Sparsity threshold");
137  program->addParamsLine(" [--diffusion <eps=-1>] : Diffusion weight");
138  program->addParamsLine(" [--surface <surf_mask_file=\"\">] : Mask for the surface constraint. It says where the volume is known to be 0");
139  program->addParamsLine(" [--POCS_freq <f=1>] : Impose POCS conditions every f projections");
140  program->addParamsLine(" [--known_volume <value=-1>] : The volume is cut down to this mass, ie, the highest [value] voxels are kept while ");
141  program->addParamsLine(" : the rest are set to 0");
142  program->addParamsLine(" [--POCS_positivity] : Force the resulting volume to be positive");
143  program->addParamsLine(" [--goldmask <value=1.e+6>] : Pixels below this value are considered to come from gold beads and are not used for reconstruction");
144  program->addParamsLine(" [--shiftedTomograms] : Remove external zero-valued border pixels created by alignment of tomograms");
145  program->addParamsLine(" [--dont_apply_shifts] : Do not apply shifts as stored in the 2D-image headers");
146  program->addParamsLine(" [--variability] : Perform variability analysis");
147  program->addParamsLine(" [--refine] : Refine input projection before backprojecting");
148  program->addParamsLine(" [--noisy_reconstruction] : Perform a companion noisy reconstruction. ");
149  program->addParamsLine(" :+ If given, the algorithm will perform two reconstructions. One with the input ");
150  program->addParamsLine(" :+ data, and another one with pure noise images applying exactly the same procedure ");
151  program->addParamsLine(" :+ as to the signal projections. This reconstruction is further used by ");
152  program->addParamsLine(" :+ the SSNR program in order to calculate the VSSNR or the SSNR itself.");
153  program->addParamsLine(" :+++ The created files are as follows: %BR%");
154  program->addParamsLine(" :+++ =[fn_root]_noise.vol= Reconstruction of the pure noise %BR%");
155  program->addParamsLine(" :+++ =[fn_root]_noise_proj.sel= Selection file with the pure noise images %BR%");
156  program->addParamsLine(" :+++ =[fn_root]_signal_proj.sel= Selection file with the signal images (a reordered version of the input (-i) selfile) %BR%");
157  program->addParamsLine(" :+++ =[fn_root]_noise_proj.stk= Pure noise images used for the reconstruction %BR%");
158  program->addParamsLine(" [--ray_length <r=-1>] : Length of the ray in basis units that will be projected onto the image plane");
159 
160  program->addParamsLine(" == Symmetry parameters == ");
161  program->addParamsLine(" [--sym <sym_file=\"\">] : Use a symmetry file. It should give symmetry elements, ie, rotational axis, ");
162  program->addParamsLine(" : symmetry planes or whatever such that new points of view can be obtained");
163  program->addParamsLine(" [--sym_each <n=0>] : Force the reconstruction to be symmetric each n projections");
164  program->addParamsLine(" [--force_sym <n=0>] : Force the reconstruction to be symmetric n times at each projection");
165  program->addParamsLine(" [--no_group] : Do not generate symmetry subgroup");
166  program->addParamsLine(" [--no_symproj] : Do not use symmetrized projections");
167 
168  program->addParamsLine(" == Iteration parameters == ");
169  program->addParamsLine(" [-l <...>] : Relaxation factor, by default 0.01 (recommended range 0.0 - 0.1). ");
170  program->addParamsLine(" : A list of lambda values is also accepted as \"-l lambda0 lambda1 ...\"");
171  program->addParamsLine(" [-n <noit=1>] : Number of iterations");
172  program->addParamsLine(" [--stop_at <it_stop=0>] : Total number of iterated projections before algorithm stops. ");
173  program->addParamsLine(" :+ For instance, if there are 100 images, with two iterations and we ");
174  program->addParamsLine(" :+ want to stop at the half of the second iteration, then you must set it to 150");
175  program->addParamsLine(" [--equation_mode <mode=ARTK> ]: Equation to project onto the hyperplane");
176  program->addParamsLine(" where <mode> ");
177  program->addParamsLine(" ARTK : Block ART");
178  program->addParamsLine(" CAV : Component Averaging");
179  program->addParamsLine(" CAVK : Block Component Averaging");
180  program->addParamsLine(" CAVARTK : Component Averaging Variant of Block ART");
181 
182  program->addParamsLine(" [--sort_last <N=2>] : By default the algorithm sorts projections in the most orthogonally possible way. ");
183  program->addParamsLine(" : The most orthogonal way is defined as choosing the projection which maximizes the ");
184  program->addParamsLine(" : dot product with the N previous inserted projections. Use -1 to sort with all ");
185  program->addParamsLine(" : previous projections");
186  program->addParamsLine(" or --random_sort : Instead of orthogonal sort, projections are presented randomly to the algorithm");
187  program->addParamsLine(" or --no_sort : No sort must be applied");
188  program->addParamsLine(" [--WLS] : Perform weighted least squares ART");
189  program->addParamsLine(" [-k <...> ] : Relaxation factor for WLS residual, by default 0.5. ");
190  program->addParamsLine(" : A list of kappa values is also accepted as \"-k kappa0 kappa1 ...\"");
191 
192  program->addParamsLine(" == Basis Parameters ==");
193  Basis::defineParams(program);
194 
195  program->addParamsLine(" == Grid parameters == ");
196  program->addParamsLine(" [-g <gridsz=1.41>] : Relative size of the measuring unit in the grid lattice in pixels. By default, a unit in ");
197  program->addParamsLine(" : the grid system equals 1.41 units in the Universal System. This value is optimized ");
198  program->addParamsLine(" : for a BCC structure");
199  program->addParamsLine(" :+++ %BR% <verbatim>");
200  program->addParamsLine(" : if gridsz = -1 => gridsz=2^(1/2)");
201  program->addParamsLine(" :+++ </verbatim> <verbatim> ");
202  program->addParamsLine(" : -2 => gridsz=2^(1/3)");
203  program->addParamsLine(" :+++ </verbatim> ");
204  program->addParamsLine(" [--grid_type <type=BCC>] : Shape of the grid structure");
205  program->addParamsLine(" where <type>");
206  program->addParamsLine(" BCC : Body Centered Cubic");
207  program->addParamsLine(" FCC : Face Centered Cubic");
208  program->addParamsLine(" SC : Simple Cubic");
209  program->addParamsLine(" [-R <interest_sphere=-1>] : Radius of the interest sphere. If provided, ART runs twice faster since only the ");
210  program->addParamsLine(" : sphere with this radius (in pixel units) is reconstructed");
211  program->addParamsLine(" [--ext <proj_ext=0>] : Projection extension. In order to avoid the box effect (those voxels near the volume ");
212  program->addParamsLine(" : borders are brighter than the rest), you can extent your projections resulting in ");
213  program->addParamsLine(" : a slower reconstruction but more accurate. Recommended values to avoid the box ");
214  program->addParamsLine(" : effect go from 5 to 10");
215  program->addParamsLine(" [--output_size <Xsize=0> <Ysize=0> <Zsize=0>] : Output volume size in Pixels. Reconstruction size is taken from ");
216  program->addParamsLine(" : the projection size. However, the output size can be different, if the output volume ");
217  program->addParamsLine(" : is bigger, then the volume is zero padded.");
218  program->addParamsLine(" [--sampling_rate <Ts=1>] : Pixel size (Angstroms)");
219 
220  program->addParamsLine(" ==+ Parallel parameters == ");
221  program->addParamsLine(" : by default, sequential ART is applied");
222  program->addParamsLine(" [--thr <N=1>] : Number of threads to use. NOTE: Not available when using MPI.");
223  program->addParamsLine(" [--parallel_mode <mode=ART>]: Parallelization algorithm to use with threads or MPI program version");
224  program->addParamsLine(" where <mode>");
225  program->addParamsLine(" ART : Default");
226  program->addParamsLine(" SIRT : Simultaneous Iterative Reconstruction Technique");
227  program->addParamsLine(" pSIRT : Parallel (MPI) Simultaneous Iterative Reconstruction Technique");
228  program->addParamsLine(" pfSIRT : Parallel (MPI) False Simultaneous Iterative Reconstruction Technique (Faster convergence than pSIRT)");
229  program->addParamsLine(" pSART : Parallel (MPI) Simultaneous ART");
230  program->addParamsLine(" pAVSP : Parallel (MPI) Average Strings");
231  program->addParamsLine(" pBiCAV : Parallel (MPI) Block Iterative CAV");
232  program->addParamsLine(" pCAV : Parallel (MPI) CAV");
233  program->addParamsLine(" [--block_size <n=1>] : Number of projections for each block (SART and BiCAV)");
234 
235  program->addParamsLine("==+ Debugging options ==");
236  program->addParamsLine(" [--print_system_matrix] : Print the matrix of the system Ax=b. The format is:");
237  program->addParamsLine(" :+++ %BR% <verbatim>");
238  program->addParamsLine(" : Equation system (Ax=b) ---------------------- ");
239  program->addParamsLine(" :+++ </verbatim> <verbatim> ");
240  program->addParamsLine(" : pixel=<p> --> <b> = <a1> <a2> ... ");
241  program->addParamsLine(" :+++ </verbatim> ");
242  program->addParamsLine(" : I.e., for the pixel p (pixels are numbered lexicographically) with experimental ");
243  program->addParamsLine(" : value b, the equation ax=b is set. a is the corresponding row of matrix A. The ");
244  program->addParamsLine(" : coefficient a_i is equal to the contribution of the basis i to pixel p. x is the ");
245  program->addParamsLine(" : number of basis");
246  program->addParamsLine(" [--show_iv <n=10>] : Show volumes/images as the reconstruction goes. The volume is update every n projections");
247  program->addParamsLine(" [--show_error] : Show error for each projection");
248  program->addParamsLine(" [--show_stats] : Give some statistical information during the process, they might be useful to see how the process is ");
249  program->addParamsLine(" : going. The mean squared error for each projection is shown by default");
250  program->addParamsLine(" [--save_at_each_step] : Save intermediate projections. This option allows deep debugging as it save all projections and volumes ");
251  program->addParamsLine(" : involved in the reconstruction process. After each step you are asked to press a key, so that you could ");
252  program->addParamsLine(" : inspect carefully the results. The names for these files are:");
253  program->addParamsLine(" : PPPtheo, PPPread, PPPcorr, PPPdiff");
254  program->addParamsLine(" : PPPbasis.basis, PPPvol.vol");
255  program->addParamsLine(" : PPPvolPOCS1, PPPvolPOCS2, PPPvolPOCS3");
256  program->addParamsLine(" [--save_intermediate <n=0>] : Save intermediate volumes (every <n> projections). If not provided, volumes are stored at each iteration ");
257  program->addParamsLine(" : and this parameter must be used at the end of the command to prevent errors. The names for these volumes are:");
258  program->addParamsLine(" :+++ %BR%");
259  program->addParamsLine(" : [filename root]it[it_no].vol Ex: art0001it0.vol ");
260  program->addParamsLine(" :+++ %BR%");
261  program->addParamsLine(" : [filename root]it]it_no].basis If the --save_basis option is enabled");
262  program->addParamsLine(" :+++ %BR%");
263  program->addParamsLine(" [--save_basis] : Save also the 3D reconstruction in basis each time that you have to save the reconstructed volume");
264  program->addParamsLine(" [--manual_order] : You are prompted to give the number of the following projection to be presented to the algorithm");
265  program->addParamsLine(" [--only_sym] : Skip all those projections generated by symmetry (symmetries different from -1)");
266 
267 }
268 
270 {
271  defaultValues();
272 
273  fn_sel = program->getParam("-i");
274  fn_out = program->getParam("-o");
276 
277  fn_ctf = program->getParam("--ctf");
278  unmatched = program->checkParam("--unmatched");
279  fn_start = program->getParam("--start");
280  max_tilt = program->getDoubleParam("--max_tilt");
281  ref_trans_after = program->getIntParam("--ref_trans_after");
282  ref_trans_step = program->getIntParam("--ref_trans_step");
283  sparseEps = program->getDoubleParam("--sparse");
284  diffusionWeight = program->getDoubleParam("--diffusion");
285  fn_surface_mask = program->getParam("--surface");
286  POCS_freq = program->getIntParam("--POCS_freq");
287  known_volume = program->getDoubleParam("--known_volume");
288  positivity = program->checkParam("--POCS_positivity");
289  goldmask = program->getDoubleParam("--goldmask");
290  shiftedTomograms = program->checkParam("--shiftedTomograms");
291  apply_shifts = !program->checkParam("--dont_apply_shifts");
292 
293  ray_length = program->getDoubleParam("--ray_length");
294 
295  // Symmetry parameters
296  fn_sym = program->getParam("--sym");
297  sym_each = program->getIntParam("--sym_each");
298  force_sym = program->getIntParam("--force_sym");
299  do_not_generate_subgroup = program->checkParam("--no_group");
300  do_not_use_symproj = program->checkParam("--no_symproj");
301 
302  // Iteration parameters
303  StringVector list;
304  program->getListParam("-l", list);
305  size_t listSize = list.size();
306 
307  if (listSize != 0)
308  {
309  lambda_list.resizeNoCopy(listSize);
310 
311  for (size_t k = 0; k < listSize; k++)
312  VEC_ELEM(lambda_list, k) = textToFloat(list[k]);
313  }
314 
315  no_it = program->getIntParam("-n");
316  stop_at = program->getIntParam("--stop_at");
317 
318  String tempString = program->getParam("--equation_mode");
319  if (tempString == "CAVK")
320  eq_mode = CAVK;
321  else if (tempString == "CAV")
322  eq_mode = CAV;
323  else if (tempString == "CAVARTK")
324  eq_mode = CAVARTK;
325  else
326  eq_mode = ARTK;
327 
328  sort_last_N = program->getIntParam("--sort_last");
329  random_sort = program->checkParam("--random_sort");
330  dont_sort = program->checkParam("--no_sort");
331  WLS = program->checkParam("--WLS");
332 
333  list.clear();
334  program->getListParam("-k", list);
335  listSize = list.size();
336  if (listSize != 0)
337  {
338  kappa_list.resizeNoCopy(listSize);
339 
340  for (size_t k = 0; k < listSize; k++)
341  VEC_ELEM(kappa_list, k) = textToFloat(list[k]);
342  }
343 
344  // Basis parameters
345  basis.readParams(program);
346 
347  // Grid parameters
349  grid_type = CC;
350 
351  if (program->checkParam("-g"))
352  {
353  grid_relative_size = program->getDoubleParam("-g");
354  if (grid_relative_size == -1)
355  grid_relative_size = sqrt (2.0);
356  else if (grid_relative_size == -2)
357  grid_relative_size = pow (2.0,1.0/3.0);
358  }
359  else
361 
362  tempString = program->getParam("--grid_type");
363 
364  if (tempString == "BCC")
365  grid_type = BCC;
366  if (tempString == "FCC")
367  grid_type = FCC;
368  else if (tempString == "SC")
369  grid_type = CC;
370  else
371  grid_type = BCC;
372 
373  R = program->getDoubleParam("-R");
374  proj_ext = program->getIntParam("--ext");
375  Xoutput_volume_size = program->getIntParam("--output_size", 0);
376  Youtput_volume_size = program->getIntParam("--output_size", 1);
377  Zoutput_volume_size = program->getIntParam("--output_size", 2);
378  sampling = program->getDoubleParam("--sampling_rate");
379 
380  // Parallel parameters
381  threads = program->getIntParam("--thr");
382 
383  tempString = program->getParam("--parallel_mode");
384 
385  if (tempString == "pSART")
387  else if (tempString == "pSIRT")
389  else if (tempString == "SIRT")
391  else if (tempString == "pfSIRT")
393  else if (tempString == "pBiCAV")
395  else if (tempString == "pAVSP")
397  else if (tempString == "pCAV")
399  else
401 
402  block_size = program->getIntParam("--block_size");
403  // fn_control = program->getParam("--control");
404 
405  // Debugging parameters
406  print_system_matrix = program->checkParam("--print_system_matrix");
407  if (program->checkParam("--show_error"))
409  if (program->checkParam("--manual_order"))
411  if (program->checkParam("--only_sym"))
412  tell |= TELL_ONLY_SYM;
413  if (program->checkParam("--save_at_each_step"))
415  if (program->checkParam("--save_basis"))
417  if (program->checkParam("--show_stats"))
418  tell |= TELL_STATS;
419  if (program->checkParam("--save_intermediate"))
420  {
422  save_intermidiate_every = program->getIntParam("save_intermediate");
423  }
424  if (program->checkParam("--show_iv"))
425  {
426  tell |= TELL_IV;
427  save_intermidiate_every = program->getIntParam("save_intermediate");
428  }
429 
430  verbose = program->getIntParam("--verbose");
431 
432  if (program->checkParam("--variability"))
433  {
434  variability_analysis = true;
436  no_it = 1;
437  }
438 
439  refine = program->checkParam("--refine");
440 
441  if (program->checkParam("--noisy_reconstruction"))
442  {
443  if (parallel_mode != ART)
444  REPORT_ERROR(ERR_ARG_INCORRECT,"BasicARTParameters::read: Noisy reconstructions" \
445  " can only be done for ART");
446  else
447  noisy_reconstruction = true;
448  }
449 
450  // Measures are given in pixels, independent of pixel size
451  // //divide by the sampling rate
452  // if (sampling != 1.)
453  // {
454  // basis.setSamplingRate(sampling);
455  // grid_relative_size /= sampling;
456  // if (R != -1.)
457  // R /= sampling;
458  // ref_trans_step /= sampling;
459  // }
460 
461 
462 }
463 
464 /* ------------------------------------------------------------------------- */
465 /* Produce Side Information */
466 /* ------------------------------------------------------------------------- */
467 //#define DEBUG
469  int rank)
470 {
471  MetaDataVec selfile;
472 
473  /* If checking the variability --------------------------------------------- */
476 
477  /* Create history file handler --------------------------------------------- */
478  if (level >= FULL)
479  {
480  fh_hist = new std::ofstream;
481  fh_hist->open((fn_root + ".hist").c_str(), std::ios::out);
482  if (!fh_hist)
483  REPORT_ERROR(ERR_IO_NOWRITE, fn_root + ".hist");
484  }
485 
486  /* Get True Image number and projection size ------------------------------- */
487  if (level >= BASIC)
488  {
489  //take into account weights here
490  if (WLS)
491  {
492  MetaDataDb SF_aux;
493  SF_aux.read(fn_sel);
494  if (SF_aux.containsLabel(MDL_ENABLED))
495  SF_aux.removeObjects(MDValueEQ(MDL_ENABLED, -1));
496  MetaDataDb tmp; // so that we can easily import
497  tmp.importObjects(SF_aux, MDValueRange(MDL_WEIGHT, 1e-9, 99e99));
498  if (tmp.size() == 0)
499  REPORT_ERROR(ERR_MD_OBJECTNUMBER, "There is no input file with weight!=0");
500  selfile = tmp; // copy results to the vector version
501  }
502  else
503  {
504  selfile.read(fn_sel);
505  if (selfile.containsLabel(MDL_ENABLED))
506  selfile.removeObjects(MDValueEQ(MDL_ENABLED, -1));
507  }
508  trueIMG = selfile.size();
509  if (trueIMG == 0)
510  REPORT_ERROR(ERR_MD_OBJECTNUMBER, "Produce_Basic_ART_Side_Info: No images !!");
511  size_t idum, idumLong;
512  getImageSize(selfile, projXdim, projYdim, idum, idumLong);
513  }
514 
515  /* Read symmetry file -------------------------------------------------- */
516  if (level >= FULL)
517  {
518  double accuracy = do_not_generate_subgroup ? -1 : 1e-6;
519  if (fn_sym != "")
520  SL.readSymmetryFile(fn_sym, accuracy);
521  if (!do_not_use_symproj)
522  numIMG = trueIMG * (SL.symsNo() + 1);
523  else
524  numIMG = trueIMG;
525  }
526 
527  /* Read surface mask --------------------------------------------------- */
528  if (level >= FULL)
529  {
530  if (fn_surface_mask != "")
531  {
534  (*surface_mask)().setXmippOrigin();
535  }
536  }
537 
538  /* Fill ART_sort_info structure and Sort ------------------------------- */
539  if (level >= FULL)
540  {
541  buildReconsInfo(selfile, fn_ctf, SL, IMG_Inf,
543 
544  if (!(tell&TELL_MANUAL_ORDER))
545  {
546  if (parallel_mode == SIRT ||
547  parallel_mode == pSIRT ||
548  parallel_mode == pfSIRT ||
549  parallel_mode == pCAV ||
550  eq_mode == CAV ||
551  rank > 0 || dont_sort)
553  else if (random_sort)
555  else if (sort_last_N != -1)
557  sort_last_N);
558  else
560  }
561  }
562 
563  /* In case of weighted least-squares, find average weight & write residual images ------ */
564  if (WLS)
565  {
566  FileName fn_resi;
567  Projection read_proj;
568  double weight;
569 
570  sum_weight = 0.;
571  for (int iact_proj = 0; iact_proj < numIMG ; iact_proj++)
572  {
573 
574  fn_resi = IMG_Inf[iact_proj].fn_proj;
575  read_proj.read(fn_resi);
576  read_proj().setXmippOrigin();
577  weight = read_proj.weight();
578  if (weight < 0)
580  "BASIC_ART: negative weight not set correctly!");
581  sum_weight += weight;
582  /*
583  read_proj().initZeros();
584  fn_resi+="."+fn_root+"_residual";
585  if (IMG_Inf[iact_proj].sym>-1)
586  fn_resi+=integerToString(IMG_Inf[iact_proj].sym);
587  read_proj.write(fn_resi);
588  */
589  }
590 
591  *fh_hist << "WLS-ART% Sum over all weights = " << sum_weight << std::endl;
592  }
593 
594  /* Setting initial volumes ------------------------------------------------- */
595  if (level >= FULL)
596  {
597  if ( !fn_start.empty() )
598  {
599  if (fn_start.contains("basis")) // A basis file
600  vol_basis0.read(fn_start, basis.basisName());
601  else // If it is a volume of voxels
602  {
603  Image<double> imTemp;
604  imTemp.read(fn_start);
605  basis.changeFromVoxels(imTemp(), vol_basis0, grid_type, grid_relative_size,
606  nullptr, nullptr, R, threads);
607  }
608  }
609  else
610  {
611  Grid grid_basis;
612  if (R == -1)
613  {
614  Matrix1D<double> corner;
615  if (basis.type == Basis::blobs)
616  {
617  if (Zoutput_volume_size == 0)
618  corner = vectorR3((double)projXdim / 2, (double)projXdim / 2,
619  (double)projXdim / 2);
620  else
621  corner = vectorR3(
622  (double)Xoutput_volume_size / 2,
623  (double)Youtput_volume_size / 2,
624  (double)Zoutput_volume_size / 2);
625  }
626  else
627  {
628  if (Zoutput_volume_size == 0)
629  corner = vectorR3(-(double)FIRST_XMIPP_INDEX(projXdim),
630  -(double)FIRST_XMIPP_INDEX(projXdim),
631  -(double)FIRST_XMIPP_INDEX(projXdim));
632  else
636  }
637  /* If you subtract half the basis radius, you are forcing that the
638  last basis touches slightly the volume border. By not subtracting
639  it there is a basis center as near the border as possible. */
640  corner = corner + proj_ext/*CO: -blob.radius/2*/;
641  switch (grid_type)
642  {
643  case CC:
644  grid_basis = Create_CC_grid(grid_relative_size, -corner, corner);
645  break;
646  case FCC:
647  grid_basis = Create_FCC_grid(grid_relative_size, -corner, corner);
648  break;
649  case BCC:
650  grid_basis = Create_BCC_grid(grid_relative_size, -corner, corner);
651  break;
652  }
653  }
654  else
655  {
656  switch (grid_type)
657  {
658  case CC:
659  grid_basis = Create_CC_grid(grid_relative_size, R);
660  break;
661  case FCC:
662  grid_basis = Create_FCC_grid(grid_relative_size, R);
663  break;
664  case BCC:
665  grid_basis = Create_BCC_grid(grid_relative_size, R);
666  break;
667  }
668  }
669  vol_basis0.adapt_to_grid(grid_basis);
670  }
671  }
672 
673  /* Basis side info --------------------------------------------------------- */
674  if (level >= BASIC)
675 {
676  basis.setD(D);
677  basis.produceSideInfo(vol_basis0.grid());
678  }
679 
680  /* Express the ray length in basis units ----------------------------------- */
681  if (ray_length != -1)
683 
684  /* With CAV equalization mode weights must be calculated, but for the parallel cases
685  where weights are calculated in a parallel manner.*/
686  if(eq_mode == CAV && parallel_mode != pCAV && parallel_mode != pBiCAV)
687  computeCAVWeights(vol_basis0, numIMG, verbose-1);
688 }
689 #undef DEBUG
690 
691 /* Count number of equations for CAV --------------------------------------- */
693  int numProjs_node, int debug_level)
694 {
695  if (GVNeq == nullptr)
696  GVNeq = new GridVolumeT<int>;
697  GVNeq->resize(vol_basis0);
698  GVNeq->initZeros();
699 
700  Projection read_proj;
701  if (debug_level > 0)
702  {
703  std::cerr << "Counting equations ...\n";
705  }
706  for (int act_proj = 0; act_proj < numProjs_node ; act_proj++)
707  {
708  ReconsInfo &imgInfo = IMG_Inf[ordered_list(act_proj)];
709 
710  read_proj.read(imgInfo.fn_proj, apply_shifts, DATA, &imgInfo.row);
711  read_proj().setXmippOrigin();
712 
713  // Projection extension? .........................................
714  if (proj_ext != 0)
715  read_proj().selfWindow(
716  STARTINGY(read_proj()) - proj_ext,
717  STARTINGX(read_proj()) - proj_ext,
718  FINISHINGY(read_proj()) + proj_ext,
719  FINISHINGX(read_proj()) + proj_ext);
720 
721  count_eqs_in_projection(*GVNeq, basis, read_proj);
722 
723  if (debug_level > 0 &&
724  act_proj % XMIPP_MAX(1, numIMG / 60) == 0)
725  progress_bar(act_proj);
726  }
727  if (debug_level > 0)
728  {
730  long int Neq = 0, Nunk = 0;
731  for (size_t n = 0; n < GVNeq->VolumesNo(); n++)
733  {
734  Neq += (*GVNeq)(n)(k, i, j);
735  Nunk++;
736  }
737  double redundancy = (0 == Neq) ? 0 : (100.0 - 100.0*Nunk / Neq);
738  std::cerr << "There are " << Neq << " equations and " << Nunk
739  << " unknowns (redundancy=" << redundancy << ")\n";
740  }
741 }
742 
744 {
745  return projXdim;
746 }
747 
749 {
750  return projYdim;
751 }
752 
753 
754 
755 
bool is_crystal
Is this a crystal 0 means NO 1 YES.
Definition: basic_art.h:252
int verbose
Verbose level.
Definition: basic_art.h:317
#define TELL_IV
Definition: basic_art.h:269
void removeObjects(const std::vector< size_t > &toRemove) override
void init_progress_bar(long total)
MDRowVec row
Header information of projection.
Definition: basic_art.h:63
bool positivity
Apply positivity constraint.
Definition: basic_art.h:246
int numIMG
Total number of images to process (taking symmetries into account)
Definition: basic_art.h:348
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
static void defineParams(XmippProgram *program, bool mpiMode=false)
Definition: basic_art.cpp:115
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
size_t projXdim
Projection X dimension.
Definition: basic_art.h:333
double getDoubleParam(const char *param, int arg=0)
bool refine
Refine experimental projection before backprojecting.
Definition: basic_art.h:258
#define TELL_SHOW_ERROR
Definition: basic_art.h:272
Basis basis
Basis function. By default, blobs.
Definition: basic_art.h:97
void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=nullptr, bool decomposeStack=true) override
#define FINISHINGX(v)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void resize(const Matrix1D< double > &corner1, const Matrix1D< double > &corner2)
Definition: grids.h:873
FileName fn_start
Grid volume as initial guess.
Definition: basic_art.h:220
SimpleGrid Create_CC_grid(double relative_size, const Matrix1D< double > &corner1, const Matrix1D< double > &corner2, const Matrix1D< double > &origin)
Definition: grids.cpp:196
double grid_relative_size
Relative size for the grid.
Definition: basis.h:64
#define FULL
Definition: basic_art.h:406
void sqrt(Image< double > &op)
#define TELL_MANUAL_ORDER
Definition: basic_art.h:273
Matrix2D< double > * D
Definition: basic_art.h:365
Couldn&#39;t write to file.
Definition: xmipp_error.h:140
void removeObjects(const std::vector< size_t > &toRemove) override
int readSymmetryFile(FileName fn_sym, double accuracy=SYM_ACCURACY)
Definition: symmetries.cpp:33
Matrix1D< double > vectorR3(double x, double y, double z)
Definition: matrix1d.cpp:892
#define TELL_STATS
Definition: basic_art.h:277
void changeFromVoxels(const MultidimArray< double > &vol_voxels, GridVolume &vol_basis, int grid_type, double grid_relative_size, const MultidimArray< double > *vol_mask, const Matrix2D< double > *D, double R, int threads=1) const
Definition: basis.cpp:292
void getImageSize(const MetaData &md, size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim, MDLabel image_label)
bool do_not_use_symproj
Do not use symmetrized projections.
Definition: basic_art.h:202
#define TELL_SAVE_BASIS
Definition: basic_art.h:276
constexpr int ARTK
Definition: projection.h:177
double grid_relative_size
Relative size for the grid.
Definition: basic_art.h:141
FileName fn_sym
File containing symmetries.
Definition: basic_art.h:173
bool shiftedTomograms
Shifted tomograms.
Definition: basic_art.h:214
tBasisFunction type
Basis function to use.
Definition: basis.h:52
Definition: grids.h:479
double maxLength() const
Definition: basis.cpp:242
int symsNo() const
Definition: symmetries.h:268
#define CC
CC identifier.
Definition: grids.h:585
void getListParam(const char *param, StringVector &list)
void setDefault()
Default values.
Definition: basis.cpp:36
FileName fn_sel
Selection file with all images to process.
Definition: basic_art.h:208
std::ofstream * fh_hist
File handler for the history file.
Definition: basic_art.h:339
bool variability_analysis
Variability analysis.
Definition: basic_art.h:255
int save_intermidiate_every
Frequency for saving intermidiate.
Definition: basic_art.h:314
double weight(const size_t n=0) const
size_t projYdim
Projection Y dimension.
Definition: basic_art.h:336
#define STARTINGX(v)
double sampling
Sampling rate.
Definition: basic_art.h:170
std::vector< String > StringVector
Definition: xmipp_strings.h:35
size_t size() const override
#define i
Is this image enabled? (int [-1 or 1])
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
Incorrect number of objects in Metadata.
Definition: xmipp_error.h:160
int block_size
Number of projections for each parallel block.
Definition: basic_art.h:112
bool random_sort
True if random sort of projections.
Definition: basic_art.h:120
int grid_type
CC, BCC or FCC (in grids.hh)
Definition: basic_art.h:144
#define STARTINGY(v)
#define BCC
BCC identifier.
Definition: grids.h:589
int trueIMG
Number of different images (without symmetries)
Definition: basic_art.h:351
void adapt_to_grid(const Grid &_grid)
Definition: grids.h:838
FileName fn_surface_mask
File containing surface mask.
Definition: basic_art.h:205
double known_volume
Known volume. If -1, not applied.
Definition: basic_art.h:226
bool dont_sort
True if no sort must be made.
Definition: basic_art.h:123
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
Matrix1D< double > kappa_list
Definition: basic_art.h:132
#define TELL_ONLY_SYM
Definition: basic_art.h:270
double sparseEps
Sparse reconstruction.
Definition: basic_art.h:190
size_t VolumesNo() const
Definition: grids.h:1003
bool print_system_matrix
Print system matrix.
Definition: basic_art.h:249
bool apply_shifts
Apply shifts stored in the headers of the 2D-images.
Definition: basic_art.h:243
#define BASIC
Definition: basic_art.h:405
const char * getParam(const char *param, int arg=0)
GridVolumeT< int > * GVNeq
Definition: basic_art.h:381
double goldmask
Goldmask.
Definition: basic_art.h:211
void sortRandomly(int numIMG, MultidimArray< int > &ordered_list)
#define FCC
FCC identifier.
Definition: grids.h:587
float textToFloat(const char *str)
Incorrect argument received.
Definition: xmipp_error.h:113
int stop_at
Stop after this number of images, if 0 then don&#39;t use.
Definition: basic_art.h:223
ReconsInfo * IMG_Inf
Array with all the sorting information for each projection.
Definition: basic_art.h:342
void resize(size_t Xdim, bool copy=true)
Definition: matrix1d.h:410
void initZeros()
Definition: grids.h:936
void progress_bar(long rlen)
void read(const FileName &fn, const std::string &basisName)
Definition: grids.h:1330
#define TELL_SAVE_INTERMIDIATE
Definition: basic_art.h:275
ARTParallelMode parallel_mode
Definition: basic_art.h:109
void produceSideInfo(GridVolume &vol_basis0, int level=FULL, int rank=-1)
Definition: basic_art.cpp:468
String basisName() const
Basis name.
Definition: basis.cpp:50
FileName fn_root
Definition: basic_art.h:217
bool contains(const String &str) const
FileName fn_proj
Projection filename.
Definition: basic_art.h:61
void sortPerpendicular(int numIMG, ReconsInfo *IMG_Inf, MultidimArray< int > &ordered_list, int N)
size_t size() const override
double ref_trans_step
Refine the translation alignement after n projection presentations.
Definition: basic_art.h:187
#define j
bool noisy_reconstruction
Noisy reconstruction.
Definition: basic_art.h:261
void importObjects(const MetaData &md, const std::vector< size_t > &objectsToAdd, bool doClear=true) override
void computeCAVWeights(GridVolume &vol_basis0, int numProjs_node, int debug_level=0)
Definition: basic_art.cpp:692
int force_sym
Force the reconstruction to be symmetric this number of times.
Definition: basic_art.h:196
Grid Create_FCC_grid(double relative_size, const Matrix1D< double > &corner1, const Matrix1D< double > &corner2)
Definition: grids.cpp:306
constexpr int CAV
Definition: projection.h:180
bool unmatched
Apply unmatched projectors to correct for the CTF.
Definition: basic_art.h:232
Grid Create_BCC_grid(double relative_size, const Matrix1D< double > &corner1, const Matrix1D< double > &corner2)
Definition: grids.cpp:251
int no_it
Number of iterations.
Definition: basic_art.h:100
void produceSideInfo(const Grid &grid)
Definition: basis.cpp:162
#define FINISHINGY(v)
constexpr int CAVARTK
Definition: projection.h:181
void setD(Matrix2D< double > *_D)
Definition: basis.h:123
MultidimArray< int > ordered_list
Order in which projections will be presented to algorithm.
Definition: basic_art.h:345
FileName withoutExtension() const
#define TELL_SAVE_AT_EACH_STEP
Definition: basic_art.h:274
Image< double > * surface_mask
Definition: basic_art.h:371
constexpr int CAVK
Definition: projection.h:178
FileName fn_control
Name of file for improved control in parallel jobs.
Definition: basic_art.h:320
#define FIRST_XMIPP_INDEX(size)
Definition: xmipp_macros.h:439
void noSort(int numIMG, MultidimArray< int > &ordered_list)
std::string String
Definition: xmipp_strings.h:34
const SimpleGrid & grid(size_t n) const
Definition: grids.h:978
int ref_trans_after
Refine the translation alignement after n projection presentations.
Definition: basic_art.h:184
void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=NULL, bool decomposeStack=true) override
static void defineParams(XmippProgram *program, const char *prefix=NULL, const char *comment=NULL)
Definition: basis.cpp:69
void resizeNoCopy(int Xdim)
Definition: matrix1d.h:458
bool checkParam(const char *param)
void read(const FileName &fn, const bool only_apply_shifts=false, DataMode datamode=DATA, MDRow *row=nullptr)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
int sort_last_N
Sort perpendicular with the last N projections. If -1 with all previous.
Definition: basic_art.h:126
void readParams(XmippProgram *program)
Definition: basis.cpp:100
int idum
bool containsLabel(const MDLabel label) const override
FileName fn_ctf
Selection file with all images to process.
Definition: basic_art.h:229
int getIntParam(const char *param, int arg=0)
double diffusionWeight
Tomographic diffussion.
Definition: basic_art.h:193
void buildReconsInfo(MetaDataVec &selfile, const FileName &fn_ctf, const SymList &SL, ReconsInfo *&IMG_Inf, bool do_not_use_symproj)
Definition: recons_misc.cpp:37
void readParams(XmippProgram *program)
Definition: basic_art.cpp:269
Incorrect value received.
Definition: xmipp_error.h:195
void count_eqs_in_projection(GridVolumeT< int > &GVNeq, const Basis &basis, Projection &read_proj)
int threads
Number of threads to use. Can not be different than 1 when using MPI.
Definition: basic_art.h:267
void initConstant(T val)
Definition: matrix1d.cpp:83
int * n
FileName fn_out
Name of the output volume, also used to set the root of rest output files.
Definition: basic_art.h:217
void addParamsLine(const String &line)
SymList SL
A list with the symmetry matrices.
Definition: basic_art.h:330
< Score 4 for volumes
Matrix2D< double > * Dinv
Just the inverse of D.
Definition: basic_art.h:367
Matrix1D< double > lambda_list
Relaxation parameter.
Definition: basic_art.h:103
bool do_not_generate_subgroup
Do not generate symmetry subgroup.
Definition: basic_art.h:199
bool containsLabel(const MDLabel label) const override
Definition: metadata_db.h:305