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

#include <volume_initial_simulated_annealing.h>

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

Public Member Functions

void readParams ()
 Read arguments from command line. More...
 
void defineParams ()
 Read arguments from command line. More...
 
void show ()
 
void run ()
 
void produceSideinfo ()
 Produce side info: fill arrays with relevant transformation matrices. More...
 
void reconstructCurrent ()
 Reconstruct current volume. More...
 
void generateProjections ()
 Generate projections from the current volume. More...
 
void filterByCorrelation ()
 Filter by correlation. More...
 
- Public Member Functions inherited from XmippProgram
const char * getParam (const char *param, int arg=0)
 
const char * getParam (const char *param, const char *subparam, int arg=0)
 
int getIntParam (const char *param, int arg=0)
 
int getIntParam (const char *param, const char *subparam, int arg=0)
 
double getDoubleParam (const char *param, int arg=0)
 
double getDoubleParam (const char *param, const char *subparam, int arg=0)
 
float getFloatParam (const char *param, int arg=0)
 
float getFloatParam (const char *param, const char *subparam, int arg=0)
 
void getListParam (const char *param, StringVector &list)
 
int getCountParam (const char *param)
 
bool checkParam (const char *param)
 
bool existsParam (const char *param)
 
void addParamsLine (const String &line)
 
void addParamsLine (const char *line)
 
ParamDefgetParamDef (const char *param) const
 
virtual void quit (int exit_code=0) const
 
virtual int tryRun ()
 
void initProgress (size_t total, size_t stepBin=60)
 
void setProgress (size_t value=0)
 
void endProgress ()
 
void processDefaultComment (const char *param, const char *left)
 
void setDefaultComment (const char *param, const char *comment)
 
virtual void initComments ()
 
void setProgramName (const char *name)
 
void addUsageLine (const char *line, bool verbatim=false)
 
void clearUsage ()
 
void addExampleLine (const char *example, bool verbatim=true)
 
void addSeeAlsoLine (const char *seeAlso)
 
void addKeywords (const char *keywords)
 
const char * name () const
 
virtual void usage (int verb=0) const
 
virtual void usage (const String &param, int verb=2)
 
int version () const
 
virtual void show () const
 
virtual void read (int argc, const char **argv, bool reportErrors=true)
 
virtual void read (int argc, char **argv, bool reportErrors=true)
 
void read (const String &argumentsLine)
 
 XmippProgram ()
 
 XmippProgram (int argc, const char **argv)
 
virtual ~XmippProgram ()
 

Public Attributes

FileName fnIn
 
FileName fnRoot
 
FileName fnSym
 
FileName fnInit
 
double T0
 
int NiterRandom
 
int NiterGreedy
 
double rejection
 
int Nthr
 
bool positiveConstraint
 
bool keepIntermediateVolumes
 
double angularSampling
 
MetaDataDb mdIn
 
MetaDataDb mdReconstruction
 
std::vector< GalleryImagemdGallery
 
std::vector< InputImagemdInp
 
FileName fnAngles
 
FileName fnVolume
 
FileName fnGallery
 
FileName fnGalleryMetaData
 
Image< double > gallery
 
Image< double > inputImages
 
int iter
 
ThreadVolumeInitialAlignmentthreadResults
 
Mutex mutexMaxCC
 
double sumCorr
 
double sumImprovement
 
- Public Attributes inherited from XmippProgram
bool doRun
 
bool runWithoutArgs
 
int verbose
 Verbosity level. More...
 
int debug
 

Additional Inherited Members

- Protected Member Functions inherited from XmippProgram
void defineCommons ()
 
- Protected Attributes inherited from XmippProgram
int errorCode
 
ProgramDefprogDef
 Program definition and arguments parser. More...
 
std::map< String, CommentListdefaultComments
 
int argc
 Original command line arguments. More...
 
const char ** argv
 

Detailed Description

Random reconstruction parameters.

Definition at line 61 of file volume_initial_simulated_annealing.h.

Member Function Documentation

◆ defineParams()

void ProgVolumeInitialSimulatedAnnealing::defineParams ( )
virtual

Read arguments from command line.

Reimplemented from XmippProgram.

Definition at line 30 of file volume_initial_simulated_annealing.cpp.

31 {
32  //usage
33  addUsageLine("Generate 3D reconstructions from projections using random orientations");
34  //params
35  addParamsLine(" -i <md_file> : Metadata file with input projections");
36  addParamsLine(" [--oroot <volume_file=\"rec_random\">] : Filename for output rootname");
37  addParamsLine(" [--sym <symfile=c1>] : Enforce symmetry in projections");
38  addParamsLine(" [--randomIter <N=10>] : Number of iterations with random assignment");
39  addParamsLine(" [--greedyIter <N=0>] : Number of iterations with greedy assignment");
40  addParamsLine(" [--rejection <p=25>] : Percentage of images to reject for reconstruction");
41  addParamsLine(" [--initial <file=\"\">] : Initial volume if available");
42  addParamsLine(" [--keepIntermediateVolumes] : Keep the volume of each iteration");
43  addParamsLine(" [--dontApplyPositive] : Do not apply positive constraint in the random iterations");
44  addParamsLine(" [--T0 <T=0.1>] : Initial temperature for simulated annealing");
45  addParamsLine(" [--thr <n=1>] : Number of threads");
46  addParamsLine(" [--angularSampling <a=5>] : Angular sampling in degrees for generating the projection gallery");
47 }
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)

◆ filterByCorrelation()

void ProgVolumeInitialSimulatedAnnealing::filterByCorrelation ( )

Filter by correlation.

Definition at line 301 of file volume_initial_simulated_annealing.cpp.

302 {
303  MetaDataVec mdAux;
304  mdAux=mdReconstruction;
305  mdAux.removeDisabled();
306 
307  std::vector<double> correlations;
308  mdAux.getColumnValues(MDL_MAXCC,correlations);
309  std::sort(correlations.begin(),correlations.end());
310  auto skip=(size_t)floor(correlations.size()*(rejection/100.0));
311  double minCorr=correlations[skip];
312  //double maxCorr=correlations[correlations.size()-skip/4-1];
313 
314  std::vector<double> weights;
315  mdAux.getColumnValues(MDL_WEIGHT,weights);
316  std::sort(weights.begin(),weights.end());
317  double minWeight=weights[skip];
318  //double maxWeight=weights[weights.size()-skip/4-1];
319 
320  for (size_t objId : mdAux.ids())
321  {
322  double cc, weight;
323  mdAux.getValue(MDL_MAXCC,cc,objId);
324  if (cc<minCorr) // COSS || cc>maxCorr)
325  mdAux.setValue(MDL_ENABLED,-1,objId);
326  mdAux.getValue(MDL_WEIGHT,weight,objId);
327  if (weight<minWeight) // COSS || weight>maxWeight)
328  mdAux.setValue(MDL_ENABLED,-1,objId);
329  }
330  mdAux.removeDisabled();
331  mdAux.write(fnAngles);
332 }
__host__ __device__ float2 floor(const float2 v)
void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const
virtual IdIteratorProxy< false > ids()
Is this image enabled? (int [-1 or 1])
bool setValue(const MDObject &mdValueIn, size_t id)
Maximum cross-correlation for the image (double)
void sort(struct DCEL_T *dcel)
Definition: sorting.cpp:18
size_t correlations(const Dimensions &d)
bool getValue(MDObject &mdValueOut, size_t id) const override
void getColumnValues(const MDLabel label, std::vector< MDObject > &valuesOut) const override
virtual void removeDisabled()
< Score 4 for volumes

◆ generateProjections()

void ProgVolumeInitialSimulatedAnnealing::generateProjections ( )

Generate projections from the current volume.

Definition at line 362 of file volume_initial_simulated_annealing.cpp.

363 {
364  String args=formatString("-i %s -o %s --sampling_rate %f --sym %s --compute_neighbors --angular_distance -1 --experimental_images %s -v 0",
365  fnVolume.c_str(),fnGallery.c_str(),angularSampling,fnSym.c_str(),fnAngles.c_str());
366  String cmd=(String)"xmipp_angular_project_library "+args;
367  if (system(cmd.c_str())==-1)
368  REPORT_ERROR(ERR_UNCLASSIFIED,"Cannot open shell");
370  mdGallery.clear();
371  for (size_t objId : mdAux.ids())
372  {
373  GalleryImage I;
374  mdAux.getValue(MDL_IMAGE,I.fnImg,objId);
375  mdAux.getValue(MDL_ANGLE_ROT,I.rot,objId);
376  mdAux.getValue(MDL_ANGLE_TILT,I.tilt,objId);
377  mdGallery.push_back(I);
378  }
380 }
Just to locate unclassified errors.
Definition: xmipp_error.h:192
Rotation angle of an image (double,degrees)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Tilting angle of an image (double,degrees)
std::string String
Definition: xmipp_strings.h:34
String formatString(const char *format,...)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
Name of an image (std::string)

◆ produceSideinfo()

void ProgVolumeInitialSimulatedAnnealing::produceSideinfo ( )

Produce side info: fill arrays with relevant transformation matrices.

Definition at line 382 of file volume_initial_simulated_annealing.cpp.

383 {
384  mdIn.read(fnIn);
386 
387  mdIn.fillConstant(MDL_MAXCC,"0.0");
388  mdIn.fillRandom(MDL_ANGLE_ROT,"uniform",0,360);
389  mdIn.fillRandom(MDL_ANGLE_TILT,"uniform",0,180);
390  mdIn.fillRandom(MDL_ANGLE_PSI,"uniform",0,360);
394 
395  fnAngles=fnRoot+".xmd";
396  fnVolume=fnRoot+".vol";
397  fnGallery=fnRoot+"_gallery.stk";
398  fnGalleryMetaData=fnRoot+"_gallery.doc";
399 
400  size_t xdim, ydim, zdim, ndim;
401  getImageSize(mdIn,xdim, ydim, zdim, ndim);
402  inputImages().resizeNoCopy(mdIn.size(), 1, ydim, xdim);
403 
404  Image<double> I;
405  size_t n=0;
406  MultidimArray<double> mCurrentImage;
407  for (size_t objId : mdIn.ids())
408  {
409  InputImage Ip;
410  mdIn.getValue(MDL_IMAGE,Ip.fnImg,objId);
411  Ip.maxcc=0.0;
412  mdInp.push_back(Ip);
413  I.read(Ip.fnImg);
414  mCurrentImage.aliasImageInStack(inputImages(),n++);
415  memcpy(MULTIDIM_ARRAY(mCurrentImage),MULTIDIM_ARRAY(I()),MULTIDIM_SIZE(mCurrentImage)*sizeof(double));
416  }
417 
419  iter=0;
420  if (fnInit=="")
422  else
423  {
424  if (system(formatString("cp %s %s",fnInit.c_str(),fnVolume.c_str()).c_str())==-1)
425  REPORT_ERROR(ERR_UNCLASSIFIED,"Cannot open shell");
426  }
427 
429 }
Just to locate unclassified errors.
Definition: xmipp_error.h:192
Rotation angle of an image (double,degrees)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define MULTIDIM_SIZE(v)
void aliasImageInStack(const MultidimArray< T > &m, size_t select_image)
bool getValue(MDObject &mdValueOut, size_t id) const override
Tilting angle of an image (double,degrees)
Shift for the image in the X axis (double)
void getImageSize(const MetaData &md, size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim, MDLabel image_label)
#define MULTIDIM_ARRAY(v)
Special label to be used when gathering MDs in MpiMetadataPrograms.
void reconstructCurrent()
Reconstruct current volume.
virtual IdIteratorProxy< false > ids()
void fillConstant(MDLabel label, const String &value) override
Maximum cross-correlation for the image (double)
void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const override
size_t size() const override
virtual void removeDisabled()
String formatString(const char *format,...)
void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=NULL, bool decomposeStack=true) override
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
Shift for the image in the Y axis (double)
int * n
Name of an image (std::string)
void fillRandom(MDLabel label, const String &mode, double op1, double op2, double op3=0.) override
< Score 4 for volumes

◆ readParams()

void ProgVolumeInitialSimulatedAnnealing::readParams ( )
virtual

Read arguments from command line.

Reimplemented from XmippProgram.

Definition at line 50 of file volume_initial_simulated_annealing.cpp.

51 {
52  fnIn = getParam("-i");
53  fnRoot = getParam("--oroot");
54  fnSym = getParam("--sym");
55  T0 = getDoubleParam("--T0");
56  NiterRandom = getIntParam("--randomIter");
57  NiterGreedy = getIntParam("--greedyIter");
58  rejection = getDoubleParam("--rejection");
59  fnInit = getParam("--initial");
60  Nthr = getIntParam("--thr");
61  positiveConstraint = !checkParam("--dontApplyPositive");
62  keepIntermediateVolumes = checkParam("--keepIntermediateVolumes");
63  angularSampling=getDoubleParam("--angularSampling");
64 }
double getDoubleParam(const char *param, int arg=0)
const char * getParam(const char *param, int arg=0)
bool checkParam(const char *param)
int getIntParam(const char *param, int arg=0)

◆ reconstructCurrent()

void ProgVolumeInitialSimulatedAnnealing::reconstructCurrent ( )

Reconstruct current volume.

Definition at line 334 of file volume_initial_simulated_annealing.cpp.

335 {
336  String args=formatString("-i %s -o %s --sym %s --weight --thr %d -v 0",fnAngles.c_str(),fnVolume.c_str(),fnSym.c_str(),Nthr);
337  String cmd=(String)"xmipp_reconstruct_fourier "+args;
338  if (system(cmd.c_str())==-1)
339  REPORT_ERROR(ERR_UNCLASSIFIED,"Cannot open shell");
340 
341  args=formatString("-i %s --mask circular %d -v 0",fnVolume.c_str(),-XSIZE(inputImages())/2);
342  cmd=(String)"xmipp_transform_mask "+args;
343  if (system(cmd.c_str())==-1)
344  REPORT_ERROR(ERR_UNCLASSIFIED,"Cannot open shell");
345 
347  {
348  args=formatString("-i %s --select below 0 --substitute value 0 -v 0",fnVolume.c_str());
349  cmd=(String)"xmipp_transform_threshold "+args;
350  if (system(cmd.c_str())==-1)
351  REPORT_ERROR(ERR_UNCLASSIFIED,"Cannot open shell");
352  }
353 
355  {
356  cmd=formatString("cp %s %s_iter%02d.vol",fnVolume.c_str(),fnRoot.c_str(),iter);
357  if (system(cmd.c_str())==-1)
358  REPORT_ERROR(ERR_UNCLASSIFIED,"Cannot open shell");
359  }
360 }
Just to locate unclassified errors.
Definition: xmipp_error.h:192
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define XSIZE(v)
std::string String
Definition: xmipp_strings.h:34
String formatString(const char *format,...)

◆ run()

void ProgVolumeInitialSimulatedAnnealing::run ( )
virtual

Run.

Reimplemented from XmippProgram.

Definition at line 262 of file volume_initial_simulated_annealing.cpp.

263 {
264  show();
265  produceSideinfo();
266 
267  bool finish=false;
268  iter=1;
269  ThreadManager thMgr(Nthr,this);
270  do
271  {
272  // Generate projections from the volume
274 
275  // Align the input images to the projections
281  size_t nImg=0;
282  for (size_t objId : mdIn.ids())
283  mdIn.setValue(MDL_MAXCC,mdInp[nImg++].maxcc,objId);
284  std::cout << "Iter " << iter << " avg.correlation=" << sumCorr/mdIn.size()
285  << " avg.improvement=" << sumImprovement/mdIn.size() << std::endl;
286 
287  // Remove too good and too bad images
289 
290  // Reconstruct
292 
293  finish=(iter==(NiterRandom+NiterGreedy));
294  iter++;
295  } while (!finish);
296  deleteFile(fnRoot+"_gallery_sampling.xmd");
297  deleteFile(fnRoot+"_gallery.stk");
298  deleteFile(fnRoot+"_gallery.doc");
299 }
void run(ThreadFunction function, void *data=NULL)
void generateProjections()
Generate projections from the current volume.
void init_progress_bar(long total)
ThreadManager * thMgr
void reconstructCurrent()
Reconstruct current volume.
virtual IdIteratorProxy< false > ids()
void produceSideinfo()
Produce side info: fill arrays with relevant transformation matrices.
void deleteFile(const char *line)
Definition: tools.cpp:280
void progress_bar(long rlen)
void clear() override
Definition: metadata_db.cpp:54
Maximum cross-correlation for the image (double)
size_t size() const override
bool setValue(const MDObject &mdValueIn, size_t id) override
Definition: metadata_db.cpp:90
void threadAlignSubset(ThreadArgument &thArg)

◆ show()

void ProgVolumeInitialSimulatedAnnealing::show ( )

Show.

Definition at line 67 of file volume_initial_simulated_annealing.cpp.

68 {
69  if (verbose > 0)
70  {
71  std::cout << "Input metadata : " << fnIn << std::endl;
72  std::cout << "Output rootname : " << fnRoot << std::endl;
73  std::cout << "T0 : " << T0 << std::endl;
74  std::cout << "Number of random iterations : " << NiterRandom << std::endl;
75  std::cout << "Number of greedy iterations : " << NiterGreedy << std::endl;
76  std::cout << "Rejection percentage : " << rejection << std::endl;
77  std::cout << "Number of threads : " << Nthr << std::endl;
78  std::cout << "Apply positive constraint : " << positiveConstraint << std::endl;
79  std::cout << "Keep intermediate volumes : " << keepIntermediateVolumes << std::endl;
80  std::cout << "Angular sampling : " << angularSampling << std::endl;
81  if (fnSym != "")
82  std::cout << "Symmetry for projections : " << fnSym << std::endl;
83  if (fnInit !="")
84  std::cout << "Initial volume : " << fnInit << std::endl;
85  }
86 }
int verbose
Verbosity level.

Member Data Documentation

◆ angularSampling

double ProgVolumeInitialSimulatedAnnealing::angularSampling

Angular sampling

Definition at line 86 of file volume_initial_simulated_annealing.h.

◆ fnAngles

FileName ProgVolumeInitialSimulatedAnnealing::fnAngles

Definition at line 98 of file volume_initial_simulated_annealing.h.

◆ fnGallery

FileName ProgVolumeInitialSimulatedAnnealing::fnGallery

Definition at line 98 of file volume_initial_simulated_annealing.h.

◆ fnGalleryMetaData

FileName ProgVolumeInitialSimulatedAnnealing::fnGalleryMetaData

Definition at line 98 of file volume_initial_simulated_annealing.h.

◆ fnIn

FileName ProgVolumeInitialSimulatedAnnealing::fnIn

Filenames

Definition at line 65 of file volume_initial_simulated_annealing.h.

◆ fnInit

FileName ProgVolumeInitialSimulatedAnnealing::fnInit

Definition at line 65 of file volume_initial_simulated_annealing.h.

◆ fnRoot

FileName ProgVolumeInitialSimulatedAnnealing::fnRoot

Definition at line 65 of file volume_initial_simulated_annealing.h.

◆ fnSym

FileName ProgVolumeInitialSimulatedAnnealing::fnSym

Definition at line 65 of file volume_initial_simulated_annealing.h.

◆ fnVolume

FileName ProgVolumeInitialSimulatedAnnealing::fnVolume

Definition at line 98 of file volume_initial_simulated_annealing.h.

◆ gallery

Image<double> ProgVolumeInitialSimulatedAnnealing::gallery

Definition at line 101 of file volume_initial_simulated_annealing.h.

◆ inputImages

Image<double> ProgVolumeInitialSimulatedAnnealing::inputImages

Definition at line 101 of file volume_initial_simulated_annealing.h.

◆ iter

int ProgVolumeInitialSimulatedAnnealing::iter

Definition at line 104 of file volume_initial_simulated_annealing.h.

◆ keepIntermediateVolumes

bool ProgVolumeInitialSimulatedAnnealing::keepIntermediateVolumes

Keep intermediate volumes

Definition at line 83 of file volume_initial_simulated_annealing.h.

◆ mdGallery

std::vector<GalleryImage> ProgVolumeInitialSimulatedAnnealing::mdGallery

Definition at line 92 of file volume_initial_simulated_annealing.h.

◆ mdIn

MetaDataDb ProgVolumeInitialSimulatedAnnealing::mdIn

Definition at line 89 of file volume_initial_simulated_annealing.h.

◆ mdInp

std::vector<InputImage> ProgVolumeInitialSimulatedAnnealing::mdInp

Definition at line 95 of file volume_initial_simulated_annealing.h.

◆ mdReconstruction

MetaDataDb ProgVolumeInitialSimulatedAnnealing::mdReconstruction

Definition at line 89 of file volume_initial_simulated_annealing.h.

◆ mutexMaxCC

Mutex ProgVolumeInitialSimulatedAnnealing::mutexMaxCC

Definition at line 110 of file volume_initial_simulated_annealing.h.

◆ NiterGreedy

int ProgVolumeInitialSimulatedAnnealing::NiterGreedy

Definition at line 71 of file volume_initial_simulated_annealing.h.

◆ NiterRandom

int ProgVolumeInitialSimulatedAnnealing::NiterRandom

Total number of iterations

Definition at line 71 of file volume_initial_simulated_annealing.h.

◆ Nthr

int ProgVolumeInitialSimulatedAnnealing::Nthr

Number of threads

Definition at line 77 of file volume_initial_simulated_annealing.h.

◆ positiveConstraint

bool ProgVolumeInitialSimulatedAnnealing::positiveConstraint

Positive constraint

Definition at line 80 of file volume_initial_simulated_annealing.h.

◆ rejection

double ProgVolumeInitialSimulatedAnnealing::rejection

Rejection percentage

Definition at line 74 of file volume_initial_simulated_annealing.h.

◆ sumCorr

double ProgVolumeInitialSimulatedAnnealing::sumCorr

Definition at line 113 of file volume_initial_simulated_annealing.h.

◆ sumImprovement

double ProgVolumeInitialSimulatedAnnealing::sumImprovement

Definition at line 113 of file volume_initial_simulated_annealing.h.

◆ T0

double ProgVolumeInitialSimulatedAnnealing::T0

First temperature

Definition at line 68 of file volume_initial_simulated_annealing.h.

◆ threadResults

ThreadVolumeInitialAlignment* ProgVolumeInitialSimulatedAnnealing::threadResults

Definition at line 107 of file volume_initial_simulated_annealing.h.


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