 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
28 if ( sigma < 1 ) sigma = 1;
29 ksize = 2*( (long) (4*sigma + 0.9) ) + 1;
40 cout <<
"threshold = " << threshold << endl;
76 double part_ori,
double& fommin,
double fommax,
77 long maxnum,
double pix_min,
double pix_max)
79 if ( part_ori < excl_dist ) part_ori = excl_dist;
84 origin = origin.
min(pcc->
size()-1);
88 cout <<
"Limits: " << min <<
tab << max << endl;
93 if ( excl_dist < 10 ) excl_dist = 1.8*part_ori;
102 for ( i=j=0; i<ncoor && j<maxnum; i++ ) {
103 fom = pcc->
get(0, coor[i]);
104 if ( fom >= fommin && fom <= fommax ) {
105 if ( coor[i] >= min && coor[i] <= max ) {
107 if ( !partlist ) partlist = part;
108 part->
loc = coor[i] * obin;
118 cout <<
"Number of particles found: " << j << endl << endl;
142 double hires,
double lores,
double fommin,
double fommax,
double excl_dist,
long bin)
144 if ( !p )
return NULL;
145 if ( bin < 1 ) bin = 1;
146 if ( bin > 4 ) bin = 4;
147 if ( excl_dist < 1 ) excl_dist = 0.8*ptemp->
sizeX();
150 cout <<
"Picking from " << p->
file_name() << endl;
170 cout <<
"DEBUG particles_pick: bin=" << bin << endl;
182 double a1, a2, v, d(1), l((gauss[1]+gauss[2])/(gauss[0]+gauss[3]));
183 double cut((gauss[1] + gauss[4])/2);
186 v = (cut - gauss[1])/gauss[2];
187 a1 = gauss[0]*exp(-0.5*v*v);
188 v = (cut - gauss[4])/gauss[5];
189 a2 = gauss[3]*exp(-0.5*v*v);
194 cout << a1 <<
tab << a2 <<
tab << cut << endl;
199 cout <<
"u1=" << gauss[1] <<
tab <<
"u2=" << gauss[4] <<
tab <<
"cut=" << cut << endl;
221 double nsig,
double part_ori,
double excl_dist,
long bin)
223 if ( !p )
return NULL;
224 if ( bin < 1 ) bin = 1;
225 if ( bin > 4 ) bin = 4;
226 if ( excl_dist < 1 ) excl_dist = 1.6*part_ori;
229 cout <<
"Picking from " << p->
file_name() << endl;
235 cout <<
"DEBUG particles_pick_var: nsig=" << nsig << endl;
245 t = fabs(gauss[1]-gauss[4])/sqrt(gauss[2]*gauss[2]+gauss[5]*gauss[5]);
258 if ( gauss[1] < gauss[4] ) {
259 fomcut = gauss[1] + nsig*gauss[2];
260 if ( fomcut > gauss[4] ) fomcut = gauss[4];
262 fomcut = gauss[4] + nsig*gauss[5];
263 if ( fomcut > gauss[1] ) fomcut = gauss[1];
267 cout <<
"Variance image min, max: " << pc->
minimum() <<
tab << pc->
maximum() << endl;
268 cout <<
"First peak: " << gauss[0] <<
tab << gauss[1] <<
tab << gauss[2] << endl;
269 cout <<
"Second peak: " << gauss[3] <<
tab << gauss[4] <<
tab << gauss[5] << endl;
270 cout <<
"T and FOM: " << t <<
tab << fomcut << endl;
274 cout <<
"DEBUG particles_pick_var: fomcut=" << fomcut << endl;
279 part_ori, fomcut, 1e30, 1000000, 2, excl_dist);
287 double cutmin,
double cutmax,
double part_ori,
double excl_dist,
long bin)
289 if ( !p )
return NULL;
290 if ( bin < 1 ) bin = 1;
291 if ( bin > 4 ) bin = 4;
292 if ( excl_dist < 1 ) excl_dist = 1.6*part_ori;
295 cout <<
"Picking from " << p->
file_name() << endl;
301 cout <<
"DEBUG particles_pick_var: cutmin=" << cutmin <<
" cutmax=" << cutmax << endl;
309 part_ori, cutmin, cutmax, 1000000, 2, excl_dist);
337 Bimage* pmask,
double hires,
double lores,
double fommin,
double fommax,
338 double excl_dist,
long bin)
341 if ( !p )
return NULL;
346 hires, lores, fommin, fommax, excl_dist, bin);
371 long avg_kernel,
long var_kernel,
double nsig,
372 double part_ori,
double excl_dist,
long bin)
375 if ( !p )
return NULL;
378 nsig, part_ori, excl_dist, bin);
388 double v, sumin(0), sumout(0);
394 for ( n=0, mark = markin; mark; mark = mark->
next ) {
395 v = p->
get(0, mark->
loc + c, 0);
404 for ( n=0, mark = markout; mark; mark = mark->
next ) {
405 v = p->
get(0, mark->
loc + c, 0);
412 if ( n ) sumout /= n;
414 return sumin - sumout;
436 dispatch_apply(p->
data_size(), dispatch_get_global_queue(0, 0), ^(
size_t i){
440 #pragma omp parallel for
448 if ( contrast > 0 ) scale = 1/pt->
maximum();
474 Bmarker* markout,
int avg_kernel,
int contrast)
476 if ( !mg->
select )
return 0;
508 for ( part = mg->
part; part; part = part->
next )
534 double hires,
double lores,
double fommin,
double fommax,
double excl_dist,
long bin)
537 double min_thresh(1);
543 cout <<
"Finding particles by cross-correlation:" << endl;
544 cout <<
"Template: " << ptemp->
file_name() << endl;
546 cout <<
"Mask: " << pmask->
file_name() << endl;
547 cout <<
"Resolution limits: " << hires <<
" - ";
548 if ( lores > 0 ) cout << lores <<
" A" << endl;
549 else cout <<
"inf A" << endl;
550 cout <<
"Thresholds: " << fommin <<
" - " << fommax << endl;
551 cout <<
"Exclusion distance: " << excl_dist << endl;
552 cout <<
"Binning: " << bin << endl;
557 for ( mg = field->
mg; mg; mg = mg->
next )
if ( mg->
select ) {
559 cout <<
"Picking from micrograph " << mg->
id << flush;
564 if ( min_thresh > mg->
fom ) min_thresh = mg->
fom;
566 cout <<
tab << npart << endl;
573 cout <<
"Picking from reconstruction " << rec->
id << endl;
577 if ( min_thresh > rec->
fom ) min_thresh = rec->
fom;
584 cout <<
"Number of particles: " << npart << endl << endl;
606 double nsig,
double part_ori,
double excl_dist,
long bin)
608 if ( part_ori < 1 ) part_ori = excl_dist;
611 double min_thresh(1);
617 cout <<
"Finding particles from local variance map:" << endl;
618 cout <<
"Averaging kernel size: " << avg_kernel << endl;
619 cout <<
"Variance kernel size: " << var_kernel << endl;
620 cout <<
"Multiple of sigma for cutoff: " << nsig << endl;
621 cout <<
"Exclusion distance: " << excl_dist << endl;
622 cout <<
"Binning: " << bin << endl;
627 for ( mg = field->
mg; mg; mg = mg->
next )
if ( mg->
select ) {
629 cout <<
"Picking from micrograph " << mg->
id << endl;
633 avg_kernel, var_kernel, nsig, part_ori, excl_dist, bin);
634 if ( min_thresh > mg->
fom ) min_thresh = mg->
fom;
642 cout <<
"Picking from reconstruction " << rec->
id << endl;
646 avg_kernel, var_kernel, nsig, part_ori, excl_dist, bin);
647 if ( min_thresh > rec->
fom ) min_thresh = rec->
fom;
654 cout <<
"Number of particles: " << npart << endl << endl;
677 int avg_kernel,
double ainc,
int flags,
int contrast)
680 cerr <<
"Error: The particle diameter must be specified!" << endl << endl;
684 int w = (int) (dout + 10);
695 cout <<
"Finding particles using a circular fore/background template:" << endl;
696 cout <<
"Particle diameter: " << din << endl;
697 cout <<
"Background diameter: " << dout << endl;
698 cout <<
"Angular increment: " << ainc*180.0/
M_PI <<
" degrees" << endl;
699 cout <<
"Averaging kernel size: " << avg_kernel << endl << endl;
703 for ( mg = field->
mg; mg; mg = mg->
next )
if ( mg->
select ) {
708 cout <<
"Picking from micrograph " << mg->
id << endl;
723 cout <<
"Number of particles: " << npart << endl << endl;
732 cout <<
"Masking the existing particles:" << endl;
733 cout <<
"Box size: " << box_size << endl;
736 for ( ; part; part = part->
next )
745 cout <<
"Masking the variance map:" << endl;
746 cout <<
"Threshold: " << threshold << endl;
749 for (
long i=0; i<p->
data_size(); i++ )
if ( (*p)[i] > threshold ) pvar->
set(i, 0);
755 long avg_kernel,
long var_kernel,
double excl_dist)
757 if ( !mg->
select )
return 0;
762 cout <<
"Filtered min, max, avg & std: " << p->
minimum() <<
" " <<
772 cout <<
"Variance min, max, avg & std: " << pvar->
minimum() <<
" " <<
798 long avg_kernel,
long var_kernel,
double excl_dist)
803 cout <<
"Filtered min, max, avg & std: " << p->
minimum() <<
" " <<
813 cout <<
"Variance min, max, avg & std: " << pvar->
minimum() <<
" " <<
849 long avg_kernel,
long var_kernel,
double excl_dist)
858 cout <<
"Finding background areas:" << endl;
859 cout <<
"Maximum number: " << number << endl;
860 cout <<
"Averaging kernel size: " << avg_kernel << endl;
861 cout <<
"Variance kernel size: " << var_kernel << endl;
862 cout <<
"Exclusion distance: " << excl_dist << endl << endl;
867 for ( mg = field->
mg; mg; mg = mg->
next )
if ( !mg->
select ) {
871 cout <<
"Picking from micrograph " << mg->
id << endl;
884 cout <<
"Picking from reconstruction " << rec->
id << endl;
894 cout <<
"Background areas picked: " << npart << endl << endl;
911 for ( j=0, g=1; part; part = part->
next, ++g ) {
912 tr = part->
ori - refori + part->
loc;
914 for ( s=1, v = views; v; v = v->
next, ++s ) {
918 if ( !nupart_list ) nupart_list = nupart;
923 if ( part->
loc[2] < 1 ) nupart->
loc[2] = 0;
925 cout << j <<
tab << nupart->
view << endl;
954 if ( sym_axis == 2 ) {
956 refview =
View(1, 0, 0, 0);
957 }
else if ( sym->
point == 432 ) {
958 refview =
View(1, -1, 0, 0);
960 }
else if ( sym_axis == 3 && sym->
point > 300 ) {
961 refview =
View(1, 1, 1, 0);
962 }
else if ( sym_axis == 5 && sym->
point == 532 ) {
967 cout <<
"Picking subregions based on symmetry " << sym->
label <<
":" << endl;
968 cout <<
"Symmetry axis: " << refview <<
" (" << sym_axis <<
")" << endl;
969 cout <<
"Distance along axis: " << axis_dist << endl;
986 for ( mg = field->
mg; mg; mg = mg->
next ) {
997 cout <<
"Number of new particles: " << n << endl << endl;
1004 if ( tempfile.
length() < 1 )
return NULL;
1008 cerr <<
"Error: The template/reference file was not read!" << endl;
1014 double angle(hires/ptemp->
real_size()[0]);
1019 if ( ptemp->
sizeZ() > 1 ) {
1021 cout <<
"Calculating projections:" << endl;
1022 cout <<
"Symmetry: " << sym->
label << endl;
1023 cout <<
"Angle step size: " << angle*180.0/
M_PI << endl;
1033 cout <<
"Number of projections: " << ptemp->
images() << endl;
1037 cout <<
"DEBUG img_prepare_projections: Calculating the background" << endl;
1041 cout <<
"DEBUG img_prepare_projections: Smoothing the edge" << endl;
1045 cout <<
"DEBUG img_prepare_projections: Doubling the size" << endl;
1051 if ( bin > 1 ) ptemp->bin(bin);
1061 if ( tempfile.
length() < 1 )
return NULL;
1065 cerr <<
"Error: The template/reference file was not read!" << endl;
1069 if ( ptemp->
sizeZ() < 2 ) {
1070 cerr <<
"Error: The template must be a 3D volume!" << endl;
1076 double angle(hires/ptemp->
real_size()[0]);
1079 cout <<
"Calculating orientations:" << endl;
1080 cout <<
"Symmetry: " << sym->
label << endl;
1081 cout <<
"Angle step size: " << angle*180.0/
M_PI << endl;
1094 cout <<
"Number of orientations: " << ptemp->
images() << endl;
1097 cout <<
"DEBUG img_prepare_orientations: Calculating the background" << endl;
1101 cout <<
"DEBUG img_prepare_orientations: Smoothing the edge" << endl;
1105 cout <<
"DEBUG img_prepare_orientations: Doubling the size" << endl;
1111 if ( bin > 1 ) ptemp->bin(bin);
1121 double hires,
double lores,
double shift_limit,
long bin,
1129 if ( bin > 1 ) p->bin(bin);
1132 cout <<
"DEBUG part_align: Transforming" << endl;
1136 cout <<
"DEBUG part_align: Band-pass filtering" << endl;
1140 cout <<
"DEBUG part_align: Normalizing" << endl;
1144 cout <<
"DEBUG part_align: Calculating the complex conjugate product" << endl;
1146 if ( !pcc ) cerr <<
"Complex conjugate product failed!" << endl;
1149 cout <<
"DEBUG part_align: Back-transforming" << endl;
1154 cout <<
"DEBUG part_align: Finding peaks" << endl;
1158 for ( nn=0; nn<pcc->
images(); nn++ ) {
1172 cout << right << setprecision(2) << part->
id <<
tab << shift
1173 << setprecision(4) <<
tab << part->
view <<
tab
1174 << setprecision(6) << part->
fom[0] << endl;
1182 return part->
fom[0];
1211 cout <<
"Micrograph " << mg->
id <<
" (" << mg->
img_num <<
")" << endl;
1219 if ( npart < 1 )
return 0;
1224 cout <<
"Finding particles from image " << p->
file_name() << endl;
1226 double shift_limit(ptemp->
sizeX()/4);
1229 cout <<
"ID\tdx\tdy\tdz\tvx\tvy\tvz\tva\tFOM" << endl;
1230 for ( part = mg->
part; part; part = part->
next ) {
1232 cout <<
"DEBUG mg_extract_orient_particles: Extracting particle" << endl;
1233 start = part->
loc - origin;
1234 start = start.
max(0);
1235 start = start.
min(p->
size() - extsize);
1236 pex = p->
extract(0, start, extsize);
1251 cout <<
"Reconstruction " << rec->
id << endl;
1259 if ( npart < 1 )
return 0;
1264 cout <<
"Finding particles from image " << p->
file_name() << endl;
1266 double shift_limit(ptemp->
sizeX()/4);
1269 cout <<
"ID\tdx\tdy\tdz\tvx\tvy\tvz\tva\tFOM" << endl;
1270 for ( part = rec->
part; part; part = part->
next ) {
1272 cout <<
"DEBUG mg_extract_orient_particles: Extracting particle" << endl;
1273 start = part->
loc - origin;
1274 start = start.
max(0);
1275 start = start.
min(p->
size() - extsize);
1276 pex = p->
extract(0, start, extsize);
1302 Bsymmetry* sym,
double hires,
double lores,
long bin)
1315 cout <<
"Extracting and orienting particles in micrographs:" << endl;
1316 cout <<
"Template: " << ptemp->
file_name() << endl;
1317 cout <<
"Template images: " << ptemp->
images() << endl;
1318 cout <<
"Template size: " << ptemp->
size() << endl;
1321 cout <<
"Resolution limits: " << hires <<
" - ";
1322 if ( lores > 0 ) cout << lores <<
" A" << endl;
1323 else cout <<
"inf A" << endl;
1326 cout <<
"Binning: " << bin << endl;
1330 cout <<
"Setting up FFT plans" << endl;
1336 cout <<
"Transforming template" << endl;
1341 cout <<
"Band-pass filtering template" << endl;
1346 cout <<
"Normalizing template" << endl;
1352 for ( mg = field->
mg; mg; mg = mg->
next ) {
void coordinates(long i, long &nx, long &ny, long &nz)
long micrograph_set_part_links(Bmicrograph *mg)
Sets the links from particles back to the micrograph.
fft_plan fft_setup(fft_direction dir, int opt=0)
Sets up a plan for fast Fourier transforms.
long project_count_mg_particles(Bproject *project)
Counts all the particles in the project structure.
int rescale(double scale, double shift)
Rescales the image data with a given multiplier and offset.
long mask_erode(long times=1)
Erodes a binary mask.
Vector3< double > real_size()
int filter_gaussian(long kernel_size, double sigma)
Applies a gaussian filter to an image.
vector< double > histogram_gauss_fit(long bins, long ngauss=1)
Fits a gaussian function to a histogram of an image.
Bimage * img_prepare_for_picking(Bimage *p, int flags, long sigma, long bin)
int truncate(double minim, double maxim, double setmin, double setmax)
Truncates image data to a given minimum and maximum.
View * symmetry_get_all_views(Bsymmetry *sym, View asu_view)
Get all symmetry-related views of one given view.
Bimage * find_peaks(long kernelsize)
Finds peaks in a map with periodic boundaries.
double get(long nn, long xx, long yy, long zz, long cc=0)
Returns the data value at the given coordinates.
long kill_list(char *list, unsigned long size)
Frees all the items in a linked list.
double rec_pick_background(Breconstruction *rec, Bimage *p, long number, long avg_kernel, long var_kernel, double excl_dist)
void set(long j, double v)
Sets a single value at the given index.
Bimage * find_template(Bimage *ptemp, Bimage *pmask, double hires, double lores, int bin, fft_plan planf, fft_plan planb)
Finds one or more matches to a template.
Bimage * copy()
Copies the header information and data of an image into a new image structure.
double img_marker_set_difference_at_voxel(Bimage *p, long i, Bmarker *markin, Bmarker *markout)
int variance(long kernel_size, int flag=0)
Calculates the local variance within the given kernel.
int find_peak(double radius=1e30, double sigma=0)
Finds the peak in an image to the nearest voxel.
int bexit(int value)
Exit function for cleanup and debugging.
long reconstruction_set_part_links(Breconstruction *rec)
Sets the links from particles back to the reconstruction.
Header file for micrograph processing.
Bimage * img_prepare_orientations(Bstring &tempfile, Bsymmetry *sym, double hires, long bin)
Vector3< long > size() const
Header file for single particle picking functions.
double project_extract_orient_particles(Bproject *project, Bstring &tempfile, Bsymmetry *sym, double hires, double lores, long bin)
Picks particles using cross-correlation.
int calculate_background(long nn, int flag)
Calculates the background for one sub-image.
View * asymmetric_unit_views(Bsymmetry *sym, double theta_step, double phi_step, int flag)
Initializes a well-distributed set of views in an asymmetric unit.
void view(double x, double y, double z, double a)
double mg_pick_particles(Bmicrograph *mg, Bimage *p, Bmarker *markin, Bmarker *markout, int avg_kernel, int contrast)
Locates particles using a fore/background difference measure.
int part_mask_particles(Bparticle *part, Bimage *pmask, long box_size)
double mg_pick_background(Bmicrograph *mg, Bimage *p, long number, long avg_kernel, long var_kernel, double excl_dist)
double standard_deviation()
double project_pick_particles(Bproject *project, Bimage *ptemp, Bimage *pmask, double hires, double lores, double fommin, double fommax, double excl_dist, long bin)
Picks particles using cross-correlation.
int refine_peak()
Refines the position of a peak to sub-voxel resolution.
Bimage * complex_conjugate_product_one2many(Bimage *p)
Calculates the product of a complex image with the conjugate of a second.
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
void origin(double x, double y, double z)
void multiply(long j, Complex< double > cv)
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Bimage * project(char axis, int flags=1)
Projects a 3D image to a 2D image down one of the three major axes.
Bimage * orient(View *views)
Calculates multiple copies oriented according to views.
int quadric_correct(vector< double > param)
Corrects for a quadric surface.
int fft_destroy_plan(fft_plan plan)
Deallocates a plan for fast Fourier transforms.
Bimage * bin_copy(long b)
Bimage * mask_by_threshold(double threshold)
Generates a mask based on an image at a given threshold.
double part_align(Bparticle *part, Bimage *p, Bimage *ptemp, double hires, double lores, double shift_limit, long bin, fft_plan planf, fft_plan planb)
Bmarker * marker_set_at_radius(double rad, double ainc)
Generates a marker set at a given radius with z=0.
General image parameter class.
double average(long cc, double xf, double yf, double zf, long nn, double iscale)
Averages in 3D when scaling is less than 1.
unsigned char * data_alloc()
long rec_extract_orient_particles(Breconstruction *rec, Bimage *ptemp, double hires, double lores, long bin, fft_plan planf, fft_plan planb)
vector< double > quadric_fit()
Fits the whole image to a quadric surface.
Bparticle * part_pick_sym_axis(Bparticle *part, Bsymmetry *sym, View &refview, Vector3< double > refori, double axis_dist)
Bparticle * particles_pick_cc(Bimage *p, Bimage *ptemp, Bimage *pmask, double hires, double lores, double fommin, double fommax, double excl_dist, long bin)
Picks particles using cross-correlation.
Header file for general utilities.
ostream & tab(ostream &out)
long mg_extract_orient_particles(Bmicrograph *mg, Bimage *ptemp, double hires, double lores, long bin, fft_plan planf, fft_plan planb)
Finds the centers of picked particles within a micrograph.
void check_resolution(double &resolution)
Checks that the resolution falls within reasonable limits.
Vector3< double > vector3()
double complex_normalize()
Normalizes the power in a complex image.
Bparticle * particles_pick_var(Bimage *p, long avg_kernel, long var_kernel, double nsig, double part_ori, double excl_dist, long bin)
Picks particles in variance map.
void origin(double ox, double oy, double oz)
Bimage * img_marker_set_difference(Bimage *p, Bmarker *markin, Bmarker *markout, int contrast)
Calculates the average difference between voxels tagged by two marker sets.
long project_pick_sym_axis(Bproject *project, Bsymmetry *sym, int sym_axis, double axis_dist)
Picks subregions in 3D particles on the given symmetry axis.
void change_type(char letter)
Get the data type indicated by a single letter code.
Bparticle * particle_add(Bparticle **part, int pid)
Adds a particle parameter structure to a linked list.
Bimage * img_prepare_projections(Bstring &tempfile, Bsymmetry *sym, double hires, long bin)
int filter_average(long kernel_size)
Applies an averaging filter to an image.
Header file for micrograph processing.
Bimage * extract(long nn)
Extracts one sub-image into new image structure.
Header file for generalized linked list functions.
Vector3< double > pixel_size
void sampling(long nn, Vector3< double > u)
Bparticle * particles_from_peaks(Bimage *pcc, long bin, double excl_dist, double part_ori, double &fommin, double fommax, long maxnum, double pix_min, double pix_max)
Finds the peaks in a cross-correlation map corresponding to particles.
int particle_kill(Bparticle *part)
Frees a list of particles.
double gauss_find_intersection(long ngauss, vector< double > &gauss)
int edge(int type, Vector3< long > rect, Vector3< double > start, double width, int fill_type=0, double fill=0)
Smooths the image edge with a soft rectangular function.
long particle_count(Bparticle *part)
Counts the number of particles in a linked list.
int complex_bandpass(double hires, double lores)
Bandpasses a Fourier transform.
long project_pick_background(Bproject *project, long number, long avg_kernel, long var_kernel, double excl_dist)
Picks background areas not overlapping existing particles.
int img_mask_above_threshold(Bimage *pvar, Bimage *p, double threshold)
long statistics()
Calculates the statistics for an image.
int filter_extremes()
Filters the extremes out of a micrograph image.
int resize(Vector3< long > nusize, Vector3< long > translate, int fill_type=0, double fill=0)
Resizes without interpolation or rescaling.
int sphere(Vector3< double > center, double radius, double width=0, int fill_type=0, double fill=0)
Fills a sphere within an image with a uniform value.
long project_count_rec_particles(Bproject *project)
Counts all the particles in the project structure.
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.