def species_mixing(V,W,L,n_finish=1,n_start=0,delta=100,rcut=False): #The total number of frames we are going to look at if rcut == False: rcut=min_particle_distance(V[-1:],W[-1:],L)+6 print rcut #rcut = 19 rcut = 22 n_frames = (n_finish-n_start)/delta x = np.arange(n_start,n_finish,delta) s = [] o = [] for k in x: Same = 0 Other = 0 print k for i in range(V[k].shape[0]): Same += len(nearest_neighbors_point(V[k],V[k][i],L,rcut)[0]) Same += len(nearest_neighbors_point(W[k],W[k][i],L,rcut)[0]) Other += len(nearest_neighbors_point(W[k],V[k][i],L,rcut)[0]) Other += len(nearest_neighbors_point(V[k],W[k][i],L,rcut)[0]) s.append(float(Same)/(W[k].shape[0]+V[k].shape[0])) o.append(float(Other)/(V[k].shape[0]+W[k].shape[0])) print s print o util.pickle_dump([x,s,o],'mix.pkl') pyplot.plot2(x, s, x, o, label1='Same', label2='other', save=('mixing_avg_cut%.1f'%rcut), showleg=True)
def int_type(V, W, DV, DW, CV, CW, L): #find the two nearest points in the system #and record their type def find_nearest(point, A, B, L): smallA = 100 smallB = 100 typeA = 'G' typeB = 'G' for i in range(A.shape[0]): d = points.dist(point,A[i],L)[0] if d < smallB: smallA = smallB typeA =typeB smallB = d typeB = 'A' else: if smallA < d: smallA = d typeA = 'A' for i in range(B.shape[0]): d = points.dist(point,B[i],L)[0] if d < smallB: smallA = smallB typeA =typeB smallB = d typeB = 'B' else: if smallA < d: smallA = d typeA = 'B' return [typeA,typeB] totaldiff = [] totalsame =[] for k in range(DV.shape[0]): print k types = [] for i in range(DV.shape[1]): #if it is an interstitial, look for the 2 closests points if abs(DV[k][i]) == 2: types.append(find_nearest(CV[i],V[k],W[k],L)) for i in range(DW.shape[1]): if abs(DW[k][i]) == 2: types.append(find_nearest(CW[i],V[k],W[k],L)) different = 0 same = 0 for i in types: if i[0] == i[1]: different += 1 else: same += 1 totaldiff.append(different) totalsame.append(same) print totaldiff print totalsame x = range(V.shape[0]) pyplot.plot2(x,totaldiff,x,totalsame,label1='different',label2='same',showleg=True,xlabel='Time',ylabel='interstistials',save='int_type')
def end_end_connected(M,L): #find the length of the polymer ## \brief end to end distance of hybridized vs nonhybridized polymers # # \returns average distance from start to end of polymer # for hybridizations and free polymer # # \param M - ReadCord Class # \param L # # V ----- A C k # W ----- F G T import MD.analysis.connections as con try: K=util.pickle_load('K.pkl') T=util.pickle_load('T.pkl') S=util.pickle_load('S.pkl') except: K=M.cord_auto(['K']) T=M.cord_auto(['T']) S=M.cord_auto(['M']) util.pickle_dump(K,'K.pkl') util.pickle_dump(T,'T.pkl') util.pickle_dump(S,'S.pkl') #get connections con = _connections(M) h_sum = [] f_sum = [] for k in range(len(con)): print k hybrid = [] free = [] #get the points that are not connected for i in range(K.shape[1]): if i in con[k][0]: hybrid.append(points.dist(K[k][i],S[k][i],L[k])[0]+0.5) else: free.append(points.dist(K[k][i],S[k][i],L[k])[0]+0.5) for i in range(T.shape[1]): if i in con[k][1]: hybrid.append(points.dist(T[k][i],S[k][i+K.shape[1]],L[k])[0]+0.5) else: free.append(points.dist(T[k][i],S[k][i+K.shape[1]],L[k])[0]+0.5) print hybrid h_sum.append(sum(hybrid)/len(hybrid)) f_sum.append(sum(free)/len(free)) f_sum[-1]= f_sum[-2] h_sum[-1]= h_sum[-2] x = range(S.shape[0]) pyplot.plot2(x,h_sum,x,f_sum,xlabel='timestep',ylabel='sigma',label1='hybridizations', label2='free',save='free_hybrid_end_end_connections',showleg='true')
def center_end_connected(M,L): ## \brief center to end distance of hybridized vs nonhybridized polymers # # \returns average distance from center of particle to end of polymer # for hybridizations and free polymer # # \param M - ReadCord Class # \param L # # V ----- A C k # W ----- F G T #find the length of the polymer import MD.analysis.connections as con try: K=util.pickle_load('K.pkl') T=util.pickle_load('T.pkl') V=util.pickle_load('V.pkl') W=util.pickle_load('W.pkl') except: V=M.cord_auto(['V']) W=M.cord_auto(['W']) K=M.cord_auto(['K']) T=M.cord_auto(['T']) util.pickle_dump(K,'K.pkl') util.pickle_dump(T,'T.pkl') util.pickle_dump(V,'V.pkl') util.pickle_dump(W,'W.pkl') #get connections con = _connections(M) h_sum = [] f_sum = [] if len(con) != K.shape[0]: print len(con) print K.shape print 'connections and K have different lenghts' asdf for k in range(len(con)): print k hybrid = [] free = [] #get the points that are not connected for i in range(K.shape[1]): if i in con[k][0]: hybrid.append(points.dist(K[k][i],V[k][i/(K.shape[1]/V.shape[1])],L[k])[0]+0.5) else: free.append(points.dist(K[k][i],V[k][i/(K.shape[1]/V.shape[1])],L[k])[0]+0.5) for i in range(T.shape[1]): if i in con[k][1]: hybrid.append(points.dist(T[k][i],W[k][i/(T.shape[1]/W.shape[1])],L[k])[0]+0.5) else: free.append(points.dist(T[k][i],W[k][i/(T.shape[1]/W.shape[1])],L[k])[0]+0.5) h_sum.append(sum(hybrid)/len(hybrid)) f_sum.append(sum(free)/len(free)) f_sum[-1]= f_sum[-2] h_sum[-1]= h_sum[-2] x = range(V.shape[0]) print 'number of DNA per NP' print K.shape[1]/V.shape[1] print T.shape[1]/W.shape[1] pyplot.plot2(x,h_sum,x,f_sum,xlabel='timestep',ylabel='sigma',label1='hybridizations', label2='free',save='free_hybrid_connections',showleg='true')