Bsoft  2.1.0
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 
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());
102  p->origin(pgrate->image->origin());
103  p->sampling(pgrate->sampling(0));
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 
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 
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,
345  Vector3<double> pixel_size, double img_origin,
346  double volt, double Cs, double Cc, double alpha, double energy_spread,
347  double amp_shift, double def_min, double def_max, double dose,
348  double tsigma, Bstring& fieldbase, Bstring& mgbase, Bstring& partbase,
349  int fieldnumber, int mgnumber, int partnumber)
350 {
351  random_seed();
352 
353  double def_range = def_max - def_min;
354  if ( def_range < 0 ) def_range = 0;
355 
356  int i, j, k, block = 0;
357  double irm = 1.0/get_rand_max(), irm2 = 2*irm;
358  Vector3<float> t;
359  View* v = new View[npart];
361  Bfield* field = NULL;
362  Bmicrograph* mg = NULL;
363  Bparticle* part = NULL;
364  Bstring field_id, mg_id;
365 
366  if ( verbose ) {
367  cout << "Generating a new project:" << endl;
368  cout << "Number of fields: " << nfield << endl;
369  cout << "Number of micrographs: " << nmg << endl;
370  cout << "Number of particles: " << npart << endl;
371  }
372 
373  for ( i=0; i<nfield; i++ ) {
374  field_id = fieldbase + Bstring(fieldnumber, "_%06d");
375  if ( project->field ) field = field_add(&field, field_id);
376  else field = field_add(&project->field, field_id);
377  for ( k=0; k<npart; k++ ) {
378  v[k] = View(random()*irm2 - 1, random()*irm2 - 1, random()*irm2 - 1, M_PI*(random()*irm2 - 1));
379  v[k].normalize();
380  }
381  for ( j=0; j<nmg; j++ ) {
382  mg_id = mgbase + Bstring(fieldnumber, "_%03d") + Bstring(mgnumber, "_%03d");
383  if ( field->mg ) mg = micrograph_add(&mg, mg_id);
384  else mg = micrograph_add(&field->mg, mg_id);
385  mg->block = block;
386  block++;
387  mg->fpart = partbase + Bstring(fieldnumber, "_%03d") + Bstring(mgnumber, "_%03d.spi");
388  if ( !mg->ctf ) mg->ctf = new CTFparam;
389  mg->ctf->defocus_average(def_range*random()*irm + def_min);
390  mg->ctf->volt(volt);
391  mg->ctf->Cs(Cs);
392  mg->ctf->Cc(Cc);
393  mg->ctf->alpha(alpha);
394  mg->ctf->dE(energy_spread);
395  mg->ctf->amp_shift(amp_shift);
396  mg->pixel_size = pixel_size;
397  mg->dose = dose;
398  mg->box_size[0] = mg->box_size[1] = (int) (2*img_origin);
399  mg->box_size[2] = 1;
400  mg->ctf->zero(1);
401  mg->ctf->baseline(0, 1);
402  mg->ctf->envelope(0, 3);
403  mg->ctf->envelope(1, -M_PI*M_PI*mg->ctf->alpha()*mg->ctf->alpha()*mg->ctf->defocus_average()*mg->ctf->defocus_average());
404  for ( k=0; k<npart; k++ ) {
405  if ( mg->part ) part = particle_add(&part, k+partnumber);
406  else part = particle_add(&mg->part, k+partnumber);
407  if ( tsigma > 0 ) t = vector3_xy_random_gaussian(0.0, (double)tsigma);
408  part->view = v[k];
409  part->loc[0] = part->loc[1] = img_origin;
410  part->ori = t + img_origin;
411  part->ori[2] = 0;
412  }
413  mgnumber++;
414  }
415  fieldnumber++;
416  }
417 
418  delete[] v;
419 
420  return project;
421 }
422 
443  Vector3<double> pixel_size, double img_origin,
444  double theta_step, double phi_step,
445  double volt, double Cs, double Cc, double alpha, double energy_spread,
446  double amp_shift, double defocus, double dose, Bstring& mgbase, Bstring& partbase)
447 {
448  int k, npart;
450  Bfield* field = NULL;
451  Bmicrograph* mg = NULL;
452  Bparticle* part = NULL;
453 
454  Bsymmetry* sym = init_point_group_symmetry(symmetry_string);
455  View* view = asymmetric_unit_views(sym, theta_step, phi_step, 0);
456  View* v;
457  for ( v=view, npart=0; v; v=v->next ) npart++;
458 
459  field = field_add(&project->field, mgbase);
460  mg = micrograph_add(&field->mg, mgbase);
461  mg->block = 0;
462  mg->fpart = partbase + ".spi";
463  if ( !mg->ctf ) mg->ctf = new CTFparam;
464  mg->ctf->defocus_average(defocus);
465  mg->ctf->volt(volt);
466  mg->ctf->Cs(Cs);
467  mg->ctf->Cc(Cc);
468  mg->ctf->alpha(alpha);
469  mg->ctf->dE(energy_spread);
470  mg->ctf->amp_shift(amp_shift);
471  mg->pixel_size = pixel_size;
472  mg->dose = dose;
473  mg->box_size[0] = mg->box_size[1] = (int) (2*img_origin);
474  mg->box_size[2] = 1;
475  for ( k=0, v=view; k<npart && v; k++, v=v->next ) {
476  if ( mg->part ) part = particle_add(&part, k+1);
477  else part = particle_add(&mg->part, k+1);
478  part->view = *v;
479  part->loc = part->ori = Vector3<float>(img_origin, img_origin, 0);
480  }
481 
482  kill_list((char *) view, sizeof(View));
483  kill_symmetry(sym);
484 
485  return project;
486 }
487 
505  Bstring& fieldname, Bstring& mgname, int partselect,
506  Vector3<long> size, double thickness, double resolution,
507  double Bfactor, int pottype, Bstring& paramfile)
508 {
509  random_seed();
510 
511  Vector3<double> sam, box;
512  sam = project->field->mg->pixel_size;
513  if ( resolution < 2*project->field->mg->pixel_size[0] )
514  resolution = 2*project->field->mg->pixel_size[0];
515 
516  if ( size.volume() < 1 ) {
517  size[0] = (long) (molgroup->box[0]/sam[0]);
518  size[1] = (long) (molgroup->box[1]/sam[1]);
519  size[2] = (long) (molgroup->box[2]/sam[2]);
520  }
521  if ( water ) {
522  if ( molgroup->box.length2() < water->box.length2() ) {
523  size[0] = (long) (water->box[0]/sam[0]);
524  size[1] = (long) (water->box[1]/sam[1]);
525  size[2] = (long) (water->box[2]/sam[2]);
526  }
527  box = sam * size;
528  water->box = Vector3<float>(box[0], box[1], box[2]);
529  }
530  box = sam * size;
531  molgroup->box = Vector3<float>(box[0], box[1], box[2]);
532 
533  Vector3<double> sampling3(sam[0], sam[1], sam[2]);
534 
535  if ( verbose )
536  cout << "Simulation box: " << molgroup->box << " = " << molgroup->box.volume() << " A^3" << endl;
537 
538  int j;
539  Bfield* field = NULL;
540  Bmicrograph* mg = NULL;
541  Bparticle* part = NULL;
542  Bmolgroup* mol_rot = NULL;
543  Bmolgroup* mol_sim = NULL;
544  Bimage *ppot;
545  Bstring potname;
546  double ranshift = molgroup->box[0];
547  Vector3<float> t, rot_ori;
548  Vector3<double> ori;
549 
550  for ( field = project->field; field; field = field->next )
551  if ( fieldname.length() < 1 || field->id == fieldname ) {
552  if ( verbose )
553  cout << "Calculating potentials for field " << field->id << endl;
554  for ( mg = field->mg; mg; mg = mg->next )
555  if ( mgname.length() < 1 || mg->id == mgname ) {
556  if ( verbose )
557  cout << "Calculating potentials for micrograph " << mg->id << endl;
558  for ( part = mg->part; part; part = part->next )
559  if ( partselect < 1 || part->id == partselect ) {
560 // potname = number_filename(mg->fpart, part->id, 3);
561  potname = mg->fpart;
562  potname = potname.pre_rev('.') + Bstring(part->id, "_%03d.") + potname.post_rev('.');
563  if ( access(potname.c_str(), F_OK) != 0 ) { // Skip if the file already exists
564  if ( verbose )
565  cout << "Calculating potentials for particle " << part->id << endl;
566  t = (part->ori - part->loc) * sampling3;
567 // cout << "origin=" << origin << " shift=" << t << endl;
568  mol_rot = molgroup_rotate_from_view(molgroup, part->view, rot_ori, t);
569  if ( water ) {
570  mol_sim = molgroup_copy(water);
571  molgroup_coor_shift_PBC(mol_sim, vector3_random(-ranshift, ranshift));
572  molgroup_insert(mol_sim, mol_rot, 2);
573  molgroup_kill(mol_rot);
574  } else {
575  mol_sim = mol_rot;
576  }
577  ori = {part->ori[0], part->ori[1], part->ori[2]};
578  ppot = img_calc_potential(mol_sim, size, ori, sam, thickness,
579  resolution, Bfactor, paramfile, pottype);
580  ppot->complex_to_real();
581  for ( j=0; j<ppot->images(); j++ ) {
582  ppot->image[j].view(part->view);
583  ppot->image[j].origin(part->ori);
584  }
585  part->fpart = potname;
586  write_img(potname, ppot, 0);
587  molgroup_kill(mol_sim);
588  delete ppot;
589  }
590  }
591  }
592  }
593 
594  return 0;
595 }
596 
604 int project_generate_image(Bproject* project, double thickness, double resolution)
605 {
606  Bstring potname = project->field->mg->fpart;
607  potname = potname.pre_rev('.') + Bstring(project->field->mg->part->id, "_%03d.") + potname.post_rev('.');
608 
609  Bimage* ppot = read_img(potname, 0, 0);
610  Vector3<long> size(ppot->sizeX(), ppot->sizeY(), 1);
611  delete ppot;
612 
613  Vector3<double> realsize(size);
614  realsize *= project->field->mg->pixel_size;
615 
616  if ( resolution < 2*project->field->mg->pixel_size[0] )
617  resolution = 2*project->field->mg->pixel_size[0];
618 
619  long i, j, k, npart;
620  Bfield* field = NULL;
621  Bmicrograph* mg = NULL;
622  Bparticle* part = NULL;
623  Bimage *p, *pone;
624  int spacegroup = 1;
625 
626  long imgsize = 2*size[0]*size[1];
627  UnitCell unit_cell(realsize[0], realsize[1], realsize[2], M_PI_2, M_PI_2, M_PI_2);
628 
629  for ( field = project->field; field; field = field->next ) {
630  if ( verbose )
631  cout << "Calculating images for field " << field->id << endl;
632  for ( mg = field->mg; mg; mg = mg->next ) {
633  if ( verbose )
634  cout << "Calculating images for micrograph " << mg->id << endl;
635  for ( npart=0, part = mg->part; part; part = part->next, npart++ ) ;
636  p = new Bimage(Float, TComplex, size[0], size[1], 1, npart);
637  p->unit_cell(unit_cell);
638  p->space_group(spacegroup);
639  p->sampling(mg->pixel_size);
640  for ( i=0, part = mg->part; part; part = part->next, i++ ) {
641  if ( verbose )
642  cout << "Calculating image for particle " << part->id << endl;
643  potname = mg->fpart;
644  potname = potname.pre_rev('.') + Bstring(part->id, "_%03d.") + potname.post_rev('.');
645  ppot = read_img(potname, 1, -1);
646  ppot->simple_to_complex();
647  img_calc_phase_grating(ppot, mg->ctf->volt());
648  pone = img_calc_multi_slice(ppot, thickness, mg->ctf->volt(), resolution);
649  for ( j=i*imgsize, k=0; k<imgsize; j++, k++ ) p->set(j, (*pone)[k]);
650  p->image[i] = ppot->image[0];
651  delete ppot;
652  delete pone;
653  }
654  if ( mg->ctf->defocus_average() )
656  mg->ctf->volt(), mg->ctf->Cs(), mg->ctf->Cc(), mg->ctf->amp_shift(), mg->ctf->alpha(), mg->ctf->dE());
657  p->fft(FFTW_BACKWARD, 2);
659  p->statistics();
660  write_img(mg->fpart, p, 0);
661  delete p;
662  }
663  }
664 
665  return 0;
666 }
667 
676 int project_apply_distortions(Bproject* project, int poisson, double gauss, double kmtf)
677 {
678  double dose_per_pixel;
679  Bfield* field = NULL;
680  Bmicrograph* mg = NULL;
681 
682  Bimage* p;
683  Bstring insert("_tf."); // Transfer functions(s)
684  if ( poisson || gauss ) insert = "_tfn."; // Transfer functions(s) and noise
685 
686  for ( field = project->field; field; field = field->next ) {
687  for ( mg = field->mg; mg; mg = mg->next ) {
688  if ( verbose )
689  cout << "Applying distortions to micrograph " << mg->id << endl;
690  p = read_img(mg->fpart, 1, -1);
691  if ( p->compound_type() == TComplex ) {
692  p->fft(FFTW_BACKWARD, 2);
694  } else {
695  p->change_type(Float);
696  }
697  dose_per_pixel = mg->dose*mg->pixel_size[0]*mg->pixel_size[1];
698  if ( dose_per_pixel )
699  p->rescale(dose_per_pixel/p->average(), 0);
700  if ( poisson )
701 // img_add_poisson_noise(p);
702  p->noise_poisson(p->average());
703  if ( gauss < 1000 )
704 // img_add_gaussian_noise(p, gauss);
705  p->noise_gaussian(0, p->standard_deviation()/sqrt(gauss));
706  if ( kmtf > 0 )
707  p->fspace_weigh_B_factor(4*kmtf);
708  mg->fpart = mg->fpart.pre_rev('.') + insert + mg->fpart.post_rev('.');
709  write_img(mg->fpart, p, 0);
710  delete p;
711  }
712  }
713 
714  return 0;
715 }
716 
717 
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
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
Bmicrograph::id
Bstring id
Definition: mg_processing.h:203
Bimage::rescale
int rescale(double scale, double shift)
Rescales the image data with a given multiplier and offset.
Definition: Bimage_rescale.cpp:27
Bmicrograph
Definition: mg_processing.h:201
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
View::next
View * next
Definition: View.h:28
Bimage::real_size
Vector3< double > real_size()
Definition: Bimage.h:500
Bimage::sizeZ
void sizeZ(long nz)
Definition: Bimage.h:392
CTFparam::zero
double zero(int i)
Definition: ctf.h:228
molgroup_kill
int molgroup_kill(Bmolgroup *molgroup)
Destroys a molecule group.
Definition: rwmolecule.cpp:374
verbose
int verbose
CTFparam::Cc
double Cc()
Definition: ctf.h:93
CTFparam::dE
double dE()
Definition: ctf.h:97
kill_list
long kill_list(char *list, unsigned long size)
Frees all the items in a linked list.
Definition: linked_list.cpp:214
Complex
Definition: Complex.h:23
Bparticle::view
View view
Definition: mg_processing.h:102
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
Bimage::set
void set(long j, double v)
Sets a single value at the given index.
Definition: Bimage.cpp:1118
Bstring
Definition: Bstring.h:29
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:121
Bparticle
Definition: mg_processing.h:90
Bstring::post_rev
Bstring post_rev(char c)
Definition: Bstring.cpp:436
Bproject::field
Bfield * field
Definition: mg_processing.h:346
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:504
Bimage::simple_to_complex
void simple_to_complex()
A simple image is converted to a complex image.
Definition: Bimage_complex.cpp:22
CTFparam::astigmatism_angle
double astigmatism_angle()
Definition: ctf.h:110
Vector3< long >
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:390
Bimage::unit_cell
void unit_cell(UnitCell uc)
Definition: Bimage.h:608
random_numbers.h
Header file for functions for creating random images.
Complex.h
Class for complex numbers.
project_init
Bproject * project_init()
Initializes a micrograph processing project parameter structure.
Definition: mg_processing.cpp:30
TComplex
@ TComplex
Definition: Bimage.h:60
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:386
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
project_generate_image
int project_generate_image(Bproject *project, double thickness, double resolution)
Generates final images from a multislice calculation.
Definition: mg_multislice.cpp:604
Bmicrograph::part
Bparticle * part
Definition: mg_processing.h:242
mol_edit.h
Library routines used for atomic coordinates.
Bfield::id
Bstring id
Definition: mg_processing.h:262
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:564
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
View
Definition: View.h:26
Bsub_image::view
void view(double x, double y, double z, double a)
Definition: Bimage.h:157
Bmicrograph::fpart
Bstring fpart
Definition: mg_processing.h:208
Bfield
Definition: mg_processing.h:260
Bimage::image
Bsub_image * image
Definition: Bimage.h:202
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:111
Bsymmetry
Definition: symmetry.h:38
mol_transform.h
Library routines used for atomic coordinate transformations.
M_PI_2
#define M_PI_2
Definition: utilities.h:66
Bimage::standard_deviation
double standard_deviation()
Definition: Bimage.h:544
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
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
Bmicrograph::dose
double dose
Definition: mg_processing.h:216
Bimage::images
long images()
Definition: Bimage.h:504
project
Bproject * project
Definition: bshow.cpp:33
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:77
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:136
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:281
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
Bstring::str
string str()
Definition: Bstring.h:42
Bparticle::fpart
Bstring fpart
Definition: mg_processing.h:92
project_generate_asu
Bproject * project_generate_asu(Bstring &symmetry_string, Vector3< 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:442
insert
string insert(string &filename, string ins)
Definition: string_util.cpp:48
Bimage::sizeY
void sizeY(long ny)
Definition: Bimage.h:391
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::fft
int fft()
Definition: Bimage.h:830
Bimage::fourier_type
FourierType fourier_type()
Definition: Bimage.h:380
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:421
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
mg_ctf.h
Functions for CTF (contrast transfer function) processing.
Bimage
General image parameter class.
Definition: Bimage.h:177
Bimage::compound_type
CompoundType compound_type()
Definition: Bimage.h:364
Bmolgroup::box
Vector3< double > box
Definition: rwmolecule.h:184
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:1371
Bproject
Definition: mg_processing.h:336
Vector3.h
Class for 3-value vectors.
View::normalize
double normalize()
Definition: View.h:109
CTFparam::volt
double volt()
Definition: ctf.h:87
Bimage::complex
Complex< double > complex(long j)
Returns a complex value at the given index.
Definition: Bimage.cpp:1027
CTFparam::defocus_deviation
double defocus_deviation()
Definition: ctf.h:108
Bparticle::loc
Vector3< double > loc
Definition: mg_processing.h:100
M_PI
#define M_PI
Definition: utilities.h:63
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:1183
utilities.h
Header file for general utilities.
Bmolgroup::comment
Bstring comment
Definition: rwmolecule.h:175
Bmicrograph::box_size
Vector3< long > box_size
Definition: mg_processing.h:233
Bstring::length
long length() const
Definition: Bstring.cpp:263
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::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:570
random_seed
long random_seed()
Gets a random seed and sets the flag.
Definition: random_numbers.cpp:41
molgroup_insert
int molgroup_insert(Bmolgroup *molgroup, Bmolgroup *molinsert, double distance)
Inserts one set of molecules into another.
Definition: mol_edit.cpp:244
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1765
CTFparam::baseline
vector< double > & baseline()
Definition: ctf.h:114
CTFparam
Definition: ctf.h:28
Vector3::volume
double volume()
Definition: Vector3.h:237
particle_add
Bparticle * particle_add(Bparticle **part, int pid)
Adds a particle parameter structure to a linked list.
Definition: mg_processing.cpp:221
Bmolgroup::min
Vector3< double > min
Definition: rwmolecule.h:182
Bmicrograph::ctf
CTFparam * ctf
Definition: mg_processing.h:241
Bfield::next
Bfield * next
Definition: mg_processing.h:261
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
Bparticle::ori
Vector3< double > ori
Definition: mg_processing.h:101
mg_processing.h
Header file for micrograph processing.
Bimage::extract
Bimage * extract(long nn)
Extracts one sub-image into new image structure.
Definition: Bimage_extract.cpp:21
CTFparam::defocus_average
double defocus_average()
Definition: ctf.h:106
Bmicrograph::block
int block
Definition: mg_processing.h:205
Bimage::space_group
long space_group()
Definition: Bimage.h:598
micrograph_add
Bmicrograph * micrograph_add(Bmicrograph **mg, Bstring &mg_id)
Adds a micrograph parameter structure to a linked list.
Definition: mg_processing.cpp:154
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
Bparticle::next
Bparticle * next
Definition: mg_processing.h:91
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
kill_symmetry
int kill_symmetry(Bsymmetry *sym)
Deallocates a symmetry structure.
Definition: symmetry.cpp:207
linked_list.h
Header file for generalized linked list functions.
Bimage::noise_poisson
int noise_poisson(double ravg)
Generates an image with a poisson random distribution of densities.
Definition: Bimage_noise.cpp:115
electron_wavelength
double electron_wavelength(double volt)
Calculates the wavelength in angstrom from the acceleration voltage.
Definition: ctf.cpp:456
VERB_FULL
#define VERB_FULL
Definition: utilities.h:113
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
Bmicrograph::pixel_size
Vector3< double > pixel_size
Definition: mg_processing.h:215
Bimage::complex_product
int complex_product(Bimage *p)
Calculates the complex product of two complex images.
Definition: Bimage_complex.cpp:430
irm
double irm(1.0L/get_rand_max())
Bmolgroup
Definition: rwmolecule.h:170
CTFparam::alpha
double alpha()
Definition: ctf.h:95
Bimage::sampling
void sampling(long nn, Vector3< double > u)
Definition: Bimage.h:514
CTFparam::amp_shift
double amp_shift()
Definition: ctf.h:99
UnitCell
Definition: UnitCell.h:22
get_rand_max
long get_rand_max()
Finds the maximum random number for a system.
Definition: random_numbers.cpp:22
Float
@ Float
Definition: utilities.h:161
Bimage::channels
long channels()
Definition: Bimage.h:384
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:110
CTFparam::envelope
vector< double > & envelope()
Definition: ctf.h:121
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:202
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:267
Bparticle::id
int id
Definition: mg_processing.h:93
NoTransform
@ NoTransform
Definition: Bimage.h:41
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:676
molgroup_copy
Bmolgroup * molgroup_copy(Bmolgroup *molgroup)
Copies a molecule group.
Definition: rwmolecule.cpp:547
molecule_to_map.h
Header file for functions to calculate a 3D map from atomic coordinates.
Vector3::length2
double length2()
Definition: Vector3.h:221
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
project_generate
Bproject * project_generate(int nfield, int nmg, int npart, Vector3< 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
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:357
Bimage::statistics
long statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22
CTFparam::Cs
double Cs()
Definition: ctf.h:91
Bimage::label
void label(string s)
Definition: Bimage.h:250