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

#include <volume_correct_bfactor.h>

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

Public Member Functions

 ProgVolumeCorrectBfactor ()
 
 ~ProgVolumeCorrectBfactor ()
 
void make_guinier_plot (MultidimArray< std::complex< double > > &m1, std::vector< fit_point2D > &guinier)
 
void apply_bfactor (MultidimArray< std::complex< double > > &FT1, double bfactor)
 
void apply_allpoints (MultidimArray< std::complex< double > > &FT1, std::vector< fit_point2D > &guinier_diff)
 
void get_snr_weights (std::vector< double > &snr)
 
void apply_snr_weights (MultidimArray< std::complex< double > > &FT1, std::vector< double > &snr)
 
void write_guinierfile (const FileName &fn_guinier, std::vector< fit_point2D > &guinierin, std::vector< fit_point2D > &guinierweighted, std::vector< fit_point2D > &guiniernew, double intercept, std::vector< fit_point2D > &guinierref)
 
void bfactor_correction (MultidimArray< double > &m1, const FileName &fn_guinier)
 
- 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 ()
 

Protected Types

enum  MODES { MODES::BFACTOR_AUTO = 1, MODES::BFACTOR_REF = 2, MODES::BFACTOR_ADHOC = 3, MODES::ALLPOINTS_REF = 4 }
 

Protected Member Functions

void show ()
 
void defineParams ()
 
void readParams ()
 
void processImage (const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
 
- Protected Member Functions inherited from XmippMetadataProgram
virtual void initComments ()
 
virtual void preProcess ()
 
virtual void postProcess ()
 
virtual bool getImageToProcess (size_t &objId, size_t &objIndex)
 
void show () const override
 
virtual void startProcessing ()
 
virtual void finishProcessing ()
 
virtual void writeOutput ()
 
virtual void showProgress ()
 
virtual void defineLabelParam ()
 
- Protected Member Functions inherited from XmippProgram
void defineCommons ()
 

Protected Attributes

double fit_minres
 
double fit_maxres
 
double apply_maxres
 
double sampling_rate
 
MODES bMode
 
int xsize
 
FileName fn_ref
 
double adhocB
 
FileName fn_fsc
 
- 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
 

Additional Inherited Members

- 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
 

Detailed Description

correct_bfactor parameters.

Definition at line 37 of file volume_correct_bfactor.h.

Member Enumeration Documentation

◆ MODES

enum ProgVolumeCorrectBfactor::MODES
strongprotected

Mode for B-factor correction Three modes are provided:

  1. automated fit according to Rosenthal and Henderson (2003)
  2. fit according to a reference map
  3. ad-hoc correction with a user-defined B-factor
Enumerator
BFACTOR_AUTO 
BFACTOR_REF 
BFACTOR_ADHOC 
ALLPOINTS_REF 

Definition at line 53 of file volume_correct_bfactor.h.

53  {
54  BFACTOR_AUTO = 1,
55  BFACTOR_REF = 2,
56  BFACTOR_ADHOC = 3,
57  ALLPOINTS_REF = 4
58  };

Constructor & Destructor Documentation

◆ ProgVolumeCorrectBfactor()

ProgVolumeCorrectBfactor::ProgVolumeCorrectBfactor ( )

◆ ~ProgVolumeCorrectBfactor()

ProgVolumeCorrectBfactor::~ProgVolumeCorrectBfactor ( )
inline

Destructor

Definition at line 87 of file volume_correct_bfactor.h.

88  { }

Member Function Documentation

◆ bfactor_correction()

void ProgVolumeCorrectBfactor::bfactor_correction ( MultidimArray< double > &  m1,
const FileName fn_guinier 
)

B-factor correction (sharpening)

Definition at line 347 of file volume_correct_bfactor.cpp.

349 {
351  FourierTransformer transformer;
352  double slope;
353  double intercept = 0.;
354  std::vector<fit_point2D> guinierin, guinierweighted, guinierref, guinierdiff;
355  std::vector<double> snr;
356 
357  // Transform
358  xsize=XSIZE(m1);
359  transformer.FourierTransform(m1, FT1, true);
360  make_guinier_plot(FT1,guinierin);
361 
362  // Get SNR weights and apply to guinier1
363  if (fn_fsc != "")
364  {
365  get_snr_weights(snr);
366  apply_snr_weights(FT1,snr);
367  make_guinier_plot(FT1,guinierweighted);
368  }
369  else
370  guinierweighted=guinierin;
371 
372  if (bMode == MODES::BFACTOR_AUTO)
373  {
374  least_squares_line_fit(guinierweighted, slope, intercept);
375  std::cerr<<" Fitted slope= "<<slope<<" intercept= "<<intercept<<std::endl;
376  adhocB = 4. * slope;
377  }
379  {
380  Image<double> ref;
381  ref.read(fn_ref);
382  ref().setXmippOrigin();
383  transformer.FourierTransform(ref(), FT2, true);
384  make_guinier_plot(FT2,guinierref);
385  guinierdiff = guinierweighted;
386  for (size_t i = 0; i < guinierdiff.size(); i++)
387  {
388  (guinierdiff[i]).y -= (guinierref[i]).y;
389  }
390  if (bMode == MODES::BFACTOR_REF)
391  {
392  least_squares_line_fit(guinierdiff, slope, intercept);
393  std::cerr<<" Fitted slope= "<<slope<<" intercept= "<<intercept<<std::endl;
394  adhocB = 4. * slope;
395  }
396  }
397 
399  {
400  // Now apply the allpoints correction
401  std::cerr<<"Adjust power spectrum to that of reference "<<std::endl;
402  apply_allpoints(FT1,guinierdiff);
403  }
404  else
405  {
406  // Now apply the B-factor
407  std::cerr<<"Applying B-factor of "<< adhocB << " squared Angstroms"<<std::endl;
408  apply_bfactor(FT1,adhocB);
409  }
410  // Now backtransform
411  transformer.inverseFourierTransform(FT1,m1);
412 
413  // Write Guinier-plot
414  std::vector<fit_point2D> guiniernew;
415  make_guinier_plot(FT1,guiniernew);
416  write_guinierfile(fn_guinier, guinierin, guinierweighted, guiniernew, intercept, guinierref);
417 }
void write_guinierfile(const FileName &fn_guinier, std::vector< fit_point2D > &guinierin, std::vector< fit_point2D > &guinierweighted, std::vector< fit_point2D > &guiniernew, double intercept, std::vector< fit_point2D > &guinierref)
void inverseFourierTransform()
Definition: xmipp_fftw.cpp:329
static double * y
#define i
void apply_allpoints(MultidimArray< std::complex< double > > &FT1, std::vector< fit_point2D > &guinier_diff)
void make_guinier_plot(MultidimArray< std::complex< double > > &m1, std::vector< fit_point2D > &guinier)
void least_squares_line_fit(const std::vector< fit_point2D > &IN_points, double &line_a, double &line_b)
Definition: geometry.cpp:212
#define XSIZE(v)
void FourierTransform(T &v, T1 &V, bool getCopy=true)
Definition: xmipp_fftw.h:166
void apply_snr_weights(MultidimArray< std::complex< double > > &FT1, std::vector< double > &snr)
void get_snr_weights(std::vector< double > &snr)
void apply_bfactor(MultidimArray< std::complex< double > > &FT1, double bfactor)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)

◆ defineParams()

void ProgVolumeCorrectBfactor::defineParams ( )
protectedvirtual

Function in which the param of each Program are defined.

Reimplemented from XmippMetadataProgram.

Definition at line 31 of file volume_correct_bfactor.cpp.

32 {
33  addUsageLine("Sharpen a volume by applying a negative B-factor");
34  addUsageLine("+The high-resolution features are enhanced, thereby correcting ");
35  addUsageLine("+the envelope functions of the microscope, detector etc. Three ");
36  addUsageLine("+modes are available:");
37  addUsageLine("+");
38  addUsageLine("+1. An automated mode based on methodology developed by [[http://www.ncbi.nlm.nih.gov/pubmed/14568533][Rosenthal and Henderson]]");
39  addUsageLine("+");
40  addUsageLine("+2. Based on the fall-off in a reference map (possibly obtained using xmipp_volume_from_pdb)");
41  addUsageLine("+");
42  addUsageLine("+3. An user-provided (ad hoc) B-factor");
43  addSeeAlsoLine("volume_from_pdb, resolution_fsc");
45  addParamsLine(" --auto : Use automated B-factor fit in flat Wilson region");
46  addParamsLine(" : Note: do not use the automated mode for maps with resolutions");
47  addParamsLine(" : lower than 12-15 Angstroms!");
48  addParamsLine(" or --ref <fn_ref> <mode=bfactorref> : Fit B-factor according to the reference ");
49  addParamsLine(" where <mode>");
50  addParamsLine(" bfactorref : Fit B-factor");
51  addParamsLine(" allpoints : Adjust power spectrum to reference");
52  addParamsLine(" or --adhoc <B> : Use a user-provided (negative) B-factor");
53  addParamsLine("== Specific parameters == ");
54  addParamsLine(" --sampling <float> : Pixel size of the input volume (in Angstroms/pixel) ");
55  addParamsLine(" --maxres <float> : High-resolution limit for B-factor correction (in Ang.) ");
56  addParamsLine(" -o <filename> : Output file Name with corrected volume ");
57  addParamsLine(" [--fit_minres+ <f=15>] : Low-resolution limit (in Ang.) for fit in --auto or --ref ");
58  addParamsLine(" [--fit_maxres+ <f=-1>] : High-resolution limit (in Ang.) for fit in --auto or --ref,");
59  addParamsLine(" : -1 means maximum resolution ");
60  addParamsLine(" [--fsc+ <fscFile=\"\">] : FSC file produced by xmipp_resolution_fsc");
61  addExampleLine("xmipp_correct_bfactor -i volume.vol -o correctedVolume.vol --auto --sampling 1.4 --maxres 10");
62  addExampleLine("To plot the Guinier file you may use:",false);
63  addExampleLine("gnuplot");
64  addExampleLine("set xlabel \"d^(-2)\"");
65  addExampleLine("plot \"correctedVolume.vol.guinier\" using 1:2 title \"log F\" with line, \"correctedVolume.vol.guinier\" using 1:4 title \"Corrected log F\"with line");
66 }
void addSeeAlsoLine(const char *seeAlso)
void addExampleLine(const char *example, bool verbatim=true)
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)

◆ processImage()

void ProgVolumeCorrectBfactor::processImage ( const FileName fnImg,
const FileName fnImgOut,
const MDRow rowIn,
MDRow rowOut 
)
protectedvirtual

Implements XmippMetadataProgram.

Definition at line 123 of file volume_correct_bfactor.cpp.

124 {
125  Image<double> vol;
126  vol.read(fnImg);
127  vol().checkDimensionWithDebug(3,__FILE__,__LINE__);
128  FileName fn_guinier = fn_out + ".guinier";
129  bfactor_correction(vol(), fn_guinier);
130  vol.write(fn_out);
131 }
void bfactor_correction(MultidimArray< double > &m1, const FileName &fn_guinier)
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)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)

◆ readParams()

void ProgVolumeCorrectBfactor::readParams ( )
protectedvirtual

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

Reimplemented from XmippMetadataProgram.

Definition at line 68 of file volume_correct_bfactor.cpp.

69 {
70  produces_an_output = true;
71 
73  if (checkParam("--ref"))
74  {
75  fn_ref= getParam("--ref");
76  String strMode=getParam("--ref",1);
77  bMode = strMode=="allpoints" ? MODES::ALLPOINTS_REF : MODES::BFACTOR_REF;
78  }
79  else if (checkParam("--adhoc"))
80  {
82  adhocB = getDoubleParam("--adhoc");
83  }
84  else if (checkParam("--auto"))
86  else
87  REPORT_ERROR(ERR_DEBUG_IMPOSIBLE, "This should not happens, review program definition");
88  sampling_rate = getDoubleParam("--sampling");
89  apply_maxres = getDoubleParam("--maxres");
90  fit_minres = getDoubleParam("--fit_minres");
91  fit_maxres = getDoubleParam("--fit_maxres");
92  fn_fsc = getParam("--fsc");
93 
94  if (fit_maxres < 0.)
96 }
double getDoubleParam(const char *param, int arg=0)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Just for debugging, situation that can&#39;t happens.
Definition: xmipp_error.h:120
const char * getParam(const char *param, int arg=0)
bool produces_an_output
Indicate that a unique final output is produced.
std::string String
Definition: xmipp_strings.h:34
bool checkParam(const char *param)

◆ show()

void ProgVolumeCorrectBfactor::show ( )
protected

Functions from XmippMetadataProgram

Definition at line 98 of file volume_correct_bfactor.cpp.

99 {
101  std::cout << "Pixel size : " << sampling_rate << " Angstrom" << std::endl;
102  std::cout << "Maximum resolution: " << apply_maxres << " Angstrom" << std::endl;
104  {
105  std::cerr<<"Fit within resolutions: " << fit_minres << " - " << fit_maxres << " Angstrom" << std::endl;
106  }
107  if (bMode == MODES::BFACTOR_REF)
108  {
109  std::cout << "Adjust B-factor according to reference "<<fn_ref<<std::endl;
110  }
111  else if (bMode == MODES::BFACTOR_ADHOC)
112  {
113  std::cout << "Apply ad-hoc B-factor of "<< adhocB <<" squared Angstroms" << std::endl;
114  }
115  else
116  {
117  std::cout << "Use automated B-factor fit (Rosenthal and Henderson, 2003) " << std::endl;
118  }
119  if (fn_fsc != "")
120  std::cout << "Use signal-to-noise weight based on "<< fn_fsc <<std::endl;
121 }
void show() const override

Member Data Documentation

◆ adhocB

double ProgVolumeCorrectBfactor::adhocB
protected

Ad hoc B-factor (for mode BFACTOR_ADHOC)

Definition at line 69 of file volume_correct_bfactor.h.

◆ apply_maxres

double ProgVolumeCorrectBfactor::apply_maxres
protected

Definition at line 42 of file volume_correct_bfactor.h.

◆ bMode

MODES ProgVolumeCorrectBfactor::bMode
protected

Definition at line 60 of file volume_correct_bfactor.h.

◆ fit_maxres

double ProgVolumeCorrectBfactor::fit_maxres
protected

Definition at line 42 of file volume_correct_bfactor.h.

◆ fit_minres

double ProgVolumeCorrectBfactor::fit_minres
protected

Low and high resolution limits for automated fit

Definition at line 42 of file volume_correct_bfactor.h.

◆ fn_fsc

FileName ProgVolumeCorrectBfactor::fn_fsc
protected

Filename for FSC curve

Definition at line 72 of file volume_correct_bfactor.h.

◆ fn_ref

FileName ProgVolumeCorrectBfactor::fn_ref
protected

Reference map file name (for mode BFACTOR_REF)

Definition at line 66 of file volume_correct_bfactor.h.

◆ sampling_rate

double ProgVolumeCorrectBfactor::sampling_rate
protected

Pixels size in Angstrom

Definition at line 44 of file volume_correct_bfactor.h.

◆ xsize

int ProgVolumeCorrectBfactor::xsize
protected

X-size of the original volume or image

Definition at line 63 of file volume_correct_bfactor.h.


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