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

#include <flexible_alignment.h>

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

Public Member Functions

 ProgFlexibleAlignment ()
 Empty constructor. More...
 
void defineParams ()
 Define params. More...
 
void readParams ()
 Read arguments from command line. More...
 
void show ()
 Show. More...
 
FileName createDeformedPDB () const
 
void performCompleteSearch (int pyramidLevel)
 
double performContinuousAssignment (int pyramidLevel)
 
double eval ()
 
virtual void preProcess ()
 
virtual void processImage (const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
 
virtual void finishProcessing ()
 
virtual void writeImageParameters (const FileName &fnImg)
 
- Public Member Functions inherited from XmippMetadataProgram
MetaDatagetInputMd ()
 
MetaDataVecgetOutputMd ()
 
 XmippMetadataProgram ()
 Empty constructor. More...
 
virtual int tryRead (int argc, const char **argv, bool reportErrors=true)
 
virtual void init ()
 
virtual void setup (MetaData *md, const FileName &o="", const FileName &oroot="", bool applyGeo=false, MDLabel label=MDL_IMAGE)
 
virtual ~XmippMetadataProgram ()
 
void setMode (WriteModeMetaData _mode)
 
void setupRowOut (const FileName &fnImgIn, const MDRow &rowIn, const FileName &fnImgOut, MDRow &rowOut) const
 Prepare rowout. More...
 
virtual void wait ()
 Wait for the distributor to finish. More...
 
virtual void checkPoint ()
 For very long programs, it may be needed to write checkpoints. More...
 
virtual void run ()
 Run over all images. 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)
 
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 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

bool MPIversion
 
bool resume
 
FileName fnPDB
 PDB file. More...
 
FileName fnModeList
 File zith a list of modes. More...
 
FileName fnOutDir
 Output directory. More...
 
double maxdefamp
 Maximum deformation amplitude. More...
 
double defampsampling
 Deformation sampling. More...
 
double scale_defamp
 Temporary. More...
 
double scdefamp
 Scaling factor to scale deformation amplitude. More...
 
double translsampling
 Translation sampling. More...
 
double maxtransl
 Maximum translation. More...
 
double sampling_rate
 Sampling rate. More...
 
FileName fnmask
 Mask file. More...
 
bool do_centerPDB
 Center PDB. More...
 
bool projMatch
 ProjMatch. More...
 
double minAngularSampling
 Min angular sampling rate. More...
 
double gaussian_Real_sigma
 Gaussian weight sigma in real space. More...
 
double weight_zero_freq
 Weight for zero frequency. More...
 
bool do_FilterPDBVol
 Low-pass filter the volume from PDB. More...
 
double cutoff_LPfilter
 Low-pass cut-off frequency. More...
 
bool useFixedGaussian
 Use fixed Gaussian instead of scattering factors. More...
 
double sigmaGaussian
 Fixed Gaussian standard deviation. More...
 
double costfunctionvalue
 
double costfunctionvalue_cst
 
double sigma
 Sigma. More...
 
int max_no_iter
 Max iteration number. More...
 
std::vector< std::string > modeList
 
int rangen
 
Matrix1D< double > parameters
 
Matrix1D< double > trial
 
Matrix1D< double > trial_best
 
int numberOfModes
 
int imgSize
 
FileName currentImgName
 
int currentStage
 
Matrix1D< double > bestStage1
 
MetaDataVec DF_out
 
char nameTemplate [256]
 
FileName fnDown
 
- Public Attributes inherited from XmippMetadataProgram
FileName fn_in
 Filenames of input and output Metadata. More...
 
FileName fn_out
 
FileName baseName
 
FileName pathBaseName
 
FileName oextBaseName
 
bool apply_geo
 Apply geo. More...
 
size_t ndimOut
 Output dimensions. More...
 
size_t zdimOut
 
size_t ydimOut
 
size_t xdimOut
 
DataType datatypeOut
 
size_t mdInSize
 Number of input elements. More...
 
- Public Attributes inherited from XmippProgram
bool doRun
 
bool runWithoutArgs
 
int verbose
 Verbosity level. More...
 
int debug
 

Protected Member Functions

virtual void createWorkFiles ()
 
- Protected Member Functions inherited from XmippMetadataProgram
virtual void initComments ()
 
virtual void postProcess ()
 
virtual bool getImageToProcess (size_t &objId, size_t &objIndex)
 
void show () const override
 
virtual void startProcessing ()
 
virtual void writeOutput ()
 
virtual void showProgress ()
 
virtual void defineLabelParam ()
 
- Protected Member Functions inherited from XmippProgram
void defineCommons ()
 
- Protected Member Functions inherited from Rerunable
 Rerunable (const FileName &fn)
 
virtual void createWorkFiles (bool resume, MetaData *md)
 
const FileNamegetFileName () const
 
void setFileName (const FileName &fn)
 

Additional Inherited Members

- Protected Attributes inherited from XmippMetadataProgram
WriteModeMetaData mode
 Metadata writing mode: OVERWRITE, APPEND. More...
 
FileName oext
 Output extension and root. More...
 
FileName oroot
 
MDLabel image_label
 MDLabel to be used to read/write images, usually will be MDL_IMAGE. More...
 
bool produces_an_output
 Indicate that a unique final output is produced. More...
 
bool produces_a_metadata
 Indicate that the unique final output file is a Metadata. More...
 
bool each_image_produces_an_output
 Indicate that an output is produced for each image in the input. More...
 
bool allow_apply_geo
 
bool decompose_stacks
 Input Metadata will treat a stack file as a set of images instead of a unique file. More...
 
bool delete_output_stack
 Delete previous output stack file prior to process images. More...
 
bool get_image_info
 Get the input image file dimensions to further operations. More...
 
bool save_metadata_stack
 Save the associated output metadata when output file is a stack. More...
 
bool track_origin
 Include the original input image filename in the output stack. More...
 
bool keep_input_columns
 Keep input metadata columns. More...
 
bool remove_disabled
 Remove disabled images from the input selfile. More...
 
bool allow_time_bar
 Show process time bar. More...
 
bool input_is_metadata
 Input is a metadata. More...
 
bool single_image
 Input is a single image. More...
 
bool input_is_stack
 Input is a stack. More...
 
bool output_is_stack
 Output is a stack. More...
 
bool create_empty_stackfile
 
bool delete_mdIn
 
size_t time_bar_step
 Some time bar related counters. More...
 
size_t time_bar_size
 
size_t time_bar_done
 
- 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

NMA Alignment Parameters.

Definition at line 37 of file flexible_alignment.h.

Constructor & Destructor Documentation

◆ ProgFlexibleAlignment()

ProgFlexibleAlignment::ProgFlexibleAlignment ( )

Empty constructor.

Definition at line 40 of file flexible_alignment.cpp.

40  : Rerunable("")
41 {
42  rangen = 0;
43  resume = false;
44  currentImgName = "";
46  produces_an_output = true;
47 }
bool produces_an_output
Indicate that a unique final output is produced.
bool each_image_produces_an_output
Indicate that an output is produced for each image in the input.
Rerunable(const FileName &fn)

Member Function Documentation

◆ createDeformedPDB()

FileName ProgFlexibleAlignment::createDeformedPDB ( ) const

Create deformed PDB

Definition at line 174 of file flexible_alignment.cpp.

174  {
175  String program;
176  String arguments;
177  FileName fnRandom;
179  const char *randStr = fnRandom.c_str();
180  program = "xmipp_pdb_nma_deform";
181  arguments = formatString(
182  "--pdb %s -o %s_deformedPDB.pdb --nma %s --deformations ",
183  fnPDB.c_str(), randStr, fnModeList.c_str());
184  for (size_t i = 5; i < VEC_XSIZE(trial); i++)
185  arguments += floatToString(trial(i)) + " ";
186  runSystem(program, arguments, false);
187 
188  return fnRandom;
189 }
#define VEC_XSIZE(m)
Definition: matrix1d.h:77
void initUniqueName(const char *templateStr="xmippTemp_XXXXXX", const String &fnDir="")
void runSystem(const String &program, const String &arguments, bool useSystem)
String floatToString(float F, int _width, int _prec)
#define i
FileName fnPDB
PDB file.
Matrix1D< double > trial
std::string String
Definition: xmipp_strings.h:34
String formatString(const char *format,...)
FileName fnModeList
File zith a list of modes.
FileName fnOutDir
Output directory.

◆ createWorkFiles()

virtual void ProgFlexibleAlignment::createWorkFiles ( )
inlineprotectedvirtual

Definition at line 200 of file flexible_alignment.h.

200  {
202  }
virtual void createWorkFiles(bool resume, MetaData *md)

◆ defineParams()

void ProgFlexibleAlignment::defineParams ( )
virtual

Define params.

Reimplemented from XmippMetadataProgram.

Definition at line 50 of file flexible_alignment.cpp.

50  {
52  "Compute deformation parameters according to a set of NMA modes");
53  defaultComments["-o"].clear();
54  defaultComments["-o"].addComment(
55  "Metadata with output alignment and deformations");
58  " --pdb <PDB_filename> : PDB Model to compute NMA");
59  addParamsLine(" [--odir <outputDir=\".\">] : Output directory");
60  addParamsLine(" [--resume] : Resume processing");
61  addParamsLine("==Generation of the deformed volumes==");
63  " --modes <filename> : File with a list of mode filenames");
65  " [--defampsampling <s=200>] : Deformation sampling");
67  " [--maxdefamp <s=2000>] : Maximum deformation amplitude");
69  " [--translsampling <s=2>] : Translational sampling");
71  " [--maxtransl <max=10>] : Maximum translation");
73  " [--sampling_rate <Ts=1>] : in Angstroms/pixel");
75  " [--filterVol <cutoff=15.>] : Filter the volume after deforming. Default cut-off is 15 A.");
77  " [--centerPDB] : Center the PDB structure");
79  " [--fixed_Gaussian <std=-1>] : For pseudo atoms fixed_Gaussian must be used.");
81  " : Default standard deviation <std> is read from PDB file.");
82  addParamsLine("==Angular assignment and mode detection==");
84  " [--mask <m=\"\">] : 2D Mask applied to the reference images of the deformed volume");
86  " :+Note that wavelet assignment needs the input images to be of a size power of 2");
88  " [--minAngularSampling <ang=3>] : Minimum angular sampling rate");
90  " [--gaussian_Real <s=0.5>] : Weighting sigma in Real space");
92  " [--zerofreq_weight <s=0.>] : Zero-frequency weight");
93  addParamsLine(" [--sigma <s=10>] : Sigma");
95  " [--max_iter <N=60>] : Maximum number of iterations");
97  "xmipp_nma_alignment -i images.sel --pdb 2tbv.pdb --modes modelist.xmd --sampling_rate 6.4 -o output.xmd --resume");
98  Rerunable::setFileName(fnOutDir+"/nmaDone.xmd");
99 }
void setFileName(const FileName &fn)
void addExampleLine(const char *example, bool verbatim=true)
void addUsageLine(const char *line, bool verbatim=false)
FileName fnOutDir
Output directory.
void addParamsLine(const String &line)
std::map< String, CommentList > defaultComments
Definition: xmipp_program.h:83

◆ eval()

double ProgFlexibleAlignment::eval ( )

Alignment

Definition at line 1192 of file flexible_alignment.cpp.

1192  {
1193  int pyramidLevelDisc = 1;
1194  int pyramidLevelCont = (currentStage == 1) ? 1 : 0;
1195 
1196  if (currentStage == 1) {
1197  performCompleteSearch(pyramidLevelDisc);
1198  } else {
1199  //link(currentImgName.c_str(), fnDown.c_str());
1200  }
1201  double fitness = performContinuousAssignment(pyramidLevelCont);
1202 
1203  std::cout << "Fitness" << std::endl;
1204  return fitness;
1205 }
void performCompleteSearch(int pyramidLevel)
double performContinuousAssignment(int pyramidLevel)
double fitness(double *p)

◆ finishProcessing()

void ProgFlexibleAlignment::finishProcessing ( )
virtual

Write the final parameters.

Reimplemented from XmippMetadataProgram.

Definition at line 168 of file flexible_alignment.cpp.

168  {
170  rename(Rerunable::getFileName().c_str(), fn_out.c_str());
171 }
const FileName & getFileName() const

◆ performCompleteSearch()

void ProgFlexibleAlignment::performCompleteSearch ( int  pyramidLevel)

Perform a complete search with the given image and reference volume at the given level of pyramid. Return the values in the last five positions of trial.

Definition at line 968 of file flexible_alignment.cpp.

968  {
969 
970  int dim = numberOfModes;
971  int ModMaxdeDefamp, ModpowDim, help;
972  double SinPhi, CosPhi, SinPsi, CosPsi;
973  double S_muMin = 1e30;
974  //double *cost;
975  costfunctionvalue = 0.0;
976  Matrix1D<double> Parameters(dim + 5);
977  Matrix1D<double> limit0(3), limitF(3), centerOfMass(3);
978  const char *intensityColumn = "Bfactor";
979  computePDBgeometry(fnPDB, centerOfMass, limit0, limitF, intensityColumn);
980  centerOfMass = (limit0 + limitF) / 2;
981 
982  FileName fnRandom;
984  std::string command;
985 
986  // Reduce the image
987  fnDown = formatString("%s_downimg.xmp", fnRandom.c_str());
988  if (pyramidLevel != 0) {
989  Image<double> I;
990  I.read(currentImgName);
992  I.write(fnDown);
993  }
994  Image<double> imgtemp;
995  imgtemp.read(fnDown);
996 
997  imgtemp().setXmippOrigin();
998  MultidimArray<double> P_mu_image;
999  P_mu_image.resize(imgtemp());
1000  int Xwidth = XSIZE(imgtemp());
1001  int Ywidth = YSIZE(imgtemp());
1002  double reduce_rate = 1;
1003 
1004  ModMaxdeDefamp = (int) floor(maxdefamp / defampsampling) + 1;
1005  ModpowDim = (int) pow(ModMaxdeDefamp, dim);
1006 
1007  std::vector<double> Rz1(16,0);
1008  std::vector<double> Ry(16,0);
1009  std::vector<double> Rz2(16,0);
1010  std::vector<double> R(16,0);
1011  std::vector<double> Tr(16,0);
1012 
1013  int phiSteps=360/minAngularSampling;
1014  int thetaSteps=180/minAngularSampling;
1015  int psiSteps=360/minAngularSampling;
1016  int transSteps=maxtransl/translsampling;
1017  for (int iphi = 0; iphi <= phiSteps; iphi++) {
1018  double phi=iphi*minAngularSampling;
1019  Parameters(0) = phi;
1020  trial(0) = phi;
1021  SinPhi = sin(phi / 180 * PI);
1022  CosPhi = cos(phi / 180 * PI);
1023 
1024  GetIdentitySquareMatrix(Ry.data(), 4L);
1025 
1026  double *hlp = Ry.data();
1027  *hlp = CosPhi;
1028  hlp += (std::ptrdiff_t) 2L;
1029  *hlp = -SinPhi;
1030  hlp += (std::ptrdiff_t) 6L;
1031  *hlp = SinPhi;
1032  hlp += (std::ptrdiff_t) 2L;
1033  *hlp = CosPhi;
1034 
1035  for (int itheta = 0; itheta <=thetaSteps; itheta++) {
1036  double theta=itheta*minAngularSampling;
1037  Parameters(1) = theta;
1038  trial(1) = theta;
1039 
1040  GetIdentitySquareMatrix(Rz1.data(), 4L);
1041 
1042  hlp = Rz1.data();
1043  *hlp++ = CosPhi;
1044  *hlp = SinPhi;
1045  hlp += (std::ptrdiff_t) 3L;
1046  *hlp++ = -SinPhi;
1047  *hlp = CosPhi;
1048 
1049  for (int ipsi = 0; ipsi<=psiSteps; ipsi++) {
1050  double psi=ipsi*minAngularSampling;
1051  Parameters(2) = psi;
1052  trial(2) = psi;
1053  SinPsi = sin(psi / 180 * PI);
1054  CosPsi = cos(psi / 180 * PI);
1055 
1056  GetIdentitySquareMatrix(Rz2.data(), 4L);
1057 
1058  hlp = Rz2.data();
1059  *hlp++ = CosPsi;
1060  *hlp = SinPsi;
1061  hlp += (std::ptrdiff_t) 3L;
1062  *hlp++ = -SinPsi;
1063  *hlp = CosPsi;
1064 
1065  multiply_3Matrices(Rz2.data(), Ry.data(), Rz1.data(), R.data(), 4L, 4L, 4L, 4L);
1066 
1067  for (int ix0=0; ix0<=transSteps; ix0++) {
1068  double x0=ix0*translsampling;
1069  Parameters(3) = x0 / reduce_rate;
1070  trial(3) = x0;
1071  for (int iy0=0; iy0<=transSteps; iy0++) {
1072  double y0=iy0*translsampling;
1073  Parameters(4) = y0 / reduce_rate;
1074  trial(4) = y0;
1075 
1076  GetIdentitySquareMatrix(Tr.data(), 4L);
1077  hlp = Tr.data();
1078  hlp += (std::ptrdiff_t) 3L;
1079  *hlp = -x0;
1080  hlp += (std::ptrdiff_t) 5L;
1081  *hlp = -y0;
1082 
1083  MatrixMultiply(R.data(), Tr.data(), Tr.data(), 4L, 4L, 4L);
1084 
1085  for (int i = 0; i < ModpowDim; i++) {
1086  help = i;
1087  for (int j = dim - 1; j >= 0; j--) {
1088  Parameters(j + 5) = (double) (help
1089  % ModMaxdeDefamp) * defampsampling;
1090  trial(j + 5) = (double) (help % ModMaxdeDefamp)
1091  * defampsampling;
1092  help = (int) floor(help / ModMaxdeDefamp);
1093 
1094  }
1095 
1096  ProjectionRefencePoint(Parameters, dim, R.data(), Tr.data(),
1097  P_mu_image, imgtemp(), Xwidth, Ywidth,
1098  sigma);
1099 
1100  if (costfunctionvalue < S_muMin) { //2
1101  S_muMin = costfunctionvalue;
1102  for (int k = 0; k < dim + 5; k++) {
1103  trial_best(k) = trial(k);
1104  }
1105 
1106  }
1107  std::cout << "trial" << trial << " cost="
1108  << costfunctionvalue << std::endl;
1109  std::cout << "trial_best" << trial_best
1110  << " cost_best=" << S_muMin << std::endl;
1111  }
1112  }
1113  }
1114  }
1115  }
1116 
1117  }
1118 
1119  std::cout << "trial" << trial << costfunctionvalue << std::endl;
1120  std::cout << "trial_best" << trial_best << S_muMin << std::endl;
1121  for (int i = 0; i < dim + 5; i++) {
1122  trial(i) = trial_best(i);
1123  parameters(i) = trial_best(i);
1124  }
1125 
1126  MetaDataVec DF_out_discrete;
1127  size_t id = DF_out_discrete.addObject();
1128  DF_out_discrete.setValue(MDL_IMAGE, currentImgName, id);
1129  std::vector<double> aux;
1130  aux.resize(VEC_XSIZE(parameters));
1132  aux[i] = parameters(i);
1133  DF_out_discrete.setValue(MDL_NMA, aux, id);
1134  DF_out_discrete.write("result_angular_discrete.xmd");
1135 }
#define YSIZE(v)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
void ProjectionRefencePoint(Matrix1D< double > &Parameters, int dim, double *R, double *Tr, MultidimArray< double > &proj_help_test, MultidimArray< double > &P_esp_image, int Xwidth, int Ywidth, double sigma)
__host__ __device__ float2 floor(const float2 v)
#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)
double maxtransl
Maximum translation.
void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const
void initUniqueName(const char *templateStr="xmippTemp_XXXXXX", const String &fnDir="")
double minAngularSampling
Min angular sampling rate.
Matrix1D< double > trial_best
int MatrixMultiply(double *A, double *B, double *X, long Lines, long CommonSize, long Columns)
#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
double theta
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
Definition: matrix1d.h:72
#define y0
#define x0
bool setValue(const MDObject &mdValueIn, size_t id)
size_t addObject() override
FileName fnPDB
PDB file.
Matrix1D< double > parameters
#define XSIZE(v)
void computePDBgeometry(const std::string &fnPDB, Matrix1D< double > &centerOfMass, Matrix1D< double > &limit0, Matrix1D< double > &limitF, const std::string &intensityColumn)
Definition: pdb.cpp:238
Normal mode displacements (vector double)
Matrix1D< double > trial
#define j
double psi(const double x)
String formatString(const char *format,...)
int GetIdentitySquareMatrix(double *A, long Size)
double translsampling
Translation sampling.
double maxdefamp
Maximum deformation amplitude.
int multiply_3Matrices(double *A, double *B, double *C, double *X, long Lines, long CommonSizeH, long CommonSizeW, long Columns)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
FileName fnOutDir
Output directory.
#define PI
Definition: tools.h:43
void selfPyramidReduce(int SplineDegree, MultidimArrayGeneric &V1, int levels)
Name of an image (std::string)
double defampsampling
Deformation sampling.

◆ performContinuousAssignment()

double ProgFlexibleAlignment::performContinuousAssignment ( int  pyramidLevel)

Perform a continuous search with the given image and reference volume at the given pyramid level. Return the values in the last five positions of trial.

Definition at line 1138 of file flexible_alignment.cpp.

1138  {
1139  costfunctionvalue = 0.0;
1140  costfunctionvalue_cst = 0.0;
1141 
1142  Matrix1D<double> Parameters;
1143 
1144  Parameters = trial_best;
1145 
1146  std::string command;
1147  if (pyramidLevel == 0) {
1148  // Make links
1149  FileName fnRandom;
1151  fnDown = formatString("%s_downimg.xmp", fnRandom.c_str());
1152 
1153  Image<double> I;
1154  I.read(currentImgName);
1156  I.write(fnDown);
1157  }
1158 
1159  //std::string arguments;
1160  //arguments = formatString("%s_downimg.xmp",fnRandom.c_str());
1161  Image<double> imgtemp;
1162  imgtemp.read(fnDown);
1163 
1164  imgtemp().setXmippOrigin();
1165  MultidimArray<double> P_mu_image, P_esp_image;
1166  P_esp_image = imgtemp();
1167  P_mu_image.resize(imgtemp());
1168  int Xwidth = XSIZE(imgtemp());
1169  int Ywidth = YSIZE(imgtemp());
1170  //double P_mu_image[Xwidth*Xwidth];
1171  Matrix1D<double> limit0(3), limitF(3), centerOfMass(3);
1172  const char *intensityColumn = "Bfactor";
1173  //Matrix1D<double> test=centerOfMass;
1174  computePDBgeometry(fnPDB, centerOfMass, limit0, limitF, intensityColumn);
1175 
1176  centerOfMass = (limit0 + limitF) / 2;
1177 
1178  cstregistrationcontinuous(centerOfMass, Parameters, P_mu_image, P_esp_image,
1179  Xwidth, Ywidth);
1180  /* Insert code for continious alignment */
1181 
1182  trial(3) *= pow(2.0, (double) pyramidLevel);
1183  trial(4) *= pow(2.0, (double) pyramidLevel);
1184 
1185  trial_best = trial;
1186 
1187  double outcost = costfunctionvalue_cst;
1188  return outcost;
1189 }
#define YSIZE(v)
int cstregistrationcontinuous(Matrix1D< double > &centerOfMass, Matrix1D< double > &Parameters, MultidimArray< double > &cst_P_mu_image, MultidimArray< double > &P_esp_image, size_t Xwidth, size_t Ywidth)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
void initUniqueName(const char *templateStr="xmippTemp_XXXXXX", const String &fnDir="")
Matrix1D< double > trial_best
FileName fnPDB
PDB file.
#define XSIZE(v)
void computePDBgeometry(const std::string &fnPDB, Matrix1D< double > &centerOfMass, Matrix1D< double > &limit0, Matrix1D< double > &limitF, const std::string &intensityColumn)
Definition: pdb.cpp:238
Matrix1D< double > trial
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)
FileName fnOutDir
Output directory.
void selfPyramidReduce(int SplineDegree, MultidimArrayGeneric &V1, int levels)

◆ preProcess()

void ProgFlexibleAlignment::preProcess ( )
virtual

Produce side info. An exception is thrown if any of the files is not found

Reimplemented from XmippMetadataProgram.

Definition at line 155 of file flexible_alignment.cpp.

155  {
157  numberOfModes = SF.size();
158  SF.getColumnValues(MDL_NMA_MODEFILE, modeList);
159 
160  // Get the size of the images in the selfile
161  imgSize = xdimOut;
162  // Set the pointer of the program to this object
163  global_flexible_prog = this;
164  //create some neededs files
165  createWorkFiles();
166 }
ProgFlexibleAlignment * global_flexible_prog
virtual void createWorkFiles()
std::vector< std::string > modeList
FileName fnModeList
File zith a list of modes.
File with an NMA mode.

◆ processImage()

void ProgFlexibleAlignment::processImage ( const FileName fnImg,
const FileName fnImgOut,
const MDRow rowIn,
MDRow rowOut 
)
virtual

Assign NMA and Alignment parameters to an image

Implements XmippMetadataProgram.

Definition at line 1207 of file flexible_alignment.cpp.

1208  {
1209  static size_t imageCounter = 0;
1210  ++imageCounter;
1211 
1212  int dim = numberOfModes;
1213 
1214  parameters.initZeros(dim + 5);
1215  currentImgName = fnImg;
1216  snprintf(nameTemplate, 256, "_node%d_img%ld_XXXXXX", rangen,
1217  (long int) imageCounter);
1218 
1219  trial.initZeros(dim + 5);
1220  trial_best.initZeros(dim + 5);
1221 
1222  currentStage = 1;
1223 #ifdef DEBUG
1224 
1225  std::cerr << std::endl << "DEBUG: ===== Node: " << rangen
1226  <<" processing image " << fnImg <<"(" << objId << ")"
1227  << " at stage: " << currentStage << std::endl;
1228 #endif
1229 
1230  eval(); // FIXME is this call necessary?
1232 
1233  currentStage = 2;
1234 #ifdef DEBUG
1235 
1236  std::cerr << std::endl << "DEBUG: ===== Node: " << rangen
1237  <<" processing image " << fnImg <<"(" << objId << ")"
1238  << " at stage: " << currentStage << std::endl;
1239 #endif
1240 
1241  double fitness = eval();
1242 
1243  trial = trial_best;
1245 
1248 
1249  writeImageParameters(fnImg);
1250 }
#define VEC_XSIZE(m)
Definition: matrix1d.h:77
Matrix1D< double > trial_best
virtual void writeImageParameters(const FileName &fnImg)
Matrix1D< double > parameters
void resize(size_t Xdim, bool copy=true)
Definition: matrix1d.h:410
void initZeros()
Definition: matrix1d.h:592
Matrix1D< double > trial
Matrix1D< double > bestStage1
double fitness(double *p)

◆ readParams()

void ProgFlexibleAlignment::readParams ( )
virtual

Read arguments from command line.

Reimplemented from XmippMetadataProgram.

Definition at line 102 of file flexible_alignment.cpp.

102  {
104  fnPDB = getParam("--pdb");
105  fnOutDir = getParam("--odir");
106  fnModeList = getParam("--modes");
107  resume = checkParam("--resume");
108  maxdefamp = getDoubleParam("--maxdefamp");
109  defampsampling = getDoubleParam("--defampsampling");
110  translsampling = getDoubleParam("--translsampling");
111  maxtransl = getDoubleParam("--maxtransl");
112  sampling_rate = getDoubleParam("--sampling_rate");
113  fnmask = getParam("--mask");
114  gaussian_Real_sigma = getDoubleParam("--gaussian_Real");
115  weight_zero_freq = getDoubleParam("--zerofreq_weight");
116  do_centerPDB = checkParam("--centerPDB");
117  do_FilterPDBVol = checkParam("--filterVol");
118  if (do_FilterPDBVol)
119  cutoff_LPfilter = getDoubleParam("--filterVol");
120  useFixedGaussian = checkParam("--fixed_Gaussian");
121  //if (useFixedGaussian)
122  sigmaGaussian = getDoubleParam("--fixed_Gaussian");
123  minAngularSampling = getDoubleParam("--minAngularSampling");
124  sigma = getDoubleParam("--sigma");
125  max_no_iter = getIntParam("--max_iter");
126 }
double getDoubleParam(const char *param, int arg=0)
double weight_zero_freq
Weight for zero frequency.
bool do_FilterPDBVol
Low-pass filter the volume from PDB.
double gaussian_Real_sigma
Gaussian weight sigma in real space.
FileName fnmask
Mask file.
double maxtransl
Maximum translation.
double cutoff_LPfilter
Low-pass cut-off frequency.
double minAngularSampling
Min angular sampling rate.
bool do_centerPDB
Center PDB.
const char * getParam(const char *param, int arg=0)
FileName fnPDB
PDB file.
int max_no_iter
Max iteration number.
double sigmaGaussian
Fixed Gaussian standard deviation.
double translsampling
Translation sampling.
double maxdefamp
Maximum deformation amplitude.
bool checkParam(const char *param)
FileName fnModeList
File zith a list of modes.
FileName fnOutDir
Output directory.
bool useFixedGaussian
Use fixed Gaussian instead of scattering factors.
double sampling_rate
Sampling rate.
int getIntParam(const char *param, int arg=0)
double defampsampling
Deformation sampling.

◆ show()

void ProgFlexibleAlignment::show ( )

Show.

Definition at line 129 of file flexible_alignment.cpp.

129  {
131  std::cout << "Output directory: " << fnOutDir << std::endl
132  << "PDB: " << fnPDB << std::endl
133  << "Resume: " << resume << std::endl
134  << "Mode list: " << fnModeList << std::endl
135  << "Deformation sampling: " << defampsampling << std::endl
136  << "Maximum amplitude: " << maxdefamp << std::endl
137  << "Transl. sampling: " << translsampling << std::endl
138  << "Max. Translation: " << maxtransl << std::endl
139  << "Sampling rate: " << sampling_rate << std::endl
140  << "Mask: " << fnmask << std::endl
141  << "Center PDB: " << do_centerPDB << std::endl
142  << "Filter PDB volume " << do_FilterPDBVol << std::endl
143  << "Use fixed Gaussian: " << useFixedGaussian << std::endl
144  << "Sigma of Gaussian: " << sigmaGaussian << std::endl
145  << "minAngularSampling: " << minAngularSampling << std::endl
146  << "Gaussian Real: " << gaussian_Real_sigma << std::endl
147  << "Zero-frequency weight:" << weight_zero_freq << std::endl
148  << "Sigma: " << sigma << std::endl
149  << "Max. Iter: " << max_no_iter << std::endl;
150 }
double weight_zero_freq
Weight for zero frequency.
bool do_FilterPDBVol
Low-pass filter the volume from PDB.
double gaussian_Real_sigma
Gaussian weight sigma in real space.
FileName fnmask
Mask file.
double maxtransl
Maximum translation.
double minAngularSampling
Min angular sampling rate.
bool do_centerPDB
Center PDB.
FileName fnPDB
PDB file.
int max_no_iter
Max iteration number.
double sigmaGaussian
Fixed Gaussian standard deviation.
void show() const override
double translsampling
Translation sampling.
double maxdefamp
Maximum deformation amplitude.
FileName fnModeList
File zith a list of modes.
FileName fnOutDir
Output directory.
bool useFixedGaussian
Use fixed Gaussian instead of scattering factors.
double sampling_rate
Sampling rate.
double defampsampling
Deformation sampling.

◆ writeImageParameters()

void ProgFlexibleAlignment::writeImageParameters ( const FileName fnImg)
virtual

Write the parameters found for one image

Definition at line 1252 of file flexible_alignment.cpp.

1252  {
1253 
1254  MetaDataVec md;
1255  size_t objId = md.addObject();
1256  md.setValue(MDL_IMAGE, fnImg, objId);
1257  md.setValue(MDL_ENABLED, 1, objId);
1258  md.setValue(MDL_ANGLE_ROT, parameters(0), objId);
1259  md.setValue(MDL_ANGLE_TILT, parameters(1), objId);
1260  md.setValue(MDL_ANGLE_PSI, parameters(2), objId);
1261  md.setValue(MDL_SHIFT_X, parameters(3), objId);
1262  md.setValue(MDL_SHIFT_Y, parameters(4), objId);
1263 
1264  int dim = numberOfModes;
1265  std::vector<double> vectortemp;
1266 
1267  for (int j = 5; j < 5 + dim; j++)
1268  vectortemp.push_back(parameters(j));
1269  md.setValue(MDL_NMA, vectortemp, objId);
1270  md.setValue(MDL_COST, parameters(5 + dim), objId);
1272 }
Rotation angle of an image (double,degrees)
Tilting angle of an image (double,degrees)
Shift for the image in the X axis (double)
Special label to be used when gathering MDs in MpiMetadataPrograms.
Is this image enabled? (int [-1 or 1])
const FileName & getFileName() const
bool setValue(const MDObject &mdValueIn, size_t id)
size_t addObject() override
Matrix1D< double > parameters
Cost for the image (double)
Normal mode displacements (vector double)
#define j
void append(const FileName &outFile) const
Shift for the image in the Y axis (double)
Name of an image (std::string)

Member Data Documentation

◆ bestStage1

Matrix1D<double> ProgFlexibleAlignment::bestStage1

Definition at line 147 of file flexible_alignment.h.

◆ costfunctionvalue

double ProgFlexibleAlignment::costfunctionvalue

Definition at line 107 of file flexible_alignment.h.

◆ costfunctionvalue_cst

double ProgFlexibleAlignment::costfunctionvalue_cst

Definition at line 110 of file flexible_alignment.h.

◆ currentImgName

FileName ProgFlexibleAlignment::currentImgName

Definition at line 141 of file flexible_alignment.h.

◆ currentStage

int ProgFlexibleAlignment::currentStage

Definition at line 144 of file flexible_alignment.h.

◆ cutoff_LPfilter

double ProgFlexibleAlignment::cutoff_LPfilter

Low-pass cut-off frequency.

Definition at line 98 of file flexible_alignment.h.

◆ defampsampling

double ProgFlexibleAlignment::defampsampling

Deformation sampling.

Definition at line 59 of file flexible_alignment.h.

◆ DF_out

MetaDataVec ProgFlexibleAlignment::DF_out

Definition at line 150 of file flexible_alignment.h.

◆ do_centerPDB

bool ProgFlexibleAlignment::do_centerPDB

Center PDB.

Definition at line 80 of file flexible_alignment.h.

◆ do_FilterPDBVol

bool ProgFlexibleAlignment::do_FilterPDBVol

Low-pass filter the volume from PDB.

Definition at line 95 of file flexible_alignment.h.

◆ fnDown

FileName ProgFlexibleAlignment::fnDown

Definition at line 156 of file flexible_alignment.h.

◆ fnmask

FileName ProgFlexibleAlignment::fnmask

Mask file.

Definition at line 77 of file flexible_alignment.h.

◆ fnModeList

FileName ProgFlexibleAlignment::fnModeList

File zith a list of modes.

Definition at line 50 of file flexible_alignment.h.

◆ fnOutDir

FileName ProgFlexibleAlignment::fnOutDir

Output directory.

Definition at line 53 of file flexible_alignment.h.

◆ fnPDB

FileName ProgFlexibleAlignment::fnPDB

PDB file.

Definition at line 47 of file flexible_alignment.h.

◆ gaussian_Real_sigma

double ProgFlexibleAlignment::gaussian_Real_sigma

Gaussian weight sigma in real space.

Definition at line 89 of file flexible_alignment.h.

◆ imgSize

int ProgFlexibleAlignment::imgSize

Definition at line 138 of file flexible_alignment.h.

◆ max_no_iter

int ProgFlexibleAlignment::max_no_iter

Max iteration number.

Definition at line 116 of file flexible_alignment.h.

◆ maxdefamp

double ProgFlexibleAlignment::maxdefamp

Maximum deformation amplitude.

Definition at line 56 of file flexible_alignment.h.

◆ maxtransl

double ProgFlexibleAlignment::maxtransl

Maximum translation.

Definition at line 71 of file flexible_alignment.h.

◆ minAngularSampling

double ProgFlexibleAlignment::minAngularSampling

Min angular sampling rate.

Definition at line 86 of file flexible_alignment.h.

◆ modeList

std::vector<std::string> ProgFlexibleAlignment::modeList

Definition at line 120 of file flexible_alignment.h.

◆ MPIversion

bool ProgFlexibleAlignment::MPIversion

MPI version

Definition at line 41 of file flexible_alignment.h.

◆ nameTemplate

char ProgFlexibleAlignment::nameTemplate[256]

Definition at line 153 of file flexible_alignment.h.

◆ numberOfModes

int ProgFlexibleAlignment::numberOfModes

Definition at line 135 of file flexible_alignment.h.

◆ parameters

Matrix1D<double> ProgFlexibleAlignment::parameters

Definition at line 126 of file flexible_alignment.h.

◆ projMatch

bool ProgFlexibleAlignment::projMatch

ProjMatch.

Definition at line 83 of file flexible_alignment.h.

◆ rangen

int ProgFlexibleAlignment::rangen

Definition at line 123 of file flexible_alignment.h.

◆ resume

bool ProgFlexibleAlignment::resume

Resume computations

Definition at line 44 of file flexible_alignment.h.

◆ sampling_rate

double ProgFlexibleAlignment::sampling_rate

Sampling rate.

Definition at line 74 of file flexible_alignment.h.

◆ scale_defamp

double ProgFlexibleAlignment::scale_defamp

Temporary.

Definition at line 62 of file flexible_alignment.h.

◆ scdefamp

double ProgFlexibleAlignment::scdefamp

Scaling factor to scale deformation amplitude.

Definition at line 65 of file flexible_alignment.h.

◆ sigma

double ProgFlexibleAlignment::sigma

Sigma.

Definition at line 113 of file flexible_alignment.h.

◆ sigmaGaussian

double ProgFlexibleAlignment::sigmaGaussian

Fixed Gaussian standard deviation.

Definition at line 104 of file flexible_alignment.h.

◆ translsampling

double ProgFlexibleAlignment::translsampling

Translation sampling.

Definition at line 68 of file flexible_alignment.h.

◆ trial

Matrix1D<double> ProgFlexibleAlignment::trial

Definition at line 129 of file flexible_alignment.h.

◆ trial_best

Matrix1D<double> ProgFlexibleAlignment::trial_best

Definition at line 132 of file flexible_alignment.h.

◆ useFixedGaussian

bool ProgFlexibleAlignment::useFixedGaussian

Use fixed Gaussian instead of scattering factors.

Definition at line 101 of file flexible_alignment.h.

◆ weight_zero_freq

double ProgFlexibleAlignment::weight_zero_freq

Weight for zero frequency.

Definition at line 92 of file flexible_alignment.h.


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