Xmipp  v3.23.11-Nereus
ctf_correct_idr.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Carlos Oscar S. Sorzano (coss@cnb.csic.es)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 #include "ctf_correct_idr.h"
27 #include "data/projection.h"
28 
30 {
32  fn_vol = getParam("--vol");
33  mu = getDoubleParam("--mu");
34 }
35 
37 {
38  V.read(fn_vol);
39  V().setXmippOrigin();
40 }
41 
43 {
44  if (!verbose)
45  return;
47  std::cout << "Input volume: " << fn_vol << std::endl
48  << "Relaxation factor: " << mu << std::endl;
49 }
50 
52 {
54  addUsageLine("Correct CTF by using IDR");
55  addUsageLine("+This utility allows you to make reconstructions removing the effect ");
56  addUsageLine("+of the CTF. The projection images are modified according to a current ");
57  addUsageLine("+guess of the reconstruction and the CTF definition. The modified images ");
58  addUsageLine("+should be used for reconstruction which now serves as a new current guess ");
59  addUsageLine("+for a new IDR iteration.");
60  addUsageLine("+The method is fully described at http://www.ncbi.nlm.nih.gov/pubmed/15005161");
61  addUsageLine("+");
62  addUsageLine("+The program will assume that the image phase have already been corrected");
63  addUsageLine("+(otherwise the initial solution is too far from the true solution and the ");
64  addUsageLine("+algorithm does not converge).");
65  addSeeAlsoLine("ctf_phase_flip");
66  defaultComments["-i"].clear();
67  defaultComments["-i"].addComment("Metadata with images and corresponding CTFs (ctfdat)");
69  addParamsLine(" --vol <volume> : Volume with the current reconstruction");
70  addParamsLine(" [--mu <s=1.8>] : Relaxation factor");
71  addExampleLine("xmipp_ctf_correct_idr -i images.sel --vol currentGuess.vol -o idrCorrectedImages.stk");
72 }
73 
74 /* IDR correction ---------------------------------------------------------- */
75 //#define DEBUG
76 void ProgCtfCorrectIdr::processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
77 {
78  FileName fn_ctf;
79  rowIn.getValue(MDL_CTF_MODEL,fn_ctf);
80 
81  // Read current input image
82  Ireal.readApplyGeo(fnImg, rowIn);
83  int Ydim = YSIZE(Ireal());
84  int Xdim = XSIZE(Ireal());
85 
86  // Project the volume in the same direction
87  projectVolume(V(), Itheo, Ydim, Xdim, Ireal.rot(), Ireal.tilt(), Ireal.psi());
88 
89  // Copy to theo_CTF and resize
90  Itheo_CTF = Itheo();
91  Itheo_CTF.setXmippOrigin();
92  Itheo_CTF.selfWindow(FIRST_XMIPP_INDEX(2*Ydim), FIRST_XMIPP_INDEX(2*Xdim),
93  LAST_XMIPP_INDEX(2*Ydim), LAST_XMIPP_INDEX(2*Xdim));
94 
95  // Read CTF file
96  if (last_fn_ctf!=fn_ctf)
97  {
98  ctf.FilterBand = CTF;
99  ctf.ctf.read(fn_ctf);
100  ctf.ctf.enable_CTFnoise = false;
102  ctf.generateMask(Itheo_CTF);
103  ctf.correctPhase();
104  last_fn_ctf=fn_ctf;
105  }
106 
107  // Apply CTF
108  ctf.applyMaskSpace(Itheo_CTF);
109  Itheo_CTF.selfWindow(FIRST_XMIPP_INDEX(Ydim), FIRST_XMIPP_INDEX(Xdim),
110  LAST_XMIPP_INDEX(Ydim), LAST_XMIPP_INDEX(Xdim));
111 
112 #ifdef DEBUG
113 
114  Itheo.write("PPPtheo.xmp");
115  Ireal.write("PPPreal.xmp");
116 #endif
117 
118  // Apply IDR process
119  MultidimArray<double> &mItheo=Itheo();
120  const MultidimArray<double> &mIreal=Ireal();
122  DIRECT_MULTIDIM_ELEM(mItheo, n) = mu * DIRECT_MULTIDIM_ELEM(mIreal, n) +
123  (DIRECT_MULTIDIM_ELEM(mItheo, n) -
124  mu * DIRECT_MULTIDIM_ELEM(Itheo_CTF, n));
125 
126  // Save output image
127  Itheo.write(fnImgOut);
128 
129 #ifdef DEBUG
130 
131  Image<double> save;
132  save()=Itheo_CTF;
133  save.write("PPPtheo_CTF.xmp");
134  save() = Itheo() - mu * Itheo_CTF;
135  save.write("PPPdiff.xmp");
136  Itheo.write("PPPidr.xmp");
137  std::cout << "Press any key to continue\n";
138  char c;
139  std::cin >> c;
140 #endif
141 }
#define YSIZE(v)
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
Process one image.
double getDoubleParam(const char *param, int arg=0)
CTFDescription ctf
double psi(const size_t n=0) const
doublereal * c
FileName fn_vol
Reference volume.
void preProcess()
Preprocess.
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)
Name for the CTF Model (std::string)
double rot(const size_t n=0) const
int readApplyGeo(const FileName &name, const MDRow &row, const ApplyGeoParams &params=DefaultApplyGeoParams)
FourierFilter ctf
void addSeeAlsoLine(const char *seeAlso)
void read(const FileName &fn, bool disable_if_not_K=true)
Definition: ctf.cpp:1220
double tilt(const size_t n=0) const
T & getValue(MDLabel label)
double mu
Relaxation factor.
const char * getParam(const char *param, int arg=0)
#define CTF
#define XSIZE(v)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
void addExampleLine(const char *example, bool verbatim=true)
void projectVolume(FourierProjector &projector, Projection &P, int Ydim, int Xdim, double rot, double tilt, double psi, const MultidimArray< double > *ctf)
int verbose
Verbosity level.
MultidimArray< double > Itheo_CTF
Image< double > V
void readParams()
Read params.
void show() const override
#define FIRST_XMIPP_INDEX(size)
Definition: xmipp_macros.h:439
void produceSideInfo()
Produce Side information.
Definition: ctf.cpp:1392
void defineParams()
Define parameters.
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
void show()
Show parameters.
bool each_image_produces_an_output
Indicate that an output is produced for each image in the input.
void addUsageLine(const char *line, bool verbatim=false)
bool enable_CTFnoise
Enable CTFnoise part.
Definition: ctf.h:273
#define LAST_XMIPP_INDEX(size)
Definition: xmipp_macros.h:448
void generateMask(MultidimArray< double > &v)
int * n
void addParamsLine(const String &line)
void applyMaskSpace(MultidimArray< double > &v)
std::map< String, CommentList > defaultComments
Definition: xmipp_program.h:83