22 int rotation_axis,
int back_flag,
int mask_width);
39 char format[32] =
"%03d";
43 cout <<
"DEBUG particle_setup_filenames: base=" << filename << endl;
46 if ( !partpath.
empty() )
47 if ( partpath[-1] ==
'/' ) partpath = partpath.
truncate(1);
48 n = partpath.
count(
'?');
50 partpath = partpath.
remove(
'?');
51 snprintf(format, 32,
"%%0%ldd", n);
54 cout <<
"DEBUG particle_setup_filenames: path=" << partpath << endl;
58 for ( ; part; part = part->
next ) {
59 if ( partpath.
length() > 1 ) {
60 if ( n < 1 ) path = partpath;
61 else path = partpath +
Bstring(part->
id, format);
62 part->
fpart = path +
"/" + filename;
63 }
else part->
fpart = filename;
64 mkdir(path.
c_str(), (mode_t)0755);
68 cout <<
"DEBUG particle_setup_filenames: id=" << part->
id <<
" path=" << part->
fpart << endl;
89 char format[32] =
"%03d";
93 if ( !filpath.
empty() )
94 if ( filpath[-1] ==
'/' ) filpath = filpath.
truncate(1);
95 n = filpath.
count(
'?');
97 filpath = filpath.
remove(
'?');
98 snprintf(format, 32,
"%%0%ldd", n);
101 cout <<
"DEBUG filament_setup_filenames: path=" << filpath << endl;
105 for ( ; fil; fil = fil->
next ) {
106 if ( filpath.
length() > 1 ) {
107 if ( n < 1 ) path = filpath;
108 else path = filpath +
Bstring(fil->
id, format);
109 fil->
ffil = path +
"/" + filename;
110 }
else fil->
ffil = filename;
111 mkdir(path.
c_str(), (mode_t)0755);
133 for ( n=0, fn = fnode; fn; fn=fn->
next ) n++;
137 for ( n=0, fn = fnode; fn; fn=fn->
next, n++ ) coords[n] = fn->
loc;
162 int back_flag,
int norm_flag,
int fill_type,
double fill,
int mask_width,
172 if ( !partpath.
empty() )
if ( partpath[-1] !=
'/' ) partpath +=
"/";
174 if ( partext.
length() < 1 ) partext =
"mrc";
183 else if ( field && field->
mg ) size = field->
mg->
box_size;
184 if ( size.
volume() < 1 ) {
185 cerr <<
"Error in project_extract_particles: Box size = " << size << endl;
190 cout <<
"Extracting particles:" << endl;
191 cout <<
"Particle size: " << size << endl;
192 cout <<
"Particle scale: " << scale << endl;
194 cout <<
"Filament mask width: " << mask_width << endl;
195 if ( back_flag ) cout <<
"With background correction" << endl;
196 if ( norm_flag ) cout <<
"With normalization" << endl;
198 cout <<
"Particle base name: " << partbase << endl;
200 cout <<
"Particle extension: " << partext << endl;
202 cout <<
"Particle path: " << partpath << endl;
204 cout <<
"Projecting" << endl;
210 for ( mg=field->
mg; mg; mg=mg->
next, i++ ) {
212 if ( mg->
fmg == mg->
next->
fmg ) multi_img = 1;
218 if ( partbase.
length() ) {
222 filename = partbase +
Bstring(i,
"_%03d");
228 if ( multi_img ) filename = filename +
Bstring(mg->
img_num+1,
"_part%03d");
229 else filename = filename +
"_part";
232 filename = filename +
"_fil";
235 if ( filename.
length() < 1 )
236 cerr <<
"Error in project_extract_particles: No particle file name!" << endl;
237 filename = filename +
"." + partext;
238 if ( partpath.
length() > 1 ) {
240 filename = partpath + filename;
246 mg->
fpart = filename;
247 if ( partpath.
length() > 1 ) mkdir(partpath.
c_str(), (mode_t)0755);
271 if ( partbase.
length() ) {
275 filename = partbase +
Bstring(i,
"_%03d");
283 filename = filename +
"_part";
286 filename = filename +
"_fil";
289 if ( filename.
length() < 1 )
290 cerr <<
"Error in project_extract_particles: No particle file name!" << endl;
291 filename = filename +
"." + partext;
292 if ( partpath.
length() > 1 ) {
294 filename = partpath + filename;
300 rec->
fpart = filename;
301 if ( partpath.
length() > 1 ) mkdir(partpath.
c_str(), (mode_t)0755);
353 int back_flag,
int norm_flag,
double fill,
int mask_width)
357 if ( npart < 1 )
return 0;
360 cout << mg->
id <<
tab << npart << endl;
365 scale, mg->
bad_radius, back_flag, norm_flag, fill, mask_width);
387 int back_flag,
int norm_flag,
double fill,
int mask_width)
391 if ( npart < 1 )
return 0;
394 cout << rec->
id <<
tab << npart << endl;
399 scale, rec->
bad_radius, back_flag, norm_flag, fill, mask_width);
424 int back_flag,
int norm_flag,
double fill,
int mask_width)
428 if ( npart < 1 )
return 0;
431 cout << rec->
id <<
tab << npart << endl;
445 for ( part = part2D; part; part = part->
next )
449 scale, rec->
bad_radius, back_flag, norm_flag, fill, mask_width);
452 for ( part = part2D; part; part = part->
next ) {
493 int back_flag,
int norm_flag,
double fill,
int mask_width)
498 if ( scale < 0.1 ) scale = 1;
502 long id, i, j, k, c, n, x, y, z;
503 long oldx, oldy, oldz, oldn(0);
504 double d(0), dh(0), halfwidth(mask_width/2.0), ori_tol;
505 double iscale(1/scale);
517 if ( npart < 1 )
return NULL;
523 if ( pixel_size[0] < 0.01 ) pixel_size = p->
image->
sampling();
525 if ( pixel_size[0] < 0.01 ) {
526 cerr <<
"Error in particle_extract: Pixel size is too small! " << pixel_size << endl;
530 pixel_size *= iscale;
532 box = box.
min(p->
size()*scale);
535 ori_tol = radius.
length()/4;
536 if ( ori_tol > 2 ) ori_tol = 2;
539 cerr <<
"Error: Particle box size is zero!" << endl;
543 if ( box[2] == 1 ) pixel_size[2] = 1;
546 cout <<
"Extracting " << npart <<
" particles from " << p->
file_name() << endl;
549 cout <<
"Number of particles: " << npart << endl;
550 cout <<
"Particle box size: " << box << endl;
551 cout <<
"Particle scale: " << scale << endl;
552 cout <<
"Particle radii: " << radius << endl;
553 cout <<
"Bad region radius: " << bad_radius << endl;
554 cout <<
"Mask width: " << mask_width << endl;
555 cout <<
"Fill value: " << fill << endl;
556 if ( back_flag ) cout <<
"Background corrected" << endl;
557 if ( norm_flag ) cout <<
"Normalized" << endl;
561 if ( bad_areas && bad_radius > 1 ) {
563 for ( bad = bad_areas; bad; bad = bad->
next )
575 for (
id=1, i=n=0, part = particles; part; part = part->
next, n++,
id++ ) {
589 u[0] = cos(euler.
psi());
590 u[1] = -sin(euler.
psi());
591 for ( z=0; z<ppart->
sizeZ(); z++ ) {
592 oldz = (z - radius[2])*iscale + (
long) part->
loc[2];
594 for ( y=0; y<ppart->
sizeY(); y++ ) {
595 oldy = (y - radius[1])*iscale + (
long) part->
loc[1];
597 for ( x=0; x<ppart->
sizeX(); x++, i++ ) {
598 oldx = (x - radius[0])*iscale + (
long) part->
loc[0];
600 if ( oldx >= 0 && oldx < p->sizeX() && oldy >= 0 && oldy < p->
sizeY() && oldz >= 0 && oldz < p->
sizeZ()) {
602 if ( halfwidth > 0 ) dh = (u.
cross(v)).
length() - halfwidth;
603 if ( back_flag ) d = (v/ppart->
size()).
length() - 0.5;
605 if ( ( pmask && (*pmask)[j] > 0 ) || ( d > 0 ) || ( dh > 0 ) ) {
609 ppart->
set(k++, p->
average(c, oldx, oldy, oldz, oldn, iscale));
614 ppart->
set(k++, p->
average(c, oldx, oldy, oldz, oldn, iscale));
648 for ( n=0, part = particles; part; part = part->
next, n++ ) {
704 long i, j, c, n, x, y, z;
705 long oldx, oldy, oldz;
712 if ( nmark < 1 )
return NULL;
714 iradius[0] = iradius[1] = iradius[2] = (int)(2*radius);
715 box[0] = box[1] = box[2] = (int)(4*radius);
716 if ( p->
sizeZ() < 2 ) {
722 cout <<
"Extracting " << nmark <<
" markers from image " << p->
file_name()
723 <<
" (" << img_num <<
") with box size " << box << endl;
729 pmark->
origin(n, iradius);
730 for ( z=0; z<pmark->
sizeZ(); z++ ) {
731 oldz = z - iradius[2] + (int) mark->
loc[2];
732 for ( y=0; y<pmark->
sizeY(); y++ ) {
733 oldy = y - iradius[1] + (int) mark->
loc[1];
734 for ( x=0; x<pmark->
sizeX(); x++ ) {
735 oldx = x - iradius[0] + (int) mark->
loc[0];
736 if ( oldx >= 0 && oldx < p->sizeX() && oldy >= 0 && oldy < p->
sizeY() && oldz >= 0 && oldz < p->
sizeZ()) {
739 for ( c=0; c<p->
channels(); c++, i++, j++ ) pmark->
set(i, (*p)[j]);
776 if ( path.
length() && access(path.
c_str(), F_OK) ) {
777 cerr <<
"Error: The directory " << path <<
" must exist to extract filaments!" << endl;
781 if ( !path.
empty() )
if ( path[-1] !=
'/' ) path +=
"/";
783 if ( ext.
length() < 1 ) ext =
"mrc";
790 cout <<
"Extracting filaments from micrographs" << endl << endl;
792 for ( mg = field->
mg; mg; mg = mg->
next, i++ ) {
795 if (
base.length() ) {
806 filename = filename +
"." + ext;
807 if ( filename.
length() < 1 )
808 cerr <<
"Error in project_extract_filaments: No filament file name!" << endl;
815 filename = path +
"/" + filename;
828 cout <<
"Extracting filaments from reconstructions" << endl << endl;
832 if (
base.length() ) {
841 filename = filename +
"_fil.";
843 filename = filename +
"." + ext;
844 if ( filename.
length() < 1 )
845 cerr <<
"Error in project_extract_filaments: No filament file name!" << endl;
852 filename = path +
"/" + filename;
854 rec->
ffil = filename;
936 if ( axis < 1 || axis > 3 ) {
937 if ( p->
sizeZ() > 1 ) axis = 3;
945 long nfil(1), nspline;
953 if ( p->
sizeX() < width ) size[0] = p->
sizeX();
954 if ( p->
sizeY() < width ) size[1] = p->
sizeY();
955 if ( p->
sizeZ() < width ) size[2] = p->
sizeZ();
958 for ( nfil=0, fil=filaments; fil; fil=fil->
next ) {
963 size[axis-1] = (int) maxlen;
970 cout <<
"DEBUG filament_extract: size=" << size << endl;
971 cout <<
"DEBUG filament_extract: axis=" << axis <<
" split=" <<
split << endl;
974 for ( n=0, fil=filaments; fil; fil=fil->
next, n++ ) {
981 else cerr <<
"Error: No filename for filament " << fil->
id << endl;
1007 double boxing_interval,
double rise,
double angle)
1016 for ( mg=field->
mg; mg; mg=mg->
next )
1041 double boxing_interval,
double rise,
double angle)
1043 if ( box_size[0] < 1 ) box_size[0] = 40;
1044 if ( box_size[1] < 1 ) box_size[1] = box_size[0];
1048 if ( boxing_interval < 1 ) boxing_interval = box_size[0]/2;
1051 cout <<
"DEBUG micrograph_filaments_to_particles: box_size=" << mg->
box_size << endl;
1077 double boxing_interval,
double rise,
double angle)
1079 if ( box_size[0] < 1 ) box_size[0] = 40;
1080 if ( box_size[1] < 1 ) box_size[1] = box_size[0];
1081 if ( box_size[2] < 1 ) box_size[2] = box_size[0];
1084 if ( boxing_interval < 1 ) boxing_interval = box_size[0]/2;
1087 cout <<
"DEBUG micrograph_filaments_to_particles: box_size=" << rec->
box_size << endl;
1115 double boxing_interval,
double rise,
double angle)
1117 long i, n(1), nspline, it, nfil(0);
1124 double bi, dr(rise/pixel_size[0]), phi(0), st, t, od(0);
1127 cout <<
"Converting filaments to particles:" << endl;
1128 cout <<
"Box size: " << box_size << endl;
1129 cout <<
"Boxing interval: " << boxing_interval << endl;
1130 cout <<
"Helical rise and angle: " << rise <<
" A " << angle <<
" degrees" << endl << endl;
1133 for ( fil=filaments; fil; fil=fil->
next ) {
1136 for ( bi=0; bi<nspline; bi += boxing_interval, n++ ) {
1137 i = (int) (bi + 0.5);
1139 if ( !part_list ) part_list = part;
1141 part->
loc = spline[i];
1142 part->
ori = box_size/2;
1143 if ( i == 0 ) dir = spline[1] - spline[0];
1144 else dir = spline[i] - spline[i-1];
1145 st = sqrt(1 - dir[2]*dir[2]);
1148 it = (int) (t + 0.5);
1151 part->
ori -= dir*od;
1161 cout <<
"DEBUG filaments_to_particles: npart=" << n << endl;
1185 for ( mg=field->
mg; mg; mg=mg->
next )
1209 int rotation_axis,
int back_flag,
int mask_width)
1213 if ( rotation_axis < 1 || rotation_axis > 3 )
return 0;
1223 cout <<
"Rotating and masking filament particles:" << endl;
1224 cout <<
"Rotation axis: " << (char) (119+rotation_axis) << endl;
1225 cout <<
"Mask width: " << mask_width << endl;
1226 if ( back_flag ) cout <<
"With background correction" << endl;
1232 for ( mg=field->
mg; mg; mg=mg->
next )
1234 rotation_axis, back_flag, mask_width);
1238 rotation_axis, back_flag, mask_width);
1259 double d, halfwidth = mask_width/2.0;
1268 for ( n=0, part = partlist; part; part = part->
next, n++ ) {
1270 u[0] = cos(euler.
psi());
1271 u[1] = -sin(euler.
psi());
1272 for ( i=n*imagesize, z=0; z<p->
sizeZ(); z++ ) {
1274 for ( y=0; y<p->
sizeY(); y++ ) {
1276 for ( x=0; x<p->
sizeX(); x++, i++ ) {
1307 int rotation_axis,
int back_flag,
int mask_width)
1310 long i, j, n, x, y, z;
1311 double d(0), dx(0), dy(0), dz(0), halfwidth;
1318 error_show(
"Error in rotate_mask_filament_particles: No image!", __FILE__, __LINE__);
1325 halfwidth = mask_width/2.0;
1329 for ( n=0, part = partlist; part; part = part->
next, n++ ) {
1333 euler[1] = euler[2] = 0;
1334 if ( rotation_axis == 2 ) euler[0] +=
M_PI_2;
1338 for ( i=n*imagesize, j=0, z=0; z<p->
sizeZ(); z++ ) {
1339 if ( p->
sizeZ() > 1 ) {
1343 for ( y=0; y<p->
sizeY(); y++ ) {
1345 if ( p->
sizeZ() > 1 ) dy *= dy;
1346 for ( x=0; x<p->
sizeX(); x++, i++, j++ ) {
1348 if ( p->
sizeZ() < 2 ) {
1349 if ( rotation_axis == 2 ) d = dx;
1353 d = sqrt(dx + dy + dz);
1356 else p->
set(i, (*pex)[j]);