 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
38 for ( n=0; n<p->
images(); n++ ) {
63 cerr <<
"Error: No model selected!" << endl << endl;
68 sam[0] = sam[1] = sam[2] = 1;
72 if ( sigma < sam[0] ) sigma = sam[0];
75 long x, y, z, xlo, ylo, zlo, xhi, yhi, zhi;
77 double pix_sigma = sigma/sam[0];
78 double pix_rad = 3*pix_sigma;
79 double nhis2 = -0.5/(pix_sigma*pix_sigma);
84 for ( n=0, mp =
model; mp; mp = mp->
next )
if ( mp->
sel ) {
86 for ( comp = mp->
comp; comp; comp = comp->
next )
if ( comp->
sel ) {
92 if ( size[0] < 1 ) size[0] = (long) ((max[0] - min[0] + 3*sigma)/sam[0]);
93 if ( size[1] < 1 ) size[1] = (long) ((max[1] - min[1] + 3*sigma)/sam[1]);
94 if ( size[2] < 1 ) size[2] = (long) ((max[2] - min[2] + 3*sigma)/sam[2]);
95 size = size.
min(1024);
104 cout <<
"Calculating density by simple gaussian expansion:" << endl;
105 cout <<
"Models: " << p->
images() << endl;
106 cout <<
"Dimensions: " << p->
size() <<
" voxels" << endl;
108 cout <<
"Sampling: " << p->
sampling(0) <<
" A/voxel" << endl;
109 cout <<
"Sigma: " << sigma <<
" A (" << pix_sigma <<
" pixels)" << endl << endl;
111 cout << endl <<
"Calculating density" << endl << endl;
113 for ( n=0, mp =
model; mp; mp = mp->
next )
if ( mp->
sel ) {
114 for ( comp = mp->
comp; comp; comp = comp->
next )
if ( comp->
sel ) {
115 c = comp->
loc/sam + ori;
116 xlo = (long) (c[0] - pix_rad + 0.5);
117 ylo = (long) (c[1] - pix_rad + 0.5);
118 zlo = (long) (c[2] - pix_rad + 0.5);
119 if ( xlo < 0 ) xlo = 0;
120 if ( ylo < 0 ) ylo = 0;
121 if ( zlo < 0 ) zlo = 0;
122 xhi = (long) (c[0] + pix_rad + 0.5);
123 yhi = (long) (c[1] + pix_rad + 0.5);
124 zhi = (long) (c[2] + pix_rad + 0.5);
125 if ( xhi >= p->
sizeX() ) xhi = p->
sizeX() - 1;
126 if ( yhi >= p->
sizeY() ) yhi = p->
sizeY() - 1;
127 if ( zhi >= p->
sizeZ() ) zhi = p->
sizeZ() - 1;
128 for ( z = zlo; z <= zhi; z++ ) {
131 for ( y = ylo; y <= yhi; y++ ) {
134 for ( x = xlo; x <= xhi; x++ ) {
137 i = p->
index(0, x, y, z, n);
138 p->
add(i, exp(nhis2*(x2 + y2 + z2)));
166 for ( i=0, mp =
model; mp; mp = mp->
next, i++ ) {
194 if ( lores < 1 ) lores = 1000;
195 if ( hires > lores ) swap(hires, lores);
200 error_show(
"Error in model_shell_fit: No map read!", __FILE__, __LINE__);
202 double sigma = hires;
209 if ( neg ) pmod->
invert();
212 cout <<
"Fitting the model to the map" << endl;
214 double cc(0), radius = p->
sizeX()/4;
220 cout <<
"Fit CC: " << cc << endl;
221 cout <<
"Shifting the model by: " << shift << endl << endl;
243 return error_show(
"Error in model_shell_radial_profile: No map specified!", __FILE__, __LINE__);
248 error_show(
"Error in model_shell_radial_profile: No map read!", __FILE__, __LINE__);
255 int maxrad = p->
sizeX()/2;
262 for ( ntype=0, ct =
model->
type; ct; ct = ct->
next ) ntype++;
264 if ( ntype < 1 ) ntype = 1;
266 float* r =
new float[ntype*maxrad];
267 float* r2 =
new float[ntype*maxrad];
268 float* w =
new float[ntype*maxrad];
269 for ( i=0; i<ntype*maxrad; i++ ) r[i] = r2[i] = w[i] = 0;
271 for ( ncomp=0, davg=0, comp =
model->
comp; comp; comp = comp->
next, ncomp++ )
275 error_show(
"Error in model_shell_radial_profile: No components!", __FILE__, __LINE__);
280 cout <<
"Calculating a radial profile based on a shell model:" << endl;
281 cout <<
"Radial step size: " << radstep << endl;
282 cout <<
"Average component distance: " << davg << endl << endl;
288 nvec = comp->
loc/radstep;
290 for ( j=0; j<maxrad; j++ ) {
292 vec = nvec*(d+j) + origin;
293 if ( vec[0]>=0 && vec[0]<=p->
sizeX()-2 && vec[1]>=0 && vec[1]<=p->
sizeY()-2 && vec[2]>=0 && vec[2]<=p->
sizeZ()-2 ) {
303 for ( i=0; i<ntype*maxrad; i++ )
if ( w[i] ) {
305 r2[i] = r2[i]/w[i] - r[i]*r[i];
306 if ( r2[i] > 0 ) r2[i] = sqrt(r2[i]);
310 for ( n=0, ct =
model->
type; ct && n<ntype; ct = ct->next, n++ ) {
311 if ( ct ) cout <<
"Component type: " << ct->
id << endl;
312 cout <<
"#\tRadius\tDensity\tSTDev\tWeight" << endl;
313 for ( j=0, i=n*maxrad; j<maxrad; j++, i++ )
314 cout << j <<
tab << j*radstep <<
tab << r[i] <<
tab << r2[i] <<
tab << w[i] << endl;
346 double hires,
double lores)
349 if ( ft_size < 128 ) ft_size = 128;
355 if ( ann_min < 1 ) ann_min = 1;
356 if ( ann_max < 1 ) ann_max = p->
sizeX()/2;
357 if ( ann_max < ann_min ) swap(ann_min, ann_max);
360 if ( hires < 1 ) hires = 2*p->
sampling(0)[0];
361 if ( lores < hires ) swap(hires, lores);
372 int i, j, k, n, jb, nmax(6);
374 int nannuli = p->
sizeX()/2;
376 double cc1, ccbest(0);
403 for ( j=0; j<nmax; j++ ) {
411 int* num =
new int[nmax];
412 float* cc =
new float[nmax];
413 float* ccs =
new float[nmax];
414 float* ccr =
new float[nmax];
416 for ( i=0; i<nmax; i++ ) cc[i] = ccs[i] = ccr[i] = num[i] = 0;
425 cout <<
"Comp\tOrder\tAngle\tCC" << endl;
426 for ( i=0, comp =
model->
comp; i<p->images() && comp; i++, comp = comp->
next ) {
428 for ( j=1; j<nmax; j++ ) {
432 for ( k=1; k<n; k++ ) {
435 shift = pone->
find_shift(pt, NULL, hires, lores, pone->
sizeX()/4, 0, 1, cc1);
441 ori[j] += mat * shift + origin;
444 ccs[j] = ccs[j]/j - cc[j]*cc[j];
445 if ( ccs[j] > 0 ) ccs[j] = sqrt(ccs[j]);
450 ccr[1] = 4*cc[1]/(cc[2]+cc[3]+cc[4]+cc[5]);
451 ccr[2] = 4*cc[2]/(cc[1]+cc[3]+cc[4]+cc[5]);
452 ccr[3] = 3*(cc[1]+cc[3])/(2*(cc[2]+cc[4]+cc[5]));
453 ccr[4] = 4*cc[4]/(cc[1]+cc[2]+cc[3]+cc[5]);
454 ccr[5] = 2*(cc[1]+cc[2]+cc[5])/(3*(cc[3]+cc[4]));
455 for ( j=1, jb=0, ccbest = 1.1; j<nmax; j++ ) {
456 if ( ccbest < ccr[j] ) {
460 cout << cc[j] <<
tab << ccr[j] <<
tab;
483 case 3: comp->color =
RGBA<float>(1,0.5,0,1);
break;
484 case 4: comp->color =
RGBA<float>(0.3,1,0.3,1);
break;
491 cout << comp->id <<
tab << jb+1 <<
tab << comp->view.angle()*180.0/
M_PI <<
tab << pcc << endl;
499 cout <<
"Order\tCount" << endl;
500 for ( j=0; j<nmax; j++ )
501 cout << j+1 <<
tab << num[j] << endl;
504 for ( j=0; j<nmax; j++ )
if ( num[j] ) pref[j]->
multiply(1.0L/num[j]);
515 for ( j=0; j<nmax; j++ )
delete pref[j];
524 for ( i=0; i<pfin->
images(); i++ )
534 if ( minorder < 1 ) minorder = 1;
536 long i, j, k, is(0), is2, xx, nyz(p->
sizeY()*p->
sizeZ()), nf, nb;
537 double v, sf,
sb, mx(0), mx2(0);
540 cout <<
"DEBUG comp_set_fom_sym: comp_id=" << comp->
id << endl;
544 for ( j=0; j<nyz; j++ ) {
545 for ( k=minorder; k<=maxorder; k++ ) {
549 for ( xx=minorder, i+=xx; xx<p->
sizeX()/2; xx++, i++ ) {
550 v = (*p)[i] * sqrt(1.0*xx);
561 if (
sb < 0.001 )
sb = 0.001;
562 if ( sf < 0.001 ) sf = 0.001;
570 for ( k=minorder; k<=maxorder; k++ ) {
571 v = (*psym)[j*psym->
sizeX()+k];
577 for ( k=minorder; k<=maxorder; k++ )
if ( k != is ) {
578 v = (*psym)[j*psym->
sizeX()+k];
586 for ( k=minorder; k<=maxorder; k++ )
if ( k != is && k != is2 ) {
587 v = (*psym)[j*psym->
sizeX()+k];
598 comp->
fom = 1 - mx2/mx;
619 long ann_min,
long ann_max,
long ann_width,
620 long zmin,
long zmax,
long zinc,
long minorder,
long maxorder)
622 if ( ann_width < 1 ) ann_width = ann_max - ann_min;
624 long i, nsym[maxorder+1];
625 double fomsym[maxorder+1], sep(0), sep_avg(0);
636 for ( i=0; i<=maxorder; i++ ) fomsym[i] = nsym[i] = 0;
643 zmin = p->
sizeZ() / 4;
644 zmax = p->
sizeZ() - zmin - 1;
645 zinc = zmax - zmin + 1;
651 cout <<
"Determining cyclic symmetry:" << endl;
652 cout <<
"Maximum order: " << nangles << endl;
653 cout <<
"Number of angles: " << maxorder << endl;
654 cout <<
"Annuli: " << ann_min <<
" - " << ann_max <<
" @ " << ann_width <<
" pixels" << endl;
655 cout <<
"Z limits: " << zmin <<
" - " << zmax <<
" @ " << zinc <<
" pixels" << endl;
659 cout <<
"Model\tComponent\tOrder\tPower\tSeparation" << endl;
660 for ( i=0, mp =
model; mp; mp = mp->
next ) {
662 for ( comp = mp->
comp; comp; comp = comp->
next, i++ ) {
669 if ( ann_width < 1 ) ann_width = ann_max - ann_min;
670 if ( ann_width < 1 ) ann_width = 1;
671 }
else if ( ann_width > 0 ) {
673 ann_max = ann_min + ann_width - 1;
677 ann_width = ann_max - ann_min + 1;
679 pps = pex->
polar_transform(nangles, ann_min, ann_max, ann_width, zmin, zmax, zinc);
688 setprecision(4) << comp->
fom <<
tab << sep << endl;
690 fomsym[comp->
sel] += comp->
fom;
695 if ( i ) sep_avg /= i;
699 for ( i=minorder; i<=maxorder; i++ )
if ( nsym[i]) {
700 fomsym[i] /= nsym[i];
704 cout <<
"Order\tCount\tFOM" << endl;
705 for ( i=minorder; i<=maxorder; i++ )
706 cout << i <<
tab << nsym[i] <<
tab << fomsym[i] << endl;
707 cout <<
"Separation average: " << sep_avg << endl << endl;
int model_catenate_maps(Bmodel *model, Bstring &filename)
Concatenates all model maps into one multi-image file.
void complex_to_intensities()
The intensities from a complex image is written to a simple image.
Matrix3 singular_value_decomposition()
Header file for reading and writing atomic model files.
void set(long j, double v)
Sets a single value at the given index.
string base(string &filename)
int model_shell_fit(Bmodel *model, double hires, double lores, int neg)
Fits a shell model as a rigid body to a map.
int line_powerspectra(fft_plan plan)
Calculates the 1D power spectrum of each line in an image.
int error_show(string message, string file, int line)
Displays the error with file and line reference.
double background(long nn)
Vector3< long > size() const
int transform(Vector3< double > scale, Vector3< double > origin, Vector3< double > translate, Matrix3 mat, int fill_type=0, double fill=0)
Transforms an image by translation, rotation, scaling and skewing, in place.
int comp_type_list_kill(Bcomptype *type)
Deallocates memory for a list of component types.
int find_shift(Bimage *pref, Bimage *pmask, double hires, double lores, double radius, double sigma, int refine_flag)
Calculates a cross-correlation map to find the shift for the pair of images.
Bimage * cartesian_to_cylindrical(long nannuli, long nphi, int flag=0)
Calculates an image with cylindrical coordinates.
int rotate_and_add(Bimage *p, Vector3< double > origin, View view)
Rotates an image to a specified view and adds it to another image.
Library routines for single particle analysis.
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.
void add(long j, double v)
int fft_destroy_plan(fft_plan plan)
Deallocates a plan for fast Fourier transforms.
General image parameter class.
Bmodel * model_from_images(Bimage *plist)
Creates one or more models from 3D images.
int center_wrap()
Centers an image with wrapping.
Header file for general utilities.
ostream & tab(ostream &out)
double interpolate(long cc, double xx, double yy=0, double zz=0, long nn=0, double fill=0) const
Interpolates using a given location.
fft_plan fft_setup_plan(long x, long y, long z, fft_direction dir, int opt)
Sets up a plan for fast Fourier transforms.
void origin(double ox, double oy, double oz)
void change_type(char letter)
Get the data type indicated by a single letter code.
long index(long nx, long ny) const
Header file for 2D and 3D image I/O.
Bimage * polar_transform(long nangles, long ann_min, long ann_max, long dann, long zmin, long zmax, long zinc)
Calculates an image with cylindrical coordinates by integration.
Bimage * model_shell_power_spectrum(Bmodel *model, Vector3< long > size, Vector3< double > origin, int ft_size, int ann_min, int ann_max, double hires, double lores)
Calculates a radial profile from a shell model.
Bimage * extract(long nn)
Extracts one sub-image into new image structure.
void catenate(long m, Bimage **p)
Catenates an array of images of the same size into a multi-image structure.
Bmodel * model_add(Bmodel **model, Bstring &id)
Adds a model to a linked list.
void invert()
Inverts the data in the image.
Bcomptype * model_add_type_by_id(Bmodel *model, Bstring &id)
Add a type to a model if the identifier does not exist already.
int pad(long sz, int fill_type=0, double fill=0)
Pads an image to a new size with a given fill value.
Header file for combining two images in various ways.
void sampling(long nn, Vector3< double > u)
Bimage * img_from_model(Bmodel *model, Vector3< double > ori, Vector3< long > size, Vector3< double > sam, double sigma)
Calculates a map from model component coordinates.
int model_shell_radial_profile(Bmodel *model)
Calculates a radial profile from a shell model.
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.
int model_component_symmetry(Bmodel *model, long nangles, long ann_min, long ann_max, long ann_width, long zmin, long zmax, long zinc, long minorder, long maxorder)
Determines the cyclic symmetry of components.
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
int findNextPowerOf(int startNumber, int powerOf)
Finds the next greatest number that is a power of a given number.
int comp_set_fom_sym(Bcomponent *comp, Bimage *p, long minorder, long maxorder)
double correlate_annuli(Bimage *polref, int ann_min, int ann_max, double ang_min, double ang_max, fft_plan planf, fft_plan planb, double &cc_max)
Correlate annuli of a polar image.
Bimage * img_catenate(Bstring *file_list, Bstring &rawstring, DataType newdatatype, Vector3< long > nusize, int setZslices=0, int fill_type=0, double fill=0, double newavg=0, double newstd=0)
Catenates a list of images into a multi-image structure.