def fft_and_extrapolate(f, k, dr, direction, n_pots_for_extrap=6): """ uses pubfft.sinfti routine computes sinfti(f, dr, direction)/k and extrapolates to 0 """ f_c = f.copy() f_k = pubfft.sinfti(f_c[1:], dr, direction) / k[1:] # extrapolates to 0 r_for_extrp = [dr * (i + 1) for i in range(n_pots_for_extrap)] return extrapolate_to_0(f_k, r_for_extrp, n_pots_for_extrap)
def compute_xvvr(self): """ Return xvv(r) matrix """ r = np.array([i * self.dr for i in range(self.ngrid)]) k = self.get_k() xvvr = [["" for i in range(self.nsites)] for j in range(self.nsites)] for i in range(self.nsites): for j in range(self.nsites): xvvk_ij = self.xvv_data[:, i, j] xvvr_ij = pubfft.sinfti(xvvk_ij * k, self.dr, -1) / r # n_pots_for_interp = 6 # r_for_interp = r[1:n_pots_for_interp+1] # xvvr_for_interp = xvvr_ij[:n_pots_for_interp] # poly_coefs = np.polyfit(r_for_interp, xvvr_for_interp, 3) # poly_f = np.poly1d(poly_coefs) # xvvr[i][j] = [poly_f(0)] xvvr[i][j] = xvvr_ij return r, np.swapaxes(xvvr, 0, 2)
def compute_xvvr(self): """ Return xvv(r) matrix """ r = np.array([i*self.dr for i in range(self.ngrid)]) k = self.get_k() xvvr = [["" for i in range(self.nsites)] for j in range(self.nsites)] for i in range(self.nsites): for j in range(self.nsites): xvvk_ij = self.xvv_data[:,i,j] xvvr_ij = pubfft.sinfti(xvvk_ij*k, self.dr, -1)/r # n_pots_for_interp = 6 # r_for_interp = r[1:n_pots_for_interp+1] # xvvr_for_interp = xvvr_ij[:n_pots_for_interp] # poly_coefs = np.polyfit(r_for_interp, xvvr_for_interp, 3) # poly_f = np.poly1d(poly_coefs) # xvvr[i][j] = [poly_f(0)] xvvr[i][j] = xvvr_ij return r, np.swapaxes(xvvr, 0, 2)
def compute_zr(self): """ Return z(r) matrix """ r = np.array([i * self.dr for i in range(self.ngrid)]) k, zk = self.compute_zk() print 'computed zk', zk.shape zr = [["" for i in range(self.nsites)] for j in range(self.nsites)] for i in range(self.nsites): for j in range(self.nsites): zk_ij = zk[1:, i, j] zr_ij = pubfft.sinfti(zk_ij * k[1:], self.dr, -1) / r[1:] #zr_ij = np.abs(fftpack.fft(zk_ij)) n_pots_for_interp = 6 r_for_interp = r[1:n_pots_for_interp + 1] zr_for_interp = zr_ij[:n_pots_for_interp] poly_coefs = np.polyfit(r_for_interp, zr_for_interp, 3) poly_f = np.poly1d(poly_coefs) zr[i][j] = [poly_f(0)] zr[i][j].extend(zr_ij) return r, np.swapaxes(zr, 0, 2)
def compute_zr(self): """ Return z(r) matrix """ r = np.array([i*self.dr for i in range(self.ngrid)]) k, zk = self.compute_zk() print 'computed zk',zk.shape zr = [["" for i in range(self.nsites)] for j in range(self.nsites)] for i in range(self.nsites): for j in range(self.nsites): zk_ij = zk[1:,i,j] zr_ij = pubfft.sinfti(zk_ij*k[1:], self.dr, -1)/r[1:] #zr_ij = np.abs(fftpack.fft(zk_ij)) n_pots_for_interp = 6 r_for_interp = r[1:n_pots_for_interp+1] zr_for_interp = zr_ij[:n_pots_for_interp] poly_coefs = np.polyfit(r_for_interp, zr_for_interp, 3) poly_f = np.poly1d(poly_coefs) zr[i][j] = [poly_f(0)] zr[i][j].extend(zr_ij) return r, np.swapaxes(zr, 0, 2)