Planned maintenance on Wednesday, 2021-01-20, 17:00-18:00. Expect some interruptions during that time

Commit 82c718f2 authored by David Rohr's avatar David Rohr

use improved FFTs for real and hermitian input

parent da3cdbbc
This diff is collapsed.
......@@ -30,7 +30,7 @@ public:
int createProjection(int iMap, mycomplex_t* map);
int calcross_cor(bioem_map& localmap,myfloat_t& sum,myfloat_t& sumsquare);
int calProb(int iRefMap,int iOrient, int iConv,myfloat_t sumC,myfloat_t sumsquareC, int value, int disx, int disy);
int calculateCCFFT(int iMap, int iOrient, int iConv, myfloat_t sumC,myfloat_t sumsquareC, mycomplex_t* localConvFFT,mycomplex_t* localCCT,mycomplex_t* lCC);
int calculateCCFFT(int iMap, int iOrient, int iConv, myfloat_t sumC,myfloat_t sumsquareC, mycomplex_t* localConvFFT,mycomplex_t* localCCT,myfloat_t* lCC);
bioem_Probability* pProb;
......
......@@ -10,7 +10,11 @@ typedef float myfloat_t;
#define myfftw_destroy_plan fftwf_destroy_plan
#define myfftw_execute fftwf_execute
#define myfftw_execute_dft fftwf_execute_dft
#define myfftw_execute_dft_r2c fftwf_execute_dft_r2c
#define myfftw_execute_dft_c2r fftwf_execute_dft_c2r
#define myfftw_plan_dft_2d fftwf_plan_dft_2d
#define myfftw_plan_dft_r2c_2d fftwf_plan_dft_r2c_2d
#define myfftw_plan_dft_c2r_2d fftwf_plan_dft_c2r_2d
#define myfftw_plan fftwf_plan
#else
typedef double myfloat_t;
......@@ -19,7 +23,11 @@ typedef double myfloat_t;
#define myfftw_destroy_plan fftw_destroy_plan
#define myfftw_execute fftw_execute
#define myfftw_execute_dft fftw_execute_dft
#define myfftw_execute_dft_r2c fftw_execute_dft_r2c
#define myfftw_execute_dft_c2r fftw_execute_dft_c2r
#define myfftw_plan_dft_2d fftw_plan_dft_2d
#define myfftw_plan_dft_r2c_2d fftw_plan_dft_r2c_2d
#define myfftw_plan_dft_c2r_2d fftw_plan_dft_c2r_2d
#define myfftw_plan fftw_plan
#endif
typedef myfloat_t mycomplex_t[2];
......
......@@ -17,7 +17,6 @@ class bioem_map_forFFT
{
public:
mycomplex_t cpoints[BIOEM_MAP_SIZE_X*BIOEM_MAP_SIZE_Y];
};
class bioem_convolutedMap
......@@ -49,7 +48,6 @@ public:
__host__ __device__ inline const myfloat_t* getp(int map, int x, int y) const {return(&Ref[map].points[x][y]);}
};
class bioem_RefMap_Mod
{
public:
......
......@@ -15,6 +15,7 @@ public:
int maxDisplaceCenter;
int GridSpaceCenter;
int NumberPixels;
int NumberFFTPixels1D;
int NtotDist;
myfloat_t Ntotpi;
myfloat_t volu;
......
......@@ -9,7 +9,6 @@
#include "map.h"
#include "param.h"
using namespace std;
int bioem_RefMap::readRefMaps(bioem_param& param)
......@@ -134,12 +133,14 @@ int bioem_RefMap::PreCalculateMapsFFT(bioem_param& param)
/********** Routine that pre-calculates Kernels for Convolution **********************/
/************************************************************************************/
mycomplex_t* localMap;
myfloat_t* localMap;
localMap= (myfloat_t *) myfftw_malloc(sizeof(myfloat_t) *param.param_device.NumberPixels*param.param_device.NumberPixels);
localMap= (mycomplex_t *) myfftw_malloc(sizeof(mycomplex_t) *param.param_device.NumberPixels*param.param_device.NumberPixels);
RefMapFFT = new bioem_map_forFFT[ntotRefMap];
mycomplex_t* localout;
localout= (mycomplex_t *) myfftw_malloc(sizeof(mycomplex_t) *param.param_device.NumberPixels*param.param_device.NumberPixels);
localout= (mycomplex_t *) myfftw_malloc(sizeof(mycomplex_t) *param.param_device.NumberPixels*param.param_device.NumberFFTPixels1D);
for (int iRefMap = 0; iRefMap < ntotRefMap ; iRefMap++)
{
......@@ -148,21 +149,20 @@ int bioem_RefMap::PreCalculateMapsFFT(bioem_param& param)
{
for(int j=0; j< param.param_device.NumberPixels; j++)
{
localMap[i*param.param_device.NumberPixels+j][0]=Ref[iRefMap].points[i][j];
localMap[i*param.param_device.NumberPixels+j][1]=0.0;
localMap[i*param.param_device.NumberPixels+j]=Ref[iRefMap].points[i][j];
}
}
//Calling FFT_Forward
myfftw_execute_dft(param.fft_plan_c2c_forward,localMap,localout);
myfftw_execute_dft_r2c(param.fft_plan_r2c_forward,localMap,localout);
// Normalizing and saving the Reference CTFs
for(int i=0; i < param.param_device.NumberPixels ; i++ )
{
for(int j=0; j < param.param_device.NumberPixels ; j++ )
for(int j=0; j < param.param_device.NumberFFTPixels1D ; j++ )
{
RefMapFFT[iRefMap].cpoints[i*param.param_device.NumberPixels+j][0]=localout[i*param.param_device.NumberPixels+j][0];
RefMapFFT[iRefMap].cpoints[i*param.param_device.NumberPixels+j][1]=localout[i*param.param_device.NumberPixels+j][1];
RefMapFFT[iRefMap].cpoints[i*param.param_device.NumberFFTPixels1D+j][0]=localout[i*param.param_device.NumberFFTPixels1D+j][0];
RefMapFFT[iRefMap].cpoints[i*param.param_device.NumberFFTPixels1D+j][1]=localout[i*param.param_device.NumberFFTPixels1D+j][1];
}
}
......@@ -172,6 +172,5 @@ int bioem_RefMap::PreCalculateMapsFFT(bioem_param& param)
myfftw_free(localMap);
myfftw_free(localout);
return(0);
}
......@@ -65,7 +65,6 @@ int bioem_model::readModel()
float z = 0.0;
char tmp[6] = {' '};
// parse name
strncpy(tmp,line+12,4);
sscanf (tmp,"%s",name);
......@@ -172,8 +171,6 @@ int bioem_model::readModel()
return(0);
}
myfloat_t bioem_model::getAminoAcidRad(char *name)
{
/*************** Function that gets the radius for each amino acid ****************/
......@@ -209,7 +206,6 @@ myfloat_t bioem_model::getAminoAcidRad(char *name)
}
myfloat_t bioem_model::getAminoAcidDensity(char *name)
{
/*************** Function that gets the number of electrons for each amino acid ****************/
......@@ -242,6 +238,5 @@ myfloat_t bioem_model::getAminoAcidDensity(char *name)
exit(0);
}
return iaa;
}
......@@ -15,6 +15,7 @@ bioem_param::bioem_param()
{
//Number of Pixels
param_device.NumberPixels=0;
param_device.NumberFFTPixels1D = 0;
// Euler angle grid spacing
angleGridPointsAlpha = 0;
angleGridPointsBeta = 0;
......@@ -175,6 +176,7 @@ int bioem_param::readParameters()
}
input.close();
param_device.NumberFFTPixels1D = param_device.NumberPixels / 2 + 1;
cout << " +++++++++++++++++++++++++++++++++++++++++ \n";
cout << "Preparing FFTs\n";
......@@ -183,10 +185,12 @@ int bioem_param::readParameters()
tmp_map = (mycomplex_t *) myfftw_malloc(sizeof(mycomplex_t) * param_device.NumberPixels * param_device.NumberPixels);
tmp_map2 = (mycomplex_t *) myfftw_malloc(sizeof(mycomplex_t) * param_device.NumberPixels * param_device.NumberPixels);
fft_plan_c2c_forward = myfftw_plan_dft_2d(param_device.NumberPixels, param_device.NumberPixels, tmp_map, tmp_map2, FFTW_FORWARD, FFTW_MEASURE);
fft_plan_c2c_backward = myfftw_plan_dft_2d(param_device.NumberPixels, param_device.NumberPixels, tmp_map, tmp_map2, FFTW_BACKWARD, FFTW_MEASURE);
fft_plan_c2c_forward = myfftw_plan_dft_2d(param_device.NumberPixels, param_device.NumberPixels, tmp_map, tmp_map2, FFTW_FORWARD, FFTW_MEASURE | FFTW_DESTROY_INPUT);
fft_plan_c2c_backward = myfftw_plan_dft_2d(param_device.NumberPixels, param_device.NumberPixels, tmp_map, tmp_map2, FFTW_BACKWARD, FFTW_MEASURE | FFTW_DESTROY_INPUT);
fft_plan_r2c_forward = myfftw_plan_dft_r2c_2d(param_device.NumberPixels, param_device.NumberPixels, (myfloat_t*) tmp_map, tmp_map2, FFTW_MEASURE | FFTW_DESTROY_INPUT);
fft_plan_c2r_backward = myfftw_plan_dft_c2r_2d(param_device.NumberPixels, param_device.NumberPixels, tmp_map, (myfloat_t*) tmp_map2, FFTW_MEASURE | FFTW_DESTROY_INPUT);
if (fft_plan_c2c_forward == 0 || fft_plan_c2c_backward == 0)
if (fft_plan_c2c_forward == 0 || fft_plan_c2c_backward == 0 || fft_plan_r2c_forward == 0 || fft_plan_c2r_backward == 0)
{
cout << "Error planing FFTs\n";
exit(1);
......@@ -255,7 +259,6 @@ int bioem_param::CalculateGridsParam() //TO DO FOR QUATERNIONS
}
int bioem_param::CalculateRefCTF()
{
/**************************************************************************************/
......@@ -263,14 +266,13 @@ int bioem_param::CalculateRefCTF()
/************************************************************************************/
myfloat_t amp,env,phase,ctf,radsq;
mycomplex_t* localCTF;
myfloat_t* localCTF;
int nctfmax= param_device.NumberPixels / 2;
int n=0;
localCTF= (mycomplex_t *) myfftw_malloc(sizeof(mycomplex_t) * param_device.NumberPixels*param_device.NumberPixels);
localCTF= (myfloat_t *) myfftw_malloc(sizeof(myfloat_t) * param_device.NumberPixels*param_device.NumberPixels);
refCTF = new bioem_map_forFFT[MAX_REF_CTF];
for (int iamp = 0; iamp < numberGridPointsCTF_amp ; iamp++) //Loop over amplitud
{
amp = (myfloat_t) iamp * gridCTF_amp + startGridCTF_amp;
......@@ -283,7 +285,7 @@ int bioem_param::CalculateRefCTF()
{
env= (myfloat_t) ienv * gridEnvelop + startGridEnvelop;
memset(localCTF,0,param_device.NumberPixels*param_device.NumberPixels*sizeof(mycomplex_t));
memset(localCTF,0,param_device.NumberPixels*param_device.NumberPixels*sizeof(myfloat_t));
//Assigning CTF values
for(int i=0; i< nctfmax; i++)
......@@ -293,25 +295,25 @@ int bioem_param::CalculateRefCTF()
radsq=(myfloat_t) (i*i+j*j) * pixelSize * pixelSize;
ctf=exp(-radsq*env/2.0)*(amp*cos(radsq*phase/2.0)-sqrt((1-amp*amp))*sin(radsq*phase/2.0));
localCTF[i*param_device.NumberPixels+j][0]=(myfloat_t) ctf;
localCTF[i*param_device.NumberPixels+param_device.NumberPixels-j-1][0]=(myfloat_t) ctf;
localCTF[(param_device.NumberPixels-i-1)*param_device.NumberPixels+j][0]=(myfloat_t) ctf;
localCTF[(param_device.NumberPixels-i-1)*param_device.NumberPixels+param_device.NumberPixels-j-1][0]=(myfloat_t) ctf;
localCTF[i*param_device.NumberPixels+j]=(myfloat_t) ctf;
localCTF[i*param_device.NumberPixels+param_device.NumberPixels-j-1]=(myfloat_t) ctf;
localCTF[(param_device.NumberPixels-i-1)*param_device.NumberPixels+j]=(myfloat_t) ctf;
localCTF[(param_device.NumberPixels-i-1)*param_device.NumberPixels+param_device.NumberPixels-j-1]=(myfloat_t) ctf;
}
}
//Creatting FFT_Forward of Kernel to store
mycomplex_t* localout;
localout= (mycomplex_t *) myfftw_malloc(sizeof(mycomplex_t) *param_device.NumberPixels*param_device.NumberPixels);
localout= (mycomplex_t *) myfftw_malloc(sizeof(mycomplex_t) *param_device.NumberPixels*param_device.NumberFFTPixels1D);
//Calling FFT_Forward
myfftw_execute_dft(fft_plan_c2c_forward,localCTF,localout);
myfftw_execute_dft_r2c(fft_plan_r2c_forward,localCTF,localout);
// Normalizing and saving the Reference CTFs
for(int i=0; i < param_device.NumberPixels ; i++ )
{
for(int j=0; j < param_device.NumberPixels ; j++ )
for(int j=0; j < param_device.NumberFFTPixels1D ; j++ )
{
refCTF[n].cpoints[i*param_device.NumberPixels+j][0]=localout[i*param_device.NumberPixels+j][0];
refCTF[n].cpoints[i*param_device.NumberPixels+j][1]=localout[i*param_device.NumberPixels+j][1];
refCTF[n].cpoints[i*param_device.NumberFFTPixels1D+j][0]=localout[i*param_device.NumberFFTPixels1D+j][0];
refCTF[n].cpoints[i*param_device.NumberFFTPixels1D+j][1]=localout[i*param_device.NumberFFTPixels1D+j][1];
}
}
CtfParam[n].pos[0]=amp;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment