Xmipp  v3.23.11-Nereus
project.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 #include "project.h"
27 #include "directions.h"
28 #include "project_real_shears.h"
31 #include "core/metadata_sql.h"
32 #include <core/args.h>
33 
34 /* Read from command line ================================================== */
36 {
37  fnPhantom = getParam("-i");
38  fnOut = getParam("-o");
39  samplingRate = getDoubleParam("--sampling_rate");
40  highTs = getDoubleParam("--high_sampling_rate");
41  singleProjection = false;
42  if (STR_EQUAL(getParam("--method"), "real_space"))
44  if (STR_EQUAL(getParam("--method"), "shears"))
45  projType = SHEARS;
46  if (STR_EQUAL(getParam("--method"), "fourier"))
47  {
48  projType = FOURIER;
49  paddFactor = getDoubleParam("--method", 1);
50  maxFrequency = getDoubleParam("--method", 2);
51  String degree = getParam("--method", 3);
52  if (degree == "nearest")
54  else if (degree == "linear")
56  else if (degree == "bspline")
58  else
59  REPORT_ERROR(ERR_ARG_BADCMDLINE, "The values for interpolation can be : nearest, linear, bspline");
60 
61  }
62  bool doParams = checkParam("--params");
63  bool doAngles = checkParam("--angles");
64 
65  if (doParams && doAngles)
66  REPORT_ERROR(ERR_ARG_BADCMDLINE, "--params and --angles are mutually exclusive");
67  else if (!doParams && !doAngles)
68  REPORT_ERROR(ERR_ARG_BADCMDLINE, "You should provide --params or --angles");
69 
70  if (doParams)
71  {
72  fn_proj_param = getParam("--params");
73  if (checkParam("--sym"))
74  fn_sym = getParam("--sym");
75  only_create_angles = checkParam("--only_create_angles");
76  }
77  else //doAngles = true
78  {
79  singleProjection = true;
80  only_create_angles = false;
81  projSize = getIntParam("--xdim");
82  rotSingle = getDoubleParam("--angles",0);
83  tiltSingle = getDoubleParam("--angles",1);
84  psiSingle = getDoubleParam("--angles",2);
85  xShift = getDoubleParam("--angles",3);
86  yShift = getDoubleParam("--angles",4);
87  }
88 }
89 
90 /* Usage =================================================================== */
92 {
93  addUsageLine("This program is able to generate a set of projections from a volume. ");
94  addUsageLine("++The projection is done using the information directly or from a file.");
95  addSeeAlsoLine("tomo_project,phantom_create");
96 
97  addParamsLine(" -i <volume_file> : Voxel volume, PDB or description file");
98  addParamsLine(" -o <image_file> : Output stack or image");
99  addParamsLine(" [--sampling_rate <Ts=1>] : It is only used for PDB phantoms");
100  addParamsLine(" [--high_sampling_rate <highTs=0.08333333>] : Sampling rate before downsampling. It is only used for PDB phantoms");
101  addParamsLine(" [--method <method=real_space>] : Projection method");
102  addParamsLine(" where <method>");
103  addParamsLine(" real_space : Makes projections by ray tracing in real space");
104  addParamsLine(" shears : Use real-shears algorithm");
105  addParamsLine(" :+This algorithm is slower but more accurate. For a full description see");
106  addParamsLine(" fourier <pad=2> <maxfreq=0.25> <interp=bspline> : Takes a central slice in Fourier space");
107  addParamsLine(" :+++ %BR% ");
108  addParamsLine(" : pad: controls the padding factor.");
109  addParamsLine(" :+++ %BR% ");
110  addParamsLine(" : maxfreq: is the maximum frequency for the pixels and by default ");
111  addParamsLine(" : pixels with frequency more than 0.25 are not considered.");
112  addParamsLine(" :+++ %BR% ");
113  addParamsLine(" : interp: is the method for interpolation and the values can be: ");
114  addParamsLine(" :+++ %BR% ");
115  addParamsLine(" : nearest: Nearest Neighborhood ");
116  addParamsLine(" :+++ %BR% ");
117  addParamsLine(" : linear: Linear BSpline ");
118  addParamsLine(" :+++ %BR% ");
119  addParamsLine(" : bspline: Cubic BSpline ");
120  addParamsLine("== Generating a set of projections == ");
121  addParamsLine(" [--params <parameters_file>] : File containing projection parameters");
122  addParamsLine(" : Check the manual for a description of the parameters");
123  addParamsLine(" : tilt angle should be in the range [0-180]");
124  addParamsLine(" [--sym <sym_file>] : It is used for computing the asymmetric unit");
125  addParamsLine(" [--only_create_angles] : Do not create projections");
126  addParamsLine("== Generating a single projection == ");
127  addParamsLine(" [--angles <rot> <tilt> <psi> <x=0.> <y=0.>]: Angles and shifts for a single projection");
128  addParamsLine(" [--xdim <size=-1>] : Size of the projection");
129  addParamsLine(" : For geometric descriptions and voxel volumes");
130  addParamsLine(" : this parameter is not necessary");
131  addExampleLine("Generating a set of projections using fourier method",false);
132  addExampleLine("xmipp_phantom_project -i volume.vol -o images.stk --method fourier 3 0.25 bspline --params uniformProjection_xmd.param");
133  addExampleLine("Generating a set of projections using shears method",false);
134  addExampleLine("xmipp_phantom_project -i volume.vol -o images.stk --method shears --params uniformProjection_xmd.param");
135  addExampleLine("Generating a top view from Z",false);
136  addExampleLine("xmipp_phantom_project -i volume.vol -o image.xmp --angles 0 0 0");
137  addExampleLine("Generating a side view from Y",false);
138  addExampleLine("xmipp_phantom_project -i volume.vol -o image.xmp --angles 90 90 0");
139  addExampleLine("Generating a side view from X",false);
140  addExampleLine("xmipp_phantom_project -i volume.vol -o image.xmp --angles 0 90 0");
141  addExampleLine("+++In the following links you can find some examples of projection parameter files",false);
142  addExampleLine("+++",false);
143  addExampleLine("+++http://sourceforge.net/p/testxmipp/code/ci/master/tree/input/phantomProject.param?format=raw",false);
144  addExampleLine("+++",false);
145  addExampleLine("+++http://sourceforge.net/p/testxmipp/code/ci/master/tree/input/uniformProjection_xmd.param?format=raw",false);
146  addExampleLine("+++",false);
147  addExampleLine("+++http://sourceforge.net/p/testxmipp/code/ci/master/tree/input/clusterProjection_xmd.param?format=raw",false);
148  addExampleLine("+++",false);
149  addExampleLine("+++Creating a 2D crystal",false);
150  addExampleLine("+In order to create a 2D crystal, you can pass --params as a projection file with a second block for crystal projection.: ",false);
151  addExampleLine("+xmipp_phantom_project -i cylinder_with_axis.descr --oroot MRCproj --params MRCCrystalProj_xmd.param");
152  addExampleLine("+++In the following links you can find some examples of projection parameter files",false);
153  addExampleLine("+++",false);
154  addExampleLine("+++http://sourceforge.net/p/testxmipp/code/ci/master/tree/input/Crystal/MRCCrystalProj_xmd.param?format=raw",false);
155  addExampleLine("+++",false);
156  addExampleLine("+++ http://sourceforge.net/p/testxmipp/code/ci/master/tree/input/Crystal/cylinder_with_axis.descr?format=raw",false);
157  addExampleLine("+++",false);
158  addExampleLine("+++http://sourceforge.net/p/testxmipp/code/ci/master/tree/input/Crystal/MRC_crystal_projection_xmd.param?format=raw",false);
159 
160  addExampleLine("+++",false);
161  addExampleLine("+++Figures (a) and (b) show the achievable resolution for different methods of projection. ",false);
162  addExampleLine("+++",false);
163  addExampleLine("+++<img width='100%' alt='Test_Resolution_Small.jpg' src='%ATTACHURLPATH%/Test_Resolution_Small.jpg' height='100%' />");
164  addExampleLine("+++",false);
165  addExampleLine("+++(a) The achievable resolution for different methods for a volume of size 64*64",false);
166  addExampleLine("+++",false);
167  addExampleLine("+++ <img width='100%' alt='Test_Resolution_Big.jpg' src='%ATTACHURLPATH%/Test_Resolution_Big.jpg' height='100%' />");
168  addExampleLine("+++",false);
169  addExampleLine("+++(b) The achievable resolution for different methods for a volume of size 400*400",false);
170  addExampleLine("+++",false);
171  addExampleLine("+++As it can be seen in these two figures, Fourier method with cubic B-Spline interpolation for both padding two and padding one provides the best resolution. However, there is a preference on padding one because of less memory and time complexity.",false);
172 }
173 
174 /* Run ===================================================================== */
176 {
177  Projection proj;
178  MetaDataVec SF;
179  ROUT_project(*this, proj, SF);
180 }
181 
182 /* Projection parameters from program parameters =========================== */
184 {
185  read(prog_prm.fn_proj_param);
186 }
187 
188 /* Read Projection Parameters ============================================== */
189 int translate_randomness(char * str)
190 {
191  if (str == nullptr)
193  if (strcmp(str, "random_group") == 0)
195  if (strcmp(str, "random") == 0)
196  return ANGLE_RANGE_RANDOM;
197  if (strcmp(str, "even") == 0)
198  return ANGLE_EVENLY;
200  (String)"Prog_Project_Parameters::read: Not recognized randomness: "
201  + str);
202 }
203 
205 {
206  Npixel_avg=0.;
207  Npixel_dev=0.;
208  Ncenter_avg=0.;
209  Ncenter_dev=0.;
210  rot_range.Navg = 0.;
211  rot_range.Ndev=0.;
212  tilt_range.Navg=0.;
213  tilt_range.Ndev=0.;
214  psi_range.Navg=0.;
215  psi_range.Ndev=0.;
216  doPhaseFlip=false;
217  applyShift=true;
218 }
219 
221 {
222 
223  if (fn_proj_param.isMetaData())
224  {
225  MetaDataVec MD;
226  MD.read(fn_proj_param);
227  //if X and Y those not exists add them
228  if (!MD.containsLabel(MDL_SHIFT_X))
229  MD.addLabel(MDL_SHIFT_X);
230  if (!MD.containsLabel(MDL_SHIFT_Y))
231  MD.addLabel(MDL_SHIFT_Y);
232  if (MD.isEmpty())
234  (String)"Prog_Project_Parameters::read: There is a problem "
235  "opening the file " + fn_proj_param);
236 
237  std::vector <double> ParamVec;
238  std::string RandStr;
239  char * RandChar;
240  size_t objId;
241 
242  // Read data from the MetaData
243  objId = MD.firstRowId();
244  MD.getValue(MDL_DIMENSIONS_2D, ParamVec, objId);
245  proj_Xdim = (int)ParamVec[0];
246  proj_Ydim = (int)ParamVec[1];
247  if (!MD.getValue(MDL_PRJ_ANGFILE, fn_angle, objId))
248  fn_angle = "NULL";
249  else if (fn_angle != "NULL")
250  if (!fn_angle.exists())
251  REPORT_ERROR(ERR_IO_NOTEXIST, (String)"Prog_Project_Parameters::read: "
252  "file " + fn_angle + " doesn't exist");
253  else
254  {
255  MD.getValue(MDL_CTF_DATA_PHASE_FLIPPED, doPhaseFlip, objId);
256  doPhaseFlip = !doPhaseFlip;
257  MD.getValue(MDL_CTF_CORRECTED, doCTFCorrection, objId);
258  doCTFCorrection = !doCTFCorrection;
259  MD.getValue(MDL_APPLY_SHIFT, applyShift, objId);
260  }
261 
262  if (MD.getValue(MDL_PRJ_ROT_RANGE,ParamVec, objId))
263  {
264  enable_angle_range = true;
265  rot_range.ang0 = ParamVec[0];
266  if (ParamVec.size() == 1)
267  {
268  rot_range.angF = rot_range.ang0;
269  rot_range.samples = 1;
270  }
271  else
272  {
273  rot_range.angF = ParamVec[1];
274  rot_range.samples = (int)ParamVec[2];
275  if (rot_range.ang0 == rot_range.angF)
276  rot_range.samples = 1;
277  }
278  if (!MD.getValue(MDL_PRJ_ROT_RANDSTR,RandStr,objId))
279  rot_range.randomness = ANGLE_RANGE_DETERMINISTIC;
280  else
281  {
282  RandChar = new char[RandStr.length() + 1];
283  strcpy(RandChar, RandStr.c_str());
284  rot_range.randomness = translate_randomness(RandChar);
285  }
286  MD.getValue(MDL_PRJ_TILT_RANGE,ParamVec, objId);
287  tilt_range.ang0 = ParamVec[0];
288  if (ParamVec.size() == 1)
289  {
290  tilt_range.angF = tilt_range.ang0;
291  tilt_range.samples = 1;
292  }
293  else
294  {
295  tilt_range.angF = ParamVec[1];
296  tilt_range.samples = (int)ParamVec[2];
297  if (tilt_range.ang0 == tilt_range.angF)
298  tilt_range.samples = 1;
299  }
300  if (!MD.getValue(MDL_PRJ_TILT_RANDSTR,RandStr,objId))
301  tilt_range.randomness = ANGLE_RANGE_DETERMINISTIC;
302  else
303  {
304  RandChar = new char[RandStr.length() + 1];
305  strcpy(RandChar, RandStr.c_str());
306  tilt_range.randomness = translate_randomness(RandChar);
307  }
308  MD.getValue(MDL_PRJ_PSI_RANGE,ParamVec, objId);
309  psi_range.ang0 = ParamVec[0];
310  if (ParamVec.size() == 1)
311  {
312  psi_range.angF = psi_range.ang0;
313  psi_range.samples = 1;
314  }
315  else
316  {
317  psi_range.angF = ParamVec[1];
318  psi_range.samples = (int)ParamVec[2];
319  if (psi_range.ang0 == psi_range.angF)
320  psi_range.samples = 1;
321  }
322  if (!MD.getValue(MDL_PRJ_PSI_RANDSTR,RandStr,objId))
323  psi_range.randomness = ANGLE_RANGE_DETERMINISTIC;
324  else
325  {
326  RandChar = new char[RandStr.length() + 1];
327  strcpy(RandChar, RandStr.c_str());
328  psi_range.randomness = translate_randomness(RandChar);
329  }
330  }
331  else
332  enable_angle_range = false;
333 
334  if(MD.getValue(MDL_PRJ_ROT_NOISE,ParamVec, objId))
335  {
336  rot_range.Ndev = ParamVec[0];
337  if (ParamVec.size()<2)
338  rot_range.Navg = 0;
339  else
340  rot_range.Navg = ParamVec[1];
341  }
342  else
343  rot_range.Ndev = rot_range.Navg =0.;
344 
345  if(MD.getValue(MDL_PRJ_TILT_NOISE,ParamVec, objId))
346  {
347  tilt_range.Ndev = ParamVec[0];
348  if (ParamVec.size()<2)
349  tilt_range.Navg = 0;
350  else
351  tilt_range.Navg = ParamVec[1];
352  }
353  else
354  tilt_range.Ndev = tilt_range.Navg =0.;
355 
356  if(MD.getValue(MDL_PRJ_PSI_NOISE,ParamVec, objId))
357  {
358  psi_range.Ndev = ParamVec[0];
359  if (ParamVec.size()<2)
360  psi_range.Navg = 0;
361  else
362  psi_range.Navg = ParamVec[1];
363  }
364  else
365  psi_range.Ndev = psi_range.Navg =0.;
366 
367  if(MD.getValue(MDL_NOISE_PIXEL_LEVEL,ParamVec, objId))
368  {
369  Npixel_dev = ParamVec[0];
370  if (ParamVec.size() < 2)
371  Npixel_avg = 0;
372  else
373  Npixel_avg = ParamVec[1];
374  }
375  else
376  Npixel_dev = Npixel_avg =0.;
377 
378  if(MD.getValue(MDL_NOISE_COORD,ParamVec, objId))
379  {
380  Ncenter_dev = ParamVec[0];
381  if (ParamVec.size() < 2)
382  Ncenter_avg = 0;
383  else
384  Ncenter_avg = ParamVec[1];
385  }
386  else
387  Ncenter_dev = Ncenter_avg =0.;
388 
389  }
390  else
391  {
392  FILE *fh_param;
393  char line[201];
394  int lineNo = 0;
395  char *auxstr;
396 
397  if ((fh_param = fopen(fn_proj_param.c_str(), "r")) == NULL)
399  (String)"Prog_Project_Parameters::read: There is a problem "
400  "opening the file " + fn_proj_param);
401  while (fgets(line, 200, fh_param) != NULL)
402  {
403  if (line[0] == 0)
404  continue;
405  if (line[0] == '#')
406  continue;
407  if (line[0] == '\n')
408  continue;
409  switch (lineNo)
410  {
411  case 0:
412  proj_Xdim = textToInteger(firstToken(line));
413  proj_Ydim = textToInteger(nextToken());
414  lineNo = 1;
415  break;
416  case 1:
417  // Angle file
418  fn_angle = firstWord(line);
419  if (fn_angle == "NULL")
420  ;
421  else if (!fn_angle.exists())
422  REPORT_ERROR(ERR_IO_NOTEXIST, (String)"Prog_Project_Parameters::read: "
423  "file " + fn_angle + " doesn't exist");
424  lineNo = 2;
425  break;
426  case 2:
427  // theta init
428  auxstr = firstWord(line);
429  if (strcmp(auxstr, "NULL") != 0)
430  {
431  enable_angle_range = true;
432  rot_range.ang0 = textToFloat(auxstr);
433  auxstr = nextToken();
434  if (auxstr == nullptr)
435  {
436  // Fixed mode
437  rot_range.randomness = ANGLE_RANGE_DETERMINISTIC;
438  rot_range.angF = rot_range.ang0;
439  rot_range.samples = 1;
440  }
441  else
442  {
443  rot_range.angF = textToFloat(auxstr);
444  rot_range.samples = textToInteger(nextToken());
445  if (rot_range.ang0 == rot_range.angF)
446  rot_range.samples = 1;
447  rot_range.randomness = translate_randomness(nextToken());
448  }
449  lineNo = 3;
450  }
451  else
452  {
453  enable_angle_range = false;
454  lineNo = 5;
455  }
456  break;
457  case 3:
458  tilt_range.ang0 = textToFloat(firstToken(line));
459  auxstr = nextToken();
460  if (auxstr == nullptr)
461  {
462  // Fixed mode
463  tilt_range.randomness = ANGLE_RANGE_DETERMINISTIC;
464  tilt_range.angF = tilt_range.ang0;
465  tilt_range.samples = 1;
466  }
467  else
468  {
469  tilt_range.angF = textToFloat(auxstr);
470  tilt_range.samples = textToInteger(nextToken());
471  if (tilt_range.ang0 == tilt_range.angF)
472  tilt_range.samples = 1;
473  tilt_range.randomness = translate_randomness(nextToken());
474  }
475  lineNo = 4;
476  break;
477  case 4:
478  psi_range.ang0 = textToFloat(firstToken(line));
479  auxstr = nextToken();
480  if (auxstr == nullptr)
481  {
482  // Fixed mode
483  psi_range.randomness = ANGLE_RANGE_DETERMINISTIC;
484  psi_range.angF = psi_range.ang0;
485  psi_range.samples = 1;
486  }
487  else
488  {
489  psi_range.angF = textToFloat(auxstr);
490  psi_range.samples = textToInteger(nextToken());
491  if (psi_range.ang0 == psi_range.angF)
492  psi_range.samples = 1;
493  psi_range.randomness = translate_randomness(nextToken());
494  }
495  lineNo = 5;
496  break;
497  case 5:
498  rot_range.Ndev = textToFloat(firstWord(line));
499  auxstr = nextToken();
500  if (auxstr != nullptr)
501  rot_range.Navg = textToFloat(auxstr);
502  else
503  rot_range.Navg = 0;
504  lineNo = 6;
505  break;
506  case 6:
507  tilt_range.Ndev = textToFloat(firstWord(line));
508  auxstr = nextToken();
509  if (auxstr != nullptr)
510  tilt_range.Navg = textToFloat(auxstr);
511  else
512  tilt_range.Navg = 0;
513  lineNo = 7;
514  break;
515  case 7:
516  psi_range.Ndev = textToFloat(firstWord(line));
517  auxstr = nextToken();
518  if (auxstr != nullptr)
519  psi_range.Navg = textToFloat(auxstr);
520  else
521  psi_range.Navg = 0;
522  lineNo = 8;
523  break;
524  case 8:
525  Npixel_dev = textToFloat(firstWord(line));
526  auxstr = nextToken();
527  if (auxstr != nullptr)
528  Npixel_avg = textToFloat(auxstr);
529  else
530  Npixel_avg = 0;
531  lineNo = 9;
532  break;
533  case 9:
534  Ncenter_dev = textToFloat(firstWord(line));
535  auxstr = nextToken();
536  if (auxstr != nullptr)
537  Ncenter_avg = textToFloat(auxstr);
538  else
539  Ncenter_avg = 0;
540  lineNo = 10;
541  break;
542  } /* switch end */
543  } /* while end */
544  if (lineNo != 10)
545  REPORT_ERROR(ERR_PARAM_MISSING, formatString("Prog_Project_Parameters::read: I "
546  "couldn't read all parameters from file %s, only read %d lines", fn_proj_param.c_str(), lineNo));
547  fclose(fh_param);
548  }
549 }
550 
551 /* Generate angles ========================================================= */
552 // This function generates the angles for a given angle ("rot", "tilt"
553 // or "psi") according to the projection parameters. The output document
554 // file is supposed to be large enough to hold all angles
555 // Some aliases
556 #define Nrot prm.rot_range.samples
557 #define Ntilt prm.tilt_range.samples
558 #define Npsi prm.psi_range.samples
559 #define proj_number(base,irot,itilt,ipsi) base+irot*Ntilt*Npsi+itilt*Npsi+ipsi
560 void generate_angles(int ExtProjs, const Angle_range &range,
561  MetaDataVec &DF, char ang_name, const ParametersProjection &prm)
562 {
563  double ang;
564  int N1=0, N2=0;
565  int i, j, k;
566  size_t iproj, idx=0;
567  int limit=0;
568  MetaDataVec DFaux=DF;
569 
570  // Select loop limit ....................................................
571  switch (range.randomness)
572  {
574  limit = range.samples;
575  break;
577  limit = range.samples;
578  break;
579  case ANGLE_RANGE_RANDOM :
580  limit = Nrot * Ntilt * Npsi;
581  break;
582  }
583 
584  // Which column to write in the document file ...........................
585  switch (ang_name)
586  {
587  case 'r':
588  idx = 0;
589  break;
590  case 't':
591  idx = 1;
592  break;
593  case 'p':
594  idx = 2;
595  break;
596  }
597 
598  double unif_min = cos(DEG2RAD(range.angF));
599  double unif_max = cos(DEG2RAD(range.ang0));
600  for (i = 0; i < limit; i++)
601  {
602  // Select angle .....................................................
604  {
605  if (range.samples > 1)
606  ang = range.ang0 +
607  (range.angF - range.ang0) / (double)(range.samples - 1) * i;
608  else
609  ang = range.ang0;
610  }
611  else
612  {
613  switch (ang_name)
614  {
615  case 'r':
616  case 'p':
617  ang = rnd_unif(range.ang0, range.angF);
618  break;
619  case 't':
620  ang = RAD2DEG(acos(rnd_unif(unif_min, unif_max)));
621  break;
622  }
623  }
624 
625  // Copy this angle to those projections belonging to this group .....
626  // If there is any group
627  if (range.randomness != ANGLE_RANGE_RANDOM)
628  {
629  switch (ang_name)
630  {
631  case 'r':
632  N1 = Ntilt;
633  N2 = Npsi;
634  break;
635  case 't':
636  N1 = Nrot;
637  N2 = Npsi;
638  break;
639  case 'p':
640  N1 = Nrot;
641  N2 = Ntilt;
642  break;
643  }
644  for (j = 0; j < N1; j++)
645  for (k = 0; k < N2; k++)
646  {
647  switch (ang_name)
648  {
649  case 'r':
650  iproj = proj_number(ExtProjs, i, j, k);
651  break;
652  case 't':
653  iproj = proj_number(ExtProjs, j, i, k);
654  break;
655  case 'p':
656  iproj = proj_number(ExtProjs, j, k, i);
657  break;
658  }
659  size_t idx_tmp=DFaux.firstObject(MDValueEQ(MDL_ORDER,iproj));
660  if (idx_tmp==BAD_OBJID)
661  {
662  idx_tmp=DFaux.addObject();
663  DFaux.setValue(MDL_ORDER,iproj,idx_tmp);
664  }
665  switch (idx)
666  {
667  case 0:
668  DFaux.setValue(MDL_ANGLE_ROT,ang,idx_tmp);
669  break;
670  case 1:
671  DFaux.setValue(MDL_ANGLE_TILT,ang,idx_tmp);
672  break;
673  case 2:
674  DFaux.setValue(MDL_ANGLE_PSI,ang,idx_tmp);
675  break;
676  }
677  }
678  }
679  else
680  {
681  size_t iproj=ExtProjs + i;
682  size_t dfidx=DFaux.firstObject(MDValueEQ(MDL_ORDER,iproj));
683  if (dfidx==BAD_OBJID)
684  {
685  dfidx=DFaux.addObject();
686  DFaux.setValue(MDL_ORDER,iproj,dfidx);
687  }
688  switch (idx)
689  {
690  case 0:
691  DFaux.setValue(MDL_ANGLE_ROT,ang,dfidx);
692  break;
693  case 1:
694  DFaux.setValue(MDL_ANGLE_TILT,ang,dfidx);
695  break;
696  case 2:
697  DFaux.setValue(MDL_ANGLE_PSI,ang,dfidx);
698  break;
699  }
700  }
701  }
702  DF.sort(DFaux,MDL_ORDER);
703 }
704 
705 /* Generate evenly distributed angles ====================================== */
706 void generate_even_angles(int ExtProjs, int Nrottilt, MetaDataVec &DF,
707  const ParametersProjection &prm)
708 {
709  // We will run over the tilt angle in a deterministic way
710  // then for every tilt angle, a rot_step is computed so that
711  // it keeps the same distance in the circle generated by tilt
712  // as the sample distance at the equator (tilt=90).
713  MetaDataVec DFaux;
714  int N = 0;
715  int limit = prm.tilt_range.samples;
716  double rot_step_at_equator = (prm.rot_range.angF - prm.rot_range.ang0) /
717  (double)(Nrot - 1);
718  for (int i = 0; i < limit; i++)
719  {
720  // Compute the corresponding deterministic tilt
721  double tilt = prm.tilt_range.ang0 +
722  (prm.tilt_range.angF - prm.tilt_range.ang0) /
723  (double)(Ntilt - 1) * i;
724  // Now compute the corresponding rotational angles
725  double rot_step;
726  if (tilt != 0 && tilt != 180)
727  rot_step = rot_step_at_equator / sin(DEG2RAD(tilt));
728  else
729  rot_step = prm.rot_range.angF - prm.rot_range.ang0 + 1;
730  int iterRot = static_cast<int>((prm.rot_range.angF - prm.rot_range.ang0) / rot_step);
731  for (int irot = 0; irot <= iterRot; irot ++)
732  {
733  double rot = prm.rot_range.ang0+irot*rot_step;
734  // Copy this angle to those projections belonging to this group .....
735  // If there is any group
736  for (int k = 0; k < Npsi; k++)
737  {
738  // Select psi
739  double psi;
741  {
742  if (prm.psi_range.samples > 1)
743  {
744  psi = prm.psi_range.ang0 +
745  (prm.psi_range.angF - prm.psi_range.ang0) /
746  (double)(prm.psi_range.samples - 1) * k;
747  }
748  else
749  psi = prm.psi_range.ang0;
750  }
751  else
752  psi = prm.psi_range.ang0 +
753  (prm.psi_range.angF - prm.psi_range.ang0) /
754  (double)(Npsi - 1) * k;
755 
756  size_t iproj = ExtProjs + N + Nrottilt * k;
757  size_t idx_tmp=DFaux.firstObject(MDValueEQ(MDL_ORDER,iproj));
758  if (idx_tmp==BAD_OBJID)
759  {
760  idx_tmp=DFaux.addObject();
761  DFaux.setValue(MDL_ORDER,iproj,idx_tmp);
762  }
763  DFaux.setValue(MDL_ANGLE_ROT,rot,idx_tmp);
764  DFaux.setValue(MDL_ANGLE_TILT,tilt,idx_tmp);
765  DFaux.setValue(MDL_ANGLE_PSI,psi,idx_tmp);
766  }
767  N++;
768  }
769  }
770  DF.sort(DFaux,MDL_ORDER);
772 }
773 
774 // See generate_even_angles for comments
776 {
777  int N = 0;
778  int limit = prm.tilt_range.samples;
779  double rot_step_at_equator = (prm.rot_range.angF - prm.rot_range.ang0) /
780  (double)(Nrot - 1);
781  for (int i = 0; i < limit; i++)
782  {
783  double tilt = prm.tilt_range.ang0 +
784  (prm.tilt_range.angF - prm.tilt_range.ang0) /
785  (double)(Ntilt - 1) * i;
786  double rot_step;
787  if (tilt != 0 && tilt != 180)
788  rot_step = rot_step_at_equator / sin(DEG2RAD(tilt));
789  else
790  rot_step = prm.rot_range.angF - prm.rot_range.ang0 + 1;
791  int iterRot = static_cast<int>((prm.rot_range.angF - prm.rot_range.ang0) / rot_step);
792  N+=iterRot+1;
793  }
794  N++; // This shouldn't be necessary but some GCC optimization
795  // sometimes doesn't do well its work. For instance if we
796  // add std::cout << N after N++ in the loop, then it works perfectly
797  return N;
798 }
799 
800 /* Assign angles =========================================================== */
802  const FileName &fn_sym)
803 {
804  int ExtProjs = 0, IntProjs = 0; // External and internal projections
805  int Nrottilt=0; // Number of evenly distributed
806 
807  // External generation mode
808  if (prm.fn_angle != "NULL")
809  {
810  DF.read(prm.fn_angle);
811  ExtProjs = DF.size();
812  }
813 
814  // Internal generation mode
815  if (prm.enable_angle_range)
816  {
818  if (prm.rot_range.randomness != ANGLE_EVENLY)
819  IntProjs = Nrot * Ntilt * Npsi;
820  else
821  {
822  if (fn_sym == "")
823  {
824  Nrottilt = count_even_angles(prm);
825  IntProjs = Nrottilt * Npsi;
826  }
827  else
828  IntProjs = 0;
829  }
830  if (prm.rot_range.randomness != ANGLE_EVENLY)
831  {
832  generate_angles(ExtProjs, prm.rot_range, DF, 'r', prm);
833  generate_angles(ExtProjs, prm.tilt_range, DF, 't', prm);
834  generate_angles(ExtProjs, prm.psi_range, DF, 'p', prm);
836  }
837  else
838  {
839  if (fn_sym == "")
840  generate_even_angles(ExtProjs, Nrottilt, DF, prm);
841  else
842  {
843  SymList SL;
844  if (fn_sym != "")
845  SL.readSymmetryFile(fn_sym);
846  std::vector<double> rotList, tiltList;
847  double rot_step_at_equator = (prm.rot_range.angF - prm.rot_range.ang0) /
848  (double)(Nrot - 1);
849  make_even_distribution(rotList, tiltList, rot_step_at_equator, SL, true);
850  size_t NN=rotList.size();
851  for (size_t n=0; n<NN; ++n)
852  {
853  if (tiltList[n]>=prm.tilt_range.ang0 && tiltList[n]<=prm.tilt_range.angF &&
854  rotList[n]>=prm.rot_range.ang0 && rotList[n]<=prm.rot_range.angF)
855  {
856  size_t DFid=DF.addObject();
857  DF.setValue(MDL_ANGLE_ROT,rotList[n],DFid);
858  DF.setValue(MDL_ANGLE_TILT,tiltList[n],DFid);
859  DF.setValue(MDL_ANGLE_PSI,0.0,DFid);
860  }
861  }
862  }
863  }
864  }
865 
866  // Exit
867  return ExtProjs + IntProjs;
868 }
869 
870 /* Produce Side Information ================================================ */
872  ProgProject &prog_prm)
873 {
874  // Generate Projection angles
875  if (!prog_prm.singleProjection)
876  Assign_angles(DF, prm, prog_prm.fn_sym);
877  else
878  {
879  size_t DFid=DF.addObject();
880  DF.setValue(MDL_ANGLE_ROT,prog_prm.rotSingle,DFid);
881  DF.setValue(MDL_ANGLE_TILT,prog_prm.tiltSingle,DFid);
882  DF.setValue(MDL_ANGLE_PSI,prog_prm.psiSingle,DFid);
883  DF.setValue(MDL_SHIFT_X,prog_prm.xShift,DFid);
884  DF.setValue(MDL_SHIFT_Y,prog_prm.yShift,DFid);
885  }
886 
887  // Load Phantom and set working mode
888  if (prog_prm.fnPhantom.isMetaData())
889  {
890  phantomDescr.read(prog_prm.fnPhantom);
891  phantomMode = XMIPP;
892  if (prog_prm.singleProjection)
893  {
894  if (prog_prm.projSize==-1)
895  prm.proj_Xdim=prm.proj_Ydim=phantomDescr.xdim;
896  else
897  prm.proj_Xdim=prm.proj_Ydim=prog_prm.projSize;
898  }
899  }
900  else if (prog_prm.fnPhantom.getExtension()=="pdb")
901  {
902  phantomPDB.read(prog_prm.fnPhantom);
903  for (int i=0; i<phantomPDB.atomList.size(); i++)
904  {
905  phantomPDB.atomList[i].x /=prog_prm.samplingRate;
906  phantomPDB.atomList[i].y /=prog_prm.samplingRate;
907  phantomPDB.atomList[i].z /=prog_prm.samplingRate;
908  }
909  int M=ROUND(prog_prm.samplingRate/prog_prm.highTs);
910  interpolator.setup(M,prog_prm.samplingRate/M,true);
911  phantomMode = PDB;
912  if (prog_prm.singleProjection)
913  {
914  if (prog_prm.projSize==-1)
915  REPORT_ERROR(ERR_ARG_MISSING,"--xdim");
916  else
917  prm.proj_Xdim=prm.proj_Ydim=prog_prm.projSize;
918  }
919  }
920  else
921  {
922  phantomVol.read(prog_prm.fnPhantom);
923  phantomVol().setXmippOrigin();
924  phantomMode = VOXEL;
925  if (prog_prm.singleProjection)
926  {
927  if (prog_prm.projSize==-1)
928  prm.proj_Xdim=prm.proj_Ydim=XSIZE(phantomVol());
929  else
930  prm.proj_Xdim=prm.proj_Ydim=prog_prm.projSize;
931  }
932  }
933  paddFactor = prog_prm.paddFactor;
934  maxFrequency = prog_prm.maxFrequency;
935  BSplineDeg = prog_prm.BSplineDeg;
936 }
937 
938 /* Effectively project ===================================================== */
940  bool singleProjection,
942  double sampling_rate,
943  const ParametersProjection &prm,
944  PROJECT_Side_Info &side,
945  const Crystal_Projection_Parameters &prm_crystal,
946  Projection &proj, MetaData &SF)
947 {
948  int NumProjs = 0;
949  SF.clear();
950  if (!fnOut.isInStack())
951  fnOut.deleteFile();
952  std::cerr << "Projecting ...\n";
953  init_progress_bar(side.DF.size());
954  SF.setComment("First set of angles=actual angles; Second set of angles=noisy angles");
955 
956  //#define DEBUG
957 #ifdef DEBUG
958 
959  MetaDataVec mdShifts;
960  MetaDataVec mdRotations;
980 #endif
981 
982  bool existFlip = false;
983  bool hasCTF=false;
984 
985  int projIdx=FIRST_IMAGE;
986  FileName fn_proj; // Projection name
987  RealShearsInfo *Vshears=nullptr;
988  FourierProjector *Vfourier=nullptr;
989  if (projType == SHEARS && side.phantomMode==PROJECT_Side_Info::VOXEL)
990  Vshears=new RealShearsInfo(side.phantomVol());
991  if (projType == FOURIER && side.phantomMode==PROJECT_Side_Info::VOXEL)
992  Vfourier=new FourierProjector(side.phantomVol(),side.paddFactor,side.maxFrequency,side.BSplineDeg);
994  fn_proj=fnOut;
995  if (side.doCrystal)
996  createEmptyFile(fn_proj, prm_crystal.crystal_Xdim, prm_crystal.crystal_Ydim,
997  1, side.DF.size(), true,WRITE_OVERWRITE);
998  else
999  createEmptyFile(fn_proj, prm.proj_Xdim, prm.proj_Ydim,
1000  1, side.DF.size(), true,WRITE_OVERWRITE);
1001 
1002  if (side.DF.containsLabel(MDL_FLIP))
1003  existFlip = true;
1004 
1005 
1006  for (size_t objId : side.DF.ids())
1007  {
1008  size_t DFmov_objId=SF.addObject();
1009  if (!singleProjection)
1010  fn_proj.compose(projIdx,fnOut);
1011  SF.setValue(MDL_IMAGE,fn_proj,DFmov_objId);
1012  SF.setValue(MDL_ENABLED,1,DFmov_objId);
1013 
1014  // Choose angles .....................................................
1015  double rot, tilt, psi, x=0, y=0; // Actual projecting angles
1016  bool flip=false;
1017  side.DF.getValue(MDL_ANGLE_ROT,rot,objId);
1018  side.DF.getValue(MDL_ANGLE_TILT,tilt,objId);
1019  side.DF.getValue(MDL_ANGLE_PSI,psi,objId);
1020 
1021  if (prm.applyShift)
1022  {
1023  if (side.DF.containsLabel(MDL_SHIFT_X))
1024  side.DF.getValue(MDL_SHIFT_X,x,objId);
1025  if (side.DF.containsLabel(MDL_SHIFT_Y))
1026  side.DF.getValue(MDL_SHIFT_Y,y,objId);
1027  }
1028  realWRAP(rot, 0, 360);
1029  realWRAP(tilt, 0, 360);
1030  realWRAP(psi, 0, 360);
1031 
1032  if (existFlip)
1033  side.DF.getValue(MDL_FLIP,flip,objId);
1034 
1035 
1036  SF.setValue(MDL_ANGLE_ROT,rot,DFmov_objId);
1037  SF.setValue(MDL_ANGLE_TILT,tilt,DFmov_objId);
1038  SF.setValue(MDL_ANGLE_PSI,psi,DFmov_objId);
1039 
1040  if ((NumProjs % XMIPP_MAX(1, side.DF.size() / 60)) == 0)
1041  progress_bar(NumProjs);
1042 
1043  // Choose Center displacement ........................................
1044  double shiftX = rnd_gaus(prm.Ncenter_avg, prm.Ncenter_dev)+x;
1045  double shiftY = rnd_gaus(prm.Ncenter_avg, prm.Ncenter_dev)+y;
1046  SF.setValue(MDL_SHIFT_X,shiftX,DFmov_objId);
1047  SF.setValue(MDL_SHIFT_Y,shiftY,DFmov_objId);
1048  //ROB: totally anoying behaviour in xmipp
1049  shiftX=-shiftX;
1050  shiftY=-shiftY;
1051 
1052  //If there is CTF information use it
1053  CTFDescription ctf;
1055  {
1056  //JV he tenido que tocar esta funcion para poder acceder al sampling rate
1057  hasCTF = true;
1058  MDRowVec row;
1059  side.DF.getRow(row,objId);
1060  ctf.readFromMdRow(row);
1061  ctf.produceSideInfo();
1062  }
1063 
1064 #ifdef DEBUG
1065 
1066  mdShifts.addObject();
1067  mdShifts.setValue(MDL_IMAGE,fn_proj,DFmov_objId);
1068  mdShifts.setValue(MDL_SHIFT_X,-shiftX,DFmov_objId);
1069  mdShifts.setValue(MDL_SHIFT_Y,-shiftY,DFmov_objId);
1070  mdShifts.setValue(MDL_ENABLED,1,DFmov_objId);
1071 
1072 
1073  mdRotations.addObject();
1074  mdRotations.setValue(MDL_IMAGE,fn_proj,DFmov_objId);
1075  mdRotations.setValue(MDL_ANGLE_ROT,-rot,DFmov_objId);
1076  mdRotations.setValue(MDL_ANGLE_TILT,-tilt,DFmov_objId);
1077  mdRotations.setValue(MDL_ANGLE_PSI,-psi,DFmov_objId);
1078 
1079 
1080 #endif
1081  // Really project ....................................................
1083  {
1084  if (projType == SHEARS)
1085  projectVolume(*Vshears, proj, prm.proj_Ydim, prm.proj_Xdim,
1086  rot, tilt, psi);
1087  else if (projType == FOURIER)
1088  projectVolume(*Vfourier, proj, prm.proj_Ydim, prm.proj_Xdim,
1089  rot, tilt, psi);
1090  else if (projType == REALSPACE)
1091  projectVolume(side.phantomVol(), proj, prm.proj_Ydim, prm.proj_Xdim,
1092  rot, tilt, psi);
1093 
1094  if (hasCTF)
1095  ctf.applyCTF(proj(),sampling_rate, prm.doPhaseFlip);
1096 
1097  hasCTF = false;
1098 
1099  Matrix1D<double> shifts(2);
1100  XX(shifts) = shiftX;
1101  YY(shifts) = shiftY;
1103  }
1104  else if (side.phantomMode==PROJECT_Side_Info::PDB)
1105  {
1106  PDBPhantom aux;
1107  aux=side.phantomPDB;
1108  aux.shift(shiftX,shiftY,0);
1109  projectPDB(side.phantomPDB, side.interpolator,
1110  proj, prm.proj_Ydim, prm.proj_Xdim,
1111  rot, tilt, psi);
1112  }
1113  else if (side.phantomMode==PROJECT_Side_Info::XMIPP)
1114  {
1115  Phantom aux;
1116  aux = side.phantomDescr;
1117  aux.shift(shiftX, shiftY, 0);
1118  if (prm_crystal.crystal_Xdim == 0)
1119  {
1120  // Project a single mathematical volume
1121  aux.project_to(proj,
1122  prm.proj_Ydim, prm.proj_Xdim,
1123  rot, tilt, psi);
1124  }
1125  else
1126  { // Project mathematical volume as a crystal
1127  project_crystal(aux, proj, prm, side, prm_crystal, rot, tilt, psi);
1128  }
1129  }
1130  if (flip)
1131  proj().selfReverseX();
1132 
1133  // Add noise in angles and voxels ....................................
1134  SF.setValue(MDL_ANGLE_ROT2,rot,DFmov_objId);
1135  SF.setValue(MDL_ANGLE_TILT2,tilt,DFmov_objId);
1136  SF.setValue(MDL_ANGLE_PSI2,psi,DFmov_objId);
1137  rot += rnd_gaus(prm.rot_range.Navg, prm.rot_range.Ndev);
1138  tilt += rnd_gaus(prm.tilt_range.Navg, prm.tilt_range.Ndev);
1139  psi += rnd_gaus(prm.psi_range.Navg, prm.psi_range.Ndev);
1140 
1141 
1142  SF.setValue(MDL_ANGLE_ROT,realWRAP(rot, 0, 360),DFmov_objId);
1143  SF.setValue(MDL_ANGLE_TILT,realWRAP(tilt, 0, 360),DFmov_objId);
1144  SF.setValue(MDL_ANGLE_PSI,realWRAP(psi, 0, 360),DFmov_objId);
1145 
1146  IMGMATRIX(proj).addNoise(prm.Npixel_avg, prm.Npixel_dev, "gaussian");
1147 
1148  // Save ..............................................................
1149  if (singleProjection)
1150  proj.write(fn_proj);
1151  else
1152  {
1153  proj.write(fn_proj,projIdx,true,WRITE_OVERWRITE);
1154  }
1155  projIdx++;
1156  NumProjs++;
1157  }
1158  progress_bar(side.DF.size());
1159 
1160 #ifdef DEBUG
1161 
1162  mdShifts.write("shifts.xmd");
1163  mdRotations.write("rotations.xmd");
1164 #endif
1165 #undef DEBUG
1166  // release memory
1167  delete Vshears;
1168  delete Vfourier;
1169 
1170  return NumProjs;
1171 }
1172 
1173 /* ROUT_project ============================================================ */
1175 {
1177  // Read projection parameters and produce side information
1178  ParametersProjection proj_prm;
1179  PROJECT_Side_Info side;
1180  if (!prm.singleProjection)
1181  proj_prm.from_prog_params(prm);
1182  side.produce_Side_Info(proj_prm, prm);
1183  Crystal_Projection_Parameters crystal_proj_prm;
1184 
1185  side.doCrystal=false;
1186  if (prm.fn_proj_param != "")
1187  {
1188  MetaDataVec MD;
1189  size_t objId;
1190  MD.read(prm.fn_proj_param);
1191  objId = MD.firstRowId();
1192  MD.getValue(MDL_CRYSTAL_PROJ,side.doCrystal,objId);
1193  }
1194  if (side.doCrystal)
1195  {
1196  crystal_proj_prm.read(prm.fn_proj_param,
1197  (side.phantomDescr).phantom_scale);
1198  // if not null read doc file with unitcell shift
1199  // format h, k, shift_X shift_Y shift_Z
1200  if (crystal_proj_prm.DF_shift_bool == true)
1201  crystal_proj_prm.DF_shift.read(crystal_proj_prm.fn_shift);
1202  double my_scale = (side.phantomDescr).phantom_scale;
1203 
1204  for (size_t objId : crystal_proj_prm.DF_shift.ids())
1205  {
1206  double xcell, ycell;
1207  crystal_proj_prm.DF_shift.getValue(MDL_CRYSTAL_CELLX,xcell,objId);
1208  crystal_proj_prm.DF_shift.getValue(MDL_CRYSTAL_CELLY,ycell,objId);
1209  crystal_proj_prm.DF_shift.setValue(MDL_CRYSTAL_CELLX,xcell*my_scale,objId);
1210  crystal_proj_prm.DF_shift.setValue(MDL_CRYSTAL_CELLY,ycell*my_scale,objId);
1211 
1212  double x,y,z;
1213  crystal_proj_prm.DF_shift.getValue(MDL_SHIFT_X,x,objId);
1214  crystal_proj_prm.DF_shift.getValue(MDL_SHIFT_Y,y,objId);
1215  crystal_proj_prm.DF_shift.getValue(MDL_SHIFT_Z,z,objId);
1216  crystal_proj_prm.DF_shift.setValue(MDL_SHIFT_X,x*my_scale,objId);
1217  crystal_proj_prm.DF_shift.setValue(MDL_SHIFT_Y,y*my_scale,objId);
1218  crystal_proj_prm.DF_shift.setValue(MDL_SHIFT_Z,z*my_scale,objId);
1219 
1220  crystal_proj_prm.DF_shift.getValue(MDL_CRYSTAL_SHIFTX,x,objId);
1221  crystal_proj_prm.DF_shift.getValue(MDL_CRYSTAL_SHIFTY,y,objId);
1222  crystal_proj_prm.DF_shift.getValue(MDL_CRYSTAL_SHIFTZ,z,objId);
1223  crystal_proj_prm.DF_shift.setValue(MDL_CRYSTAL_SHIFTX,x*my_scale,objId);
1224  crystal_proj_prm.DF_shift.setValue(MDL_CRYSTAL_SHIFTY,y*my_scale,objId);
1225  crystal_proj_prm.DF_shift.setValue(MDL_CRYSTAL_SHIFTZ,z*my_scale,objId);
1226  }
1227  }
1228 
1229  //#define DEBUG1
1230 #ifdef DEBUG1
1231  if (crystal_proj_prm.DF_shift_bool == true)
1232  crystal_proj_prm.DF_shift.write("DEBUG1_shifts");
1233 #endif
1234 #undef DEBUG1
1235 
1236 
1237  int ProjNo = 0;
1238  if (!prm.only_create_angles)
1239  {
1240  // Really project
1241  if (prm.singleProjection)
1243  proj_prm, side, crystal_proj_prm, proj, SF);
1244  else
1245  {
1246  FileName stackName;
1247  if (prm.fnOut.hasStackExtension())
1248  stackName = prm.fnOut;
1249  else
1250  stackName = prm.fnOut.removeAllExtensions() + ".stk";
1251  FileName mdName = prm.fnOut.removeAllExtensions() + ".xmd";
1252  ProjNo = PROJECT_Effectively_project(stackName, prm.singleProjection, prm.projType,prm.samplingRate,
1253  proj_prm, side, crystal_proj_prm, proj, SF);
1254  SF.setComment("Angles rot,tilt and psi contain noisy projection angles and rot2,tilt2 and psi2 contain actual projection angles");
1255  SF.write(mdName);
1256  }
1257  }
1258  else
1259  if (!prm.singleProjection)
1260  side.DF.write(prm.fnOut.removeAllExtensions()+".xmd");
1261  return ProjNo;
1262 }
Argument missing.
Definition: xmipp_error.h:114
void init_progress_bar(long total)
double highTs
High sampling rate: Only used for PDB projections.
Definition: project.h:65
Errors on command line parameters.
Definition: xmipp_error.h:112
void produce_Side_Info(ParametersProjection &prm, ProgProject &prog_prm)
Definition: project.cpp:871
void defineParams()
Definition: project.cpp:91
bool enable_angle_range
Enable angle range mode (0 or 1)
Definition: project.h:169
constexpr int FOURIER
Rotation angle of an image (double,degrees)
char * firstWord(char *str)
Parameter incorrect.
Definition: xmipp_error.h:181
Defocus U (Angstroms)
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
virtual size_t addObject()=0
Tilting angle of an image (double,degrees)
int ROUT_project(ProgProject &prm, Projection &proj, MetaData &SF)
Definition: project.cpp:1174
#define Npsi
Definition: project.cpp:558
void read(const FileName &fn_crystal, double scale=1.0)
projectionType projType
Type of projection algorithm.
Definition: project.h:81
void sort(const MetaDataVec &MDin, const MDLabel sortLabel, bool asc=true, int limit=-1, int offset=0)
double getDoubleParam(const char *param, int arg=0)
virtual void read(int argc, const char **argv, bool reportErrors=true)
double paddFactor
The padding factor for Fourier projection.
Definition: project.h:83
Cell location for crystals.
int proj_Ydim
Projection Ydim.
Definition: project.h:163
void projectPDB(const PDBPhantom &phantomPDB, const AtomInterpolator &interpolator, Projection &proj, int Ydim, int Xdim, double rot, double tilt, double psi)
Definition: pdb.cpp:1603
double Ndev
Stddev of the noise that must be added to the definition of the angle.
Definition: project.h:145
void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=nullptr, bool decomposeStack=true) override
virtual void clear()
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Angle_range psi_range
Psi angle range.
Definition: project.h:175
bool singleProjection
Single projection.
Definition: project.h:69
< Type of randomness for Tilt (std::string)
#define DEG2RAD(d)
Definition: xmipp_macros.h:312
void make_even_distribution(std::vector< double > &rotList, std::vector< double > &tiltList, double sampling, SymList &SL, bool include_mirror)
Make even distribution, taking symmetry into account.
Definition: directions.cpp:133
Angle_range tilt_range
Tilting angle range.
Definition: project.h:173
bool removeLabel(const MDLabel label) override
#define ANGLE_RANGE_RANDOM
Definition: project.h:135
int BSplineDeg
The type of interpolation (NEAR.
Definition: project.h:237
< Rotational angle dev and mean noise (vector double)
virtual void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const =0
int Assign_angles(MetaDataVec &DF, const ParametersProjection &prm, const FileName &fn_sym)
Definition: project.cpp:801
Tilting angle of an image (double,degrees)
static double * y
Phantom phantomDescr
Phantom mathematical description.
Definition: project.h:227
PDBPhantom phantomPDB
Phantom PDB.
Definition: project.h:229
int samples
No. of samples.
Definition: project.h:131
int readSymmetryFile(FileName fn_sym, double accuracy=SYM_ACCURACY)
Definition: symmetries.cpp:33
Shift for the image in the X axis (double)
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
PhantomType phantomMode
Projecting from a voxel volume, Xmipp description or PDB?
Definition: project.h:223
File for generated angles.
void generate_even_angles(int ExtProjs, int Nrottilt, MetaDataVec &DF, const ParametersProjection &prm)
Definition: project.cpp:706
Special label to be used when gathering MDs in MpiMetadataPrograms.
Name for the CTF Model (std::string)
size_t firstObject(const MDQuery &) const override
void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const
void from_prog_params(const ProgProject &prog_prm)
Definition: project.cpp:183
int proj_Xdim
Projection Xdim.
Definition: project.h:161
double maxFrequency
The maximum frequency for pixels.
Definition: project.h:235
FileName removeAllExtensions() const
void shift(double shiftX, double shiftY, double shiftZ)
Definition: phantom.cpp:2479
Definition: situs.h:43
double Npixel_avg
Bias to be applied to each pixel grey value */.
Definition: project.h:188
virtual IdIteratorProxy< false > ids()
projectionType
Type of projection.
Definition: project.h:42
double maxFrequency
The maximum frequency for Fourier projection.
Definition: project.h:85
int translate_randomness(char *str)
Definition: project.cpp:189
#define IMGMATRIX(I)
std::unique_ptr< MDRow > getRow(size_t id) override
AtomInterpolator interpolator
Atom interpolator.
Definition: project.h:231
double xShift
Definition: project.h:77
Definition: project.h:42
doublereal * x
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
virtual void setComment(const String &newComment="No comment")
FileName fnOut
Output filename (used for a singleProjection or a stack)
Definition: project.h:54
void addSeeAlsoLine(const char *seeAlso)
double yShift
Definition: project.h:79
bool DF_shift_bool
is doc file with shifts available
Shift for the image in the Z axis (double) for crystals.
double tiltSingle
Tilt angle of a single projection.
Definition: project.h:73
double Ncenter_avg
Bias to apply to the image center.
Definition: project.h:193
MetaDataVec DF_shift
Document File for shifts. Order: H K x_SHIFT y_SHIFT z_SHIFT.
String getExtension() const
double rnd_unif()
void readParams()
Definition: project.cpp:35
bool isEmpty() const override
Rotation angle of an image (double,degrees)
FileName fn_proj_param
Filename with the Projection_Parameters.
Definition: project.h:49
Shift for the image in the Y axis (double) for crystals.
Image< double > phantomVol
Phantom Xmipp volume.
Definition: project.h:225
FileName fn_angle
Document filename.
Definition: project.h:185
int PROJECT_Effectively_project(const FileName &fnOut, bool singleProjection, projectionType projType, double sampling_rate, const ParametersProjection &prm, PROJECT_Side_Info &side, const Crystal_Projection_Parameters &prm_crystal, Projection &proj, MetaData &SF)
Definition: project.cpp:939
const char * getParam(const char *param, int arg=0)
#define XX(v)
Definition: matrix1d.h:85
double rotSingle
Rotational angle of a single projection.
Definition: project.h:71
void applyCTF(MultidimArray< std::complex< double > > &FFTI, const MultidimArray< double > &I, double Ts, bool absPhase=false)
Apply CTF to an image.
Definition: ctf.cpp:1521
<Orthogonal projection or not (bool)
void selfTranslate(int SplineDegree, MultidimArray< T > &V1, const Matrix1D< double > &v, bool wrap=xmipp_transformation::WRAP, T outside=0)
bool setValue(const MDObject &mdValueIn, size_t id)
double paddFactor
The padding factor for Fourier projection.
Definition: project.h:233
size_t addObject() override
float textToFloat(const char *str)
< Have a crystal projection (bool)
size_t firstRowId() const override
double psiSingle
Psi angle of a single projection.
Definition: project.h:75
Flip the image? (bool)
Angle_range rot_range
Rotational angle range.
Definition: project.h:171
#define XSIZE(v)
void progress_bar(long rlen)
FileName fn_sym
Symmetry file.
Definition: project.h:59
void read(const FileName &fn_proj_param)
Definition: project.cpp:220
Structure for holding a volume.
double angF
final angular value
Definition: project.h:129
double Ncenter_dev
Standard deviation of the image center.
Definition: project.h:195
double z
void addExampleLine(const char *example, bool verbatim=true)
Noise description for pixels&#39; gray level (when projecting)
#define ROUND(x)
Definition: xmipp_macros.h:210
File or directory does not exist.
Definition: xmipp_error.h:136
void projectVolume(FourierProjector &projector, Projection &P, int Ydim, int Xdim, double rot, double tilt, double psi, const MultidimArray< double > *ctf)
bool only_create_angles
Only create angles, do not project.
Definition: project.h:67
void readFromMdRow(const MDRow &row, bool disable_if_not_K=true)
Definition: ctf.cpp:1172
void createEmptyFile(const FileName &filename, int xdim, int ydim, int Zdim, size_t select_img, bool isStack, int mode, int _swapWrite, const MDRowVec *md)
void shift(double x, double y, double z)
Apply a shift to all atoms.
Definition: pdb.cpp:514
#define STR_EQUAL(str1, str2)
Definition: xmipp_strings.h:42
int crystal_Xdim
Crystal X dimension.
< Psi angle dev and mean noise (vector double)
int BSplineDeg
The type of interpolation (NEAR.
Definition: project.h:87
#define Ntilt
Definition: project.cpp:557
Psi angle of an image (double,degrees)
#define j
void deleteFile() const
#define YY(v)
Definition: matrix1d.h:93
double ang0
initial angular value
Definition: project.h:127
bool getValue(MDObject &mdValueOut, size_t id) const override
#define proj_number(base, irot, itilt, ipsi)
Definition: project.cpp:559
bool addLabel(const MDLabel label, int pos=-1) override
#define ANGLE_RANGE_DETERMINISTIC
Definition: project.h:133
bool setValue(const MDLabel label, const T &valueIn, size_t id)
File cannot be open.
Definition: xmipp_error.h:137
int count_even_angles(const ParametersProjection &prm)
Definition: project.cpp:775
MetaDataVec DF
Document File for the projecting angles. Order: rot, tilt, psi.
Definition: project.h:219
int crystal_Ydim
Crystal Y dimension.
bool isMetaData(bool failIfNotExists=true) const
void generate_angles(int ExtProjs, const Angle_range &range, MetaDataVec &DF, char ang_name, const ParametersProjection &prm)
Definition: project.cpp:560
int randomness
Definition: project.h:141
#define RAD2DEG(r)
Definition: xmipp_macros.h:320
double Navg
Mean of the noise that must be added to the definition of the angle.
Definition: project.h:143
#define ANGLE_EVENLY
Definition: project.h:136
std::string String
Definition: xmipp_strings.h:34
void produceSideInfo()
Produce Side information.
Definition: ctf.cpp:1392
double psi(const double x)
double rnd_gaus()
FileName fn_shift
file with shifts
String formatString(const char *format,...)
Shift for the image in the Z axis (double)
int textToInteger(const char *str)
#define realWRAP(x, x0, xF)
Definition: xmipp_macros.h:304
char * firstToken(const char *str)
void project_crystal(Phantom &phantom, Projection &P, const ParametersProjection &prm, PROJECT_Side_Info &side, const Crystal_Projection_Parameters &prm_crystal, float rot, float tilt, float psi)
bool checkParam(const char *param)
< Type of randomness for Rotational (std::string)
Apply shift when project the volume ,.
#define FIRST_IMAGE
ProgClassifyCL2D * prm
Shift for the image in the Y axis (double)
void addUsageLine(const char *line, bool verbatim=false)
unsigned int randomize_random_generator()
bool containsLabel(const MDLabel label) const override
bool hasStackExtension() const
void project_to(Projection &P, int Ydim, int Xdim, double rot, double tilt, double psi, const Matrix2D< double > *A=nullptr) const
Definition: phantom.cpp:2511
double samplingRate
Sampling rate: Only used for PDB projections.
Definition: project.h:63
< Psi angle range (vector double)
< Tilt angle dev and mean noise (vector double)
int getIntParam(const char *param, int arg=0)
String nextToken(const String &str, size_t &i)
int projSize
Projection size when fnOut is given.
Definition: project.h:61
#define ANGLE_RANGE_RANDOM_GROUPS
Definition: project.h:134
int * n
void run()
Definition: project.cpp:175
Name of an image (std::string)
FileName fnPhantom
Definition: project.h:52
< Type of randomness for Psi (std::string)
Parameter missing.
Definition: xmipp_error.h:182
double Npixel_dev
Standard deviation of the noise to be added to each pixel grey value.
Definition: project.h:190
bool doCrystal
Is this a crystal projection.
Definition: project.h:239
void addParamsLine(const String &line)
#define Nrot
Definition: project.cpp:556
bool isInStack() const
Cell location for crystals.
#define BAD_OBJID
Definition: metadata_base.h:55