Xmipp  v3.23.11-Nereus
volume_structure_factor.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 "core/xmipp_program.h"
27 #include "core/xmipp_image.h"
28 #include "core/metadata_vec.h"
29 #include "core/xmipp_fftw.h"
30 
32 {
33 protected:
35  double sampling;
36 
37  void defineParams()
38  {
39  //Usage
40  addUsageLine("Calculate the structure factor and the Guinier plot of a volume");
41  //Parameters
42  addParamsLine("-i <volume> : Volume to analyze");
43  addParamsLine("[-o <structure=\"\">] : Metadata with the structure factor and the Guinier plot");
44  addParamsLine(" : If no name is given, then volume_structure.xmd");
45  addParamsLine("[--sampling <T=1>] : Sampling rate in Angstroms/pixel");
46  }
47 
48  void readParams()
49  {
50  fnVol=getParam("-i");
51  fnStructure=getParam("-o");
52  if (fnStructure=="")
53  fnStructure=fnVol.removeAllExtensions()+"_structure.xmd";
54  sampling=getDoubleParam("--sampling");
55  }
56 
57  void show()
58  {
59  std::cout
60  << "Input volume: " << fnVol << std::endl
61  << "Output structure: " << fnStructure << std::endl
62  << "Sampling: " << sampling << std::endl
63  ;
64  }
65 
66  void run()
67  {
68  show();
69 
70  Image<double> V;
71  FourierTransformer transformer;
73  MultidimArray<double> VFourierMag, spectrum;
74 
75  V.read(fnVol);
76  transformer.FourierTransform(V(),VFourier,false);
77  FFT_magnitude(VFourier,VFourierMag);
78  getSpectrum(VFourierMag,spectrum,POWER_SPECTRUM);
79 
80  MetaDataVec MDout;
82  {
83  if (i==0 || A1D_ELEM(spectrum,i)==0)
84  continue;
85  size_t id=MDout.addObject();
86  double f;
87  FFT_IDX2DIGFREQ(i,XSIZE(V()),f);
88  if (f>0.5)
89  continue;
90  f/=sampling;
91  double fA=1/f;
92  double f2=f*f;
93 
94  MDout.setValue(MDL_RESOLUTION_FREQ,f,id);
95  MDout.setValue(MDL_RESOLUTION_FREQREAL,fA,id);
96  MDout.setValue(MDL_RESOLUTION_FREQ2,f2,id);
98  double aux=0;
99  if (A1D_ELEM(spectrum,i)>0)
100  aux=log(A1D_ELEM(spectrum,i));
102  }
103  MDout.write(fnStructure);
104  }
105 };
Logarithm of the structure factor.
double getDoubleParam(const char *param, int arg=0)
#define A1D_ELEM(v, i)
void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const
FileName removeAllExtensions() const
#define FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY1D(v)
#define i
void getSpectrum(MultidimArray< double > &Min, MultidimArray< double > &spectrum, int spectrum_type)
Definition: xmipp_fftw.cpp:752
void log(Image< double > &op)
const char * getParam(const char *param, int arg=0)
Frequency in 1/A squared (double)
bool setValue(const MDObject &mdValueIn, size_t id)
size_t addObject() override
Frequency in A (double)
double * f
#define XSIZE(v)
void FourierTransform(T &v, T1 &V, bool getCopy=true)
Definition: xmipp_fftw.h:166
__device__ float FFT_IDX2DIGFREQ(int idx, int size)
Frequency in 1/A (double)
#define POWER_SPECTRUM
Definition: xmipp_fftw.h:668
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
void addUsageLine(const char *line, bool verbatim=false)
void FFT_magnitude(const MultidimArray< std::complex< double > > &v, MultidimArray< double > &mag)
Definition: xmipp_fftw.cpp:393
void addParamsLine(const String &line)