82 <<
"Output directory: " <<
fnOutDir << std::endl
83 <<
"Reference volume: " <<
fnVolR << std::endl
84 <<
"Reference mask: " <<
fnMaskR << std::endl
85 <<
"Max. Shift: " <<
maxShift << std::endl
87 <<
"Max. Resolution: " <<
maxResol << std::endl
88 <<
"Sampling: " <<
Ts << std::endl
89 <<
"Max. Radius: " <<
Rmax << std::endl
90 <<
"Max. Radius Deform. " <<
RmaxDef << std::endl
91 <<
"Zernike Degree: " <<
L1 << std::endl
92 <<
"SH Degree: " <<
L2 << std::endl
94 <<
"Correct CTF: " <<
useCTF << std::endl
97 <<
"Regularization: " <<
lambda << std::endl
99 <<
"Blob radius: " <<
blob_r << std::endl
107 addUsageLine(
"Make a continuous angular assignment with deformations");
111 defaultComments[
"-o"].addComment(
"Metadata with the angular alignment and deformation parameters");
114 addParamsLine(
" --priors <metadata_file> : List of priors (deformation coefficients)");
116 addParamsLine(
" [--odir <outputDir=\".\">] : Output directory");
117 addParamsLine(
" [--max_shift <s=-1>] : Maximum shift allowed in pixels");
118 addParamsLine(
" [--max_angular_change <a=5>] : Maximum angular change allowed (in degrees)");
119 addParamsLine(
" [--max_resolution <f=4>] : Maximum resolution (A)");
120 addParamsLine(
" [--sampling <Ts=1>] : Sampling rate (A/pixel)");
121 addParamsLine(
" [--Rmax <R=-1>] : Maximum radius (px). -1=Half of volume size");
122 addParamsLine(
" [--RDef <r=-1>] : Maximum radius of the deformation (px). -1=Half of volume size");
123 addParamsLine(
" [--l1 <l1=3>] : Degree Zernike Polynomials=1,2,3,...");
124 addParamsLine(
" [--l2 <l2=2>] : Harmonical depth of the deformation=1,2,3,...");
125 addParamsLine(
" [--regularization <l=0.005>] : Regularization weight");
128 addParamsLine(
" [--optimizeAlignment] : Optimize alignment");
130 addParamsLine(
" [--phaseFlipped] : Input images have been phase flipped");
131 addParamsLine(
" [--blobr <b=1.5>] : Blob radius for forward mapping splatting");
132 addParamsLine(
" [--image_mode <im=-1>] : Image mode (single, pairs, triplets). By default, it will be automatically identified.");
135 addExampleLine(
"xmipp_angular_sph_alignment -i anglesFromContinuousAssignment.xmd --ref reference.vol -o assigned_anglesAndDeformations.xmd --optimizeAlignment --optimizeDeformation --depth 1");
141 V().setXmippOrigin();
148 bool first_line =
true;
149 while (std::getline(priorsFile, line))
154 L1 = (int)basisParams[0];
L2 = (int)basisParams[1];
RmaxDef = (int)basisParams[2];
156 for (
int idx=3; idx < basisParams.size(); idx++)
298 double deformation=0.0;
302 P[0]().setXmippOrigin();
306 deformVol(
P[0](), mV, deformation, currentRot, currentTilt, currentPsi);
318 P[1]().setXmippOrigin();
319 currentRot =
old_rot[1] + deltaRot[1];
320 currentTilt =
old_tilt[1] + deltaTilt[1];
321 currentPsi =
old_psi[1] + deltaPsi[1];
322 deformVol(
P[1](), mV, deformation, currentRot, currentTilt, currentPsi);
334 xmipp_transformation::IS_NOT_INV, xmipp_transformation::DONT_WRAP, 0.);
336 xmipp_transformation::IS_NOT_INV, xmipp_transformation::DONT_WRAP, 0.);
347 P[1]().setXmippOrigin();
348 currentRot =
old_rot[1] + deltaRot[1];
349 currentTilt =
old_tilt[1] + deltaTilt[1];
350 currentPsi =
old_psi[1] + deltaPsi[1];
351 deformVol(
P[1](), mV, deformation, currentRot, currentTilt, currentPsi);
354 P[2]().setXmippOrigin();
355 currentRot =
old_rot[2] + deltaRot[2];
356 currentTilt =
old_tilt[2] + deltaTilt[2];
357 currentPsi =
old_psi[2] + deltaPsi[2];
358 deformVol(
P[2](), mV, deformation, currentRot, currentTilt, currentPsi);
373 xmipp_transformation::IS_NOT_INV, xmipp_transformation::DONT_WRAP, 0.);
375 xmipp_transformation::IS_NOT_INV, xmipp_transformation::DONT_WRAP, 0.);
377 xmipp_transformation::IS_NOT_INV, xmipp_transformation::DONT_WRAP, 0.);
397 xmipp_transformation::IS_NOT_INV,xmipp_transformation::DONT_WRAP,0.);
424 cost=-(corr1+corr2+corr3) / 2.0;
427 cost=-(corr1+corr2+corr3) / 3.0;
430 cost=-(corr1+corr2+corr3);
435 std::cout <<
"A=" << A << std::endl;
438 save.
write(
"PPPtheo.xmp");
440 save.
write(
"PPPfilteredp.xmp");
442 save.
write(
"PPPfiltered.xmp");
444 std::cout <<
"Cost=" << cost <<
" deformation=" << deformation << std::endl;
445 std::cout <<
"Press any key" << std::endl;
446 char c; std::cin >>
c;
451 std::cout <<
"A1=" <<
A1 << std::endl;
454 save.
write(
"PPPtheo1.xmp");
456 save.
write(
"PPPfilteredp1.xmp");
458 save.
write(
"PPPfiltered1.xmp");
464 std::cout <<
"A2=" <<
A2 << std::endl;
466 save.
write(
"PPPtheo2.xmp");
468 save.
write(
"PPPfilteredp2.xmp");
470 save.
write(
"PPPfiltered2.xmp");
476 std::cout <<
"A2=" <<
A2 << std::endl;
478 save.
write(
"PPPtheo2.xmp");
480 save.
write(
"PPPfilteredp2.xmp");
482 save.
write(
"PPPfiltered2.xmp");
484 std::cout <<
"A3=" <<
A3 << std::endl;
486 save.
write(
"PPPtheo3.xmp");
488 save.
write(
"PPPfilteredp3.xmp");
490 save.
write(
"PPPfiltered3.xmp");
499 std::cout <<
"Press any key" << std::endl;
500 char c; std::cin >>
c;
514 if (sum > 1.0 && bound == 1.0)
518 std::cout << cost <<
" " << deformation << std::endl;
525 int idx = prm->
priors.size();
534 prm->
deltaX[0] = x[idx + 1];
535 prm->
deltaY[0] = x[idx + 3];
543 prm->
deltaX[1] = x[idx + 2];
544 prm->
deltaY[1] = x[idx + 4];
568 prm->
deltaX[0] = x[idx + 1];
569 prm->
deltaY[0] = x[idx + 4];
577 prm->
deltaX[1] = x[idx + 2];
578 prm->
deltaY[1] = x[idx + 5];
586 prm->
deltaX[2] = x[idx + 3];
587 prm->
deltaY[2] = x[idx + 6];
619 prm->
deltaX[0] = x[idx + 1];
620 prm->
deltaY[0] = x[idx + 2];
662 I[0]().setXmippOrigin();
676 I[1]().setXmippOrigin();
681 std::cout <<
"Processing Pair (" <<
fnImage[0] <<
"," <<
fnImage[1] <<
")" << std::endl;
692 I[1]().setXmippOrigin();
703 I[2]().setXmippOrigin();
708 std::cout <<
"Processing Triplet (" <<
fnImage[0] <<
"," <<
fnImage[1] <<
"," <<
fnImage[2] <<
")" << std::endl;
713 std::cout <<
"Processing Image (" <<
fnImage[0] <<
")" << std::endl;
751 std::cout << std::endl;
752 std::cout <<
"------------------------------ Fiding priors linear combination ----------------------------" << std::endl;
767 for (
int i = init;
i < end;
i++)
773 int end = steps.
size();
774 for (
int i = init;
i < end;
i++)
797 std::cout << std::endl;
798 for (
int j = 1;
j < 4;
j++)
803 std::cout <<
"X Coefficients=(";
806 std::cout <<
"Y Coefficients=(";
809 std::cout <<
"Z Coefficients=(";
817 std::cout <<
clnm(
i);
818 if (
i <
j * vecSize - 1)
821 std::cout <<
")" << std::endl;
823 std::cout <<
"Radius=" <<
RmaxDef << std::endl;
824 std::cout <<
" Dshift=(" <<
p(totalSize - 5) <<
"," <<
p(totalSize - 4) <<
") " 825 <<
"Drot=" <<
p(totalSize - 3) <<
" Dtilt=" <<
p(totalSize - 2)
826 <<
" Dpsi=" <<
p(totalSize - 1) << std::endl;
828 std::cout << std::endl;
833 std::cerr << XE.what() << std::endl;
834 std::cerr <<
"Warning: Cannot refine " << fnImg << std::endl;
896 std::vector<double> vectortemp;
898 for (
int j = 0;
j < end_clnm;
j++) {
899 vectortemp.push_back(
clnm(
j));
909 checkPoint.
addRow(rowAppend);
915 for (
int h=0; h<=l2; h++)
919 int numEven=(count>>1)+(count&1 && !(h&1));
921 vecSize += numSPH*numEven;
924 vecSize += numSPH*(l1-h+1-numEven);
932 for (
int idx=0; idx<size; idx++) {
945 for (
int h=0; h<=l2; h++) {
946 int totalSPH = 2*h+1;
948 for (
int l=h; l<=l1; l+=2) {
949 for (
int m=0;
m<totalSPH;
m++) {
970 double rot,
double tilt,
double psi)
978 size_t idxZ0=2*idxY0;
980 double RmaxF2=RmaxF*RmaxF;
981 double iRmaxF=1.0/RmaxF;
998 double gx=0.0, gy=0.0, gz=0.0;
1005 double rr=
sqrt(r2)*iRmaxF;
1006 for (
size_t idx = 0; idx < idxY0; idx++)
1013 auto c = std::array<double, 3>{};
1017 if (rr>0 || l2==0) {
1024 auto pos = std::array<double, 3>{};
1025 double r_x = j + gx;
1026 double r_y = i + gy;
1027 double r_z = k + gz;
1032 double voxel_mV =
A3D_ELEM(mV,k,i,j);
1034 modg += gx*gx+gy*gy+gz*gz;
1041 def =
sqrt(modg/Ncount);
1050 double fx0 = x -
x0;
1052 double fx1 = x1 -
x;
1055 double fy0 = y -
y0;
1057 double fy1 = y1 -
y;
1060 double fz0 = z -
z0;
1062 double fz1 = z1 -
z;
1078 double x_pos = r[0];
1079 double y_pos = r[1];
1080 double z_pos = r[2];
1085 for (
int i = i0;
i <= iF;
i++)
1088 for (
int j = j0;
j <= jF;
j++)
1091 A2D_ELEM(mP,
i,
j) += weight * x_val * y_val;
1098 std::stringstream iss(s);
1100 std::vector<double> v;
1101 while (iss >> number)
1102 v.push_back(number);
1109 for (
int idx=0; idx < 3*
vecSize; idx++)
1111 for (
int idc = 0; idc <
priors.size(); idc++)
1119 std::vector<double>
z(
priors[0].size(), 0.0);
1237 auto lambda_aux =
lambda;
1239 for (
int idx=0; idx <
priors.size(); idx++)
1249 std::vector<std::size_t> index_vec;
1250 for (std::size_t
i = 0;
i !=
priors.size(); ++
i)
1252 index_vec.push_back(
i);
1256 index_vec.begin(), index_vec.end(),
1257 [&](std::size_t
a, std::size_t
b)
1258 {
return cost_vec[
a] < cost_vec[
b]; });
1260 auto priors_aux =
priors;
1264 for (std::size_t
i = 0;
i != index_vec.size(); ++
i)
1266 auto v = priors_aux[index_vec[
i]];
1267 auto d = prior_deformations_aux[index_vec[
i]];
1268 bool zeros = std::all_of(v.begin(), v.end(), [](
double j) {
return j==0.0; });
1274 else if (zeros &&
i==0)
1282 if (0. < x && x <
blob_r)
1284 else if (-
blob_r < x && x <= 0.)
void splattingAtPos(std::array< double, 3 > r, double weight, MultidimArray< double > &mP, const MultidimArray< double > &mV)
std::vector< Image< double > > Ifiltered
#define A2D_ELEM(v, i, j)
std::vector< double > old_shiftX
double alpha
Smoothness parameter.
virtual void checkPoint()
For very long programs, it may be needed to write checkpoints.
double getDoubleParam(const char *param, int arg=0)
__host__ __device__ float2 floor(const float2 v)
void numCoefficients(int l1, int l2, int &vecSize)
Length of coefficients vector.
virtual void finishProcessing()
void Euler_angles2matrix(T alpha, T beta, T gamma, Matrix2D< T > &A, bool homogeneous)
MultidimArray< int > mask2D
std::vector< double > deltaDefocusAngle
void sqrt(Image< double > &op)
double DeltafV
Defocus in V (in Angstroms). Negative values are underfocused.
std::vector< double > deltaX
std::vector< double > old_shiftY
std::vector< std::vector< double > > priors
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
double correlationIndex(const MultidimArray< T > &x, const MultidimArray< T > &y, const MultidimArray< int > *mask=NULL, MultidimArray< double > *Contributions=NULL)
void abs(Image< double > &op)
void linearCombinationClnm()
std::vector< double > old_defocusV
void setFileName(const FileName &fn)
std::vector< double > string2vector(std::string const &s) const
double bspline1(double x)
std::vector< double > currentDefocusU
void optimalPowellOrder()
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
std::vector< double > old_psi
double DeltafU
Global gain. By default, 1.
#define MAT_ELEM(m, i, j)
#define A3D_ELEM(V, k, i, j)
double azimuthal_angle
Azimuthal angle (between X and U) in degrees.
std::vector< double > prior_deformations
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
const FileName & getFileName() const
T & getValue(MDLabel label)
const char * getParam(const char *param, int arg=0)
std::vector< FileName > fnImage
std::vector< double > deltaDefocusV
void defineParams()
Define parameters.
std::vector< double > deltaDefocusU
std::vector< Image< double > > I
std::vector< double > deltaTilt
~ProgForwardZernikeImagesPriors()
Destructor.
MultidimArray< int > V_mask
double Tm
Sampling rate (A/pixel)
Matrix1D< double > steps_cp
void addExampleLine(const char *example, bool verbatim=true)
void readFromMdRow(const MDRow &row, bool disable_if_not_K=true)
int verbose
Verbosity level.
Matrix1D< double > c_priors
void sort(struct DCEL_T *dcel)
std::vector< double > old_defocusU
std::vector< double > deltaPsi
const T & getValueOrDefault(MDLabel label, const T &def) const
double continuousZernikePriorsCost(double *x, void *_prm)
std::vector< double > deltaY
double K
Global gain. By default, 1.
void setValue(MDLabel label, const T &d, bool addLabel=true)
void readParams()
Read argument from command line.
void generate_mask(bool apply_geo=false)
virtual bool containsLabel(MDLabel label) const =0
void typeCast(const Matrix1D< T1 > &v1, Matrix1D< T2 > &v2)
#define BINARY_CIRCULAR_MASK
void produceSideInfo()
Produce Side information.
double psi(const double x)
std::vector< double > old_rot
std::vector< double > old_defocusAngle
int order
Derivation order and Bessel function order.
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
virtual void writeImageParameters(MDRow &row)
bool checkParam(const char *param)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
void addUsageLine(const char *line, bool verbatim=false)
std::vector< double > currentAngle
std::vector< double > old_tilt
FileName fnOutDir
Output directory.
bool enable_CTFnoise
Enable CTFnoise part.
const MultidimArray< int > & get_binary_mask() const
void minimizepos(Matrix1D< double > &steps)
Determine the positions to be minimize of a vector containing spherical harmonic coefficients.
T * adaptForNumericalRecipes() const
int getIntParam(const char *param, int arg=0)
std::vector< double > deltaRot
std::vector< Image< double > > Ifilteredp
ProgForwardZernikeImagesPriors()
Empty constructor.
void generateMask(MultidimArray< double > &v)
Matrix1D< double > weightsInterpolation3D(double x, double y, double z)
Image< double > Vdeformed
double radius
Spatial radius in Universal System units.
std::vector< double > currentDefocusV
void fillVectorTerms(int l1, int l2, Matrix1D< int > &vL1, Matrix1D< int > &vN, Matrix1D< int > &vL2, Matrix1D< int > &vM)
Zernike and SPH coefficients allocation.
void updateCTFImage(double defocusU, double defocusV, double angle)
void addParamsLine(const String &line)
std::vector< Image< double > > P
void deformVol(MultidimArray< double > &mVD, const MultidimArray< double > &mV, double &def, double rot, double tilt, double psi)
Deform a volumen using Zernike-Spherical harmonic basis.
void applyMaskSpace(MultidimArray< double > &v)
std::map< String, CommentList > defaultComments
double transformImageSph(double *pc_priors)