Bsoft 2.1.4
Bernard's software package
mg_reconstruct.cpp File Reference

Functions for reconstruction. More...

#include "rwimg.h"
#include "rwmg.h"
#include "mg_processing.h"
#include "mg_select.h"
#include "mg_img_proc.h"
#include "mg_particle_select.h"
#include "mg_reconstruct.h"
#include "mg_ctf.h"
#include "Complex.h"
#include "symmetry.h"
#include "utilities.h"
#include <sys/stat.h>
#include <fcntl.h>

Functions

int part_ft_size (int xsize, double scale, int pad_factor)
 Sets the Fourier transform size for 2D particle images for reconstruction. More...
 
Bimageparticle_reconstruct (Bparticle *partlist, Bsymmetry sym, int sym_mode, double hi_res, Vector3< double > scale, Vector3< double > sam, Vector3< long > size, int ft_size, fft_plan plan, int interp_type, int ctf_action, double wiener, int flags, int first)
 Reciprocal space reconstruction from 2D particle images.
More...
 
Bimageimg_reconstruction_sum_weigh (Bimage **pacc, int imap, int nmaps, int maps_per_class, double hi_res)
 Combines and weighs a map from several partial maps and weight sets. More...
 
double part_single_reconstruction (Bparticle *part, Vector3< long > size, Bimage *pmask, Bsymmetry &sym, double hi_res, Vector3< double > scale, int ft_size, fft_plan img_plan, fft_plan map_plan, double part_weight, int interp_type, CTFparam *mg_ctf, int ctf_action, double wiener, int flags)
 
long project_single_particle_reconstruction (Bproject *project, Bstring &maskfile, Bsymmetry &sym, int num_select, double hi_res, Vector3< double > scale, Vector3< long > size, int pad_factor, int interp_type, int ctf_action, double wiener, int flags)
 Reciprocal space reconstruction from the images in a multi-image file.
More...
 
Vector3< long > project_set_reconstruction_size (Bproject *project, Vector3< double > &sam, double scale, int twoD_flag)
 Sets the reconstruction size for reconstruction from 2D particle images. More...
 
int project_configure_for_reconstruction (Bproject *project, Bstring classes, long &nmaps, int &nthreads)
 Sets up the particle selection for reconstruction. More...
 
int project_update_class_averages (Bproject *project, Bimage *prec, Bstring file_name)
 
Bimageproject_reconstruct_2D (Bproject *project, Bstring file_name, int transform_output)
 Creates a 2D reconstruction from the images in a multi-image file.
More...
 
Bparticleimg_reconstruct_2D (long i, Bproject *project, Bimage *prec, double hires, fft_plan planf, fft_plan planb)
 
long img_reconstruct_2D_fspace (long i, Bproject *project, Bimage *prec, double hires, fft_plan planf, fft_plan planb)
 
Bimageproject_reconstruct_2D_fast (Bproject *project, Bstring file_name)
 
Bimageproject_reconstruct_3D (Bproject *project, long selnum, int calcfom, Vector3< long > size)
 Transforms 3D maps and calculates an average. More...
 
Bimageproject_reconstruct_3D (Bproject *project, long selnum, Vector3< long > size, double resolution)
 Transforms 3D maps and calculates an average. More...
 
Bimageproject_back_projection (Bproject *project, long num_select, Vector3< long > map_size, Vector3< double > sam, double scale, double resolution, fft_plan planf, fft_plan planb)
 Back projects a set of 2D images into a 3D volume. More...
 
Bimageimg_backprojection_accumulate (Bimage **pacc, int imap, int nmaps, int nthreads)
 Accumulates multiple backprojections. More...
 

Variables

int verbose
 

Detailed Description

Functions for reconstruction.

Author
Bernard Heymann
Date
Created: 20010403
Modified: 20220221

Function Documentation

◆ img_backprojection_accumulate()

Bimage * img_backprojection_accumulate ( Bimage **  pacc,
int  imap,
int  nmaps,
int  nthreads 
)

Accumulates multiple backprojections.

Parameters
**paccarray of partial maps with linked weight maps.
imapwhich output map to weigh.
nmapsnumber of output maps (1,2,3).
nthreadsnumber of threads per map (= number of partial maps).
Returns
int 0.

◆ img_reconstruct_2D()

Bparticle * img_reconstruct_2D ( long  i,
Bproject project,
Bimage prec,
double  hires,
fft_plan  planf,
fft_plan  planb 
)

◆ img_reconstruct_2D_fspace()

long img_reconstruct_2D_fspace ( long  i,
Bproject project,
Bimage prec,
double  hires,
fft_plan  planf,
fft_plan  planb 
)

◆ img_reconstruction_sum_weigh()

Bimage * img_reconstruction_sum_weigh ( Bimage **  pacc,
int  imap,
int  nmaps,
int  maps_per_class,
double  hi_res 
)

Combines and weighs a map from several partial maps and weight sets.

Parameters
**paccarray of partial maps with linked weight maps.
imapwhich output map to weigh.
nmapsnumber of output maps (1,2,3).
maps_per_classnumber of threads per map (= number of partial maps).
hi_reshigh resolution limit.
Returns
Bimage* weighed reconstruction with FOM block.
The input is a set of partially integrated complex maps with associated 
weigths as follows:
    voxel power sums            FOM block of map.
    voxel weight sums           linked image.
    voxel weight squared sums   linked image FOM block.
The partial sums are completed into corresponding blocks in three possible
ways based on the value of imap and nmap:
    nmap    imap    result
    1       0       one map from all input maps
    2       0,1     one map from half of the input maps
    3       0       one map from all input maps
    3       1,2     one map from half of the input maps
The total number of maps in the array is nclasses*nmaps.

◆ part_ft_size()

int part_ft_size ( int  xsize,
double  scale,
int  pad_factor 
)

Sets the Fourier transform size for 2D particle images for reconstruction.

Parameters
xsizesize of x dimension.
scalescale of reconstruction.
pad_factorfactor that determines image padding.
Returns
int transform size.
The reconstruction size must be set.

◆ part_single_reconstruction()

double part_single_reconstruction ( Bparticle part,
Vector3< long >  size,
Bimage pmask,
Bsymmetry sym,
double  hi_res,
Vector3< double >  scale,
int  ft_size,
fft_plan  img_plan,
fft_plan  map_plan,
double  part_weight,
int  interp_type,
CTFparam mg_ctf,
int  ctf_action,
double  wiener,
int  flags 
)

◆ particle_reconstruct()

Bimage * particle_reconstruct ( Bparticle partlist,
Bsymmetry  sym,
int  sym_mode,
double  hi_res,
Vector3< double >  scale,
Vector3< double >  sam,
Vector3< long >  size,
int  ft_size,
fft_plan  plan,
int  interp_type,
int  ctf_action,
double  wiener,
int  flags,
int  first 
)

Reciprocal space reconstruction from 2D particle images.

Parameters
*partlista list of 2D particle image parameters.
*sympoint group symmetry.
sym_mode0=apply symmetry, 1=C1, 2=random symmetry view
hi_reshigh resolution limit.
scalescale of reconstruction.
samsampling/voxel size of reconstruction.
sizesize of reconstruction.
ft_sizeFourier transform size.
planFourier transform plan.
interp_typeinterpolation type.
ctf_actionflag to apply CTF to projections.
wienerWiener factor.
flags1=rescale particles, 2=2D reconstruction, 4=bootstrap, 8=Ewald.
firstflag to indicate the first thread.
Returns
Bimage* 3D reconstructed map.
The orientation parameters, view vector, angle of rotation and origin,
must all be set. Each image is padded to at least two times its size 
and its Fourier transform packed into 3D reciprocal space.
The figure-of-merit calculated for each reciprocal space voxel is:
           sum(w*re)^2 + sum(w*im)^2
    FOM = ---------------------------
          sum(w)*sum(w*(re^2 + im^2))
where
    re  real part
    im  imaginary part
    w   weight (inverse distance of image pixel to closest grid point)
For voxels with only one data pixel contributing to it, FOM = 0.
A bootstrap reconstruction uses the particle selection to weigh each
selected particle.

◆ project_back_projection()

Bimage * project_back_projection ( Bproject project,
long  num_select,
Vector3< long >  map_size,
Vector3< double >  sam,
double  scale,
double  resolution,
fft_plan  planf,
fft_plan  planb 
)

Back projects a set of 2D images into a 3D volume.

Parameters
*projectimage processing parameter structure.
num_selectselection number from the selection column.
map_size3-valued vector for the new map size.
sam3-value vector for the voxel size in angstrom.
scalereconstruction scale.
resolutionresolution for low-pass filtering.
planf2D forward Fourier transform plan.
planb2D backward Fourier transform plan.
Returns
Bimage* the new 3D reconstruction map.
All the information needed to do a 3D reconstruction is passed in through
an image processing structure. The new 3D volume is initialized.
Each sub-image in each particle file is read individually and 
back-projected within the new volume. The orientation parameters from
the image processing structure is transferred to the sub-image
structure in the 2D image before calling the function packing one
image into the volume. The default origin is the center of the image.

◆ project_configure_for_reconstruction()

int project_configure_for_reconstruction ( Bproject project,
Bstring  classes,
long &  nmaps,
int &  nthreads 
)

Sets up the particle selection for reconstruction.

Parameters
*projectproject parameter structure.
classesstring specifying classes to use.
nmapsnumber of maps per class (1,2,3).
nthreadsnumber of threads per class (must be even if nmaps > 1).
Returns
int number of classes.
The classes are specified in a string of comma-separated numbers,
also allowing hyphened ranges (e.g., "2,5-7,9").
The selection numbers for the particles in the project are set to
calculate partial maps so that there are nthread maps per class.
Each such partial map will be calculated in its own thread and
integrated with others from the same class afterwards.

◆ project_reconstruct_2D()

Bimage * project_reconstruct_2D ( Bproject project,
Bstring  file_name,
int  transform_output 
)

Creates a 2D reconstruction from the images in a multi-image file.

Parameters
*projectimage processing parameter structure.
file_name2D reconstruction file name.
transform_outputflag to output transformed images.
Returns
Bimage* 2D reconstruction image.
The angle of rotation and the x,y origins must already have been found 
and placed in the appropriate arrays within the Bproject structure.
Each selected image is transformed, and then added to the reconstruction
image corresponding to the original projection image chosen.
If the transform_output flag is set, then the transformed images are written
into a new image with a "_proj.spi" ending.

◆ project_reconstruct_2D_fast()

Bimage * project_reconstruct_2D_fast ( Bproject project,
Bstring  file_name 
)

◆ project_reconstruct_3D() [1/2]

Bimage * project_reconstruct_3D ( Bproject project,
long  selnum,
int  calcfom,
Vector3< long >  size 
)

Transforms 3D maps and calculates an average.

Parameters
*projectparameter structure with all parameters.
selnumselection number of reconstructions or particles.
calcfomflag to calculate FOM block (1=var, 2=std).
sizesize of particles to extract (only when extraction needed).
Returns
Bimage* average map with FOM block defined.
The orientations of the maps in the project must already be specified.
Each map is transformed and added to an average map.
A FOM block is optionally calculated with either the variance or
standard deviation.

◆ project_reconstruct_3D() [2/2]

Bimage * project_reconstruct_3D ( Bproject project,
long  selnum,
Vector3< long >  size,
double  resolution 
)

Transforms 3D maps and calculates an average.

Parameters
*projectparameter structure with all parameters.
selnumselection number of reconstructions or particles.
sizesize of particles to extract (only when extraction needed).
resolutionmaximum reconstruction resolution (in angstrom, default Nyquest).
Returns
Bimage* average map with FOM block defined.
The orientations of the maps in the project must already be specified.
Each map is transformed and added to an average map.
A FOM block is optionally calculated with either the variance or
standard deviation.

◆ project_set_reconstruction_size()

Vector3< long > project_set_reconstruction_size ( Bproject project,
Vector3< double > &  sam,
double  scale,
int  twoD_flag 
)

Sets the reconstruction size for reconstruction from 2D particle images.

Parameters
*projectproject parameter structure.
&samsampling/voxel size of new map.
scalescale of reconstruction.
twoD_flagdoing a 2D reconstruction rather than 3D.
Returns
Vector3<long> reconstruction size.
The reconstruction size is set from the first particle image size found.

◆ project_single_particle_reconstruction()

long project_single_particle_reconstruction ( Bproject project,
Bstring maskfile,
Bsymmetry sym,
int  num_select,
double  hi_res,
Vector3< double >  scale,
Vector3< long >  size,
int  pad_factor,
int  interp_type,
int  ctf_action,
double  wiener,
int  flags 
)

Reciprocal space reconstruction from the images in a multi-image file.

Parameters
*projectimage processing parameter structure.
&maskfilemask to determine density statistics.
*sympoint group symmetry.
num_selectselection number from the selection column.
hi_reshigh resolution limit.
scalescale of reconstruction.
sizesize of reconstruction.
pad_factorimage padding factor.
interp_typeinterpolation type (provisional).
ctf_actionflag to apply CTF to projections.
wienerWiener factor.
flagsoption flags.
Returns
long particles processed.
The orientation parameters, view vector, angle of rotation and origin,
must all be set. Each image is padded to at least two times its size 
and its Fourier transform packed into 3D reciprocal space.
The figure-of-merit calculated for each reciprocal space voxel is:
           sum(w*re)^2 + sum(w*im)^2
    FOM = ---------------------------
          sum(w)*sum(w*(re^2 + im^2))
where
    re  real part
    im  imaginary part
    w   weight (inverse distance of image pixel to closest grid point)
For voxels with only one data pixel contributing to it, FOM = 0.
An image is used in the reconstruction if its selection flag has been set.
If the selection number is less than zero, all particles with selection flags
greater than zero are used. If the selection number is zero or above, all
particles with the selection flag set to the same number are used.
A bootstrap reconstruction uses the particle selection to weigh each
selected particle.

◆ project_update_class_averages()

int project_update_class_averages ( Bproject project,
Bimage prec,
Bstring  file_name 
)

Variable Documentation

◆ verbose

int verbose
extern