 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
33 double thickness,
double volt,
double resolution)
37 if ( resolution < sam[0] || resolution > 1000 )
42 double arg, sx2, sy2, s2;
43 double afactor =
M_PI*wavelength*thickness;
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]);
49 for ( y=0; y<p->
sizeY(); y++ ) {
53 if ( sy2 <= resmax2 )
for ( x=0; x<p->
sizeX(); x++ ) {
58 if ( s2 <= resmax2 ) {
105 long slice_size = size[0]*size[1];
107 for ( i=0; i<slice_size; i++ ) p->
set(i, cv);
110 for ( i=0; i<pgrate->
images(); i++ ) {
114 p->
fft(FFTW_FORWARD, 0);
115 if ( i < pgrate->images()-1 ) {
117 p->
fft(FFTW_BACKWARD, 0);
140 Vector3<double> sam,
double thickness,
double resolution,
double Bfactor,
149 cout <<
"Calculating the atomic potential" << endl;
158 p->
sampling(sam[0], sam[1], thickness);
161 for ( i=0; i<nslices; i++ ) {
163 origin[2] = -slice_molgroup[i]->
min[2]/sam[2] - 0.5;
164 size[2] = (int) (thickness/sam[2] + 1);
166 resolution, 0.001, 0, 2 - type, spacegroup, unit_cell);
177 resolution, spacegroup, unit_cell, 2, Bfactor, paramfile);
178 ptemp->
fft(FFTW_BACKWARD, 0);
180 for ( j=0, k=i*imgsize; j<imgsize; j++, k++ ) p->
set(k, (*ptemp)[j]);
184 cout <<
"Slice " << i+1 <<
" done" << endl << endl;
189 for ( i=0; i<nslices; i++ )
192 delete[] slice_molgroup;
214 double sigma = 0.0208886 * wavelength *
215 sqrt(1 + 5.8886579e-4/(wavelength*wavelength));
218 cout <<
"Sigma (interaction factor): " << sigma << endl;
220 for ( i=n=0; n<p->
images(); n++ ) {
221 for ( j=0; j<imgsize; i++, j++ ) {
222 arg = -sigma*(p->
complex(i)).real();
253 double volts,
double Cs,
double Cc,
double amp_shift,
double alpha,
double energy_spread)
257 double xx, yy, zz, sx2, sy2, sz2, s, s2, defocus, dphi, env, arg;
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));
270 cout <<
"Applying a CTF to a complex Fourier transform" << endl;
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;
284 for ( i=n=0; n<p->
images(); n++ ) {
285 for ( z=0; z<p->
sizeZ(); z++ ) {
287 if ( z > (p->
sizeZ() - 1)/2 ) zz -= p->
sizeZ();
288 sz2 = freq_scale[2]*zz;
290 for ( y=0; y<p->
sizeY(); y++ ) {
292 if ( y > (p->
sizeY() - 1)/2 ) yy -= p->
sizeY();
293 sy2 = freq_scale[1]*yy;
295 for ( x=0; x<p->
sizeX(); x++, i++ ) {
297 if ( x > (p->
sizeX() - 1)/2 ) xx -= p->
sizeX();
298 sx2 = freq_scale[0]*xx;
300 s2 = sx2 + sy2 + sz2;
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;
306 arg = arg*arg + pi2l2df2*s2*s2;
310 p->
set(i, ((*p)[i] * ctf) * env);
346 double volt,
double Cs,
double Cc,
double alpha,
double energy_spread,
347 double amp_shift,
double def_min,
double def_max,
double dose,
349 int fieldnumber,
int mgnumber,
int partnumber)
353 double def_range = def_max - def_min;
354 if ( def_range < 0 ) def_range = 0;
356 int i, j, k, block = 0;
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;
373 for ( i=0; i<nfield; i++ ) {
374 field_id = fieldbase +
Bstring(fieldnumber,
"_%06d");
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));
381 for ( j=0; j<nmg; j++ ) {
382 mg_id = mgbase +
Bstring(fieldnumber,
"_%03d") +
Bstring(mgnumber,
"_%03d");
394 mg->
ctf->
dE(energy_spread);
404 for ( k=0; k<npart; k++ ) {
409 part->
loc[0] = part->
loc[1] = img_origin;
410 part->
ori = t + 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)
457 for ( v=view, npart=0; v; v=v->
next ) npart++;
462 mg->
fpart = partbase +
".spi";
469 mg->
ctf->
dE(energy_spread);
475 for ( k=0, v=view; k<npart && v; k++, v=v->
next ) {
507 double Bfactor,
int pottype,
Bstring& paramfile)
513 if ( resolution < 2*project->field->mg->pixel_size[0] )
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]);
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]);
536 cout <<
"Simulation box: " << molgroup->
box <<
" = " << molgroup->
box.
volume() <<
" A^3" << endl;
546 double ranshift = molgroup->
box[0];
551 if ( fieldname.
length() < 1 || field->
id == fieldname ) {
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 ) {
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 ) {
563 if ( access(potname.
c_str(), F_OK) != 0 ) {
565 cout <<
"Calculating potentials for particle " << part->
id << endl;
566 t = (part->
ori - part->
loc) * sampling3;
577 ori = {part->
ori[0], part->
ori[1], part->
ori[2]};
579 resolution, Bfactor, paramfile, pottype);
581 for ( j=0; j<ppot->
images(); j++ ) {
585 part->
fpart = potname;
616 if ( resolution < 2*project->field->mg->pixel_size[0] )
626 long imgsize = 2*size[0]*size[1];
631 cout <<
"Calculating images for field " << field->
id << endl;
632 for ( mg = field->
mg; mg; mg = mg->
next ) {
634 cout <<
"Calculating images for micrograph " << mg->
id << endl;
635 for ( npart=0, part = mg->
part; part; part = part->
next, npart++ ) ;
640 for ( i=0, part = mg->
part; part; part = part->
next, i++ ) {
642 cout <<
"Calculating image for particle " << part->
id << endl;
649 for ( j=i*imgsize, k=0; k<imgsize; j++, k++ ) p->
set(j, (*pone)[k]);
657 p->
fft(FFTW_BACKWARD, 2);
678 double dose_per_pixel;
684 if ( poisson || gauss )
insert =
"_tfn.";
687 for ( mg = field->
mg; mg; mg = mg->
next ) {
689 cout <<
"Applying distortions to micrograph " << mg->
id << endl;
692 p->
fft(FFTW_BACKWARD, 2);
698 if ( dose_per_pixel )
Bimage * img_calc_multi_slice(Bimage *pgrate, double thickness, double volt, double resolution)
Simulates the electron imaging process using a multi-slice approach.
int rescale(double scale, double shift)
Rescales the image data with a given multiplier and offset.
void complex_to_intensities()
The intensities from a complex image is written to a simple image.
Vector3< double > real_size()
int molgroup_kill(Bmolgroup *molgroup)
Destroys a molecule group.
long kill_list(char *list, unsigned long size)
Frees all the items in a linked list.
Vector3< double > vector3_xy_random_gaussian(double avg, double std)
Generates a random vector within a random gaussian-distributed length in the xy plane.
void set(long j, double v)
Sets a single value at the given index.
Bfield * field_add(Bfield **field, Bstring &field_id)
Adds a field-of-view parameter structure to a linked list.
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 ¶mfile)
Generates potential images using a multislice calculation.
void simple_to_complex()
A simple image is converted to a complex image.
double astigmatism_angle()
void unit_cell(UnitCell uc)
Header file for functions for creating random images.
Class for complex numbers.
Bproject * project_init()
Initializes a micrograph processing project parameter structure.
Vector3< long > size() const
Bimage * img_calc_potential(Bmolgroup *molgroup, Vector3< long > size, Vector3< double > origin, Vector3< double > sam, double thickness, double resolution, double Bfactor, Bstring ¶mfile, int type)
Calculates the atomic potential.
int project_generate_image(Bproject *project, double thickness, double resolution)
Generates final images from a multislice calculation.
Library routines used for atomic coordinates.
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.
Vector3< double > vector3_random(const double min, const double max)
Generates a random vector within a defined cube.
void view(double x, double y, double z, double a)
double standard_deviation()
Bmolgroup ** molgroup_split_into_slices(Bmolgroup *molgroup, double slice_thickness, int &nslices)
Splits a set of coordinates into slices with a given thickness.
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)
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.
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.
string insert(string &filename, string ins)
int img_calc_phase_grating(Bimage *p, double volt)
Calculates the phase grating approximation from the atomic potential.
FourierType fourier_type()
int noise_gaussian(double ravg=0, double rstd=1)
Generates an image with a gaussian random distribution of densities.
Functions for CTF (contrast transfer function) processing.
General image parameter class.
CompoundType compound_type()
double average(long cc, double xf, double yf, double zf, long nn, double iscale)
Averages in 3D when scaling is less than 1.
Class for 3-value vectors.
Complex< double > complex(long j)
Returns a complex value at the given index.
double defocus_deviation()
int fspace_weigh_B_factor(double B, double resolution=0)
Weighs an image's amplitudes with B-factor (gaussian) curve.
Header file for general utilities.
Bsymmetry * init_point_group_symmetry(Bstring symmetry_string)
Sets up a symmetry structure from a string identifier.
void origin(double ox, double oy, double oz)
long random_seed()
Gets a random seed and sets the flag.
int molgroup_insert(Bmolgroup *molgroup, Bmolgroup *molinsert, double distance)
Inserts one set of molecules into another.
void change_type(char letter)
Get the data type indicated by a single letter code.
vector< double > & baseline()
Bparticle * particle_add(Bparticle **part, int pid)
Adds a particle parameter structure to a linked list.
Bimage * img_calc_wave_propagator(Vector3< long > size, Vector3< double > sam, double thickness, double volt, double resolution)
Calculates the wave propagation function between slices.
Header file for micrograph processing.
Bimage * extract(long nn)
Extracts one sub-image into new image structure.
Bmicrograph * micrograph_add(Bmicrograph **mg, Bstring &mg_id)
Adds a micrograph parameter structure to a linked list.
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.
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.
int kill_symmetry(Bsymmetry *sym)
Deallocates a symmetry structure.
Header file for generalized linked list functions.
int noise_poisson(double ravg)
Generates an image with a poisson random distribution of densities.
double electron_wavelength(double volt)
Calculates the wavelength in angstrom from the acceleration voltage.
Vector3< double > pixel_size
int complex_product(Bimage *p)
Calculates the complex product of two complex images.
double irm(1.0L/get_rand_max())
void sampling(long nn, Vector3< double > u)
long get_rand_max()
Finds the maximum random number for a system.
vector< double > & envelope()
int project_apply_distortions(Bproject *project, int poisson, double gauss, double kmtf)
Applies imaging distortions to the final images from a multislice calculation.
Bmolgroup * molgroup_copy(Bmolgroup *molgroup)
Copies a molecule group.
Header file for functions to calculate a 3D map from atomic coordinates.
void complex_to_real()
The real part of a complex image is written to a simple image.
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.
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 ¶mfile)
Calculates a 3D set of structure factors from a set of atomic coordinates.
long statistics()
Calculates the statistics for an image.