Core of the Adjust CTF routine. This is the routine which does everything. It returns the fitting error committed in the best fit.
1478 std::cout <<
"Best background Fit:\n" << prm.
current_ctfmodel << std::endl;
1564 prm2D->noDefocusEstimate=
true;
1574 if (prm2D->initial_ctfmodel.Q0 != 0)
1576 if (prm2D->modelSimplification >= 3)
1578 if (prm2D->modelSimplification >= 2)
1580 if (prm2D->modelSimplification >= 1)
1582 if(prm2D->initial_ctfmodel.VPP_radius == 0)
1592 prm2D, 0.01, fitness, iter, steps, prm2D->show_optimization);
1594 prm2D->current_ctfmodel.forcePhysicalMeaning();
1597 if (!prm.
noDefocusEstimate && prm2D->current_ctfmodel.DeltafV > prm2D->current_ctfmodel.DeltafU)
1600 temp = prm2D->current_ctfmodel.DeltafU;
1601 prm2D->current_ctfmodel.DeltafU = prm2D->current_ctfmodel.DeltafV;
1602 prm2D->current_ctfmodel.DeltafV = temp;
1603 prm2D->current_ctfmodel.azimuthal_angle -= 90;
1606 if (prm2D->show_optimization)
1608 std::cout <<
"Best fit with 2D parameters:\n" << prm2D->current_ctfmodel << std::endl;
1609 prm2D->saveIntermediateResults(
"step05b_estimate_2D_parameters",
true);
1616 if (prm2D->fn_psd !=
"")
1619 prm2D->mask_between_zeroes.initZeros(prm2D->mask);
1626 prm2D->current_ctfmodel.lookFor(3,
u, z3, 0);
1629 prm2D->current_ctfmodel.lookFor(1,
u, z1, 0);
1636 prm2D->current_ctfmodel.lookFor(3,
u, z3, 0);
1637 prm2D->current_ctfmodel.lookFor(1,
u, z1, 0);
1638 double z1m = z1.module();
1639 double z3m = z3.module();
1643 if (wn<=z3m && wn>=z1m)
1647 CTF_fitness(prm2D->adjust_params->adaptForNumericalRecipes(), prm2D);
1651 FileName fn_rootMODEL = fn_rootCTFPARAM;
1652 size_t atPosition=fn_rootCTFPARAM.find(
'@');
1654 if (atPosition!=std::string::npos)
1657 fn_rootCTFPARAM.substr(atPosition+1).c_str());
1659 fn_rootCTFPARAM.substr(atPosition+1).c_str());
1662 fn_rootCTFPARAM=(
String)
"fullMicrograph@"+fn_rootCTFPARAM;
1664 prm2D->saveIntermediateResults(fn_rootMODEL,
false);
1665 prm2D->current_ctfmodel.Tm /= prm2D->downsampleFactor;
1666 prm2D->current_ctfmodel.azimuthal_angle = std::fmod(prm2D->current_ctfmodel.azimuthal_angle,360.);
1667 prm2D->current_ctfmodel.phase_shift = (prm2D->current_ctfmodel.phase_shift*180)/3.14;
1668 if(prm2D->current_ctfmodel.phase_shift<0.0)
1669 prm2D->current_ctfmodel.phase_shift = 0.0;
1671 prm2D->current_ctfmodel.write(fn_rootCTFPARAM +
".ctfparam_tmp");
1673 MD.
read(fn_rootCTFPARAM +
".ctfparam_tmp");
1684 fn_rootCTFPARAM = fn_rootCTFPARAM +
".ctfparam_tmp";
1686 fn_rootCTFPARAM.deleteFile();
1688 output_ctfmodel = prm2D->current_ctfmodel;
#define DEBUG_TEXTFILE(str)
#define VECTOR_R2(v, x, y)
MultidimArray< double > * f
Image< double > ctftomodel
CTF amplitude to model.
FileName removeLastExtension() const
double heavy_penalization
void estimate_background_gauss_parameters_fast()
void estimate_envelope_parameters_fast()
CTFDescription1D initial_ctfmodel
constexpr int FIRST_SQRT_PARAMETER
Matrix1D< double > * adjust_params
double DeltafV
Defocus in V (in Angstroms). Negative values are underfocused.
void estimate_background_sqrt_parameters_fast()
void show()
Show parameters.
double evaluateIceness(const MultidimArray< double > &enhanced_ctftomodel, double Tm)
#define DEBUG_OPEN_TEXTFILE(fnRoot)
#define COPY_ctfmodel_TO_CURRENT_GUESS
FileName fn_psd
CTF filename.
constexpr int ALL_CTF_PARAMETERS2D
double max_freq
Maximum frequency to adjust.
static constexpr double penalty
double DeltafU
Global gain. By default, 1.
bool enable_CTF
Enable CTF part.
double azimuthal_angle
Azimuthal angle (between X and U) in degrees.
void produceSideInfo()
Produce side information.
double CTF_fitness_fast(double *, void *)
bool noDefocusEstimate
No defocus estimate.
void resize(size_t Xdim, bool copy=true)
constexpr int ALL_CTF_PARAMETERS
double CTF_fitness(double *p, void *vprm)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
bool refineAmplitudeContrast
Refine amplitude contrast.
#define DIRECT_MULTIDIM_ELEM(v, n)
CTFDescription1D current_ctfmodel
double Cs
Spherical aberration (in milimeters). Typical value 5.6.
#define DEBUG_MODEL_TEXTFILE
void estimate_defoci_fast()
bool show_optimization
Show convergence values.
void forcePhysicalMeaning()
double Defocus
Defocus (in Angstroms). Negative values are underfocused.
CTFDescription initial_ctfmodel2D
void saveIntermediateResults_fast(const FileName &fn_root, bool generate_profiles)
void estimate_background_gauss_parameters2_fast()
Matrix1D< double > adjust
Set of parameters for the complete adjustment of the CTF.
#define MATRIX1D_ARRAY(v)
int modelSimplification
Model simplification.
FileName withoutExtension() const
double min_freq
Minimum frequency to adjust.
String formatString(const char *format,...)
int textToInteger(const char *str)
double y0
In the case of local CTF determination x0,xF,y0,yF determines the region where the CTF is determined...
double Q0
Factor for the importance of the Amplitude contrast.
ProgCTFEstimateFromPSDFast * global_prm
double x0
In the case of local CTF determination x0,xF,y0,yF determines the region where the CTF is determined...
double kV
Accelerating Voltage (in KiloVolts)
bool enable_CTFnoise
Enable CTFnoise part.
double xF
In the case of local CTF determination x0,xF,y0,yF determines the region where the CTF is determined...
double yF
In the case of local CTF determination x0,xF,y0,yF determines the region where the CTF is determined...
double fitness(double *p)
constexpr int BACKGROUND_CTF_PARAMETERS