Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | List of all members

#include <reconstruct_art_pseudo.h>

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

Public Member Functions

void defineParams ()
 
void readParams ()
 
void show () const
 
void produceSideInfo ()
 
void run ()
 
void writePseudo ()
 
double ART_single_step (const MultidimArray< double > &Iexp, double rot, double tilt, double psi, double shiftX, double shiftY, const std::vector< double > &lambda)
 
- 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)
 
virtual void initComments ()
 
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

FileName fnDoc
 Selfile with the input images. More...
 
FileName fnPseudo
 Pseudoatom filename. More...
 
FileName fnNMA
 Selfile with the input NMAs. More...
 
FileName fnRoot
 Output filename. More...
 
double lambdaART
 Lambda. More...
 
int Nit
 Number of iterations. More...
 
double sigma
 Sigma of atoms. More...
 
double sampling
 Sampling rate. More...
 
MetaDataVec DF
 
std::vector< Matrix1D< double > > atomPosition
 
std::vector< double > atomWeight
 
Matrix1D< double > gaussianProjectionTable
 
Matrix1D< double > gaussianProjectionTable2
 
std::vector< Matrix2D< double > > NMA
 
- Public Attributes inherited from XmippProgram
bool doRun
 
bool runWithoutArgs
 
int verbose
 Verbosity level. More...
 
int debug
 

Additional Inherited Members

- Protected Member Functions inherited from XmippProgram
void defineCommons ()
 
- 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

Parameters for reconstructing with pseudoatoms.

Definition at line 41 of file reconstruct_art_pseudo.h.

Member Function Documentation

◆ ART_single_step()

double ProgARTPseudo::ART_single_step ( const MultidimArray< double > &  Iexp,
double  rot,
double  tilt,
double  psi,
double  shiftX,
double  shiftY,
const std::vector< double > &  lambda 
)

ART single step

Definition at line 367 of file reconstruct_art_pseudo.cpp.

370 {
371  MultidimArray<double> Itheo, Icorr, Idiff;
372  Itheo.initZeros(Iexp);
373  Icorr.initZeros(Iexp);
375  Euler_angles2matrix(rot, tilt, psi, Euler);
377  Euler, shiftX, shiftY, lambda, NMA, FORWARD,
379  Idiff.initZeros(Iexp);
380 
381  double mean_error=0;
383  {
384  // Compute difference image and error
385  DIRECT_A2D_ELEM(Idiff, i, j) = DIRECT_A2D_ELEM(Iexp, i, j) - DIRECT_A2D_ELEM(Itheo, i, j);
386  mean_error += DIRECT_A2D_ELEM(Idiff, i, j) * DIRECT_A2D_ELEM(Idiff, i, j);
387 
388  // Compute the correction image
389  DIRECT_A2D_ELEM(Icorr, i, j) = XMIPP_MAX(DIRECT_A2D_ELEM(Icorr, i, j), 1);
390  DIRECT_A2D_ELEM(Icorr, i, j) =
391  lambdaART * DIRECT_A2D_ELEM(Idiff, i, j) / DIRECT_A2D_ELEM(Icorr, i, j);
392  }
393  mean_error /= YXSIZE(Iexp);
394 
396  Euler, shiftX, shiftY, lambda, NMA, BACKWARD,
398  return mean_error;
399 }
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
constexpr int BACKWARD
#define FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY2D(m)
void Euler_angles2matrix(T alpha, T beta, T gamma, Matrix2D< T > &A, bool homogeneous)
Definition: geometry.cpp:624
#define DIRECT_A2D_ELEM(v, i, j)
Matrix1D< double > gaussianProjectionTable
void project_Pseudo(const std::vector< Matrix1D< double > > &atomPosition, std::vector< double > &atomWeight, double sigma, MultidimArray< double > &proj, MultidimArray< double > &norm_proj, Matrix2D< double > &Euler, double shiftX, double shiftY, const std::vector< double > &lambda, const std::vector< Matrix2D< double > > &NMA, int direction, const Matrix1D< double > &gaussianProjectionTable, const Matrix1D< double > &gaussianProjectionTable2)
constexpr int FORWARD
double sigma
Sigma of atoms.
#define i
double * lambda
std::vector< double > atomWeight
Definition: euler.h:39
std::vector< Matrix2D< double > > NMA
double lambdaART
Lambda.
Matrix1D< double > gaussianProjectionTable2
#define j
double psi(const double x)
void initZeros(const MultidimArray< T1 > &op)
#define YXSIZE(v)
std::vector< Matrix1D< double > > atomPosition

◆ defineParams()

void ProgARTPseudo::defineParams ( )
virtual

Define parameters

Reimplemented from XmippProgram.

Definition at line 191 of file reconstruct_art_pseudo.cpp.

192 {
193  addUsageLine("Generate 3D reconstructions from projections using ART on pseudoatoms.");
194  addUsageLine("+This program reconstructs based on irregular grids given by pseudo atomic structures. ");
195  addUsageLine("+In case of regular grids, please refer to other programs as reconstruct_art ");
196  addUsageLine("+or reconstruct_fourier. Optionally, a deformation file generated by Nodal Mode ");
197  addUsageLine("+Alignment (NMA) can be passed with --nma parameter.");
198 
199  addSeeAlsoLine("volume_to_pseudoatoms, nma_alignment");
200 
201  addParamsLine(" -i <md_file> : Metadata file with input projections");
202  addParamsLine(" --oroot <rootname> : Output rootname");
203  addParamsLine(" alias -o;");
204  addParamsLine(" --pseudo <pseudofile> : Pseudo atomic structure (PDB format)");
205  addParamsLine(" alias -p;");
206  addParamsLine(" [--sigma <s=-1>] : Pseudoatom sigma. By default, from pseudo file");
207  addParamsLine(" [--sampling_rate <Ts=1>] : Pixel size (Angstrom)");
208  addParamsLine(" alias -s;");
209  addParamsLine(" [-l <lambda=0.1>] : Relaxation factor");
210  addParamsLine(" [-n <N=1>] : Number of iterations");
211  addParamsLine(" [--nma <selfile=\"\">] : Selfile with NMA");
212 
213  addExampleLine("Reconstruct with NMA file and relaxation factor of 0.2:", false);
214  addExampleLine("xmipp_reconstruct_art_pseudo -i projections.xmd -o art_rec --nma nmafile.xmd -l 0.2");
215 }
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)

◆ produceSideInfo()

void ProgARTPseudo::produceSideInfo ( )

Produce side info

Definition at line 229 of file reconstruct_art_pseudo.cpp.

230 {
231  DF.read(fnDoc);
232  std::ifstream fhPseudo;
233  fhPseudo.open(fnPseudo.c_str());
234  if (!fhPseudo)
236  while (!fhPseudo.eof())
237  {
238  std::string line;
239  getline(fhPseudo, line);
240  if (line.length() == 0)
241  continue;
242  if (line.substr(7,13)=="fixedGaussian" && sigma<0)
243  {
244  std::vector < std::string> results;
245  splitString(line," ",results);
246  sigma=textToFloat(results[2]);
247  sigma/=sampling;
248  }
249  else if (line.substr(0,4)=="ATOM")
250  {
251  Matrix1D<double> v(3);
252  v(0)=textToFloat(line.substr(30,8));
253  v(1)=textToFloat(line.substr(38,8));
254  v(2)=textToFloat(line.substr(46,8));
255  v/=sampling;
256  atomPosition.push_back(v);
257  atomWeight.push_back(0);
258  }
259  }
260  fhPseudo.close();
261 
262  double sigma4=4*sigma;
263  gaussianProjectionTable.resize(CEIL(sigma4*sqrt(2)*1000));
269 
270  // NMA
271  if (!fnNMA.empty())
272  {
273  MetaDataVec DFNMA(fnNMA);
274  DFNMA.removeDisabled();
275  for (size_t objId : DFNMA.ids())
276  {
278  mode.initZeros(atomPosition.size(),3);
279  FileName fnMode;
280  DFNMA.getValue( MDL_NMA_MODEFILE, fnMode,objId);
281  mode.read(fnMode);
282  NMA.push_back(mode);
283  }
284  }
285 }
void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=nullptr, bool decomposeStack=true) override
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void sqrt(Image< double > &op)
Matrix1D< double > gaussianProjectionTable
double sigma
Sigma of atoms.
#define i
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
Definition: matrix1d.h:72
#define CEIL(x)
Definition: xmipp_macros.h:225
float textToFloat(const char *str)
std::vector< double > atomWeight
int splitString(const String &input, const String &delimiter, StringVector &results, bool includeEmpties)
double sampling
Sampling rate.
void resize(size_t Xdim, bool copy=true)
Definition: matrix1d.h:410
File or directory does not exist.
Definition: xmipp_error.h:136
std::vector< Matrix2D< double > > NMA
void mode
Matrix1D< double > gaussianProjectionTable2
FileName fnDoc
Selfile with the input images.
void read(const FileName &fn)
Definition: matrix2d.cpp:101
FileName fnPseudo
Pseudoatom filename.
void initZeros()
Definition: matrix2d.h:626
File with an NMA mode.
FileName fnNMA
Selfile with the input NMAs.
std::vector< Matrix1D< double > > atomPosition
double gaussian1D(double x, double sigma, double mu)

◆ readParams()

void ProgARTPseudo::readParams ( )
virtual

Read parameters from command line.

Reimplemented from XmippProgram.

Definition at line 217 of file reconstruct_art_pseudo.cpp.

218 {
219  fnDoc = getParam("-i");
220  fnPseudo = getParam("--pseudo");
221  fnRoot = getParam("--oroot");
222  lambdaART = getDoubleParam("-l");
223  Nit = getIntParam("-n");
224  sigma = getDoubleParam("--sigma");
225  fnNMA = getParam("--nma");
226  sampling = getDoubleParam("--sampling_rate");
227 }
double getDoubleParam(const char *param, int arg=0)
int Nit
Number of iterations.
double sigma
Sigma of atoms.
const char * getParam(const char *param, int arg=0)
double sampling
Sampling rate.
double lambdaART
Lambda.
FileName fnRoot
Output filename.
FileName fnDoc
Selfile with the input images.
FileName fnPseudo
Pseudoatom filename.
int getIntParam(const char *param, int arg=0)
FileName fnNMA
Selfile with the input NMAs.

◆ run()

void ProgARTPseudo::run ( )
virtual

Run

Reimplemented from XmippProgram.

Definition at line 287 of file reconstruct_art_pseudo.cpp.

288 {
289  show();
290  produceSideInfo();
291  Image<double> Iexp;
292  for (int it=0; it<Nit; it++)
293  {
294  double itError=0;
295  for (size_t objId : DF.ids())
296  {
297  FileName fnExp;
298  DF.getValue( MDL_IMAGE, fnExp,objId);
299  double rot;
300  DF.getValue( MDL_ANGLE_ROT, rot,objId);
301  double tilt;
302  DF.getValue( MDL_ANGLE_TILT, tilt,objId);
303  double psi;
304  DF.getValue( MDL_ANGLE_PSI, psi,objId);
305  double shiftX;
306  DF.getValue( MDL_SHIFT_X, shiftX,objId);
307  double shiftY;
308  DF.getValue( MDL_SHIFT_Y, shiftY,objId);
309  std::vector<double> lambda;
310  if (NMA.size()>0)
311  DF.getValue( MDL_NMA, lambda,objId);
312 
313  Iexp.read(fnExp);
314  Iexp().setXmippOrigin();
315  itError+=ART_single_step(Iexp(),rot,tilt,psi,-shiftX,-shiftY,lambda);
316  }
317  if (DF.size()>0)
318  itError/=DF.size();
319  std::cerr << "Error at iteration " << it << " = " << itError << std::endl;
320  }
321  writePseudo();
322 }
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.
int Nit
Number of iterations.
virtual IdIteratorProxy< false > ids()
size_t size() const override
double * lambda
Normal mode displacements (vector double)
std::vector< Matrix2D< double > > NMA
bool getValue(MDObject &mdValueOut, size_t id) const override
double psi(const double x)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
Shift for the image in the Y axis (double)
Name of an image (std::string)
double ART_single_step(const MultidimArray< double > &Iexp, double rot, double tilt, double psi, double shiftX, double shiftY, const std::vector< double > &lambda)

◆ show()

void ProgARTPseudo::show ( ) const
virtual

Show parameters

Reimplemented from XmippProgram.

Definition at line 171 of file reconstruct_art_pseudo.cpp.

172 {
173  if (verbose > 0)
174  {
175  std::cout << " =======================================================" << std::endl;
176  std::cout << " ART reconstruction method using pseudo atomic structure" << std::endl;
177  std::cout << " =======================================================" << std::endl;
178  std::cout << "Input images: " << fnDoc << std::endl;
179  std::cout << "Pseudoatoms: " << fnPseudo << std::endl;
180  std::cout << "Sigma: " << sigma << std::endl;
181  std::cout << "Sampling rate: " << sampling << std::endl;
182  if (!fnNMA.empty())
183  std::cout << "NMA: " << fnNMA << std::endl;
184  std::cout << "Output rootname: " << fnRoot << std::endl;
185  std::cout << "Lambda ART: " << lambdaART << std::endl;
186  std::cout << "N. Iterations: " << Nit << std::endl;
187  std::cout << "\n -----------------------------------------------------" << std::endl;
188  }
189 }
int Nit
Number of iterations.
double sigma
Sigma of atoms.
double sampling
Sampling rate.
double lambdaART
Lambda.
int verbose
Verbosity level.
FileName fnRoot
Output filename.
FileName fnDoc
Selfile with the input images.
FileName fnPseudo
Pseudoatom filename.
FileName fnNMA
Selfile with the input NMAs.

◆ writePseudo()

void ProgARTPseudo::writePseudo ( )

Write Pseudo

Definition at line 324 of file reconstruct_art_pseudo.cpp.

325 {
326  // Convert from pseudoatoms to volume
327  Image<double> V;
328  size_t objId = DF.firstRowId();
329  FileName fnExp;
330  DF.getValue( MDL_IMAGE, fnExp, objId);
331  Image<double> I;
332  I.read(fnExp,HEADER);
333  V().resize(XSIZE(I()),XSIZE(I()),XSIZE(I()));
334  V().setXmippOrigin();
335 
336  int nmax=atomPosition.size();
337  double sigma4=4*sigma;
338  for (int n=0; n<nmax; n++)
339  {
340  int XX_corner1 = CEIL(XMIPP_MAX(STARTINGX(V()), XX(atomPosition[n]) - sigma4));
341  int YY_corner1 = CEIL(XMIPP_MAX(STARTINGY(V()), YY(atomPosition[n]) - sigma4));
342  int ZZ_corner1 = CEIL(XMIPP_MAX(STARTINGY(V()), ZZ(atomPosition[n]) - sigma4));
343  int XX_corner2 = FLOOR(XMIPP_MIN(FINISHINGX(V()), XX(atomPosition[n]) + sigma4));
344  int YY_corner2 = FLOOR(XMIPP_MIN(FINISHINGY(V()), YY(atomPosition[n]) + sigma4));
345  int ZZ_corner2 = FLOOR(XMIPP_MIN(FINISHINGY(V()), ZZ(atomPosition[n]) + sigma4));
346  if (XX_corner1 <= XX_corner2 && YY_corner1 <= YY_corner2 &&
347  ZZ_corner1 <= ZZ_corner2)
348  {
349  for (int z = ZZ_corner1; z <= ZZ_corner2; z++)
350  for (int y = YY_corner1; y <= YY_corner2; y++)
351  for (int x = XX_corner1; x <= XX_corner2; x++)
352  V(z,y,x)+=atomWeight[n]*
356  }
357  }
358  V.write(fnRoot+".vol");
359 
360  // Histogram of the intensities
361  MultidimArray<double> intensities(atomWeight);
362  Histogram1D hist;
363  compute_hist(intensities, hist, 100);
364  hist.write(fnRoot+"_intensities.hist");
365 }
int * nmax
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
#define FINISHINGX(v)
static double * y
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 sigma
Sigma of atoms.
#define STARTINGX(v)
doublereal * x
#define STARTINGY(v)
#define FLOOR(x)
Definition: xmipp_macros.h:240
void compute_hist(const MultidimArrayGeneric &array, Histogram1D &hist, int no_steps)
Definition: histogram.cpp:572
#define XX(v)
Definition: matrix1d.h:85
#define CEIL(x)
Definition: xmipp_macros.h:225
std::vector< double > atomWeight
size_t firstRowId() const override
#define XSIZE(v)
double z
#define XMIPP_MIN(x, y)
Definition: xmipp_macros.h:181
FileName fnRoot
Output filename.
#define YY(v)
Definition: matrix1d.h:93
bool getValue(MDObject &mdValueOut, size_t id) const override
#define FINISHINGY(v)
void write(const FileName &fn, MDLabel=MDL_X, MDLabel=MDL_COUNT)
Definition: histogram.cpp:129
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
int * n
Name of an image (std::string)
std::vector< Matrix1D< double > > atomPosition
#define ZZ(v)
Definition: matrix1d.h:101
double gaussian1D(double x, double sigma, double mu)

Member Data Documentation

◆ atomPosition

std::vector< Matrix1D<double> > ProgARTPseudo::atomPosition

Definition at line 95 of file reconstruct_art_pseudo.h.

◆ atomWeight

std::vector< double > ProgARTPseudo::atomWeight

Definition at line 98 of file reconstruct_art_pseudo.h.

◆ DF

MetaDataVec ProgARTPseudo::DF

Definition at line 92 of file reconstruct_art_pseudo.h.

◆ fnDoc

FileName ProgARTPseudo::fnDoc

Selfile with the input images.

Definition at line 45 of file reconstruct_art_pseudo.h.

◆ fnNMA

FileName ProgARTPseudo::fnNMA

Selfile with the input NMAs.

Definition at line 51 of file reconstruct_art_pseudo.h.

◆ fnPseudo

FileName ProgARTPseudo::fnPseudo

Pseudoatom filename.

Definition at line 48 of file reconstruct_art_pseudo.h.

◆ fnRoot

FileName ProgARTPseudo::fnRoot

Output filename.

Definition at line 54 of file reconstruct_art_pseudo.h.

◆ gaussianProjectionTable

Matrix1D<double> ProgARTPseudo::gaussianProjectionTable

Definition at line 101 of file reconstruct_art_pseudo.h.

◆ gaussianProjectionTable2

Matrix1D<double> ProgARTPseudo::gaussianProjectionTable2

Definition at line 104 of file reconstruct_art_pseudo.h.

◆ lambdaART

double ProgARTPseudo::lambdaART

Lambda.

Definition at line 57 of file reconstruct_art_pseudo.h.

◆ Nit

int ProgARTPseudo::Nit

Number of iterations.

Definition at line 60 of file reconstruct_art_pseudo.h.

◆ NMA

std::vector< Matrix2D<double> > ProgARTPseudo::NMA

Definition at line 107 of file reconstruct_art_pseudo.h.

◆ sampling

double ProgARTPseudo::sampling

Sampling rate.

Definition at line 66 of file reconstruct_art_pseudo.h.

◆ sigma

double ProgARTPseudo::sigma

Sigma of atoms.

Definition at line 63 of file reconstruct_art_pseudo.h.


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