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

#include <pdb_construct_dictionary.h>

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

Public Member Functions

void defineParams ()
 
void readParams ()
 
void show ()
 
void run ()
 
- Public Member Functions inherited from ProgPDBDictionary
void extractPatch (const MultidimArray< double > &V, MultidimArray< double > &patch, int k, int i, int j)
 
void insertPatch (MultidimArray< double > &Vhigh, MultidimArray< double > &weightHigh, const MultidimArray< double > &patchHigh, int k, int i, int j, double R2)
 
void constructRotationGroup2D ()
 
void constructRotationGroup3D ()
 
void constructRotationGroup ()
 
size_t canonicalOrientation2D (const MultidimArray< double > &patch, MultidimArray< double > &canonicalPatch, Matrix1D< double > &patchSignature)
 
size_t canonicalOrientation3D (const MultidimArray< double > &patch, MultidimArray< double > &canonicalPatch, Matrix1D< double > &patchSignature)
 
bool notInDictionary (const MultidimArray< double > &candidatePatch, MultidimArray< double > &canonicalPatch, Matrix1D< double > &canonicalSignature, size_t &canonicalIdx)
 
void selectDictionaryPatches (const MultidimArray< double > &lowResolutionPatch, Matrix1D< double > &lowResolutionPatchSignature, std::vector< size_t > &selectedPatchesIdx, std::vector< double > &weight)
 
double approximatePatch (const MultidimArray< double > &lowResolutionPatch, std::vector< size_t > &selectedPatchesIdx, std::vector< double > &weight, Matrix1D< double > &alpha)
 
void reconstructPatch (size_t idxTransf, std::vector< size_t > &selectedPatchesIdx, Matrix1D< double > &alpha, MultidimArray< double > &highResolutionPatch)
 
void loadDictionaries ()
 
void saveDictionaries () const
 
- 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 ()
 

Additional Inherited Members

- Public Attributes inherited from ProgPDBDictionary
FileName fnRoot
 
int patchSize
 
double stdThreshold
 
double angleThreshold
 
double lambda
 
int iterations
 
int mode
 
std::vector< MultidimArray< double > > dictionaryLow
 
std::vector< MultidimArray< double > > dictionaryHigh
 
std::vector< Matrix1D< double > > dictionarySignature
 
std::vector< Matrix2D< double > > rotationGroup
 
MultidimArray< double > auxPatch
 
Matrix1D< double > auxSignature
 
Matrix2D< double > Ui
 
Matrix2D< double > UitUi
 
Matrix1D< double > wi
 
Matrix1D< double > v1
 
Matrix1D< double > v2
 
Matrix1D< double > y
 
Matrix1D< double > yp
 
Matrix1D< double > Uity
 
int patchSize_2
 
- Public Attributes inherited from XmippProgram
bool doRun
 
bool runWithoutArgs
 
int verbose
 Verbosity level. More...
 
int debug
 
- 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

Construct Low and High resolution dictionary

Definition at line 137 of file pdb_construct_dictionary.h.

Member Function Documentation

◆ defineParams()

void ProgConstructPDBDictionary::defineParams ( )
virtual

Function in which the param of each Program are defined.

Reimplemented from ProgPDBDictionary.

Definition at line 541 of file pdb_construct_dictionary.cpp.

542 {
543  // Usage
544  addUsageLine("This program takes a set of PDB files at low and high resolution and constructs a dictionary for them.");
545 
546  // Parameters
547  addParamsLine(" --low <metadata> : Metadata with the low resolution volumes");
548  addParamsLine(" --high <metadata> : Metadata with the high resolution volumes");
549  addParamsLine(" [--R2Threshold <s=0.99>] : Threshold in R2 to include a patch");
550  addParamsLine(" [--oroot <root=dictionary>] : Rootname for the output files");
551  addParamsLine(" [--patchSize <n=5>] : Patch size for the dictionary");
553 }
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)

◆ readParams()

void ProgConstructPDBDictionary::readParams ( )
virtual

Function in which each program will read parameters that it need. If some error occurs the usage will be printed out.

Reimplemented from ProgPDBDictionary.

Definition at line 555 of file pdb_construct_dictionary.cpp.

556 {
557  fnLow=getParam("--low");
558  fnHigh=getParam("--high");
559  fnRoot=getParam("--oroot");
560  patchSize=getIntParam("--patchSize");
561  R2threshold=getDoubleParam("--R2Threshold");
563 }
double getDoubleParam(const char *param, int arg=0)
const char * getParam(const char *param, int arg=0)
int getIntParam(const char *param, int arg=0)

◆ run()

void ProgConstructPDBDictionary::run ( )
virtual

This function will be start running the program. it also should be implemented by derived classes.

Implements ProgPDBDictionary.

Definition at line 581 of file pdb_construct_dictionary.cpp.

582 {
583  show();
584  if (fileExists(fnRoot+"_low.mrcs"))
586 
587  MetaDataVec mdlow, mdhigh;
588  mdlow.read(fnLow);
589  mdhigh.read(fnHigh);
590  if (mode==0)
592  else
594 
595  FileName fnVol;
596  Image<double> Vlow, Vhigh;
597 #ifdef DEBUG
598  Image<double>Vmask;
599 #endif
600  MultidimArray<double> patchLow, patchHigh, canonicalPatch;
601  Matrix1D<double> alpha, canonicalSignature;
603 
604  if (mode==0)
606  else
607  patchLow.resize(patchSize,patchSize);
608  patchLow.setXmippOrigin();
609  patchHigh=patchLow;
610 
611  auto itIdLow = mdlow.ids().begin();
612  auto itIdHigh = mdhigh.ids().end();
613  for (; itIdLow != mdlow.ids().end(); ++itIdLow, ++itIdHigh)
614  {
615  // Read the low and high resolution volumes
616  mdlow.getValue(MDL_IMAGE,fnVol, *itIdLow);
617  Vlow.read(fnVol);
618  std::cout << "Processing " << fnVol << " and ";
619  mdhigh.getValue(MDL_IMAGE,fnVol, *itIdHigh);
620  std::cout << fnVol << std::endl;
621  Vhigh.read(fnVol);
622 
623  // Go through the volumes and decide whether to move into the dictionary
624  const MultidimArray<double> &mVlow=Vlow();
625  const MultidimArray<double> &mVhigh=Vhigh();
626 
627  double minLow, maxLow, meanLow, stdLow=0;
628  double minHigh, maxHigh, meanHigh, stdHigh=0;
629  mVlow.computeStats(meanLow,stdLow,minLow,maxLow);
630  mVhigh.computeStats(meanHigh,stdHigh,minHigh,maxHigh);
631 #ifdef DEBUG
632  Vmask().initZeros(Vhigh());
633 #endif
634 
635  std::vector< size_t > selectedPatchesIdx;
636  std::vector<double> weight;
637  size_t Npatches=0, NcandidatePatches=0, NsuccessfulPatches=0;
638  init_progress_bar(ZSIZE(mVlow));
639  for (int k=patchSize_2; k<(int)ZSIZE(mVlow)-patchSize_2; ++k)
640  {
641  for (int i=patchSize_2; i<(int)ZSIZE(mVlow)-patchSize_2; ++i)
642  for (int j=patchSize_2; j<(int)ZSIZE(mVlow)-patchSize_2; ++j)
643  {
644  ++Npatches;
645  extractPatch(mVlow,patchLow,k,i,j);
646  extractPatch(mVhigh,patchHigh,k,i,j);
647 
648  double minPatchLow, maxPatchLow, meanPatchLow, stdPatchLow=0;
649  double minPatchHigh, maxPatchHigh, meanPatchHigh, stdPatchHigh=0;
650  patchLow.computeStats(meanPatchLow,stdPatchLow,minPatchLow,maxPatchLow);
651  patchHigh.computeStats(meanPatchHigh,stdPatchHigh,minPatchHigh,maxPatchHigh);
652 
653  if (stdPatchLow > stdThreshold*stdLow && stdPatchHigh > stdThreshold*stdHigh)
654  {
655  ++NcandidatePatches;
656 
657  // Candidate patch
658  double inormPatchLow=1.0/sqrt(patchLow.sum2());
659  patchLow*=inormPatchLow;
660  size_t canonicalIdx=0;
661  if (mode==0)
662  canonicalIdx=canonicalOrientation3D(patchLow,canonicalPatch,canonicalSignature);
663  else
664  canonicalIdx=canonicalOrientation2D(patchLow,canonicalPatch,canonicalSignature);
665  selectDictionaryPatches(canonicalPatch, canonicalSignature, selectedPatchesIdx, weight);
666  bool introduceInDictionary=(selectedPatchesIdx.size()==0);
667 #ifdef DEBUG
668  std::cout << "Evaluating " << k << "," << i << "," << j << " -> selectedPatches=" << selectedPatchesIdx.size() << std::endl;
669 #endif
670  double R2=-1;
671  if (!introduceInDictionary)
672  {
673  R2=approximatePatch(canonicalPatch,selectedPatchesIdx,weight,alpha);
674 #ifdef DEBUG
675  std::cout << " R2=" << R2 << std::endl;
676 #endif
677  introduceInDictionary=(R2<R2threshold);
678  }
679  if (introduceInDictionary)
680  {
681  ++NsuccessfulPatches;
682  selfApplyGeometry(xmipp_transformation::LINEAR,patchHigh,rotationGroup[canonicalIdx],xmipp_transformation::IS_INV,xmipp_transformation::DONT_WRAP);
683 
684  dictionaryLow.push_back(canonicalPatch);
685  patchHigh*=inormPatchLow;
686  dictionaryHigh.push_back(patchHigh);
687  dictionarySignature.push_back(canonicalSignature);
688 #ifdef DEBUG
689  std::cout << " Introducing it into dictionary" << std::endl;
690 #endif
691  }
692 
693 #ifdef DEBUG
694  Vmask(k,i,j)=1;
695 #endif
696  }
697  }
698  progress_bar(k);
699  }
700  progress_bar(ZSIZE(mVlow));
701  std::cout << "Candidate patches =" << NcandidatePatches << "(" << ((double)NcandidatePatches)/Npatches*100 << "%)"
702  << " successful=" << NsuccessfulPatches << "(" << ((double)NsuccessfulPatches)/NcandidatePatches*100 << "%)" << std::endl;
704 #ifdef DEBUG
705  Vmask.write("PPPmask.vol");
706  std::cout << "Press any key\n";
707  char c; std::cin >> c;
708 #endif
709  }
710 }
void selfApplyGeometry(int Splinedegree, MultidimArray< std::complex< double > > &V1, const Matrix2D< double > &A, bool inv, bool wrap, std::complex< double > outside)
void init_progress_bar(long total)
std::vector< MultidimArray< double > > dictionaryHigh
void extractPatch(const MultidimArray< double > &V, MultidimArray< double > &patch, int k, int i, int j)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=nullptr, bool decomposeStack=true) override
doublereal * c
void sqrt(Image< double > &op)
void computeStats(double &avg, double &stddev, T &minval, T &maxval) const
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)
size_t canonicalOrientation3D(const MultidimArray< double > &patch, MultidimArray< double > &canonicalPatch, Matrix1D< double > &patchSignature)
virtual IdIteratorProxy< false > ids()
#define i
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
std::vector< Matrix1D< double > > dictionarySignature
double approximatePatch(const MultidimArray< double > &lowResolutionPatch, std::vector< size_t > &selectedPatchesIdx, std::vector< double > &weight, Matrix1D< double > &alpha)
void progress_bar(long rlen)
#define ZSIZE(v)
std::vector< Matrix2D< double > > rotationGroup
#define j
bool getValue(MDObject &mdValueOut, size_t id) const override
double sum2() const
std::vector< MultidimArray< double > > dictionaryLow
bool fileExists(const char *filename)
void selectDictionaryPatches(const MultidimArray< double > &lowResolutionPatch, Matrix1D< double > &lowResolutionPatchSignature, std::vector< size_t > &selectedPatchesIdx, std::vector< double > &weight)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
size_t canonicalOrientation2D(const MultidimArray< double > &patch, MultidimArray< double > &canonicalPatch, Matrix1D< double > &patchSignature)
Name of an image (std::string)

◆ show()

void ProgConstructPDBDictionary::show ( )
virtual

Reimplemented from ProgPDBDictionary.

Definition at line 565 of file pdb_construct_dictionary.cpp.

566 {
567  if (verbose)
568  {
569  std::cout
570  << "Input low volumes: " << fnLow << std::endl
571  << "Input high volumes: " << fnHigh << std::endl
572  << "Output rootname: " << fnRoot << std::endl
573  << "Patch size: " << patchSize << std::endl
574  << "R2 threshold: " << R2threshold << std::endl
575  ;
577  }
578 }
int verbose
Verbosity level.

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