54 unsigned long slice_size = size.x()*size.y();
56 for ( i=0; i<slice_size; i++ ) p->
set(i, cv);
59 for ( i=0; i<pgrate->
images(); i++ ) {
64 if ( i < pgrate->images()-1 ) {
85 double thickness,
double volt,
double resolution)
89 if ( resolution < sampling.
x() || resolution > 1000 )
90 resolution = sampling.
x();
94 double arg, sx2, sy2, s2;
95 double afactor =
M_PI*wavelength*thickness;
97 double resmax2 = 1.0/(resolution*resolution);
98 double xscale2 = 1.0/(p->
sizeX()*p->
sizeX()*sampling.
x()*sampling.
x());
99 double yscale2 = 1.0/(p->
sizeY()*p->
sizeY()*sampling.
y()*sampling.
y());
101 for ( y=0; y<p->
sizeY(); y++ ) {
105 if ( sy2 <= resmax2 )
for ( x=0; x<p->
sizeX(); x++ ) {
110 if ( s2 <= resmax2 ) {
111 i = y*p->
sizeX() + x;
137 Vector3<float> sampling,
double thickness,
double resolution,
double Bfactor,
141 unsigned long i, j, k;
146 cout <<
"Calculating the atomic potential" << endl;
155 p->
sampling(sampling.
x(), sampling.
y(), thickness);
158 for ( i=0; i<nslices; i++ ) {
160 origin[2] = -slice_molgroup[i]->
min.
z()/sampling.
z() - 0.5;
161 size[2] = (int) (thickness/sampling.
z() + 1);
163 resolution, 0.001, 0, 2 - type, spacegroup, unit_cell);
165 ptemp->project(
'z', 1);
166 ptemp->simple_to_complex();
172 sampling[2] = thickness;
174 resolution, spacegroup, unit_cell, 2, Bfactor, paramfile);
177 for ( j=0, k=i*imgsize; j<imgsize; j++, k++ ) p->
set(k, (*ptemp)[j]);
181 cout <<
"Slice " << i+1 <<
" done" << endl << endl;
186 for ( i=0; i<nslices; i++ )
189 delete[] slice_molgroup;
207 unsigned long i, j, n;
208 unsigned long imgsize = p->
sizeX()*p->
sizeY();
211 double sigma = 0.0208886 * wavelength *
212 sqrt(1 + 5.8886579e-4/(wavelength*wavelength));
215 cout <<
"Sigma (interaction factor): " << sigma << endl;
217 for ( i=n=0; n<p->
images(); n++ ) {
218 for ( j=0; j<imgsize; i++, j++ ) {
219 arg = -sigma*(p->
complex(i)).real();
248 double volts,
double Cs,
double Cc,
double amp_fac,
double alpha,
double energy_spread)
251 unsigned long i, n, x, y, z;
252 double xx, yy, zz, sx2, sy2, sz2, s, s2, defocus, dphi, env, arg;
255 double hpil3Cs =
M_PI_2*lambda*lambda*lambda*Cs;
256 double pil =
M_PI*lambda;
257 double pialf =
M_PI*alpha;
258 double Csl2 = Cs*lambda*lambda;
259 double focus_spread = Cc*energy_spread;
260 double pi2l2df2 =
M_PI*
M_PI*lambda*lambda*focus_spread*focus_spread/(16.0*log(2.0));
265 cout <<
"Applying a CTF to a complex Fourier transform" << endl;
268 cout <<
"Defocus average & deviation: " << def_avg <<
" A " << def_dev <<
" A" << endl;
269 cout <<
"Astigmatism angle: " << ast_angle*180/
M_PI <<
" degrees" << endl;
270 cout <<
"Voltage: " << volts <<
" V" << endl;
271 cout <<
"Wavelength: " << lambda << endl;
272 cout <<
"Cs: " << Cs <<
" A" << endl;
273 cout <<
"Cc: " << Cc <<
" A" << endl;
274 cout <<
"Amplitude contrast: " << amp_fac << endl;
275 cout <<
"Beam source size: " << alpha <<
" radians" << endl;
276 cout <<
"Energy spread (focus spread): " << energy_spread <<
" (" << focus_spread <<
" A)" << endl << endl;
279 for ( i=n=0; n<p->
images(); n++ ) {
280 for ( z=0; z<p->
sizeZ(); z++ ) {
282 if ( z > (p->
sizeZ() - 1)/2 ) zz -= p->
sizeZ();
283 sz2 = freq_scale.z()*zz;
285 for ( y=0; y<p->
sizeY(); y++ ) {
287 if ( y > (p->
sizeY() - 1)/2 ) yy -= p->
sizeY();
288 sy2 = freq_scale.y()*yy;
290 for ( x=0; x<p->
sizeX(); x++, i++ ) {
292 if ( x > (p->
sizeX() - 1)/2 ) xx -= p->
sizeX();
293 sx2 = freq_scale.x()*xx;
295 s2 = sx2 + sy2 + sz2;
297 defocus = def_avg + def_dev*cos(2*(atan2(yy,xx)-ast_angle));
298 dphi = (hpil3Cs*s2 - pil*defocus)*s2;
299 arg = pialf*(Csl2*s2 - defocus)*s;
301 arg = arg*arg + pi2l2df2*s2*s2;
305 p->
set(i, ((*p)[i] * ctf) * env);
Bimage * img_calc_wave_propagator(Vector3< int > size, Vector3< float > sampling, double thickness, double volt, double resolution)
Calculates the wave propagation function between slices.
Header file for functions to calculate a 3D map from atomic coordinates.
Header file for general utilities.
int complex_product(Bimage *p)
Calculates the complex product of two complex images.
int img_apply_complex_CTF(Bimage *p, double def_avg, double def_dev, double ast_angle, double volts, double Cs, double Cc, double amp_fac, double alpha, double energy_spread)
Applies a complex CTF function to a Fourier transform.
Class for complex numbers.
void unit_cell(UnitCell u)
int img_calc_phase_grating(Bimage *p, double volt)
Calculates the phase grating approximation from the atomic potential.
Bimage * img_calc_potential(Bmolgroup *molgroup, Vector3< int > size, Vector3< float > origin, Vector3< float > sampling, double thickness, double resolution, double Bfactor, Bstring ¶mfile, int type)
Calculates the atomic potential.
Vector3< size_t > size() const
Bimage * img_sf_from_molecule(Bmolgroup *molgroup, Vector3< float > origin, Vector3< int > size, Vector3< float > sampling, 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.
General image parameter class.
Vector3< double > real_size()
Complex< double > complex(size_t j)
Returns a complex value at the given index.
int molgroup_kill(Bmolgroup *molgroup)
Destroys a molecule group.
void simple_to_complex()
A simple image is converted to a complex image.
unsigned int space_group()
void origin(double x, double y, double z)
void set(size_t j, double v)
Sets a single value at the given index.
Bimage * extract(size_t nn)
Extracts one sub-image into new image structure.
Header file for CTF (contrast transfer function) functions.
Class for 3-value vectors.
Bimage * img_calc_multi_slice(Bimage *pgrate, double thickness, double volt, double resolution)
Simulates the electron imaging process using a multi-slice approach.
Header file for multi-slice simulation of the electron imaging process.
Bimage * img_from_molecule(Bmolgroup *molgroup, Vector3< float > origin, Vector3< int > size, Vector3< float > sampling, double resolution, double Bfactor, int wrap, int gextype, int spacegroup, UnitCell unit_cell)
Calculates a 3D density map from a set of atomic coordinates.
Bmolgroup ** molgroup_split_into_slices(Bmolgroup *molgroup, double slice_thickness, int &nslices)
Splits a set of coordinates into slices with a given thickness.
double electron_wavelength(double volt)
Calculates the wavelength in angstrom from the acceleration voltage.
Library routines used for atomic coordinates.
FourierType fourier_type()
void origin(double ox, double oy, double oz)