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

#include <nma_alignment.h>

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

Public Member Functions

 ProgNmaAlignment ()
 Empty constructor. More...
 
 ~ProgNmaAlignment ()
 Destructor. More...
 
void defineParams ()
 Define params. More...
 
void readParams ()
 Read arguments from command line. More...
 
void show ()
 Show. More...
 
FileName createDeformedPDB (int pyramidLevel) const
 
void performCompleteSearch (const FileName &fnRandom, int pyramidLevel) const
 
double performContinuousAssignment (const FileName &fnRandom, int pyramidLevel) const
 
double computeFitness (Matrix1D< double > &trial) const
 
void updateBestFit (double fitness)
 
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
 Reference atomic or pseudo-atomic structure in PDB format. More...
 
FileName fnOutDir
 Output directory. More...
 
FileName fnModeList
 File with a list of mode filenames. More...
 
double trustradius_scale
 Positive scaling factor to scale the initial trust region radius. More...
 
double sampling_rate
 Pixel size in Angstroms. More...
 
FileName fnmask
 Mask file for 2D masking of the projections of the deformed volume. More...
 
bool do_centerPDB
 Center the PDB structure. More...
 
bool projMatch
 Real-space instead of wavelet-space (default) projection matching (global matching) that is refined by local (Fourier central slice) projection matching. More...
 
double discrAngStep
 Angular sampling step for computing the reference projections for global matching. More...
 
double gaussian_DFT_sigma
 Sigma of Gaussian weigthing in Fourier space (parameter of central-slice method) More...
 
double gaussian_Real_sigma
 Sigma of Gaussian weigthing in real space for spline interpolation in Fourier space (parameter of central-slice method) More...
 
double weight_zero_freq
 Zero-frequency weight (parameter of central-slice method) More...
 
bool do_FilterPDBVol
 Low-pass filter the volume from PDB. More...
 
double cutoff_LPfilter
 Low-pass cut-off frequency. More...
 
bool useFixedGaussian
 Use pseudo-atoms instead of atoms. More...
 
double sigmaGaussian
 Gaussian standard deviation for pseudo-atoms. More...
 
int rangen
 
Matrix1D< double > parameters
 
Matrix1D< double > trial
 
Matrix1D< double > trial_best
 
Matrix1D< double > fitness_min
 
int numberOfModes
 
int imgSize
 
FileName currentImgName
 
int currentStage
 
Matrix1D< double > bestStage1
 
MetaDataVec DF_out
 
char nameTemplate [256]
 
ProgPdbConverterprogVolumeFromPDB
 
- 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 40 of file nma_alignment.h.

Constructor & Destructor Documentation

◆ ProgNmaAlignment()

ProgNmaAlignment::ProgNmaAlignment ( )

Empty constructor.

Definition at line 33 of file nma_alignment.cpp.

33  : Rerunable("") {
34  rangen = 0;
35  resume = false;
36  currentImgName = "";
38  produces_an_output = true;
40  projMatch = false;
41 }
bool projMatch
Real-space instead of wavelet-space (default) projection matching (global matching) that is refined b...
Definition: nma_alignment.h:71
ProgPdbConverter * progVolumeFromPDB
bool produces_an_output
Indicate that a unique final output is produced.
FileName currentImgName
bool each_image_produces_an_output
Indicate that an output is produced for each image in the input.
Rerunable(const FileName &fn)

◆ ~ProgNmaAlignment()

ProgNmaAlignment::~ProgNmaAlignment ( )

Destructor.

Definition at line 43 of file nma_alignment.cpp.

43  {
44  delete progVolumeFromPDB;
45 }
ProgPdbConverter * progVolumeFromPDB

Member Function Documentation

◆ computeFitness()

double ProgNmaAlignment::computeFitness ( Matrix1D< double > &  trial) const

Computes the fitness of a set of trial parameters

◆ createDeformedPDB()

FileName ProgNmaAlignment::createDeformedPDB ( int  pyramidLevel) const

Create deformed PDB

Definition at line 146 of file nma_alignment.cpp.

146  {
147  String program;
148  String arguments;
149  FileName fnRandom;
151  const char * randStr = fnRandom.c_str();
152 
153  program = "xmipp_pdb_nma_deform";
154  arguments = formatString(
155  "--pdb %s -o %s_deformedPDB.pdb --nma %s --deformations ",
156  fnPDB.c_str(), randStr, fnModeList.c_str());
157  for (size_t i = 0; i < VEC_XSIZE(trial) - 5; ++i)
158  arguments += floatToString(trial(i)) + " ";
159  runSystem(program, arguments, false);
160 
161  program = "xmipp_volume_from_pdb";
162  arguments = formatString(
163  "-i %s_deformedPDB.pdb --size %i --sampling %f -v 0", randStr,
165 
166  if (do_centerPDB)
167  arguments.append(" --centerPDB ");
168 
169  if (useFixedGaussian) {
170  arguments.append(" --intensityColumn Bfactor --fixed_Gaussian ");
171  if (sigmaGaussian >= 0)
172  arguments += formatString("%f",sigmaGaussian);
173  }
174  //else
175  //arguments +=" --poor_Gaussian"; // Otherwise, a detailed conversion of the atoms takes too long in this context
176 
177  progVolumeFromPDB->read(arguments);
179 
180  if (do_FilterPDBVol) {
181  program = "xmipp_transform_filter";
182  arguments = formatString(
183  "-i %s_deformedPDB.vol --sampling %f --fourier low_pass %f -v 0",
184  randStr, sampling_rate, cutoff_LPfilter);
185  runSystem(program, arguments, false);
186  }
187 
188  if (pyramidLevel != 0) {
189  Image<double> I;
190  FileName fnDeformed = formatString("%s_deformedPDB.vol",randStr);
191  I.read(fnDeformed);
193  I.write(fnDeformed);
194  }
195  return fnRandom;
196 }
virtual void read(int argc, const char **argv, bool reportErrors=true)
double sigmaGaussian
Gaussian standard deviation for pseudo-atoms.
Definition: nma_alignment.h:95
#define VEC_XSIZE(m)
Definition: matrix1d.h:77
virtual int tryRun()
double cutoff_LPfilter
Low-pass cut-off frequency.
Definition: nma_alignment.h:89
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)
bool do_centerPDB
Center the PDB structure.
Definition: nma_alignment.h:68
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
bool do_FilterPDBVol
Low-pass filter the volume from PDB.
Definition: nma_alignment.h:86
double sampling_rate
Pixel size in Angstroms.
Definition: nma_alignment.h:62
ProgPdbConverter * progVolumeFromPDB
char nameTemplate[256]
Matrix1D< double > trial
FileName fnOutDir
Output directory.
Definition: nma_alignment.h:53
std::string String
Definition: xmipp_strings.h:34
String formatString(const char *format,...)
FileName fnPDB
Reference atomic or pseudo-atomic structure in PDB format.
Definition: nma_alignment.h:50
bool useFixedGaussian
Use pseudo-atoms instead of atoms.
Definition: nma_alignment.h:92
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
FileName fnModeList
File with a list of mode filenames.
Definition: nma_alignment.h:56
void selfPyramidReduce(int SplineDegree, MultidimArrayGeneric &V1, int levels)

◆ createWorkFiles()

virtual void ProgNmaAlignment::createWorkFiles ( )
inlineprotectedvirtual

Reimplemented in MpiProgNMA.

Definition at line 187 of file nma_alignment.h.

187  {
189  }
virtual void createWorkFiles(bool resume, MetaData *md)

◆ defineParams()

void ProgNmaAlignment::defineParams ( )
virtual

Define params.

Reimplemented from XmippMetadataProgram.

Definition at line 48 of file nma_alignment.cpp.

48  {
49  addUsageLine("Align images with an atomic or pseudo-atomic (from EM volume) structure by computing deformation amplitudes along normal modes, three Euler angles, and two in-plane shifts");
50  addUsageLine("+See [[http://xmipp.cnb.csic.es/twiki/bin/view/Xmipp/Nma_alignment_v3][here]] for further information about the parameters of this program.");
51  defaultComments["-i"].clear();
52  defaultComments["-i"].addComment("Metadata with image filenames");
53  defaultComments["-o"].clear();
54  defaultComments["-o"].addComment("Metadata with output Euler angles, shifts, and deformation amplitudes");
56  addParamsLine(" --pdb <PDB_filename> : Reference atomic or pseudo-atomic structure in PDB format");
57  addParamsLine(" [--odir <outputDir=\".\">] : Output directory");
58  addParamsLine(" [--resume] : Resume processing");
59  addParamsLine("==Generation of the deformed reference volumes==");
60  addParamsLine(" --modes <filename> : File with a list of mode filenames");
61  addParamsLine(" [--sampling_rate <Ts=1>] : Pixel size in Angstroms");
62  addParamsLine(" [--filterVol <cutoff=15.>] : Filter the volume after deforming. If this option is used, the default cut-off is 15 A.");
63  addParamsLine(" [--centerPDB] : Center the PDB structure");
64  addParamsLine(" [--fixed_Gaussian <std=-1>] : For pseudo-atoms fixed_Gaussian must be used.");
65  addParamsLine(" : Default standard deviation <std> is read from the PDB file.");
66  addParamsLine("==Combined elastic and rigid-body alignment==");
67  addParamsLine(" [--trustradius_scale <s=1>] : Positive scaling factor to scale the initial trust region radius");
68  addParamsLine(" [--mask <m=\"\">] : 2D masking of the projections of the deformed volume");
69  addParamsLine(" [--projMatch] : Real-space instead of wavelet-space (default) projection matching (global matching) that is refined by local (Fourier central slice) projection matching");
70  addParamsLine(" :+Note that wavelet-based method needs the image size to be power of 2");
71  addParamsLine(" [--discrAngStep <ang=10>] : Angular sampling step for computing the reference projections for global matching");
72  addParamsLine(" [--gaussian_Fourier <s=0.5>] : Sigma of Gaussian weigthing in Fourier space (parameter of central-slice method)");
73  addParamsLine(" [--gaussian_Real <s=0.5>] : Sigma of Gaussian weigthing in real space for spline interpolation in Fourier space (parameter of central-slice method)");
74  addParamsLine(" [--zerofreq_weight <s=0.>] : Zero-frequency weight (parameter of central-slice method)");
75  addExampleLine("xmipp_nma_alignment -i images.sel --pdb 2tbv.pdb --modes modelist.xmd --trustradius_scale 1.2 --sampling_rate 3.2 -o output.xmd --resume");
76 }
void addExampleLine(const char *example, bool verbatim=true)
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)
std::map< String, CommentList > defaultComments
Definition: xmipp_program.h:83

◆ finishProcessing()

void ProgNmaAlignment::finishProcessing ( )
virtual

Write the final parameters.

Reimplemented from XmippMetadataProgram.

Reimplemented in MpiProgNMA.

Definition at line 140 of file nma_alignment.cpp.

140  {
142  rename(Rerunable::getFileName().c_str(), fn_out.c_str());
143 }
const FileName & getFileName() const

◆ performCompleteSearch()

void ProgNmaAlignment::performCompleteSearch ( const FileName fnRandom,
int  pyramidLevel 
) const

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 199 of file nma_alignment.cpp.

200  {
201  String program;
202  String arguments;
203  const char * randStr = fnRandom.c_str();
204 
205  // Reduce the image
206  FileName fnDown = formatString("%s_downimg.xmp", fnRandom.c_str());
207  if (pyramidLevel != 0) {
208  Image<double> I;
209  I.read(currentImgName);
211  I.write(fnDown);
212  } else
213  copyImage(currentImgName.c_str(), fnDown.c_str());
214 
215  mkdir((fnRandom+"_ref").c_str(), S_IRWXU);
216 
217  double angSampling=2*RAD2DEG(atan(1.0/((double) imgSize / pow(2.0, (double) pyramidLevel+1))));
218  angSampling=std::max(angSampling,discrAngStep);
219  program = "xmipp_angular_project_library";
220  arguments = formatString(
221  "-i %s_deformedPDB.vol -o %s_ref/ref.stk --sampling_rate %f -v 0",
222  randStr, randStr, angSampling);
223  if (projMatch)
224  arguments +=formatString(
225  " --compute_neighbors --angular_distance -1 --experimental_images %s_downimg.xmp", randStr);
226 
227  runSystem(program, arguments, false);
228 
229  String refSelStr = formatString("%s_ref/ref.doc", randStr);
230 
231  if (fnmask != "") {
232  program = "xmipp_transform_mask";
233  arguments = formatString("-i %s --mask binary_file %s", refSelStr.c_str(),
234  fnmask.c_str());
235  runSystem(program, arguments, false);
236  }
237 
238  // Perform alignment
239  String fnOut=formatString("%s_angledisc.xmd",randStr);
240  if (!projMatch) {
241  program = "xmipp_angular_discrete_assign";
242  arguments = formatString(
243  "-i %s_downimg.xmp --ref %s -o %s --psi_step 5 --max_shift_change %d --search5D -v 0",
244  randStr, refSelStr.c_str(), fnOut.c_str(), (int)round((double) imgSize / (10.0 * pow(2.0, (double) pyramidLevel))));
245  } else {
246  String refStkStr = formatString("%s_ref/ref.stk", randStr);
247  program = "xmipp_angular_projection_matching";
248  arguments = formatString(
249  "-i %s_downimg.xmp --ref %s -o %s --search5d_step 1 --search5d_shift %d -v 0",
250  randStr, refStkStr.c_str(), fnOut.c_str(), (int)round((double) imgSize / (10.0 * pow(2.0, (double) pyramidLevel))));
251  }
252  runSystem(program, arguments, false);
253  if (projMatch)
254  {
255  MetaDataVec MD;
256  MD.read(fnOut);
257  bool flip;
258  size_t id=MD.firstRowId();
259  MD.getValue(MDL_FLIP,flip,id);
260  if (flip)
261  {
262  // This is because continuous assignment does not understand flips
263 
264  double shiftX, rot, tilt, psi, newrot, newtilt, newpsi;
265  // Change sign in shiftX
266  MD.getValue(MDL_SHIFT_X,shiftX,id);
267  MD.setValue(MDL_SHIFT_X,-shiftX,id);
268 
269  // Change Euler angles
270  MD.getValue(MDL_ANGLE_ROT,rot,id);
271  MD.getValue(MDL_ANGLE_TILT,tilt,id);
272  MD.getValue(MDL_ANGLE_PSI,psi,id);
273  Euler_mirrorY(rot,tilt,psi,newrot,newtilt,newpsi);
274  MD.setValue(MDL_ANGLE_ROT,newrot,id);
275  MD.setValue(MDL_ANGLE_TILT,newtilt,id);
276  MD.setValue(MDL_ANGLE_PSI,newpsi,id);
277  MD.write(fnOut);
278  }
279  }
280 }
Rotation angle of an image (double,degrees)
void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=nullptr, bool decomposeStack=true) override
void copyImage(const FileName &source, const FileName &target)
Tilting angle of an image (double,degrees)
Shift for the image in the X axis (double)
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
void Euler_mirrorY(double rot, double tilt, double psi, double &newrot, double &newtilt, double &newpsi)
Definition: geometry.cpp:1011
Special label to be used when gathering MDs in MpiMetadataPrograms.
void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const
double discrAngStep
Angular sampling step for computing the reference projections for global matching.
Definition: nma_alignment.h:74
bool projMatch
Real-space instead of wavelet-space (default) projection matching (global matching) that is refined b...
Definition: nma_alignment.h:71
void runSystem(const String &program, const String &arguments, bool useSystem)
bool setValue(const MDObject &mdValueIn, size_t id)
size_t firstRowId() const override
FileName fnOut
Flip the image? (bool)
void max(Image< double > &op1, const Image< double > &op2)
bool getValue(MDObject &mdValueOut, size_t id) const override
int round(double x)
Definition: ap.cpp:7245
#define RAD2DEG(r)
Definition: xmipp_macros.h:320
FileName fnmask
Mask file for 2D masking of the projections of the deformed volume.
Definition: nma_alignment.h:65
std::string String
Definition: xmipp_strings.h:34
double psi(const double x)
FileName currentImgName
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)
void selfPyramidReduce(int SplineDegree, MultidimArrayGeneric &V1, int levels)

◆ performContinuousAssignment()

double ProgNmaAlignment::performContinuousAssignment ( const FileName fnRandom,
int  pyramidLevel 
) const

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 283 of file nma_alignment.cpp.

284  {
285  // Perform alignment
286  const char * randStr = fnRandom.c_str();
287  String fnResults=formatString("%s_anglecont.xmd", randStr);
288  bool costSource=true;
289  String program = "xmipp_angular_continuous_assign";
290  String arguments =
291  formatString(
292  "-i %s_angledisc.xmd --ref %s_deformedPDB.vol -o %s --gaussian_Fourier %f --gaussian_Real %f --zerofreq_weight %f -v 0",
293  randStr, randStr, fnResults.c_str(), gaussian_DFT_sigma,
295  runSystem(program, arguments, false);
296 
297  // Pick up results
298  MetaDataVec DF(fnResults);
299  MDRowVec row;
300  DF.getRow(row, DF.firstRowId());
305  trial(VEC_XSIZE(trial) - 2) *= pow(2.0, (double) pyramidLevel);
307  trial(VEC_XSIZE(trial) - 1) *= pow(2.0, (double) pyramidLevel);
308  double tempvar;
309  if (!costSource) {
310  row.getValue(MDL_MAXCC, tempvar);
311  tempvar = -tempvar;
312  } else
313  row.getValue(MDL_COST, tempvar);
314  return tempvar;
315 }
Rotation angle of an image (double,degrees)
#define VEC_XSIZE(m)
Definition: matrix1d.h:77
Tilting angle of an image (double,degrees)
double gaussian_Real_sigma
Sigma of Gaussian weigthing in real space for spline interpolation in Fourier space (parameter of cen...
Definition: nma_alignment.h:80
Shift for the image in the X axis (double)
Special label to be used when gathering MDs in MpiMetadataPrograms.
double gaussian_DFT_sigma
Sigma of Gaussian weigthing in Fourier space (parameter of central-slice method)
Definition: nma_alignment.h:77
void runSystem(const String &program, const String &arguments, bool useSystem)
T & getValue(MDLabel label)
Matrix1D< double > trial
Cost for the image (double)
Maximum cross-correlation for the image (double)
double weight_zero_freq
Zero-frequency weight (parameter of central-slice method)
Definition: nma_alignment.h:83
std::string String
Definition: xmipp_strings.h:34
String formatString(const char *format,...)
Shift for the image in the Y axis (double)

◆ preProcess()

void ProgNmaAlignment::preProcess ( )
virtual

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

Reimplemented from XmippMetadataProgram.

Definition at line 128 of file nma_alignment.cpp.

128  {
130  SF.removeDisabled();
131  numberOfModes = SF.size();
132  // Get the size of the images in the selfile
133  imgSize = xdimOut;
134  // Set the pointer of the program to this object
135  global_nma_prog = this;
136  //create some neededs files
137  createWorkFiles();
138 }
virtual void createWorkFiles()
FileName fnModeList
File with a list of mode filenames.
Definition: nma_alignment.h:56
ProgNmaAlignment * global_nma_prog

◆ processImage()

void ProgNmaAlignment::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 380 of file nma_alignment.cpp.

381  {
382  static size_t imageCounter = 0;
383  ++imageCounter;
384 
385  double rhoStart=trustradius_scale*250.;
386  double rhoEnd=trustradius_scale*50.;
387 
388  int niter=10000;
389 
390  ObjectiveFunction *of;
391 
392  int dim = numberOfModes;
393 
394  parameters.initZeros(dim + 5);
395  currentImgName = fnImg;
396  sprintf(nameTemplate, "_node%d_img%lu_XXXXXX", rangen, (long unsigned int)imageCounter);
397 
398  trial.initZeros(dim + 5);
399  trial_best.initZeros(dim + 5);
400 
402  fitness_min(0) = 1000000.0;
403 
404  currentStage = 1;
405 #ifdef DEBUG
406  std::cerr << std::endl << "DEBUG: ===== Node: " << rangen
407  <<" processing image " << fnImg <<"(" << objId << ")"
408  << " at stage: " << currentStage << std::endl;
409 #endif
410  of = new ObjFunc_nma_alignment(1, dim);
411 
412  of->xStart.setSize(dim);
413  for (int i = 0; i < dim; i++)
414  of->xStart[i] = 0.;
415 
416 #ifdef DEBUG
417  strcpy(of->name,("OF1_"+integerToString(rangen)).c_str());
418  of->setSaveFile();
419 #endif
420 
421  CONDOR(rhoStart, rhoEnd, niter, of);
422 #ifdef DEBUG
423  of->printStats();
424  FILE *ff = fopen(("res1_"+integerToString(rangen)+".xmd").c_str(),"w");
425  fprintf(ff,"%s & %i & %i & (%i) & %e \\\\\n", of->name, of->dim(), of->getNFE(), of->getNFE2(), of->valueBest);
426  fclose(ff);
427 #endif
428 
430 
431  delete of;
432 
433  currentStage = 2;
434 #ifdef DEBUG
435  std::cerr << std::endl << "DEBUG: ===== Node: " << rangen
436  <<" processing image " << fnImg <<"(" << objId << ")"
437  << " at stage: " << currentStage << std::endl;
438 #endif
439 
440  fitness_min(0) = 1000000.0;
441 
442  of = new ObjFunc_nma_alignment(1, dim);
443 
444  of->xStart.setSize(dim);
445  for (int i = 0; i < dim; i++)
446  of->xStart[i] = parameters(i);
447 #ifdef DEBUG
448  strcpy(of->name,("OF2_"+integerToString(rangen)).c_str());
449  of->setSaveFile();
450 #endif
451 
452  rhoStart=trustradius_scale*50.-1., rhoEnd=0.5;
453  CONDOR(rhoStart, rhoEnd, niter, of);
454 #ifdef DEBUG
455  of->printStats();
456  ff=fopen(("res2_"+integerToString(rangen)+".xmd").c_str(),"w");
457  fprintf(ff,"%s & %i & %i & (%i) & %e \\\\\n", of->name, of->dim(), of->getNFE(), of->getNFE2(), of->valueBest);
458  fclose(ff);
459 #endif
460 
461 #ifdef DEBUG
462  std::cout << "Best fitness = " << fitness << std::endl;
463  for (int i=0; i<dim; i++)
464  {
465  std::cout << "Best deformations = " << dd[i] << std::endl;
466  }
467 #endif
468 
469  trial = trial_best;
470 
471  for (int i = dim; i < dim + 5; i++) {
472  parameters(i - dim) = trial_best(i);
473  }
474 
475  for (int i = 0; i < dim; i++) {
476  parameters(5 + i) = trial_best(i);
477  }
478 
481 
482  writeImageParameters(fnImg);
483  delete of;
484 }
virtual int getNFE()
Matrix1D< double > trial_best
#define VEC_XSIZE(m)
Definition: matrix1d.h:77
Matrix1D< double > parameters
String integerToString(int I, int _width, char fill_with)
#define i
void setSize(int _n)
Definition: Vector.cpp:112
#define DEBUG
char nameTemplate[256]
void setSaveFile(char *b=NULL)
Matrix1D< double > trial
Matrix1D< double > bestStage1
void resize(size_t Xdim, bool copy=true)
Definition: matrix1d.h:410
void initZeros()
Definition: matrix1d.h:592
virtual int getNFE2()
virtual void writeImageParameters(const FileName &fnImg)
FileName currentImgName
double trustradius_scale
Positive scaling factor to scale the initial trust region radius.
Definition: nma_alignment.h:59
Matrix1D< double > fitness_min
fprintf(glob_prnt.io, "\)
void CONDOR(double rhoStart, double rhoEnd, int niter, ObjectiveFunction *of, int nnode)
Definition: CNLSolver.cpp:75
double fitness(double *p)
virtual void printStats(char cc=1)

◆ readParams()

void ProgNmaAlignment::readParams ( )
virtual

Read arguments from command line.

Reimplemented from XmippMetadataProgram.

Definition at line 79 of file nma_alignment.cpp.

79  {
81  fnPDB = getParam("--pdb");
82  fnOutDir = getParam("--odir");
83  Rerunable::setFileName(fnOutDir + "/nmaDone.xmd");
84  fnModeList = getParam("--modes");
85  resume = checkParam("--resume");
86  trustradius_scale = std::abs(getDoubleParam("--trustradius_scale"));
87  sampling_rate = getDoubleParam("--sampling_rate");
88  fnmask = getParam("--mask");
89  gaussian_DFT_sigma = getDoubleParam("--gaussian_Fourier");
90  gaussian_Real_sigma = getDoubleParam("--gaussian_Real");
91  weight_zero_freq = getDoubleParam("--zerofreq_weight");
92  do_centerPDB = checkParam("--centerPDB");
93  do_FilterPDBVol = checkParam("--filterVol");
94  if (do_FilterPDBVol)
95  cutoff_LPfilter = getDoubleParam("--filterVol");
96  useFixedGaussian = checkParam("--fixed_Gaussian");
97  if (useFixedGaussian)
98  sigmaGaussian = getDoubleParam("--fixed_Gaussian");
99  projMatch = checkParam("--projMatch");
100  discrAngStep = getDoubleParam("--discrAngStep");
101 }
double getDoubleParam(const char *param, int arg=0)
double sigmaGaussian
Gaussian standard deviation for pseudo-atoms.
Definition: nma_alignment.h:95
double cutoff_LPfilter
Low-pass cut-off frequency.
Definition: nma_alignment.h:89
double gaussian_Real_sigma
Sigma of Gaussian weigthing in real space for spline interpolation in Fourier space (parameter of cen...
Definition: nma_alignment.h:80
bool do_centerPDB
Center the PDB structure.
Definition: nma_alignment.h:68
void abs(Image< double > &op)
double discrAngStep
Angular sampling step for computing the reference projections for global matching.
Definition: nma_alignment.h:74
double gaussian_DFT_sigma
Sigma of Gaussian weigthing in Fourier space (parameter of central-slice method)
Definition: nma_alignment.h:77
void setFileName(const FileName &fn)
bool projMatch
Real-space instead of wavelet-space (default) projection matching (global matching) that is refined b...
Definition: nma_alignment.h:71
bool do_FilterPDBVol
Low-pass filter the volume from PDB.
Definition: nma_alignment.h:86
double sampling_rate
Pixel size in Angstroms.
Definition: nma_alignment.h:62
const char * getParam(const char *param, int arg=0)
FileName fnOutDir
Output directory.
Definition: nma_alignment.h:53
double weight_zero_freq
Zero-frequency weight (parameter of central-slice method)
Definition: nma_alignment.h:83
FileName fnmask
Mask file for 2D masking of the projections of the deformed volume.
Definition: nma_alignment.h:65
double trustradius_scale
Positive scaling factor to scale the initial trust region radius.
Definition: nma_alignment.h:59
FileName fnPDB
Reference atomic or pseudo-atomic structure in PDB format.
Definition: nma_alignment.h:50
bool checkParam(const char *param)
bool useFixedGaussian
Use pseudo-atoms instead of atoms.
Definition: nma_alignment.h:92
FileName fnModeList
File with a list of mode filenames.
Definition: nma_alignment.h:56

◆ show()

void ProgNmaAlignment::show ( )

Show.

Definition at line 104 of file nma_alignment.cpp.

104  {
106  std::cout
107  << "Output directory: " << fnOutDir << std::endl
108  << "PDB: " << fnPDB << std::endl
109  << "Resume: " << resume << std::endl
110  << "Mode list: " << fnModeList << std::endl
111  << "Trust-region scale: " << trustradius_scale << std::endl
112  << "Pixel size: " << sampling_rate << std::endl
113  << "Mask: " << fnmask << std::endl
114  << "Center PDB: " << do_centerPDB << std::endl
115  << "Filter PDB volume: " << do_FilterPDBVol << std::endl
116  << "Use pseudo-atoms: " << useFixedGaussian << std::endl
117  << "Pseudo-atom sigma: " << sigmaGaussian << std::endl
118  << "Projection matching: " << projMatch << std::endl
119  << "AngularSamplingStep: " << discrAngStep << std::endl
120  << "Gaussian Fourier: " << gaussian_DFT_sigma << std::endl
121  << "Gaussian Real: " << gaussian_Real_sigma << std::endl
122  << "Zero-frequency weight:" << weight_zero_freq << std::endl;
123 }
double sigmaGaussian
Gaussian standard deviation for pseudo-atoms.
Definition: nma_alignment.h:95
double gaussian_Real_sigma
Sigma of Gaussian weigthing in real space for spline interpolation in Fourier space (parameter of cen...
Definition: nma_alignment.h:80
bool do_centerPDB
Center the PDB structure.
Definition: nma_alignment.h:68
double discrAngStep
Angular sampling step for computing the reference projections for global matching.
Definition: nma_alignment.h:74
double gaussian_DFT_sigma
Sigma of Gaussian weigthing in Fourier space (parameter of central-slice method)
Definition: nma_alignment.h:77
bool projMatch
Real-space instead of wavelet-space (default) projection matching (global matching) that is refined b...
Definition: nma_alignment.h:71
bool do_FilterPDBVol
Low-pass filter the volume from PDB.
Definition: nma_alignment.h:86
double sampling_rate
Pixel size in Angstroms.
Definition: nma_alignment.h:62
FileName fnOutDir
Output directory.
Definition: nma_alignment.h:53
double weight_zero_freq
Zero-frequency weight (parameter of central-slice method)
Definition: nma_alignment.h:83
void show() const override
FileName fnmask
Mask file for 2D masking of the projections of the deformed volume.
Definition: nma_alignment.h:65
double trustradius_scale
Positive scaling factor to scale the initial trust region radius.
Definition: nma_alignment.h:59
FileName fnPDB
Reference atomic or pseudo-atomic structure in PDB format.
Definition: nma_alignment.h:50
bool useFixedGaussian
Use pseudo-atoms instead of atoms.
Definition: nma_alignment.h:92
FileName fnModeList
File with a list of mode filenames.
Definition: nma_alignment.h:56

◆ updateBestFit()

void ProgNmaAlignment::updateBestFit ( double  fitness)

Update the best fitness and the corresponding best trial

Definition at line 317 of file nma_alignment.cpp.

317  {
318  if (fitness < fitness_min(0)) {
319  fitness_min(0) = fitness;
320  trial_best = trial;
321  }
322 }
Matrix1D< double > trial_best
Matrix1D< double > trial
Matrix1D< double > fitness_min
double fitness(double *p)

◆ writeImageParameters()

void ProgNmaAlignment::writeImageParameters ( const FileName fnImg)
virtual

Write the parameters found for one image

Reimplemented in MpiProgNMA.

Definition at line 486 of file nma_alignment.cpp.

486  {
487  MetaDataVec md;
488  size_t objId = md.addObject();
489  md.setValue(MDL_IMAGE, fnImg, objId);
490  md.setValue(MDL_ENABLED, 1, objId);
491  md.setValue(MDL_ANGLE_ROT, parameters(0), objId);
492  md.setValue(MDL_ANGLE_TILT, parameters(1), objId);
493  md.setValue(MDL_ANGLE_PSI, parameters(2), objId);
494  md.setValue(MDL_SHIFT_X, parameters(3), objId);
495  md.setValue(MDL_SHIFT_Y, parameters(4), objId);
496 
497  int dim = numberOfModes;
498  std::vector<double> vectortemp;
499 
500  for (int j = 5; j < 5 + dim; j++) {
501  vectortemp.push_back(parameters(j));
502  }
503 
504  md.setValue(MDL_NMA, vectortemp, objId);
505  md.setValue(MDL_COST, parameters(5 + dim), objId);
506 
508 }
Rotation angle of an image (double,degrees)
Tilting angle of an image (double,degrees)
Shift for the image in the X axis (double)
Matrix1D< double > parameters
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
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> ProgNmaAlignment::bestStage1

Definition at line 127 of file nma_alignment.h.

◆ currentImgName

FileName ProgNmaAlignment::currentImgName

Definition at line 121 of file nma_alignment.h.

◆ currentStage

int ProgNmaAlignment::currentStage

Definition at line 124 of file nma_alignment.h.

◆ cutoff_LPfilter

double ProgNmaAlignment::cutoff_LPfilter

Low-pass cut-off frequency.

Definition at line 89 of file nma_alignment.h.

◆ DF_out

MetaDataVec ProgNmaAlignment::DF_out

Definition at line 130 of file nma_alignment.h.

◆ discrAngStep

double ProgNmaAlignment::discrAngStep

Angular sampling step for computing the reference projections for global matching.

Definition at line 74 of file nma_alignment.h.

◆ do_centerPDB

bool ProgNmaAlignment::do_centerPDB

Center the PDB structure.

Definition at line 68 of file nma_alignment.h.

◆ do_FilterPDBVol

bool ProgNmaAlignment::do_FilterPDBVol

Low-pass filter the volume from PDB.

Definition at line 86 of file nma_alignment.h.

◆ fitness_min

Matrix1D<double> ProgNmaAlignment::fitness_min

Definition at line 112 of file nma_alignment.h.

◆ fnmask

FileName ProgNmaAlignment::fnmask

Mask file for 2D masking of the projections of the deformed volume.

Definition at line 65 of file nma_alignment.h.

◆ fnModeList

FileName ProgNmaAlignment::fnModeList

File with a list of mode filenames.

Definition at line 56 of file nma_alignment.h.

◆ fnOutDir

FileName ProgNmaAlignment::fnOutDir

Output directory.

Definition at line 53 of file nma_alignment.h.

◆ fnPDB

FileName ProgNmaAlignment::fnPDB

Reference atomic or pseudo-atomic structure in PDB format.

Definition at line 50 of file nma_alignment.h.

◆ gaussian_DFT_sigma

double ProgNmaAlignment::gaussian_DFT_sigma

Sigma of Gaussian weigthing in Fourier space (parameter of central-slice method)

Definition at line 77 of file nma_alignment.h.

◆ gaussian_Real_sigma

double ProgNmaAlignment::gaussian_Real_sigma

Sigma of Gaussian weigthing in real space for spline interpolation in Fourier space (parameter of central-slice method)

Definition at line 80 of file nma_alignment.h.

◆ imgSize

int ProgNmaAlignment::imgSize

Definition at line 118 of file nma_alignment.h.

◆ MPIversion

bool ProgNmaAlignment::MPIversion

MPI version

Definition at line 44 of file nma_alignment.h.

◆ nameTemplate

char ProgNmaAlignment::nameTemplate[256]

Definition at line 133 of file nma_alignment.h.

◆ numberOfModes

int ProgNmaAlignment::numberOfModes

Definition at line 115 of file nma_alignment.h.

◆ parameters

Matrix1D<double> ProgNmaAlignment::parameters

Definition at line 103 of file nma_alignment.h.

◆ progVolumeFromPDB

ProgPdbConverter* ProgNmaAlignment::progVolumeFromPDB

Definition at line 136 of file nma_alignment.h.

◆ projMatch

bool ProgNmaAlignment::projMatch

Real-space instead of wavelet-space (default) projection matching (global matching) that is refined by local (Fourier central slice) projection matching.

Definition at line 71 of file nma_alignment.h.

◆ rangen

int ProgNmaAlignment::rangen

Definition at line 100 of file nma_alignment.h.

◆ resume

bool ProgNmaAlignment::resume

Resume computations

Definition at line 47 of file nma_alignment.h.

◆ sampling_rate

double ProgNmaAlignment::sampling_rate

Pixel size in Angstroms.

Definition at line 62 of file nma_alignment.h.

◆ sigmaGaussian

double ProgNmaAlignment::sigmaGaussian

Gaussian standard deviation for pseudo-atoms.

Definition at line 95 of file nma_alignment.h.

◆ trial

Matrix1D<double> ProgNmaAlignment::trial

Definition at line 106 of file nma_alignment.h.

◆ trial_best

Matrix1D<double> ProgNmaAlignment::trial_best

Definition at line 109 of file nma_alignment.h.

◆ trustradius_scale

double ProgNmaAlignment::trustradius_scale

Positive scaling factor to scale the initial trust region radius.

Definition at line 59 of file nma_alignment.h.

◆ useFixedGaussian

bool ProgNmaAlignment::useFixedGaussian

Use pseudo-atoms instead of atoms.

Definition at line 92 of file nma_alignment.h.

◆ weight_zero_freq

double ProgNmaAlignment::weight_zero_freq

Zero-frequency weight (parameter of central-slice method)

Definition at line 83 of file nma_alignment.h.


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