| Bsoft 2.0.5 Bernard's software package

mg_multislice.cpp
Go to the documentation of this file.
1
9 #include "mg_processing.h"
10 #include "mg_ctf.h"
11 #include "molecule_to_map.h"
12 #include "mol_transform.h"
13 #include "mol_edit.h"
14 #include "Complex.h"
15 #include "Vector3.h"
16 #include "linked_list.h"
17 #include "random_numbers.h"
18 #include "utilities.h"
19
20 // Declaration of global variables
21 extern int verbose; // Level of output to the screen
22
32 Bimage* img_calc_wave_propagator(Vector3<long> size, Vector3<double> sam,
33 double thickness, double volt, double resolution)
34 {
35 Bimage* p = new Bimage(Float, TComplex, size[0], size[1], 1, 1);
36 p->sampling(sam);
37 if ( resolution < sam[0] || resolution > 1000 )
38 resolution = sam[0];
39
40 long i, h, k, x, y;
41 double wavelength = electron_wavelength(volt);
42 double arg, sx2, sy2, s2;
43 double afactor = M_PI*wavelength*thickness;
44 double nfactor = 1.0/(p->sizeX()*p->sizeY()); // Normalization for passing through FFT's
45 double resmax2 = 1.0/(resolution*resolution);
46 double xscale2 = 1.0/(p->sizeX()*p->sizeX()*sam[0]*sam[0]);
47 double yscale2 = 1.0/(p->sizeY()*p->sizeY()*sam[1]*sam[1]);
48
49 for ( y=0; y<p->sizeY(); y++ ) {
50 k = y;
51 if ( k > (p->sizeY()-1)/2 ) k -= p->sizeY();
52 sy2 = k*k*yscale2;
53 if ( sy2 <= resmax2 ) for ( x=0; x<p->sizeX(); x++ ) {
54 h = x;
55 if ( h > (p->sizeX()-1)/2 ) h -= p->sizeX();
56 sx2 = h*h*xscale2;
57 s2 = sx2 + sy2;
58 if ( s2 <= resmax2 ) {
59 i = y*p->sizeX() + x;
60 arg = afactor*s2;
61 p->set(i, Complex<double>(cos(arg), sin(arg)) * nfactor);
62 }
63 }
64 }
65
66 // write_img("propagator.map", p);
67
68 return p;
69 }
70
89 Bimage* img_calc_multi_slice(Bimage* pgrate, double thickness, double volt, double resolution)
90 {
91 Vector3<long> size(pgrate->size());
92
93 // wavelength & size - loop one slice -> propagator (one 2D image)
94 Bimage* prop = img_calc_wave_propagator(size, pgrate->sampling(0), thickness, volt, resolution);
95
96 // For all slices: Multiply previous exitwave with phasegrating - FFT -
97 // multiply with propagator - FFT-1 - next slice -> exitwave (one 2D image)
98 long i;
99 Bimage* p = new Bimage(Float, TComplex, size[0], size[1], 1, 1);
100 p->label(pgrate->label());
101 p->fourier_type(NoTransform);
102 p->origin(pgrate->image->origin());
103 p->sampling(pgrate->sampling());
104
105 long slice_size = size[0]*size[1];
106 Complex<double> cv(1);
107 for ( i=0; i<slice_size; i++ ) p->set(i, cv);
108
109 Bimage* ptemp;
110 for ( i=0; i<pgrate->images(); i++ ) {
111 ptemp = pgrate->extract(i); // Get phase grating slice
112 p->complex_product(ptemp); // Multiply with current wave
113 delete ptemp;
114 p->fft(FFTW_FORWARD, 0); // Normalization in propagator
115 if ( i < pgrate->images()-1 ) {
116 p->complex_product(prop); // Multiply with propagator
117 p->fft(FFTW_BACKWARD, 0); // Normalization in propagator
118 }
119 }
120
121 delete prop;
122
123 return p;
124 }
125
139 Bimage* img_calc_potential(Bmolgroup* molgroup, Vector3<long> size, Vector3<double> origin,
140 Vector3<double> sam, double thickness, double resolution, double Bfactor,
141 Bstring& paramfile, int type)
142 {
143 // Atoms & scat cross-sections - Loop slices - calc 2D reciprocal space structure factors
144 long i, j, k;
145 int nslices(0);
146 Bmolgroup** slice_molgroup = molgroup_split_into_slices(molgroup, thickness, nslices);
147
148 if ( verbose )
149 cout << "Calculating the atomic potential" << endl;
150
151 int spacegroup(0);
152 UnitCell unit_cell(sam[0]*size[0],sam[1]*size[1],sam[2]*size[2],M_PI_2,M_PI_2,M_PI_2);
153 Bimage* ptemp = NULL;
154 Bimage* p = new Bimage(Float, TComplex, size[0], size[1], 1, nslices);
155 long imgsize = p->sizeX()*p->sizeY()*p->channels();
156 p->label(molgroup->comment.str());
157 p->unit_cell(unit_cell);
158 p->sampling(sam[0], sam[1], thickness);
159 p->space_group(spacegroup);
160
161 for ( i=0; i<nslices; i++ ) {
162 if ( type ) {
163 origin[2] = -slice_molgroup[i]->min[2]/sam[2] - 0.5;
164 size[2] = (int) (thickness/sam[2] + 1);
165 ptemp = img_from_molecule(slice_molgroup[i], origin, size, sam,
166 resolution, 0.001, 0, 2 - type, spacegroup, unit_cell);
167 // img_project(ptemp);
168 ptemp->project('z', 1);
169 ptemp->simple_to_complex();
170 } else {
171 // origin[2] = -slice_molgroup[i]->min[2]/sam[2] - 0.5;
172 // origin[2] = -i*thickness;
173 // origin[2] = 0;
174 size[2] = 1;
175 sam[2] = thickness;
176 ptemp = img_sf_from_molecule(slice_molgroup[i], origin, size, sam,
177 resolution, spacegroup, unit_cell, 2, Bfactor, paramfile);
178 ptemp->fft(FFTW_BACKWARD, 0); // No normalization - get actual potential at the beam
179 }
180 for ( j=0, k=i*imgsize; j<imgsize; j++, k++ ) p->set(k, (*ptemp)[j]);
181 delete ptemp;
182 p->origin(i, origin);
183 if ( verbose )
184 cout << "Slice " << i+1 << " done" << endl << endl;
185 }
186
187 p->fourier_type(NoTransform);
188
189 for ( i=0; i<nslices; i++ )
190 molgroup_kill(slice_molgroup[i]);
191
192 delete[] slice_molgroup;
193
194 return p;
195 }
196
206 int img_calc_phase_grating(Bimage* p, double volt)
207 {
208 p->simple_to_complex();
209
210 long i, j, n;
211 long imgsize = p->sizeX()*p->sizeY();
212 double wavelength = electron_wavelength(volt);
213 double arg;
214 double sigma = 0.0208886 * wavelength *
215 sqrt(1 + 5.8886579e-4/(wavelength*wavelength)); // According to Roar Kilaas
216
217 if ( verbose & VERB_FULL )
218 cout << "Sigma (interaction factor): " << sigma << endl;
219
220 for ( i=n=0; n<p->images(); n++ ) {
221 for ( j=0; j<imgsize; i++, j++ ) {
222 arg = -sigma*(p->complex(i)).real();
223 p->set(i, Complex<double>(cos(arg), sin(arg)));
224 }
225 }
226
227 return 0;
228 }
229
252 int img_apply_complex_CTF(Bimage* p, double def_avg, double def_dev, double ast_angle,
253 double volts, double Cs, double Cc, double amp_shift, double alpha, double energy_spread)
254 {
255
256 long i, n, x, y, z;
257 double xx, yy, zz, sx2, sy2, sz2, s, s2, defocus, dphi, env, arg;
258 // double phi_fac = sqrt(1-amp_fac*amp_fac);
259 double lambda = electron_wavelength(volts);
260 double hpil3Cs = M_PI_2*lambda*lambda*lambda*Cs;
261 double pil = M_PI*lambda;
262 double pialf = M_PI*alpha;
263 double Csl2 = Cs*lambda*lambda;
264 double focus_spread = Cc*energy_spread;
265 double pi2l2df2 = M_PI*M_PI*lambda*lambda*focus_spread*focus_spread/(16.0*log(2.0));
266 Complex<double> ctf;
267 Vector3<double> freq_scale(1.0/p->real_size());
268
269 if ( verbose & ( VERB_LABEL | VERB_PROCESS ) )
270 cout << "Applying a CTF to a complex Fourier transform" << endl;
271
272 if ( verbose & VERB_PROCESS ) {
273 cout << "Defocus average & deviation: " << def_avg << " A " << def_dev << " A" << endl;
274 cout << "Astigmatism angle: " << ast_angle*180/M_PI << " degrees" << endl;
275 cout << "Voltage: " << volts << " V" << endl;
276 cout << "Wavelength: " << lambda << endl;
277 cout << "Cs: " << Cs << " A" << endl;
278 cout << "Cc: " << Cc << " A" << endl;
279 cout << "Amplitude contrast phase shift: " << amp_shift << endl;
280 cout << "Beam source size: " << alpha << " radians" << endl;
281 cout << "Energy spread (focus spread): " << energy_spread << " (" << focus_spread << " A)" << endl << endl;
282 }
283
284 for ( i=n=0; n<p->images(); n++ ) {
285 for ( z=0; z<p->sizeZ(); z++ ) {
286 zz = z;
287 if ( z > (p->sizeZ() - 1)/2 ) zz -= p->sizeZ();
288 sz2 = freq_scale[2]*zz;
289 sz2 *= sz2;
290 for ( y=0; y<p->sizeY(); y++ ) {
291 yy = y;
292 if ( y > (p->sizeY() - 1)/2 ) yy -= p->sizeY();
293 sy2 = freq_scale[1]*yy;
294 sy2 *= sy2;
295 for ( x=0; x<p->sizeX(); x++, i++ ) {
296 xx = x;
297 if ( x > (p->sizeX() - 1)/2 ) xx -= p->sizeX();
298 sx2 = freq_scale[0]*xx;
299 sx2 *= sx2;
300 s2 = sx2 + sy2 + sz2;
301 s = sqrt(s2);
302 defocus = def_avg + def_dev*cos(2*(atan2(yy,xx)-ast_angle));
303 dphi = (hpil3Cs*s2 - pil*defocus)*s2 - amp_shift;
304 arg = pialf*(Csl2*s2 - defocus)*s;
305 // arg = pialf*defocus*s;
306 arg = arg*arg + pi2l2df2*s2*s2;
307 env = exp(-arg);
308 //env=1;//dphi -= arg*arg;
309 ctf = Complex<double>(cos(dphi), sin(dphi));
310 p->set(i, ((*p)[i] * ctf) * env);
311 }
312 }
313 }
314 }
315
316 return 0;
317 }
318
344 Bproject* project_generate(int nfield, int nmg, int npart, double pixel_size, double img_origin,
345 double volt, double Cs, double Cc, double alpha, double energy_spread,
346 double amp_shift, double def_min, double def_max, double dose,
347 double tsigma, Bstring& fieldbase, Bstring& mgbase, Bstring& partbase,
348 int fieldnumber, int mgnumber, int partnumber)
349 {
350 random_seed();
351
352 double def_range = def_max - def_min;
353 if ( def_range < 0 ) def_range = 0;
354
355 int i, j, k, block = 0;
356 double irm = 1.0/get_rand_max(), irm2 = 2*irm;
357 Vector3<float> t;
358 View* v = new View[npart];
359 Bproject* project = project_init();
360 Bfield* field = NULL;
361 Bmicrograph* mg = NULL;
362 Bparticle* part = NULL;
363 Bstring field_id, mg_id;
364
365 if ( verbose ) {
366 cout << "Generating a new project:" << endl;
367 cout << "Number of fields: " << nfield << endl;
368 cout << "Number of micrographs: " << nmg << endl;
369 cout << "Number of particles: " << npart << endl;
370 }
371
372 for ( i=0; i<nfield; i++ ) {
373 field_id = fieldbase + Bstring(fieldnumber, "_%06d");
374 if ( project->field ) field = field_add(&field, field_id);
375 else field = field_add(&project->field, field_id);
376 for ( k=0; k<npart; k++ ) {
377 v[k] = View(random()*irm2 - 1, random()*irm2 - 1, random()*irm2 - 1, M_PI*(random()*irm2 - 1));
378 v[k].normalize();
379 }
380 for ( j=0; j<nmg; j++ ) {
381 mg_id = mgbase + Bstring(fieldnumber, "_%03d") + Bstring(mgnumber, "_%03d");
382 if ( field->mg ) mg = micrograph_add(&mg, mg_id);
383 else mg = micrograph_add(&field->mg, mg_id);
384 mg->block = block;
385 block++;
386 mg->fpart = partbase + Bstring(fieldnumber, "_%03d") + Bstring(mgnumber, "_%03d.spi");
387 if ( !mg->ctf ) mg->ctf = new CTFparam;
388 mg->ctf->defocus_average(def_range*random()*irm + def_min);
389 mg->ctf->volt(volt);
390 mg->ctf->Cs(Cs);
391 mg->ctf->Cc(Cc);
392 mg->ctf->alpha(alpha);
393 mg->ctf->dE(energy_spread);
394 mg->ctf->amp_shift(amp_shift);
395 mg->pixel_size = pixel_size;
396 mg->dose = dose;
397 mg->box_size[0] = mg->box_size[1] = (int) (2*img_origin);
398 mg->box_size[2] = 1;
399 mg->ctf->zero(1);
400 mg->ctf->baseline(0, 1);
401 mg->ctf->envelope(0, 3);
402 mg->ctf->envelope(1, -M_PI*M_PI*mg->ctf->alpha()*mg->ctf->alpha()*mg->ctf->defocus_average()*mg->ctf->defocus_average());
403 for ( k=0; k<npart; k++ ) {
404 if ( mg->part ) part = particle_add(&part, k+partnumber);
405 else part = particle_add(&mg->part, k+partnumber);
406 if ( tsigma > 0 ) t = vector3_xy_random_gaussian(0.0, (double)tsigma);
407 part->view = v[k];
408 part->loc[0] = part->loc[1] = img_origin;
409 part->ori = t + img_origin;
410 part->ori[2] = 0;
411 }
412 mgnumber++;
413 }
414 fieldnumber++;
415 }
416
417 delete[] v;
418
419 return project;
420 }
421
441 Bproject* project_generate_asu(Bstring& symmetry_string, double pixel_size, double img_origin,
442 double theta_step, double phi_step,
443 double volt, double Cs, double Cc, double alpha, double energy_spread,
444 double amp_shift, double defocus, double dose, Bstring& mgbase, Bstring& partbase)
445 {
446 int k, npart;
447 Bproject* project = project_init();
448 Bfield* field = NULL;
449 Bmicrograph* mg = NULL;
450 Bparticle* part = NULL;
451
452 Bsymmetry* sym = init_point_group_symmetry(symmetry_string);
453 View* view = asymmetric_unit_views(sym, theta_step, phi_step, 0);
454 View* v;
455 for ( v=view, npart=0; v; v=v->next ) npart++;
456
457 field = field_add(&project->field, mgbase);
458 mg = micrograph_add(&field->mg, mgbase);
459 mg->block = 0;
460 mg->fpart = partbase + ".spi";
461 if ( !mg->ctf ) mg->ctf = new CTFparam;
462 mg->ctf->defocus_average(defocus);
463 mg->ctf->volt(volt);
464 mg->ctf->Cs(Cs);
465 mg->ctf->Cc(Cc);
466 mg->ctf->alpha(alpha);
467 mg->ctf->dE(energy_spread);
468 mg->ctf->amp_shift(amp_shift);
469 mg->pixel_size = pixel_size;
470 mg->dose = dose;
471 mg->box_size[0] = mg->box_size[1] = (int) (2*img_origin);
472 mg->box_size[2] = 1;
473 for ( k=0, v=view; k<npart && v; k++, v=v->next ) {
474 if ( mg->part ) part = particle_add(&part, k+1);
475 else part = particle_add(&mg->part, k+1);
476 part->view = *v;
477 part->loc = part->ori = Vector3<float>(img_origin, img_origin, 0);
478 }
479
480 kill_list((char *) view, sizeof(View));
481 kill_symmetry(sym);
482
483 return project;
484 }
485
502 int project_generate_potential(Bmolgroup* molgroup, Bmolgroup* water, Bproject* project,
503 Bstring& fieldname, Bstring& mgname, int partselect,
504 Vector3<long> size, double thickness, double resolution,
505 double Bfactor, int pottype, Bstring& paramfile)
506 {
507 random_seed();
508
509 Vector3<double> sam, box;
510 sam[0] = sam[1] = sam[2] = project->field->mg->pixel_size;
511 if ( resolution < 2*project->field->mg->pixel_size )
512 resolution = 2*project->field->mg->pixel_size;
513
514 if ( size.volume() < 1 ) {
515 size[0] = (long) (molgroup->box[0]/sam[0]);
516 size[1] = (long) (molgroup->box[1]/sam[1]);
517 size[2] = (long) (molgroup->box[2]/sam[2]);
518 }
519 if ( water ) {
520 if ( molgroup->box.length2() < water->box.length2() ) {
521 size[0] = (long) (water->box[0]/sam[0]);
522 size[1] = (long) (water->box[1]/sam[1]);
523 size[2] = (long) (water->box[2]/sam[2]);
524 }
525 box = sam * size;
526 water->box = Vector3<float>(box[0], box[1], box[2]);
527 }
528 box = sam * size;
529 molgroup->box = Vector3<float>(box[0], box[1], box[2]);
530
531 Vector3<double> sampling3(sam[0], sam[1], sam[2]);
532
533 if ( verbose )
534 cout << "Simulation box: " << molgroup->box << " = " << molgroup->box.volume() << " A^3" << endl;
535
536 int j;
537 Bfield* field = NULL;
538 Bmicrograph* mg = NULL;
539 Bparticle* part = NULL;
540 Bmolgroup* mol_rot = NULL;
541 Bmolgroup* mol_sim = NULL;
542 Bimage *ppot;
543 Bstring potname;
544 double ranshift = molgroup->box[0];
545 Vector3<float> t, rot_ori;
546 Vector3<double> ori;
547
548 for ( field = project->field; field; field = field->next )
549 if ( fieldname.length() < 1 || field->id == fieldname ) {
550 if ( verbose )
551 cout << "Calculating potentials for field " << field->id << endl;
552 for ( mg = field->mg; mg; mg = mg->next )
553 if ( mgname.length() < 1 || mg->id == mgname ) {
554 if ( verbose )
555 cout << "Calculating potentials for micrograph " << mg->id << endl;
556 for ( part = mg->part; part; part = part->next )
557 if ( partselect < 1 || part->id == partselect ) {
558 // potname = number_filename(mg->fpart, part->id, 3);
559 potname = mg->fpart;
560 potname = potname.pre_rev('.') + Bstring(part->id, "_%03d.") + potname.post_rev('.');
561 if ( access(potname.c_str(), F_OK) != 0 ) { // Skip if the file already exists
562 if ( verbose )
563 cout << "Calculating potentials for particle " << part->id << endl;
564 t = (part->ori - part->loc) * sampling3;
565 // cout << "origin=" << origin << " shift=" << t << endl;
566 mol_rot = molgroup_rotate_from_view(molgroup, part->view, rot_ori, t);
567 if ( water ) {
568 mol_sim = molgroup_copy(water);
569 molgroup_coor_shift_PBC(mol_sim, vector3_random(-ranshift, ranshift));
570 molgroup_insert(mol_sim, mol_rot, 2);
571 molgroup_kill(mol_rot);
572 } else {
573 mol_sim = mol_rot;
574 }
575 ori = {part->ori[0], part->ori[1], part->ori[2]};
576 ppot = img_calc_potential(mol_sim, size, ori, sam, thickness,
577 resolution, Bfactor, paramfile, pottype);
578 ppot->complex_to_real();
579 for ( j=0; j<ppot->images(); j++ ) {
580 ppot->image[j].view(part->view);
581 ppot->image[j].origin(part->ori);
582 }
583 part->fpart = potname;
584 write_img(potname, ppot, 0);
585 molgroup_kill(mol_sim);
586 delete ppot;
587 }
588 }
589 }
590 }
591
592 return 0;
593 }
594
602 int project_generate_image(Bproject* project, double thickness, double resolution)
603 {
604 Bstring potname = project->field->mg->fpart;
605 potname = potname.pre_rev('.') + Bstring(project->field->mg->part->id, "_%03d.") + potname.post_rev('.');
606
607 Bimage* ppot = read_img(potname, 0, 0);
608 Vector3<long> size(ppot->sizeX(), ppot->sizeY(), 1);
609 delete ppot;
610
611 Vector3<double> realsize(size);
612 realsize *= project->field->mg->pixel_size;
613
614 if ( resolution < 2*project->field->mg->pixel_size )
615 resolution = 2*project->field->mg->pixel_size;
616
617 long i, j, k, npart;
618 Bfield* field = NULL;
619 Bmicrograph* mg = NULL;
620 Bparticle* part = NULL;
621 Bimage *p, *pone;
622 int spacegroup = 1;
623
624 long imgsize = 2*size[0]*size[1];
625 UnitCell unit_cell(realsize[0], realsize[1], realsize[2], M_PI_2, M_PI_2, M_PI_2);
626
627 for ( field = project->field; field; field = field->next ) {
628 if ( verbose )
629 cout << "Calculating images for field " << field->id << endl;
630 for ( mg = field->mg; mg; mg = mg->next ) {
631 if ( verbose )
632 cout << "Calculating images for micrograph " << mg->id << endl;
633 for ( npart=0, part = mg->part; part; part = part->next, npart++ ) ;
634 p = new Bimage(Float, TComplex, size[0], size[1], 1, npart);
635 p->unit_cell(unit_cell);
636 p->space_group(spacegroup);
637 p->sampling(mg->pixel_size, mg->pixel_size, 1);
638 for ( i=0, part = mg->part; part; part = part->next, i++ ) {
639 if ( verbose )
640 cout << "Calculating image for particle " << part->id << endl;
641 potname = mg->fpart;
642 potname = potname.pre_rev('.') + Bstring(part->id, "_%03d.") + potname.post_rev('.');
643 ppot = read_img(potname, 1, -1);
644 ppot->simple_to_complex();
645 img_calc_phase_grating(ppot, mg->ctf->volt());
646 pone = img_calc_multi_slice(ppot, thickness, mg->ctf->volt(), resolution);
647 for ( j=i*imgsize, k=0; k<imgsize; j++, k++ ) p->set(j, (*pone)[k]);
648 p->image[i] = ppot->image[0];
649 delete ppot;
650 delete pone;
651 }
652 if ( mg->ctf->defocus_average() )
653 img_apply_complex_CTF(p, mg->ctf->defocus_average(), mg->ctf->defocus_deviation(), mg->ctf->astigmatism_angle(),
654 mg->ctf->volt(), mg->ctf->Cs(), mg->ctf->Cc(), mg->ctf->amp_shift(), mg->ctf->alpha(), mg->ctf->dE());
655 p->fft(FFTW_BACKWARD, 2);
656 p->complex_to_intensities();
657 p->statistics();
658 write_img(mg->fpart, p, 0);
659 delete p;
660 }
661 }
662
663 return 0;
664 }
665
674 int project_apply_distortions(Bproject* project, int poisson, double gauss, double kmtf)
675 {
676 double dose_per_pixel;
677 Bfield* field = NULL;
678 Bmicrograph* mg = NULL;
679
680 Bimage* p;
681 Bstring insert("_tf."); // Transfer functions(s)
682 if ( poisson || gauss ) insert = "_tfn."; // Transfer functions(s) and noise
683
684 for ( field = project->field; field; field = field->next ) {
685 for ( mg = field->mg; mg; mg = mg->next ) {
686 if ( verbose )
687 cout << "Applying distortions to micrograph " << mg->id << endl;
688 p = read_img(mg->fpart, 1, -1);
689 if ( p->compound_type() == TComplex ) {
690 p->fft(FFTW_BACKWARD, 2);
691 p->complex_to_intensities();
692 } else {
693 p->change_type(Float);
694 }
695 dose_per_pixel = mg->dose*mg->pixel_size*mg->pixel_size;
696 if ( dose_per_pixel )
697 p->rescale(dose_per_pixel/p->average(), 0);
698 if ( poisson )
699 // img_add_poisson_noise(p);
700 p->noise_poisson(p->average());
701 if ( gauss < 1000 )
702 // img_add_gaussian_noise(p, gauss);
703 p->noise_gaussian(0, p->standard_deviation()/sqrt(gauss));
704 if ( kmtf > 0 )
705 p->fspace_weigh_B_factor(4*kmtf);
706 mg->fpart = mg->fpart.pre_rev('.') + insert + mg->fpart.post_rev('.');
707 write_img(mg->fpart, p, 0);
708 delete p;
709 }
710 }
711
712 return 0;
713 }
714
715
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
Bparticle::id
int id
Definition: mg_processing.h:92
CTFparam::zero
double zero(int i)
Definition: ctf.h:218
M_PI_2
#define M_PI_2
Definition: utilities.h:62
CTFparam::Cs
double Cs()
Definition: ctf.h:87
UnitCell
Definition: UnitCell.h:22
vector3_random
Vector3< double > vector3_random(const double min, const double max)
Generates a random vector within a defined cube.
Definition: random_numbers.cpp:440
CTFparam::dE
double dE()
Definition: ctf.h:93
Bsub_image::view
void view(double x, double y, double z, double a)
Definition: Bimage.h:143
insert
string insert(string &filename, string ins)
Definition: string_util.cpp:48
random_seed
long random_seed()
Gets a random seed and sets the flag.
Definition: random_numbers.cpp:41
vector3_xy_random_gaussian
Vector3< double > vector3_xy_random_gaussian(double avg, double std)
Generates a random vector within a random gaussian-distributed length in the xy plane.
Definition: random_numbers.cpp:522
Bparticle::view
View view
Definition: mg_processing.h:101
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
View::next
View * next
Definition: View.h:28
Bmicrograph::id
Bstring id
Definition: mg_processing.h:202
molecule_to_map.h
Header file for functions to calculate a 3D map from atomic coordinates.
Bimage::fft
int fft()
Definition: Bimage.h:822
utilities.h
Header file for general utilities.
Bimage::complex_product
int complex_product(Bimage *p)
Calculates the complex product of two complex images.
Definition: Bimage_complex.cpp:430
CTFparam::astigmatism_angle
double astigmatism_angle()
Definition: ctf.h:104
project_generate_asu
Bproject * project_generate_asu(Bstring &symmetry_string, double pixel_size, double img_origin, double theta_step, double phi_step, double volt, double Cs, double Cc, double alpha, double energy_spread, double amp_shift, double defocus, double dose, Bstring &mgbase, Bstring &partbase)
Generates a project for multislice calculations of an asymmetric unit.
Definition: mg_multislice.cpp:441
Bimage::compound_type
CompoundType compound_type()
Definition: Bimage.h:351
verbose
int verbose
kill_list
long kill_list(char *list, unsigned long size)
Frees all the items in a linked list.
Definition: linked_list.cpp:214
Complex.h
Class for complex numbers.
particle_add
Bparticle * particle_add(Bparticle **part, int pid)
Adds a particle parameter structure to a linked list.
Definition: mg_processing.cpp:527
Bstring::length
long length() const
Definition: Bstring.cpp:263
Bmicrograph::pixel_size
double pixel_size
Definition: mg_processing.h:214
project
Bproject * project
Definition: bshow.cpp:31
Bimage::complex
Complex< double > complex(long j)
Returns a complex value at the given index.
Definition: Bimage.cpp:1005
mol_transform.h
Library routines used for atomic coordinate transformations.
Bmicrograph::dose
double dose
Definition: mg_processing.h:215
kill_symmetry
int kill_symmetry(Bsymmetry *sym)
Deallocates a symmetry structure.
Definition: symmetry.cpp:207
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:107
mg_ctf.h
Functions for CTF (contrast transfer function) processing.
TComplex
Definition: Bimage.h:59
molgroup_rotate_from_view
Bmolgroup * molgroup_rotate_from_view(Bmolgroup *molgroup, View view, Vector3< double > origin, Vector3< double > trans)
Rotates a molecule group from a specified view and translates it afterwards.
Definition: mol_transform.cpp:203
molgroup_insert
int molgroup_insert(Bmolgroup *molgroup, Bmolgroup *molinsert, double distance)
Inserts one set of molecules into another.
Definition: mol_edit.cpp:244
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:76
Bfield::next
Bfield * next
Definition: mg_processing.h:258
project_init
Bproject * project_init()
Initializes a micrograph processing project parameter structure.
Definition: mg_processing.cpp:29
Bimage::noise_gaussian
int noise_gaussian(double ravg=0, double rstd=1)
Generates an image with a gaussian random distribution of densities.
Definition: Bimage_noise.cpp:72
Bmicrograph::part
Bparticle * part
Definition: mg_processing.h:239
Float
Definition: utilities.h:157
img_calc_potential
Bimage * img_calc_potential(Bmolgroup *molgroup, Vector3< long > size, Vector3< double > origin, Vector3< double > sam, double thickness, double resolution, double Bfactor, Bstring &paramfile, int type)
Calculates the atomic potential.
Definition: mg_multislice.cpp:139
Bmolgroup::box
Vector3< double > box
Definition: rwmolecule.h:184
Bimage::rescale
int rescale(double scale, double shift)
Rescales the image data with a given multiplier and offset.
Definition: Bimage_rescale.cpp:27
img_calc_wave_propagator
Bimage * img_calc_wave_propagator(Vector3< long > size, Vector3< double > sam, double thickness, double volt, double resolution)
Calculates the wave propagation function between slices.
Definition: mg_multislice.cpp:32
Bimage
General image parameter class.
Definition: Bimage.h:163
Bmicrograph::fpart
Bstring fpart
Definition: mg_processing.h:207
Bimage::real_size
Vector3< double > real_size()
Definition: Bimage.h:487
Bfield
Definition: mg_processing.h:257
M_PI
#define M_PI
Definition: utilities.h:59
linked_list.h
Header file for generalized linked list functions.
Bmicrograph::ctf
CTFparam * ctf
Definition: mg_processing.h:238
Bimage::extract
Bimage * extract(long nn)
Extracts one sub-image into new image structure.
Definition: Bimage_extract.cpp:21
Bmolgroup
Definition: rwmolecule.h:170
molgroup_copy
Bmolgroup * molgroup_copy(Bmolgroup *molgroup)
Copies a molecule group.
Definition: rwmolecule.cpp:547
Bimage::statistics
long statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22
Bfield::id
Bstring id
Definition: mg_processing.h:259
Bmolgroup::comment
Bstring comment
Definition: rwmolecule.h:175
Bimage::label
void label(string s)
Definition: Bimage.h:235
Bproject::field
Bfield * field
Definition: mg_processing.h:343
molgroup_kill
int molgroup_kill(Bmolgroup *molgroup)
Destroys a molecule group.
Definition: rwmolecule.cpp:374
Bimage::simple_to_complex
void simple_to_complex()
A simple image is converted to a complex image.
Definition: Bimage_complex.cpp:22
init_point_group_symmetry
Bsymmetry * init_point_group_symmetry(Bstring symmetry_string)
Sets up a symmetry structure from a string identifier.
Definition: symmetry.cpp:39
Bimage::unit_cell
void unit_cell(UnitCell uc)
Definition: Bimage.h:601
CTFparam::defocus_deviation
double defocus_deviation()
Definition: ctf.h:102
Bimage::project
Bimage * project(char axis, int flags=1)
Projects a 3D image to a 2D image down one of the three major axes.
Definition: Bimage_project.cpp:31
project_apply_distortions
int project_apply_distortions(Bproject *project, int poisson, double gauss, double kmtf)
Applies imaging distortions to the final images from a multislice calculation.
Definition: mg_multislice.cpp:674
Bmicrograph
Definition: mg_processing.h:200
asymmetric_unit_views
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.
Definition: symmetry.cpp:570
Bimage::complex_to_intensities
void complex_to_intensities()
The intensities from a complex image is written to a simple image.
Definition: Bimage_complex.cpp:92
project_generate
Bproject * project_generate(int nfield, int nmg, int npart, double pixel_size, double img_origin, double volt, double Cs, double Cc, double alpha, double energy_spread, double amp_shift, double def_min, double def_max, double dose, double tsigma, Bstring &fieldbase, Bstring &mgbase, Bstring &partbase, int fieldnumber, int mgnumber, int partnumber)
Generates a project for multislice simulations.
Definition: mg_multislice.cpp:344
irm
double irm(1.0L/get_rand_max())
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:373
View::normalize
double normalize()
Definition: View.h:106
Bparticle::fpart
Bstring fpart
Definition: mg_processing.h:91
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:127
Bparticle::ori
Vector3< double > ori
Definition: mg_processing.h:100
Bimage::channels
long channels()
Definition: Bimage.h:371
Vector3::length2
double length2()
Definition: Vector3.h:221
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
get_rand_max
long get_rand_max()
Finds the maximum random number for a system.
Definition: random_numbers.cpp:22
Bimage::standard_deviation
double standard_deviation()
Definition: Bimage.h:537
Bimage::space_group
long space_group()
Definition: Bimage.h:591
Bstring::post_rev
Bstring post_rev(char c)
Definition: Bstring.cpp:428
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:264
Bimage::set
void set(long j, double v)
Sets a single value at the given index.
Definition: Bimage.cpp:1096
Bsymmetry
Definition: symmetry.h:38
field_add
Bfield * field_add(Bfield **field, Bstring &field_id)
Adds a field-of-view parameter structure to a linked list.
Definition: mg_processing.cpp:120
Bimage::noise_poisson
int noise_poisson(double ravg)
Generates an image with a poisson random distribution of densities.
Definition: Bimage_noise.cpp:115
Bimage::complex_to_real
void complex_to_real()
The real part of a complex image is written to a simple image.
Definition: Bimage_complex.cpp:50
Complex
Definition: Complex.h:23
molgroup_coor_shift_PBC
int molgroup_coor_shift_PBC(Bmolgroup *molgroup, Vector3< double > shift)
Translates a molecule within a periodic box.
Definition: mol_transform.cpp:544
Bparticle
Definition: mg_processing.h:89
random_numbers.h
Header file for functions for creating random images.
Bmicrograph::block
int block
Definition: mg_processing.h:204
Bstring
Definition: Bstring.h:29
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:377
CTFparam::volt
double volt()
Definition: ctf.h:83
Bmicrograph::box_size
Vector3< long > box_size
Definition: mg_processing.h:230
img_apply_complex_CTF
int img_apply_complex_CTF(Bimage *p, double def_avg, double def_dev, double ast_angle, double volts, double Cs, double Cc, double amp_shift, double alpha, double energy_spread)
Applies a complex CTF function to a Fourier transform.
Definition: mg_multislice.cpp:252
img_calc_phase_grating
int img_calc_phase_grating(Bimage *p, double volt)
Calculates the phase grating approximation from the atomic potential.
Definition: mg_multislice.cpp:206
Bimage::fspace_weigh_B_factor
int fspace_weigh_B_factor(double B, double resolution=0)
Weighs an image's amplitudes with B-factor (gaussian) curve.
Definition: Bimage_fspace.cpp:1185
project_generate_potential
int project_generate_potential(Bmolgroup *molgroup, Bmolgroup *water, Bproject *project, Bstring &fieldname, Bstring &mgname, int partselect, Vector3< long > size, double thickness, double resolution, double Bfactor, int pottype, Bstring &paramfile)
Generates potential images using a multislice calculation.
Definition: mg_multislice.cpp:502
Bimage::sizeZ
void sizeZ(long nz)
Definition: Bimage.h:379
Vector3< long >
Bparticle::loc
Vector3< double > loc
Definition: mg_processing.h:99
project_generate_image
int project_generate_image(Bproject *project, double thickness, double resolution)
Generates final images from a multislice calculation.
Definition: mg_multislice.cpp:602
Vector3.h
Class for 3-value vectors.
View
Definition: View.h:26
CTFparam::defocus_average
double defocus_average()
Definition: ctf.h:100
Bimage::average
double average(long cc, double xf, double yf, double zf, long nn, double iscale)
Averages in 3D when scaling is less than 1.
Definition: Bimage.cpp:1349
img_sf_from_molecule
Bimage * img_sf_from_molecule(Bmolgroup *molgroup, Vector3< double > origin, Vector3< long > size, Vector3< double > sam, double resolution, int spacegroup, UnitCell unit_cell, int wrap, double Bfactor, Bstring &paramfile)
Calculates a 3D set of structure factors from a set of atomic coordinates.
Definition: molecule_to_map.cpp:355
mg_processing.h
Header file for micrograph processing.
CTFparam::baseline
vector< double > & baseline()
Definition: ctf.h:108
Bmolgroup::min
Vector3< double > min
Definition: rwmolecule.h:182
CTFparam::envelope
vector< double > & envelope()
Definition: ctf.h:115
Bimage::images
long images()
Definition: Bimage.h:491
CTFparam::amp_shift
double amp_shift()
Definition: ctf.h:95
img_calc_multi_slice
Bimage * img_calc_multi_slice(Bimage *pgrate, double thickness, double volt, double resolution)
Simulates the electron imaging process using a multi-slice approach.
Definition: mg_multislice.cpp:89
img_from_molecule
Bimage * img_from_molecule(Bmolgroup *molgroup, Vector3< double > origin, Vector3< long > size, Vector3< double > sam, double resolution, double Bfactor, int wrap, int gextype, int spacegroup, UnitCell unit_cell)
Calculates a 3D density map from a set of atomic coordinates.
Definition: molecule_to_map.cpp:53
NoTransform
Definition: Bimage.h:40
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:413
Vector3::volume
double volume()
Definition: Vector3.h:235
Bparticle::next
Bparticle * next
Definition: mg_processing.h:90
VERB_FULL
#define VERB_FULL
Definition: utilities.h:109
molgroup_split_into_slices
Bmolgroup ** molgroup_split_into_slices(Bmolgroup *molgroup, double slice_thickness, int &nslices)
Splits a set of coordinates into slices with a given thickness.
Definition: mol_edit.cpp:158
Bimage::sizeY
void sizeY(long ny)
Definition: Bimage.h:378
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:106
electron_wavelength
double electron_wavelength(double volt)
Calculates the wavelength in angstrom from the acceleration voltage.
Definition: ctf.cpp:403
Bstring::str
string str()
Definition: Bstring.h:42
micrograph_add
Bmicrograph * micrograph_add(Bmicrograph **mg, Bstring &mg_id)
Adds a micrograph parameter structure to a linked list.
Definition: mg_processing.cpp:461
CTFparam::Cc
double Cc()
Definition: ctf.h:89
mol_edit.h
Library routines used for atomic coordinates.
Bimage::fourier_type
FourierType fourier_type()
Definition: Bimage.h:367
CTFparam::alpha
double alpha()
Definition: ctf.h:91
Bproject
Definition: mg_processing.h:333
Bimage::image
Bsub_image * image
Definition: Bimage.h:188
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:563
CTFparam
Definition: ctf.h:26
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:201