def find_gr(M,L,x_target,x_edges,delta=5): #finds end to end distances and plots a histogram with that data print "############# FINDING GR ##############" distance=particle_distance(M,M,L,rmax=L[0]/2) bin_set = np.linspace(.8,2.2,75) hist_s, xs = np.histogram(distance,bins=bin_set) r_new = np.zeros(xs.shape[0]-1) for i in range(r_new.shape[0]): r_new[i] = (xs[i]+xs[i+1])/2 hist = np.zeros(hist_s.shape) delta_r = xs[1] - xs[0] #normalize the function with respect to an ideal gas for i in range(hist_s.shape[0]): r = r_new[i] hist[i] = hist_s[i] / ((delta*M.shape[1])*(4*math.pi*delta_r*r**2*(M.shape[1]/L[0]**3))) #interpolate g(r) for very smooth plot fhist = interpolate.interp1d(r_new, Smooth(hist)) shist = [] for i in x_target: try: shist.append(fhist(i)) except: try: shist.append(fhist(i+.0001)) except: shist.append(fhist(i-.0001)) return x_target,shist
def find_gr(M, L, x_target, x_edges, delta=5): #finds end to end distances and plots a histogram with that data print "############# FINDING GR ##############" distance = particle_distance(M, M, L, rmax=L[0] / 2) bin_set = np.linspace(.8, 2.2, 75) hist_s, xs = np.histogram(distance, bins=bin_set) r_new = np.zeros(xs.shape[0] - 1) for i in range(r_new.shape[0]): r_new[i] = (xs[i] + xs[i + 1]) / 2 hist = np.zeros(hist_s.shape) delta_r = xs[1] - xs[0] #normalize the function with respect to an ideal gas for i in range(hist_s.shape[0]): r = r_new[i] hist[i] = hist_s[i] / ((delta * M.shape[1]) * (4 * math.pi * delta_r * r**2 * (M.shape[1] / L[0]**3))) #interpolate g(r) for very smooth plot fhist = interpolate.interp1d(r_new, Smooth(hist)) shist = [] for i in x_target: try: shist.append(fhist(i)) except: try: shist.append(fhist(i + .0001)) except: shist.append(fhist(i - .0001)) return x_target, shist
def hist(M1,M2,save_name,label): distance=particle_distance(M1,M2,L) dist = [] for d in distance: if d>1 and d<25: dist.append(d) hist_s,xs=histogram_reg(dist,bins=25) return xs,hist_s
def hist(M1,M2,L,save_name,label,end=1): distance=particle_distance(M1,M2,L) hist_s,xs,max_hist=histogram_normal(distance,bins=60,end=end) #normalize the function with respect to an ideal gas delta_r = xs[1] - xs[0] for i in range(len(hist_s)): r = (xs[i]) hist_s[i] /= (4*math.pi*delta_r*r*(M1.shape[1]/L[0]**3)) return xs,hist_s
def PMF(hpy, V,L,n_frames=15,n_start=1,end=1): start=n_start finish=n_start+n_frames time_start = time.clock() distance=particle_distance(V[start:finish],V[start:finish],L) print "g(r) Elapsed Time -" , time.clock()-time_start time_start = time.clock() dset = hpy.create_dataset("%i"%n_start, data = np.array(distance)) dset.attrs.create("N_atoms",V.shape[1]) dset.attrs.create("V",L[0]*L[1]*L[2]) dset.attrs.create("L",L[0]) dset.attrs.create("n_frames",n_frames) #util.marshal_dump([V.shape[1],L[0],n_frames,distance], 'pmf_dist%i.pkl'%n_start) print "Marshal Elapsed Time -" , time.clock()-time_start
def hist(M1,M2,save_name,label): distance=particle_distance(M1,M2,L) hist_s,xs,max_hist=histogram(distance,bins=50) return xs,hist_s