def Transform(self): '''Return the FFT of the 3D grid''' return fft.lib().fftn_R2C(self.grid)
def InverseTransform(self): '''Return the inverse FFT of the 3D grid''' return np.real_if_close(fft.lib().ifftn_C2R(self.grid), tol = 10000000)
fC = np.zeros([grd_size], dtype=float) FC = np.zeros([grd_size], dtype=complex) # Setup 1D grids representing discretized molecules # fA = (0, 0, 0, 0, 0, 0, 1, -5, 1, 1, 0, 0, 0, 0, 0, 0) # fB = (0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0) fA[6:10] = 1.0 fA[7] = -5.0 fB[6:10] = 1.0 print print 'fA =', fA.round() print 'fB =', fB.round() print # Transform "molecule" grids FA = fft.lib().fftn_R2C(fA) FB = fft.lib().fftn_R2C(fB) #FA = np.fft.fft(fA) #FB = np.fft.fft(fB) # Perform Fourier correlation FC = FA.conj() * FB # Perform inverse transform fC = np.real_if_close(fft.lib().ifftn_C2R(FC)) # Look at the correlation function (fC) and the position of the best score # before shifting. print 'fC =', fC.round(), 'no shift' print 'fC max =', fC.max(), 'fC maxloc =', fC.argmax() print