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

#include <pdb_construct_dictionary.h>

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

Public Member Functions

virtual void defineParams ()
 
virtual void readParams ()
 
virtual void show ()
 
virtual void run ()=0
 
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 ()
 

Public Attributes

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
 

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

Generic class to handle PDB Low and High resolution dictionary

Definition at line 38 of file pdb_construct_dictionary.h.

Member Function Documentation

◆ approximatePatch()

double ProgPDBDictionary::approximatePatch ( const MultidimArray< double > &  lowResolutionPatch,
std::vector< size_t > &  selectedPatchesIdx,
std::vector< double > &  weight,
Matrix1D< double > &  alpha 
)

Approximate patch. It returns the R2 of the approximation.

Definition at line 215 of file pdb_construct_dictionary.cpp.

217 {
218  Ui.initZeros(MULTIDIM_SIZE(lowResolutionPatch),selectedPatchesIdx.size());
219 
220  // Prepare Ui
221  for (size_t j=0; j<MAT_XSIZE(Ui); ++j)
222  {
223  const double *ptr=MULTIDIM_ARRAY(dictionaryLow[selectedPatchesIdx[j]]);
224  for (size_t i=0; i<MAT_YSIZE(Ui); ++i, ++ptr)
225  MAT_ELEM(Ui,i,j)=*ptr;
226  }
228 
229  // Prepare y
230  y.resizeNoCopy(MULTIDIM_SIZE(lowResolutionPatch));
231  memcpy(&VEC_ELEM(y,0),&DIRECT_MULTIDIM_ELEM(lowResolutionPatch,0),MULTIDIM_SIZE(lowResolutionPatch)*sizeof(double));
233 
234  // Solve Least Squares problem
235  solveBySVD(UitUi,Uity,alpha,1e-6);
236 
237  // Calculate R2
238  matrixOperation_Ax(Ui,alpha,yp);
239  double diff2=0.0, norm2=0.0;
240  double ymean=y.computeMean();
242  {
243  double diff=VEC_ELEM(y,i)-VEC_ELEM(yp,i);
244  diff2+=diff*diff;
245  diff=VEC_ELEM(y,i)-ymean;
246  norm2+=diff*diff;
247  }
248  double R2=1-diff2/norm2;
249  return R2;
250 }
#define MAT_YSIZE(m)
Definition: matrix2d.h:124
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
#define MULTIDIM_SIZE(v)
#define MULTIDIM_ARRAY(v)
void matrixOperation_AtA(const Matrix2D< double > &A, Matrix2D< double > &B)
Definition: matrix2d.cpp:436
#define i
#define MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
Definition: matrix1d.h:72
double computeMean() const
Definition: matrix1d.cpp:546
#define DIRECT_MULTIDIM_ELEM(v, n)
void matrixOperation_Ax(const Matrix2D< double > &A, const Matrix1D< double > &x, Matrix1D< double > &y)
Definition: matrix2d.cpp:424
void matrixOperation_Atx(const Matrix2D< double > &A, const Matrix1D< double > &x, Matrix1D< double > &y)
Definition: matrix2d.cpp:488
#define j
std::vector< MultidimArray< double > > dictionaryLow
#define MAT_XSIZE(m)
Definition: matrix2d.h:120
void initZeros()
Definition: matrix2d.h:626
void resizeNoCopy(int Xdim)
Definition: matrix1d.h:458
Matrix2D< double > UitUi
Matrix1D< double > Uity
void solveBySVD(const Matrix2D< T > &A, const Matrix1D< T > &b, Matrix1D< double > &result, double tolerance)

◆ canonicalOrientation2D()

size_t ProgPDBDictionary::canonicalOrientation2D ( const MultidimArray< double > &  patch,
MultidimArray< double > &  canonicalPatch,
Matrix1D< double > &  patchSignature 
)

Orient canonically a patch

Definition at line 467 of file pdb_construct_dictionary.cpp.

469 {
470  patchSignature.resizeNoCopy(4);
471  size_t nmax=rotationGroup.size();
472  double bestMoment=-1e38;
473  size_t bestIdx=0;
474  for (size_t n=0; n<nmax; ++n)
475  {
476  applyGeometry(xmipp_transformation::LINEAR,auxPatch,patch,rotationGroup[n],xmipp_transformation::IS_INV,xmipp_transformation::DONT_WRAP);
477  // Calculate gradients
478  double momentX=0, momentY=0, momentXmY=0, momentXY=0;
481  {
482  double val=A2D_ELEM(auxPatch,i,j);
483  double jval=j*val;
484  double ival=i*val;
485  momentX+=jval;
486  momentY+=ival;
487  momentXmY+=jval-ival;
488  momentXY+=jval+ival;
489  }
490  double moment=momentX+momentY;
491  if (moment>bestMoment)
492  {
493  bestMoment=moment;
494  bestIdx=n;
495  canonicalPatch=auxPatch;
496  VEC_ELEM(patchSignature,0)=momentX;
497  VEC_ELEM(patchSignature,1)=momentY;
498  VEC_ELEM(patchSignature,2)=momentXmY;
499  VEC_ELEM(patchSignature,3)=momentXY;
500  }
501  }
502  patchSignature.selfNormalize();
503  return bestIdx;
504 }
int * nmax
#define A2D_ELEM(v, i, j)
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
void applyGeometry(int SplineDegree, MultidimArray< std::complex< double > > &V2, const MultidimArray< std::complex< double > > &V1, const Matrix2D< double > &A, bool inv, bool wrap, std::complex< double > outside, MultidimArray< double > *BcoeffsPtr)
void selfNormalize()
Definition: matrix1d.cpp:723
MultidimArray< double > auxPatch
#define i
#define FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
std::vector< Matrix2D< double > > rotationGroup
#define j
void resizeNoCopy(int Xdim)
Definition: matrix1d.h:458
int * n

◆ canonicalOrientation3D()

size_t ProgPDBDictionary::canonicalOrientation3D ( const MultidimArray< double > &  patch,
MultidimArray< double > &  canonicalPatch,
Matrix1D< double > &  patchSignature 
)

Orient canonically a patch

Definition at line 506 of file pdb_construct_dictionary.cpp.

508 {
509  patchSignature.resizeNoCopy(3);
510  size_t nmax=rotationGroup.size();
511  double bestMoment=-1e38;
512  size_t bestIdx=0;
513  for (size_t n=0; n<nmax; ++n)
514  {
515  applyGeometry(xmipp_transformation::LINEAR,auxPatch,patch,rotationGroup[n],xmipp_transformation::IS_INV,xmipp_transformation::DONT_WRAP);
516  // Calculate gradients
517  double momentX=0, momentY=0, momentZ=0;
520  {
521  double val=A3D_ELEM(auxPatch,k,i,j);
522  momentX+=j*val;
523  momentY+=i*val;
524  momentZ+=k*val;
525  }
526  double moment=momentX+momentY+momentZ;
527  if (moment>bestMoment)
528  {
529  bestMoment=moment;
530  bestIdx=n;
531  canonicalPatch=auxPatch;
532  XX(patchSignature)=momentX;
533  YY(patchSignature)=momentY;
534  ZZ(patchSignature)=momentZ;
535  }
536  }
537  patchSignature.selfNormalize();
538  return bestIdx;
539 }
int * nmax
void applyGeometry(int SplineDegree, MultidimArray< std::complex< double > > &V2, const MultidimArray< std::complex< double > > &V1, const Matrix2D< double > &A, bool inv, bool wrap, std::complex< double > outside, MultidimArray< double > *BcoeffsPtr)
void selfNormalize()
Definition: matrix1d.cpp:723
MultidimArray< double > auxPatch
#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
#define A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
#define XX(v)
Definition: matrix1d.h:85
std::vector< Matrix2D< double > > rotationGroup
#define j
#define YY(v)
Definition: matrix1d.h:93
void resizeNoCopy(int Xdim)
Definition: matrix1d.h:458
int * n
#define ZZ(v)
Definition: matrix1d.h:101

◆ constructRotationGroup()

void ProgPDBDictionary::constructRotationGroup ( )

Construct rotation group

Definition at line 439 of file pdb_construct_dictionary.cpp.

440 {
442  bool finished;
443  do
444  {
445  finished=true;
446  for (size_t i=0; i<rotationGroup.size(); ++i)
447  for (size_t j=0; j<rotationGroup.size(); ++j)
448  {
450  bool found=false;
451  for (size_t k=0; k<rotationGroup.size(); ++k)
452  if (rotationGroup[k].equal(B))
453  {
454  found=true;
455  break;
456  }
457  if (!found)
458  {
459  rotationGroup.push_back(B);
460  finished=false;
461  }
462  }
463  } while (!finished);
464  std::cout << "Size of rotation group=" << rotationGroup.size() << std::endl;
465 }
#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< Matrix2D< double > > rotationGroup
#define j

◆ constructRotationGroup2D()

void ProgPDBDictionary::constructRotationGroup2D ( )

Construct rotation group 2D

Definition at line 389 of file pdb_construct_dictionary.cpp.

390 {
391  Matrix2D<double> A(3,3);
392  A.initIdentity();
393  rotationGroup.push_back(A);
394 
395  A.initZeros();
396  A(0,0)=-1; A(1,1)=1; A(2,2)=1;
397  rotationGroup.push_back(A);
398 
399  A.initZeros();
400  A(0,0)=1; A(1,1)=-1; A(2,2)=1;
401  rotationGroup.push_back(A);
402 
403  A.initZeros();
404  A(0,1)=1; A(1,0)=-1; A(2,2)=1;
405  rotationGroup.push_back(A);
406 
408 }
std::vector< Matrix2D< double > > rotationGroup

◆ constructRotationGroup3D()

void ProgPDBDictionary::constructRotationGroup3D ( )

Construct rotation group 3D

Definition at line 410 of file pdb_construct_dictionary.cpp.

411 {
412  Matrix2D<double> A(4,4);
413  A.initIdentity();
414  rotationGroup.push_back(A);
415 
416  A.initZeros();
417  A(0,1)=A(2,2)=1; A(1,0)=-1; A(3,3)=1;
418  rotationGroup.push_back(A);
419 
420  A.initZeros();
421  A(2,0)=1; A(1,1)=1; A(0,2)=1; A(3,3)=1;
422  rotationGroup.push_back(A);
423 
424  A.initZeros();
425  A(0,0)=1; A(1,2)=-1; A(2,1)=1; A(3,3)=1;
426  rotationGroup.push_back(A);
427 
428  A.initZeros();
429  A(0,0)=-1; A(2,2)=1; A(1,1)=1; A(3,3)=1;
430  rotationGroup.push_back(A);
431 
432  A.initZeros();
433  A(0,0)=1; A(1,1)=-1; A(2,2)=1; A(3,3)=1;
434  rotationGroup.push_back(A);
435 
437 }
std::vector< Matrix2D< double > > rotationGroup

◆ defineParams()

void ProgPDBDictionary::defineParams ( )
virtual

Function in which the param of each Program are defined.

Reimplemented from XmippProgram.

Reimplemented in ProgConstructPDBDictionary, and ProgRestoreWithPDBDictionary.

Definition at line 35 of file pdb_construct_dictionary.cpp.

36 {
37  // Parameters
38  addParamsLine(" [--stdThreshold <s=0.25>] : Threshold on the standard deviation to include a patch");
39  addParamsLine(" [--angleThreshold <s=20>] : Threshold in degrees on the angle to consider a patch");
40  addParamsLine(" [--regularization <lambda=0.01>] : Regularization factor for the approximation phase");
41  addParamsLine(" [--iter <s=50>] : Number of iterations");
42  addParamsLine(" [--mode <m=\"3D\">] : 3D, 2Dx, 2Dy, 2Dz mode");
43 }
void addParamsLine(const String &line)

◆ extractPatch()

void ProgPDBDictionary::extractPatch ( const MultidimArray< double > &  V,
MultidimArray< double > &  patch,
int  k,
int  i,
int  j 
)

Extract Patch from volume

Definition at line 323 of file pdb_construct_dictionary.cpp.

324 {
325  if (mode==0)
327  else if (mode==1)
328  {
329  for (int kk=-patchSize_2; kk<=patchSize_2; ++kk)
330  for (int ii=-patchSize_2; ii<=patchSize_2; ++ii)
331  A2D_ELEM(patch,kk,ii)=A3D_ELEM(V,k+kk,i+ii,j);
332  }
333  else if (mode==2)
334  {
335  for (int kk=-patchSize_2; kk<=patchSize_2; ++kk)
336  for (int jj=-patchSize_2; jj<=patchSize_2; ++jj)
337  A2D_ELEM(patch,kk,jj)=A3D_ELEM(V,k+kk,i,j+jj);
338  }
339  else if (mode==3)
340  {
341  for (int ii=-patchSize_2; ii<=patchSize_2; ++ii)
342  for (int jj=-patchSize_2; jj<=patchSize_2; ++jj)
343  A2D_ELEM(patch,ii,jj)=A3D_ELEM(V,k,i+ii,j+jj);
344  }
345 }
#define A2D_ELEM(v, i, j)
#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
#define A3D_ELEM(V, k, i, j)
void window(MultidimArray< T1 > &result, int n0, int z0, int y0, int x0, int nF, int zF, int yF, int xF, T1 init_value=0) const
#define j

◆ insertPatch()

void ProgPDBDictionary::insertPatch ( MultidimArray< double > &  Vhigh,
MultidimArray< double > &  weightHigh,
const MultidimArray< double > &  patchHigh,
int  k,
int  i,
int  j,
double  R2 
)

Insert Patch into volume

Definition at line 347 of file pdb_construct_dictionary.cpp.

349 {
350  if (mode==0)
351  {
352  for (int kk=-patchSize_2; kk<=patchSize_2; ++kk)
353  for (int ii=-patchSize_2; ii<=patchSize_2; ++ii)
354  for (int jj=-patchSize_2; jj<=patchSize_2; ++jj)
355  {
356  A3D_ELEM(Vhigh,k+kk,i+ii,j+jj)+=R2*A3D_ELEM(patchHigh,kk,ii,jj);
357  A3D_ELEM(weightHigh,k+kk,i+ii,j+jj)+=R2;
358  }
359  }
360  else if (mode==1)
361  {
362  for (int kk=-patchSize_2; kk<=patchSize_2; ++kk)
363  for (int ii=-patchSize_2; ii<=patchSize_2; ++ii)
364  {
365  A3D_ELEM(Vhigh,k+kk,i+ii,j)+=R2*A2D_ELEM(patchHigh,kk,ii);
366  A3D_ELEM(weightHigh,k+kk,i+ii,j)+=R2;
367  }
368  }
369  else if (mode==2)
370  {
371  for (int kk=-patchSize_2; kk<=patchSize_2; ++kk)
372  for (int jj=-patchSize_2; jj<=patchSize_2; ++jj)
373  {
374  A3D_ELEM(Vhigh,k+kk,i,j+jj)+=R2*A2D_ELEM(patchHigh,kk,jj);
375  A3D_ELEM(weightHigh,k+kk,i,j+jj)+=R2;
376  }
377  }
378  else if (mode==3)
379  {
380  for (int ii=-patchSize_2; ii<=patchSize_2; ++ii)
381  for (int jj=-patchSize_2; jj<=patchSize_2; ++jj)
382  {
383  A3D_ELEM(Vhigh,k,i+ii,j+jj)+=R2*A2D_ELEM(patchHigh,ii,jj);
384  A3D_ELEM(weightHigh,k,i+ii,j+jj)+=R2;
385  }
386  }
387 }
#define A2D_ELEM(v, i, j)
#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
#define A3D_ELEM(V, k, i, j)
#define j

◆ loadDictionaries()

void ProgPDBDictionary::loadDictionaries ( )

Load dictionaries

Definition at line 265 of file pdb_construct_dictionary.cpp.

266 {
267  std::cout << "Loading dictionaries .." << std::endl;
268  size_t Xdim, Ydim, Zdim, Ndim;
269  FileName fnLow=fnRoot+"_low.mrcs";
270  FileName fnHigh=fnRoot+"_high.mrcs";
271  FileName fnSignature=fnRoot+"_signature.raw";
272  getImageSize(fnLow, Xdim, Ydim, Zdim, Ndim);
273  patchSize=Xdim;
274  dictionaryLow.reserve(Ndim);
275  dictionaryHigh.reserve(Ndim);
276  FILE *fhSignature=fopen(fnSignature.c_str(),"r");
277  Image<double> aux;
279  if (Zdim==1)
281  for (size_t n=0; n<Ndim; ++n)
282  {
283  aux.read(fnLow,DATA,n+1);
284  dictionaryLow.push_back(aux());
285  aux.read(fnHigh,DATA,n+1);
286  dictionaryHigh.push_back(aux());
287  size_t sizeRead=fread(MATRIX1D_ARRAY(auxSignature),sizeof(double),VEC_XSIZE(auxSignature),fhSignature);
288  if (sizeRead==VEC_XSIZE(auxSignature))
290  }
291  fclose(fhSignature);
292  if (dictionarySignature.size()!=dictionaryLow.size())
293  REPORT_ERROR(ERR_INDEX_OUTOFBOUNDS,"The dictionary is corrupted: the number of signatures does not correspond to the number of patches");
294 }
Index out of bounds.
Definition: xmipp_error.h:132
std::vector< MultidimArray< double > > dictionaryHigh
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define VEC_XSIZE(m)
Definition: matrix1d.h:77
void getImageSize(const MetaData &md, size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim, MDLabel image_label)
std::vector< Matrix1D< double > > dictionarySignature
Matrix1D< double > auxSignature
std::vector< MultidimArray< double > > dictionaryLow
#define MATRIX1D_ARRAY(v)
Definition: matrix1d.h:58
void resizeNoCopy(int Xdim)
Definition: matrix1d.h:458
int * n

◆ notInDictionary()

bool ProgPDBDictionary::notInDictionary ( const MultidimArray< double > &  candidatePatch,
MultidimArray< double > &  canonicalPatch,
Matrix1D< double > &  canonicalSignature,
size_t &  canonicalIdx 
)

True if the patch is not already in the low resolution dictionary

Definition at line 74 of file pdb_construct_dictionary.cpp.

76 {
77  if (mode==0)
78  canonicalIdx=canonicalOrientation3D(candidatePatch,canonicalPatch,canonicalSignature);
79  else
80  canonicalIdx=canonicalOrientation2D(candidatePatch,canonicalPatch,canonicalSignature);
81  size_t imax=dictionaryLow.size();
82 
83  for (size_t i=0; i<imax; ++i)
84  {
85  const Matrix1D<double> &dictSignature=dictionarySignature[i];
86  double dotProduct=0;
87  for (size_t j=0; j<VEC_XSIZE(dictSignature); ++j)
88  dotProduct+=VEC_ELEM(canonicalSignature,j)*VEC_ELEM(dictSignature,j);
89  if (dotProduct>angleThreshold)
90  {
91  const MultidimArray<double> &dictionaryPatch=dictionaryLow[i];
92  dotProduct=0;
94  dotProduct+=DIRECT_MULTIDIM_ELEM(dictionaryPatch,n)*DIRECT_MULTIDIM_ELEM(canonicalPatch,n);
95  if (dotProduct>angleThreshold)
96  return false;
97  }
98  }
99  return true;
100 }
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
#define VEC_XSIZE(m)
Definition: matrix1d.h:77
size_t canonicalOrientation3D(const MultidimArray< double > &patch, MultidimArray< double > &canonicalPatch, Matrix1D< double > &patchSignature)
#define i
std::vector< Matrix1D< double > > dictionarySignature
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
#define j
std::vector< MultidimArray< double > > dictionaryLow
T dotProduct(const Matrix1D< T > &v1, const Matrix1D< T > &v2)
Definition: matrix1d.h:1140
size_t canonicalOrientation2D(const MultidimArray< double > &patch, MultidimArray< double > &canonicalPatch, Matrix1D< double > &patchSignature)
int * n

◆ readParams()

void ProgPDBDictionary::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 XmippProgram.

Reimplemented in ProgConstructPDBDictionary, and ProgRestoreWithPDBDictionary.

Definition at line 45 of file pdb_construct_dictionary.cpp.

46 {
47  stdThreshold=getDoubleParam("--stdThreshold");
48  angleThreshold=cos(DEG2RAD(getDoubleParam("--angleThreshold")));
49  lambda=getDoubleParam("--regularization");
50  iterations=getIntParam("--iter");
51  String modeStr=getParam("--mode");
52  if (modeStr=="3D")
53  mode=0;
54  else if (modeStr=="2Dx")
55  mode=1;
56  else if (modeStr=="2Dy")
57  mode=2;
58  else if (modeStr=="2Dz")
59  mode=3;
60 }
double getDoubleParam(const char *param, int arg=0)
#define DEG2RAD(d)
Definition: xmipp_macros.h:312
const char * getParam(const char *param, int arg=0)
std::string String
Definition: xmipp_strings.h:34
int getIntParam(const char *param, int arg=0)

◆ reconstructPatch()

void ProgPDBDictionary::reconstructPatch ( size_t  idxTransf,
std::vector< size_t > &  selectedPatchesIdx,
Matrix1D< double > &  alpha,
MultidimArray< double > &  highResolutionPatch 
)

Reconstruct patch

Definition at line 252 of file pdb_construct_dictionary.cpp.

254 {
255  const Matrix2D<double> &A=rotationGroup[idxTransf];
256  for (size_t j=0; j<VEC_XSIZE(alpha); ++j)
257  {
258  applyGeometry(xmipp_transformation::LINEAR,auxPatch,dictionaryHigh[selectedPatchesIdx[j]],A,xmipp_transformation::IS_NOT_INV,xmipp_transformation::DONT_WRAP);
259  const double *ptr=MULTIDIM_ARRAY(auxPatch);
260  for (size_t n=0; n<MULTIDIM_SIZE(highResolutionPatch); ++n, ++ptr)
261  DIRECT_MULTIDIM_ELEM(highResolutionPatch,n)+=VEC_ELEM(alpha,j)*(*ptr);
262  }
263 }
std::vector< MultidimArray< double > > dictionaryHigh
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
#define VEC_XSIZE(m)
Definition: matrix1d.h:77
#define MULTIDIM_SIZE(v)
void applyGeometry(int SplineDegree, MultidimArray< std::complex< double > > &V2, const MultidimArray< std::complex< double > > &V1, const Matrix2D< double > &A, bool inv, bool wrap, std::complex< double > outside, MultidimArray< double > *BcoeffsPtr)
#define MULTIDIM_ARRAY(v)
MultidimArray< double > auxPatch
#define DIRECT_MULTIDIM_ELEM(v, n)
std::vector< Matrix2D< double > > rotationGroup
#define j
int * n

◆ run()

virtual void ProgPDBDictionary::run ( )
pure virtual

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

Reimplemented from XmippProgram.

Implemented in ProgConstructPDBDictionary, and ProgRestoreWithPDBDictionary.

◆ saveDictionaries()

void ProgPDBDictionary::saveDictionaries ( ) const

Save dictionaries

Definition at line 296 of file pdb_construct_dictionary.cpp.

297 {
298  std::cout << "Saving dictionaries ..." << std::endl;
299  size_t imax=dictionaryLow.size();
300  FileName fnLow=fnRoot+"_low.mrcs";
301  FileName fnHigh=fnRoot+"_high.mrcs";
302  FileName fnSignature=fnRoot+"_signature.raw";
303  int Zdim;
304  if (mode==0)
305  Zdim=patchSize;
306  else
307  Zdim=1;
308  createEmptyFile(fnLow,patchSize,patchSize,Zdim,imax,true);
309  createEmptyFile(fnHigh,patchSize,patchSize,Zdim,imax,true);
310  Image<double> aux;
311  FILE *fhSignature=fopen(fnSignature.c_str(),"wb");
312  for (size_t i=0; i<imax; ++i)
313  {
314  aux()=dictionaryLow[i];
315  aux.write(fnLow,i+1,true,WRITE_REPLACE);
316  aux()=dictionaryHigh[i];
317  aux.write(fnHigh,i+1,true,WRITE_REPLACE);
318  fwrite(MATRIX1D_ARRAY(dictionarySignature[i]),sizeof(double),VEC_XSIZE(dictionarySignature[i]),fhSignature);
319  }
320  fclose(fhSignature);
321 }
std::vector< MultidimArray< double > > dictionaryHigh
#define VEC_XSIZE(m)
Definition: matrix1d.h:77
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)
#define i
std::vector< Matrix1D< double > > dictionarySignature
void createEmptyFile(const FileName &filename, int xdim, int ydim, int Zdim, size_t select_img, bool isStack, int mode, int _swapWrite, const MDRowVec *md)
std::vector< MultidimArray< double > > dictionaryLow
#define MATRIX1D_ARRAY(v)
Definition: matrix1d.h:58

◆ selectDictionaryPatches()

void ProgPDBDictionary::selectDictionaryPatches ( const MultidimArray< double > &  lowResolutionPatch,
Matrix1D< double > &  lowResolutionPatchSignature,
std::vector< size_t > &  selectedPatchesIdx,
std::vector< double > &  weight 
)

Select dictionary patches for a low resolution patch

Definition at line 103 of file pdb_construct_dictionary.cpp.

105 {
106  selectedPatchesIdx.clear();
107  weight.clear();
108  size_t imax=dictionaryLow.size();
109  for (size_t i=0; i<imax; ++i)
110  {
111  const Matrix1D<double> &dictSignature=dictionarySignature[i];
112  double dotProduct=0;
113  for (size_t j=0; j<VEC_XSIZE(dictSignature); ++j)
114  dotProduct+=VEC_ELEM(lowResolutionPatchSignature,j)*VEC_ELEM(dictSignature,j);
115  if (dotProduct>angleThreshold)
116  {
117  const double *ptrDictionaryPatch=MULTIDIM_ARRAY(dictionaryLow[i]);
118  dotProduct=0;
119  FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(lowResolutionPatch)
120  dotProduct+=(*ptrDictionaryPatch++)*DIRECT_MULTIDIM_ELEM(lowResolutionPatch,n);
121  if (dotProduct>angleThreshold)
122  {
123  if (dotProduct>1)
124  dotProduct=1;
125  selectedPatchesIdx.push_back(i);
126  weight.push_back(1/dotProduct);
127  #ifdef DEBUG
128  Image<double> save;
129  save()=lowResolutionPatch;
130  save.write("PPPexperimentalPatch.vol");
132  MULTIDIM_SIZE(lowResolutionPatch)*sizeof(double));
133  save.write("PPPdictionaryPatch.vol");
134  std::cout << RAD2DEG(acos(dotProduct)) << ". Press any key" << std::endl;
135  char c; std::cin >> c;
136  #endif
137  }
138  }
139  }
140 #ifdef DEBUG
141  std::cout << "Size idx=" << selectedPatchesIdx.size() << std::endl;
142  std::cout << "Weights=";
143  for (size_t i=0; i<weight.size(); ++i)
144  std::cout << weight[i] << " ";
145  std::cout << std::endl;
146 #endif
147 }
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
#define VEC_XSIZE(m)
Definition: matrix1d.h:77
doublereal * c
#define MULTIDIM_SIZE(v)
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)
#define MULTIDIM_ARRAY(v)
#define i
std::vector< Matrix1D< double > > dictionarySignature
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
#define j
std::vector< MultidimArray< double > > dictionaryLow
T dotProduct(const Matrix1D< T > &v1, const Matrix1D< T > &v2)
Definition: matrix1d.h:1140
#define RAD2DEG(r)
Definition: xmipp_macros.h:320
int * n

◆ show()

void ProgPDBDictionary::show ( )
virtual

Reimplemented in ProgConstructPDBDictionary, and ProgRestoreWithPDBDictionary.

Definition at line 62 of file pdb_construct_dictionary.cpp.

63 {
64  if (verbose)
65  std::cout
66  << "Std threshold: " << stdThreshold << std::endl
67  << "Angle threshold: " << angleThreshold << std::endl
68  << "Iterations: " << iterations << std::endl
69  << "Regularization: " << lambda << std::endl
70  << "Mode: " << mode << std::endl
71  ;
72 }
int verbose
Verbosity level.

Member Data Documentation

◆ angleThreshold

double ProgPDBDictionary::angleThreshold

Definition at line 50 of file pdb_construct_dictionary.h.

◆ auxPatch

MultidimArray<double> ProgPDBDictionary::auxPatch

Auxiliary patch

Definition at line 72 of file pdb_construct_dictionary.h.

◆ auxSignature

Matrix1D<double> ProgPDBDictionary::auxSignature

Signature

Definition at line 75 of file pdb_construct_dictionary.h.

◆ dictionaryHigh

std::vector< MultidimArray<double> > ProgPDBDictionary::dictionaryHigh

Definition at line 63 of file pdb_construct_dictionary.h.

◆ dictionaryLow

std::vector< MultidimArray<double> > ProgPDBDictionary::dictionaryLow

Low resolution and high resolution dictionary

Definition at line 63 of file pdb_construct_dictionary.h.

◆ dictionarySignature

std::vector< Matrix1D<double> > ProgPDBDictionary::dictionarySignature

Signature dictionary

Definition at line 66 of file pdb_construct_dictionary.h.

◆ fnRoot

FileName ProgPDBDictionary::fnRoot

Dictionary rootname

Definition at line 42 of file pdb_construct_dictionary.h.

◆ iterations

int ProgPDBDictionary::iterations

Definition at line 56 of file pdb_construct_dictionary.h.

◆ lambda

double ProgPDBDictionary::lambda

Definition at line 53 of file pdb_construct_dictionary.h.

◆ mode

int ProgPDBDictionary::mode

Definition at line 59 of file pdb_construct_dictionary.h.

◆ patchSize

int ProgPDBDictionary::patchSize

Patch is of size size x size x size

Definition at line 45 of file pdb_construct_dictionary.h.

◆ patchSize_2

int ProgPDBDictionary::patchSize_2

Definition at line 80 of file pdb_construct_dictionary.h.

◆ rotationGroup

std::vector< Matrix2D<double> > ProgPDBDictionary::rotationGroup

Rotation group

Definition at line 69 of file pdb_construct_dictionary.h.

◆ stdThreshold

double ProgPDBDictionary::stdThreshold

A patch is candidate if its standard deviation is at least this factor of the total standard deviation

Definition at line 48 of file pdb_construct_dictionary.h.

◆ Ui

Matrix2D<double> ProgPDBDictionary::Ui

Definition at line 78 of file pdb_construct_dictionary.h.

◆ UitUi

Matrix2D<double> ProgPDBDictionary::UitUi

Definition at line 78 of file pdb_construct_dictionary.h.

◆ Uity

Matrix1D<double> ProgPDBDictionary::Uity

Definition at line 79 of file pdb_construct_dictionary.h.

◆ v1

Matrix1D<double> ProgPDBDictionary::v1

Definition at line 79 of file pdb_construct_dictionary.h.

◆ v2

Matrix1D<double> ProgPDBDictionary::v2

Definition at line 79 of file pdb_construct_dictionary.h.

◆ wi

Matrix1D<double> ProgPDBDictionary::wi

Definition at line 79 of file pdb_construct_dictionary.h.

◆ y

Matrix1D<double> ProgPDBDictionary::y

Definition at line 79 of file pdb_construct_dictionary.h.

◆ yp

Matrix1D<double> ProgPDBDictionary::yp

Definition at line 79 of file pdb_construct_dictionary.h.


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