 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
27 if ( ctf.
Cs() )
Cs(ctf.
Cs());
28 if ( ctf.
Cc() ) cc = ctf.
Cc();
30 if ( ctf.
dE() ) de = ctf.
dE();
74 cerr <<
"in CTFparam::calculate" << endl;
78 if ( npsi < 1 ) npsi = 1;
81 double s2, dphi, defocus;
82 double dpsi =
M_PI*2.0/npsi;
84 ctf.resize(nrad*npsi);
87 for ( j=k=0; j<npsi; j++ ) {
88 if ( npsi > 1 ) defocus = def_avg + def_dev*cos(2*(j*dpsi-ast_ang));
89 for ( i=0; i<nrad; i++, k++ ) {
92 dphi = (t1*s2 - t2*defocus)*s2 - ac;
122 cerr <<
"in CTFparam::zeroes" << endl;
127 double t, sm2(max_s*max_s);
129 double l3Cs = l*l*l*cs/2.0;
130 double fz = def_avg/(l*l*cs), fz2 = fz*fz;
135 long nzero = (long) (l*def_avg*sm2 - l3Cs*sm2*sm2 + ps);
137 if ( nzero < 1 ) nzero = 1;
140 cout <<
"DEBUG CTFparam::zeroes: " << nzero <<
tab << max_s << endl;
144 for ( i=0; i<nzero; i++ ) {
147 zero[i] = sqrt(fz - sqrt(fz2 - t));
154 for ( i=0; i<nzero; i++ ) cout << i+1 <<
tab <<
zero[i] <<
tab << 1.0/
zero[i] << endl;
169 if ( base[0] <= 0 && base[1] == 0 ) base[0] = 1;
176 bleq +=
Bstring(base[1],
" + %.4g*$s") +
Bstring(base[2],
" + %.4g*$s2")
177 +
Bstring(base[3],
" + %.4g*$s3") +
Bstring(base[4],
" + %.4g*$s4");
181 bleq +=
Bstring(base[1],
" + %.4g") +
Bstring(base[2],
"*exp(%.4g*$s2)")
182 +
Bstring(base[3],
" + %.4g") +
Bstring(base[4],
"*exp(%.4g*$s2)");
186 bleq +=
Bstring(base[1],
" + %.4g") +
Bstring(base[2],
"*exp(%.4g*sqrt($s)")
187 +
Bstring(base[3],
" + %.4g*$s2)");
196 bleq +=
Bstring(base[5],
" + %.4g") +
Bstring(base[7],
"*exp(%.4g")
197 +
Bstring(base[6],
"*(%.4g - $s)") +
Bstring(base[6],
"*(%.4g - $s))");
217 enveq +=
Bstring(env[1],
"*exp(%.4g*$s2)");
220 enveq +=
Bstring(env[1],
" + %.4g") +
Bstring(env[2],
"*exp(%.4g*$s2)");
223 enveq +=
Bstring(env[1],
"*exp(%.4g*$s2)") +
227 enveq +=
Bstring(env[1],
" + %.4g") +
Bstring(env[2],
"*exp(%.4g*$s2)") +
246 base_eq = base_eq.
remove(
'\"');
252 sscanf(base_eq.
c_str(),
"%lf + %lf*$s + %lf*$s2 + %lf*$s3 + %lf*$s4%n",
253 &base[0], &base[1], &base[2], &base[3], &base[4], &n);
254 }
else if ( base_eq.
contains(
"sqrt") ) {
256 sscanf(base_eq.
c_str(),
"%lf + %lf*exp(%lf*sqrt($s) + %lf*$s2)%n",
257 &base[0], &base[1], &base[2], &base[3], &n);
258 }
else if ( base_eq.
contains(
"exp") ) {
260 sscanf(base_eq.
c_str(),
"%lf + %lf*exp(%lf*$s2) + %lf*exp(%lf*$s2)%n",
261 &base[0], &base[1], &base[2], &base[3], &base[4], &n);
264 char* ptr = &base_eq[n];
265 if ( strstr(ptr,
"exp") ) {
267 sscanf(ptr,
" + %lf*exp(%lf*(%lf - $s)*(%lf - $s))",
268 &base[5], &base[7], &base[6], &base[6]);
274 cout <<
"DEBUG parse_baseline_equation: bt=" << bt <<
" baseline=" <<
275 base[0] <<
"," << base[1] <<
"," << base[2] <<
"," <<
276 base[3] <<
"," << base[4] << endl;
291 env_eq = env_eq.
remove(
'\"');
297 sscanf(env_eq.
c_str(),
"%lf*exp(%lf*$s2)",
301 sscanf(env_eq.
c_str(),
"%lf + %lf*exp(%lf*$s2)",
302 &env[0], &env[1], &env[2]);
305 sscanf(env_eq.
c_str(),
"%lf*exp(%lf*$s2) + %lf*exp(%lf*$s2)",
306 &env[0], &env[1], &env[2], &env[3]);
309 sscanf(env_eq.
c_str(),
"%lf + %lf*exp(%lf*$s2) + %lf*exp(%lf*$s2)",
310 &env[0], &env[1], &env[2], &env[3], &env[4]);
343 double l =
lambda(), Csl2(cs*l*l);
344 double s, arg, pal(
M_PI*a);
345 vector<double> curve(n);
347 for ( i=0; i<n; i++ ) {
349 arg = pal*(Csl2*s*s - def_avg)*s;
350 curve[i] = exp(-arg*arg);
381 vector<double> curve(n);
383 for ( i=0; i<n; i++ ) {
386 curve[i] = exp(-fac*arg*arg);
401 js[
"Volt"] = cp.
volt();
402 js[
"Wavelength"] = cp.
lambda();
408 js[
"Beam_convergence"] = cp.
alpha();
409 js[
"Energy_spread"] = cp.
dE();
427 if ( js.
exists(
"Volt") ) cp.
volt(js[
"Volt"].real());
432 if ( js.
exists(
"Cs") ) cp.
Cs(js[
"Cs"].real());
433 if ( js.
exists(
"Cc") ) cp.
Cc(js[
"Cc"].real());
434 if ( js.
exists(
"Beam_convergence") ) cp.
alpha(js[
"Beam_convergence"].real());
435 if ( js.
exists(
"Energy_spread") ) cp.
dE(js[
"Energy_spread"].real());
436 if ( js.
exists(
"Amplitude_phase") ) cp.
amp_shift(js[
"Amplitude_phase"].real());
459 error_show(
"Error in electron_wavelength", __FILE__, __LINE__);
460 cerr <<
"The acceleration voltage is below 1 V! (" << volt <<
" V)" << endl;
502 return sqrt(
beta2(volt));
515 vector<double>
C_curve(
long n,
double freq_step)
519 vector<double> curve(n);
521 for ( i=0; i<n; i++ ) {
524 curve[i] = 0.893*exp(-0.2465*s2) + 0.2563*exp(-1.7100*s2) +
525 0.7570*exp(-6.4094*s2) + 1.0487*exp(-18.6113*s2) +
526 0.3575*exp(-50.2523*s2);
547 long n(scut/freq_step+1);
550 vector<double> c(n, 0.5);
556 vector<double> c(n, 0);
560 for ( def = def_min; def <= def_max; def += def_step, ++m ) {
562 for ( i=0; i<n; ++i ) {
572 for ( i=0; i<n; ++i )
591 if ( def_min < 1 )
return 0.5;
596 for (
auto it = c.begin(); it != c.end(); ++it ) def_fac += *it;
Bstring remove(const char c)
int update(CTFparam *ctf)
double objective_aperture()
double astigmatism_angle()
int error_show(string message, string file, int line)
Displays the error with file and line reference.
vector< double > defocus_range_profile(CTFparam &ctf, double freq_step, double def_min, double def_max, double def_step)
Calculates a weighting profile associated with a range of defocus values.
vector< double > envelope_energy_spread(long n, double freq_step)
Calculates the envelope curve based on energy spread.
int parse_baseline_equation(Bstring base_eq)
Extracts the coefficients from the baseline string.
JSvalue ctf_to_json(CTFparam &cp)
Converts microscope parameters to a JSON object list.
double calculate(double s2, double angle)
vector< double > C_curve(long n, double freq_step)
Calculates the carbon scattering curve.
Header file for CTF (contrast transfer function) functions.
Bstring envelope_equation()
Generates an envelope equation string from 4 coefficients.
vector< double > envelope_partial_coherence(long n, double freq_step)
Calculates the envelope curve based on partial coherence.
CTFparam ctf_from_json(JSvalue &js)
Converts a JSON object list to microscope parameters.
int parse_envelope_equation(Bstring env_eq)
Extracts the coefficients from the envelope string.
double electron_wavelength(double volt)
Calculates the wavelength in angstrom from the acceleration voltage.
double defocus_deviation()
vector< double > zeroes(double max_s)
Calculates the zeroes of a CTF curve on the spatial frequency scale.
Header file for general utilities.
ostream & tab(ostream &out)
bool isfinite(complex< T > &value)
vector< double > & baseline()
double frequency_cutoff()
double defocus_factor(CTFparam &ctf, double def_min, double def_max, double def_step)
Calculates an integrated defocus weighting factor for a raneg of defocus values.
double beta2(double volt)
Calculates the square of the relative electron velocity.
bool contains(const Bstring &s)
Bstring baseline_equation()
Generates a baseline equation string from 4 to 10 coefficients.
vector< double > & envelope()
double beta(double volt)
Calculates the relative electron velocity.